1 /** 2 Singleton that manages $(D InputEventAction). 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.inputmap; 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.inputevent; 24 /** 25 Singleton that manages $(D InputEventAction). 26 27 Manages all $(D InputEventAction) which can be created/modified from the project settings menu $(B Project > Project Settings > Input Map) or in code with $(D addAction) and $(D actionAddEvent). See $(D Node._input). 28 */ 29 @GodotBaseClass struct InputMapSingleton 30 { 31 package(godot) enum string _GODOT_internal_name = "InputMap"; 32 public: 33 @nogc nothrow: 34 union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; } 35 alias _GODOT_base this; 36 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 37 package(godot) __gshared bool _classBindingInitialized = false; 38 package(godot) static struct GDNativeClassBinding 39 { 40 __gshared: 41 godot_object _singleton; 42 immutable char* _singletonName = "InputMap"; 43 @GodotName("action_add_event") GodotMethod!(void, String, InputEvent) actionAddEvent; 44 @GodotName("action_erase_event") GodotMethod!(void, String, InputEvent) actionEraseEvent; 45 @GodotName("action_erase_events") GodotMethod!(void, String) actionEraseEvents; 46 @GodotName("action_has_event") GodotMethod!(bool, String, InputEvent) actionHasEvent; 47 @GodotName("action_set_deadzone") GodotMethod!(void, String, double) actionSetDeadzone; 48 @GodotName("add_action") GodotMethod!(void, String, double) addAction; 49 @GodotName("erase_action") GodotMethod!(void, String) eraseAction; 50 @GodotName("event_is_action") GodotMethod!(bool, InputEvent, String) eventIsAction; 51 @GodotName("get_action_list") GodotMethod!(Array, String) getActionList; 52 @GodotName("get_actions") GodotMethod!(Array) getActions; 53 @GodotName("has_action") GodotMethod!(bool, String) hasAction; 54 @GodotName("load_from_globals") GodotMethod!(void) loadFromGlobals; 55 } 56 /// 57 pragma(inline, true) bool opEquals(in InputMapSingleton other) const 58 { return _godot_object.ptr is other._godot_object.ptr; } 59 /// 60 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 61 { _godot_object.ptr = n; return null; } 62 /// 63 pragma(inline, true) bool opEquals(typeof(null) n) const 64 { return _godot_object.ptr is n; } 65 /// 66 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 67 mixin baseCasts; 68 /// Construct a new instance of InputMapSingleton. 69 /// Note: use `memnew!InputMapSingleton` instead. 70 static InputMapSingleton _new() 71 { 72 static godot_class_constructor constructor; 73 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("InputMap"); 74 if(constructor is null) return typeof(this).init; 75 return cast(InputMapSingleton)(constructor()); 76 } 77 @disable new(size_t s); 78 /** 79 Adds an $(D InputEvent) to an action. This $(D InputEvent) will trigger the action. 80 */ 81 void actionAddEvent(in String action, InputEvent event) 82 { 83 checkClassBinding!(typeof(this))(); 84 ptrcall!(void)(GDNativeClassBinding.actionAddEvent, _godot_object, action, event); 85 } 86 /** 87 Removes an $(D InputEvent) from an action. 88 */ 89 void actionEraseEvent(in String action, InputEvent event) 90 { 91 checkClassBinding!(typeof(this))(); 92 ptrcall!(void)(GDNativeClassBinding.actionEraseEvent, _godot_object, action, event); 93 } 94 /** 95 Removes all events from an action. 96 */ 97 void actionEraseEvents(in String action) 98 { 99 checkClassBinding!(typeof(this))(); 100 ptrcall!(void)(GDNativeClassBinding.actionEraseEvents, _godot_object, action); 101 } 102 /** 103 Returns `true` if the action has the given $(D InputEvent) associated with it. 104 */ 105 bool actionHasEvent(in String action, InputEvent event) 106 { 107 checkClassBinding!(typeof(this))(); 108 return ptrcall!(bool)(GDNativeClassBinding.actionHasEvent, _godot_object, action, event); 109 } 110 /** 111 Sets a deadzone value for the action. 112 */ 113 void actionSetDeadzone(in String action, in double deadzone) 114 { 115 checkClassBinding!(typeof(this))(); 116 ptrcall!(void)(GDNativeClassBinding.actionSetDeadzone, _godot_object, action, deadzone); 117 } 118 /** 119 Adds an empty action to the $(D InputMap) with a configurable `deadzone`. 120 An $(D InputEvent) can then be added to this action with $(D actionAddEvent). 121 */ 122 void addAction(in String action, in double deadzone = 0.5) 123 { 124 checkClassBinding!(typeof(this))(); 125 ptrcall!(void)(GDNativeClassBinding.addAction, _godot_object, action, deadzone); 126 } 127 /** 128 Removes an action from the $(D InputMap). 129 */ 130 void eraseAction(in String action) 131 { 132 checkClassBinding!(typeof(this))(); 133 ptrcall!(void)(GDNativeClassBinding.eraseAction, _godot_object, action); 134 } 135 /** 136 Returns `true` if the given event is part of an existing action. This method ignores keyboard modifiers if the given $(D InputEvent) is not pressed (for proper release detection). See $(D actionHasEvent) if you don't want this behavior. 137 */ 138 bool eventIsAction(InputEvent event, in String action) const 139 { 140 checkClassBinding!(typeof(this))(); 141 return ptrcall!(bool)(GDNativeClassBinding.eventIsAction, _godot_object, event, action); 142 } 143 /** 144 Returns an array of $(D InputEvent)s associated with a given action. 145 */ 146 Array getActionList(in String action) 147 { 148 checkClassBinding!(typeof(this))(); 149 return ptrcall!(Array)(GDNativeClassBinding.getActionList, _godot_object, action); 150 } 151 /** 152 Returns an array of all actions in the $(D InputMap). 153 */ 154 Array getActions() 155 { 156 checkClassBinding!(typeof(this))(); 157 return ptrcall!(Array)(GDNativeClassBinding.getActions, _godot_object); 158 } 159 /** 160 Returns `true` if the $(D InputMap) has a registered action with the given name. 161 */ 162 bool hasAction(in String action) const 163 { 164 checkClassBinding!(typeof(this))(); 165 return ptrcall!(bool)(GDNativeClassBinding.hasAction, _godot_object, action); 166 } 167 /** 168 Clears all $(D InputEventAction) in the $(D InputMap) and load it anew from $(D ProjectSettings). 169 */ 170 void loadFromGlobals() 171 { 172 checkClassBinding!(typeof(this))(); 173 ptrcall!(void)(GDNativeClassBinding.loadFromGlobals, _godot_object); 174 } 175 } 176 /// Returns: the InputMapSingleton 177 @property @nogc nothrow pragma(inline, true) 178 InputMapSingleton InputMap() 179 { 180 checkClassBinding!InputMapSingleton(); 181 return InputMapSingleton(InputMapSingleton.GDNativeClassBinding._singleton); 182 }