mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Improve training tooltip with multiple selection
Reviewed by: bb. Fixes #4264. Differential Revision: https://code.wildfiregames.com/D43 This was SVN commit r19538.
This commit is contained in:
parent
30823d8988
commit
af2f8a95fb
3 changed files with 16 additions and 15 deletions
|
|
@ -353,14 +353,14 @@ function multiplyEntityCosts(template, trainNum)
|
|||
/**
|
||||
* Helper function for getEntityCostTooltip.
|
||||
*/
|
||||
function getEntityCostComponentsTooltipString(template, trainNum, entity)
|
||||
function getEntityCostComponentsTooltipString(template, entity, buildingsCountToTrainFullBatch = 1, fullBatchSize = 1, remainderBatch = 0)
|
||||
{
|
||||
if (!trainNum)
|
||||
trainNum = 1;
|
||||
|
||||
let totalCosts = multiplyEntityCosts(template, trainNum);
|
||||
let totalCosts = multiplyEntityCosts(template, buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch);
|
||||
if (template.cost.time)
|
||||
totalCosts.time = Math.ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1));
|
||||
totalCosts.time = Math.ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", {
|
||||
"entity": entity,
|
||||
"batchSize": buildingsCountToTrainFullBatch > 0 ? fullBatchSize : remainderBatch
|
||||
}) : 1));
|
||||
|
||||
let costs = [];
|
||||
for (let type in template.cost)
|
||||
|
|
@ -493,7 +493,7 @@ function getWallPieceTooltip(wallTypes)
|
|||
/**
|
||||
* Returns the cost information to display in the specified entity's construction button tooltip.
|
||||
*/
|
||||
function getEntityCostTooltip(template, trainNum, entity)
|
||||
function getEntityCostTooltip(template, entity, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch)
|
||||
{
|
||||
// Entities with a wallset component are proxies for initiating wall placement and as such do not have a cost of
|
||||
// their own; the individual wall pieces within it do.
|
||||
|
|
@ -512,7 +512,7 @@ function getEntityCostTooltip(template, trainNum, entity)
|
|||
}
|
||||
|
||||
if (template.cost)
|
||||
return getEntityCostComponentsTooltipString(template, trainNum, entity).join(" ");
|
||||
return getEntityCostComponentsTooltipString(template, entity, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch).join(" ");
|
||||
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1423,7 +1423,7 @@ function addResearchToQueue(entity, researchType)
|
|||
|
||||
/**
|
||||
* Returns the number of units that will be present in a batch if the user clicks
|
||||
* the training button with shift down
|
||||
* the training button depending on the batch training modifier hotkey
|
||||
*/
|
||||
function getTrainingStatus(playerState, trainEntType, selection)
|
||||
{
|
||||
|
|
@ -1445,10 +1445,13 @@ function getTrainingStatus(playerState, trainEntType, selection)
|
|||
limits = getEntityLimitAndCount(playerState, trainEntType);
|
||||
|
||||
// We need to calculate count after the next increment if it's possible
|
||||
if (limits.canBeAddedCount == undefined ||
|
||||
limits.canBeAddedCount > nextBatchTrainingCount * appropriateBuildings.length)
|
||||
if ((limits.canBeAddedCount == undefined ||
|
||||
limits.canBeAddedCount > nextBatchTrainingCount * appropriateBuildings.length) &&
|
||||
Engine.HotkeyIsPressed("session.batchtrain"))
|
||||
nextBatchTrainingCount += batchIncrementSize;
|
||||
|
||||
nextBatchTrainingCount = Math.max(nextBatchTrainingCount, 1);
|
||||
|
||||
// If training limits don't allow us to train batchTrainingCount in each appropriate building
|
||||
// train as many full batches as we can and remainer in one more building.
|
||||
var buildingsCountToTrainFullBatch = appropriateBuildings.length;
|
||||
|
|
|
|||
|
|
@ -986,9 +986,7 @@ g_SelectionPanels.Training = {
|
|||
let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] =
|
||||
getTrainingStatus(data.playerState, data.item, data.unitEntStates.map(status => status.id));
|
||||
|
||||
let trainNum = buildingsCountToTrainFullBatch || 1;
|
||||
if (Engine.HotkeyIsPressed("session.batchtrain"))
|
||||
trainNum = buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch;
|
||||
let trainNum = buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch;
|
||||
|
||||
let neededResources;
|
||||
if (template.cost)
|
||||
|
|
@ -1010,7 +1008,7 @@ g_SelectionPanels.Training = {
|
|||
getVisibleEntityClassesFormatted(template),
|
||||
getAurasTooltip(template),
|
||||
getEntityTooltip(template),
|
||||
getEntityCostTooltip(template, trainNum, data.unitEntStates[0].id)
|
||||
getEntityCostTooltip(template, data.unitEntStates[0].id, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch)
|
||||
];
|
||||
|
||||
let limits = getEntityLimitAndCount(data.playerState, data.item);
|
||||
|
|
|
|||
Loading…
Reference in a new issue