From 4f5ecc60b1d4ca3cab4a92c236ba37a4e2b648fe Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Sat, 18 Jun 2022 01:39:19 +0200 Subject: [PATCH] Allow to change a panel offset at runtime --- DOCS.md | 2 +- api.lua | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/DOCS.md b/DOCS.md index 9b16c60..2493693 100644 --- a/DOCS.md +++ b/DOCS.md @@ -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 = { diff --git a/api.lua b/api.lua index b44b3ae..4de9c80 100644 --- a/api.lua +++ b/api.lua @@ -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