58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#include "heads_up_display.h"
|
|
|
|
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() {
|
|
connect("child_entered_tree", callable_mp(this, &self_type::on_child_entered));
|
|
singleton_instance = this;
|
|
}
|
|
|
|
void HeadsUpDisplay::exit_tree() {
|
|
singleton_instance = nullptr;
|
|
}
|
|
|
|
void HeadsUpDisplay::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_ENTER_TREE:
|
|
enter_tree();
|
|
return;
|
|
case NOTIFICATION_EXIT_TREE:
|
|
exit_tree();
|
|
return;
|
|
}
|
|
}
|
|
|
|
HeadsUpDisplay *HeadsUpDisplay::get_singleton() {
|
|
return singleton_instance;
|
|
}
|
|
|
|
void HeadsUpDisplay::set_reticle_visibility(bool visible) {
|
|
if (this->reticle) {
|
|
this->reticle->set_visible(visible);
|
|
}
|
|
}
|
|
|
|
void HeadsUpDisplay::set_tooltip(String const &tooltip) {
|
|
this->tooltip->set_text(tooltip);
|
|
}
|