Allow to change a panel offset at runtime

master
Zughy 2022-06-18 01:39:19 +02:00
parent df565b2b47
commit 4f5ecc60b1
2 changed files with 22 additions and 3 deletions

View File

@ -42,7 +42,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. Beware: `panel_params` only supports a few. They are `position`, `bg`, `title` and `title_color`.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`, `offset`, `bg`, `title` and `title_color`.For instance, calling
```
panel:update(nil, nil, {my_custom_img = {

23
api.lua
View File

@ -205,8 +205,7 @@ function Panel:update(def, txt_elems, img_elems)
local player = minetest.get_player_by_name(self.player_name)
for k, v in pairs(def) do
-- aggiorno eventuale posizione, che tratto a parte perché influisce sia su sfondo che titolo,
-- influenzando anche tutti i sottoelementi del pannello
-- aggiorno eventuale posizione, influenzando anche i vari sottoelementi
if k == "position" then
self.background_def.position = v
self.title_def.position = v
@ -224,6 +223,26 @@ function Panel:update(def, txt_elems, img_elems)
player:hud_change(self.hud_id.bg_hud_id, k, v)
player:hud_change(self.hud_id.text_hud_id, k, v)
-- aggiorno eventuale scostamento, influenzando anche i vari sottoelementi
elseif k == "offset" then
self.background_def.offset = v
self.title_def.offset = v
for _, elem in pairs(self.sub_img_elems) do
local HUD_ID = self.hud_id[elem]
local offset = { x = (v.x or 0) + (self[elem].offset.x or 0), y = (v.y or 0) + (self[elem].offset.y or 0)}
player:hud_change(HUD_ID, k, offset)
end
for _, elem in pairs(self.sub_txt_elems) do
local HUD_ID = self.hud_id[elem]
local offset = { x = (v.x or 0) + (self[elem].offset.x or 0), y = (v.y or 0) + (self[elem].offset.y or 0)}
player:hud_change(HUD_ID, k, offset)
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