Massive refactoring
parent
30cec02a97
commit
c7e2c5dd14
36
DOCS.md
36
DOCS.md
|
@ -1,16 +1,16 @@
|
|||
# Scoreboard_lib docs
|
||||
# Panel_lib docs
|
||||
|
||||
## 1. Scoreboard structure
|
||||
## 1. Panel structure
|
||||
|
||||
A scoreboard 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 scoreboard, simply do
|
||||
`local scoreboard = Scoreboard:new({parameters})`
|
||||
To declare a new panel, simply do
|
||||
`local panel = Panel:new({parameters})`
|
||||
|
||||
The parameters it takes are the following:
|
||||
* `player`: the player to assign the scoreboard to
|
||||
* `position`: the scoreboard position (as in any other HUD)
|
||||
* `player`: the player to assign the panel to
|
||||
* `position`: the panel position (as in any other HUD)
|
||||
* `alignment`: same
|
||||
* `bg`: the picture to put in the background
|
||||
* `bg_scale`: its scaling
|
||||
|
@ -18,15 +18,15 @@ The parameters it takes are the following:
|
|||
* `title_alignment`
|
||||
* `title_offset`
|
||||
* `title_color`
|
||||
* `sub_img_elems`: (table) whatever image to add to the scoreboard
|
||||
* `sub_txt_elems`: (table) whatever text to add to the scoreboard
|
||||
* `sub_img_elems`: (table) whatever image to add to the panel
|
||||
* `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:
|
||||
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, `scoreboard_lib` automatically overrides the position with the scoreboard's.
|
||||
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.
|
||||
|
||||
Have a look at [the example file](https://gitlab.com/zughy-friends-minetest/scoreboard_lib/-/blob/master/scoreboard.example) to see a complete scoreboard declaration.
|
||||
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.
|
||||
|
||||
## 2. Configuration
|
||||
|
||||
|
@ -34,21 +34,21 @@ Install it as any other mod `¯\_(ツ)_/¯`
|
|||
|
||||
## 2.1. Functions
|
||||
|
||||
* `new({params})`: creates a new scoreboard
|
||||
* `show()`: makes the scoreboard appear
|
||||
* `hide()`: makes the scoreboard disappear (but it's still assigned to the player)
|
||||
* `new({params})`: creates a new panel
|
||||
* `show()`: makes the panel appear
|
||||
* `hide()`: makes the panel disappear (but it's still assigned to the player)
|
||||
* `remove()`: deletes it
|
||||
* `update(scoreboard_params, txt_elems, img_elems)`: updates only the mentioned parameters. For instance, calling
|
||||
* `update(panel_params, txt_elems, img_elems)`: updates only the mentioned parameters. For instance, calling
|
||||
|
||||
```
|
||||
scoreboard:update(nil, nil, {my_custom_img = {
|
||||
panel:update(nil, nil, {my_custom_img = {
|
||||
text = "pic2.png"
|
||||
})
|
||||
```
|
||||
updates just the text of the sub-element `my_custom_img`.
|
||||
|
||||
There is also a getter, to obtain the scoreboard associated with a player
|
||||
* `scoreboard_lib.get_scoreboard(player_name)`
|
||||
There is also a getter, to obtain the panel associated with a player
|
||||
* `panel_lib.get_panel(player_name)`
|
||||
|
||||
## 3. Collaborating
|
||||
Something's wrong? Feel free to open an issue, go for a merge request and whatnot. I'd really appreciate it :)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Scoreboard_lib
|
||||
# Panel_lib
|
||||
|
||||
Scoreboard_lib is a library for Minetest allowing modders to create complex scoreboards in an easy way
|
||||
Panel_lib is a library for Minetest allowing modders to create complex HUDs in an easy way
|
||||
|
||||
<a href="https://liberapay.com/EticaDigitale/donate"><img src="https://i.imgur.com/4B2PxjP.png" alt="Support my work"/></a>
|
||||
|
||||
|
@ -17,4 +17,4 @@ Have a read at the [DOCS](https://gitlab.com/zughy-friends-minetest/scoreboard_l
|
|||
(none)
|
||||
|
||||
#### Mods relying on scoreboard_lib
|
||||
[Quake](https://gitlab.com/zughy-friends-minetest/minetest-quake)
|
||||
[Quake](https://gitlab.com/zughy-friends-minetest/minetest-quake)
|
||||
|
|
72
api.lua
72
api.lua
|
@ -1,20 +1,20 @@
|
|||
scoreboard_lib.scoreboards = {}
|
||||
panel_lib.panels = {}
|
||||
|
||||
local function clone_table() end
|
||||
|
||||
Scoreboard = {
|
||||
-- player to show the scoreboard to
|
||||
Panel = {
|
||||
-- player to show the panel to
|
||||
player_name = "",
|
||||
-- ids of the hud of the player
|
||||
hud_id = {},
|
||||
-- because the scoreboard is composed by a background and a text we need to
|
||||
-- because the panel is composed by a background and a text we need to
|
||||
-- define the two HUD to use later
|
||||
background_def = {
|
||||
hud_elem_type = "image",
|
||||
position = { x = 1, y = 0.5 },
|
||||
scale = { x = 1, y = 1 },
|
||||
alignment = { x = -1, y = 0 },
|
||||
text = "scoreboard_bg.png",
|
||||
text = "panel_bg.png",
|
||||
},
|
||||
title_def = {
|
||||
hud_elem_type = "text",
|
||||
|
@ -32,63 +32,63 @@ Scoreboard = {
|
|||
|
||||
|
||||
|
||||
function Scoreboard:new(def)
|
||||
local scoreboard = {}
|
||||
function Panel:new(def)
|
||||
local panel = {}
|
||||
|
||||
setmetatable(scoreboard, self)
|
||||
setmetatable(panel, self)
|
||||
self.__index = self
|
||||
|
||||
if def.position then
|
||||
scoreboard.background_def.position = def.position
|
||||
scoreboard.title_def.position = def.position
|
||||
panel.background_def.position = def.position
|
||||
panel.title_def.position = def.position
|
||||
end
|
||||
|
||||
if def.alignment then
|
||||
scoreboard.background_def.alignment = def.alignment
|
||||
panel.background_def.alignment = def.alignment
|
||||
end
|
||||
|
||||
if def.bg then
|
||||
scoreboard.background_def.text = def.bg
|
||||
panel.background_def.text = def.bg
|
||||
end
|
||||
|
||||
if def.bg_scale then
|
||||
scoreboard.background_def.scale = def.bg_scale
|
||||
panel.background_def.scale = def.bg_scale
|
||||
end
|
||||
|
||||
if def.title then
|
||||
scoreboard.title_def.text = def.title
|
||||
panel.title_def.text = def.title
|
||||
end
|
||||
|
||||
if def.title_alignment then
|
||||
scoreboard.title_def.alignment = def.title_alignment
|
||||
panel.title_def.alignment = def.title_alignment
|
||||
end
|
||||
|
||||
if def.title_offset then
|
||||
scoreboard.title_def.offset = def.title_offset
|
||||
panel.title_def.offset = def.title_offset
|
||||
end
|
||||
|
||||
if def.title_color then
|
||||
scoreboard.title_def.number = def.title_color
|
||||
panel.title_def.number = def.title_color
|
||||
end
|
||||
|
||||
if def.player then
|
||||
scoreboard.player_name = def.player
|
||||
panel.player_name = def.player
|
||||
end
|
||||
|
||||
-- controllo sottoelementi
|
||||
if def.sub_img_elems then
|
||||
local i = 1
|
||||
for name, elem in pairs(def.sub_img_elems) do
|
||||
scoreboard.sub_img_elems[i] = name
|
||||
scoreboard[name] = clone_table(scoreboard.background_def)
|
||||
panel.sub_img_elems[i] = name
|
||||
panel[name] = clone_table(panel.background_def)
|
||||
|
||||
for param, v in pairs(elem) do
|
||||
scoreboard[name][param] = v
|
||||
panel[name][param] = v
|
||||
end
|
||||
|
||||
-- mantengo la stessa posizione del corpo della scoreboard, costringendo
|
||||
-- mantengo la stessa posizione del corpo della panel, costringendo
|
||||
-- l'utente a modificare gli offset se vuole spostare gli elementi
|
||||
scoreboard[name].position = def.position
|
||||
panel[name].position = def.position
|
||||
i = i +1
|
||||
end
|
||||
end
|
||||
|
@ -96,27 +96,27 @@ function Scoreboard:new(def)
|
|||
if def.sub_txt_elems then
|
||||
local i = 1
|
||||
for name, elem in pairs(def.sub_txt_elems) do
|
||||
scoreboard.sub_txt_elems[i] = name
|
||||
scoreboard[name] = clone_table(scoreboard.title_def)
|
||||
panel.sub_txt_elems[i] = name
|
||||
panel[name] = clone_table(panel.title_def)
|
||||
|
||||
for param, v in pairs(elem) do
|
||||
scoreboard[name][param] = v
|
||||
panel[name][param] = v
|
||||
end
|
||||
|
||||
-- idem come sopra
|
||||
scoreboard[name].position = def.position
|
||||
panel[name].position = def.position
|
||||
i = i +1
|
||||
end
|
||||
end
|
||||
|
||||
-- salvo in memoria
|
||||
scoreboard_lib.scoreboards[def.player] = scoreboard
|
||||
return scoreboard
|
||||
panel_lib.panels[def.player] = panel
|
||||
return panel
|
||||
end
|
||||
|
||||
|
||||
|
||||
function Scoreboard:show()
|
||||
function Panel:show()
|
||||
local player = minetest.get_player_by_name(self.player_name)
|
||||
self.hud_id.bg_hud_id = player:hud_add(self.background_def)
|
||||
self.hud_id.text_hud_id = player:hud_add(self.title_def)
|
||||
|
@ -133,7 +133,7 @@ end
|
|||
|
||||
|
||||
|
||||
function Scoreboard:hide()
|
||||
function Panel:hide()
|
||||
|
||||
if (self.hud_id) then
|
||||
local player = minetest.get_player_by_name(self.player_name)
|
||||
|
@ -146,7 +146,7 @@ end
|
|||
|
||||
|
||||
|
||||
function Scoreboard:update(def, txt_elems, img_elems)
|
||||
function Panel:update(def, txt_elems, img_elems)
|
||||
|
||||
if def ~= nil then
|
||||
for k, v in pairs(def) do
|
||||
|
@ -177,8 +177,8 @@ end
|
|||
|
||||
|
||||
|
||||
function Scoreboard:remove()
|
||||
scoreboard_lib.scoreboards[self.player_name] = nil
|
||||
function Panel:remove()
|
||||
panel_lib.panels[self.player_name] = nil
|
||||
self:hide()
|
||||
self = nil
|
||||
end
|
||||
|
@ -189,8 +189,8 @@ end
|
|||
-----------------GETTERS----------------------
|
||||
----------------------------------------------
|
||||
|
||||
function scoreboard_lib.get_scoreboard(p_name)
|
||||
return scoreboard_lib.scoreboards[p_name]
|
||||
function panel_lib.get_panel(p_name)
|
||||
return panel_lib.panels[p_name]
|
||||
end
|
||||
|
||||
|
||||
|
|
4
init.lua
4
init.lua
|
@ -1,3 +1,3 @@
|
|||
scoreboard_lib = {}
|
||||
panel_lib = {}
|
||||
|
||||
dofile(minetest.get_modpath("scoreboard_lib") .. "/api.lua")
|
||||
dofile(minetest.get_modpath("panel_lib") .. "/api.lua")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
player = "singleplayer",
|
||||
position = { x = 1, y = 0.5 },
|
||||
alignment = { x = -1, y = 0 },
|
||||
bg = "scoreboard_bg.png"
|
||||
bg = "panel_bg.png"
|
||||
bg_scale = { x = 45, y = 28 },
|
||||
title = "Default",
|
||||
title_alignment = { x = 0, y = 0 },
|
Before Width: | Height: | Size: 99 B After Width: | Height: | Size: 99 B |
Loading…
Reference in New Issue