2281: Add Learn button which opens the ddnet wiki in the browser. r=heinrich5991 a=edg-l

![image](https://user-images.githubusercontent.com/15859336/85147350-05f00d00-b24f-11ea-8b6c-f79dbf605747.png)

## **I didn't test it on windows or mac.**

Co-authored-by: Edgar <git@edgarluque.com>
This commit is contained in:
bors[bot] 2020-06-20 12:00:45 +00:00 committed by GitHub
commit 4edac3143a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View file

@ -3247,6 +3247,21 @@ void shell_execute(const char *file)
#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)
{
#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);
/*
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);

View file

@ -676,11 +676,22 @@ int CMenus::RenderMenubar(CUIRect r)
// offline menus
Box.VSplitLeft(90.0f, &Button, &Box);
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;
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(100.0f, &Button, &Box);