Ticket #3215: t3215_fix_observer_statusbars_v2.patch

File t3215_fix_observer_statusbars_v2.patch, 16.8 KB (added by elexis, 9 years ago)
  • binaries/data/mods/public/gui/session/input.js

     
    158158    else if (placementSupport.mode === "wall")
    159159    {
    160160        if (placementSupport.wallSet && placementSupport.position)
    161161        {
    162162            // Fetch an updated list of snapping candidate entities
    163             placementSupport.wallSnapEntities = Engine.PickSimilarFriendlyEntities(
     163            placementSupport.wallSnapEntities = Engine.PickSimilarPlayerEntities(
    164164                placementSupport.wallSet.templates.tower,
    165165                placementSupport.wallSnapEntitiesIncludeOffscreen,
    166166                true, // require exact template match
    167167                true  // include foundations
    168168            );
     
    548548        switch (ev.type)
    549549        {
    550550        case "mousemotion":
    551551            var rect = updateBandbox(bandbox, ev, false);
    552552
    553             var ents = Engine.PickFriendlyEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID());
     553            var ents = Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID());
    554554            var preferredEntities = getPreferredEntities(ents);
    555555            g_Selection.setHighlightList(preferredEntities);
    556556
    557557            return false;
    558558
     
    560560            if (ev.button == SDL_BUTTON_LEFT)
    561561            {
    562562                var rect = updateBandbox(bandbox, ev, true);
    563563
    564564                // Get list of entities limited to preferred entities
    565                 var ents = getPreferredEntities(Engine.PickFriendlyEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID()));
     565                var ents = getPreferredEntities(Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID()));
    566566
    567567                // Remove the bandbox hover highlighting
    568568                g_Selection.setHighlightList([]);
    569569
    570570                // Update the list of selected units
     
    10421042                        // Select units matching exact template name (same rank)
    10431043                        templateToMatch = GetEntityState(selectedEntity).template;
    10441044                    }
    10451045
    10461046                    // TODO: Should we handle "control all units" here as well?
    1047                     ents = Engine.PickSimilarFriendlyEntities(templateToMatch, showOffscreen, matchRank, false);
     1047                    ents = Engine.PickSimilarPlayerEntities(templateToMatch, showOffscreen, matchRank, false);
    10481048                }
    10491049                else
    10501050                {
    10511051                    // It's single click right now but it may become double or triple click
    10521052                    doubleClicked = false;
  • binaries/data/mods/public/gui/session/session.js

     
    810810
    811811// Toggles the display of status bars for all of the player's entities.
    812812function recalculateStatusBarDisplay()
    813813{
    814814    if (g_ShowAllStatusBars)
    815         var entities = Engine.PickFriendlyEntitiesOnScreen(Engine.GetPlayerID());
     815        var entities = g_IsObserver ? Engine.PickAllPlayersEntitiesOnScreen() : Engine.PickPlayerEntitiesOnScreen(Engine.GetPlayerID());
    816816    else
    817817    {
    818818        var selected = g_Selection.toList();
    819819        for each (var ent in g_Selection.highlighted)
    820820            selected.push(ent);
    821 
     821       
    822822        // Remove selected entities from the 'all entities' array, to avoid disabling their status bars.
    823         var entities = Engine.GuiInterfaceCall("GetPlayerEntities").filter(
    824                 function(idx) { return (selected.indexOf(idx) == -1); }
    825         );
     823        var entities = Engine.GuiInterfaceCall(g_IsObserver ? "GetAllPlayerEntities" : "GetPlayerEntities").filter(idx => selected.indexOf(idx) == -1);
    826824    }
    827825
    828826    Engine.GuiInterfaceCall("SetStatusBars", { "entities": entities, "enabled": g_ShowAllStatusBars });
    829827}
    830 
    831828// Update the additional list of entities to be highlighted.
    832829function updateAdditionalHighlight()
    833830{
    834831    var entsAdd = [];    // list of entities units to be highlighted
    835832    var entsRemove = [];
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    893893{
    894894    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    895895    return cmpRangeManager.GetEntitiesByPlayer(player);
    896896};
    897897
     898GuiInterface.prototype.GetAllPlayerEntities = function(player)
     899{
     900    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     901    return cmpRangeManager.GetAllPlayerEntities(player);
     902};
     903
    898904/**
    899905 * Displays the rally points of a given list of entities (carried in cmd.entities).
    900906 *
    901907 * The 'cmd' object may carry its own x/z coordinate pair indicating the location where the rally point should
    902908 * be rendered, in order to support instantaneously rendering a rally point marker at a specified location
     
    18891895
    18901896    "SetSelectionHighlight": 1,
    18911897    "GetAllBuildableEntities": 1,
    18921898    "SetStatusBars": 1,
    18931899    "GetPlayerEntities": 1,
     1900    "GetAllPlayerEntities": 1,
    18941901    "DisplayRallyPoint": 1,
    18951902    "SetBuildingPlacementPreview": 1,
    18961903    "SetWallPlacementPreview": 1,
    18971904    "GetFoundationSnapData": 1,
    18981905    "PlaySound": 1,
  • source/gui/scripting/ScriptFunctions.cpp

     
    5959#include "renderer/scripting/JSInterface_Renderer.h"
    6060#include "simulation2/Simulation2.h"
    6161#include "simulation2/components/ICmpAIManager.h"
    6262#include "simulation2/components/ICmpCommandQueue.h"
    6363#include "simulation2/components/ICmpGuiInterface.h"
     64#include "simulation2/components/ICmpPlayerManager.h"
    6465#include "simulation2/components/ICmpRangeManager.h"
    6566#include "simulation2/components/ICmpSelectable.h"
    6667#include "simulation2/components/ICmpTemplateManager.h"
    6768#include "simulation2/helpers/Selection.h"
    6869#include "soundmanager/SoundManager.h"
     
    151152entity_id_t PickEntityAtPoint(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x, int y)
    152153{
    153154    return EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, g_Game->GetPlayerID(), false);
    154155}
    155156
    156 std::vector<entity_id_t> PickFriendlyEntitiesInRect(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x0, int y0, int x1, int y1, int player)
     157std::vector<entity_id_t> PickPlayerEntitiesInRect(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x0, int y0, int x1, int y1, int player)
    157158{
    158159    return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, player, false);
    159160}
    160161
    161 std::vector<entity_id_t> PickFriendlyEntitiesOnScreen(ScriptInterface::CxPrivate* pCxPrivate, int player)
     162std::vector<entity_id_t> PickPlayerEntitiesOnScreen(ScriptInterface::CxPrivate* pCxPrivate, int player)
    162163{
    163     return PickFriendlyEntitiesInRect(pCxPrivate, 0, 0, g_xres, g_yres, player);
     164    return PickPlayerEntitiesInRect(pCxPrivate, 0, 0, g_xres, g_yres, player);
    164165}
    165166
    166 std::vector<entity_id_t> PickSimilarFriendlyEntities(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string templateName, bool includeOffScreen, bool matchRank, bool allowFoundations)
     167std::vector<entity_id_t> PickAllPlayersEntitiesOnScreen(ScriptInterface::CxPrivate* pCxPrivate)
     168{
     169    std::vector<entity_id_t> entities;
     170
     171    CmpPtr<ICmpPlayerManager> cmpPlayerManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
     172
     173    if (!cmpPlayerManager)
     174        return entities;
     175
     176    i32 numPlayers = cmpPlayerManager->GetNumPlayers();
     177    for (i32 player = 1; player < numPlayers; ++player)
     178    {
     179        std::vector<entity_id_t> ents = PickPlayerEntitiesOnScreen(pCxPrivate, player);
     180        entities.insert(entities.end(), ents.begin(), ents.end());
     181    }
     182    return entities;
     183}
     184
     185std::vector<entity_id_t> PickSimilarPlayerEntities(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string templateName, bool includeOffScreen, bool matchRank, bool allowFoundations)
    167186{
    168187    return EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, g_Game->GetPlayerID(), includeOffScreen, matchRank, false, allowFoundations);
    169188}
    170189
    171190CFixedVector3D GetTerrainAtScreenPoint(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x, int y)
     
    942961    scriptInterface.RegisterFunction<JS::Value, std::wstring, JS::HandleValue, &GuiInterfaceCall>("GuiInterfaceCall");
    943962    scriptInterface.RegisterFunction<void, JS::HandleValue, &PostNetworkCommand>("PostNetworkCommand");
    944963
    945964    // Entity picking
    946965    scriptInterface.RegisterFunction<entity_id_t, int, int, &PickEntityAtPoint>("PickEntityAtPoint");
    947     scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, int, int, int, int, &PickFriendlyEntitiesInRect>("PickFriendlyEntitiesInRect");
    948     scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, &PickFriendlyEntitiesOnScreen>("PickFriendlyEntitiesOnScreen");
    949     scriptInterface.RegisterFunction<std::vector<entity_id_t>, std::string, bool, bool, bool, &PickSimilarFriendlyEntities>("PickSimilarFriendlyEntities");
     966    scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, int, int, int, int, &PickPlayerEntitiesInRect>("PickPlayerEntitiesInRect");
     967    scriptInterface.RegisterFunction<std::vector<entity_id_t>, int, &PickPlayerEntitiesOnScreen>("PickPlayerEntitiesOnScreen");
     968    scriptInterface.RegisterFunction<std::vector<entity_id_t>, &PickAllPlayersEntitiesOnScreen>("PickAllPlayersEntitiesOnScreen");
     969    scriptInterface.RegisterFunction<std::vector<entity_id_t>, std::string, bool, bool, bool, &PickSimilarPlayerEntities>("PickSimilarPlayerEntities");
    950970    scriptInterface.RegisterFunction<CFixedVector3D, int, int, &GetTerrainAtScreenPoint>("GetTerrainAtScreenPoint");
    951971
    952972    // Network / game setup functions
    953973    scriptInterface.RegisterFunction<void, &StartNetworkGame>("StartNetworkGame");
    954974    scriptInterface.RegisterFunction<void, JS::HandleValue, int, &StartGame>("StartGame");
  • source/simulation2/components/CCmpRangeManager.cpp

     
    905905        }
    906906
    907907        return entities;
    908908    }
    909909
     910    virtual std::vector<entity_id_t> GetAllPlayerEntities()
     911    {
     912        // Compute ownership mask for all players
     913        u32 ownerMask = 0;
     914        for (player_id_t player = 1; player < MAX_LOS_PLAYER_ID + 1; ++player)
     915            ownerMask |= CalcOwnerMask(player);
     916
     917        // Get a list of all entities of all players
     918        std::vector<entity_id_t> entities;
     919        for (EntityMap<EntityData>::const_iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it)
     920        {
     921            // Check owner and add to list if it matches
     922            if (CalcOwnerMask(it->second.owner) & ownerMask)
     923                entities.push_back(it->first);
     924        }
     925
     926        return entities;
     927    }
     928
    910929    virtual void SetDebugOverlay(bool enabled)
    911930    {
    912931        m_DebugOverlayEnabled = enabled;
    913932        m_DebugOverlayDirty = true;
    914933        if (!enabled)
  • source/simulation2/components/ICmpRangeManager.cpp

     
    4343DEFINE_INTERFACE_METHOD_1("DisableActiveQuery", void, ICmpRangeManager, DisableActiveQuery, ICmpRangeManager::tag_t)
    4444DEFINE_INTERFACE_METHOD_1("ResetActiveQuery", std::vector<entity_id_t>, ICmpRangeManager, ResetActiveQuery, ICmpRangeManager::tag_t)
    4545DEFINE_INTERFACE_METHOD_3("SetEntityFlag", void, ICmpRangeManager, SetEntityFlag, entity_id_t, std::string, bool)
    4646DEFINE_INTERFACE_METHOD_1("GetEntityFlagMask", u8, ICmpRangeManager, GetEntityFlagMask, std::string)
    4747DEFINE_INTERFACE_METHOD_1("GetEntitiesByPlayer", std::vector<entity_id_t>, ICmpRangeManager, GetEntitiesByPlayer, player_id_t)
     48DEFINE_INTERFACE_METHOD_0("GetAllPlayerEntities", std::vector<entity_id_t>, ICmpRangeManager, GetAllPlayerEntities)
    4849DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool)
    4950DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t)
    5051DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories)
    5152DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool)
    5253DEFINE_INTERFACE_METHOD_1("GetLosRevealAll", bool, ICmpRangeManager, GetLosRevealAll, player_id_t)
  • source/simulation2/components/ICmpRangeManager.h

     
    177177     * @return list of entities matching the query, ordered by increasing distance from the source entity.
    178178     */
    179179    virtual std::vector<entity_id_t> ResetActiveQuery(tag_t tag) = 0;
    180180
    181181    /**
    182      * Returns list of all entities for specific player.
     182     * Returns a list of all entities for specific player.
    183183     * (This is on this interface because it shares a lot of the implementation.
    184184     * Maybe it should be extended to be more like ExecuteQuery without
    185185     * the range parameter.)
    186186     */
    187187    virtual std::vector<entity_id_t> GetEntitiesByPlayer(player_id_t player) = 0;
    188188
    189189    /**
     190     * Returns a list of all entities for all players.
     191     */
     192    virtual std::vector<entity_id_t> GetAllPlayerEntities() = 0;
     193
     194    /**
    190195     * Toggle the rendering of debug info.
    191196     */
    192197    virtual void SetDebugOverlay(bool enabled) = 0;
    193198
    194199    /**
  • source/simulation2/helpers/Selection.cpp

     
    161161    }
    162162
    163163    return hitEnts;
    164164}
    165165
     166std::vector<entity_id_t> EntitySelection::PickAllPlayerEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables)
     167{
     168    PROFILE2("PickAllPlayerEntitiesInRect");
     169    // Make sure sx0 <= sx1, and sy0 <= sy1
     170    if (sx0 > sx1)
     171        std::swap(sx0, sx1);
     172    if (sy0 > sy1)
     173        std::swap(sy0, sy1);
     174
     175    CmpPtr<ICmpRangeManager> cmpRangeManager(simulation, SYSTEM_ENTITY);
     176    ENSURE(cmpRangeManager);
     177
     178    std::vector<entity_id_t> hitEnts;
     179
     180    CComponentManager& componentManager = simulation.GetSimContext().GetComponentManager();
     181
     182    std::vector<entity_id_t> ents = cmpRangeManager->GetAllPlayerEntities();
     183    for (std::vector<entity_id_t>::iterator it = ents.begin(); it != ents.end(); ++it)
     184    {
     185        CmpPtr<ICmpOwnership> cmpOwnership(simulation.GetSimContext(), *it);
     186        if (CheckEntityVisibleAndInRect(componentManager.LookupEntityHandle(*it), cmpRangeManager, camera, sx0, sy0, sx1, sy1, cmpOwnership->GetOwner(), allowEditorSelectables))
     187            hitEnts.push_back(*it);
     188    }
     189
     190    return hitEnts;
     191}
     192
    166193std::vector<entity_id_t> EntitySelection::PickSimilarEntities(CSimulation2& simulation, const CCamera& camera,
    167194    const std::string& templateName, player_id_t owner, bool includeOffScreen, bool matchRank,
    168195    bool allowEditorSelectables, bool allowFoundations)
    169196{
    170197    PROFILE2("PickSimilarEntities");
  • source/simulation2/helpers/Selection.h

     
    6363 * @return unordered list of selected entities.
    6464 */
    6565std::vector<entity_id_t> PickEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, player_id_t owner, bool allowEditorSelectables);
    6666
    6767/**
     68 * Finds all selectable entities within the given screen coordinate rectangle,
     69 * belonging to any player.
     70 *
     71 * @param camera use this view to convert screen to world coordinates.
     72 * @param sx0,sy0,sx1,sy1 diagonally opposite corners of the rectangle in 2D screen coordinates.
     73 * @param owner player whose entities we are selecting. Ownership is ignored if
     74 *  INVALID_PLAYER is used.
     75 * @param allowEditorSelectables if true, all entities with the ICmpSelectable interface
     76 *  will be selected (including decorative actors), else only those selectable ingame.
     77 *
     78 * @return unordered list of selected entities.
     79 */
     80std::vector<entity_id_t> PickAllPlayerEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables);
     81
     82/**
    6883 * Finds all entities with the given entity template name, belonging to the given player.
    6984 *
    7085 * @param camera use this view to convert screen to world coordinates.
    7186 * @param templateName the name of the template to match, or the selection group name
    7287 *  for similar matching.