feat: added HUD object
This commit is contained in:
parent
3ceabd50eb
commit
7e3afd6c64
9 changed files with 64 additions and 20 deletions
|
|
@ -1,9 +1,24 @@
|
|||
#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) {
|
||||
|
|
@ -16,8 +31,18 @@ void HeadsUpDisplay::_notification(int what) {
|
|||
case NOTIFICATION_ENTER_TREE:
|
||||
enter_tree();
|
||||
return;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
exit_tree();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void HeadsUpDisplay::set_reticle_visibility(bool visible) {
|
||||
HeadsUpDisplay *HeadsUpDisplay::get_singleton() {
|
||||
return singleton_instance;
|
||||
}
|
||||
|
||||
void HeadsUpDisplay::set_reticle_visibility(bool visible) {
|
||||
if (this->reticle) {
|
||||
this->reticle->set_visible(visible);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,16 @@
|
|||
class HeadsUpDisplay : public Control {
|
||||
GDCLASS(HeadsUpDisplay, Control);
|
||||
static void _bind_methods();
|
||||
static HeadsUpDisplay *singleton_instance;
|
||||
void on_child_entered(Node *node);
|
||||
void enter_tree();
|
||||
void exit_tree();
|
||||
|
||||
protected:
|
||||
void _notification(int what);
|
||||
|
||||
public:
|
||||
static HeadsUpDisplay *get_singleton();
|
||||
void set_reticle_visibility(bool visible);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "wave_survival/damage_box.h"
|
||||
#include "wave_survival/enemies/enemy_wretched.h"
|
||||
#include "wave_survival/enemy_body.h"
|
||||
#include "wave_survival/heads_up_display.h"
|
||||
#include "wave_survival/health_status.h"
|
||||
#include "wave_survival/hitbox.h"
|
||||
#include "wave_survival/hitscan_muzzle.h"
|
||||
|
|
@ -55,6 +56,7 @@ void initialize_wave_survival_module(ModuleInitializationLevel p_level) {
|
|||
GDREGISTER_CLASS(SoundEventPatchboard);
|
||||
GDREGISTER_CLASS(SoundEventNode);
|
||||
GDREGISTER_CLASS(MuzzleEffect);
|
||||
GDREGISTER_RUNTIME_CLASS(HeadsUpDisplay);
|
||||
|
||||
memnew(SoundEventPatchboard);
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton(SoundEventPatchboard::get_class_static(), SoundEventPatchboard::get_singleton()));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "rifle.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "wave_survival/heads_up_display.h"
|
||||
#include "wave_survival/hitscan_muzzle.h"
|
||||
#include "wave_survival/macros.h"
|
||||
#include "wave_survival/player_body.h"
|
||||
|
|
@ -17,11 +18,13 @@ void Rifle::_bind_methods() {
|
|||
void Rifle::queue_enter_alt() {
|
||||
get_anim()->queue("hip_to_aim");
|
||||
get_anim()->queue("aim");
|
||||
HeadsUpDisplay::get_singleton()->set_reticle_visibility(false);
|
||||
}
|
||||
|
||||
void Rifle::queue_exit_alt() {
|
||||
get_anim()->queue("aim_to_hip");
|
||||
get_anim()->queue("hip");
|
||||
HeadsUpDisplay::get_singleton()->set_reticle_visibility(true);
|
||||
}
|
||||
|
||||
void Rifle::queue_enter_run() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue