feat: implemented interaction tooltips
This commit is contained in:
parent
34db607145
commit
2511ac69c0
7 changed files with 44 additions and 15 deletions
|
|
@ -4,12 +4,17 @@ HeadsUpDisplay *HeadsUpDisplay::singleton_instance{ nullptr };
|
|||
|
||||
void HeadsUpDisplay::_bind_methods() {
|
||||
ClassDB::bind_static_method("HeadsUpDisplay", D_METHOD("get_singleton"), &self_type::get_singleton);
|
||||
ClassDB::bind_method(D_METHOD("set_tooltip"), &self_type::set_tooltip);
|
||||
}
|
||||
|
||||
void HeadsUpDisplay::on_child_entered(Node *child) {
|
||||
child->connect("child_entered_tree", callable_mp(this, &self_type::on_child_entered));
|
||||
if (child->is_unique_name_in_owner() && child->get_name() == "Reticle") {
|
||||
this->reticle = cast_to<Control>(child);
|
||||
}
|
||||
if (child->is_unique_name_in_owner() && child->get_name() == "Tooltip") {
|
||||
this->tooltip = cast_to<Label>(child);
|
||||
}
|
||||
}
|
||||
|
||||
void HeadsUpDisplay::enter_tree() {
|
||||
|
|
@ -46,3 +51,7 @@ void HeadsUpDisplay::set_reticle_visibility(bool visible) {
|
|||
this->reticle->set_visible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
void HeadsUpDisplay::set_tooltip(String const &tooltip) {
|
||||
this->tooltip->set_text(tooltip);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define HEADS_UP_DISPLAY_H
|
||||
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/gui/label.h"
|
||||
|
||||
class HeadsUpDisplay : public Control {
|
||||
GDCLASS(HeadsUpDisplay, Control);
|
||||
|
|
@ -17,9 +18,11 @@ protected:
|
|||
public:
|
||||
static HeadsUpDisplay *get_singleton();
|
||||
void set_reticle_visibility(bool visible);
|
||||
void set_tooltip(String const &tooltip);
|
||||
|
||||
private:
|
||||
Control *reticle{ nullptr };
|
||||
Label *tooltip{ nullptr };
|
||||
};
|
||||
|
||||
#endif // !HEADS_UP_DISPLAY_H
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "interactable.h"
|
||||
#include "heads_up_display.h"
|
||||
#include "macros.h"
|
||||
|
||||
void Interactable::_bind_methods() {
|
||||
|
|
@ -23,11 +24,3 @@ void Interactable::set_highlighted(PlayerInteractor *interactor, bool value) {
|
|||
bool Interactable::get_highlighted() const {
|
||||
return this->highlighted;
|
||||
}
|
||||
|
||||
void Interactable::set_highlight_tooltip(String value) {
|
||||
this->highlight_tooltip = value;
|
||||
}
|
||||
|
||||
String Interactable::get_highlight_tooltip() const {
|
||||
return this->highlight_tooltip;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,9 @@ public:
|
|||
|
||||
void set_highlighted(PlayerInteractor *interactor, bool value);
|
||||
bool get_highlighted() const;
|
||||
void set_highlight_tooltip(String value);
|
||||
String get_highlight_tooltip() const;
|
||||
|
||||
private:
|
||||
bool highlighted{ false };
|
||||
String highlight_tooltip{ "Activate" };
|
||||
};
|
||||
|
||||
#endif // !INTERACTABLE_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue