minimal end turn button implementation
This commit is contained in:
parent
2012035eb6
commit
586ea68d2b
@ -38,7 +38,7 @@ local controlMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function camera:update(dt)
|
function camera:update(dt)
|
||||||
if self.animationNode and not (self.animationNode.t >= 1) then
|
if self.animationNode and self.animationNode.state == "running" then
|
||||||
self.animationNode:update(dt) -- тик анимации
|
self.animationNode:update(dt) -- тик анимации
|
||||||
self.position = utils.lerp(self.animationBeginPosition, self.animationEndPosition, self.animationNode:getValue())
|
self.position = utils.lerp(self.animationBeginPosition, self.animationEndPosition, self.animationNode:getValue())
|
||||||
return
|
return
|
||||||
@ -100,7 +100,7 @@ end
|
|||||||
--- @param position Vec3
|
--- @param position Vec3
|
||||||
--- @param animationNode AnimationNode
|
--- @param animationNode AnimationNode
|
||||||
function camera:animateTo(position, animationNode)
|
function camera:animateTo(position, animationNode)
|
||||||
if self.animationNode then self.animationNode:finish() end
|
if self.animationNode and self.animationNode.state ~= "finished" then self.animationNode:finish() end
|
||||||
self.animationNode = animationNode
|
self.animationNode = animationNode
|
||||||
self.animationEndPosition = position
|
self.animationEndPosition = position
|
||||||
self.animationBeginPosition = self.position
|
self.animationBeginPosition = self.position
|
||||||
|
|||||||
@ -35,7 +35,6 @@ function level:update(dt)
|
|||||||
el:update(dt)
|
el:update(dt)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self.camera:update(dt)
|
|
||||||
self.selector:update(dt)
|
self.selector:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -34,11 +34,8 @@ function selector:update(dt)
|
|||||||
|
|
||||||
char:try(Tree.behaviors.spellcaster, function(b)
|
char:try(Tree.behaviors.spellcaster, function(b)
|
||||||
if not b.cast then
|
if not b.cast then
|
||||||
-- тут какая-то страшная дичь, я даже не уверен что оно работает
|
if not selectedId then self:select(nil) end
|
||||||
-- зато я точно уверен, что это надо было писать не так
|
return
|
||||||
if not selectedId then self:select(selectedId) end
|
|
||||||
if selectedId ~= Tree.level.turnOrder.current and Tree.level.turnOrder.isTurnsEnabled then return end
|
|
||||||
return self:select(selectedId)
|
|
||||||
end
|
end
|
||||||
if b.cast:cast(char, mousePosition) then
|
if b.cast:cast(char, mousePosition) then
|
||||||
self:lock()
|
self:lock()
|
||||||
|
|||||||
@ -30,7 +30,6 @@ end
|
|||||||
---
|
---
|
||||||
--- Если в очереди на ход больше никого нет, заканчиваем раунд
|
--- Если в очереди на ход больше никого нет, заканчиваем раунд
|
||||||
function turnOrder:next()
|
function turnOrder:next()
|
||||||
Tree.level.selector:select(nil)
|
|
||||||
self.actedQueue:insert(self.current)
|
self.actedQueue:insert(self.current)
|
||||||
local next = self.pendingQueue:peek()
|
local next = self.pendingQueue:peek()
|
||||||
if not next then return self:endRound() end
|
if not next then return self:endRound() end
|
||||||
|
|||||||
@ -4,13 +4,14 @@ local Element = require "lib.simple_ui.element"
|
|||||||
local Rect = require "lib.simple_ui.rect"
|
local Rect = require "lib.simple_ui.rect"
|
||||||
local SkillRow = require "lib.simple_ui.level.skill_row"
|
local SkillRow = require "lib.simple_ui.level.skill_row"
|
||||||
local Bars = require "lib.simple_ui.level.bottom_bars"
|
local Bars = require "lib.simple_ui.level.bottom_bars"
|
||||||
|
local EndTurnButton = require "lib.simple_ui.level.end_turn"
|
||||||
|
|
||||||
--- @class CharacterPanel : UIElement
|
--- @class CharacterPanel : UIElement
|
||||||
--- @field animationNode AnimationNode
|
--- @field animationNode AnimationNode
|
||||||
--- @field state "show" | "idle" | "hide"
|
--- @field state "show" | "idle" | "hide"
|
||||||
--- @field skillRow SkillRow
|
--- @field skillRow SkillRow
|
||||||
--- @field bars BottomBars
|
--- @field bars BottomBars
|
||||||
|
--- @field endTurnButton EndTurnButton
|
||||||
local characterPanel = setmetatable({}, Element)
|
local characterPanel = setmetatable({}, Element)
|
||||||
characterPanel.__index = characterPanel
|
characterPanel.__index = characterPanel
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ function characterPanel.new(characterId)
|
|||||||
t.state = "show"
|
t.state = "show"
|
||||||
t.skillRow = SkillRow(characterId)
|
t.skillRow = SkillRow(characterId)
|
||||||
t.bars = Bars(characterId)
|
t.bars = Bars(characterId)
|
||||||
|
t.endTurnButton = EndTurnButton {}
|
||||||
return setmetatable(t, characterPanel)
|
return setmetatable(t, characterPanel)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -69,6 +71,14 @@ function characterPanel:update(dt)
|
|||||||
height = self.bars.bounds.height + self.skillRow.bounds.height
|
height = self.bars.bounds.height + self.skillRow.bounds.height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.endTurnButton.bounds = Rect {
|
||||||
|
x = self.bounds.x + self.bounds.width + 32,
|
||||||
|
y = self.bounds.y + 12,
|
||||||
|
width = 150,
|
||||||
|
height = self.bounds.height - 24
|
||||||
|
}
|
||||||
|
self.endTurnButton:update(dt)
|
||||||
|
|
||||||
if not characterPanelCanvas then
|
if not characterPanelCanvas then
|
||||||
characterPanelCanvas = love.graphics.newCanvas(self.bounds.width, self.bounds.height)
|
characterPanelCanvas = love.graphics.newCanvas(self.bounds.width, self.bounds.height)
|
||||||
end
|
end
|
||||||
@ -107,6 +117,8 @@ function characterPanel:draw()
|
|||||||
love.graphics.setShader(Tree.assets.files.shaders.reveal)
|
love.graphics.setShader(Tree.assets.files.shaders.reveal)
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
|
||||||
|
self.endTurnButton:draw()
|
||||||
|
|
||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
love.graphics.translate(self.bounds.x, self.bounds.y)
|
love.graphics.translate(self.bounds.x, self.bounds.y)
|
||||||
love.graphics.draw(characterPanelCanvas)
|
love.graphics.draw(characterPanelCanvas)
|
||||||
|
|||||||
64
lib/simple_ui/level/end_turn.lua
Normal file
64
lib/simple_ui/level/end_turn.lua
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
local Element = require "lib.simple_ui.element"
|
||||||
|
local AnimationNode = require "lib.animation_node"
|
||||||
|
local easing = require "lib.utils.easing"
|
||||||
|
|
||||||
|
--- @class EndTurnButton : UIElement
|
||||||
|
--- @field hovered boolean
|
||||||
|
--- @field onClick function?
|
||||||
|
local endTurnButton = setmetatable({}, Element)
|
||||||
|
endTurnButton.__index = endTurnButton
|
||||||
|
|
||||||
|
function endTurnButton:update(dt)
|
||||||
|
local mx, my = love.mouse.getPosition()
|
||||||
|
if self:hitTest(mx, my) then
|
||||||
|
self.hovered = true
|
||||||
|
if Tree.controls:isJustPressed("select") then
|
||||||
|
if self.onClick then self.onClick() end
|
||||||
|
Tree.controls:consume("select")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.hovered = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function endTurnButton:draw()
|
||||||
|
love.graphics.setColor(38 / 255, 50 / 255, 56 / 255)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
|
||||||
|
if self.hovered then
|
||||||
|
love.graphics.setColor(0.1, 0.1, 0.1)
|
||||||
|
love.graphics.rectangle("fill", self.bounds.x, self.bounds.y, self.bounds.width, self.bounds.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
love.graphics.setColor(0.95, 0.95, 0.95)
|
||||||
|
local font = love.graphics.newFont(16)
|
||||||
|
love.graphics.printf("end_turn", font, self.bounds.x,
|
||||||
|
(self.bounds.y + self.bounds.height / 2) - (font:getHeight() / 2), self.bounds.width, "center")
|
||||||
|
|
||||||
|
|
||||||
|
love.graphics.setLineWidth(2)
|
||||||
|
self:drawBorder("outer")
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function endTurnButton:onClick()
|
||||||
|
Tree.level.turnOrder:next()
|
||||||
|
Tree.level.selector:select(nil)
|
||||||
|
local cid = Tree.level.turnOrder.current
|
||||||
|
local playing = Tree.level.characters[cid]
|
||||||
|
if not playing:has(Tree.behaviors.map) then return end
|
||||||
|
|
||||||
|
AnimationNode {
|
||||||
|
function(node)
|
||||||
|
Tree.level.camera:animateTo(playing:has(Tree.behaviors.map).displayedPosition, node)
|
||||||
|
end,
|
||||||
|
duration = 1500,
|
||||||
|
easing = easing.easeInOutCubic,
|
||||||
|
onEnd = function() Tree.level.selector:select(cid) end
|
||||||
|
}:run()
|
||||||
|
end
|
||||||
|
|
||||||
|
return function(values)
|
||||||
|
return endTurnButton:new(values)
|
||||||
|
end
|
||||||
@ -1,15 +1,19 @@
|
|||||||
local CPanel = require "lib.simple_ui.level.cpanel"
|
local CPanel = require "lib.simple_ui.level.cpanel"
|
||||||
|
|
||||||
|
local build
|
||||||
|
|
||||||
local layout = {}
|
local layout = {}
|
||||||
function layout:update(dt)
|
function layout:update(dt)
|
||||||
|
if self.characterPanel then self.characterPanel:update(dt) end
|
||||||
|
|
||||||
local cid = Tree.level.selector:selected()
|
local cid = Tree.level.selector:selected()
|
||||||
if cid then
|
if cid then
|
||||||
self.characterPanel = CPanel(cid)
|
self.characterPanel = CPanel(cid)
|
||||||
self.characterPanel:show()
|
self.characterPanel:show()
|
||||||
|
self.characterPanel:update(dt)
|
||||||
elseif Tree.level.selector:deselected() then
|
elseif Tree.level.selector:deselected() then
|
||||||
self.characterPanel:hide()
|
self.characterPanel:hide()
|
||||||
end
|
end
|
||||||
if self.characterPanel then self.characterPanel:update(dt) end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function layout:draw()
|
function layout:draw()
|
||||||
|
|||||||
14
main.lua
14
main.lua
@ -25,21 +25,11 @@ local lt = "0"
|
|||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
local t1 = love.timer.getTime()
|
local t1 = love.timer.getTime()
|
||||||
Tree.controls:poll()
|
Tree.controls:poll()
|
||||||
testLayout:update(dt) -- логика UI-слоя должна отработать раньше всех, потому что нужно перехватить жесты и не пустить их дальше
|
Tree.level.camera:update(dt) -- сначала логика камеры, потому что на нее завязан UI
|
||||||
|
testLayout:update(dt) -- потом UI, потому что нужно перехватить жесты и не пустить их дальше
|
||||||
Tree.panning:update(dt)
|
Tree.panning:update(dt)
|
||||||
Tree.level:update(dt)
|
Tree.level:update(dt)
|
||||||
|
|
||||||
-- для тестов очереди ходов
|
|
||||||
-- удалить как только появится ui для людей
|
|
||||||
if Tree.controls:isJustPressed("endTurnTest") then
|
|
||||||
Tree.level.turnOrder:next()
|
|
||||||
print("Now playing:", Tree.level.turnOrder.current)
|
|
||||||
end
|
|
||||||
if Tree.controls:isJustPressed("toggleTurns") then
|
|
||||||
print('toggle turns')
|
|
||||||
Tree.level.turnOrder:toggleTurns()
|
|
||||||
end
|
|
||||||
|
|
||||||
Tree.controls:cache()
|
Tree.controls:cache()
|
||||||
|
|
||||||
local t2 = love.timer.getTime()
|
local t2 = love.timer.getTime()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user