From 17e6b316fa28d993d72bffd8f21a40600fa82047 Mon Sep 17 00:00:00 2001 From: elexis Date: Wed, 2 Mar 2016 16:38:05 +0000 Subject: [PATCH] Diplomacy manager cleanup. Move the diplomatic stance button initialization to a custom function. Always hide the button if locked-teams is enabled, refs #3702. Inline setDiplomacy. This was SVN commit r17818. --- binaries/data/mods/public/gui/session/menu.js | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/binaries/data/mods/public/gui/session/menu.js b/binaries/data/mods/public/gui/session/menu.js index 7e1e67cb7f..19a790a1a2 100644 --- a/binaries/data/mods/public/gui/session/menu.js +++ b/binaries/data/mods/public/gui/session/menu.js @@ -258,11 +258,6 @@ function toggleChatWindow(teamChat) chatWindow.hidden = !hidden; } -function setDiplomacy(data) -{ - Engine.PostNetworkCommand({ "type": "diplomacy", "to": data.to, "player": data.player }); -} - function tributeResource(data) { Engine.PostNetworkCommand({ "type": "tribute", "player": data.player, "amounts": data.amounts }); @@ -306,6 +301,7 @@ function openDiplomacy() let playerInactive = isPlayerObserver(g_ViewedPlayer) || isPlayerObserver(i); let hasAllies = g_Players.filter(player => player.isMutualAlly[g_ViewedPlayer]).length > 1; + diplomacyFormatStanceButtons(i, myself || playerInactive || isCeasefireActive || g_Players[g_ViewedPlayer].teamsLocked); diplomacyFormatAttackRequestButton(i, myself || playerInactive || isCeasefireActive || !hasAllies || !g_Players[i].isEnemy[g_ViewedPlayer]); // Don't display the options for ourself, or if we or the other player aren't active anymore @@ -354,27 +350,28 @@ function openDiplomacy() button.hidden = false; button.tooltip = formatTributeTooltip(g_Players[i], resource, 100); } - - // Skip our own teams on teams locked - if (g_Players[g_ViewedPlayer].teamsLocked && g_Players[g_ViewedPlayer].team != -1 && g_Players[g_ViewedPlayer].team == g_Players[i].team) - continue; - - // Diplomacy settings - // Set up the buttons - for (let setting of ["Ally", "Neutral", "Enemy"]) - { - let button = Engine.GetGUIObjectByName("diplomacyPlayer"+setting+"["+(i-1)+"]"); - - button.caption = g_Players[g_ViewedPlayer]["is" + setting][i] ? translate("x") : ""; - button.onpress = (function(e){ return function() { setDiplomacy(e); }; })({ "player": i, "to": setting.toLowerCase() }); - button.enabled = controlsPlayer(g_ViewedPlayer); - button.hidden = isCeasefireActive; - } } Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = false; } +function diplomacyFormatStanceButtons(i, hidden) +{ + for (let stance of ["Ally", "Neutral", "Enemy"]) + { + let button = Engine.GetGUIObjectByName("diplomacyPlayer"+stance+"["+(i-1)+"]"); + button.hidden = hidden; + if (hidden) + continue; + + button.caption = g_Players[g_ViewedPlayer]["is" + stance][i] ? translate("x") : ""; + button.enabled = controlsPlayer(g_ViewedPlayer); + button.onpress = (function(player, stance) { return function() { + Engine.PostNetworkCommand({ "type": "diplomacy", "player": i, "to": stance.toLowerCase() }); + }; })(i, stance); + } +} + function diplomacyFormatAttackRequestButton(i, hidden) { let button = Engine.GetGUIObjectByName("diplomacyAttackRequest["+(i-1)+"]");