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 -- Draw the whole game
function CoreSystem:draw() function CoreSystem:draw()
self.scenemanager:redraw()
self.scenemanager:draw() self.scenemanager:draw()
end end

View file

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

View file

@ -20,9 +20,6 @@ end
function CanvasElement:updateElement(dt) function CanvasElement:updateElement(dt)
CanvasElement.super.updateElement(self, dt) CanvasElement.super.updateElement(self, dt)
if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:redraw()
end
end end
function CanvasElement:getCanvasDimensions() function CanvasElement:getCanvasDimensions()
@ -30,6 +27,12 @@ function CanvasElement:getCanvasDimensions()
end end
function CanvasElement:redraw() 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 w, h = self:getDimensions()
local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2)) 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 FUNCTIONS
-- Draw the menu and its content -- Draw the menu and its content
function GuiElement:redraw()
end
function GuiElement:drawElement() function GuiElement:drawElement()
self:draw() self:draw()
end end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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