Replace POPUP_DISCONNECT(_DUMMY) with generic confirmation popup

This commit is contained in:
Robert Müller 2022-11-30 23:06:44 +01:00
parent f4708a3a00
commit 620e3e56db
3 changed files with 15 additions and 58 deletions

View file

@ -1591,16 +1591,6 @@ int CMenus::Render()
pTitle = Localize("Quit"); pTitle = Localize("Quit");
pExtraText = Localize("Are you sure that you want to quit?"); pExtraText = Localize("Are you sure that you want to quit?");
} }
else if(m_Popup == POPUP_DISCONNECT)
{
pTitle = Localize("Disconnect");
pExtraText = Localize("Are you sure that you want to disconnect?");
}
else if(m_Popup == POPUP_DISCONNECT_DUMMY)
{
pTitle = Localize("Disconnect Dummy");
pExtraText = Localize("Are you sure that you want to disconnect your dummy?");
}
else if(m_Popup == POPUP_FIRST_LAUNCH) else if(m_Popup == POPUP_FIRST_LAUNCH)
{ {
pTitle = Localize("Welcome to DDNet"); pTitle = Localize("Welcome to DDNet");
@ -1756,50 +1746,6 @@ int CMenus::Render()
Client()->Quit(); Client()->Quit();
} }
} }
else if(m_Popup == POPUP_DISCONNECT)
{
CUIRect Yes, No;
Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
// buttons
Part.VMargin(80.0f, &Part);
Part.VSplitMid(&No, &Yes);
Yes.VMargin(20.0f, &Yes);
No.VMargin(20.0f, &No);
static CButtonContainer s_ButtonAbort;
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
m_Popup = POPUP_NONE;
static CButtonContainer s_ButtonTryAgain;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
Client()->Disconnect();
}
else if(m_Popup == POPUP_DISCONNECT_DUMMY)
{
CUIRect Yes, No;
Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
// buttons
Part.VMargin(80.0f, &Part);
Part.VSplitMid(&No, &Yes);
Yes.VMargin(20.0f, &Yes);
No.VMargin(20.0f, &No);
static CButtonContainer s_ButtonAbort;
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || UI()->ConsumeHotkey(CUI::HOTKEY_ESCAPE))
m_Popup = POPUP_NONE;
static CButtonContainer s_ButtonTryAgain;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
{
Client()->DummyDisconnect(0);
m_Popup = POPUP_NONE;
SetActive(false);
}
}
else if(m_Popup == POPUP_PASSWORD) else if(m_Popup == POPUP_PASSWORD)
{ {
CUIRect Label, TextBox, TryAgain, Abort; CUIRect Label, TextBox, TryAgain, Abort;

View file

@ -529,6 +529,8 @@ protected:
// found in menus_ingame.cpp // found in menus_ingame.cpp
void RenderGame(CUIRect MainView); void RenderGame(CUIRect MainView);
void PopupConfirmDisconnect();
void PopupConfirmDisconnectDummy();
void RenderPlayers(CUIRect MainView); void RenderPlayers(CUIRect MainView);
void RenderServerInfo(CUIRect MainView); void RenderServerInfo(CUIRect MainView);
void RenderServerControl(CUIRect MainView); void RenderServerControl(CUIRect MainView);
@ -729,8 +731,6 @@ public:
POPUP_SOUNDERROR, POPUP_SOUNDERROR,
POPUP_PASSWORD, POPUP_PASSWORD,
POPUP_QUIT, POPUP_QUIT,
POPUP_DISCONNECT,
POPUP_DISCONNECT_DUMMY,
POPUP_WARNING, POPUP_WARNING,
POPUP_SWITCH_SERVER, POPUP_SWITCH_SERVER,

View file

@ -56,7 +56,7 @@ void CMenus::RenderGame(CUIRect MainView)
{ {
if(Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) if(Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
{ {
m_Popup = POPUP_DISCONNECT; PopupConfirm(Localize("Disconnect"), Localize("Are you sure that you want to disconnect?"), Localize("Yes"), Localize("No"), &CMenus::PopupConfirmDisconnect);
} }
else else
{ {
@ -88,7 +88,7 @@ void CMenus::RenderGame(CUIRect MainView)
{ {
if(Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) if(Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
{ {
m_Popup = POPUP_DISCONNECT_DUMMY; PopupConfirm(Localize("Disconnect Dummy"), Localize("Are you sure that you want to disconnect your dummy?"), Localize("Yes"), Localize("No"), &CMenus::PopupConfirmDisconnectDummy);
} }
else else
{ {
@ -208,6 +208,17 @@ void CMenus::RenderGame(CUIRect MainView)
} }
} }
void CMenus::PopupConfirmDisconnect()
{
Client()->Disconnect();
}
void CMenus::PopupConfirmDisconnectDummy()
{
Client()->DummyDisconnect(0);
SetActive(false);
}
void CMenus::RenderPlayers(CUIRect MainView) void CMenus::RenderPlayers(CUIRect MainView)
{ {
CUIRect Button, Button2, ButtonBar, Options, Player; CUIRect Button, Button2, ButtonBar, Options, Player;