From 0c6026c22ee15fd599692e5e209129f14643edc6 Mon Sep 17 00:00:00 2001 From: Redix Date: Mon, 18 Sep 2017 00:57:21 +0200 Subject: [PATCH] Hide ghost menu buttons if there are no ghosts --- src/game/client/components/ghost.cpp | 2 +- src/game/client/components/ghost.h | 1 + src/game/client/components/menus_ingame.cpp | 27 +++++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/game/client/components/ghost.cpp b/src/game/client/components/ghost.cpp index 61c727426..184f347aa 100644 --- a/src/game/client/components/ghost.cpp +++ b/src/game/client/components/ghost.cpp @@ -413,6 +413,7 @@ int CGhost::Load(const char *pFilename) // select ghost CGhostItem *pGhost = &m_aActiveGhosts[Slot]; + pGhost->Reset(); pGhost->m_Path.SetSize(NumTicks); str_copy(pGhost->m_aPlayer, pHeader->m_aOwner, sizeof(pGhost->m_aPlayer)); @@ -421,7 +422,6 @@ int CGhost::Load(const char *pFilename) bool FoundSkin = false; bool NoTick = false; bool Error = false; - pGhost->m_StartTick = -1; int Type; while(!Error && GhostLoader()->ReadNextType(&Type)) diff --git a/src/game/client/components/ghost.h b/src/game/client/components/ghost.h index 27587bb6e..8d2f51898 100644 --- a/src/game/client/components/ghost.h +++ b/src/game/client/components/ghost.h @@ -93,6 +93,7 @@ private: void Reset() { m_Path.Reset(); + m_StartTick = -1; m_PlaybackPos = 0; } }; diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 21fbbfc61..1f1a3ec49 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -1128,17 +1128,23 @@ void CMenus::RenderGhost(CUIRect MainView) if(NewSelected != -1) s_SelectedIndex = NewSelected; - CGhostItem *pGhost = &m_lGhosts[s_SelectedIndex]; - RenderTools()->DrawUIRect(&Status, vec4(1,1,1,0.25f), CUI::CORNER_B, 5.0f); Status.Margin(5.0f, &Status); CUIRect Button; + Status.VSplitLeft(120.0f, &Button, &Status); - static int s_GhostButton = 0; - static int s_DeleteButton = 0; - static int s_SaveButton = 0; static int s_ReloadButton = 0; + if(DoButton_Menu(&s_ReloadButton, Localize("Reload"), 0, &Button)) + { + m_pClient->m_pGhost->UnloadAll(); + GhostlistPopulate(); + } + + if(s_SelectedIndex >= m_lGhosts.size()) + return; + + CGhostItem *pGhost = &m_lGhosts[s_SelectedIndex]; CGhostItem *pOwnGhost = GetOwnGhost(); int ReservedSlots = !pGhost->m_Own && !(pOwnGhost && pOwnGhost->Active()); @@ -1146,6 +1152,7 @@ void CMenus::RenderGhost(CUIRect MainView) { Status.VSplitRight(120.0f, &Status, &Button); + static int s_GhostButton = 0; const char *pText = pGhost->Active() ? Localize("Deactivate") : Localize("Activate"); if(DoButton_Menu(&s_GhostButton, pText, 0, &Button) || (NewSelected != -1 && Input()->MouseDoubleClick())) { @@ -1163,6 +1170,7 @@ void CMenus::RenderGhost(CUIRect MainView) Status.VSplitRight(120.0f, &Status, &Button); + static int s_DeleteButton = 0; if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &Button)) { if(pGhost->Active()) @@ -1175,16 +1183,9 @@ void CMenus::RenderGhost(CUIRect MainView) bool Recording = m_pClient->m_pGhost->GhostRecorder()->IsRecording(); if(!pGhost->HasFile() && !Recording && pGhost->Active()) { + static int s_SaveButton = 0; Status.VSplitRight(120.0f, &Status, &Button); if(DoButton_Menu(&s_SaveButton, Localize("Save"), 0, &Button)) m_pClient->m_pGhost->SaveGhost(pGhost); } - - Status.VSplitLeft(120.0f, &Button, &Status); - - if(DoButton_Menu(&s_ReloadButton, Localize("Reload"), 0, &Button)) - { - m_pClient->m_pGhost->UnloadAll(); - GhostlistPopulate(); - } }