Index: ps/trunk/binaries/data/mods/public/gui/session/session.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/session.js +++ ps/trunk/binaries/data/mods/public/gui/session/session.js @@ -278,6 +278,7 @@ LoadModificationTemplates(); updatePlayerData(); + Engine.GuiInterfaceCall("UpdateDisplayedPlayerColors"); g_BarterSell = g_ResourceData.GetCodes()[0]; Index: ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js +++ ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -843,6 +843,19 @@ return buildableEnts; }; +/** + * Updates player colors on the minimap. + */ +GuiInterface.prototype.UpdateDisplayedPlayerColors = function() +{ + for (let ent of Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetGaiaAndNonGaiaEntities()) + { + let cmpMinimap = Engine.QueryInterface(ent, IID_Minimap); + if (cmpMinimap) + cmpMinimap.UpdateColor(); + } +}; + GuiInterface.prototype.SetSelectionHighlight = function(player, cmd) { let playerColors = {}; // cache of owner -> color map @@ -1978,6 +1991,7 @@ "GetFormationInfoFromTemplate": 1, "IsStanceSelected": 1, + "UpdateDisplayedPlayerColors": 1, "SetSelectionHighlight": 1, "GetAllBuildableEntities": 1, "SetStatusBars": 1, Index: ps/trunk/source/simulation2/components/CCmpMinimap.cpp =================================================================== --- ps/trunk/source/simulation2/components/CCmpMinimap.cpp +++ ps/trunk/source/simulation2/components/CCmpMinimap.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -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) @@ -168,28 +161,7 @@ } case MT_OwnershipChanged: { - if (!m_UsePlayerColor) - break; - - const CMessageOwnershipChanged& msgData = static_cast (msg); - - // If there's no new owner (e.g. the unit is dying) then don't try updating the color - 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(); break; } case MT_MinimapPing: @@ -236,6 +208,33 @@ return m_IsPinging; } + + virtual void UpdateColor() + { + if (!m_UsePlayerColor) + return; + + CmpPtr cmpOwnership(GetEntityHandle()); + if (!cmpOwnership) + return; + + player_id_t owner = cmpOwnership->GetOwner(); + if (owner == INVALID_PLAYER) + return; + + CmpPtr cmpPlayerManager(GetSystemEntity()); + if (!cmpPlayerManager) + return; + + CmpPtr cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(owner)); + 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: ps/trunk/source/simulation2/components/ICmpMinimap.h =================================================================== --- ps/trunk/source/simulation2/components/ICmpMinimap.h +++ ps/trunk/source/simulation2/components/ICmpMinimap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -29,17 +29,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() = 0; + DECLARE_INTERFACE_TYPE(Minimap) }; Index: ps/trunk/source/simulation2/components/ICmpMinimap.cpp =================================================================== --- ps/trunk/source/simulation2/components/ICmpMinimap.cpp +++ ps/trunk/source/simulation2/components/ICmpMinimap.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -22,4 +22,5 @@ #include "simulation2/system/InterfaceScripted.h" BEGIN_INTERFACE_WRAPPER(Minimap) +DEFINE_INTERFACE_METHOD_0("UpdateColor", void, ICmpMinimap, UpdateColor) END_INTERFACE_WRAPPER(Minimap)