Ticket #3113: total_carried_resources_v1.7.1.patch

File total_carried_resources_v1.7.1.patch, 6.3 KB (added by Imarok, 8 years ago)

followed the suggestions of comment:17

  • binaries/data/mods/public/gui/common/tooltips.js

     
    1 const g_CostDisplayNames = {
     1const g_CostDisplayIcons = {
    22    "food": '[icon="iconFood"]',
    33    "wood": '[icon="iconWood"]',
    44    "stone": '[icon="iconStone"]',
     
    258258 * Translates a cost component identifier as they are used internally
    259259 * (e.g. "population", "food", etc.) to proper display names.
    260260 */
    261 function getCostComponentDisplayName(costComponentName)
     261function getCostComponentDisplayIcon(costComponentName)
    262262{
    263     if (costComponentName in g_CostDisplayNames)
    264         return g_CostDisplayNames[costComponentName];
     263    if (costComponentName in g_CostDisplayIcons)
     264        return g_CostDisplayIcons[costComponentName];
    265265
    266266    warn(sprintf("The specified cost component, ‘%(component)s’, is not currently supported.", { "component": costComponentName }));
    267267    return "";
     
    292292
    293293    let costs = [];
    294294
    295     for (let type in g_CostDisplayNames)
     295    for (let type in g_CostDisplayIcons)
    296296        if (totalCosts[type])
    297297            costs.push(sprintf(translate("%(component)s %(cost)s"), {
    298                 "component": getCostComponentDisplayName(type),
     298                "component": getCostComponentDisplayIcon(type),
    299299                "cost": totalCosts[type]
    300300            }));
    301301
     
    353353            // Translation: This string is part of the resources cost string on
    354354            // the tooltip for wall structures.
    355355            out.push(sprintf(translate("%(resourceIcon)s %(minimum)s to %(resourceIcon)s %(maximum)s"), {
    356                 "resourceIcon": getCostComponentDisplayName(resource),
     356                "resourceIcon": getCostComponentDisplayIcon(resource),
    357357                "minimum": resourceMin,
    358358                "maximum": resourceMax
    359359            }));
     
    415415    let formatted = [];
    416416    for (let resource in resources)
    417417        formatted.push(sprintf(translate("%(component)s %(cost)s"), {
    418             "component": '[font="sans-12"]' + getCostComponentDisplayName(resource) + '[/font]',
     418            "component": '[font="sans-12"]' + getCostComponentDisplayIcon(resource) + '[/font]',
    419419            "cost": resources[resource]
    420420        }));
    421421
  • binaries/data/mods/public/gui/session/selection_details.js

     
    338338    let maxCapturePoints = 0;
    339339    let capturePoints = (new Array(g_MaxPlayers + 1)).fill(0);
    340340    let playerID = 0;
     341    let totalResourcesCarried = {};
    341342
    342343    for (let i = 0; i < selection.length; ++i)
    343344    {
     
    355356            maxCapturePoints += entState.maxCapturePoints;
    356357            capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]);
    357358        }
     359
     360        if (entState.resourceCarrying && entState.resourceCarrying.length != 0)
     361        {
     362            let carrying = entState.resourceCarrying[0];
     363            totalResourcesCarried[carrying.type] = (totalResourcesCarried[carrying.type] || 0) + carrying.amount;
     364        }
    358365    }
    359366
    360367    Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0;
     
    404411        });
    405412    }
    406413
    407     Engine.GetGUIObjectByName("numberOfUnits").caption = selection.length;
     414    let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits");
     415    numberOfUnits.caption = selection.length;
    408416
     417    numberOfUnits.tooltip = Object.keys(totalResourcesCarried).map
     418                                (
     419                                    res => getCostComponentDisplayIcon(res) + totalResourcesCarried[res]
     420                                ).join(" ");
     421
    409422    // Unhide Details Area
    410423    Engine.GetGUIObjectByName("detailsAreaMultiple").hidden = false;
    411424    Engine.GetGUIObjectByName("detailsAreaSingle").hidden = true;
  • binaries/data/mods/public/gui/session/selection_panels.js

     
    737737        {
    738738            tooltip += "\n[color=\"red\"]" + translate("Insufficient population capacity:") + "\n[/color]";
    739739            tooltip += sprintf(translate("%(population)s %(neededSlots)s"), {
    740                 "population": getCostComponentDisplayName("population"),
     740                "population": getCostComponentDisplayIcon("population"),
    741741                "neededSlots": data.item.neededSlots
    742742            });
    743743        }
     
    977977    },
    978978    "setTooltip": function(data)
    979979    {
     980        let str = data.name;
    980981        if (data.carried)
    981         {
    982             var str = data.name + "\n";
    983             var ress = ["food", "wood", "stone", "metal"];
    984             for (var i = 0; i < 4; ++i)
    985             {
    986                 if (data.carried[ress[i]])
    987                 {
    988                     str += getCostComponentDisplayName(ress[i]) + data.carried[ress[i]];
    989                     if (i !== 3)
    990                         str += " ";
    991                 }
    992             }
    993             data.button.tooltip = str;
    994         }
    995         else
    996             data.button.tooltip = data.name;
     982            str += "\n" + Object.keys(data.carried).map
     983                                (
     984                                    res => getCostComponentDisplayIcon(res) + data.carried[res]
     985                                ).join(" ");
     986        data.button.tooltip = str;
    997987    },
    998988    "setCountDisplay": function(data)
    999989    {
  • binaries/data/mods/public/gui/session/selection_panels_middle/multiple_details_area.xml

     
    1919
    2020    <!-- Total -->
    2121    <object size="100%-42 12 100%-8 46" type="image" sprite="groupsIcon">
    22     <object size="0 0 100% 100%" type="text" style="largeCenteredOutlinedText" name="numberOfUnits"/>
     22    <object size="0 0 100% 100%" type="text" style="largeCenteredOutlinedText" name="numberOfUnits" tooltip_style="sessionToolTipBold"/>
    2323    </object>
    2424
    2525    <!-- Stats Bars -->
  • binaries/data/mods/public/gui/structree/draw.js

     
    366366        let rates = [];
    367367        for (let type in template.gather)
    368368            rates.push(sprintf(translate("%(resourceIcon)s %(rate)s"), {
    369                 "resourceIcon": getCostComponentDisplayName(type),
     369                "resourceIcon": getCostComponentDisplayIcon(type),
    370370                "rate": template.gather[type]
    371371            }));
    372372