Make sure that we have a free ghost slot for new records

This commit is contained in:
Redix 2017-09-10 04:57:03 +02:00
parent 353190588b
commit 0721b895ae
3 changed files with 18 additions and 3 deletions

View file

@ -90,6 +90,15 @@ int CGhost::GetSlot() const
return -1; return -1;
} }
int CGhost::FreeSlot() const
{
int Num = 0;
for(int i = 0; i < MAX_ACTIVE_GHOSTS; i++)
if(m_aActiveGhosts[i].Empty())
Num++;
return Num;
}
void CGhost::OnRender() void CGhost::OnRender()
{ {
// only for race // only for race
@ -226,8 +235,11 @@ void CGhost::StopRecord(int Time)
CMenus::CGhostItem *pOwnGhost = m_pClient->m_pMenus->GetOwnGhost(); CMenus::CGhostItem *pOwnGhost = m_pClient->m_pMenus->GetOwnGhost();
if(Time > 0 && (!pOwnGhost || Time < pOwnGhost->m_Time)) if(Time > 0 && (!pOwnGhost || Time < pOwnGhost->m_Time))
{ {
if(pOwnGhost && pOwnGhost->Active())
Unload(pOwnGhost->m_Slot);
// add to active ghosts // add to active ghosts
int Slot = pOwnGhost ? pOwnGhost->m_Slot : GetSlot(); int Slot = GetSlot();
if(Slot != -1) if(Slot != -1)
m_aActiveGhosts[Slot] = m_CurGhost; m_aActiveGhosts[Slot] = m_CurGhost;

View file

@ -85,6 +85,7 @@ private:
static void GetNetObjCharacter(CNetObj_Character *pChar, const CGhostCharacter *pGhostChar); static void GetNetObjCharacter(CNetObj_Character *pChar, const CGhostCharacter *pGhostChar);
void AddInfos(const CNetObj_Character *pChar); void AddInfos(const CNetObj_Character *pChar);
int GetSlot() const;
void StartRecord(); void StartRecord();
void StopRecord(int Time = -1); void StopRecord(int Time = -1);
@ -106,7 +107,7 @@ public:
virtual void OnMessage(int MsgType, void *pRawMsg); virtual void OnMessage(int MsgType, void *pRawMsg);
virtual void OnMapLoad(); virtual void OnMapLoad();
int GetSlot() const; int FreeSlot() const;
int Load(const char *pFilename); int Load(const char *pFilename);
void Unload(int Slot); void Unload(int Slot);

View file

@ -1140,7 +1140,9 @@ void CMenus::RenderGhost(CUIRect MainView)
static int s_SaveButton = 0; static int s_SaveButton = 0;
static int s_ReloadButton = 0; static int s_ReloadButton = 0;
if(pGhost->HasFile() && (pGhost->Active() || m_pClient->m_pGhost->GetSlot() != -1)) CGhostItem *pOwnGhost = GetOwnGhost();
int ReservedSlots = !pGhost->m_Own && !(pOwnGhost && pOwnGhost->Active());
if(pGhost->HasFile() && (pGhost->Active() || m_pClient->m_pGhost->FreeSlot() > ReservedSlots))
{ {
Status.VSplitRight(120.0f, &Status, &Button); Status.VSplitRight(120.0f, &Status, &Button);