Index: binaries/data/mods/public/gui/session/session.js =================================================================== --- binaries/data/mods/public/gui/session/session.js +++ binaries/data/mods/public/gui/session/session.js @@ -276,6 +276,7 @@ g_PlayerAssignments.local.player = -1; updatePlayerData(); + Engine.GuiInterfaceCall("UpdateDisplayedColors"); g_BarterSell = g_ResourceData.GetCodes()[0]; Index: binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- binaries/data/mods/public/simulation/components/GuiInterface.js +++ binaries/data/mods/public/simulation/components/GuiInterface.js @@ -865,6 +865,25 @@ return buildableEnts; }; +/** + * Updates the color of Minimap entities. + */ +GuiInterface.prototype.UpdateDisplayedColors = function() +{ + let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers(); + for (let i = 0; i < numPlayers; ++i) + { + let entities = cmpRangeManager.GetEntitiesByPlayer(i); + for (let ent of entities) + { + let cmpMinimap = Engine.QueryInterface(ent, IID_Minimap); + if (cmpMinimap) + cmpMinimap.UpdateColor(i); + } + } +}; + GuiInterface.prototype.SetSelectionHighlight = function(player, cmd) { let playerColors = {}; // cache of owner -> color map @@ -1994,6 +2013,7 @@ "GetFormationInfoFromTemplate": 1, "IsStanceSelected": 1, + "UpdateDisplayedColors": 1, "SetSelectionHighlight": 1, "GetAllBuildableEntities": 1, "SetStatusBars": 1, Index: source/simulation2/components/CCmpMinimap.cpp =================================================================== --- source/simulation2/components/CCmpMinimap.cpp +++ source/simulation2/components/CCmpMinimap.cpp @@ -117,13 +117,6 @@ template void SerializeCommon(S& serialize) { - if (m_UsePlayerColor) - { - serialize.NumberU8_Unbounded("r", m_R); - serialize.NumberU8_Unbounded("g", m_G); - serialize.NumberU8_Unbounded("b", m_B); - } - serialize.Bool("active", m_Active); if (m_Active) @@ -177,18 +170,7 @@ if (msgData.to == INVALID_PLAYER) break; - // Find the new player's color - CmpPtr cmpPlayerManager(GetSystemEntity()); - if (!cmpPlayerManager) - break; - CmpPtr cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(msgData.to)); - if (!cmpPlayer) - break; - CColor color = cmpPlayer->GetColor(); - m_R = (u8)(color.r*255.0); - m_G = (u8)(color.g*255.0); - m_B = (u8)(color.b*255.0); - // TODO: probably should avoid using floating-point here + UpdateColor(msgData.to); break; } @@ -236,6 +218,25 @@ return m_IsPinging; } + + virtual void UpdateColor(player_id_t player) + { + if (!m_UsePlayerColor) + return; + + CmpPtr cmpPlayerManager(GetSystemEntity()); + if (!cmpPlayerManager) + return; + + CmpPtr cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(player)); + if (!cmpPlayer) + return; + + CColor color = cmpPlayer->GetColor(); + m_R = (u8) (color.r * 255); + m_G = (u8) (color.g * 255); + m_B = (u8) (color.b * 255); + } }; REGISTER_COMPONENT_TYPE(Minimap) Index: source/simulation2/components/ICmpMinimap.h =================================================================== --- source/simulation2/components/ICmpMinimap.h +++ source/simulation2/components/ICmpMinimap.h @@ -20,6 +20,7 @@ #include "simulation2/system/Interface.h" +#include "simulation2/helpers/Player.h" #include "simulation2/helpers/Position.h" /** @@ -29,17 +30,22 @@ { public: /** - * Get the data for rendering this entity on the minimap. + * Gets the data for rendering this entity on the minimap. * If it should not be drawn, returns false; otherwise the arguments are set * to the color and world position. */ virtual bool GetRenderData(u8& r, u8& g, u8& b, entity_pos_t& x, entity_pos_t& z) const = 0; /** - * Return true if entity is actively pinging based on the current time + * Returns true if the entity is actively pinging based on the current time. */ virtual bool CheckPing(double currentTime, double pingDuration) = 0; + /** + * Updates the entity's minimap color to match the player color. + */ + virtual void UpdateColor(player_id_t player) = 0; + DECLARE_INTERFACE_TYPE(Minimap) }; Index: source/simulation2/components/ICmpMinimap.cpp =================================================================== --- source/simulation2/components/ICmpMinimap.cpp +++ source/simulation2/components/ICmpMinimap.cpp @@ -22,4 +22,5 @@ #include "simulation2/system/InterfaceScripted.h" BEGIN_INTERFACE_WRAPPER(Minimap) +DEFINE_INTERFACE_METHOD_1("UpdateColor", void, ICmpMinimap, UpdateColor, player_id_t) END_INTERFACE_WRAPPER(Minimap)