Refonte pour utiliser le systeme de GUI #112
5 changed files with 54 additions and 5 deletions
|
@ -56,18 +56,18 @@ end
|
||||||
|
|
||||||
function GuiElement:getFocus()
|
function GuiElement:getFocus()
|
||||||
local gui = self:getGui()
|
local gui = self:getGui()
|
||||||
gui.focusedMenu = self.name
|
gui.focusedElement = self.name
|
||||||
end
|
end
|
||||||
|
|
||||||
function GuiElement:haveFocus()
|
function GuiElement:haveFocus()
|
||||||
local gui = self:getGui()
|
local gui = self:getGui()
|
||||||
return (gui.focusedMenu == self.name)
|
return (gui.focusedElement == self.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GuiElement:looseFocus()
|
function GuiElement:looseFocus()
|
||||||
if (self:haveFocus()) then
|
if (self:haveFocus()) then
|
||||||
local gui = self:getGui()
|
local gui = self:getGui()
|
||||||
gui.focusedMenu = nil
|
gui.focusedElement = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,7 +97,13 @@ function GuiElement:newMovement(start, duration, x, y, easing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GuiElement:newSwitch(start, bools)
|
function GuiElement:newSwitch(start, bools)
|
||||||
self:newSwitch(start, bools)
|
self.tweens:newSwitch(start, bools)
|
||||||
|
end
|
||||||
|
|
||||||
|
function GuiElement:delayFocus(start)
|
||||||
|
self.tweens:newFunc(start, "focus", function ()
|
||||||
|
self:getFocus()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
|
|
|
@ -67,6 +67,8 @@ function Gui:transformOne(rawTransform)
|
||||||
self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing)
|
self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing)
|
||||||
elseif transform.type == "switch" then
|
elseif transform.type == "switch" then
|
||||||
self:newSwitch(transform.name, transform.start, transform.bools)
|
self:newSwitch(transform.name, transform.start, transform.bools)
|
||||||
|
elseif transform.type == "delayFocus" then
|
||||||
|
self:delayFocus(transform.name, transform.start)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,6 +84,26 @@ function Gui:newSwitch(element, start, bools)
|
||||||
self.elements[element]:newSwitch(start, bools)
|
self.elements[element]:newSwitch(start, bools)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Gui:delayFocus(element, start)
|
||||||
|
self.elements[element]:delayFocus(start)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- KEYBOARD FUNCTIONS
|
||||||
|
-- Handle keyboard
|
||||||
|
|
||||||
|
function Gui:keycheck(keys)
|
||||||
|
local haveFocus = self:haveFocus()
|
||||||
|
if (haveFocus) then
|
||||||
|
local elem = self:getFocusedElement()
|
||||||
|
for key,_ in pairs(keys) do
|
||||||
|
if keys[key].isPressed then
|
||||||
|
elem:keypressed(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return haveFocus
|
||||||
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the menu and its content
|
-- Draw the menu and its content
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ local ElementList = Object:extend()
|
||||||
|
|
||||||
function ElementList:initElements()
|
function ElementList:initElements()
|
||||||
self.elements = {}
|
self.elements = {}
|
||||||
self.focusedElem = nil
|
self.focusedElement = nil
|
||||||
self.nbrElement = 0
|
self.nbrElement = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,6 +16,25 @@ function ElementList:deleteElement(name)
|
||||||
self.elements[name] = nil
|
self.elements[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ElementList:elementExists(name)
|
||||||
|
return (self:getElement(name) ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ElementList:haveFocus()
|
||||||
|
return self:elementExists(self.focusedElement)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ElementList:getFocusedElement()
|
||||||
|
return self:getElement(self.focusedElement)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ElementList:getElement(name)
|
||||||
|
if (not utils.string.isEmpty(name)) then
|
||||||
|
return self.elements[name]
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
function ElementList:getVisibleElement(topLayer)
|
function ElementList:getVisibleElement(topLayer)
|
||||||
local visibleList = {}
|
local visibleList = {}
|
||||||
for _, element in pairs(self.elements) do
|
for _, element in pairs(self.elements) do
|
||||||
|
|
|
@ -107,6 +107,7 @@ function Scene:updateMenus(dt)
|
||||||
if (self.menusystem ~= nil) then
|
if (self.menusystem ~= nil) then
|
||||||
self.menusystem:update(dt)
|
self.menusystem:update(dt)
|
||||||
if (core.screen:isActive() and (self.dialog == nil)) then
|
if (core.screen:isActive() and (self.dialog == nil)) then
|
||||||
|
self.gui:keycheck(self:getKeys(1))
|
||||||
self.menusystem:keycheck()
|
self.menusystem:keycheck()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,5 @@ return {
|
||||||
tween = {"name", "type", "start", "duration", "target", "easing"},
|
tween = {"name", "type", "start", "duration", "target", "easing"},
|
||||||
movement = {"name", "type", "start", "duration", "x", "y", "easing"},
|
movement = {"name", "type", "start", "duration", "x", "y", "easing"},
|
||||||
switch = {"name", "type", "start", "bools"},
|
switch = {"name", "type", "start", "bools"},
|
||||||
|
delayFocus = {"name", "type", "start"},
|
||||||
}
|
}
|
Loading…
Reference in a new issue