From b83b4c8e33ea933b0531c13f6e2b06ea2cc2132c Mon Sep 17 00:00:00 2001 From: def Date: Fri, 23 Oct 2020 23:25:58 +0200 Subject: [PATCH] Warn new players about name with points (fixes #3178) --- src/engine/client.h | 1 + src/engine/client/client.cpp | 5 +++ src/game/client/components/menus.cpp | 46 +++++++++++++++++++++++++++- src/game/client/components/menus.h | 1 + 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/engine/client.h b/src/engine/client.h index 8e4bbcd39..515f62269 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -49,6 +49,7 @@ protected: public: char m_aNews[3000]; + int m_Points; int64 m_ReconnectTime; class CSnapItem diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 0be8ea034..4132981dc 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -328,6 +328,7 @@ CClient::CClient() : str_format(m_aDDNetInfoTmp, sizeof(m_aDDNetInfoTmp), DDNET_INFO ".%d.tmp", pid()); m_pDDNetInfoTask = NULL; m_aNews[0] = '\0'; + m_Points = -1; m_CurrentServerInfoRequestTime = -1; @@ -2521,6 +2522,10 @@ void CClient::LoadDDNetInfo() str_copy(m_aNews, pNewsString, sizeof(m_aNews)); } + + const json_value *pPoints = json_object_get(pDDNetInfo, "points"); + if(pPoints->type == json_integer) + m_Points = pPoints->u.integer; } void CClient::PumpNetwork() diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 52380d56c..c135a6191 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1440,6 +1440,24 @@ int CMenus::Render() pButtonText = Localize("Ok"); ExtraAlign = -1; } + else if(m_Popup == POPUP_POINTS) + { + pTitle = Localize("Existing Player"); + if(Client()->m_Points > 50) + { + str_format(aBuf, sizeof(aBuf), Localize("Your nick name '%s' is already used (%d points). Do you still want to use it?"), Client()->PlayerName(), Client()->m_Points); + pExtraText = aBuf; + } + else if(Client()->m_Points >= 0) + { + m_Popup = POPUP_NONE; + } + else + { + pExtraText = Localize("Checking for existing player with your name"); + } + ExtraAlign = -1; + } else if(m_Popup == POPUP_WARNING) { BgColor = ColorRGBA{0.5f, 0.0f, 0.0f, 0.7f}; @@ -2024,7 +2042,12 @@ int CMenus::Render() if(DoButton_Menu(&s_EnterButton, Localize("Enter"), 0, &Part) || m_EnterPressed) { Client()->RequestDDNetInfo(); - m_Popup = POPUP_NONE; + if(g_Config.m_BrIndicateFinished) + m_Popup = POPUP_POINTS; + else + { + m_Popup = POPUP_NONE; + } } Box.HSplitBottom(20.f, &Box, &Part); @@ -2050,6 +2073,27 @@ int CMenus::Render() static float Offset = 0.0f; DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &Offset, false, CUI::CORNER_ALL, Client()->PlayerName()); } + else if(m_Popup == POPUP_POINTS) + { + 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_ButtonNo = 0; + if(DoButton_Menu(&s_ButtonNo, Localize("No"), 0, &No) || m_EscapePressed) + m_Popup = POPUP_FIRST_LAUNCH; + + static int s_ButtonYes = 0; + if(DoButton_Menu(&s_ButtonYes, Localize("Yes"), 0, &Yes) || m_EnterPressed) + m_Popup = POPUP_NONE; + } else if(m_Popup == POPUP_WARNING) { Box.HSplitBottom(20.f, &Box, &Part); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 79df6207b..0abaa2a9e 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -502,6 +502,7 @@ public: { POPUP_NONE = 0, POPUP_FIRST_LAUNCH, + POPUP_POINTS, POPUP_CONNECTING, POPUP_MESSAGE, POPUP_DISCONNECTED,