diff --git a/src/dialogxml/widgets/control.cpp b/src/dialogxml/widgets/control.cpp index d4b681a7..47664c59 100644 --- a/src/dialogxml/widgets/control.cpp +++ b/src/dialogxml/widgets/control.cpp @@ -434,6 +434,16 @@ std::string cControl::parse(ticpp::Element& who, std::string fname) { frame.height() = height > 0 ? height : bestSz.y; setBounds(frame); validatePostParse(who, fname, foundAttrs, foundNodes); + + // Wire links to function: + // TODO links are identified only by having the color 'link', and can only link to their text value. + if(is_link){ + attachClickHandler([](cDialog& self, std::string clicked, eKeyMod) { + launchURL(self[clicked].getText()); + return false; + }); + } + return id; } @@ -540,6 +550,8 @@ bool cControl::parseAttribute(ticpp::Attribute& attr, std::string tagName, std:: setColour({0x7f, 0xd7, 0xFF}); if(parent->getBg() == cDialog::BG_LIGHT) setColour({0x00, 0x00, 0xFF}); + + is_link = true; } else try { sf::Color clr = parseColor(val); setColour(clr); diff --git a/src/dialogxml/widgets/control.hpp b/src/dialogxml/widgets/control.hpp index dd988aae..fb40ff95 100644 --- a/src/dialogxml/widgets/control.hpp +++ b/src/dialogxml/widgets/control.hpp @@ -32,6 +32,9 @@ namespace ticpp { class Node; } +// Hyperlink forward declaration +void launchURL(std::string url); + /// Formatting properties enum eFormat { TXT_FRAME, ///< The control's frame style. Should be an enum from @ref eFrameStyle. @@ -462,6 +465,7 @@ private: // Transient values only used during parsing ePosition horz = POS_ABS, vert = POS_ABS; std::string anchor; + bool is_link = false; }; #endif diff --git a/src/game/boe.actions.cpp b/src/game/boe.actions.cpp index 87689b05..bf3ce77b 100644 --- a/src/game/boe.actions.cpp +++ b/src/game/boe.actions.cpp @@ -246,17 +246,7 @@ void show_dialog_action(std::string xml_file) { record_action("show_dialog_action", xml_file); } - cChoiceDlog dlog(xml_file); - - // Dialogs with hyperlinks need special handling: - if(xml_file == "about-boe"){ - dlog->attachClickHandlers([](cDialog& self, std::string clicked, eKeyMod) { - launchURL(self[clicked].getText()); - return false; - }, {"src", "issues"}); - } - - dlog.show(); + cChoiceDlog(xml_file).show(); } bool prime_time() { diff --git a/src/game/boe.main.cpp b/src/game/boe.main.cpp index d28e67b9..2bdf782a 100644 --- a/src/game/boe.main.cpp +++ b/src/game/boe.main.cpp @@ -689,15 +689,7 @@ void init_boe(int argc, char* argv[]) { } void showWelcome() { - if(recording){ - record_action("showWelcome", ""); - } - cChoiceDlog welcome("welcome"); - welcome->attachClickHandlers([](cDialog& self, std::string clicked, eKeyMod) { - launchURL(self[clicked].getText()); - return false; - }, {"spidweb", "scen", "forum", "home", "src"}); - welcome.show(); + show_dialog_action("welcome"); } using Key = sf::Keyboard::Key;