improvement: port the main menu to gui

This commit is contained in:
Kazhnuz 2021-09-16 21:00:39 +02:00
parent 0343c017d3
commit 35764021af
2 changed files with 27 additions and 247 deletions

View file

@ -1,158 +1,15 @@
local Scene = require "game.scenes"
local menu = require "scenes.menus.mainmenu.menu"
local DebugMenu = Scene:extend()
local panels = require "scenes.menus.mainmenu.infopanel"
local gui = require "game.modules.gui"
local MenuBack = require "game.modules.gui.menuback"
local TweenManager = require "birb.classes.time"
local MainMenu = require "scenes.menus.mainmenu.menu"
function DebugMenu:new()
DebugMenu.super.new(self)
menu.commons.MainMenu(self, "BaseMenu")
menu.StartGameWidget(self, "BaseMenu")
menu.commons.SceneWidget(self, "BaseMenu", scenes.menus.options, "Options")
self:buildDebugMenu()
menu.TitleWidget(self, "BaseMenu")
self.menusystem.menus["BaseMenu"]:setCancelWidget()
menu.ExitWidget(self, "BaseMenu")
self.menusystem.menus["BaseMenu"]:finalize()
self.menusystem:activate()
self.menusystem:switchMenu("BaseMenu")
self.menusystem:setSoundFromSceneAssets("mBeep")
self.panel = panels.Gamedata()
self.borderY = 30
self.borders = gui.newBorder(424, 30, 8)
self.backImage = love.graphics.newImage("assets/artworks/back.png")
self.back = MenuBack()
self.tweens = TweenManager(self)
end
function DebugMenu:buildDebugMenu()
if (core.debug.active) then
self:addSubMenu("debug", "BaseMenu", "Debug Menu")
self:buildBattleMenu()
--self:buildOverworldMenu()
self:buildSaveMenu()
self:buildOtherMenu()
end
end
function DebugMenu:buildOverworldMenu()
self:addSubMenu("overworld", "debug", "Overworld")
menu.commons.SceneWidget(self, "overworld", scenes.overworld, "Launch Overworld")
end
function DebugMenu:buildBattleMenu()
self:addSubMenu("combat", "debug", "Battle System")
self:addSubMenu("launchBattle", "combat", "Launch Battle")
local listCat = core.datas:getCategories("battles")
for i,battleCat in ipairs(listCat) do
self:addBattles(battleCat)
end
menu.commons.SceneWidget(self, "combat", scenes.menus.debug.battleBack, "Background Viewer")
menu.commons.SceneWidget(self, "combat", scenes.menus.debug.animation, "Animation Viewer")
menu.commons.SceneWidget(self, "combat", scenes.menus.debug.choregraphy, "Ennemies' Action Viewer")
end
function DebugMenu:addBattles(battleCat)
local menuName = "b_" .. battleCat
self:addSubMenu(menuName, "launchBattle", battleCat)
for i,battleName in ipairs(core.datas:getFromCategory("battles", battleCat)) do
local data = core.datas:get("battles", battleName)
menu.commons.SceneWidget(self, menuName, scenes.cbs, "Launch " .. battleName, data)
end
end
function DebugMenu:buildSaveMenu()
self:addSubMenu("save", "debug", "Save System", panels.Gamedata, nil)
self:addSubMenu("characters", "save", "Characters", panels.Gamedata, nil)
self:addSubMenu("team", "save", "Team Formation", panels.Team, nil)
menu.ChangeLeaderWidget(self, "team")
for name, data in pairs(game.characters.list) do
self:addCharacterMenu(name, data)
menu.AddRemoveWidget(self, "team", data)
end
self:addInventory()
self:addSubMenu("load", "save", "Load Saves")
for i=1, game.slotNumber do
menu.LoadWidget(self, "load", i)
end
menu.SaveWidget(self, "save")
end
function DebugMenu:addCharacterMenu(name, data)
self:addSubMenu(name, "characters", data.fullname, panels.Character, data)
menu.LevelUpWidget(self, name, data)
end
function DebugMenu:addInventory()
self:addSubMenu("inventory", "save", "Inventory")
for i,pocket in ipairs(game.loot.inventory) do
self:addSubMenu(pocket.name, "inventory", pocket.fullname)
for j, item in ipairs(core.datas:getFromCategory("items", pocket.name)) do
menu.ItemWidget(self, pocket.name, core.datas:get("items", item))
end
end
end
function DebugMenu:buildOtherMenu()
self:addSubMenu("other", "debug", "Other gameplay")
self:addSubMenu("battle", "other", "Sonic Battle Maps")
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
menu.commons.SceneWidget(self, "battle", scenes.test, trueName, name)
end
menu.commons.SceneWidget(self, "other", scenes.test2, "Shadow Shot Maps")
end
function DebugMenu:update(dt)
if (love.keyboard.isDown("space") and (not self.menusystem.isActive)) then
self.menusystem:activate()
end
self.back:update(dt)
self.tweens:update(dt)
end
function DebugMenu:addSubMenu(submenu, parent, name, panel, panelArgument)
local parent = parent or "BaseMenu"
self.menusystem.menus[parent]:addSubMenu(submenu, name)
if (panel ~= nil) then
--self.menusystem.menus[submenu]:setPanel(panel, panelArgument)
end
end
function DebugMenu:draw()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.rectangle("fill", 0, 0, 424, 240)
self.back:draw()
utils.graphics.resetColor()
love.graphics.draw(self.backImage, 0, 0)
if (self.menusystem.isActive) then
self.panel:draw(240, 48)
end
end
function DebugMenu:drawOverTransition()
love.graphics.draw(self.borders, 0, self.borderY, 0, 1, -1)
love.graphics.draw(self.borders, 424, 240 - self.borderY, 0, -1, 1)
self.assets.fonts["small"]:draw("v" .. game.version, 424 - 44, 240 + 10 - self.borderY)
DebugMenu.super.new(self, true, true)
MainMenu()
MenuBack()
end
return DebugMenu;

