diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index f12509143..78b6b0fca 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -88,6 +88,7 @@ CMenus::CMenus() m_NeedSendinfo = false; m_MenuActive = true; m_UseMouseButtons = true; + m_DemolistDelEntry = false; m_EscapePressed = false; m_EnterPressed = false; @@ -846,6 +847,12 @@ int CMenus::Render() pButtonText = Localize("Ok"); ExtraAlign = -1; } + else if(m_Popup == POPUP_DELETE_DEMO) + { + pTitle = Localize("Delete demo"); + pExtraText = Localize("Are you sure that you want to delete the demo?"); + ExtraAlign = -1; + } else if(m_Popup == POPUP_PASSWORD) { pTitle = Localize("Password incorrect"); @@ -939,6 +946,29 @@ int CMenus::Render() static float Offset = 0.0f; DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true); } + else if(m_Popup == POPUP_DELETE_DEMO) + { + CUIRect Yes, No; + Box.HSplitBottom(20.f, &Box, &Part); + Box.HSplitBottom(24.f, &Box, &Part); + Part.VMargin(80.0f, &Part); + + Part.VSplitMid(&No, &Yes); + + Yes.VMargin(20.0f, &Yes); + No.VMargin(20.0f, &No); + + static int s_ButtonAbort = 0; + if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed) + m_Popup = POPUP_NONE; + + static int s_ButtonTryAgain = 0; + if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed) + { + m_Popup = POPUP_NONE; + m_DemolistDelEntry = true; + } + } else if(m_Popup == POPUP_FIRST_LAUNCH) { CUIRect Label, TextBox; diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index ec2ff264c..6998acfe1 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -95,6 +95,7 @@ class CMenus : public CComponent POPUP_MESSAGE, POPUP_DISCONNECTED, POPUP_PURE, + POPUP_DELETE_DEMO, POPUP_PASSWORD, POPUP_QUIT, }; @@ -163,6 +164,7 @@ class CMenus : public CComponent sorted_array m_lDemos; char m_aCurrentDemoFolder[256]; + bool m_DemolistDelEntry; void DemolistPopulate(); static void DemolistCountCallback(const char *pName, int IsDir, void *pUser); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 5321b0878..859dedc42 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -450,6 +450,25 @@ void CMenus::RenderDemoList(CUIRect MainView) if(m_lDemos.size() > 0) s_SelectedItem = 0; } + + bool IsDir = false; + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) + { + if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0 || fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) + IsDir = true; + } + + // delete demo + if(m_DemolistDelEntry) + { + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir) + { + Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename); + DemolistPopulate(); + s_SelectedItem = s_SelectedItem-1 < 0 ? m_lDemos.size() > 0 ? 0 : -1 : s_SelectedItem-1; + } + m_DemolistDelEntry = false; + } // render background RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f); @@ -479,13 +498,6 @@ void CMenus::RenderDemoList(CUIRect MainView) ButtonBar.VSplitLeft(10.0f, &DeleteRect, &ButtonBar); ButtonBar.VSplitLeft(120.0f, &DeleteRect, &ButtonBar); - bool IsDir = false; - if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) - { - if(str_comp(m_lDemos[s_SelectedItem].m_aName, "..") == 0 || fs_is_dir(m_lDemos[s_SelectedItem].m_aFilename)) - IsDir = true; - } - static int s_RefreshButton = 0; if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect)) { @@ -526,13 +538,13 @@ void CMenus::RenderDemoList(CUIRect MainView) } } - static int s_DeleteButton = 0; - if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) + if(!IsDir) { - if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir) + static int s_DeleteButton = 0; + if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed) { - Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename); - DemolistPopulate(); + if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size()) + m_Popup = POPUP_DELETE_DEMO; } } }