scoreboard_lib/DOCS.md

70 lines
3.8 KiB
Markdown
Raw Permalink Normal View History

2020-04-23 05:54:16 -07:00
# Panel_lib docs
2020-04-23 04:24:32 -07:00
2020-04-23 05:54:16 -07:00
## 1. Panel structure
2020-04-23 04:24:32 -07:00
2020-04-23 05:54:16 -07:00
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.
2020-04-23 04:24:32 -07:00
### 1.1. Declaration
2020-04-23 05:54:16 -07:00
To declare a new panel, simply do
2020-11-28 15:21:18 -08:00
`local panel = Panel:new(name, {parameters})`
2020-04-23 04:24:32 -07:00
The parameters it takes are the following:
2020-07-27 17:20:50 -07:00
* `player`: required. The player to assign the panel to
2020-04-23 05:54:16 -07:00
* `position`: the panel position (as in any other HUD)
2020-04-23 04:24:32 -07:00
* `alignment`: same
* `offset`: same
2020-04-23 04:24:32 -07:00
* `bg`: the picture to put in the background
* `bg_scale`: its scaling
2020-11-28 15:21:18 -08:00
* `title`: the default text. Default is empty (`""`)
* `title_size`: (table) as a multiplier, where Y is not considered. Ie. `{ x = 2}` will double up the font size
2020-04-23 04:24:32 -07:00
* `title_alignment`
* `title_offset`: if `offset` is declared already, it'll add/subtract the two values
2020-04-23 04:24:32 -07:00
* `title_color`
2020-11-28 15:21:18 -08:00
* `visible`: (bool) whether the panel is visible right after its creation. Default is `true`
2020-04-23 05:54:16 -07:00
* `sub_img_elems`: (table) whatever image to add to the panel
* `sub_txt_elems`: (table) whatever text to add to the panel
2020-04-23 04:24:32 -07:00
### 1.2. Sub-elements
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.
2020-04-23 05:54:16 -07:00
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.
2020-04-23 04:24:32 -07:00
2020-04-23 05:54:16 -07:00
Have a look at [the example file](https://gitlab.com/zughy-friends-minetest/panel_lib/-/blob/master/panel.example) to see a complete panel declaration.
2020-04-23 04:24:32 -07:00
## 2. Configuration
Install it as any other mod `¯\_(ツ)_/¯`
## 2.1. Functions
2020-04-23 05:54:16 -07:00
* `new({params})`: creates a new panel
* `show()`: makes the panel appear
* `hide()`: makes the panel disappear (but it's still assigned to the player)
2020-11-28 15:21:18 -08:00
* `is_visible()`: whether the panel is currently displayed
2020-04-23 04:24:32 -07:00
* `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
2020-04-23 04:24:32 -07:00
```
2020-04-23 05:54:16 -07:00
panel:update(nil, nil, {my_custom_img = {
2020-04-23 04:24:32 -07:00
text = "pic2.png"
})
```
updates just the text of the sub-element `my_custom_img`.
2020-11-28 15:35:23 -08:00
* `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
2020-07-27 17:20:50 -07:00
## 2.2 Getters
* `panel_lib.get_panel(player_name, panel_name)`: obtains the panel associated with a player
2020-04-23 04:24:32 -07:00
## 3. Collaborating
2020-06-26 09:02:27 -07:00
Something's wrong? Feel free to:
* open an [issue](https://gitlab.com/zughy-friends-minetest/panel_lib/-/issues)
* submit a merge request. In this case, PLEASE, do follow milestones and my [coding guidelines](https://cryptpad.fr/pad/#/2/pad/view/-l75iHl3x54py20u2Y5OSAX4iruQBdeQXcO7PGTtGew/embed/). I won't merge features for milestones that are different from the upcoming one (if it's declared), nor messy code
* contact me on the [Minetest Forum](https://forum.minetest.net/memberlist.php?mode=viewprofile&u=26472)
I'd really appreciate it :)
2020-04-23 04:24:32 -07:00
## 4. About the author(s)
2020-06-08 04:50:40 -07:00
I'm Zughy (Marco), a professional Italian pixel artist who fights for FOSS and digital ethics. If this library spared you a lot of time and you want to support me somehow, please consider donating on [LiberaPay](https://liberapay.com/Zughy/). Also, this project wouldn't have been possible if it hadn't been for some friends who helped me testing through: `SonoMichele`, `_Zaizen_` and `Xx_Crazyminer_xX`