1
0
forked from 0ad/0ad

Fix range overlay color after deserialization following 5fbb224dc0 / D555, refs #3915.

Since the component initialization order is the alphabetic filename
order and
since the RangeOverlayRenderer < Player < Selectable, the new file in
that commit introduced the issue.
Similar to 36b315ca32, refs #4632.

UpdateColor function taken from temple's D754

This was SVN commit r20963.
This commit is contained in:
elexis 2018-01-22 06:50:35 +00:00
parent 36fba76a74
commit 034124e8d8

View File

@ -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
@ -23,6 +23,7 @@
#include "graphics/TextureManager.h"
#include "renderer/Renderer.h"
#include "simulation2/MessageTypes.h"
#include "simulation2/components/ICmpOwnership.h"
#include "simulation2/components/ICmpPlayer.h"
#include "simulation2/components/ICmpPlayerManager.h"
#include "simulation2/components/ICmpPosition.h"
@ -34,6 +35,7 @@ class CCmpRangeOverlayRenderer : public ICmpRangeOverlayRenderer
public:
static void ClassInit(CComponentManager& componentManager)
{
componentManager.SubscribeToMessageType(MT_Deserialized);
componentManager.SubscribeToMessageType(MT_OwnershipChanged);
}
@ -119,22 +121,10 @@ public:
break;
}
case MT_Deserialized:
case MT_OwnershipChanged:
{
const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg);
if (msgData.to == INVALID_PLAYER)
break;
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
if (!cmpPlayerManager)
break;
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(msgData.to));
if (!cmpPlayer)
break;
CColor color = cmpPlayer->GetColor();
m_Color = color;
UpdateColor();
break;
}
case MT_RenderSubmit:
@ -146,6 +136,28 @@ public:
}
}
virtual void UpdateColor()
{
CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle());
if (!cmpOwnership)
return;
player_id_t owner = cmpOwnership->GetOwner();
if (owner == INVALID_PLAYER)
return;
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
if (!cmpPlayerManager)
return;
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(owner));
if (!cmpPlayer)
return;
CColor color = cmpPlayer->GetColor();
m_Color = color;
}
void UpdateMessageSubscriptions()
{
bool needInterpolate = false;