examples/options: use mainmenu as a base
This commit is contained in:
parent
193e9b6fbf
commit
6c2be10628
1 changed files with 123 additions and 0 deletions
123
examples/menus/options/init.lua
Normal file
123
examples/menus/options/init.lua
Normal file
|
@ -0,0 +1,123 @@
|
|||
-- 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 Widget = require "gamecore.modules.menusystem.widgets"
|
||||
|
||||
local SubMenuWidget = Widget.Text:extend()
|
||||
local SceneWidget = Widget.Text:extend()
|
||||
local ExitWidget = Widget.Text:extend()
|
||||
|
||||
function OptionsMenu:new()
|
||||
OptionsMenu.super.new(self)
|
||||
self.assets:addImageFont("medium", "examples/mainmenu/assets/medium")
|
||||
|
||||
self:addMenu("main", true)
|
||||
self:addSubMenu("basic", "Basic Tests")
|
||||
self:addScene("basic", examples.Test, "Basic Test 1")
|
||||
self:addScene("basic", examples.Test2, "Basic Test 2")
|
||||
self:addScene("basic", examples.TestMenu, "Basic Test Menu")
|
||||
self:addSubMenu("menus", "Menus Tests")
|
||||
self:addScene("menus", examples.Inventory, "Inventory")
|
||||
self:addSubMenu("gameplay", "Games Examples")
|
||||
self:addScene("gameplay", examples.MovePlayer, "Movable Player")
|
||||
|
||||
ExitWidget(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)
|
||||
SubMenuWidget(self, "main", name, fullname)
|
||||
SubMenuWidget(self, name, "main", "< Back", 1)
|
||||
end
|
||||
|
||||
function OptionsMenu:addScene(submenu, scene, fullname)
|
||||
SceneWidget(self, submenu, scene, fullname)
|
||||
end
|
||||
|
||||
function OptionsMenu:draw()
|
||||
love.graphics.setColor(.3, .1, .4, 1)
|
||||
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
||||
end
|
||||
|
||||
-- WIDGETS
|
||||
-- Widgets used by menus
|
||||
|
||||
-- Submenu widget :: go to a submenu
|
||||
|
||||
function SubMenuWidget:new(scene, menu, newmenu, fullname, order)
|
||||
self.scene = scene
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
self.newmenu = newmenu
|
||||
SubMenuWidget.super.new(self, widgetmenu, font, fullname)
|
||||
self.order = order or 0
|
||||
end
|
||||
|
||||
function SubMenuWidget:action()
|
||||
self.scene.menusystem:switchMenu(self.newmenu)
|
||||
end
|
||||
|
||||
-- Scene widget :: switch scene
|
||||
|
||||
function SceneWidget:new(scene, menu, newscene, fullname)
|
||||
self.scene = scene
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
self.newscene = newscene
|
||||
SceneWidget.super.new(self, widgetmenu, font, fullname)
|
||||
end
|
||||
|
||||
function SceneWidget:action()
|
||||
core.scenemanager:storeCurrentScene("mainmenu")
|
||||
self.newscene()
|
||||
end
|
||||
|
||||
-- Exit Widget : exit the examples
|
||||
|
||||
function ExitWidget:new(scene, menu)
|
||||
self.scene = scene
|
||||
local widgetmenu = self.scene.menusystem.menus[menu]
|
||||
local font = self.scene.assets.fonts["medium"]
|
||||
SceneWidget.super.new(self, widgetmenu, font, "Exit")
|
||||
end
|
||||
|
||||
function ExitWidget:action()
|
||||
love.event.quit()
|
||||
end
|
||||
|
||||
return OptionsMenu
|
Loading…
Reference in a new issue