examples : add basic inventory example

This commit is contained in:
Kazhnuz 2019-04-07 12:33:28 +02:00
parent 714a20ca23
commit 81f6b940a4
5 changed files with 122 additions and 0 deletions

View file

@ -3,4 +3,5 @@ return {
Test2 = require "examples.test_scene2",
TestMenu = require "examples.test_menus",
MainMenu = require "examples.mainmenu",
Inventory = require "examples.menus.inventory"
}

View file

@ -39,6 +39,8 @@ function MainMenu:new()
self:addScene("basic", examples.Test, "Basic Test 1")
self:addScene("basic", examples.Test2, "Basic Test 2")
self:addScene("basic", examples.TestMenu, "Basic Test Menu")
self:addSubMenu("menus", "Menus Tests")
self:addScene("menus", examples.Inventory, "Inventory")
self.menusystem:switchMenu("main")
end

View file

@ -0,0 +1,5 @@
return {
filename = "medium.png",
glyphs = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|} ",
extraspacing = 1,
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,114 @@
-- 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