1
0
forked from 0ad/0ad

Add "chat" command.

Simplify deletion of multiple entities.
Simplify some setTimeouts.

This was SVN commit r8864.
This commit is contained in:
Ykkrosh 2011-01-12 12:21:41 +00:00
parent 23a3dfe755
commit 1051d10f54
3 changed files with 57 additions and 29 deletions

View File

@ -1007,10 +1007,9 @@ function performCommand(entity, commandName)
{
var message = "Are you sure you want to\ndelete the selected units?";
var deleteFunction = deleteFunction = function ()
var deleteFunction = function ()
{
for each (var ent in selection)
Engine.PostNetworkCommand({"type": "delete-entity", "entity": ent});
Engine.PostNetworkCommand({"type": "delete-entities", "entities": selection});
};
g_SessionDialog.open("Delete", message, null, 340, 160, deleteFunction);

View File

@ -15,17 +15,31 @@ function handleNotifications()
{
var notification = Engine.GuiInterfaceCall("GetNextNotification");
if (notification && notification.player == Engine.GetPlayerID())
if (!notification)
return;
// Handle chat notifications specially
if (notification.type == "chat")
{
var timerExpiredFunction = function () { removeOldNotifications(); }
addChatMessage({
"type": "message",
"guid": findGuidForPlayerID(g_PlayerAssignments, notification.player),
"text": notification.message
});
}
else
{
// Only display notifications directed to this player
if (notification.player == Engine.GetPlayerID())
{
notifications.push(notification);
notificationsTimers.push(setTimeout(removeOldNotifications, NOTIFICATION_TIMEOUT));
notifications.push(notification);
notificationsTimers.push(setTimeout(timerExpiredFunction, NOTIFICATION_TIMEOUT));
if (notifications.length > MAX_NUM_NOTIFICATION_LINES)
removeOldNotifications();
else
displayNotifications();
if (notifications.length > MAX_NUM_NOTIFICATION_LINES)
removeOldNotifications();
else
displayNotifications();
}
}
}
@ -144,9 +158,19 @@ function submitChatInput()
function addChatMessage(msg)
{
var n = g_PlayerAssignments[msg.guid].player;
var playerColor = g_Players[n].color.r + " " + g_Players[n].color.g + " " + g_Players[n].color.b;
var username = escapeText(g_PlayerAssignments[msg.guid].name);
var playerColor, username;
if (g_PlayerAssignments[msg.guid])
{
var n = g_PlayerAssignments[msg.guid].player;
playerColor = g_Players[n].color.r + " " + g_Players[n].color.g + " " + g_Players[n].color.b;
username = escapeText(g_PlayerAssignments[msg.guid].name);
}
else
{
playerColor = "255 255 255";
username = "Unknown player";
}
var message = escapeText(msg.text);
var formatted;
@ -165,10 +189,8 @@ function addChatMessage(msg)
return;
}
var timerExpiredFunction = function () { removeOldChatMessages(); }
chatMessages.push(formatted);
chatTimers.push(setTimeout(timerExpiredFunction, CHAT_TIMEOUT));
chatTimers.push(setTimeout(removeOldChatMessages, CHAT_TIMEOUT));
if (chatMessages.length > MAX_NUM_CHAT_LINES)
removeOldChatMessages();

View File

@ -11,6 +11,11 @@ function ProcessCommand(player, cmd)
print(cmd.message);
break;
case "chat":
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
cmpGuiInterface.PushNotification({"type": "chat", "player": player, "message": cmd.message});
break;
case "reveal-map":
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
cmpRangeManager.SetLosRevealAll(cmd.enable);
@ -139,18 +144,20 @@ function ProcessCommand(player, cmd)
break;
case "delete-entity":
// Verify the player owns the unit
var cmpOwnership = Engine.QueryInterface(cmd.entity, IID_Ownership);
if (!cmpOwnership || cmpOwnership.GetOwner() != player)
break;
var cmpHealth = Engine.QueryInterface(cmd.entity, IID_Health);
if (cmpHealth)
cmpHealth.Kill();
else
Engine.DestroyEntity(cmd.entity);
case "delete-entities":
for each (var ent in cmd.entities)
{
// Verify the player owns the unit
var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
if (!cmpOwnership || cmpOwnership.GetOwner() != player)
continue;
var cmpHealth = Engine.QueryInterface(ent, IID_Health);
if (cmpHealth)
cmpHealth.Kill();
else
Engine.DestroyEntity(ent);
}
break;
case "set-rallypoint":