Refonte pour utiliser le systeme de GUI #112
2 changed files with 22 additions and 3 deletions
|
@ -10,7 +10,7 @@ function GuiElement:new(name, x, y, w, h)
|
||||||
self.isVisible = true
|
self.isVisible = true
|
||||||
self.screen = nil
|
self.screen = nil
|
||||||
|
|
||||||
self.depth = 0
|
self.depth = 10
|
||||||
|
|
||||||
self.tweens = TweenManager(self)
|
self.tweens = TweenManager(self)
|
||||||
self.assets = self:getAssets()
|
self.assets = self:getAssets()
|
||||||
|
@ -62,7 +62,7 @@ end
|
||||||
|
|
||||||
function GuiElement:getFocus()
|
function GuiElement:getFocus()
|
||||||
local gui = self:getGui()
|
local gui = self:getGui()
|
||||||
gui.focusedElement = self.name
|
gui:setFocus(self.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GuiElement:haveFocus()
|
function GuiElement:haveFocus()
|
||||||
|
@ -73,7 +73,7 @@ end
|
||||||
function GuiElement:looseFocus()
|
function GuiElement:looseFocus()
|
||||||
if (self:haveFocus()) then
|
if (self:haveFocus()) then
|
||||||
local gui = self:getGui()
|
local gui = self:getGui()
|
||||||
gui.focusedElement = nil
|
gui:removeFocus()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ local ElementList = Object:extend()
|
||||||
function ElementList:initElements()
|
function ElementList:initElements()
|
||||||
self.elements = {}
|
self.elements = {}
|
||||||
self.focusedElement = nil
|
self.focusedElement = nil
|
||||||
|
self.lastFocused = nil
|
||||||
self.nbrElement = 0
|
self.nbrElement = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,10 +19,28 @@ end
|
||||||
|
|
||||||
function ElementList:setFocus(name)
|
function ElementList:setFocus(name)
|
||||||
assert(self:elementExists(name), "Element " .. name .. " doesn't exists")
|
assert(self:elementExists(name), "Element " .. name .. " doesn't exists")
|
||||||
|
self:storeLastFocus()
|
||||||
self.focusedElement = name
|
self.focusedElement = name
|
||||||
self.elements[name].isVisible = true
|
self.elements[name].isVisible = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ElementList:removeFocus()
|
||||||
|
self:storeLastFocus()
|
||||||
|
self.focusedElement = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function ElementList:storeLastFocus()
|
||||||
|
if (self.focusedElement ~= nil) then
|
||||||
|
self.lastFocused = self.focusedElement
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ElementList:setLastFocus()
|
||||||
|
if (self:elementExists(self.lastFocused)) then
|
||||||
|
self:setFocus(self.lastFocused)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function ElementList:elementExists(name)
|
function ElementList:elementExists(name)
|
||||||
return (self:getElement(name) ~= nil)
|
return (self:getElement(name) ~= nil)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue