sonic-radiance/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua

138 lines
4.1 KiB
Lua
Raw Normal View History

2020-08-29 11:36:59 +02:00
local ParentScreen = require "scenes.overworld.screens.parent"
local ItemsScreen = ParentScreen:extend()
local menu = require "game.modules.menus.list"
local const = require "scenes.overworld.screens.mainmenu.const"
local gui = require "game.modules.gui"
local ItemWidget = menu.DualTextWidget:extend()
local BackWidget = menu.DualTextWidget:extend()
local DESC_SIZE = 48*4
function ItemsScreen:new(scene)
self.menuIndex = 1
self.choiceBack = gui.newChoiceBack(DESC_SIZE)
self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40+16)
self.effectBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40)
self.desc = ""
self.effects = ""
ItemsScreen.super.new(self, scene, "Items")
end
function ItemsScreen:update(dt)
local keys = self.scene:getKeys(1)
if (keys["left"].isPressed) then
self:getMenu(self.menuIndex - 1)
end
if (keys["right"].isPressed) then
self:getMenu(self.menuIndex + 1)
end
end
function ItemsScreen:getMenu(newMenuIndex)
local newMenuIndex = newMenuIndex or 1
if (newMenuIndex > #game.loot.inventory) then
newMenuIndex = 1
end
if (newMenuIndex < 1) then
newMenuIndex = #game.loot.inventory
end
self.menuIndex = newMenuIndex
self.scene.menusystem:reset()
self:setMenu()
end
function ItemsScreen:setMenu()
self.pocket = game.loot:getPocketById(self.menuIndex)
local w = 128+32
menu.ListMenu(self.scene, "menu", const.X2 - w, const.Y + 8, 128+32, 9, true)
for i,item in ipairs(self.pocket.list) do
--menu.DualTextWidget(self.scene, "menu", item.name, "x" .. item.number)
ItemWidget(self.scene, self.pocket.name, item)
end
BackWidget(self.scene)
self.scene.menusystem.menus["menu"]:setCancelWidget()
self.scene.menusystem:switchMenu("menu")
end
function ItemsScreen:draw()
self.scene.assets.fonts["small"]:setLineHeight(16/18)
self:drawPocket()
self:drawDescription(const.X, const.Y2 - (88+16))
self:drawEffects(const.X, const.Y2 - 40)
end
function ItemsScreen:drawDescription(x, y)
love.graphics.draw(self.descBox, x, y)
local xx, yy, ww = x + 6, y + 4, DESC_SIZE - 12
self.scene.assets.fonts["small"]:draw(self.desc, xx, yy, ww, "left")
end
function ItemsScreen:drawEffects(x, y)
love.graphics.draw(self.effectBox, x, y)
local xx, yy, ww = x + 6, y + 4, DESC_SIZE - 12
self.scene.assets.fonts["small"]:draw(self.effects, xx, yy, ww, "left")
end
function ItemsScreen:drawPocket()
local middleX = ((16) + (DESC_SIZE - 24)) / 2
love.graphics.draw(self.choiceBack, const.X, const.Y)
self.scene.assets.fonts["small"]:draw("<", const.X + 16, const.Y - 2, -1, "left")
self.scene.assets.fonts["small"]:draw(">", const.X + DESC_SIZE - 24, const.Y - 2, -1, "right")
self.scene.assets.fonts["small"]:draw(self.pocket.fullname, const.X + middleX, const.Y - 2, -1, "center")
self:drawPocketRoll(const.X + 48*2, const.Y + 20)
end
function ItemsScreen:drawPocketRoll(x, y)
core.screen:setScissor(const.X, const.Y+ 16, 48*4, 48)
local trueX = x - ((self.menuIndex - 1) * 32)
for i, pocket in ipairs(game.loot.inventory) do
local trueIndex = i - self.menuIndex
if (trueIndex > 4) then
trueIndex = trueIndex - 8
end
if (trueIndex < -4) then
trueIndex = trueIndex + 8
end
if (trueIndex ~= 0) then
love.graphics.setColor(.3, .3, .3, .6)
end
self.scene.assets.tileset["itembox"]:drawTile(i, x + ((trueIndex)*32), y, 0, 1, 1, 14, 0)
utils.graphics.resetColor()
end
core.screen:resetScissor()
end
-- Widgets
function ItemWidget:new(scene, pocket, item)
self.item = item
self.itemData = game.loot:getItemData(pocket, self.item.name)
ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. self.item.number)
end
function ItemWidget:selectAction()
self.scene.currentScreen.desc = self.itemData.description
end
--BackWidget
function BackWidget:new(scene)
ItemWidget.super.new(self, scene, "menu", "Back", "")
end
function BackWidget:selectAction()
self.scene.currentScreen.desc = ""
self.scene.currentScreen.effects = ""
end
function BackWidget:action()
self.scene.screens.mainmenu["pause"](self.scene, "main", 3)
end
return ItemsScreen