Rebase on Radiance #71
4 changed files with 62 additions and 104 deletions
|
@ -25,7 +25,7 @@ end
|
||||||
-- All widgets used by the pause menu
|
-- All widgets used by the pause menu
|
||||||
|
|
||||||
function ResumeWidget:new()
|
function ResumeWidget:new()
|
||||||
self.scene = core.scenemanager.currentScene
|
self.scene = core.scenemanager:getScene()
|
||||||
local label = "resume"
|
local label = "resume"
|
||||||
ResumeWidget.super.new(self, MENU_NAME, "medium", label)
|
ResumeWidget.super.new(self, MENU_NAME, "medium", label)
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ function ResumeWidget:action()
|
||||||
end
|
end
|
||||||
|
|
||||||
function RestartWidget:new()
|
function RestartWidget:new()
|
||||||
self.scene = core.scenemanager.currentScene
|
self.scene = core.scenemanager:getScene()
|
||||||
local label = "restart"
|
local label = "restart"
|
||||||
RestartWidget.super.new(self, MENU_NAME, "medium", label)
|
RestartWidget.super.new(self, MENU_NAME, "medium", label)
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ function RestartWidget:action()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ExitWidget:new()
|
function ExitWidget:new()
|
||||||
self.scene = core.scenemanager.currentScene
|
self.scene = core.scenemanager:getScene()
|
||||||
local label = "exit"
|
local label = "exit"
|
||||||
ExitWidget.super.new(self, MENU_NAME, "medium", label)
|
ExitWidget.super.new(self, MENU_NAME, "medium", label)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
-- scenes/mainmenu :: the main menu of the different birb scenes
|
-- scenes/mainmenu :: the main menu of the different birb examples
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Copyright © 2019 Kazhnuz
|
Copyright © 2019 Kazhnuz
|
||||||
|
@ -24,101 +24,12 @@
|
||||||
local Scene = require "birb.modules.scenes"
|
local Scene = require "birb.modules.scenes"
|
||||||
local MainMenu = Scene:extend()
|
local MainMenu = Scene:extend()
|
||||||
|
|
||||||
local TextMenu = require "birb.modules.gui.textmenu"
|
local Menu = require "scenes.mainmenu.menu"
|
||||||
|
|
||||||
local SceneWidget = TextMenu.baseWidgets.Base:extend()
|
function MainMenu:new()
|
||||||
local ExitWidget = TextMenu.baseWidgets.Base:extend()
|
MainMenu.super.new(self, true, true)
|
||||||
|
|
||||||
local MENU_NAME = "mainMenu"
|
|
||||||
|
|
||||||
function MainMenu:start()
|
|
||||||
self.assets:batchImport("scenes.mainmenu.assets")
|
self.assets:batchImport("scenes.mainmenu.assets")
|
||||||
print(self.assets:getFont("medium"))
|
Menu(self)
|
||||||
local menu = self:addMenu()
|
|
||||||
for i=1, 4 do
|
|
||||||
local name = i .. "player"
|
|
||||||
menu:addSubmenu(name, core.lang:translate("commons", name))
|
|
||||||
if i == 1 then
|
|
||||||
self:addScene(scenes.Plateformer, "plateform", i)
|
|
||||||
end
|
|
||||||
self:addScene(scenes.MovePlayer, "topdown", i)
|
|
||||||
self:addScene(scenes.MovePlayer3D, "topdown3D", i)
|
|
||||||
self:addScene(scenes.Action3D, "bigmap3D", i)
|
|
||||||
if i > 1 then
|
|
||||||
self:addScene(scenes.MovePlayer, "topdown (zoom)", i, "zoom")
|
|
||||||
self:addScene(scenes.MovePlayer3D, "topdown3D (zoom)", i, "zoom")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self:addSubMenu("menus", "menu")
|
|
||||||
self:addScene(scenes.Inventory, "inventory")
|
|
||||||
self:addScene(scenes.Options, "options")
|
|
||||||
self:addScene(scenes.TestMenu, "tests")
|
|
||||||
|
|
||||||
|
|
||||||
self.menusystem:setSoundFromSceneAssets("navigate")
|
|
||||||
local menu = self.menusystem.menus[MENU_NAME]
|
|
||||||
menu:switch("main")
|
|
||||||
|
|
||||||
ExitWidget(self, "main")
|
|
||||||
self.menusystem:switchMenu(MENU_NAME)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- MENU FUNCTION
|
|
||||||
-- Functions that serve the handling of menus
|
|
||||||
|
|
||||||
function MainMenu:addMenu()
|
|
||||||
local w = 424/2
|
|
||||||
local x, y = w / 2, 24
|
|
||||||
return TextMenu(MENU_NAME, "medium", x, y, w, 8, 0)
|
|
||||||
end
|
|
||||||
|
|
||||||
function MainMenu:addSubMenu(name, fullname)
|
|
||||||
local menu = self.menusystem.menus[MENU_NAME]
|
|
||||||
menu:addSubmenu(name, core.lang:translate("mainmenu", fullname))
|
|
||||||
end
|
|
||||||
|
|
||||||
function MainMenu:addScene(scene, fullname, arg1, arg2, arg3, arg4, arg5)
|
|
||||||
local args = {arg1, arg2, arg3, arg4, arg5}
|
|
||||||
SceneWidget(self, MENU_NAME, scene, fullname, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function MainMenu:draw()
|
|
||||||
love.graphics.setColor(.3, .1, .4, 1)
|
|
||||||
love.graphics.rectangle("fill", 0, 0, 424, 240)
|
|
||||||
utils.graphics.resetColor()
|
|
||||||
love.graphics.print(math.floor(game.playtime), 8, 8)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- WIDGETS
|
|
||||||
-- Widgets used by menus
|
|
||||||
|
|
||||||
-- Scene widget :: switch scene
|
|
||||||
|
|
||||||
function SceneWidget:new(scene, menu, newscene, fullname, args)
|
|
||||||
self.scene = scene
|
|
||||||
self.args = args
|
|
||||||
self.newscene = newscene
|
|
||||||
local label = core.lang:translate("mainmenu", fullname)
|
|
||||||
SceneWidget.super.new(self, MENU_NAME, label)
|
|
||||||
end
|
|
||||||
|
|
||||||
function SceneWidget:action()
|
|
||||||
core.scenemanager:storeCurrentScene("mainmenu")
|
|
||||||
core.scenemanager:prepareTransition()
|
|
||||||
self.newscene(self.args[1], self.args[2], self.args[3], self.args[4], self.args[5])
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Exit Widget : exit the scenes
|
|
||||||
|
|
||||||
function ExitWidget:new(scene, menu)
|
|
||||||
self.scene = scene
|
|
||||||
local label = core.lang:translate("commons", "exit")
|
|
||||||
SceneWidget.super.new(self, MENU_NAME, label)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ExitWidget:action()
|
|
||||||
game:write()
|
|
||||||
love.event.quit()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return MainMenu
|
return MainMenu
|
||||||
|
|
47
examples/scenes/mainmenu/menu.lua
Normal file
47
examples/scenes/mainmenu/menu.lua
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
local Parent = require "birb.modules.gui.textmenu"
|
||||||
|
local MainMenu = Parent:extend()
|
||||||
|
|
||||||
|
local defTransitions = require "birb.modules.transitions"
|
||||||
|
|
||||||
|
local MENU_X, MENU_Y = 24, 48
|
||||||
|
local MENU_W = 424/3
|
||||||
|
local MENU_ITEM_NUMBER = 8
|
||||||
|
|
||||||
|
function MainMenu:new()
|
||||||
|
MainMenu.super.new(self, "mainmenu", "medium", MENU_X, MENU_Y, MENU_W, MENU_ITEM_NUMBER, false)
|
||||||
|
|
||||||
|
for i=1, 4 do
|
||||||
|
local name = i .. "player"
|
||||||
|
self:switch("main")
|
||||||
|
self:addSubmenu(name, i .. " Players")
|
||||||
|
if i == 1 then
|
||||||
|
self:addItem("Plateformer", "left", function() self:launchScene(scenes.Plateformer, i) end)
|
||||||
|
end
|
||||||
|
self:addItem("Overworld", "left", function() self:launchScene(scenes.MovePlayer, i) end)
|
||||||
|
self:addItem("Basic 3D", "left", function() self:launchScene(scenes.MovePlayer3D, i) end)
|
||||||
|
self:addItem("Complexe 3D", "left", function() self:launchScene(scenes.Action3D, i) end)
|
||||||
|
if i > 1 then
|
||||||
|
self:addItem("Basic 3D (zoom)", "left", function() self:launchScene(scenes.MovePlayer3D, i, "zoom") end)
|
||||||
|
self:addItem("Complexe 3D (zoom)", "left", function() self:launchScene(scenes.Action3D, i, "zoom") end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:switch("main")
|
||||||
|
self:addSubmenu("menus", "Menus")
|
||||||
|
self:addItem("Inventory", "left", function() self:launchScene(scenes.Inventory) end)
|
||||||
|
self:addItem("Options", "left", function() self:launchScene(scenes.Options) end)
|
||||||
|
self:addItem("Tests", "left", function() self:launchScene(scenes.TestMenu) end)
|
||||||
|
self:switch("main")
|
||||||
|
self:addItem("Exit game", "left", function() self:exitGame() end)
|
||||||
|
self:getFocus()
|
||||||
|
end
|
||||||
|
|
||||||
|
function MainMenu:launchScene(scene, arg1, arg2, arg3, arg4, arg5)
|
||||||
|
local args = {arg1, arg2, arg3, arg4, arg5}
|
||||||
|
core.screen:startTransition(defTransitions.circle, defTransitions.default, function() scene(args) end, 424/2, 240/2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function MainMenu:exitGame()
|
||||||
|
love.event.quit("000")
|
||||||
|
end
|
||||||
|
|
||||||
|
return MainMenu
|
|
@ -136,7 +136,7 @@ end
|
||||||
|
|
||||||
function widgets.Switch:action()
|
function widgets.Switch:action()
|
||||||
self:modifyKey()
|
self:modifyKey()
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager:getScene()
|
||||||
scene.assets:playSFX("confirm")
|
scene.assets:playSFX("confirm")
|
||||||
self:replaceLabel(2, self:getLabel())
|
self:replaceLabel(2, self:getLabel())
|
||||||
core.options:write()
|
core.options:write()
|
||||||
|
@ -163,7 +163,7 @@ function widgets.Resolution:action()
|
||||||
end
|
end
|
||||||
self:replaceLabel(2, self:getLabel())
|
self:replaceLabel(2, self:getLabel())
|
||||||
core.screen:applySettings()
|
core.screen:applySettings()
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager:getScene()
|
||||||
scene.assets:playSFX("confirm")
|
scene.assets:playSFX("confirm")
|
||||||
self:invalidateCanvas()
|
self:invalidateCanvas()
|
||||||
core.options:write()
|
core.options:write()
|
||||||
|
@ -179,7 +179,7 @@ function widgets.Lang:new(lang)
|
||||||
end
|
end
|
||||||
|
|
||||||
function widgets.Lang:action()
|
function widgets.Lang:action()
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager:getScene()
|
||||||
scene.assets:playSFX("confirm")
|
scene.assets:playSFX("confirm")
|
||||||
core.options:setLanguage(self.lang)
|
core.options:setLanguage(self.lang)
|
||||||
--self.scene.menusystem:invalidateAllWidgets()
|
--self.scene.menusystem:invalidateAllWidgets()
|
||||||
|
@ -198,7 +198,7 @@ function widgets.PlayerSubMenu:new(scene, menu, sourceid)
|
||||||
end
|
end
|
||||||
|
|
||||||
function widgets.PlayerSubMenu:action()
|
function widgets.PlayerSubMenu:action()
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager:getScene()
|
||||||
scene.assets:playSFX("confirm")
|
scene.assets:playSFX("confirm")
|
||||||
scene.menusystem:switchMenu(self.newmenu)
|
scene.menusystem:switchMenu(self.newmenu)
|
||||||
end
|
end
|
||||||
|
@ -223,14 +223,14 @@ function widgets.Key:getLabel()
|
||||||
end
|
end
|
||||||
|
|
||||||
function widgets.Key:action()
|
function widgets.Key:action()
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager:getScene()
|
||||||
scene.assets:playSFX("navigate")
|
scene.assets:playSFX("navigate")
|
||||||
scene:changeKey(self)
|
scene:changeKey(self)
|
||||||
scene.menusystem:deactivate()
|
scene.menusystem:deactivate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function widgets.Key:receiveKey( key )
|
function widgets.Key:receiveKey( key )
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager:getScene()
|
||||||
scene.assets:playSFX("confirm")
|
scene.assets:playSFX("confirm")
|
||||||
core.options:setInputKey(self.source, self.key, key)
|
core.options:setInputKey(self.source, self.key, key)
|
||||||
self:replaceLabel(2, self:getLabel())
|
self:replaceLabel(2, self:getLabel())
|
||||||
|
@ -289,7 +289,7 @@ end
|
||||||
function widgets.Audio:action()
|
function widgets.Audio:action()
|
||||||
local value = self:getVolume()
|
local value = self:getVolume()
|
||||||
self:setVolume(value - 20)
|
self:setVolume(value - 20)
|
||||||
local scene = core.scenemanager.currentScene
|
local scene = core.scenemanager:getScene()
|
||||||
scene.assets:playSFX("confirm")
|
scene.assets:playSFX("confirm")
|
||||||
core.music:applyVolume()
|
core.music:applyVolume()
|
||||||
core.options:write()
|
core.options:write()
|
||||||
|
|
Loading…
Reference in a new issue