More panels per player

master
Zughy 2020-07-28 02:20:50 +02:00
parent fac2e279d4
commit 9e8ea201ca
3 changed files with 17 additions and 7 deletions

View File

@ -9,7 +9,8 @@ To declare a new panel, simply do
`local panel = Panel:new({parameters})` `local panel = Panel:new({parameters})`
The parameters it takes are the following: The parameters it takes are the following:
* `player`: the player to assign the panel to * `name`: required. The panel name. Used to retrieve it via `panel_lib.get_panel(player_name, panel_name)`.
* `player`: required. The player to assign the panel to
* `position`: the panel position (as in any other HUD) * `position`: the panel position (as in any other HUD)
* `alignment`: same * `alignment`: same
* `bg`: the picture to put in the background * `bg`: the picture to put in the background
@ -47,8 +48,8 @@ panel:update(nil, nil, {my_custom_img = {
``` ```
updates just the text of the sub-element `my_custom_img`. updates just the text of the sub-element `my_custom_img`.
There is also a getter, to obtain the panel associated with a player ## 2.2 Getters
* `panel_lib.get_panel(player_name)` * `panel_lib.get_panel(player_name, panel_name)`: obtains the panel associated with a player
## 3. Collaborating ## 3. Collaborating
Something's wrong? Feel free to: Something's wrong? Feel free to:

14
api.lua
View File

@ -1,4 +1,4 @@
panel_lib.panels = {} panel_lib.panels = {} -- KEY: p_name; VALUE: {{"panel name" = panel}, {"panel name 2" = panel2}, ...}
local function clone_table() end local function clone_table() end
@ -111,7 +111,11 @@ function Panel:new(def)
end end
-- salvo in memoria -- salvo in memoria
panel_lib.panels[def.player] = panel if not panel_lib.panels[def.player] then
panel_lib.panels[def.player] = {}
end
panel_lib.panels[def.player][def.name] = panel
return panel return panel
end end
@ -130,6 +134,7 @@ function Panel:show()
for _, name in pairs(self.sub_txt_elems) do for _, name in pairs(self.sub_txt_elems) do
self.hud_id[name] = player:hud_add(self[name]) self.hud_id[name] = player:hud_add(self[name])
end end
end end
@ -143,6 +148,7 @@ function Panel:hide()
player:hud_remove(self.hud_id[k]) player:hud_remove(self.hud_id[k])
end end
end end
end end
@ -190,8 +196,8 @@ end
-----------------GETTERS---------------------- -----------------GETTERS----------------------
---------------------------------------------- ----------------------------------------------
function panel_lib.get_panel(p_name) function panel_lib.get_panel(p_name, panel_name)
return panel_lib.panels[p_name] return panel_lib.panels[p_name][panel_name]
end end

View File

@ -1,3 +1,6 @@
panel_lib = {} panel_lib = {}
local version = "2.0.0-dev"
dofile(minetest.get_modpath("panel_lib") .. "/api.lua") dofile(minetest.get_modpath("panel_lib") .. "/api.lua")
minetest.log("action", "[PANEL_LIB] Mod initialised, running version " .. version)