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
14 changed files with 212 additions and 164 deletions
Showing only changes of commit 11e028e0e9 - Show all commits

View file

@ -13,7 +13,7 @@ local CbsScreen = require "scenes.battlesystem.gui"
local TweenManager = require "birb.classes.time" local TweenManager = require "birb.classes.time"
function BattleSystem:new(battleData) function BattleSystem:new(battleData)
BattleSystem.super.new(self) BattleSystem.super.new(self, false, false)
self.assets:batchImport("assets.battle") self.assets:batchImport("assets.battle")
self:playMusic(battleData.music) self:playMusic(battleData.music)

View file

@ -1,35 +1,28 @@
local Scene = require "game.scenes" local Scene = require "scenes.menus.debugmenus.commons.scene"
local menu = require "scenes.menus.debugmenus.animation.menu"
local CharAnimViewer = Scene:extend() local CharAnimViewer = Scene:extend()
local Background = require "game.modules.drawing.parallaxBackground" local Background = require "game.modules.drawing.parallaxBackground"
local Sprite = require "birb.modules.assets.types.sprites" local Sprite = require "birb.modules.assets.types.sprites"
function CharAnimViewer:new() function CharAnimViewer:new()
CharAnimViewer.super.new(self) 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 self.sprite = nil
end 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 end
function CharAnimViewer:setSpriteAndAnim(character, animationName) function CharAnimViewer:setSpriteAndAnim(character, animationName)
@ -39,18 +32,12 @@ end
function CharAnimViewer:update(dt) function CharAnimViewer:update(dt)
if (love.keyboard.isDown("z") and (not self.menusystem.isActive)) then CharAnimViewer.super.update(self,dt)
self.menusystem:activate()
end
if (self.sprite ~= nil) then if (self.sprite ~= nil) then
self.sprite:update(dt) self.sprite:update(dt)
end end
end end
function CharAnimViewer:setBackground(newBackground)
self.background = Background(self, 5, 1, newBackground)
end
function CharAnimViewer:draw() function CharAnimViewer:draw()
self.background:draw() self.background:draw()
if (self.sprite ~= nil) then if (self.sprite ~= nil) then

View file

@ -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

View file

@ -1,31 +1,20 @@
local Scene = require "game.scenes" local Scene = require "scenes.menus.debugmenus.commons.scene"
local menu = require "scenes.menus.debugmenus.battleBack.menu"
local BackgroundViewer = Scene:extend() local BackgroundViewer = Scene:extend()
local Background = require "game.modules.drawing.parallaxBackground" local Background = require "game.modules.drawing.parallaxBackground"
local backgroundList = require "datas.gamedata.maps.shoot.zones" local backgroundList = require "datas.gamedata.maps.shoot.zones"
function BackgroundViewer:new() function BackgroundViewer:new()
BackgroundViewer.super.new(self) BackgroundViewer.super.new(self)
self.assets:batchImport("assets.debug")
menu.commons.DebugMenu(self, "MainMenu")
self:setBackground("city") 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 end
function BackgroundViewer:initMenu()
function BackgroundViewer:update(dt) for backId, backgroundData in pairs(backgroundList) do
if (love.keyboard.isDown("z") and (not self.menusystem.isActive)) then self.menu:addItem(backgroundData.name, "left", function()
self.menusystem:activate() self:setBackground(backId)
self:hideMenu()
end, "select")
end end
end end

View file

@ -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

View file

@ -1,6 +1,4 @@
local Scene = require "game.scenes" local Scene = require "scenes.menus.debugmenus.commons.scene"
local menu = require "scenes.menus.debugmenus.choregraphy.menu"
local ChoregraphyViewer = Scene:extend() local ChoregraphyViewer = Scene:extend()
local World = require "scenes.battlesystem.world" local World = require "scenes.battlesystem.world"
@ -11,48 +9,34 @@ function ChoregraphyViewer:new()
self.assets:batchImport("assets.battle") self.assets:batchImport("assets.battle")
self.world = World(self) self.world = World(self)
self:buildMenu()
self:buildMocks() self:buildMocks()
end end
-- MENU FUNCTIONS -- MENU FUNCTIONS
function ChoregraphyViewer:buildMenu() function ChoregraphyViewer:initMenu()
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()
for i,category in ipairs(core.datas:getCategories("ennemies")) do for i,category in ipairs(core.datas:getCategories("ennemies")) do
self:buildEnnemyListMenu(category) self:buildEnnemyMenu(category)
end end
self:addSubMenu("characters", "MainMenu", "Rivals") self.menu:addSubmenu("characters", "Rivals", "main", true)
for k, character in pairs(game.characters.list) do for k, character in pairs(game.characters.list) do
self:addSubMenu(k, "characters", character.fullname) self.menu:addSubmenu(k, character.fullname, "characters")
menu.HeroChoregraphyWidget(self, k, core.datas:get("skills", "attack")) self:addItem("rivals", k, core.datas:get("skills", "attack"))
self:buildSkillMenu(k) self:buildSkillMenu(k)
end end
end end
function ChoregraphyViewer:buildEnnemyListMenu(category) function ChoregraphyViewer:buildEnnemyMenu(category)
self:addSubMenu(category, "MainMenu", category) self.menu:addSubmenu(category, category, "main", true)
for i,ennemy in ipairs(core.datas.getFromCategory("ennemies", category)) do
self:buildEnnemySkillMenu(category, ennemy)
end
end
function ChoregraphyViewer:buildEnnemySkillMenu(category, ennemy) for i,ennemy in ipairs(core.datas:getFromCategory("ennemies", category)) do
self:addSubMenu(ennemy, category, ennemy) self.menu:addSubmenu(ennemy, ennemy, category, true)
local data = core.datas:get("ennemies", ennemy) local data = core.datas:get("ennemies", ennemy)
for j,skillName in ipairs(data.skills) do for j,skillName in ipairs(data.skills) do
if (core.datas:exists("badskills", skillName)) then if (core.datas:exists("badskills", skillName)) then
menu.EnnemyChoregraphyWidget(self, category, ennemy, core.datas:get("badskills", skillName)) self:addItem(category, ennemy, core.datas:get("badskills", skillName))
end
end end
end end
end end
@ -65,15 +49,14 @@ function ChoregraphyViewer:buildSkillMenu(charName)
if (skillTreated[skillName] ~= true) then if (skillTreated[skillName] ~= true) then
skillTreated[skillName] = true skillTreated[skillName] = true
if (core.datas:exists("skills", skillName)) then 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
end end
end end
function ChoregraphyViewer:addSubMenu(submenu, parent, name) function ChoregraphyViewer:addItem(category, ennemy, data)
local parent = parent or "MainMenu" self.menu:addItem(data.name, "left", function() self:playEnnemyChoregraphy(category, ennemy, data) end, "select")
self.menusystem.menus[parent]:addSubMenu(submenu, name)
end end
-- MOCKS FUNCTIONS -- MOCKS FUNCTIONS
@ -86,7 +69,11 @@ function ChoregraphyViewer:playHeroChoregraphy(character, data)
end end
function ChoregraphyViewer:playEnnemyChoregraphy(category, ennemy, data) function ChoregraphyViewer:playEnnemyChoregraphy(category, ennemy, data)
if (category == "rivals") then
self.fighter:playHeroChoregraphy(ennemy, data)
else
self.fighter:playEnnemyChoregraphy(category, ennemy, data) self.fighter:playEnnemyChoregraphy(category, ennemy, data)
end
end end
-- OTHER -- OTHER

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -5,6 +5,7 @@ return {
battleBack = require "scenes.menus.debugmenus.battleBack", battleBack = require "scenes.menus.debugmenus.battleBack",
choregraphy = require "scenes.menus.debugmenus.choregraphy", choregraphy = require "scenes.menus.debugmenus.choregraphy",
animation = require "scenes.menus.debugmenus.animation", animation = require "scenes.menus.debugmenus.animation",
menu = require "scenes.menus.debugmenus"
}, },
options = require "scenes.menus.options" options = require "scenes.menus.options"
} }

View file

@ -11,6 +11,9 @@ local MENU_ITEM_NUMBER = 8
function MainMenu:new() function MainMenu:new()
MainMenu.super.new(self, "mainmenu", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, false) 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("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("Options", "left", function() self:launchOptions() end)
self:addItem("Return to title", "left", function() self:returnToTitle() end, "back") self:addItem("Return to title", "left", function() self:returnToTitle() end, "back")
self:setCancelWidget() self:setCancelWidget()
@ -23,6 +26,10 @@ function MainMenu:launchGame()
core.scenemanager.currentScene:hideOverlay() core.scenemanager.currentScene:hideOverlay()
end 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() function MainMenu:launchOptions()
core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.options() end, 424/2, 240/2) core.screen:startTransition(defTransitions.default, defTransitions.default, function() scenes.menus.options() end, 424/2, 240/2)
end end

View file

@ -0,0 +1,5 @@
return {
MENU_Y = 48,
MENU_W = math.floor(424 / 1.5),
MENU_ITEM_NUMBER = 8
}

View file

@ -2,8 +2,6 @@ local Scene = require "game.scenes"
local OptionsMenu = Scene:extend() local OptionsMenu = Scene:extend()
local OptionMenu = require "scenes.menus.options.menu" local OptionMenu = require "scenes.menus.options.menu"
local gui = require "game.modules.gui"
local MenuBack = require "game.modules.gui.menuback" local MenuBack = require "game.modules.gui.menuback"
function OptionsMenu:new() function OptionsMenu:new()

View file

@ -11,14 +11,12 @@ local KeysWidget = TextMenuWidget:extend()
local defTransitions = require "birb.modules.transitions" local defTransitions = require "birb.modules.transitions"
local ConfirmDialog = require "game.modules.confirmdialog" local ConfirmDialog = require "game.modules.confirmdialog"
local MENU_Y = 48 local const = require "scenes.menus.options.const"
local MENU_W = 424 / 1.5
local MENU_ITEM_NUMBER = 8
function MainMenu:new() function MainMenu:new()
local screenw, screenh = core.screen:getDimensions() local screenw, screenh = core.screen:getDimensions()
MainMenu.super.new(self, "optionMenu", screenw/2, MENU_Y, MENU_W, MENU_ITEM_NUMBER, true) MainMenu.super.new(self, "optionMenu", screenw/2, const.MENU_Y, const.MENU_W, const.MENU_ITEM_NUMBER, true)
self.ox = MENU_W/2 self.ox = const.MENU_W/2
self:addVideoMenu() self:addVideoMenu()
self:addAudioMenu() self:addAudioMenu()
self:addDifficultyMenu() self:addDifficultyMenu()