improvement: port the debug menu to the new framework

This commit is contained in:
Kazhnuz 2020-08-19 20:44:38 +02:00
parent 625123813c
commit 78fca02441
6 changed files with 53 additions and 128 deletions

View file

@ -1,12 +1,10 @@
local menu = {} local menu = {}
local ListBox = require "core.modules.menusystem.listbox" local RadianceListMenu = require "game.modules.menus.list"
local Widget = require "core.modules.menusystem.widgets" local Widget = require "core.modules.menusystem.widgets"
menu.DebugMenu = ListBox:extend() menu.DebugMenu = RadianceListMenu.ListMenu:extend()
menu.DebugWidget = Widget.Text:extend() menu.SceneWidget = RadianceListMenu.DualTextWidget:extend()
menu.SubMenuWidget = menu.DebugWidget:extend()
menu.SceneWidget = menu.DebugWidget:extend()
local CONST = {} local CONST = {}
CONST.MENU = {} CONST.MENU = {}
@ -14,18 +12,29 @@ CONST.MENU.X = 16
CONST.MENU.Y = 48 CONST.MENU.Y = 48
CONST.MENU.W = 424/2 CONST.MENU.W = 424/2
CONST.MENU.ITEM_NUMBER = 8 CONST.MENU.ITEM_NUMBER = 8
CONST.MENU.ITEM_HEIGHT = 18
-- Basic menu structure -- Basic menu structure
function menu.DebugMenu:new(scene, name) function menu.DebugMenu:new(scene, name)
self.scene = scene
local x, y = CONST.MENU.X, CONST.MENU.Y local x, y = CONST.MENU.X, CONST.MENU.Y
local w, h = CONST.MENU.W, CONST.MENU.ITEM_NUMBER * CONST.MENU.ITEM_HEIGHT local w = CONST.MENU.W
menu.DebugMenu.super.new(self, scene.menusystem, name, x, y, w, h, CONST.MENU.ITEM_NUMBER) local itemNumber = CONST.MENU.ITEM_NUMBER
menu.DebugMenu.super.new(self, scene, name, x, y, w, itemNumber, false)
end end
function menu.DebugMenu:drawCursor() function menu.DebugMenu:setPanel(panel, panelArgument)
self.panel = panel
self.panelArgument = panelArgument
end
function menu.DebugMenu:activationAction()
print("test")
if (self.panel ~= nil) then
self.scene.panel = self.panel(self.panelArgument)
end
end
function menu.DebugMenu:clone(name)
return menu.DebugMenu(self.scene, name)
end end
function menu.DebugMenu:draw() function menu.DebugMenu:draw()
@ -35,38 +44,9 @@ function menu.DebugMenu:draw()
menu.DebugMenu.super.draw(self) menu.DebugMenu.super.draw(self)
end end
-- Widget
function menu.DebugWidget:new(scene, menu_name, label)
local font = scene.assets.fonts["small"]
self.scene = scene
local widgetMenu = scene.menusystem.menus[menu_name]
menu.DebugWidget.super.new(self, widgetMenu, font, label)
end
function menu.DebugWidget:drawCanvas()
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
self.font:draw(self.label, 8, h, -1, "left")
end
function menu.DebugWidget:drawSelected(x, y, w, h)
love.graphics.setColor(1, 1, 0, 1)
self:draw(x, y, w, h)
utils.graphics.resetColor()
end
-- SubMenuWidget
function menu.SubMenuWidget:new(scene, menu_name, newmenu, name)
menu.SubMenuWidget.super.new(self, scene, menu_name, name)
self.newmenu = newmenu or "BaseMenu"
end
function menu.SubMenuWidget:action()
self.scene.menusystem:switchMenu(self.newmenu)
end
-- SceneWidget -- SceneWidget
function menu.SceneWidget:new(scene, menuName, newScene, newSceneName, sceneArgument) function menu.SceneWidget:new(scene, menuName, newScene, newSceneName, sceneArgument)
menu.SceneWidget.super.new(self, scene, menuName, newSceneName) menu.SceneWidget.super.new(self, scene, menuName, newSceneName, "")
self.newScene = newScene self.newScene = newScene
self.sceneArgument = sceneArgument self.sceneArgument = sceneArgument
end end

