Ticket #3743: t3743_automatic_camera_controls.patch

File t3743_automatic_camera_controls.patch, 7.7 KB (added by elexis, 8 years ago)
  • binaries/data/mods/public/gui/session/messages.js

    var g_NotificationsTypes =  
    221221    "attack": function(notification, player)
    222222    {
    223223        if (player != g_ViewedPlayer)
    224224            return;
    225225
     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
    226236        if (Engine.ConfigDB_GetValue("user", "gui.session.attacknotificationmessage") !== "true")
    227237            return;
    228238
    229239        addChatMessage({
    230240            "type": "attack",
     241            "target": notification.target,
    231242            "player": player,
    232243            "attacker": notification.attacker,
    233244            "targetIsDomesticAnimal": notification.targetIsDomesticAnimal
    234245        });
    235246    },
    var g_NotificationsTypes =  
    241252    "resetselectionpannel": function(notification, player)
    242253    {
    243254        if (player != Engine.GetPlayerID())
    244255            return;
    245256        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");
    246291    }
    247292};
    248293
    249294/**
    250295 * Loads all known cheat commands.
  • binaries/data/mods/public/gui/session/selection.js

    EntitySelection.prototype.checkRenamedEn  
    286286};
    287287
    288288/**
    289289 * Add entities to selection. Play selection sound unless quiet is true
    290290 */
    291 EntitySelection.prototype.addList = function(ents, quiet)
     291EntitySelection.prototype.addList = function(ents, quiet, force = false)
    292292{
    293293    let selection = this.toList();
    294294
    295295    // If someone else's player is the sole selected unit, don't allow adding to the selection
    296296    let firstEntState = selection.length == 1 && GetEntityState(selection[0]);
    297     if (firstEntState && firstEntState.player != g_ViewedPlayer)
     297    if (firstEntState && firstEntState.player != g_ViewedPlayer && !force)
    298298        return;
    299299
    300300    let i = 1;
    301301    let added = [];
    302302
    EntitySelection.prototype.addList = func  
    314314
    315315        let isUnowned = g_ViewedPlayer != -1 && entState.player != g_ViewedPlayer ||
    316316                        g_ViewedPlayer == -1 && entState.player == 0;
    317317
    318318        // 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)
    320320            continue;
    321321
    322322        added.push(ent);
    323323        this.selected[ent] = ent;
    324324        ++i;
  • binaries/data/mods/public/gui/session/session.js

    var g_IsObserver = false;  
    3636 * The playerID selected in the change perspective tool.
    3737 */
    3838var g_ViewedPlayer = Engine.GetPlayerID();
    3939
    4040/**
     41 * True if the camera should focus on attacks and player commands
     42 * and select the affected units.
     43 */
     44var g_FollowPlayer = false;
     45
     46/**
    4147 * Unique ID for lobby reports.
    4248 */
    4349var g_MatchID;
    4450
    4551/**
    function selectViewPlayer(playerID)  
    326332
    327333    let alphaLabel = Engine.GetGUIObjectByName("alphaLabel");
    328334    alphaLabel.hidden = g_ViewedPlayer > 0 && !viewPlayer.hidden;
    329335    alphaLabel.size = g_ViewedPlayer > 0 ? "50%+20 0 100%-226 100%" : "200 0 100%-475 100%";
    330336
     337    Engine.GetGUIObjectByName("optionFollowPlayer").hidden = !g_IsObserver || g_ViewedPlayer < 1;
     338
    331339    if (g_IsDiplomacyOpen)
    332340        openDiplomacy();
    333341
    334342    if (g_IsTradeOpen)
    335343        openTrade();
  • binaries/data/mods/public/gui/session/top_panel.xml

     
    55    size="-3 0 100%+3 36"
    66>
    77    <!-- most elements are defined in this directory -->
    88    <include directory="gui/session/top_panel/"/>
    99
     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
    1024    <!-- ================================  ================================ -->
    1125    <!-- Some development features -->
    1226    <!-- ================================  ================================ -->
    1327
    1428    <!-- ================================  ================================ -->
  • binaries/data/mods/public/simulation/components/AttackDetection.js

    AttackDetection.prototype.AttackAlert =  
    118118        this.AddSuppression(event);
    119119
    120120    Engine.PostMessage(this.entity, MT_AttackDetected, { "player": cmpPlayer.GetPlayerID(), "event": event });
    121121    Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).PushNotification({
    122122        "type": "attack",
     123        "target": target,
    123124        "players": [cmpPlayer.GetPlayerID()],
    124125        "attacker": cmpAttackerOwnership.GetOwner(),
    125126        "targetIsDomesticAnimal": targetIsDomesticAnimal
    126127    });
    127128    PlaySound("attacked", target);
  • binaries/data/mods/public/simulation/helpers/Commands.js

    function ProcessCommand(player, cmd)  
    2121    data.controlAllUnits = data.cmpPlayer.CanControlAllUnits();
    2222
    2323    if (cmd.entities)
    2424        data.entities = FilterEntityList(cmd.entities, player, data.controlAllUnits);
    2525
     26    let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     27    cmpGuiInterface.PushNotification({
     28        "type": "playercommand",
     29        "players": [player],
     30        "cmd": cmd
     31    });
     32
    2633    // Note: checks of UnitAI targets are not robust enough here, as ownership
    2734    //  can change after the order is issued, they should be checked by UnitAI
    2835    //  when the specific behavior (e.g. attack, garrison) is performed.
    2936    // (Also it's not ideal if a command silently fails, it's nicer if UnitAI
    3037    //  moves the entities closer to the target before giving up.)