Add "chat" command.
Simplify deletion of multiple entities. Simplify some setTimeouts. This was SVN commit r8864.
This commit is contained in:
parent
23a3dfe755
commit
1051d10f54
@ -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);
|
||||
|
@ -15,18 +15,32 @@ function handleNotifications()
|
||||
{
|
||||
var notification = Engine.GuiInterfaceCall("GetNextNotification");
|
||||
|
||||
if (notification && notification.player == Engine.GetPlayerID())
|
||||
{
|
||||
var timerExpiredFunction = function () { removeOldNotifications(); }
|
||||
if (!notification)
|
||||
return;
|
||||
|
||||
// Handle chat notifications specially
|
||||
if (notification.type == "chat")
|
||||
{
|
||||
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(timerExpiredFunction, NOTIFICATION_TIMEOUT));
|
||||
notificationsTimers.push(setTimeout(removeOldNotifications, NOTIFICATION_TIMEOUT));
|
||||
|
||||
if (notifications.length > MAX_NUM_NOTIFICATION_LINES)
|
||||
removeOldNotifications();
|
||||
else
|
||||
displayNotifications();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeOldNotifications()
|
||||
@ -144,9 +158,19 @@ function submitChatInput()
|
||||
|
||||
function addChatMessage(msg)
|
||||
{
|
||||
var playerColor, username;
|
||||
if (g_PlayerAssignments[msg.guid])
|
||||
{
|
||||
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);
|
||||
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();
|
||||
|
@ -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":
|
||||
case "delete-entities":
|
||||
for each (var ent in cmd.entities)
|
||||
{
|
||||
// Verify the player owns the unit
|
||||
var cmpOwnership = Engine.QueryInterface(cmd.entity, IID_Ownership);
|
||||
var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
|
||||
if (!cmpOwnership || cmpOwnership.GetOwner() != player)
|
||||
break;
|
||||
continue;
|
||||
|
||||
var cmpHealth = Engine.QueryInterface(cmd.entity, IID_Health);
|
||||
var cmpHealth = Engine.QueryInterface(ent, IID_Health);
|
||||
if (cmpHealth)
|
||||
cmpHealth.Kill();
|
||||
else
|
||||
Engine.DestroyEntity(cmd.entity);
|
||||
|
||||
Engine.DestroyEntity(ent);
|
||||
}
|
||||
break;
|
||||
|
||||
case "set-rallypoint":
|
||||
|
Loading…
Reference in New Issue
Block a user