Ticket #4217: specificNames.patch

File specificNames.patch, 10.4 KB (added by s0600204, 8 years ago)

Proposed patch

  • binaries/data/mods/public/globalscripts/Templates.js

    diff --git a/binaries/data/mods/public/globalscripts/Templates.js b/binaries/data/mods/public/globalscripts/Templates.js
    index 9b622db..219f221 100644
    a b function GetTemplateDataHelper(template, player, auraTemplates)  
    336336
    337337/**
    338338 * Get information about a technology template.
     339 *
    339340 * @param template A valid template as obtained by loading the tech JSON file.
    340  * @param civ Civilization for which the specific name should be returned.
    341341 */
    342 function GetTechnologyDataHelper(template, civ)
     342function GetTechnologyDataHelper(template)
    343343{
    344344    var ret = {};
    345345
    346     // Get specific name for this civ or else the generic specific name
    347     var specific;
    348     if (template.specificName)
    349     {
    350         if (template.specificName[civ])
    351             specific = template.specificName[civ];
    352         else
    353             specific = template.specificName['generic'];
    354     }
    355 
    356346    ret.name = {
    357         "specific": specific,
     347        "specific": template.specificName || undefined,
    358348        "generic": template.genericName,
    359349    };
    360350
  • binaries/data/mods/public/gui/common/tooltips.js

    diff --git a/binaries/data/mods/public/gui/common/tooltips.js b/binaries/data/mods/public/gui/common/tooltips.js
    index 6cebc6d..c29d0f8 100644
    a b function getWallPieceTooltip(wallTypes)  
    412412/**
    413413 * Returns the cost information to display in the specified entity's construction button tooltip.
    414414 */
    415 function getEntityCostTooltip(template, trainNum, entity)
     415function getEntityCostTooltip(template, civ, trainNum, entity)
    416416{
    417417    // Entities with a wallset component are proxies for initiating wall placement and as such do not have a cost of
    418418    // their own; the individual wall pieces within it do.
    function getAurasTooltip(template)  
    538538    return tooltips.join("\n");
    539539}
    540540
    541 function getEntityNames(template)
     541function getCivSpecificEntityName(template, civ)
    542542{
    543543    if (!template.name.specific)
    544         return template.name.generic;
     544        return false;
     545
     546    if (typeof template.name.specific == "string")
     547        if (template.name.specific != template.name.generic)
     548            return template.name.specific;
     549        else
     550            return false;
     551
     552    if (template.name.specific[civ])
     553        return template.name.specific[civ];
    545554
    546     if (template.name.specific == template.name.generic)
    547         return template.name.specific;
     555    if (template.name.specific.generic)
     556        return template.name.specific.generic;
     557
     558    return false;
     559}
     560
     561function getEntityNames(template, civ)
     562{
     563    let specific = getCivSpecificEntityName(template, civ);
     564    if (!specific)
     565        return template.name.generic;
    548566
    549567    return sprintf(translate("%(specificName)s (%(genericName)s)"), {
    550         "specificName": template.name.specific,
     568        "specificName": specific,
    551569        "genericName": template.name.generic
    552570    });
    553571
    554572}
    555 function getEntityNamesFormatted(template)
     573function getEntityNamesFormatted(template, civ)
    556574{
    557     if (!template.name.specific)
     575    let specific = getCivSpecificEntityName(template, civ);
     576    if (!specific)
    558577        return '[font="sans-bold-16"]' + template.name.generic + "[/font]";
    559578
    560579    return sprintf(translate("%(specificName)s %(fontStart)s(%(genericName)s)%(fontEnd)s"), {
    561580        "specificName":
    562             '[font="sans-bold-16"]' + template.name.specific[0] + '[/font]' +
    563             '[font="sans-bold-12"]' + template.name.specific.slice(1).toUpperCase() + '[/font]',
     581            '[font="sans-bold-16"]' + specific[0] + '[/font]' +
     582            '[font="sans-bold-12"]' + specific.slice(1).toUpperCase() + '[/font]',
    564583        "genericName": template.name.generic,
    565584        "fontStart": '[font="sans-bold-16"]',
    566585        "fontEnd": '[/font]'
  • binaries/data/mods/public/gui/session/selection_panels.js

    diff --git a/binaries/data/mods/public/gui/session/selection_panels.js b/binaries/data/mods/public/gui/session/selection_panels.js
    index fb12b00..1d03334 100644
    a b g_SelectionPanels.Construction = {  
    316316            getGarrisonTooltip,
    317317            getProjectilesTooltip,
    318318            getPopulationBonusTooltip
    319         ].map(func => func(template));
     319        ].map(func => func(template, data.playerState.civ));
    320320
    321321        let limits = getEntityLimitAndCount(data.playerState, data.item);
    322322        tooltips.push(formatLimitString(limits.entLimit, limits.entCount, limits.entLimitChangers));
    323323
    324324        if (!technologyEnabled)
    325325            tooltips.push(sprintf(translate("Requires %(technology)s"), {
    326                 "technology": getEntityNames(GetTechnologyData(template.requiredTechnology))
     326                "technology": getEntityNames(GetTechnologyData(template.requiredTechnology), data.playerState.civ)
    327327            }));
    328328
    329329        tooltips.push(getNeededResourcesTooltip(neededResources));
    g_SelectionPanels.Garrison = {  
    441441
    442442        let tooltip = canUngarrison || g_IsObserver ?
    443443            sprintf(translate("Unload %(name)s"),
    444             { "name": getEntityNames(template) }) + "\n" +
     444            { "name": getEntityNames(template, data.playerState.civ) }) + "\n" +
    445445            translate("Single-click to unload 1. Shift-click to unload all of this type.") :
    446             getEntityNames(template);
     446            getEntityNames(template, data.playerState.civ);
    447447
    448448        tooltip += "\n" + sprintf(translate("Player: %(playername)s"), {
    449449            "playername": g_Players[garrisonedUnitOwner].name
    g_SelectionPanels.Queue = {  
    645645
    646646        data.button.onPress = function() { removeFromProductionQueue(data.item.producingEnt, data.item.id); };
    647647
    648         let tooltip = getEntityNames(template);
     648        let tooltip = getEntityNames(template, data.playerState.civ);
    649649        if (data.item.neededSlots)
    650650        {
    651651            tooltip += "\n[color=\"red\"]" + translate("Insufficient population capacity:") + "\n[/color]";
    g_SelectionPanels.Research = {  
    758758                getEntityNamesFormatted,
    759759                getEntityTooltip,
    760760                getEntityCostTooltip
    761             ].map(func => func(template));
     761            ].map(func => func(template, data.playerState.civ));
    762762
    763763            if (!requirementsPassed)
    764764            {
    g_SelectionPanels.Selection = {  
    874874            }
    875875        }
    876876
    877         let tooltip = getEntityNames(template);
     877        let tooltip = getEntityNames(template, data.playerState.civ);
    878878        if (data.carried)
    879879            tooltip += "\n" + Object.keys(data.carried).map(res =>
    880880                costIcon(res) + data.carried[res]
    g_SelectionPanels.Training = {  
    965965        let tooltips = [
    966966            "[font=\"sans-bold-16\"]" +
    967967                colorizeHotkey("%(hotkey)s", "session.queueunit." + (data.i + 1)) +
    968                 "[/font]" + " " + getEntityNamesFormatted(template),
     968                "[/font]" + " " + getEntityNamesFormatted(template, data.playerState.civ),
    969969            getVisibleEntityClassesFormatted(template),
    970970            getAurasTooltip(template),
    971971            getEntityTooltip(template),
    972             getEntityCostTooltip(template, trainNum, data.unitEntState.id)
     972            getEntityCostTooltip(template, null, trainNum, data.unitEntState.id)
    973973        ];
    974974
    975975        let limits = getEntityLimitAndCount(data.playerState, data.item);
    g_SelectionPanels.Training = {  
    994994
    995995        if (!technologyEnabled)
    996996            tooltips.push(sprintf(translate("Requires %(technology)s"), {
    997                 "technology": getEntityNames(GetTechnologyData(template.requiredTechnology))
     997                "technology": getEntityNames(GetTechnologyData(template.requiredTechnology), data.playerState.civ)
    998998            }));
    999999
    10001000        if (neededResources)
    g_SelectionPanels.Upgrade = {  
    10841084            tooltip += formatLimitString(limits.entLimit, limits.entCount, limits.entLimitChangers);
    10851085            if (!technologyEnabled)
    10861086                tooltip += "\n" + sprintf(translate("Requires %(technology)s"), {
    1087                     "technology": getEntityNames(GetTechnologyData(data.item.requiredTechnology))
     1087                    "technology": getEntityNames(GetTechnologyData(data.item.requiredTechnology), data.playerState.civ)
    10881088                });
    10891089
    10901090            tooltip += getNeededResourcesTooltip(neededResources);
  • binaries/data/mods/public/gui/session/session.js

    diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js
    index d82312e..1e7b74e 100644
    a b function updateResearchDisplay()  
    10001000        let template = GetTechnologyData(tech);
    10011001        let button = Engine.GetGUIObjectByName("researchStartedButton[" + numButtons + "]");
    10021002        button.hidden = false;
    1003         button.tooltip = getEntityNames(template);
     1003        button.tooltip = getEntityNames(template, g_Players[g_ViewedPlayer].civ);
    10041004        button.onpress = (function(e) { return function() { selectAndMoveTo(e); }; })(researchStarted[tech].researcher);
    10051005
    10061006        let icon = "stretched:session/portraits/" + template.icon;
  • binaries/data/mods/public/gui/structree/draw.js

    diff --git a/binaries/data/mods/public/gui/structree/draw.js b/binaries/data/mods/public/gui/structree/draw.js
    index 06f1e39..f3544b6 100644
    a b function predraw()  
    384384 */
    385385function assembleTooltip(template)
    386386{
    387     return g_TooltipFunctions.map(func => func(template)).filter(tip => tip).join("\n");
     387    return g_TooltipFunctions.map(func => func(template, g_SelectedCiv)).filter(tip => tip).join("\n");
    388388}
  • binaries/data/mods/public/gui/structree/structree.js

    diff --git a/binaries/data/mods/public/gui/structree/structree.js b/binaries/data/mods/public/gui/structree/structree.js
    index 65bfd9e..5462c2a 100644
    a b function selectCiv(civCode)  
    9797        let realcode = depath(techcode);
    9898
    9999        if (realcode.slice(0,4) == "pair" || realcode.indexOf("_pair") > -1)
    100             techPairs[techcode] = loadTechnologyPair(techcode);
     100        {
     101            if (!techPairs[techcode])
     102                techPairs[techcode] = loadTechnologyPair(techcode);
     103        }
    101104        else if (realcode.slice(0,5) == "phase")
    102             g_ParsedData.phases[techcode] = loadPhase(techcode);
     105        {
     106            if (!g_ParsedData.phases[techcode])
     107                g_ParsedData.phases[techcode] = loadPhase(techcode);
     108        }
    103109        else
    104             g_ParsedData.techs[techcode] = loadTechnology(techcode);
     110            if (!g_ParsedData.techs[techcode])
     111                g_ParsedData.techs[techcode] = loadTechnology(techcode);
    105112    }
    106113
    107114    // Expand tech pairs
  • binaries/data/mods/public/simulation/components/GuiInterface.js

    diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js
    index 533c891..1d67aa4 100644
    a b GuiInterface.prototype.GetTechnologyData = function(player, name)  
    645645    }
    646646
    647647    let cmpPlayer = QueryPlayerIDInterface(player, IID_Player);
    648     return GetTechnologyDataHelper(template, cmpPlayer.GetCiv());
     648    return GetTechnologyDataHelper(template);
    649649};
    650650
    651651GuiInterface.prototype.IsTechnologyResearched = function(player, data)