From e1ea505ca313271a820be8829367b135b241274d Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Wed, 3 Mar 2021 13:53:59 +0100 Subject: [PATCH] Add offset as parameter for panels and adjust sub-elements offset accordingly --- DOCS.md | 3 ++- api.lua | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/DOCS.md b/DOCS.md index 9d31588..9b16c60 100644 --- a/DOCS.md +++ b/DOCS.md @@ -12,12 +12,13 @@ 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) * `alignment`: same +* `offset`: same * `bg`: the picture to put in the background * `bg_scale`: its scaling * `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 * `title_alignment` -* `title_offset` +* `title_offset`: if `offset` is declared already, it'll add/subtract the two values * `title_color` * `visible`: (bool) whether the panel is visible right after its creation. Default is `true` * `sub_img_elems`: (table) whatever image to add to the panel diff --git a/api.lua b/api.lua index 6b9bf77..230d397 100644 --- a/api.lua +++ b/api.lua @@ -19,6 +19,7 @@ Panel = { position = { x = 1, y = 0.5 }, scale = { x = 1, y = 1 }, alignment = { x = -1, y = 0 }, + offset = {x = 0, y = 0}, text = "panel_bg.png", }, title_def = { @@ -75,6 +76,11 @@ function Panel:new(name, def) panel.background_def.alignment = def.alignment end + if def.offset then + panel.background_def.offset = def.offset + panel.title_def.offset = def.offset + end + if def.bg then panel.background_def.text = def.bg end @@ -92,7 +98,11 @@ function Panel:new(name, def) end if def.title_offset then - panel.title_def.offset = def.title_offset + if not def.offset then + panel.title_def.offset = def.title_offset + else + panel.title_def.offset = {x = panel.title_def.offset.x + (def.title_offset.x or 0), y = panel.title_def.offset.y + (def.title_offset.y or 0)} + end end if def.title_color then @@ -362,6 +372,11 @@ function add_sub_elem(panel, type, name, HUD_elem) -- l'utente a modificare gli offset se vuole spostare gli elementi panel[name].position = mould.position + -- se il pannello ha gli offset personalizzati e il sottoelemento pure, li sommo + if HUD_elem.offset and (panel.background_def.offset.x ~= 0 or panel.background_def.offset.y ~= 0) then + panel[name].offset = {x = panel.background_def.offset.x + (HUD_elem.offset.x or 0), y = panel.background_def.offset.y + (HUD_elem.offset.y or 0)} + end + -- mostro l'elemento se il pannello era giĆ  visibile panel[name].text = panel:is_visible() and panel[name].text or "" @@ -377,7 +392,11 @@ function update_sub_elems(panel, elems) for elem, _ in pairs(elems) do for k, v in pairs(elems[elem]) do - panel[elem][k] = v + if k == "offset" and (panel.background_def.offset.x ~= 0 or panel.background_def.offset.y ~= 0) then + panel[elem][k] = { x = panel.background_def.offset.x + (v.x or 0), y = panel.background_def.offset.y + (v.y or 0)} + else + panel[elem][k] = v + end if k == "text" then panel.hud_text[elem] = v