Ticket #1924: build limits v1.patch
File build limits v1.patch, 16.1 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
1464 1464 1465 1465 // Called by GUI when user clicks construction button 1466 1466 // @param buildTemplate Template name of the entity the user wants to build 1467 function startBuildingPlacement(buildTemplate )1467 function startBuildingPlacement(buildTemplate, playerState) 1468 1468 { 1469 // TODO: we should clear any highlight selection rings here. If the mouse was over an entity before going onto the GUI 1470 // to start building a structure, then the highlight selection rings are kept during the construction of the building. 1471 // Gives the impression that somehow the hovered-over entity has something to do with the building you're constructing. 1469 if(getEntityLimitAndCount(playerState, buildTemplate)[2]!=0) 1470 { 1471 // TODO: we should clear any highlight selection rings here. If the mouse was over an entity before going onto the GUI 1472 // to start building a structure, then the highlight selection rings are kept during the construction of the building. 1473 // Gives the impression that somehow the hovered-over entity has something to do with the building you're constructing. 1472 1474 1473 1475 placementSupport.Reset(); 1474 1476 1475 // find out if we're building a wall, and change the entity appropriately if so 1476 var templateData = GetTemplateData(buildTemplate); 1477 if (templateData.wallSet) 1478 { 1479 placementSupport.mode = "wall"; 1480 placementSupport.wallSet = templateData.wallSet; 1481 inputState = INPUT_BUILDING_PLACEMENT; 1482 } 1483 else 1484 { 1485 placementSupport.mode = "building"; 1486 placementSupport.template = buildTemplate; 1487 inputState = INPUT_BUILDING_PLACEMENT; 1488 } 1477 // find out if we're building a wall, and change the entity appropriately if so 1478 var templateData = GetTemplateData(buildTemplate); 1479 if (templateData.wallSet) 1480 { 1481 placementSupport.mode = "wall"; 1482 placementSupport.wallSet = templateData.wallSet; 1483 inputState = INPUT_BUILDING_PLACEMENT; 1484 } 1485 else 1486 { 1487 placementSupport.mode = "building"; 1488 placementSupport.template = buildTemplate; 1489 inputState = INPUT_BUILDING_PLACEMENT; 1490 } 1491 } 1489 1492 } 1490 1493 1491 1494 // Called by GUI when user changes preferred trading goods … … 1548 1551 function getEntityLimitAndCount(playerState, entType) 1549 1552 { 1550 1553 var template = GetTemplateData(entType); 1551 var trainingCategory = null;1554 var entCategory = null; 1552 1555 if (template.trainingRestrictions) 1553 trainingCategory = template.trainingRestrictions.category; 1554 var trainEntLimit = undefined; 1555 var trainEntCount = undefined; 1556 var canBeTrainedCount = undefined; 1557 if (trainingCategory && playerState.entityLimits[trainingCategory]) 1556 entCategory = template.trainingRestrictions.category; 1557 else if (template.buildRestrictions) 1558 entCategory = template.buildRestrictions.category; 1559 var entLimit = undefined; 1560 var entCount = undefined; 1561 var canBeAddedCount = undefined; 1562 if (entCategory && playerState.entityLimits[entCategory]) 1558 1563 { 1559 trainEntLimit = playerState.entityLimits[trainingCategory];1560 trainEntCount = playerState.entityCounts[trainingCategory];1561 canBe TrainedCount = Math.max(trainEntLimit - trainEntCount, 0);1564 entLimit = playerState.entityLimits[entCategory]; 1565 entCount = playerState.entityCounts[entCategory]; 1566 canBeAddedCount = Math.max(entLimit - entCount, 0); 1562 1567 } 1563 return [ trainEntLimit, trainEntCount, canBeTrainedCount];1568 return [entLimit, entCount, canBeAddedCount]; 1564 1569 } 1565 1570 1566 1571 // Add the unit shown at position to the training queue for all entities in the selection -
binaries/data/mods/public/gui/session/unit_commands.js
146 146 { 147 147 if (trainEntLimit == undefined) 148 148 return ""; 149 var text = "\n\nCurrent count: " + trainEntCount + ", limit: " + trainEntLimit + ".";149 var text = "\n\nCurrent Count: " + trainEntCount + ", Limit: " + trainEntLimit + "."; 150 150 if (trainEntCount >= trainEntLimit) 151 151 text = "[color=\"red\"]" + text + "[/color]"; 152 152 return text; … … 376 376 377 377 switch (guiName) 378 378 { 379 380 381 382 383 384 379 case SELECTION: 380 var name = getEntityNames(template); 381 var tooltip = name; 382 var count = g_Selection.groups.getCount(item); 383 getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : ""); 384 break; 385 385 386 387 388 389 386 case QUEUE: 387 var tooltip = getEntityNames(template); 388 if (item.neededSlots) 389 tooltip += "\n[color=\"red\"]Insufficient population capacity:\n[/color]"+getCostComponentDisplayName("population")+" "+item.neededSlots; 390 390 391 392 391 var progress = Math.round(item.progress*100) + "%"; 392 getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (item.count > 1 ? item.count : ""); 393 393 394 395 396 397 394 if (i == 0) 395 { 396 getGUIObjectByName("queueProgress").caption = (item.progress ? progress : ""); 397 var size = getGUIObjectByName("unit"+guiName+"ProgressSlider["+i+"]").size; 398 398 399 400 401 402 403 399 // Buttons are assumed to be square, so left/right offsets can be used for top/bottom. 400 size.top = size.left + Math.round(item.progress * (size.right - size.left)); 401 getGUIObjectByName("unit"+guiName+"ProgressSlider["+i+"]").size = size; 402 } 403 break; 404 404 405 406 407 408 409 410 405 case GARRISON: 406 var name = getEntityNames(template); 407 var tooltip = "Unload " + name + "\nSingle-click to unload 1. Shift-click to unload all of this type."; 408 var count = garrisonGroups.getCount(item); 409 getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : ""); 410 break; 411 411 412 413 414 415 416 417 412 case GATE: 413 var tooltip = item.tooltip; 414 if (item.template) 415 { 416 var template = GetTemplateData(item.template); 417 tooltip += "\n" + getEntityCostTooltip(template); 418 418 419 420 419 var affordableMask = getGUIObjectByName("unitGateUnaffordable["+i+"]"); 420 affordableMask.hidden = true; 421 421 422 423 424 425 426 427 428 429 422 var neededResources = Engine.GuiInterfaceCall("GetNeededResources", template.cost); 423 if (neededResources) 424 { 425 affordableMask.hidden = false; 426 tooltip += getNeededResourcesTooltip(neededResources); 427 } 428 } 429 break; 430 430 431 432 433 431 case PACK: 432 var tooltip = item.tooltip; 433 break; 434 434 435 436 437 438 435 case STANCE: 436 case FORMATION: 437 var tooltip = toTitleCase(item); 438 break; 439 439 440 441 440 case TRAINING: 441 var tooltip = getEntityNamesFormatted(template); 442 442 443 444 443 if (template.tooltip) 444 tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]"; 445 445 446 447 448 449 450 451 446 var [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] = 447 getTrainingBatchStatus(playerState, unitEntState.id, entType, selection); 448 if (Engine.HotkeyIsPressed("session.batchtrain")) 449 { 450 trainNum = buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch; 451 } 452 452 453 453 tooltip += "\n" + getEntityCostTooltip(template, trainNum, unitEntState.id); 454 454 455 456 457 458 459 460 461 462 455 if (template.health) 456 tooltip += "\n[font=\"serif-bold-13\"]Health:[/font] " + template.health; 457 if (template.armour) 458 tooltip += "\n[font=\"serif-bold-13\"]Armour:[/font] " + armorTypesToText(template.armour); 459 if (template.attack) 460 tooltip += "\n" + getEntityAttack(template); 461 if (template.speed) 462 tooltip += "\n" + getEntitySpeed(template); 463 463 464 465 466 464 var [trainEntLimit, trainEntCount, canBeTrainedCount] = 465 getEntityLimitAndCount(playerState, entType) 466 tooltip += formatLimitString(trainEntLimit, trainEntCount); 467 467 468 469 470 471 472 473 474 468 tooltip += formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch); 469 var key = g_ConfigDB.system["hotkey.session.queueunit." + (i+1)]; 470 if (key !== undefined) 471 { 472 tooltip += "\n[font=\"serif-bold-13\"]HotKey (" + key + ").[/font]"; 473 } 474 break; 475 475 476 477 478 479 476 case RESEARCH: 477 var tooltip = getEntityNamesFormatted(template); 478 if (template.tooltip) 479 tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]"; 480 480 481 481 tooltip += "\n" + getEntityCostTooltip(template); 482 482 483 484 485 486 487 483 if (item.pair) 484 { 485 var tooltip1 = getEntityNamesFormatted(template1); 486 if (template1.tooltip) 487 tooltip1 += "\n[font=\"serif-13\"]" + template1.tooltip + "[/font]"; 488 488 489 490 491 489 tooltip1 += "\n" + getEntityCostTooltip(template1); 490 } 491 break; 492 492 493 494 495 496 493 case CONSTRUCTION: 494 var tooltip = getEntityNamesFormatted(template); 495 if (template.tooltip) 496 tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]"; 497 497 498 tooltip += "\n" + getEntityCostTooltip(template); // see utility_functions.js 499 tooltip += getPopulationBonusTooltip(template); // see utility_functions.js 498 tooltip += "\n" + getEntityCostTooltip(template); // see utility_functions.js 499 tooltip += getPopulationBonusTooltip(template); // see utility_functions.js 500 if (template.health) 501 tooltip += "\n[font=\"serif-bold-13\"]Health:[/font] " + template.health; 502 503 var [entLimit, entCount, canBeAddeddCount] = 504 getEntityLimitAndCount(playerState, entType) // see input.js 505 tooltip += formatLimitString(entLimit, entCount); 500 506 501 if (template.health)502 tooltip += "\n[font=\"serif-bold-13\"]Health:[/font] " + template.health;503 504 507 break; 505 508 506 509 case COMMAND: … … 777 780 var totalCosts = {}; 778 781 var trainNum = 1; 779 782 var button_disableable = true; 783 if (getEntityLimitAndCount(playerState, entType)[2]==0) 784 { 785 grayscale = "grayscale:"; 786 affordableMask.hidden = false; 787 affordableMask.sprite = "colour: 0 0 0 100"; 788 } 789 icon.sprite = "stretched:" + grayscale + "session/portraits/" + template.icon; 780 790 if (guiName == TRAINING) 781 791 { 782 var trainingCategory = null;783 if (template.trainingRestrictions)784 trainingCategory = template.trainingRestrictions.category;785 if (trainingCategory && playerState.entityLimits[trainingCategory] &&786 playerState.entityCounts[trainingCategory] >= playerState.entityLimits[trainingCategory])787 {788 grayscale = "grayscale:";789 affordableMask.hidden = false;790 affordableMask.sprite = "colour: 0 0 0 100";791 }792 icon.sprite = "stretched:" + grayscale + "session/portraits/" + template.icon;793 794 792 if (Engine.HotkeyIsPressed("session.batchtrain")) 795 793 { 796 794 var [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch, batchTrainingCount] = … … 1082 1080 1083 1081 // The first selected entity's type has priority. 1084 1082 if (entState.buildEntities) 1085 setupUnitPanel(CONSTRUCTION, usedPanels, entState, playerState, buildableEnts, startBuildingPlacement); 1083 setupUnitPanel(CONSTRUCTION, usedPanels, entState, playerState, buildableEnts, 1084 function (trainEntType) { startBuildingPlacement(trainEntType, playerState); } ); 1086 1085 else if (entState.production && entState.production.entities) 1087 1086 setupUnitPanel(TRAINING, usedPanels, entState, playerState, trainableEnts, 1088 1087 function (trainEntType) { addTrainingToQueue(selection, trainEntType, playerState); } );