feat: add more actions in menus
This commit is contained in:
parent
f7e1beae68
commit
a677902f6c
5 changed files with 80 additions and 3 deletions
|
@ -36,6 +36,7 @@ function ListBox:new(name, x, y, w, h, slotNumber)
|
||||||
ListBox.super.new(self, name, x, y, w, h)
|
ListBox.super.new(self, name, x, y, w, h)
|
||||||
self.h = slotNumber * self.widgetSize.h -- On fait en sorte que la hauteur
|
self.h = slotNumber * self.widgetSize.h -- On fait en sorte que la hauteur
|
||||||
-- soit un multiple du nombre de slot et de leur hauteur
|
-- soit un multiple du nombre de slot et de leur hauteur
|
||||||
|
self.lateralFunc = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- UPDATE FUNCTIONS
|
-- UPDATE FUNCTIONS
|
||||||
|
@ -54,6 +55,10 @@ function ListBox:resetView()
|
||||||
self.view:reset()
|
self.view:reset()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ListBox:addLateralAction(func)
|
||||||
|
self.lateralFunc = func
|
||||||
|
end
|
||||||
|
|
||||||
-- KEYBOARD FUNCTIONS
|
-- KEYBOARD FUNCTIONS
|
||||||
-- Handle input from keyboard/controllers.
|
-- Handle input from keyboard/controllers.
|
||||||
|
|
||||||
|
@ -69,6 +74,10 @@ function ListBox:moveByKeys(key)
|
||||||
self:playNavigationSound()
|
self:playNavigationSound()
|
||||||
self.canvas.needRedraw = true
|
self.canvas.needRedraw = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (self.lateralFunc ~= nil and (key == 'left' or key == 'right')) then
|
||||||
|
self.widget:lateralAction(self.lateralFunc, key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- POSITION FUNCTIONS
|
-- POSITION FUNCTIONS
|
||||||
|
|
|
@ -21,6 +21,7 @@ function MenuModel:new()
|
||||||
self.cancel = 0
|
self.cancel = 0
|
||||||
self.limit = -1
|
self.limit = -1
|
||||||
-- self:updateWidgetSize()
|
-- self:updateWidgetSize()
|
||||||
|
self.hoverFunc = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuModel:clear()
|
function MenuModel:clear()
|
||||||
|
@ -33,6 +34,7 @@ end
|
||||||
|
|
||||||
function MenuModel:addPage(pageName)
|
function MenuModel:addPage(pageName)
|
||||||
local page = Page()
|
local page = Page()
|
||||||
|
page.name = pageName
|
||||||
self.pages[pageName] = page
|
self.pages[pageName] = page
|
||||||
self.currentPage = pageName
|
self.currentPage = pageName
|
||||||
return page
|
return page
|
||||||
|
@ -58,6 +60,7 @@ end
|
||||||
function MenuModel:switch(pageName)
|
function MenuModel:switch(pageName)
|
||||||
if (self:pageExists(pageName)) then
|
if (self:pageExists(pageName)) then
|
||||||
self.currentPage = pageName
|
self.currentPage = pageName
|
||||||
|
self:hoverAction()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,6 +73,10 @@ function MenuModel:getCurrentPage()
|
||||||
return self:getPage(self.currentPage)
|
return self:getPage(self.currentPage)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MenuModel:getCurrentPageName()
|
||||||
|
return self.currentPage
|
||||||
|
end
|
||||||
|
|
||||||
-- UPDATE/DRAW FUNCTIONS
|
-- UPDATE/DRAW FUNCTIONS
|
||||||
-- All the update functions
|
-- All the update functions
|
||||||
|
|
||||||
|
@ -91,6 +98,10 @@ end
|
||||||
-- ACTION FUNCTIONS
|
-- ACTION FUNCTIONS
|
||||||
-- All the actions callback used by the widgets
|
-- All the actions callback used by the widgets
|
||||||
|
|
||||||
|
function MenuModel:addHoverAction(func)
|
||||||
|
self.hoverFunc = func
|
||||||
|
end
|
||||||
|
|
||||||
function MenuModel:cancelAction()
|
function MenuModel:cancelAction()
|
||||||
local page = self:getCurrentPage()
|
local page = self:getCurrentPage()
|
||||||
page:cancelAction()
|
page:cancelAction()
|
||||||
|
@ -106,6 +117,19 @@ function MenuModel:selectedAction()
|
||||||
page:selectedAction()
|
page:selectedAction()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MenuModel:hoverAction()
|
||||||
|
local page = self:getCurrentPage()
|
||||||
|
if (self.hoverFunc ~= nil) then
|
||||||
|
page:hoverAction(self.hoverFunc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function MenuModel:lateralAction(func, key)
|
||||||
|
local page = self:getCurrentPage()
|
||||||
|
page:lateralAction(func, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- WIDGET FUNCTIONS
|
-- WIDGET FUNCTIONS
|
||||||
-- All the functions to handle widgets
|
-- All the functions to handle widgets
|
||||||
|
|
||||||
|
@ -167,22 +191,29 @@ end
|
||||||
|
|
||||||
function MenuModel:trySelectWidget(cursorid)
|
function MenuModel:trySelectWidget(cursorid)
|
||||||
local page = self:getCurrentPage()
|
local page = self:getCurrentPage()
|
||||||
return page:trySelectWidget(cursorid)
|
local isSuccess = page:trySelectWidget(cursorid)
|
||||||
|
if (isSuccess) then
|
||||||
|
self:hoverAction()
|
||||||
|
end
|
||||||
|
return isSuccess
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuModel:setCursor(cursorid)
|
function MenuModel:setCursor(cursorid)
|
||||||
local page = self:getCurrentPage()
|
local page = self:getCurrentPage()
|
||||||
page:setCursor(cursorid)
|
page:setCursor(cursorid)
|
||||||
|
self:hoverAction()
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuModel:moveCursorAbsolute(newSelected)
|
function MenuModel:moveCursorAbsolute(newSelected)
|
||||||
local page = self:getCurrentPage()
|
local page = self:getCurrentPage()
|
||||||
page:moveCursorAbsolute(newSelected)
|
page:moveCursorAbsolute(newSelected)
|
||||||
|
self:hoverAction()
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuModel:moveCursor(relative)
|
function MenuModel:moveCursor(relative)
|
||||||
local page = self:getCurrentPage()
|
local page = self:getCurrentPage()
|
||||||
page:moveCursor(relative)
|
page:moveCursor(relative)
|
||||||
|
self:hoverAction()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DRAW
|
-- DRAW
|
||||||
|
|
|
@ -84,6 +84,18 @@ function Page:selectedAction()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Page:hoverAction(func)
|
||||||
|
if (self:widgetExist(self.selected)) then
|
||||||
|
func(self.widgets[self.selected])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Page:lateralAction(func, key)
|
||||||
|
if (self:widgetExist(self.selected)) then
|
||||||
|
func(key, self.widgets[self.selected], self.selected, self.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- WIDGET FUNCTIONS
|
-- WIDGET FUNCTIONS
|
||||||
-- All the functions to handle widgets
|
-- All the functions to handle widgets
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,18 @@ function Menu:new(name, x, y, w, h)
|
||||||
self:updateWidgetSize()
|
self:updateWidgetSize()
|
||||||
|
|
||||||
self:initCanvas()
|
self:initCanvas()
|
||||||
|
self.cancelFunc = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- FUNCTIONS FUNCTIONS
|
||||||
|
-- Add functions to the menu system
|
||||||
|
|
||||||
|
function Menu:addCancelAction(func)
|
||||||
|
self.cancelFunc = func
|
||||||
|
end
|
||||||
|
|
||||||
|
function Menu:addHoverAction(func)
|
||||||
|
self.widget:addHoverAction(func)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- INTERACTION FUNCTIONS
|
-- INTERACTION FUNCTIONS
|
||||||
|
@ -112,14 +124,20 @@ function Menu:getPage(pageName)
|
||||||
self.widget:getPage(pageName)
|
self.widget:getPage(pageName)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Menu:getCurrentPageName()
|
||||||
|
return self.widget:getCurrentPageName()
|
||||||
|
end
|
||||||
|
|
||||||
function Menu:switch(pageName)
|
function Menu:switch(pageName)
|
||||||
self.widget:switch(pageName)
|
self.widget:switch(pageName)
|
||||||
self:resetView()
|
self:resetView()
|
||||||
|
self.canvas.needRedraw = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Menu:back()
|
function Menu:back()
|
||||||
self.widget:back()
|
self.widget:back()
|
||||||
self:resetView()
|
self:resetView()
|
||||||
|
self.canvas.needRedraw = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function GuiElement:setSubFocus(widgetId, pageName)
|
function GuiElement:setSubFocus(widgetId, pageName)
|
||||||
|
@ -133,7 +151,11 @@ end
|
||||||
-- Send actions to the widgets
|
-- Send actions to the widgets
|
||||||
|
|
||||||
function Menu:cancelAction()
|
function Menu:cancelAction()
|
||||||
|
if (self.cancelFunc ~= nil) then
|
||||||
|
self.cancelFunc(self)
|
||||||
|
else
|
||||||
self.widget:cancelAction()
|
self.widget:cancelAction()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Menu:clear()
|
function Menu:clear()
|
||||||
|
|
|
@ -41,7 +41,7 @@ function TextMenu:new(name, font, x, y, w, slotNumber, padding, lineSize)
|
||||||
TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber)
|
TextMenu.super.new(self, name, x, y, w, (self.lineHeight * slotNumber), slotNumber)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextMenu:addItem(text, position, func, type, additionnalItems, color)
|
function TextMenu:addItem(text, position, func, type, additionnalItems, color, additionnalDatas)
|
||||||
local widget = TextMenu.baseWidgets.Base(self.name, text, position)
|
local widget = TextMenu.baseWidgets.Base(self.name, text, position)
|
||||||
widget:setFunc(func)
|
widget:setFunc(func)
|
||||||
widget.type = type or "select"
|
widget.type = type or "select"
|
||||||
|
@ -53,6 +53,9 @@ function TextMenu:addItem(text, position, func, type, additionnalItems, color)
|
||||||
if (color ~= nil) then
|
if (color ~= nil) then
|
||||||
widget:setColor(color[1], color[2], color[3])
|
widget:setColor(color[1], color[2], color[3])
|
||||||
end
|
end
|
||||||
|
if (additionnalDatas ~= nil) then
|
||||||
|
widget.datas = additionnalDatas
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidget)
|
function TextMenu:generateSubmenu(pageName, label, parent, list, func, backWidget)
|
||||||
|
|
Loading…
Reference in a new issue