editor_node.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*************************************************************************/
  2. /* editor_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef EDITOR_NODE_H
  30. #define EDITOR_NODE_H
  31. #include "scene/gui/control.h"
  32. #include "scene/gui/panel.h"
  33. #include "scene/gui/tool_button.h"
  34. #include "scene/gui/menu_button.h"
  35. #include "scene/gui/tree.h"
  36. #include "scene/gui/dialogs.h"
  37. #include "scene/gui/separator.h"
  38. #include "scene/gui/tab_container.h"
  39. #include "scene/gui/panel_container.h"
  40. #include "scene/gui/file_dialog.h"
  41. #include "scene/gui/split_container.h"
  42. #include "scene/gui/center_container.h"
  43. #include "scene/gui/texture_progress.h"
  44. #include "tools/editor/scenes_dock.h"
  45. #include "tools/editor/scene_tree_editor.h"
  46. #include "tools/editor/property_editor.h"
  47. #include "tools/editor/create_dialog.h"
  48. #include "tools/editor/call_dialog.h"
  49. #include "tools/editor/reparent_dialog.h"
  50. #include "tools/editor/connections_dialog.h"
  51. #include "tools/editor/settings_config_dialog.h"
  52. #include "tools/editor/groups_editor.h"
  53. #include "tools/editor/editor_data.h"
  54. #include "tools/editor/editor_path.h"
  55. #include "tools/editor/editor_run.h"
  56. #include "tools/editor/pane_drag.h"
  57. #include "tools/editor/animation_editor.h"
  58. #include "tools/editor/script_create_dialog.h"
  59. #include "tools/editor/run_settings_dialog.h"
  60. #include "tools/editor/project_settings.h"
  61. #include "tools/editor/project_export.h"
  62. #include "tools/editor/editor_log.h"
  63. #include "tools/editor/scene_tree_dock.h"
  64. #include "tools/editor/resources_dock.h"
  65. #include "tools/editor/optimized_save_dialog.h"
  66. #include "tools/editor/editor_run_script.h"
  67. #include "tools/editor/editor_run_native.h"
  68. #include "scene/gui/tabs.h"
  69. #include "tools/editor/quick_open.h"
  70. #include "tools/editor/project_export.h"
  71. #include "tools/editor/editor_sub_scene.h"
  72. #include "editor_import_export.h"
  73. #include "editor_reimport_dialog.h"
  74. #include "import_settings.h"
  75. #include "tools/editor/editor_plugin.h"
  76. #include "fileserver/editor_file_server.h"
  77. #include "progress_dialog.h"
  78. /**
  79. @author Juan Linietsky <[email protected]>
  80. */
  81. typedef void (*EditorNodeInitCallback)();
  82. class EditorNode : public Node {
  83. OBJ_TYPE( EditorNode, Node );
  84. enum {
  85. HISTORY_SIZE=64
  86. };
  87. enum MenuOptions {
  88. FILE_NEW_SCENE,
  89. FILE_OPEN_SCENE,
  90. FILE_SAVE_SCENE,
  91. FILE_SAVE_AS_SCENE,
  92. FILE_IMPORT_SUBSCENE,
  93. FILE_EXPORT_PROJECT,
  94. FILE_EXPORT_MESH_LIBRARY,
  95. FILE_EXPORT_TILESET,
  96. FILE_SAVE_OPTIMIZED,
  97. FILE_SAVE_SUBSCENE,
  98. FILE_DUMP_STRINGS,
  99. FILE_OPEN_RECENT,
  100. FILE_OPEN_OLD_SCENE,
  101. FILE_QUICK_OPEN_SCENE,
  102. FILE_QUICK_OPEN_SCRIPT,
  103. FILE_RUN_SCRIPT,
  104. FILE_OPEN_PREV,
  105. FILE_QUIT,
  106. FILE_EXTERNAL_OPEN_SCENE,
  107. EDIT_UNDO,
  108. EDIT_REDO,
  109. RESOURCE_NEW,
  110. RESOURCE_LOAD,
  111. RESOURCE_SAVE,
  112. RESOURCE_SAVE_AS,
  113. RESOURCE_UNREF,
  114. RESOURCE_COPY,
  115. OBJECT_COPY_PARAMS,
  116. OBJECT_PASTE_PARAMS,
  117. OBJECT_CALL_METHOD,
  118. OBJECT_REQUEST_HELP,
  119. RUN_PLAY,
  120. RUN_PAUSE,
  121. RUN_STOP,
  122. RUN_PLAY_SCENE,
  123. RUN_PLAY_CUSTOM_SCENE,
  124. RUN_SCENE_SETTINGS,
  125. RUN_SETTINGS,
  126. RUN_PROJECT_MANAGER,
  127. RUN_FILE_SERVER,
  128. RUN_DEPLOY_DUMB_CLIENTS,
  129. SETTINGS_UPDATE_ALWAYS,
  130. SETTINGS_UPDATE_CHANGES,
  131. SETTINGS_IMPORT,
  132. SETTINGS_EXPORT_PREFERENCES,
  133. SETTINGS_PREFERENCES,
  134. SETTINGS_OPTIMIZED_PRESETS,
  135. SETTINGS_SHOW_ANIMATION,
  136. SETTINGS_LOAD_EXPORT_TEMPLATES,
  137. SETTINGS_HELP,
  138. SETTINGS_ABOUT,
  139. SOURCES_REIMPORT,
  140. DEPENDENCY_LOAD_CHANGED_IMAGES,
  141. DEPENDENCY_UPDATE_IMPORTED,
  142. IMPORT_PLUGIN_BASE=100,
  143. OBJECT_METHOD_BASE=500
  144. };
  145. Node *edited_scene; //scene being edited
  146. Viewport *scene_root; //root of the scene being edited
  147. Ref<ResourceImportMetadata> scene_import_metadata;
  148. Control* scene_root_parent;
  149. Control *gui_base;
  150. VBoxContainer *main_vbox;
  151. HSplitContainer *main_split;
  152. VSplitContainer *left_split;
  153. int old_split_ofs;
  154. VSplitContainer *top_split;
  155. HBoxContainer *bottom_hb;
  156. Control *vp_base;
  157. PaneDrag *pd;
  158. //PaneDrag *pd_anim;
  159. TextureButton *anim_close;
  160. Panel *menu_panel;
  161. HSplitContainer *editor_hsplit;
  162. VSplitContainer *editor_vsplit;
  163. HBoxContainer *menu_hb;
  164. Control *viewport;
  165. MenuButton *file_menu;
  166. MenuButton *import_menu;
  167. ToolButton *export_button;
  168. ToolButton *prev_scene;
  169. MenuButton *object_menu;
  170. MenuButton *settings_menu;
  171. ToolButton *play_button;
  172. MenuButton *native_play_button;
  173. ToolButton *pause_button;
  174. ToolButton *stop_button;
  175. ToolButton *run_settings_button;
  176. ToolButton *animation_menu;
  177. ToolButton *play_scene_button;
  178. ToolButton *play_custom_scene_button;
  179. TextureProgress *audio_vu;
  180. MenuButton *fileserver_menu;
  181. TextEdit *load_errors;
  182. AcceptDialog *load_error_dialog;
  183. Control *scene_root_base;
  184. PopupMenu *recent_scenes;
  185. Button *property_back;
  186. Button *property_forward;
  187. SceneTreeDock *scene_tree_dock;
  188. ResourcesDock *resources_dock;
  189. PropertyEditor *property_editor;
  190. ScenesDock *scenes_dock;
  191. EditorRunNative *run_native;
  192. CallDialog *call_dialog;
  193. ConfirmationDialog *confirmation;
  194. ConfirmationDialog *import_confirmation;
  195. ConfirmationDialog *open_recent_confirmation;
  196. AcceptDialog *accept;
  197. AcceptDialog *about;
  198. //OptimizedPresetsDialog *optimized_presets;
  199. EditorSettingsDialog *settings_config_dialog;
  200. RunSettingsDialog *run_settings_dialog;
  201. ProjectSettings *project_settings;
  202. FileDialog *file;
  203. FileDialog *file_templates;
  204. FileDialog *file_export;
  205. FileDialog *file_export_lib;
  206. FileDialog *file_script;
  207. CheckButton *file_export_check;
  208. CheckButton *file_export_lib_merge;
  209. LineEdit *file_export_password;
  210. String current_path;
  211. MenuButton *update_menu;
  212. ToolButton *sources_button;
  213. TabContainer *prop_pallete;
  214. TabContainer *top_pallete;
  215. String defer_load_scene;
  216. String defer_translatable;
  217. String defer_optimize;
  218. String defer_optimize_preset;
  219. String defer_export;
  220. String defer_export_platform;
  221. bool defer_export_debug;
  222. Node *_last_instanced_scene;
  223. PanelContainer *animation_panel;
  224. HBoxContainer *animation_panel_hb;
  225. VBoxContainer *animation_vb;
  226. EditorPath *editor_path;
  227. AnimationKeyEditor *animation_editor;
  228. EditorLog *log;
  229. CenterContainer *tabs_center;
  230. EditorQuickOpen *quick_open;
  231. EditorQuickOpen *quick_run;
  232. Tabs *main_editor_tabs;
  233. Vector<EditorPlugin*> editor_table;
  234. EditorReImportDialog *reimport_dialog;
  235. ImportSettingsDialog *import_settings;
  236. ProgressDialog *progress_dialog;
  237. BackgroundProgress *progress_hb;
  238. String _tmp_import_path;
  239. EditorImportExport *editor_import_export;
  240. Object *current;
  241. bool _playing_edited;
  242. bool reference_resource_mem;
  243. bool save_external_resources_mem;
  244. uint64_t saved_version;
  245. bool unsaved_cache;
  246. String open_navigate;
  247. uint32_t circle_step_msec;
  248. uint64_t circle_step_frame;
  249. int circle_step;
  250. Vector<EditorPlugin*> editor_plugins;
  251. EditorPlugin *editor_plugin_screen;
  252. EditorPlugin *editor_plugin_over;
  253. EditorHistory editor_history;
  254. EditorData editor_data;
  255. EditorRun editor_run;
  256. EditorSelection *editor_selection;
  257. ProjectExport *project_export;
  258. ProjectExportDialog *project_export_settings;
  259. EditorFileServer *file_server;
  260. String external_file;
  261. List<String> previous_scenes;
  262. bool opening_prev;
  263. void _dialog_action(String p_file);
  264. void _edit_current();
  265. void _dialog_display_file_error(String p_file,Error p_error);
  266. int current_option;
  267. //void _animation_visibility_toggle();
  268. void _resource_selected(const RES& p_res,const String& p_property="");
  269. void _menu_option(int p_option);
  270. void _menu_confirm_current();
  271. void _menu_option_confirm(int p_option,bool p_confirmed);
  272. void _property_editor_forward();
  273. void _property_editor_back();
  274. void _fs_changed();
  275. void _sources_changed(bool p_exist);
  276. void _imported(Node *p_node);
  277. void _node_renamed();
  278. void _editor_select(int p_which);
  279. void _set_scene_metadata();
  280. void _get_scene_metadata();
  281. void _update_title();
  282. void _close_messages();
  283. void _show_messages();
  284. void _vp_resized();
  285. void _save_scene(String p_file);
  286. void _instance_request(const String& p_path);
  287. void _property_keyed(const String& p_keyed,const Variant& p_value);
  288. void _transform_keyed(Object *sp,const String& p_sub,const Transform& p_key);
  289. void _update_keying();
  290. void _hide_top_editors();
  291. void _quick_opened(const String& p_resource);
  292. void _quick_run(const String& p_resource);
  293. void _run(bool p_current=false, const String &p_custom="");
  294. void _save_optimized();
  295. void _import_action(const String& p_action);
  296. void _import(const String &p_file);
  297. void _add_to_recent_scenes(const String& p_scene);
  298. void _update_recent_scenes();
  299. void _open_recent_scene(int p_idx);
  300. void _open_recent_scene_confirm();
  301. String _recent_scene;
  302. bool convert_old;
  303. void _unhandled_input(const InputEvent& p_event);
  304. static void _load_error_notify(void* p_ud,const String& p_text);
  305. bool has_main_screen() const { return true; }
  306. void _fetch_translatable_strings(const Object *p_object,Set<StringName>& strings);
  307. bool _find_editing_changed_scene(Node *p_from);
  308. String import_reload_fn;
  309. Set<FileDialog*> file_dialogs;
  310. Map<String,Ref<Texture> > icon_type_cache;
  311. static Ref<Texture> _file_dialog_get_icon(const String& p_path);
  312. static void _file_dialog_register(FileDialog *p_dialog);
  313. static void _file_dialog_unregister(FileDialog *p_dialog);
  314. void _cleanup_scene();
  315. bool _find_and_save_edited_subresources(Object *obj,Set<RES>& processed,int32_t flags);
  316. void _save_edited_subresources(Node* scene,Set<RES>& processed,int32_t flags);
  317. struct ExportDefer {
  318. String platform;
  319. String path;
  320. bool debug;
  321. String password;
  322. } export_defer;
  323. static EditorNode *singleton;
  324. static Vector<EditorNodeInitCallback> _init_callbacks;
  325. bool _find_scene_in_use(Node* p_node,const String& p_path) const;
  326. protected:
  327. void _notification(int p_what);
  328. static void _bind_methods();
  329. public:
  330. static EditorNode* get_singleton() { return singleton; }
  331. EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
  332. EditorPlugin *get_editor_plugin_over() { return editor_plugin_over; }
  333. PropertyEditor *get_property_editor() { return property_editor; }
  334. static void add_editor_plugin(EditorPlugin *p_editor);
  335. static void remove_editor_plugin(EditorPlugin *p_editor);
  336. void edit_node(Node *p_node);
  337. void edit_resource(const Ref<Resource>& p_resource);
  338. void open_resource(const String& p_type="");
  339. void save_resource(const Ref<Resource>& p_resource);
  340. void save_resource_as(const Ref<Resource>& p_resource);
  341. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  342. static HBoxContainer *get_menu_hb() { return singleton->menu_hb; }
  343. void push_item(Object *p_object,const String& p_property="");
  344. void open_request(const String& p_path);
  345. void set_edited_scene(Node *p_scene);
  346. static EditorLog *get_log() { return singleton->log; }
  347. Control* get_viewport();
  348. AnimationKeyEditor *get_animation_editor() const { return animation_editor; }
  349. Control *get_animation_panel() { return animation_vb; }
  350. HBoxContainer *get_animation_panel_hb() { return animation_panel_hb; }
  351. void animation_editor_make_visible(bool p_visible);
  352. void hide_animation_player_editors();
  353. void animation_panel_make_visible(bool p_visible);
  354. Node *get_edited_scene() { return edited_scene; }
  355. Viewport *get_scene_root() { return scene_root; } //root of the scene being edited
  356. Error save_optimized_copy(const String& p_scene,const String& p_preset);
  357. void clear_scene() { _cleanup_scene(); }
  358. Error load_scene(const String& p_scene);
  359. Error load_resource(const String& p_scene);
  360. static EditorData& get_editor_data() { return singleton->editor_data; }
  361. static VSplitContainer *get_top_split() { return singleton->top_split; }
  362. Node* request_instance_scene(const String &p_path);
  363. ScenesDock *get_scenes_dock();
  364. static UndoRedo* get_undo_redo() { return &singleton->editor_data.get_undo_redo(); }
  365. EditorSelection *get_editor_selection() { return editor_selection; }
  366. Error save_translatable_strings(const String& p_to_file);
  367. void set_convert_old_scene(bool p_old) { convert_old=p_old; }
  368. void notify_child_process_exited();
  369. void stop_child_process();
  370. Error export_platform(const String& p_platform, const String& p_path, bool p_debug,const String& p_password,bool p_quit_after=false);
  371. static void register_editor_types();
  372. static void unregister_editor_types();
  373. Control *get_gui_base() { return gui_base; }
  374. static void add_io_error(const String& p_error);
  375. static void progress_add_task(const String& p_task,const String& p_label, int p_steps);
  376. static void progress_task_step(const String& p_task,const String& p_state, int p_step=-1);
  377. static void progress_end_task(const String& p_task);
  378. static void progress_add_task_bg(const String& p_task,const String& p_label, int p_steps);
  379. static void progress_task_step_bg(const String& p_task,int p_step=-1);
  380. static void progress_end_task_bg(const String& p_task);
  381. void save_scene(String p_file) { _save_scene(p_file); }
  382. bool is_scene_in_use(const String& p_path);
  383. void scan_import_changes();
  384. EditorNode();
  385. ~EditorNode();
  386. void get_singleton(const char* arg1, bool arg2);
  387. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  388. };
  389. struct EditorProgress {
  390. String task;
  391. void step(const String& p_state, int p_step=-1) { EditorNode::progress_task_step(task,p_state,p_step); }
  392. EditorProgress(const String& p_task,const String& p_label,int p_amount) { EditorNode::progress_add_task(p_task,p_label,p_amount); task=p_task; }
  393. ~EditorProgress() { EditorNode::progress_end_task(task); }
  394. };
  395. struct EditorProgressBG {
  396. String task;
  397. void step(int p_step=-1) { EditorNode::progress_task_step_bg(task,p_step); }
  398. EditorProgressBG(const String& p_task,const String& p_label,int p_amount) { EditorNode::progress_add_task_bg(p_task,p_label,p_amount); task=p_task; }
  399. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  400. };
  401. #endif