epervier-old/examples/menus/inventory/init.lua

131 lines
4 KiB
Lua
Raw Normal View History

2019-04-07 12:33:28 +02:00
-- scenes/inventory :: a basic inventory example
--[[
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 Inventory = Scene:extend()
local HListBox = require "gamecore.modules.menusystem.hlistbox"
local FloxBox = require "gamecore.modules.menusystem.flowbox"
local Widget = require "gamecore.modules.menusystem.widgets"
local InventoryWidget = Widget.Text:extend()
local ItemWidget = Widget.Text:extend()
2019-04-07 12:48:03 +02:00
local ExitWidget = Widget.Text:extend()
2019-04-07 12:33:28 +02:00
function Inventory:new()
Inventory.super.new(self)
self.assets:addImageFont("medium", "assets/fonts/medium")
2019-04-07 12:33:28 +02:00
HListBox(self.menusystem, "main", 42, 32, 424-84, 32, 5)
self:addSubMenu("weapon", "weapons")
self:addSubMenu("shield", "shields")
self:addSubMenu("stuff", "stuff")
ExitWidget(self, "main", "exit")
2019-04-07 12:33:28 +02:00
self:addItem("weapon", 3)
self:addItem("weapon", 2)
self:addItem("shield", 2)
self:addItem("shield", 1)
self.menusystem:lockMenu("main")
2019-04-07 12:33:28 +02:00
self.menusystem:switchMenu("main")
self.menusystem:setMenuActivity("weapon", true)
2019-04-07 12:33:28 +02:00
end
-- MENU FUNCTION
-- Functions that serve the handling of menus
function Inventory:addMenu(name, nobackbutton)
local w, h = 424 - 84, 240 - 48
local x, y = 42, 64 + 4
local widgetw, widgeth = w / 24, h / 24
FloxBox(self.menusystem, name, x, y, w, h, widgetw, widgeth)
end
function Inventory:addSubMenu(name, fullname)
self:addMenu(name)
InventoryWidget(self, "main", name, fullname)
end
function Inventory:addItem(submenu, id)
ItemWidget(self, submenu, id)
end
function Inventory: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 InventoryWidget:new(scene, menu, newmenu, fullname)
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
self.newmenu = newmenu
local label = core.lang:translate("inventory", fullname)
InventoryWidget.super.new(self, widgetmenu, font, label)
2019-04-07 12:33:28 +02:00
end
function InventoryWidget:action(source)
2019-04-07 12:33:28 +02:00
self.scene.menusystem:switchMenu(self.newmenu)
if (source == "pointer") then
self.scene.menusystem.menus["main"]:getFocus()
end
2019-04-07 12:33:28 +02:00
end
-- Scene widget :: switch scene
function ItemWidget:new(scene, menu, id)
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
ItemWidget.super.new(self, widgetmenu, font, id)
end
function ItemWidget:action()
end
2019-04-07 12:48:03 +02:00
-- Exit widget
function ExitWidget:new(scene, menu)
2019-04-07 12:48:03 +02:00
self.scene = scene
local widgetmenu = self.scene.menusystem.menus[menu]
local font = self.scene.assets.fonts["medium"]
local label = core.lang:translate("commons", "exit")
ExitWidget.super.new(self, widgetmenu, font, label)
2019-04-07 12:48:03 +02:00
end
function ExitWidget:action(source)
core.scenemanager:setStoredScene("mainmenu")
end
2019-04-07 12:33:28 +02:00
return Inventory