From 4b9ba5eed68862e7321f19cb0d1d42b10df06a97 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 1 Aug 2020 10:31:09 +0200 Subject: [PATCH] feat: add basic debug menu --- sonic-radiance.love/game/init.lua | 2 + sonic-radiance.love/main.lua | 2 +- .../scenes/debug/commons/assets.lua | 51 +++++++++++++ .../scenes/debug/commons/menu.lua | 60 +++++++++++++++ sonic-radiance.love/scenes/debug/init.lua | 3 + .../scenes/debug/menu/init.lua | 75 +++++++++++++++++++ .../scenes/debug/menu/menu.lua | 36 +++++++++ sonic-radiance.love/scenes/init.lua | 1 + 8 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/scenes/debug/commons/assets.lua create mode 100644 sonic-radiance.love/scenes/debug/commons/menu.lua create mode 100644 sonic-radiance.love/scenes/debug/init.lua create mode 100644 sonic-radiance.love/scenes/debug/menu/init.lua create mode 100644 sonic-radiance.love/scenes/debug/menu/menu.lua diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index c95d3f1..d47cd04 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -40,6 +40,8 @@ function Game:new() self.characters = Characters(self) self.ennemies = Ennemies(self) self.skills = Skills(self) + + self.version = "0.0.0" end function Game:setData(data) diff --git a/sonic-radiance.love/main.lua b/sonic-radiance.love/main.lua index f3e47c7..32ffdc6 100644 --- a/sonic-radiance.love/main.lua +++ b/sonic-radiance.love/main.lua @@ -30,7 +30,7 @@ function love.load() core = Core(true) game = Game() - scenes.cbs() + scenes.debug.menu() end function love.update(dt) diff --git a/sonic-radiance.love/scenes/debug/commons/assets.lua b/sonic-radiance.love/scenes/debug/commons/assets.lua new file mode 100644 index 0000000..244881b --- /dev/null +++ b/sonic-radiance.love/scenes/debug/commons/assets.lua @@ -0,0 +1,51 @@ +return { + ["tilesets"] = { + {"charicons", "assets/sprites/characters/charicons"}, + {"normaltiles", "assets/backgrounds/normaltile"}, + {"sptiles", "assets/backgrounds/specialtile"}, + {"borders", "assets/backgrounds/borders"}, + }, + ["sprites"] = { + {"cursorground", "assets/gui/cursor/ground"}, + {"hitGFX", "assets/sprites/gfx/hit"}, + }, + ["textures"] = { + {"menucursor", "assets/gui/cursor-menulist.png"}, + {"statusbar", "assets/gui/status_bar.png"}, + {"cursorpeak", "assets/gui/cursor/peak.png"}, + {"actorsShadow", "assets/sprites/shadow.png"}, + {"emptytile", "assets/backgrounds/tilemask.png"}, + + {"e_speedster", "assets/gui/emblem_speedster.png"}, + {"e_technic", "assets/gui/emblem_technic.png"}, + {"e_power", "assets/gui/emblem_power.png"}, + + {"m_speedster", "assets/gui/emblem_speedster_mask.png"}, + {"m_technic", "assets/gui/emblem_technic_mask.png"}, + {"m_power", "assets/gui/emblem_power_mask.png"}, + + {"hudturn", "assets/gui/strings/hudturn.png"}, + {"battlecompleted", "assets/gui/strings/battle_completed.png" } + }, + ["fonts"] = { + {"small", "assets/gui/fonts/PixelOperator.ttf", 16}, + {"victory", "assets/gui/fonts/vipnagorgialla.ttf", 12} + }, + ["imagefonts"] = { + {"hudnbrs", "assets/gui/fonts/hudnumbers"}, + {"hudnbrs_small", "assets/gui/fonts/hudsmallnumbers"}, + }, + ["sfx"] = { + {"hit", "assets/sfx/hit.wav"}, + {"hitconnect", "assets/sfx/hitconnect.wav"}, + {"jump", "assets/sfx/jump.wav"}, + {"woosh", "assets/sfx/woosh.wav"}, + {"spincharge", "assets/sfx/spincharge.wav"}, + {"spinrelease", "assets/sfx/spinrelease.wav"}, + + {"mBack", "assets/sfx/menus/back.wav"}, + {"mBeep", "assets/sfx/menus/beep.wav"}, + {"mSelect", "assets/sfx/menus/select.wav"}, + {"mError", "assets/sfx/menus/error.wav"}, + } +} diff --git a/sonic-radiance.love/scenes/debug/commons/menu.lua b/sonic-radiance.love/scenes/debug/commons/menu.lua new file mode 100644 index 0000000..d60d79f --- /dev/null +++ b/sonic-radiance.love/scenes/debug/commons/menu.lua @@ -0,0 +1,60 @@ +local menu = {} + +local ListBox = require "core.modules.menusystem.listbox" +local Widget = require "core.modules.menusystem.widgets" + +menu.DebugMenu = ListBox:extend() +menu.DebugWidget = Widget.Text:extend() +menu.SubMenuWidget = menu.DebugWidget:extend() + +local CONST = {} +CONST.MENU = {} +CONST.MENU.X = 16 +CONST.MENU.Y = 48 +CONST.MENU.W = 424/2 +CONST.MENU.ITEM_NUMBER = 10 +CONST.MENU.ITEM_HEIGHT = 18 + +-- Basic menu structure +function menu.DebugMenu:new(scene, name) + self.scene = scene + local x, y = CONST.MENU.X, CONST.MENU.Y + local w, h = CONST.MENU.W, CONST.MENU.ITEM_NUMBER * CONST.MENU.ITEM_HEIGHT + menu.DebugMenu.super.new(self, scene.menusystem, name, x, y, w, h, CONST.MENU.ITEM_NUMBER) +end + +function menu.DebugMenu:drawCursor() + +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 + + +return menu diff --git a/sonic-radiance.love/scenes/debug/init.lua b/sonic-radiance.love/scenes/debug/init.lua new file mode 100644 index 0000000..1cf1b92 --- /dev/null +++ b/sonic-radiance.love/scenes/debug/init.lua @@ -0,0 +1,3 @@ +return { + menu = require "scenes.debug.menu" +} diff --git a/sonic-radiance.love/scenes/debug/menu/init.lua b/sonic-radiance.love/scenes/debug/menu/init.lua new file mode 100644 index 0000000..37886aa --- /dev/null +++ b/sonic-radiance.love/scenes/debug/menu/init.lua @@ -0,0 +1,75 @@ +local Scene = require "core.modules.scenes" +local menu = require "scenes.debug.menu.menu" + +local DebugMenu = Scene:extend() + +function DebugMenu:new() + DebugMenu.super.new(self) + self.assets:batchImport("scenes.debug.commons.assets") + menu.commons.DebugMenu(self, "BaseMenu") + menu.SceneWidget(self, "BaseMenu", scenes.title, "Launch Game") + self:buildBattleMenu() + self:buildOverworldMenu() + self:buildSaveMenu() + self:buildOtherMenu() + self:buildOptionsMenu() + menu.ExitWidget(self, "BaseMenu") + + self.menusystem:activate() + self.menusystem:switchMenu("BaseMenu") +end + +function DebugMenu:buildOptionsMenu() + self:addSubMenu("options", "BaseMenu", "Options") + self:addSubMenu("backgrounds", "options", "Set Background") + menu.ShowBackgroundWidget(self, "options") + + menu.commons.SubMenuWidget(self, "backgrounds", "options", "Back") + menu.commons.SubMenuWidget(self, "options", "BaseMenu", "Back") +end + +function DebugMenu:buildOverworldMenu() + self:addSubMenu("overworld", "BaseMenu", "Overworld") + menu.commons.SubMenuWidget(self, "overworld", "BaseMenu", "Back") +end + +function DebugMenu:buildBattleMenu() + self:addSubMenu("combat", "BaseMenu", "Battle System") + menu.SceneWidget(self, "combat", scenes.cbs, "Launch Battle") + + menu.commons.SubMenuWidget(self, "combat", "BaseMenu", "Back") +end + +function DebugMenu:buildSaveMenu() + self:addSubMenu("save", "BaseMenu", "Save System") + menu.commons.SubMenuWidget(self, "save", "BaseMenu", "Back") +end + +function DebugMenu:buildOtherMenu() + self:addSubMenu("other", "BaseMenu", "Other gameplay") + menu.SceneWidget(self, "other", scenes.test, "Minigame Engine") + + menu.commons.SubMenuWidget(self, "other", "BaseMenu", "Back") +end + + +function DebugMenu:update(dt) + if (love.keyboard.isDown("space") and (not self.menusystem.isActive)) then + self.menusystem:activate() + end +end + +function DebugMenu:addSubMenu(submenu, parent, name) + local parent = parent or "BaseMenu" + menu.commons.DebugMenu(self, submenu) + menu.commons.SubMenuWidget(self, parent, submenu, name .. " >") +end + +function DebugMenu:draw() + if (self.menusystem.isActive) then + self.assets.fonts["small"]:print("## SONIC RADIANCE - DEBUG MENU ##", 424/2, 8, "center") + self.assets.fonts["small"]:print("v" .. game.version, 424 - 8, 240 - 22, "right") + end +end + +return DebugMenu; diff --git a/sonic-radiance.love/scenes/debug/menu/menu.lua b/sonic-radiance.love/scenes/debug/menu/menu.lua new file mode 100644 index 0000000..609ae60 --- /dev/null +++ b/sonic-radiance.love/scenes/debug/menu/menu.lua @@ -0,0 +1,36 @@ +local commons = require "scenes.debug.commons.menu" +local menu = {} +menu.commons = commons +menu.ExitWidget = commons.DebugWidget:extend() +menu.ShowBackgroundWidget = commons.DebugWidget:extend() +menu.SceneWidget = commons.DebugWidget:extend() + +-- ExitWidget +function menu.ExitWidget:new(scene, menuName) + menu.ExitWidget.super.new(self, scene, menuName, "Exit") +end + +function menu.ExitWidget:action() + love.event.quit("000") +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 + +-- SceneWidget +function menu.SceneWidget:new(scene, menuName, newScene, newSceneName) + menu.SceneWidget.super.new(self, scene, menuName, newSceneName) + self.newScene = newScene +end + +function menu.SceneWidget:action() + self.newScene() +end + +return menu diff --git a/sonic-radiance.love/scenes/init.lua b/sonic-radiance.love/scenes/init.lua index 64af5eb..1354fae 100644 --- a/sonic-radiance.love/scenes/init.lua +++ b/sonic-radiance.love/scenes/init.lua @@ -2,4 +2,5 @@ return { test = require "scenes.test_scene", title = require "scenes.titlescreen", cbs = require "scenes.battlesystem", + debug = require "scenes.debug", }