Replace POPUP_SWITCH_SERVER with generic confirmation popup

This commit is contained in:
Robert Müller 2022-11-30 23:41:32 +01:00
parent cb1d9ccc98
commit a45f833afa
3 changed files with 20 additions and 45 deletions

View file

@ -1618,11 +1618,6 @@ int CMenus::Render()
pButtonText = m_aMessageButton;
ExtraAlign = -1;
}
else if(m_Popup == POPUP_SWITCH_SERVER)
{
pTitle = Localize("Disconnect");
pExtraText = Localize("Are you sure that you want to disconnect and switch to a different server?");
}
CUIRect Box, Part;
Box = Screen;
@ -2159,29 +2154,6 @@ int CMenus::Render()
SetActive(false);
}
}
else if(m_Popup == POPUP_SWITCH_SERVER)
{
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;
m_aNextServer[0] = '\0';
}
static CButtonContainer s_ButtonTryAgain;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
Client()->Connect(m_aNextServer);
}
else
{
Box.HSplitBottom(20.f, &Box, &Part);

View file

@ -544,6 +544,8 @@ protected:
int m_DoubleClickIndex;
int m_ScrollOffset;
void RenderServerbrowserServerList(CUIRect View);
void Connect(const char *pAddress);
void PopupConfirmSwitchServer();
void RenderServerbrowserServerDetail(CUIRect View);
void RenderServerbrowserFilters(CUIRect View);
void RenderServerbrowserFriends(CUIRect View);
@ -731,7 +733,6 @@ public:
POPUP_PASSWORD,
POPUP_QUIT,
POPUP_WARNING,
POPUP_SWITCH_SERVER,
// demo player states
DEMOPLAYER_NONE = 0,

View file

@ -509,15 +509,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
const CServerInfo *pItem = ServerBrowser()->SortedGet(NewSelected);
str_copy(g_Config.m_UiServerAddress, pItem->m_aAddress);
if(DoubleClicked && Input()->MouseDoubleClick())
{
if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
{
m_Popup = POPUP_SWITCH_SERVER;
str_copy(m_aNextServer, g_Config.m_UiServerAddress);
}
else
Client()->Connect(g_Config.m_UiServerAddress);
}
Connect(g_Config.m_UiServerAddress);
}
//Status.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 5.0f);
@ -668,17 +660,27 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
m_ConnectButton, &s_JoinButton, []() -> const char * { return Localize("Connect"); }, 0, &ButtonConnect, false, false, IGraphics::CORNER_ALL, 5, 0, vec4(0.7f, 1, 0.7f, 0.1f), vec4(0.7f, 1, 0.7f, 0.2f)) ||
UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
{
if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
{
m_Popup = POPUP_SWITCH_SERVER;
str_copy(m_aNextServer, g_Config.m_UiServerAddress);
}
else
Client()->Connect(g_Config.m_UiServerAddress);
Connect(g_Config.m_UiServerAddress);
}
}
}
void CMenus::Connect(const char *pAddress)
{
if(Client()->State() == IClient::STATE_ONLINE && Client()->GetCurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
{
str_copy(m_aNextServer, pAddress);
PopupConfirm(Localize("Disconnect"), Localize("Are you sure that you want to disconnect and switch to a different server?"), Localize("Yes"), Localize("No"), &CMenus::PopupConfirmSwitchServer);
}
else
Client()->Connect(pAddress);
}
void CMenus::PopupConfirmSwitchServer()
{
Client()->Connect(m_aNextServer);
}
void CMenus::RenderServerbrowserFilters(CUIRect View)
{
CUIRect ServerFilter = View, FilterHeader;