Compare commits
5 Commits
6c47828604
...
415f1c5a19
Author | SHA1 | Date |
---|---|---|
Zughy | 415f1c5a19 | |
Zughy | 4f5ecc60b1 | |
Zughy | df565b2b47 | |
Zughy | 0bdd612252 | |
Zughy | f4b33eb484 |
2
DOCS.md
2
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 = {
|
||||
|
|
11
README.md
11
README.md
|
@ -9,12 +9,5 @@ Library for Minetest allowing modders to create complex HUDs in an easy way
|
|||
### Config
|
||||
Have a read at the [DOCS](https://gitlab.com/zughy-friends-minetest/scoreboard_lib/-/blob/master/DOCS.md) to understand how to use it
|
||||
|
||||
|
||||
### Dependencies
|
||||
(none)
|
||||
|
||||
### Known conflicts
|
||||
(none)
|
||||
|
||||
#### Mods relying on scoreboard_lib
|
||||
[Quake](https://gitlab.com/zughy-friends-minetest/minetest-quake)
|
||||
#### Mods relying on panel_lib
|
||||
[Block League](https://gitlab.com/zughy-friends-minetest/block_league)
|
||||
|
|
53
api.lua
53
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
|
||||
}
|
||||
|
@ -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,12 +223,32 @@ 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
|
||||
self.background_def.text = v
|
||||
|
||||
if self.is_visible then
|
||||
if self:is_visible() then
|
||||
player:hud_change(self.hud_id.bg_hud_id, "text", v)
|
||||
end
|
||||
|
||||
|
@ -239,7 +258,7 @@ function Panel:update(def, txt_elems, img_elems)
|
|||
if k == "title" then
|
||||
self.hud_text.text_hud_txt = v
|
||||
self.title_def.text = v
|
||||
if self.is_visible then
|
||||
if self:is_visible() then
|
||||
player:hud_change(self.hud_id.text_hud_id, "text", v)
|
||||
end
|
||||
else
|
||||
|
@ -361,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)
|
||||
|
||||
|
@ -368,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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue