BaseButton: add shortcut_in_tooltip

This flag disables the input related information in the tooltip.
It is exposed as a member variable in gdscript.
This commit is contained in:
lupoDharkael 2018-11-19 14:30:59 +01:00
parent 26d33d1c6e
commit d2b890ede5
3 changed files with 22 additions and 1 deletions

View File

@ -68,6 +68,9 @@
<member name="toggle_mode" type="bool" setter="set_toggle_mode" getter="is_toggle_mode">
If [code]true[/code] the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
</member>
<member name="shortcut_in_tooltip" type="bool" setter="set_shortcut_in_tooltip" getter="is_shortcut_in_tooltip_enabled">
If [code]true[/code] the button will add information about its shortcut in the tooltip.
</member>
</members>
<signals>
<signal name="button_down">

View File

@ -406,6 +406,16 @@ bool BaseButton::is_toggle_mode() const {
return toggle_mode;
}
void BaseButton::set_shortcut_in_tooltip(bool p_on) {
shortcut_in_tooltip = p_on;
}
bool BaseButton::is_shortcut_in_tooltip_enabled() const {
return shortcut_in_tooltip;
}
void BaseButton::set_action_mode(ActionMode p_mode) {
action_mode = p_mode;
@ -471,7 +481,7 @@ void BaseButton::_unhandled_input(Ref<InputEvent> p_event) {
String BaseButton::get_tooltip(const Point2 &p_pos) const {
String tooltip = Control::get_tooltip(p_pos);
if (shortcut.is_valid() && shortcut->is_valid()) {
if (shortcut_in_tooltip && shortcut.is_valid() && shortcut->is_valid()) {
String text = shortcut->get_name() + " (" + shortcut->get_as_text() + ")";
if (shortcut->get_name().nocasecmp_to(tooltip) != 0) {
text += "\n" + tooltip;
@ -510,6 +520,8 @@ void BaseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_hovered"), &BaseButton::is_hovered);
ClassDB::bind_method(D_METHOD("set_toggle_mode", "enabled"), &BaseButton::set_toggle_mode);
ClassDB::bind_method(D_METHOD("is_toggle_mode"), &BaseButton::is_toggle_mode);
ClassDB::bind_method(D_METHOD("set_shortcut_in_tooltip", "enabled"), &BaseButton::set_shortcut_in_tooltip);
ClassDB::bind_method(D_METHOD("is_shortcut_in_tooltip_enabled"), &BaseButton::is_shortcut_in_tooltip_enabled);
ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &BaseButton::set_disabled);
ClassDB::bind_method(D_METHOD("is_disabled"), &BaseButton::is_disabled);
ClassDB::bind_method(D_METHOD("set_action_mode", "mode"), &BaseButton::set_action_mode);
@ -535,6 +547,7 @@ void BaseButton::_bind_methods() {
ADD_SIGNAL(MethodInfo("toggled", PropertyInfo(Variant::BOOL, "button_pressed")));
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toggle_mode"), "set_toggle_mode", "is_toggle_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_in_tooltip"), "set_shortcut_in_tooltip", "is_shortcut_in_tooltip_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::INT, "action_mode", PROPERTY_HINT_ENUM, "Button Press,Button Release"), "set_action_mode", "get_action_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask", PROPERTY_HINT_FLAGS, "Mouse Left, Mouse Right, Mouse Middle"), "set_button_mask", "get_button_mask");
@ -555,6 +568,7 @@ void BaseButton::_bind_methods() {
BaseButton::BaseButton() {
toggle_mode = false;
shortcut_in_tooltip = true;
status.pressed = false;
status.press_attempt = false;
status.hovering = false;

View File

@ -51,6 +51,7 @@ public:
private:
int button_mask;
bool toggle_mode;
bool shortcut_in_tooltip;
FocusMode enabled_focus_mode;
Ref<ShortCut> shortcut;
@ -100,6 +101,9 @@ public:
void set_toggle_mode(bool p_on);
bool is_toggle_mode() const;
void set_shortcut_in_tooltip(bool p_on);
bool is_shortcut_in_tooltip_enabled() const;
void set_disabled(bool p_disabled);
bool is_disabled() const;