hp-bar-the-dumb-way #22

Merged
PeaAshMeter merged 7 commits from hp-bar-the-dumb-way into main 2025-12-07 20:35:58 +03:00
2 changed files with 31 additions and 3 deletions
Showing only changes of commit bc1c6cfd6a - Show all commits

View File

@ -1,9 +1,22 @@
local Rect = require "lib.simple_ui.rect" local Rect = require "lib.simple_ui.rect"
local function makeGradientMesh(w, h, topColor, bottomColor)
local vertices = {
{ 0, 0, 0, 0, topColor[1], topColor[2], topColor[3], topColor[4] }, -- левый верх
{ w, 0, 1, 0, topColor[1], topColor[2], topColor[3], topColor[4] }, -- правый верх
{ w, h, 1, 1, bottomColor[1], bottomColor[2], bottomColor[3], bottomColor[4] }, -- правый низ
{ 0, h, 0, 1, bottomColor[1], bottomColor[2], bottomColor[3], bottomColor[4] }, -- левый низ
}
local mesh = love.graphics.newMesh(vertices, "fan", "static")
return mesh
end
--- @class UIElement --- @class UIElement
--- @field bounds Rect Прямоугольник, в границах которого размещается элемент. Размеры и положение в *локальных* координатах --- @field bounds Rect Прямоугольник, в границах которого размещается элемент. Размеры и положение в экранных координатах
--- @field transform love.Transform Преобразование из локальных координат элемента (bounds) в экранные координаты --- @field overlayGradientMesh love.Mesh Общий градиент поверх элемента (интерполированный меш)
local uiElement = {} local uiElement = {}
uiElement.bounds = Rect {}
uiElement.overlayGradientMesh = makeGradientMesh(1, 1, { 0, 0, 0, 0 }, { 0, 0, 0, 0.4 });
uiElement.__index = uiElement uiElement.__index = uiElement
function uiElement:update(dt) end function uiElement:update(dt) end
@ -20,6 +33,7 @@ end
--- @return T --- @return T
function uiElement.new(self, values) function uiElement.new(self, values)
values.bounds = values.bounds or Rect {} values.bounds = values.bounds or Rect {}
values.overlayGradientMesh = values.overlayGradientMesh or uiElement.bounds;
return setmetatable(values, self) return setmetatable(values, self)
end end
@ -59,4 +73,14 @@ function uiElement:drawBorder(type)
love.graphics.setColor(1, 1, 1) love.graphics.setColor(1, 1, 1)
end end
--- рисует градиент поверх элемента
function uiElement:drawGradientOverlay()
love.graphics.push()
love.graphics.translate(self.bounds.x, self.bounds.y)
love.graphics.scale(self.bounds.width, self.bounds.height)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(self.overlayGradientMesh)
love.graphics.pop()
end
return uiElement return uiElement

View File

@ -197,8 +197,12 @@ function skillRow:draw()
--граница --граница
self:drawBorder("outer") self:drawBorder("outer")
love.graphics.setColor(1, 1, 1) love.graphics.setStencilTest()
--затенение
self:drawGradientOverlay()
love.graphics.setColor(1, 1, 1)
love.graphics.setCanvas() love.graphics.setCanvas()
local alpha = 1 local alpha = 1