Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion language/en/interface.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@
"gone": "%{player} (gone)",
"team": "Team %{number}",
"members": "%{count} players",
"memberOne": "1 player",
"notYet": "Not available yet",
"unknownPlayer": "Unknown player",
"foldHint": "Click to fold.",
Expand Down
68 changes: 49 additions & 19 deletions luaui/Include/graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,34 @@ end
-- Text, queued while the list is built and printed in one batch
----------------------------------------------------------------

function Graph:text(str, x, y, opts, size)
-- `asName` marks what a series is called - a player, a team - which the caller can ask to
-- be set in a face of its own (`cfg.nameFont`), the way the rest of the interface writes
-- names. Everything else is the interface's own face.
function Graph:text(str, x, y, opts, size, asName)
local n = self.pendingCount + 1
self.pendingCount = n
self.pending[n] = { str, x, y, size or self.cfg.fontSize, opts or "o" }
self.pending[n] = { str, x, y, size or self.cfg.fontSize, opts or "o", asName or false }
end

-- One batch a face, with the outline pinned: the fonts are shared with every widget, so a
-- bake would otherwise freeze in whatever outline the last one set.
function Graph:printBatch(face, asName, all)
local began = false
for i = 1, self.pendingCount do
local p = self.pending[i]
---@cast p -?
if all or p[6] == asName then
if not began then
began = true
face:Begin()
face:SetOutlineColor(self.cfg.look.outline)
end
face:Print(p[1], p[2], p[3], p[4], p[5])
end
end
if began then
face:End()
end
end

function Graph:flushText()
Expand All @@ -616,22 +640,21 @@ function Graph:flushText()
self.pendingCount = 0
return
end
font:Begin()
-- The font is shared with every widget; pinned so a bake does not freeze in whatever
-- outline the last one set.
font:SetOutlineColor(self.cfg.look.outline)
local nameFont = self.cfg.nameFont or font
if nameFont == font then
self:printBatch(font, false, true)
else
self:printBatch(font, false)
self:printBatch(nameFont, true)
end
for i = 1, self.pendingCount do
local p = self.pending[i]
---@cast p -?
font:Print(p[1], p[2], p[3], p[4], p[5])
self.pending[i] = nil
end
font:End()
self.pendingCount = 0
end

function Graph:textWidth(str, size)
local font = self.cfg.font
function Graph:textWidth(str, size, asName)
local font = (asName and self.cfg.nameFont) or self.cfg.font
if not font then
return #str * (size or self.cfg.fontSize) * 0.55
end
Expand Down Expand Up @@ -926,7 +949,7 @@ function Graph:prepareLine()
if cfg.legend and #self.prepared > 0 then
local rows, x = 1, left
for _, p in ipairs(self.prepared) do
local w = mathFloor(fs * 0.8) + fs * 0.4 + self:textWidth(p.name, fs)
local w = mathFloor(fs * 0.8) + fs * 0.4 + self:textWidth(p.name, fs, true)
if x + w > plot.right and x > left then
rows = rows + 1
x = left
Expand All @@ -943,7 +966,7 @@ function Graph:prepareLine()
if cfg.endLabels and not stacked and #self.prepared > 0 then
local w = 0
for _, p in ipairs(self.prepared) do
w = mathMax(w, self:textWidth(p.name, fs))
w = mathMax(w, self:textWidth(p.name, fs, true))
end
local room = mathFloor(w + fs * 0.8)
if room < (right - left) / 3 then
Expand Down Expand Up @@ -1490,7 +1513,7 @@ function Graph:drawEndLabels()
local c = it.p.color
local k = alphaOf(self, it.si, 1)
local faded = { c[1] * k + 0.1 * (1 - k), c[2] * k + 0.1 * (1 - k), c[3] * k + 0.1 * (1 - k) }
self:text(colorCode(faded) .. it.p.name, x, mathFloor(it.y), "ov", fs)
self:text(colorCode(faded) .. it.p.name, x, mathFloor(it.y), "ov", fs, true)
end
end

