Skip to content

Commit 3d83d6b

Browse files
committed
Add missile build progress display to command buttons
Add getMaxBuildProgress() to track the highest build progress among all building missiles. Display format: 'x[count] ([percent]%)' or just '[percent]%' if no missiles are ready. Shows progress of the next missile being built. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiaPfKSj8kGFjaUPyxYYHd
1 parent 6d7a261 commit 3d83d6b

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

LuaUI/Widgets/missle_command_center.lua

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ local function missle_class()
111111
return count
112112
end
113113

114+
function self:getMaxBuildProgress()
115+
local maxProgress = 0
116+
local allUnits = Spring.GetTeamUnits(Spring.GetMyTeamID()) or {}
117+
118+
for _, unitID in ipairs(allUnits) do
119+
if not Spring.GetUnitIsDead(unitID) then
120+
local unitDefID = Spring.GetUnitDefID(unitID)
121+
if unitDefID and self.launchableTypes[unitDefID] then
122+
local _, _, _, _, buildProgress = Spring.GetUnitHealth(unitID)
123+
if buildProgress and buildProgress < 1 then
124+
maxProgress = math.max(maxProgress, buildProgress)
125+
end
126+
end
127+
end
128+
end
129+
return maxProgress
130+
end
131+
114132
function self:canGiveOrder(unit)
115133
local _, _, _, _, build = Spring.GetUnitHealth(unit)
116134
local type = self.launchableTypes[Spring.GetUnitDefID(unit)]
@@ -521,15 +539,24 @@ function widget:Update(dt)
521539

522540
for _, command in pairs(commands) do
523541
local count = command:getCount()
542+
local buildProgress = command:getMaxBuildProgress()
524543
local customCommands = widgetHandler.customCommands
525544

526545
for i = 1, #customCommands do
527546
if customCommands[i].id == command.cmd then
547+
local displayName = ""
528548
if count > 0 then
529-
customCommands[i].name = "x" .. count
530-
else
531-
customCommands[i].name = ""
549+
displayName = "x" .. count
550+
end
551+
if buildProgress > 0 then
552+
local progressPercent = math.floor(buildProgress * 100)
553+
if displayName ~= "" then
554+
displayName = displayName .. " (" .. progressPercent .. "%)"
555+
else
556+
displayName = progressPercent .. "%"
557+
end
532558
end
559+
customCommands[i].name = displayName
533560
break
534561
end
535562
end

0 commit comments

Comments
 (0)