From 415f1c5a1944d228cbc3f344149e2f414ddcf14a Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Sun, 26 Jun 2022 15:16:58 +0200 Subject: [PATCH] Bugfix: save the correct offset for subelements when the panel has a custom offset as well --- api.lua | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/api.lua b/api.lua index 4de9c80..462078e 100644 --- a/api.lua +++ b/api.lua @@ -32,8 +32,8 @@ Panel = { text = "" }, - sub_img_elems = {}, - sub_txt_elems = {}, + sub_img_elems = {}, -- KEY: ID, VALUE: name + sub_txt_elems = {}, -- KEY: ID, VALUE: name visible = true } @@ -380,6 +380,7 @@ function add_sub_elem(panel, type, name, HUD_elem) minetest.log("error", "[PANEL_LIB] Attempt to create a sub element with the same name of another. Aborting") return end + -- clono la tabella di riferimento e ne modifico i valori con quelli del sottoelemento sub_elems[#sub_elems +1] = name panel[name] = clone_table(mould) @@ -387,20 +388,27 @@ function add_sub_elem(panel, type, name, HUD_elem) panel[name][k] = v end - -- mantengo la stessa posizione del corpo del panel, costringendo - -- l'utente a modificare gli offset se vuole spostare gli elementi + -- mantengo la stessa posizione del corpo del panello, costringendo + -- l'utente a modificare gli scostamenti se vuole spostare gli elementi panel[name].position = mould.position - -- se il pannello ha gli offset personalizzati e il sottoelemento pure, li sommo - if HUD_elem.offset and (panel.background_def.offset.x ~= 0 or panel.background_def.offset.y ~= 0) then - panel[name].offset = {x = panel.background_def.offset.x + (HUD_elem.offset.x or 0), y = panel.background_def.offset.y + (HUD_elem.offset.y or 0)} - end - -- mostro l'elemento se il pannello era già visibile panel[name].text = panel:is_visible() and panel[name].text or "" + -- salvo panel.hud_id[name] = minetest.get_player_by_name(panel.player_name):hud_add(panel[name]) panel.hud_text[name] = HUD_elem.text + + -- se sia il pannello che il sottoelemento hanno scostamenti personalizzati, + -- li sommo DOPO aver salvato il pannello, senza che la somma venga salvata in + -- panel[name]. Questo perché i sottoelementi devono salvare solo il proprio + -- valore di scostamento (nel for in alto). Vedasi anche Panel:update(), che + -- appunto ne cambia eventuale scostamento (hud_change) senza andarlo a salvare in tabella + if HUD_elem.offset and (panel.background_def.offset.x ~= 0 or panel.background_def.offset.y ~= 0) then + local player = minetest.get_player_by_name(panel.player_name) + local offset = {x = (panel.background_def.offset.x or 0) + (HUD_elem.offset.x or 0), y = (panel.background_def.offset.y or 0) + (HUD_elem.offset.y or 0)} + player:hud_change(panel.hud_id[name], "offset", offset) + end end