View file

@ -18,6 +18,7 @@ function DebugMenu:new()
menu.commons.SceneWidget(self, "BaseMenu", scenes.options, "Options") menu.commons.SceneWidget(self, "BaseMenu", scenes.options, "Options")
menu.ExitWidget(self, "BaseMenu") menu.ExitWidget(self, "BaseMenu")
self.menusystem.menus["BaseMenu"]:finalize()
self.menusystem:activate() self.menusystem:activate()
self.menusystem:switchMenu("BaseMenu") self.menusystem:switchMenu("BaseMenu")
@ -27,7 +28,6 @@ end
function DebugMenu:buildOverworldMenu() function DebugMenu:buildOverworldMenu()
self:addSubMenu("overworld", "BaseMenu", "Overworld") self:addSubMenu("overworld", "BaseMenu", "Overworld")
menu.commons.SceneWidget(self, "overworld", scenes.overworld, "Launch Overworld") menu.commons.SceneWidget(self, "overworld", scenes.overworld, "Launch Overworld")
menu.commons.SubMenuWidget(self, "overworld", "BaseMenu", "Back")
end end
function DebugMenu:buildBattleMenu() function DebugMenu:buildBattleMenu()
@ -41,9 +41,6 @@ function DebugMenu:buildBattleMenu()
menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.battleBack, "Background Viewer") menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.battleBack, "Background Viewer")
menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.choregraphy, "Ennemies' Action Viewer") menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.choregraphy, "Ennemies' Action Viewer")
menu.commons.SubMenuWidget(self, "combat", "BaseMenu", "Back")
menu.commons.SubMenuWidget(self, "launchBattle", "combat", "Back")
end end
function DebugMenu:addBattles(battleCat) function DebugMenu:addBattles(battleCat)
@ -54,13 +51,11 @@ function DebugMenu:addBattles(battleCat)
local data = battleutils.getBattleData(battleCat, battleName) local data = battleutils.getBattleData(battleCat, battleName)
menu.commons.SceneWidget(self, menuName, scenes.cbs, "Launch " .. battleName, data) menu.commons.SceneWidget(self, menuName, scenes.cbs, "Launch " .. battleName, data)
end end
menu.commons.SubMenuWidget(self, menuName, "launchBattle", "Back")
end end
function DebugMenu:buildSaveMenu() function DebugMenu:buildSaveMenu()
self:addSubMenu("save", "BaseMenu", "Save System") self:addSubMenu("save", "BaseMenu", "Save System", panels.Gamedata, nil)
self:addSubMenu("characters", "save", "Characters") self:addSubMenu("characters", "save", "Characters", panels.Gamedata, nil)
self:addSubMenu("team", "save", "Team Formation", panels.Team, nil) self:addSubMenu("team", "save", "Team Formation", panels.Team, nil)
menu.ChangeLeaderWidget(self, "team") menu.ChangeLeaderWidget(self, "team")
for name, data in pairs(game.characters.list) do for name, data in pairs(game.characters.list) do
@ -75,18 +70,11 @@ function DebugMenu:buildSaveMenu()
menu.LoadWidget(self, "load", i) menu.LoadWidget(self, "load", i)
end end
menu.SaveWidget(self, "save") menu.SaveWidget(self, "save")
menu.commons.SubMenuWidget(self, "save", "BaseMenu", "Back")
menu.commons.SubMenuWidget(self, "characters", "save", "Back")
menu.commons.SubMenuWidget(self, "load", "save", "Back")
menu.SubMenuWidget(self, "team", "save", "Back", panels.Gamedata, nil)
end end
function DebugMenu:addCharacterMenu(name, data) function DebugMenu:addCharacterMenu(name, data)
self:addSubMenu(name, "characters", data.fullname, panels.Character, data) self:addSubMenu(name, "characters", data.fullname, panels.Character, data)
menu.LevelUpWidget(self, name, data) menu.LevelUpWidget(self, name, data)
menu.SubMenuWidget(self, name, "characters", "Back", panels.Gamedata, nil)
end end
function DebugMenu:addInventory() function DebugMenu:addInventory()
@ -96,9 +84,7 @@ function DebugMenu:addInventory()
for j, item in ipairs(itemutils.getItemsFromCategory(pocket.name)) do for j, item in ipairs(itemutils.getItemsFromCategory(pocket.name)) do
menu.ItemWidget(self, pocket.name, itemutils.getItemData(pocket.name, item)) menu.ItemWidget(self, pocket.name, itemutils.getItemData(pocket.name, item))
end end
menu.commons.SubMenuWidget(self, pocket.name, "inventory", "Back")
end end
menu.commons.SubMenuWidget(self, "inventory", "save", "Back")
end end
function DebugMenu:buildOtherMenu() function DebugMenu:buildOtherMenu()
@ -112,9 +98,6 @@ function DebugMenu:buildOtherMenu()
end end
menu.commons.SceneWidget(self, "other", scenes.test2, "Shadow Shot Maps") menu.commons.SceneWidget(self, "other", scenes.test2, "Shadow Shot Maps")
menu.commons.SubMenuWidget(self, "battle", "other", "Back")
menu.commons.SubMenuWidget(self, "other", "BaseMenu", "Back")
end end
@ -126,11 +109,9 @@ end
function DebugMenu:addSubMenu(submenu, parent, name, panel, panelArgument) function DebugMenu:addSubMenu(submenu, parent, name, panel, panelArgument)
local parent = parent or "BaseMenu" local parent = parent or "BaseMenu"
menu.commons.DebugMenu(self, submenu) self.menusystem.menus[parent]:addSubMenu(submenu, name)
if (panel == nil) then if (panel ~= nil) then
menu.commons.SubMenuWidget(self, parent, submenu, name .. " >") self.menusystem.menus[submenu]:setPanel(panel, panelArgument)
else
menu.SubMenuWidget(self, parent, submenu, name .. " >", panel, panelArgument)
end end
end end

