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
10 changed files with 64 additions and 21 deletions
Showing only changes of commit 6c55a070fe - Show all commits

View file

@ -138,6 +138,7 @@ end
-- Draw the whole game
function CoreSystem:draw()
self.scenemanager:redraw()
self.scenemanager:draw()
end

View file

@ -127,4 +127,8 @@ function SceneManager:draw()
self.controller.screen:cease()
end
function SceneManager:redraw()
self.currentScene:redraw()
end
return SceneManager

View file

@ -20,9 +20,6 @@ end
function CanvasElement:updateElement(dt)
CanvasElement.super.updateElement(self, dt)
if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:redraw()
end
end
function CanvasElement:getCanvasDimensions()
@ -30,6 +27,12 @@ function CanvasElement:getCanvasDimensions()
end
function CanvasElement:redraw()
if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:generateTexture()
end
end
function CanvasElement:generateTexture()
local w, h = self:getDimensions()
local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2))

View file

@ -110,6 +110,10 @@ end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function GuiElement:redraw()
end
function GuiElement:drawElement()
self:draw()
end

View file

@ -162,6 +162,12 @@ end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function Gui:redraw()
for _, element in pairs(self.elements) do
element:redraw()
end
end
function Gui:drawTop()
for _, element in ipairs(self:getVisibleElement(true)) do
element:drawElement()

View file

@ -185,5 +185,12 @@ function MenuModel:moveCursor(relative)
page:moveCursor(relative)
end
-- DRAW
-- Draw widget
function MenuModel:redraw()
local page = self:getCurrentPage()
page:redraw()
end
return MenuModel

View file

@ -189,5 +189,11 @@ function Page:moveCursor(relative)
self:moveCursorAbsolute(self.selected + relative)
end
-- DRAW
function Page:redraw()
for _, widget in ipairs(self.widgets) do
widget:redraw()
end
end
return Page

View file

@ -169,6 +169,11 @@ function Menu:drawWidgetBackground(x, y, w, h)
end
function Menu:redraw()
self.widget:redraw()
Menu.super.redraw(self)
end
-- WIDGET FUNCTIONS
-- Handle widgets of the functions

View file

@ -73,7 +73,13 @@ function BaseWidget:register()
self.menu:addWidget(self)
end
function BaseWidget:redrawCanvas()
function BaseWidget:redraw()
if (self.canvas.needRedraw) then
self:generateTexture()
end
end
function BaseWidget:generateTexture()
self.width, self.height = self.menu:getWidgetSize(self.id)
local canvas = love.graphics.newCanvas(self.width, self.height)
@ -134,9 +140,6 @@ end
-- Update the widget
function BaseWidget:update(dt)
if (self.canvas.needRedraw) then
self:redrawCanvas()
end
-- N/A
end

View file

@ -149,6 +149,10 @@ end
-- DRAW FUNCTIONS
-- Draw the scene and its content
function Scene:redraw()
self.gui:redraw()
end
function Scene:drawScene()
self:drawStart()
self:drawWorld()