Refonte pour utiliser le systeme de GUI #112

Merged
kazhnuz merged 102 commits from feat/gui into master 2022-01-06 19:15:16 +01:00
2 changed files with 27 additions and 247 deletions
Showing only changes of commit 35764021af - Show all commits

View file

@ -1,158 +1,15 @@
local Scene = require "game.scenes" local Scene = require "game.scenes"
local menu = require "scenes.menus.mainmenu.menu"
local DebugMenu = Scene:extend() 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 MenuBack = require "game.modules.gui.menuback"
local TweenManager = require "birb.classes.time" local MainMenu = require "scenes.menus.mainmenu.menu"
function DebugMenu:new() function DebugMenu:new()
DebugMenu.super.new(self) DebugMenu.super.new(self, true, true)
menu.commons.MainMenu(self, "BaseMenu") MainMenu()
menu.StartGameWidget(self, "BaseMenu") MenuBack()
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)
end end
return DebugMenu; return DebugMenu;

View file

@ -1,115 +1,38 @@
local commons = require "scenes.menus.commons.menu" local Parent = require "game.modules.gui.fancymenu"
local listMenu = require "game.modules.menus.fancy" local MainMenu = Parent:extend()
local defTransitions = require "birb.modules.transitions" local defTransitions = require "birb.modules.transitions"
local radTransitions = require "game.modules.transitions" local radTransitions = require "game.modules.transitions"
local menu = {} local MENU_X, MENU_Y = 24, 48
menu.commons = commons local MENU_W = 424/3
menu.ExitWidget = listMenu.BaseWidget:extend() local MENU_ITEM_NUMBER = 8
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()
function MainMenu:new()
-- TitleWidget MainMenu.super.new(self, "mainmenu", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, false)
function menu.StartGameWidget:new(scene, menuName) self:addItem("Launch game", "left", function() self:launchGame() end)
local str = "Start game" self:addItem("Options", "left", function() self:launchOptions() end)
if (game.exists) then self:addItem("Return to title", "left", function() self:returnToTitle() end, "back")
str = "Continue game" self:setCancelWidget()
end self:addItem("Exit game", "left", function() self:exitGame() end)
menu.TitleWidget.super.new(self, scene, menuName, str, "") self:getFocus()
end end
function menu.StartGameWidget:action() function MainMenu:launchGame()
self.scene.assets:playSFX("mSelect")
core.screen:startTransition(defTransitions.circle, defTransitions.default, function() scenes.overworld() end, 424/2, 240/2) 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 end
-- TitleWidget function MainMenu:launchOptions()
function menu.TitleWidget:new(scene, menuName) core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.options() end, 424/2, 240/2)
menu.TitleWidget.super.new(self, scene, menuName, "Return to Title", "")
end end
function menu.TitleWidget:action() function MainMenu:returnToTitle()
self.scene.assets:playSFX("mBack")
core.screen:startTransition(defTransitions.circle, radTransitions.borders, function() scenes.menus.title(true) end, 424/2, 240/2) core.screen:startTransition(defTransitions.circle, radTransitions.borders, function() scenes.menus.title(true) end, 424/2, 240/2)
end end
-- ExitWidget function MainMenu:exitGame()
function menu.ExitWidget:new(scene, menuName)
menu.ExitWidget.super.new(self, scene, menuName, "Exit", "")
end
function menu.ExitWidget:action()
self.scene.assets:playSFX("mSelect")
love.event.quit("000") love.event.quit("000")
end end
-- Save game return MainMenu
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