-- scenes/options :: a basic example of how to handle gamecore options in a menu --[[ Copyright © 2019 Kazhnuz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] local Scene = require "gamecore.modules.scenes" local OptionsMenu = Scene:extend() local ListBox = require "gamecore.modules.menusystem.listbox" local Widgets = require "examples.menus.options.widgets" function OptionsMenu:new() OptionsMenu.super.new(self) self.assets:addImageFont("medium", "examples/mainmenu/assets/medium") 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.Exit(self, "main") self.menusystem:switchMenu("main") 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) 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:draw() love.graphics.setColor(.3, .1, .4, 1) love.graphics.rectangle("fill", 0, 0, 424, 240) end return OptionsMenu