Skip to content

Commit

Permalink
Use the skirt size instead of footprint size
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed Jun 22, 2024
1 parent 223d9ec commit 5bd048c
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions lua/ui/game/cursor/Adjacency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ local BackgroundTextures = {
---@field FrameCount number
UnitAdjacencyLabel = ClassUI(Group) {

StandardLabelDimensions = 48,
StandardLabelDimensions = 64,

---@param self UIUnitAdjacencyLabel
---@param parent Control
Expand Down Expand Up @@ -110,18 +110,34 @@ UnitAdjacencyLabel = ClassUI(Group) {
---@param unit UserUnit
SetScale = function(self, worldView, unit)
local unitBlueprint = unit:GetBlueprint()
local unitFootprintSize = math.min(unitBlueprint.Footprint.SizeX, unitBlueprint.Footprint.SizeZ)
local unitSkirtSize = math.min(unitBlueprint.Physics.SkirtSizeX, unitBlueprint.Physics.SkirtSizeZ)
local unitPosition = unit:GetPosition()
local unitScreenPosition1 = worldView:Project({ unitPosition[1] - unitFootprintSize / 2, unitPosition[2],
unitPosition[3] + unitFootprintSize / 2 })
local unitScreenPosition2 = worldView:Project({ unitPosition[1] + unitFootprintSize / 2, unitPosition[2],
unitPosition[3] - unitFootprintSize / 2 })
local unitScreenPosition1 = worldView:Project(
{
unitPosition[1] - unitSkirtSize * 0.5,
unitPosition[2],
unitPosition[3] + unitSkirtSize * 0.5
}
)
local unitScreenPosition2 = worldView:Project(
{
unitPosition[1] + unitSkirtSize * 0.5,
unitPosition[2],
unitPosition[3] - unitSkirtSize * 0.5
}
)

local standardPixels = self.StandardLabelDimensions
local screenPixels = unitScreenPosition2[1] - unitScreenPosition1[1]

-- check if the icon fits on top of the footprint, if not then we shrink it once
local ratio = math.floor(math.clamp((unitScreenPosition2[1] - unitScreenPosition1[1]) / (0.5 * self.StandardLabelDimensions), 0.5, 2.0) * self.StandardLabelDimensions) * (1 / self.StandardLabelDimensions)
local ratio = math.floor(
math.clamp(screenPixels / standardPixels, 0.25, 1.0) * standardPixels
) * (1 / standardPixels)

LayoutHelpers.LayoutFor(self)
:Width(ratio * self.StandardLabelDimensions)
:Height(ratio * self.StandardLabelDimensions)
:Width(ratio * standardPixels)
:Height(ratio * standardPixels)
end,

--- Positions the label on top of a unit.
Expand Down

0 comments on commit 5bd048c

Please sign in to comment.