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 48 additions and 27 deletions
Showing only changes of commit ae13c1d5ae - Show all commits

View file

@ -33,6 +33,7 @@ local TransformDataStruct = require "birb.structures.tween"
function Gui:new(scene) function Gui:new(scene)
self.scene = scene self.scene = scene
self:reset() self:reset()
self.sfx = {}
end end
function Gui:reset() function Gui:reset()
@ -125,6 +126,23 @@ function Gui:showScreen(screenname)
self.screens[screenname]:show() self.screens[screenname]:show()
end end
-- SOUND FUNCTIONS
-- Handle SFX
function Gui:addSFX(guiName, sfxName)
self.sfx[guiName] = sfxName
end
function Gui:playSFX(type)
local sfxName = self.sfx[type]
if (sfxName ~= nil) then
local sfx = self.scene.assets.sfx[sfxName]
if (sfx ~= nil) then
sfx:play()
end
end
end
-- KEYBOARD FUNCTIONS -- KEYBOARD FUNCTIONS
-- Handle keyboard -- Handle keyboard

View file

@ -85,18 +85,22 @@ function FlowBox:moveByKeys(key)
local col, line = self.view:getCoord(self.widget:getSelected()) local col, line = self.view:getCoord(self.widget:getSelected())
if key == 'left' then if key == 'left' then
self:moveCursor2D(col - 1, line) self:moveCursor2D(col - 1, line)
self:playNavigationSound()
end end
if key == 'right' then if key == 'right' then
self:moveCursor2D(col + 1, line) self:moveCursor2D(col + 1, line)
self:playNavigationSound()
end end
if key == 'up' then if key == 'up' then
self:moveCursor2D(col, line - 1) self:moveCursor2D(col, line - 1)
self:playNavigationSound()
end end
if key == 'down' then if key == 'down' then
self:moveCursor2D(col, line + 1) self:moveCursor2D(col, line + 1)
self:playNavigationSound()
end end
end end

View file

@ -150,18 +150,22 @@ function GridBox:keyreleased(key, code)
local col, line = self.cursor.x, self.cursor.y local col, line = self.cursor.x, self.cursor.y
if key == 'left' then if key == 'left' then
self:moveCol(-1) self:moveCol(-1)
self:playNavigationSound()
end end
if key == 'right' then if key == 'right' then
self:moveCol(1) self:moveCol(1)
self:playNavigationSound()
end end
if key == 'up' then if key == 'up' then
self:moveLine(-1) self:moveLine(-1)
self:playNavigationSound()
end end
if key == 'down' then if key == 'down' then
self:moveLine(1) self:moveLine(1)
self:playNavigationSound()
end end
if key == "A" and self.widget:getSelected() <= self.widget:lenght() then if key == "A" and self.widget:getSelected() <= self.widget:lenght() then

View file

@ -60,10 +60,12 @@ end
function HListBox:moveByKeys(key, code) function HListBox:moveByKeys(key, code)
if key == 'left' then if key == 'left' then
self.widget:moveCursor(-1) self.widget:moveCursor(-1)
self:playNavigationSound()
end end
if key == 'right' then if key == 'right' then
self.widget:moveCursor(1) self.widget:moveCursor(1)
self:playNavigationSound()
end end
end end

View file

@ -60,10 +60,12 @@ end
function ListBox:moveByKeys(key) function ListBox:moveByKeys(key)
if key == 'up' then if key == 'up' then
self.widget:moveCursor(-1) self.widget:moveCursor(-1)
self:playNavigationSound()
end end
if key == 'down' then if key == 'down' then
self.widget:moveCursor(1) self.widget:moveCursor(1)
self:playNavigationSound()
end end
end end
@ -84,7 +86,6 @@ function ListBox:drawTexture()
local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber) local listWidget = self.widget:getList(self.view.firstSlot, self.view.slotNumber)
for _, widget in ipairs(listWidget) do for _, widget in ipairs(listWidget) do
print(self.canvas.padding, widgety)
widget:drawWidget(self.canvas.padding, widgety, self.w, self.widgetSize.h) widget:drawWidget(self.canvas.padding, widgety, self.w, self.widgetSize.h)
widgety = widgety + self.widgetSize.h widgety = widgety + self.widgetSize.h
end end
@ -95,7 +96,7 @@ function ListBox:getGraphicalCursorPosition()
local w, h = self:getWidgetSize() local w, h = self:getWidgetSize()
local y = (self.widget:getSelected() - self.view.firstSlot) * h local y = (self.widget:getSelected() - self.view.firstSlot) * h
return self.x,self.y + y, w, h return self.x - self.ox,self.y + y - self.oy, w, h
end end
return ListBox return ListBox

View file

@ -74,6 +74,7 @@ end
function Page:action(id, type) function Page:action(id, type)
if (self:widgetExist(id)) then if (self:widgetExist(id)) then
self.widgets[id]:action(type) self.widgets[id]:action(type)
self.widgets[id]:playSFX()
end end
end end

View file

@ -39,7 +39,6 @@ function Menu:new(name, x, y, w, h)
self.widgetSize = {} self.widgetSize = {}
self:updateWidgetSize() self:updateWidgetSize()
self:resetSound()
self:initCanvas() self:initCanvas()
end end
@ -141,7 +140,7 @@ end
-- UPDATE FUNCTIONS -- UPDATE FUNCTIONS
function Menu:updateElement(dt) function Menu:updateElement(dt)
self:update(dt) Menu.super.updateElement(self, dt)
self.widget:update(dt) self.widget:update(dt)
if (self.canvas.needRedraw or self.canvas.isAnimated) then if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:redraw() self:redraw()
@ -204,7 +203,6 @@ function Menu:setCursor(cursorid)
end end
function Menu:moveCursor(new_selected) function Menu:moveCursor(new_selected)
self:playNavigationSound()
self.widget:moveCursorAbsolute(new_selected) self.widget:moveCursorAbsolute(new_selected)
self.canvas.needRedraw = true self.canvas.needRedraw = true
end end
@ -212,25 +210,13 @@ end
-- SOUND FUNCTION -- SOUND FUNCTION
-- Handle SFX -- Handle SFX
function Menu:resetSound()
self.sound = {}
self.sound.active = false
self.sound.asset = nil
end
function Menu:setSoundFromSceneAssets(name)
self:setSound(self.menusystem.scene.assets:getWithType(name, "sfx"))
end
function Menu:setSound(soundasset)
self.sound.active = true
self.sound.asset = soundasset
end
function Menu:playNavigationSound() function Menu:playNavigationSound()
if self.sound.active == true then self:playSFX("navigate")
self.sound.asset:play() end
end
function Menu:playSFX(name)
local gui = self:getGui()
gui:playSFX(name)
end end
-- VIEW FUNCTIONS -- VIEW FUNCTIONS

View file

@ -42,6 +42,7 @@ function BaseWidget:new(menuName)
self.order = 0 self.order = 0
self:register() self:register()
self.func = nil self.func = nil
self.type = "select"
end end
function BaseWidget:setFunc(func) function BaseWidget:setFunc(func)
@ -106,9 +107,7 @@ function BaseWidget:drawCanvas()
end end
function BaseWidget:selectAction() function BaseWidget:selectAction()
if (self.func ~= nil) then -- Do nothing
self.func(self)
end
end end
-- DRAW WIDGETS -- DRAW WIDGETS
@ -152,8 +151,14 @@ end
-- ACTION FUNCTION -- ACTION FUNCTION
-- Functions to handle actions and selection. -- Functions to handle actions and selection.
function BaseWidget:playSFX()
self.menu:playSFX(self.type)
end
function BaseWidget:action(source) function BaseWidget:action(source)
--self:destroy() if (self.func ~= nil) then
self.func(self)
end
end end
function BaseWidget:destroy() function BaseWidget:destroy()