sonic-radiance/sonic-radiance.love/scenes/overworld/screens/mainmenu/common/charwidget.lua

66 lines
2.3 KiB
Lua
Raw Normal View History

local baseWidget = require "game.modules.menus.parents.widget"
local CharacterWidget = baseWidget:extend()
local ComplexHPBar = require "game.modules.gui.complexhpbar"
local Emblem = require "game.modules.gui.emblem"
-- Hero custom widget
--
2021-04-22 23:41:20 +02:00
function CharacterWidget:new(scene, name, showEquip)
self.charName = name
self.emblem = Emblem(game.characters.list[name], scene)
self.font2 = scene.assets.fonts["hudnbrs_small"]
2021-04-22 23:41:20 +02:00
self.showEquip = showEquip
CharacterWidget.super.new(self, scene, "character")
self.hpbar = ComplexHPBar(88)
self.ppbar = ComplexHPBar(88)
self.hpbar:setColorForeground(248 / 255, 160 / 255, 0, 1)
self.hpbar:setColorBackground(112 / 255, 0, 0)
self.ppbar:setColorForeground(0, 248 / 255, 248 / 255, 1)
self.ppbar:setColorBackground(0, 54 / 255, 229 / 255)
end
function CharacterWidget:drawCanvas()
local character = game.characters.list[self.charName]
self.font:setFilter("shadow")
local debut = 0
local xDebut = 32
self.font:draw(character.fullname, xDebut, debut, -1, "left")
2021-04-22 23:41:20 +02:00
if (self.showEquip == nil) then
local yLvl = debut + 16
local xLvl = xDebut
self.scene.assets.images["lvl"]:draw(xLvl, yLvl)
self.scene.assets.images["exp"]:draw(xLvl, yLvl + 10)
self.font2:print(character.level, xLvl + 19, yLvl, "left")
local expString = character.exp .. "/" .. character.exp_next
self.font2:print(expString, xLvl + 19, yLvl + 10, "left")
else
local charEquip = character.equip[self.showEquip]
local equipString = "None"
if (not utils.string.isEmpty(charEquip)) then
local data = core.datas:get("items", charEquip)
2021-04-22 23:41:20 +02:00
equipString = data.fullname
end
self.font:draw(equipString, xDebut, debut + 16, -1, "left")
end
end
function CharacterWidget:draw(x, y)
local character = game.characters.list[self.charName]
self.emblem:draw(x, y + 6)
2021-04-22 23:41:20 +02:00
if (self.showEquip == nil) then
local xDebut = x + 52
local yDebut = y + 15
self.scene.assets.fonts["hudnbrs_small"]:set()
2021-07-03 09:51:19 +02:00
local stats = character.stats
self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, stats:get(stats.HPMAX))
self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, stats:get(stats.PPMAX))
2021-04-22 23:41:20 +02:00
end
if self.canvas.texture ~= nil then
love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy)
end
end
return CharacterWidget