Ticket #2179: moveFormation.diff

File moveFormation.diff, 2.9 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    3838// Indexes of resources to sell and buy on barter panel
    3939var g_barterSell = 0;
    4040
     41// Cache a few quantities which depend on selection
     42var g_canMoveIntoFormation = {};
     43
    4144// Lay out a row of centered buttons (does not work inside a loop like the other function)
    4245function layoutButtonRowCentered(rowNumber, guiName, startIndex, endIndex, width)
    4346{
     
    572575        // Get icon image
    573576        if (guiName == FORMATION)
    574577        {
    575             var formationOk = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", {
    576                 "ents": g_Selection.toList(),
    577                 "formationName": item
    578             });
    579 
     578            var formationOk = canMoveEntsIntoFormation(item);
    580579            var grayscale = "";
    581580            button.enabled = formationOk;
    582581            if (!formationOk)
     
    12881287    removeDupes(buildableEnts);
    12891288    return buildableEnts;
    12901289}
     1290
     1291// Check if the selection can move into formation, and cache the result
     1292function canMoveEntsIntoFormation(formationName)
     1293{
     1294    if (!(formationName in g_canMoveIntoFormation))
     1295    {
     1296        g_canMoveIntoFormation[formationName] = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", {
     1297            "ents": g_Selection.toList(),
     1298            "formationName": formationName
     1299        });
     1300    }
     1301    return g_canMoveIntoFormation[formationName];
     1302}
     1303
     1304// Reset cached quantities which depend on selection
     1305function onSelectionChanged()
     1306{
     1307    g_canMoveIntoFormation = {};
     1308}
     1309 Pas de retour chariot à la fin du fichier
  • binaries/data/mods/public/gui/session/session.js

     
    312312    // simulation state and the current selection).
    313313    if (g_Selection.dirty)
    314314    {
     315        // reset cached quantities which depend on selection (in unit_commands.js)
     316        onSelectionChanged();
     317
    315318        onSimulationUpdate();
    316319
    317320        // Display rally points for selected buildings
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    12801280    formationName = formationName.replace(/\s+/g,"");
    12811281
    12821282    var count = 0;
     1283    if (requirements.count == 0)
     1284        return true;
    12831285    var reqClasses = requirements.classesRequired || [];
    12841286    for each (var ent in ents)
    12851287    {
     
    12921294            return false;
    12931295
    12941296        count++;
     1297        if (count == requirements.count)
     1298            return true;
    12951299    }
    12961300
    1297     if (count < requirements.count)
    1298         return false;
    1299 
    1300     return true;
     1301    return false;
    13011302}
    13021303
    13031304/**