Ticket #3114: health_garrisoned_v1.patch
File health_garrisoned_v1.patch, 4.7 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/session/selection_panels.js
468 468 return false; 469 469 data.name = getEntityNames(data.template); 470 470 data.count = data.item.ents.length; 471 472 data.health = 0; 473 data.maxHealth = 0; 474 let ents = data.item.ents; 475 for (let i = 0; i < ents.length; i++) 476 { 477 let state = GetEntityState(ents[i]); 478 data.health += state.hitpoints; 479 data.maxHealth += state.maxHitpoints; 480 } 471 481 return true; 472 482 }, 473 483 "setAction": function(data) -
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> -
binaries/data/mods/public/gui/session/unit_commands.js
40 40 } 41 41 let selection = g_Selection.toList(); 42 42 43 varitems = g_SelectionPanels[guiName].getItems(unitEntState, selection);43 let items = g_SelectionPanels[guiName].getItems(unitEntState, selection); 44 44 45 45 if (!items || !items.length) 46 46 return; 47 47 48 varnumberOfItems = items.length;49 vargarrisonGroups = new EntityGroups();48 let numberOfItems = items.length; 49 let garrisonGroups = new EntityGroups(); 50 50 51 51 // Determine how many buttons there should be 52 varmaxNumberOfItems = g_SelectionPanels[guiName].getMaxNumberOfItems();52 let maxNumberOfItems = g_SelectionPanels[guiName].getMaxNumberOfItems(); 53 53 if (maxNumberOfItems < numberOfItems) 54 54 numberOfItems = maxNumberOfItems; 55 55 … … 58 58 if (g_SelectionPanels[guiName].resizePanel) 59 59 g_SelectionPanels[guiName].resizePanel(numberOfItems, rowLength); 60 60 61 let totalGarrisionHealth = 0; 62 let maxGarrisionHealth = 0; 63 61 64 // Make buttons 62 65 for (let i = 0; i < numberOfItems; ++i) 63 66 { 64 varitem = items[i];67 let item = items[i]; 65 68 66 69 // If a tech has been researched it leaves an empty slot 67 70 if (!item) … … 73 76 74 77 // STANDARD DATA 75 78 // add standard data 76 vardata = {79 let data = { 77 80 "i": i, 78 81 "item": item, 79 82 "selection": selection, … … 104 107 // add general data, and a chance to abort on faulty data 105 108 if (g_SelectionPanels[guiName].addData) 106 109 { 107 varsuccess = g_SelectionPanels[guiName].addData(data);110 let success = g_SelectionPanels[guiName].addData(data); 108 111 if (!success) 109 112 continue; // ignore faulty data 110 113 } 114 if (guiName == "Garrison") 115 { 116 totalGarrisionHealth += data.health; 117 maxGarrisionHealth += data.maxHealth; 118 } 111 119 112 120 // SET CONTENT 113 121 // run all content setters 114 for ( varf in g_SelectionPanels[guiName])122 for (let f in g_SelectionPanels[guiName]) 115 123 { 116 124 if (f.match(/^set/)) 117 125 g_SelectionPanels[guiName][f](data); … … 137 145 // remember the number of items 138 146 g_unitPanelButtons[guiName] = numberOfItems; 139 147 g_SelectionPanels[guiName].used = true; 148 149 // Show health of garrisoned units 150 if (guiName == "Garrison") 151 { 152 let healthGarrison = Engine.GetGUIObjectByName("healthGarrison"); 153 healthGarrison.hidden = totalGarrisionHealth <= 0; 154 if (totalGarrisionHealth > 0) 155 { 156 let garrisonedUnitsHealthBar = Engine.GetGUIObjectByName("healthBarGarrison"); 157 let healthSize = garrisonedUnitsHealthBar.size; 158 healthSize.rtop = 100-100*Math.max(0, Math.min(1, totalGarrisionHealth / maxGarrisionHealth)); 159 garrisonedUnitsHealthBar.size = healthSize; 160 healthGarrison.tooltip = sprintf(translate("%(label)s %(current)s / %(max)s"), { 161 "label": "[font=\"sans-bold-13\"]" + translate("Hitpoints:") + "[/font]", 162 "current": Math.ceil(totalGarrisionHealth), 163 "max": Math.ceil(maxGarrisionHealth) 164 }); 165 } 166 } 140 167 } 141 168 142 169 /**