Ticket #3215: t3215_fix_observer_statusbars_v3.patch
File t3215_fix_observer_statusbars_v3.patch, 17.2 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
159 159 else if (placementSupport.mode === "wall") 160 160 { 161 161 if (placementSupport.wallSet && placementSupport.position) 162 162 { 163 163 // Fetch an updated list of snapping candidate entities 164 placementSupport.wallSnapEntities = Engine.PickSimilar FriendlyEntities(164 placementSupport.wallSnapEntities = Engine.PickSimilarPlayerEntities( 165 165 placementSupport.wallSet.templates.tower, 166 166 placementSupport.wallSnapEntitiesIncludeOffscreen, 167 167 true, // require exact template match 168 168 true // include foundations 169 169 ); … … 549 549 switch (ev.type) 550 550 { 551 551 case "mousemotion": 552 552 var rect = updateBandbox(bandbox, ev, false); 553 553 554 var ents = Engine.Pick FriendlyEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID());554 var ents = Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID()); 555 555 var preferredEntities = getPreferredEntities(ents); 556 556 g_Selection.setHighlightList(preferredEntities); 557 557 558 558 return false; 559 559 … … 561 561 if (ev.button == SDL_BUTTON_LEFT) 562 562 { 563 563 var rect = updateBandbox(bandbox, ev, true); 564 564 565 565 // Get list of entities limited to preferred entities 566 var ents = getPreferredEntities(Engine.Pick FriendlyEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID()));566 var ents = getPreferredEntities(Engine.PickPlayerEntitiesInRect(rect[0], rect[1], rect[2], rect[3], Engine.GetPlayerID())); 567 567 568 568 // Remove the bandbox hover highlighting 569 569 g_Selection.setHighlightList([]); 570 570 571 571 // Update the list of selected units … … 1043 1043 // Select units matching exact template name (same rank) 1044 1044 templateToMatch = GetEntityState(selectedEntity).template; 1045 1045 } 1046 1046 1047 1047 // TODO: Should we handle "control all units" here as well? 1048 ents = Engine.PickSimilar FriendlyEntities(templateToMatch, showOffscreen, matchRank, false);1048 ents = Engine.PickSimilarPlayerEntities(templateToMatch, showOffscreen, matchRank, false); 1049 1049 } 1050 1050 else 1051 1051 { 1052 1052 // It's single click right now but it may become double or triple click 1053 1053 doubleClicked = false; -
binaries/data/mods/public/gui/session/session.js
820 820 821 821 // Toggles the display of status bars for all of the player's entities. 822 822 function recalculateStatusBarDisplay() 823 823 { 824 824 if (g_ShowAllStatusBars) 825 var entities = Engine.PickFriendlyEntitiesOnScreen(Engine.GetPlayerID());825 var entities = g_IsObserver ? Engine.PickNonGaiaEntitiesOnScreen() : Engine.PickPlayerEntitiesOnScreen(Engine.GetPlayerID()); 826 826 else 827 827 { 828 828 var selected = g_Selection.toList(); 829 829 for each (var ent in g_Selection.highlighted) 830 830 selected.push(ent); 831 831 832 832 // Remove selected entities from the 'all entities' array, to avoid disabling their status bars. 833 var entities = Engine.GuiInterfaceCall("GetPlayerEntities").filter( 834 function(idx) { return (selected.indexOf(idx) == -1); } 835 ); 833 var entities = Engine.GuiInterfaceCall(g_IsObserver ? "GetNonGaiaEntities" : "GetPlayerEntities").filter(idx => selected.indexOf(idx) == -1); 836 834 } 837 835 838 836 Engine.GuiInterfaceCall("SetStatusBars", { "entities": entities, "enabled": g_ShowAllStatusBars }); 839 837 } 840 841 838 // Update the additional list of entities to be highlighted. 842 839 function updateAdditionalHighlight() 843 840 { 844 841 var entsAdd = []; // list of entities units to be highlighted 845 842 var entsRemove = []; -
binaries/data/mods/public/simulation/components/GuiInterface.js
891 891 { 892 892 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 893 893 return cmpRangeManager.GetEntitiesByPlayer(player); 894 894 }; 895 895 896 GuiInterface.prototype.GetNonGaiaEntities = function() 897 { 898 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 899 return cmpRangeManager.GetNonGaiaEntities(); 900 }; 901 896 902 /** 897 903 * Displays the rally points of a given list of entities (carried in cmd.entities). 898 904 * 899 905 * The 'cmd' object may carry its own x/z coordinate pair indicating the location where the rally point should 900 906 * be rendered, in order to support instantaneously rendering a rally point marker at a specified location … … 1883 1889 1884 1890 "SetSelectionHighlight": 1, 1885 1891 "GetAllBuildableEntities": 1, 1886 1892 "SetStatusBars": 1, 1887 1893 "GetPlayerEntities": 1, 1894 "GetNonGaiaEntities": 1, 1888 1895 "DisplayRallyPoint": 1, 1889 1896 "SetBuildingPlacementPreview": 1, 1890 1897 "SetWallPlacementPreview": 1, 1891 1898 "GetFoundationSnapData": 1, 1892 1899 "PlaySound": 1, -
source/gui/scripting/ScriptFunctions.cpp
59 59 #include "renderer/scripting/JSInterface_Renderer.h" 60 60 #include "simulation2/Simulation2.h" 61 61 #include "simulation2/components/ICmpAIManager.h" 62 62 #include "simulation2/components/ICmpCommandQueue.h" 63 63 #include "simulation2/components/ICmpGuiInterface.h" 64 #include "simulation2/components/ICmpPlayerManager.h" 64 65 #include "simulation2/components/ICmpRangeManager.h" 65 66 #include "simulation2/components/ICmpSelectable.h" 66 67 #include "simulation2/components/ICmpTemplateManager.h" 67 68 #include "simulation2/helpers/Selection.h" 68 69 #include "soundmanager/SoundManager.h" … … 151 152 entity_id_t PickEntityAtPoint(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x, int y) 152 153 { 153 154 return EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, g_Game->GetPlayerID(), false); 154 155 } 155 156 156 std::vector<entity_id_t> Pick FriendlyEntitiesInRect(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x0, int y0, int x1, int y1, int player)157 std::vector<entity_id_t> PickPlayerEntitiesInRect(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x0, int y0, int x1, int y1, int player) 157 158 { 158 159 return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, player, false); 159 160 } 160 161 161 std::vector<entity_id_t> Pick FriendlyEntitiesOnScreen(ScriptInterface::CxPrivate* pCxPrivate, int player)162 std::vector<entity_id_t> PickPlayerEntitiesOnScreen(ScriptInterface::CxPrivate* pCxPrivate, int player) 162 163 { 163 return Pick FriendlyEntitiesInRect(pCxPrivate, 0, 0, g_xres, g_yres, player);164 return PickPlayerEntitiesInRect(pCxPrivate, 0, 0, g_xres, g_yres, player); 164 165 } 165 166 166 std::vector<entity_id_t> PickSimilarFriendlyEntities(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string templateName, bool includeOffScreen, bool matchRank, bool allowFoundations) 167 std::vector<entity_id_t> PickNonGaiaEntitiesOnScreen(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 185 std::vector<entity_id_t> PickSimilarPlayerEntities(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string templateName, bool includeOffScreen, bool matchRank, bool allowFoundations) 167 186 { 168 187 return EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, g_Game->GetPlayerID(), includeOffScreen, matchRank, false, allowFoundations); 169 188 } 170 189 171 190 CFixedVector3D GetTerrainAtScreenPoint(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x, int y) … … 942 961 scriptInterface.RegisterFunction<JS::Value, std::wstring, JS::HandleValue, &GuiInterfaceCall>("GuiInterfaceCall"); 943 962 scriptInterface.RegisterFunction<void, JS::HandleValue, &PostNetworkCommand>("PostNetworkCommand"); 944 963 945 964 // Entity picking 946 965 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>, &PickNonGaiaEntitiesOnScreen>("PickNonGaiaEntitiesOnScreen"); 969 scriptInterface.RegisterFunction<std::vector<entity_id_t>, std::string, bool, bool, bool, &PickSimilarPlayerEntities>("PickSimilarPlayerEntities"); 950 970 scriptInterface.RegisterFunction<CFixedVector3D, int, int, &GetTerrainAtScreenPoint>("GetTerrainAtScreenPoint"); 951 971 952 972 // Network / game setup functions 953 973 scriptInterface.RegisterFunction<void, &StartNetworkGame>("StartNetworkGame"); 954 974 scriptInterface.RegisterFunction<void, JS::HandleValue, int, &StartGame>("StartGame"); -
source/simulation2/components/CCmpRangeManager.cpp
905 905 } 906 906 907 907 return entities; 908 908 } 909 909 910 virtual std::vector<entity_id_t> GetNonGaiaEntities() 911 { 912 // Compute ownership mask for all players except gaia as in CalcOwnerMask 913 u32 ownerMask = ((1 << MAX_LOS_PLAYER_ID) - 1) << 1; 914 915 // Get the list of entities 916 std::vector<entity_id_t> entities; 917 for (EntityMap<EntityData>::const_iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it) 918 { 919 // Check owner and add to list if it matches 920 if (CalcOwnerMask(it->second.owner) & ownerMask) 921 entities.push_back(it->first); 922 } 923 924 return entities; 925 } 926 910 927 virtual void SetDebugOverlay(bool enabled) 911 928 { 912 929 m_DebugOverlayEnabled = enabled; 913 930 m_DebugOverlayDirty = true; 914 931 if (!enabled) -
source/simulation2/components/ICmpRangeManager.cpp
43 43 DEFINE_INTERFACE_METHOD_1("DisableActiveQuery", void, ICmpRangeManager, DisableActiveQuery, ICmpRangeManager::tag_t) 44 44 DEFINE_INTERFACE_METHOD_1("ResetActiveQuery", std::vector<entity_id_t>, ICmpRangeManager, ResetActiveQuery, ICmpRangeManager::tag_t) 45 45 DEFINE_INTERFACE_METHOD_3("SetEntityFlag", void, ICmpRangeManager, SetEntityFlag, entity_id_t, std::string, bool) 46 46 DEFINE_INTERFACE_METHOD_1("GetEntityFlagMask", u8, ICmpRangeManager, GetEntityFlagMask, std::string) 47 47 DEFINE_INTERFACE_METHOD_1("GetEntitiesByPlayer", std::vector<entity_id_t>, ICmpRangeManager, GetEntitiesByPlayer, player_id_t) 48 DEFINE_INTERFACE_METHOD_0("GetNonGaiaEntities", std::vector<entity_id_t>, ICmpRangeManager, GetNonGaiaEntities) 48 49 DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool) 49 50 DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t) 50 51 DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories) 51 52 DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool) 52 53 DEFINE_INTERFACE_METHOD_1("GetLosRevealAll", bool, ICmpRangeManager, GetLosRevealAll, player_id_t) -
source/simulation2/components/ICmpRangeManager.h
177 177 * @return list of entities matching the query, ordered by increasing distance from the source entity. 178 178 */ 179 179 virtual std::vector<entity_id_t> ResetActiveQuery(tag_t tag) = 0; 180 180 181 181 /** 182 * Returns list of all entities for specific player.182 * Returns a list of all entities for specific player. 183 183 * (This is on this interface because it shares a lot of the implementation. 184 184 * Maybe it should be extended to be more like ExecuteQuery without 185 185 * the range parameter.) 186 186 */ 187 187 virtual std::vector<entity_id_t> GetEntitiesByPlayer(player_id_t player) = 0; 188 188 189 189 /** 190 * Returns a list of all entities of all players except gaia. 191 */ 192 virtual std::vector<entity_id_t> GetNonGaiaEntities() = 0; 193 194 /** 190 195 * Toggle the rendering of debug info. 191 196 */ 192 197 virtual void SetDebugOverlay(bool enabled) = 0; 193 198 194 199 /** -
source/simulation2/helpers/Selection.cpp
142 142 143 143 if (owner != INVALID_PLAYER) 144 144 { 145 145 CComponentManager& componentManager = simulation.GetSimContext().GetComponentManager(); 146 146 std::vector<entity_id_t> ents = cmpRangeManager->GetEntitiesByPlayer(owner); 147 for ( std::vector<entity_id_t>::iterator it = ents.begin(); it != ents.end(); ++it)147 for (const entity_id_t& ent : ents) 148 148 { 149 if (CheckEntityVisibleAndInRect(componentManager.LookupEntityHandle( *it), cmpRangeManager, camera, sx0, sy0, sx1, sy1, owner, allowEditorSelectables))150 hitEnts.push_back( *it);149 if (CheckEntityVisibleAndInRect(componentManager.LookupEntityHandle(ent), cmpRangeManager, camera, sx0, sy0, sx1, sy1, owner, allowEditorSelectables)) 150 hitEnts.push_back(ent); 151 151 } 152 152 } 153 153 else // owner == INVALID_PLAYER; Used when selecting units in Atlas or other mods that allow all kinds of selectables to be selected. 154 154 { 155 155 const CSimulation2::InterfaceListUnordered& selectableEnts = simulation.GetEntitiesWithInterfaceUnordered(IID_Selectable); … … 161 161 } 162 162 163 163 return hitEnts; 164 164 } 165 165 166 std::vector<entity_id_t> EntitySelection::PickNonGaiaEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables) 167 { 168 PROFILE2("PickNonGaiaEntitiesInRect"); 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->GetNonGaiaEntities(); 183 for (const entity_id_t& ent : ents) 184 { 185 CmpPtr<ICmpOwnership> cmpOwnership(simulation.GetSimContext(), ent); 186 if (CheckEntityVisibleAndInRect(componentManager.LookupEntityHandle(ent), cmpRangeManager, camera, sx0, sy0, sx1, sy1, cmpOwnership->GetOwner(), allowEditorSelectables)) 187 hitEnts.push_back(ent); 188 } 189 190 return hitEnts; 191 } 192 166 193 std::vector<entity_id_t> EntitySelection::PickSimilarEntities(CSimulation2& simulation, const CCamera& camera, 167 194 const std::string& templateName, player_id_t owner, bool includeOffScreen, bool matchRank, 168 195 bool allowEditorSelectables, bool allowFoundations) 169 196 { 170 197 PROFILE2("PickSimilarEntities"); -
source/simulation2/helpers/Selection.h
63 63 * @return unordered list of selected entities. 64 64 */ 65 65 std::vector<entity_id_t> PickEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, player_id_t owner, bool allowEditorSelectables); 66 66 67 67 /** 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 */ 80 std::vector<entity_id_t> PickNonGaiaEntitiesInRect(CSimulation2& simulation, const CCamera& camera, int sx0, int sy0, int sx1, int sy1, bool allowEditorSelectables); 81 82 /** 68 83 * Finds all entities with the given entity template name, belonging to the given player. 69 84 * 70 85 * @param camera use this view to convert screen to world coordinates. 71 86 * @param templateName the name of the template to match, or the selection group name 72 87 * for similar matching.