epervier-old/examples/mainmenu/init.lua

136 lines
4.3 KiB
Lua
Raw Normal View History

2019-04-06 19:08:30 +02:00
-- scenes/mainmenu :: the main menu of the different gamecore examples
--[[
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 MainMenu = 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()
2019-04-07 13:02:39 +02:00
local ExitWidget = Widget.Text:extend()
2019-04-06 19:08:30 +02:00
function MainMenu:new()
MainMenu.super.new(self)
2019-04-28 13:03:14 +02:00
self.assets:batchImport("examples.mainmenu.assets")
2019-04-20 17:56:30 +02:00
2019-04-06 19:08:30 +02:00
self:addMenu("main", true)
2019-04-14 17:49:25 +02:00
self:addSubMenu("menus", "menu")
self:addScene("menus", examples.Inventory, "inventory")
self:addScene("menus", examples.Options, "options")
self:addSubMenu("gameplay", "gameplay")
self:addScene("gameplay", examples.MovePlayer, "movable")
2019-04-28 17:07:53 +02:00
self:addScene("gameplay", examples.Plateformer, "plateform")
self:addScene("gameplay", examples.MovePlayer3D, "movable3D")
2019-04-20 17:56:30 +02:00
self.menusystem:setSoundFromSceneAssets("navigate")
2019-04-07 13:02:39 +02:00
ExitWidget(self, "main")
2019-04-06 19:08:30 +02:00
self.menusystem:switchMenu("main")
end
-- MENU FUNCTION
-- Functions that serve the handling of menus
function MainMenu: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 MainMenu:addSubMenu(name, fullname)
self:addMenu(name)
SubMenuWidget(self, "main", name, fullname)
2019-04-14 17:49:25 +02:00
SubMenuWidget(self, name, "main", "back", 1)
2019-04-06 19:08:30 +02:00
end
function MainMenu:addScene(submenu, scene, fullname)
SceneWidget(self, submenu, scene, fullname)
end
function MainMenu: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)
2019-04-06 19:08:30 +02:00
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
self.newmenu = newmenu
2019-04-14 17:49:25 +02:00
local label = ""
if fullname == "back" then
label = core.lang:translate("commons", fullname)
self.sfx = "cancel"
2019-04-14 17:49:25 +02:00
else
label = core.lang:translate("mainmenu", fullname)
self.sfx = "confirm"
2019-04-14 17:49:25 +02:00
end
SubMenuWidget.super.new(self, widgetmenu, font, label)
self.order = order or 0
2019-04-06 19:08:30 +02:00
end
function SubMenuWidget:action()
self.scene.assets:playSFX(self.sfx)
2019-04-06 19:08:30 +02:00
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
2019-04-14 17:49:25 +02:00
local label = core.lang:translate("mainmenu", fullname)
SceneWidget.super.new(self, widgetmenu, font, label)
2019-04-06 19:08:30 +02:00
end
function SceneWidget:action()
core.scenemanager:storeCurrentScene("mainmenu")
self.newscene()
end
2019-04-07 13:02:39 +02:00
-- 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"]
2019-04-14 17:49:25 +02:00
local label = core.lang:translate("commons", "exit")
SceneWidget.super.new(self, widgetmenu, font, label)
2019-04-07 13:02:39 +02:00
end
function ExitWidget:action()
love.event.quit()
end
2019-04-06 19:08:30 +02:00
return MainMenu