115 lines
3.4 KiB
Lua
115 lines
3.4 KiB
Lua
|
-- 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()
|
||
|
|
||
|
function Inventory:new()
|
||
|
Inventory.super.new(self)
|
||
|
self.assets:addImageFont("medium", "examples/test_menus/assets/medium")
|
||
|
|
||
|
|
||
|
HListBox(self.menusystem, "main", 42, 32, 424-84, 32, 5)
|
||
|
self:addSubMenu("weapon", "Weapons")
|
||
|
self:addSubMenu("shield", "Shields")
|
||
|
self:addSubMenu("stuff", "Stuff")
|
||
|
|
||
|
self:addItem("weapon", 3)
|
||
|
self:addItem("weapon", 2)
|
||
|
|
||
|
self:addItem("shield", 2)
|
||
|
self:addItem("shield", 1)
|
||
|
|
||
|
self.menusystem.menus["main"].isLocked = true
|
||
|
|
||
|
self.menusystem:switchMenu("main")
|
||
|
self.menusystem.menus["weapon"].isVisible = true
|
||
|
self.menusystem.menus["weapon"].isActive = true
|
||
|
|
||
|
|
||
|
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
|
||
|
InventoryWidget.super.new(self, widgetmenu, font, fullname)
|
||
|
end
|
||
|
|
||
|
function InventoryWidget:action()
|
||
|
self.scene.menusystem:switchMenu(self.newmenu)
|
||
|
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
|
||
|
|
||
|
|
||
|
return Inventory
|