Ticket #2179: selectionCache.diff
File selectionCache.diff, 5.0 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
1631 1631 if (!selection.length) 1632 1632 return; 1633 1633 1634 var trainableEnts = getAllTrainableEntities (selection);1634 var trainableEnts = getAllTrainableEntitiesFromSelection(); 1635 1635 1636 1636 // Check if the position is valid 1637 1637 if (!trainableEnts.length || trainableEnts.length <= position) -
binaries/data/mods/public/gui/session/selection.js
217 217 */ 218 218 EntitySelection.prototype.update = function() 219 219 { 220 var changed = false; 220 221 this.checkRenamedEntities(); 221 222 for each (var ent in this.selected) 222 223 { … … 227 228 { 228 229 delete this.selected[ent]; 229 230 this.groups.removeEnt(ent); 230 this.dirty= true;231 changed = true; 231 232 continue; 232 233 } 233 234 … … 241 242 242 243 delete this.selected[ent]; 243 244 this.groups.removeEnt(ent); 244 this.dirty= true;245 changed = true; 245 246 continue; 246 247 } 247 248 } 249 if (changed) 250 this.onChange(); 248 251 }; 249 252 250 253 /** … … 318 321 } 319 322 320 323 this.groups.add(this.toList()); // Create Selection Groups 321 this. dirty = true;324 this.onChange(); 322 325 }; 323 326 324 327 EntitySelection.prototype.removeList = function(ents) … … 339 342 _setStatusBars(removed, false); 340 343 _setMotionOverlay(removed, false); 341 344 342 this. dirty = true;345 this.onChange(); 343 346 }; 344 347 345 348 EntitySelection.prototype.reset = function() … … 349 352 _setMotionOverlay(this.toList(), false); 350 353 this.selected = {}; 351 354 this.groups.reset(); 352 this. dirty = true;355 this.onChange(); 353 356 }; 354 357 355 358 EntitySelection.prototype.rebuildSelection = function(renamed) … … 407 410 _setMotionOverlay(this.toList(), enabled); 408 411 }; 409 412 410 var g_Selection = new EntitySelection(); 413 EntitySelection.prototype.onChange = function() 414 { 415 this.dirty = true; 416 if (this == g_Selection) 417 onSelectionChange(); 418 } 411 419 420 412 421 /** 413 422 * EntityGroupsContainer class for managing grouped entities 414 423 */ … … 483 492 } 484 493 485 494 var g_Groups = new EntityGroupsContainer(); 495 496 /** 497 * Cache some quantities which depends only on g_Selection 498 */ 499 500 var g_Selection = new EntitySelection(); 501 502 var g_canMoveIntoFormation = {}; 503 var g_allBuildableEntities = undefined; 504 var g_allTrainableEntities = undefined; 505 506 // Reset cached quantities which depend on selection 507 function onSelectionChange() 508 { 509 g_canMoveIntoFormation = {}; 510 g_allBuildableEntities = undefined; 511 g_allTrainableEntities = undefined; 512 } -
binaries/data/mods/public/gui/session/session.js
327 327 // simulation state and the current selection). 328 328 if (g_Selection.dirty) 329 329 { 330 g_Selection.dirty = false; 331 330 332 onSimulationUpdate(); 331 333 332 334 // Display rally points for selected buildings … … 427 429 */ 428 430 function onSimulationUpdate() 429 431 { 430 g_Selection.dirty = false;431 432 g_EntityStates = {}; 432 433 g_TemplateData = {}; 433 434 g_TechnologyData = {}; -
binaries/data/mods/public/gui/session/unit_commands.js
572 572 // Get icon image 573 573 if (guiName == FORMATION) 574 574 { 575 var formationOk = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", { 576 "ents": g_Selection.toList(), 577 "formationName": item 578 }); 579 575 var formationOk = canMoveSelectionIntoFormation(item); 580 576 var grayscale = ""; 581 577 button.enabled = formationOk; 582 578 if (!formationOk) … … 1272 1268 return trainableEnts; 1273 1269 } 1274 1270 1271 function getAllTrainableEntitiesFromSelection() 1272 { 1273 if (!g_allTrainableEntities) 1274 g_allTrainableEntities = getAllTrainableEntities(g_Selection.toList()); 1275 1276 return g_allTrainableEntities; 1277 } 1278 1275 1279 // Get all of the available entities which can be built by the selected entities 1276 1280 function getAllBuildableEntities(selection) 1277 1281 { … … 1288 1292 removeDupes(buildableEnts); 1289 1293 return buildableEnts; 1290 1294 } 1295 1296 function getAllBuildableEntitiesFromSelection() 1297 { 1298 if (!g_allBuildableEntities) 1299 g_allBuildableEntities = getAllBuildableEntities(g_Selection.toList()); 1300 1301 return g_allBuildableEntities; 1302 } 1303 1304 // Check if the selection can move into formation, and cache the result 1305 function canMoveSelectionIntoFormation(formationName) 1306 { 1307 if (!(formationName in g_canMoveIntoFormation)) 1308 { 1309 g_canMoveIntoFormation[formationName] = Engine.GuiInterfaceCall("CanMoveEntsIntoFormation", { 1310 "ents": g_Selection.toList(), 1311 "formationName": formationName 1312 }); 1313 } 1314 return g_canMoveIntoFormation[formationName]; 1315 }