implement a generic UIElement constructor
This commit is contained in:
parent
12d57892be
commit
c741bf3952
@ -3,10 +3,8 @@ local Rect = require "lib.simple_ui.rect"
|
|||||||
--- @class UIElement
|
--- @class UIElement
|
||||||
--- @field bounds Rect Прямоугольник, в границах которого размещается элемент. Размеры и положение в *локальных* координатах
|
--- @field bounds Rect Прямоугольник, в границах которого размещается элемент. Размеры и положение в *локальных* координатах
|
||||||
--- @field transform love.Transform Преобразование из локальных координат элемента (bounds) в экранные координаты
|
--- @field transform love.Transform Преобразование из локальных координат элемента (bounds) в экранные координаты
|
||||||
local uiElement = {
|
---
|
||||||
bounds = Rect {},
|
local uiElement = {}
|
||||||
transform = love.math.newTransform()
|
|
||||||
}
|
|
||||||
uiElement.__index = uiElement
|
uiElement.__index = uiElement
|
||||||
|
|
||||||
function uiElement:update(dt) end
|
function uiElement:update(dt) end
|
||||||
@ -18,4 +16,14 @@ function uiElement:hitTest(screenX, screenY)
|
|||||||
return self.bounds:hasPoint(lx, ly)
|
return self.bounds:hasPoint(lx, ly)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @generic T : UIElement
|
||||||
|
--- @param values table
|
||||||
|
--- @param self T
|
||||||
|
--- @return T
|
||||||
|
function uiElement.new(self, values)
|
||||||
|
values.bounds = values.bounds or Rect {}
|
||||||
|
values.transform = values.transform or love.math.newTransform()
|
||||||
|
return setmetatable(values, self)
|
||||||
|
end
|
||||||
|
|
||||||
return uiElement
|
return uiElement
|
||||||
|
|||||||
@ -12,12 +12,6 @@ local Rect = require "lib.simple_ui.rect"
|
|||||||
local skillButton = setmetatable({}, Element)
|
local skillButton = setmetatable({}, Element)
|
||||||
skillButton.__index = skillButton
|
skillButton.__index = skillButton
|
||||||
|
|
||||||
function skillButton.new(icon)
|
|
||||||
return setmetatable({
|
|
||||||
icon = icon
|
|
||||||
}, skillButton)
|
|
||||||
end
|
|
||||||
|
|
||||||
function skillButton:update(dt)
|
function skillButton:update(dt)
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = love.mouse.getPosition()
|
||||||
if self:hitTest(mx, my) then
|
if self:hitTest(mx, my) then
|
||||||
@ -77,7 +71,7 @@ function skillRow.new(characterId)
|
|||||||
local char = Tree.level.characters[characterId]
|
local char = Tree.level.characters[characterId]
|
||||||
char:try(Tree.behaviors.spellcaster, function(behavior)
|
char:try(Tree.behaviors.spellcaster, function(behavior)
|
||||||
for i, spell in ipairs(behavior.spellbook) do
|
for i, spell in ipairs(behavior.spellbook) do
|
||||||
local skb = skillButton.new(spell.tag)
|
local skb = skillButton:new { icon = spell.tag }
|
||||||
skb.onClick = function()
|
skb.onClick = function()
|
||||||
skb.selected = not skb.selected
|
skb.selected = not skb.selected
|
||||||
if t.selected then t.selected.selected = false end
|
if t.selected then t.selected.selected = false end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user