浏览代码

ability to set process on parent nodes on visibility notifier

Juan Linietsky 10 年之前
父节点
当前提交
ae28305d7c
共有 2 个文件被更改,包括 24 次插入0 次删除
  1. 22 0
      scene/2d/visibility_notifier_2d.cpp
  2. 2 0
      scene/2d/visibility_notifier_2d.h

+ 22 - 0
scene/2d/visibility_notifier_2d.cpp

@@ -155,6 +155,11 @@ void VisibilityEnabler2D::_screen_enter() {
 		_change_node_state(E->key(),true);
 	}
 
+	if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
+		get_parent()->set_fixed_process(true);
+	if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+		get_parent()->set_process(true);
+
 	visible=true;
 }
 
@@ -165,6 +170,11 @@ void VisibilityEnabler2D::_screen_exit(){
 		_change_node_state(E->key(),false);
 	}
 
+	if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
+		get_parent()->set_fixed_process(false);
+	if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+		get_parent()->set_process(false);
+
 	visible=false;
 }
 
@@ -235,6 +245,12 @@ void VisibilityEnabler2D::_notification(int p_what){
 
 		_find_nodes(from);
 
+		if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
+			get_parent()->set_fixed_process(false);
+		if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+			get_parent()->set_process(false);
+
+
 	}
 
 	if (p_what==NOTIFICATION_EXIT_TREE) {
@@ -317,10 +333,14 @@ void VisibilityEnabler2D::_bind_methods(){
 	ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_animations"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_ANIMATIONS );
 	ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/freeze_bodies"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_FREEZE_BODIES);
 	ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_particles"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_PARTICLES);
+	ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/process_parent"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PARENT_PROCESS);
+	ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/fixed_process_parent"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PARENT_FIXED_PROCESS);
 
 	BIND_CONSTANT( ENABLER_FREEZE_BODIES );
 	BIND_CONSTANT( ENABLER_PAUSE_ANIMATIONS );
 	BIND_CONSTANT( ENABLER_PAUSE_PARTICLES );
+	BIND_CONSTANT( ENABLER_PARENT_PROCESS );
+	BIND_CONSTANT( ENABLER_PARENT_FIXED_PROCESS );
 	BIND_CONSTANT( ENABLER_MAX);
 }
 
@@ -341,6 +361,8 @@ VisibilityEnabler2D::VisibilityEnabler2D() {
 
 	for(int i=0;i<ENABLER_MAX;i++)
 		enabler[i]=true;
+	enabler[ENABLER_PARENT_PROCESS]=false;
+	enabler[ENABLER_PARENT_FIXED_PROCESS]=false;
 
 	visible=false;
 

+ 2 - 0
scene/2d/visibility_notifier_2d.h

@@ -74,6 +74,8 @@ public:
 		ENABLER_PAUSE_ANIMATIONS,
 		ENABLER_FREEZE_BODIES,
 		ENABLER_PAUSE_PARTICLES,
+		ENABLER_PARENT_PROCESS,
+		ENABLER_PARENT_FIXED_PROCESS,
 		ENABLER_MAX
 	};