Ticket #3213: unitTrainingUnits.patch

File unitTrainingUnits.patch, 5.8 KB (added by s0600204, 9 years ago)

Patch to place units that train other units on same level as structures.

  • gui/structree/draw.js

    function draw()  
    102102            hideRemaining("phase["+i+"]_struct["+s+"]_row[", r, "]");
    103103            ++s;
    104104        }
     105       
     106        for (let unit of g_CivData[g_SelectedCiv].trainList[pha])
     107        {
     108            let thisEle = Engine.GetGUIObjectByName("phase["+i+"]_struct["+s+"]");
     109            if (thisEle === undefined)
     110            {
     111                error("\""+g_SelectedCiv+"\" has more structures + units in phase "+pha+" than can be supported by the current GUI layout");
     112                break;
     113            }
     114
     115            let c = 0;
     116            let rowCounts = [];
     117            unit = g_ParsedData.units[unit];
     118            Engine.GetGUIObjectByName("phase["+i+"]_struct["+s+"]_icon").sprite = "stretched:session/portraits/"+unit.icon;
     119            Engine.GetGUIObjectByName("phase["+i+"]_struct["+s+"]_icon").tooltip = assembleTooltip(unit);
     120            Engine.GetGUIObjectByName("phase["+i+"]_struct["+s+"]_name").caption = translate(unit.name.specific);
     121            thisEle.hidden = false;
     122           
     123           
     124            for (let r in g_DrawLimits[pha].prodQuant)
     125            {
     126                let p = 0;
     127                r = +r; // force int
     128                let prod_pha = phaseList[phaseList.indexOf(pha) + r];
     129                if (unit.trainer[prod_pha])
     130                {
     131                    for (let prod of unit.trainer[prod_pha])
     132                    {
     133                        prod = g_ParsedData.units[prod];
     134                        if (!drawProdIcon(i, s, r, p, prod, "Blue"))
     135                            break;
     136                        p++;
     137                    }
     138                }
     139                rowCounts[r] = p;
     140                if (p>c)
     141                    c = p;
     142                hideRemaining("phase["+i+"]_struct["+s+"]_row["+r+"]_prod[", p, "]");
     143            }
     144
     145           
     146            let size = thisEle.size;
     147            size.left = y;
     148            size.right = size.left + ((c*24 < defWidth)?defWidth:c*24)+4;
     149            y = size.right + defMargin;
     150            thisEle.size = size;
     151
     152            let eleWidth = size.right - size.left;
     153            let r;
     154            for (r in rowCounts)
     155            {
     156                let wid = rowCounts[r] * 24 - 4;
     157                let phaEle = Engine.GetGUIObjectByName("phase["+i+"]_struct["+s+"]_row["+r+"]");
     158                size = phaEle.size;
     159                size.left = (eleWidth - wid)/2;
     160                phaEle.size = size;
     161            }
     162            ++r;
     163            hideRemaining("phase["+i+"]_struct["+s+"]_row[", r, "]");
     164            ++s;
     165        }
     166       
    105167        hideRemaining("phase["+i+"]_struct[", s, "]");
    106168        ++i;
    107169    }
  • gui/structree/load.js

    function loadUnit(templateName)  
    5454
    5555    unit.gather = getGatherRates(templateName);
    5656
     57    if (template.ProductionQueue)
     58    {
     59        unit.trainer = [];
     60        for (let build of template.ProductionQueue.Entities._string.split(" "))
     61        {
     62            build = build.replace("{civ}", g_SelectedCiv);
     63            unit.trainer.push(build);
     64            if (g_Lists.units.indexOf(build) < 0)
     65                g_Lists.units.push(build);
     66        }
     67    }
     68
    5769    if (template.Heal)
    5870        unit.healer = {
    5971            "Range": +template.Heal.Range || 0,
  • gui/structree/rows.xml

     
    33<object name="phase_rows">
    44    <repeat count="4" var="k">
    55        <object name="phase[k]">
    6             <repeat count="11" var="s">
     6            <repeat count="12" var="s">
    77                <object type="image" style="StructBox" name="phase[k]_struct[s]">
    88                    <object type="text" style="StructNameSpecific" name="phase[k]_struct[s]_name"/>
    99                    <object type="image" style="StructIcon" name="phase[k]_struct[s]_icon"
  • gui/structree/structree.js

    function selectCiv(civCode)  
    236236            "units": newProdUnits
    237237        };
    238238    }
     239   
     240    // Group training lists of units by phase
     241    for (let unitCode of g_Lists.units)
     242    {
     243        let unitInfo = g_ParsedData.units[unitCode];
     244
     245        if (!unitInfo || !unitInfo.trainer)
     246            continue;
     247
     248        // Determine phase for units
     249        let newTrainees = {};
     250        for (let prod of unitInfo.trainer)
     251        {
     252            if (!(prod in g_ParsedData.units))
     253            {
     254                error(prod+" doesn't exist! ("+structCode+")");
     255                continue;
     256            }
     257            let unit = g_ParsedData.units[prod];
     258            let phase = "";
     259
     260            if (unit.phase !== false)
     261                phase = unit.phase;
     262            else if (unit.required !== undefined)
     263            {
     264                if (unit.required in g_ParsedData.phases)
     265                    phase = g_ParsedData.phases[unit.required].actualPhase;
     266                else
     267                {
     268                    let reqs = g_ParsedData.techs[unit.required].reqs;
     269                    if (g_SelectedCiv in reqs)
     270                        phase = reqs[g_SelectedCiv][0];
     271                    else
     272                        phase = reqs.generic[0];
     273                }
     274            }
     275            else if (unitInfo.phase !== false)
     276                phase = unitInfo.phase;
     277            else
     278                phase = g_ParsedData.phaseList[0];
     279
     280            if (!(phase in newTrainees))
     281                newTrainees[phase] = [];
     282
     283            newTrainees[phase].push(prod);
     284        }
     285
     286        g_ParsedData.units[unitCode].trainer = newTrainees;
     287    }
    239288
    240289    // Determine the buildList for the civ (grouped by phase)
    241290    var buildList = {};
     291    var trainerList = {};
    242292    for (let pha of g_ParsedData.phaseList)
     293    {
    243294        buildList[pha] = [];
     295        trainerList[pha] = [];
     296    }
    244297    for (let structCode of g_Lists.structures)
    245298    {
    246299        if (!g_ParsedData.structures[structCode].phase || startStructs.indexOf(structCode) > -1)
    function selectCiv(civCode)  
    249302        let myPhase = g_ParsedData.structures[structCode].phase;
    250303        buildList[myPhase].push(structCode);
    251304    }
     305    for (let unitCode of g_Lists.units)
     306    {
     307        if (!g_ParsedData.units[unitCode] || !g_ParsedData.units[unitCode].trainer)
     308            continue;
     309       
     310        let myPhase = g_ParsedData.units[unitCode].phase;
     311        if (g_ParsedData.phaseList.indexOf(myPhase) === -1)
     312            myPhase = g_ParsedData.phases[myPhase].actualPhase;
     313       
     314        trainerList[myPhase].push(unitCode);
     315    }
    252316
    253317    g_CivData[g_SelectedCiv].buildList = buildList;
     318    g_CivData[g_SelectedCiv].trainList = trainerList;
    254319
    255320    // Draw tree
    256321    draw();