Add panel:get_info()

This commit is contained in:
Zughy 2023-08-23 16:48:38 +02:00
parent c02d7ba31a
commit 4503417438
2 changed files with 20 additions and 7 deletions

17
DOCS.md
View File

@ -2,12 +2,12 @@
## 1. Panel structure
A panel is a custom object made of 2 HUD elements, the title and the background, plus a group of two sub-elements: the text and the images. Picture the background as the container of all the things you want to showcase in your HUD. Those things go in the sub-elements.
A panel is a custom object made of 2 HUD elements, the title and the background, plus a group of two sub-elements: the text and the images. Picture the background as the container of all the things you want to showcase in your HUD. Those things go in the sub-elements.
### 1.1. Declaration
To declare a new panel, simply do
`local panel = Panel:new(name, {parameters})`
To declare a new panel, simply do
`local panel = Panel:new(name, {parameters})`
The parameters it takes are the following:
* `player`: required. The player to assign the panel to
* `position`: the panel position (as in any other HUD)
@ -26,7 +26,7 @@ The parameters it takes are the following:
* `sub_txt_elems`: (table) whatever text to add to the panel
### 1.2. Sub-elements
Sub-elements are HUDs added on top of the main container, sharing the same position. This means two things:
Sub-elements are HUDs added on top of the main container, sharing the same position. This means two things:
1. As a HUD, they take the same parameters a HUD takes. They are clones respectively of the background and the title, so if you skip some parameter, they'll keep their reference default value.
2. If you wanna move them around, you must tweak the offset, **NOT** the position. If you change the position, they may look fine in a screen resolution, but not in another. In order to prevent it, `panel_lib` automatically overrides the position with the panel's.
@ -39,18 +39,21 @@ Install it as any other mod `¯\_(ツ)_/¯`
## 2.1. Functions
* `new({params})`: creates a new panel
* `get_info()`: returns a table containing the following fields:
* `bg`: (table) a copy of the HUD of the background (with MT values such as `hud_elem_type`, `position`, `scale` etc.)
* `title`: (table) same as `bg` but for the title HUD
* `show()`: makes the panel appear
* `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`, `offset`, `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 = {
text = "pic2.png"
})
```
updates just the text of the sub-element `my_custom_img`.
updates just the text of the sub-element `my_custom_img`.
* `add_sub_elem(type, name, HUD_elem)`: adds a sub-element at runtime. `type` must be either `text` or `image`. `HUD_elem` is the table representing the HUD
* `remove_sub_elem(name)`: removes a sub-element at runtime

10
api.lua
View File

@ -305,6 +305,16 @@ end
function Panel:get_info()
local info = {}
info.bg = table.copy(self.background_def)
info.title = table.copy(self.title_def)
return info
end
function Panel:is_visible()
return self.visible
end