mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Apply modifications to template values based on entity owner instead watching player
When observer selects some building he can see possible units to be trained. Data about that templates are returned with id of observer what means no technologies or bonuses for selected player have been applied to the template. So observer does not see correct information in tooltip. Differential Revision: https://code.wildfiregames.com/D2054 Fixes: #5109 Tested by: Nescio This was SVN commit r23237.
This commit is contained in:
parent
425fb6d93a
commit
d0403bd3a8
4 changed files with 31 additions and 21 deletions
|
|
@ -644,16 +644,16 @@ function getWallPieceTooltip(wallTypes)
|
|||
/**
|
||||
* Returns the cost information to display in the specified entity's construction button tooltip.
|
||||
*/
|
||||
function getEntityCostTooltip(template, entity, buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch)
|
||||
function getEntityCostTooltip(template, player, 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.
|
||||
if (template.wallSet)
|
||||
{
|
||||
let templateLong = GetTemplateData(template.wallSet.templates.long);
|
||||
let templateMedium = GetTemplateData(template.wallSet.templates.medium);
|
||||
let templateShort = GetTemplateData(template.wallSet.templates.short);
|
||||
let templateTower = GetTemplateData(template.wallSet.templates.tower);
|
||||
let templateLong = GetTemplateData(template.wallSet.templates.long, player);
|
||||
let templateMedium = GetTemplateData(template.wallSet.templates.medium, player);
|
||||
let templateShort = GetTemplateData(template.wallSet.templates.short, player);
|
||||
let templateTower = GetTemplateData(template.wallSet.templates.tower, player);
|
||||
|
||||
let wallCosts = getWallPieceTooltip([templateShort, templateMedium, templateLong]);
|
||||
let towerCosts = getEntityCostComponentsTooltipString(templateTower);
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ g_SelectionPanels.Construction = {
|
|||
},
|
||||
"setupButton": function(data)
|
||||
{
|
||||
let template = GetTemplateData(data.item);
|
||||
let template = GetTemplateData(data.item, data.player);
|
||||
if (!template)
|
||||
return false;
|
||||
|
||||
|
|
@ -240,12 +240,15 @@ g_SelectionPanels.Construction = {
|
|||
getEntityNamesFormatted,
|
||||
getVisibleEntityClassesFormatted,
|
||||
getAurasTooltip,
|
||||
getEntityTooltip,
|
||||
getEntityCostTooltip,
|
||||
getGarrisonTooltip,
|
||||
getPopulationBonusTooltip,
|
||||
showTemplateViewerOnRightClickTooltip
|
||||
getEntityTooltip
|
||||
].map(func => func(template));
|
||||
tooltips.push(
|
||||
getEntityCostTooltip(template, data.player),
|
||||
getGarrisonTooltip(template),
|
||||
getPopulationBonusTooltip(template),
|
||||
showTemplateViewerOnRightClickTooltip(template)
|
||||
);
|
||||
|
||||
|
||||
let limits = getEntityLimitAndCount(data.playerState, data.item);
|
||||
tooltips.push(
|
||||
|
|
@ -930,7 +933,7 @@ g_SelectionPanels.Training = {
|
|||
},
|
||||
"setupButton": function(data)
|
||||
{
|
||||
let template = GetTemplateData(data.item);
|
||||
let template = GetTemplateData(data.item, data.player);
|
||||
if (!template)
|
||||
return false;
|
||||
|
||||
|
|
@ -969,9 +972,8 @@ g_SelectionPanels.Training = {
|
|||
getVisibleEntityClassesFormatted(template),
|
||||
getAurasTooltip(template),
|
||||
getEntityTooltip(template),
|
||||
getEntityCostTooltip(template, unitIds[0], buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch)
|
||||
getEntityCostTooltip(template, data.player, unitIds[0], buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch)
|
||||
];
|
||||
|
||||
let limits = getEntityLimitAndCount(data.playerState, data.item);
|
||||
tooltips.push(formatLimitString(limits.entLimit, limits.entCount, limits.entLimitChangers));
|
||||
|
||||
|
|
|
|||
|
|
@ -208,15 +208,21 @@ function GetEntityState(entId)
|
|||
return g_EntityStates[entId];
|
||||
}
|
||||
|
||||
function GetTemplateData(templateName)
|
||||
/**
|
||||
* Returns template data calling GetTemplateData defined in GuiInterface.js
|
||||
* and deepfreezing returned object.
|
||||
* @param {string} templateName - Data of this template will be returned.
|
||||
* @param {number|undefined} owner - Modifications of this player will be applied to the template.
|
||||
* If undefined, id of player calling this method will be used.
|
||||
*/
|
||||
function GetTemplateData(templateName, owner)
|
||||
{
|
||||
if (!(templateName in g_TemplateData))
|
||||
{
|
||||
let template = Engine.GuiInterfaceCall("GetTemplateData", templateName);
|
||||
let template = Engine.GuiInterfaceCall("GetTemplateData", { "templateName": templateName, "owner": owner });
|
||||
translateObjectKeys(template, ["specific", "generic", "tooltip"]);
|
||||
g_TemplateData[templateName] = deepfreeze(template);
|
||||
}
|
||||
|
||||
return g_TemplateData[templateName];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -561,8 +561,10 @@ GuiInterface.prototype.GetAverageRangeForBuildings = function(player, cmd)
|
|||
return cmpRangeManager.GetElevationAdaptedRange(pos, rot, range, elevationBonus, 2*Math.PI);
|
||||
};
|
||||
|
||||
GuiInterface.prototype.GetTemplateData = function(player, templateName)
|
||||
GuiInterface.prototype.GetTemplateData = function(player, data)
|
||||
{
|
||||
let templateName = data.templateName;
|
||||
let owner = !!data.owner ? data.owner : player;
|
||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
|
||||
let template = cmpTemplateManager.GetTemplate(templateName);
|
||||
|
||||
|
|
@ -572,14 +574,14 @@ GuiInterface.prototype.GetTemplateData = function(player, templateName)
|
|||
let aurasTemplate = {};
|
||||
|
||||
if (!template.Auras)
|
||||
return GetTemplateDataHelper(template, player, aurasTemplate);
|
||||
return GetTemplateDataHelper(template, owner, aurasTemplate);
|
||||
|
||||
let auraNames = template.Auras._string.split(/\s+/);
|
||||
|
||||
for (let name of auraNames)
|
||||
aurasTemplate[name] = AuraTemplates.Get(name);
|
||||
|
||||
return GetTemplateDataHelper(template, player, aurasTemplate);
|
||||
return GetTemplateDataHelper(template, owner, aurasTemplate);
|
||||
};
|
||||
|
||||
GuiInterface.prototype.IsTechnologyResearched = function(player, data)
|
||||
|
|
@ -1219,7 +1221,7 @@ GuiInterface.prototype.SetWallPlacementPreview = function(player, cmd)
|
|||
this.placementWallEntities[tpl] = {
|
||||
"numUsed": 0,
|
||||
"entities": [],
|
||||
"templateData": this.GetTemplateData(player, tpl),
|
||||
"templateData": this.GetTemplateData(player, { "templateName": tpl }),
|
||||
};
|
||||
|
||||
// ensure that the loaded template data contains a wallPiece component
|
||||
|
|
|
|||
Loading…
Reference in a new issue