1 /**
2 Godot editor's interface.
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.editorinterface;
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.node;
24 import godot.resource;
25 import godot.control;
26 import godot.editorsettings;
27 import godot.filesystemdock;
28 import godot.editorinspector;
29 import godot.editorfilesystem;
30 import godot.editorresourcepreview;
31 import godot.scripteditor;
32 import godot.editorselection;
33 /**
34 Godot editor's interface.
35 
36 EditorInterface gives you control over Godot editor's window. It allows customizing the window, saving and (re-)loading scenes, rendering mesh previews, inspecting and editing resources and objects, and provides access to $(D EditorSettings), $(D EditorFileSystem), $(D EditorResourcePreview), $(D ScriptEditor), the editor viewport, and information about scenes.
37 $(B Note:) This class shouldn't be instantiated directly. Instead, access the singleton using $(D EditorPlugin.getEditorInterface).
38 */
39 @GodotBaseClass struct EditorInterface
40 {
41 	package(godot) enum string _GODOT_internal_name = "EditorInterface";
42 public:
43 @nogc nothrow:
44 	union { /** */ godot_object _godot_object; /** */ Node _GODOT_base; }
45 	alias _GODOT_base this;
46 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
47 	package(godot) __gshared bool _classBindingInitialized = false;
48 	package(godot) static struct GDNativeClassBinding
49 	{
50 		__gshared:
51 		@GodotName("edit_node") GodotMethod!(void, Node) editNode;
52 		@GodotName("edit_resource") GodotMethod!(void, Resource) editResource;
53 		@GodotName("get_base_control") GodotMethod!(Control) getBaseControl;
54 		@GodotName("get_current_path") GodotMethod!(String) getCurrentPath;
55 		@GodotName("get_edited_scene_root") GodotMethod!(Node) getEditedSceneRoot;
56 		@GodotName("get_editor_scale") GodotMethod!(double) getEditorScale;
57 		@GodotName("get_editor_settings") GodotMethod!(EditorSettings) getEditorSettings;
58 		@GodotName("get_editor_viewport") GodotMethod!(Control) getEditorViewport;
59 		@GodotName("get_file_system_dock") GodotMethod!(FileSystemDock) getFileSystemDock;
60 		@GodotName("get_inspector") GodotMethod!(EditorInspector) getInspector;
61 		@GodotName("get_open_scenes") GodotMethod!(Array) getOpenScenes;
62 		@GodotName("get_playing_scene") GodotMethod!(String) getPlayingScene;
63 		@GodotName("get_resource_filesystem") GodotMethod!(EditorFileSystem) getResourceFilesystem;
64 		@GodotName("get_resource_previewer") GodotMethod!(EditorResourcePreview) getResourcePreviewer;
65 		@GodotName("get_script_editor") GodotMethod!(ScriptEditor) getScriptEditor;
66 		@GodotName("get_selected_path") GodotMethod!(String) getSelectedPath;
67 		@GodotName("get_selection") GodotMethod!(EditorSelection) getSelection;
68 		@GodotName("inspect_object") GodotMethod!(void, GodotObject, String, bool) inspectObject;
69 		@GodotName("is_distraction_free_mode_enabled") GodotMethod!(bool) isDistractionFreeModeEnabled;
70 		@GodotName("is_playing_scene") GodotMethod!(bool) isPlayingScene;
71 		@GodotName("is_plugin_enabled") GodotMethod!(bool, String) isPluginEnabled;
72 		@GodotName("make_mesh_previews") GodotMethod!(Array, Array, long) makeMeshPreviews;
73 		@GodotName("open_scene_from_path") GodotMethod!(void, String) openSceneFromPath;
74 		@GodotName("play_current_scene") GodotMethod!(void) playCurrentScene;
75 		@GodotName("play_custom_scene") GodotMethod!(void, String) playCustomScene;
76 		@GodotName("play_main_scene") GodotMethod!(void) playMainScene;
77 		@GodotName("reload_scene_from_path") GodotMethod!(void, String) reloadSceneFromPath;
78 		@GodotName("save_scene") GodotMethod!(GodotError) saveScene;
79 		@GodotName("save_scene_as") GodotMethod!(void, String, bool) saveSceneAs;
80 		@GodotName("select_file") GodotMethod!(void, String) selectFile;
81 		@GodotName("set_distraction_free_mode") GodotMethod!(void, bool) setDistractionFreeMode;
82 		@GodotName("set_main_screen_editor") GodotMethod!(void, String) setMainScreenEditor;
83 		@GodotName("set_plugin_enabled") GodotMethod!(void, String, bool) setPluginEnabled;
84 		@GodotName("stop_playing_scene") GodotMethod!(void) stopPlayingScene;
85 	}
86 	/// 
87 	pragma(inline, true) bool opEquals(in EditorInterface other) const
88 	{ return _godot_object.ptr is other._godot_object.ptr; }
89 	/// 
90 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
91 	{ _godot_object.ptr = n; return null; }
92 	/// 
93 	pragma(inline, true) bool opEquals(typeof(null) n) const
94 	{ return _godot_object.ptr is n; }
95 	/// 
96 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
97 	mixin baseCasts;
98 	/// Construct a new instance of EditorInterface.
99 	/// Note: use `memnew!EditorInterface` instead.
100 	static EditorInterface _new()
101 	{
102 		static godot_class_constructor constructor;
103 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorInterface");
104 		if(constructor is null) return typeof(this).init;
105 		return cast(EditorInterface)(constructor());
106 	}
107 	@disable new(size_t s);
108 	/**
109 	Edits the given $(D Node). The node will be also selected if it's inside the scene tree.
110 	*/
111 	void editNode(Node node)
112 	{
113 		checkClassBinding!(typeof(this))();
114 		ptrcall!(void)(GDNativeClassBinding.editNode, _godot_object, node);
115 	}
116 	/**
117 	Edits the given $(D Resource).
118 	*/
119 	void editResource(Resource resource)
120 	{
121 		checkClassBinding!(typeof(this))();
122 		ptrcall!(void)(GDNativeClassBinding.editResource, _godot_object, resource);
123 	}
124 	/**
125 	Returns the main container of Godot editor's window. For example, you can use it to retrieve the size of the container and place your controls accordingly.
126 	*/
127 	Control getBaseControl()
128 	{
129 		checkClassBinding!(typeof(this))();
130 		return ptrcall!(Control)(GDNativeClassBinding.getBaseControl, _godot_object);
131 	}
132 	/**
133 	Returns the current path being viewed in the $(D FileSystemDock).
134 	*/
135 	String getCurrentPath() const
136 	{
137 		checkClassBinding!(typeof(this))();
138 		return ptrcall!(String)(GDNativeClassBinding.getCurrentPath, _godot_object);
139 	}
140 	/**
141 	Returns the edited (current) scene's root $(D Node).
142 	*/
143 	Node getEditedSceneRoot()
144 	{
145 		checkClassBinding!(typeof(this))();
146 		return ptrcall!(Node)(GDNativeClassBinding.getEditedSceneRoot, _godot_object);
147 	}
148 	/**
149 	Returns the actual scale of the editor UI (`1.0` being 100% scale). This can be used to adjust position and dimensions of the UI added by plugins.
150 	$(B Note:) This value is set via the `interface/editor/display_scale` and `interface/editor/custom_display_scale` editor settings. Editor must be restarted for changes to be properly applied.
151 	*/
152 	double getEditorScale() const
153 	{
154 		checkClassBinding!(typeof(this))();
155 		return ptrcall!(double)(GDNativeClassBinding.getEditorScale, _godot_object);
156 	}
157 	/**
158 	Returns the editor's $(D EditorSettings) instance.
159 	*/
160 	Ref!EditorSettings getEditorSettings()
161 	{
162 		checkClassBinding!(typeof(this))();
163 		return ptrcall!(EditorSettings)(GDNativeClassBinding.getEditorSettings, _godot_object);
164 	}
165 	/**
166 	Returns the main editor control. Use this as a parent for main screens.
167 	$(B Note:) This returns the main editor control containing the whole editor, not the 2D or 3D viewports specifically.
168 	*/
169 	Control getEditorViewport()
170 	{
171 		checkClassBinding!(typeof(this))();
172 		return ptrcall!(Control)(GDNativeClassBinding.getEditorViewport, _godot_object);
173 	}
174 	/**
175 	Returns the editor's $(D FileSystemDock) instance.
176 	*/
177 	FileSystemDock getFileSystemDock()
178 	{
179 		checkClassBinding!(typeof(this))();
180 		return ptrcall!(FileSystemDock)(GDNativeClassBinding.getFileSystemDock, _godot_object);
181 	}
182 	/**
183 	Returns the editor's $(D EditorInspector) instance.
184 	*/
185 	EditorInspector getInspector() const
186 	{
187 		checkClassBinding!(typeof(this))();
188 		return ptrcall!(EditorInspector)(GDNativeClassBinding.getInspector, _godot_object);
189 	}
190 	/**
191 	Returns an $(D Array) with the file paths of the currently opened scenes.
192 	*/
193 	Array getOpenScenes() const
194 	{
195 		checkClassBinding!(typeof(this))();
196 		return ptrcall!(Array)(GDNativeClassBinding.getOpenScenes, _godot_object);
197 	}
198 	/**
199 	Returns the name of the scene that is being played. If no scene is currently being played, returns an empty string.
200 	*/
201 	String getPlayingScene() const
202 	{
203 		checkClassBinding!(typeof(this))();
204 		return ptrcall!(String)(GDNativeClassBinding.getPlayingScene, _godot_object);
205 	}
206 	/**
207 	Returns the editor's $(D EditorFileSystem) instance.
208 	*/
209 	EditorFileSystem getResourceFilesystem()
210 	{
211 		checkClassBinding!(typeof(this))();
212 		return ptrcall!(EditorFileSystem)(GDNativeClassBinding.getResourceFilesystem, _godot_object);
213 	}
214 	/**
215 	Returns the editor's $(D EditorResourcePreview) instance.
216 	*/
217 	EditorResourcePreview getResourcePreviewer()
218 	{
219 		checkClassBinding!(typeof(this))();
220 		return ptrcall!(EditorResourcePreview)(GDNativeClassBinding.getResourcePreviewer, _godot_object);
221 	}
222 	/**
223 	Returns the editor's $(D ScriptEditor) instance.
224 	*/
225 	ScriptEditor getScriptEditor()
226 	{
227 		checkClassBinding!(typeof(this))();
228 		return ptrcall!(ScriptEditor)(GDNativeClassBinding.getScriptEditor, _godot_object);
229 	}
230 	/**
231 	Returns the path of the directory currently selected in the $(D FileSystemDock). If a file is selected, its base directory will be returned using $(D String.getBaseDir) instead.
232 	*/
233 	String getSelectedPath() const
234 	{
235 		checkClassBinding!(typeof(this))();
236 		return ptrcall!(String)(GDNativeClassBinding.getSelectedPath, _godot_object);
237 	}
238 	/**
239 	Returns the editor's $(D EditorSelection) instance.
240 	*/
241 	EditorSelection getSelection()
242 	{
243 		checkClassBinding!(typeof(this))();
244 		return ptrcall!(EditorSelection)(GDNativeClassBinding.getSelection, _godot_object);
245 	}
246 	/**
247 	Shows the given property on the given `object` in the editor's Inspector dock. If `inspector_only` is `true`, plugins will not attempt to edit `object`.
248 	*/
249 	void inspectObject(GodotObject object, in String for_property = gs!"", in bool inspector_only = false)
250 	{
251 		checkClassBinding!(typeof(this))();
252 		ptrcall!(void)(GDNativeClassBinding.inspectObject, _godot_object, object, for_property, inspector_only);
253 	}
254 	/**
255 	
256 	*/
257 	bool isDistractionFreeModeEnabled() const
258 	{
259 		checkClassBinding!(typeof(this))();
260 		return ptrcall!(bool)(GDNativeClassBinding.isDistractionFreeModeEnabled, _godot_object);
261 	}
262 	/**
263 	Returns `true` if a scene is currently being played, `false` otherwise. Paused scenes are considered as being played.
264 	*/
265 	bool isPlayingScene() const
266 	{
267 		checkClassBinding!(typeof(this))();
268 		return ptrcall!(bool)(GDNativeClassBinding.isPlayingScene, _godot_object);
269 	}
270 	/**
271 	Returns `true` if the specified `plugin` is enabled. The plugin name is the same as its directory name.
272 	*/
273 	bool isPluginEnabled(in String plugin) const
274 	{
275 		checkClassBinding!(typeof(this))();
276 		return ptrcall!(bool)(GDNativeClassBinding.isPluginEnabled, _godot_object, plugin);
277 	}
278 	/**
279 	Returns mesh previews rendered at the given size as an $(D Array) of $(D Texture)s.
280 	*/
281 	Array makeMeshPreviews(in Array meshes, in long preview_size)
282 	{
283 		checkClassBinding!(typeof(this))();
284 		return ptrcall!(Array)(GDNativeClassBinding.makeMeshPreviews, _godot_object, meshes, preview_size);
285 	}
286 	/**
287 	Opens the scene at the given path.
288 	*/
289 	void openSceneFromPath(in String scene_filepath)
290 	{
291 		checkClassBinding!(typeof(this))();
292 		ptrcall!(void)(GDNativeClassBinding.openSceneFromPath, _godot_object, scene_filepath);
293 	}
294 	/**
295 	Plays the currently active scene.
296 	*/
297 	void playCurrentScene()
298 	{
299 		checkClassBinding!(typeof(this))();
300 		ptrcall!(void)(GDNativeClassBinding.playCurrentScene, _godot_object);
301 	}
302 	/**
303 	Plays the scene specified by its filepath.
304 	*/
305 	void playCustomScene(in String scene_filepath)
306 	{
307 		checkClassBinding!(typeof(this))();
308 		ptrcall!(void)(GDNativeClassBinding.playCustomScene, _godot_object, scene_filepath);
309 	}
310 	/**
311 	Plays the main scene.
312 	*/
313 	void playMainScene()
314 	{
315 		checkClassBinding!(typeof(this))();
316 		ptrcall!(void)(GDNativeClassBinding.playMainScene, _godot_object);
317 	}
318 	/**
319 	Reloads the scene at the given path.
320 	*/
321 	void reloadSceneFromPath(in String scene_filepath)
322 	{
323 		checkClassBinding!(typeof(this))();
324 		ptrcall!(void)(GDNativeClassBinding.reloadSceneFromPath, _godot_object, scene_filepath);
325 	}
326 	/**
327 	Saves the scene. Returns either `OK` or `ERR_CANT_CREATE` (see $(D @GlobalScope) constants).
328 	*/
329 	GodotError saveScene()
330 	{
331 		checkClassBinding!(typeof(this))();
332 		return ptrcall!(GodotError)(GDNativeClassBinding.saveScene, _godot_object);
333 	}
334 	/**
335 	Saves the scene as a file at `path`.
336 	*/
337 	void saveSceneAs(in String path, in bool with_preview = true)
338 	{
339 		checkClassBinding!(typeof(this))();
340 		ptrcall!(void)(GDNativeClassBinding.saveSceneAs, _godot_object, path, with_preview);
341 	}
342 	/**
343 	Selects the file, with the path provided by `file`, in the FileSystem dock.
344 	*/
345 	void selectFile(in String file)
346 	{
347 		checkClassBinding!(typeof(this))();
348 		ptrcall!(void)(GDNativeClassBinding.selectFile, _godot_object, file);
349 	}
350 	/**
351 	
352 	*/
353 	void setDistractionFreeMode(in bool enter)
354 	{
355 		checkClassBinding!(typeof(this))();
356 		ptrcall!(void)(GDNativeClassBinding.setDistractionFreeMode, _godot_object, enter);
357 	}
358 	/**
359 	Sets the editor's current main screen to the one specified in `name`. `name` must match the text of the tab in question exactly (`2D`, `3D`, `Script`, `AssetLib`).
360 	*/
361 	void setMainScreenEditor(in String name)
362 	{
363 		checkClassBinding!(typeof(this))();
364 		ptrcall!(void)(GDNativeClassBinding.setMainScreenEditor, _godot_object, name);
365 	}
366 	/**
367 	Sets the enabled status of a plugin. The plugin name is the same as its directory name.
368 	*/
369 	void setPluginEnabled(in String plugin, in bool enabled)
370 	{
371 		checkClassBinding!(typeof(this))();
372 		ptrcall!(void)(GDNativeClassBinding.setPluginEnabled, _godot_object, plugin, enabled);
373 	}
374 	/**
375 	Stops the scene that is currently playing.
376 	*/
377 	void stopPlayingScene()
378 	{
379 		checkClassBinding!(typeof(this))();
380 		ptrcall!(void)(GDNativeClassBinding.stopPlayingScene, _godot_object);
381 	}
382 	/**
383 	If `true`, enables distraction-free mode which hides side docks to increase the space available for the main view.
384 	*/
385 	@property bool distractionFreeMode()
386 	{
387 		return isDistractionFreeModeEnabled();
388 	}
389 	/// ditto
390 	@property void distractionFreeMode(bool v)
391 	{
392 		setDistractionFreeMode(v);
393 	}
394 }