tooltips on node links
This commit is contained in:
@@ -808,13 +808,23 @@ void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter&
|
||||
redraw_everything();
|
||||
|
||||
bool inField = false;
|
||||
bool onTooltip = false;
|
||||
for(auto& ctrl : controls) {
|
||||
if(!ctrl.second->tooltip_text.empty() && ctrl.second->getBounds().contains(x, y)){
|
||||
if(tooltip_control.empty()){
|
||||
LOG("Warning! Tooltip activated but nowhere to show it!");
|
||||
}else{
|
||||
getControl(tooltip_control).setText(ctrl.second->tooltip_text);
|
||||
onTooltip = true;
|
||||
}
|
||||
}
|
||||
if(ctrl.second->getType() == CTRL_FIELD && ctrl.second->getBounds().contains(x, y)) {
|
||||
set_cursor(text_curs);
|
||||
inField = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!onTooltip && !tooltip_control.empty()) getControl(tooltip_control).setText("");
|
||||
if(!inField) set_cursor(sword_curs);
|
||||
}break;
|
||||
default: // To silence warning of unhandled enum values
|
||||
|
@@ -107,6 +107,8 @@ public:
|
||||
/// Create a new dialog with no items.
|
||||
/// @param p Optionally, a parent dialog.
|
||||
explicit cDialog(cDialog* p = nullptr);
|
||||
/// Designate a control as the place to display tooltip text
|
||||
void setTooltipControl(std::string key) { this->tooltip_control = key; }
|
||||
/// Creates a new dialog, loading its definition from a file.
|
||||
/// @param path The name of the file to load. It must be in the game's dialogs directory.
|
||||
/// @param p Optionally, a parent dialog.
|
||||
@@ -298,6 +300,8 @@ private:
|
||||
std::string fname;
|
||||
std::string defaultButton;
|
||||
std::string escapeButton;
|
||||
/// TODO make this specifiable in dialogxml
|
||||
std::string tooltip_control;
|
||||
sf::Clock animTimer, paintTimer;
|
||||
friend class cControl;
|
||||
friend class cContainer;
|
||||
|
@@ -385,6 +385,9 @@ public:
|
||||
/// If the control automatically determines its rect based on certain criteria, override this.
|
||||
/// It will automatically be called during parsing.
|
||||
virtual void recalcRect() {}
|
||||
|
||||
// Set text that will be displayed when the mouse hovers this
|
||||
void setTooltipText(std::string text) { this->tooltip_text = text; }
|
||||
protected:
|
||||
/// Create a new control attached to a dialog.
|
||||
/// @param t The type of the control.
|
||||
@@ -508,6 +511,8 @@ private:
|
||||
std::string anchor;
|
||||
bool is_link = false;
|
||||
static std::mt19937 ui_rand;
|
||||
// TODO make this specifiable in dialogXML
|
||||
std::string tooltip_text;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user