Skip to content

Commit 3437dab

Browse files
committed
Add tab badge support with missile unit icon and count
Extend integral menu to support tab badges showing unit icon and missile count. Add badgeUnitName and badgeCountWG configuration fields to command panels. Missile widget exports total count via WG.missileTotalCount. Badge displays on Missiles tab showing tacnuke icon with ready missile count. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiaPfKSj8kGFjaUPyxYYHd
1 parent 608fac6 commit 3437dab

3 files changed

Lines changed: 68 additions & 8 deletions

File tree

LuaUI/Configs/integral_menu_config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ local commandPanels = {
521521
end,
522522
loiterable = true,
523523
buttonLayoutConfig = buttonLayoutConfig.command,
524+
badgeUnitName = "tacnuke",
525+
badgeCountWG = "missileTotalCount",
524526
},
525527
{
526528
humanName = "Orders",

LuaUI/Widgets/gui_chili_integral_menu.lua

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,9 @@ end
18191819
--------------------------------------------------------------------------------
18201820
-- Tab Panel
18211821

1822-
local function GetTabButton(panel, contentControl, name, humanName, hotkey, loiterable, OnSelect)
1822+
local function GetTabButton(panel, contentControl, name, humanName, hotkey, loiterable, OnSelect, badgeConfig)
18231823
local disabled = disabledTabs[name]
1824-
1824+
18251825
local function DoClick(mouse)
18261826
if disabled or TabClickFunction(mouse) then
18271827
return
@@ -1832,7 +1832,7 @@ local function GetTabButton(panel, contentControl, name, humanName, hotkey, loit
18321832
OnSelect()
18331833
end
18341834
end
1835-
1835+
18361836
local button = Button:New {
18371837
classname = "button_tab",
18381838
caption = humanName,
@@ -1846,23 +1846,65 @@ local function GetTabButton(panel, contentControl, name, humanName, hotkey, loit
18461846
},
18471847
}
18481848
button.backgroundColor[4] = 0.4
1849-
1849+
18501850
if disabled then
18511851
button.font = WG.GetSpecialFont(14, "integral_grey", {outlineColor = {0, 0, 0, 1}, color = {0.6, 0.6, 0.6, 1}})
18521852
button.supressButtonReaction = true
18531853
end
1854-
1854+
18551855
local hideHotkey = loiterable
1856-
1856+
18571857
if hotkey and (not hideHotkey) and (not disabled) then
18581858
button:SetCaption(humanName .. " (" .. GetGreenStr(hotkey) .. ")")
18591859
end
1860-
1860+
18611861
local externalFunctionsAndData = {
18621862
button = button,
18631863
name = name,
18641864
DoClick = DoClick,
1865+
badgePanel = nil,
18651866
}
1867+
1868+
-- Create badge if configured
1869+
if badgeConfig and badgeConfig.unitName then
1870+
local unitDef = UnitDefNames[badgeConfig.unitName]
1871+
if unitDef then
1872+
externalFunctionsAndData.badgePanel = Panel:New {
1873+
x = "100%-30",
1874+
y = 0,
1875+
width = 30,
1876+
height = 30,
1877+
parent = button,
1878+
}
1879+
1880+
Image:New {
1881+
x = 0,
1882+
y = 0,
1883+
width = 20,
1884+
height = 20,
1885+
file = "#" .. unitDef.id,
1886+
parent = externalFunctionsAndData.badgePanel,
1887+
}
1888+
1889+
externalFunctionsAndData.badgeLabel = Label:New {
1890+
x = 20,
1891+
y = 0,
1892+
width = 10,
1893+
height = 20,
1894+
caption = "0",
1895+
align = "left",
1896+
valign = "center",
1897+
fontSize = 10,
1898+
parent = externalFunctionsAndData.badgePanel,
1899+
}
1900+
1901+
function externalFunctionsAndData.UpdateBadgeCount(count)
1902+
if externalFunctionsAndData.badgeLabel then
1903+
externalFunctionsAndData.badgeLabel:SetCaption(tostring(count))
1904+
end
1905+
end
1906+
end
1907+
end
18661908

18671909
function externalFunctionsAndData.IsTabSelected()
18681910
return contentControl.visible
@@ -2345,7 +2387,7 @@ local function InitializeControls()
23452387
end
23462388
end
23472389

2348-
data.tabButton = GetTabButton(tabPanel, commandHolder, data.name, data.humanName, hotkey, data.loiterable, OnTabSelect)
2390+
data.tabButton = GetTabButton(tabPanel, commandHolder, data.name, data.humanName, hotkey, data.loiterable, OnTabSelect, {unitName = data.badgeUnitName, countWG = data.badgeCountWG})
23492391

23502392
if data.gridHotkeys and ((not data.disableableKeys) or options.unitsHotkeys2.value) then
23512393
data.buttons.ApplyGridHotkeys(gridMap, (gridCustomOverrides and gridCustomOverrides[data.name]) or {})
@@ -2550,6 +2592,15 @@ function widget:Update()
25502592
local _,cmdID = spGetActiveCommand()
25512593
UpdateButtonSelection(cmdID)
25522594
UpdateReturnToOrders(cmdID)
2595+
2596+
-- Update tab badges
2597+
for i = 1, #commandPanels do
2598+
local panelData = commandPanels[i]
2599+
if panelData.badgeCountWG and panelData.tabButton and panelData.tabButton.UpdateBadgeCount then
2600+
local count = WG[panelData.badgeCountWG] or 0
2601+
panelData.tabButton:UpdateBadgeCount(count)
2602+
end
2603+
end
25532604
end
25542605

25552606
function widget:KeyPress(key, modifier, isRepeat)

LuaUI/Widgets/missle_command_center.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,15 @@ function widget:Update(dt)
575575

576576
findButtonsByCommand()
577577

578+
local totalMissileCount = 0
579+
578580
for _, command in pairs(commands) do
579581
local count = command:getCount()
580582
local buildProgress = command:getMaxBuildProgress()
581583
local customCommands = widgetHandler.customCommands
582584

585+
totalMissileCount = totalMissileCount + count
586+
583587
for i = 1, #customCommands do
584588
if customCommands[i].id == command.cmd then
585589
local displayName = ""
@@ -605,6 +609,9 @@ function widget:Update(dt)
605609
end
606610
end
607611
end
612+
613+
-- Export total count for tab badge
614+
WG.missileTotalCount = totalMissileCount
608615
end
609616

610617
function widget:CommandNotify(cmdID, cmdParams, cmdOptions)

0 commit comments

Comments
 (0)