Add Learn button which opens the ddnet wiki in the browser.

This commit is contained in:
Edgar 2020-06-19 17:04:35 +02:00
parent e36dc36b15
commit 07f0239e01
No known key found for this signature in database
GPG key ID: 8731E6C0166EAA85
3 changed files with 42 additions and 1 deletions

View file

@ -3247,6 +3247,21 @@ void shell_execute(const char *file)
#endif #endif
} }
int open_link(const char *link)
{
char aBuf[512];
#if defined(CONF_FAMILY_WINDOWS)
str_format(aBuf, sizeof(aBuf), "start %s", link);
return (uintptr_t)ShellExecuteA(NULL, "open", link, NULL, NULL, SW_SHOWDEFAULT) > 32;
#elif defined(CONF_PLATFORM_LINUX)
str_format(aBuf, sizeof(aBuf), "xdg-open %s", link);
return system(aBuf) == 0;
#elif defined(CONF_FAMILY_UNIX)
str_format(aBuf, sizeof(aBuf), "open %s", link);
return system(aBuf) == 0;
#endif
}
int os_is_winxp_or_lower(void) int os_is_winxp_or_lower(void)
{ {
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)

View file

@ -1656,6 +1656,21 @@ int net_would_block(void);
int net_socket_read_wait(NETSOCKET sock, int time); int net_socket_read_wait(NETSOCKET sock, int time);
/*
Function: open_link
Opens a link in the browser.
Parameters:
link - The link to open in a browser.
Returns:
Returns 1 on success, 0 on failure.
Remarks:
This may not be called with untrusted input or it'll result in arbitrary code execution.
*/
int open_link(const char *link);
void swap_endian(void *data, unsigned elem_size, unsigned num); void swap_endian(void *data, unsigned elem_size, unsigned num);

View file

@ -676,11 +676,22 @@ int CMenus::RenderMenubar(CUIRect r)
// offline menus // offline menus
Box.VSplitLeft(90.0f, &Button, &Box); Box.VSplitLeft(90.0f, &Button, &Box);
static int s_NewsButton=0; static int s_NewsButton=0;
if(DoButton_MenuTab(&s_NewsButton, Localize("News"), m_ActivePage==PAGE_NEWS, &Button, CUI::CORNER_T)) if(DoButton_MenuTab(&s_NewsButton, Localize("News"), m_ActivePage==PAGE_NEWS, &Button, CUI::CORNER_TL))
{ {
NewPage = PAGE_NEWS; NewPage = PAGE_NEWS;
m_DoubleClickIndex = -1; m_DoubleClickIndex = -1;
} }
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_LearnButton=0;
if(DoButton_MenuTab(&s_LearnButton, Localize("Learn"), false, &Button, CUI::CORNER_TR))
{
if(!open_link("https://wiki.ddnet.tw/"))
{
dbg_msg("menus", "couldn't open link");
}
m_DoubleClickIndex = -1;
}
Box.VSplitLeft(10.0f, 0, &Box); Box.VSplitLeft(10.0f, 0, &Box);
Box.VSplitLeft(100.0f, &Button, &Box); Box.VSplitLeft(100.0f, &Button, &Box);