1 /** 2 Plugin for adding custom property editors on inspector. 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.editorinspectorplugin; 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.reference; 24 import godot.control; 25 /** 26 Plugin for adding custom property editors on inspector. 27 28 These plugins allow adding custom property editors to $(D EditorInspector). 29 Plugins are registered via $(D EditorPlugin.addInspectorPlugin). 30 When an object is edited, the $(D canHandle) function is called and must return `true` if the object type is supported. 31 If supported, the function $(D parseBegin) will be called, allowing to place custom controls at the beginning of the class. 32 Subsequently, the $(D parseCategory) and $(D parseProperty) are called for every category and property. They offer the ability to add custom controls to the inspector too. 33 Finally, $(D parseEnd) will be called. 34 On each of these calls, the "add" functions can be called. 35 */ 36 @GodotBaseClass struct EditorInspectorPlugin 37 { 38 package(godot) enum string _GODOT_internal_name = "EditorInspectorPlugin"; 39 public: 40 @nogc nothrow: 41 union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; } 42 alias _GODOT_base this; 43 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 44 package(godot) __gshared bool _classBindingInitialized = false; 45 package(godot) static struct GDNativeClassBinding 46 { 47 __gshared: 48 @GodotName("add_custom_control") GodotMethod!(void, Control) addCustomControl; 49 @GodotName("add_property_editor") GodotMethod!(void, String, Control) addPropertyEditor; 50 @GodotName("add_property_editor_for_multiple_properties") GodotMethod!(void, String, PoolStringArray, Control) addPropertyEditorForMultipleProperties; 51 @GodotName("can_handle") GodotMethod!(bool, GodotObject) canHandle; 52 @GodotName("parse_begin") GodotMethod!(void, GodotObject) parseBegin; 53 @GodotName("parse_category") GodotMethod!(void, GodotObject, String) parseCategory; 54 @GodotName("parse_end") GodotMethod!(void) parseEnd; 55 @GodotName("parse_property") GodotMethod!(bool, GodotObject, long, String, long, String, long) parseProperty; 56 } 57 /// 58 pragma(inline, true) bool opEquals(in EditorInspectorPlugin other) const 59 { return _godot_object.ptr is other._godot_object.ptr; } 60 /// 61 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 62 { _godot_object.ptr = n; return null; } 63 /// 64 pragma(inline, true) bool opEquals(typeof(null) n) const 65 { return _godot_object.ptr is n; } 66 /// 67 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 68 mixin baseCasts; 69 /// Construct a new instance of EditorInspectorPlugin. 70 /// Note: use `memnew!EditorInspectorPlugin` instead. 71 static EditorInspectorPlugin _new() 72 { 73 static godot_class_constructor constructor; 74 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorInspectorPlugin"); 75 if(constructor is null) return typeof(this).init; 76 return cast(EditorInspectorPlugin)(constructor()); 77 } 78 @disable new(size_t s); 79 /** 80 Adds a custom control, which is not necessarily a property editor. 81 */ 82 void addCustomControl(Control control) 83 { 84 checkClassBinding!(typeof(this))(); 85 ptrcall!(void)(GDNativeClassBinding.addCustomControl, _godot_object, control); 86 } 87 /** 88 Adds a property editor for an individual property. The `editor` control must extend $(D EditorProperty). 89 */ 90 void addPropertyEditor(in String property, Control editor) 91 { 92 checkClassBinding!(typeof(this))(); 93 ptrcall!(void)(GDNativeClassBinding.addPropertyEditor, _godot_object, property, editor); 94 } 95 /** 96 Adds an editor that allows modifying multiple properties. The `editor` control must extend $(D EditorProperty). 97 */ 98 void addPropertyEditorForMultipleProperties(in String label, in PoolStringArray properties, Control editor) 99 { 100 checkClassBinding!(typeof(this))(); 101 ptrcall!(void)(GDNativeClassBinding.addPropertyEditorForMultipleProperties, _godot_object, label, properties, editor); 102 } 103 /** 104 Returns `true` if this object can be handled by this plugin. 105 */ 106 bool canHandle(GodotObject object) 107 { 108 Array _GODOT_args = Array.make(); 109 _GODOT_args.append(object); 110 String _GODOT_method_name = String("can_handle"); 111 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 112 } 113 /** 114 Called to allow adding controls at the beginning of the list. 115 */ 116 void parseBegin(GodotObject object) 117 { 118 Array _GODOT_args = Array.make(); 119 _GODOT_args.append(object); 120 String _GODOT_method_name = String("parse_begin"); 121 this.callv(_GODOT_method_name, _GODOT_args); 122 } 123 /** 124 Called to allow adding controls at the beginning of the category. 125 */ 126 void parseCategory(GodotObject object, in String category) 127 { 128 Array _GODOT_args = Array.make(); 129 _GODOT_args.append(object); 130 _GODOT_args.append(category); 131 String _GODOT_method_name = String("parse_category"); 132 this.callv(_GODOT_method_name, _GODOT_args); 133 } 134 /** 135 Called to allow adding controls at the end of the list. 136 */ 137 void parseEnd() 138 { 139 Array _GODOT_args = Array.make(); 140 String _GODOT_method_name = String("parse_end"); 141 this.callv(_GODOT_method_name, _GODOT_args); 142 } 143 /** 144 Called to allow adding property specific editors to the inspector. Usually these inherit $(D EditorProperty). Returning `true` removes the built-in editor for this property, otherwise allows to insert a custom editor before the built-in one. 145 */ 146 bool parseProperty(GodotObject object, in long type, in String path, in long hint, in String hint_text, in long usage) 147 { 148 Array _GODOT_args = Array.make(); 149 _GODOT_args.append(object); 150 _GODOT_args.append(type); 151 _GODOT_args.append(path); 152 _GODOT_args.append(hint); 153 _GODOT_args.append(hint_text); 154 _GODOT_args.append(usage); 155 String _GODOT_method_name = String("parse_property"); 156 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 157 } 158 }