From 11e028e0e95ca9ee8f81c267f95a0ccf0c6745ca Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 6 Jan 2022 14:34:45 +0100 Subject: [PATCH] improvement: port the debug menu to gui --- .../scenes/battlesystem/init.lua | 2 +- .../menus/debugmenus/animation/init.lua | 43 +++---- .../menus/debugmenus/animation/menu.lua | 19 --- .../menus/debugmenus/battleBack/init.lua | 27 ++--- .../menus/debugmenus/battleBack/menu.lua | 19 --- .../menus/debugmenus/choregraphy/init.lua | 61 ++++------ .../menus/debugmenus/choregraphy/menu.lua | 34 ------ .../scenes/menus/debugmenus/commons/scene.lua | 36 ++++++ .../scenes/menus/debugmenus/init.lua | 112 ++++++++++++++++++ sonic-radiance.love/scenes/menus/init.lua | 1 + .../scenes/menus/mainmenu/menu.lua | 7 ++ .../scenes/menus/options/const.lua | 5 + .../scenes/menus/options/init.lua | 2 - .../scenes/menus/options/menu.lua | 8 +- 14 files changed, 212 insertions(+), 164 deletions(-) delete mode 100644 sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua delete mode 100644 sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua delete mode 100644 sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua create mode 100644 sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua create mode 100644 sonic-radiance.love/scenes/menus/debugmenus/init.lua create mode 100644 sonic-radiance.love/scenes/menus/options/const.lua diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 43c0713..bc8be04 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -13,7 +13,7 @@ local CbsScreen = require "scenes.battlesystem.gui" local TweenManager = require "birb.classes.time" function BattleSystem:new(battleData) - BattleSystem.super.new(self) + BattleSystem.super.new(self, false, false) self.assets:batchImport("assets.battle") self:playMusic(battleData.music) diff --git a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua index 023f999..0f08f0a 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/animation/init.lua @@ -1,35 +1,28 @@ -local Scene = require "game.scenes" -local menu = require "scenes.menus.debugmenus.animation.menu" +local Scene = require "scenes.menus.debugmenus.commons.scene" local CharAnimViewer = Scene:extend() local Background = require "game.modules.drawing.parallaxBackground" local Sprite = require "birb.modules.assets.types.sprites" - function CharAnimViewer:new() CharAnimViewer.super.new(self) - self.assets:batchImport("assets.debug") - local mainMenu = menu.commons.DebugMenu(self, "MainMenu") - - self:setBackground("city") - - for charName, _ in pairs(game.characters.list) do - mainMenu:addSubMenu(charName, charName) - local sprite = Sprite("datas/gamedata/characters/" .. charName .. "/sprites") - for animName, _ in pairs(sprite.data.animations) do - menu.AnimationWidget(self, charName, animName) - end - end - menu.commons.SceneWidget(self, "MainMenu", scenes.menus.main, "Back") - - self.menusystem:activate() - self.menusystem:switchMenu("MainMenu") + self.background = Background(self, 5, 1, "city") self.sprite = nil end -function CharAnimViewer:constructMenu() - +function CharAnimViewer:initMenu() + for charName, _ in pairs(game.characters.list) do + self.menu:addSubmenu(charName, charName, "main", true) + self.menu:switch(charName) + local sprite = Sprite("datas/gamedata/characters/" .. charName .. "/sprites") + for animName, _ in pairs(sprite.data.animations) do + self.menu:addItem(animName, "left", function() + self:setSpriteAndAnim(charName, animName) + self:hideMenu() + end, "select") + end + end end function CharAnimViewer:setSpriteAndAnim(character, animationName) @@ -39,18 +32,12 @@ end function CharAnimViewer:update(dt) - if (love.keyboard.isDown("z") and (not self.menusystem.isActive)) then - self.menusystem:activate() - end + CharAnimViewer.super.update(self,dt) if (self.sprite ~= nil) then self.sprite:update(dt) end end -function CharAnimViewer:setBackground(newBackground) - self.background = Background(self, 5, 1, newBackground) -end - function CharAnimViewer:draw() self.background:draw() if (self.sprite ~= nil) then diff --git a/sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua b/sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua deleted file mode 100644 index 1fe81b5..0000000 --- a/sonic-radiance.love/scenes/menus/debugmenus/animation/menu.lua +++ /dev/null @@ -1,19 +0,0 @@ -local commons = require "scenes.menus.commons.menu" -local listMenu = require "game.modules.menus.list" -local menu = {} -menu.commons = commons -menu.AnimationWidget = listMenu.DualTextWidget:extend() - --- ShowBackground -function menu.AnimationWidget:new(scene, menuName, animName) - menu.AnimationWidget.super.new(self, scene, menuName, animName, "") - self.charName = menuName - self.animName = animName -end - -function menu.AnimationWidget:action() - self.scene:setSpriteAndAnim(self.charName, self.animName) - self.scene.menusystem:deactivate() -end - -return menu diff --git a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua index 7928d32..25fcb0c 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/init.lua @@ -1,31 +1,20 @@ -local Scene = require "game.scenes" -local menu = require "scenes.menus.debugmenus.battleBack.menu" - +local Scene = require "scenes.menus.debugmenus.commons.scene" local BackgroundViewer = Scene:extend() + local Background = require "game.modules.drawing.parallaxBackground" local backgroundList = require "datas.gamedata.maps.shoot.zones" - function BackgroundViewer:new() BackgroundViewer.super.new(self) - self.assets:batchImport("assets.debug") - menu.commons.DebugMenu(self, "MainMenu") - self:setBackground("city") - - for backId, backgroundData in pairs(backgroundList) do - menu.ShowBackgroundWidget(self, "MainMenu", backgroundData.name, backId) - end - menu.commons.SceneWidget(self, "MainMenu", scenes.menus.main, "Back") - - self.menusystem:activate() - self.menusystem:switchMenu("MainMenu") end - -function BackgroundViewer:update(dt) - if (love.keyboard.isDown("z") and (not self.menusystem.isActive)) then - self.menusystem:activate() +function BackgroundViewer:initMenu() + for backId, backgroundData in pairs(backgroundList) do + self.menu:addItem(backgroundData.name, "left", function() + self:setBackground(backId) + self:hideMenu() + end, "select") end end diff --git a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua b/sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua deleted file mode 100644 index 9927170..0000000 --- a/sonic-radiance.love/scenes/menus/debugmenus/battleBack/menu.lua +++ /dev/null @@ -1,19 +0,0 @@ -local commons = require "scenes.menus.commons.menu" -local listMenu = require "game.modules.menus.list" -local menu = {} -menu.commons = commons -menu.ShowBackgroundWidget = listMenu.DualTextWidget:extend() - --- ShowBackground -function menu.ShowBackgroundWidget:new(scene, menuName, backgroundName, backgroundId) - menu.ShowBackgroundWidget.super.new(self, scene, menuName, backgroundName, "") - self.backgroundId = backgroundId -end - -function menu.ShowBackgroundWidget:action() - self.scene:setBackground(self.backgroundId) - self.scene.menusystem:deactivate() -end - - -return menu diff --git a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua index 8105301..3ae8f6e 100644 --- a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/init.lua @@ -1,6 +1,4 @@ -local Scene = require "game.scenes" -local menu = require "scenes.menus.debugmenus.choregraphy.menu" - +local Scene = require "scenes.menus.debugmenus.commons.scene" local ChoregraphyViewer = Scene:extend() local World = require "scenes.battlesystem.world" @@ -11,48 +9,34 @@ function ChoregraphyViewer:new() self.assets:batchImport("assets.battle") self.world = World(self) - self:buildMenu() self:buildMocks() end -- MENU FUNCTIONS -function ChoregraphyViewer:buildMenu() - menu.commons.DebugMenu(self, "MainMenu") - - self:buildCharacterMenu() - - self.menusystem.menus["MainMenu"]:finalize() - self.menusystem:activate() - self.menusystem:switchMenu("MainMenu") - menu.commons.SceneWidget(self, "MainMenu", scenes.menus.main, "Back") -end - -function ChoregraphyViewer:buildCharacterMenu() +function ChoregraphyViewer:initMenu() for i,category in ipairs(core.datas:getCategories("ennemies")) do - self:buildEnnemyListMenu(category) + self:buildEnnemyMenu(category) end - self:addSubMenu("characters", "MainMenu", "Rivals") + self.menu:addSubmenu("characters", "Rivals", "main", true) for k, character in pairs(game.characters.list) do - self:addSubMenu(k, "characters", character.fullname) - menu.HeroChoregraphyWidget(self, k, core.datas:get("skills", "attack")) + self.menu:addSubmenu(k, character.fullname, "characters") + self:addItem("rivals", k, core.datas:get("skills", "attack")) self:buildSkillMenu(k) end end -function ChoregraphyViewer:buildEnnemyListMenu(category) - self:addSubMenu(category, "MainMenu", category) - for i,ennemy in ipairs(core.datas.getFromCategory("ennemies", category)) do - self:buildEnnemySkillMenu(category, ennemy) - end -end +function ChoregraphyViewer:buildEnnemyMenu(category) + self.menu:addSubmenu(category, category, "main", true) -function ChoregraphyViewer:buildEnnemySkillMenu(category, ennemy) - self:addSubMenu(ennemy, category, ennemy) - local data = core.datas:get("ennemies", ennemy) - for j,skillName in ipairs(data.skills) do - if (core.datas:exists("badskills", skillName)) then - menu.EnnemyChoregraphyWidget(self, category, ennemy, core.datas:get("badskills", skillName)) + for i,ennemy in ipairs(core.datas:getFromCategory("ennemies", category)) do + self.menu:addSubmenu(ennemy, ennemy, category, true) + local data = core.datas:get("ennemies", ennemy) + + for j,skillName in ipairs(data.skills) do + if (core.datas:exists("badskills", skillName)) then + self:addItem(category, ennemy, core.datas:get("badskills", skillName)) + end end end end @@ -65,15 +49,14 @@ function ChoregraphyViewer:buildSkillMenu(charName) if (skillTreated[skillName] ~= true) then skillTreated[skillName] = true if (core.datas:exists("skills", skillName)) then - menu.HeroChoregraphyWidget(self, charName, core.datas:get("skills", skillName)) + self:addItem("rivals", charName, core.datas:get("skills", skillName)) end end end end -function ChoregraphyViewer:addSubMenu(submenu, parent, name) - local parent = parent or "MainMenu" - self.menusystem.menus[parent]:addSubMenu(submenu, name) +function ChoregraphyViewer:addItem(category, ennemy, data) + self.menu:addItem(data.name, "left", function() self:playEnnemyChoregraphy(category, ennemy, data) end, "select") end -- MOCKS FUNCTIONS @@ -86,7 +69,11 @@ function ChoregraphyViewer:playHeroChoregraphy(character, data) end function ChoregraphyViewer:playEnnemyChoregraphy(category, ennemy, data) - self.fighter:playEnnemyChoregraphy(category, ennemy, data) + if (category == "rivals") then + self.fighter:playHeroChoregraphy(ennemy, data) + else + self.fighter:playEnnemyChoregraphy(category, ennemy, data) + end end -- OTHER diff --git a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua b/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua deleted file mode 100644 index 9ef4fac..0000000 --- a/sonic-radiance.love/scenes/menus/debugmenus/choregraphy/menu.lua +++ /dev/null @@ -1,34 +0,0 @@ -local commons = require "scenes.menus.commons.menu" -local listMenu = require "game.modules.menus.list" -local menu = {} -menu.commons = commons -menu.HeroChoregraphyWidget = listMenu.DualTextWidget:extend() -menu.EnnemyChoregraphyWidget = listMenu.DualTextWidget:extend() - --- ShowBackground -function menu.HeroChoregraphyWidget:new(scene, charName, skillData) - menu.HeroChoregraphyWidget.super.new(self, scene, charName, skillData.name, "") - self.character = charName - self.skillData = skillData -end - -function menu.HeroChoregraphyWidget:action() - self.scene:playHeroChoregraphy(self.character, self.skillData) - self.scene.menusystem:deactivate() -end - --- ShowBackground -function menu.EnnemyChoregraphyWidget:new(scene, category, charName, skillData) - menu.EnnemyChoregraphyWidget.super.new(self, scene, charName, skillData.name, "") - self.category = category - self.character = charName - self.skillData = skillData -end - -function menu.EnnemyChoregraphyWidget:action() - self.scene:playEnnemyChoregraphy(self.category, self.character, self.skillData) - self.scene.menusystem:deactivate() -end - - -return menu diff --git a/sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua b/sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua new file mode 100644 index 0000000..19abdf6 --- /dev/null +++ b/sonic-radiance.love/scenes/menus/debugmenus/commons/scene.lua @@ -0,0 +1,36 @@ +local DebugScene = require("game.scenes"):extend() +local BoxedMenu = require("game.modules.gui.boxedmenu") + +local defTransitions = require "birb.modules.transitions" + +local CONST = { + MENU = {X = 16, Y = 48, W = (424/2)/ 1.5, ITEM_NUMBER = 8} +} + +function DebugScene:new() + DebugScene.super.new(self, false, false) + self.assets:batchImport("assets.debug") + self.menu = BoxedMenu("debugMenu", CONST.MENU.X, CONST.MENU.Y, CONST.MENU.W, CONST.MENU.ITEM_NUMBER, true, false) + self:initMenu() + self.menu:switch("main") + self.menu:addItem("Back", "left", function() + core.screen:startTransition(defTransitions.circle, defTransitions.default, function() scenes.menus.debug.menu() end, 424/2, 240/2) + end, "back") + self.gui:setFocus("debugMenu") +end + +function DebugScene:initMenu() + +end + +function DebugScene:hideMenu() + self.menu.isVisible = false +end + +function DebugScene:update(dt) + if (love.keyboard.isDown("z") and (not self.menu.isVisible)) then + self.menu.isVisible = true + end +end + +return DebugScene \ No newline at end of file diff --git a/sonic-radiance.love/scenes/menus/debugmenus/init.lua b/sonic-radiance.love/scenes/menus/debugmenus/init.lua new file mode 100644 index 0000000..737f8a9 --- /dev/null +++ b/sonic-radiance.love/scenes/menus/debugmenus/init.lua @@ -0,0 +1,112 @@ +local Scene = require "game.scenes" +local DebugMenu = Scene:extend() + +local MenuBack = require "game.modules.gui.menuback" +local BoxedMenu = require "game.modules.gui.boxedmenu" + +local const = require "scenes.menus.options.const" +local defTransitions = require "birb.modules.transitions" + +function DebugMenu:new(page, widgetId) + DebugMenu.super.new(self, true, true) + + local screenw, _ = core.screen:getDimensions() + self.menu = BoxedMenu("debugMenu", screenw/2, const.MENU_Y, const.MENU_W, const.MENU_ITEM_NUMBER, true) + MenuBack() + + self.menu.ox = const.MENU_W/2 + + self:rebuild() + + self.menu:switch(page or "main") + self.menu:setCursor(widgetId or 1) + self.gui:setFocus("debugMenu") +end + +function DebugMenu:rebuild() + self:buildBattleMenu() + self:buildSaveMenu() + self:buildOtherMenu() + self.menu:switch("main") + self.menu:addItem("Back", "left", function() self:changeScene(scenes.menus.main, nil, true) end, "back") + self.menu:setCancelWidget() +end + +function DebugMenu:buildBattleMenu() + self.menu:addSubmenu("combat", "Battle System", "main", true) + self.menu:addSubmenu("launchBattle", "Launch Battle", "combat", true) + + local listCat = core.datas:getCategories("battles") + + for i,battleCat in ipairs(listCat) do + local menuName = "b_" .. battleCat + + self.menu:addSubmenu(menuName, battleCat, "launchBattle", true) + + for j, battleName in ipairs(core.datas:getFromCategory("battles", battleCat)) do + local data = core.datas:get("battles", battleName) + self.menu:addItem("Launch " .. battleName, "left", function() self:changeScene(scenes.cbs, data, false) end, "select") + end + end + + self.menu:switch("combat") + + self.menu:addItem("Background Viewer ", "left", function() self:changeScene(scenes.menus.debug.battleBack, nil, false) end, "select") + self.menu:addItem("Animation Viewer ", "left", function() self:changeScene(scenes.menus.debug.animation, nil, false) end, "select") + self.menu:addItem("Ennemies' Action Viewer ", "left", function() self:changeScene(scenes.menus.debug.choregraphy, nil, false) end, "select") +end + + +function DebugMenu:buildSaveMenu() + self.menu:addSubmenu("characters", "Characters", "main", true) + self.menu:addSubmenu("team", "Team Formation", "characters", true) + + for name, data in pairs(game.characters.list) do + self.menu:switch("characters") + self:addCharacterMenu(name, data) + self.menu:switch("team") + self.menu:addItem(data.fullname, "left", function() + game.characters:addOrRemoveToTeam(name) + game:write() + end, "select") + end + + self:addInventory() +end + +function DebugMenu:addCharacterMenu(name, data) + self.menu:addSubmenu(name, data.fullname, "characters", true) + self.menu:addItem("Level Up", "left", function() data:levelUp() game:write() end, "select") +end + +function DebugMenu:addInventory() + self.menu:addSubmenu("inventory", "Inventory", "main", true) + for i,pocket in ipairs(game.loot.inventory) do + self.menu:addSubmenu(pocket.name, pocket.fullname, "inventory", true) + for j, item in ipairs(core.datas:getFromCategory("items", pocket.name)) do + local data = core.datas:get("items", item) + self.menu:addItem(data.fullname, "left", function() game.loot:addItem(pocket.name, item, 1) game:write() end, "select") + end + end +end + +function DebugMenu:buildOtherMenu() + self.menu:addSubmenu("other", "Other gameplay", "main", true) + self.menu:addItem("Shadow Shot Maps", "left", function() self:changeScene(scenes.test2, nil, false) end, "select") + self.menu:addSubmenu("battleMaps", "Sonic Battle Maps", "other", true) + + local mapList = require "datas.gamedata.maps.battle" + for i, name in ipairs(mapList) do + local mapData = require("datas.gamedata.maps.battle." .. name) + local trueName = mapData.name + self.menu:addItem(trueName, "left", function() self:changeScene(scenes.test, name, false) end, "select") + end + +end + +function DebugMenu:changeScene(scene, arg, useFade) + local trans2 = utils.math.either(useFade == true, defTransitions.default, defTransitions.circle) + core.screen:startTransition(defTransitions.default, trans2, function() scene(arg) end, 424/2, 240/2) +end + +return DebugMenu diff --git a/sonic-radiance.love/scenes/menus/init.lua b/sonic-radiance.love/scenes/menus/init.lua index 941170a..849e218 100644 --- a/sonic-radiance.love/scenes/menus/init.lua +++ b/sonic-radiance.love/scenes/menus/init.lua @@ -5,6 +5,7 @@ return { battleBack = require "scenes.menus.debugmenus.battleBack", choregraphy = require "scenes.menus.debugmenus.choregraphy", animation = require "scenes.menus.debugmenus.animation", + menu = require "scenes.menus.debugmenus" }, options = require "scenes.menus.options" } diff --git a/sonic-radiance.love/scenes/menus/mainmenu/menu.lua b/sonic-radiance.love/scenes/menus/mainmenu/menu.lua index d5d2f40..4743dd2 100644 --- a/sonic-radiance.love/scenes/menus/mainmenu/menu.lua +++ b/sonic-radiance.love/scenes/menus/mainmenu/menu.lua @@ -11,6 +11,9 @@ local MENU_ITEM_NUMBER = 8 function MainMenu:new() MainMenu.super.new(self, "mainmenu", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, false) self:addItem("Launch game", "left", function() self:launchGame() end) + if (core.debug.active) then + self:addItem("Debug Menu", "left", function() self:launchDebug() end) + end self:addItem("Options", "left", function() self:launchOptions() end) self:addItem("Return to title", "left", function() self:returnToTitle() end, "back") self:setCancelWidget() @@ -23,6 +26,10 @@ function MainMenu:launchGame() core.scenemanager.currentScene:hideOverlay() end +function MainMenu:launchDebug() + core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.debug.menu() end, 424/2, 240/2) +end + function MainMenu:launchOptions() core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.options() end, 424/2, 240/2) end diff --git a/sonic-radiance.love/scenes/menus/options/const.lua b/sonic-radiance.love/scenes/menus/options/const.lua new file mode 100644 index 0000000..ec7965a --- /dev/null +++ b/sonic-radiance.love/scenes/menus/options/const.lua @@ -0,0 +1,5 @@ +return { + MENU_Y = 48, + MENU_W = math.floor(424 / 1.5), + MENU_ITEM_NUMBER = 8 +} \ No newline at end of file diff --git a/sonic-radiance.love/scenes/menus/options/init.lua b/sonic-radiance.love/scenes/menus/options/init.lua index 7e4e7b4..9db0b13 100644 --- a/sonic-radiance.love/scenes/menus/options/init.lua +++ b/sonic-radiance.love/scenes/menus/options/init.lua @@ -2,8 +2,6 @@ local Scene = require "game.scenes" local OptionsMenu = Scene:extend() local OptionMenu = require "scenes.menus.options.menu" - -local gui = require "game.modules.gui" local MenuBack = require "game.modules.gui.menuback" function OptionsMenu:new() diff --git a/sonic-radiance.love/scenes/menus/options/menu.lua b/sonic-radiance.love/scenes/menus/options/menu.lua index 52614d1..0b5b622 100644 --- a/sonic-radiance.love/scenes/menus/options/menu.lua +++ b/sonic-radiance.love/scenes/menus/options/menu.lua @@ -11,14 +11,12 @@ local KeysWidget = TextMenuWidget:extend() local defTransitions = require "birb.modules.transitions" local ConfirmDialog = require "game.modules.confirmdialog" -local MENU_Y = 48 -local MENU_W = 424 / 1.5 -local MENU_ITEM_NUMBER = 8 +local const = require "scenes.menus.options.const" function MainMenu:new() local screenw, screenh = core.screen:getDimensions() - MainMenu.super.new(self, "optionMenu", screenw/2, MENU_Y, MENU_W, MENU_ITEM_NUMBER, true) - self.ox = MENU_W/2 + MainMenu.super.new(self, "optionMenu", screenw/2, const.MENU_Y, const.MENU_W, const.MENU_ITEM_NUMBER, true) + self.ox = const.MENU_W/2 self:addVideoMenu() self:addAudioMenu() self:addDifficultyMenu()