From cb626bfa4a7cc17ee6ea27991667610b36712812 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 19 Aug 2020 23:25:36 +0200 Subject: [PATCH] improvement: port the options to the new system --- .../game/modules/menus/list.lua | 4 +- .../scenes/menus/options/assets.lua | 3 + .../scenes/menus/options/init.lua | 32 +++--- .../scenes/menus/options/menu.lua | 21 ++-- .../scenes/menus/options/widgets.lua | 104 ++++-------------- 5 files changed, 47 insertions(+), 117 deletions(-) diff --git a/sonic-radiance.love/game/modules/menus/list.lua b/sonic-radiance.love/game/modules/menus/list.lua index 02274a4..531e95d 100644 --- a/sonic-radiance.love/game/modules/menus/list.lua +++ b/sonic-radiance.love/game/modules/menus/list.lua @@ -54,7 +54,7 @@ function list.ListMenu:finalize() end function list.ListMenu:clone(name) - return list.ListMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber) + return list.ListMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber, self.isBoxed) end function list.ListMenu:getSubmenuWidget() @@ -97,7 +97,7 @@ end function list.ListMenu:draw() if (self.isBoxed) then - + love.graphics.draw(self.box, self.x - 8, self.y - 8) end self:updateView() local widgety = self.y diff --git a/sonic-radiance.love/scenes/menus/options/assets.lua b/sonic-radiance.love/scenes/menus/options/assets.lua index 41efadb..8569868 100644 --- a/sonic-radiance.love/scenes/menus/options/assets.lua +++ b/sonic-radiance.love/scenes/menus/options/assets.lua @@ -6,6 +6,9 @@ return { ["textures"] = { {"background", "assets/backgrounds/options.png"} }, + ["fonts"] = { + {"small", "assets/gui/fonts/PixelOperator.ttf", 16} + }, ["imagefonts"] = { {"medium", "assets/gui/fonts/SA2font"}, }, diff --git a/sonic-radiance.love/scenes/menus/options/init.lua b/sonic-radiance.love/scenes/menus/options/init.lua index 3178774..23a5f07 100644 --- a/sonic-radiance.love/scenes/menus/options/init.lua +++ b/sonic-radiance.love/scenes/menus/options/init.lua @@ -11,24 +11,26 @@ function OptionsMenu:new() self.assets:batchImport("scenes.menus.options.assets") self:addMenu("main", true) - self:addSubMenu("video", "video") - self:addSubMenu("audio", "audio") + self:addSubMenu("video", "Video") + self:addSubMenu("audio", "Audio") --self:addSubMenu("langs", "langs") - self:addSubMenu("inputs", "inputs") + self:addSubMenu("inputs", "Inputs") Widgets.Resolution(self, "video") - Widgets.Switch(self, "video", "fullscreen") - Widgets.Switch(self, "video", "borders") - Widgets.Switch(self, "video", "vsync") + Widgets.Switch(self, "video", "fullscreen", "Fullscreen") + Widgets.Switch(self, "video", "borders", "Borders") + Widgets.Switch(self, "video", "vsync", "Vsync") self:addPlayerMenus() --self:setLanguageMenu() - Widgets.Audio(self, "audio", "sfx") - Widgets.Audio(self, "audio", "music") + Widgets.Audio(self, "audio", "sfx", "SFX") + Widgets.Audio(self, "audio", "music", "Music") Widgets.Exit(self, "main") + + self.menusystem.menus["main"]:finalize() self.menusystem:switchMenu("main") self.menusystem:setSoundFromSceneAssets("mBeep") @@ -50,26 +52,24 @@ end -- Functions that serve the handling of menus function OptionsMenu:addMenu(name, nobackbutton) - OptionMenu(self.menusystem, name) + OptionMenu(self, name) end function OptionsMenu:addSubMenu(name, fullname) - self:addMenu(name) - Widgets.SubMenu(self, "main", name, fullname) - Widgets.SubMenu(self, name, "main", "back", 1, "<") + self.menusystem.menus["main"]:addSubMenu(name, fullname) end function OptionsMenu:addPlayerMenus() for i,v in ipairs(core.input.data) do - local menu = "player" .. i - self:addMenu(menu) - Widgets.PlayerSubMenu(self, "inputs", i) + + self.menusystem.menus["inputs"]:addSubMenu("player" .. i, "Player " .. i, "inputs") + local keyList = require "datas.keys" for j, key in ipairs(keyList) do Widgets.Key(self, i, key) end - Widgets.SubMenu(self, menu, "inputs", "back", 1, "<") end + end function OptionsMenu:addScene(submenu, scene, fullname) diff --git a/sonic-radiance.love/scenes/menus/options/menu.lua b/sonic-radiance.love/scenes/menus/options/menu.lua index 87a95d6..9575afe 100644 --- a/sonic-radiance.love/scenes/menus/options/menu.lua +++ b/sonic-radiance.love/scenes/menus/options/menu.lua @@ -1,22 +1,15 @@ -local ListBox = require "core.modules.menusystem.listbox" -local OptionMenu = ListBox:extend() -local WIDTH = 424/1.4 -local HEIGHT = 240/1.9 +local RadianceListMenu = require "game.modules.menus.list" -local gui = require "game.modules.gui" +local OptionMenu = RadianceListMenu.ListMenu:extend() +local WIDTH = 128+32 +local ITEMNUMBER = 6 -function OptionMenu:new(menusystem, name) - local w, h = math.floor(WIDTH), math.floor(HEIGHT) +function OptionMenu:new(scene, name) + local w, h = math.floor(WIDTH), math.floor(17 * ITEMNUMBER) local screenw, screenh = core.screen:getDimensions() local x = (screenw/2) - (w/2) local y = (screenh/2) - (h/2) - OptionMenu.super.new(self, menusystem, name, x, y, w, h, 6) - self.box = gui.newTextBox("assets/gui/dialogbox.png", w+16, h+16) -end - -function OptionMenu:draw() - love.graphics.draw(self.box, self.x-8, self.y-8) - OptionMenu.super.draw(self) + OptionMenu.super.new(self, scene, name, x, y, w, ITEMNUMBER, true) end return OptionMenu diff --git a/sonic-radiance.love/scenes/menus/options/widgets.lua b/sonic-radiance.love/scenes/menus/options/widgets.lua index b59b38e..a0bc19c 100644 --- a/sonic-radiance.love/scenes/menus/options/widgets.lua +++ b/sonic-radiance.love/scenes/menus/options/widgets.lua @@ -1,17 +1,19 @@ local widgets = {} local Widget = require "core.modules.menusystem.widgets" +local RadianceListMenu = require "game.modules.menus.list" + local DoubleTextWidget = Widget.Text:extend() widgets.SubMenu = DoubleTextWidget:extend() -widgets.Dummy = Widget.Text:extend() -widgets.Exit = Widget.Text:extend() -widgets.Switch = DoubleTextWidget:extend() -widgets.Resolution = DoubleTextWidget:extend() -widgets.Lang = Widget.Text:extend() -widgets.PlayerSubMenu = DoubleTextWidget:extend() -widgets.Key = DoubleTextWidget:extend() -widgets.Audio = DoubleTextWidget:extend() +widgets.Dummy = RadianceListMenu.DualTextWidget:extend() +widgets.Exit = RadianceListMenu.DualTextWidget:extend() +widgets.Switch = RadianceListMenu.DualTextWidget:extend() +widgets.Resolution = RadianceListMenu.DualTextWidget:extend() +widgets.Lang = RadianceListMenu.DualTextWidget:extend() +widgets.PlayerSubMenu = RadianceListMenu.DualTextWidget:extend() +widgets.Key = RadianceListMenu.DualTextWidget:extend() +widgets.Audio = RadianceListMenu.DualTextWidget:extend() -- BASIC WIDGETS -- Simple and reusables widgets @@ -52,10 +54,7 @@ end -- Dummy widget :: An empty widget to serve as a base for others function widgets.Dummy:new(scene, menu, fullname) - self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] - widgets.Dummy.super.new(self, widgetmenu, font, fullname) + widgets.Dummy.super.new(self, scene, menu, fullname) end function widgets.Dummy:action() @@ -65,11 +64,7 @@ end -- Exit Widget : exit the examples function widgets.Exit:new(scene, menu) - self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] - local label = core.lang:translate("commons", "exit") - widgets.Exit.super.new(self, widgetmenu, font, "Exit") + widgets.Exit.super.new(self, scene, menu, "Exit", "") end function widgets.Exit:action() @@ -82,14 +77,10 @@ end -- Switch widget (One widget to handle graphical switch) -function widgets.Switch:new(scene, menu, keyname) - self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] +function widgets.Switch:new(scene, menu, keyname, label) self.keyname = keyname - local label = core.lang:translate("options", keyname) local label2 = self:getLabel() - widgets.Switch.super.new(self, widgetmenu, font, label, label2) + widgets.Switch.super.new(self, scene, menu, label, label2) self.order = order or 0 end @@ -138,12 +129,9 @@ end -- Resolution Widget function widgets.Resolution:new(scene, menu) - self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] local label = core.lang:translate("options", "resolution") local label2 = self:getLabel() - widgets.Resolution.super.new(self, widgetmenu, font, label, label2) + widgets.Resolution.super.new(self, scene, menu, label, label2) end function widgets.Resolution:getLabel() @@ -163,58 +151,16 @@ function widgets.Resolution:action() core.options:write() end --- LANGS WIDGET --- Allow you to change the lang of the game - -function widgets.Lang:new(scene, menu, lang) - self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] - local label = core.lang:getLangName(lang) - self.lang = lang - widgets.Lang.super.new(self, widgetmenu, font, label) -end - -function widgets.Lang:action() - self.scene.assets:playSFX("mSelect") - core.options:setLanguage(self.lang) - --self.scene.menusystem:invalidateAllWidgets() -end - --- INPUT WIDGETS --- Widgets to handle inputs - -function widgets.PlayerSubMenu:new(scene, menu, sourceid) - self.scene = scene - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] - local label = core.lang:translate("options", "player") .. " " .. sourceid - local label2 = ">" - self.newmenu = "player" .. sourceid - widgets.PlayerSubMenu.super.new(self, widgetmenu, font, label, label2) - self.order = 0 -end - -function widgets.PlayerSubMenu:action() - self.scene.assets:playSFX("mSelect") - self.scene.menusystem:switchMenu(self.newmenu) -end - -- Key widgets - function widgets.Key:new(scene, sourceid, key) - self.scene = scene self.source = sourceid self.key = key local menu = "player" .. self.source - - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] local label = self.key local label2 = self:getLabel() - widgets.Key.super.new(self, widgetmenu, font, label, label2) + widgets.Key.super.new(self, scene, menu, label, label2) self.order = 0 end @@ -238,23 +184,11 @@ end -- AUDIO FUNCTIONS -- Sounds/Music functions -function widgets.Audio:new(scene, menu, audiotype) - self.scene = scene - self.audiotype = key - - - local widgetmenu = self.scene.menusystem.menus[menu] - local font = self.scene.assets.fonts["medium"] +function widgets.Audio:new(scene, menu, audiotype, label) self.audiotype = audiotype - local label = "" - if (self.audiotype == "sfx") then - label = core.lang:translate("options", "sfx") - else - label = core.lang:translate("options", "music") - end - local label2 = self:getLabel() - widgets.Audio.super.new(self, widgetmenu, font, label, label2) + local label2 = self:getLabel() + widgets.Audio.super.new(self, scene, menu, label, label2) self.order = 0 end