Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
5 changed files with 54 additions and 5 deletions
Showing only changes of commit 42fbda0c58 - Show all commits

View file

@ -56,18 +56,18 @@ end
function GuiElement:getFocus()
local gui = self:getGui()
gui.focusedMenu = self.name
gui.focusedElement = self.name
end
function GuiElement:haveFocus()
local gui = self:getGui()
return (gui.focusedMenu == self.name)
return (gui.focusedElement == self.name)
end
function GuiElement:looseFocus()
if (self:haveFocus()) then
local gui = self:getGui()
gui.focusedMenu = nil
gui.focusedElement = nil
end
end
@ -97,7 +97,13 @@ function GuiElement:newMovement(start, duration, x, y, easing)
end
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
-- DRAW FUNCTIONS

View file

@ -67,6 +67,8 @@ function Gui:transformOne(rawTransform)
self:newMovement(transform.name, transform.start, transform.duration, transform.x, transform.y, transform.easing)
elseif transform.type == "switch" then
self:newSwitch(transform.name, transform.start, transform.bools)
elseif transform.type == "delayFocus" then
self:delayFocus(transform.name, transform.start)
end
end
@ -82,6 +84,26 @@ function Gui:newSwitch(element, start, bools)
self.elements[element]:newSwitch(start, bools)
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 the menu and its content

View file

@ -2,7 +2,7 @@ local ElementList = Object:extend()
function ElementList:initElements()
self.elements = {}
self.focusedElem = nil
self.focusedElement = nil
self.nbrElement = 0
end
@ -16,6 +16,25 @@ function ElementList:deleteElement(name)
self.elements[name] = nil
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)
local visibleList = {}
for _, element in pairs(self.elements) do

View file

@ -107,6 +107,7 @@ function Scene:updateMenus(dt)
if (self.menusystem ~= nil) then
self.menusystem:update(dt)
if (core.screen:isActive() and (self.dialog == nil)) then
self.gui:keycheck(self:getKeys(1))
self.menusystem:keycheck()
end
end

View file

@ -2,4 +2,5 @@ return {
tween = {"name", "type", "start", "duration", "target", "easing"},
movement = {"name", "type", "start", "duration", "x", "y", "easing"},
switch = {"name", "type", "start", "bools"},
delayFocus = {"name", "type", "start"},
}