sonic-radiance/sonic-radiance.love/scenes/options/init.lua
2020-08-01 16:06:08 +02:00

97 lines
2.5 KiB
Lua

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