Ticket #3670: 3670_req_tooltip.patch

File 3670_req_tooltip.patch, 2.7 KB (added by Matias Lavik, 8 years ago)

Ticket #3670

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

     
    369369    }
    370370
    371371    ret.tooltip = template.tooltip;
     372    ret.requirements = template.requirements;
    372373    ret.requirementsTooltip = template.requirementsTooltip || "";
    373374
    374375    if (template.requirements && template.requirements.class)
  • binaries/data/mods/public/gui/common/tooltips.js

     
    450450    return popBonus;
    451451}
    452452
     453
     454
    453455/**
     456 * Gets a string containing all requirements, connected with commas
     457 *
     458 * @param reqs Requirement(s), as stored in the units' JSON-files
     459 */
     460function GetTechnologyRequirementsTooltip(reqs)
     461{
     462    if (!reqs)
     463        return "";
     464   
     465    let reqArr = [];
     466   
     467    if (reqs.tech)
     468        reqArr.push(getEntityNames(GetTechnologyData(reqs.tech)));
     469    if(reqs.class)
     470        reqArr.push(reqs.class + "(" + reqs.number + "x)");
     471   
     472    if (reqs.all)
     473    {
     474        let allArr = [];
     475        for(let iReq = 0; iReq < reqs.all.length; iReq++)
     476        {
     477            let newReq = GetTechnologyRequirementsTooltip(reqs.all[iReq]);
     478            if(newReq != "")
     479                allArr.push(newReq);
     480        }
     481        if(allArr.length > 0)
     482            reqArr.push(( allArr.length > 1 ? translate("All:") + " " : "" ) + allArr.join(", "));
     483    }
     484    if (reqs.any)
     485    {
     486        let anyArr = [];
     487        for(let iReq = 0; iReq < reqs.any.length; iReq++)
     488        {
     489            let newReq = GetTechnologyRequirementsTooltip(reqs.any[iReq]);
     490            if(newReq != "")
     491                anyArr.push(newReq);
     492        }
     493        if(anyArr.length > 0)
     494            reqArr.push(( anyArr.length > 1 ? translate("All:") + " " : "" ) + anyArr.join(", "));
     495    }
     496   
     497    return reqArr.join(", ");
     498}
     499
     500
     501/**
    454502 * Returns a message with the amount of each resource needed to create an entity.
    455503 */
    456504function getNeededResourcesTooltip(resources)
  • binaries/data/mods/public/gui/session/selection_panels.js

     
    763763            if (!requirementsPassed)
    764764            {
    765765                let tip = template.requirementsTooltip;
     766                if(tip == "")
     767                    tip = headerFont(translate("Requirements:")) + " " + ( GetTechnologyRequirementsTooltip(template.requirements) || translate("(none)") );
     768
    766769                if (template.classRequirements)
    767770                {
    768771                    let player = data.unitEntState.player;