From 50bccd87204ea110bb58f269f71441eadd6f7ea1 Mon Sep 17 00:00:00 2001 From: WhiteTreePaladin Date: Sat, 14 Aug 2010 04:34:49 +0000 Subject: [PATCH] Made notifications visible only to the relevant player This was SVN commit r7942. --- .../mods/public/gui/session_new/messages.js | 29 +++++++++++------ .../mods/public/gui/session_new/session.js | 3 +- .../simulation/components/GuiInterface.js | 31 +++++++++---------- .../public/simulation/components/Player.js | 3 +- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/binaries/data/mods/public/gui/session_new/messages.js b/binaries/data/mods/public/gui/session_new/messages.js index c4f46ab31c..3810cbe82a 100644 --- a/binaries/data/mods/public/gui/session_new/messages.js +++ b/binaries/data/mods/public/gui/session_new/messages.js @@ -14,17 +14,18 @@ var notificationsTimers = []; function handleNotifications() { var notification = Engine.GuiInterfaceCall("PopNotification"); - var timerExpiredFunction = function () { removeOldNotifications(); } - if (notification) + if (notification && notification.player == Engine.GetPlayerID()) { + var timerExpiredFunction = function () { removeOldNotifications(); } + notifications.push(notification); notificationsTimers.push(setTimeout(timerExpiredFunction, NOTIFICATION_TIMEOUT)); - if (notifications.length <= MAX_NUM_NOTIFICATION_LINES) - getGUIObjectByName("notificationText").caption = notifications.join("\n"); - else + if (notifications.length > MAX_NUM_NOTIFICATION_LINES) removeOldNotifications(); + else + displayNotifications(); } } @@ -33,7 +34,15 @@ function removeOldNotifications() clearTimeout(notificationsTimers[0]); // The timer only needs to be cleared when new notifications bump old notifications off notificationsTimers.shift(); notifications.shift(); - getGUIObjectByName("notificationText").caption = notifications.join("\n"); + displayNotifications(); +} + +function displayNotifications() +{ + var messages = []; + for each (var n in notifications) + messages.push(n.message); + getGUIObjectByName("notificationText").caption = messages.join("\n"); } //Messages @@ -111,6 +120,8 @@ function addChatMessage(msg) // TODO: we ought to escape all values before displaying them, // to prevent people inserting colours and newlines etc + //var n = msg.player; + //var playerColor = g_Players[n].color.r + " " + g_Players[n].color.g + " " + g_Players[n].color.b; var playerColor = getColorByPlayerName(msg.username); var formatted; @@ -135,10 +146,10 @@ function addChatMessage(msg) chatMessages.push(formatted); chatTimers.push(setTimeout(timerExpiredFunction, CHAT_TIMEOUT)); - if (chatMessages.length <= MAX_NUM_CHAT_LINES) - getGUIObjectByName("chatText").caption = chatMessages.join("\n"); - else + if (chatMessages.length > MAX_NUM_CHAT_LINES) removeOldChatMessages(); + else + getGUIObjectByName("chatText").caption = chatMessages.join("\n"); } function removeOldChatMessages() diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js index 550fbea389..5ceb8ec9f0 100644 --- a/binaries/data/mods/public/gui/session_new/session.js +++ b/binaries/data/mods/public/gui/session_new/session.js @@ -24,6 +24,7 @@ var g_IsNetworked = false; // Cache the basic player data (name, civ, color) var g_Players = []; var g_PlayerAssignments = {}; +var g_PlayerID; // Cache dev-mode settings that are frequently or widely used var g_DevSettings = { @@ -52,7 +53,7 @@ function init(initData, hotloadData) { g_Players = getPlayerData(null); } - + cacheMenuObjects(); onSimulationUpdate(); diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 5d732c45fa..4eff07ef41 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -17,21 +17,6 @@ GuiInterface.prototype.Init = function() this.rallyPoints = undefined; }; -GuiInterface.prototype.PushNotification = function(notification) -{ - this.notifications.push(notification); -}; - -GuiInterface.prototype.PopNotification = function() -{ - //warn(uneval(this.notifications)); - - if (this.notifications.length) - return this.notifications.pop(); - else - return ""; -}; - GuiInterface.prototype.GetSimulationState = function(player) { var ret = { @@ -191,6 +176,19 @@ GuiInterface.prototype.GetTemplateData = function(player, name) return ret; }; +GuiInterface.prototype.PushNotification = function(notification) +{ + this.notifications.push(notification); +}; + +GuiInterface.prototype.PopNotification = function() +{ + if (this.notifications.length) + return this.notifications.pop(); + else + return ""; +}; + GuiInterface.prototype.SetSelectionHighlight = function(player, cmd) { var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); @@ -385,10 +383,11 @@ GuiInterface.prototype.SetRangeDebugOverlay = function(player, enabled) // trusted and indicates the player associated with the current client; no data should // be returned unless this player is meant to be able to see it.) var exposedFunctions = { - "PopNotification": 1, + "GetSimulationState": 1, "GetEntityState": 1, "GetTemplateData": 1, + "PopNotification": 1, "SetSelectionHighlight": 1, "DisplayRallyPoint": 1, diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index eb6ac278f7..d543211f41 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -95,8 +95,9 @@ Player.prototype.TrySubtractResources = function(amounts) // If we don't have enough resources, send a notification to the player if (formattedAmountsNeeded.length) { + var notification = {"player": this.playerID, "message": "Resources needed: " + formattedAmountsNeeded.join(", ")}; var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); - cmpGUIInterface.PushNotification("Resources needed: " + formattedAmountsNeeded.join(", ")); + cmpGUIInterface.PushNotification(notification); return false; } else