Bugfix: save the correct offset for subelements when the panel has a custom offset as well

master
Zughy 2022-06-26 15:16:58 +02:00
parent 4f5ecc60b1
commit 415f1c5a19
1 changed files with 17 additions and 9 deletions

26
api.lua
View File

@ -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