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
8 changed files with 41 additions and 50 deletions
Showing only changes of commit 4a84d2dc53 - Show all commits

View file

@ -2,8 +2,8 @@ local Parent = require "birb.modules.gui.elements.drawable"
local AssetElement = Parent:extend()
function AssetElement:new(name, assetType, assetName, x, y,r,sx,sy,ox,oy, opacity)
local gui = self:getGui()
local asset = gui.scene.assets[assetType][assetName]
self:initWrapper()
local asset = self.assets[assetType][assetName]
assert(asset ~= nil, assetName .. ' (' .. assetType .. ") doesn't exist")
AssetElement.super.new(self, name, asset, x, y,r,sx,sy,ox,oy, opacity)

View file

@ -24,7 +24,7 @@ end
function CompositeElement:update(dt)
for _, child in ipairs(self.children) do
local childElement = self.getGui().elements[child.name]
local childElement = self.gui.elements[child.name]
childElement.x = self.x + child.relx
childElement.y = self.y + child.rely
childElement.isVisible = self.isVisible

View file

@ -13,33 +13,27 @@ function GuiElement:new(name, x, y, w, h)
self.depth = 10
self.tweens = TweenManager(self)
self.assets = self:getAssets()
self:initWrapper()
self:register()
end
function GuiElement:initWrapper()
self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.gui = self.scene.gui
self.assets = self.scene.assets
end
function GuiElement:setKeyPressAction(func)
self.func = func
end
function GuiElement:getGui()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
return scene.gui
end
function GuiElement:getAssets()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
return scene.assets
end
function GuiElement:register()
local gui = self:getGui()
self.creationId = gui:addElement(self.name, self)
self.creationId = self.gui:addElement(self.name, self)
end
function GuiElement:destroy()
local gui = self:getGui()
gui:deleteElement(self.name)
self.gui:deleteElement(self.name)
if (self.screen ~= nil) then
self.screen:deleteElement(self.name)
end
@ -65,19 +59,16 @@ function GuiElement:setVisibility(visibility)
end
function GuiElement:getFocus()
local gui = self:getGui()
gui:setFocus(self.name)
self.gui:setFocus(self.name)
end
function GuiElement:haveFocus()
local gui = self:getGui()
return (gui.focusedElement == self.name)
return (self.gui.focusedElement == self.name)
end
function GuiElement:looseFocus()
if (self:haveFocus()) then
local gui = self:getGui()
gui:removeFocus()
self.gui:removeFocus()
end
end

View file

@ -2,11 +2,10 @@ local Parent = require "birb.modules.gui.elements.parent"
local TextElement = Parent:extend()
function TextElement:new(name, fontName, text, x, y, align)
self.text = text
local gui = self:getGui()
self.font = gui.scene.assets.fonts[fontName]
TextElement.super.new(self, name, x, y, 1, 1)
self.text = text
self.font = self.assets.fonts[fontName]
self.align = align
end

View file

@ -33,7 +33,9 @@ local menuUtils = require "birb.modules.gui.utils"
function Menu:new(name, x, y, w, h)
Menu.super.new(self, name, x, y, w, h)
self.menusystem = self:getGui()
--TODO: remove this
self.menusystem = self.gui
self.widget = MenuModel()
self.widgetSize = {}
@ -216,8 +218,7 @@ function Menu:playNavigationSound()
end
function Menu:playSFX(name)
local gui = self:getGui()
gui:playSFX(name)
self.gui:playSFX(name)
end
-- VIEW FUNCTIONS

View file

@ -26,9 +26,8 @@ local BaseWidget = Object:extend()
-- Initialize and configure the widget
function BaseWidget:new(menuName)
self.scene = self:getScene()
self:initWrapper()
self.menu = self:getMenuByName(menuName)
self.assets = self:getAssets()
self.destroyed = false
self.selectable = false
@ -45,25 +44,25 @@ function BaseWidget:new(menuName)
self.type = "select"
end
function BaseWidget:initWrapper()
self.scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.gui = self.scene.gui
self.assets = self.scene.assets
end
function BaseWidget:setFunc(func)
self.func = func
end
function BaseWidget:getMenuByName(name)
local gui = self:getGui()
assert(name ~= nil, "Name cant be nil")
return gui.elements[name]
return self.gui.elements[name]
end
function BaseWidget:getScene()
return core.scenemanager.nextScene or core.scenemanager.currentScene
end
function BaseWidget:getGui()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
return scene.gui
end
function BaseWidget:getAssets()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
return scene.assets

View file

@ -10,7 +10,8 @@ local elementDataStruct = require "birb.structures.elementData"
function GuiScreen:new(name, controller)
self.controller = controller or self:getGui()
self:initWrapper()
self.controller = controller or self.gui
self.name = name
self.isVisible = false
self.transforms = {}
@ -21,6 +22,13 @@ function GuiScreen:new(name, controller)
self.controller:addScreen(name, self)
end
function GuiScreen:initWrapper()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
self.scene = scene
self.gui = scene.gui
self.assets = scene.assets
end
function GuiScreen:update(dt)
self.tweens:update(dt)
for _, screen in pairs(self.screens) do
@ -56,13 +64,7 @@ function GuiScreen:addTransform(name, transform)
end
function GuiScreen:playTransform(name, delay)
local gui = self:getGui()
return gui:transform(self.transforms[name], delay)
end
function GuiScreen:getGui()
local scene = core.scenemanager.nextScene or core.scenemanager.currentScene
return scene.gui
return self.gui:transform(self.transforms[name], delay)
end
function GuiScreen:reset()

View file

@ -78,8 +78,7 @@ function ConfirmDialog:doAction(choice)
end
function ConfirmDialog:dismiss()
local guiSystem = self:getGui()
guiSystem:setLastFocus()
self.gui:setLastFocus()
self:destroy()
end