feat: added HUD object

This commit is contained in:
Sara 2025-08-10 20:53:27 +02:00
parent 3ceabd50eb
commit 7e3afd6c64
9 changed files with 64 additions and 20 deletions

View file

@ -1,9 +1,24 @@
#include "heads_up_display.h" #include "heads_up_display.h"
HeadsUpDisplay *HeadsUpDisplay::singleton_instance{ nullptr };
void HeadsUpDisplay::_bind_methods() { 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() { 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) { void HeadsUpDisplay::_notification(int what) {
@ -16,8 +31,18 @@ void HeadsUpDisplay::_notification(int what) {
case NOTIFICATION_ENTER_TREE: case NOTIFICATION_ENTER_TREE:
enter_tree(); enter_tree();
return; 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);
}
} }

View file

@ -6,12 +6,16 @@
class HeadsUpDisplay : public Control { class HeadsUpDisplay : public Control {
GDCLASS(HeadsUpDisplay, Control); GDCLASS(HeadsUpDisplay, Control);
static void _bind_methods(); static void _bind_methods();
static HeadsUpDisplay *singleton_instance;
void on_child_entered(Node *node); void on_child_entered(Node *node);
void enter_tree(); void enter_tree();
void exit_tree();
protected: protected:
void _notification(int what); void _notification(int what);
public: public:
static HeadsUpDisplay *get_singleton();
void set_reticle_visibility(bool visible); void set_reticle_visibility(bool visible);
private: private:

View file

@ -4,6 +4,7 @@
#include "wave_survival/damage_box.h" #include "wave_survival/damage_box.h"
#include "wave_survival/enemies/enemy_wretched.h" #include "wave_survival/enemies/enemy_wretched.h"
#include "wave_survival/enemy_body.h" #include "wave_survival/enemy_body.h"
#include "wave_survival/heads_up_display.h"
#include "wave_survival/health_status.h" #include "wave_survival/health_status.h"
#include "wave_survival/hitbox.h" #include "wave_survival/hitbox.h"
#include "wave_survival/hitscan_muzzle.h" #include "wave_survival/hitscan_muzzle.h"
@ -55,6 +56,7 @@ void initialize_wave_survival_module(ModuleInitializationLevel p_level) {
GDREGISTER_CLASS(SoundEventPatchboard); GDREGISTER_CLASS(SoundEventPatchboard);
GDREGISTER_CLASS(SoundEventNode); GDREGISTER_CLASS(SoundEventNode);
GDREGISTER_CLASS(MuzzleEffect); GDREGISTER_CLASS(MuzzleEffect);
GDREGISTER_RUNTIME_CLASS(HeadsUpDisplay);
memnew(SoundEventPatchboard); memnew(SoundEventPatchboard);
Engine::get_singleton()->add_singleton(Engine::Singleton(SoundEventPatchboard::get_class_static(), SoundEventPatchboard::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton(SoundEventPatchboard::get_class_static(), SoundEventPatchboard::get_singleton()));

View file

@ -1,5 +1,6 @@
#include "rifle.h" #include "rifle.h"
#include "scene/animation/animation_player.h" #include "scene/animation/animation_player.h"
#include "wave_survival/heads_up_display.h"
#include "wave_survival/hitscan_muzzle.h" #include "wave_survival/hitscan_muzzle.h"
#include "wave_survival/macros.h" #include "wave_survival/macros.h"
#include "wave_survival/player_body.h" #include "wave_survival/player_body.h"
@ -17,11 +18,13 @@ void Rifle::_bind_methods() {
void Rifle::queue_enter_alt() { void Rifle::queue_enter_alt() {
get_anim()->queue("hip_to_aim"); get_anim()->queue("hip_to_aim");
get_anim()->queue("aim"); get_anim()->queue("aim");
HeadsUpDisplay::get_singleton()->set_reticle_visibility(false);
} }
void Rifle::queue_exit_alt() { void Rifle::queue_exit_alt() {
get_anim()->queue("aim_to_hip"); get_anim()->queue("aim_to_hip");
get_anim()->queue("hip"); get_anim()->queue("hip");
HeadsUpDisplay::get_singleton()->set_reticle_visibility(true);
} }
void Rifle::queue_enter_run() { void Rifle::queue_enter_run() {

View file

@ -0,0 +1,24 @@
[gd_scene load_steps=2 format=3 uid="uid://dqo1pfy3r00ai"]
[ext_resource type="Texture2D" uid="uid://dc26l1ync7env" path="res://assets/gui/reticle.svg" id="1_1o2rr"]
[node name="HeadsUpDisplay" type="HeadsUpDisplay"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
mouse_behavior_recursive = 1
[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="TextureRect" type="TextureRect" parent="CenterContainer"]
layout_mode = 2
texture = ExtResource("1_1o2rr")

View file

@ -2,8 +2,8 @@
[ext_resource type="PackedScene" uid="uid://snjgu4yp5swd" path="res://objects/player.tscn" id="1_7vohb"] [ext_resource type="PackedScene" uid="uid://snjgu4yp5swd" path="res://objects/player.tscn" id="1_7vohb"]
[ext_resource type="PackedScene" uid="uid://dllho5nkq2smw" path="res://maps/industrial_area_map.tscn" id="2_hph0i"] [ext_resource type="PackedScene" uid="uid://dllho5nkq2smw" path="res://maps/industrial_area_map.tscn" id="2_hph0i"]
[ext_resource type="PackedScene" uid="uid://bt054d3ic71rf" path="res://menus/pause_menu.tscn" id="3_28e7h"] [ext_resource type="PackedScene" uid="uid://dqo1pfy3r00ai" path="res://guis/heads_up_display.tscn" id="3_7vohb"]
[ext_resource type="Texture2D" uid="uid://bwfkmwx6bd5u4" path="res://icon.svg" id="4_buohg"] [ext_resource type="PackedScene" uid="uid://bt054d3ic71rf" path="res://guis/pause_menu.tscn" id="3_28e7h"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ien74"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ien74"]
sky_horizon_color = Color(0.66224277, 0.6717428, 0.6867428, 1) sky_horizon_color = Color(0.66224277, 0.6717428, 0.6867428, 1)
@ -48,20 +48,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -20.417719, 1.340589, -8.0147
[node name="IndustrialAreaMap" parent="SubViewportContainer/SubViewport" instance=ExtResource("2_hph0i")] [node name="IndustrialAreaMap" parent="SubViewportContainer/SubViewport" instance=ExtResource("2_hph0i")]
[node name="HeadsUpDisplay" parent="." instance=ExtResource("3_7vohb")]
[node name="PauseMenu" parent="." instance=ExtResource("3_28e7h")] [node name="PauseMenu" parent="." instance=ExtResource("3_28e7h")]
[node name="CenterContainer" type="CenterContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
focus_behavior_recursive = 1
mouse_filter = 2
mouse_behavior_recursive = 1
[node name="TextureRect" type="TextureRect" parent="CenterContainer"]
custom_minimum_size = Vector2(10, 10)
layout_mode = 2
texture = ExtResource("4_buohg")
expand_mode = 4

View file

@ -3,7 +3,7 @@
[ext_resource type="PackedScene" uid="uid://snjgu4yp5swd" path="res://objects/player.tscn" id="1_6t4yh"] [ext_resource type="PackedScene" uid="uid://snjgu4yp5swd" path="res://objects/player.tscn" id="1_6t4yh"]
[ext_resource type="Material" uid="uid://b075rlo1f0e4u" path="res://assets/materials/greenish_grid.tres" id="1_ng1ul"] [ext_resource type="Material" uid="uid://b075rlo1f0e4u" path="res://assets/materials/greenish_grid.tres" id="1_ng1ul"]
[ext_resource type="PackedScene" uid="uid://5hg5eirw7v8n" path="res://objects/units/unit_4_wretched.tscn" id="3_7ng1a"] [ext_resource type="PackedScene" uid="uid://5hg5eirw7v8n" path="res://objects/units/unit_4_wretched.tscn" id="3_7ng1a"]
[ext_resource type="PackedScene" uid="uid://bt054d3ic71rf" path="res://menus/pause_menu.tscn" id="4_d7x8f"] [ext_resource type="PackedScene" uid="uid://bt054d3ic71rf" path="res://guis/pause_menu.tscn" id="4_d7x8f"]
[sub_resource type="NavigationMesh" id="NavigationMesh_7ng1a"] [sub_resource type="NavigationMesh" id="NavigationMesh_7ng1a"]
vertices = PackedVector3Array(-13.25, 0.24851608, -15, -11.5, 0.24851608, -15.25, -11.75, 0.24851608, -24.5, -24.5, 0.24851608, -24.5, -24.5, 0.24851608, -13.75, -13.25, 0.24851608, -13.5, -2, 0.24851608, -15.25, 2.25, 0.24851608, -15.5, 2.5, 0.24851608, -23.5, 12.25, 0.24851608, -23.5, 12.5, 0.24851608, -24.5, 14, 0.24851608, -23.25, 24.5, 0.24851608, -24.5, 14, 0.24851608, 19.5, 12.25, 0.24851608, 19.75, 12.5, 0.24851608, 24.5, 24.5, 0.24851608, 24.5, 3.25, 6.998516, -22.5, 3.25, 6.998516, 18.75, 13, 6.998516, 18.75, 13, 6.998516, -22.5, 2.25, 0.24851608, 6.75, 3, 0.24851608, 6.5, 3, 0.24851608, 6.25, 2.25, 0.24851608, 6, -1.5, 0.24851608, 5.25, -1.5, 0.24851608, 6, -1.5, 0.24851608, 11.25, 2.25, 0.24851608, 11.75, 2.25, 0.24851608, -8.75, 3, 0.24851608, -9, 3, 0.24851608, -9.25, 2.25, 0.24851608, -9.5, -1.5, 0.24851608, -10, -1.5, 0.24851608, -9.25, -1.5, 0.24851608, -15, -2.5, 0.24851608, -9.75, -2.5, 0.24851608, -9.5, -2.5, 0.24851608, 5.5, -2.5, 0.24851608, 5.75, -2, 0.24851608, 11.5, -12.25, 6.998516, -14.25, -12.25, 6.998516, 10.5, -2.5, 6.998516, 10.5, -2.5, 6.998516, -14.25, -24.5, 0.24851608, 10, -13.25, 0.24851608, 9.75, -10.75, 0.24851608, -6.5, -10.5, 0.24851608, -6.5, -10.25, 0.24851608, -7.25, -11, 0.24851608, -7.25, -3.25, 0.24851608, -10, -3.25, 0.24851608, -9.25, -11.75, 0.24851608, -13.5, -3.25, 0.24851608, -13.5, -3.25, 0.24851608, -7.25, -11.75, 0.24851608, -7.25, -11.75, 3.498516, -9.5, -12.25, 3.498516, -9, -11.75, 3.498516, -8.75, -10.75, 3.498516, -6.5, -10.5, 3.498516, -6.5, -10.25, 3.498516, -7.25, -11, 3.498516, -7.25, -11.75, 3.498516, -13.5, -3.25, 3.498516, -7.25, -3.25, 3.498516, -13.5, -11.75, 3.498516, -7.25, 3.75, 0.24851608, -8.75, 3.75, 0.24851608, -9.5, 3.75, 0.24851608, -13.25, 6, 0.24851608, -7, 12.5, 0.24851608, -7, 12.5, 0.24851608, -13.25, 5.25, 0.24851608, -7, 5.5, 0.24851608, -6.25, 5.75, 0.24851608, -6.25, 3.75, 0.24851608, -7, 5.5, 3.498516, -6.25, 5.75, 3.498516, -6.25, 6, 3.498516, -7, 5.25, 3.498516, -7, 12.5, 3.498516, -7, 12, 3.498516, -10.25, 7.75, 3.498516, -10.25, 12.5, 3.498516, -13.25, 7.5, 3.498516, -13.25, 3.75, 3.498516, -13.25, 3.75, 3.498516, -7, -10.25, 0.24851608, -6, -11, 0.24851608, -6, -11.75, 0.24851608, 2, -4.5, 0.24851608, 2, -3.25, 0.24851608, 2, -3.25, 0.24851608, -6, -5.25, 0.24851608, 2, -5, 0.24851608, 2.75, -4.75, 0.24851608, 2.75, -11.75, 0.24851608, -6, -10.25, 3.498516, -6, -11, 3.498516, -6, -11.75, 3.498516, 2, -4.5, 3.498516, 2, -3.25, 3.498516, 2, -3.25, 3.498516, -6, -5.25, 3.498516, 2, -5, 3.498516, 2.75, -4.75, 3.498516, 2.75, -11.75, 3.498516, -6, 11, 0.24851608, 2.5, 11.25, 0.24851608, 3.25, 11.5, 0.24851608, 3.25, 11.75, 0.24851608, 2.5, 12.5, 0.24851608, -5.5, 6, 0.24851608, -5.5, 3.75, 0.24851608, 2.5, 5.25, 0.24851608, -5.5, 3.75, 0.24851608, -5.5, 12.5, 0.24851608, 2.5, 10.75, 3.498516, 2.5, 11, 3.498516, 3.25, 11.25, 3.498516, 3.25, 11.5, 3.498516, 2.5, 12.5, 3.498516, -5.5, 6, 3.498516, -5.5, 3.75, 3.498516, 2.5, 5.25, 3.498516, -5.5, 3.75, 3.498516, -5.5, 12.5, 3.498516, 2.5, -3.25, 0.24851608, 5.25, -3.25, 0.24851608, 6, -4.5, 0.24851608, 3.75, -5.25, 0.24851608, 3.75, -3.25, 0.24851608, 10, -11.75, 0.24851608, 3.75, -11.75, 0.24851608, 10, -3.25, 0.24851608, 3.75, -5.25, 3.498516, 3.75, -4.5, 3.498516, 3.75, -11.75, 3.498516, 3.75, -11.75, 3.498516, 7.25, -7, 3.498516, 7, -6.75, 3.498516, 10, -3.25, 3.498516, 10, -3.25, 3.498516, 3.75, 12.5, 3.498516, 6, 13, 3.498516, 5.5, 12.5, 3.498516, 5.25, 10.75, 3.498516, 4, 11.5, 3.498516, 4, 12.5, 3.498516, 10.25, 3.75, 3.498516, 4, 3.75, 3.498516, 10.25, 12.5, 3.498516, 4, 3.75, 0.24851608, 6, 3.75, 0.24851608, 6.75, 11, 0.24851608, 4, 12.5, 0.24851608, 10.25, 11.75, 0.24851608, 4, 3.75, 0.24851608, 10.25, 3.75, 0.24851608, 4, 12.5, 0.24851608, 4, -13, 0.24851608, 11.5, -11, 0.24851608, 24.5, -11, 0.24851608, 11.5, -24.5, 0.24851608, 24.5, 3.75, 0.24851608, 24.5, 4, 0.24851608, 19.75, 2.25, 0.24851608, 19.5) vertices = PackedVector3Array(-13.25, 0.24851608, -15, -11.5, 0.24851608, -15.25, -11.75, 0.24851608, -24.5, -24.5, 0.24851608, -24.5, -24.5, 0.24851608, -13.75, -13.25, 0.24851608, -13.5, -2, 0.24851608, -15.25, 2.25, 0.24851608, -15.5, 2.5, 0.24851608, -23.5, 12.25, 0.24851608, -23.5, 12.5, 0.24851608, -24.5, 14, 0.24851608, -23.25, 24.5, 0.24851608, -24.5, 14, 0.24851608, 19.5, 12.25, 0.24851608, 19.75, 12.5, 0.24851608, 24.5, 24.5, 0.24851608, 24.5, 3.25, 6.998516, -22.5, 3.25, 6.998516, 18.75, 13, 6.998516, 18.75, 13, 6.998516, -22.5, 2.25, 0.24851608, 6.75, 3, 0.24851608, 6.5, 3, 0.24851608, 6.25, 2.25, 0.24851608, 6, -1.5, 0.24851608, 5.25, -1.5, 0.24851608, 6, -1.5, 0.24851608, 11.25, 2.25, 0.24851608, 11.75, 2.25, 0.24851608, -8.75, 3, 0.24851608, -9, 3, 0.24851608, -9.25, 2.25, 0.24851608, -9.5, -1.5, 0.24851608, -10, -1.5, 0.24851608, -9.25, -1.5, 0.24851608, -15, -2.5, 0.24851608, -9.75, -2.5, 0.24851608, -9.5, -2.5, 0.24851608, 5.5, -2.5, 0.24851608, 5.75, -2, 0.24851608, 11.5, -12.25, 6.998516, -14.25, -12.25, 6.998516, 10.5, -2.5, 6.998516, 10.5, -2.5, 6.998516, -14.25, -24.5, 0.24851608, 10, -13.25, 0.24851608, 9.75, -10.75, 0.24851608, -6.5, -10.5, 0.24851608, -6.5, -10.25, 0.24851608, -7.25, -11, 0.24851608, -7.25, -3.25, 0.24851608, -10, -3.25, 0.24851608, -9.25, -11.75, 0.24851608, -13.5, -3.25, 0.24851608, -13.5, -3.25, 0.24851608, -7.25, -11.75, 0.24851608, -7.25, -11.75, 3.498516, -9.5, -12.25, 3.498516, -9, -11.75, 3.498516, -8.75, -10.75, 3.498516, -6.5, -10.5, 3.498516, -6.5, -10.25, 3.498516, -7.25, -11, 3.498516, -7.25, -11.75, 3.498516, -13.5, -3.25, 3.498516, -7.25, -3.25, 3.498516, -13.5, -11.75, 3.498516, -7.25, 3.75, 0.24851608, -8.75, 3.75, 0.24851608, -9.5, 3.75, 0.24851608, -13.25, 6, 0.24851608, -7, 12.5, 0.24851608, -7, 12.5, 0.24851608, -13.25, 5.25, 0.24851608, -7, 5.5, 0.24851608, -6.25, 5.75, 0.24851608, -6.25, 3.75, 0.24851608, -7, 5.5, 3.498516, -6.25, 5.75, 3.498516, -6.25, 6, 3.498516, -7, 5.25, 3.498516, -7, 12.5, 3.498516, -7, 12, 3.498516, -10.25, 7.75, 3.498516, -10.25, 12.5, 3.498516, -13.25, 7.5, 3.498516, -13.25, 3.75, 3.498516, -13.25, 3.75, 3.498516, -7, -10.25, 0.24851608, -6, -11, 0.24851608, -6, -11.75, 0.24851608, 2, -4.5, 0.24851608, 2, -3.25, 0.24851608, 2, -3.25, 0.24851608, -6, -5.25, 0.24851608, 2, -5, 0.24851608, 2.75, -4.75, 0.24851608, 2.75, -11.75, 0.24851608, -6, -10.25, 3.498516, -6, -11, 3.498516, -6, -11.75, 3.498516, 2, -4.5, 3.498516, 2, -3.25, 3.498516, 2, -3.25, 3.498516, -6, -5.25, 3.498516, 2, -5, 3.498516, 2.75, -4.75, 3.498516, 2.75, -11.75, 3.498516, -6, 11, 0.24851608, 2.5, 11.25, 0.24851608, 3.25, 11.5, 0.24851608, 3.25, 11.75, 0.24851608, 2.5, 12.5, 0.24851608, -5.5, 6, 0.24851608, -5.5, 3.75, 0.24851608, 2.5, 5.25, 0.24851608, -5.5, 3.75, 0.24851608, -5.5, 12.5, 0.24851608, 2.5, 10.75, 3.498516, 2.5, 11, 3.498516, 3.25, 11.25, 3.498516, 3.25, 11.5, 3.498516, 2.5, 12.5, 3.498516, -5.5, 6, 3.498516, -5.5, 3.75, 3.498516, 2.5, 5.25, 3.498516, -5.5, 3.75, 3.498516, -5.5, 12.5, 3.498516, 2.5, -3.25, 0.24851608, 5.25, -3.25, 0.24851608, 6, -4.5, 0.24851608, 3.75, -5.25, 0.24851608, 3.75, -3.25, 0.24851608, 10, -11.75, 0.24851608, 3.75, -11.75, 0.24851608, 10, -3.25, 0.24851608, 3.75, -5.25, 3.498516, 3.75, -4.5, 3.498516, 3.75, -11.75, 3.498516, 3.75, -11.75, 3.498516, 7.25, -7, 3.498516, 7, -6.75, 3.498516, 10, -3.25, 3.498516, 10, -3.25, 3.498516, 3.75, 12.5, 3.498516, 6, 13, 3.498516, 5.5, 12.5, 3.498516, 5.25, 10.75, 3.498516, 4, 11.5, 3.498516, 4, 12.5, 3.498516, 10.25, 3.75, 3.498516, 4, 3.75, 3.498516, 10.25, 12.5, 3.498516, 4, 3.75, 0.24851608, 6, 3.75, 0.24851608, 6.75, 11, 0.24851608, 4, 12.5, 0.24851608, 10.25, 11.75, 0.24851608, 4, 3.75, 0.24851608, 10.25, 3.75, 0.24851608, 4, 12.5, 0.24851608, 4, -13, 0.24851608, 11.5, -11, 0.24851608, 24.5, -11, 0.24851608, 11.5, -24.5, 0.24851608, 24.5, 3.75, 0.24851608, 24.5, 4, 0.24851608, 19.75, 2.25, 0.24851608, 19.5)