From d0403bd3a83f3c15b55bcafed34f679a99f5462c Mon Sep 17 00:00:00 2001 From: Angen Date: Sat, 14 Dec 2019 20:10:32 +0000 Subject: [PATCH] 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. --- .../data/mods/public/gui/common/tooltips.js | 10 +++++----- .../public/gui/session/selection_panels.js | 20 ++++++++++--------- .../data/mods/public/gui/session/session.js | 12 ++++++++--- .../simulation/components/GuiInterface.js | 10 ++++++---- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/binaries/data/mods/public/gui/common/tooltips.js b/binaries/data/mods/public/gui/common/tooltips.js index 9de103566c..35024e3964 100644 --- a/binaries/data/mods/public/gui/common/tooltips.js +++ b/binaries/data/mods/public/gui/common/tooltips.js @@ -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); diff --git a/binaries/data/mods/public/gui/session/selection_panels.js b/binaries/data/mods/public/gui/session/selection_panels.js index 751f211f39..1fcc4c784e 100644 --- a/binaries/data/mods/public/gui/session/selection_panels.js +++ b/binaries/data/mods/public/gui/session/selection_panels.js @@ -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)); diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 079fbded55..ad8b7acf80 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -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]; } diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 22011d6b2c..8f05dff989 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -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