From a2ecee41684fead030d81d5118fba97e054a17f5 Mon Sep 17 00:00:00 2001 From: elexis Date: Tue, 15 Mar 2016 04:08:07 +0000 Subject: [PATCH] Rest of the previous commit, refs #3743. This was SVN commit r17894. --- .../data/mods/public/gui/session/messages.js | 46 +++++++++++++++++++ .../data/mods/public/gui/session/selection.js | 6 +-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/binaries/data/mods/public/gui/session/messages.js b/binaries/data/mods/public/gui/session/messages.js index 1cbef58eb0..7eec0ef2fe 100644 --- a/binaries/data/mods/public/gui/session/messages.js +++ b/binaries/data/mods/public/gui/session/messages.js @@ -223,6 +223,16 @@ var g_NotificationsTypes = if (player != g_ViewedPlayer) return; + // Focus camera on attacks + if (g_FollowPlayer) + { + setCameraFollow(notification.target); + + g_Selection.reset(); + if (notification.target) + g_Selection.addList([notification.target]); + } + if (Engine.ConfigDB_GetValue("user", "gui.session.attacknotificationmessage") !== "true") return; @@ -243,6 +253,42 @@ var g_NotificationsTypes = if (player != Engine.GetPlayerID()) return; g_Selection.rebuildSelection({}); + }, + "playercommand": function(notification, player) + { + // For observers, focus the camera on units commanded by the selected player + if (!g_FollowPlayer || player != g_ViewedPlayer) + return; + + let cmd = notification.cmd; + + // Ignore boring animals + let entState = cmd.entities && cmd.entities[0] && GetEntityState(cmd.entities[0]); + if (entState && entState.identity && entState.identity.classes && + entState.identity.classes.indexOf("Animal") != -1) + return; + + // Focus the building to construct + if (cmd.type == "repair") + { + let targetState = GetEntityState(cmd.target); + if (targetState) + Engine.CameraMoveTo(targetState.position.x, targetState.position.z); + } + // Focus commanded entities, but don't lose previous focus when training units + else if (cmd.type != "train" && cmd.type != "research" && entState) + setCameraFollow(cmd.entities[0]); + + // Select units affected by that command + let selection = []; + if (cmd.entities) + selection = cmd.entities; + if (cmd.target) + selection.push(cmd.target); + + // Allow gaia in selection when gathering + g_Selection.reset(); + g_Selection.addList(selection, false, cmd.type == "gather"); } }; diff --git a/binaries/data/mods/public/gui/session/selection.js b/binaries/data/mods/public/gui/session/selection.js index bd8715a138..63ce20377d 100644 --- a/binaries/data/mods/public/gui/session/selection.js +++ b/binaries/data/mods/public/gui/session/selection.js @@ -288,13 +288,13 @@ EntitySelection.prototype.checkRenamedEntities = function() /** * Add entities to selection. Play selection sound unless quiet is true */ -EntitySelection.prototype.addList = function(ents, quiet) +EntitySelection.prototype.addList = function(ents, quiet, force = false) { let selection = this.toList(); // If someone else's player is the sole selected unit, don't allow adding to the selection let firstEntState = selection.length == 1 && GetEntityState(selection[0]); - if (firstEntState && firstEntState.player != g_ViewedPlayer) + if (firstEntState && firstEntState.player != g_ViewedPlayer && !force) return; let i = 1; @@ -316,7 +316,7 @@ EntitySelection.prototype.addList = function(ents, quiet) g_ViewedPlayer == -1 && entState.player == 0; // Don't add unowned entities to the list, unless a single entity was selected - if (isUnowned && (ents.length > 1 || selection.length)) + if (isUnowned && (ents.length > 1 || selection.length) && !force) continue; added.push(ent);