View file

@ -1,115 +1,38 @@
local commons = require "scenes.menus.commons.menu"
local listMenu = require "game.modules.menus.fancy"
local Parent = require "game.modules.gui.fancymenu"
local MainMenu = Parent:extend()
local defTransitions = require "birb.modules.transitions"
local radTransitions = require "game.modules.transitions"
local menu = {}
menu.commons = commons
menu.ExitWidget = listMenu.BaseWidget:extend()
menu.SaveWidget = listMenu.BaseWidget:extend()
menu.LoadWidget = listMenu.BaseWidget:extend()
menu.LevelUpWidget = listMenu.BaseWidget:extend()
menu.AddRemoveWidget = listMenu.BaseWidget:extend()
menu.ChangeLeaderWidget = listMenu.BaseWidget:extend()
menu.ItemWidget = listMenu.BaseWidget:extend()
menu.TitleWidget = listMenu.BaseWidget:extend()
menu.StartGameWidget = listMenu.BaseWidget:extend()
local MENU_X, MENU_Y = 24, 48
local MENU_W = 424/3
local MENU_ITEM_NUMBER = 8
-- TitleWidget
function menu.StartGameWidget:new(scene, menuName)
local str = "Start game"
if (game.exists) then
str = "Continue game"
end
menu.TitleWidget.super.new(self, scene, menuName, str, "")
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)
self:addItem("Options", "left", function() self:launchOptions() end)
self:addItem("Return to title", "left", function() self:returnToTitle() end, "back")
self:setCancelWidget()
self:addItem("Exit game", "left", function() self:exitGame() end)
self:getFocus()
end
function menu.StartGameWidget:action()
self.scene.assets:playSFX("mSelect")
function MainMenu:launchGame()
core.screen:startTransition(defTransitions.circle, defTransitions.default, function() scenes.overworld() end, 424/2, 240/2)
self.scene.tweens:newTween(0, 0.5, {borderY = 0}, "inOutQuart")
core.scenemanager.currentScene:hideOverlay()
end
-- TitleWidget
function menu.TitleWidget:new(scene, menuName)
menu.TitleWidget.super.new(self, scene, menuName, "Return to Title", "")
function MainMenu:launchOptions()
core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.options() end, 424/2, 240/2)
end
function menu.TitleWidget:action()
self.scene.assets:playSFX("mBack")
function MainMenu:returnToTitle()
core.screen:startTransition(defTransitions.circle, radTransitions.borders, function() scenes.menus.title(true) end, 424/2, 240/2)
end
-- ExitWidget
function menu.ExitWidget:new(scene, menuName)
menu.ExitWidget.super.new(self, scene, menuName, "Exit", "")
end
function menu.ExitWidget:action()
self.scene.assets:playSFX("mSelect")
function MainMenu:exitGame()
love.event.quit("000")
end
-- Save game
function menu.SaveWidget:new(scene, menuName)
menu.SaveWidget.super.new(self, scene, menuName, "Save game", "")
end
function menu.SaveWidget:action()
game:write()
end
-- Save game
function menu.LoadWidget:new(scene, menuName, slot)
menu.LoadWidget.super.new(self, scene, menuName, "Load file ", slot)
self.slot = slot
end
function menu.LoadWidget:action()
game:read(self.slot)
end
-- Level Up
function menu.LevelUpWidget:new(scene, menuName, character)
menu.LevelUpWidget.super.new(self, scene, menuName, "Levelup to", character.level + 1)
self.character = character
end
function menu.LevelUpWidget:action()
self.character:levelUp()
end
-- Add Remove Widget
function menu.AddRemoveWidget:new(scene, menuName, character)
menu.AddRemoveWidget.super.new(self, scene, menuName, "Add/Remove", character.name)
self.character = character
end
function menu.AddRemoveWidget:action()
game.characters:addOrRemoveToTeam(self.character.simplename)
end
--Change Team Leader
function menu.ChangeLeaderWidget:new(scene, menuName)
menu.ChangeLeaderWidget.super.new(self, scene, menuName, "Change active character", "")
end
function menu.ChangeLeaderWidget:action()
game.characters:setActiveCharacter(1)
end
-- ItemWidget
function menu.ItemWidget:new(scene, menuName, itemdata)
menu.ItemWidget.super.new(self, scene, menuName, itemdata.fullname, "")
self.category = menuName
self.itemName = itemdata.name
end
function menu.ItemWidget:action()
game.loot:addItem(self.category, self.itemName, 1)
end
return menu
return MainMenu