Skip to content

Commit

Permalink
link controls auto-add click handler
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Nov 19, 2024
1 parent bf91f41 commit cd6c0a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/dialogxml/widgets/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/dialogxml/widgets/control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -462,6 +465,7 @@ class cControl {
// Transient values only used during parsing
ePosition horz = POS_ABS, vert = POS_ABS;
std::string anchor;
bool is_link = false;
};

#endif
12 changes: 1 addition & 11 deletions src/game/boe.actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 1 addition & 9 deletions src/game/boe.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd6c0a0

Please sign in to comment.