feat: add switching from main/character menu

Fix #53
This commit is contained in:
Kazhnuz 2020-08-23 10:40:06 +02:00
parent 1136bc1fd6
commit 722c69d733
3 changed files with 26 additions and 6 deletions

View file

@ -86,9 +86,7 @@ function ListBox:keyreleased(key, code)
end end
if key == "B" then if key == "B" then
if (self.widget.cancel >= 1 and self.widget.cancel <= #self.widget.list) then self:cancelAction()
self.widget.list[self.widget.cancel]:action("key")
end
end end
end end

View file

@ -126,7 +126,7 @@ end
-- Send actions to the widgets -- Send actions to the widgets
function Menu:cancelAction() function Menu:cancelAction()
if (self.widget.cancel ~= 0) then if (self.widget.cancel >= 1 and self.widget.cancel <= #self.widget.list) then
self.widget.list[self.widget.cancel]:action("key") self.widget.list[self.widget.cancel]:action("key")
end end
end end

View file

@ -10,8 +10,10 @@ local menu = require "game.modules.menus.fancy"
local baseMenu = require "game.modules.menus.parents.menu" local baseMenu = require "game.modules.menus.parents.menu"
local baseWidget = require "game.modules.menus.parents.widget" local baseWidget = require "game.modules.menus.parents.widget"
local CharacterMenu = baseMenu:extend()
local CharacterWidget = baseWidget:extend() local CharacterWidget = baseWidget:extend()
local TeamWidget = menu.BaseWidget:extend()
--local PauseMenu = --local PauseMenu =
function PauseScreen:new(scene) function PauseScreen:new(scene)
@ -20,7 +22,7 @@ end
function PauseScreen:setMenu() function PauseScreen:setMenu()
menu.FancyMenu(self.scene, "main", 16, 48, 128, 8, false) menu.FancyMenu(self.scene, "main", 16, 48, 128, 8, false)
menu.BaseWidget(self.scene, "main", "Team", ">") TeamWidget(self.scene)
menu.BaseWidget(self.scene, "main", "Quest", ">") menu.BaseWidget(self.scene, "main", "Quest", ">")
menu.BaseWidget(self.scene, "main", "Items", ">") menu.BaseWidget(self.scene, "main", "Items", ">")
menu.BaseWidget(self.scene, "main", "Chao", ">") menu.BaseWidget(self.scene, "main", "Chao", ">")
@ -29,7 +31,7 @@ function PauseScreen:setMenu()
menu.BaseWidget(self.scene, "main", "Save / Exit", ">") menu.BaseWidget(self.scene, "main", "Save / Exit", ">")
menu.BaseWidget(self.scene, "main", "Resume", ">") menu.BaseWidget(self.scene, "main", "Resume", ">")
baseMenu(self.scene, "character", 168, 40, 248, 168, 4) CharacterMenu(self.scene)
CharacterWidget(self.scene, "sonic") CharacterWidget(self.scene, "sonic")
CharacterWidget(self.scene, "tails") CharacterWidget(self.scene, "tails")
CharacterWidget(self.scene, "amy") CharacterWidget(self.scene, "amy")
@ -42,6 +44,15 @@ function PauseScreen:draw()
self.scene.assets.fonts["SA2font"]:print("MAIN MENU", 158, 16) self.scene.assets.fonts["SA2font"]:print("MAIN MENU", 158, 16)
end end
-- Character menu
function CharacterMenu:new(scene)
CharacterMenu.super.new(self, scene, "character", 168, 40, 248, 168, 4)
end
function CharacterMenu:cancelAction()
self.scene.menusystem.menus["main"]:getFocus()
end
-- Hero custom widget -- Hero custom widget
-- --
function CharacterWidget:new(scene, name) function CharacterWidget:new(scene, name)
@ -74,4 +85,15 @@ function CharacterWidget:draw(x, y)
end end
end end
-- Team Widget
--
function TeamWidget:new(scene)
TeamWidget.super.new(self, scene, "main", "Team", ">")
end
function TeamWidget:action()
self.scene.menusystem.menus["character"]:getFocus()
end
return PauseScreen return PauseScreen