Updated usage to PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY

Changing emitting or one shot disables autostart
This commit is contained in:
gamecoder-nz 2024-09-26 06:56:29 +12:00
parent 2855b9beef
commit fd5d4615be
4 changed files with 60 additions and 4 deletions

View file

@ -41,6 +41,13 @@ void CPUParticles2D::set_emitting(bool p_emitting) {
return;
}
if (p_emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
emitting = p_emitting;
if (emitting) {
active = true;
@ -77,6 +84,13 @@ void CPUParticles2D::set_lifetime(double p_lifetime) {
void CPUParticles2D::set_one_shot(bool p_one_shot) {
one_shot = p_one_shot;
if (emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
}
void CPUParticles2D::set_pre_process_time(double p_time) {
@ -543,7 +557,7 @@ void CPUParticles2D::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "autostart") {
if (emitting && !one_shot) {
p_property.usage = PROPERTY_USAGE_NONE;
p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY;
}
}

View file

@ -43,6 +43,12 @@
void GPUParticles2D::set_emitting(bool p_emitting) {
// Do not return even if `p_emitting == emitting` because `emitting` is just an approximation.
if (p_emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
if (p_emitting && one_shot) {
if (!active && !emitting) {
// Last cycle ended.
@ -78,6 +84,7 @@ void GPUParticles2D::set_amount(int p_amount) {
}
void GPUParticles2D::set_lifetime(double p_lifetime) {
ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0.");
lifetime = p_lifetime;
RS::get_singleton()->particles_set_lifetime(particles, lifetime);
@ -85,6 +92,12 @@ void GPUParticles2D::set_lifetime(double p_lifetime) {
void GPUParticles2D::set_one_shot(bool p_enable) {
one_shot = p_enable;
if (emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
RS::get_singleton()->particles_set_one_shot(particles, one_shot);
if (is_emitting()) {
@ -394,7 +407,7 @@ Ref<Texture2D> GPUParticles2D::get_texture() const {
void GPUParticles2D::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "autostart") {
if (emitting && !one_shot) {
p_property.usage = PROPERTY_USAGE_NONE;
p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY;
}
}
}

View file

@ -47,6 +47,13 @@ void CPUParticles3D::set_emitting(bool p_emitting) {
return;
}
if (p_emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
emitting = p_emitting;
if (emitting) {
active = true;
@ -90,6 +97,13 @@ void CPUParticles3D::set_lifetime(double p_lifetime) {
void CPUParticles3D::set_one_shot(bool p_one_shot) {
one_shot = p_one_shot;
if (emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
}
void CPUParticles3D::set_pre_process_time(double p_time) {
@ -581,7 +595,7 @@ void CPUParticles3D::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "autostart") {
if (emitting && !one_shot) {
p_property.usage = PROPERTY_USAGE_NONE;
p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY;
}
}
}

View file

@ -42,6 +42,13 @@ AABB GPUParticles3D::get_aabb() const {
void GPUParticles3D::set_emitting(bool p_emitting) {
// Do not return even if `p_emitting == emitting` because `emitting` is just an approximation.
if (p_emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
if (p_emitting && one_shot) {
if (!active && !emitting) {
// Last cycle ended.
@ -90,7 +97,15 @@ void GPUParticles3D::set_interp_to_end(float p_interp) {
}
void GPUParticles3D::set_one_shot(bool p_one_shot) {
one_shot = p_one_shot;
if (emitting && !one_shot) {
autostart = false;
notify_property_list_changed();
} else {
notify_property_list_changed();
}
RS::get_singleton()->particles_set_one_shot(particles, one_shot);
if (is_emitting()) {
@ -432,7 +447,7 @@ void GPUParticles3D::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "autostart") {
if (emitting && !one_shot) {
p_property.usage = PROPERTY_USAGE_NONE;
p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY;
}
}
}