allow window resizing again

This commit is contained in:
PeaAshMeter 2025-12-08 03:53:43 +03:00
parent 7394249cb8
commit 615738d06a
4 changed files with 85 additions and 52 deletions

View File

@ -65,6 +65,8 @@ function barElement:draw()
self.bounds.y, self.bounds.width, "center") self.bounds.y, self.bounds.width, "center")
end end
self:drawBorder("inner")
self:drawGradientOverlay() self:drawGradientOverlay()
end end
@ -109,7 +111,7 @@ function bottomBars.new(cid)
end end
function bottomBars:update(dt) function bottomBars:update(dt)
local height = 14 local height = 16
local margin = 2 local margin = 2
self.bounds.height = height self.bounds.height = height
@ -117,16 +119,16 @@ function bottomBars:update(dt)
self.hpBar.bounds = Rect { self.hpBar.bounds = Rect {
width = -2 * margin + self.bounds.width / 2, width = -2 * margin + self.bounds.width / 2,
height = height, height = height - margin,
x = self.bounds.x + margin, x = self.bounds.x + margin,
y = self.bounds.y y = self.bounds.y + margin
} }
self.manaBar.bounds = Rect { self.manaBar.bounds = Rect {
width = -2 * margin + self.bounds.width / 2, width = -2 * margin + self.bounds.width / 2,
height = height, height = height - margin,
x = self.bounds.x + margin + self.bounds.width / 2, x = self.bounds.x + margin + self.bounds.width / 2,
y = self.bounds.y y = self.bounds.y + margin
} }
self.hpBar:update(dt) self.hpBar:update(dt)
@ -148,8 +150,6 @@ function bottomBars:draw()
self.manaBar:draw() self.manaBar:draw()
end end
local c = love.graphics.newCanvas(1280, 720) --- @TODO: выставлять канвасу правильный размер в зависимости от окна
--- @class CharacterPanel : UIElement --- @class CharacterPanel : UIElement
--- @field animationNode AnimationNode --- @field animationNode AnimationNode
--- @field state "show" | "idle" | "hide" --- @field state "show" | "idle" | "hide"
@ -193,6 +193,9 @@ function characterPanel:hide()
}:run() }:run()
end end
--- @type love.Canvas
local characterPanelCanvas;
function characterPanel:update(dt) function characterPanel:update(dt)
if self.animationNode then self.animationNode:update(dt) end if self.animationNode then self.animationNode:update(dt) end
self.skillRow:update(dt) self.skillRow:update(dt)
@ -210,6 +213,10 @@ function characterPanel:update(dt)
height = self.bars.bounds.height + self.skillRow.bounds.height height = self.bars.bounds.height + self.skillRow.bounds.height
} }
if not characterPanelCanvas then
characterPanelCanvas = love.graphics.newCanvas(self.bounds.width, self.bounds.height)
end
--- анимация появления --- анимация появления
local alpha = 1 local alpha = 1
if self.state == "show" then if self.state == "show" then
@ -222,19 +229,33 @@ function characterPanel:update(dt)
end end
function characterPanel:draw() function characterPanel:draw()
love.graphics.setCanvas(c)
love.graphics.clear()
self.skillRow:draw() self.skillRow:draw()
self.bars:draw()
--- @TODO: переписать этот ужас с жонглированием координатами, а то слишком хардкод (skillRow рисуется относительно нуля и не закрывает канвас)
love.graphics.push()
local canvas = love.graphics.getCanvas()
love.graphics.translate(0, self.bars.bounds.height)
love.graphics.setCanvas(characterPanelCanvas)
love.graphics.clear()
love.graphics.draw(canvas)
love.graphics.pop()
love.graphics.push()
love.graphics.translate(-self.bounds.x, -self.bounds.y)
self.bars:draw()
self:drawBorder("outer") self:drawBorder("outer")
love.graphics.pop()
--- рисуем текстуру шейдером появления --- рисуем текстуру шейдером появления
love.graphics.setCanvas() love.graphics.setCanvas()
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)
love.graphics.draw(c)
love.graphics.push()
love.graphics.translate(self.bounds.x, self.bounds.y)
love.graphics.draw(characterPanelCanvas)
love.graphics.setColor(1, 1, 1) love.graphics.setColor(1, 1, 1)
love.graphics.pop()
love.graphics.setShader() love.graphics.setShader()
end end

View File

@ -1,2 +1,2 @@
local UI_SCALE = 0.8 -- выдуманное значение для dependency injection local UI_SCALE = 0.75 -- выдуманное значение для dependency injection, надо подбирать так, чтобы UI_SCALE * 64 было целым числом
return UI_SCALE return UI_SCALE

View File

@ -103,8 +103,11 @@ function skillRow.new(characterId)
return t return t
end end
--- @type love.Canvas
local c;
function skillRow:update(dt) function skillRow:update(dt)
local iconSize = 64 * UI_SCALE local iconSize = math.floor(64 * UI_SCALE)
local screenW, screenH = love.graphics.getDimensions() local screenW, screenH = love.graphics.getDimensions()
local padding, margin = 8, 4 local padding, margin = 8, 4
local count = #self.children -- слоты под скиллы local count = #self.children -- слоты под скиллы
@ -121,16 +124,22 @@ function skillRow:update(dt)
y = self.bounds.y + margin, height = iconSize, width = iconSize } y = self.bounds.y + margin, height = iconSize, width = iconSize }
skb:update(dt) skb:update(dt)
end end
if not c then
c = love.graphics.newCanvas(self.bounds.width, self.bounds.height)
end
end end
local c = love.graphics.newCanvas(1280, 720) --- @TODO: выставлять канвасу правильный размер в зависимости от окна
function skillRow:draw() function skillRow:draw()
local oldCanvas = love.graphics.getCanvas()
love.graphics.setCanvas({ c, stencil = true }) love.graphics.setCanvas({ c, stencil = true })
love.graphics.clear() love.graphics.clear()
love.graphics.setColor(1, 1, 1) love.graphics.setColor(1, 1, 1)
do
--- рисуем в локальных координатах текстурки
love.graphics.push()
love.graphics.translate(-self.bounds.x, -self.bounds.y)
-- сначала иконки скиллов -- сначала иконки скиллов
for _, skb in ipairs(self.children) do for _, skb in ipairs(self.children) do
skb:draw() skb:draw()
@ -148,6 +157,7 @@ function skillRow:draw()
end, "replace", 1) end, "replace", 1)
love.graphics.setShader() love.graphics.setShader()
-- дальше рисуем панель, перекрывая иконки -- дальше рисуем панель, перекрывая иконки
love.graphics.setStencilTest("less", 1) love.graphics.setStencilTest("less", 1)
-- шум -- шум
@ -165,10 +175,12 @@ function skillRow:draw()
--затенение --затенение
self:drawGradientOverlay() self:drawGradientOverlay()
love.graphics.pop()
end
love.graphics.setColor(1, 1, 1) love.graphics.setColor(1, 1, 1)
love.graphics.setCanvas(oldCanvas) -- love.graphics.setCanvas(oldCanvas)
love.graphics.draw(c) -- love.graphics.draw(c)
end end
return skillRow.new return skillRow.new

View File

@ -18,7 +18,7 @@ function love.load()
end end
Tree.level.turnOrder:endRound() Tree.level.turnOrder:endRound()
print("Now playing:", Tree.level.turnOrder.current) print("Now playing:", Tree.level.turnOrder.current)
love.window.setMode(1280, 720, { resizable = false, msaa = 0, vsync = true }) love.window.setMode(1280, 720, { resizable = true, msaa = 4, vsync = true })
end end
local lt = "0" local lt = "0"