@@ -1279,7 +1279,39 @@ local function GetImage(parentControl, name, initY, imageFile, iconSize, xOffset
12791279 return Update
12801280end
12811281
1282- local function GetImageWithText (parentControl , name , initY , imageFile , caption , fontSize , iconSize , textOffset , xOffset )
1282+ local function UpdatePanelWidthsIfNeeded (caption , parentPanel , otherPanel )
1283+ if parentPanel .name ~= " leftPanel" or caption == nil then
1284+ return
1285+ end
1286+ local isTooltipVersion = parentPanel .parent .name == " tooltipWindow"
1287+ local n = string.len (caption )
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
1295+ return
1296+ end
1297+ if isTooltipVersion then
1298+ nMaxCaptionCharactersForTooltip = n
1299+ else
1300+ nMaxCaptionCharactersForSelection = n
1301+ end
1302+ local w = LEFT_WIDTH
1303+ if n > 10 then
1304+ -- icon, characters minus the color tags (HACK this assumes that the string has color tags)
1305+ w = ICON_SIZE + n * 5 - 4
1306+ end
1307+ if w ~= parentPanel .minWidth then
1308+ parentPanel .minWidth = w
1309+ parentPanel :Resize (w , parentPanel .height )
1310+ otherPanel :SetPos (w , 0 )
1311+ end
1312+ end
1313+
1314+ local function GetImageWithText (parentControl , otherPanel , name , initY , imageFile , caption , fontSize , iconSize , textOffset , xOffset )
12831315 fontSize = fontSize or IMAGE_FONT
12841316 iconSize = iconSize or ICON_SIZE
12851317 xOffset = xOffset or 0
@@ -1317,6 +1349,7 @@ local function GetImageWithText(parentControl, name, initY, imageFile, caption,
13171349 label :SetPos (nil , yPos + textOffset , nil , nil , nil , true )
13181350 end
13191351 label :SetCaption (newCaption )
1352+ UpdatePanelWidthsIfNeeded (newCaption , parentControl , otherPanel )
13201353 if newImage ~= imageFile then
13211354 if imageFile == nil then
13221355 label :SetPos (iconSize + 2 , nil , nil , nil , nil , true )
@@ -2016,6 +2049,7 @@ local function GetSingleUnitInfoPanel(parentControl, isTooltipVersion)
20162049 width = LEFT_WIDTH ,
20172050 minWidth = LEFT_WIDTH ,
20182051 autosize = true ,
2052+ resizable = true ,
20192053 padding = {0 ,2 ,0 ,2 },
20202054 parent = parentControl ,
20212055 }
@@ -2035,9 +2069,9 @@ local function GetSingleUnitInfoPanel(parentControl, isTooltipVersion)
20352069 name = " unitImage" ,
20362070 x = 0 ,
20372071 y = 0 ,
2038- right = 0 ,
2072+ left = 0 ,
20392073 height = PIC_HEIGHT ,
2040- keepAspect = false ,
2074+ keepAspect = true ,
20412075 file = imageFile ,
20422076 parent = leftPanel ,
20432077 }
@@ -2060,7 +2094,7 @@ local function GetSingleUnitInfoPanel(parentControl, isTooltipVersion)
20602094 end
20612095 end
20622096
2063- local unitNameUpdate = GetImageWithText (rightPanel , " unitNameUpdate" , 1 , nil , nil , NAME_FONT , nil , 2 , 1 )
2097+ local unitNameUpdate = GetImageWithText (rightPanel , leftPanel , " unitNameUpdate" , 1 , nil , nil , NAME_FONT , nil , 2 , 1 )
20642098
20652099 local unitDesc = Chili .TextBox :New {
20662100 name = " unitDesc" ,
@@ -2072,12 +2106,12 @@ local function GetSingleUnitInfoPanel(parentControl, isTooltipVersion)
20722106 parent = rightPanel ,
20732107 }
20742108
2075- local costInfoUpdate = GetImageWithText (leftPanel , " costInfoUpdate" , PIC_HEIGHT + 4 , IMAGE .COST , nil , nil , ICON_SIZE , 4 )
2076- local metalInfoUpdate = GetImageWithText (leftPanel , " metalInfoUpdate" , PIC_HEIGHT + LEFT_SPACE + 4 , IMAGE .METAL , nil , nil , ICON_SIZE , 4 )
2077- local energyInfoUpdate = GetImageWithText (leftPanel , " energyInfoUpdate" , PIC_HEIGHT + 2 * LEFT_SPACE + 4 , IMAGE .ENERGY , nil , nil , ICON_SIZE , 4 )
2078- local maxHealthLabel = GetImageWithText (rightPanel , " maxHealthLabel" , PIC_HEIGHT + 4 , IMAGE .HEALTH , nil , NAME_FONT , ICON_SIZE , 2 , 2 )
2109+ local costInfoUpdate = GetImageWithText (leftPanel , rightPanel , " costInfoUpdate" , PIC_HEIGHT + 4 , IMAGE .COST , nil , nil , ICON_SIZE , 4 )
2110+ local metalInfoUpdate = GetImageWithText (leftPanel , rightPanel , " metalInfoUpdate" , PIC_HEIGHT + LEFT_SPACE + 4 , IMAGE .METAL , nil , nil , ICON_SIZE , 4 )
2111+ local energyInfoUpdate = GetImageWithText (leftPanel , rightPanel , " energyInfoUpdate" , PIC_HEIGHT + 2 * LEFT_SPACE + 4 , IMAGE .ENERGY , nil , nil , ICON_SIZE , 4 )
2112+ local maxHealthLabel = GetImageWithText (rightPanel , leftPanel , " maxHealthLabel" , PIC_HEIGHT + 4 , IMAGE .HEALTH , nil , NAME_FONT , ICON_SIZE , 2 , 2 )
20792113
2080- local minWindLabel = GetImageWithText (leftPanel , " minWindLabel" , PIC_HEIGHT + LEFT_SPACE + 4 , IMAGE .WIND_SPEED , nil , nil , ICON_SIZE , 4 )
2114+ local minWindLabel = GetImageWithText (leftPanel , rightPanel , " minWindLabel" , PIC_HEIGHT + LEFT_SPACE + 4 , IMAGE .WIND_SPEED , nil , nil , ICON_SIZE , 4 )
20812115 local healthBarUpdate = GetBarWithImage (rightPanel , " healthBarUpdate" , PIC_HEIGHT + 4 , IMAGE .HEALTH , {0 , 1 , 0 , 1 }, GetHealthColor )
20822116 local unitpicBadgeUpdate = GetImage (unitImage , " costInfoUpdate" , 4 , IMAGE .NO_AMMO , ICON_SIZE , 4 )
20832117
@@ -2443,6 +2477,15 @@ local function GetSingleUnitInfoPanel(parentControl, isTooltipVersion)
24432477 rightPanel :SetVisibility (newVisible )
24442478 end
24452479
2480+ function externalFunctions .ResetPanelWidths ()
2481+ local w = LEFT_WIDTH
2482+ if leftPanel .minWidth ~= w then
2483+ leftPanel .minWidth = w
2484+ leftPanel :Resize (w , leftPanel .height )
2485+ rightPanel :SetPos (w , 0 )
2486+ end
2487+ end
2488+
24462489 return externalFunctions
24472490end
24482491
@@ -2721,6 +2764,8 @@ local function UpdateTooltip(dt, requiredOnly)
27212764 tooltipWindow .SetVisible (visible )
27222765 if visible then
27232766 tooltipWindow .SetPosition (mx + 20 / (WG .uiScale or 1 ), my - 20 / (WG .uiScale or 1 ))
2767+ else
2768+ nMaxCaptionCharactersForTooltip = 0
27242769 end
27252770end
27262771
@@ -2796,6 +2841,8 @@ local function GetSelectionWindow()
27962841
27972842 function externalFunctions .ShowSingleUnit (unitID , unitDefID )
27982843 singleUnitID , singleUnitDefID = unitID , unitDefID or spGetUnitDefID (unitID )
2844+ nMaxCaptionCharactersForSelection = 0
2845+ singleUnitDisplay .ResetPanelWidths ()
27992846 singleUnitDisplay .SetDisplay (unitID , singleUnitDefID )
28002847 singleUnitDisplay .SetVisible (true )
28012848 multiUnitDisplay .SetUnitDisplay ()
@@ -2932,6 +2979,9 @@ local function InitializeWindParameters()
29322979 econMultEnabled = (Spring .GetGameRulesParam (" econ_mult_enabled" ) and true ) or false
29332980end
29342981
2982+ local nMaxCaptionCharactersForTooltip = 0
2983+ local nMaxCaptionCharactersForSelection = 0
2984+
29352985local updateTimer = 0
29362986function widget :Update (dt )
29372987 updateTimer = updateTimer + dt
0 commit comments