Add ingame and browser buttons to copy server info to clipboard

Add "Copy info" buttons to server browser and ingame menu to copy the server info of the selected/current server to the clipboard.

The margins around the server browser details are improved.

Closes #5440.
This commit is contained in:
Robert Müller 2023-01-06 21:14:26 +01:00
parent c8ea372d98
commit fc7c376738
4 changed files with 48 additions and 9 deletions

View file

@ -1505,6 +1505,7 @@ int CServerInfo::EstimateLatency(int Loc1, int Loc2)
}
return 99;
}
bool CServerInfo::ParseLocation(int *pResult, const char *pString)
{
*pResult = LOC_UNKNOWN;
@ -1534,3 +1535,16 @@ bool CServerInfo::ParseLocation(int *pResult, const char *pString)
}
return true;
}
void CServerInfo::InfoToString(char *pBuffer, int BufferSize) const
{
str_format(
pBuffer,
BufferSize,
"%s\n"
"Address: ddnet://%s\n"
"My IGN: %s\n",
m_aName,
m_aAddress,
g_Config.m_PlayerName);
}

View file

@ -83,6 +83,7 @@ public:
static int EstimateLatency(int Loc1, int Loc2);
static bool ParseLocation(int *pResult, const char *pString);
void InfoToString(char *pBuffer, int BufferSize) const;
};
class IServerBrowser : public IInterface

View file

@ -1030,8 +1030,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
const CServerInfo *pSelectedServer = ServerBrowser()->SortedGet(m_SelectedIndex);
// split off a piece to use for scoreboard
ServerDetails.HSplitTop(90.0f, &ServerDetails, &ServerScoreBoard);
ServerDetails.HSplitBottom(2.5f, &ServerDetails, 0x0);
ServerDetails.HSplitTop(110.0f, &ServerDetails, &ServerScoreBoard);
// server details
CTextCursor Cursor;
@ -1043,8 +1042,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
if(pSelectedServer)
{
ServerDetails.VSplitLeft(5.0f, 0, &ServerDetails);
ServerDetails.Margin(3.0f, &ServerDetails);
ServerDetails.Margin(5.0f, &ServerDetails);
CUIRect Row;
static CLocConstString s_aLabels[] = {
@ -1052,17 +1050,28 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
"Game type",
"Ping"};
CUIRect LeftColumn;
CUIRect RightColumn;
// copy info button
{
CUIRect Button;
ServerDetails.HSplitBottom(15.0f, &ServerDetails, &Button);
static CButtonContainer s_CopyButton;
if(DoButton_Menu(&s_CopyButton, Localize("Copy info"), 0, &Button))
{
char aInfo[256];
pSelectedServer->InfoToString(aInfo, sizeof(aInfo));
Input()->SetClipboardText(aInfo);
}
}
//
ServerDetails.HSplitBottom(2.5f, &ServerDetails, nullptr);
// favorite checkbox
{
CUIRect Button;
ServerDetails.HSplitBottom(20.0f, &ServerDetails, &Button);
CUIRect ButtonAddFav;
CUIRect ButtonLeakIp;
Button.VSplitMid(&ButtonAddFav, &ButtonLeakIp);
ButtonAddFav.VSplitLeft(5.0f, 0, &ButtonAddFav);
static int s_AddFavButton = 0;
static int s_LeakIpButton = 0;
if(DoButton_CheckBox_Tristate(&s_AddFavButton, Localize("Favorite"), pSelectedServer->m_Favorite, &ButtonAddFav))
@ -1091,7 +1100,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
}
}
ServerDetails.VSplitLeft(5.0f, 0x0, &ServerDetails);
CUIRect LeftColumn, RightColumn;
ServerDetails.VSplitLeft(80.0f, &LeftColumn, &RightColumn);
for(auto &Label : s_aLabels)

View file

@ -415,6 +415,21 @@ void CMenus::RenderServerInfo(CUIRect MainView)
TextRender()->Text(0, ServerInfo.x + x, ServerInfo.y + y, 20, aBuf, 250.0f);
// copy info button
{
CUIRect Button;
ServerInfo.HSplitBottom(20.0f, &ServerInfo, &Button);
Button.VSplitRight(200.0f, &ServerInfo, &Button);
static CButtonContainer s_CopyButton;
if(DoButton_Menu(&s_CopyButton, Localize("Copy info"), 0, &Button))
{
char aInfo[256];
CurrentServerInfo.InfoToString(aInfo, sizeof(aInfo));
Input()->SetClipboardText(aInfo);
}
}
// favorite checkbox
{
CUIRect Button;
NETADDR ServerAddr = Client()->ServerAddress();