More panels per player
parent
fac2e279d4
commit
9e8ea201ca
7
DOCS.md
7
DOCS.md
|
@ -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
14
api.lua
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue