wave-survival/modules/wave_survival/heads_up_display.cpp
2025-08-10 20:53:27 +02:00

49 lines
1.1 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);
}
void HeadsUpDisplay::on_child_entered(Node *child) {
if (child->is_unique_name_in_owner() && child->get_name() == "Reticle") {
this->reticle = cast_to<Control>(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);
}
}