Ticket #3395: ticket3394unitactions_3.2.diff

File ticket3394unitactions_3.2.diff, 8.8 KB (added by bb, 9 years ago)

Some more improvements (thanks elexis) and added a tooltip for "focus on rally point".

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

     
    157157    else
    158158        var rateLabel = txtFormats.header[0] + translate("Rate:") + txtFormats.header[1];
    159159
    160     for (var type in template.attack)
     160    for (let type in template.attack)
    161161    {
    162162        if (type == "Slaughter")
    163163            continue; // Slaughter is not a real attack, so do not show it.
     
    219219    return attacks.join("\n");
    220220}
    221221
     222function getRepairTimeRatioTooltip(ratio)
     223{
     224    var unit = sprintf(translate("%(health)s / %(second)s / %(worker)s"), {
     225                health: txtFormats.unit[0] + translate("Health") + txtFormats.unit[1],
     226                second: txtFormats.unit[0] + translate("second") + txtFormats.unit[1],
     227                worker: txtFormats.unit[0] + translate("worker") + txtFormats.unit[1]
     228            });
     229
     230    return "\n" + sprintf(translate("%(repairRateLabel)s %(detail)s %(unit)s"), {
     231                repairRateLabel: txtFormats.header[0] + translate("Repair Rate:") + txtFormats.header[1],
     232                detail: ratio,
     233                unit: unit
     234            });
     235}
     236
    222237/**
    223238 * Translates a cost component identifier as they are used internally
    224239 * (e.g. "population", "food", etc.) to proper display names.
  • binaries/data/mods/public/gui/session/selection_details.js

     
    254254    var armorString = getArmorTooltip(entState.armour);
    255255
    256256    // Attack and Armor
    257     if ("attack" in entState && entState.attack)
     257    if (entState.attack)
    258258        Engine.GetGUIObjectByName("attackAndArmorStats").tooltip = getAttackTooltip(entState) + "\n" + armorString;
    259259    else
    260260        Engine.GetGUIObjectByName("attackAndArmorStats").tooltip = armorString;
    261261
     262    // Repair Rate
     263    if (entState.repairTimeRatio)
     264        Engine.GetGUIObjectByName("attackAndArmorStats").tooltip += getRepairTimeRatioTooltip(entState.repairTimeRatio);
     265
    262266    // Icon Tooltip
    263267    var iconTooltip = "";
    264268
  • binaries/data/mods/public/gui/session/unit_actions.js

     
    677677                    count += state.garrisonHolder.entities.length;
    678678            }
    679679            return {
    680                 "tooltip": translate("Unload All"),
     680                "tooltip": '[font="sans-bold-16"]' + translate("Unload All") + "[/font]\n" + translate("Release all garrisoned units"),
    681681                "icon": "garrison-out.png",
    682682                "count": count,
    683683            };
     
    705705                   
    706706
    707707            return {
    708                 "tooltip": translate("Delete"),
     708                "tooltip": '[font="sans-bold-16"]' + translate("Delete") + "[/font]\n" + translate("Destroy everything selected"),
    709709                "icon": "kill_small.png"
    710710            };
    711711        },
     
    731731            if (!entState.unitAI)
    732732                return false;
    733733            return {
    734                 "tooltip": translate("Stop"),
     734                "tooltip": '[font="sans-bold-16"]' + translate("Stop") + "[/font]\n" + translate("Cancel all existing orders"),
    735735                "icon": "stop.png"
    736736            };
    737737        },
     
    749749            if (!entState.unitAI || entState.turretParent)
    750750                return false;
    751751            return {
    752                 "tooltip": translate("Garrison"),
     752                "tooltip": '[font="sans-bold-16"]' + translate("Garrison") + "[/font]\n" + translate("Lock selected units inside and shoot arrows from warships and defensive buildings"),
    753753                "icon": "garrison.png"
    754754            };
    755755        },
     
    770770            if (!p.garrisonHolder || p.garrisonHolder.entities.indexOf(entState.id) == -1)
    771771                return false;
    772772            return {
    773                 "tooltip": translate("Unload"),
     773                "tooltip": '[font="sans-bold-16"]' + translate("Unload") + "[/font]\n" + translate("Release one unit"),
    774774                "icon": "garrison-out.png"
    775775            };
    776776        },
     
    786786            if (!entState.builder)
    787787                return false;
    788788            return {
    789                 "tooltip": translate("Repair"),
     789                "tooltip": '[font="sans-bold-16"]' + translate("Repair") + "[/font]\n" + translate("Restore health, rate depends on structure"),
    790790                "icon": "repair.png"
    791791            };
    792792        },
     
    803803            if (!entState.rallyPoint)
    804804                return false;
    805805            return {
    806                 "tooltip": translate("Focus on Rally Point"),
     806                "tooltip": '[font="sans-bold-16"]' + translate("Focus on Rally Point") + "[/font]\n" + translate("Move camera to entity"),
    807807                "icon": "focus-rally.png"
    808808            };
    809809        },
     
    826826            if (!entState.unitAI || !entState.unitAI.hasWorkOrders)
    827827                return false;
    828828            return {
    829                 "tooltip": translate("Back to Work"),
     829                "tooltip": '[font="sans-bold-16"]' + translate("Back to Work") + "[/font]\n" + translate("Order unit the last given task"),
    830830                "icon": "production.png"
    831831            };
    832832        },
     
    842842            if (!entState.unitAI || !entState.unitAI.canGuard || entState.unitAI.isGuarding)
    843843                return false;
    844844            return {
    845                 "tooltip": translate("Guard"),
     845                "tooltip": '[font="sans-bold-16"]' + translate("Guard") + "[/font]\n" + translate("Follow another entity, repair/heal it and protect when attacked"),
    846846                "icon": "add-guard.png"
    847847            };
    848848        },
     
    859859            if (!entState.unitAI || !entState.unitAI.isGuarding)
    860860                return false;
    861861            return {
    862                 "tooltip": translate("Remove guard"),
     862                "tooltip": '[font="sans-bold-16"]' + translate("Remove guard") +"[/font]\n" + translate("Stop guarding"),
    863863                "icon": "remove-guard.png"
    864864            };
    865865        },
     
    910910                }
    911911            }
    912912            return {
    913                 "tooltip": translate("Unload All"),
     913                "tooltip": '[font="sans-bold-16"]' + translate("Unload All") + "[/font]\n" + translate("Release all garrisoned units"),
    914914                "icon": "garrison-out.png",
    915915                "count": count,
    916916            };
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    343343   
    344344    var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
    345345    if (cmpOwnership)
    346     {
    347346        ret.player = cmpOwnership.GetOwner();
    348     }
    349347
    350348    var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint);
    351349    if (cmpRallyPoint)
    352     {
    353350        ret.rallyPoint = {'position': cmpRallyPoint.GetPositions()[0]}; // undefined or {x,z} object
    354     }
    355351
    356352    var cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder);
    357353    if (cmpGarrisonHolder)
     
    433429        "obstruction": null,
    434430        "turretParent":null,
    435431        "promotion": null,
     432        "repairTimeRatio": null,
    436433        "resourceDropsite": null,
    437434        "resourceGatherRates": null,
    438435        "resourceSupply": null,
     
    489486
    490487    var cmpArmour = Engine.QueryInterface(ent, IID_DamageReceiver);
    491488    if (cmpArmour)
    492     {
    493489        ret.armour = cmpArmour.GetArmourStrengths();
    494     }
    495490
    496491    var cmpAuras = Engine.QueryInterface(ent, IID_Auras)
    497492    if (cmpAuras)
    498     {
    499493        ret.auras = cmpAuras.GetDescriptions();
    500     }
    501494
    502495    var cmpBuildingAI = Engine.QueryInterface(ent, IID_BuildingAI);
    503496    if (cmpBuildingAI)
     
    523516    if (cmpPosition && cmpPosition.GetTurretParent() != INVALID_ENTITY)
    524517        ret.turretParent = cmpPosition.GetTurretParent();
    525518
     519    var cmpRepairTimeRatio = Engine.QueryInterface(ent, IID_Repairable);
     520        if (cmpRepairTimeRatio)
     521            ret.repairTimeRatio = cmpRepairTimeRatio.GetRepairTimeRatio();
     522
    526523    var cmpResourceSupply = QueryMiragedInterface(ent, IID_ResourceSupply);
    527524    if (cmpResourceSupply)
    528525    {
     
    539536
    540537    var cmpResourceGatherer = Engine.QueryInterface(ent, IID_ResourceGatherer);
    541538    if (cmpResourceGatherer)
    542     {
    543539        ret.resourceGatherRates = cmpResourceGatherer.GetGatherRates();
    544     }
    545540   
    546541    var cmpResourceDropsite = Engine.QueryInterface(ent, IID_ResourceDropsite);
    547542    if (cmpResourceDropsite)
  • binaries/data/mods/public/simulation/components/Repairable.js

     
    7474        Engine.PostMessage(this.entity, MT_ConstructionFinished, { "entity": this.entity, "newentity": this.entity });
    7575};
    7676
     77Repairable.prototype.GetRepairTimeRatio = function()
     78{
     79    return this.repairTimeRatio;
     80};
     81
    7782Engine.RegisterComponentType(IID_Repairable, "Repairable", Repairable);
  • binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js

     
    508508    obstruction: null,
    509509    turretParent: null,
    510510    promotion: null,
     511    repairTimeRatio: null,
    511512    resourceDropsite: null,
    512513    resourceGatherRates: null,
    513514    resourceSupply: null,