example/mainmenu : add an exit widget

This commit is contained in:
Kazhnuz 2019-04-07 13:02:39 +02:00
parent a9fb455ec0
commit 00aedfd89b

View file

@ -29,6 +29,7 @@ local Widget = require "gamecore.modules.menusystem.widgets"
local SubMenuWidget = Widget.Text:extend()
local SceneWidget = Widget.Text:extend()
local ExitWidget = Widget.Text:extend()
function MainMenu:new()
MainMenu.super.new(self)
@ -42,6 +43,7 @@ function MainMenu:new()
self:addSubMenu("menus", "Menus Tests")
self:addScene("menus", examples.Inventory, "Inventory")
ExitWidget(self, "main")
self.menusystem:switchMenu("main")
end
@ -102,5 +104,17 @@ function SceneWidget:action()
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 MainMenu