Skip to content

Commit 6545ead

Browse files
committed
Fix bad shared state between the selection window and the tool window by splitting the nMaxCaptionCharacters variable into two, one for each
1 parent 33bd95f commit 6545ead

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

LuaUI/Widgets/gui_chili_selections_and_cursortip.lua

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,15 +1283,26 @@ local function UpdatePanelWidthsIfNeeded(caption, parentPanel, otherPanel)
12831283
if parentPanel.name ~= "leftPanel" or caption == nil then
12841284
return
12851285
end
1286+
local isTooltipVersion = parentPanel.parent.name == "tooltipWindow"
12861287
local n = string.len(caption)
1287-
if nMaxCaptionCharacters ~= nil and n <= nMaxCaptionCharacters then
1288+
local nMax = nil
1289+
if isTooltipVersion then
1290+
nMax = nMaxCaptionCharactersForTooltip
1291+
else
1292+
nMax = nMaxCaptionCharactersForSelection
1293+
end
1294+
if nMax ~= nil and n <= nMax then
12881295
return
12891296
end
1290-
nMaxCaptionCharacters = n
1297+
if isTooltipVersion then
1298+
nMaxCaptionCharactersForTooltip = n
1299+
else
1300+
nMaxCaptionCharactersForSelection = n
1301+
end
12911302
local w = LEFT_WIDTH
1292-
if nMaxCaptionCharacters > 10 then
1303+
if n > 10 then
12931304
-- icon, characters minus the color tags (HACK this assumes that the string has color tags)
1294-
w = ICON_SIZE + nMaxCaptionCharacters * 5 - 4
1305+
w = ICON_SIZE + n * 5 - 4
12951306
end
12961307
if w ~= parentPanel.minWidth then
12971308
parentPanel.minWidth = w
@@ -2465,6 +2476,15 @@ local function GetSingleUnitInfoPanel(parentControl, isTooltipVersion)
24652476
rightPanel:SetVisibility(newVisible)
24662477
end
24672478

2479+
function externalFunctions.ResetPanelWidths()
2480+
local w = LEFT_WIDTH
2481+
if leftPanel.minWidth ~= w then
2482+
leftPanel.minWidth = w
2483+
leftPanel:Resize(w, leftPanel.height)
2484+
rightPanel:SetPos(w, 0)
2485+
end
2486+
end
2487+
24682488
return externalFunctions
24692489
end
24702490

@@ -2744,7 +2764,7 @@ local function UpdateTooltip(dt, requiredOnly)
27442764
if visible then
27452765
tooltipWindow.SetPosition(mx + 20/(WG.uiScale or 1), my - 20/(WG.uiScale or 1))
27462766
else
2747-
nMaxCaptionCharacters = 0
2767+
nMaxCaptionCharactersForTooltip = 0
27482768
end
27492769
end
27502770

@@ -2820,6 +2840,8 @@ local function GetSelectionWindow()
28202840

28212841
function externalFunctions.ShowSingleUnit(unitID, unitDefID)
28222842
singleUnitID, singleUnitDefID = unitID, unitDefID or spGetUnitDefID(unitID)
2843+
nMaxCaptionCharactersForSelection = 0
2844+
singleUnitDisplay.ResetPanelWidths()
28232845
singleUnitDisplay.SetDisplay(unitID, singleUnitDefID)
28242846
singleUnitDisplay.SetVisible(true)
28252847
multiUnitDisplay.SetUnitDisplay()
@@ -2956,7 +2978,8 @@ local function InitializeWindParameters()
29562978
econMultEnabled = (Spring.GetGameRulesParam("econ_mult_enabled") and true) or false
29572979
end
29582980

2959-
local nMaxCaptionCharacters = 0
2981+
local nMaxCaptionCharactersForTooltip = 0
2982+
local nMaxCaptionCharactersForSelection = 0
29602983

29612984
local updateTimer = 0
29622985
function widget:Update(dt)

0 commit comments

Comments
 (0)