Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions config/ui/game/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ gameui_confirm_text = ""
// Confirm panel action
gameui_confirm_action = []

// Open link panel link
gameui_openlink_href = ""

// Number of widget states to reset
gameui_num_states = 0

Expand Down Expand Up @@ -491,6 +494,12 @@ gameui_confirm = [
gameui_open ui_gameui_confirm
]

gameui_openlink = [
gameui_openlink_href = $arg1

gameui_open ui_gameui_openlink
]



////////////
Expand Down Expand Up @@ -593,6 +602,65 @@ ui_gameui_confirm_dims = 0.72
]
]

ui_gameui_openlink_dims = 0.72

# ui_gameui_openlink = [
#(gameui_begin_ids)

uivlist 0.05 [
uistyle clampx

uicolour 0x55010101 0 0 [
uistyle clampx

uitext "Open external link in your default browser?" 1.5

ui_gameui_shadowhoriz
]

uitext $gameui_openlink_href 1.5 [
uitextwrap 0.68
]

uivlist 0 [
ui_gameui_prettybutton [
p_label = "Open in Browser"
p_label_align = 0
p_width = 0.3
p_pad_h_shift = 0
p_on_click = [
openurl $gameui_openlink_href
gameui_close
]
p_id = #(gameui_get_id prettybutton)
]

ui_gameui_prettybutton [
p_label = "Copy to Clipboard"
p_label_align = 0
p_width = 0.3
p_pad_h_shift = 0
p_on_click = [
setclipboard $gameui_openlink_href
gameui_close
]
p_id = #(gameui_get_id prettybutton)
]

ui_gameui_prettybutton [
p_label = "Cancel"
p_label_align = 0
p_width = 0.3
p_pad_h_shift = 0
p_on_click = [
gameui_close
]
p_id = #(gameui_get_id prettybutton)
]
]
]
]

ui_gameui_panel = [
// Initialize state
gameui_hovering = 0
Expand Down
22 changes: 22 additions & 0 deletions src/engine/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ bool connected(bool attempt, bool local)
return curpeer || (attempt && connpeer) || (local && haslocalclients());
}

bool isvalidurl(char *href)
{
int len = strlen(href);
if(len < 7) return false;

if(!strncmp("http://", href, 7)) return true;

if(len >= 8 && !strncmp("https://", href, 8)) return true;

return false;
}

const ENetAddress *connectedpeer()
{
return curpeer ? &curpeer->address : NULL;
Expand All @@ -65,6 +77,16 @@ ICOMMAND(0, connectedport, "", (),
intret(address ? address->port : -1);
});

ICOMMAND(0, openurl, "s", (char *href),
{
if(isvalidurl(href)) SDL_OpenURL(href);
});

ICOMMAND(0, setclipboard, "s", (char *data),
{
SDL_SetClipboardText(data);
});

VARR(connectstatus, 0);

void abortconnect(bool msg)
Expand Down