From 722c69d733ce41357855b7431a98f27a2cae7cb5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 23 Aug 2020 10:40:06 +0200 Subject: [PATCH] feat: add switching from main/character menu Fix #53 --- .../core/modules/menusystem/listbox.lua | 4 +-- .../core/modules/menusystem/parent.lua | 2 +- .../overworld/screens/mainmenu/pause.lua | 26 +++++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/sonic-radiance.love/core/modules/menusystem/listbox.lua b/sonic-radiance.love/core/modules/menusystem/listbox.lua index 10e4f85..c2e51c8 100644 --- a/sonic-radiance.love/core/modules/menusystem/listbox.lua +++ b/sonic-radiance.love/core/modules/menusystem/listbox.lua @@ -86,9 +86,7 @@ function ListBox:keyreleased(key, code) end if key == "B" then - if (self.widget.cancel >= 1 and self.widget.cancel <= #self.widget.list) then - self.widget.list[self.widget.cancel]:action("key") - end + self:cancelAction() end end diff --git a/sonic-radiance.love/core/modules/menusystem/parent.lua b/sonic-radiance.love/core/modules/menusystem/parent.lua index 4cf9380..4ee3fff 100644 --- a/sonic-radiance.love/core/modules/menusystem/parent.lua +++ b/sonic-radiance.love/core/modules/menusystem/parent.lua @@ -126,7 +126,7 @@ end -- Send actions to the widgets 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") end end diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua index f9948ee..cac7211 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/pause.lua @@ -10,8 +10,10 @@ local menu = require "game.modules.menus.fancy" local baseMenu = require "game.modules.menus.parents.menu" local baseWidget = require "game.modules.menus.parents.widget" +local CharacterMenu = baseMenu:extend() local CharacterWidget = baseWidget:extend() +local TeamWidget = menu.BaseWidget:extend() --local PauseMenu = function PauseScreen:new(scene) @@ -20,7 +22,7 @@ end function PauseScreen:setMenu() 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", "Items", ">") 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", "Resume", ">") - baseMenu(self.scene, "character", 168, 40, 248, 168, 4) + CharacterMenu(self.scene) CharacterWidget(self.scene, "sonic") CharacterWidget(self.scene, "tails") CharacterWidget(self.scene, "amy") @@ -42,6 +44,15 @@ function PauseScreen:draw() self.scene.assets.fonts["SA2font"]:print("MAIN MENU", 158, 16) 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 -- function CharacterWidget:new(scene, name) @@ -74,4 +85,15 @@ function CharacterWidget:draw(x, y) 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