mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
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:
parent
c8ea372d98
commit
fc7c376738
|
@ -1505,6 +1505,7 @@ int CServerInfo::EstimateLatency(int Loc1, int Loc2)
|
||||||
}
|
}
|
||||||
return 99;
|
return 99;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CServerInfo::ParseLocation(int *pResult, const char *pString)
|
bool CServerInfo::ParseLocation(int *pResult, const char *pString)
|
||||||
{
|
{
|
||||||
*pResult = LOC_UNKNOWN;
|
*pResult = LOC_UNKNOWN;
|
||||||
|
@ -1534,3 +1535,16 @@ bool CServerInfo::ParseLocation(int *pResult, const char *pString)
|
||||||
}
|
}
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ public:
|
||||||
|
|
||||||
static int EstimateLatency(int Loc1, int Loc2);
|
static int EstimateLatency(int Loc1, int Loc2);
|
||||||
static bool ParseLocation(int *pResult, const char *pString);
|
static bool ParseLocation(int *pResult, const char *pString);
|
||||||
|
void InfoToString(char *pBuffer, int BufferSize) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IServerBrowser : public IInterface
|
class IServerBrowser : public IInterface
|
||||||
|
|
|
@ -1030,8 +1030,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
|
||||||
const CServerInfo *pSelectedServer = ServerBrowser()->SortedGet(m_SelectedIndex);
|
const CServerInfo *pSelectedServer = ServerBrowser()->SortedGet(m_SelectedIndex);
|
||||||
|
|
||||||
// split off a piece to use for scoreboard
|
// split off a piece to use for scoreboard
|
||||||
ServerDetails.HSplitTop(90.0f, &ServerDetails, &ServerScoreBoard);
|
ServerDetails.HSplitTop(110.0f, &ServerDetails, &ServerScoreBoard);
|
||||||
ServerDetails.HSplitBottom(2.5f, &ServerDetails, 0x0);
|
|
||||||
|
|
||||||
// server details
|
// server details
|
||||||
CTextCursor Cursor;
|
CTextCursor Cursor;
|
||||||
|
@ -1043,8 +1042,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
|
||||||
|
|
||||||
if(pSelectedServer)
|
if(pSelectedServer)
|
||||||
{
|
{
|
||||||
ServerDetails.VSplitLeft(5.0f, 0, &ServerDetails);
|
ServerDetails.Margin(5.0f, &ServerDetails);
|
||||||
ServerDetails.Margin(3.0f, &ServerDetails);
|
|
||||||
|
|
||||||
CUIRect Row;
|
CUIRect Row;
|
||||||
static CLocConstString s_aLabels[] = {
|
static CLocConstString s_aLabels[] = {
|
||||||
|
@ -1052,17 +1050,28 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
|
||||||
"Game type",
|
"Game type",
|
||||||
"Ping"};
|
"Ping"};
|
||||||
|
|
||||||
CUIRect LeftColumn;
|
// copy info button
|
||||||
CUIRect RightColumn;
|
{
|
||||||
|
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;
|
CUIRect Button;
|
||||||
ServerDetails.HSplitBottom(20.0f, &ServerDetails, &Button);
|
ServerDetails.HSplitBottom(20.0f, &ServerDetails, &Button);
|
||||||
CUIRect ButtonAddFav;
|
CUIRect ButtonAddFav;
|
||||||
CUIRect ButtonLeakIp;
|
CUIRect ButtonLeakIp;
|
||||||
Button.VSplitMid(&ButtonAddFav, &ButtonLeakIp);
|
Button.VSplitMid(&ButtonAddFav, &ButtonLeakIp);
|
||||||
ButtonAddFav.VSplitLeft(5.0f, 0, &ButtonAddFav);
|
|
||||||
static int s_AddFavButton = 0;
|
static int s_AddFavButton = 0;
|
||||||
static int s_LeakIpButton = 0;
|
static int s_LeakIpButton = 0;
|
||||||
if(DoButton_CheckBox_Tristate(&s_AddFavButton, Localize("Favorite"), pSelectedServer->m_Favorite, &ButtonAddFav))
|
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);
|
ServerDetails.VSplitLeft(80.0f, &LeftColumn, &RightColumn);
|
||||||
|
|
||||||
for(auto &Label : s_aLabels)
|
for(auto &Label : s_aLabels)
|
||||||
|
|
|
@ -415,6 +415,21 @@ void CMenus::RenderServerInfo(CUIRect MainView)
|
||||||
|
|
||||||
TextRender()->Text(0, ServerInfo.x + x, ServerInfo.y + y, 20, aBuf, 250.0f);
|
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;
|
CUIRect Button;
|
||||||
NETADDR ServerAddr = Client()->ServerAddress();
|
NETADDR ServerAddr = Client()->ServerAddress();
|
||||||
|
|
Loading…
Reference in a new issue