View file

@ -1,37 +1,28 @@
local commons = require "scenes.debug.commons.menu" local commons = require "scenes.debug.commons.menu"
local listMenu = require "game.modules.menus.list"
local menu = {} local menu = {}
menu.commons = commons menu.commons = commons
menu.ExitWidget = commons.DebugWidget:extend() menu.ExitWidget = listMenu.DualTextWidget:extend()
menu.ShowBackgroundWidget = commons.DebugWidget:extend() menu.SaveWidget = listMenu.DualTextWidget:extend()
menu.SaveWidget = commons.DebugWidget:extend() menu.LoadWidget = listMenu.DualTextWidget:extend()
menu.LoadWidget = commons.DebugWidget:extend() menu.LevelUpWidget = listMenu.DualTextWidget:extend()
menu.LevelUpWidget = commons.DebugWidget:extend() menu.AddRemoveWidget = listMenu.DualTextWidget:extend()
menu.AddRemoveWidget = commons.DebugWidget:extend() menu.ChangeLeaderWidget = listMenu.DualTextWidget:extend()
menu.ChangeLeaderWidget = commons.DebugWidget:extend() menu.ItemWidget = listMenu.DualTextWidget:extend()
menu.SubMenuWidget = commons.SubMenuWidget:extend()
menu.ItemWidget = commons.DebugWidget:extend()
-- ExitWidget -- ExitWidget
function menu.ExitWidget:new(scene, menuName) function menu.ExitWidget:new(scene, menuName)
menu.ExitWidget.super.new(self, scene, menuName, "Exit") menu.ExitWidget.super.new(self, scene, menuName, "Exit", "")
end end
function menu.ExitWidget:action() function menu.ExitWidget:action()
love.event.quit("000") love.event.quit("000")
end end
-- ShowBackground
function menu.ShowBackgroundWidget:new(scene, menuName)
menu.ShowBackgroundWidget.super.new(self, scene, menuName, "Show Background")
end
function menu.ShowBackgroundWidget:action()
self.scene.menusystem:deactivate()
end
-- Save game -- Save game
function menu.SaveWidget:new(scene, menuName) function menu.SaveWidget:new(scene, menuName)
menu.SaveWidget.super.new(self, scene, menuName, "Save game") menu.SaveWidget.super.new(self, scene, menuName, "Save game", "")
end end
function menu.SaveWidget:action() function menu.SaveWidget:action()
@ -40,7 +31,7 @@ end
-- Save game -- Save game
function menu.LoadWidget:new(scene, menuName, slot) function menu.LoadWidget:new(scene, menuName, slot)
menu.LoadWidget.super.new(self, scene, menuName, "Load file " .. slot) menu.LoadWidget.super.new(self, scene, menuName, "Load file ", slot)
self.slot = slot self.slot = slot
end end
@ -48,21 +39,9 @@ function menu.LoadWidget:action()
game:read(self.slot) game:read(self.slot)
end end
-- Submenu
function menu.SubMenuWidget:new(scene, menu_name, newmenu, name, panel, panelArgument)
menu.SubMenuWidget.super.new(self, scene, menu_name, newmenu, name)
self.panel = panel
self.panelArgument = panelArgument
end
function menu.SubMenuWidget:action()
self.scene.menusystem:switchMenu(self.newmenu)
self.scene.panel = self.panel(self.panelArgument)
end
-- Level Up -- Level Up
function menu.LevelUpWidget:new(scene, menuName, character) function menu.LevelUpWidget:new(scene, menuName, character)
menu.ShowBackgroundWidget.super.new(self, scene, menuName, "Level Up") menu.LevelUpWidget.super.new(self, scene, menuName, "Levelup to", character.level + 1)
self.character = character self.character = character
end end
@ -72,7 +51,7 @@ end
-- Add Remove Widget -- Add Remove Widget
function menu.AddRemoveWidget:new(scene, menuName, character) function menu.AddRemoveWidget:new(scene, menuName, character)
menu.AddRemoveWidget.super.new(self, scene, menuName, "Add/Remove " .. character.name) menu.AddRemoveWidget.super.new(self, scene, menuName, "Add/Remove", character.name)
self.character = character self.character = character
end end
@ -82,7 +61,7 @@ end
--Change Team Leader --Change Team Leader
function menu.ChangeLeaderWidget:new(scene, menuName) function menu.ChangeLeaderWidget:new(scene, menuName)
menu.ShowBackgroundWidget.super.new(self, scene, menuName, "Change active character") menu.ChangeLeaderWidget.super.new(self, scene, menuName, "Change active character", "")
end end
function menu.ChangeLeaderWidget:action() function menu.ChangeLeaderWidget:action()
@ -91,7 +70,7 @@ end
-- ItemWidget -- ItemWidget
function menu.ItemWidget:new(scene, menuName, itemdata) function menu.ItemWidget:new(scene, menuName, itemdata)
menu.ItemWidget.super.new(self, scene, menuName, itemdata.fullname) menu.ItemWidget.super.new(self, scene, menuName, itemdata.fullname, "")
self.category = menuName self.category = menuName
self.itemName = itemdata.name self.itemName = itemdata.name
end end
@ -101,5 +80,4 @@ function menu.ItemWidget:action()
end end
return menu return menu

View file

@ -1,11 +1,12 @@
local commons = require "scenes.debug.commons.menu" local commons = require "scenes.debug.commons.menu"
local listMenu = require "game.modules.menus.list"
local menu = {} local menu = {}
menu.commons = commons menu.commons = commons
menu.ShowBackgroundWidget = menu.commons.DebugWidget:extend() menu.ShowBackgroundWidget = listMenu.DualTextWidget:extend()
-- ShowBackground -- ShowBackground
function menu.ShowBackgroundWidget:new(scene, menuName, backgroundName, backgroundId) function menu.ShowBackgroundWidget:new(scene, menuName, backgroundName, backgroundId)
menu.ShowBackgroundWidget.super.new(self, scene, menuName, backgroundName) menu.ShowBackgroundWidget.super.new(self, scene, menuName, backgroundName, "")
self.backgroundId = backgroundId self.backgroundId = backgroundId
end end

View file

@ -23,6 +23,7 @@ function ChoregraphyViewer:buildMenu()
self:buildCharacterMenu() self:buildCharacterMenu()
self.menusystem.menus["MainMenu"]:finalize()
self.menusystem:activate() self.menusystem:activate()
self.menusystem:switchMenu("MainMenu") self.menusystem:switchMenu("MainMenu")
menu.commons.SceneWidget(self, "MainMenu", scenes.debug.menu, "Back") menu.commons.SceneWidget(self, "MainMenu", scenes.debug.menu, "Back")
@ -38,9 +39,7 @@ function ChoregraphyViewer:buildCharacterMenu()
self:addSubMenu(k, "characters", character.fullname) self:addSubMenu(k, "characters", character.fullname)
menu.HeroChoregraphyWidget(self, k, game.skills:getSkillData("attack")) menu.HeroChoregraphyWidget(self, k, game.skills:getSkillData("attack"))
self:buildSkillMenu(k) self:buildSkillMenu(k)
menu.commons.SubMenuWidget(self, k, "characters", "Back")
end end
menu.commons.SubMenuWidget(self, "characters", "MainMenu", "Back")
end end
function ChoregraphyViewer:buildEnnemyListMenu(category) function ChoregraphyViewer:buildEnnemyListMenu(category)
@ -48,7 +47,6 @@ function ChoregraphyViewer:buildEnnemyListMenu(category)
for i,ennemy in ipairs(ennutils.getEnnemiesFromCategory(category)) do for i,ennemy in ipairs(ennutils.getEnnemiesFromCategory(category)) do
self:buildEnnemySkillMenu(category, ennemy) self:buildEnnemySkillMenu(category, ennemy)
end end
menu.commons.SubMenuWidget(self, category, "MainMenu", "Back")
end end
function ChoregraphyViewer:buildEnnemySkillMenu(category, ennemy) function ChoregraphyViewer:buildEnnemySkillMenu(category, ennemy)
@ -59,7 +57,6 @@ function ChoregraphyViewer:buildEnnemySkillMenu(category, ennemy)
menu.EnnemyChoregraphyWidget(self, category, ennemy, game.skills:getEnnemySkillData(skillName)) menu.EnnemyChoregraphyWidget(self, category, ennemy, game.skills:getEnnemySkillData(skillName))
end end
end end
menu.commons.SubMenuWidget(self, ennemy, category, "Back")
end end
function ChoregraphyViewer:buildSkillMenu(charName) function ChoregraphyViewer:buildSkillMenu(charName)
@ -78,8 +75,7 @@ end
function ChoregraphyViewer:addSubMenu(submenu, parent, name) function ChoregraphyViewer:addSubMenu(submenu, parent, name)
local parent = parent or "MainMenu" local parent = parent or "MainMenu"
menu.commons.DebugMenu(self, submenu) self.menusystem.menus[parent]:addSubMenu(submenu, name)
menu.commons.SubMenuWidget(self, parent, submenu, name .. " >")
end end
-- MOCKS FUNCTIONS -- MOCKS FUNCTIONS