Expand Down Expand Up @@ -1950,7 +1973,7 @@ function Graph:drawLegend()
local x = x0
local swatch = mathFloor(fs * 0.8)
for si, p in ipairs(entries) do
local w = self:textWidth(p.name, fs)
local w = self:textWidth(p.name, fs, true)
-- Wrapped where the layout counted a row for it.
if x + swatch + fs * 0.4 + w > plot.right and x > x0 then
x = x0
Expand All @@ -1966,7 +1989,7 @@ function Graph:drawLegend()
glVertex(x, y + swatch)
end)
local color = isLit(self, si) and look.text or "\255\130\130\130"
self:text(color .. p.name, mathFloor(x + swatch + fs * 0.4), mathFloor(y + swatch * 0.15), "o", fs)
self:text(color .. p.name, mathFloor(x + swatch + fs * 0.4), mathFloor(y + swatch * 0.15), "o", fs, true)
x = mathFloor(x + swatch + fs * 0.4 + w + fs * 1.2)
end
end
Expand Down Expand Up @@ -2322,7 +2345,7 @@ function Graph:drawRadar()
local y = mathFloor(self.plot.top - fs * 1.2)
local swatch = mathFloor(fs * 0.8)
for si, p in ipairs(self.prepared) do
local w = self:textWidth(p.name, fs)
local w = self:textWidth(p.name, fs, true)
if x + swatch + fs * 0.5 + w > self.plot.right then
break
end
Expand All @@ -2334,7 +2357,14 @@ function Graph:drawRadar()
glVertex(x + swatch, y + swatch)
glVertex(x, y + swatch)
end)
self:text(look.text .. p.name, mathFloor(x + swatch + fs * 0.4), mathFloor(y + swatch * 0.15), "o", fs)
self:text(
look.text .. p.name,
mathFloor(x + swatch + fs * 0.4),
mathFloor(y + swatch * 0.15),
"o",
fs,
true
)
x = mathFloor(x + swatch + fs * 0.4 + w + fs * 1.2)
end
end
Expand Down
38 changes: 29 additions & 9 deletions luaui/Include/teamstats_graphs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,8 @@ function M.new(ctx)
return layoutParts().toggle
end

function page.setFont(font, fontSize)
chart:configure({ font = font, fontSize = fontSize })
function page.setFont(font, fontSize, nameFont)
chart:configure({ font = font, fontSize = fontSize, nameFont = nameFont or font })
page.dirty = true
end

Expand Down Expand Up @@ -1909,7 +1909,10 @@ function M.new(ctx)
local unit = {
key = "ally" .. ally.id,
allyID = ally.id,
name = ctx.i18n("ui.teamStats.team", { number = ally.id + 1 }),
-- A side of one player goes by that player's name: its number would say
-- nothing beside it.
name = (#ally.teams == 1 and ally.teams[1].name)
or ctx.i18n("ui.teamStats.team", { number = ally.id + 1 }),
color = first and { first.accent[1], first.accent[2], first.accent[3] } or { 0.8, 0.8, 0.8 },
members = members,
teams = ally.teams,
Expand Down Expand Up @@ -2026,8 +2029,12 @@ function M.new(ctx)
local pad = ctx.metrics.sidePad
local fs = ctx.metrics.catFs
local font = ctx.font()
local function widthOf(label)
return font and mathFloor(font:GetTextWidth(label) * fs) or #label * fs * 0.55
-- A block standing for a team or a player is captioned with its name, in the face
-- the interface names players in, so its room is measured in that face too.
local nameFont = ctx.nameFont()
local function widthOf(label, isName)
local face = isName and nameFont or font
return face and mathFloor(face:GetTextWidth(label) * fs) or #label * fs * 0.55
end
local all = { all = true, label = ctx.i18n("ui.teamStats.graph.all"), members = {} }
all.labelW = widthOf(all.label)
Expand Down Expand Up @@ -2060,10 +2067,15 @@ function M.new(ctx)
local block = seen[team.allyID]
if not block then
-- A side of one is named after its player, and the viewer's own - playing
-- or watching it - is "You".
-- or watching it - is "You" where every side is one player, since nothing
-- else on the bar is theirs. In a game of teams the viewer has a block of
-- their own beside All, so a side of one keeps its player's name there.
local allyUnit = page.unitByKey and page.unitByKey["ally" .. team.allyID]
local label = ctx.i18n("ui.teamStats.team", { number = team.allyID + 1 })
if ctx.soloTeams then
label = team.isLocal and youLabel or team.name
elseif allyUnit and #allyUnit.teams == 1 then
label = team.name
end
block = {
ally = team.allyID,
Expand All @@ -2090,7 +2102,8 @@ function M.new(ctx)
local b = blocks[i]
if not b.all and not b.me then
count = count + #b.members
b.labelW = widthOf(b.label)
b.named = true
b.labelW = widthOf(b.label, true)
labelW = labelW + b.labelW + pad
if b.short then
b.shortW = widthOf(b.short)
Expand Down Expand Up @@ -3484,7 +3497,7 @@ function M.new(ctx)
fillChart(chartOf, mini.key, true)
-- A column's chart says itself whether its % of total is on it; the others take
-- their short name from the list.
local setup = { font = ctx.font(), fontSize = mini.fs }
local setup = { font = ctx.font(), fontSize = mini.fs, nameFont = ctx.nameFont() }
if not ctx.COLUMNS[statOf(mini.key)] then
setup.title = mini.label
end
Expand Down Expand Up @@ -3725,7 +3738,14 @@ function M.new(ctx)
Highlight(b.x1, py1, b.x2, py2, cs, look.barHoverOpacity, look.white)
end
if b.labelX then
ctx.queueText((lit and colors.selected or colors.dim) .. (b.caption or b.label), b.labelX, cy, fs, "ov")
ctx.queueText(
(lit and colors.selected or colors.dim) .. (b.caption or b.label),
b.labelX,
cy,
fs,
"ov",
b.named and not b.caption and "name" or nil
)
end
if b.swatch and b.unit then
local c = b.unit.color
Expand Down
Loading
Loading