Add offset as parameter for panels and adjust sub-elements offset accordingly
This commit is contained in:
parent
c0268247fe
commit
e1ea505ca3
3
DOCS.md
3
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
|
||||
|
23
api.lua
23
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user