fix: port the option menu to the new menusystem
This commit is contained in:
parent
e8b796f978
commit
f347f47aab
4 changed files with 102 additions and 105 deletions
8
examples/scenes/menus/options/consts.lua
Normal file
8
examples/scenes/menus/options/consts.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
local consts = {}
|
||||
|
||||
consts.OPTION_MENU = "optionMenu"
|
||||
consts.BORDERS_W = 96
|
||||
consts.BORDERS_H = 24
|
||||
consts.NBR_ELEMS = 8
|
||||
|
||||
return consts
|
|
@ -24,10 +24,12 @@
|
|||
local Scene = require "birb.modules.scenes"
|
||||
local OptionsMenu = Scene:extend()
|
||||
|
||||
local ListBox = require "birb.modules.menusystem.menus.listbox"
|
||||
local Widgets = require "scenes.menus.options.widgets"
|
||||
local Menu = require "scenes.menus.options.menu"
|
||||
|
||||
function OptionsMenu:new()
|
||||
local consts = require "scenes.menus.options.consts"
|
||||
|
||||
function OptionsMenu:start()
|
||||
OptionsMenu.super.new(self)
|
||||
self.assets:addImageFont("medium", "assets/fonts/medium")
|
||||
self.assets:setMusic("assets/music/options.ogg")
|
||||
|
@ -38,26 +40,31 @@ function OptionsMenu:new()
|
|||
|
||||
self.assets:playMusic()
|
||||
|
||||
self:addMenu("main", true)
|
||||
self.menu = Menu("medium");
|
||||
|
||||
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")
|
||||
Widgets.Switch("fullscreen")
|
||||
Widgets.Switch("borders")
|
||||
Widgets.Switch("vsync")
|
||||
|
||||
self:addPlayerMenus()
|
||||
self:addSubMenu("audio", "audio")
|
||||
Widgets.Audio("sfx")
|
||||
Widgets.Audio("music")
|
||||
|
||||
self:addSubMenu("langs", "langs")
|
||||
|
||||
self:setLanguageMenu()
|
||||
|
||||
Widgets.Audio(self, "audio", "sfx")
|
||||
Widgets.Audio(self, "audio", "music")
|
||||
self:addSubMenu("inputs", "inputs")
|
||||
|
||||
self:addPlayerMenus()
|
||||
|
||||
local menu = self.menusystem.menus[consts.OPTION_MENU]
|
||||
menu:switch("main")
|
||||
|
||||
Widgets.Exit(self, "main")
|
||||
self.menusystem:switchMenu("main")
|
||||
self.menusystem:switchMenu(consts.OPTION_MENU)
|
||||
|
||||
self.menusystem:setSoundFromSceneAssets("navigate")
|
||||
|
||||
|
@ -69,29 +76,19 @@ end
|
|||
-- 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)
|
||||
Menu("medium")
|
||||
end
|
||||
|
||||
function OptionsMenu:addSubMenu(name, fullname)
|
||||
self:addMenu(name)
|
||||
Widgets.SubMenu(self, "main", name, fullname)
|
||||
Widgets.SubMenu(self, name, "main", "back", 1, "<")
|
||||
local menu = self.menusystem.menus[consts.OPTION_MENU]
|
||||
menu:addSubmenu(name, core.lang:translate("options", fullname), "main")
|
||||
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, "<")
|
||||
for key, _ in pairs(core.input.data[1].keys) do
|
||||
-- FIXME: make sure that you can use the order you want for the keys list
|
||||
-- instead of a random one
|
||||
Widgets.Key(key)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -100,8 +97,8 @@ function OptionsMenu:addScene(submenu, scene, fullname)
|
|||
end
|
||||
|
||||
function OptionsMenu:setLanguageMenu()
|
||||
for i,v in ipairs(core.lang.data.available) do
|
||||
Widgets.Lang(self, "langs", v)
|
||||
for i,lang in ipairs(core.lang.data.available) do
|
||||
Widgets.Lang(lang)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -121,6 +118,7 @@ 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
|
||||
|
|
14
examples/scenes/menus/options/menu.lua
Normal file
14
examples/scenes/menus/options/menu.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
local TextMenu = require "birb.modules.menusystem.textmenu"
|
||||
local OptionMenu = TextMenu:extend()
|
||||
|
||||
local consts = require "examples.scenes.menus.options.consts"
|
||||
|
||||
function OptionMenu:new(font)
|
||||
local screenWidth, _ = core.screen:getDimensions()
|
||||
local w = screenWidth - (consts.BORDERS_W*2)
|
||||
local x = consts.BORDERS_W
|
||||
local y = consts.BORDERS_H
|
||||
OptionMenu.super.new(self, consts.OPTION_MENU, font, x, y, w, consts.NBR_ELEMS, 8)
|
||||
end
|
||||
|
||||
return OptionMenu
|
|
@ -23,15 +23,15 @@
|
|||
|
||||
local widgets = {}
|
||||
|
||||
local Widget = require "birb.modules.menusystem.menus.widgets"
|
||||
local DoubleTextWidget = Widget.Text:extend()
|
||||
local Widget = require "birb.modules.menusystem.textmenu.widgets.basic"
|
||||
local DoubleTextWidget = Widget:extend()
|
||||
|
||||
widgets.SubMenu = DoubleTextWidget:extend()
|
||||
widgets.Dummy = Widget.Text:extend()
|
||||
widgets.Exit = Widget.Text:extend()
|
||||
widgets.Dummy = Widget:extend()
|
||||
widgets.Exit = Widget:extend()
|
||||
widgets.Switch = DoubleTextWidget:extend()
|
||||
widgets.Resolution = DoubleTextWidget:extend()
|
||||
widgets.Lang = Widget.Text:extend()
|
||||
widgets.Lang = Widget:extend()
|
||||
widgets.PlayerSubMenu = DoubleTextWidget:extend()
|
||||
widgets.Key = DoubleTextWidget:extend()
|
||||
widgets.Audio = DoubleTextWidget:extend()
|
||||
|
@ -41,44 +41,33 @@ widgets.Audio = DoubleTextWidget:extend()
|
|||
|
||||
-- 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")
|
||||
function DoubleTextWidget:new(label1, label2)
|
||||
DoubleTextWidget.super.new(self, "optionMenu", label1, "left")
|
||||
local label2 = label2 or ""
|
||||
self:addLabel(label2, "right")
|
||||
end
|
||||
|
||||
-- Submenu widget :: go to a submenu
|
||||
|
||||
function widgets.SubMenu:new(scene, menu, newmenu, fullname, order, label2)
|
||||
function widgets.SubMenu:new(scene, 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)
|
||||
widgets.SubMenu.super.new(self, label, label2)
|
||||
self.order = order or 0
|
||||
end
|
||||
|
||||
function widgets.SubMenu:action()
|
||||
self.scene.assets:playSFX("confirm")
|
||||
self.scene.menusystem:switchMenu(self.newmenu)
|
||||
self.menu:switch(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)
|
||||
widgets.Dummy.super.new(self, menu, fullname)
|
||||
end
|
||||
|
||||
function widgets.Dummy:action()
|
||||
|
@ -89,14 +78,12 @@ end
|
|||
|
||||
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, "optionMenu", label, "left")
|
||||
end
|
||||
|
||||
function widgets.Exit:action()
|
||||
self.scene.assets:playSFX("confirm")
|
||||
self.assets:playSFX("confirm")
|
||||
core.scenemanager:setStoredScene("mainmenu")
|
||||
end
|
||||
|
||||
|
@ -105,14 +92,11 @@ 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(keyname)
|
||||
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, label, label2)
|
||||
self.order = 0
|
||||
end
|
||||
|
||||
|
@ -152,21 +136,19 @@ end
|
|||
|
||||
function widgets.Switch:action()
|
||||
self:modifyKey()
|
||||
self.scene.assets:playSFX("confirm")
|
||||
self.label2 = self:getLabel()
|
||||
local scene = core.scenemanager.currentScene
|
||||
scene.assets:playSFX("confirm")
|
||||
self:replaceLabel(2, 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"]
|
||||
function widgets.Resolution:new()
|
||||
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, label, label2)
|
||||
end
|
||||
|
||||
function widgets.Resolution:getLabel()
|
||||
|
@ -179,9 +161,10 @@ function widgets.Resolution:action()
|
|||
else
|
||||
core.options.data.video.resolution = core.options.data.video.resolution + 1
|
||||
end
|
||||
self.label2 = self:getLabel()
|
||||
self:replaceLabel(2, self:getLabel())
|
||||
core.screen:applySettings()
|
||||
self.scene.assets:playSFX("confirm")
|
||||
local scene = core.scenemanager.currentScene
|
||||
scene.assets:playSFX("confirm")
|
||||
self:invalidateCanvas()
|
||||
core.options:write()
|
||||
end
|
||||
|
@ -189,17 +172,15 @@ 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"]
|
||||
function widgets.Lang:new(lang)
|
||||
local label = core.lang:getLangName(lang)
|
||||
self.lang = lang
|
||||
widgets.Lang.super.new(self, widgetmenu, font, label)
|
||||
widgets.Lang.super.new(self, "optionMenu", label, "left")
|
||||
end
|
||||
|
||||
function widgets.Lang:action()
|
||||
self.scene.assets:playSFX("confirm")
|
||||
local scene = core.scenemanager.currentScene
|
||||
scene.assets:playSFX("confirm")
|
||||
core.options:setLanguage(self.lang)
|
||||
--self.scene.menusystem:invalidateAllWidgets()
|
||||
end
|
||||
|
@ -209,35 +190,31 @@ end
|
|||
|
||||
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)
|
||||
widgets.PlayerSubMenu.super.new(self, label, label2)
|
||||
self.order = 0
|
||||
end
|
||||
|
||||
function widgets.PlayerSubMenu:action()
|
||||
self.scene.assets:playSFX("confirm")
|
||||
self.scene.menusystem:switchMenu(self.newmenu)
|
||||
local scene = core.scenemanager.currentScene
|
||||
scene.assets:playSFX("confirm")
|
||||
scene.menusystem:switchMenu(self.newmenu)
|
||||
end
|
||||
|
||||
-- Key widgets
|
||||
|
||||
function widgets.Key:new(scene, sourceid, key)
|
||||
self.scene = scene
|
||||
self.source = sourceid
|
||||
function widgets.Key:new(key)
|
||||
self.source = 1
|
||||
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, label, label2)
|
||||
self.order = 0
|
||||
end
|
||||
|
||||
|
@ -246,28 +223,27 @@ function widgets.Key:getLabel()
|
|||
end
|
||||
|
||||
function widgets.Key:action()
|
||||
self.scene.assets:playSFX("navigate")
|
||||
self.scene:changeKey(self)
|
||||
self.scene.menusystem:deactivate()
|
||||
local scene = core.scenemanager.currentScene
|
||||
scene.assets:playSFX("navigate")
|
||||
scene:changeKey(self)
|
||||
scene.menusystem:deactivate()
|
||||
end
|
||||
|
||||
function widgets.Key:receiveKey( key )
|
||||
self.scene.assets:playSFX("confirm")
|
||||
local scene = core.scenemanager.currentScene
|
||||
scene.assets:playSFX("confirm")
|
||||
core.options:setInputKey(self.source, self.key, key)
|
||||
self.label2 = self:getLabel()
|
||||
self:replaceLabel(2, self:getLabel())
|
||||
self:invalidateCanvas()
|
||||
end
|
||||
|
||||
-- AUDIO FUNCTIONS
|
||||
-- Sounds/Music functions
|
||||
|
||||
function widgets.Audio:new(scene, menu, audiotype)
|
||||
self.scene = scene
|
||||
function widgets.Audio:new(audiotype)
|
||||
self.audiotype = audiotype
|
||||
|
||||
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
self.audiotype = audiotype
|
||||
local label = ""
|
||||
if (self.audiotype == "sfx") then
|
||||
|
@ -277,7 +253,7 @@ function widgets.Audio:new(scene, menu, audiotype)
|
|||
end
|
||||
local label2 = self:getLabel()
|
||||
|
||||
widgets.Audio.super.new(self, widgetmenu, font, label, label2)
|
||||
widgets.Audio.super.new(self, label, label2)
|
||||
self.order = 0
|
||||
end
|
||||
|
||||
|
@ -306,15 +282,16 @@ function widgets.Audio:setVolume(vol)
|
|||
core.options.data.audio.music = vol
|
||||
end
|
||||
|
||||
self.label2 = self:getLabel()
|
||||
self:replaceLabel(2, self:getLabel())
|
||||
self:invalidateCanvas()
|
||||
end
|
||||
|
||||
function widgets.Audio:action()
|
||||
local value = self:getVolume()
|
||||
self:setVolume(value - 20)
|
||||
self.scene.assets:playSFX("confirm")
|
||||
self.scene.assets.music:setVolume(core.options.data.audio.music / 100)
|
||||
local scene = core.scenemanager.currentScene
|
||||
scene.assets:playSFX("confirm")
|
||||
core.music:applyVolume()
|
||||
core.options:write()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue