Ticket #3743: t3743_automatic_camera_controls.patch
File t3743_automatic_camera_controls.patch, 7.7 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/session/messages.js
var g_NotificationsTypes = 221 221 "attack": function(notification, player) 222 222 { 223 223 if (player != g_ViewedPlayer) 224 224 return; 225 225 226 // Focus camera on attacks 227 if (g_FollowPlayer) 228 { 229 setCameraFollow(notification.target); 230 231 g_Selection.reset(); 232 if (notification.target) 233 g_Selection.addList([notification.target]); 234 } 235 226 236 if (Engine.ConfigDB_GetValue("user", "gui.session.attacknotificationmessage") !== "true") 227 237 return; 228 238 229 239 addChatMessage({ 230 240 "type": "attack", 241 "target": notification.target, 231 242 "player": player, 232 243 "attacker": notification.attacker, 233 244 "targetIsDomesticAnimal": notification.targetIsDomesticAnimal 234 245 }); 235 246 }, … … var g_NotificationsTypes = 241 252 "resetselectionpannel": function(notification, player) 242 253 { 243 254 if (player != Engine.GetPlayerID()) 244 255 return; 245 256 g_Selection.rebuildSelection({}); 257 }, 258 "playercommand": function(notification, player) 259 { 260 if (!g_FollowPlayer || player != g_ViewedPlayer) 261 return; 262 263 let cmd = notification.cmd; 264 265 // Ignore boring animals 266 let entState = cmd.entities && cmd.entities[0] && GetEntityState(cmd.entities[0]); 267 if (entState && entState.identity && entState.identity.classes.indexOf("Animal") != -1) 268 return; 269 270 // Focus the building to construct 271 if (cmd.type == "repair") 272 { 273 let targetState = GetEntityState(cmd.target); 274 if (targetState) 275 Engine.CameraMoveTo(targetState.position.x, targetState.position.z); 276 } 277 // Focus commanded entities, but don't lose previous focus when training units 278 else if (cmd.type != "train" && cmd.type != "research" && entState) 279 setCameraFollow(cmd.entities[0]); 280 281 // Select units affected by that command 282 let selection = []; 283 if (cmd.entities) 284 selection = cmd.entities; 285 if (cmd.target) 286 selection.push(cmd.target); 287 288 // Allow gaia in selection when gathering 289 g_Selection.reset(); 290 g_Selection.addList(selection, false, cmd.type == "gather"); 246 291 } 247 292 }; 248 293 249 294 /** 250 295 * Loads all known cheat commands. -
binaries/data/mods/public/gui/session/selection.js
EntitySelection.prototype.checkRenamedEn 286 286 }; 287 287 288 288 /** 289 289 * Add entities to selection. Play selection sound unless quiet is true 290 290 */ 291 EntitySelection.prototype.addList = function(ents, quiet )291 EntitySelection.prototype.addList = function(ents, quiet, force = false) 292 292 { 293 293 let selection = this.toList(); 294 294 295 295 // If someone else's player is the sole selected unit, don't allow adding to the selection 296 296 let firstEntState = selection.length == 1 && GetEntityState(selection[0]); 297 if (firstEntState && firstEntState.player != g_ViewedPlayer )297 if (firstEntState && firstEntState.player != g_ViewedPlayer && !force) 298 298 return; 299 299 300 300 let i = 1; 301 301 let added = []; 302 302 … … EntitySelection.prototype.addList = func 314 314 315 315 let isUnowned = g_ViewedPlayer != -1 && entState.player != g_ViewedPlayer || 316 316 g_ViewedPlayer == -1 && entState.player == 0; 317 317 318 318 // Don't add unowned entities to the list, unless a single entity was selected 319 if (isUnowned && (ents.length > 1 || selection.length) )319 if (isUnowned && (ents.length > 1 || selection.length) && !force) 320 320 continue; 321 321 322 322 added.push(ent); 323 323 this.selected[ent] = ent; 324 324 ++i; -
binaries/data/mods/public/gui/session/session.js
var g_IsObserver = false; 36 36 * The playerID selected in the change perspective tool. 37 37 */ 38 38 var g_ViewedPlayer = Engine.GetPlayerID(); 39 39 40 40 /** 41 * True if the camera should focus on attacks and player commands 42 * and select the affected units. 43 */ 44 var g_FollowPlayer = false; 45 46 /** 41 47 * Unique ID for lobby reports. 42 48 */ 43 49 var g_MatchID; 44 50 45 51 /** … … function selectViewPlayer(playerID) 326 332 327 333 let alphaLabel = Engine.GetGUIObjectByName("alphaLabel"); 328 334 alphaLabel.hidden = g_ViewedPlayer > 0 && !viewPlayer.hidden; 329 335 alphaLabel.size = g_ViewedPlayer > 0 ? "50%+20 0 100%-226 100%" : "200 0 100%-475 100%"; 330 336 337 Engine.GetGUIObjectByName("optionFollowPlayer").hidden = !g_IsObserver || g_ViewedPlayer < 1; 338 331 339 if (g_IsDiplomacyOpen) 332 340 openDiplomacy(); 333 341 334 342 if (g_IsTradeOpen) 335 343 openTrade(); -
binaries/data/mods/public/gui/session/top_panel.xml
5 5 size="-3 0 100%+3 36" 6 6 > 7 7 <!-- most elements are defined in this directory --> 8 8 <include directory="gui/session/top_panel/"/> 9 9 10 <!-- Follow Player Option --> 11 <object name="optionFollowPlayer" size="50%+64 4 50%+256 100%" hidden="true"> 12 13 <!-- Checkbox --> 14 <object name="followPlayer" type="checkbox" checked="false" style="ModernTickBox" size="0 4 20 100%" font="sans-bold-13"> 15 <action on="Press">g_FollowPlayer = !g_FollowPlayer;</action> 16 </object> 17 18 <!-- Label --> 19 <object type="text" size="20 2 100% 100%" text_align="left" textcolor="white"> 20 <translatableAttribute id="caption">Follow Player</translatableAttribute> 21 </object> 22 </object> 23 10 24 <!-- ================================ ================================ --> 11 25 <!-- Some development features --> 12 26 <!-- ================================ ================================ --> 13 27 14 28 <!-- ================================ ================================ --> -
binaries/data/mods/public/simulation/components/AttackDetection.js
AttackDetection.prototype.AttackAlert = 118 118 this.AddSuppression(event); 119 119 120 120 Engine.PostMessage(this.entity, MT_AttackDetected, { "player": cmpPlayer.GetPlayerID(), "event": event }); 121 121 Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).PushNotification({ 122 122 "type": "attack", 123 "target": target, 123 124 "players": [cmpPlayer.GetPlayerID()], 124 125 "attacker": cmpAttackerOwnership.GetOwner(), 125 126 "targetIsDomesticAnimal": targetIsDomesticAnimal 126 127 }); 127 128 PlaySound("attacked", target); -
binaries/data/mods/public/simulation/helpers/Commands.js
function ProcessCommand(player, cmd) 21 21 data.controlAllUnits = data.cmpPlayer.CanControlAllUnits(); 22 22 23 23 if (cmd.entities) 24 24 data.entities = FilterEntityList(cmd.entities, player, data.controlAllUnits); 25 25 26 let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 27 cmpGuiInterface.PushNotification({ 28 "type": "playercommand", 29 "players": [player], 30 "cmd": cmd 31 }); 32 26 33 // Note: checks of UnitAI targets are not robust enough here, as ownership 27 34 // can change after the order is issued, they should be checked by UnitAI 28 35 // when the specific behavior (e.g. attack, garrison) is performed. 29 36 // (Also it's not ideal if a command silently fails, it's nicer if UnitAI 30 37 // moves the entities closer to the target before giving up.)