Ticket #3114: health_garrisoned_v2.patch

File health_garrisoned_v2.patch, 3.4 KB (added by Imarok, 8 years ago)

Move the code of the health bar to selection_details

  • binaries/data/mods/public/gui/session/selection_details.js

     
    1919        return getLocalizedResourceName(resourceCode, "firstWord");
    2020}
    2121
     22// Updates the health bar of garrisoned units
     23function 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
    2260// Fills out information that most entities have
    2361function displaySingle(entState)
    2462{
     
    376414    Engine.GetGUIObjectByName("detailsAreaSingle").hidden = true;
    377415}
    378416
    379 // Updates middle entity Selection Details Panel
     417// Updates middle entity Selection Details Panel and left Unit Commands Panel
    380418function updateSelectionDetails()
    381419{
    382420    let supplementalDetailsPanel = Engine.GetGUIObjectByName("supplementalSelectionDetails");
     
    415453
    416454    // Fill out commands panel for specific unit selected (or first unit of primary group)
    417455    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);
    418460}
  • binaries/data/mods/public/gui/session/selection_panels_left/garrison_panel.xml

     
    88            </object>
    99        </repeat>
    1010    </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>
    1119</object>