From cf04bad4bc74681bddfef1f892bed402647bd762 Mon Sep 17 00:00:00 2001 From: elexis Date: Wed, 20 Jul 2016 01:22:07 +0000 Subject: [PATCH] Ingame summary screen and allied resource / population tooltips for active players. Patch by Imarok, also reviewed by fatherbushido and discussed with mimo, fixes #3841. Shows (only) the stats of the current player in the summary screen while playing. Also shows those of mutual allies too if the shared vision tech is researched. Display the resources and population counts of allies in the tooltips of the top panel. Use a sprintf for the pop / limit ratio and remove hardcoded resource strings in the XML, refs #3934. This was SVN commit r18533. --- binaries/data/mods/public/gui/session/menu.js | 9 ++++-- .../data/mods/public/gui/session/menu.xml | 1 - .../data/mods/public/gui/session/session.js | 32 +++++++++++++++---- .../gui/session/top_panel/resource_food.xml | 3 +- .../gui/session/top_panel/resource_metal.xml | 3 +- .../gui/session/top_panel/resource_stone.xml | 3 +- .../gui/session/top_panel/resource_wood.xml | 3 +- .../simulation/components/GuiInterface.js | 1 + .../public/simulation/components/Player.js | 5 +++ .../components/tests/test_GuiInterface.js | 6 ++++ 10 files changed, 48 insertions(+), 18 deletions(-) diff --git a/binaries/data/mods/public/gui/session/menu.js b/binaries/data/mods/public/gui/session/menu.js index f7db497dcc..494bd143b3 100644 --- a/binaries/data/mods/public/gui/session/menu.js +++ b/binaries/data/mods/public/gui/session/menu.js @@ -610,7 +610,10 @@ function toggleGameSpeed() let gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); gameSpeed.hidden = !gameSpeed.hidden; } - +/** + * Allows players to see their own summary. + * If they have shared ally vision researched, they are able to see the summary of there allies too. + */ function openGameSummary() { closeOpenDialogs(); @@ -620,7 +623,9 @@ function openGameSummary() Engine.PushGuiPage("page_summary.xml", { "sim": { "mapSettings": g_GameAttributes.settings, - "playerStates": extendedSimState.players, + "playerStates":extendedSimState.players.filter((state,player) => + g_IsObserver || player == 0 || player == g_ViewedPlayer || + extendedSimState.players[g_ViewedPlayer].hasSharedLos && g_Players[player].isMutualAlly[g_ViewedPlayer]), "timeElapsed" : extendedSimState.timeElapsed }, "gui": { diff --git a/binaries/data/mods/public/gui/session/menu.xml b/binaries/data/mods/public/gui/session/menu.xml index f9ce348403..5f50bb21fc 100644 --- a/binaries/data/mods/public/gui/session/menu.xml +++ b/binaries/data/mods/public/gui/session/menu.xml @@ -48,7 +48,6 @@ style="StoneButtonFancy" size="0 96 100% 124" tooltip_style="sessionToolTip" - enabled="false" > Summary openGameSummary(); diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index ff1421c6f1..245ff19335 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -483,7 +483,6 @@ function updateTopPanel() // Disable stuff observers shouldn't use Engine.GetGUIObjectByName("pauseButton").enabled = !g_IsObserver || !g_IsNetworked; Engine.GetGUIObjectByName("menuResignButton").enabled = !g_IsObserver; - Engine.GetGUIObjectByName("summaryButton").enabled = g_IsObserver; } function reportPerformance(time) @@ -936,19 +935,38 @@ function updateDebug() debug.caption = text.replace(/\[/g, "\\["); } +function getAllyStatTooltip(resource) +{ + let playersState = GetSimState().players; + let ret = ""; + for (let player in playersState) + if (player != 0 && player != g_ViewedPlayer && + (g_IsObserver || playersState[g_ViewedPlayer].hasSharedLos && g_Players[player].isMutualAlly[g_ViewedPlayer])) + ret += "\n" + sprintf(translate("%(playername)s: %(statValue)s"),{ + "playername": colorizePlayernameHelper("■", player) + " " + g_Players[player].name, + "statValue": resource == "pop" ? + sprintf(translate("%(popCount)s/%(popLimit)s/%(popMax)s"), playersState[player]) : + playersState[player].resourceCounts[resource] + }); + return ret; +} + function updatePlayerDisplay() { let playerState = GetSimState().players[g_ViewedPlayer]; if (!playerState) return; - Engine.GetGUIObjectByName("resourceFood").caption = Math.floor(playerState.resourceCounts.food); - Engine.GetGUIObjectByName("resourceWood").caption = Math.floor(playerState.resourceCounts.wood); - Engine.GetGUIObjectByName("resourceStone").caption = Math.floor(playerState.resourceCounts.stone); - Engine.GetGUIObjectByName("resourceMetal").caption = Math.floor(playerState.resourceCounts.metal); - Engine.GetGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; + for (let res of RESOURCES) + { + Engine.GetGUIObjectByName("resource_" + res).caption = Math.floor(playerState.resourceCounts[res]); + Engine.GetGUIObjectByName(res).tooltip = getLocalizedResourceName(res, "firstWord") + getAllyStatTooltip(res); + } + + Engine.GetGUIObjectByName("resourcePop").caption = sprintf(translate("%(popCount)s/%(popLimit)s"), playerState); Engine.GetGUIObjectByName("population").tooltip = translate("Population (current / limit)") + "\n" + - sprintf(translate("Maximum population: %(popCap)s"), { "popCap": playerState.popMax }); + sprintf(translate("Maximum population: %(popCap)s"), { "popCap": playerState.popMax }) + + getAllyStatTooltip("pop"); g_IsTrainingBlocked = playerState.trainingBlocked; } diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_food.xml b/binaries/data/mods/public/gui/session/top_panel/resource_food.xml index c3f49a4688..4d84ca7551 100644 --- a/binaries/data/mods/public/gui/session/top_panel/resource_food.xml +++ b/binaries/data/mods/public/gui/session/top_panel/resource_food.xml @@ -1,6 +1,5 @@ - Food - + diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_metal.xml b/binaries/data/mods/public/gui/session/top_panel/resource_metal.xml index 8dc01ecc93..4edba7939b 100644 --- a/binaries/data/mods/public/gui/session/top_panel/resource_metal.xml +++ b/binaries/data/mods/public/gui/session/top_panel/resource_metal.xml @@ -1,6 +1,5 @@ - Metal - + diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_stone.xml b/binaries/data/mods/public/gui/session/top_panel/resource_stone.xml index 37d08e39e9..6133acc30e 100644 --- a/binaries/data/mods/public/gui/session/top_panel/resource_stone.xml +++ b/binaries/data/mods/public/gui/session/top_panel/resource_stone.xml @@ -1,6 +1,5 @@ - Stone - + diff --git a/binaries/data/mods/public/gui/session/top_panel/resource_wood.xml b/binaries/data/mods/public/gui/session/top_panel/resource_wood.xml index 90558afb3b..f020979f33 100644 --- a/binaries/data/mods/public/gui/session/top_panel/resource_wood.xml +++ b/binaries/data/mods/public/gui/session/top_panel/resource_wood.xml @@ -1,6 +1,5 @@ - Wood - + diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index de6aebaf92..aaa7855580 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -107,6 +107,7 @@ GuiInterface.prototype.GetSimulationState = function() "cheatsEnabled": cmpPlayer.GetCheatsEnabled(), "disabledTemplates": cmpPlayer.GetDisabledTemplates(), "hasSharedDropsites": cmpPlayer.HasSharedDropsites(), + "hasSharedLos": cmpPlayer.HasSharedLos(), "phase": phase, "isAlly": allies, "isMutualAlly": mutualAllies, diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index 4f81bd6254..cb137ddd93 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -545,6 +545,11 @@ Player.prototype.HasStartingCamera = function() return this.startCam !== undefined; }; +Player.prototype.HasSharedLos = function() +{ + let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager); + return cmpTechnologyManager && cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech); +}; Player.prototype.HasSharedDropsites = function() { return this.sharedDropsites; diff --git a/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js b/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js index 2224a3f7a1..6ae026e645 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js @@ -91,6 +91,7 @@ AddMock(100, IID_Player, { IsEnemy: function() { return true; }, GetDisabledTemplates: function() { return {}; }, HasSharedDropsites: function() { return false; }, + HasSharedLos: function() { return false; }, }); AddMock(100, IID_EntityLimits, { @@ -174,6 +175,7 @@ AddMock(101, IID_Player, { IsEnemy: function() { return false; }, GetDisabledTemplates: function() { return {}; }, HasSharedDropsites: function() { return false; }, + HasSharedLos: function() { return false; }, }); AddMock(101, IID_EntityLimits, { @@ -257,6 +259,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), { cheatsEnabled: false, disabledTemplates: {}, hasSharedDropsites: false, + hasSharedLos: false, phase: "village", isAlly: [false, false], isMutualAlly: [false, false], @@ -298,6 +301,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), { cheatsEnabled: false, disabledTemplates: {}, hasSharedDropsites: false, + hasSharedLos: false, phase: "village", isAlly: [true, true], isMutualAlly: [false, false], @@ -348,6 +352,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), { cheatsEnabled: false, disabledTemplates: {}, hasSharedDropsites: false, + hasSharedLos: false, phase: "village", isAlly: [false, false], isMutualAlly: [false, false], @@ -402,6 +407,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), { cheatsEnabled: false, disabledTemplates: {}, hasSharedDropsites: false, + hasSharedLos: false, phase: "village", isAlly: [true, true], isMutualAlly: [false, false],