1 /** 2 Enable certain nodes only when 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.visibilityenabler; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.visibilitynotifier; 24 import godot.spatial; 25 import godot.node; 26 /** 27 Enable certain nodes only when visible. 28 29 The VisibilityEnabler will disable $(D RigidBody) and $(D AnimationPlayer) nodes when they are not visible. It will only affect other nodes within the same scene as the VisibilityEnabler itself. 30 */ 31 @GodotBaseClass struct VisibilityEnabler 32 { 33 enum string _GODOT_internal_name = "VisibilityEnabler"; 34 public: 35 @nogc nothrow: 36 union { godot_object _godot_object; VisibilityNotifier _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct _classBinding 41 { 42 __gshared: 43 @GodotName("set_enabler") GodotMethod!(void, long, bool) setEnabler; 44 @GodotName("is_enabler_enabled") GodotMethod!(bool, long) isEnablerEnabled; 45 @GodotName("_node_removed") GodotMethod!(void, GodotObject) _nodeRemoved; 46 } 47 bool opEquals(in VisibilityEnabler other) const { return _godot_object.ptr is other._godot_object.ptr; } 48 VisibilityEnabler opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 49 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 50 mixin baseCasts; 51 static VisibilityEnabler _new() 52 { 53 static godot_class_constructor constructor; 54 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisibilityEnabler"); 55 if(constructor is null) return typeof(this).init; 56 return cast(VisibilityEnabler)(constructor()); 57 } 58 @disable new(size_t s); 59 /// 60 enum Enabler : int 61 { 62 /** 63 This enabler will pause $(D AnimationPlayer) nodes. 64 */ 65 enablerPauseAnimations = 0, 66 /** 67 This enabler will freeze $(D RigidBody) nodes. 68 */ 69 enablerFreezeBodies = 1, 70 /** 71 72 */ 73 enablerMax = 2, 74 } 75 /// 76 enum Constants : int 77 { 78 enablerPauseAnimations = 0, 79 enablerFreezeBodies = 1, 80 enablerMax = 2, 81 } 82 /** 83 84 */ 85 void setEnabler(in long enabler, in bool enabled) 86 { 87 checkClassBinding!(typeof(this))(); 88 ptrcall!(void)(_classBinding.setEnabler, _godot_object, enabler, enabled); 89 } 90 /** 91 92 */ 93 bool isEnablerEnabled(in long enabler) const 94 { 95 checkClassBinding!(typeof(this))(); 96 return ptrcall!(bool)(_classBinding.isEnablerEnabled, _godot_object, enabler); 97 } 98 /** 99 100 */ 101 void _nodeRemoved(GodotObject arg0) 102 { 103 Array _GODOT_args = Array.empty_array; 104 _GODOT_args.append(arg0); 105 String _GODOT_method_name = String("_node_removed"); 106 this.callv(_GODOT_method_name, _GODOT_args); 107 } 108 /** 109 If `true` $(D AnimationPlayer) nodes will be paused. 110 */ 111 @property bool pauseAnimations() 112 { 113 return isEnablerEnabled(0); 114 } 115 /// ditto 116 @property void pauseAnimations(bool v) 117 { 118 setEnabler(0, v); 119 } 120 /** 121 If `true` $(D RigidBody) nodes will be paused. 122 */ 123 @property bool freezeBodies() 124 { 125 return isEnablerEnabled(1); 126 } 127 /// ditto 128 @property void freezeBodies(bool v) 129 { 130 setEnabler(1, v); 131 } 132 }