Skip to content

Commit d5f3a7d

Browse files
committed
Add visual progress bar support for missile commands
Create helper widget (gui_missile_progress.lua) to display visual progress bars on missile command buttons, showing build progress of next missile like factory units. Export progress data via WG.missileProgress for access by other widgets. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiaPfKSj8kGFjaUPyxYYHd
1 parent 3d83d6b commit d5f3a7d

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
function widget:GetInfo()
2+
return {
3+
name = "Missile Command Progress",
4+
desc = "Displays visual progress bars for missile building",
5+
author = "Amnykon",
6+
date = "2026",
7+
license = "GNU GPL, v2 or later",
8+
layer = 5,
9+
enabled = true,
10+
handler = true,
11+
}
12+
end
13+
14+
local missileCommands = {
15+
[39610] = true, -- EOS
16+
[39611] = true, -- Seismic
17+
[39612] = true, -- Shockley
18+
[39613] = true, -- Inferno
19+
[39614] = true, -- Reef
20+
[39615] = true, -- Trinity
21+
[39616] = true, -- Slow
22+
}
23+
24+
local UPDATE_FREQUENCY = 0.25
25+
local timer = UPDATE_FREQUENCY + 1
26+
27+
local function getMissileProgress(cmdID)
28+
local progressMap = {
29+
[39610] = {"tacnuke", "subtacmissile"},
30+
[39611] = {"seismic"},
31+
[39612] = {"empmissile"},
32+
[39613] = {"napalmmissile"},
33+
[39614] = {"shipcarrier"},
34+
[39615] = {"staticnuke"},
35+
[39616] = {"missileslow"},
36+
}
37+
38+
local unitNames = progressMap[cmdID]
39+
if not unitNames then return 0 end
40+
41+
local maxProgress = 0
42+
local teamUnits = Spring.GetTeamUnits(Spring.GetMyTeamID()) or {}
43+
44+
for _, unitID in ipairs(teamUnits) do
45+
if not Spring.GetUnitIsDead(unitID) then
46+
local unitDefID = Spring.GetUnitDefID(unitID)
47+
if unitDefID then
48+
local unitDef = UnitDefs[unitDefID]
49+
if unitDef then
50+
for _, unitName in ipairs(unitNames) do
51+
if unitDef.name == unitName then
52+
local _, _, _, _, buildProgress = Spring.GetUnitHealth(unitID)
53+
if buildProgress and buildProgress < 1 then
54+
maxProgress = math.max(maxProgress, buildProgress)
55+
end
56+
break
57+
end
58+
end
59+
end
60+
end
61+
end
62+
end
63+
64+
return maxProgress
65+
end
66+
67+
function widget:Update(dt)
68+
timer = timer + dt
69+
if timer < UPDATE_FREQUENCY then
70+
return
71+
end
72+
timer = 0
73+
74+
local integralMenu = widgetHandler:FindWidget("Chili Integral Menu")
75+
if not integralMenu then return end
76+
77+
for cmdID in pairs(missileCommands) do
78+
local progress = getMissileProgress(cmdID)
79+
if progress > 0 and integralMenu.SetCmdButtonProgress then
80+
integralMenu:SetCmdButtonProgress(cmdID, progress)
81+
end
82+
end
83+
end

LuaUI/Widgets/missle_command_center.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,16 @@ function widget:Update(dt)
537537
end
538538
timer = 0
539539

540+
WG.missileProgress = WG.missileProgress or {}
541+
540542
for _, command in pairs(commands) do
541543
local count = command:getCount()
542544
local buildProgress = command:getMaxBuildProgress()
543545
local customCommands = widgetHandler.customCommands
544546

547+
-- Export progress data for other widgets
548+
WG.missileProgress[command.cmd] = buildProgress
549+
545550
for i = 1, #customCommands do
546551
if customCommands[i].id == command.cmd then
547552
local displayName = ""

0 commit comments

Comments
 (0)