Ticket #3114: health_garrisoned_v2.patch
File health_garrisoned_v2.patch, 3.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/session/selection_details.js
19 19 return getLocalizedResourceName(resourceCode, "firstWord"); 20 20 } 21 21 22 // Updates the health bar of garrisoned units 23 function updateGarrisionHealthBar(entState, selection) 24 { 25 if (!entState.garrisonHolder) 26 return; 27 28 // Summing up the Health of every single unit 29 let totalGarrisionHealth = 0; 30 let maxGarrisionHealth = 0; 31 for (let selEnt of selection) 32 { 33 let selEntState = GetEntityState(selEnt); 34 if (selEntState.garrisonHolder) 35 for (let ent of selEntState.garrisonHolder.entities) 36 { 37 let state = GetEntityState(ent); 38 totalGarrisionHealth += state.hitpoints || 0; 39 maxGarrisionHealth += state.maxHitpoints || 0; 40 } 41 } 42 43 // Configuring the health bar 44 let healthGarrison = Engine.GetGUIObjectByName("healthGarrison"); 45 healthGarrison.hidden = totalGarrisionHealth <= 0; 46 if (totalGarrisionHealth > 0) 47 { 48 let healthBarGarrison = Engine.GetGUIObjectByName("healthBarGarrison"); 49 let healthSize = healthBarGarrison.size; 50 healthSize.rtop = 100-100*Math.max(0, Math.min(1, totalGarrisionHealth / maxGarrisionHealth)); 51 healthBarGarrison.size = healthSize; 52 healthGarrison.tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), { 53 "label": "[font=\"sans-bold-13\"]" + translate("Hitpoints:") + "[/font]", 54 "current": Math.ceil(totalGarrisionHealth), 55 "max": Math.ceil(maxGarrisionHealth) 56 }); 57 } 58 } 59 22 60 // Fills out information that most entities have 23 61 function displaySingle(entState) 24 62 { … … 376 414 Engine.GetGUIObjectByName("detailsAreaSingle").hidden = true; 377 415 } 378 416 379 // Updates middle entity Selection Details Panel 417 // Updates middle entity Selection Details Panel and left Unit Commands Panel 380 418 function updateSelectionDetails() 381 419 { 382 420 let supplementalDetailsPanel = Engine.GetGUIObjectByName("supplementalSelectionDetails"); … … 415 453 416 454 // Fill out commands panel for specific unit selected (or first unit of primary group) 417 455 updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, selection); 456 457 // Show health bar for garrisoned units if the garrison panel is visible 458 if (Engine.GetGUIObjectByName("unitGarrisonPanel") && !Engine.GetGUIObjectByName("unitGarrisonPanel").hidden) 459 updateGarrisionHealthBar(entState, selection); 418 460 } -
binaries/data/mods/public/gui/session/selection_panels_left/garrison_panel.xml
8 8 </object> 9 9 </repeat> 10 10 </object> 11 <!-- Health bar of garrisoned units --> 12 <object size="-14 1 -7 100%-49" type="image" name="healthGarrison" tooltip_style="sessionToolTip"> 13 <translatableAttribute id="tooltip">Hitpoints</translatableAttribute> 14 <object type="image" sprite="barBorder" ghost="true" size="-1 -1 100%+1 100%+1"/> 15 <object type="image" sprite="healthBackground" ghost="true"/> 16 <object type="image" sprite="healthForeground" ghost="true" name="healthBarGarrison"/> 17 <object type="image" sprite="statsBarShaderVertical" ghost="true"/> 18 </object> 11 19 </object>