From df4b8e64cc153ba70457a199661e1e6e92e30bf9 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 19 Aug 2021 19:21:33 +0200 Subject: [PATCH] finish `mcl_title` API + doc --- mods/HUD/mcl_title/API.md | 8 ++++++ mods/HUD/mcl_title/init.lua | 28 +++++++++++--------- mods/HUD/mcl_tmp_message/API.md | 7 ----- mods/HUD/mcl_tmp_message/init.lua | 44 ------------------------------- mods/HUD/mcl_tmp_message/mod.conf | 3 --- 5 files changed, 23 insertions(+), 67 deletions(-) delete mode 100644 mods/HUD/mcl_tmp_message/API.md delete mode 100644 mods/HUD/mcl_tmp_message/init.lua delete mode 100644 mods/HUD/mcl_tmp_message/mod.conf diff --git a/mods/HUD/mcl_title/API.md b/mods/HUD/mcl_title/API.md index 50614be4f..97d75ece8 100644 --- a/mods/HUD/mcl_title/API.md +++ b/mods/HUD/mcl_title/API.md @@ -39,4 +39,12 @@ Allow mods to set `stay` and upcomming `fadeIn`/`fadeOut` params. ```lua mcl_title.params_set(player, {stay = 600}) --elements with no 'data.stay' field will stay during 30s (600/20) +``` + +## mcl_title.params_get(player) + +Get `stay` and upcomming `fadeIn` and `fadeOut` params of a player as a table. + +```lua +mcl_title.params_get(player) ``` \ No newline at end of file diff --git a/mods/HUD/mcl_title/init.lua b/mods/HUD/mcl_title/init.lua index 933158d20..2ea1571c8 100644 --- a/mods/HUD/mcl_title/init.lua +++ b/mods/HUD/mcl_title/init.lua @@ -32,7 +32,7 @@ mcl_title.layout.actionbar = {position = {x = 0.5, y = 1}, alignment = {x = 0, y local get_color = mcl_util.get_color -local string = string +--local string = string local pairs = pairs local function gametick_to_secondes(gametick) @@ -44,7 +44,7 @@ local function gametick_to_secondes(gametick) end --https://github.com/minetest/minetest/blob/b3b075ea02034306256b486dd45410aa765f035a/doc/lua_api.txt#L8477 - +--[[ local function style_to_bits(bold, italic) if bold then if italic then @@ -60,24 +60,25 @@ local function style_to_bits(bold, italic) end end end +]] --PARAMS SYSTEM local player_params = {} minetest.register_on_joinplayer(function(player) - local playername = player:get_player_name() + --local playername = player:get_player_name() player_params[player] = { stay = mcl_title.defaults.stay, --fadeIn = mcl_title.defaults.fadein, --fadeOut = mcl_title.defaults.fadeout, } - local _, hex_color = get_color("white") + local _, hex_color = get_color("white") huds_idx.title[player] = player:hud_add({ hud_elem_type = "text", position = mcl_title.layout.title.position, alignment = mcl_title.layout.title.alignment, text = "", - style = 0, + --style = 0, size = {x = mcl_title.layout.title.size}, number = hex_color, z_index = 100, @@ -87,7 +88,7 @@ minetest.register_on_joinplayer(function(player) position = mcl_title.layout.subtitle.position, alignment = mcl_title.layout.subtitle.alignment, text = "", - style = 0, + --style = 0, size = {x = mcl_title.layout.subtitle.size}, number = hex_color, z_index = 100, @@ -97,7 +98,7 @@ minetest.register_on_joinplayer(function(player) position = mcl_title.layout.actionbar.position, offset = {x = 0, y = -210}, alignment = mcl_title.layout.actionbar.alignment, - style = 0, + --style = 0, text = "", size = {x = mcl_title.layout.actionbar.size}, number = hex_color, @@ -116,7 +117,7 @@ minetest.register_on_leaveplayer(function(player) huds_idx.subtitle[player] = nil huds_idx.actionbar[player] = nil - --remove timers form list + --remove timers from list hud_hide_timeouts.title[playername] = nil hud_hide_timeouts.subtitle[playername] = nil hud_hide_timeouts.actionbar[playername] = nil @@ -149,7 +150,7 @@ function mcl_title.set(player, type, data) player:hud_change(huds_idx[type][player], "number", hex_color) --apply bold and italic - player:hud_change(huds_idx[type][player], "style", style_to_bits(data.bold, data.italic)) + --player:hud_change(huds_idx[type][player], "style", style_to_bits(data.bold, data.italic)) hud_hide_timeouts[type][player:get_player_name()] = gametick_to_secondes(data.stay) or gametick_to_secondes(mcl_title.params_get(player).stay) return true @@ -158,7 +159,7 @@ end function mcl_title.remove(player, type) if player then player:hud_change(huds_idx[type][player], "text", "") - player:hud_change(huds_idx[type][player], "style", 0) --no styling + --player:hud_change(huds_idx[type][player], "style", 0) --no styling end end @@ -193,8 +194,8 @@ minetest.register_globalstep(function(dtime) end) ---TEMP STUFF!! ---TODO: remove then testing/tweaking done +--DEBUG STUFF!! +--[[ minetest.register_chatcommand("title", { func = function(name, param) local player = minetest.get_player_by_name(name) @@ -231,4 +232,5 @@ minetest.register_chatcommand("all", { mcl_title.set(player, "subtitle", {text=param, color="gold"}) mcl_title.set(player, "actionbar", {text=param, color="gold"}) end, -}) \ No newline at end of file +}) +]] \ No newline at end of file diff --git a/mods/HUD/mcl_tmp_message/API.md b/mods/HUD/mcl_tmp_message/API.md deleted file mode 100644 index 0a3fc06a3..000000000 --- a/mods/HUD/mcl_tmp_message/API.md +++ /dev/null @@ -1,7 +0,0 @@ -# mcl_temp_message - -Allow mods to show short messages in the hud of players. - -## mcl_tmp_message.message(player, message) - -Show above the hotbar a hud message to player . \ No newline at end of file diff --git a/mods/HUD/mcl_tmp_message/init.lua b/mods/HUD/mcl_tmp_message/init.lua deleted file mode 100644 index 1456cd592..000000000 --- a/mods/HUD/mcl_tmp_message/init.lua +++ /dev/null @@ -1,44 +0,0 @@ -mcl_tmp_message = {} - -local huds = {} -local hud_hide_timeouts = {} - -function mcl_tmp_message.message(player, message) - local name = player:get_player_name() - player:hud_change(huds[name], "text", message) - hud_hide_timeouts[name] = 3 -end - -minetest.register_on_joinplayer(function(player) - huds[player:get_player_name()] = player:hud_add({ - hud_elem_type = "text", - position = {x=0.5, y=1}, - offset = {x = 0, y = -210}, - alignment = {x=0, y=0}, - number = 0xFFFFFF , - text = "", - z_index = 100, - }) -end) - -minetest.register_on_leaveplayer(function(player) - local name = player:get_player_name() - huds[name] = nil - hud_hide_timeouts[name] = nil -end) - -minetest.register_globalstep(function(dtime) - local new_timeouts = {} - for name, timeout in pairs(hud_hide_timeouts) do - timeout = timeout - dtime - if timeout <= 0 then - local player = minetest.get_player_by_name(name) - if player then - player:hud_change(huds[name], "text", "") - end - else - new_timeouts[name] = timeout - end - end - hud_hide_timeouts = new_timeouts -end) diff --git a/mods/HUD/mcl_tmp_message/mod.conf b/mods/HUD/mcl_tmp_message/mod.conf deleted file mode 100644 index ad453643e..000000000 --- a/mods/HUD/mcl_tmp_message/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = mcl_tmp_message -author = Fleckenstein -description = A simple API to show a temporary message to a player