Actually update panel non-sub elems (position, bg, title and title_color)
parent
0b63551489
commit
c0268247fe
2
DOCS.md
2
DOCS.md
|
@ -41,7 +41,7 @@ Install it as any other mod `¯\_(ツ)_/¯`
|
|||
* `hide()`: makes the panel disappear (but it's still assigned to the player)
|
||||
* `is_visible()`: whether the panel is currently displayed
|
||||
* `remove()`: deletes it
|
||||
* `update(panel_params, txt_elems, img_elems)`: updates only the mentioned parameters. For instance, calling
|
||||
* `update(panel_params, txt_elems, img_elems)`: updates only the mentioned parameters. Beware: `panel_params` only supports a few. They are `position`, `bg`, `title` and `title_color`.For instance, calling
|
||||
|
||||
```
|
||||
panel:update(nil, nil, {my_custom_img = {
|
||||
|
|
49
api.lua
49
api.lua
|
@ -192,8 +192,55 @@ end
|
|||
function Panel:update(def, txt_elems, img_elems)
|
||||
|
||||
if def ~= nil then
|
||||
local player = minetest.get_player_by_name(self.player_name)
|
||||
|
||||
for k, v in pairs(def) do
|
||||
self[k] = v
|
||||
-- aggiorno eventuale posizione, che tratto a parte perché influisce sia su sfondo che titolo,
|
||||
-- influenzando anche tutti i sottoelementi del pannello
|
||||
if k == "position" then
|
||||
self.background_def.position = v
|
||||
self.title_def.position = v
|
||||
|
||||
for _, elem in pairs(self.sub_img_elems) do
|
||||
local HUD_ID = self.hud_id[elem]
|
||||
player:hud_change(HUD_ID, k, v)
|
||||
end
|
||||
|
||||
for _, elem in pairs(self.sub_txt_elems) do
|
||||
local HUD_ID = self.hud_id[elem]
|
||||
player:hud_change(HUD_ID, k, v)
|
||||
end
|
||||
|
||||
player:hud_change(self.hud_id.bg_hud_id, k, v)
|
||||
player:hud_change(self.hud_id.text_hud_id, k, v)
|
||||
|
||||
-- aggiorno eventuale sfondo
|
||||
elseif k == "bg" then
|
||||
self.hud_text.bg_hud_txt = v
|
||||
self.background_def.text = v
|
||||
|
||||
if self.is_visible then
|
||||
player:hud_change(self.hud_id.bg_hud_id, "text", v)
|
||||
end
|
||||
|
||||
-- aggiorno eventuali proprietà titolo
|
||||
elseif k == "title" or k == "title_color" then
|
||||
|
||||
if k == "title" then
|
||||
self.hud_text.text_hud_txt = v
|
||||
self.title_def.text = v
|
||||
if self.is_visible then
|
||||
player:hud_change(self.hud_id.text_hud_id, "text", v)
|
||||
end
|
||||
else
|
||||
self.title_def.number = v
|
||||
player:hud_change(self.hud_id.text_hud_id, "number", v)
|
||||
end
|
||||
|
||||
else
|
||||
error("[PANEL_LIB] Invalid or unsupported element type, check DOCS and spelling")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue