diff --git a/.luacheckrc b/.luacheckrc index 9b1049c..79da584 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -10,6 +10,7 @@ read_globals = { "armor", "skins", "awards", + "hb", "vector", "string", "table", diff --git a/init.lua b/init.lua index 337d5f8..9097048 100644 --- a/init.lua +++ b/init.lua @@ -30,6 +30,7 @@ i3 = { min_fs_version = 6, item_btn_size = 1.1, drop_bag_on_die = true, + wielditem_fade_after = 3, save_interval = 600, -- Player data save interval (in seconds) hud_speed = 1, @@ -56,6 +57,7 @@ i3 = { waypoints = true, inv_items = true, known_recipes = true, + wielditem_hud = true, legacy_inventory = true, }, diff --git a/src/callbacks.lua b/src/callbacks.lua index 166d6f6..528d521 100644 --- a/src/callbacks.lua +++ b/src/callbacks.lua @@ -148,6 +148,10 @@ if core.global_exists"skins" then i3.modules.skins = true end +if core.global_exists"hb" then + i3.modules.hudbars = true +end + if core.global_exists"awards" then i3.modules.awards = true diff --git a/src/gui.lua b/src/gui.lua index f493f14..9953499 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -629,6 +629,7 @@ local function show_settings(fs, data) elseif show_style then checkbox(2.6, 9.95, "cb_hide_tabs", "Hide tabs", tostring(data.hide_tabs)) checkbox(2.6, 10.4, "cb_legacy_inventory", "Legacy inventory", tostring(data.legacy_inventory)) + checkbox(2.6, 10.85, "cb_wielditem_hud", "HUD description", tostring(data.wielditem_hud)) local sign = (data.font_size > 0 and "+") or (data.font_size > 0 and "-") or "" label(5.3, 9.95, ES"Font size" .. fmt(": %s", sign .. data.font_size)) @@ -637,6 +638,13 @@ local function show_settings(fs, data) fs(fmt("scrollbaroptions[min=-%u;max=%u;smallstep=1;largestep=1;thumbsize=2]", range, range)) fs(fmt("scrollbar[5.3,10.25;2.45,0.3;horizontal;sb_font_size;%d]", data.font_size)) + fs(fmt("tooltip[cb_hide_tabs;%s;#707070;#fff]", + ES"Enable this option to change the style of the right panel"), + fmt("tooltip[cb_legacy_inventory;%s;#707070;#fff]", + ES"Enable this option to set the classic inventory size in Minetest"), + fmt("tooltip[cb_wielditem_hud;%s;#707070;#fff]", + ES"Enable this option to show the wielded item description in your HUD")) + elseif show_sorting then checkbox(2.6, 9.95, "cb_inv_compress", "Compression", tostring(data.inv_compress)) checkbox(2.6, 10.4, "cb_reverse_sorting", "Reverse mode", tostring(data.reverse_sorting)) diff --git a/src/hud.lua b/src/hud.lua index 135b237..93ee92a 100644 --- a/src/hud.lua +++ b/src/hud.lua @@ -1,4 +1,4 @@ -IMPORT("get_connected_players", "str_to_pos", "add_hud_waypoint") +IMPORT("ceil", "get_connected_players", "str_to_pos", "add_hud_waypoint") local function init_hud(player) local name = player:get_player_name() @@ -32,6 +32,17 @@ local function init_hud(player) z_index = 0xDEAD, style = 1, }, + + wielditem = player:hud_add { + hud_elem_type = "text", + position = {x = 0.5, y = 1}, + offset = {x = 0, y = -65 - (i3.modules.hudbars and (ceil(hb.hudbars_count / 2) * 25) or 25)}, + alignment = {x = 0, y = -1}, + number = 0xffffff, + text = "", + z_index = 0xDEAD, + style = 1, + }, } end @@ -84,6 +95,50 @@ local function show_hud(player, data) end end +core.register_globalstep(function(dt) + local players = get_connected_players() + players[0] = #players + + for i = 1, players[0] do + local player = players[i] + local name = player:get_player_name() + local data = i3.data[name] + if not data then return end + + local function reset() + player:hud_change(data.hud.wielditem, "text", "") + data.timer = 0 + end + + if not data.wielditem_hud then + return reset() + end + + data.timer = (data.timer or 0) + dt + + local wielditem = player:get_wielded_item() + local wieldname = wielditem:get_name() + + if wieldname == data.old_wielditem then + if data.timer >= i3.settings.wielditem_fade_after then + return reset() + end + return + end + + data.old_wielditem = wieldname + + local meta = wielditem:get_meta() + local meta_desc = meta:get_string"short_description" + meta_desc = meta_desc:gsub("\27", "") + meta_desc = core.strip_colors(meta_desc) + + local desc = meta_desc ~= "" and meta_desc or wielditem:get_short_description() + + player:hud_change(data.hud.wielditem, "text", desc:trim()) + end +end) + core.register_globalstep(function() local players = get_connected_players() players[0] = #players