Made notifications visible only to the relevant player

This was SVN commit r7942.
This commit is contained in:
WhiteTreePaladin 2010-08-14 04:34:49 +00:00
parent f221caecda
commit 50bccd8720
4 changed files with 39 additions and 27 deletions

View File

@ -14,17 +14,18 @@ var notificationsTimers = [];
function handleNotifications()
{
var notification = Engine.GuiInterfaceCall("PopNotification");
if (notification && notification.player == Engine.GetPlayerID())
{
var timerExpiredFunction = function () { removeOldNotifications(); }
if (notification)
{
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()

View File

@ -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 = {

View File

@ -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,

View File

@ -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