View file

@ -1,24 +1,13 @@
local commons = require "scenes.debug.commons.menu" local commons = require "scenes.debug.commons.menu"
local listMenu = require "game.modules.menus.list"
local menu = {} local menu = {}
menu.commons = commons menu.commons = commons
menu.ShowBackgroundWidget = menu.commons.DebugWidget:extend() menu.HeroChoregraphyWidget = listMenu.DualTextWidget:extend()
menu.HeroChoregraphyWidget = commons.DebugWidget:extend() menu.EnnemyChoregraphyWidget = listMenu.DualTextWidget:extend()
menu.EnnemyChoregraphyWidget = commons.DebugWidget: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
-- ShowBackground -- ShowBackground
function menu.HeroChoregraphyWidget:new(scene, charName, skillData) function menu.HeroChoregraphyWidget:new(scene, charName, skillData)
menu.HeroChoregraphyWidget.super.new(self, scene, charName, skillData.name) menu.HeroChoregraphyWidget.super.new(self, scene, charName, skillData.name, "")
self.character = charName self.character = charName
self.skillData = skillData self.skillData = skillData
end end
@ -30,7 +19,7 @@ end
-- ShowBackground -- ShowBackground
function menu.EnnemyChoregraphyWidget:new(scene, category, charName, skillData) function menu.EnnemyChoregraphyWidget:new(scene, category, charName, skillData)
menu.EnnemyChoregraphyWidget.super.new(self, scene, charName, skillData.name) menu.EnnemyChoregraphyWidget.super.new(self, scene, charName, skillData.name, "")
self.category = category self.category = category
self.character = charName self.character = charName
self.skillData = skillData self.skillData = skillData