diff --git a/DOCS.md b/DOCS.md index 3bdc580..30de84e 100644 --- a/DOCS.md +++ b/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 :) diff --git a/README.md b/README.md index 49df06a..cff5064 100644 --- a/README.md +++ b/README.md @@ -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 Support my work @@ -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) \ No newline at end of file +[Quake](https://gitlab.com/zughy-friends-minetest/minetest-quake) diff --git a/api.lua b/api.lua index f21a7d3..176ad48 100644 --- a/api.lua +++ b/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 diff --git a/init.lua b/init.lua index 1d4370f..0681251 100644 --- a/init.lua +++ b/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") diff --git a/mod.conf b/mod.conf deleted file mode 100644 index c5837c2..0000000 --- a/mod.conf +++ /dev/null @@ -1 +0,0 @@ -name = scoreboard_lib diff --git a/scoreboard.example b/panel.example similarity index 95% rename from scoreboard.example rename to panel.example index 4220ed1..1f46d4a 100644 --- a/scoreboard.example +++ b/panel.example @@ -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 }, diff --git a/textures/scoreboard_bg.png b/textures/panel_bg.png similarity index 100% rename from textures/scoreboard_bg.png rename to textures/panel_bg.png