From 459f4905c71b8a44a03d8eaba346e3532398c2af Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 1 Aug 2020 16:06:08 +0200 Subject: [PATCH] feat: add basic option menu --- .../assets/gui/fonts/SA2font.lua | 4 + .../assets/gui/fonts/SA2font.png | Bin 0 -> 5623 bytes sonic-radiance.love/assets/gui/fonts/sadv.lua | 4 + .../datas/languages/en/init.lua | 5 + .../datas/languages/en/options.lua | 11 + .../datas/languages/fr/init.lua | 5 + .../datas/languages/fr/options.lua | 11 + .../scenes/debug/menu/init.lua | 11 +- sonic-radiance.love/scenes/init.lua | 1 + sonic-radiance.love/scenes/options/assets.lua | 52 +++ sonic-radiance.love/scenes/options/init.lua | 97 ++++++ .../scenes/options/widgets.lua | 298 ++++++++++++++++++ 12 files changed, 489 insertions(+), 10 deletions(-) create mode 100644 sonic-radiance.love/assets/gui/fonts/SA2font.lua create mode 100644 sonic-radiance.love/assets/gui/fonts/SA2font.png create mode 100644 sonic-radiance.love/assets/gui/fonts/sadv.lua create mode 100644 sonic-radiance.love/datas/languages/en/init.lua create mode 100644 sonic-radiance.love/datas/languages/en/options.lua create mode 100644 sonic-radiance.love/datas/languages/fr/init.lua create mode 100644 sonic-radiance.love/datas/languages/fr/options.lua create mode 100644 sonic-radiance.love/scenes/options/assets.lua create mode 100644 sonic-radiance.love/scenes/options/init.lua create mode 100644 sonic-radiance.love/scenes/options/widgets.lua diff --git a/sonic-radiance.love/assets/gui/fonts/SA2font.lua b/sonic-radiance.love/assets/gui/fonts/SA2font.lua new file mode 100644 index 0000000..8b7e7ff --- /dev/null +++ b/sonic-radiance.love/assets/gui/fonts/SA2font.lua @@ -0,0 +1,4 @@ +return { + glyphs = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZÇÂÄÀÆÉÊËÈÎÏÔÖŒÜÛÙ[\\]^_`abcdefghijklmnopqrstuvwxyzçâäàæéêëèïîôöœûüù{|}", + extraspacing = 0, +} diff --git a/sonic-radiance.love/assets/gui/fonts/SA2font.png b/sonic-radiance.love/assets/gui/fonts/SA2font.png new file mode 100644 index 0000000000000000000000000000000000000000..f377f4cbcd2b9246d5e5f29be720a041f85cc7e2 GIT binary patch literal 5623 zcmYLNcRU;1*H>z^ilWP&)p}4RW{J_7jah2etR168?8IZYjXjGdYSz{oQ6XrlO(Zd+ z8mhL~V)OdF&-;7cKkm8rk8|!h_kPYj_j|r?jSRGzu5w1wE(27MqS&a3C-m}3y`xS#5F4qqnr z!^?j-+Bpp8IvQ{ARS`PPGj-m@6|C)Cq8ZR%6S69R5&FDr#`aJ@y+JV$%kl9x>+!7h zv|oNj1i$cJ5lM^{C)Y1jqrU`p!Vk+!-U&H)J974Gdpy(2h177c>_%G0Av6JX>*4{F zrI4ROm<=7Fa_DxeT{(F^t`w&H#JXY>(QB5zE{?KVou8cAD5cP+XcdtG6D@{9&4X{w zdOoEuE&k?aIhss3=M9U!fnT@$AJWU#2{3)TVf_C$|rB9{DiK zH1~aWbj_-{DWe$@o}oU6@9<|Vh?}>p`-D~r{OBbbSI~B&-a%%e&AYXM0F_t&xCf&d za%}+rDO|Wcxgf+jSh&>^XQS=zG>Z5!lcL4XmxQx@)gB3Dir#V&80)4cgRv zZ^Y4Ef6O2d{f`I~hTGOj#1A^ve5!K24@!VeA{#TzC@rdtIM_GeyZ@*4n1OY3$Bl+g z$VP+H_v+>U8b5v$(YTig+21CUPv@s0#?_(R%d+_8F;c7Tb`8O8n`8p|AYUr&|Jm@k zWe{w9xG|e`cdBItcfX)N|6}oAaDyt`rFVsdd;fSzz79JkH-ur+ENDXkHH08K-d09KqfDf87CCsI;?#d!F+;wc)+lc_ zpsL8@)G@i8`=66``kgpKFKMP~#l9BI>8VZj$nV?Ln{R@hpJ6D_%tz@lYptTAd7@ZJ z?5(g;2xn5`Ul;=(WxQ0|?9q+V7JV-rMq?>fRr&7({_g8G^q_gyQH_bn5#V=xlK|-< z*0f7@=-F9Od>mFIi#8-I|I$2(0n;Pr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jiE9|%MEnpE4;;_*Uc|RF&p>dfy>VI+7zsmm* jfsgOl>s+`iJy3NZY9F~X2S6{FTq<2n1C8p(_L2Vsk5x3K literal 0 HcmV?d00001 diff --git a/sonic-radiance.love/assets/gui/fonts/sadv.lua b/sonic-radiance.love/assets/gui/fonts/sadv.lua new file mode 100644 index 0000000..956a37b --- /dev/null +++ b/sonic-radiance.love/assets/gui/fonts/sadv.lua @@ -0,0 +1,4 @@ +return { + glyphs = "abcdefghijklmnopqrstuvwxyz0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ", + extraspacing = 1 +} diff --git a/sonic-radiance.love/datas/languages/en/init.lua b/sonic-radiance.love/datas/languages/en/init.lua new file mode 100644 index 0000000..532eaa3 --- /dev/null +++ b/sonic-radiance.love/datas/languages/en/init.lua @@ -0,0 +1,5 @@ +return { + name = "English", + name_ascii = "English", + subfolder = "en" +} diff --git a/sonic-radiance.love/datas/languages/en/options.lua b/sonic-radiance.love/datas/languages/en/options.lua new file mode 100644 index 0000000..2e5406e --- /dev/null +++ b/sonic-radiance.love/datas/languages/en/options.lua @@ -0,0 +1,11 @@ +return { + ["inputs"] = "Inputs", + ["video"] = "Video", + ["audio"] = "Audio", + ["langs"] = "Languages", + ["resolution"] = "Resolution", + ["fullscreen"] = "Fullscreen", + ["borders"] = "Borders", + ["vsync"] = "V-Sync", + ["back"] = "Back", +} diff --git a/sonic-radiance.love/datas/languages/fr/init.lua b/sonic-radiance.love/datas/languages/fr/init.lua new file mode 100644 index 0000000..0c9be78 --- /dev/null +++ b/sonic-radiance.love/datas/languages/fr/init.lua @@ -0,0 +1,5 @@ +return { + name = "Français", + name_ascii = "Francais", + subfolder = "fr" +} diff --git a/sonic-radiance.love/datas/languages/fr/options.lua b/sonic-radiance.love/datas/languages/fr/options.lua new file mode 100644 index 0000000..d0b2d8f --- /dev/null +++ b/sonic-radiance.love/datas/languages/fr/options.lua @@ -0,0 +1,11 @@ +return { + ["inputs"] = "Controles", + ["video"] = "Affichage", + ["audio"] = "Sons", + ["langs"] = "Langues", + ["resolution"] = "Resolution", + ["fullscreen"] = "Plein Ecran", + ["borders"] = "Bordures", + ["vsync"] = "Sync Vert.", + ["back"] = "Retour", +} diff --git a/sonic-radiance.love/scenes/debug/menu/init.lua b/sonic-radiance.love/scenes/debug/menu/init.lua index bae199c..5d11638 100644 --- a/sonic-radiance.love/scenes/debug/menu/init.lua +++ b/sonic-radiance.love/scenes/debug/menu/init.lua @@ -12,22 +12,13 @@ function DebugMenu:new() self:buildOverworldMenu() self:buildSaveMenu() self:buildOtherMenu() - self:buildOptionsMenu() + menu.commons.SceneWidget(self, "BaseMenu", scenes.options, "Options") 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") diff --git a/sonic-radiance.love/scenes/init.lua b/sonic-radiance.love/scenes/init.lua index 58bf0ee..0f611e0 100644 --- a/sonic-radiance.love/scenes/init.lua +++ b/sonic-radiance.love/scenes/init.lua @@ -4,4 +4,5 @@ return { title = require "scenes.titlescreen", cbs = require "scenes.battlesystem", debug = require "scenes.debug", + options = require "scenes.options", } diff --git a/sonic-radiance.love/scenes/options/assets.lua b/sonic-radiance.love/scenes/options/assets.lua new file mode 100644 index 0000000..17a38c4 --- /dev/null +++ b/sonic-radiance.love/scenes/options/assets.lua @@ -0,0 +1,52 @@ +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"}, + {"medium", "assets/gui/fonts/SA2font"}, + }, + ["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/options/init.lua b/sonic-radiance.love/scenes/options/init.lua new file mode 100644 index 0000000..6790219 --- /dev/null +++ b/sonic-radiance.love/scenes/options/init.lua @@ -0,0 +1,97 @@ +local Scene = require "core.modules.scenes" +local OptionsMenu = Scene:extend() + +local ListBox = require "core.modules.menusystem.listbox" +local Widgets = require "scenes.options.widgets" + +function OptionsMenu:new() + OptionsMenu.super.new(self) + + self.assets:batchImport("scenes.options.assets") + self:addMenu("main", true) + self:addSubMenu("video", "video") + self:addSubMenu("audio", "audio") + self:addSubMenu("langs", "langs") + self:addSubMenu("inputs", "inputs") + + Widgets.Resolution(self, "video") + Widgets.Switch(self, "video", "fullscreen") + Widgets.Switch(self, "video", "borders") + Widgets.Switch(self, "video", "vsync") + + self:addPlayerMenus() + + self:setLanguageMenu() + + Widgets.Audio(self, "audio", "sfx") + Widgets.Audio(self, "audio", "music") + + Widgets.Exit(self, "main") + self.menusystem:switchMenu("main") + + self.menusystem:setSoundFromSceneAssets("mBeep") + + self.keyDetector = {} + self.keyDetector.widget = nil +end + +-- MENU FUNCTION +-- Functions that serve the handling of menus + +function OptionsMenu:addMenu(name, nobackbutton) + local screenHeight, screenWidth = core.screen:getDimensions() + local w, h = 424/2, 240 - 48 + local x, y = w / 2, 24 + ListBox(self.menusystem, name, x, y, w, h, 8) +end + +function OptionsMenu:addSubMenu(name, fullname) + self:addMenu(name) + Widgets.SubMenu(self, "main", name, fullname) + Widgets.SubMenu(self, name, "main", "back", 1, "<") +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) + for k,w in pairs(v.keys) do + -- FIXME: make sure that you can use the order you want for the keys list + -- instead of a random one + Widgets.Key(self, i, k) + end + Widgets.SubMenu(self, menu, "inputs", "back", 1, "<") + end +end + +function OptionsMenu:addScene(submenu, scene, fullname) + Widgets.Dummy(self, submenu, fullname) +end + +function OptionsMenu:setLanguageMenu() + for i,v in ipairs(core.lang.data.available) do + Widgets.Lang(self, "langs", v) + end +end + +function OptionsMenu:changeKey(widget) + self.keyDetector.isActive = true + self.keyDetector.widget = widget +end + +function OptionsMenu:keypressed( key ) + if (self.keyDetector.isActive) then + self.keyDetector.widget:receiveKey( key ) + self.menusystem:activate() + self.keyDetector.isActive = false + end +end + +function OptionsMenu:draw() + love.graphics.setColor(.3, .1, .4, 1) + love.graphics.rectangle("fill", 0, 0, 424, 240) + utils.graphics.resetColor() +end + +return OptionsMenu diff --git a/sonic-radiance.love/scenes/options/widgets.lua b/sonic-radiance.love/scenes/options/widgets.lua new file mode 100644 index 0000000..b59b38e --- /dev/null +++ b/sonic-radiance.love/scenes/options/widgets.lua @@ -0,0 +1,298 @@ +local widgets = {} + +local Widget = require "core.modules.menusystem.widgets" +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() + +-- BASIC WIDGETS +-- Simple and reusables widgets + +-- DoubleText widget : a two-side text widget + +function DoubleTextWidget:new(menu, font, label1, label2) + DoubleTextWidget.super.new(self, menu, font, label1) + self.label2 = label2 or "" +end + +function DoubleTextWidget:drawCanvas() + local w, h + w = math.floor(self.width) + h = math.floor(self.height / 2) - (self.font:getHeight() / 2) + self.font:draw(self.label, 4, h, -1, "left") + self.font:draw(self.label2, w-4, h, -1, "right") +end + +-- Submenu widget :: go to a submenu + +function widgets.SubMenu:new(scene, menu, newmenu, fullname, order, label2) + self.scene = scene + local widgetmenu = self.scene.menusystem.menus[menu] + local font = self.scene.assets.fonts["medium"] + local label = core.lang:translate("options", fullname) + local label2 = label2 or ">" + self.newmenu = newmenu + widgets.SubMenu.super.new(self, widgetmenu, font, label, label2) + self.order = order or 0 +end + +function widgets.SubMenu:action() + self.scene.assets:playSFX("mSelect") + self.scene.menusystem:switchMenu(self.newmenu) +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) +end + +function widgets.Dummy:action() + -- shoosh +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") +end + +function widgets.Exit:action() + self.scene.assets:playSFX("mSelect") + core.scenemanager:setStoredScene("mainmenu") +end + +-- VIDEO WIDGETS +-- Handle graphical settings + +-- 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"] + self.keyname = keyname + local label = core.lang:translate("options", keyname) + local label2 = self:getLabel() + widgets.Switch.super.new(self, widgetmenu, font, label, label2) + self.order = order or 0 +end + +function widgets.Switch:modifyKey() + --self.key = (self.key == false) + if self.keyname == "fullscreen" then + core.options.data.video.fullscreen = (core.options.data.video.fullscreen == false) + elseif self.keyname == "borders" then + core.options.data.video.border = (core.options.data.video.border == false) + elseif self.keyname == "vsync" then + core.options.data.video.vsync = (core.options.data.video.vsync == false) + end + core.screen:applySettings() +end + +function widgets.Switch:getKey() + if self.keyname == "fullscreen" then + self.key = core.options.data.video.fullscreen + elseif self.keyname == "borders" then + self.key = (core.options.data.video.border) + elseif self.keyname == "vsync" then + self.key = (core.options.data.video.vsync) + end +end + +function widgets.Switch:getLabel() + self:getKey() + local label = "" + if (self.key) then + label = "true" + else + label = "false" + end + + return core.lang:translate("commons", label) +end + +function widgets.Switch:action() + self:modifyKey() + self.scene.assets:playSFX("mSelect") + self.label2 = self:getLabel() + core.options:write() + self:invalidateCanvas() +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) +end + +function widgets.Resolution:getLabel() + return "x" .. core.options.data.video.resolution +end + +function widgets.Resolution:action() + if core.options.data.video.resolution == 3 then + core.options.data.video.resolution = 1 + else + core.options.data.video.resolution = core.options.data.video.resolution + 1 + end + self.label2 = self:getLabel() + core.screen:applySettings() + self.scene.assets:playSFX("mSelect") + self:invalidateCanvas() + 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) + self.order = 0 +end + +function widgets.Key:getLabel() + return core.input.data[self.source].keys[self.key] +end + +function widgets.Key:action() + self.scene.assets:playSFX("navigate") + self.scene:changeKey(self) + self.scene.menusystem:deactivate() +end + +function widgets.Key:receiveKey( key ) + self.scene.assets:playSFX("mSelect") + core.options:setInputKey(self.source, self.key, key) + self.label2 = self:getLabel() + self:invalidateCanvas() +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"] + 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) + self.order = 0 +end + +function widgets.Audio:getLabel() + local value = self:getVolume() + string = utils.math.numberToString(value, 3) + local label = string .. "%" + + return label +end + +function widgets.Audio:getVolume() + if (self.audiotype == "sfx") then + return core.options.data.audio.sfx + else + return core.options.data.audio.music + end +end + +function widgets.Audio:setVolume(vol) + if (vol < 0) then vol = 100 end + + if (self.audiotype == "sfx") then + core.options.data.audio.sfx = vol + else + core.options.data.audio.music = vol + end + + self.label2 = self:getLabel() + self:invalidateCanvas() +end + +function widgets.Audio:action() + local value = self:getVolume() + self:setVolume(value - 20) + self.scene.assets:playSFX("mSelect") + --self.scene.assets.music:setVolume(core.options.data.audio.music / 100) + core.options:write() +end + +return widgets