Ticket #3113: total_carried_resources_v1.6.patch

File total_carried_resources_v1.6.patch, 8.2 KB (added by Imarok, 8 years ago)

rename getCostComponentDisplayName to getCostComponentDisplayIcon

  • 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 "";
     
    291291    totalCosts.time = Math.ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1));
    292292
    293293    let costs = [];
    294     if (totalCosts.food) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayName("food"), "cost": totalCosts.food }));
    295     if (totalCosts.wood) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayName("wood"), "cost": totalCosts.wood }));
    296     if (totalCosts.metal) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayName("metal"), "cost": totalCosts.metal }));
    297     if (totalCosts.stone) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayName("stone"), "cost": totalCosts.stone }));
    298     if (totalCosts.population) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayName("population"), "cost": totalCosts.population }));
    299     if (totalCosts.time) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayName("time"), "cost": totalCosts.time }));
     294    if (totalCosts.food) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("food"), "cost": totalCosts.food }));
     295    if (totalCosts.wood) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("wood"), "cost": totalCosts.wood }));
     296    if (totalCosts.metal) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("metal"), "cost": totalCosts.metal }));
     297    if (totalCosts.stone) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("stone"), "cost": totalCosts.stone }));
     298    if (totalCosts.population) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("population"), "cost": totalCosts.population }));
     299    if (totalCosts.time) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("time"), "cost": totalCosts.time }));
    300300    return costs;
    301301}
    302302
     
    351351            // Translation: This string is part of the resources cost string on
    352352            // the tooltip for wall structures.
    353353            out.push(sprintf(translate("%(resourceIcon)s %(minimum)s to %(resourceIcon)s %(maximum)s"), {
    354                 "resourceIcon": getCostComponentDisplayName(resource),
     354                "resourceIcon": getCostComponentDisplayIcon(resource),
    355355                "minimum": resourceMin,
    356356                "maximum": resourceMax
    357357            }));
     
    413413    let formatted = [];
    414414    for (let resource in resources)
    415415        formatted.push(sprintf(translate("%(component)s %(cost)s"), {
    416             "component": '[font="sans-12"]' + getCostComponentDisplayName(resource) + '[/font]',
     416            "component": '[font="sans-12"]' + getCostComponentDisplayIcon(resource) + '[/font]',
    417417            "cost": resources[resource]
    418418        }));
    419419
  • binaries/data/mods/public/gui/session/selection_details.js

     
    341341    let maxCapturePoints = 0;
    342342    let capturePoints = (new Array(9)).fill(0);
    343343    let playerID = 0;
     344    let totalResourcesCarried;
    344345
    345346    for (let i = 0; i < selection.length; i++)
    346347    {
     
    358359            maxCapturePoints += entState.maxCapturePoints;
    359360            capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]);
    360361        }
     362
     363        if (entState.resourceCarrying && entState.resourceCarrying.length !== 0)
     364        {
     365            if (!totalResourcesCarried)
     366                totalResourcesCarried = {};
     367
     368            let carrying = entState.resourceCarrying[0];
     369            if (totalResourcesCarried[carrying.type])
     370                totalResourcesCarried[carrying.type] += carrying.amount;
     371            else
     372                totalResourcesCarried[carrying.type] = carrying.amount;
     373        }
    361374    }
    362375
    363376    Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0;
     
    407420        });
    408421    }
    409422
    410     Engine.GetGUIObjectByName("numberOfUnits").caption = selection.length;
     423    let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits");
     424    numberOfUnits.caption = selection.length;
    411425
     426    let str = "";
     427    if (totalResourcesCarried)
     428        for (let res of RESOURCES)
     429            if (totalResourcesCarried[res])
     430                str += getCostComponentDisplayIcon(res) + totalResourcesCarried[res] + " ";
     431    numberOfUnits.tooltip = str.substr(0, str.length - 1);
     432
    412433    // Unhide Details Area
    413434    Engine.GetGUIObjectByName("detailsAreaMultiple").hidden = false;
    414435    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        }
     
    979979    {
    980980        if (data.carried)
    981981        {
    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;
     982            let str = data.name + "\n";
     983            for (let res of RESOURCES)
     984                if (data.carried[res])
     985                    str += getCostComponentDisplayIcon(res) + data.carried[res] + " ";
     986           
     987            data.button.tooltip = str.substr(0, str.length - 1);
    994988        }
    995989        else
    996990            data.button.tooltip = data.name;
  • 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