2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visibility_notifier_2d.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "visibility_notifier_2d.h"
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/engine.h"
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "gpu_particles_2d.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/2d/animated_sprite_2d.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/2d/physics_body_2d.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/animation/animation_player.h"
|
2020-03-04 02:51:12 +01:00
|
|
|
#include "scene/main/window.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/scene_string_names.h"
|
|
|
|
|
2019-10-21 23:37:07 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
Rect2 VisibilityNotifier2D::_edit_get_rect() const {
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisibilityNotifier2D::_edit_use_rect() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) {
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(viewports.has(p_viewport));
|
|
|
|
viewports.insert(p_viewport);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
|
2016-08-09 00:04:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-09 00:04:12 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (viewports.size() == 1) {
|
2017-01-12 04:51:08 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->screen_entered);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
_screen_enter();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->viewport_entered, p_viewport);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) {
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!viewports.has(p_viewport));
|
|
|
|
viewports.erase(p_viewport);
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
|
2016-08-09 00:04:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-09 00:04:12 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->viewport_exited, p_viewport);
|
|
|
|
if (viewports.size() == 0) {
|
2017-01-12 04:51:08 +01:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->screen_exited);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_screen_exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) {
|
|
|
|
rect = p_rect;
|
2015-04-02 12:22:17 +02:00
|
|
|
if (is_inside_tree()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
get_world_2d()->_update_notifier(this, get_global_transform().xform(rect));
|
2017-08-19 01:02:56 +02:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2015-04-02 12:22:17 +02:00
|
|
|
update();
|
|
|
|
item_rect_changed();
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_change_notify("rect");
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 VisibilityNotifier2D::get_rect() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisibilityNotifier2D::_notification(int p_what) {
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_what) {
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2014-02-10 02:10:30 +01:00
|
|
|
//get_world_2d()->
|
2017-03-05 16:44:50 +01:00
|
|
|
get_world_2d()->_register_notifier(this, get_global_transform().xform(rect));
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
|
|
|
//get_world_2d()->
|
2017-03-05 16:44:50 +01:00
|
|
|
get_world_2d()->_update_notifier(this, get_global_transform().xform(rect));
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_DRAW: {
|
2017-08-19 01:02:56 +02:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
draw_rect(rect, Color(1, 0.5, 1, 0.2));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
} break;
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2014-02-10 02:10:30 +01:00
|
|
|
get_world_2d()->_remove_notifier(this);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisibilityNotifier2D::is_on_screen() const {
|
2017-03-05 16:44:50 +01:00
|
|
|
return viewports.size() > 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityNotifier2D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibilityNotifier2D::set_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rect"), &VisibilityNotifier2D::get_rect);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier2D::is_on_screen);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), "set_rect", "get_rect");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("viewport_entered", PropertyInfo(Variant::OBJECT, "viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport")));
|
|
|
|
ADD_SIGNAL(MethodInfo("viewport_exited", PropertyInfo(Variant::OBJECT, "viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport")));
|
|
|
|
ADD_SIGNAL(MethodInfo("screen_entered"));
|
|
|
|
ADD_SIGNAL(MethodInfo("screen_exited"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VisibilityNotifier2D::VisibilityNotifier2D() {
|
2017-03-05 16:44:50 +01:00
|
|
|
rect = Rect2(-10, -10, 20, 20);
|
2017-01-13 00:35:46 +01:00
|
|
|
set_notify_transform(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
|
|
|
void VisibilityEnabler2D::_screen_enter() {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
|
|
|
|
_change_node_state(E->key(), true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) {
|
2017-09-30 16:19:07 +02:00
|
|
|
get_parent()->set_physics_process(true);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) {
|
2015-06-22 20:43:13 +02:00
|
|
|
get_parent()->set_process(true);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-06-22 20:43:13 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
visible = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityEnabler2D::_screen_exit() {
|
|
|
|
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
|
|
|
|
_change_node_state(E->key(), false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) {
|
2017-09-30 16:19:07 +02:00
|
|
|
get_parent()->set_physics_process(false);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) {
|
2015-06-22 20:43:13 +02:00
|
|
|
get_parent()->set_process(false);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-06-22 20:43:13 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
visible = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityEnabler2D::_find_nodes(Node *p_node) {
|
|
|
|
bool add = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant meta;
|
|
|
|
|
2020-03-17 16:44:48 +01:00
|
|
|
{
|
2017-08-24 22:58:51 +02:00
|
|
|
RigidBody2D *rb2d = Object::cast_to<RigidBody2D>(p_node);
|
2018-11-20 03:06:02 +01:00
|
|
|
if (rb2d && ((rb2d->get_mode() == RigidBody2D::MODE_CHARACTER || rb2d->get_mode() == RigidBody2D::MODE_RIGID))) {
|
2017-03-05 16:44:50 +01:00
|
|
|
add = true;
|
|
|
|
meta = rb2d->get_mode();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:44:48 +01:00
|
|
|
{
|
2017-08-24 22:58:51 +02:00
|
|
|
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (ap) {
|
2017-03-05 16:44:50 +01:00
|
|
|
add = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:44:48 +01:00
|
|
|
{
|
2020-03-26 22:49:16 +01:00
|
|
|
AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node);
|
2016-05-15 04:48:23 +02:00
|
|
|
if (as) {
|
2017-03-05 16:44:50 +01:00
|
|
|
add = true;
|
2016-05-15 04:48:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:44:48 +01:00
|
|
|
{
|
2020-03-27 08:44:44 +01:00
|
|
|
GPUParticles2D *ps = Object::cast_to<GPUParticles2D>(p_node);
|
2015-03-09 06:34:56 +01:00
|
|
|
if (ps) {
|
2017-03-05 16:44:50 +01:00
|
|
|
add = true;
|
2015-03-09 06:34:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (add) {
|
2020-02-21 23:26:13 +01:00
|
|
|
p_node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed), varray(p_node), CONNECT_ONESHOT);
|
2017-03-05 16:44:50 +01:00
|
|
|
nodes[p_node] = meta;
|
|
|
|
_change_node_state(p_node, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
Node *c = p_node->get_child(i);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c->get_filename() != String()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
continue; //skip, instance
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_find_nodes(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityEnabler2D::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Node *from = this;
|
|
|
|
//find where current scene starts
|
2020-05-14 16:41:43 +02:00
|
|
|
while (from->get_parent() && from->get_filename() == String()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
from = from->get_parent();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_find_nodes(from);
|
|
|
|
|
2019-09-03 20:22:22 +02:00
|
|
|
// We need to defer the call of set_process and set_physics_process,
|
|
|
|
// otherwise they are overwritten inside NOTIFICATION_READY.
|
|
|
|
// We can't use call_deferred, because it happens after a physics frame.
|
|
|
|
// The ready signal works as it's emitted immediately after NOTIFICATION_READY.
|
|
|
|
|
|
|
|
if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) {
|
|
|
|
get_parent()->connect(SceneStringNames::get_singleton()->ready,
|
|
|
|
callable_mp(get_parent(), &Node::set_physics_process), varray(false), CONNECT_ONESHOT);
|
|
|
|
}
|
|
|
|
if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) {
|
|
|
|
get_parent()->connect(SceneStringNames::get_singleton()->ready,
|
|
|
|
callable_mp(get_parent(), &Node::set_process), varray(false), CONNECT_ONESHOT);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_EXIT_TREE) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!visible) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_change_node_state(E->key(), true);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-21 23:26:13 +01:00
|
|
|
E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nodes.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) {
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!nodes.has(p_node));
|
|
|
|
|
2020-03-17 16:44:48 +01:00
|
|
|
if (enabler[ENABLER_FREEZE_BODIES]) {
|
2017-08-24 22:58:51 +02:00
|
|
|
RigidBody2D *rb = Object::cast_to<RigidBody2D>(p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (rb) {
|
2016-07-08 00:32:28 +02:00
|
|
|
rb->set_sleeping(!p_enabled);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 16:44:48 +01:00
|
|
|
if (enabler[ENABLER_PAUSE_ANIMATIONS]) {
|
2017-08-24 22:58:51 +02:00
|
|
|
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (ap) {
|
|
|
|
ap->set_active(p_enabled);
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 16:44:48 +01:00
|
|
|
|
|
|
|
if (enabler[ENABLER_PAUSE_ANIMATED_SPRITES]) {
|
2020-03-26 22:49:16 +01:00
|
|
|
AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node);
|
2016-05-15 04:48:23 +02:00
|
|
|
|
|
|
|
if (as) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_enabled) {
|
2016-05-15 04:48:23 +02:00
|
|
|
as->play();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2016-05-15 04:48:23 +02:00
|
|
|
as->stop();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-05-15 04:48:23 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-17 16:44:48 +01:00
|
|
|
if (enabler[ENABLER_PAUSE_PARTICLES]) {
|
2020-03-27 08:44:44 +01:00
|
|
|
GPUParticles2D *ps = Object::cast_to<GPUParticles2D>(p_node);
|
2015-03-09 06:34:56 +01:00
|
|
|
|
|
|
|
if (ps) {
|
|
|
|
ps->set_emitting(p_enabled);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityEnabler2D::_node_removed(Node *p_node) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!visible) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_change_node_state(p_node, true);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
nodes.erase(p_node);
|
|
|
|
}
|
|
|
|
|
2016-05-17 23:27:15 +02:00
|
|
|
String VisibilityEnabler2D::get_configuration_warning() const {
|
2016-05-18 07:29:53 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
if (is_inside_tree() && get_parent() && (get_parent()->get_filename() == String() && get_parent() != get_tree()->get_edited_scene_root())) {
|
2019-07-09 00:17:04 +02:00
|
|
|
return TTR("VisibilityEnabler2D works best when used with the edited scene root directly as parent.");
|
2016-05-17 23:27:15 +02:00
|
|
|
}
|
2016-05-18 07:29:53 +02:00
|
|
|
#endif
|
2016-05-17 23:27:15 +02:00
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityEnabler2D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler2D::set_enabler);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler2D::is_enabler_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("_node_removed"), &VisibilityEnabler2D::_node_removed);
|
|
|
|
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_particles"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_PARTICLES);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animated_sprites"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATED_SPRITES);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "process_parent"), "set_enabler", "is_enabler_enabled", ENABLER_PARENT_PROCESS);
|
2017-09-30 16:19:07 +02:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "physics_process_parent"), "set_enabler", "is_enabler_enabled", ENABLER_PARENT_PHYSICS_PROCESS);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_PAUSE_ANIMATIONS);
|
2017-10-21 20:58:02 +02:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_FREEZE_BODIES);
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_PAUSE_PARTICLES);
|
|
|
|
BIND_ENUM_CONSTANT(ENABLER_PARENT_PROCESS);
|
2017-09-30 16:19:07 +02:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_PARENT_PHYSICS_PROCESS);
|
2017-10-21 20:58:02 +02:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_PAUSE_ANIMATED_SPRITES);
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(ENABLER_MAX);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisibilityEnabler2D::set_enabler(Enabler p_enabler, bool p_enable) {
|
|
|
|
ERR_FAIL_INDEX(p_enabler, ENABLER_MAX);
|
|
|
|
enabler[p_enabler] = p_enable;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
return enabler[p_enabler];
|
|
|
|
}
|
|
|
|
|
|
|
|
VisibilityEnabler2D::VisibilityEnabler2D() {
|
2020-05-14 16:41:43 +02:00
|
|
|
for (int i = 0; i < ENABLER_MAX; i++) {
|
2017-03-05 16:44:50 +01:00
|
|
|
enabler[i] = true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
enabler[ENABLER_PARENT_PROCESS] = false;
|
2017-09-30 16:19:07 +02:00
|
|
|
enabler[ENABLER_PARENT_PHYSICS_PROCESS] = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
visible = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|