1 /**
2 Enables certain nodes only when approximately visible.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.visibilityenabler2d;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.visibilitynotifier2d;
25 import godot.node;
26 /**
27 Enables certain nodes only when approximately visible.
28 
29 The VisibilityEnabler2D will disable $(D RigidBody2D), $(D AnimationPlayer), and other nodes when they are not visible. It will only affect nodes with the same root node as the VisibilityEnabler2D, and the root node itself.
30 If you just want to receive notifications, use $(D VisibilityNotifier2D) instead.
31 $(B Note:) For performance reasons, VisibilityEnabler2D uses an approximate heuristic with precision determined by $(D ProjectSettings.world/2d/cellSize). If you need precise visibility checking, use another method such as adding an $(D Area2D) node as a child of a $(D Camera2D) node.
32 $(B Note:) VisibilityEnabler2D will not affect nodes added after scene initialization.
33 */
34 @GodotBaseClass struct VisibilityEnabler2D
35 {
36 	package(godot) enum string _GODOT_internal_name = "VisibilityEnabler2D";
37 public:
38 @nogc nothrow:
39 	union { /** */ godot_object _godot_object; /** */ VisibilityNotifier2D _GODOT_base; }
40 	alias _GODOT_base this;
41 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
42 	package(godot) __gshared bool _classBindingInitialized = false;
43 	package(godot) static struct GDNativeClassBinding
44 	{
45 		__gshared:
46 		@GodotName("_node_removed") GodotMethod!(void, Node) _nodeRemoved;
47 		@GodotName("is_enabler_enabled") GodotMethod!(bool, long) isEnablerEnabled;
48 		@GodotName("set_enabler") GodotMethod!(void, long, bool) setEnabler;
49 	}
50 	/// 
51 	pragma(inline, true) bool opEquals(in VisibilityEnabler2D other) const
52 	{ return _godot_object.ptr is other._godot_object.ptr; }
53 	/// 
54 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
55 	{ _godot_object.ptr = n; return null; }
56 	/// 
57 	pragma(inline, true) bool opEquals(typeof(null) n) const
58 	{ return _godot_object.ptr is n; }
59 	/// 
60 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
61 	mixin baseCasts;
62 	/// Construct a new instance of VisibilityEnabler2D.
63 	/// Note: use `memnew!VisibilityEnabler2D` instead.
64 	static VisibilityEnabler2D _new()
65 	{
66 		static godot_class_constructor constructor;
67 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisibilityEnabler2D");
68 		if(constructor is null) return typeof(this).init;
69 		return cast(VisibilityEnabler2D)(constructor());
70 	}
71 	@disable new(size_t s);
72 	/// 
73 	enum Enabler : int
74 	{
75 		/**
76 		This enabler will pause $(D AnimationPlayer) nodes.
77 		*/
78 		enablerPauseAnimations = 0,
79 		/**
80 		This enabler will freeze $(D RigidBody2D) nodes.
81 		*/
82 		enablerFreezeBodies = 1,
83 		/**
84 		This enabler will stop $(D Particles2D) nodes.
85 		*/
86 		enablerPauseParticles = 2,
87 		/**
88 		This enabler will stop the parent's _process function.
89 		*/
90 		enablerParentProcess = 3,
91 		/**
92 		This enabler will stop the parent's _physics_process function.
93 		*/
94 		enablerParentPhysicsProcess = 4,
95 		/**
96 		This enabler will stop $(D AnimatedSprite) nodes animations.
97 		*/
98 		enablerPauseAnimatedSprites = 5,
99 		/**
100 		Represents the size of the $(D enabler) enum.
101 		*/
102 		enablerMax = 6,
103 	}
104 	/// 
105 	enum Constants : int
106 	{
107 		enablerPauseAnimations = 0,
108 		enablerFreezeBodies = 1,
109 		enablerPauseParticles = 2,
110 		enablerParentProcess = 3,
111 		enablerParentPhysicsProcess = 4,
112 		enablerPauseAnimatedSprites = 5,
113 		enablerMax = 6,
114 	}
115 	/**
116 	
117 	*/
118 	void _nodeRemoved(Node arg0)
119 	{
120 		Array _GODOT_args = Array.make();
121 		_GODOT_args.append(arg0);
122 		String _GODOT_method_name = String("_node_removed");
123 		this.callv(_GODOT_method_name, _GODOT_args);
124 	}
125 	/**
126 	Returns whether the enabler identified by given $(D enabler) constant is active.
127 	*/
128 	bool isEnablerEnabled(in long enabler) const
129 	{
130 		checkClassBinding!(typeof(this))();
131 		return ptrcall!(bool)(GDNativeClassBinding.isEnablerEnabled, _godot_object, enabler);
132 	}
133 	/**
134 	Sets active state of the enabler identified by given $(D enabler) constant.
135 	*/
136 	void setEnabler(in long enabler, in bool enabled)
137 	{
138 		checkClassBinding!(typeof(this))();
139 		ptrcall!(void)(GDNativeClassBinding.setEnabler, _godot_object, enabler, enabled);
140 	}
141 	/**
142 	If `true`, $(D RigidBody2D) nodes will be paused.
143 	*/
144 	@property bool freezeBodies()
145 	{
146 		return isEnablerEnabled(1);
147 	}
148 	/// ditto
149 	@property void freezeBodies(bool v)
150 	{
151 		setEnabler(1, v);
152 	}
153 	/**
154 	If `true`, $(D AnimatedSprite) nodes will be paused.
155 	*/
156 	@property bool pauseAnimatedSprites()
157 	{
158 		return isEnablerEnabled(5);
159 	}
160 	/// ditto
161 	@property void pauseAnimatedSprites(bool v)
162 	{
163 		setEnabler(5, v);
164 	}
165 	/**
166 	If `true`, $(D AnimationPlayer) nodes will be paused.
167 	*/
168 	@property bool pauseAnimations()
169 	{
170 		return isEnablerEnabled(0);
171 	}
172 	/// ditto
173 	@property void pauseAnimations(bool v)
174 	{
175 		setEnabler(0, v);
176 	}
177 	/**
178 	If `true`, $(D Particles2D) nodes will be paused.
179 	*/
180 	@property bool pauseParticles()
181 	{
182 		return isEnablerEnabled(2);
183 	}
184 	/// ditto
185 	@property void pauseParticles(bool v)
186 	{
187 		setEnabler(2, v);
188 	}
189 	/**
190 	If `true`, the parent's $(D Node._physicsProcess) will be stopped.
191 	*/
192 	@property bool physicsProcessParent()
193 	{
194 		return isEnablerEnabled(4);
195 	}
196 	/// ditto
197 	@property void physicsProcessParent(bool v)
198 	{
199 		setEnabler(4, v);
200 	}
201 	/**
202 	If `true`, the parent's $(D Node._process) will be stopped.
203 	*/
204 	@property bool processParent()
205 	{
206 		return isEnablerEnabled(3);
207 	}
208 	/// ditto
209 	@property void processParent(bool v)
210 	{
211 		setEnabler(3, v);
212 	}
213 }