Ticket #4193: 4193-loot-tooltip.patch

File 4193-loot-tooltip.patch, 6.2 KB (added by Mate-86, 8 years ago)
  • binaries/data/mods/public/globalscripts/Templates.js

     
    244244            "rate": getEntityValue("Heal/Rate")
    245245        };
    246246
     247    if (template.Loot)
     248    {
     249        ret.loot = {};
     250        if (template.Loot.xp)
     251            ret.loot.xp = getEntityValue("Loot/xp");
     252        if (template.Loot.food)
     253            ret.loot.food = getEntityValue("Loot/food");
     254
     255        if (template.Loot.wood)
     256            ret.loot.wood = getEntityValue("Loot/wood");
     257
     258        if (template.Loot.stone)
     259            ret.loot.stone = getEntityValue("Loot/stone");
     260
     261        if (template.Loot.metal)
     262            ret.loot.metal = getEntityValue("Loot/metal");
     263    }
     264
    247265    if (template.Obstruction)
    248266    {
    249267        ret.obstruction = {
  • binaries/data/mods/public/gui/common/setup_resources.xml

     
    2525        sprite="stretched:session/icons/resources/time_small.png"
    2626        size="16 16"
    2727    />
     28    <icon name="icon_xp"
     29        sprite="stretched:session/icons/resources/xp_small.png"
     30        size="16 16"
     31    />
    2832</setup>
  • binaries/data/mods/public/gui/common/tooltips.js

     
    575575    return headerFont(translate("Classes:")) + ' ' +
    576576        bodyFont(template.visibleIdentityClasses.map(c => translate(c)).join(translate(", ")));
    577577}
     578
     579function getLootTooltip(template, trainNum, entity)
     580{
     581    if (template.loot)
     582    {
     583        let loots = [];
     584        for (let type in template.loot)
     585            loots.push(sprintf(translate("%(component)s %(loot)s"), {
     586                "component": costIcon(type),
     587                "loot": template.loot[type]
     588        }));
     589       
     590        return headerFont("Loot: ") + loots;
     591    }
     592    return "";
     593}
  • binaries/data/mods/public/gui/session/selection_details.js

     
     1const lootTypes = ["xp", "food", "wood", "stone", "metal"];
     2
    13function layoutSelectionSingle()
    24{
    35    Engine.GetGUIObjectByName("detailsAreaSingle").hidden = false;
     
    291293        getBuildRateTooltip,
    292294        getSpeedTooltip,
    293295        getGarrisonTooltip,
    294         getProjectilesTooltip
     296        getProjectilesTooltip,
     297        getLootTooltip
    295298    ].map(func => func(entState)).filter(tip => tip).join("\n");
    296299
    297300    let iconTooltips = [];
     
    320323    let capturePoints = (new Array(g_MaxPlayers + 1)).fill(0);
    321324    let playerID = 0;
    322325    let totalResourcesCarried = {};
     326    let totalTrade = {};
     327    let totalLoot = {};
    323328
    324329    for (let i = 0; i < selection.length; ++i)
    325330    {
    326331        let entState = GetEntityState(selection[i]);
     332        let extEntState = GetExtendedEntityState(selection[i]);
    327333        if (!entState)
    328334            continue;
    329335        playerID = entState.player; // trust that all selected entities have the same owner
     
    338344            capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]);
    339345        }
    340346
     347        if (extEntState.loot)
     348        {
     349            for (let i in lootTypes)
     350            {
     351                let type = lootTypes[i];
     352                totalLoot[type] = (totalLoot[type] || 0) + extEntState.loot[type];
     353            }
     354        }
     355
    341356        if (entState.resourceCarrying && entState.resourceCarrying.length)
    342357        {
    343358            let carrying = entState.resourceCarrying[0];
    344359            totalResourcesCarried[carrying.type] = (totalResourcesCarried[carrying.type] || 0) + carrying.amount;
    345360        }
     361
     362        if (entState.trader && entState.trader.goods)
     363        {
     364            let totalGain = entState.trader.goods.amount.traderGain;
     365            if (entState.trader.goods.amount.market1Gain)
     366                totalGain += entState.trader.goods.amount.market1Gain;
     367            if (entState.trader.goods.amount.market2Gain)
     368                totalGain += entState.trader.goods.amount.market2Gain;
     369
     370            totalTrade[entState.trader.goods.type] = totalGain;
     371        }
    346372    }
    347373
     374    for (let i in lootTypes)
     375    {
     376        let type = lootTypes[i];
     377        totalLoot[type] += totalResourcesCarried[type] || 0;
     378        totalLoot[type] += totalTrade[type] || 0;
     379        if (totalLoot[type] == 0)
     380            delete totalLoot[type];
     381    }
     382
    348383    Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0;
    349384    if (averageHealth > 0)
    350385    {
     
    394429
    395430    let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits");
    396431    numberOfUnits.caption = selection.length;
    397     numberOfUnits.tooltip = Object.keys(totalResourcesCarried).map(res =>
    398         costIcon(res) + totalResourcesCarried[res]
     432    numberOfUnits.tooltip = (Object.keys(totalLoot)).map(res =>
     433        costIcon(res) + totalLoot[res]
    399434    ).join(" ");
    400435
    401436    // Unhide Details Area
  • binaries/data/mods/public/gui/structree/draw.js

     
    1414    getProjectilesTooltip,
    1515    getSpeedTooltip,
    1616    getGatherTooltip,
    17     getPopulationBonusTooltip
     17    getPopulationBonusTooltip,
     18    getLootTooltip
    1819];
    1920
    2021/**
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    421421        "barterMarket": null,
    422422        "buildingAI": null,
    423423        "heal": null,
     424        "loot": null,
    424425        "obstruction": null,
    425426        "turretParent":null,
    426427        "promotion": null,
     
    568569            "healableClasses": cmpHeal.GetHealableClasses(),
    569570        };
    570571
     572    let cmpLoot = Engine.QueryInterface(ent, IID_Loot);
     573    if (cmpLoot)
     574    {
     575        let resources = cmpLoot.GetResources();
     576        ret.loot = {
     577            "xp": cmpLoot.GetXp(),
     578            "food": resources.food,
     579            "wood": resources.wood,
     580            "stone": resources.stone,
     581            "metal": resources.metal
     582        };
     583    }
     584
    571585    let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
    572586    if (cmpUnitMotion)
    573587        ret.speed = {