2020-05-01 14:19:00 +02:00
|
|
|
local HUD = Object:extend()
|
|
|
|
|
|
|
|
local gui = require "game.modules.gui"
|
|
|
|
local TweenManager = require "game.modules.tweenmanager"
|
|
|
|
|
2020-08-04 18:50:36 +02:00
|
|
|
local PLAYER_HUD_HIDDEN = 240+64
|
|
|
|
local PLAYER_HUD_VISIBLE = 240-44
|
2021-03-13 17:26:05 +01:00
|
|
|
local PLAYER_MESSAGE = 240 - 24
|
2020-05-01 14:19:00 +02:00
|
|
|
|
2020-07-19 16:20:57 +02:00
|
|
|
function HUD:new(turns)
|
|
|
|
self.turns = turns
|
|
|
|
self.scene = turns.scene
|
|
|
|
self.world = self.scene.world
|
|
|
|
self.assets = self.scene.assets
|
2020-05-01 14:19:00 +02:00
|
|
|
|
|
|
|
self.frame = gui.newBorder(424, 30, 4)
|
|
|
|
self.tweens = TweenManager(self)
|
|
|
|
|
2020-08-04 18:50:36 +02:00
|
|
|
self.playerHUDPosition = PLAYER_HUD_HIDDEN
|
2020-05-01 16:15:39 +02:00
|
|
|
self.battlerCursor = self.turns.turns.current
|
2021-03-13 17:26:05 +01:00
|
|
|
|
|
|
|
self.message = "Test de message"
|
|
|
|
self.messageOpacity = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function HUD:showMessage(message)
|
|
|
|
self.message = message
|
|
|
|
self.messageOpacity = 1
|
|
|
|
self.tweens:newTween(0, 0.2, {messageOpacity = 1}, 'inOutCubic')
|
|
|
|
self.tweens:newTween(1, 0.2, {messageOpacity = 0}, 'inOutCubic')
|
2020-05-01 14:19:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function HUD:update(dt)
|
|
|
|
self.tweens:update(dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
function HUD:movePlayerHUD(beginBattle)
|
|
|
|
if (beginBattle) then
|
2020-08-04 18:50:36 +02:00
|
|
|
self.tweens:newTween(0, 0.4, {playerHUDPosition = PLAYER_HUD_VISIBLE}, 'inCubic')
|
2020-05-01 14:19:00 +02:00
|
|
|
else
|
2020-08-04 18:50:36 +02:00
|
|
|
self.tweens:newTween(0, 0.4, {playerHUDPosition = PLAYER_HUD_HIDDEN}, 'inCubic')
|
2020-05-01 14:19:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function HUD:moveBattleCursor(moveCursorTo)
|
|
|
|
self.tweens:newTween(0, 0.2, {battlerCursor = moveCursorTo}, 'inCubic')
|
|
|
|
end
|
|
|
|
|
|
|
|
function HUD:getPlayerHUDPosition()
|
|
|
|
return self.playerHUDPosition
|
|
|
|
end
|
|
|
|
|
|
|
|
function HUD:draw()
|
2020-08-04 18:50:36 +02:00
|
|
|
local x, y = 4, 5
|
2020-05-01 14:19:00 +02:00
|
|
|
|
2020-08-04 18:50:36 +02:00
|
|
|
love.graphics.draw(self.frame, 0, 24, 0, 1, -1)
|
2020-05-01 14:19:00 +02:00
|
|
|
self.assets.images["hudturn"]:draw(x, y)
|
|
|
|
self.assets.fonts["hudnbrs"]:set()
|
2020-05-01 16:15:39 +02:00
|
|
|
local turnnbr = self.turns.turns.number
|
2020-05-01 14:19:00 +02:00
|
|
|
if (turnnbr < 10) then
|
|
|
|
turnnbr = "0" .. turnnbr
|
|
|
|
end
|
|
|
|
love.graphics.print(turnnbr, x + 33, y + 1)
|
2020-08-04 18:50:36 +02:00
|
|
|
|
|
|
|
for i, action in ipairs(self.turns.actionList) do
|
|
|
|
if action.fighter:canFight() then
|
|
|
|
action.fighter:drawIcon(76 + (i-1)*(20), 5)
|
|
|
|
else
|
|
|
|
self:drawEmptyIcon(76 + (i-1)*(20), 5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local cursorx = (self.battlerCursor-1) * 20 + 76
|
|
|
|
|
|
|
|
if #self.turns.actionList > 0 then
|
|
|
|
self.assets.images["menucursor"]:draw(cursorx, 5, math.rad(90), 1, 1, 4, 16)
|
|
|
|
end
|
2021-03-13 17:26:05 +01:00
|
|
|
|
|
|
|
love.graphics.setColor(0,0,0, 0.5 * self.messageOpacity)
|
|
|
|
love.graphics.rectangle("fill", 0, PLAYER_MESSAGE, 424, 16)
|
|
|
|
if (self.messageOpacity > 0) then
|
|
|
|
self.assets.fonts["small"]:setColor(1,1,1, self.messageOpacity)
|
|
|
|
self.assets.fonts["small"]:draw(self.message, 424/2, PLAYER_MESSAGE - 1, -1, "center")
|
|
|
|
self.assets.fonts["small"]:setColor(1,1,1, 1)
|
|
|
|
end
|
|
|
|
utils.graphics.resetColor()
|
2020-05-01 14:19:00 +02:00
|
|
|
end
|
|
|
|
|
2020-07-25 12:03:14 +02:00
|
|
|
function HUD:drawEmptyIcon(x, y)
|
|
|
|
local outlineLight = 0.15
|
|
|
|
love.graphics.circle("fill", x + 8, y + 8, 2, 8)
|
|
|
|
love.graphics.setColor(outlineLight, outlineLight, outlineLight, 1)
|
|
|
|
love.graphics.circle("line", x + 8, y + 8, 2, 8)
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
end
|
|
|
|
|
2020-05-01 14:19:00 +02:00
|
|
|
return HUD
|