diff --git a/config/ui/game/common.cfg b/config/ui/game/common.cfg index f6bc6c87e..8cfd06168 100644 --- a/config/ui/game/common.cfg +++ b/config/ui/game/common.cfg @@ -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 @@ -491,6 +494,12 @@ gameui_confirm = [ gameui_open ui_gameui_confirm ] +gameui_openlink = [ + gameui_openlink_href = $arg1 + + gameui_open ui_gameui_openlink +] + //////////// @@ -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 diff --git a/src/engine/client.cpp b/src/engine/client.cpp index c9ba88185..ae8111483 100644 --- a/src/engine/client.cpp +++ b/src/engine/client.cpp @@ -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; @@ -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)