sonic-bluestreak/sonic-bluestreak.love/scenes/overworld/screens/mainmenu/equip.lua
2021-11-25 10:57:13 +01:00

115 lines
4 KiB
Lua

local ParentScreen = require "scenes.overworld.screens.parent"
local EquipScreen = ParentScreen:extend()
local menu = require "game.modules.menus.list"
local const = require "scenes.overworld.screens.mainmenu.const"
local gui = require "game.modules.gui"
local baseCharacterMenu = require "scenes.overworld.screens.mainmenu.common.charmenu"
local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.charwidget"
local CharacterMenu = baseCharacterMenu:extend()
local CharacterWidget = baseCharacterWidget:extend()
local STATS = require "datas.consts.stats"
local DESC_SIZE = 32 * 6
function EquipScreen:new(scene, category, item, widgetId)
self.category = category
self.item = item
self.itemData = core.datas:get("items", self.item.name)
self.widgetId = widgetId
self.choiceBack = gui.newChoiceBack(48 + 16)
self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40 + 48+16)
self.desc = self.itemData.description
self.charName = ""
EquipScreen.super.new(self, scene, "Equipement")
end
function EquipScreen:setMenu()
CharacterMenu(self.scene, 224)
for i, name in ipairs(game.characters.team) do
CharacterWidget(self.scene, name, self.category)
end
self.scene.menusystem:switchMenu("character")
end
function EquipScreen:draw()
self.scene.assets.fonts["small"]:setLineHeight(16 / 18)
self:drawPocket()
self:drawDescription(const.X, const.Y)
end
function EquipScreen: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.itemData.fullname, xx, yy, ww, "left")
if (self.charName ~= "") then
local char = game.characters.list[self.charName]
for i, statName in ipairs(STATS.LIST) do
local xStat = xx + (((i - 1) % 2) * (ww/2))
local yStat = yy + (math.floor((i-1)/2) * 16) + 24
local middle = xStat + 10 + ww/4
local stat = char.stats:get(statName)
local newStat = char:predictStat(statName, self.category, self.item.name)
self.scene.assets.fonts["small"]:draw(STATS.SIMPLENAME[statName], xStat, yStat, ww, "left")
self.scene.assets.fonts["small"]:setColor(1, 1, 1, 0.9)
self.scene.assets.fonts["small"]:draw(stat .. " ", middle, yStat, -1, "right")
self.scene.assets.fonts["small"]:draw(">", middle, yStat, -1, "center")
if (newStat > stat) then
self.scene.assets.fonts["small"]:setColor(0.3, 1, 0.3, 0.9)
elseif (newStat < stat) then
self.scene.assets.fonts["small"]:setColor(1, 0.3, 0.3, 0.9)
end
self.scene.assets.fonts["small"]:draw(" " .. newStat, middle, yStat, -1, "left")
self.scene.assets.fonts["small"]:setColor(1, 1, 1, 1)
utils.graphics.resetColor()
end
end
end
function EquipScreen:drawPocket()
local x = const.X + DESC_SIZE - 48
local y = const.Y2 - 24
love.graphics.draw(self.choiceBack, x, y)
self.scene.assets.fonts["small"]:draw("x" .. self.item.number, x + 16, y - 2, -1, "left")
end
function EquipScreen:goBack()
self.scene.screens.mainmenu["items"](self.scene, game.loot:getPocketIdByName(self.category), self.widgetId)
end
function EquipScreen:useItem(charName)
local character = game.characters.list[charName]
if (self.item.number <= 1) then
character:setEquip(self.category, self.item.name)
self:goBack()
else
character:setEquip(self.category, self.item.name)
end
end
-- Character menu
function CharacterMenu:cancelAction()
-- Switch à l'écran précédant
self.scene.assets:playSFX("mBack")
self.scene.currentScreen:goBack()
end
-- Hero custom widget
--
function CharacterWidget:selectAction()
self.scene.currentScreen.charName = self.charName
end
function CharacterWidget:action()
self.scene.assets:playSFX("mSelect")
self.scene.currentScreen:useItem(self.charName)
self:redrawCanvas()
end
return EquipScreen