mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
fixed selected index when deleting a demo and added a popup to confirm the deletion
This commit is contained in:
parent
fcfaa8389f
commit
5588e1ec8c
|
@ -88,6 +88,7 @@ CMenus::CMenus()
|
||||||
m_NeedSendinfo = false;
|
m_NeedSendinfo = false;
|
||||||
m_MenuActive = true;
|
m_MenuActive = true;
|
||||||
m_UseMouseButtons = true;
|
m_UseMouseButtons = true;
|
||||||
|
m_DemolistDelEntry = false;
|
||||||
|
|
||||||
m_EscapePressed = false;
|
m_EscapePressed = false;
|
||||||
m_EnterPressed = false;
|
m_EnterPressed = false;
|
||||||
|
@ -846,6 +847,12 @@ int CMenus::Render()
|
||||||
pButtonText = Localize("Ok");
|
pButtonText = Localize("Ok");
|
||||||
ExtraAlign = -1;
|
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)
|
else if(m_Popup == POPUP_PASSWORD)
|
||||||
{
|
{
|
||||||
pTitle = Localize("Password incorrect");
|
pTitle = Localize("Password incorrect");
|
||||||
|
@ -939,6 +946,29 @@ int CMenus::Render()
|
||||||
static float Offset = 0.0f;
|
static float Offset = 0.0f;
|
||||||
DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true);
|
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)
|
else if(m_Popup == POPUP_FIRST_LAUNCH)
|
||||||
{
|
{
|
||||||
CUIRect Label, TextBox;
|
CUIRect Label, TextBox;
|
||||||
|
|
|
@ -95,6 +95,7 @@ class CMenus : public CComponent
|
||||||
POPUP_MESSAGE,
|
POPUP_MESSAGE,
|
||||||
POPUP_DISCONNECTED,
|
POPUP_DISCONNECTED,
|
||||||
POPUP_PURE,
|
POPUP_PURE,
|
||||||
|
POPUP_DELETE_DEMO,
|
||||||
POPUP_PASSWORD,
|
POPUP_PASSWORD,
|
||||||
POPUP_QUIT,
|
POPUP_QUIT,
|
||||||
};
|
};
|
||||||
|
@ -163,6 +164,7 @@ class CMenus : public CComponent
|
||||||
|
|
||||||
sorted_array<CDemoItem> m_lDemos;
|
sorted_array<CDemoItem> m_lDemos;
|
||||||
char m_aCurrentDemoFolder[256];
|
char m_aCurrentDemoFolder[256];
|
||||||
|
bool m_DemolistDelEntry;
|
||||||
|
|
||||||
void DemolistPopulate();
|
void DemolistPopulate();
|
||||||
static void DemolistCountCallback(const char *pName, int IsDir, void *pUser);
|
static void DemolistCountCallback(const char *pName, int IsDir, void *pUser);
|
||||||
|
|
|
@ -451,6 +451,25 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
||||||
s_SelectedItem = 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
|
// render background
|
||||||
RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f);
|
RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f);
|
||||||
MainView.Margin(10.0f, &MainView);
|
MainView.Margin(10.0f, &MainView);
|
||||||
|
@ -479,13 +498,6 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
||||||
ButtonBar.VSplitLeft(10.0f, &DeleteRect, &ButtonBar);
|
ButtonBar.VSplitLeft(10.0f, &DeleteRect, &ButtonBar);
|
||||||
ButtonBar.VSplitLeft(120.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;
|
static int s_RefreshButton = 0;
|
||||||
if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect))
|
if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &RefreshRect))
|
||||||
{
|
{
|
||||||
|
@ -526,13 +538,13 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!IsDir)
|
||||||
|
{
|
||||||
static int s_DeleteButton = 0;
|
static int s_DeleteButton = 0;
|
||||||
if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed)
|
if(DoButton_Menu(&s_DeleteButton, Localize("Delete"), 0, &DeleteRect) || m_DeletePressed)
|
||||||
{
|
{
|
||||||
if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size() && !IsDir)
|
if(s_SelectedItem >= 0 && s_SelectedItem < m_lDemos.size())
|
||||||
{
|
m_Popup = POPUP_DELETE_DEMO;
|
||||||
Storage()->RemoveFile(m_lDemos[s_SelectedItem].m_aFilename);
|
|
||||||
DemolistPopulate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue