generated from Persson-dev/Godot-Xmake
Fix SubViewport bug when opening the scene FirstPersonPlayer / Zombie (bone collision shape) / Bullet in the editor
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#include "BoneCollisionShape.h"
|
#include "BoneCollisionShape.h"
|
||||||
|
|
||||||
|
#include <godot_cpp/classes/engine.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
@@ -25,7 +27,13 @@ BoneCollisionShape::BoneCollisionShape() {}
|
|||||||
BoneCollisionShape::~BoneCollisionShape() {}
|
BoneCollisionShape::~BoneCollisionShape() {}
|
||||||
|
|
||||||
void BoneCollisionShape::_ready() {
|
void BoneCollisionShape::_ready() {
|
||||||
m_Crosshair = Object::cast_to<Crosshair>(get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("Crosshair"));
|
#if DEBUG_ENABLED
|
||||||
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
m_Crosshair = Object::cast_to<Crosshair>(
|
||||||
|
get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("Crosshair"));
|
||||||
DEV_ASSERT(m_Crosshair);
|
DEV_ASSERT(m_Crosshair);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,13 +55,13 @@ int BoneCollisionShape::get_body_damage() const {
|
|||||||
|
|
||||||
void BoneCollisionShape::headshot_hit() {
|
void BoneCollisionShape::headshot_hit() {
|
||||||
ERR_PRINT("zombie headshot hit");
|
ERR_PRINT("zombie headshot hit");
|
||||||
m_Crosshair->set_dot_color(Color(1,0,0,1));
|
m_Crosshair->set_dot_color(Color(1, 0, 0, 1));
|
||||||
emit_signal("a_ZombieHeadShotHit", m_HeadDamage);
|
emit_signal("a_ZombieHeadShotHit", m_HeadDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoneCollisionShape::bodyshot_hit() {
|
void BoneCollisionShape::bodyshot_hit() {
|
||||||
ERR_PRINT("zombie body hit");
|
ERR_PRINT("zombie body hit");
|
||||||
m_Crosshair->set_dot_color(Color(0,0,1,1));
|
m_Crosshair->set_dot_color(Color(0, 0, 1, 1));
|
||||||
emit_signal("a_ZombieBodyShotHit", m_BodyDamage);
|
emit_signal("a_ZombieBodyShotHit", m_BodyDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "Bullet.h"
|
#include "Bullet.h"
|
||||||
#include "BoneCollisionShape.h"
|
#include "BoneCollisionShape.h"
|
||||||
|
|
||||||
|
#include <godot_cpp/classes/engine.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
@@ -25,6 +27,11 @@ void Bullet::_ready() {
|
|||||||
m_Timer = memnew(Timer);
|
m_Timer = memnew(Timer);
|
||||||
add_child(m_Timer);
|
add_child(m_Timer);
|
||||||
m_Timer->connect("timeout", callable_mp(this, &Bullet::_on_timer_timeout));
|
m_Timer->connect("timeout", callable_mp(this, &Bullet::_on_timer_timeout));
|
||||||
|
#if DEBUG_ENABLED
|
||||||
|
if (Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
m_Crosshair = Object::cast_to<Crosshair>(get_parent()->find_child("Crosshair"));
|
m_Crosshair = Object::cast_to<Crosshair>(get_parent()->find_child("Crosshair"));
|
||||||
DEV_ASSERT(m_Crosshair);
|
DEV_ASSERT(m_Crosshair);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,19 @@ Crosshair::Crosshair() :
|
|||||||
Crosshair::~Crosshair() {}
|
Crosshair::~Crosshair() {}
|
||||||
|
|
||||||
void Crosshair::_ready() {
|
void Crosshair::_ready() {
|
||||||
m_Player = Object::cast_to<FirstPersonPlayer>(get_parent()->get_parent()->get_parent()->find_child("FirstPersonPlayer"));
|
// Catch the parent node directly without SubViewport problem in the editor thx to "recursivity" (if we go up the tree one more
|
||||||
|
// notch its bugging)
|
||||||
|
Node* root_node = get_parent();
|
||||||
|
while (root_node != nullptr && !root_node->is_class("FirstPersonPlayer")) {
|
||||||
|
root_node = root_node->get_parent();
|
||||||
|
}
|
||||||
|
if (root_node != nullptr && root_node->is_class("FirstPersonPlayer")) {
|
||||||
|
m_Player = Object::cast_to<FirstPersonPlayer>(root_node);
|
||||||
DEV_ASSERT(m_Player);
|
DEV_ASSERT(m_Player);
|
||||||
|
} else {
|
||||||
|
ERR_PRINT("FirstPersonPlayer not found in parent hierarchy.");
|
||||||
|
}
|
||||||
|
|
||||||
m_CrosshairLines = {Object::cast_to<Line2D>(find_child("Top")), Object::cast_to<Line2D>(find_child("Right")),
|
m_CrosshairLines = {Object::cast_to<Line2D>(find_child("Top")), Object::cast_to<Line2D>(find_child("Right")),
|
||||||
Object::cast_to<Line2D>(find_child("Bottom")), Object::cast_to<Line2D>(find_child("Left"))};
|
Object::cast_to<Line2D>(find_child("Bottom")), Object::cast_to<Line2D>(find_child("Left"))};
|
||||||
for (size_t i = 0; i < m_CrosshairLines.size(); i++) {
|
for (size_t i = 0; i < m_CrosshairLines.size(); i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user