From 573d47d9a91c7a44a455eb87beb9679e20a0fc2c Mon Sep 17 00:00:00 2001 From: leper Date: Wed, 19 Dec 2012 20:19:54 +0000 Subject: [PATCH] Disable diplomacy settings when player is defeated. Fixes #1764. This was SVN commit r13000. --- binaries/data/mods/public/gui/session/menu.js | 104 ++++++++++-------- .../data/mods/public/gui/session/messages.js | 4 + .../public/simulation/components/Player.js | 10 +- 3 files changed, 69 insertions(+), 49 deletions(-) diff --git a/binaries/data/mods/public/gui/session/menu.js b/binaries/data/mods/public/gui/session/menu.js index fa15054ffb..4bbd7fe4fb 100644 --- a/binaries/data/mods/public/gui/session/menu.js +++ b/binaries/data/mods/public/gui/session/menu.js @@ -255,59 +255,67 @@ function openDiplomacy() getGUIObjectByName("diplomacyPlayerTeam["+(i-1)+"]").caption = (players[i].team < 0) ? "None" : players[i].team+1; - // Don't display this for ourself and our locked team members - if (i != we && !(players[we].teamsLocked && players[we].team != -1 && players[we].team == players[i].team)) - { + if (i != we) getGUIObjectByName("diplomacyPlayerTheirs["+(i-1)+"]").caption = (players[i].isAlly[we] ? "Ally" : (players[i].isNeutral[we] ? "Neutral" : "Enemy")); - // Set up the buttons - for each (var setting in ["ally", "neutral", "enemy"]) - { - var button = getGUIObjectByName("diplomacyPlayer"+toTitleCase(setting)+"["+(i-1)+"]"); - - if (setting == "ally") - { - if (players[we].isAlly[i]) - button.caption = "x"; - else - button.caption = ""; - } - else if (setting == "neutral") - { - if (players[we].isNeutral[i]) - button.caption = "x"; - else - button.caption = ""; - } - else // "enemy" - { - if (players[we].isEnemy[i]) - button.caption = "x"; - else - button.caption = ""; - } - - button.onpress = (function(e){ return function() { setDiplomacy(e) } })({"player": i, "to": setting}); - button.hidden = false; - } - } - - // Tributes (you can't tribute to yourself) - if (i != we) + // Don't display the options for ourself, or if we or the other player aren't active anymore + if (i == we || players[we].state != "active" || players[i].state != "active") { - for each (var resource in ["food", "wood", "stone", "metal"]) + // Hide the unused/unselectable options + for each (var a in ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"]) + getGUIObjectByName("diplomacyPlayer"+a+"["+(i-1)+"]").hidden = true; + continue; + } + + // Tribute + for each (var resource in ["food", "wood", "stone", "metal"]) + { + var button = getGUIObjectByName("diplomacyPlayerTribute"+toTitleCase(resource)+"["+(i-1)+"]"); + // TODO: Make amounts changeable or change to 500 if shift is pressed + var amounts = { + "food": (resource=="food")?100:0, + "wood": (resource=="wood")?100:0, + "stone": (resource=="stone")?100:0, + "metal": (resource=="metal")?100:0, + }; + button.onpress = (function(e){ return function() { tributeResource(e) } })({"player": i, "amounts": amounts}); + button.hidden = false; + } + + // Skip our own teams on teams locked + if (players[we].teamsLocked && players[we].team != -1 && players[we].team == players[i].team) + continue; + + // Diplomacy settings + // Set up the buttons + for each (var setting in ["ally", "neutral", "enemy"]) + { + var button = getGUIObjectByName("diplomacyPlayer"+toTitleCase(setting)+"["+(i-1)+"]"); + + if (setting == "ally") { - var button = getGUIObjectByName("diplomacyPlayerTribute"+toTitleCase(resource)+"["+(i-1)+"]"); - // TODO: Make amounts changeable or change to 500 if shift is pressed - var amounts = { - "food": (resource=="food")?100:0, - "wood": (resource=="wood")?100:0, - "stone": (resource=="stone")?100:0, - "metal": (resource=="metal")?100:0, - }; - button.onpress = (function(e){ return function() { tributeResource(e) } })({"player": i, "amounts": amounts}); - button.hidden = false; + if (players[we].isAlly[i]) + button.caption = "x"; + else + button.caption = ""; } + else if (setting == "neutral") + { + if (players[we].isNeutral[i]) + button.caption = "x"; + else + button.caption = ""; + } + else // "enemy" + { + if (players[we].isEnemy[i]) + button.caption = "x"; + else + button.caption = ""; + } + + button.onpress = (function(e){ return function() { setDiplomacy(e) } })({"player": i, "to": setting}); + button.hidden = false; } } diff --git a/binaries/data/mods/public/gui/session/messages.js b/binaries/data/mods/public/gui/session/messages.js index 982c61e7fb..c88225dd56 100644 --- a/binaries/data/mods/public/gui/session/messages.js +++ b/binaries/data/mods/public/gui/session/messages.js @@ -35,6 +35,10 @@ function handleNotifications() "guid": findGuidForPlayerID(g_PlayerAssignments, notification.player), "player": notification.player }); + + // If the diplomacy panel is open refresh it. + if (isDiplomacyOpen) + openDiplomacy(); } else if (notification.type == "diplomacy") { diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index 67c6606278..3516ce56ad 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -285,6 +285,9 @@ Player.prototype.SetDiplomacyIndex = function(idx, value) if (!cmpPlayer) return; + if (this.state != "active" || cmpPlayer.state != "active") + return; + // You can have alliances with other players, if (this.teamsLocked) { @@ -528,8 +531,13 @@ Player.prototype.TributeResource = function(player, amounts) return; var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(player), IID_Player); + if (!cmpPlayer) + return; - if (cmpPlayer && !this.GetNeededResources(amounts)) + if (this.state != "active" || cmpPlayer.state != "active") + return; + + if (!this.GetNeededResources(amounts)) { for (var type in amounts) this.resourceCount[type] -= amounts[type];