2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* editor_node.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 14:16:55 +02:00
/* https://godotengine.org */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
2018-01-01 14:40:08 +01:00
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
2014-02-10 02:10:30 +01:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2018-01-05 00:50:27 +01:00
2014-02-10 02:10:30 +01:00
# include "editor_node.h"
2017-01-16 08:04:19 +01:00
2017-08-26 17:46:49 +02:00
# include "core/bind/core_bind.h"
# include "core/class_db.h"
# include "core/io/config_file.h"
2014-02-10 02:10:30 +01:00
# include "core/io/resource_loader.h"
2017-03-05 16:44:50 +01:00
# include "core/io/resource_saver.h"
2017-08-26 17:46:49 +02:00
# include "core/io/stream_peer_ssl.h"
# include "core/io/zip_io.h"
# include "core/message_queue.h"
# include "core/os/file_access.h"
# include "core/os/input.h"
# include "core/os/keyboard.h"
# include "core/os/os.h"
# include "core/path_remap.h"
# include "core/print_string.h"
# include "core/project_settings.h"
# include "core/translation.h"
# include "core/version.h"
2017-03-05 16:44:50 +01:00
# include "main/input_default.h"
# include "scene/resources/packed_scene.h"
# include "servers/physics_2d_server.h"
2017-08-26 17:46:49 +02:00
# include "editor/animation_editor.h"
# include "editor/editor_audio_buses.h"
# include "editor/editor_file_system.h"
# include "editor/editor_help.h"
# include "editor/editor_initialize_ssl.h"
# include "editor/editor_settings.h"
# include "editor/editor_themes.h"
# include "editor/import/editor_import_collada.h"
# include "editor/import/editor_scene_importer_gltf.h"
2018-01-06 20:36:49 +01:00
# include "editor/import/resource_importer_bitmask.h"
2017-08-26 17:46:49 +02:00
# include "editor/import/resource_importer_csv_translation.h"
# include "editor/import/resource_importer_obj.h"
# include "editor/import/resource_importer_scene.h"
# include "editor/import/resource_importer_texture.h"
# include "editor/import/resource_importer_wav.h"
# include "editor/plugins/animation_player_editor_plugin.h"
# include "editor/plugins/animation_tree_editor_plugin.h"
# include "editor/plugins/asset_library_editor_plugin.h"
2017-12-14 12:59:46 +01:00
# include "editor/plugins/baked_lightmap_editor_plugin.h"
2017-08-26 17:46:49 +02:00
# include "editor/plugins/camera_editor_plugin.h"
# include "editor/plugins/canvas_item_editor_plugin.h"
# include "editor/plugins/collision_polygon_2d_editor_plugin.h"
# include "editor/plugins/collision_polygon_editor_plugin.h"
# include "editor/plugins/collision_shape_2d_editor_plugin.h"
# include "editor/plugins/cube_grid_theme_editor_plugin.h"
# include "editor/plugins/curve_editor_plugin.h"
# include "editor/plugins/editor_preview_plugins.h"
# include "editor/plugins/gi_probe_editor_plugin.h"
# include "editor/plugins/gradient_editor_plugin.h"
# include "editor/plugins/item_list_editor_plugin.h"
# include "editor/plugins/light_occluder_2d_editor_plugin.h"
# include "editor/plugins/line_2d_editor_plugin.h"
# include "editor/plugins/material_editor_plugin.h"
# include "editor/plugins/mesh_editor_plugin.h"
# include "editor/plugins/mesh_instance_editor_plugin.h"
# include "editor/plugins/multimesh_editor_plugin.h"
2017-02-28 13:10:29 +01:00
# include "editor/plugins/navigation_mesh_editor_plugin.h"
2017-08-26 17:46:49 +02:00
# include "editor/plugins/navigation_polygon_editor_plugin.h"
# include "editor/plugins/particles_2d_editor_plugin.h"
# include "editor/plugins/particles_editor_plugin.h"
# include "editor/plugins/path_2d_editor_plugin.h"
# include "editor/plugins/path_editor_plugin.h"
2017-10-03 18:49:32 +02:00
# include "editor/plugins/physical_bone_plugin.h"
2017-08-26 17:46:49 +02:00
# include "editor/plugins/polygon_2d_editor_plugin.h"
# include "editor/plugins/resource_preloader_editor_plugin.h"
# include "editor/plugins/script_editor_plugin.h"
# include "editor/plugins/script_text_editor.h"
# include "editor/plugins/shader_editor_plugin.h"
# include "editor/plugins/shader_graph_editor_plugin.h"
2018-02-21 21:23:27 +01:00
# include "editor/plugins/skeleton_2d_editor_plugin.h"
2017-10-03 18:49:32 +02:00
# include "editor/plugins/skeleton_editor_plugin.h"
2017-08-26 17:46:49 +02:00
# include "editor/plugins/spatial_editor_plugin.h"
2018-02-21 13:38:21 +01:00
# include "editor/plugins/sprite_editor_plugin.h"
2017-08-26 17:46:49 +02:00
# include "editor/plugins/sprite_frames_editor_plugin.h"
# include "editor/plugins/style_box_editor_plugin.h"
# include "editor/plugins/texture_editor_plugin.h"
# include "editor/plugins/texture_region_editor_plugin.h"
# include "editor/plugins/theme_editor_plugin.h"
# include "editor/plugins/tile_map_editor_plugin.h"
# include "editor/plugins/tile_set_editor_plugin.h"
# include "editor/pvrtc_compress.h"
# include "editor/register_exporters.h"
# include "editor/script_editor_debugger.h"
2017-03-05 16:44:50 +01:00
# include <stdio.h>
2014-02-18 05:21:06 +01:00
2017-03-05 16:44:50 +01:00
EditorNode * EditorNode : : singleton = NULL ;
2014-02-10 02:10:30 +01:00
2015-06-22 05:03:19 +02:00
void EditorNode : : _update_scene_tabs ( ) {
2017-12-20 19:41:02 +01:00
bool show_rb = EditorSettings : : get_singleton ( ) - > get ( " interface/scene_tabs/show_script_button " ) ;
2015-11-18 08:47:41 +01:00
2015-06-22 05:03:19 +02:00
scene_tabs - > clear_tabs ( ) ;
2017-03-05 16:44:50 +01:00
Ref < Texture > script_icon = gui_base - > get_icon ( " Script " , " EditorIcons " ) ;
for ( int i = 0 ; i < editor_data . get_edited_scene_count ( ) ; i + + ) {
2015-07-24 19:18:02 +02:00
2017-03-05 16:44:50 +01:00
String type = editor_data . get_scene_type ( i ) ;
2015-07-24 19:18:02 +02:00
Ref < Texture > icon ;
2017-03-05 16:44:50 +01:00
if ( type ! = String ( ) ) {
2015-07-24 19:18:02 +02:00
2017-03-05 16:44:50 +01:00
if ( ! gui_base - > has_icon ( type , " EditorIcons " ) ) {
type = " Node " ;
2015-07-24 19:18:02 +02:00
}
2017-03-05 16:44:50 +01:00
icon = gui_base - > get_icon ( type , " EditorIcons " ) ;
2015-07-24 19:18:02 +02:00
}
2015-06-22 05:03:19 +02:00
int current = editor_data . get_edited_scene ( ) ;
2017-03-05 16:44:50 +01:00
bool unsaved = ( i = = current ) ? saved_version ! = editor_data . get_undo_redo ( ) . get_version ( ) : editor_data . get_scene_version ( i ) ! = 0 ;
scene_tabs - > add_tab ( editor_data . get_scene_title ( i ) + ( unsaved ? " (*) " : " " ) , icon ) ;
2015-07-24 19:18:02 +02:00
2015-11-18 08:47:41 +01:00
if ( show_rb & & editor_data . get_scene_root_script ( i ) . is_valid ( ) ) {
2017-03-05 16:44:50 +01:00
scene_tabs - > set_tab_right_button ( i , script_icon ) ;
2015-07-26 15:44:10 +02:00
}
2015-06-22 05:03:19 +02:00
}
scene_tabs - > set_current_tab ( editor_data . get_edited_scene ( ) ) ;
2017-11-16 23:57:57 +01:00
int current = editor_data . get_edited_scene ( ) ;
if ( scene_tabs - > get_offset_buttons_visible ( ) ) {
// move add button to fixed position on the tabbar
if ( scene_tab_add - > get_parent ( ) = = scene_tabs ) {
scene_tab_add - > set_position ( Point2 ( 0 , 0 ) ) ;
scene_tabs - > remove_child ( scene_tab_add ) ;
tabbar_container - > add_child ( scene_tab_add ) ;
tabbar_container - > move_child ( scene_tab_add , 1 ) ;
}
} else {
// move add button to after last tab
if ( scene_tab_add - > get_parent ( ) = = tabbar_container ) {
tabbar_container - > remove_child ( scene_tab_add ) ;
scene_tabs - > add_child ( scene_tab_add ) ;
}
2017-11-20 15:49:07 +01:00
Rect2 last_tab = Rect2 ( ) ;
if ( scene_tabs - > get_tab_count ( ) ! = 0 )
last_tab = scene_tabs - > get_tab_rect ( scene_tabs - > get_tab_count ( ) - 1 ) ;
2017-11-16 23:57:57 +01:00
scene_tab_add - > set_position ( Point2 ( last_tab . get_position ( ) . x + last_tab . get_size ( ) . x + 3 , last_tab . get_position ( ) . y ) ) ;
}
2015-06-22 05:03:19 +02:00
}
2014-02-10 02:10:30 +01:00
void EditorNode : : _update_title ( ) {
2017-07-19 22:00:46 +02:00
String appname = ProjectSettings : : get_singleton ( ) - > get ( " application/config/name " ) ;
2017-11-19 21:18:01 +01:00
String title = appname . empty ( ) ? String ( VERSION_FULL_NAME ) : String ( VERSION_NAME + String ( " - " ) + appname ) ;
2017-03-05 16:44:50 +01:00
String edited = editor_data . get_edited_scene_root ( ) ? editor_data . get_edited_scene_root ( ) - > get_filename ( ) : String ( ) ;
2014-04-10 04:50:30 +02:00
if ( ! edited . empty ( ) )
2017-03-05 16:44:50 +01:00
title + = " - " + String ( edited . get_file ( ) ) ;
2014-02-10 02:10:30 +01:00
if ( unsaved_cache )
2017-03-05 16:44:50 +01:00
title + = " (*) " ;
2014-02-10 02:10:30 +01:00
OS : : get_singleton ( ) - > set_window_title ( title ) ;
}
2017-05-20 17:38:03 +02:00
void EditorNode : : _unhandled_input ( const Ref < InputEvent > & p_event ) {
2014-02-10 02:10:30 +01:00
2016-06-28 01:14:59 +02:00
if ( Node : : get_viewport ( ) - > get_modal_stack_top ( ) )
return ; //ignore because of modal window
2017-05-20 17:38:03 +02:00
Ref < InputEventKey > k = p_event ;
if ( k . is_valid ( ) & & k - > is_pressed ( ) & & ! k - > is_echo ( ) & & ! gui_base - > get_viewport ( ) - > gui_has_modal_stack ( ) ) {
2016-06-15 18:25:17 +02:00
2018-03-13 21:20:59 +01:00
EditorPlugin * old_editor = editor_plugin_screen ;
2016-06-25 06:42:09 +02:00
if ( ED_IS_SHORTCUT ( " editor/next_tab " , p_event ) ) {
int next_tab = editor_data . get_edited_scene ( ) + 1 ;
next_tab % = editor_data . get_edited_scene_count ( ) ;
_scene_tab_changed ( next_tab ) ;
}
if ( ED_IS_SHORTCUT ( " editor/prev_tab " , p_event ) ) {
int next_tab = editor_data . get_edited_scene ( ) - 1 ;
next_tab = next_tab > = 0 ? next_tab : editor_data . get_edited_scene_count ( ) - 1 ;
_scene_tab_changed ( next_tab ) ;
}
2017-01-21 13:07:29 +01:00
if ( ED_IS_SHORTCUT ( " editor/filter_files " , p_event ) ) {
filesystem_dock - > focus_on_filter ( ) ;
}
2016-06-15 18:25:17 +02:00
2017-05-16 21:26:32 +02:00
if ( ED_IS_SHORTCUT ( " editor/editor_2d " , p_event ) ) {
_editor_select ( EDITOR_2D ) ;
} else if ( ED_IS_SHORTCUT ( " editor/editor_3d " , p_event ) ) {
_editor_select ( EDITOR_3D ) ;
} else if ( ED_IS_SHORTCUT ( " editor/editor_script " , p_event ) ) {
_editor_select ( EDITOR_SCRIPT ) ;
} else if ( ED_IS_SHORTCUT ( " editor/editor_help " , p_event ) ) {
emit_signal ( " request_help_search " , " " ) ;
} else if ( ED_IS_SHORTCUT ( " editor/editor_assetlib " , p_event ) ) {
_editor_select ( EDITOR_ASSETLIB ) ;
} else if ( ED_IS_SHORTCUT ( " editor/editor_next " , p_event ) ) {
_editor_select_next ( ) ;
} else if ( ED_IS_SHORTCUT ( " editor/editor_prev " , p_event ) ) {
_editor_select_prev ( ) ;
2014-02-10 02:10:30 +01:00
}
2018-01-19 09:04:55 +01:00
if ( k - > get_scancode ( ) = = KEY_ESCAPE ) {
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
_bottom_panel_switch ( false , i ) ;
}
}
2018-03-13 21:20:59 +01:00
if ( old_editor ! = editor_plugin_screen ) {
get_tree ( ) - > set_input_as_handled ( ) ;
}
2014-02-10 02:10:30 +01:00
}
}
void EditorNode : : _notification ( int p_what ) {
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_EXIT_TREE ) {
2015-04-21 00:38:02 +02:00
2014-02-10 02:10:30 +01:00
editor_data . save_editor_external_data ( ) ;
2016-06-13 15:10:50 +02:00
FileAccess : : set_file_close_fail_notify_callback ( NULL ) ;
2014-02-10 02:10:30 +01:00
log - > deinit ( ) ; // do not get messages anymore
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_PROCESS ) {
2016-03-09 00:00:52 +01:00
2017-01-13 14:45:50 +01:00
if ( opening_prev & & ! confirmation - > is_visible ( ) )
2017-03-05 16:44:50 +01:00
opening_prev = false ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( unsaved_cache ! = ( saved_version ! = editor_data . get_undo_redo ( ) . get_version ( ) ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
unsaved_cache = ( saved_version ! = editor_data . get_undo_redo ( ) . get_version ( ) ) ;
2014-02-10 02:10:30 +01:00
_update_title ( ) ;
}
2017-03-05 16:44:50 +01:00
if ( last_checked_version ! = editor_data . get_undo_redo ( ) . get_version ( ) ) {
2015-06-22 05:03:19 +02:00
_update_scene_tabs ( ) ;
2017-03-05 16:44:50 +01:00
last_checked_version = editor_data . get_undo_redo ( ) . get_version ( ) ;
2015-06-22 05:03:19 +02:00
}
2014-02-10 02:10:30 +01:00
//update the circle
2017-01-13 16:51:14 +01:00
uint64_t frame = Engine : : get_singleton ( ) - > get_frames_drawn ( ) ;
2014-02-10 02:10:30 +01:00
uint32_t tick = OS : : get_singleton ( ) - > get_ticks_msec ( ) ;
2017-03-05 16:44:50 +01:00
if ( frame ! = circle_step_frame & & ( tick - circle_step_msec ) > ( 1000 / 8 ) ) {
2014-02-10 02:10:30 +01:00
circle_step + + ;
2017-03-05 16:44:50 +01:00
if ( circle_step > = 8 )
circle_step = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
circle_step_msec = tick ;
circle_step_frame = frame + 1 ;
2014-02-10 02:10:30 +01:00
2017-01-02 21:38:20 +01:00
// update the circle itself only when its enabled
2017-03-05 16:44:50 +01:00
if ( ! update_menu - > get_popup ( ) - > is_item_checked ( 3 ) ) {
update_menu - > set_icon ( gui_base - > get_icon ( " Progress " + itos ( circle_step + 1 ) , " EditorIcons " ) ) ;
2017-01-02 21:38:20 +01:00
}
2014-02-10 02:10:30 +01:00
}
editor_selection - > update ( ) ;
2017-07-19 22:00:46 +02:00
scene_root - > set_size_override ( true , Size2 ( ProjectSettings : : get_singleton ( ) - > get ( " display/window/size/width " ) , ProjectSettings : : get_singleton ( ) - > get ( " display/window/size/height " ) ) ) ;
2017-06-12 21:18:17 +02:00
2017-02-06 04:38:39 +01:00
ResourceImporterTexture : : get_singleton ( ) - > update_imports ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_ENTER_TREE ) {
2014-02-10 02:10:30 +01:00
2017-08-13 16:21:45 +02:00
Engine : : get_singleton ( ) - > set_editor_hint ( true ) ;
2017-12-07 00:47:56 +01:00
get_tree ( ) - > get_root ( ) - > set_usage ( Viewport : : USAGE_2D_NO_SAMPLING ) ; //reduce memory usage
2016-10-05 06:26:35 +02:00
get_tree ( ) - > get_root ( ) - > set_disable_3d ( true ) ;
2014-11-06 01:20:42 +01:00
get_tree ( ) - > get_root ( ) - > set_as_audio_listener ( false ) ;
get_tree ( ) - > get_root ( ) - > set_as_audio_listener_2d ( false ) ;
get_tree ( ) - > set_auto_accept_quit ( false ) ;
2017-03-05 16:44:50 +01:00
get_tree ( ) - > connect ( " files_dropped " , this , " _dropped_files " ) ;
2017-09-15 00:38:38 +02:00
property_editable_warning - > set_icon ( gui_base - > get_icon ( " NodeWarning " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
}
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_EXIT_TREE ) {
2015-06-22 05:03:19 +02:00
editor_data . clear_edited_scenes ( ) ;
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_READY ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
VisualServer : : get_singleton ( ) - > viewport_set_hide_scenario ( get_scene_root ( ) - > get_viewport_rid ( ) , true ) ;
VisualServer : : get_singleton ( ) - > viewport_set_hide_canvas ( get_scene_root ( ) - > get_viewport_rid ( ) , true ) ;
VisualServer : : get_singleton ( ) - > viewport_set_disable_environment ( get_viewport ( ) - > get_viewport_rid ( ) , true ) ;
2015-03-16 04:47:37 +01:00
2015-11-25 00:46:44 +01:00
_editor_select ( EDITOR_3D ) ;
2017-02-08 06:18:48 +01:00
_update_debug_options ( ) ;
2017-11-25 00:32:54 +01:00
_load_docks ( ) ;
2014-02-10 02:10:30 +01:00
}
if ( p_what = = MainLoop : : NOTIFICATION_WM_FOCUS_IN ) {
2017-02-01 13:45:45 +01:00
EditorFileSystem : : get_singleton ( ) - > scan_changes ( ) ;
2014-02-10 02:10:30 +01:00
}
if ( p_what = = MainLoop : : NOTIFICATION_WM_QUIT_REQUEST ) {
_menu_option_confirm ( FILE_QUIT , false ) ;
2017-05-02 22:13:12 +02:00
}
2014-02-10 02:10:30 +01:00
2016-02-20 02:41:29 +01:00
if ( p_what = = EditorSettings : : NOTIFICATION_EDITOR_SETTINGS_CHANGED ) {
2017-12-20 19:41:02 +01:00
scene_tabs - > set_tab_close_display_policy ( ( bool ( EDITOR_DEF ( " interface/scene_tabs/always_show_close_button " , false ) ) ? Tabs : : CLOSE_BUTTON_SHOW_ALWAYS : Tabs : : CLOSE_BUTTON_SHOW_ACTIVE_ONLY ) ) ;
2017-10-17 16:39:31 +02:00
Ref < Theme > theme = create_editor_theme ( theme_base - > get_theme ( ) ) ;
2017-09-02 03:25:40 +02:00
2017-05-02 22:13:12 +02:00
theme_base - > set_theme ( theme ) ;
2017-11-11 18:57:54 +01:00
gui_base - > set_theme ( theme ) ;
2017-09-02 03:25:40 +02:00
2017-05-02 22:13:12 +02:00
gui_base - > add_style_override ( " panel " , gui_base - > get_stylebox ( " Background " , " EditorStyles " ) ) ;
play_button_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " PlayButtonPanel " , " EditorStyles " ) ) ;
scene_root_parent - > add_style_override ( " panel " , gui_base - > get_stylebox ( " Content " , " EditorStyles " ) ) ;
2017-07-15 06:40:17 +02:00
bottom_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " panel " , " TabContainer " ) ) ;
2017-06-16 20:00:57 +02:00
scene_tabs - > add_style_override ( " tab_fg " , gui_base - > get_stylebox ( " SceneTabFG " , " EditorStyles " ) ) ;
scene_tabs - > add_style_override ( " tab_bg " , gui_base - > get_stylebox ( " SceneTabBG " , " EditorStyles " ) ) ;
2017-09-02 03:25:40 +02:00
file_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
project_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
debug_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
settings_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
help_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
2017-06-15 17:30:03 +02:00
if ( bool ( EDITOR_DEF ( " interface/scene_tabs/resize_if_many_tabs " , true ) ) ) {
scene_tabs - > set_min_width ( int ( EDITOR_DEF ( " interface/scene_tabs/minimum_width " , 50 ) ) * EDSCALE ) ;
} else {
scene_tabs - > set_min_width ( 0 ) ;
}
_update_scene_tabs ( ) ;
2017-08-30 01:03:13 +02:00
2017-10-20 12:24:00 +02:00
recent_scenes - > set_as_minsize ( ) ;
2017-09-18 21:06:55 +02:00
// debugger area
if ( ScriptEditor : : get_singleton ( ) - > get_debugger ( ) - > is_visible ( ) )
bottom_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " BottomPanelDebuggerOverride " , " EditorStyles " ) ) ;
2018-01-09 13:42:45 +01:00
// update_icons
2017-08-30 01:03:13 +02:00
for ( int i = 0 ; i < singleton - > main_editor_buttons . size ( ) ; i + + ) {
2018-02-25 17:04:16 +01:00
ToolButton * tb = singleton - > main_editor_buttons [ i ] ;
EditorPlugin * p_editor = singleton - > editor_table [ i ] ;
Ref < Texture > icon = p_editor - > get_icon ( ) ;
2017-12-06 23:27:45 +01:00
if ( icon . is_valid ( ) ) {
2018-02-25 17:04:16 +01:00
tb - > set_icon ( icon ) ;
} else if ( singleton - > gui_base - > has_icon ( p_editor - > get_name ( ) , " EditorIcons " ) ) {
tb - > set_icon ( singleton - > gui_base - > get_icon ( p_editor - > get_name ( ) , " EditorIcons " ) ) ;
2017-12-06 23:27:45 +01:00
}
2017-08-30 01:03:13 +02:00
}
2018-02-25 17:04:16 +01:00
_build_icon_type_cache ( ) ;
2017-08-30 01:03:13 +02:00
play_button - > set_icon ( gui_base - > get_icon ( " MainPlay " , " EditorIcons " ) ) ;
play_scene_button - > set_icon ( gui_base - > get_icon ( " PlayScene " , " EditorIcons " ) ) ;
play_custom_scene_button - > set_icon ( gui_base - > get_icon ( " PlayCustom " , " EditorIcons " ) ) ;
pause_button - > set_icon ( gui_base - > get_icon ( " Pause " , " EditorIcons " ) ) ;
stop_button - > set_icon ( gui_base - > get_icon ( " Stop " , " EditorIcons " ) ) ;
prev_scene - > set_icon ( gui_base - > get_icon ( " PrevScene " , " EditorIcons " ) ) ;
distraction_free - > set_icon ( gui_base - > get_icon ( " DistractionFree " , " EditorIcons " ) ) ;
2017-11-16 23:57:57 +01:00
scene_tab_add - > set_icon ( gui_base - > get_icon ( " Add " , " EditorIcons " ) ) ;
2017-08-30 01:03:13 +02:00
resource_new_button - > set_icon ( gui_base - > get_icon ( " New " , " EditorIcons " ) ) ;
resource_load_button - > set_icon ( gui_base - > get_icon ( " Load " , " EditorIcons " ) ) ;
resource_save_button - > set_icon ( gui_base - > get_icon ( " Save " , " EditorIcons " ) ) ;
property_back - > set_icon ( gui_base - > get_icon ( " Back " , " EditorIcons " ) ) ;
property_forward - > set_icon ( gui_base - > get_icon ( " Forward " , " EditorIcons " ) ) ;
editor_history_menu - > set_icon ( gui_base - > get_icon ( " History " , " EditorIcons " ) ) ;
search_button - > set_icon ( gui_base - > get_icon ( " Search " , " EditorIcons " ) ) ;
object_menu - > set_icon ( gui_base - > get_icon ( " Tools " , " EditorIcons " ) ) ;
2018-01-18 21:37:17 +01:00
// clear_button->set_icon(gui_base->get_icon("Close", "EditorIcons")); don't have access to that node. needs to become a class property
2017-08-30 01:03:13 +02:00
update_menu - > set_icon ( gui_base - > get_icon ( " Collapse " , " EditorIcons " ) ) ;
dock_tab_move_left - > set_icon ( theme - > get_icon ( " Back " , " EditorIcons " ) ) ;
dock_tab_move_right - > set_icon ( theme - > get_icon ( " Forward " , " EditorIcons " ) ) ;
update_menu - > set_icon ( gui_base - > get_icon ( " Progress1 " , " EditorIcons " ) ) ;
2018-02-25 17:04:16 +01:00
PopupMenu * p = help_menu - > get_popup ( ) ;
p - > set_item_icon ( p - > get_item_index ( HELP_CLASSES ) , gui_base - > get_icon ( " ClassList " , " EditorIcons " ) ) ;
p - > set_item_icon ( p - > get_item_index ( HELP_SEARCH ) , gui_base - > get_icon ( " HelpSearch " , " EditorIcons " ) ) ;
p - > set_item_icon ( p - > get_item_index ( HELP_DOCS ) , gui_base - > get_icon ( " Instance " , " EditorIcons " ) ) ;
p - > set_item_icon ( p - > get_item_index ( HELP_QA ) , gui_base - > get_icon ( " Instance " , " EditorIcons " ) ) ;
p - > set_item_icon ( p - > get_item_index ( HELP_ISSUES ) , gui_base - > get_icon ( " Instance " , " EditorIcons " ) ) ;
p - > set_item_icon ( p - > get_item_index ( HELP_COMMUNITY ) , gui_base - > get_icon ( " Instance " , " EditorIcons " ) ) ;
p - > set_item_icon ( p - > get_item_index ( HELP_ABOUT ) , gui_base - > get_icon ( " Godot " , " EditorIcons " ) ) ;
2016-02-20 02:41:29 +01:00
}
2017-11-21 08:46:39 +01:00
if ( p_what = = Control : : NOTIFICATION_RESIZED ) {
2017-11-16 23:57:57 +01:00
_update_scene_tabs ( ) ;
}
2014-02-10 02:10:30 +01:00
}
void EditorNode : : _fs_changed ( ) {
2017-03-05 16:44:50 +01:00
for ( Set < FileDialog * > : : Element * E = file_dialogs . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 02:10:30 +01:00
E - > get ( ) - > invalidate ( ) ;
}
2015-05-31 06:59:42 +02:00
2017-03-05 16:44:50 +01:00
for ( Set < EditorFileDialog * > : : Element * E = editor_file_dialogs . front ( ) ; E ; E = E - > next ( ) ) {
2015-05-31 06:59:42 +02:00
E - > get ( ) - > invalidate ( ) ;
}
2016-02-10 07:41:48 +01:00
2017-02-01 13:45:45 +01:00
{
//reload changed resources
List < Ref < Resource > > changed ;
2014-02-10 02:10:30 +01:00
2017-02-01 13:45:45 +01:00
List < Ref < Resource > > cached ;
ResourceCache : : get_cached_resources ( & cached ) ;
2017-08-26 17:46:49 +02:00
// FIXME: This should be done in a thread.
2017-03-05 16:44:50 +01:00
for ( List < Ref < Resource > > : : Element * E = cached . front ( ) ; E ; E = E - > next ( ) ) {
2016-05-27 19:18:40 +02:00
2017-02-01 13:45:45 +01:00
if ( ! E - > get ( ) - > editor_can_reload_from_file ( ) )
continue ;
if ( ! E - > get ( ) - > get_path ( ) . is_resource_file ( ) & & ! E - > get ( ) - > get_path ( ) . is_abs_path ( ) )
continue ;
if ( ! FileAccess : : exists ( E - > get ( ) - > get_path ( ) ) )
continue ;
2016-05-27 19:18:40 +02:00
2017-03-05 16:44:50 +01:00
if ( E - > get ( ) - > get_import_path ( ) ! = String ( ) ) {
2017-12-17 15:29:39 +01:00
//this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback
2017-08-31 23:57:03 +02:00
continue ;
}
2016-05-27 19:18:40 +02:00
2017-08-31 23:57:03 +02:00
uint64_t mt = FileAccess : : get_modified_time ( E - > get ( ) - > get_path ( ) ) ;
2016-05-27 19:18:40 +02:00
2017-08-31 23:57:03 +02:00
if ( mt ! = E - > get ( ) - > get_last_modified_time ( ) ) {
changed . push_back ( E - > get ( ) ) ;
2016-05-27 19:18:40 +02:00
}
2017-02-01 13:45:45 +01:00
}
2016-05-27 19:18:40 +02:00
2017-02-01 13:45:45 +01:00
if ( changed . size ( ) ) {
2017-03-05 16:44:50 +01:00
for ( List < Ref < Resource > > : : Element * E = changed . front ( ) ; E ; E = E - > next ( ) ) {
2017-02-01 13:45:45 +01:00
E - > get ( ) - > reload_from_file ( ) ;
}
2016-05-27 19:18:40 +02:00
}
}
2017-06-29 19:37:54 +02:00
_mark_unsaved_scenes ( ) ;
2017-12-30 10:39:09 +01:00
if ( export_defer . preset ! = " " & & ! EditorFileSystem : : get_singleton ( ) - > is_scanning ( ) ) {
Ref < EditorExportPreset > preset ;
for ( int i = 0 ; i < EditorExport : : get_singleton ( ) - > get_export_preset_count ( ) ; + + i ) {
preset = EditorExport : : get_singleton ( ) - > get_export_preset ( i ) ;
if ( preset - > get_name ( ) = = export_defer . preset ) {
break ;
}
preset . unref ( ) ;
}
if ( preset . is_null ( ) ) {
2018-04-19 13:04:41 +02:00
String errstr = " Unknown export preset: " + export_defer . preset ;
ERR_PRINTS ( errstr ) ;
2017-12-30 10:39:09 +01:00
} else {
Ref < EditorExportPlatform > platform = preset - > get_platform ( ) ;
if ( platform . is_null ( ) ) {
2018-04-19 13:04:41 +02:00
String errstr = " Preset \" " + export_defer . preset + " \" doesn't have a platform. " ;
ERR_PRINTS ( errstr ) ;
2017-12-30 10:39:09 +01:00
} else {
// ensures export_project does not loop infinitely, because notifications may
// come during the export
export_defer . preset = " " ;
2018-04-19 13:04:41 +02:00
Error err = OK ;
2017-12-30 10:39:09 +01:00
if ( ! preset - > is_runnable ( ) & & ( export_defer . path . ends_with ( " .pck " ) | | export_defer . path . ends_with ( " .zip " ) ) ) {
if ( export_defer . path . ends_with ( " .zip " ) ) {
2018-04-26 23:08:19 +02:00
err = platform - > export_zip ( preset , export_defer . debug , export_defer . path ) ;
2017-12-30 10:39:09 +01:00
} else if ( export_defer . path . ends_with ( " .pck " ) ) {
2018-04-26 23:08:19 +02:00
err = platform - > export_pack ( preset , export_defer . debug , export_defer . path ) ;
2017-12-30 10:39:09 +01:00
}
} else {
2018-04-26 23:08:19 +02:00
err = platform - > export_project ( preset , export_defer . debug , export_defer . path ) ;
2018-04-04 16:13:06 +02:00
}
if ( err ! = OK ) {
2018-05-01 13:07:05 +02:00
ERR_PRINTS ( vformat ( TTR ( " Project export failed with error code %d. " ) , ( int ) err ) ) ;
2017-12-30 10:39:09 +01:00
}
}
}
get_tree ( ) - > quit ( ) ;
}
2017-02-01 13:45:45 +01:00
}
2016-05-27 19:18:40 +02:00
2017-08-31 23:57:03 +02:00
void EditorNode : : _resources_reimported ( const Vector < String > & p_resources ) {
2017-10-21 19:31:23 +02:00
2017-08-31 23:57:03 +02:00
List < String > scenes ; //will load later
for ( int i = 0 ; i < p_resources . size ( ) ; i + + ) {
String file_type = ResourceLoader : : get_resource_type ( p_resources [ i ] ) ;
if ( file_type = = " PackedScene " ) {
scenes . push_back ( p_resources [ i ] ) ;
//reload later if needed, first go with normal resources
continue ;
}
if ( ! ResourceCache : : has ( p_resources [ i ] ) ) {
continue ; //not loaded, no need to reload
}
//reload normally
Resource * resource = ResourceCache : : get ( p_resources [ i ] ) ;
if ( resource ) {
resource - > reload_from_file ( ) ;
}
}
for ( List < String > : : Element * E = scenes . front ( ) ; E ; E = E - > next ( ) ) {
reload_scene ( E - > get ( ) ) ;
}
}
2017-02-01 13:45:45 +01:00
void EditorNode : : _sources_changed ( bool p_exist ) {
2014-02-10 02:10:30 +01:00
2017-02-01 13:45:45 +01:00
if ( waiting_for_first_scan ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( defer_load_scene ! = " " ) {
2014-02-10 02:10:30 +01:00
2017-02-01 13:45:45 +01:00
load_scene ( defer_load_scene ) ;
2017-03-05 16:44:50 +01:00
defer_load_scene = " " ;
2017-02-01 13:45:45 +01:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
waiting_for_first_scan = false ;
2014-02-10 02:10:30 +01:00
}
}
void EditorNode : : _vp_resized ( ) {
}
void EditorNode : : _node_renamed ( ) {
if ( property_editor )
property_editor - > update_tree ( ) ;
}
2017-05-16 21:26:32 +02:00
void EditorNode : : _editor_select_next ( ) {
int editor = _get_current_main_editor ( ) ;
if ( editor = = editor_table . size ( ) - 1 ) {
editor = 0 ;
} else {
editor + + ;
}
_editor_select ( editor ) ;
}
void EditorNode : : _editor_select_prev ( ) {
int editor = _get_current_main_editor ( ) ;
if ( editor = = 0 ) {
editor = editor_table . size ( ) - 1 ;
} else {
editor - - ;
}
_editor_select ( editor ) ;
}
2017-03-05 16:44:50 +01:00
Error EditorNode : : load_resource ( const String & p_scene ) {
2014-02-10 02:10:30 +01:00
RES res = ResourceLoader : : load ( p_scene ) ;
2017-03-05 16:44:50 +01:00
ERR_FAIL_COND_V ( ! res . is_valid ( ) , ERR_CANT_OPEN ) ;
2014-02-10 02:10:30 +01:00
edit_resource ( res ) ;
return OK ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : edit_resource ( const Ref < Resource > & p_resource ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
_resource_selected ( p_resource , " " ) ;
2014-02-10 02:10:30 +01:00
}
void EditorNode : : edit_node ( Node * p_node ) {
push_item ( p_node ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : open_resource ( const String & p_type ) {
2014-02-10 02:10:30 +01:00
2015-05-31 06:59:42 +02:00
file - > set_mode ( EditorFileDialog : : MODE_OPEN_FILE ) ;
2014-02-10 02:10:30 +01:00
List < String > extensions ;
2017-03-05 16:44:50 +01:00
ResourceLoader : : get_recognized_extensions_for_type ( p_type , & extensions ) ;
2014-02-10 02:10:30 +01:00
file - > clear_filters ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < extensions . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
file - > add_filter ( " *. " + extensions [ i ] + " ; " + extensions [ i ] . to_upper ( ) ) ;
2014-02-10 02:10:30 +01:00
}
file - > popup_centered_ratio ( ) ;
2017-03-05 16:44:50 +01:00
current_option = RESOURCE_LOAD ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : save_resource_in_path ( const Ref < Resource > & p_resource , const String & p_path ) {
2015-09-01 05:49:47 +02:00
editor_data . apply_changes_in_editors ( ) ;
2018-03-17 18:52:39 +01:00
2017-03-05 16:44:50 +01:00
int flg = 0 ;
2017-01-05 23:41:36 +01:00
if ( EditorSettings : : get_singleton ( ) - > get ( " filesystem/on_save/compress_binary_resources " ) )
2017-03-05 16:44:50 +01:00
flg | = ResourceSaver : : FLAG_COMPRESS ;
2015-09-01 05:49:47 +02:00
2017-07-19 22:00:46 +02:00
String path = ProjectSettings : : get_singleton ( ) - > localize_path ( p_path ) ;
2017-03-05 16:44:50 +01:00
Error err = ResourceSaver : : save ( path , p_resource , flg | ResourceSaver : : FLAG_REPLACE_SUBRESOURCE_PATHS ) ;
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
2018-03-11 15:33:21 +01:00
current_option = - 1 ;
2016-05-04 03:25:37 +02:00
accept - > set_text ( TTR ( " Error saving resource! " ) ) ;
2015-09-01 05:49:47 +02:00
accept - > popup_centered_minsize ( ) ;
2017-03-05 16:44:50 +01:00
return ;
2015-09-01 05:49:47 +02:00
}
2017-03-05 16:44:50 +01:00
( ( Resource * ) p_resource . ptr ( ) ) - > set_path ( path ) ;
emit_signal ( " resource_saved " , p_resource ) ;
2018-01-12 22:43:29 +01:00
editor_data . notify_resource_saved ( p_resource ) ;
2015-09-01 05:49:47 +02:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : save_resource ( const Ref < Resource > & p_resource ) {
2014-02-10 02:10:30 +01:00
2015-09-01 05:49:47 +02:00
if ( p_resource - > get_path ( ) . is_resource_file ( ) ) {
2017-03-05 16:44:50 +01:00
save_resource_in_path ( p_resource , p_resource - > get_path ( ) ) ;
2015-09-01 05:49:47 +02:00
} else {
save_resource_as ( p_resource ) ;
}
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : save_resource_as ( const Ref < Resource > & p_resource , const String & p_at_path ) {
2014-02-10 02:10:30 +01:00
2015-09-01 05:49:47 +02:00
file - > set_mode ( EditorFileDialog : : MODE_SAVE_FILE ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_option = RESOURCE_SAVE_AS ;
2015-09-01 05:49:47 +02:00
List < String > extensions ;
2017-03-05 16:44:50 +01:00
Ref < PackedScene > sd = memnew ( PackedScene ) ;
ResourceSaver : : get_recognized_extensions ( p_resource , & extensions ) ;
2015-09-01 05:49:47 +02:00
file - > clear_filters ( ) ;
2015-12-31 17:12:27 +01:00
List < String > preferred ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < extensions . size ( ) ; i + + ) {
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
if ( p_resource - > is_class ( " Script " ) & & ( extensions [ i ] = = " tres " | | extensions [ i ] = = " res " | | extensions [ i ] = = " xml " ) ) {
2015-12-31 17:12:27 +01:00
//this serves no purpose and confused people
continue ;
}
2017-03-05 16:44:50 +01:00
file - > add_filter ( " *. " + extensions [ i ] + " ; " + extensions [ i ] . to_upper ( ) ) ;
2015-12-31 17:12:27 +01:00
preferred . push_back ( extensions [ i ] ) ;
2015-09-01 05:49:47 +02:00
}
2017-03-05 16:44:50 +01:00
if ( p_at_path ! = String ( ) ) {
2016-05-11 16:46:08 +02:00
file - > set_current_dir ( p_at_path ) ;
if ( p_resource - > get_path ( ) . is_resource_file ( ) ) {
file - > set_current_file ( p_resource - > get_path ( ) . get_file ( ) ) ;
} else {
2017-03-05 16:44:50 +01:00
if ( extensions . size ( ) ) {
file - > set_current_file ( " new_ " + p_resource - > get_class ( ) . to_lower ( ) + " . " + preferred . front ( ) - > get ( ) . to_lower ( ) ) ;
2016-05-11 16:46:08 +02:00
} else {
file - > set_current_file ( String ( ) ) ;
}
}
2017-03-05 16:44:50 +01:00
} else if ( p_resource - > get_path ( ) ! = " " ) {
2016-05-11 16:46:08 +02:00
2015-09-01 05:49:47 +02:00
file - > set_current_path ( p_resource - > get_path ( ) ) ;
if ( extensions . size ( ) ) {
2017-03-05 16:44:50 +01:00
String ext = p_resource - > get_path ( ) . get_extension ( ) . to_lower ( ) ;
if ( extensions . find ( ext ) = = NULL ) {
file - > set_current_path ( p_resource - > get_path ( ) . replacen ( " . " + ext , " . " + extensions . front ( ) - > get ( ) ) ) ;
2015-09-01 05:49:47 +02:00
}
}
2015-12-31 17:12:27 +01:00
} else if ( preferred . size ( ) ) {
2015-09-01 05:49:47 +02:00
String existing ;
if ( extensions . size ( ) ) {
2017-03-05 16:44:50 +01:00
existing = " new_ " + p_resource - > get_class ( ) . to_lower ( ) + " . " + preferred . front ( ) - > get ( ) . to_lower ( ) ;
2015-09-01 05:49:47 +02:00
}
file - > set_current_path ( existing ) ;
}
file - > popup_centered_ratio ( ) ;
2018-04-22 19:36:01 +02:00
file - > set_title ( TTR ( " Save Resource As... " ) ) ;
2014-02-10 02:10:30 +01:00
}
void EditorNode : : _menu_option ( int p_option ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
_menu_option_confirm ( p_option , false ) ;
2014-02-10 02:10:30 +01:00
}
void EditorNode : : _menu_confirm_current ( ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
_menu_option_confirm ( current_option , true ) ;
2014-02-10 02:10:30 +01:00
}
2017-08-28 05:24:50 +02:00
void EditorNode : : _dialog_display_save_error ( String p_file , Error p_error ) {
2014-02-10 02:10:30 +01:00
if ( p_error ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
switch ( p_error ) {
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
case ERR_FILE_CANT_WRITE : {
2017-03-05 16:44:50 +01:00
accept - > set_text ( TTR ( " Can't open file for writing: " ) + " " + p_file . get_extension ( ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case ERR_FILE_UNRECOGNIZED : {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
accept - > set_text ( TTR ( " Requested file format unknown: " ) + " " + p_file . get_extension ( ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
default : {
2016-03-09 00:00:52 +01:00
2016-05-19 00:08:12 +02:00
accept - > set_text ( TTR ( " Error while saving. " ) ) ;
2017-03-05 16:44:50 +01:00
} break ;
2014-02-10 02:10:30 +01:00
}
2016-03-09 00:00:52 +01:00
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
}
}
2017-08-28 05:24:50 +02:00
void EditorNode : : _dialog_display_load_error ( String p_file , Error p_error ) {
if ( p_error ) {
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2017-08-28 05:24:50 +02:00
switch ( p_error ) {
case ERR_CANT_OPEN : {
2018-01-09 13:42:45 +01:00
accept - > set_text ( vformat ( TTR ( " Can't open '%s'. The file could have been moved or deleted. " ) , p_file . get_file ( ) ) ) ;
2017-08-28 05:24:50 +02:00
} break ;
case ERR_PARSE_ERROR : {
accept - > set_text ( vformat ( TTR ( " Error while parsing '%s'. " ) , p_file . get_file ( ) ) ) ;
} break ;
case ERR_FILE_CORRUPT : {
accept - > set_text ( vformat ( TTR ( " Unexpected end of file '%s'. " ) , p_file . get_file ( ) ) ) ;
} break ;
case ERR_FILE_NOT_FOUND : {
accept - > set_text ( vformat ( TTR ( " Missing '%s' or its dependencies. " ) , p_file . get_file ( ) ) ) ;
} break ;
default : {
accept - > set_text ( vformat ( TTR ( " Error while loading '%s'. " ) , p_file . get_file ( ) ) ) ;
} break ;
}
accept - > popup_centered_minsize ( ) ;
}
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _get_scene_metadata ( const String & p_file ) {
2014-02-10 02:10:30 +01:00
2015-06-22 05:03:19 +02:00
Node * scene = editor_data . get_edited_scene_root ( ) ;
2014-02-10 02:10:30 +01:00
if ( ! scene )
return ;
2017-11-17 15:50:18 +01:00
String path = EditorSettings : : get_singleton ( ) - > get_project_settings_dir ( ) . plus_file ( p_file . get_file ( ) + " -editstate- " + p_file . md5_text ( ) + " .cfg " ) ;
2014-02-10 02:10:30 +01:00
2015-12-31 04:31:00 +01:00
Ref < ConfigFile > cf ;
cf . instance ( ) ;
2014-02-10 02:10:30 +01:00
2015-12-31 04:31:00 +01:00
Error err = cf - > load ( path ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK | | ! cf - > has_section ( " editor_states " ) )
2015-12-31 04:31:00 +01:00
return ; //must not exist
2014-02-10 02:10:30 +01:00
2015-12-31 04:31:00 +01:00
List < String > esl ;
2017-03-05 16:44:50 +01:00
cf - > get_section_keys ( " editor_states " , & esl ) ;
2014-02-10 02:10:30 +01:00
2015-12-31 04:31:00 +01:00
Dictionary md ;
2017-03-05 16:44:50 +01:00
for ( List < String > : : Element * E = esl . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Variant st = cf - > get_value ( " editor_states " , E - > get ( ) ) ;
2015-12-31 04:31:00 +01:00
if ( st . get_type ( ) ) {
2017-03-05 16:44:50 +01:00
md [ E - > get ( ) ] = st ;
2015-12-31 04:31:00 +01:00
}
2014-02-10 02:10:30 +01:00
}
2015-12-31 04:31:00 +01:00
editor_data . set_editor_states ( md ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _set_scene_metadata ( const String & p_file , int p_idx ) {
2014-02-10 02:10:30 +01:00
2016-06-26 05:54:17 +02:00
Node * scene = editor_data . get_edited_scene_root ( p_idx ) ;
2014-02-10 02:10:30 +01:00
if ( ! scene )
return ;
2017-03-05 16:44:50 +01:00
scene - > set_meta ( " __editor_run_settings__ " , Variant ( ) ) ; //clear it (no point in keeping it)
scene - > set_meta ( " __editor_plugin_states__ " , Variant ( ) ) ;
2014-02-10 02:10:30 +01:00
2017-11-17 15:50:18 +01:00
String path = EditorSettings : : get_singleton ( ) - > get_project_settings_dir ( ) . plus_file ( p_file . get_file ( ) + " -editstate- " + p_file . md5_text ( ) + " .cfg " ) ;
2014-02-10 02:10:30 +01:00
2015-12-31 04:31:00 +01:00
Ref < ConfigFile > cf ;
cf . instance ( ) ;
2014-02-10 02:10:30 +01:00
2016-07-17 21:59:15 +02:00
Dictionary md ;
2017-03-05 16:44:50 +01:00
if ( p_idx < 0 | | editor_data . get_edited_scene ( ) = = p_idx ) {
2016-07-17 21:59:15 +02:00
md = editor_data . get_editor_states ( ) ;
} else {
md = editor_data . get_scene_editor_states ( p_idx ) ;
}
2015-12-31 04:31:00 +01:00
List < Variant > keys ;
md . get_key_list ( & keys ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( List < Variant > : : Element * E = keys . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
cf - > set_value ( " editor_states " , E - > get ( ) , md [ E - > get ( ) ] ) ;
2015-12-31 04:31:00 +01:00
}
2014-02-10 02:10:30 +01:00
2015-12-31 04:31:00 +01:00
Error err = cf - > save ( path ) ;
2017-03-05 16:44:50 +01:00
ERR_FAIL_COND ( err ! = OK ) ;
2014-02-10 02:10:30 +01:00
}
2017-08-12 18:52:50 +02:00
bool EditorNode : : _find_and_save_resource ( RES p_res , Map < RES , bool > & processed , int32_t flags ) {
2015-05-17 18:11:55 +02:00
2017-08-12 18:52:50 +02:00
if ( p_res . is_null ( ) )
2015-05-17 18:11:55 +02:00
return false ;
2017-08-12 18:52:50 +02:00
if ( processed . has ( p_res ) ) {
2015-05-17 18:11:55 +02:00
2017-08-12 18:52:50 +02:00
return processed [ p_res ] ;
2017-03-05 16:44:50 +01:00
}
2015-05-17 18:11:55 +02:00
2017-08-12 18:52:50 +02:00
bool changed = p_res - > is_edited ( ) ;
p_res - > set_edited ( false ) ;
2015-05-17 18:11:55 +02:00
2017-08-12 18:52:50 +02:00
bool subchanged = _find_and_save_edited_subresources ( p_res . ptr ( ) , processed , flags ) ;
2015-05-17 18:11:55 +02:00
2017-08-12 18:52:50 +02:00
if ( p_res - > get_path ( ) . is_resource_file ( ) ) {
2015-05-17 18:11:55 +02:00
if ( changed | | subchanged ) {
//save
2017-08-12 18:52:50 +02:00
ResourceSaver : : save ( p_res - > get_path ( ) , p_res , flags ) ;
2015-05-17 18:11:55 +02:00
}
2017-08-12 18:52:50 +02:00
processed [ p_res ] = false ; //because it's a file
2015-05-17 18:11:55 +02:00
return false ;
} else {
2017-08-12 18:52:50 +02:00
processed [ p_res ] = changed ;
2015-05-17 18:11:55 +02:00
return changed ;
}
}
2017-03-05 16:44:50 +01:00
bool EditorNode : : _find_and_save_edited_subresources ( Object * obj , Map < RES , bool > & processed , int32_t flags ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bool ret_changed = false ;
2014-02-10 02:10:30 +01:00
List < PropertyInfo > pi ;
obj - > get_property_list ( & pi ) ;
2017-03-05 16:44:50 +01:00
for ( List < PropertyInfo > : : Element * E = pi . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( ! ( E - > get ( ) . usage & PROPERTY_USAGE_STORAGE ) )
2014-02-10 02:10:30 +01:00
continue ;
2017-03-05 16:44:50 +01:00
switch ( E - > get ( ) . type ) {
2014-02-10 02:10:30 +01:00
case Variant : : OBJECT : {
RES res = obj - > get ( E - > get ( ) . name ) ;
2017-03-05 16:44:50 +01:00
if ( _find_and_save_resource ( res , processed , flags ) )
ret_changed = true ;
2014-02-10 02:10:30 +01:00
} break ;
case Variant : : ARRAY : {
2017-03-05 16:44:50 +01:00
Array varray = obj - > get ( E - > get ( ) . name ) ;
int len = varray . size ( ) ;
for ( int i = 0 ; i < len ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Variant v = varray . get ( i ) ;
RES res = v ;
if ( _find_and_save_resource ( res , processed , flags ) )
ret_changed = true ;
2015-05-17 18:11:55 +02:00
}
2014-02-10 02:10:30 +01:00
} break ;
case Variant : : DICTIONARY : {
2017-03-05 16:44:50 +01:00
Dictionary d = obj - > get ( E - > get ( ) . name ) ;
2014-02-10 02:10:30 +01:00
List < Variant > keys ;
d . get_key_list ( & keys ) ;
2017-03-05 16:44:50 +01:00
for ( List < Variant > : : Element * E = keys . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 02:10:30 +01:00
Variant v = d [ E - > get ( ) ] ;
2017-03-05 16:44:50 +01:00
RES res = v ;
if ( _find_and_save_resource ( res , processed , flags ) )
ret_changed = true ;
2015-05-17 18:11:55 +02:00
}
2014-02-10 02:10:30 +01:00
} break ;
default : { }
}
}
return ret_changed ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _save_edited_subresources ( Node * scene , Map < RES , bool > & processed , int32_t flags ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
_find_and_save_edited_subresources ( scene , processed , flags ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < scene - > get_child_count ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
Node * n = scene - > get_child ( i ) ;
2017-03-05 16:44:50 +01:00
if ( n - > get_owner ( ) ! = editor_data . get_edited_scene_root ( ) )
2014-02-10 02:10:30 +01:00
continue ;
2017-03-05 16:44:50 +01:00
_save_edited_subresources ( n , processed , flags ) ;
2014-02-10 02:10:30 +01:00
}
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _find_node_types ( Node * p_node , int & count_2d , int & count_3d ) {
2015-05-31 06:59:42 +02:00
2017-03-05 16:44:50 +01:00
if ( p_node - > is_class ( " Viewport " ) | | ( p_node ! = editor_data . get_edited_scene_root ( ) & & p_node - > get_owner ( ) ! = editor_data . get_edited_scene_root ( ) ) )
2015-05-31 06:59:42 +02:00
return ;
2017-01-03 03:03:46 +01:00
if ( p_node - > is_class ( " CanvasItem " ) )
2015-05-31 06:59:42 +02:00
count_2d + + ;
2017-01-03 03:03:46 +01:00
else if ( p_node - > is_class ( " Spatial " ) )
2015-05-31 06:59:42 +02:00
count_3d + + ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_node - > get_child_count ( ) ; i + + )
_find_node_types ( p_node - > get_child ( i ) , count_2d , count_3d ) ;
2015-05-31 06:59:42 +02:00
}
2017-11-12 04:48:00 +01:00
void EditorNode : : _save_scene_with_preview ( String p_file , int p_idx ) {
2015-05-31 06:59:42 +02:00
2017-03-05 16:44:50 +01:00
EditorProgress save ( " save " , TTR ( " Saving Scene " ) , 4 ) ;
save . step ( TTR ( " Analyzing " ) , 0 ) ;
2017-08-26 17:46:49 +02:00
int c2d = 0 ;
int c3d = 0 ;
2017-03-05 16:44:50 +01:00
_find_node_types ( editor_data . get_edited_scene_root ( ) , c2d , c3d ) ;
2015-05-31 06:59:42 +02:00
RID viewport ;
bool is2d ;
2017-03-05 16:44:50 +01:00
if ( c3d < c2d ) {
viewport = scene_root - > get_viewport_rid ( ) ;
is2d = true ;
2015-05-31 06:59:42 +02:00
} else {
2017-03-05 16:44:50 +01:00
viewport = SpatialEditor : : get_singleton ( ) - > get_editor_viewport ( 0 ) - > get_viewport_node ( ) - > get_viewport_rid ( ) ;
is2d = false ;
2015-05-31 06:59:42 +02:00
}
2017-03-05 16:44:50 +01:00
save . step ( TTR ( " Creating Thumbnail " ) , 1 ) ;
2015-05-31 06:59:42 +02:00
//current view?
2017-06-09 05:23:50 +02:00
Ref < Image > img ;
if ( is2d ) {
img = scene_root - > get_texture ( ) - > get_data ( ) ;
} else {
img = SpatialEditor : : get_singleton ( ) - > get_editor_viewport ( 0 ) - > get_viewport_node ( ) - > get_texture ( ) - > get_data ( ) ;
2015-05-31 06:59:42 +02:00
}
2017-06-09 05:23:50 +02:00
if ( img . is_valid ( ) ) {
save . step ( TTR ( " Creating Thumbnail " ) , 2 ) ;
save . step ( TTR ( " Creating Thumbnail " ) , 3 ) ;
2015-05-31 06:59:42 +02:00
2017-06-09 05:23:50 +02:00
int preview_size = EditorSettings : : get_singleton ( ) - > get ( " filesystem/file_dialog/thumbnail_size " ) ;
preview_size * = EDSCALE ;
2015-05-31 06:59:42 +02:00
2017-11-18 04:42:14 +01:00
// consider a square region
int vp_size = MIN ( img - > get_width ( ) , img - > get_height ( ) ) ;
int x = ( img - > get_width ( ) - vp_size ) / 2 ;
int y = ( img - > get_height ( ) - vp_size ) / 2 ;
2015-05-31 06:59:42 +02:00
2017-11-18 04:42:14 +01:00
img - > convert ( Image : : FORMAT_RGB8 ) ;
if ( vp_size < preview_size ) {
// just square it.
img - > crop_from_point ( x , y , vp_size , vp_size ) ;
2017-06-09 05:23:50 +02:00
} else {
2017-11-18 04:42:14 +01:00
int ratio = vp_size / preview_size ;
int size = preview_size * ( ratio / 2 ) ;
2015-05-31 06:59:42 +02:00
2017-11-18 04:42:14 +01:00
x = ( img - > get_width ( ) - size ) / 2 ;
y = ( img - > get_height ( ) - size ) / 2 ;
img - > crop_from_point ( x , y , size , size ) ;
// We could get better pictures with better filters
img - > resize ( preview_size , preview_size , Image : : INTERPOLATE_CUBIC ) ;
2017-06-09 05:23:50 +02:00
}
2015-05-31 06:59:42 +02:00
2017-06-09 05:23:50 +02:00
img - > flip_y ( ) ;
2015-05-31 06:59:42 +02:00
2017-06-09 05:23:50 +02:00
//save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5
2017-11-17 21:48:24 +01:00
String temp_path = EditorSettings : : get_singleton ( ) - > get_cache_dir ( ) ;
2017-07-19 22:00:46 +02:00
String cache_base = ProjectSettings : : get_singleton ( ) - > globalize_path ( p_file ) . md5_text ( ) ;
2017-06-09 05:23:50 +02:00
cache_base = temp_path . plus_file ( " resthumb- " + cache_base ) ;
2015-05-31 06:59:42 +02:00
2017-06-09 05:23:50 +02:00
//does not have it, try to load a cached thumbnail
2015-05-31 06:59:42 +02:00
2017-06-09 05:23:50 +02:00
String file = cache_base + " .png " ;
2018-02-28 20:23:40 +01:00
post_process_preview ( img ) ;
2017-06-09 05:23:50 +02:00
img - > save_png ( file ) ;
2015-05-31 06:59:42 +02:00
}
2017-06-09 05:23:50 +02:00
2017-03-05 16:44:50 +01:00
save . step ( TTR ( " Saving Scene " ) , 4 ) ;
2017-11-12 04:48:00 +01:00
_save_scene ( p_file , p_idx ) ;
2017-06-09 05:23:50 +02:00
EditorResourcePreview : : get_singleton ( ) - > check_for_invalidation ( p_file ) ;
2015-05-31 06:59:42 +02:00
}
2016-06-26 05:54:17 +02:00
void EditorNode : : _save_scene ( String p_file , int idx ) {
2014-02-10 02:10:30 +01:00
2016-06-26 05:54:17 +02:00
Node * scene = editor_data . get_edited_scene_root ( idx ) ;
2014-02-10 02:10:30 +01:00
if ( ! scene ) {
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2017-08-23 22:25:14 +02:00
accept - > set_text ( TTR ( " This operation can't be done without a tree root. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
editor_data . apply_changes_in_editors ( ) ;
2017-05-29 02:46:48 +02:00
_save_default_environment ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
_set_scene_metadata ( p_file , idx ) ;
2015-12-14 00:39:01 +01:00
Ref < PackedScene > sdata ;
if ( ResourceCache : : has ( p_file ) ) {
// something may be referencing this resource and we are good with that.
// we must update it, but also let the previous scene state go, as
// old version still work for referencing changes in instanced or inherited scenes
2017-08-24 22:58:51 +02:00
sdata = Ref < PackedScene > ( Object : : cast_to < PackedScene > ( ResourceCache : : get ( p_file ) ) ) ;
2015-12-14 00:39:01 +01:00
if ( sdata . is_valid ( ) )
sdata - > recreate_state ( ) ;
else
sdata . instance ( ) ;
} else {
sdata . instance ( ) ;
}
2014-02-10 02:10:30 +01:00
Error err = sdata - > pack ( scene ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2018-01-05 23:02:54 +01:00
accept - > set_text ( TTR ( " Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-08 20:08:24 +01:00
// force creation of node path cache
// (hacky but needed for the tree to update properly)
Node * dummy_scene = sdata - > instance ( PackedScene : : GEN_EDIT_STATE_INSTANCE ) ;
2018-01-05 23:02:54 +01:00
if ( ! dummy_scene ) {
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2018-01-05 23:02:54 +01:00
accept - > set_text ( TTR ( " Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied. " ) ) ;
accept - > popup_centered_minsize ( ) ;
return ;
}
2017-03-08 20:08:24 +01:00
memdelete ( dummy_scene ) ;
2017-03-05 16:44:50 +01:00
int flg = 0 ;
2017-01-05 23:41:36 +01:00
if ( EditorSettings : : get_singleton ( ) - > get ( " filesystem/on_save/compress_binary_resources " ) )
2017-03-05 16:44:50 +01:00
flg | = ResourceSaver : : FLAG_COMPRESS ;
flg | = ResourceSaver : : FLAG_REPLACE_SUBRESOURCE_PATHS ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
err = ResourceSaver : : save ( p_file , sdata , flg ) ;
Map < RES , bool > processed ;
_save_edited_subresources ( scene , processed , flg ) ;
2014-02-10 02:10:30 +01:00
editor_data . save_editor_external_data ( ) ;
2017-03-05 16:44:50 +01:00
if ( err = = OK ) {
2017-07-19 22:00:46 +02:00
scene - > set_filename ( ProjectSettings : : get_singleton ( ) - > localize_path ( p_file ) ) ;
2016-06-26 05:54:17 +02:00
if ( idx < 0 | | idx = = editor_data . get_edited_scene ( ) )
set_current_version ( editor_data . get_undo_redo ( ) . get_version ( ) ) ;
else
2017-03-05 16:44:50 +01:00
editor_data . set_edited_scene_version ( 0 , idx ) ;
2014-02-10 02:10:30 +01:00
_update_title ( ) ;
2015-08-12 22:35:37 +02:00
_update_scene_tabs ( ) ;
2014-02-10 02:10:30 +01:00
} else {
2017-08-28 05:24:50 +02:00
_dialog_display_save_error ( p_file , err ) ;
2014-02-10 02:10:30 +01:00
}
2017-05-29 02:46:48 +02:00
}
2014-02-10 02:10:30 +01:00
2017-06-24 12:57:30 +02:00
void EditorNode : : _save_all_scenes ( ) {
2018-03-17 18:52:39 +01:00
int i = _next_unsaved_scene ( true , 0 ) ;
while ( i ! = - 1 ) {
2017-06-24 12:57:30 +02:00
Node * scene = editor_data . get_edited_scene_root ( i ) ;
if ( scene & & scene - > get_filename ( ) ! = " " ) {
2017-08-28 18:53:52 +02:00
if ( i ! = editor_data . get_edited_scene ( ) )
_save_scene ( scene - > get_filename ( ) , i ) ;
else
_save_scene_with_preview ( scene - > get_filename ( ) ) ;
2017-06-24 12:57:30 +02:00
} // else: ignore new scenes
2018-03-17 18:52:39 +01:00
i = _next_unsaved_scene ( true , + + i ) ;
2017-06-24 12:57:30 +02:00
}
_save_default_environment ( ) ;
}
2017-06-29 19:37:54 +02:00
void EditorNode : : _mark_unsaved_scenes ( ) {
for ( int i = 0 ; i < editor_data . get_edited_scene_count ( ) ; i + + ) {
Node * node = editor_data . get_edited_scene_root ( i ) ;
if ( ! node )
continue ;
String path = node - > get_filename ( ) ;
if ( ! ( path = = String ( ) | | FileAccess : : exists ( path ) ) ) {
node - > set_filename ( " " ) ;
if ( i = = editor_data . get_edited_scene ( ) )
set_current_version ( - 1 ) ;
else
editor_data . set_edited_scene_version ( - 1 , i ) ;
}
}
_update_title ( ) ;
_update_scene_tabs ( ) ;
}
2014-02-10 02:10:30 +01:00
void EditorNode : : _dialog_action ( String p_file ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
switch ( current_option ) {
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
case RESOURCE_LOAD : {
RES res = ResourceLoader : : load ( p_file ) ;
if ( res . is_null ( ) ) {
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-01-09 13:42:45 +01:00
accept - > get_ok ( ) - > set_text ( " Ugh " ) ;
2016-05-04 03:25:37 +02:00
accept - > set_text ( TTR ( " Failed to load resource. " ) ) ;
2014-02-10 02:10:30 +01:00
return ;
} ;
2017-03-05 16:44:50 +01:00
push_item ( res . operator - > ( ) ) ;
2016-03-09 00:00:52 +01:00
} break ;
2015-10-10 14:09:09 +02:00
case FILE_NEW_INHERITED_SCENE : {
2017-03-05 16:44:50 +01:00
load_scene ( p_file , false , true ) ;
2015-10-10 14:09:09 +02:00
} break ;
2014-02-10 02:10:30 +01:00
case FILE_OPEN_SCENE : {
load_scene ( p_file ) ;
} break ;
2016-06-28 00:59:33 +02:00
case SETTINGS_PICK_MAIN_SCENE : {
2014-02-10 02:10:30 +01:00
2017-07-19 22:00:46 +02:00
ProjectSettings : : get_singleton ( ) - > set ( " application/run/main_scene " , p_file ) ;
ProjectSettings : : get_singleton ( ) - > save ( ) ;
2017-04-06 17:35:08 +02:00
//would be nice to show the project manager opened with the highlighted field..
2017-06-08 00:31:53 +02:00
_run ( false , " " ) ; // automatically run the project
2014-02-10 02:10:30 +01:00
} break ;
2017-06-21 06:15:39 +02:00
case FILE_CLOSE :
2017-06-26 16:04:53 +02:00
case FILE_CLOSE_ALL_AND_QUIT :
case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER :
2017-06-21 06:15:39 +02:00
case SCENE_TAB_CLOSE :
2014-02-10 02:10:30 +01:00
case FILE_SAVE_SCENE :
case FILE_SAVE_AS_SCENE : {
2017-06-26 16:04:53 +02:00
int scene_idx = ( current_option = = FILE_SAVE_SCENE | | current_option = = FILE_SAVE_AS_SCENE ) ? - 1 : tab_closing ;
2017-06-21 06:15:39 +02:00
2017-03-05 16:44:50 +01:00
if ( file - > get_mode ( ) = = EditorFileDialog : : MODE_SAVE_FILE ) {
2014-02-10 02:10:30 +01:00
2017-05-29 02:46:48 +02:00
_save_default_environment ( ) ;
2017-11-12 04:48:00 +01:00
_save_scene_with_preview ( p_file , scene_idx ) ;
2018-01-09 13:42:45 +01:00
_add_to_recent_scenes ( p_file ) ;
2017-06-21 06:15:39 +02:00
if ( scene_idx ! = - 1 )
_discard_changes ( ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
2015-01-06 23:28:25 +01:00
case FILE_SAVE_AND_RUN : {
2017-03-05 16:44:50 +01:00
if ( file - > get_mode ( ) = = EditorFileDialog : : MODE_SAVE_FILE ) {
2015-01-06 23:28:25 +01:00
2017-05-29 02:46:48 +02:00
_save_default_environment ( ) ;
2015-05-31 06:59:42 +02:00
_save_scene_with_preview ( p_file ) ;
2017-11-19 22:59:05 +01:00
_run ( false , p_file ) ;
2015-01-06 23:28:25 +01:00
}
} break ;
2014-02-10 02:10:30 +01:00
case FILE_EXPORT_MESH_LIBRARY : {
Ref < MeshLibrary > ml ;
if ( file_export_lib_merge - > is_pressed ( ) & & FileAccess : : exists ( p_file ) ) {
2017-03-05 16:44:50 +01:00
ml = ResourceLoader : : load ( p_file , " MeshLibrary " ) ;
2014-02-10 02:10:30 +01:00
if ( ml . is_null ( ) ) {
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2016-05-19 00:08:12 +02:00
accept - > set_text ( TTR ( " Can't load MeshLibrary for merging! " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
}
if ( ml . is_null ( ) ) {
2017-03-05 16:44:50 +01:00
ml = Ref < MeshLibrary > ( memnew ( MeshLibrary ) ) ;
2014-02-10 02:10:30 +01:00
}
2017-08-15 16:41:17 +02:00
MeshLibraryEditor : : update_library_file ( editor_data . get_edited_scene_root ( ) , ml , true ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Error err = ResourceSaver : : save ( p_file , ml ) ;
2014-02-10 02:10:30 +01:00
if ( err ) {
2018-03-11 15:33:21 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2016-05-19 00:08:12 +02:00
accept - > set_text ( TTR ( " Error saving MeshLibrary! " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
} break ;
case FILE_EXPORT_TILESET : {
2018-03-11 15:59:50 +01:00
Ref < TileSet > tileset ;
if ( FileAccess : : exists ( p_file ) & & file_export_lib_merge - > is_pressed ( ) ) {
tileset = ResourceLoader : : load ( p_file , " TileSet " ) ;
2014-02-10 02:10:30 +01:00
2018-03-11 15:59:50 +01:00
if ( tileset . is_null ( ) ) {
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2018-03-11 15:59:50 +01:00
accept - > set_text ( TTR ( " Can't load TileSet for merging! " ) ) ;
accept - > popup_centered_minsize ( ) ;
return ;
2016-01-08 17:54:13 +01:00
}
2016-03-11 01:20:01 +01:00
} else {
2018-03-11 15:59:50 +01:00
tileset = Ref < TileSet > ( memnew ( TileSet ) ) ;
2014-02-10 02:10:30 +01:00
}
2018-03-11 15:59:50 +01:00
TileSetEditor : : update_library_file ( editor_data . get_edited_scene_root ( ) , tileset , true ) ;
2014-02-10 02:10:30 +01:00
2018-03-11 15:59:50 +01:00
Error err = ResourceSaver : : save ( p_file , tileset ) ;
2014-02-10 02:10:30 +01:00
if ( err ) {
2018-03-11 15:33:21 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2016-05-19 00:08:12 +02:00
accept - > set_text ( TTR ( " Error saving TileSet! " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
} break ;
2015-09-01 05:49:47 +02:00
case RESOURCE_SAVE :
case RESOURCE_SAVE_AS : {
uint32_t current = editor_history . get_current ( ) ;
2017-03-05 16:44:50 +01:00
Object * current_obj = current > 0 ? ObjectDB : : get_instance ( current ) : NULL ;
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
ERR_FAIL_COND ( ! Object : : cast_to < Resource > ( current_obj ) )
2014-02-10 02:10:30 +01:00
2017-08-24 22:58:51 +02:00
RES current_res = RES ( Object : : cast_to < Resource > ( current_obj ) ) ;
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
save_resource_in_path ( current_res , p_file ) ;
2015-09-01 05:49:47 +02:00
2015-11-22 19:11:17 +01:00
} break ;
case SETTINGS_LAYOUT_SAVE : {
if ( p_file . empty ( ) )
return ;
Ref < ConfigFile > config ;
config . instance ( ) ;
2017-11-17 21:48:24 +01:00
Error err = config - > load ( EditorSettings : : get_singleton ( ) - > get_editor_layouts_config ( ) ) ;
2016-01-01 18:48:14 +01:00
2017-03-05 16:44:50 +01:00
if ( err = = ERR_CANT_OPEN ) {
2016-01-01 18:48:14 +01:00
config . instance ( ) ; // new config
2017-03-05 16:44:50 +01:00
} else if ( err ! = OK ) {
2016-05-04 03:25:37 +02:00
show_warning ( TTR ( " Error trying to save layout! " ) ) ;
2016-01-01 18:48:14 +01:00
return ;
2015-11-22 19:11:17 +01:00
}
_save_docks_to_config ( config , p_file ) ;
2017-11-17 21:48:24 +01:00
config - > save ( EditorSettings : : get_singleton ( ) - > get_editor_layouts_config ( ) ) ;
2015-11-22 19:11:17 +01:00
layout_dialog - > hide ( ) ;
_update_layouts_menu ( ) ;
2017-03-05 16:44:50 +01:00
if ( p_file = = " Default " ) {
2016-05-04 03:25:37 +02:00
show_warning ( TTR ( " Default editor layout overridden. " ) ) ;
2016-01-11 22:23:45 +01:00
}
2015-11-22 19:11:17 +01:00
} break ;
case SETTINGS_LAYOUT_DELETE : {
if ( p_file . empty ( ) )
return ;
Ref < ConfigFile > config ;
config . instance ( ) ;
2017-11-17 21:48:24 +01:00
Error err = config - > load ( EditorSettings : : get_singleton ( ) - > get_editor_layouts_config ( ) ) ;
2015-11-22 19:11:17 +01:00
2017-03-05 16:44:50 +01:00
if ( err ! = OK | | ! config - > has_section ( p_file ) ) {
2016-05-04 03:25:37 +02:00
show_warning ( TTR ( " Layout name not found! " ) ) ;
2015-11-22 19:11:17 +01:00
return ;
}
// erase
List < String > keys ;
config - > get_section_keys ( p_file , & keys ) ;
2017-03-05 16:44:50 +01:00
for ( List < String > : : Element * E = keys . front ( ) ; E ; E = E - > next ( ) ) {
2015-11-22 19:11:17 +01:00
config - > set_value ( p_file , E - > get ( ) , Variant ( ) ) ;
}
2017-11-17 21:48:24 +01:00
config - > save ( EditorSettings : : get_singleton ( ) - > get_editor_layouts_config ( ) ) ;
2015-11-22 19:11:17 +01:00
layout_dialog - > hide ( ) ;
_update_layouts_menu ( ) ;
2017-03-05 16:44:50 +01:00
if ( p_file = = " Default " ) {
2016-05-19 00:08:12 +02:00
show_warning ( TTR ( " Restored default layout to base settings. " ) ) ;
2016-01-11 22:23:45 +01:00
}
2015-09-01 05:49:47 +02:00
} break ;
2014-02-10 02:10:30 +01:00
default : { //save scene?
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
if ( file - > get_mode ( ) = = EditorFileDialog : : MODE_SAVE_FILE ) {
2015-05-31 06:59:42 +02:00
_save_scene_with_preview ( p_file ) ;
2014-02-10 02:10:30 +01:00
}
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
} break ;
}
}
2017-03-05 16:44:50 +01:00
void EditorNode : : push_item ( Object * p_object , const String & p_property ) {
2014-02-10 02:10:30 +01:00
if ( ! p_object ) {
property_editor - > edit ( NULL ) ;
2016-06-04 18:17:56 +02:00
node_dock - > set_node ( NULL ) ;
2014-02-10 02:10:30 +01:00
scene_tree_dock - > set_selected ( NULL ) ;
return ;
}
2017-08-07 12:17:31 +02:00
uint32_t id = p_object - > get_instance_id ( ) ;
2017-03-05 16:44:50 +01:00
if ( id ! = editor_history . get_current ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( p_property = = " " )
2014-02-10 02:10:30 +01:00
editor_history . add_object ( id ) ;
else
2017-03-05 16:44:50 +01:00
editor_history . add_object ( id , p_property ) ;
2014-02-10 02:10:30 +01:00
}
_edit_current ( ) ;
}
2015-09-01 05:49:47 +02:00
void EditorNode : : _select_history ( int p_idx ) {
//push it to the top, it is not correct, but it's more useful
2017-03-05 16:44:50 +01:00
ObjectID id = editor_history . get_history_obj ( p_idx ) ;
Object * obj = ObjectDB : : get_instance ( id ) ;
2015-09-01 05:49:47 +02:00
if ( ! obj )
return ;
push_item ( obj ) ;
}
void EditorNode : : _prepare_history ( ) {
2017-03-05 16:44:50 +01:00
int history_to = MAX ( 0 , editor_history . get_history_len ( ) - 25 ) ;
2015-09-01 05:49:47 +02:00
editor_history_menu - > get_popup ( ) - > clear ( ) ;
2017-03-05 16:44:50 +01:00
Ref < Texture > base_icon = gui_base - > get_icon ( " Object " , " EditorIcons " ) ;
2015-09-01 05:49:47 +02:00
Set < ObjectID > already ;
2017-03-05 16:44:50 +01:00
for ( int i = editor_history . get_history_len ( ) - 1 ; i > = history_to ; i - - ) {
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
ObjectID id = editor_history . get_history_obj ( i ) ;
Object * obj = ObjectDB : : get_instance ( id ) ;
2015-09-01 05:49:47 +02:00
if ( ! obj | | already . has ( id ) ) {
2017-03-05 16:44:50 +01:00
if ( history_to > 0 ) {
2015-09-01 05:49:47 +02:00
history_to - - ;
}
continue ;
}
already . insert ( id ) ;
2017-03-05 16:44:50 +01:00
Ref < Texture > icon = gui_base - > get_icon ( " Object " , " EditorIcons " ) ;
if ( gui_base - > has_icon ( obj - > get_class ( ) , " EditorIcons " ) )
icon = gui_base - > get_icon ( obj - > get_class ( ) , " EditorIcons " ) ;
2015-09-01 05:49:47 +02:00
else
2017-03-05 16:44:50 +01:00
icon = base_icon ;
2015-09-01 05:49:47 +02:00
String text ;
2017-08-24 22:58:51 +02:00
if ( Object : : cast_to < Resource > ( obj ) ) {
Resource * r = Object : : cast_to < Resource > ( obj ) ;
2015-09-01 05:49:47 +02:00
if ( r - > get_path ( ) . is_resource_file ( ) )
2017-03-05 16:44:50 +01:00
text = r - > get_path ( ) . get_file ( ) ;
else if ( r - > get_name ( ) ! = String ( ) ) {
text = r - > get_name ( ) ;
2015-09-01 05:49:47 +02:00
} else {
2017-03-05 16:44:50 +01:00
text = r - > get_class ( ) ;
2015-09-01 05:49:47 +02:00
}
2017-08-24 22:58:51 +02:00
} else if ( Object : : cast_to < Node > ( obj ) ) {
text = Object : : cast_to < Node > ( obj ) - > get_name ( ) ;
2017-10-17 16:39:31 +02:00
} else if ( obj - > is_class ( " ScriptEditorDebuggerInspectedObject " ) ) {
text = obj - > call ( " get_title " ) ;
2015-09-01 05:49:47 +02:00
} else {
2017-03-05 16:44:50 +01:00
text = obj - > get_class ( ) ;
2015-09-01 05:49:47 +02:00
}
2017-03-05 16:44:50 +01:00
if ( i = = editor_history . get_history_pos ( ) ) {
text = " [ " + text + " ] " ;
2015-09-01 05:49:47 +02:00
}
2017-03-05 16:44:50 +01:00
editor_history_menu - > get_popup ( ) - > add_icon_item ( icon , text , i ) ;
2015-09-01 05:49:47 +02:00
}
}
2014-02-10 02:10:30 +01:00
void EditorNode : : _property_editor_forward ( ) {
if ( editor_history . next ( ) )
_edit_current ( ) ;
}
void EditorNode : : _property_editor_back ( ) {
2016-03-09 00:00:52 +01:00
2018-01-08 06:50:51 +01:00
if ( editor_history . previous ( ) | | editor_history . get_path_size ( ) = = 1 )
2014-02-10 02:10:30 +01:00
_edit_current ( ) ;
}
2017-11-24 07:09:51 +01:00
void EditorNode : : _menu_collapseall ( ) {
2017-12-06 23:06:18 +01:00
property_editor - > collapse_all_folding ( ) ;
2017-11-24 07:09:51 +01:00
}
void EditorNode : : _menu_expandall ( ) {
2017-12-06 23:06:18 +01:00
property_editor - > expand_all_folding ( ) ;
2017-11-24 07:09:51 +01:00
}
2017-05-29 02:46:48 +02:00
void EditorNode : : _save_default_environment ( ) {
2017-05-30 03:11:33 +02:00
Ref < Environment > fallback = get_tree ( ) - > get_root ( ) - > get_world ( ) - > get_fallback_environment ( ) ;
2017-05-29 02:46:48 +02:00
if ( fallback . is_valid ( ) & & fallback - > get_path ( ) . is_resource_file ( ) ) {
Map < RES , bool > processed ;
_find_and_save_edited_subresources ( fallback . ptr ( ) , processed , 0 ) ;
2018-03-24 19:16:47 +01:00
if ( fallback - > get_last_modified_time ( ) ! = fallback - > get_import_last_modified_time ( ) )
save_resource_in_path ( fallback , fallback - > get_path ( ) ) ;
2017-05-29 02:46:48 +02:00
}
}
2016-03-30 01:02:53 +02:00
void EditorNode : : _hide_top_editors ( ) {
2014-02-10 02:10:30 +01:00
2016-03-30 01:02:53 +02:00
_display_top_editors ( false ) ;
2014-02-10 02:10:30 +01:00
2016-03-30 01:02:53 +02:00
editor_plugins_over - > clear ( ) ;
}
void EditorNode : : _display_top_editors ( bool p_display ) {
editor_plugins_over - > make_visible ( p_display ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _set_top_editors ( Vector < EditorPlugin * > p_editor_plugins_over ) {
2016-03-30 01:02:53 +02:00
editor_plugins_over - > set_plugins_list ( p_editor_plugins_over ) ;
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
void EditorNode : : _set_editing_top_editors ( Object * p_current_object ) {
2016-03-30 01:02:53 +02:00
editor_plugins_over - > edit ( p_current_object ) ;
2014-02-10 02:10:30 +01:00
}
2017-09-03 21:23:36 +02:00
static bool overrides_external_editor ( Object * p_object ) {
Script * script = Object : : cast_to < Script > ( p_object ) ;
if ( ! script )
return false ;
return script - > get_language ( ) - > overrides_external_editor ( ) ;
}
2017-09-14 15:38:59 +02:00
void EditorNode : : _property_editable_warning_pressed ( ) {
property_editable_warning_dialog - > popup_centered_minsize ( ) ;
}
2014-02-10 02:10:30 +01:00
void EditorNode : : _edit_current ( ) {
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
uint32_t current = editor_history . get_current ( ) ;
2017-03-05 16:44:50 +01:00
Object * current_obj = current > 0 ? ObjectDB : : get_instance ( current ) : NULL ;
2014-02-10 02:10:30 +01:00
2017-09-01 17:54:57 +02:00
property_back - > set_disabled ( editor_history . is_at_beginning ( ) ) ;
2017-03-05 16:44:50 +01:00
property_forward - > set_disabled ( editor_history . is_at_end ( ) ) ;
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
this - > current = current_obj ;
2014-02-10 02:10:30 +01:00
editor_path - > update_path ( ) ;
2017-09-14 15:38:59 +02:00
String editable_warning ; //none by default
property_editable_warning - > hide ( ) ; //hide by default
2014-02-10 02:10:30 +01:00
if ( ! current_obj ) {
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
scene_tree_dock - > set_selected ( NULL ) ;
2017-03-05 16:44:50 +01:00
property_editor - > edit ( NULL ) ;
2016-06-04 18:17:56 +02:00
node_dock - > set_node ( NULL ) ;
2014-02-10 02:10:30 +01:00
object_menu - > set_disabled ( true ) ;
2015-12-03 16:30:55 +01:00
2016-03-30 01:02:53 +02:00
_display_top_editors ( false ) ;
2015-12-03 16:30:55 +01:00
2014-02-10 02:10:30 +01:00
return ;
}
object_menu - > set_disabled ( true ) ;
2017-10-17 16:39:31 +02:00
bool capitalize = bool ( EDITOR_DEF ( " interface/editor/capitalize_properties " , true ) ) ;
2017-01-03 03:03:46 +01:00
bool is_resource = current_obj - > is_class ( " Resource " ) ;
bool is_node = current_obj - > is_class ( " Node " ) ;
2015-09-01 05:49:47 +02:00
resource_save_button - > set_disabled ( ! is_resource ) ;
if ( is_resource ) {
2014-02-10 02:10:30 +01:00
2017-08-24 22:58:51 +02:00
Resource * current_res = Object : : cast_to < Resource > ( current_obj ) ;
2014-02-10 02:10:30 +01:00
ERR_FAIL_COND ( ! current_res ) ;
scene_tree_dock - > set_selected ( NULL ) ;
2017-03-05 16:44:50 +01:00
property_editor - > edit ( current_res ) ;
2016-06-04 18:17:56 +02:00
node_dock - > set_node ( NULL ) ;
2014-02-10 02:10:30 +01:00
object_menu - > set_disabled ( false ) ;
2017-06-27 00:57:18 +02:00
EditorNode : : get_singleton ( ) - > get_import_dock ( ) - > set_edit_path ( current_res - > get_path ( ) ) ;
2017-09-14 15:38:59 +02:00
int subr_idx = current_res - > get_path ( ) . find ( " :: " ) ;
2017-09-15 00:38:38 +02:00
if ( subr_idx ! = - 1 ) {
String base_path = current_res - > get_path ( ) . substr ( 0 , subr_idx ) ;
if ( FileAccess : : exists ( base_path + " .import " ) ) {
editable_warning = TTR ( " This resource belongs to a scene that was imported, so it's not editable. \n Please read the documentation relevant to importing scenes to better understand this workflow. " ) ;
2017-09-14 15:38:59 +02:00
} else {
2017-12-05 17:25:52 +01:00
if ( ( ! get_edited_scene ( ) | | get_edited_scene ( ) - > get_filename ( ) ! = base_path ) & & ResourceLoader : : get_resource_type ( base_path ) = = " PackedScene " ) {
2017-09-15 00:38:38 +02:00
editable_warning = TTR ( " This resource belongs to a scene that was instanced or inherited. \n Changes to it will not be kept when saving the current scene. " ) ;
2017-09-14 15:38:59 +02:00
}
}
2017-09-15 00:38:38 +02:00
} else if ( current_res - > get_path ( ) . is_resource_file ( ) ) {
if ( FileAccess : : exists ( current_res - > get_path ( ) + " .import " ) ) {
2017-10-20 04:40:12 +02:00
editable_warning = TTR ( " This resource was imported, so it's not editable. Change its settings in the import panel and then re-import. " ) ;
2017-09-14 15:38:59 +02:00
}
}
2016-07-09 16:46:59 +02:00
} else if ( is_node ) {
2014-02-10 02:10:30 +01:00
2017-08-24 22:58:51 +02:00
Node * current_node = Object : : cast_to < Node > ( current_obj ) ;
2014-02-10 02:10:30 +01:00
ERR_FAIL_COND ( ! current_node ) ;
2017-03-05 16:44:50 +01:00
property_editor - > edit ( current_node ) ;
2017-05-29 02:46:48 +02:00
if ( current_node - > is_inside_tree ( ) ) {
node_dock - > set_node ( current_node ) ;
scene_tree_dock - > set_selected ( current_node ) ;
} else {
node_dock - > set_node ( NULL ) ;
scene_tree_dock - > set_selected ( NULL ) ;
}
2014-02-10 02:10:30 +01:00
object_menu - > get_popup ( ) - > clear ( ) ;
2017-09-15 00:38:38 +02:00
if ( get_edited_scene ( ) & & get_edited_scene ( ) - > get_filename ( ) ! = String ( ) ) {
2017-09-14 15:38:59 +02:00
String source_scene = get_edited_scene ( ) - > get_filename ( ) ;
2017-09-15 00:38:38 +02:00
if ( FileAccess : : exists ( source_scene + " .import " ) ) {
editable_warning = TTR ( " This scene was imported, so changes to it will not be kept. \n Instancing it or inheriting will allow making changes to it. \n Please read the documentation relevant to importing scenes to better understand this workflow. " ) ;
2017-09-14 15:38:59 +02:00
}
}
2015-08-25 05:08:45 +02:00
} else {
2017-10-17 16:39:31 +02:00
if ( current_obj - > is_class ( " ScriptEditorDebuggerInspectedObject " ) ) {
editable_warning = TTR ( " This is a remote object so changes to it will not be kept. \n Please read the documentation relevant to debugging to better understand this workflow. " ) ;
capitalize = false ;
}
2017-03-05 16:44:50 +01:00
property_editor - > edit ( current_obj ) ;
2016-06-04 18:17:56 +02:00
node_dock - > set_node ( NULL ) ;
2014-02-10 02:10:30 +01:00
}
2017-09-15 00:38:38 +02:00
if ( editable_warning ! = String ( ) ) {
2017-09-14 15:38:59 +02:00
property_editable_warning - > show ( ) ; //hide by default
property_editable_warning_dialog - > set_text ( editable_warning ) ;
}
2017-10-17 16:39:31 +02:00
if ( property_editor - > is_capitalize_paths_enabled ( ) ! = capitalize ) {
property_editor - > set_enable_capitalize_paths ( capitalize ) ;
2017-11-24 07:09:51 +01:00
}
2014-02-10 02:10:30 +01:00
/* Take care of PLUGIN EDITOR */
EditorPlugin * main_plugin = editor_data . get_editor ( current_obj ) ;
if ( main_plugin ) {
2016-10-29 15:44:57 +02:00
// special case if use of external editor is true
2017-09-03 21:23:36 +02:00
if ( main_plugin - > get_name ( ) = = " Script " & & ( bool ( EditorSettings : : get_singleton ( ) - > get ( " text_editor/external/use_external_editor " ) ) | | overrides_external_editor ( current_obj ) ) ) {
2018-03-21 22:23:15 +01:00
if ( ! changing_scene )
main_plugin - > edit ( current_obj ) ;
2016-10-29 15:44:57 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
else if ( main_plugin ! = editor_plugin_screen & & ( ! ScriptEditor : : get_singleton ( ) | | ! ScriptEditor : : get_singleton ( ) - > is_visible_in_tree ( ) | | ScriptEditor : : get_singleton ( ) - > can_take_away_focus ( ) ) ) {
2014-02-10 02:10:30 +01:00
// update screen main_plugin
2015-06-22 05:03:19 +02:00
if ( ! changing_scene ) {
2017-09-03 21:23:36 +02:00
2015-06-22 05:03:19 +02:00
if ( editor_plugin_screen )
editor_plugin_screen - > make_visible ( false ) ;
2017-03-05 16:44:50 +01:00
editor_plugin_screen = main_plugin ;
2015-06-22 05:03:19 +02:00
editor_plugin_screen - > edit ( current_obj ) ;
editor_plugin_screen - > make_visible ( true ) ;
2017-07-06 09:18:20 +02:00
int plugin_count = editor_data . get_editor_plugin_count ( ) ;
for ( int i = 0 ; i < plugin_count ; i + + ) {
editor_data . get_editor_plugin ( i ) - > notify_main_screen_changed ( editor_plugin_screen - > get_name ( ) ) ;
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < editor_table . size ( ) ; i + + ) {
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
main_editor_buttons [ i ] - > set_pressed ( editor_table [ i ] = = main_plugin ) ;
2014-02-10 02:10:30 +01:00
}
}
} else {
editor_plugin_screen - > edit ( current_obj ) ;
}
}
2017-03-05 16:44:50 +01:00
Vector < EditorPlugin * > sub_plugins = editor_data . get_subeditors ( current_obj ) ;
2014-02-10 02:10:30 +01:00
2016-03-30 01:02:53 +02:00
if ( ! sub_plugins . empty ( ) ) {
_display_top_editors ( false ) ;
2014-02-10 02:10:30 +01:00
2016-03-30 01:02:53 +02:00
_set_top_editors ( sub_plugins ) ;
_set_editing_top_editors ( current_obj ) ;
_display_top_editors ( true ) ;
2016-05-21 15:29:25 +02:00
2016-03-30 01:02:53 +02:00
} else if ( ! editor_plugins_over - > get_plugins_list ( ) . empty ( ) ) {
2014-02-10 02:10:30 +01:00
2016-03-30 01:02:53 +02:00
_hide_top_editors ( ) ;
2014-02-10 02:10:30 +01:00
}
object_menu - > set_disabled ( false ) ;
2017-03-05 16:44:50 +01:00
PopupMenu * p = object_menu - > get_popup ( ) ;
2014-02-10 02:10:30 +01:00
p - > clear ( ) ;
2017-11-24 07:09:51 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/expand_all " , TTR ( " Expand all properties " ) ) , EXPAND_ALL ) ;
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/collapse_all " , TTR ( " Collapse all properties " ) ) , COLLAPSE_ALL ) ;
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/copy_params " , TTR ( " Copy Params " ) ) , OBJECT_COPY_PARAMS ) ;
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/paste_params " , TTR ( " Paste Params " ) ) , OBJECT_PASTE_PARAMS ) ;
2014-02-10 02:10:30 +01:00
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/paste_resource " , TTR ( " Paste Resource " ) ) , RESOURCE_PASTE ) ;
2015-09-01 05:49:47 +02:00
if ( is_resource ) {
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/copy_resource " , TTR ( " Copy Resource " ) ) , RESOURCE_COPY ) ;
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/unref_resource " , TTR ( " Make Built-In " ) ) , RESOURCE_UNREF ) ;
2015-09-01 05:49:47 +02:00
}
2016-07-09 16:46:59 +02:00
if ( is_resource | | is_node ) {
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " property_editor/make_subresources_unique " , TTR ( " Make Sub-Resources Unique " ) ) , OBJECT_UNIQUE_RESOURCES ) ;
2016-07-09 16:46:59 +02:00
p - > add_separator ( ) ;
2017-07-18 08:09:19 +02:00
p - > add_icon_shortcut ( gui_base - > get_icon ( " HelpSearch " , " EditorIcons " ) , ED_SHORTCUT ( " property_editor/open_help " , TTR ( " Open in Help " ) ) , OBJECT_REQUEST_HELP ) ;
2016-07-09 16:46:59 +02:00
}
2014-02-10 02:10:30 +01:00
List < MethodInfo > methods ;
current_obj - > get_method_list ( & methods ) ;
if ( ! methods . empty ( ) ) {
2017-03-05 16:44:50 +01:00
bool found = false ;
List < MethodInfo > : : Element * I = methods . front ( ) ;
int i = 0 ;
while ( I ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( I - > get ( ) . flags & METHOD_FLAG_EDITOR ) {
2014-02-10 02:10:30 +01:00
if ( ! found ) {
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
found = true ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
p - > add_item ( I - > get ( ) . name . capitalize ( ) , OBJECT_METHOD_BASE + i ) ;
2014-02-10 02:10:30 +01:00
}
i + + ;
2017-03-05 16:44:50 +01:00
I = I - > next ( ) ;
2014-02-10 02:10:30 +01:00
}
}
2016-01-18 00:03:57 +01:00
update_keying ( ) ;
2014-02-10 02:10:30 +01:00
}
2015-09-01 05:49:47 +02:00
void EditorNode : : _resource_created ( ) {
Object * c = create_dialog - > instance_selected ( ) ;
ERR_FAIL_COND ( ! c ) ;
2017-08-24 22:58:51 +02:00
Resource * r = Object : : cast_to < Resource > ( c ) ;
2015-09-01 05:49:47 +02:00
ERR_FAIL_COND ( ! r ) ;
2017-03-05 16:44:50 +01:00
REF res ( r ) ;
2015-09-01 05:49:47 +02:00
push_item ( c ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _resource_selected ( const RES & p_res , const String & p_property ) {
2014-02-10 02:10:30 +01:00
if ( p_res . is_null ( ) )
return ;
2017-03-05 16:44:50 +01:00
RES r = p_res ;
push_item ( r . operator - > ( ) , p_property ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _run ( bool p_current , const String & p_custom ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( editor_run . get_status ( ) = = EditorRun : : STATUS_PLAY ) {
2014-02-10 02:10:30 +01:00
play_button - > set_pressed ( ! _playing_edited ) ;
play_scene_button - > set_pressed ( _playing_edited ) ;
return ;
}
play_button - > set_pressed ( false ) ;
2017-03-05 16:44:50 +01:00
play_button - > set_icon ( gui_base - > get_icon ( " MainPlay " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
play_scene_button - > set_pressed ( false ) ;
2017-03-05 16:44:50 +01:00
play_scene_button - > set_icon ( gui_base - > get_icon ( " PlayScene " , " EditorIcons " ) ) ;
2016-02-17 20:51:56 +01:00
play_custom_scene_button - > set_pressed ( false ) ;
2017-03-05 16:44:50 +01:00
play_custom_scene_button - > set_icon ( gui_base - > get_icon ( " PlayCustom " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
2017-02-27 15:20:47 +01:00
String main_scene ;
2014-02-10 02:10:30 +01:00
String run_filename ;
String args ;
2017-03-05 16:44:50 +01:00
if ( p_current | | ( editor_data . get_edited_scene_root ( ) & & p_custom = = editor_data . get_edited_scene_root ( ) - > get_filename ( ) ) ) {
2014-02-10 02:10:30 +01:00
2015-06-22 05:03:19 +02:00
Node * scene = editor_data . get_edited_scene_root ( ) ;
2014-02-10 02:10:30 +01:00
if ( ! scene ) {
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2016-05-19 00:08:12 +02:00
accept - > set_text ( TTR ( " There is no defined scene to run. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( scene - > get_filename ( ) = = " " ) {
current_option = - 1 ;
2015-01-06 23:28:25 +01:00
_menu_option_confirm ( FILE_SAVE_BEFORE_RUN , false ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
run_filename = scene - > get_filename ( ) ;
} else if ( p_custom ! = " " ) {
2017-02-27 15:20:47 +01:00
run_filename = p_custom ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( run_filename = = " " ) {
2014-02-10 02:10:30 +01:00
//evidently, run the scene
2017-07-18 02:05:38 +02:00
main_scene = GLOBAL_DEF ( " application/run/main_scene " , " " ) ;
2017-03-05 16:44:50 +01:00
if ( main_scene = = " " ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2017-05-06 10:31:36 +02:00
pick_main_scene - > set_text ( TTR ( " No main scene has ever been defined, select one? \n You can change it later in \" Project Settings \" under the 'application' category. " ) ) ;
2016-06-28 00:59:33 +02:00
pick_main_scene - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-02-27 15:20:47 +01:00
if ( ! FileAccess : : exists ( main_scene ) ) {
2016-06-27 15:59:37 +02:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2017-02-27 15:20:47 +01:00
pick_main_scene - > set_text ( vformat ( TTR ( " Selected scene '%s' does not exist, select a valid one? \n You can change it later in \" Project Settings \" under the 'application' category. " ) , main_scene ) ) ;
2016-06-28 00:59:33 +02:00
pick_main_scene - > popup_centered_minsize ( ) ;
2016-06-27 15:59:37 +02:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( ResourceLoader : : get_resource_type ( main_scene ) ! = " PackedScene " ) {
2016-06-27 15:59:37 +02:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2017-02-27 15:20:47 +01:00
pick_main_scene - > set_text ( vformat ( TTR ( " Selected scene '%s' is not a scene file, select a valid one? \n You can change it later in \" Project Settings \" under the 'application' category. " ) , main_scene ) ) ;
2016-06-28 00:59:33 +02:00
pick_main_scene - > popup_centered_minsize ( ) ;
2016-06-27 15:59:37 +02:00
return ;
}
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( bool ( EDITOR_DEF ( " run/auto_save/save_before_running " , true ) ) ) {
2014-02-10 02:10:30 +01:00
if ( unsaved_cache ) {
2015-06-22 05:03:19 +02:00
Node * scene = editor_data . get_edited_scene_root ( ) ;
2014-02-10 02:10:30 +01:00
if ( scene ) { //only autosave if there is a scene obviously
2017-03-05 16:44:50 +01:00
if ( scene - > get_filename ( ) = = " " ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2016-05-19 00:08:12 +02:00
accept - > set_text ( TTR ( " Current scene was never saved, please save it prior to running. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2015-05-31 06:59:42 +02:00
_save_scene_with_preview ( scene - > get_filename ( ) ) ;
2014-02-10 02:10:30 +01:00
}
}
2016-06-26 05:54:17 +02:00
_menu_option ( FILE_SAVE_ALL_SCENES ) ;
2014-02-10 02:10:30 +01:00
editor_data . save_editor_external_data ( ) ;
}
2018-02-14 16:23:04 +01:00
if ( ! call_build ( ) )
2017-08-29 23:59:20 +02:00
return ;
2017-01-25 18:13:07 +01:00
if ( bool ( EDITOR_DEF ( " run/output/always_clear_output_on_play " , true ) ) ) {
2015-07-30 00:03:25 +02:00
log - > clear ( ) ;
}
2017-01-25 18:13:07 +01:00
if ( bool ( EDITOR_DEF ( " run/output/always_open_output_on_play " , true ) ) ) {
2016-12-24 23:39:16 +01:00
make_bottom_panel_item_visible ( log ) ;
}
2014-02-10 02:10:30 +01:00
List < String > breakpoints ;
editor_data . get_editor_breakpoints ( & breakpoints ) ;
2017-01-21 23:00:25 +01:00
2017-07-19 22:00:46 +02:00
args = ProjectSettings : : get_singleton ( ) - > get ( " editor/main_run_args " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Error error = editor_run . run ( run_filename , args , breakpoints ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( error ! = OK ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2016-05-04 03:25:37 +02:00
accept - > set_text ( TTR ( " Could not start subprocess! " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
emit_signal ( " play_pressed " ) ;
if ( p_current ) {
play_scene_button - > set_pressed ( true ) ;
2017-03-05 16:44:50 +01:00
play_scene_button - > set_icon ( gui_base - > get_icon ( " Reload " , " EditorIcons " ) ) ;
} else if ( p_custom ! = " " ) {
run_custom_filename = p_custom ;
2016-02-17 20:51:56 +01:00
play_custom_scene_button - > set_pressed ( true ) ;
2017-03-05 16:44:50 +01:00
play_custom_scene_button - > set_icon ( gui_base - > get_icon ( " Reload " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
} else {
play_button - > set_pressed ( true ) ;
2017-03-05 16:44:50 +01:00
play_button - > set_icon ( gui_base - > get_icon ( " Reload " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
}
2017-12-04 20:48:46 +01:00
stop_button - > set_disabled ( false ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
_playing_edited = p_current ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _menu_option_confirm ( int p_option , bool p_confirmed ) {
2016-03-09 00:00:52 +01:00
2015-04-27 00:02:32 +02:00
if ( ! p_confirmed ) //this may be a hack..
2017-03-05 16:44:50 +01:00
current_option = ( MenuOptions ) p_option ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
switch ( p_option ) {
2014-02-10 02:10:30 +01:00
case FILE_NEW_SCENE : {
2015-06-22 05:03:19 +02:00
int idx = editor_data . add_edited_scene ( - 1 ) ;
_scene_tab_changed ( idx ) ;
2015-08-30 03:59:25 +02:00
editor_data . clear_editor_states ( ) ;
2017-11-16 23:57:57 +01:00
_update_scene_tabs ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
2015-10-10 14:09:09 +02:00
case FILE_NEW_INHERITED_SCENE :
2014-02-10 02:10:30 +01:00
case FILE_OPEN_SCENE : {
2016-03-09 00:00:52 +01:00
2015-05-31 06:59:42 +02:00
file - > set_mode ( EditorFileDialog : : MODE_OPEN_FILE ) ;
2014-02-10 02:10:30 +01:00
List < String > extensions ;
2017-03-05 16:44:50 +01:00
ResourceLoader : : get_recognized_extensions_for_type ( " PackedScene " , & extensions ) ;
2014-02-10 02:10:30 +01:00
file - > clear_filters ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < extensions . size ( ) ; i + + ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
file - > add_filter ( " *. " + extensions [ i ] + " ; " + extensions [ i ] . to_upper ( ) ) ;
2014-02-10 02:10:30 +01:00
}
2016-03-09 00:00:52 +01:00
2015-06-22 05:03:19 +02:00
Node * scene = editor_data . get_edited_scene_root ( ) ;
2014-02-10 02:10:30 +01:00
if ( scene ) {
file - > set_current_path ( scene - > get_filename ( ) ) ;
} ;
2017-03-05 16:44:50 +01:00
file - > set_title ( p_option = = FILE_OPEN_SCENE ? TTR ( " Open Scene " ) : TTR ( " Open Base Scene " ) ) ;
2014-02-10 02:10:30 +01:00
file - > popup_centered_ratio ( ) ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
} break ;
case FILE_QUICK_OPEN_SCENE : {
2016-01-08 12:27:34 +01:00
quick_open - > popup ( " PackedScene " , true ) ;
2018-04-22 19:36:01 +02:00
quick_open - > set_title ( TTR ( " Quick Open Scene... " ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case FILE_QUICK_OPEN_SCRIPT : {
2016-01-08 12:27:34 +01:00
quick_open - > popup ( " Script " , true ) ;
2018-04-22 19:36:01 +02:00
quick_open - > set_title ( TTR ( " Quick Open Script... " ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case FILE_OPEN_PREV : {
if ( previous_scenes . empty ( ) )
break ;
2017-03-05 16:44:50 +01:00
opening_prev = true ;
2014-02-10 02:10:30 +01:00
open_request ( previous_scenes . back ( ) - > get ( ) ) ;
2015-06-22 05:03:19 +02:00
} break ;
2017-06-26 16:04:53 +02:00
case FILE_CLOSE_ALL_AND_QUIT :
case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER :
2015-06-22 05:03:19 +02:00
case FILE_CLOSE : {
2017-06-26 16:04:53 +02:00
if ( ! p_confirmed & & ( unsaved_cache | | p_option = = FILE_CLOSE_ALL_AND_QUIT | | p_option = = FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER ) ) {
2017-07-26 13:29:45 +02:00
tab_closing = p_option = = FILE_CLOSE ? editor_data . get_edited_scene ( ) : _next_unsaved_scene ( false ) ;
2017-06-26 16:04:53 +02:00
String scene_filename = editor_data . get_edited_scene_root ( tab_closing ) - > get_filename ( ) ;
2017-06-24 12:57:30 +02:00
save_confirmation - > get_ok ( ) - > set_text ( TTR ( " Save & Close " ) ) ;
2017-06-26 16:04:53 +02:00
save_confirmation - > set_text ( vformat ( TTR ( " Save changes to '%s' before closing? " ) , scene_filename ! = " " ? scene_filename : " unsaved scene " ) ) ;
2017-06-21 06:15:39 +02:00
save_confirmation - > popup_centered_minsize ( ) ;
2015-06-22 05:03:19 +02:00
break ;
2017-12-10 13:48:03 +01:00
} else {
tab_closing = editor_data . get_edited_scene ( ) ;
2015-06-22 05:03:19 +02:00
}
2017-12-10 13:48:03 +01:00
2017-06-21 06:15:39 +02:00
} // fallthrough
case SCENE_TAB_CLOSE :
2014-02-10 02:10:30 +01:00
case FILE_SAVE_SCENE : {
2017-06-26 16:04:53 +02:00
int scene_idx = ( p_option = = FILE_SAVE_SCENE ) ? - 1 : tab_closing ;
2017-06-21 06:15:39 +02:00
Node * scene = editor_data . get_edited_scene_root ( scene_idx ) ;
2017-03-05 16:44:50 +01:00
if ( scene & & scene - > get_filename ( ) ! = " " ) {
2014-02-10 02:10:30 +01:00
2017-08-28 18:53:52 +02:00
if ( scene_idx ! = editor_data . get_edited_scene ( ) )
2017-11-12 04:48:00 +01:00
_save_scene_with_preview ( scene - > get_filename ( ) , scene_idx ) ;
2017-08-28 18:53:52 +02:00
else
_save_scene_with_preview ( scene - > get_filename ( ) ) ;
2017-06-21 06:15:39 +02:00
if ( scene_idx ! = - 1 )
_discard_changes ( ) ;
2017-06-26 16:04:53 +02:00
break ;
}
2014-02-10 02:10:30 +01:00
// fallthrough to save_as
2015-12-04 16:51:36 +01:00
} ;
2014-02-10 02:10:30 +01:00
case FILE_SAVE_AS_SCENE : {
2017-06-26 16:04:53 +02:00
int scene_idx = ( p_option = = FILE_SAVE_SCENE | | p_option = = FILE_SAVE_AS_SCENE ) ? - 1 : tab_closing ;
2016-03-09 00:00:52 +01:00
2017-06-26 16:04:53 +02:00
Node * scene = editor_data . get_edited_scene_root ( scene_idx ) ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
if ( ! scene ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2017-08-23 22:25:14 +02:00
accept - > set_text ( TTR ( " This operation can't be done without a tree root. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2016-03-09 00:00:52 +01:00
break ;
2014-02-10 02:10:30 +01:00
}
2016-03-09 00:00:52 +01:00
2015-05-31 06:59:42 +02:00
file - > set_mode ( EditorFileDialog : : MODE_SAVE_FILE ) ;
2014-02-10 02:10:30 +01:00
List < String > extensions ;
2017-03-05 16:44:50 +01:00
Ref < PackedScene > sd = memnew ( PackedScene ) ;
ResourceSaver : : get_recognized_extensions ( sd , & extensions ) ;
2014-02-10 02:10:30 +01:00
file - > clear_filters ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < extensions . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
file - > add_filter ( " *. " + extensions [ i ] + " ; " + extensions [ i ] . to_upper ( ) ) ;
2014-02-10 02:10:30 +01:00
}
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
if ( scene - > get_filename ( ) ! = " " ) {
2014-02-10 02:10:30 +01:00
file - > set_current_path ( scene - > get_filename ( ) ) ;
if ( extensions . size ( ) ) {
2017-03-05 16:44:50 +01:00
String ext = scene - > get_filename ( ) . get_extension ( ) . to_lower ( ) ;
if ( extensions . find ( ext ) = = NULL ) {
file - > set_current_path ( scene - > get_filename ( ) . replacen ( " . " + ext , " . " + extensions . front ( ) - > get ( ) ) ) ;
2014-02-10 02:10:30 +01:00
}
}
} else {
String existing ;
if ( extensions . size ( ) ) {
2017-06-21 06:15:39 +02:00
String root_name ( scene - > get_name ( ) ) ;
2017-03-05 16:44:50 +01:00
existing = root_name + " . " + extensions . front ( ) - > get ( ) . to_lower ( ) ;
2014-02-10 02:10:30 +01:00
}
file - > set_current_path ( existing ) ;
}
file - > popup_centered_ratio ( ) ;
2018-04-22 19:36:01 +02:00
file - > set_title ( TTR ( " Save Scene As... " ) ) ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
} break ;
2016-06-26 05:54:17 +02:00
case FILE_SAVE_ALL_SCENES : {
2017-05-29 02:46:48 +02:00
2017-06-24 12:57:30 +02:00
_save_all_scenes ( ) ;
2016-06-26 05:54:17 +02:00
} break ;
2015-01-06 23:28:25 +01:00
case FILE_SAVE_BEFORE_RUN : {
if ( ! p_confirmed ) {
2017-06-17 12:04:50 +02:00
confirmation - > get_cancel ( ) - > set_text ( TTR ( " No " ) ) ;
confirmation - > get_ok ( ) - > set_text ( TTR ( " Yes " ) ) ;
confirmation - > set_text ( TTR ( " This scene has never been saved. Save before running? " ) ) ;
confirmation - > popup_centered_minsize ( ) ;
2015-01-06 23:28:25 +01:00
break ;
}
_menu_option ( FILE_SAVE_AS_SCENE ) ;
2017-06-08 06:38:31 +02:00
_menu_option_confirm ( FILE_SAVE_AND_RUN , false ) ;
2015-01-06 23:28:25 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case FILE_EXPORT_PROJECT : {
2017-02-20 03:19:30 +01:00
project_export - > popup_export ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case FILE_EXPORT_MESH_LIBRARY : {
2015-06-22 05:03:19 +02:00
if ( ! editor_data . get_edited_scene_root ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2017-08-23 22:25:14 +02:00
accept - > set_text ( TTR ( " This operation can't be done without a scene. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
break ;
}
List < String > extensions ;
2017-03-05 16:44:50 +01:00
Ref < MeshLibrary > ml ( memnew ( MeshLibrary ) ) ;
ResourceSaver : : get_recognized_extensions ( ml , & extensions ) ;
2014-02-10 02:10:30 +01:00
file_export_lib - > clear_filters ( ) ;
2017-03-05 16:44:50 +01:00
for ( List < String > : : Element * E = extensions . front ( ) ; E ; E = E - > next ( ) ) {
file_export_lib - > add_filter ( " *. " + E - > get ( ) ) ;
2014-02-10 02:10:30 +01:00
}
file_export_lib - > popup_centered_ratio ( ) ;
2016-05-04 03:25:37 +02:00
file_export_lib - > set_title ( TTR ( " Export Mesh Library " ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case FILE_EXPORT_TILESET : {
2017-11-07 23:44:46 +01:00
//Make sure that the scene has a root before trying to convert to tileset
if ( ! editor_data . get_edited_scene_root ( ) ) {
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2017-11-07 23:44:46 +01:00
accept - > set_text ( TTR ( " This operation can't be done without a root node. " ) ) ;
accept - > popup_centered_minsize ( ) ;
break ;
}
2014-02-10 02:10:30 +01:00
List < String > extensions ;
2017-03-05 16:44:50 +01:00
Ref < TileSet > ml ( memnew ( TileSet ) ) ;
ResourceSaver : : get_recognized_extensions ( ml , & extensions ) ;
2014-02-10 02:10:30 +01:00
file_export_lib - > clear_filters ( ) ;
2017-03-05 16:44:50 +01:00
for ( List < String > : : Element * E = extensions . front ( ) ; E ; E = E - > next ( ) ) {
file_export_lib - > add_filter ( " *. " + E - > get ( ) ) ;
2014-02-10 02:10:30 +01:00
}
file_export_lib - > popup_centered_ratio ( ) ;
2016-05-04 03:25:37 +02:00
file_export_lib - > set_title ( TTR ( " Export Tile Set " ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case SETTINGS_EXPORT_PREFERENCES : {
//project_export_settings->popup_centered_ratio();
} break ;
case FILE_IMPORT_SUBSCENE : {
2015-06-22 05:03:19 +02:00
if ( ! editor_data . get_edited_scene_root ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2017-08-23 22:25:14 +02:00
accept - > set_text ( TTR ( " This operation can't be done without a selected node. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
break ;
}
scene_tree_dock - > import_subscene ( ) ;
} break ;
case FILE_EXTERNAL_OPEN_SCENE : {
if ( unsaved_cache & & ! p_confirmed ) {
2016-05-04 03:25:37 +02:00
confirmation - > get_ok ( ) - > set_text ( TTR ( " Open " ) ) ;
confirmation - > set_text ( TTR ( " Current scene not saved. Open anyway? " ) ) ;
2015-04-08 19:02:13 +02:00
confirmation - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
break ;
}
2017-03-05 16:44:50 +01:00
bool oprev = opening_prev ;
2014-02-10 02:10:30 +01:00
Error err = load_scene ( external_file ) ;
if ( err = = OK & & oprev ) {
previous_scenes . pop_back ( ) ;
2017-03-05 16:44:50 +01:00
opening_prev = false ;
2014-02-10 02:10:30 +01:00
}
} break ;
case EDIT_UNDO : {
2017-03-05 16:44:50 +01:00
if ( Input : : get_singleton ( ) - > get_mouse_button_mask ( ) & 0x7 ) {
2014-02-10 02:10:30 +01:00
break ; // can't undo while mouse buttons are pressed
2017-01-24 03:12:08 +01:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
String action = editor_data . get_undo_redo ( ) . get_current_action_name ( ) ;
if ( action ! = " " )
log - > add_message ( " UNDO: " + action ) ;
2014-02-10 02:10:30 +01:00
editor_data . get_undo_redo ( ) . undo ( ) ;
} break ;
case EDIT_REDO : {
2017-03-05 16:44:50 +01:00
if ( Input : : get_singleton ( ) - > get_mouse_button_mask ( ) & 0x7 )
2014-02-10 02:10:30 +01:00
break ; // can't redo while mouse buttons are pressed
editor_data . get_undo_redo ( ) . redo ( ) ;
2017-03-05 16:44:50 +01:00
String action = editor_data . get_undo_redo ( ) . get_current_action_name ( ) ;
if ( action ! = " " )
log - > add_message ( " REDO: " + action ) ;
2014-02-10 02:10:30 +01:00
} break ;
2015-01-25 01:14:06 +01:00
case EDIT_REVERT : {
Node * scene = get_edited_scene ( ) ;
if ( ! scene )
break ;
2016-01-23 22:28:30 +01:00
String filename = scene - > get_filename ( ) ;
2017-03-05 16:44:50 +01:00
if ( filename = = String ( ) ) {
2016-05-19 00:08:12 +02:00
show_warning ( TTR ( " Can't reload a scene that was never saved. " ) ) ;
2016-01-23 22:28:30 +01:00
break ;
}
2015-01-27 01:00:07 +01:00
if ( unsaved_cache & & ! p_confirmed ) {
2016-05-04 03:25:37 +02:00
confirmation - > get_ok ( ) - > set_text ( TTR ( " Revert " ) ) ;
confirmation - > set_text ( TTR ( " This action cannot be undone. Revert anyway? " ) ) ;
2015-04-08 19:02:13 +02:00
confirmation - > popup_centered_minsize ( ) ;
2015-01-27 01:00:07 +01:00
break ;
}
2015-01-25 01:14:06 +01:00
2016-01-23 22:28:30 +01:00
int cur_idx = editor_data . get_edited_scene ( ) ;
_remove_edited_scene ( ) ;
Error err = load_scene ( filename ) ;
2017-09-02 22:32:31 +02:00
if ( err ! = OK )
ERR_PRINT ( " Failed to load scene " ) ;
2016-01-23 22:28:30 +01:00
editor_data . move_edited_scene_to_index ( cur_idx ) ;
get_undo_redo ( ) - > clear_history ( ) ;
scene_tabs - > set_current_tab ( cur_idx ) ;
2015-01-25 01:14:06 +01:00
} break ;
2015-09-01 05:49:47 +02:00
case RESOURCE_NEW : {
2017-03-16 21:58:45 +01:00
create_dialog - > popup_create ( true ) ;
2015-09-01 05:49:47 +02:00
} break ;
case RESOURCE_LOAD : {
open_resource ( ) ;
} break ;
case RESOURCE_SAVE : {
uint32_t current = editor_history . get_current ( ) ;
2017-03-05 16:44:50 +01:00
Object * current_obj = current > 0 ? ObjectDB : : get_instance ( current ) : NULL ;
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
ERR_FAIL_COND ( ! Object : : cast_to < Resource > ( current_obj ) )
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
RES current_res = RES ( Object : : cast_to < Resource > ( current_obj ) ) ;
2015-09-01 05:49:47 +02:00
save_resource ( current_res ) ;
} break ;
case RESOURCE_SAVE_AS : {
uint32_t current = editor_history . get_current ( ) ;
2017-03-05 16:44:50 +01:00
Object * current_obj = current > 0 ? ObjectDB : : get_instance ( current ) : NULL ;
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
ERR_FAIL_COND ( ! Object : : cast_to < Resource > ( current_obj ) )
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
RES current_res = RES ( Object : : cast_to < Resource > ( current_obj ) ) ;
2015-09-01 05:49:47 +02:00
save_resource_as ( current_res ) ;
} break ;
case RESOURCE_UNREF : {
uint32_t current = editor_history . get_current ( ) ;
2017-03-05 16:44:50 +01:00
Object * current_obj = current > 0 ? ObjectDB : : get_instance ( current ) : NULL ;
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
ERR_FAIL_COND ( ! Object : : cast_to < Resource > ( current_obj ) )
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
RES current_res = RES ( Object : : cast_to < Resource > ( current_obj ) ) ;
2015-09-01 05:49:47 +02:00
current_res - > set_path ( " " ) ;
_edit_current ( ) ;
} break ;
case RESOURCE_COPY : {
uint32_t current = editor_history . get_current ( ) ;
2017-03-05 16:44:50 +01:00
Object * current_obj = current > 0 ? ObjectDB : : get_instance ( current ) : NULL ;
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
ERR_FAIL_COND ( ! Object : : cast_to < Resource > ( current_obj ) )
2015-09-01 05:49:47 +02:00
2017-08-24 22:58:51 +02:00
RES current_res = RES ( Object : : cast_to < Resource > ( current_obj ) ) ;
2015-09-01 05:49:47 +02:00
EditorSettings : : get_singleton ( ) - > set_resource_clipboard ( current_res ) ;
} break ;
case RESOURCE_PASTE : {
RES r = EditorSettings : : get_singleton ( ) - > get_resource_clipboard ( ) ;
if ( r . is_valid ( ) ) {
2017-03-05 16:44:50 +01:00
push_item ( EditorSettings : : get_singleton ( ) - > get_resource_clipboard ( ) . ptr ( ) , String ( ) ) ;
2015-09-01 05:49:47 +02:00
}
} break ;
2014-02-10 02:10:30 +01:00
case OBJECT_REQUEST_HELP : {
if ( current ) {
2015-11-25 00:46:44 +01:00
_editor_select ( EDITOR_SCRIPT ) ;
2017-03-05 16:44:50 +01:00
emit_signal ( " request_help " , current - > get_class ( ) ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
case OBJECT_COPY_PARAMS : {
2016-03-09 00:00:52 +01:00
2017-01-14 18:03:38 +01:00
editor_data . apply_changes_in_editors ( ) ;
2014-02-10 02:10:30 +01:00
if ( current )
editor_data . copy_object_params ( current ) ;
} break ;
case OBJECT_PASTE_PARAMS : {
2016-03-09 00:00:52 +01:00
2017-01-14 18:03:38 +01:00
editor_data . apply_changes_in_editors ( ) ;
2014-02-10 02:10:30 +01:00
if ( current )
editor_data . paste_object_params ( current ) ;
editor_data . get_undo_redo ( ) . clear_history ( ) ;
} break ;
2014-11-02 15:31:01 +01:00
case OBJECT_UNIQUE_RESOURCES : {
2017-01-14 18:03:38 +01:00
editor_data . apply_changes_in_editors ( ) ;
2014-11-02 15:31:01 +01:00
if ( current ) {
List < PropertyInfo > props ;
current - > get_property_list ( & props ) ;
2017-03-05 16:44:50 +01:00
Map < RES , RES > duplicates ;
for ( List < PropertyInfo > : : Element * E = props . front ( ) ; E ; E = E - > next ( ) ) {
2014-11-02 15:31:01 +01:00
2017-03-05 16:44:50 +01:00
if ( ! ( E - > get ( ) . usage & PROPERTY_USAGE_STORAGE ) )
2014-11-02 15:31:01 +01:00
continue ;
Variant v = current - > get ( E - > get ( ) . name ) ;
if ( v . is_ref ( ) ) {
REF ref = v ;
if ( ref . is_valid ( ) ) {
RES res = ref ;
if ( res . is_valid ( ) ) {
if ( ! duplicates . has ( res ) ) {
2017-03-05 16:44:50 +01:00
duplicates [ res ] = res - > duplicate ( ) ;
2014-11-02 15:31:01 +01:00
}
2017-03-05 16:44:50 +01:00
res = duplicates [ res ] ;
2014-11-02 15:31:01 +01:00
2017-03-05 16:44:50 +01:00
current - > set ( E - > get ( ) . name , res ) ;
2014-11-02 15:31:01 +01:00
}
}
}
}
}
editor_data . get_undo_redo ( ) . clear_history ( ) ;
2016-03-30 01:02:53 +02:00
_set_editing_top_editors ( NULL ) ;
_set_editing_top_editors ( current ) ;
2014-11-02 15:31:01 +01:00
2017-11-24 07:09:51 +01:00
} break ;
case COLLAPSE_ALL : {
_menu_collapseall ( ) ;
} break ;
case EXPAND_ALL : {
_menu_expandall ( ) ;
2014-11-02 15:31:01 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case RUN_PLAY : {
2017-03-05 16:44:50 +01:00
_menu_option_confirm ( RUN_STOP , true ) ;
2014-02-10 02:10:30 +01:00
_run ( false ) ;
} break ;
case RUN_PLAY_CUSTOM_SCENE : {
2017-03-05 16:44:50 +01:00
if ( run_custom_filename . empty ( ) | | editor_run . get_status ( ) = = EditorRun : : STATUS_STOP ) {
_menu_option_confirm ( RUN_STOP , true ) ;
quick_run - > popup ( " PackedScene " , true ) ;
2018-04-22 19:36:01 +02:00
quick_run - > set_title ( TTR ( " Quick Run Scene... " ) ) ;
2016-02-18 13:16:31 +01:00
play_custom_scene_button - > set_pressed ( false ) ;
2016-02-17 20:51:56 +01:00
} else {
2017-03-05 16:44:50 +01:00
String last_custom_scene = run_custom_filename ;
_menu_option_confirm ( RUN_STOP , true ) ;
_run ( false , last_custom_scene ) ;
2016-02-17 20:51:56 +01:00
}
2014-02-10 02:10:30 +01:00
} break ;
case RUN_STOP : {
2017-03-05 16:44:50 +01:00
if ( editor_run . get_status ( ) = = EditorRun : : STATUS_STOP )
2014-02-10 02:10:30 +01:00
break ;
editor_run . stop ( ) ;
2016-02-17 20:51:56 +01:00
run_custom_filename . clear ( ) ;
2014-02-10 02:10:30 +01:00
play_button - > set_pressed ( false ) ;
2017-03-05 16:44:50 +01:00
play_button - > set_icon ( gui_base - > get_icon ( " MainPlay " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
play_scene_button - > set_pressed ( false ) ;
2017-03-05 16:44:50 +01:00
play_scene_button - > set_icon ( gui_base - > get_icon ( " PlayScene " , " EditorIcons " ) ) ;
2016-02-17 20:51:56 +01:00
play_custom_scene_button - > set_pressed ( false ) ;
2017-03-05 16:44:50 +01:00
play_custom_scene_button - > set_icon ( gui_base - > get_icon ( " PlayCustom " , " EditorIcons " ) ) ;
2017-12-04 20:48:46 +01:00
stop_button - > set_disabled ( true ) ;
2017-02-06 17:50:01 +01:00
if ( bool ( EDITOR_DEF ( " run/output/always_close_output_on_stop " , true ) ) ) {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
if ( bottom_panel_items [ i ] . control = = log ) {
_bottom_panel_switch ( false , i ) ;
2017-02-06 17:50:01 +01:00
break ;
}
}
}
2014-02-10 02:10:30 +01:00
emit_signal ( " stop_pressed " ) ;
} break ;
case RUN_PLAY_SCENE : {
2017-05-29 02:46:48 +02:00
_save_default_environment ( ) ;
2017-03-05 16:44:50 +01:00
_menu_option_confirm ( RUN_STOP , true ) ;
2014-02-10 02:10:30 +01:00
_run ( true ) ;
2015-08-06 07:37:40 +02:00
} break ;
case RUN_PLAY_NATIVE : {
2016-10-01 16:15:07 +02:00
2017-03-05 16:44:50 +01:00
bool autosave = EDITOR_DEF ( " run/auto_save/save_before_running " , true ) ;
2016-06-24 14:20:43 +02:00
if ( autosave ) {
2016-07-10 19:37:48 +02:00
_menu_option_confirm ( FILE_SAVE_ALL_SCENES , false ) ;
2016-06-24 14:20:43 +02:00
}
2017-03-05 16:44:50 +01:00
if ( run_native - > is_deploy_debug_remote_enabled ( ) ) {
_menu_option_confirm ( RUN_STOP , true ) ;
2017-08-29 23:59:20 +02:00
2018-02-14 16:23:04 +01:00
if ( ! call_build ( ) )
2017-08-29 23:59:20 +02:00
break ; // build failed
2016-06-24 14:20:43 +02:00
emit_signal ( " play_pressed " ) ;
editor_run . run_native_notify ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
case RUN_SCENE_SETTINGS : {
run_settings_dialog - > popup_run_settings ( ) ;
} break ;
case RUN_SETTINGS : {
project_settings - > popup_project_settings ( ) ;
} break ;
2017-06-26 16:04:53 +02:00
case FILE_QUIT :
2014-02-18 05:21:06 +01:00
case RUN_PROJECT_MANAGER : {
if ( ! p_confirmed ) {
2017-09-29 18:52:56 +02:00
bool save_each = EDITOR_DEF ( " interface/editor/save_each_scene_on_quit " , true ) ;
2017-07-26 13:29:45 +02:00
if ( _next_unsaved_scene ( ! save_each ) = = - 1 ) {
2014-02-18 05:21:06 +01:00
2017-09-29 18:52:56 +02:00
bool confirm = EDITOR_DEF ( " interface/editor/quit_confirmation " , true ) ;
2017-06-26 16:04:53 +02:00
if ( confirm ) {
2014-02-18 05:21:06 +01:00
2017-06-26 16:04:53 +02:00
confirmation - > get_ok ( ) - > set_text ( p_option = = FILE_QUIT ? TTR ( " Quit " ) : TTR ( " Yes " ) ) ;
confirmation - > set_text ( p_option = = FILE_QUIT ? TTR ( " Exit the editor? " ) : TTR ( " Open Project Manager? " ) ) ;
confirmation - > popup_centered_minsize ( ) ;
} else {
_discard_changes ( ) ;
2017-06-29 20:39:26 +02:00
break ;
2017-06-26 16:04:53 +02:00
}
2017-06-24 12:57:30 +02:00
} else {
2014-02-18 05:21:06 +01:00
2017-06-26 16:04:53 +02:00
if ( save_each ) {
_menu_option_confirm ( p_option = = FILE_QUIT ? FILE_CLOSE_ALL_AND_QUIT : FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER , false ) ;
} else {
String unsaved_scenes ;
2017-07-26 13:29:45 +02:00
int i = _next_unsaved_scene ( true , 0 ) ;
while ( i ! = - 1 ) {
unsaved_scenes + = " \n " + editor_data . get_edited_scene_root ( i ) - > get_filename ( ) ;
i = _next_unsaved_scene ( true , + + i ) ;
2017-06-26 16:04:53 +02:00
}
save_confirmation - > get_ok ( ) - > set_text ( TTR ( " Save & Quit " ) ) ;
save_confirmation - > set_text ( ( p_option = = FILE_QUIT ? TTR ( " Save changes to the following scene(s) before quitting? " ) : TTR ( " Save changes the following scene(s) before opening Project Manager? " ) ) + unsaved_scenes ) ;
save_confirmation - > popup_centered_minsize ( ) ;
}
2017-06-24 12:57:30 +02:00
}
2017-06-26 16:04:53 +02:00
2017-07-23 09:36:38 +02:00
OS : : get_singleton ( ) - > request_attention ( ) ;
2017-06-26 16:04:53 +02:00
break ;
2017-06-24 12:57:30 +02:00
}
2014-02-18 05:21:06 +01:00
2017-07-26 13:29:45 +02:00
if ( _next_unsaved_scene ( true ) ! = - 1 ) {
2017-06-24 12:57:30 +02:00
_save_all_scenes ( ) ;
2017-06-26 16:04:53 +02:00
}
2017-06-24 12:57:30 +02:00
_discard_changes ( ) ;
2014-02-18 05:21:06 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case RUN_FILE_SERVER : {
2017-05-24 12:00:55 +02:00
bool ischecked = debug_menu - > get_popup ( ) - > is_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_FILE_SERVER ) ) ;
2014-02-10 02:10:30 +01:00
if ( ischecked ) {
file_server - > stop ( ) ;
2016-06-03 17:34:11 +02:00
run_native - > set_deploy_dumb ( false ) ;
2014-02-10 02:10:30 +01:00
} else {
file_server - > start ( ) ;
2016-06-03 17:34:11 +02:00
run_native - > set_deploy_dumb ( true ) ;
2014-02-10 02:10:30 +01:00
}
2017-05-24 12:00:55 +02:00
debug_menu - > get_popup ( ) - > set_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_FILE_SERVER ) , ! ischecked ) ;
2017-02-08 06:18:48 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " debug_options " , " run_file_server " , ! ischecked ) ;
2014-02-10 02:10:30 +01:00
} break ;
2015-08-02 17:29:37 +02:00
case RUN_LIVE_DEBUG : {
2017-05-24 12:00:55 +02:00
bool ischecked = debug_menu - > get_popup ( ) - > is_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_LIVE_DEBUG ) ) ;
2015-08-06 07:37:40 +02:00
2017-05-24 12:00:55 +02:00
debug_menu - > get_popup ( ) - > set_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_LIVE_DEBUG ) , ! ischecked ) ;
2015-08-06 07:37:40 +02:00
ScriptEditor : : get_singleton ( ) - > get_debugger ( ) - > set_live_debugging ( ! ischecked ) ;
2017-02-08 06:18:48 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " debug_options " , " run_live_debug " , ! ischecked ) ;
2015-08-02 17:29:37 +02:00
} break ;
2015-08-06 07:37:40 +02:00
case RUN_DEPLOY_REMOTE_DEBUG : {
2017-05-24 12:00:55 +02:00
bool ischecked = debug_menu - > get_popup ( ) - > is_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_DEPLOY_REMOTE_DEBUG ) ) ;
debug_menu - > get_popup ( ) - > set_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_DEPLOY_REMOTE_DEBUG ) , ! ischecked ) ;
2015-08-06 07:37:40 +02:00
run_native - > set_deploy_debug_remote ( ! ischecked ) ;
2017-02-08 06:18:48 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " debug_options " , " run_deploy_remote_debug " , ! ischecked ) ;
2015-08-06 07:37:40 +02:00
2014-02-10 02:10:30 +01:00
} break ;
2015-09-20 18:03:46 +02:00
case RUN_DEBUG_COLLISONS : {
2017-05-24 12:00:55 +02:00
bool ischecked = debug_menu - > get_popup ( ) - > is_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_DEBUG_COLLISONS ) ) ;
debug_menu - > get_popup ( ) - > set_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_DEBUG_COLLISONS ) , ! ischecked ) ;
2015-09-20 18:03:46 +02:00
run_native - > set_debug_collisions ( ! ischecked ) ;
editor_run . set_debug_collisions ( ! ischecked ) ;
2017-02-08 06:18:48 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " debug_options " , " run_debug_collisons " , ! ischecked ) ;
2015-09-20 18:03:46 +02:00
} break ;
case RUN_DEBUG_NAVIGATION : {
2017-05-24 12:00:55 +02:00
bool ischecked = debug_menu - > get_popup ( ) - > is_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_DEBUG_NAVIGATION ) ) ;
debug_menu - > get_popup ( ) - > set_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_DEBUG_NAVIGATION ) , ! ischecked ) ;
2015-09-20 18:03:46 +02:00
run_native - > set_debug_navigation ( ! ischecked ) ;
editor_run . set_debug_navigation ( ! ischecked ) ;
2017-02-08 06:18:48 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " debug_options " , " run_debug_navigation " , ! ischecked ) ;
2015-09-20 18:03:46 +02:00
} break ;
2016-06-02 01:22:02 +02:00
case RUN_RELOAD_SCRIPTS : {
2017-05-24 12:00:55 +02:00
bool ischecked = debug_menu - > get_popup ( ) - > is_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_RELOAD_SCRIPTS ) ) ;
debug_menu - > get_popup ( ) - > set_item_checked ( debug_menu - > get_popup ( ) - > get_item_index ( RUN_RELOAD_SCRIPTS ) , ! ischecked ) ;
2016-06-03 17:34:11 +02:00
ScriptEditor : : get_singleton ( ) - > set_live_auto_reload_running_scripts ( ! ischecked ) ;
2017-02-08 06:18:48 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " debug_options " , " run_reload_scripts " , ! ischecked ) ;
2016-06-02 01:22:02 +02:00
} break ;
2014-02-10 02:10:30 +01:00
case SETTINGS_UPDATE_ALWAYS : {
2017-03-05 16:44:50 +01:00
update_menu - > get_popup ( ) - > set_item_checked ( 0 , true ) ;
update_menu - > get_popup ( ) - > set_item_checked ( 1 , false ) ;
2014-02-10 02:10:30 +01:00
OS : : get_singleton ( ) - > set_low_processor_usage_mode ( false ) ;
2017-08-28 12:12:40 +02:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " editor_options " , " update_always " , true ) ;
current_option = - 1 ;
2018-04-22 19:36:01 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " I see... " ) ) ;
2017-08-28 12:12:40 +02:00
accept - > set_text ( TTR ( " This option is deprecated. Situations where refresh must be forced are now considered a bug. Please report. " ) ) ;
accept - > popup_centered_minsize ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case SETTINGS_UPDATE_CHANGES : {
2017-03-05 16:44:50 +01:00
update_menu - > get_popup ( ) - > set_item_checked ( 0 , false ) ;
update_menu - > get_popup ( ) - > set_item_checked ( 1 , true ) ;
2014-02-10 02:10:30 +01:00
OS : : get_singleton ( ) - > set_low_processor_usage_mode ( true ) ;
2017-08-28 12:12:40 +02:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " editor_options " , " update_always " , false ) ;
2014-02-10 02:10:30 +01:00
} break ;
2017-03-05 16:44:50 +01:00
case SETTINGS_UPDATE_SPINNER_HIDE : {
2017-08-26 20:43:10 +02:00
2017-03-05 16:44:50 +01:00
update_menu - > set_icon ( gui_base - > get_icon ( " Collapse " , " EditorIcons " ) ) ;
update_menu - > get_popup ( ) - > toggle_item_checked ( 3 ) ;
2017-08-26 20:43:10 +02:00
bool checked = update_menu - > get_popup ( ) - > is_item_checked ( 3 ) ;
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " editor_options " , " update_spinner_hide " , checked ) ;
2017-03-05 16:44:50 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case SETTINGS_PREFERENCES : {
settings_config_dialog - > popup_edit_settings ( ) ;
} break ;
2017-03-21 03:31:41 +01:00
case SETTINGS_MANAGE_EXPORT_TEMPLATES : {
2014-02-10 02:10:30 +01:00
2017-03-21 03:31:41 +01:00
export_template_manager - > popup_manager ( ) ;
2014-02-10 02:10:30 +01:00
2016-09-13 14:46:17 +02:00
} break ;
case SETTINGS_TOGGLE_FULLSCREN : {
2017-03-05 16:44:50 +01:00
OS : : get_singleton ( ) - > set_window_fullscreen ( ! OS : : get_singleton ( ) - > is_window_fullscreen ( ) ) ;
2016-09-13 14:46:17 +02:00
2016-06-28 00:59:33 +02:00
} break ;
case SETTINGS_PICK_MAIN_SCENE : {
file - > set_mode ( EditorFileDialog : : MODE_OPEN_FILE ) ;
List < String > extensions ;
2017-03-05 16:44:50 +01:00
ResourceLoader : : get_recognized_extensions_for_type ( " PackedScene " , & extensions ) ;
2016-06-28 00:59:33 +02:00
file - > clear_filters ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < extensions . size ( ) ; i + + ) {
2016-06-28 00:59:33 +02:00
2017-03-05 16:44:50 +01:00
file - > add_filter ( " *. " + extensions [ i ] + " ; " + extensions [ i ] . to_upper ( ) ) ;
2016-06-28 00:59:33 +02:00
}
Node * scene = editor_data . get_edited_scene_root ( ) ;
if ( scene ) {
file - > set_current_path ( scene - > get_filename ( ) ) ;
} ;
2016-06-28 12:00:18 +02:00
file - > set_title ( TTR ( " Pick a Main Scene " ) ) ;
2016-06-28 00:59:33 +02:00
file - > popup_centered_ratio ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
2017-05-26 16:34:41 +02:00
case HELP_CLASSES : {
emit_signal ( " request_help_index " , " " ) ;
} break ;
case HELP_SEARCH : {
emit_signal ( " request_help_search " , " " ) ;
} break ;
case HELP_DOCS : {
OS : : get_singleton ( ) - > shell_open ( " http://docs.godotengine.org/ " ) ;
} break ;
case HELP_QA : {
OS : : get_singleton ( ) - > shell_open ( " https://godotengine.org/qa/ " ) ;
} break ;
case HELP_ISSUES : {
OS : : get_singleton ( ) - > shell_open ( " https://github.com/godotengine/godot/issues " ) ;
} break ;
case HELP_COMMUNITY : {
OS : : get_singleton ( ) - > shell_open ( " https://godotengine.org/community " ) ;
} break ;
case HELP_ABOUT : {
2017-07-02 20:17:47 +02:00
about - > popup_centered_minsize ( Size2 ( 780 , 500 ) * EDSCALE ) ;
2014-02-10 02:10:30 +01:00
} break ;
2016-05-27 19:18:40 +02:00
2014-02-10 02:10:30 +01:00
default : {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
if ( p_option > = OBJECT_METHOD_BASE ) {
2014-02-10 02:10:30 +01:00
ERR_FAIL_COND ( ! current ) ;
2017-03-05 16:44:50 +01:00
int idx = p_option - OBJECT_METHOD_BASE ;
2014-02-10 02:10:30 +01:00
List < MethodInfo > methods ;
current - > get_method_list ( & methods ) ;
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( idx , methods . size ( ) ) ;
String name = methods [ idx ] . name ;
2014-02-10 02:10:30 +01:00
if ( current )
current - > call ( name ) ;
2017-03-05 16:44:50 +01:00
} else if ( p_option > = IMPORT_PLUGIN_BASE ) {
2014-02-10 02:10:30 +01:00
}
}
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
2018-03-17 02:50:35 +01:00
void EditorNode : : _tool_menu_option ( int p_idx ) {
switch ( tool_menu - > get_item_id ( p_idx ) ) {
case TOOLS_ORPHAN_RESOURCES : {
orphan_resources - > show ( ) ;
} break ;
case TOOLS_CUSTOM : {
if ( tool_menu - > get_item_submenu ( p_idx ) = = " " ) {
Array params = tool_menu - > get_item_metadata ( p_idx ) ;
Object * handler = ObjectDB : : get_instance ( params [ 0 ] ) ;
String callback = params [ 1 ] ;
Variant * ud = & params [ 2 ] ;
Variant : : CallError ce ;
handler - > call ( callback , ( const Variant * * ) & ud , 1 , ce ) ;
if ( ce . error ! = Variant : : CallError : : CALL_OK ) {
String err = Variant : : get_call_error_text ( handler , callback , ( const Variant * * ) & ud , 1 , ce ) ;
ERR_PRINTS ( " Error calling function from tool menu: " + err ) ;
}
} // else it's a submenu so don't do anything.
} break ;
}
}
2017-07-26 13:29:45 +02:00
int EditorNode : : _next_unsaved_scene ( bool p_valid_filename , int p_start ) {
2017-06-24 12:57:30 +02:00
2017-07-26 13:29:45 +02:00
for ( int i = p_start ; i < editor_data . get_edited_scene_count ( ) ; i + + ) {
2017-06-24 12:57:30 +02:00
2017-07-09 20:48:39 +02:00
if ( ! editor_data . get_edited_scene_root ( i ) )
continue ;
2017-06-24 12:57:30 +02:00
int current = editor_data . get_edited_scene ( ) ;
bool unsaved = ( i = = current ) ? saved_version ! = editor_data . get_undo_redo ( ) . get_version ( ) : editor_data . get_scene_version ( i ) ! = 0 ;
2017-06-26 16:04:53 +02:00
if ( unsaved ) {
2017-07-26 13:29:45 +02:00
String scene_filename = editor_data . get_edited_scene_root ( i ) - > get_filename ( ) ;
if ( p_valid_filename & & scene_filename . length ( ) = = 0 )
continue ;
2017-06-26 16:04:53 +02:00
return i ;
}
2017-06-24 12:57:30 +02:00
}
2017-06-26 16:04:53 +02:00
return - 1 ;
2017-06-24 12:57:30 +02:00
}
2017-06-21 06:15:39 +02:00
void EditorNode : : _discard_changes ( const String & p_str ) {
switch ( current_option ) {
2017-06-26 16:04:53 +02:00
case FILE_CLOSE_ALL_AND_QUIT :
case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER :
2017-06-21 06:15:39 +02:00
case FILE_CLOSE :
case SCENE_TAB_CLOSE : {
_remove_scene ( tab_closing ) ;
_update_scene_tabs ( ) ;
2017-06-26 16:04:53 +02:00
if ( current_option = = FILE_CLOSE_ALL_AND_QUIT | | current_option = = FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER ) {
2017-07-26 13:29:45 +02:00
if ( _next_unsaved_scene ( false ) = = - 1 ) {
2017-06-26 16:04:53 +02:00
current_option = current_option = = FILE_CLOSE_ALL_AND_QUIT ? FILE_QUIT : RUN_PROJECT_MANAGER ;
_discard_changes ( ) ;
} else {
_menu_option_confirm ( current_option , false ) ;
}
} else {
current_option = - 1 ;
save_confirmation - > hide ( ) ;
}
2017-06-21 06:15:39 +02:00
} break ;
2017-06-24 12:57:30 +02:00
case FILE_QUIT : {
_menu_option_confirm ( RUN_STOP , true ) ;
exiting = true ;
get_tree ( ) - > quit ( ) ;
} break ;
case RUN_PROJECT_MANAGER : {
_menu_option_confirm ( RUN_STOP , true ) ;
exiting = true ;
get_tree ( ) - > quit ( ) ;
String exec = OS : : get_singleton ( ) - > get_executable_path ( ) ;
List < String > args ;
2017-06-21 11:09:30 +02:00
args . push_back ( " --path " ) ;
2017-06-24 12:57:30 +02:00
args . push_back ( exec . get_base_dir ( ) ) ;
2017-06-21 11:09:30 +02:00
args . push_back ( " --project-manager " ) ;
2017-06-24 12:57:30 +02:00
OS : : ProcessID pid = 0 ;
Error err = OS : : get_singleton ( ) - > execute ( exec , args , false , & pid ) ;
ERR_FAIL_COND ( err ) ;
} break ;
2017-06-21 06:15:39 +02:00
}
}
2017-02-08 06:18:48 +01:00
void EditorNode : : _update_debug_options ( ) {
2017-03-05 16:44:50 +01:00
bool check_deploy_remote = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " debug_options " , " run_deploy_remote_debug " , false ) ;
bool check_file_server = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " debug_options " , " run_file_server " , false ) ;
bool check_debug_collisons = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " debug_options " , " run_debug_collisons " , false ) ;
2017-02-08 06:18:48 +01:00
bool check_debug_navigation = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " debug_options " , " run_debug_navigation " , false ) ;
2017-03-05 16:44:50 +01:00
bool check_live_debug = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " debug_options " , " run_live_debug " , false ) ;
bool check_reload_scripts = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " debug_options " , " run_reload_scripts " , false ) ;
2017-02-08 06:18:48 +01:00
2017-03-05 16:44:50 +01:00
if ( check_deploy_remote ) _menu_option_confirm ( RUN_DEPLOY_REMOTE_DEBUG , true ) ;
if ( check_file_server ) _menu_option_confirm ( RUN_FILE_SERVER , true ) ;
if ( check_debug_collisons ) _menu_option_confirm ( RUN_DEBUG_COLLISONS , true ) ;
2017-02-08 06:18:48 +01:00
if ( check_debug_navigation ) _menu_option_confirm ( RUN_DEBUG_NAVIGATION , true ) ;
2017-03-05 16:44:50 +01:00
if ( check_live_debug ) _menu_option_confirm ( RUN_LIVE_DEBUG , true ) ;
if ( check_reload_scripts ) _menu_option_confirm ( RUN_RELOAD_SCRIPTS , true ) ;
2017-02-08 06:18:48 +01:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Control * EditorNode : : get_viewport ( ) {
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
return viewport ;
}
void EditorNode : : _editor_select ( int p_which ) {
2017-03-05 16:44:50 +01:00
static bool selecting = false ;
2015-11-17 13:46:08 +01:00
if ( selecting | | changing_scene )
2014-02-10 02:10:30 +01:00
return ;
2017-03-05 16:44:50 +01:00
selecting = true ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_which , editor_table . size ( ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < main_editor_buttons . size ( ) ; i + + ) {
main_editor_buttons [ i ] - > set_pressed ( i = = p_which ) ;
2015-11-18 08:47:41 +01:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
selecting = false ;
2014-02-10 02:10:30 +01:00
EditorPlugin * new_editor = editor_table [ p_which ] ;
ERR_FAIL_COND ( ! new_editor ) ;
2017-03-05 16:44:50 +01:00
if ( editor_plugin_screen = = new_editor )
2014-02-10 02:10:30 +01:00
return ;
if ( editor_plugin_screen ) {
editor_plugin_screen - > make_visible ( false ) ;
}
2017-03-05 16:44:50 +01:00
editor_plugin_screen = new_editor ;
2014-02-10 02:10:30 +01:00
editor_plugin_screen - > make_visible ( true ) ;
editor_plugin_screen - > selected_notify ( ) ;
2017-04-25 13:48:35 +02:00
2017-07-06 09:18:20 +02:00
int plugin_count = editor_data . get_editor_plugin_count ( ) ;
for ( int i = 0 ; i < plugin_count ; i + + ) {
editor_data . get_editor_plugin ( i ) - > notify_main_screen_changed ( editor_plugin_screen - > get_name ( ) ) ;
}
2017-09-29 18:52:56 +02:00
if ( EditorSettings : : get_singleton ( ) - > get ( " interface/editor/separate_distraction_mode " ) ) {
2017-04-25 13:48:35 +02:00
if ( p_which = = EDITOR_SCRIPT ) {
set_distraction_free_mode ( script_distraction ) ;
} else {
set_distraction_free_mode ( scene_distraction ) ;
}
}
2014-02-10 02:10:30 +01:00
}
void EditorNode : : add_editor_plugin ( EditorPlugin * p_editor ) {
if ( p_editor - > has_main_screen ( ) ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
ToolButton * tb = memnew ( ToolButton ) ;
2015-11-18 08:47:41 +01:00
tb - > set_toggle_mode ( true ) ;
2017-03-05 16:44:50 +01:00
tb - > connect ( " pressed " , singleton , " _editor_select " , varray ( singleton - > main_editor_buttons . size ( ) ) ) ;
2017-05-02 23:02:06 +02:00
tb - > set_text ( p_editor - > get_name ( ) ) ;
2017-12-06 23:27:45 +01:00
Ref < Texture > icon = p_editor - > get_icon ( ) ;
if ( icon . is_valid ( ) ) {
tb - > set_icon ( icon ) ;
} else if ( singleton - > gui_base - > has_icon ( p_editor - > get_name ( ) , " EditorIcons " ) ) {
tb - > set_icon ( singleton - > gui_base - > get_icon ( p_editor - > get_name ( ) , " EditorIcons " ) ) ;
}
2017-05-02 22:13:12 +02:00
tb - > set_name ( p_editor - > get_name ( ) ) ;
2015-11-18 08:47:41 +01:00
singleton - > main_editor_buttons . push_back ( tb ) ;
singleton - > main_editor_button_vb - > add_child ( tb ) ;
2014-02-10 02:10:30 +01:00
singleton - > editor_table . push_back ( p_editor ) ;
2016-09-13 14:46:17 +02:00
singleton - > distraction_free - > raise ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
singleton - > editor_data . add_editor_plugin ( p_editor ) ;
2014-02-10 02:10:30 +01:00
singleton - > add_child ( p_editor ) ;
}
void EditorNode : : remove_editor_plugin ( EditorPlugin * p_editor ) {
if ( p_editor - > has_main_screen ( ) ) {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < singleton - > main_editor_buttons . size ( ) ; i + + ) {
2015-11-18 08:47:41 +01:00
2017-03-05 16:44:50 +01:00
if ( p_editor - > get_name ( ) = = singleton - > main_editor_buttons [ i ] - > get_text ( ) ) {
2014-02-10 02:10:30 +01:00
2016-09-22 00:17:55 +02:00
if ( singleton - > main_editor_buttons [ i ] - > is_pressed ( ) ) {
singleton - > _editor_select ( EDITOR_SCRIPT ) ;
}
2017-03-05 16:44:50 +01:00
memdelete ( singleton - > main_editor_buttons [ i ] ) ;
2015-11-18 08:47:41 +01:00
singleton - > main_editor_buttons . remove ( i ) ;
2014-02-10 02:10:30 +01:00
break ;
}
}
singleton - > editor_table . erase ( p_editor ) ;
}
2016-06-19 00:29:16 +02:00
p_editor - > make_visible ( false ) ;
p_editor - > clear ( ) ;
singleton - > editor_plugins_over - > get_plugins_list ( ) . erase ( p_editor ) ;
2014-02-10 02:10:30 +01:00
singleton - > remove_child ( p_editor ) ;
2017-03-05 16:44:50 +01:00
singleton - > editor_data . remove_editor_plugin ( p_editor ) ;
2014-02-10 02:10:30 +01:00
}
2016-02-28 03:10:44 +01:00
void EditorNode : : _update_addon_config ( ) {
if ( _initializing_addons )
return ;
Vector < String > enabled_addons ;
2017-03-05 16:44:50 +01:00
for ( Map < String , EditorPlugin * > : : Element * E = plugin_addons . front ( ) ; E ; E = E - > next ( ) ) {
2016-02-28 03:10:44 +01:00
enabled_addons . push_back ( E - > key ( ) ) ;
}
2017-03-05 16:44:50 +01:00
if ( enabled_addons . size ( ) = = 0 ) {
2017-07-19 22:00:46 +02:00
ProjectSettings : : get_singleton ( ) - > set ( " editor_plugins/enabled " , Variant ( ) ) ;
2016-02-28 03:10:44 +01:00
} else {
2017-07-19 22:00:46 +02:00
ProjectSettings : : get_singleton ( ) - > set ( " editor_plugins/enabled " , enabled_addons ) ;
2016-02-28 03:10:44 +01:00
}
project_settings - > queue_save ( ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : set_addon_plugin_enabled ( const String & p_addon , bool p_enabled ) {
2016-02-28 03:10:44 +01:00
ERR_FAIL_COND ( p_enabled & & plugin_addons . has ( p_addon ) ) ;
ERR_FAIL_COND ( ! p_enabled & & ! plugin_addons . has ( p_addon ) ) ;
if ( ! p_enabled ) {
EditorPlugin * addon = plugin_addons [ p_addon ] ;
2016-06-19 00:29:16 +02:00
remove_editor_plugin ( addon ) ;
2016-02-28 03:10:44 +01:00
memdelete ( addon ) ; //bye
plugin_addons . erase ( p_addon ) ;
_update_addon_config ( ) ;
return ;
}
Ref < ConfigFile > cf ;
cf . instance ( ) ;
2017-03-05 16:44:50 +01:00
String addon_path = " res://addons/ " + p_addon + " /plugin.cfg " ;
2016-02-28 03:10:44 +01:00
Error err = cf - > load ( addon_path ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
2017-10-23 22:31:26 +02:00
show_warning ( vformat ( TTR ( " Unable to enable addon plugin at: '%s' parsing of config failed. " ) , addon_path ) ) ;
2016-02-28 03:10:44 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( ! cf - > has_section_key ( " plugin " , " script " ) ) {
2017-10-23 22:31:26 +02:00
show_warning ( vformat ( TTR ( " Unable to find script field for addon plugin at: 'res://addons/%s'. " ) , p_addon ) ) ;
2016-02-28 03:10:44 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
String path = cf - > get_value ( " plugin " , " script " ) ;
path = " res://addons/ " + p_addon + " / " + path ;
2016-02-28 03:10:44 +01:00
Ref < Script > script = ResourceLoader : : load ( path ) ;
if ( script . is_null ( ) ) {
2017-10-23 22:31:26 +02:00
show_warning ( vformat ( TTR ( " Unable to load addon script from path: '%s'. " ) , path ) ) ;
2016-02-28 03:10:44 +01:00
return ;
}
//could check inheritance..
2017-03-05 16:44:50 +01:00
if ( String ( script - > get_instance_base_type ( ) ) ! = " EditorPlugin " ) {
2017-10-23 22:31:26 +02:00
show_warning ( vformat ( TTR ( " Unable to load addon script from path: '%s' Base type is not EditorPlugin. " ) , path ) ) ;
2016-02-28 03:10:44 +01:00
return ;
}
if ( ! script - > is_tool ( ) ) {
2017-10-23 22:31:26 +02:00
show_warning ( vformat ( TTR ( " Unable to load addon script from path: '%s' Script is not in tool mode. " ) , path ) ) ;
2016-02-28 03:10:44 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
EditorPlugin * ep = memnew ( EditorPlugin ) ;
2016-02-28 03:10:44 +01:00
ep - > set_script ( script . get_ref_ptr ( ) ) ;
2017-03-05 16:44:50 +01:00
plugin_addons [ p_addon ] = ep ;
2016-02-28 03:10:44 +01:00
add_editor_plugin ( ep ) ;
_update_addon_config ( ) ;
}
2017-03-05 16:44:50 +01:00
bool EditorNode : : is_addon_plugin_enabled ( const String & p_addon ) const {
2016-02-28 03:10:44 +01:00
return plugin_addons . has ( p_addon ) ;
}
2015-06-22 05:03:19 +02:00
void EditorNode : : _remove_edited_scene ( ) {
int new_index = editor_data . get_edited_scene ( ) ;
2017-03-05 16:44:50 +01:00
int old_index = new_index ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
if ( new_index > 0 ) {
new_index = new_index - 1 ;
} else if ( editor_data . get_edited_scene_count ( ) > 1 ) {
new_index = 1 ;
2015-06-22 05:03:19 +02:00
} else {
editor_data . add_edited_scene ( - 1 ) ;
2017-03-05 16:44:50 +01:00
new_index = 1 ;
2015-06-22 05:03:19 +02:00
}
2017-03-05 16:44:50 +01:00
if ( editor_data . get_scene_path ( old_index ) ! = String ( ) ) {
2016-07-07 01:35:49 +02:00
ScriptEditor : : get_singleton ( ) - > close_builtin_scripts_from_scene ( editor_data . get_scene_path ( old_index ) ) ;
}
2015-06-22 05:03:19 +02:00
_scene_tab_changed ( new_index ) ;
editor_data . remove_scene ( old_index ) ;
editor_data . get_undo_redo ( ) . clear_history ( ) ;
_update_title ( ) ;
_update_scene_tabs ( ) ;
}
2015-10-22 00:23:42 +02:00
void EditorNode : : _remove_scene ( int index ) {
2015-11-19 14:15:17 +01:00
2015-10-22 00:23:42 +02:00
if ( editor_data . get_edited_scene ( ) = = index ) {
//Scene to remove is current scene
_remove_edited_scene ( ) ;
2017-03-05 16:44:50 +01:00
} else {
2018-01-09 13:42:45 +01:00
//Scene to remove is not active scene
2015-10-22 00:23:42 +02:00
editor_data . remove_scene ( index ) ;
}
}
2014-02-10 02:10:30 +01:00
void EditorNode : : set_edited_scene ( Node * p_scene ) {
2015-06-22 05:03:19 +02:00
if ( get_editor_data ( ) . get_edited_scene_root ( ) ) {
2017-03-05 16:44:50 +01:00
if ( get_editor_data ( ) . get_edited_scene_root ( ) - > get_parent ( ) = = scene_root )
2015-06-22 05:03:19 +02:00
scene_root - > remove_child ( get_editor_data ( ) . get_edited_scene_root ( ) ) ;
2016-03-09 00:00:52 +01:00
}
2015-06-22 05:03:19 +02:00
get_editor_data ( ) . set_edited_scene_root ( p_scene ) ;
2016-03-09 00:00:52 +01:00
2017-08-24 22:58:51 +02:00
if ( Object : : cast_to < Popup > ( p_scene ) )
Object : : cast_to < Popup > ( p_scene ) - > show ( ) ; //show popups
2015-06-22 05:03:19 +02:00
scene_tree_dock - > set_edited_scene ( p_scene ) ;
2014-11-06 01:20:42 +01:00
if ( get_tree ( ) )
2015-06-22 05:03:19 +02:00
get_tree ( ) - > set_edited_scene_root ( p_scene ) ;
2014-02-10 02:10:30 +01:00
2015-06-22 05:03:19 +02:00
if ( p_scene ) {
2017-03-05 16:44:50 +01:00
if ( p_scene - > get_parent ( ) ! = scene_root )
2014-02-10 02:10:30 +01:00
scene_root - > add_child ( p_scene ) ;
}
}
2015-11-18 08:47:41 +01:00
int EditorNode : : _get_current_main_editor ( ) {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < editor_table . size ( ) ; i + + ) {
if ( editor_table [ i ] = = editor_plugin_screen )
2015-11-18 08:47:41 +01:00
return i ;
}
return 0 ;
}
2015-06-22 05:03:19 +02:00
Dictionary EditorNode : : _get_main_scene_state ( ) {
Dictionary state ;
2017-03-05 16:44:50 +01:00
state [ " main_tab " ] = _get_current_main_editor ( ) ;
state [ " scene_tree_offset " ] = scene_tree_dock - > get_tree_editor ( ) - > get_scene_tree ( ) - > get_vscroll_bar ( ) - > get_value ( ) ;
state [ " property_edit_offset " ] = get_property_editor ( ) - > get_scene_tree ( ) - > get_vscroll_bar ( ) - > get_value ( ) ;
state [ " saved_version " ] = saved_version ;
state [ " node_filter " ] = scene_tree_dock - > get_filter ( ) ;
2015-06-22 05:03:19 +02:00
return state ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _set_main_scene_state ( Dictionary p_state , Node * p_for_scene ) {
2016-06-28 23:53:31 +02:00
2017-03-05 16:44:50 +01:00
if ( get_edited_scene ( ) ! = p_for_scene & & p_for_scene ! = NULL )
2016-06-28 23:53:31 +02:00
return ; //not for this scene
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
changing_scene = false ;
2015-06-22 05:03:19 +02:00
2017-09-08 23:45:04 +02:00
int current = - 1 ;
for ( int i = 0 ; i < editor_table . size ( ) ; i + + ) {
if ( editor_plugin_screen = = editor_table [ i ] ) {
current = i ;
break ;
2015-11-17 13:46:08 +01:00
}
2017-09-08 23:45:04 +02:00
}
2015-11-17 13:46:08 +01:00
2017-09-08 23:45:04 +02:00
if ( p_state . has ( " editor_index " ) ) {
int index = p_state [ " editor_index " ] ;
2018-02-21 17:30:55 +01:00
if ( current < 2 ) { //if currently in spatial/2d, only switch to spatial/2d. if currently in script, stay there
2017-09-04 23:00:09 +02:00
if ( index < 2 | | ! get_edited_scene ( ) ) {
_editor_select ( index ) ;
2017-09-08 23:45:04 +02:00
}
}
}
if ( get_edited_scene ( ) ) {
if ( current < 2 ) {
//use heuristic instead
int n2d = 0 , n3d = 0 ;
_find_node_types ( get_edited_scene ( ) , n2d , n3d ) ;
if ( n2d > n3d ) {
_editor_select ( EDITOR_2D ) ;
} else if ( n3d > n2d ) {
_editor_select ( EDITOR_3D ) ;
2015-11-17 13:46:08 +01:00
}
}
}
2015-06-22 05:03:19 +02:00
if ( p_state . has ( " scene_tree_offset " ) )
2017-01-04 05:16:14 +01:00
scene_tree_dock - > get_tree_editor ( ) - > get_scene_tree ( ) - > get_vscroll_bar ( ) - > set_value ( p_state [ " scene_tree_offset " ] ) ;
2015-06-22 05:03:19 +02:00
if ( p_state . has ( " property_edit_offset " ) )
2017-01-04 05:16:14 +01:00
get_property_editor ( ) - > get_scene_tree ( ) - > get_vscroll_bar ( ) - > set_value ( p_state [ " property_edit_offset " ] ) ;
2015-06-22 05:03:19 +02:00
2016-05-16 17:23:40 +02:00
if ( p_state . has ( " node_filter " ) )
scene_tree_dock - > set_filter ( p_state [ " node_filter " ] ) ;
2015-06-22 05:03:19 +02:00
2015-11-17 13:46:08 +01:00
//this should only happen at the very end
ScriptEditor : : get_singleton ( ) - > get_debugger ( ) - > update_live_edit_root ( ) ;
2017-03-05 16:44:50 +01:00
ScriptEditor : : get_singleton ( ) - > set_scene_root_script ( editor_data . get_scene_root_script ( editor_data . get_edited_scene ( ) ) ) ;
2015-12-09 13:08:41 +01:00
editor_data . notify_edited_scene_changed ( ) ;
2015-06-22 05:03:19 +02:00
}
void EditorNode : : set_current_version ( uint64_t p_version ) {
2017-03-05 16:44:50 +01:00
saved_version = p_version ;
2015-06-22 05:03:19 +02:00
editor_data . set_edited_scene_version ( p_version ) ;
}
bool EditorNode : : is_changing_scene ( ) const {
return changing_scene ;
}
2015-12-14 00:39:01 +01:00
void EditorNode : : _clear_undo_history ( ) {
get_undo_redo ( ) - > clear_history ( ) ;
}
2015-06-22 05:03:19 +02:00
void EditorNode : : set_current_scene ( int p_idx ) {
2015-12-14 00:39:01 +01:00
if ( editor_data . check_and_update_scene ( p_idx ) ) {
call_deferred ( " _clear_undo_history " ) ;
}
2017-03-05 16:44:50 +01:00
changing_scene = true ;
editor_data . save_edited_scene_state ( editor_selection , & editor_history , _get_main_scene_state ( ) ) ;
2015-06-22 05:03:19 +02:00
if ( get_editor_data ( ) . get_edited_scene_root ( ) ) {
2017-03-05 16:44:50 +01:00
if ( get_editor_data ( ) . get_edited_scene_root ( ) - > get_parent ( ) = = scene_root )
2015-06-22 05:03:19 +02:00
scene_root - > remove_child ( get_editor_data ( ) . get_edited_scene_root ( ) ) ;
}
editor_selection - > clear ( ) ;
editor_data . set_edited_scene ( p_idx ) ;
2017-03-05 16:44:50 +01:00
Node * new_scene = editor_data . get_edited_scene_root ( ) ;
2015-06-22 05:03:19 +02:00
2017-08-24 22:58:51 +02:00
if ( Object : : cast_to < Popup > ( new_scene ) )
Object : : cast_to < Popup > ( new_scene ) - > show ( ) ; //show popups
2015-06-22 05:03:19 +02:00
scene_tree_dock - > set_edited_scene ( new_scene ) ;
if ( get_tree ( ) )
get_tree ( ) - > set_edited_scene_root ( new_scene ) ;
if ( new_scene ) {
2017-03-05 16:44:50 +01:00
if ( new_scene - > get_parent ( ) ! = scene_root )
2015-06-22 05:03:19 +02:00
scene_root - > add_child ( new_scene ) ;
}
2017-03-05 16:44:50 +01:00
Dictionary state = editor_data . restore_edited_scene_state ( editor_selection , & editor_history ) ;
2015-06-22 05:03:19 +02:00
_edit_current ( ) ;
2017-03-05 16:44:50 +01:00
call_deferred ( " _set_main_scene_state " , state , get_edited_scene ( ) ) ; //do after everything else is done setting up
2015-06-22 05:03:19 +02:00
}
2017-03-05 16:44:50 +01:00
bool EditorNode : : is_scene_open ( const String & p_path ) {
2015-08-24 01:15:56 +02:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < editor_data . get_edited_scene_count ( ) ; i + + ) {
if ( editor_data . get_scene_path ( i ) = = p_path )
2015-08-24 01:15:56 +02:00
return true ;
}
return false ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : fix_dependencies ( const String & p_for_file ) {
2015-08-24 01:15:56 +02:00
dependency_fixer - > edit ( p_for_file ) ;
}
2017-03-05 16:44:50 +01:00
Error EditorNode : : load_scene ( const String & p_scene , bool p_ignore_broken_deps , bool p_set_inherited , bool p_clear_errors , bool p_force_open_imported ) {
2014-02-10 02:10:30 +01:00
2014-11-06 01:20:42 +01:00
if ( ! is_inside_tree ( ) ) {
2014-02-10 02:10:30 +01:00
defer_load_scene = p_scene ;
return OK ;
}
2017-03-05 16:44:50 +01:00
if ( ! p_set_inherited ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < editor_data . get_edited_scene_count ( ) ; i + + ) {
2017-02-05 00:31:15 +01:00
2017-03-05 16:44:50 +01:00
if ( editor_data . get_scene_path ( i ) = = p_scene ) {
2016-01-02 23:42:41 +01:00
_scene_tab_changed ( i ) ;
return OK ;
}
2015-06-22 05:03:19 +02:00
}
2017-02-05 00:31:15 +01:00
2017-03-05 16:44:50 +01:00
if ( ! p_force_open_imported & & FileAccess : : exists ( p_scene + " .import " ) ) {
open_imported - > set_text ( vformat ( TTR ( " Scene '%s' was automatically imported, so it can't be modified. \n To make changes to it, a new inherited scene can be created. " ) , p_scene . get_file ( ) ) ) ;
2017-02-05 00:31:15 +01:00
open_imported - > popup_centered_minsize ( ) ;
new_inherited_button - > grab_focus ( ) ;
2017-03-05 16:44:50 +01:00
open_import_request = p_scene ;
2017-02-05 00:31:15 +01:00
return OK ;
}
2015-06-22 05:03:19 +02:00
}
2016-06-26 20:37:04 +02:00
if ( p_clear_errors )
load_errors - > clear ( ) ;
2017-07-19 22:00:46 +02:00
String lpath = ProjectSettings : : get_singleton ( ) - > localize_path ( p_scene ) ;
2014-02-10 02:10:30 +01:00
if ( ! lpath . begins_with ( " res:// " ) ) {
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2016-05-04 03:25:37 +02:00
accept - > get_ok ( ) - > set_text ( TTR ( " Ugh " ) ) ;
accept - > set_text ( TTR ( " Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path. " ) ) ;
2015-04-08 19:02:13 +02:00
accept - > popup_centered_minsize ( ) ;
2017-03-05 16:44:50 +01:00
opening_prev = false ;
2014-02-10 02:10:30 +01:00
return ERR_FILE_NOT_FOUND ;
}
2015-06-22 05:03:19 +02:00
int prev = editor_data . get_edited_scene ( ) ;
int idx = editor_data . add_edited_scene ( - 1 ) ;
2017-03-05 16:44:50 +01:00
if ( ! editor_data . get_edited_scene_root ( ) & & editor_data . get_edited_scene_count ( ) = = 2 ) {
2015-06-22 05:03:19 +02:00
_remove_edited_scene ( ) ;
} else {
_scene_tab_changed ( idx ) ;
}
2015-08-24 01:15:56 +02:00
dependency_errors . clear ( ) ;
2017-08-28 05:24:50 +02:00
Error err ;
Ref < PackedScene > sdata = ResourceLoader : : load ( lpath , " " , true , & err ) ;
2014-02-10 02:10:30 +01:00
if ( ! sdata . is_valid ( ) ) {
2017-08-28 05:24:50 +02:00
_dialog_display_load_error ( lpath , err ) ;
2017-03-05 16:44:50 +01:00
opening_prev = false ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
if ( prev ! = - 1 ) {
2015-06-22 05:03:19 +02:00
set_current_scene ( prev ) ;
editor_data . remove_scene ( idx ) ;
}
2014-02-10 02:10:30 +01:00
return ERR_FILE_NOT_FOUND ;
}
2015-08-24 01:15:56 +02:00
if ( ! p_ignore_broken_deps & & dependency_errors . has ( lpath ) ) {
2017-03-05 16:44:50 +01:00
current_option = - 1 ;
2015-08-24 01:15:56 +02:00
Vector < String > errors ;
2017-03-05 16:44:50 +01:00
for ( Set < String > : : Element * E = dependency_errors [ lpath ] . front ( ) ; E ; E = E - > next ( ) ) {
2015-08-24 01:15:56 +02:00
errors . push_back ( E - > get ( ) ) ;
}
2017-03-05 16:44:50 +01:00
dependency_error - > show ( lpath , errors ) ;
opening_prev = false ;
2015-08-24 01:15:56 +02:00
2017-03-05 16:44:50 +01:00
if ( prev ! = - 1 ) {
2015-08-24 01:15:56 +02:00
set_current_scene ( prev ) ;
editor_data . remove_scene ( idx ) ;
}
return ERR_FILE_MISSING_DEPENDENCIES ;
}
dependency_errors . erase ( lpath ) ; //at least not self path
2017-03-05 16:44:50 +01:00
for ( Map < String , Set < String > > : : Element * E = dependency_errors . front ( ) ; E ; E = E - > next ( ) ) {
2015-08-24 01:15:56 +02:00
2017-03-05 16:44:50 +01:00
String txt = vformat ( TTR ( " Scene '%s' has broken dependencies: " ) , E - > key ( ) ) + " \n " ;
for ( Set < String > : : Element * F = E - > get ( ) . front ( ) ; F ; F = F - > next ( ) ) {
txt + = " \t " + F - > get ( ) + " \n " ;
2015-08-24 01:15:56 +02:00
}
add_io_error ( txt ) ;
}
2016-01-14 15:06:20 +01:00
if ( ResourceCache : : has ( lpath ) ) {
2016-01-14 15:50:24 +01:00
//used from somewhere else? no problem! update state and replace sdata
2017-08-24 22:58:51 +02:00
Ref < PackedScene > ps = Ref < PackedScene > ( Object : : cast_to < PackedScene > ( ResourceCache : : get ( lpath ) ) ) ;
2016-01-14 15:06:20 +01:00
if ( ps . is_valid ( ) ) {
2017-03-05 16:44:50 +01:00
ps - > replace_state ( sdata - > get_state ( ) ) ;
ps - > set_last_modified_time ( sdata - > get_last_modified_time ( ) ) ;
sdata = ps ;
2016-01-14 15:06:20 +01:00
}
} else {
2017-03-05 16:44:50 +01:00
sdata - > set_path ( lpath , true ) ; //take over path
2016-01-14 15:06:20 +01:00
}
2015-06-26 06:14:31 +02:00
2017-03-05 16:44:50 +01:00
Node * new_scene = sdata - > instance ( PackedScene : : GEN_EDIT_STATE_MAIN ) ;
2014-02-10 02:10:30 +01:00
if ( ! new_scene ) {
2015-06-22 05:03:19 +02:00
sdata . unref ( ) ;
2017-08-28 05:24:50 +02:00
_dialog_display_load_error ( lpath , ERR_FILE_NOT_FOUND ) ;
2017-03-05 16:44:50 +01:00
opening_prev = false ;
if ( prev ! = - 1 ) {
2015-06-22 05:03:19 +02:00
set_current_scene ( prev ) ;
editor_data . remove_scene ( idx ) ;
}
2014-02-10 02:10:30 +01:00
return ERR_FILE_NOT_FOUND ;
}
2015-10-10 14:09:09 +02:00
if ( p_set_inherited ) {
Ref < SceneState > state = sdata - > get_state ( ) ;
2016-03-09 00:00:52 +01:00
state - > set_path ( lpath ) ;
2015-10-10 14:09:09 +02:00
new_scene - > set_scene_inherited_state ( state ) ;
2015-10-18 01:55:12 +02:00
new_scene - > set_filename ( String ( ) ) ;
2015-10-10 14:09:09 +02:00
}
2015-11-29 00:56:14 +01:00
new_scene - > set_scene_instance_state ( Ref < SceneState > ( ) ) ;
2015-10-10 14:09:09 +02:00
2014-02-10 02:10:30 +01:00
set_edited_scene ( new_scene ) ;
2015-12-31 04:31:00 +01:00
_get_scene_metadata ( p_scene ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
saved_version = editor_data . get_undo_redo ( ) . get_version ( ) ;
2014-02-10 02:10:30 +01:00
_update_title ( ) ;
2015-06-22 05:03:19 +02:00
_update_scene_tabs ( ) ;
2014-02-10 02:10:30 +01:00
_add_to_recent_scenes ( lpath ) ;
2017-03-05 16:44:50 +01:00
prev_scene - > set_disabled ( previous_scenes . size ( ) = = 0 ) ;
opening_prev = false ;
2014-02-10 02:10:30 +01:00
2015-08-02 17:29:37 +02:00
ScriptEditor : : get_singleton ( ) - > get_debugger ( ) - > update_live_edit_root ( ) ;
2014-07-07 22:44:21 +02:00
push_item ( new_scene ) ;
2014-02-10 02:10:30 +01:00
2017-11-25 00:32:54 +01:00
if ( ! restoring_scenes ) {
save_layout ( ) ;
}
2014-02-10 02:10:30 +01:00
return OK ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : open_request ( const String & p_path ) {
2014-02-10 02:10:30 +01:00
2015-06-22 05:03:19 +02:00
load_scene ( p_path ) ; // as it will be opened in separate tab
2014-02-10 02:10:30 +01:00
}
2016-05-12 01:57:52 +02:00
void EditorNode : : request_instance_scene ( const String & p_path ) {
2014-02-10 02:10:30 +01:00
2016-05-12 01:57:52 +02:00
scene_tree_dock - > instance ( p_path ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : request_instance_scenes ( const Vector < String > & p_files ) {
2016-07-20 19:09:03 +02:00
scene_tree_dock - > instance_scenes ( p_files ) ;
}
2017-02-01 13:45:45 +01:00
ImportDock * EditorNode : : get_import_dock ( ) {
return import_dock ;
}
2017-01-21 13:07:29 +01:00
FileSystemDock * EditorNode : : get_filesystem_dock ( ) {
2014-02-10 02:10:30 +01:00
2017-01-21 13:07:29 +01:00
return filesystem_dock ;
2014-02-10 02:10:30 +01:00
}
2016-06-04 18:17:56 +02:00
SceneTreeDock * EditorNode : : get_scene_tree_dock ( ) {
return scene_tree_dock ;
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
void EditorNode : : _instance_request ( const Vector < String > & p_files ) {
2014-02-10 02:10:30 +01:00
2016-07-20 19:09:03 +02:00
request_instance_scenes ( p_files ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _property_keyed ( const String & p_keyed , const Variant & p_value , bool p_advance ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
AnimationPlayerEditor : : singleton - > get_key_editor ( ) - > insert_value_key ( p_keyed , p_value , p_advance ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _transform_keyed ( Object * sp , const String & p_sub , const Transform & p_key ) {
2014-02-10 02:10:30 +01:00
2017-08-24 22:58:51 +02:00
Spatial * s = Object : : cast_to < Spatial > ( sp ) ;
2014-02-10 02:10:30 +01:00
if ( ! s )
return ;
2017-03-05 16:44:50 +01:00
AnimationPlayerEditor : : singleton - > get_key_editor ( ) - > insert_transform_key ( s , p_sub , p_key ) ;
2014-02-10 02:10:30 +01:00
}
2016-01-18 00:03:57 +01:00
void EditorNode : : update_keying ( ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bool valid = false ;
2014-02-10 02:10:30 +01:00
2016-01-18 00:03:57 +01:00
if ( AnimationPlayerEditor : : singleton - > get_key_editor ( ) - > has_keying ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( editor_history . get_path_size ( ) > = 1 ) {
2014-02-10 02:10:30 +01:00
Object * obj = ObjectDB : : get_instance ( editor_history . get_path_object ( 0 ) ) ;
2017-08-24 22:58:51 +02:00
if ( Object : : cast_to < Node > ( obj ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
valid = true ;
2014-02-10 02:10:30 +01:00
}
}
}
property_editor - > set_keying ( valid ) ;
2016-01-27 15:10:51 +01:00
AnimationPlayerEditor : : singleton - > get_key_editor ( ) - > update_keying ( ) ;
2014-02-10 02:10:30 +01:00
}
void EditorNode : : _close_messages ( ) {
2015-06-14 03:12:53 +02:00
old_split_ofs = center_split - > get_split_offset ( ) ;
center_split - > set_split_offset ( 0 ) ;
2014-02-10 02:10:30 +01:00
}
void EditorNode : : _show_messages ( ) {
2015-06-14 03:12:53 +02:00
center_split - > set_split_offset ( old_split_ofs ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _add_to_recent_scenes ( const String & p_scene ) {
2014-02-10 02:10:30 +01:00
2018-01-09 13:42:45 +01:00
Array rc = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " recent_files " , " scenes " , Array ( ) ) ;
if ( rc . find ( p_scene ) ! = - 1 )
rc . erase ( p_scene ) ;
rc . push_front ( p_scene ) ;
2017-03-05 16:44:50 +01:00
if ( rc . size ( ) > 10 )
2014-02-10 02:10:30 +01:00
rc . resize ( 10 ) ;
2018-01-09 13:42:45 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " recent_files " , " scenes " , rc ) ;
2014-02-10 02:10:30 +01:00
_update_recent_scenes ( ) ;
}
void EditorNode : : _open_recent_scene ( int p_idx ) {
2017-10-12 04:35:15 +02:00
if ( p_idx = = recent_scenes - > get_item_count ( ) - 1 ) {
2018-01-09 13:42:45 +01:00
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " recent_files " , " scenes " , Array ( ) ) ;
2017-10-12 04:35:15 +02:00
call_deferred ( " _update_recent_scenes " ) ;
} else {
2018-01-09 13:42:45 +01:00
Array rc = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " recent_files " , " scenes " , Array ( ) ) ;
2017-10-12 04:35:15 +02:00
ERR_FAIL_INDEX ( p_idx , rc . size ( ) ) ;
2014-02-10 02:10:30 +01:00
2018-01-09 13:42:45 +01:00
if ( load_scene ( rc [ p_idx ] ) ! = OK ) {
rc . remove ( p_idx ) ;
EditorSettings : : get_singleton ( ) - > set_project_metadata ( " recent_files " , " scenes " , rc ) ;
_update_recent_scenes ( ) ;
}
2017-10-12 04:35:15 +02:00
}
2014-02-10 02:10:30 +01:00
}
void EditorNode : : _update_recent_scenes ( ) {
2018-01-09 13:42:45 +01:00
Array rc = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " recent_files " , " scenes " , Array ( ) ) ;
2014-02-10 02:10:30 +01:00
recent_scenes - > clear ( ) ;
2017-10-12 04:35:15 +02:00
2018-01-09 13:42:45 +01:00
String path ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < rc . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2018-01-09 13:42:45 +01:00
path = rc [ i ] ;
recent_scenes - > add_item ( path . replace ( " res:// " , " " ) , i ) ;
2014-02-10 02:10:30 +01:00
}
2017-10-12 04:35:15 +02:00
recent_scenes - > add_separator ( ) ;
recent_scenes - > add_shortcut ( ED_SHORTCUT ( " editor/clear_recent " , TTR ( " Clear Recent Scenes " ) ) ) ;
recent_scenes - > set_as_minsize ( ) ;
2014-02-10 02:10:30 +01:00
}
2016-01-08 12:27:34 +01:00
void EditorNode : : _quick_opened ( ) {
2014-02-10 02:10:30 +01:00
2016-01-08 12:27:34 +01:00
Vector < String > files = quick_open - > get_selected_files ( ) ;
for ( int i = 0 ; i < files . size ( ) ; i + + ) {
String res_path = files [ i ] ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( quick_open - > get_base_type ( ) = = " PackedScene " ) {
2016-01-08 12:27:34 +01:00
open_request ( res_path ) ;
} else {
load_resource ( res_path ) ;
}
}
2014-02-10 02:10:30 +01:00
}
2016-02-17 19:40:06 +01:00
void EditorNode : : _quick_run ( ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
_run ( false , quick_run - > get_selected ( ) ) ;
2014-02-10 02:10:30 +01:00
}
void EditorNode : : notify_child_process_exited ( ) {
2017-03-05 16:44:50 +01:00
_menu_option_confirm ( RUN_STOP , false ) ;
2014-02-10 02:10:30 +01:00
stop_button - > set_pressed ( false ) ;
editor_run . stop ( ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : add_io_error ( const String & p_error ) {
_load_error_notify ( singleton , p_error ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _load_error_notify ( void * p_ud , const String & p_text ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
EditorNode * en = ( EditorNode * ) p_ud ;
en - > load_errors - > add_image ( en - > gui_base - > get_icon ( " Error " , " EditorIcons " ) ) ;
en - > load_errors - > add_text ( p_text + " \n " ) ;
2014-02-10 02:10:30 +01:00
en - > load_error_dialog - > popup_centered_ratio ( 0.5 ) ;
}
2017-03-05 16:44:50 +01:00
bool EditorNode : : _find_scene_in_use ( Node * p_node , const String & p_path ) const {
2014-06-19 07:23:03 +02:00
2017-03-05 16:44:50 +01:00
if ( p_node - > get_filename ( ) = = p_path ) {
2014-06-19 07:23:03 +02:00
return true ;
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_node - > get_child_count ( ) ; i + + ) {
2014-06-19 07:23:03 +02:00
2017-03-05 16:44:50 +01:00
if ( _find_scene_in_use ( p_node - > get_child ( i ) , p_path ) ) {
2014-06-19 07:23:03 +02:00
return true ;
}
}
return false ;
}
2017-03-05 16:44:50 +01:00
bool EditorNode : : is_scene_in_use ( const String & p_path ) {
2014-06-19 07:23:03 +02:00
Node * es = get_edited_scene ( ) ;
if ( es )
2017-03-05 16:44:50 +01:00
return _find_scene_in_use ( es , p_path ) ;
2014-06-19 07:23:03 +02:00
return false ;
}
2014-02-10 02:10:30 +01:00
void EditorNode : : register_editor_types ( ) {
2017-01-03 03:03:46 +01:00
ClassDB : : register_class < EditorPlugin > ( ) ;
2017-04-09 00:37:31 +02:00
ClassDB : : register_class < EditorImportPlugin > ( ) ;
2017-01-03 03:03:46 +01:00
ClassDB : : register_class < EditorScript > ( ) ;
ClassDB : : register_class < EditorSelection > ( ) ;
ClassDB : : register_class < EditorFileDialog > ( ) ;
2017-11-10 05:25:10 +01:00
ClassDB : : register_virtual_class < EditorSettings > ( ) ;
2017-01-03 03:03:46 +01:00
ClassDB : : register_class < EditorSpatialGizmo > ( ) ;
2017-11-10 05:25:10 +01:00
ClassDB : : register_virtual_class < EditorResourcePreview > ( ) ;
2017-01-03 03:03:46 +01:00
ClassDB : : register_class < EditorResourcePreviewGenerator > ( ) ;
2017-11-10 05:25:10 +01:00
ClassDB : : register_virtual_class < EditorFileSystem > ( ) ;
2017-01-03 03:03:46 +01:00
ClassDB : : register_class < EditorFileSystemDirectory > ( ) ;
2017-07-06 09:18:20 +02:00
ClassDB : : register_virtual_class < ScriptEditor > ( ) ;
2017-08-26 15:32:15 +02:00
ClassDB : : register_virtual_class < EditorInterface > ( ) ;
2017-09-15 00:38:38 +02:00
ClassDB : : register_class < EditorExportPlugin > ( ) ;
2017-09-22 14:20:28 +02:00
ClassDB : : register_class < EditorResourceConversionPlugin > ( ) ;
2017-12-07 19:44:20 +01:00
ClassDB : : register_class < EditorSceneImporter > ( ) ;
2017-08-26 17:46:49 +02:00
// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
2017-11-19 15:45:16 +01:00
ClassDB : : register_class < EditorScenePostImport > ( ) ;
2017-08-26 17:46:49 +02:00
//ClassDB::register_type<EditorImportExport>();
2014-02-10 02:10:30 +01:00
}
2014-02-25 13:31:47 +01:00
void EditorNode : : unregister_editor_types ( ) {
_init_callbacks . clear ( ) ;
}
2014-02-10 02:10:30 +01:00
void EditorNode : : stop_child_process ( ) {
2017-03-05 16:44:50 +01:00
_menu_option_confirm ( RUN_STOP , false ) ;
2014-02-10 02:10:30 +01:00
}
2017-12-14 12:59:46 +01:00
void EditorNode : : progress_add_task ( const String & p_task , const String & p_label , int p_steps , bool p_can_cancel ) {
2014-02-10 02:10:30 +01:00
2017-12-14 12:59:46 +01:00
singleton - > progress_dialog - > add_task ( p_task , p_label , p_steps , p_can_cancel ) ;
2014-02-10 02:10:30 +01:00
}
2017-12-14 12:59:46 +01:00
bool EditorNode : : progress_task_step ( const String & p_task , const String & p_state , int p_step , bool p_force_refresh ) {
2014-02-10 02:10:30 +01:00
2017-12-14 12:59:46 +01:00
return singleton - > progress_dialog - > task_step ( p_task , p_state , p_step , p_force_refresh ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : progress_end_task ( const String & p_task ) {
2014-02-10 02:10:30 +01:00
singleton - > progress_dialog - > end_task ( p_task ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : progress_add_task_bg ( const String & p_task , const String & p_label , int p_steps ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
singleton - > progress_hb - > add_task ( p_task , p_label , p_steps ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : progress_task_step_bg ( const String & p_task , int p_step ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
singleton - > progress_hb - > task_step ( p_task , p_step ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : progress_end_task_bg ( const String & p_task ) {
2014-02-10 02:10:30 +01:00
singleton - > progress_hb - > end_task ( p_task ) ;
}
2017-03-05 16:44:50 +01:00
Ref < Texture > EditorNode : : _file_dialog_get_icon ( const String & p_path ) {
2014-02-10 02:10:30 +01:00
2017-01-14 15:07:57 +01:00
EditorFileSystemDirectory * efsd = EditorFileSystem : : get_singleton ( ) - > get_filesystem_path ( p_path . get_base_dir ( ) ) ;
2014-02-10 02:10:30 +01:00
if ( efsd ) {
String file = p_path . get_file ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < efsd - > get_file_count ( ) ; i + + ) {
if ( efsd - > get_file ( i ) = = file ) {
2014-02-10 02:10:30 +01:00
String type = efsd - > get_file_type ( i ) ;
if ( singleton - > icon_type_cache . has ( type ) ) {
return singleton - > icon_type_cache [ type ] ;
} else {
return singleton - > icon_type_cache [ " Object " ] ;
}
}
}
}
return singleton - > icon_type_cache [ " Object " ] ;
}
2018-02-25 17:04:16 +01:00
void EditorNode : : _build_icon_type_cache ( ) {
List < StringName > tl ;
StringName ei = " EditorIcons " ;
theme_base - > get_theme ( ) - > get_icon_list ( ei , & tl ) ;
for ( List < StringName > : : Element * E = tl . front ( ) ; E ; E = E - > next ( ) ) {
if ( ! ClassDB : : class_exists ( E - > get ( ) ) )
continue ;
icon_type_cache [ E - > get ( ) ] = theme_base - > get_theme ( ) - > get_icon ( E - > get ( ) , ei ) ;
}
}
2014-02-10 02:10:30 +01:00
void EditorNode : : _file_dialog_register ( FileDialog * p_dialog ) {
singleton - > file_dialogs . insert ( p_dialog ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _file_dialog_unregister ( FileDialog * p_dialog ) {
2014-02-10 02:10:30 +01:00
singleton - > file_dialogs . erase ( p_dialog ) ;
}
2015-05-31 06:59:42 +02:00
void EditorNode : : _editor_file_dialog_register ( EditorFileDialog * p_dialog ) {
singleton - > editor_file_dialogs . insert ( p_dialog ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _editor_file_dialog_unregister ( EditorFileDialog * p_dialog ) {
2015-05-31 06:59:42 +02:00
singleton - > editor_file_dialogs . erase ( p_dialog ) ;
}
2014-02-25 13:31:47 +01:00
Vector < EditorNodeInitCallback > EditorNode : : _init_callbacks ;
2014-02-10 02:10:30 +01:00
2017-09-14 19:49:11 +02:00
Error EditorNode : : export_preset ( const String & p_preset , const String & p_path , bool p_debug , const String & p_password , bool p_quit_after ) {
2014-02-10 02:10:30 +01:00
2017-09-14 19:49:11 +02:00
export_defer . preset = p_preset ;
2017-03-05 16:44:50 +01:00
export_defer . path = p_path ;
export_defer . debug = p_debug ;
export_defer . password = p_password ;
2014-02-10 02:10:30 +01:00
return OK ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : show_warning ( const String & p_text , const String & p_title ) {
2015-02-14 16:09:52 +01:00
warning - > set_text ( p_text ) ;
2016-03-12 14:44:12 +01:00
warning - > set_title ( p_title ) ;
2015-02-14 16:09:52 +01:00
warning - > popup_centered_minsize ( ) ;
}
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
void EditorNode : : _dock_select_input ( const Ref < InputEvent > & p_input ) {
2015-06-14 03:12:53 +02:00
2017-05-20 17:38:03 +02:00
Ref < InputEventMouse > me = p_input ;
2015-06-14 03:12:53 +02:00
2017-05-20 17:38:03 +02:00
if ( me . is_valid ( ) ) {
2017-06-03 10:54:24 +02:00
Vector2 point = me - > get_position ( ) ;
2015-06-14 03:12:53 +02:00
int nrect = - 1 ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2015-06-14 03:12:53 +02:00
if ( dock_select_rect [ i ] . has_point ( point ) ) {
2017-03-05 16:44:50 +01:00
nrect = i ;
2015-06-14 03:12:53 +02:00
break ;
}
}
2015-06-14 05:41:08 +02:00
2017-03-05 16:44:50 +01:00
if ( nrect ! = dock_select_rect_over ) {
2015-06-14 03:12:53 +02:00
dock_select - > update ( ) ;
2017-03-05 16:44:50 +01:00
dock_select_rect_over = nrect ;
2015-06-14 03:12:53 +02:00
}
2017-03-05 16:44:50 +01:00
if ( nrect = = - 1 )
2015-06-14 05:41:08 +02:00
return ;
2017-05-20 17:38:03 +02:00
Ref < InputEventMouseButton > mb = me ;
if ( mb . is_valid ( ) & & mb - > get_button_index ( ) = = 1 & & mb - > is_pressed ( ) & & dock_popup_selected ! = nrect ) {
2015-06-14 03:12:53 +02:00
Control * dock = dock_slot [ dock_popup_selected ] - > get_current_tab_control ( ) ;
if ( dock ) {
dock_slot [ dock_popup_selected ] - > remove_child ( dock ) ;
}
2017-03-05 16:44:50 +01:00
if ( dock_slot [ dock_popup_selected ] - > get_tab_count ( ) = = 0 ) {
2015-06-14 03:12:53 +02:00
dock_slot [ dock_popup_selected ] - > hide ( ) ;
2017-03-05 16:44:50 +01:00
} else {
2015-06-14 06:09:58 +02:00
dock_slot [ dock_popup_selected ] - > set_current_tab ( 0 ) ;
2015-06-14 03:12:53 +02:00
}
2015-06-14 06:09:58 +02:00
2015-06-14 03:12:53 +02:00
dock_slot [ nrect ] - > add_child ( dock ) ;
2017-03-05 16:44:50 +01:00
dock_popup_selected = nrect ;
dock_slot [ nrect ] - > set_current_tab ( dock_slot [ nrect ] - > get_tab_count ( ) - 1 ) ;
2015-06-14 03:12:53 +02:00
dock_slot [ nrect ] - > show ( ) ;
dock_select - > update ( ) ;
2017-03-05 16:44:50 +01:00
VSplitContainer * splits [ DOCK_SLOT_MAX / 2 ] = {
2015-06-14 03:12:53 +02:00
left_l_vsplit ,
left_r_vsplit ,
right_l_vsplit ,
right_r_vsplit ,
} ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < 4 ; i + + ) {
bool in_use = dock_slot [ i * 2 + 0 ] - > get_tab_count ( ) | | dock_slot [ i * 2 + 1 ] - > get_tab_count ( ) ;
2015-06-14 03:12:53 +02:00
if ( in_use )
splits [ i ] - > show ( ) ;
else
splits [ i ] - > hide ( ) ;
}
2017-12-22 19:49:14 +01:00
if ( right_l_vsplit - > is_visible ( ) | | right_r_vsplit - > is_visible ( ) )
right_hsplit - > show ( ) ;
else
right_hsplit - > hide ( ) ;
2017-08-19 00:51:17 +02:00
_edit_current ( ) ;
2015-06-14 03:12:53 +02:00
_save_docks ( ) ;
}
}
}
2015-06-14 05:41:08 +02:00
void EditorNode : : _dock_popup_exit ( ) {
2017-03-05 16:44:50 +01:00
dock_select_rect_over = - 1 ;
2015-06-14 05:41:08 +02:00
dock_select - > update ( ) ;
}
2015-06-14 03:12:53 +02:00
void EditorNode : : _dock_pre_popup ( int p_which ) {
2016-03-09 00:00:52 +01:00
2017-03-05 16:44:50 +01:00
dock_popup_selected = p_which ;
2015-06-14 03:12:53 +02:00
}
2015-06-14 05:41:08 +02:00
void EditorNode : : _dock_move_left ( ) {
2017-03-05 16:44:50 +01:00
if ( dock_popup_selected < 0 | | dock_popup_selected > = DOCK_SLOT_MAX )
2015-06-14 05:41:08 +02:00
return ;
2017-03-05 16:44:50 +01:00
Control * current = dock_slot [ dock_popup_selected ] - > get_tab_control ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) ) ;
Control * prev = dock_slot [ dock_popup_selected ] - > get_tab_control ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) - 1 ) ;
2015-06-14 05:41:08 +02:00
if ( ! current | | ! prev )
return ;
2017-03-05 16:44:50 +01:00
dock_slot [ dock_popup_selected ] - > move_child ( current , prev - > get_index ( ) ) ;
dock_slot [ dock_popup_selected ] - > set_current_tab ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) - 1 ) ;
2015-06-14 05:41:08 +02:00
dock_select - > update ( ) ;
2017-08-19 00:51:17 +02:00
_edit_current ( ) ;
2015-06-14 05:41:08 +02:00
_save_docks ( ) ;
}
void EditorNode : : _dock_move_right ( ) {
2017-03-05 16:44:50 +01:00
Control * current = dock_slot [ dock_popup_selected ] - > get_tab_control ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) ) ;
Control * next = dock_slot [ dock_popup_selected ] - > get_tab_control ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) + 1 ) ;
2015-06-14 05:41:08 +02:00
if ( ! current | | ! next )
return ;
2017-03-05 16:44:50 +01:00
dock_slot [ dock_popup_selected ] - > move_child ( next , current - > get_index ( ) ) ;
dock_slot [ dock_popup_selected ] - > set_current_tab ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) + 1 ) ;
2015-06-14 05:41:08 +02:00
dock_select - > update ( ) ;
2017-08-19 00:51:17 +02:00
_edit_current ( ) ;
2015-06-14 05:41:08 +02:00
_save_docks ( ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _dock_select_draw ( ) {
2015-06-14 03:12:53 +02:00
Size2 s = dock_select - > get_size ( ) ;
2017-03-05 16:44:50 +01:00
s . y / = 2.0 ;
s . x / = 6.0 ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
Color used = Color ( 0.6 , 0.6 , 0.6 , 0.8 ) ;
Color used_selected = Color ( 0.8 , 0.8 , 0.8 , 0.8 ) ;
2017-09-26 04:43:20 +02:00
Color tab_selected = theme_base - > get_color ( " mono_color " , " Editor " ) ;
2017-03-05 16:44:50 +01:00
Color unused = used ;
unused . a = 0.4 ;
Color unusable = unused ;
unusable . a = 0.1 ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
Rect2 unr ( s . x * 2 , 0 , s . x * 2 , s . y * 2 ) ;
2017-06-04 00:25:13 +02:00
unr . position + = Vector2 ( 2 , 5 ) ;
2017-03-05 16:44:50 +01:00
unr . size - = Vector2 ( 4 , 7 ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
dock_select - > draw_rect ( unr , unusable ) ;
2015-06-14 03:12:53 +02:00
dock_tab_move_left - > set_disabled ( true ) ;
dock_tab_move_right - > set_disabled ( true ) ;
2017-03-05 16:44:50 +01:00
if ( dock_popup_selected ! = - 1 & & dock_slot [ dock_popup_selected ] - > get_tab_count ( ) ) {
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
dock_tab_move_left - > set_disabled ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) = = 0 ) ;
dock_tab_move_right - > set_disabled ( dock_slot [ dock_popup_selected ] - > get_current_tab ( ) > = dock_slot [ dock_popup_selected ] - > get_tab_count ( ) - 1 ) ;
2015-06-14 03:12:53 +02:00
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2015-06-14 03:12:53 +02:00
Vector2 ofs ;
2017-03-05 16:44:50 +01:00
switch ( i ) {
2015-06-14 03:12:53 +02:00
case DOCK_SLOT_LEFT_UL : {
} break ;
case DOCK_SLOT_LEFT_BL : {
2017-03-05 16:44:50 +01:00
ofs . y + = s . y ;
2015-06-14 03:12:53 +02:00
} break ;
case DOCK_SLOT_LEFT_UR : {
2017-03-05 16:44:50 +01:00
ofs . x + = s . x ;
2015-06-14 03:12:53 +02:00
} break ;
case DOCK_SLOT_LEFT_BR : {
2017-03-05 16:44:50 +01:00
ofs + = s ;
2015-06-14 03:12:53 +02:00
} break ;
case DOCK_SLOT_RIGHT_UL : {
2017-03-05 16:44:50 +01:00
ofs . x + = s . x * 4 ;
2015-06-14 03:12:53 +02:00
} break ;
case DOCK_SLOT_RIGHT_BL : {
2017-03-05 16:44:50 +01:00
ofs . x + = s . x * 4 ;
ofs . y + = s . y ;
2015-06-14 03:12:53 +02:00
} break ;
case DOCK_SLOT_RIGHT_UR : {
2017-03-05 16:44:50 +01:00
ofs . x + = s . x * 4 ;
ofs . x + = s . x ;
2015-06-14 03:12:53 +02:00
} break ;
case DOCK_SLOT_RIGHT_BR : {
2017-03-05 16:44:50 +01:00
ofs . x + = s . x * 4 ;
ofs + = s ;
2015-06-14 03:12:53 +02:00
} break ;
}
2017-03-05 16:44:50 +01:00
Rect2 r ( ofs , s ) ;
dock_select_rect [ i ] = r ;
2017-06-04 00:25:13 +02:00
r . position + = Vector2 ( 2 , 5 ) ;
2017-03-05 16:44:50 +01:00
r . size - = Vector2 ( 4 , 7 ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
if ( i = = dock_select_rect_over ) {
dock_select - > draw_rect ( r , used_selected ) ;
} else if ( dock_slot [ i ] - > get_child_count ( ) = = 0 ) {
dock_select - > draw_rect ( r , unused ) ;
2015-06-14 03:12:53 +02:00
} else {
2017-03-05 16:44:50 +01:00
dock_select - > draw_rect ( r , used ) ;
2015-06-14 03:12:53 +02:00
}
2017-03-05 16:44:50 +01:00
for ( int j = 0 ; j < MIN ( 3 , dock_slot [ i ] - > get_child_count ( ) ) ; j + + ) {
int xofs = ( r . size . width / 3 ) * j ;
2015-06-14 03:12:53 +02:00
Color c = used ;
2017-03-05 16:44:50 +01:00
if ( i = = dock_popup_selected & & ( dock_slot [ i ] - > get_current_tab ( ) > 3 | | dock_slot [ i ] - > get_current_tab ( ) = = j ) )
c = tab_selected ;
dock_select - > draw_rect ( Rect2 ( 2 + ofs . x + xofs , ofs . y , r . size . width / 3 - 1 , 3 ) , c ) ;
2015-06-14 03:12:53 +02:00
}
}
}
void EditorNode : : _save_docks ( ) {
Ref < ConfigFile > config ;
config . instance ( ) ;
2015-11-22 19:11:17 +01:00
_save_docks_to_config ( config , " docks " ) ;
2017-11-25 00:32:54 +01:00
_save_open_scenes_to_config ( config , " EditorNode " ) ;
2015-11-22 19:11:17 +01:00
editor_data . get_plugin_window_layout ( config ) ;
2017-11-17 15:50:18 +01:00
config - > save ( EditorSettings : : get_singleton ( ) - > get_project_settings_dir ( ) . plus_file ( " editor_layout.cfg " ) ) ;
2015-11-22 19:11:17 +01:00
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _save_docks_to_config ( Ref < ConfigFile > p_layout , const String & p_section ) {
2015-11-22 19:11:17 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2015-06-14 03:12:53 +02:00
String names ;
2017-03-05 16:44:50 +01:00
for ( int j = 0 ; j < dock_slot [ i ] - > get_tab_count ( ) ; j + + ) {
2015-06-14 03:12:53 +02:00
String name = dock_slot [ i ] - > get_tab_control ( j ) - > get_name ( ) ;
2017-03-05 16:44:50 +01:00
if ( names ! = " " )
names + = " , " ;
names + = name ;
2015-06-14 03:12:53 +02:00
}
2017-03-05 16:44:50 +01:00
if ( names ! = " " ) {
p_layout - > set_value ( p_section , " dock_ " + itos ( i + 1 ) , names ) ;
2015-06-14 03:12:53 +02:00
}
}
2017-03-05 16:44:50 +01:00
p_layout - > set_value ( p_section , " dock_filesystem_split " , filesystem_dock - > get_split_offset ( ) ) ;
2017-01-25 02:46:44 +01:00
2017-03-05 16:44:50 +01:00
VSplitContainer * splits [ DOCK_SLOT_MAX / 2 ] = {
2015-06-14 03:12:53 +02:00
left_l_vsplit ,
left_r_vsplit ,
right_l_vsplit ,
right_r_vsplit ,
} ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + ) {
2015-06-14 03:12:53 +02:00
2017-01-13 14:45:50 +01:00
if ( splits [ i ] - > is_visible_in_tree ( ) ) {
2017-03-05 16:44:50 +01:00
p_layout - > set_value ( p_section , " dock_split_ " + itos ( i + 1 ) , splits [ i ] - > get_split_offset ( ) ) ;
2015-06-14 03:12:53 +02:00
}
}
2017-03-05 16:44:50 +01:00
HSplitContainer * h_splits [ 4 ] = {
2015-06-22 05:03:19 +02:00
left_l_hsplit ,
left_r_hsplit ,
main_hsplit ,
right_hsplit ,
} ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < 4 ; i + + ) {
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
p_layout - > set_value ( p_section , " dock_hsplit_ " + itos ( i + 1 ) , h_splits [ i ] - > get_split_offset ( ) ) ;
2015-06-22 05:03:19 +02:00
}
2015-06-14 03:12:53 +02:00
}
2017-11-25 00:32:54 +01:00
void EditorNode : : _save_open_scenes_to_config ( Ref < ConfigFile > p_layout , const String & p_section ) {
Array scenes ;
for ( int i = 0 ; i < editor_data . get_edited_scene_count ( ) ; i + + ) {
String path = editor_data . get_scene_path ( i ) ;
if ( path = = " " ) {
continue ;
}
scenes . push_back ( path ) ;
}
p_layout - > set_value ( p_section , " open_scenes " , scenes ) ;
}
2015-06-22 05:03:19 +02:00
void EditorNode : : save_layout ( ) {
dock_drag_timer - > start ( ) ;
}
2015-06-14 03:12:53 +02:00
void EditorNode : : _dock_split_dragged ( int ofs ) {
dock_drag_timer - > start ( ) ;
}
void EditorNode : : _load_docks ( ) {
Ref < ConfigFile > config ;
config . instance ( ) ;
2017-11-17 15:50:18 +01:00
Error err = config - > load ( EditorSettings : : get_singleton ( ) - > get_project_settings_dir ( ) . plus_file ( " editor_layout.cfg " ) ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
2016-01-11 22:23:45 +01:00
//no config
2017-03-05 16:44:50 +01:00
if ( overridden_default_layout > = 0 ) {
2016-01-11 22:23:45 +01:00
_layout_menu_option ( overridden_default_layout ) ;
}
return ;
2015-06-14 03:12:53 +02:00
}
2015-11-22 19:11:17 +01:00
_load_docks_from_config ( config , " docks " ) ;
2017-11-25 00:32:54 +01:00
_load_open_scenes_from_config ( config , " EditorNode " ) ;
2015-11-22 19:11:17 +01:00
editor_data . set_plugin_window_layout ( config ) ;
}
2016-02-28 03:10:44 +01:00
void EditorNode : : _update_dock_slots_visibility ( ) {
2017-03-05 16:44:50 +01:00
VSplitContainer * splits [ DOCK_SLOT_MAX / 2 ] = {
2016-02-28 03:10:44 +01:00
left_l_vsplit ,
left_r_vsplit ,
right_l_vsplit ,
right_r_vsplit ,
} ;
2016-05-30 20:29:43 +02:00
if ( ! docks_visible ) {
2016-02-28 03:10:44 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2016-02-28 03:10:44 +01:00
dock_slot [ i ] - > hide ( ) ;
2016-05-30 20:29:43 +02:00
}
2016-02-28 03:10:44 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + ) {
2016-05-30 20:29:43 +02:00
splits [ i ] - > hide ( ) ;
}
2016-02-28 03:10:44 +01:00
2016-05-30 20:29:43 +02:00
right_hsplit - > hide ( ) ;
bottom_panel - > hide ( ) ;
} else {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2016-02-28 03:10:44 +01:00
2016-05-30 20:29:43 +02:00
if ( dock_slot [ i ] - > get_tab_count ( ) )
dock_slot [ i ] - > show ( ) ;
else
dock_slot [ i ] - > hide ( ) ;
}
2016-02-28 03:10:44 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + ) {
bool in_use = dock_slot [ i * 2 + 0 ] - > get_tab_count ( ) | | dock_slot [ i * 2 + 1 ] - > get_tab_count ( ) ;
2016-05-30 20:29:43 +02:00
if ( in_use )
splits [ i ] - > show ( ) ;
else
splits [ i ] - > hide ( ) ;
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2016-05-30 20:29:43 +02:00
2017-01-13 14:45:50 +01:00
if ( dock_slot [ i ] - > is_visible ( ) & & dock_slot [ i ] - > get_tab_count ( ) ) {
2016-05-30 20:29:43 +02:00
dock_slot [ i ] - > set_current_tab ( 0 ) ;
}
2016-02-28 03:10:44 +01:00
}
2016-05-30 20:29:43 +02:00
bottom_panel - > show ( ) ;
2017-12-22 19:49:14 +01:00
if ( right_l_vsplit - > is_visible ( ) | | right_r_vsplit - > is_visible ( ) )
right_hsplit - > show ( ) ;
else
right_hsplit - > hide ( ) ;
2016-02-28 03:10:44 +01:00
}
}
2018-02-07 14:01:45 +01:00
void EditorNode : : _dock_tab_changed ( int p_tab ) {
// update visibility but dont set current tab
VSplitContainer * splits [ DOCK_SLOT_MAX / 2 ] = {
left_l_vsplit ,
left_r_vsplit ,
right_l_vsplit ,
right_r_vsplit ,
} ;
if ( ! docks_visible ) {
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
dock_slot [ i ] - > hide ( ) ;
}
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + ) {
splits [ i ] - > hide ( ) ;
}
right_hsplit - > hide ( ) ;
bottom_panel - > hide ( ) ;
} else {
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
if ( dock_slot [ i ] - > get_tab_count ( ) )
dock_slot [ i ] - > show ( ) ;
else
dock_slot [ i ] - > hide ( ) ;
}
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + ) {
bool in_use = dock_slot [ i * 2 + 0 ] - > get_tab_count ( ) | | dock_slot [ i * 2 + 1 ] - > get_tab_count ( ) ;
if ( in_use )
splits [ i ] - > show ( ) ;
else
splits [ i ] - > hide ( ) ;
}
bottom_panel - > show ( ) ;
if ( right_l_vsplit - > is_visible ( ) | | right_r_vsplit - > is_visible ( ) )
right_hsplit - > show ( ) ;
else
right_hsplit - > hide ( ) ;
}
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _load_docks_from_config ( Ref < ConfigFile > p_layout , const String & p_section ) {
2015-11-22 19:11:17 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
if ( ! p_layout - > has_section_key ( p_section , " dock_ " + itos ( i + 1 ) ) )
2015-06-14 03:12:53 +02:00
continue ;
2017-03-05 16:44:50 +01:00
Vector < String > names = String ( p_layout - > get_value ( p_section , " dock_ " + itos ( i + 1 ) ) ) . split ( " , " ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
for ( int j = 0 ; j < names . size ( ) ; j + + ) {
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
String name = names [ j ] ;
2015-06-14 03:12:53 +02:00
//find it, in a horribly inefficient way
2017-03-05 16:44:50 +01:00
int atidx = - 1 ;
Control * node = NULL ;
for ( int k = 0 ; k < DOCK_SLOT_MAX ; k + + ) {
2015-06-14 03:12:53 +02:00
if ( ! dock_slot [ k ] - > has_node ( name ) )
continue ;
2017-08-24 22:58:51 +02:00
node = Object : : cast_to < Control > ( dock_slot [ k ] - > get_node ( name ) ) ;
2015-06-14 03:12:53 +02:00
if ( ! node )
continue ;
2017-03-05 16:44:50 +01:00
atidx = k ;
2015-06-14 03:12:53 +02:00
break ;
}
2017-03-05 16:44:50 +01:00
if ( atidx = = - 1 ) //well, it's not anywhere
2015-06-14 03:12:53 +02:00
continue ;
2017-03-05 16:44:50 +01:00
if ( atidx = = i ) {
2015-06-14 03:12:53 +02:00
node - > raise ( ) ;
continue ;
}
dock_slot [ atidx ] - > remove_child ( node ) ;
2017-03-05 16:44:50 +01:00
if ( dock_slot [ atidx ] - > get_tab_count ( ) = = 0 ) {
2015-06-14 03:12:53 +02:00
dock_slot [ atidx ] - > hide ( ) ;
}
dock_slot [ i ] - > add_child ( node ) ;
dock_slot [ i ] - > show ( ) ;
}
}
2017-01-25 02:46:44 +01:00
int fs_split_ofs = 0 ;
2017-03-05 16:44:50 +01:00
if ( p_layout - > has_section_key ( p_section , " dock_filesystem_split " ) ) {
fs_split_ofs = p_layout - > get_value ( p_section , " dock_filesystem_split " ) ;
2017-01-25 02:46:44 +01:00
}
filesystem_dock - > set_split_offset ( fs_split_ofs ) ;
2017-03-05 16:44:50 +01:00
VSplitContainer * splits [ DOCK_SLOT_MAX / 2 ] = {
2015-06-14 03:12:53 +02:00
left_l_vsplit ,
left_r_vsplit ,
right_l_vsplit ,
right_r_vsplit ,
} ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + ) {
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
if ( ! p_layout - > has_section_key ( p_section , " dock_split_ " + itos ( i + 1 ) ) )
2015-06-14 03:12:53 +02:00
continue ;
2017-03-05 16:44:50 +01:00
int ofs = p_layout - > get_value ( p_section , " dock_split_ " + itos ( i + 1 ) ) ;
2015-06-14 03:12:53 +02:00
splits [ i ] - > set_split_offset ( ofs ) ;
}
2017-03-05 16:44:50 +01:00
HSplitContainer * h_splits [ 4 ] = {
2015-06-22 05:03:19 +02:00
left_l_hsplit ,
left_r_hsplit ,
main_hsplit ,
right_hsplit ,
} ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < 4 ; i + + ) {
if ( ! p_layout - > has_section_key ( p_section , " dock_hsplit_ " + itos ( i + 1 ) ) )
2015-06-22 05:03:19 +02:00
continue ;
2017-03-05 16:44:50 +01:00
int ofs = p_layout - > get_value ( p_section , " dock_hsplit_ " + itos ( i + 1 ) ) ;
2015-06-22 05:03:19 +02:00
h_splits [ i ] - > set_split_offset ( ofs ) ;
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + ) {
bool in_use = dock_slot [ i * 2 + 0 ] - > get_tab_count ( ) | | dock_slot [ i * 2 + 1 ] - > get_tab_count ( ) ;
2015-06-14 03:12:53 +02:00
if ( in_use )
splits [ i ] - > show ( ) ;
else
splits [ i ] - > hide ( ) ;
}
2015-06-14 05:41:08 +02:00
2017-12-22 19:49:14 +01:00
if ( right_l_vsplit - > is_visible ( ) | | right_r_vsplit - > is_visible ( ) )
right_hsplit - > show ( ) ;
else
right_hsplit - > hide ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
2015-06-14 05:41:08 +02:00
2017-01-13 14:45:50 +01:00
if ( dock_slot [ i ] - > is_visible ( ) & & dock_slot [ i ] - > get_tab_count ( ) ) {
2015-06-14 05:41:08 +02:00
dock_slot [ i ] - > set_current_tab ( 0 ) ;
}
}
2015-11-22 19:11:17 +01:00
}
2015-06-14 05:41:08 +02:00
2017-11-25 00:32:54 +01:00
void EditorNode : : _load_open_scenes_from_config ( Ref < ConfigFile > p_layout , const String & p_section ) {
if ( ! bool ( EDITOR_DEF ( " interface/scene_tabs/restore_scenes_on_load " , false ) ) ) {
return ;
}
if ( ! p_layout - > has_section ( p_section ) | | ! p_layout - > has_section_key ( p_section , " open_scenes " ) ) {
return ;
}
restoring_scenes = true ;
Array scenes = p_layout - > get_value ( p_section , " open_scenes " ) ;
for ( int i = 0 ; i < scenes . size ( ) ; i + + ) {
load_scene ( scenes [ i ] ) ;
}
restoring_scenes = false ;
}
2015-11-22 19:11:17 +01:00
void EditorNode : : _update_layouts_menu ( ) {
editor_layouts - > clear ( ) ;
2017-03-05 16:44:50 +01:00
overridden_default_layout = - 1 ;
2016-01-11 22:23:45 +01:00
2015-11-22 19:11:17 +01:00
editor_layouts - > set_size ( Vector2 ( ) ) ;
2017-03-05 16:44:50 +01:00
editor_layouts - > add_shortcut ( ED_SHORTCUT ( " layout/save " , TTR ( " Save Layout " ) ) , SETTINGS_LAYOUT_SAVE ) ;
editor_layouts - > add_shortcut ( ED_SHORTCUT ( " layout/delete " , TTR ( " Delete Layout " ) ) , SETTINGS_LAYOUT_DELETE ) ;
2015-11-22 19:11:17 +01:00
editor_layouts - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
editor_layouts - > add_shortcut ( ED_SHORTCUT ( " layout/default " , TTR ( " Default " ) ) , SETTINGS_LAYOUT_DEFAULT ) ;
2015-11-22 19:11:17 +01:00
Ref < ConfigFile > config ;
config . instance ( ) ;
2017-11-17 21:48:24 +01:00
Error err = config - > load ( EditorSettings : : get_singleton ( ) - > get_editor_layouts_config ( ) ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
2015-11-22 19:11:17 +01:00
return ; //no config
}
List < String > layouts ;
config . ptr ( ) - > get_sections ( & layouts ) ;
2017-03-05 16:44:50 +01:00
for ( List < String > : : Element * E = layouts . front ( ) ; E ; E = E - > next ( ) ) {
2015-11-22 19:11:17 +01:00
2017-03-05 16:44:50 +01:00
String layout = E - > get ( ) ;
2015-11-22 19:11:17 +01:00
2017-03-05 16:44:50 +01:00
if ( layout = = TTR ( " Default " ) ) {
2016-01-11 22:23:45 +01:00
editor_layouts - > remove_item ( editor_layouts - > get_item_index ( SETTINGS_LAYOUT_DEFAULT ) ) ;
2017-03-05 16:44:50 +01:00
overridden_default_layout = editor_layouts - > get_item_count ( ) ;
2016-01-11 22:23:45 +01:00
}
editor_layouts - > add_item ( layout ) ;
2015-11-22 19:11:17 +01:00
}
}
void EditorNode : : _layout_menu_option ( int p_id ) {
switch ( p_id ) {
case SETTINGS_LAYOUT_SAVE : {
2017-03-05 16:44:50 +01:00
current_option = p_id ;
2016-05-04 03:25:37 +02:00
layout_dialog - > set_title ( TTR ( " Save Layout " ) ) ;
layout_dialog - > get_ok ( ) - > set_text ( TTR ( " Save " ) ) ;
2015-11-22 19:11:17 +01:00
layout_dialog - > popup_centered ( ) ;
} break ;
case SETTINGS_LAYOUT_DELETE : {
2017-03-05 16:44:50 +01:00
current_option = p_id ;
2016-05-04 03:25:37 +02:00
layout_dialog - > set_title ( TTR ( " Delete Layout " ) ) ;
layout_dialog - > get_ok ( ) - > set_text ( TTR ( " Delete " ) ) ;
2015-11-22 19:11:17 +01:00
layout_dialog - > popup_centered ( ) ;
} break ;
case SETTINGS_LAYOUT_DEFAULT : {
2016-01-11 22:23:45 +01:00
_load_docks_from_config ( default_layout , " docks " ) ;
2015-11-22 19:11:17 +01:00
_save_docks ( ) ;
} break ;
default : {
Ref < ConfigFile > config ;
config . instance ( ) ;
2017-11-17 21:48:24 +01:00
Error err = config - > load ( EditorSettings : : get_singleton ( ) - > get_editor_layouts_config ( ) ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
2015-11-22 19:11:17 +01:00
return ; //no config
}
2015-12-14 16:44:15 +01:00
_load_docks_from_config ( config , editor_layouts - > get_item_text ( p_id ) ) ;
2015-11-22 19:11:17 +01:00
_save_docks ( ) ;
}
}
2015-06-22 05:03:19 +02:00
}
2015-07-26 15:44:10 +02:00
void EditorNode : : _scene_tab_script_edited ( int p_tab ) {
2017-03-05 16:44:50 +01:00
Ref < Script > script = editor_data . get_scene_root_script ( p_tab ) ;
2015-07-26 15:44:10 +02:00
if ( script . is_valid ( ) )
edit_resource ( script ) ;
}
2015-08-18 20:27:01 +02:00
void EditorNode : : _scene_tab_closed ( int p_tab ) {
2015-11-19 14:15:17 +01:00
current_option = SCENE_TAB_CLOSE ;
tab_closing = p_tab ;
2017-06-26 16:04:53 +02:00
Node * scene = editor_data . get_edited_scene_root ( p_tab ) ;
2017-07-09 20:48:39 +02:00
if ( ! scene ) {
_discard_changes ( ) ;
return ;
}
2016-05-02 13:40:44 +02:00
2017-03-05 16:44:50 +01:00
bool unsaved = ( p_tab = = editor_data . get_edited_scene ( ) ) ?
saved_version ! = editor_data . get_undo_redo ( ) . get_version ( ) :
editor_data . get_scene_version ( p_tab ) ! = 0 ;
2016-05-02 13:40:44 +02:00
if ( unsaved ) {
2017-06-24 12:57:30 +02:00
save_confirmation - > get_ok ( ) - > set_text ( TTR ( " Save & Close " ) ) ;
2017-06-26 16:04:53 +02:00
save_confirmation - > set_text ( vformat ( TTR ( " Save changes to '%s' before closing? " ) , scene - > get_filename ( ) ! = " " ? scene - > get_filename ( ) : " unsaved scene " ) ) ;
2017-06-21 06:15:39 +02:00
save_confirmation - > popup_centered_minsize ( ) ;
2017-03-05 16:44:50 +01:00
} else {
2017-06-21 06:15:39 +02:00
_discard_changes ( ) ;
2015-11-19 14:15:17 +01:00
}
2017-11-25 00:32:54 +01:00
save_layout ( ) ;
2017-11-16 23:57:57 +01:00
_update_scene_tabs ( ) ;
2015-08-18 20:27:01 +02:00
}
2017-06-15 17:30:03 +02:00
void EditorNode : : _scene_tab_hover ( int p_tab ) {
if ( bool ( EDITOR_DEF ( " interface/scene_tabs/show_thumbnail_on_hover " , true ) ) = = false ) {
return ;
}
int current_tab = scene_tabs - > get_current_tab ( ) ;
if ( p_tab = = current_tab | | p_tab < 0 ) {
tab_preview_panel - > hide ( ) ;
} else {
String path = editor_data . get_scene_path ( p_tab ) ;
EditorResourcePreview : : get_singleton ( ) - > queue_resource_preview ( path , this , " _thumbnail_done " , p_tab ) ;
}
}
void EditorNode : : _scene_tab_exit ( ) {
tab_preview_panel - > hide ( ) ;
}
void EditorNode : : _scene_tab_input ( const Ref < InputEvent > & p_input ) {
Ref < InputEventMouseButton > mb = p_input ;
if ( mb . is_valid ( ) ) {
2017-07-01 18:23:16 +02:00
if ( scene_tabs - > get_hovered_tab ( ) > = 0 ) {
if ( mb - > get_button_index ( ) = = BUTTON_MIDDLE & & mb - > is_pressed ( ) ) {
_scene_tab_closed ( scene_tabs - > get_hovered_tab ( ) ) ;
}
} else {
if ( ( mb - > get_button_index ( ) = = BUTTON_LEFT & & mb - > is_doubleclick ( ) ) | | ( mb - > get_button_index ( ) = = BUTTON_MIDDLE & & mb - > is_pressed ( ) ) ) {
_menu_option_confirm ( FILE_NEW_SCENE , true ) ;
}
2017-06-15 17:30:03 +02:00
}
}
}
2017-07-05 15:44:53 +02:00
void EditorNode : : _reposition_active_tab ( int idx_to ) {
editor_data . move_edited_scene_to_index ( idx_to ) ;
_update_scene_tabs ( ) ;
}
2017-06-15 17:30:03 +02:00
void EditorNode : : _thumbnail_done ( const String & p_path , const Ref < Texture > & p_preview , const Variant & p_udata ) {
int p_tab = p_udata . operator signed int ( ) ;
if ( p_preview . is_valid ( ) ) {
Rect2 rect = scene_tabs - > get_tab_rect ( p_tab ) ;
rect . position + = scene_tabs - > get_global_position ( ) ;
tab_preview - > set_texture ( p_preview ) ;
tab_preview_panel - > set_position ( rect . position + Vector2 ( 0 , rect . size . height ) ) ;
tab_preview_panel - > show ( ) ;
}
}
2015-06-22 05:03:19 +02:00
void EditorNode : : _scene_tab_changed ( int p_tab ) {
2017-06-15 17:30:03 +02:00
tab_preview_panel - > hide ( ) ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
bool unsaved = ( saved_version ! = editor_data . get_undo_redo ( ) . get_version ( ) ) ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
if ( p_tab = = editor_data . get_edited_scene ( ) )
2015-06-22 05:03:19 +02:00
return ; //pointless
uint64_t next_scene_version = editor_data . get_scene_version ( p_tab ) ;
2016-05-04 03:25:37 +02:00
editor_data . get_undo_redo ( ) . create_action ( TTR ( " Switch Scene Tab " ) ) ;
2017-03-05 16:44:50 +01:00
editor_data . get_undo_redo ( ) . add_do_method ( this , " set_current_version " , unsaved ? saved_version : 0 ) ;
editor_data . get_undo_redo ( ) . add_do_method ( this , " set_current_scene " , p_tab ) ;
editor_data . get_undo_redo ( ) . add_do_method ( this , " set_current_version " , next_scene_version = = 0 ? editor_data . get_undo_redo ( ) . get_version ( ) + 1 : next_scene_version ) ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
editor_data . get_undo_redo ( ) . add_undo_method ( this , " set_current_version " , next_scene_version ) ;
editor_data . get_undo_redo ( ) . add_undo_method ( this , " set_current_scene " , editor_data . get_edited_scene ( ) ) ;
editor_data . get_undo_redo ( ) . add_undo_method ( this , " set_current_version " , saved_version ) ;
2015-06-22 05:03:19 +02:00
editor_data . get_undo_redo ( ) . commit_action ( ) ;
2015-06-14 03:12:53 +02:00
}
2014-06-19 07:23:03 +02:00
2015-11-21 17:42:15 +01:00
void EditorNode : : _toggle_search_bar ( bool p_pressed ) {
property_editor - > set_use_filter ( p_pressed ) ;
if ( p_pressed ) {
search_bar - > show ( ) ;
search_box - > grab_focus ( ) ;
search_box - > select_all ( ) ;
} else {
search_bar - > hide ( ) ;
}
}
void EditorNode : : _clear_search_box ( ) {
2017-03-05 16:44:50 +01:00
if ( search_box - > get_text ( ) = = " " )
2015-11-21 17:42:15 +01:00
return ;
search_box - > clear ( ) ;
property_editor - > update_tree ( ) ;
}
2017-03-05 16:44:50 +01:00
ToolButton * EditorNode : : add_bottom_panel_item ( String p_text , Control * p_item ) {
2016-01-18 00:03:57 +01:00
2017-03-05 16:44:50 +01:00
ToolButton * tb = memnew ( ToolButton ) ;
tb - > connect ( " toggled " , this , " _bottom_panel_switch " , varray ( bottom_panel_items . size ( ) ) ) ;
2016-01-18 00:03:57 +01:00
tb - > set_text ( p_text ) ;
tb - > set_toggle_mode ( true ) ;
tb - > set_focus_mode ( Control : : FOCUS_NONE ) ;
bottom_panel_vb - > add_child ( p_item ) ;
bottom_panel_hb - > raise ( ) ;
bottom_panel_hb - > add_child ( tb ) ;
p_item - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
p_item - > hide ( ) ;
BottomPanelItem bpi ;
2017-03-05 16:44:50 +01:00
bpi . button = tb ;
bpi . control = p_item ;
bpi . name = p_text ;
2016-01-18 00:03:57 +01:00
bottom_panel_items . push_back ( bpi ) ;
return tb ;
}
2016-01-24 16:26:03 +01:00
bool EditorNode : : are_bottom_panels_hidden ( ) const {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
2016-01-24 16:26:03 +01:00
if ( bottom_panel_items [ i ] . button - > is_pressed ( ) )
return false ;
}
return true ;
}
2016-01-18 00:03:57 +01:00
void EditorNode : : hide_bottom_panel ( ) {
2017-03-05 16:44:50 +01:00
_bottom_panel_switch ( false , 0 ) ;
2016-01-18 00:03:57 +01:00
}
void EditorNode : : make_bottom_panel_item_visible ( Control * p_item ) {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
2016-01-18 00:03:57 +01:00
2017-03-05 16:44:50 +01:00
if ( bottom_panel_items [ i ] . control = = p_item ) {
_bottom_panel_switch ( true , i ) ;
2016-01-18 00:03:57 +01:00
break ;
}
}
}
void EditorNode : : raise_bottom_panel_item ( Control * p_item ) {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
2016-01-18 00:03:57 +01:00
2017-03-05 16:44:50 +01:00
if ( bottom_panel_items [ i ] . control = = p_item ) {
2016-01-18 00:03:57 +01:00
bottom_panel_items [ i ] . button - > raise ( ) ;
2017-03-05 16:44:50 +01:00
SWAP ( bottom_panel_items [ i ] , bottom_panel_items [ bottom_panel_items . size ( ) - 1 ] ) ;
2016-01-18 00:03:57 +01:00
break ;
}
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
bottom_panel_items [ i ] . button - > disconnect ( " toggled " , this , " _bottom_panel_switch " ) ;
bottom_panel_items [ i ] . button - > connect ( " toggled " , this , " _bottom_panel_switch " , varray ( i ) ) ;
2016-01-18 00:03:57 +01:00
}
}
2016-02-28 20:58:17 +01:00
void EditorNode : : remove_bottom_panel_item ( Control * p_item ) {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
2016-02-28 20:58:17 +01:00
2017-03-05 16:44:50 +01:00
if ( bottom_panel_items [ i ] . control = = p_item ) {
2017-01-13 14:45:50 +01:00
if ( p_item - > is_visible_in_tree ( ) ) {
2017-03-05 16:44:50 +01:00
_bottom_panel_switch ( false , 0 ) ;
2016-02-28 20:58:17 +01:00
}
bottom_panel_vb - > remove_child ( bottom_panel_items [ i ] . control ) ;
bottom_panel_hb - > remove_child ( bottom_panel_items [ i ] . button ) ;
2017-03-05 16:44:50 +01:00
memdelete ( bottom_panel_items [ i ] . button ) ;
2016-02-28 20:58:17 +01:00
bottom_panel_items . remove ( i ) ;
break ;
}
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
bottom_panel_items [ i ] . button - > disconnect ( " toggled " , this , " _bottom_panel_switch " ) ;
bottom_panel_items [ i ] . button - > connect ( " toggled " , this , " _bottom_panel_switch " , varray ( i ) ) ;
2016-02-28 20:58:17 +01:00
}
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _bottom_panel_switch ( bool p_enable , int p_idx ) {
2016-01-18 00:03:57 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_idx , bottom_panel_items . size ( ) ) ;
2016-01-18 00:03:57 +01:00
if ( p_enable ) {
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
2016-01-18 00:03:57 +01:00
2017-03-05 16:44:50 +01:00
bottom_panel_items [ i ] . button - > set_pressed ( i = = p_idx ) ;
bottom_panel_items [ i ] . control - > set_visible ( i = = p_idx ) ;
2016-01-18 00:03:57 +01:00
}
2018-01-18 21:37:17 +01:00
if ( ScriptEditor : : get_singleton ( ) - > get_debugger ( ) = = bottom_panel_items [ p_idx ] . control ) { // this is the debug panel which uses tabs, so the top section should be smaller
2017-09-18 21:06:55 +02:00
bottom_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " BottomPanelDebuggerOverride " , " EditorStyles " ) ) ;
} else {
bottom_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " panel " , " TabContainer " ) ) ;
}
2016-01-18 00:03:57 +01:00
center_split - > set_dragger_visibility ( SplitContainer : : DRAGGER_VISIBLE ) ;
center_split - > set_collapsed ( false ) ;
} else {
2017-09-18 01:58:36 +02:00
bottom_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " panel " , " TabContainer " ) ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < bottom_panel_items . size ( ) ; i + + ) {
2016-01-18 00:03:57 +01:00
bottom_panel_items [ i ] . button - > set_pressed ( false ) ;
2017-01-13 14:45:50 +01:00
bottom_panel_items [ i ] . control - > set_visible ( false ) ;
2016-01-18 00:03:57 +01:00
}
center_split - > set_dragger_visibility ( SplitContainer : : DRAGGER_HIDDEN ) ;
center_split - > set_collapsed ( true ) ;
}
}
2016-05-30 20:29:43 +02:00
void EditorNode : : set_docks_visible ( bool p_show ) {
docks_visible = p_show ;
_update_dock_slots_visibility ( ) ;
}
bool EditorNode : : get_docks_visible ( ) const {
return docks_visible ;
}
2016-09-13 14:46:17 +02:00
void EditorNode : : _toggle_distraction_free_mode ( ) {
2017-09-29 18:52:56 +02:00
if ( EditorSettings : : get_singleton ( ) - > get ( " interface/editor/separate_distraction_mode " ) ) {
2017-04-25 13:48:35 +02:00
int screen = - 1 ;
for ( int i = 0 ; i < editor_table . size ( ) ; i + + ) {
if ( editor_plugin_screen = = editor_table [ i ] ) {
screen = i ;
break ;
}
}
if ( screen = = EDITOR_SCRIPT ) {
2017-05-06 10:31:36 +02:00
script_distraction = ! script_distraction ;
2017-04-25 13:48:35 +02:00
set_distraction_free_mode ( script_distraction ) ;
} else {
2017-05-06 10:31:36 +02:00
scene_distraction = ! scene_distraction ;
2017-04-25 13:48:35 +02:00
set_distraction_free_mode ( scene_distraction ) ;
}
} else {
set_distraction_free_mode ( distraction_free - > is_pressed ( ) ) ;
}
2016-09-13 14:46:17 +02:00
}
2016-05-30 20:29:43 +02:00
void EditorNode : : set_distraction_free_mode ( bool p_enter ) {
2016-09-13 14:46:17 +02:00
distraction_free - > set_pressed ( p_enter ) ;
2016-05-30 20:29:43 +02:00
if ( p_enter ) {
if ( docks_visible ) {
set_docks_visible ( false ) ;
}
} else {
set_docks_visible ( true ) ;
}
}
bool EditorNode : : get_distraction_free_mode ( ) const {
2016-09-13 14:46:17 +02:00
return distraction_free - > is_pressed ( ) ;
2016-05-30 20:29:43 +02:00
}
2016-02-28 03:10:44 +01:00
2017-03-05 16:44:50 +01:00
void EditorNode : : add_control_to_dock ( DockSlot p_slot , Control * p_control ) {
ERR_FAIL_INDEX ( p_slot , DOCK_SLOT_MAX ) ;
2016-02-28 03:10:44 +01:00
dock_slot [ p_slot ] - > add_child ( p_control ) ;
_update_dock_slots_visibility ( ) ;
}
2017-03-05 16:44:50 +01:00
void EditorNode : : remove_control_from_dock ( Control * p_control ) {
2016-02-28 03:10:44 +01:00
2017-03-05 16:44:50 +01:00
Control * dock = NULL ;
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
if ( p_control - > get_parent ( ) = = dock_slot [ i ] ) {
dock = dock_slot [ i ] ;
2016-02-28 03:10:44 +01:00
break ;
}
}
ERR_EXPLAIN ( " Control was not in dock " ) ;
ERR_FAIL_COND ( ! dock ) ;
dock - > remove_child ( p_control ) ;
_update_dock_slots_visibility ( ) ;
}
2017-03-05 16:44:50 +01:00
Variant EditorNode : : drag_resource ( const Ref < Resource > & p_res , Control * p_from ) {
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
Control * drag_control = memnew ( Control ) ;
TextureRect * drag_preview = memnew ( TextureRect ) ;
Label * label = memnew ( Label ) ;
2016-05-11 16:46:08 +02:00
Ref < Texture > preview ;
{
//todo make proper previews
2017-09-12 21:32:04 +02:00
Ref < ImageTexture > pic = gui_base - > get_icon ( " FileBigThumb " , " EditorIcons " ) ;
2017-05-17 12:36:47 +02:00
Ref < Image > img = pic - > get_data ( ) ;
img = img - > duplicate ( ) ;
img - > resize ( 48 , 48 ) ; //meh
2017-03-05 16:44:50 +01:00
Ref < ImageTexture > resized_pic = Ref < ImageTexture > ( memnew ( ImageTexture ) ) ;
2016-05-11 16:46:08 +02:00
resized_pic - > create_from_image ( img ) ;
2017-03-05 16:44:50 +01:00
preview = resized_pic ;
2016-05-11 16:46:08 +02:00
}
drag_preview - > set_texture ( preview ) ;
drag_control - > add_child ( drag_preview ) ;
if ( p_res - > get_path ( ) . is_resource_file ( ) ) {
label - > set_text ( p_res - > get_path ( ) . get_file ( ) ) ;
2017-03-05 16:44:50 +01:00
} else if ( p_res - > get_name ( ) ! = " " ) {
2016-05-11 16:46:08 +02:00
label - > set_text ( p_res - > get_name ( ) ) ;
} else {
2017-01-03 03:03:46 +01:00
label - > set_text ( p_res - > get_class ( ) ) ;
2016-05-11 16:46:08 +02:00
}
drag_control - > add_child ( label ) ;
p_from - > set_drag_preview ( drag_control ) ; //wait until it enters scene
2017-03-29 17:29:38 +02:00
label - > set_position ( Point2 ( ( preview - > get_width ( ) - label - > get_minimum_size ( ) . width ) / 2 , preview - > get_height ( ) ) ) ;
2016-05-11 16:46:08 +02:00
Dictionary drag_data ;
2017-03-05 16:44:50 +01:00
drag_data [ " type " ] = " resource " ;
drag_data [ " resource " ] = p_res ;
drag_data [ " from " ] = p_from ;
2016-05-11 16:46:08 +02:00
return drag_data ;
}
2017-10-25 00:09:04 +02:00
Variant EditorNode : : drag_files_and_dirs ( const Vector < String > & p_paths , Control * p_from ) {
bool has_folder = false ;
bool has_file = false ;
for ( int i = 0 ; i < p_paths . size ( ) ; i + + ) {
bool is_folder = p_paths [ i ] . ends_with ( " / " ) ;
has_folder | = is_folder ;
has_file | = ! is_folder ;
}
int max_rows = 6 ;
int num_rows = p_paths . size ( ) > max_rows ? max_rows - 1 : p_paths . size ( ) ; //Don't waste a row to say "1 more file" - list it instead.
VBoxContainer * vbox = memnew ( VBoxContainer ) ;
for ( int i = 0 ; i < num_rows ; i + + ) {
HBoxContainer * hbox = memnew ( HBoxContainer ) ;
TextureRect * icon = memnew ( TextureRect ) ;
2017-03-05 16:44:50 +01:00
Label * label = memnew ( Label ) ;
2016-05-11 16:46:08 +02:00
2017-10-25 00:09:04 +02:00
if ( p_paths [ i ] . ends_with ( " / " ) ) {
label - > set_text ( p_paths [ i ] . substr ( 0 , p_paths [ i ] . length ( ) - 1 ) . get_file ( ) ) ;
icon - > set_texture ( gui_base - > get_icon ( " Folder " , " EditorIcons " ) ) ;
} else {
label - > set_text ( p_paths [ i ] . get_file ( ) ) ;
icon - > set_texture ( gui_base - > get_icon ( " File " , " EditorIcons " ) ) ;
}
icon - > set_size ( Size2 ( 16 , 16 ) ) ;
hbox - > add_child ( icon ) ;
hbox - > add_child ( label ) ;
vbox - > add_child ( hbox ) ;
2016-05-11 16:46:08 +02:00
}
2017-10-25 00:09:04 +02:00
if ( p_paths . size ( ) > num_rows ) {
2017-03-05 16:44:50 +01:00
Label * label = memnew ( Label ) ;
2017-10-25 00:09:04 +02:00
if ( has_file & & has_folder ) {
label - > set_text ( vformat ( TTR ( " %d more files or folders " ) , p_paths . size ( ) - num_rows ) ) ;
} else if ( has_folder ) {
label - > set_text ( vformat ( TTR ( " %d more folders " ) , p_paths . size ( ) - num_rows ) ) ;
} else {
label - > set_text ( vformat ( TTR ( " %d more files " ) , p_paths . size ( ) - num_rows ) ) ;
}
vbox - > add_child ( label ) ;
2016-05-11 16:46:08 +02:00
}
2017-10-25 00:09:04 +02:00
p_from - > set_drag_preview ( vbox ) ; //wait until it enters scene
2016-05-11 16:46:08 +02:00
Dictionary drag_data ;
2017-10-25 00:09:04 +02:00
drag_data [ " type " ] = has_folder ? " files_and_dirs " : " files " ;
drag_data [ " files " ] = p_paths ;
2017-03-05 16:44:50 +01:00
drag_data [ " from " ] = p_from ;
2016-05-11 16:46:08 +02:00
return drag_data ;
}
2018-03-17 02:50:35 +01:00
void EditorNode : : add_tool_menu_item ( const String & p_name , Object * p_handler , const String & p_callback , const Variant & p_ud ) {
ERR_FAIL_NULL ( p_handler ) ;
int idx = tool_menu - > get_item_count ( ) ;
tool_menu - > add_item ( p_name , TOOLS_CUSTOM ) ;
Array parameters ;
parameters . push_back ( p_handler - > get_instance_id ( ) ) ;
parameters . push_back ( p_callback ) ;
parameters . push_back ( p_ud ) ;
tool_menu - > set_item_metadata ( idx , parameters ) ;
}
void EditorNode : : add_tool_submenu_item ( const String & p_name , PopupMenu * p_submenu ) {
ERR_FAIL_NULL ( p_submenu ) ;
ERR_FAIL_COND ( p_submenu - > get_parent ( ) ! = NULL ) ;
tool_menu - > add_child ( p_submenu ) ;
tool_menu - > add_submenu_item ( p_name , p_submenu - > get_name ( ) , TOOLS_CUSTOM ) ;
}
void EditorNode : : remove_tool_menu_item ( const String & p_name ) {
for ( int i = 0 ; i < tool_menu - > get_item_count ( ) ; i + + ) {
if ( tool_menu - > get_item_id ( i ) ! = TOOLS_CUSTOM )
continue ;
if ( tool_menu - > get_item_text ( i ) = = p_name ) {
if ( tool_menu - > get_item_submenu ( i ) ! = " " ) {
Node * n = tool_menu - > get_node ( tool_menu - > get_item_submenu ( i ) ) ;
tool_menu - > remove_child ( n ) ;
memdelete ( n ) ;
}
tool_menu - > remove_item ( i ) ;
tool_menu - > set_as_minsize ( ) ;
return ;
}
}
}
2017-03-05 16:44:50 +01:00
void EditorNode : : _dropped_files ( const Vector < String > & p_files , int p_screen ) {
2016-05-27 19:18:40 +02:00
2017-11-17 21:52:03 +01:00
String to_path = ProjectSettings : : get_singleton ( ) - > globalize_path ( get_filesystem_dock ( ) - > get_current_path ( ) ) ;
DirAccessRef dir = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
2017-12-31 18:35:46 +01:00
Vector < String > just_copy = String ( " ttf,otf " ) . split ( " , " ) ;
2017-11-17 21:52:03 +01:00
for ( int i = 0 ; i < p_files . size ( ) ; i + + ) {
String from = p_files [ i ] ;
2018-01-04 01:00:11 +01:00
if ( ! ResourceFormatImporter : : get_singleton ( ) - > can_be_imported ( from ) & & ( just_copy . find ( from . get_extension ( ) . to_lower ( ) ) ! = - 1 ) ) {
2017-11-17 21:52:03 +01:00
continue ;
}
String to = to_path . plus_file ( from . get_file ( ) ) ;
dir - > copy ( from , to ) ;
2017-08-26 17:46:49 +02:00
}
2017-11-17 21:52:03 +01:00
EditorFileSystem : : get_singleton ( ) - > scan_changes ( ) ;
2016-05-27 19:18:40 +02:00
}
2017-08-26 17:46:49 +02:00
2017-03-05 16:44:50 +01:00
void EditorNode : : _file_access_close_error_notify ( const String & p_str ) {
2016-06-13 15:10:50 +02:00
2017-03-05 16:44:50 +01:00
add_io_error ( " Unable to write to file ' " + p_str + " ', file in use, locked or lacking permissions. " ) ;
2016-06-13 15:10:50 +02:00
}
2016-05-27 19:18:40 +02:00
2017-03-05 16:44:50 +01:00
void EditorNode : : reload_scene ( const String & p_path ) {
2016-06-28 23:53:31 +02:00
2017-08-31 23:57:03 +02:00
//first of all, reload internal textures, materials, meshes, etc. as they might have changed on disk
2016-06-28 23:53:31 +02:00
List < Ref < Resource > > cached ;
ResourceCache : : get_cached_resources ( & cached ) ;
List < Ref < Resource > > to_clear ; //clear internal resources from previous scene from being used
2017-03-05 16:44:50 +01:00
for ( List < Ref < Resource > > : : Element * E = cached . front ( ) ; E ; E = E - > next ( ) ) {
2016-06-28 23:53:31 +02:00
2017-08-31 23:57:03 +02:00
if ( E - > get ( ) - > get_path ( ) . begins_with ( p_path + " :: " ) ) { //subresources of existing scene
2016-06-28 23:53:31 +02:00
to_clear . push_back ( E - > get ( ) ) ;
}
}
//so reload reloads everything, clear subresources of previous scene
2017-03-05 16:44:50 +01:00
while ( to_clear . front ( ) ) {
2016-06-28 23:53:31 +02:00
to_clear . front ( ) - > get ( ) - > set_path ( " " ) ;
to_clear . pop_front ( ) ;
}
2017-03-05 16:44:50 +01:00
int scene_idx = - 1 ;
for ( int i = 0 ; i < editor_data . get_edited_scene_count ( ) ; i + + ) {
2016-06-28 23:53:31 +02:00
2017-03-05 16:44:50 +01:00
if ( editor_data . get_scene_path ( i ) = = p_path ) {
scene_idx = i ;
2016-06-28 23:53:31 +02:00
break ;
}
}
int current_tab = editor_data . get_edited_scene ( ) ;
2017-03-05 16:44:50 +01:00
if ( scene_idx = = - 1 ) {
2016-06-28 23:53:31 +02:00
if ( get_edited_scene ( ) ) {
//scene is not open, so at it might be instanced, just refresh, set tab to itself and it will reload
set_current_scene ( current_tab ) ;
editor_data . get_undo_redo ( ) . clear_history ( ) ;
}
return ;
}
2017-03-05 16:44:50 +01:00
if ( current_tab = = scene_idx ) {
2016-06-28 23:53:31 +02:00
editor_data . apply_changes_in_editors ( ) ;
_set_scene_metadata ( p_path ) ;
}
//remove scene
_remove_scene ( scene_idx ) ;
//reload scene
2017-08-31 23:57:03 +02:00
load_scene ( p_path , true , false , true , true ) ;
2016-06-28 23:53:31 +02:00
//adjust index so tab is back a the previous position
editor_data . move_edited_scene_to_index ( scene_idx ) ;
get_undo_redo ( ) - > clear_history ( ) ;
//recover the tab
scene_tabs - > set_current_tab ( current_tab ) ;
_scene_tab_changed ( current_tab ) ;
}
2017-03-05 16:44:50 +01:00
int EditorNode : : plugin_init_callback_count = 0 ;
2016-08-07 00:00:54 +02:00
void EditorNode : : add_plugin_init_callback ( EditorPluginInitializeCallback p_callback ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_COND ( plugin_init_callback_count = = MAX_INIT_CALLBACKS ) ;
2016-08-07 00:00:54 +02:00
2017-03-05 16:44:50 +01:00
plugin_init_callbacks [ plugin_init_callback_count + + ] = p_callback ;
2016-08-07 00:00:54 +02:00
}
EditorPluginInitializeCallback EditorNode : : plugin_init_callbacks [ EditorNode : : MAX_INIT_CALLBACKS ] ;
2017-03-05 16:44:50 +01:00
int EditorNode : : build_callback_count = 0 ;
2016-09-15 00:37:37 +02:00
void EditorNode : : add_build_callback ( EditorBuildCallback p_callback ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_COND ( build_callback_count = = MAX_INIT_CALLBACKS ) ;
2016-09-15 00:37:37 +02:00
2017-03-05 16:44:50 +01:00
build_callbacks [ build_callback_count + + ] = p_callback ;
2016-09-15 00:37:37 +02:00
}
2017-08-29 23:59:20 +02:00
EditorBuildCallback EditorNode : : build_callbacks [ EditorNode : : MAX_BUILD_CALLBACKS ] ;
2016-09-15 00:37:37 +02:00
2018-02-14 16:23:04 +01:00
bool EditorNode : : call_build ( ) {
2016-09-15 00:44:08 +02:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < build_callback_count ; i + + ) {
2017-08-29 23:59:20 +02:00
if ( ! build_callbacks [ i ] ( ) )
return false ;
2016-09-15 00:44:08 +02:00
}
2017-08-29 23:59:20 +02:00
return true ;
2016-09-15 00:44:08 +02:00
}
2016-09-15 00:37:37 +02:00
2017-03-05 16:44:50 +01:00
void EditorNode : : _inherit_imported ( const String & p_action ) {
2017-02-05 00:31:15 +01:00
open_imported - > hide ( ) ;
2017-03-05 16:44:50 +01:00
load_scene ( open_import_request , true , true ) ;
2017-02-05 00:31:15 +01:00
}
void EditorNode : : _open_imported ( ) {
2017-03-05 16:44:50 +01:00
load_scene ( open_import_request , true , false , true , true ) ;
2017-02-05 00:31:15 +01:00
}
2017-03-06 20:11:56 +01:00
void EditorNode : : dim_editor ( bool p_dimming ) {
static int dim_count = 0 ;
2017-09-29 18:52:56 +02:00
bool dim_ui = EditorSettings : : get_singleton ( ) - > get ( " interface/editor/dim_editor_on_dialog_popup " ) ;
2017-03-06 20:11:56 +01:00
if ( p_dimming ) {
2017-08-15 20:57:05 +02:00
if ( dim_ui ) {
if ( dim_count = = 0 ) {
_start_dimming ( true ) ;
}
dim_count + + ;
}
2017-03-06 20:11:56 +01:00
} else {
2017-08-15 20:57:05 +02:00
if ( dim_count = = 1 ) {
2017-03-06 20:11:56 +01:00
_start_dimming ( false ) ;
2017-08-15 20:57:05 +02:00
dim_count = 0 ;
} else if ( dim_ui & & dim_count > 0 ) {
dim_count - - ;
}
2017-03-06 20:11:56 +01:00
}
}
void EditorNode : : _start_dimming ( bool p_dimming ) {
_dimming = p_dimming ;
_dim_time = 0.0f ;
_dim_timer - > start ( ) ;
}
void EditorNode : : _dim_timeout ( ) {
_dim_time + = _dim_timer - > get_wait_time ( ) ;
2017-09-29 18:52:56 +02:00
float wait_time = EditorSettings : : get_singleton ( ) - > get ( " interface/editor/dim_transition_time " ) ;
2017-03-06 20:11:56 +01:00
2017-09-29 18:52:56 +02:00
float c = 1.0f - ( float ) EditorSettings : : get_singleton ( ) - > get ( " interface/editor/dim_amount " ) ;
2017-03-06 20:11:56 +01:00
Color base = _dimming ? Color ( 1 , 1 , 1 ) : Color ( c , c , c ) ;
Color final = _dimming ? Color ( c , c , c ) : Color ( 1 , 1 , 1 ) ;
if ( _dim_time + _dim_timer - > get_wait_time ( ) > = wait_time ) {
gui_base - > set_modulate ( final ) ;
_dim_timer - > stop ( ) ;
} else {
gui_base - > set_modulate ( base . linear_interpolate ( final , _dim_time / wait_time ) ) ;
}
}
2017-03-21 03:31:41 +01:00
void EditorNode : : open_export_template_manager ( ) {
export_template_manager - > popup_manager ( ) ;
}
2017-09-22 14:20:28 +02:00
void EditorNode : : add_resource_conversion_plugin ( const Ref < EditorResourceConversionPlugin > & p_plugin ) {
resource_conversion_plugins . push_back ( p_plugin ) ;
}
void EditorNode : : remove_resource_conversion_plugin ( const Ref < EditorResourceConversionPlugin > & p_plugin ) {
resource_conversion_plugins . erase ( p_plugin ) ;
}
Vector < Ref < EditorResourceConversionPlugin > > EditorNode : : find_resource_conversion_plugin ( const Ref < Resource > & p_for_resource ) {
Vector < Ref < EditorResourceConversionPlugin > > ret ;
for ( int i = 0 ; i < resource_conversion_plugins . size ( ) ; i + + ) {
if ( resource_conversion_plugins [ i ] . is_valid ( ) & & resource_conversion_plugins [ i ] - > handles ( p_for_resource ) ) {
ret . push_back ( resource_conversion_plugins [ i ] ) ;
}
}
return ret ;
}
2016-01-18 00:03:57 +01:00
void EditorNode : : _bind_methods ( ) {
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( " _menu_option " , & EditorNode : : _menu_option ) ;
2018-03-17 02:50:35 +01:00
ClassDB : : bind_method ( " _tool_menu_option " , & EditorNode : : _tool_menu_option ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( " _menu_confirm_current " , & EditorNode : : _menu_confirm_current ) ;
ClassDB : : bind_method ( " _dialog_action " , & EditorNode : : _dialog_action ) ;
ClassDB : : bind_method ( " _resource_selected " , & EditorNode : : _resource_selected , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( " _property_editor_forward " , & EditorNode : : _property_editor_forward ) ;
ClassDB : : bind_method ( " _property_editor_back " , & EditorNode : : _property_editor_back ) ;
ClassDB : : bind_method ( " _editor_select " , & EditorNode : : _editor_select ) ;
ClassDB : : bind_method ( " _node_renamed " , & EditorNode : : _node_renamed ) ;
ClassDB : : bind_method ( " edit_node " , & EditorNode : : edit_node ) ;
ClassDB : : bind_method ( " _unhandled_input " , & EditorNode : : _unhandled_input ) ;
ClassDB : : bind_method ( " _get_scene_metadata " , & EditorNode : : _get_scene_metadata ) ;
ClassDB : : bind_method ( " set_edited_scene " , & EditorNode : : set_edited_scene ) ;
ClassDB : : bind_method ( " open_request " , & EditorNode : : open_request ) ;
ClassDB : : bind_method ( " _instance_request " , & EditorNode : : _instance_request ) ;
ClassDB : : bind_method ( " update_keying " , & EditorNode : : update_keying ) ;
ClassDB : : bind_method ( " _property_keyed " , & EditorNode : : _property_keyed ) ;
ClassDB : : bind_method ( " _transform_keyed " , & EditorNode : : _transform_keyed ) ;
ClassDB : : bind_method ( " _close_messages " , & EditorNode : : _close_messages ) ;
ClassDB : : bind_method ( " _show_messages " , & EditorNode : : _show_messages ) ;
ClassDB : : bind_method ( " _vp_resized " , & EditorNode : : _vp_resized ) ;
ClassDB : : bind_method ( " _quick_opened " , & EditorNode : : _quick_opened ) ;
ClassDB : : bind_method ( " _quick_run " , & EditorNode : : _quick_run ) ;
ClassDB : : bind_method ( " _resource_created " , & EditorNode : : _resource_created ) ;
ClassDB : : bind_method ( " _open_recent_scene " , & EditorNode : : _open_recent_scene ) ;
ClassDB : : bind_method ( " stop_child_process " , & EditorNode : : stop_child_process ) ;
ClassDB : : bind_method ( " _sources_changed " , & EditorNode : : _sources_changed ) ;
ClassDB : : bind_method ( " _fs_changed " , & EditorNode : : _fs_changed ) ;
ClassDB : : bind_method ( " _dock_select_draw " , & EditorNode : : _dock_select_draw ) ;
ClassDB : : bind_method ( " _dock_select_input " , & EditorNode : : _dock_select_input ) ;
ClassDB : : bind_method ( " _dock_pre_popup " , & EditorNode : : _dock_pre_popup ) ;
ClassDB : : bind_method ( " _dock_split_dragged " , & EditorNode : : _dock_split_dragged ) ;
ClassDB : : bind_method ( " _save_docks " , & EditorNode : : _save_docks ) ;
ClassDB : : bind_method ( " _dock_popup_exit " , & EditorNode : : _dock_popup_exit ) ;
ClassDB : : bind_method ( " _dock_move_left " , & EditorNode : : _dock_move_left ) ;
ClassDB : : bind_method ( " _dock_move_right " , & EditorNode : : _dock_move_right ) ;
2018-02-07 14:01:45 +01:00
ClassDB : : bind_method ( " _dock_tab_changed " , & EditorNode : : _dock_tab_changed ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( " _layout_menu_option " , & EditorNode : : _layout_menu_option ) ;
ClassDB : : bind_method ( " set_current_scene " , & EditorNode : : set_current_scene ) ;
ClassDB : : bind_method ( " set_current_version " , & EditorNode : : set_current_version ) ;
ClassDB : : bind_method ( " _scene_tab_changed " , & EditorNode : : _scene_tab_changed ) ;
ClassDB : : bind_method ( " _scene_tab_closed " , & EditorNode : : _scene_tab_closed ) ;
2017-06-15 17:30:03 +02:00
ClassDB : : bind_method ( " _scene_tab_hover " , & EditorNode : : _scene_tab_hover ) ;
ClassDB : : bind_method ( " _scene_tab_exit " , & EditorNode : : _scene_tab_exit ) ;
ClassDB : : bind_method ( " _scene_tab_input " , & EditorNode : : _scene_tab_input ) ;
2017-07-05 15:44:53 +02:00
ClassDB : : bind_method ( " _reposition_active_tab " , & EditorNode : : _reposition_active_tab ) ;
2017-06-15 17:30:03 +02:00
ClassDB : : bind_method ( " _thumbnail_done " , & EditorNode : : _thumbnail_done ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( " _scene_tab_script_edited " , & EditorNode : : _scene_tab_script_edited ) ;
ClassDB : : bind_method ( " _set_main_scene_state " , & EditorNode : : _set_main_scene_state ) ;
ClassDB : : bind_method ( " _update_scene_tabs " , & EditorNode : : _update_scene_tabs ) ;
2017-06-21 06:15:39 +02:00
ClassDB : : bind_method ( " _discard_changes " , & EditorNode : : _discard_changes ) ;
2017-10-12 04:35:15 +02:00
ClassDB : : bind_method ( " _update_recent_scenes " , & EditorNode : : _update_recent_scenes ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( " _prepare_history " , & EditorNode : : _prepare_history ) ;
ClassDB : : bind_method ( " _select_history " , & EditorNode : : _select_history ) ;
ClassDB : : bind_method ( " _toggle_search_bar " , & EditorNode : : _toggle_search_bar ) ;
ClassDB : : bind_method ( " _clear_search_box " , & EditorNode : : _clear_search_box ) ;
ClassDB : : bind_method ( " _clear_undo_history " , & EditorNode : : _clear_undo_history ) ;
ClassDB : : bind_method ( " _dropped_files " , & EditorNode : : _dropped_files ) ;
ClassDB : : bind_method ( " _toggle_distraction_free_mode " , & EditorNode : : _toggle_distraction_free_mode ) ;
2017-09-14 15:38:59 +02:00
ClassDB : : bind_method ( " _property_editable_warning_pressed " , & EditorNode : : _property_editable_warning_pressed ) ;
2017-02-13 12:47:24 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_gui_base " ) , & EditorNode : : get_gui_base ) ;
ClassDB : : bind_method ( D_METHOD ( " _bottom_panel_switch " ) , & EditorNode : : _bottom_panel_switch ) ;
2016-01-18 00:03:57 +01:00
2017-02-13 12:47:24 +01:00
ClassDB : : bind_method ( D_METHOD ( " _open_imported " ) , & EditorNode : : _open_imported ) ;
ClassDB : : bind_method ( D_METHOD ( " _inherit_imported " ) , & EditorNode : : _inherit_imported ) ;
2017-03-06 20:11:56 +01:00
ClassDB : : bind_method ( D_METHOD ( " _dim_timeout " ) , & EditorNode : : _dim_timeout ) ;
2016-01-18 00:03:57 +01:00
2017-08-31 23:57:03 +02:00
ClassDB : : bind_method ( D_METHOD ( " _resources_reimported " ) , & EditorNode : : _resources_reimported ) ;
2017-03-05 16:44:50 +01:00
ADD_SIGNAL ( MethodInfo ( " play_pressed " ) ) ;
ADD_SIGNAL ( MethodInfo ( " pause_pressed " ) ) ;
ADD_SIGNAL ( MethodInfo ( " stop_pressed " ) ) ;
ADD_SIGNAL ( MethodInfo ( " request_help " ) ) ;
2017-05-16 21:26:32 +02:00
ADD_SIGNAL ( MethodInfo ( " request_help_search " ) ) ;
2017-05-26 16:34:41 +02:00
ADD_SIGNAL ( MethodInfo ( " request_help_index " ) ) ;
2017-03-05 16:44:50 +01:00
ADD_SIGNAL ( MethodInfo ( " script_add_function_request " , PropertyInfo ( Variant : : OBJECT , " obj " ) , PropertyInfo ( Variant : : STRING , " function " ) , PropertyInfo ( Variant : : POOL_STRING_ARRAY , " args " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " resource_saved " , PropertyInfo ( Variant : : OBJECT , " obj " ) ) ) ;
2016-01-18 00:03:57 +01:00
}
2017-03-05 16:44:50 +01:00
static Node * _resource_get_edited_scene ( ) {
2017-01-10 05:04:31 +01:00
return EditorNode : : get_singleton ( ) - > get_edited_scene ( ) ;
}
2017-11-14 23:02:31 +01:00
void EditorNode : : _print_handler ( void * p_this , const String & p_string , bool p_error ) {
EditorNode * en = ( EditorNode * ) p_this ;
en - > log - > add_message ( p_string , p_error ) ;
}
2014-02-10 02:10:30 +01:00
EditorNode : : EditorNode ( ) {
2017-03-05 16:44:50 +01:00
Resource : : _get_local_scene_func = _resource_get_edited_scene ;
2017-01-10 05:04:31 +01:00
2016-12-23 04:37:38 +01:00
VisualServer : : get_singleton ( ) - > textures_keep_original ( true ) ;
2017-06-11 20:52:03 +02:00
VisualServer : : get_singleton ( ) - > set_debug_generate_wireframes ( true ) ;
2016-12-23 04:37:38 +01:00
2014-02-16 01:16:33 +01:00
EditorHelp : : generate_doc ( ) ; //before any editor classes are crated
2015-10-17 00:11:23 +02:00
SceneState : : set_disable_placeholders ( true ) ;
2017-06-28 22:00:18 +02:00
ResourceLoader : : clear_translation_remaps ( ) ; //no remaps using during editor
2017-12-14 19:33:54 +01:00
ResourceLoader : : clear_path_remaps ( ) ;
2016-03-12 14:44:12 +01:00
editor_initialize_certificates ( ) ; //for asset sharing
2014-02-10 02:10:30 +01:00
2017-08-24 22:58:51 +02:00
InputDefault * id = Object : : cast_to < InputDefault > ( Input : : get_singleton ( ) ) ;
2015-09-24 23:06:15 +02:00
if ( id ) {
if ( ! OS : : get_singleton ( ) - > has_touchscreen_ui_hint ( ) & & Input : : get_singleton ( ) ) {
//only if no touchscreen ui hint, set emulation
2018-02-24 03:04:30 +01:00
id - > set_emulate_touch_from_mouse ( false ) ; //just disable just in case
2015-09-24 23:06:15 +02:00
}
id - > set_custom_mouse_cursor ( RES ( ) ) ;
2015-08-29 22:16:11 +02:00
}
2017-03-05 16:44:50 +01:00
singleton = this ;
exiting = false ;
last_checked_version = 0 ;
changing_scene = false ;
_initializing_addons = false ;
2016-05-30 20:29:43 +02:00
docks_visible = true ;
2017-11-25 00:32:54 +01:00
restoring_scenes = false ;
2016-09-13 14:46:17 +02:00
2017-04-25 13:48:35 +02:00
scene_distraction = false ;
script_distraction = false ;
2014-02-10 02:10:30 +01:00
TranslationServer : : get_singleton ( ) - > set_enabled ( false ) ;
// load settings
if ( ! EditorSettings : : get_singleton ( ) )
EditorSettings : : create ( ) ;
2016-09-13 16:20:09 +02:00
2018-01-12 21:18:40 +01:00
FileAccess : : set_backup_save ( EDITOR_GET ( " filesystem/on_save/safe_save_on_backup_then_rename " ) ) ;
2016-06-05 23:43:45 +02:00
{
2018-03-22 20:20:42 +01:00
int display_scale = EditorSettings : : get_singleton ( ) - > get ( " interface/editor/display_scale " ) ;
float custom_display_scale = EditorSettings : : get_singleton ( ) - > get ( " interface/editor/custom_display_scale " ) ;
switch ( display_scale ) {
case 0 : {
// Try applying a suitable display scale automatically
const int screen = OS : : get_singleton ( ) - > get_current_screen ( ) ;
editor_set_scale ( OS : : get_singleton ( ) - > get_screen_dpi ( screen ) > = 192 & & OS : : get_singleton ( ) - > get_screen_size ( screen ) . x > 2000 ? 2.0 : 1.0 ) ;
} break ;
case 1 : {
editor_set_scale ( 0.75 ) ;
} break ;
case 2 : {
editor_set_scale ( 1.0 ) ;
} break ;
case 3 : {
editor_set_scale ( 1.25 ) ;
} break ;
case 4 : {
editor_set_scale ( 1.5 ) ;
} break ;
case 5 : {
editor_set_scale ( 1.75 ) ;
} break ;
case 6 : {
editor_set_scale ( 2.0 ) ;
} break ;
default : {
editor_set_scale ( custom_display_scale ) ;
} break ;
2016-06-05 23:43:45 +02:00
}
}
2014-02-10 02:10:30 +01:00
ResourceLoader : : set_abort_on_missing_resources ( false ) ;
2017-01-05 23:41:36 +01:00
FileDialog : : set_default_show_hidden_files ( EditorSettings : : get_singleton ( ) - > get ( " filesystem/file_dialog/show_hidden_files " ) ) ;
EditorFileDialog : : set_default_show_hidden_files ( EditorSettings : : get_singleton ( ) - > get ( " filesystem/file_dialog/show_hidden_files " ) ) ;
EditorFileDialog : : set_default_display_mode ( ( EditorFileDialog : : DisplayMode ) EditorSettings : : get_singleton ( ) - > get ( " filesystem/file_dialog/display_mode " ) . operator int ( ) ) ;
2017-03-05 16:44:50 +01:00
ResourceLoader : : set_error_notify_func ( this , _load_error_notify ) ;
ResourceLoader : : set_dependency_error_notify_func ( this , _dependency_error_report ) ;
2014-02-10 02:10:30 +01:00
ResourceLoader : : set_timestamp_on_load ( true ) ;
ResourceSaver : : set_timestamp_on_save ( true ) ;
2017-03-24 21:45:31 +01:00
{ //register importers at the beginning, so dialogs are created with the right extensions
2017-02-01 13:45:45 +01:00
Ref < ResourceImporterTexture > import_texture ;
import_texture . instance ( ) ;
ResourceFormatImporter : : get_singleton ( ) - > add_importer ( import_texture ) ;
2017-02-02 00:41:05 +01:00
Ref < ResourceImporterCSVTranslation > import_csv_translation ;
import_csv_translation . instance ( ) ;
ResourceFormatImporter : : get_singleton ( ) - > add_importer ( import_csv_translation ) ;
2017-02-03 02:51:26 +01:00
Ref < ResourceImporterWAV > import_wav ;
import_wav . instance ( ) ;
ResourceFormatImporter : : get_singleton ( ) - > add_importer ( import_wav ) ;
2017-09-30 01:38:27 +02:00
Ref < ResourceImporterOBJ > import_obj ;
import_obj . instance ( ) ;
ResourceFormatImporter : : get_singleton ( ) - > add_importer ( import_obj ) ;
2017-02-04 13:48:04 +01:00
Ref < ResourceImporterScene > import_scene ;
import_scene . instance ( ) ;
ResourceFormatImporter : : get_singleton ( ) - > add_importer ( import_scene ) ;
{
Ref < EditorSceneImporterCollada > import_collada ;
import_collada . instance ( ) ;
import_scene - > add_importer ( import_collada ) ;
2017-07-18 02:05:38 +02:00
Ref < EditorOBJImporter > import_obj ;
import_obj . instance ( ) ;
import_scene - > add_importer ( import_obj ) ;
2017-08-02 20:34:55 +02:00
Ref < EditorSceneImporterGLTF > import_gltf ;
import_gltf . instance ( ) ;
import_scene - > add_importer ( import_gltf ) ;
2018-01-30 15:03:46 +01:00
Ref < EditorSceneImporterESCN > import_escn ;
import_escn . instance ( ) ;
import_scene - > add_importer ( import_escn ) ;
2017-02-04 13:48:04 +01:00
}
2018-01-06 20:36:49 +01:00
Ref < ResourceImporterBitMap > import_bitmap ;
import_bitmap . instance ( ) ;
ResourceFormatImporter : : get_singleton ( ) - > add_importer ( import_bitmap ) ;
2017-02-01 13:45:45 +01:00
}
2014-02-10 02:10:30 +01:00
_pvrtc_register_compressors ( ) ;
2017-03-05 16:44:50 +01:00
editor_selection = memnew ( EditorSelection ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
EditorFileSystem * efs = memnew ( EditorFileSystem ) ;
2014-02-10 02:10:30 +01:00
add_child ( efs ) ;
//used for previews
2017-03-05 16:44:50 +01:00
FileDialog : : get_icon_func = _file_dialog_get_icon ;
FileDialog : : register_func = _file_dialog_register ;
FileDialog : : unregister_func = _file_dialog_unregister ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
EditorFileDialog : : get_icon_func = _file_dialog_get_icon ;
EditorFileDialog : : register_func = _editor_file_dialog_register ;
EditorFileDialog : : unregister_func = _editor_file_dialog_unregister ;
2015-05-31 06:59:42 +02:00
2017-03-05 16:44:50 +01:00
editor_export = memnew ( EditorExport ) ;
2017-02-20 03:19:30 +01:00
add_child ( editor_export ) ;
2014-02-10 02:10:30 +01:00
register_exporters ( ) ;
2017-03-05 16:44:50 +01:00
GLOBAL_DEF ( " editor/main_run_args " , " " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : set_class_enabled ( " CollisionShape " , true ) ;
ClassDB : : set_class_enabled ( " CollisionShape2D " , true ) ;
ClassDB : : set_class_enabled ( " CollisionPolygon2D " , true ) ;
2014-02-10 02:10:30 +01:00
2017-05-02 22:13:12 +02:00
theme_base = memnew ( Control ) ;
2016-06-17 06:13:23 +02:00
add_child ( theme_base ) ;
2017-09-22 00:12:33 +02:00
theme_base - > set_anchors_and_margins_preset ( Control : : PRESET_WIDE ) ;
2016-06-17 06:13:23 +02:00
2017-03-05 16:44:50 +01:00
gui_base = memnew ( Panel ) ;
2016-06-17 06:13:23 +02:00
theme_base - > add_child ( gui_base ) ;
2017-09-22 00:12:33 +02:00
gui_base - > set_anchors_and_margins_preset ( Control : : PRESET_WIDE ) ;
2014-02-10 02:10:30 +01:00
2017-11-11 18:57:54 +01:00
Ref < Theme > theme = create_custom_theme ( ) ;
2017-03-05 16:44:50 +01:00
theme_base - > set_theme ( theme ) ;
2017-11-11 18:57:54 +01:00
gui_base - > set_theme ( theme ) ;
2017-05-02 22:13:12 +02:00
gui_base - > add_style_override ( " panel " , gui_base - > get_stylebox ( " Background " , " EditorStyles " ) ) ;
2016-06-17 06:13:23 +02:00
2017-03-05 16:44:50 +01:00
resource_preview = memnew ( EditorResourcePreview ) ;
2015-05-31 06:59:42 +02:00
add_child ( resource_preview ) ;
2017-03-05 16:44:50 +01:00
progress_dialog = memnew ( ProgressDialog ) ;
2014-02-10 02:10:30 +01:00
gui_base - > add_child ( progress_dialog ) ;
// take up all screen
2017-03-05 16:44:50 +01:00
gui_base - > set_anchor ( MARGIN_RIGHT , Control : : ANCHOR_END ) ;
gui_base - > set_anchor ( MARGIN_BOTTOM , Control : : ANCHOR_END ) ;
gui_base - > set_end ( Point2 ( 0 , 0 ) ) ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
main_vbox = memnew ( VBoxContainer ) ;
2014-02-10 02:10:30 +01:00
gui_base - > add_child ( main_vbox ) ;
2017-09-22 00:12:33 +02:00
main_vbox - > set_anchors_and_margins_preset ( Control : : PRESET_WIDE , Control : : PRESET_MODE_MINSIZE , 8 ) ;
2017-08-19 04:34:09 +02:00
main_vbox - > set_margin ( MARGIN_TOP , 5 * EDSCALE ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
menu_hb = memnew ( HBoxContainer ) ;
2015-11-18 08:47:41 +01:00
main_vbox - > add_child ( menu_hb ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
left_l_hsplit = memnew ( HSplitContainer ) ;
2015-06-14 03:12:53 +02:00
main_vbox - > add_child ( left_l_hsplit ) ;
left_l_hsplit - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2017-03-05 16:44:50 +01:00
left_l_vsplit = memnew ( VSplitContainer ) ;
2015-06-14 03:12:53 +02:00
left_l_hsplit - > add_child ( left_l_vsplit ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_LEFT_UL ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
left_l_vsplit - > add_child ( dock_slot [ DOCK_SLOT_LEFT_UL ] ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_LEFT_BL ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
left_l_vsplit - > add_child ( dock_slot [ DOCK_SLOT_LEFT_BL ] ) ;
left_l_vsplit - > hide ( ) ;
dock_slot [ DOCK_SLOT_LEFT_UL ] - > hide ( ) ;
dock_slot [ DOCK_SLOT_LEFT_BL ] - > hide ( ) ;
2017-03-05 16:44:50 +01:00
left_r_hsplit = memnew ( HSplitContainer ) ;
2015-06-14 03:12:53 +02:00
left_l_hsplit - > add_child ( left_r_hsplit ) ;
2017-03-05 16:44:50 +01:00
left_r_vsplit = memnew ( VSplitContainer ) ;
2015-06-14 03:12:53 +02:00
left_r_hsplit - > add_child ( left_r_vsplit ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_LEFT_UR ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
left_r_vsplit - > add_child ( dock_slot [ DOCK_SLOT_LEFT_UR ] ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_LEFT_BR ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
left_r_vsplit - > add_child ( dock_slot [ DOCK_SLOT_LEFT_BR ] ) ;
2017-03-05 16:44:50 +01:00
main_hsplit = memnew ( HSplitContainer ) ;
2015-06-14 03:12:53 +02:00
left_r_hsplit - > add_child ( main_hsplit ) ;
2017-03-05 16:44:50 +01:00
VBoxContainer * center_vb = memnew ( VBoxContainer ) ;
2015-11-18 08:47:41 +01:00
main_hsplit - > add_child ( center_vb ) ;
center_vb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
center_split = memnew ( VSplitContainer ) ;
2015-11-18 08:47:41 +01:00
center_split - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2015-06-14 03:12:53 +02:00
center_split - > set_collapsed ( false ) ;
2015-11-18 08:47:41 +01:00
center_vb - > add_child ( center_split ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
right_hsplit = memnew ( HSplitContainer ) ;
2015-06-14 03:12:53 +02:00
main_hsplit - > add_child ( right_hsplit ) ;
2017-03-05 16:44:50 +01:00
right_l_vsplit = memnew ( VSplitContainer ) ;
2015-06-14 03:12:53 +02:00
right_hsplit - > add_child ( right_l_vsplit ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_RIGHT_UL ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
right_l_vsplit - > add_child ( dock_slot [ DOCK_SLOT_RIGHT_UL ] ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_RIGHT_BL ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
right_l_vsplit - > add_child ( dock_slot [ DOCK_SLOT_RIGHT_BL ] ) ;
2017-03-05 16:44:50 +01:00
right_r_vsplit = memnew ( VSplitContainer ) ;
2015-06-14 03:12:53 +02:00
right_hsplit - > add_child ( right_r_vsplit ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_RIGHT_UR ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
right_r_vsplit - > add_child ( dock_slot [ DOCK_SLOT_RIGHT_UR ] ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ DOCK_SLOT_RIGHT_BR ] = memnew ( TabContainer ) ;
2015-06-14 03:12:53 +02:00
right_r_vsplit - > add_child ( dock_slot [ DOCK_SLOT_RIGHT_BR ] ) ;
right_r_vsplit - > hide ( ) ;
2015-08-09 21:59:13 +02:00
dock_slot [ DOCK_SLOT_RIGHT_UR ] - > hide ( ) ;
dock_slot [ DOCK_SLOT_RIGHT_BR ] - > hide ( ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
left_l_vsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
left_r_vsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
right_l_vsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
right_r_vsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
left_l_hsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
left_r_hsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
main_hsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
right_hsplit - > connect ( " dragged " , this , " _dock_split_dragged " ) ;
2015-06-22 05:03:19 +02:00
2017-07-18 15:04:20 +02:00
dock_select_popup = memnew ( PopupPanel ) ;
gui_base - > add_child ( dock_select_popup ) ;
2017-03-05 16:44:50 +01:00
VBoxContainer * dock_vb = memnew ( VBoxContainer ) ;
2017-07-18 15:04:20 +02:00
dock_select_popup - > add_child ( dock_vb ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
HBoxContainer * dock_hb = memnew ( HBoxContainer ) ;
dock_tab_move_left = memnew ( ToolButton ) ;
dock_tab_move_left - > set_icon ( theme - > get_icon ( " Back " , " EditorIcons " ) ) ;
2015-06-14 03:12:53 +02:00
dock_tab_move_left - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-03-05 16:44:50 +01:00
dock_tab_move_left - > connect ( " pressed " , this , " _dock_move_left " ) ;
2015-06-14 03:12:53 +02:00
dock_hb - > add_child ( dock_tab_move_left ) ;
2017-11-19 06:00:42 +01:00
Label * dock_label = memnew ( Label ) ;
dock_label - > set_text ( TTR ( " Dock Position " ) ) ;
dock_label - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
dock_hb - > add_child ( dock_label ) ;
2017-03-05 16:44:50 +01:00
dock_tab_move_right = memnew ( ToolButton ) ;
dock_tab_move_right - > set_icon ( theme - > get_icon ( " Forward " , " EditorIcons " ) ) ;
2015-06-14 03:12:53 +02:00
dock_tab_move_right - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-03-05 16:44:50 +01:00
dock_tab_move_right - > connect ( " pressed " , this , " _dock_move_right " ) ;
2015-06-14 05:41:08 +02:00
2015-06-14 03:12:53 +02:00
dock_hb - > add_child ( dock_tab_move_right ) ;
dock_vb - > add_child ( dock_hb ) ;
2017-03-05 16:44:50 +01:00
dock_select = memnew ( Control ) ;
dock_select - > set_custom_minimum_size ( Size2 ( 128 , 64 ) * EDSCALE ) ;
dock_select - > connect ( " gui_input " , this , " _dock_select_input " ) ;
dock_select - > connect ( " draw " , this , " _dock_select_draw " ) ;
dock_select - > connect ( " mouse_exited " , this , " _dock_popup_exit " ) ;
2015-06-14 03:12:53 +02:00
dock_select - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
dock_vb - > add_child ( dock_select ) ;
2017-07-18 15:04:20 +02:00
dock_select_popup - > set_as_minsize ( ) ;
2017-03-05 16:44:50 +01:00
dock_select_rect_over = - 1 ;
dock_popup_selected = - 1 ;
for ( int i = 0 ; i < DOCK_SLOT_MAX ; i + + ) {
dock_slot [ i ] - > set_custom_minimum_size ( Size2 ( 230 , 220 ) * EDSCALE ) ;
2015-06-14 03:12:53 +02:00
dock_slot [ i ] - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2017-07-18 15:04:20 +02:00
dock_slot [ i ] - > set_popup ( dock_select_popup ) ;
2017-03-05 16:44:50 +01:00
dock_slot [ i ] - > connect ( " pre_popup_pressed " , this , " _dock_pre_popup " , varray ( i ) ) ;
2017-05-02 22:13:12 +02:00
dock_slot [ i ] - > set_tab_align ( TabContainer : : ALIGN_LEFT ) ;
2018-02-07 14:01:45 +01:00
dock_slot [ i ] - > set_drag_to_rearrange_enabled ( true ) ;
dock_slot [ i ] - > set_tabs_rearrange_group ( 1 ) ;
dock_slot [ i ] - > connect ( " tab_changed " , this , " _dock_tab_changed " ) ;
2015-06-14 03:12:53 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
dock_drag_timer = memnew ( Timer ) ;
2015-06-14 03:12:53 +02:00
add_child ( dock_drag_timer ) ;
dock_drag_timer - > set_wait_time ( 0.5 ) ;
dock_drag_timer - > set_one_shot ( true ) ;
2017-03-05 16:44:50 +01:00
dock_drag_timer - > connect ( " timeout " , this , " _save_docks " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
top_split = memnew ( VSplitContainer ) ;
2015-06-14 03:12:53 +02:00
center_split - > add_child ( top_split ) ;
2014-02-10 02:10:30 +01:00
top_split - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
top_split - > set_collapsed ( true ) ;
2017-03-05 16:44:50 +01:00
VBoxContainer * srt = memnew ( VBoxContainer ) ;
2014-02-10 02:10:30 +01:00
srt - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
top_split - > add_child ( srt ) ;
2017-03-05 16:44:50 +01:00
srt - > add_constant_override ( " separation " , 0 ) ;
2014-02-10 02:10:30 +01:00
2017-06-15 17:30:03 +02:00
tab_preview_panel = memnew ( Panel ) ;
tab_preview_panel - > set_size ( Size2 ( 100 , 100 ) * EDSCALE ) ;
tab_preview_panel - > hide ( ) ;
tab_preview_panel - > set_self_modulate ( Color ( 1 , 1 , 1 , 0.7 ) ) ;
gui_base - > add_child ( tab_preview_panel ) ;
tab_preview = memnew ( TextureRect ) ;
tab_preview - > set_stretch_mode ( TextureRect : : STRETCH_KEEP_ASPECT_CENTERED ) ;
tab_preview - > set_size ( Size2 ( 96 , 96 ) * EDSCALE ) ;
tab_preview - > set_position ( Point2 ( 2 , 2 ) * EDSCALE ) ;
tab_preview_panel - > add_child ( tab_preview ) ;
2017-03-05 16:44:50 +01:00
scene_tabs = memnew ( Tabs ) ;
2017-06-15 17:30:03 +02:00
scene_tabs - > add_style_override ( " tab_fg " , gui_base - > get_stylebox ( " SceneTabFG " , " EditorStyles " ) ) ;
scene_tabs - > add_style_override ( " tab_bg " , gui_base - > get_stylebox ( " SceneTabBG " , " EditorStyles " ) ) ;
2015-11-18 08:47:41 +01:00
scene_tabs - > add_tab ( " unsaved " ) ;
2017-01-23 05:40:43 +01:00
scene_tabs - > set_tab_align ( Tabs : : ALIGN_LEFT ) ;
2017-12-20 19:41:02 +01:00
scene_tabs - > set_tab_close_display_policy ( ( bool ( EDITOR_DEF ( " interface/scene_tabs/always_show_close_button " , false ) ) ? Tabs : : CLOSE_BUTTON_SHOW_ALWAYS : Tabs : : CLOSE_BUTTON_SHOW_ACTIVE_ONLY ) ) ;
2017-06-15 17:30:03 +02:00
scene_tabs - > set_min_width ( int ( EDITOR_DEF ( " interface/scene_tabs/minimum_width " , 50 ) ) * EDSCALE ) ;
2018-02-07 14:01:45 +01:00
scene_tabs - > set_drag_to_rearrange_enabled ( true ) ;
2017-03-05 16:44:50 +01:00
scene_tabs - > connect ( " tab_changed " , this , " _scene_tab_changed " ) ;
scene_tabs - > connect ( " right_button_pressed " , this , " _scene_tab_script_edited " ) ;
2015-11-18 08:47:41 +01:00
scene_tabs - > connect ( " tab_close " , this , " _scene_tab_closed " ) ;
2017-06-15 17:30:03 +02:00
scene_tabs - > connect ( " tab_hover " , this , " _scene_tab_hover " ) ;
scene_tabs - > connect ( " mouse_exited " , this , " _scene_tab_exit " ) ;
scene_tabs - > connect ( " gui_input " , this , " _scene_tab_input " ) ;
2017-07-05 15:44:53 +02:00
scene_tabs - > connect ( " reposition_active_tab_request " , this , " _reposition_active_tab " ) ;
2017-11-16 23:57:57 +01:00
scene_tabs - > connect ( " resized " , this , " _update_scene_tabs " ) ;
2015-11-18 08:47:41 +01:00
2017-11-16 23:57:57 +01:00
tabbar_container = memnew ( HBoxContainer ) ;
2017-05-24 12:00:55 +02:00
scene_tabs - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
srt - > add_child ( tabbar_container ) ;
tabbar_container - > add_child ( scene_tabs ) ;
distraction_free = memnew ( ToolButton ) ;
distraction_free - > set_shortcut ( ED_SHORTCUT ( " editor/distraction_free_mode " , TTR ( " Distraction Free Mode " ) , KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F11 ) ) ;
2017-07-24 08:07:53 +02:00
distraction_free - > set_tooltip ( TTR ( " Toggle distraction-free mode. " ) ) ;
2017-05-24 12:00:55 +02:00
distraction_free - > connect ( " pressed " , this , " _toggle_distraction_free_mode " ) ;
distraction_free - > set_icon ( gui_base - > get_icon ( " DistractionFree " , " EditorIcons " ) ) ;
distraction_free - > set_toggle_mode ( true ) ;
2014-02-10 02:10:30 +01:00
2017-11-16 23:57:57 +01:00
scene_tab_add = memnew ( ToolButton ) ;
tabbar_container - > add_child ( scene_tab_add ) ;
tabbar_container - > add_child ( distraction_free ) ;
scene_tab_add - > set_tooltip ( TTR ( " Add a new scene. " ) ) ;
scene_tab_add - > set_icon ( gui_base - > get_icon ( " Add " , " EditorIcons " ) ) ;
scene_tab_add - > add_color_override ( " icon_color_normal " , Color ( 0.6f , 0.6f , 0.6f , 0.8f ) ) ;
scene_tab_add - > connect ( " pressed " , this , " _menu_option " , make_binds ( FILE_NEW_SCENE ) ) ;
2017-03-05 16:44:50 +01:00
scene_root_parent = memnew ( PanelContainer ) ;
scene_root_parent - > set_custom_minimum_size ( Size2 ( 0 , 80 ) * EDSCALE ) ;
2017-05-02 22:13:12 +02:00
scene_root_parent - > add_style_override ( " panel " , gui_base - > get_stylebox ( " Content " , " EditorStyles " ) ) ;
2017-09-02 03:29:04 +02:00
scene_root_parent - > set_draw_behind_parent ( true ) ;
2014-02-10 02:10:30 +01:00
srt - > add_child ( scene_root_parent ) ;
scene_root_parent - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2017-03-05 16:44:50 +01:00
scene_root = memnew ( Viewport ) ;
2017-12-19 19:59:32 +01:00
//scene_root->set_usage(Viewport::USAGE_2D); canvas BG mode prevents usage of this as 2D
2016-10-05 06:26:35 +02:00
scene_root - > set_disable_3d ( true ) ;
2017-03-05 16:44:50 +01:00
VisualServer : : get_singleton ( ) - > viewport_set_hide_scenario ( scene_root - > get_viewport_rid ( ) , true ) ;
2016-01-17 02:41:10 +01:00
scene_root - > set_disable_input ( true ) ;
2014-02-10 02:10:30 +01:00
scene_root - > set_as_audio_listener_2d ( true ) ;
2017-03-05 16:44:50 +01:00
viewport = memnew ( VBoxContainer ) ;
2016-02-08 17:01:54 +01:00
viewport - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2017-04-28 04:01:17 +02:00
viewport - > add_constant_override ( " separation " , 0 ) ;
2014-02-10 02:10:30 +01:00
scene_root_parent - > add_child ( viewport ) ;
2017-03-05 16:44:50 +01:00
PanelContainer * top_region = memnew ( PanelContainer ) ;
2017-05-02 22:13:12 +02:00
top_region - > add_style_override ( " panel " , gui_base - > get_stylebox ( " MenuPanel " , " EditorStyles " ) ) ;
2017-03-05 16:44:50 +01:00
HBoxContainer * left_menu_hb = memnew ( HBoxContainer ) ;
2014-02-10 02:10:30 +01:00
top_region - > add_child ( left_menu_hb ) ;
menu_hb - > add_child ( top_region ) ;
2017-08-26 17:46:49 +02:00
{
Control * sp = memnew ( Control ) ;
sp - > set_custom_minimum_size ( Size2 ( 30 , 0 ) * EDSCALE ) ;
menu_hb - > add_child ( sp ) ;
}
2017-03-05 16:44:50 +01:00
file_menu = memnew ( MenuButton ) ;
2017-09-02 03:25:40 +02:00
file_menu - > set_flat ( false ) ;
2016-05-04 03:25:37 +02:00
file_menu - > set_text ( TTR ( " Scene " ) ) ;
2017-05-02 22:13:12 +02:00
file_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
2017-09-02 03:25:40 +02:00
left_menu_hb - > add_child ( file_menu ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
prev_scene = memnew ( ToolButton ) ;
prev_scene - > set_icon ( gui_base - > get_icon ( " PrevScene " , " EditorIcons " ) ) ;
2016-05-04 03:25:37 +02:00
prev_scene - > set_tooltip ( TTR ( " Go to previously opened scene. " ) ) ;
2014-02-10 02:10:30 +01:00
prev_scene - > set_disabled ( true ) ;
2017-03-05 16:44:50 +01:00
prev_scene - > connect ( " pressed " , this , " _menu_option " , make_binds ( FILE_OPEN_PREV ) ) ;
2015-04-21 00:38:02 +02:00
gui_base - > add_child ( prev_scene ) ;
2017-03-29 17:29:38 +02:00
prev_scene - > set_position ( Point2 ( 3 , 24 ) ) ;
2015-04-21 00:38:02 +02:00
prev_scene - > hide ( ) ;
2014-02-10 02:10:30 +01:00
2017-08-30 13:59:48 +02:00
accept = memnew ( AcceptDialog ) ;
gui_base - > add_child ( accept ) ;
accept - > connect ( " confirmed " , this , " _menu_confirm_current " ) ;
project_export = memnew ( ProjectExportDialog ) ;
gui_base - > add_child ( project_export ) ;
dependency_error = memnew ( DependencyErrorDialog ) ;
gui_base - > add_child ( dependency_error ) ;
dependency_fixer = memnew ( DependencyEditor ) ;
gui_base - > add_child ( dependency_fixer ) ;
settings_config_dialog = memnew ( EditorSettingsDialog ) ;
gui_base - > add_child ( settings_config_dialog ) ;
project_settings = memnew ( ProjectSettingsEditor ( & editor_data ) ) ;
gui_base - > add_child ( project_settings ) ;
run_settings_dialog = memnew ( RunSettingsDialog ) ;
gui_base - > add_child ( run_settings_dialog ) ;
export_template_manager = memnew ( ExportTemplateManager ) ;
gui_base - > add_child ( export_template_manager ) ;
about = memnew ( EditorAbout ) ;
gui_base - > add_child ( about ) ;
warning = memnew ( AcceptDialog ) ;
gui_base - > add_child ( warning ) ;
2017-03-05 16:44:50 +01:00
ED_SHORTCUT ( " editor/next_tab " , TTR ( " Next tab " ) , KEY_MASK_CMD + KEY_TAB ) ;
ED_SHORTCUT ( " editor/prev_tab " , TTR ( " Previous tab " ) , KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_TAB ) ;
2018-04-22 19:36:01 +02:00
ED_SHORTCUT ( " editor/filter_files " , TTR ( " Filter Files... " ) , KEY_MASK_ALT + KEY_MASK_CMD + KEY_P ) ;
2017-06-22 23:04:03 +02:00
PopupMenu * p ;
2016-06-25 06:42:09 +02:00
2016-05-04 03:25:37 +02:00
file_menu - > set_tooltip ( TTR ( " Operations with scene files. " ) ) ;
2017-03-05 16:44:50 +01:00
p = file_menu - > get_popup ( ) ;
p - > add_shortcut ( ED_SHORTCUT ( " editor/new_scene " , TTR ( " New Scene " ) ) , FILE_NEW_SCENE ) ;
2018-04-22 19:36:01 +02:00
p - > add_shortcut ( ED_SHORTCUT ( " editor/new_inherited_scene " , TTR ( " New Inherited Scene... " ) ) , FILE_NEW_INHERITED_SCENE ) ;
p - > add_shortcut ( ED_SHORTCUT ( " editor/open_scene " , TTR ( " Open Scene... " ) , KEY_MASK_CMD + KEY_O ) , FILE_OPEN_SCENE ) ;
2015-04-26 04:45:49 +02:00
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " editor/save_scene " , TTR ( " Save Scene " ) , KEY_MASK_CMD + KEY_S ) , FILE_SAVE_SCENE ) ;
2018-04-22 19:36:01 +02:00
p - > add_shortcut ( ED_SHORTCUT ( " editor/save_scene_as " , TTR ( " Save Scene As... " ) , KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_S ) , FILE_SAVE_AS_SCENE ) ;
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " editor/save_all_scenes " , TTR ( " Save all Scenes " ) , KEY_MASK_ALT + KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_S ) , FILE_SAVE_ALL_SCENES ) ;
2014-02-10 02:10:30 +01:00
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " editor/close_scene " , TTR ( " Close Scene " ) , KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_W ) , FILE_CLOSE ) ;
2015-06-22 05:03:19 +02:00
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_submenu_item ( TTR ( " Open Recent " ) , " RecentScenes " , FILE_OPEN_RECENT ) ;
2014-02-10 02:10:30 +01:00
p - > add_separator ( ) ;
2018-04-22 19:36:01 +02:00
p - > add_shortcut ( ED_SHORTCUT ( " editor/quick_open_scene " , TTR ( " Quick Open Scene... " ) , KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_O ) , FILE_QUICK_OPEN_SCENE ) ;
p - > add_shortcut ( ED_SHORTCUT ( " editor/quick_open_script " , TTR ( " Quick Open Script... " ) , KEY_MASK_ALT + KEY_MASK_CMD + KEY_O ) , FILE_QUICK_OPEN_SCRIPT ) ;
2014-02-10 02:10:30 +01:00
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
PopupMenu * pm_export = memnew ( PopupMenu ) ;
2014-02-10 02:10:30 +01:00
pm_export - > set_name ( " Export " ) ;
p - > add_child ( pm_export ) ;
2018-04-22 19:36:01 +02:00
p - > add_submenu_item ( TTR ( " Convert To... " ) , " Export " ) ;
pm_export - > add_shortcut ( ED_SHORTCUT ( " editor/convert_to_MeshLibrary " , TTR ( " MeshLibrary... " ) ) , FILE_EXPORT_MESH_LIBRARY ) ;
pm_export - > add_shortcut ( ED_SHORTCUT ( " editor/convert_to_TileSet " , TTR ( " TileSet... " ) ) , FILE_EXPORT_TILESET ) ;
2017-03-05 16:44:50 +01:00
pm_export - > connect ( " id_pressed " , this , " _menu_option " ) ;
2014-02-10 02:10:30 +01:00
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_shortcut ( ED_SHORTCUT ( " editor/undo " , TTR ( " Undo " ) , KEY_MASK_CMD + KEY_Z ) , EDIT_UNDO , true ) ;
p - > add_shortcut ( ED_SHORTCUT ( " editor/redo " , TTR ( " Redo " ) , KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_Z ) , EDIT_REDO , true ) ;
2014-02-10 02:10:30 +01:00
p - > add_separator ( ) ;
2017-03-05 16:44:50 +01:00
p - > add_item ( TTR ( " Revert Scene " ) , EDIT_REVERT ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
recent_scenes = memnew ( PopupMenu ) ;
2014-02-10 02:10:30 +01:00
recent_scenes - > set_name ( " RecentScenes " ) ;
p - > add_child ( recent_scenes ) ;
2017-03-05 16:44:50 +01:00
recent_scenes - > connect ( " id_pressed " , this , " _open_recent_scene " ) ;
2014-02-10 02:10:30 +01:00
2017-06-22 23:04:03 +02:00
p - > add_separator ( ) ;
p - > add_item ( TTR ( " Quit " ) , FILE_QUIT , KEY_MASK_CMD + KEY_Q ) ;
project_menu = memnew ( MenuButton ) ;
2017-09-02 03:25:40 +02:00
project_menu - > set_flat ( false ) ;
2017-06-22 23:04:03 +02:00
project_menu - > set_tooltip ( TTR ( " Miscellaneous project or scene-wide tools. " ) ) ;
project_menu - > set_text ( TTR ( " Project " ) ) ;
project_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
left_menu_hb - > add_child ( project_menu ) ;
p = project_menu - > get_popup ( ) ;
p - > add_item ( TTR ( " Project Settings " ) , RUN_SETTINGS ) ;
p - > add_separator ( ) ;
p - > connect ( " id_pressed " , this , " _menu_option " ) ;
p - > add_item ( TTR ( " Export " ) , FILE_EXPORT_PROJECT ) ;
2018-03-17 02:50:35 +01:00
tool_menu = memnew ( PopupMenu ) ;
2017-06-22 23:04:03 +02:00
tool_menu - > set_name ( " Tools " ) ;
2018-03-17 02:50:35 +01:00
tool_menu - > connect ( " index_pressed " , this , " _tool_menu_option " ) ;
2017-06-22 23:04:03 +02:00
p - > add_child ( tool_menu ) ;
p - > add_submenu_item ( TTR ( " Tools " ) , " Tools " ) ;
tool_menu - > add_item ( TTR ( " Orphan Resource Explorer " ) , TOOLS_ORPHAN_RESOURCES ) ;
p - > add_separator ( ) ;
# ifdef OSX_ENABLED
p - > add_item ( TTR ( " Quit to Project List " ) , RUN_PROJECT_MANAGER , KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q ) ;
# else
p - > add_item ( TTR ( " Quit to Project List " ) , RUN_PROJECT_MANAGER , KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Q ) ;
# endif
2015-11-18 08:47:41 +01:00
2017-03-05 16:44:50 +01:00
PanelContainer * editor_region = memnew ( PanelContainer ) ;
main_editor_button_vb = memnew ( HBoxContainer ) ;
2015-11-18 08:47:41 +01:00
editor_region - > add_child ( main_editor_button_vb ) ;
2017-05-24 12:00:55 +02:00
menu_hb - > add_spacer ( ) ;
menu_hb - > add_child ( editor_region ) ;
2016-09-13 14:46:17 +02:00
2017-05-24 12:00:55 +02:00
debug_menu = memnew ( MenuButton ) ;
2017-09-02 03:25:40 +02:00
debug_menu - > set_flat ( false ) ;
2017-05-24 12:00:55 +02:00
debug_menu - > set_text ( TTR ( " Debug " ) ) ;
debug_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
left_menu_hb - > add_child ( debug_menu ) ;
2017-09-02 03:25:40 +02:00
2017-05-24 12:00:55 +02:00
p = debug_menu - > get_popup ( ) ;
p - > set_hide_on_item_selection ( false ) ;
p - > add_check_item ( TTR ( " Deploy with Remote Debug " ) , RUN_DEPLOY_REMOTE_DEBUG ) ;
p - > set_item_tooltip ( p - > get_item_count ( ) - 1 , TTR ( " When exporting or deploying, the resulting executable will attempt to connect to the IP of this computer in order to be debugged. " ) ) ;
p - > add_check_item ( TTR ( " Small Deploy with Network FS " ) , RUN_FILE_SERVER ) ;
p - > set_item_tooltip ( p - > get_item_count ( ) - 1 , TTR ( " When this option is enabled, export or deploy will produce a minimal executable. \n The filesystem will be provided from the project by the editor over the network. \n On Android, deploy will use the USB cable for faster performance. This option speeds up testing for games with a large footprint. " ) ) ;
p - > add_separator ( ) ;
p - > add_check_item ( TTR ( " Visible Collision Shapes " ) , RUN_DEBUG_COLLISONS ) ;
p - > set_item_tooltip ( p - > get_item_count ( ) - 1 , TTR ( " Collision shapes and raycast nodes (for 2D and 3D) will be visible on the running game if this option is turned on. " ) ) ;
p - > add_check_item ( TTR ( " Visible Navigation " ) , RUN_DEBUG_NAVIGATION ) ;
p - > set_item_tooltip ( p - > get_item_count ( ) - 1 , TTR ( " Navigation meshes and polygons will be visible on the running game if this option is turned on. " ) ) ;
p - > add_separator ( ) ;
p - > add_check_item ( TTR ( " Sync Scene Changes " ) , RUN_LIVE_DEBUG ) ;
p - > set_item_tooltip ( p - > get_item_count ( ) - 1 , TTR ( " When this option is turned on, any changes made to the scene in the editor will be replicated in the running game. \n When used remotely on a device, this is more efficient with network filesystem. " ) ) ;
p - > add_check_item ( TTR ( " Sync Script Changes " ) , RUN_RELOAD_SCRIPTS ) ;
p - > set_item_tooltip ( p - > get_item_count ( ) - 1 , TTR ( " When this option is turned on, any script that is saved will be reloaded on the running game. \n When used remotely on a device, this is more efficient with network filesystem. " ) ) ;
p - > connect ( " id_pressed " , this , " _menu_option " ) ;
2015-11-29 05:08:31 +01:00
2017-05-24 12:00:55 +02:00
menu_hb - > add_spacer ( ) ;
2015-11-29 05:08:31 +01:00
2017-05-24 12:00:55 +02:00
settings_menu = memnew ( MenuButton ) ;
2017-09-02 03:25:40 +02:00
settings_menu - > set_flat ( false ) ;
2017-05-24 12:00:55 +02:00
settings_menu - > set_text ( TTR ( " Editor " ) ) ;
settings_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
2017-09-02 03:25:40 +02:00
left_menu_hb - > add_child ( settings_menu ) ;
2017-05-24 12:00:55 +02:00
p = settings_menu - > get_popup ( ) ;
2015-11-29 05:08:31 +01:00
2017-05-24 12:00:55 +02:00
p - > add_item ( TTR ( " Editor Settings " ) , SETTINGS_PREFERENCES ) ;
p - > add_separator ( ) ;
editor_layouts = memnew ( PopupMenu ) ;
editor_layouts - > set_name ( " Layouts " ) ;
p - > add_child ( editor_layouts ) ;
editor_layouts - > connect ( " id_pressed " , this , " _layout_menu_option " ) ;
p - > add_submenu_item ( TTR ( " Editor Layout " ) , " Layouts " ) ;
p - > add_shortcut ( ED_SHORTCUT ( " editor/fullscreen_mode " , TTR ( " Toggle Fullscreen " ) , KEY_MASK_SHIFT | KEY_F11 ) , SETTINGS_TOGGLE_FULLSCREN ) ;
p - > add_separator ( ) ;
p - > add_item ( TTR ( " Manage Export Templates " ) , SETTINGS_MANAGE_EXPORT_TEMPLATES ) ;
2017-05-26 16:34:41 +02:00
// Help Menu
2017-09-02 03:25:40 +02:00
help_menu = memnew ( MenuButton ) ;
help_menu - > set_flat ( false ) ;
2017-05-26 16:34:41 +02:00
help_menu - > set_text ( TTR ( " Help " ) ) ;
help_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ;
2017-09-02 03:25:40 +02:00
left_menu_hb - > add_child ( help_menu ) ;
2017-05-26 16:34:41 +02:00
p = help_menu - > get_popup ( ) ;
p - > connect ( " id_pressed " , this , " _menu_option " ) ;
p - > add_icon_item ( gui_base - > get_icon ( " ClassList " , " EditorIcons " ) , TTR ( " Classes " ) , HELP_CLASSES ) ;
2017-07-18 08:09:19 +02:00
p - > add_icon_item ( gui_base - > get_icon ( " HelpSearch " , " EditorIcons " ) , TTR ( " Search " ) , HELP_SEARCH ) ;
2017-05-26 16:34:41 +02:00
p - > add_separator ( ) ;
p - > add_icon_item ( gui_base - > get_icon ( " Instance " , " EditorIcons " ) , TTR ( " Online Docs " ) , HELP_DOCS ) ;
p - > add_icon_item ( gui_base - > get_icon ( " Instance " , " EditorIcons " ) , TTR ( " Q&A " ) , HELP_QA ) ;
p - > add_icon_item ( gui_base - > get_icon ( " Instance " , " EditorIcons " ) , TTR ( " Issue Tracker " ) , HELP_ISSUES ) ;
p - > add_icon_item ( gui_base - > get_icon ( " Instance " , " EditorIcons " ) , TTR ( " Community " ) , HELP_COMMUNITY ) ;
2017-05-24 12:00:55 +02:00
p - > add_separator ( ) ;
2017-09-08 08:06:02 +02:00
p - > add_icon_item ( gui_base - > get_icon ( " Godot " , " EditorIcons " ) , TTR ( " About " ) , HELP_ABOUT ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
play_cc = memnew ( CenterContainer ) ;
2017-01-08 23:54:19 +01:00
play_cc - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2017-05-24 12:00:55 +02:00
menu_hb - > add_child ( play_cc ) ;
2014-02-10 02:10:30 +01:00
2017-05-02 22:13:12 +02:00
play_button_panel = memnew ( PanelContainer ) ;
play_cc - > add_child ( play_button_panel ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
HBoxContainer * play_hb = memnew ( HBoxContainer ) ;
2017-05-02 22:13:12 +02:00
play_button_panel - > add_child ( play_hb ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
play_button = memnew ( ToolButton ) ;
2014-02-10 02:10:30 +01:00
play_hb - > add_child ( play_button ) ;
play_button - > set_toggle_mode ( true ) ;
2017-03-05 16:44:50 +01:00
play_button - > set_icon ( gui_base - > get_icon ( " MainPlay " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
play_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-03-05 16:44:50 +01:00
play_button - > connect ( " pressed " , this , " _menu_option " , make_binds ( RUN_PLAY ) ) ;
2016-06-05 02:31:29 +02:00
play_button - > set_tooltip ( TTR ( " Play the project. " ) ) ;
2017-03-05 16:44:50 +01:00
play_button - > set_shortcut ( ED_SHORTCUT ( " editor/play " , TTR ( " Play " ) , KEY_F5 ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
pause_button = memnew ( ToolButton ) ;
2014-02-10 02:10:30 +01:00
pause_button - > set_toggle_mode ( true ) ;
2017-03-05 16:44:50 +01:00
pause_button - > set_icon ( gui_base - > get_icon ( " Pause " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
pause_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2016-05-22 02:18:16 +02:00
pause_button - > set_tooltip ( TTR ( " Pause the scene " ) ) ;
pause_button - > set_disabled ( true ) ;
play_hb - > add_child ( pause_button ) ;
2017-03-05 16:44:50 +01:00
pause_button - > set_shortcut ( ED_SHORTCUT ( " editor/pause_scene " , TTR ( " Pause Scene " ) , KEY_F7 ) ) ;
2016-05-22 03:34:55 +02:00
2017-03-05 16:44:50 +01:00
stop_button = memnew ( ToolButton ) ;
2014-02-10 02:10:30 +01:00
play_hb - > add_child ( stop_button ) ;
stop_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-08-19 09:09:58 +02:00
stop_button - > set_icon ( gui_base - > get_icon ( " Stop " , " EditorIcons " ) ) ;
2017-03-05 16:44:50 +01:00
stop_button - > connect ( " pressed " , this , " _menu_option " , make_binds ( RUN_STOP ) ) ;
2016-06-05 02:31:29 +02:00
stop_button - > set_tooltip ( TTR ( " Stop the scene. " ) ) ;
2017-12-04 20:48:46 +01:00
stop_button - > set_disabled ( true ) ;
2017-03-05 16:44:50 +01:00
stop_button - > set_shortcut ( ED_SHORTCUT ( " editor/stop " , TTR ( " Stop " ) , KEY_F8 ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
run_native = memnew ( EditorRunNative ) ;
2014-02-10 02:10:30 +01:00
play_hb - > add_child ( run_native ) ;
2017-03-05 16:44:50 +01:00
native_play_button = memnew ( MenuButton ) ;
2014-02-10 02:10:30 +01:00
native_play_button - > set_text ( " NTV " ) ;
menu_hb - > add_child ( native_play_button ) ;
native_play_button - > hide ( ) ;
2017-03-05 16:44:50 +01:00
native_play_button - > get_popup ( ) - > connect ( " id_pressed " , this , " _run_in_device " ) ;
run_native - > connect ( " native_run " , this , " _menu_option " , varray ( RUN_PLAY_NATIVE ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
play_scene_button = memnew ( ToolButton ) ;
2014-02-10 02:10:30 +01:00
play_hb - > add_child ( play_scene_button ) ;
play_scene_button - > set_toggle_mode ( true ) ;
play_scene_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-03-05 16:44:50 +01:00
play_scene_button - > set_icon ( gui_base - > get_icon ( " PlayScene " , " EditorIcons " ) ) ;
play_scene_button - > connect ( " pressed " , this , " _menu_option " , make_binds ( RUN_PLAY_SCENE ) ) ;
2016-06-05 02:31:29 +02:00
play_scene_button - > set_tooltip ( TTR ( " Play the edited scene. " ) ) ;
2017-03-05 16:44:50 +01:00
play_scene_button - > set_shortcut ( ED_SHORTCUT ( " editor/play_scene " , TTR ( " Play Scene " ) , KEY_F6 ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
play_custom_scene_button = memnew ( ToolButton ) ;
2014-02-10 02:10:30 +01:00
play_hb - > add_child ( play_custom_scene_button ) ;
play_custom_scene_button - > set_toggle_mode ( true ) ;
play_custom_scene_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-03-05 16:44:50 +01:00
play_custom_scene_button - > set_icon ( gui_base - > get_icon ( " PlayCustom " , " EditorIcons " ) ) ;
play_custom_scene_button - > connect ( " pressed " , this , " _menu_option " , make_binds ( RUN_PLAY_CUSTOM_SCENE ) ) ;
2016-07-11 19:46:41 +02:00
play_custom_scene_button - > set_tooltip ( TTR ( " Play custom scene " ) ) ;
2017-03-05 16:44:50 +01:00
play_custom_scene_button - > set_shortcut ( ED_SHORTCUT ( " editor/play_custom_scene " , TTR ( " Play Custom Scene " ) , KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F5 ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
progress_hb = memnew ( BackgroundProgress ) ;
2015-11-18 08:47:41 +01:00
2017-03-05 16:44:50 +01:00
HBoxContainer * right_menu_hb = memnew ( HBoxContainer ) ;
2017-05-24 12:00:55 +02:00
menu_hb - > add_child ( right_menu_hb ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
layout_dialog = memnew ( EditorNameDialog ) ;
2015-11-22 19:11:17 +01:00
gui_base - > add_child ( layout_dialog ) ;
layout_dialog - > set_hide_on_ok ( false ) ;
2017-03-05 16:44:50 +01:00
layout_dialog - > set_size ( Size2 ( 175 , 70 ) * EDSCALE ) ;
layout_dialog - > connect ( " name_confirmed " , this , " _dialog_action " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
update_menu = memnew ( MenuButton ) ;
2016-05-04 03:25:37 +02:00
update_menu - > set_tooltip ( TTR ( " Spins when the editor window repaints! " ) ) ;
2015-11-18 08:47:41 +01:00
right_menu_hb - > add_child ( update_menu ) ;
2017-03-05 16:44:50 +01:00
update_menu - > set_icon ( gui_base - > get_icon ( " Progress1 " , " EditorIcons " ) ) ;
2017-05-24 12:00:55 +02:00
update_menu - > get_popup ( ) - > connect ( " id_pressed " , this , " _menu_option " ) ;
2017-03-05 16:44:50 +01:00
p = update_menu - > get_popup ( ) ;
p - > add_check_item ( TTR ( " Update Always " ) , SETTINGS_UPDATE_ALWAYS ) ;
p - > add_check_item ( TTR ( " Update Changes " ) , SETTINGS_UPDATE_CHANGES ) ;
p - > add_separator ( ) ;
p - > add_check_item ( TTR ( " Disable Update Spinner " ) , SETTINGS_UPDATE_SPINNER_HIDE ) ;
2017-08-28 12:12:40 +02:00
int update_always = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " editor_options " , " update_always " , false ) ;
2017-08-26 20:43:10 +02:00
int hide_spinner = EditorSettings : : get_singleton ( ) - > get_project_metadata ( " editor_options " , " update_spinner_hide " , false ) ;
2017-08-28 12:12:40 +02:00
_menu_option ( update_always ? SETTINGS_UPDATE_ALWAYS : SETTINGS_UPDATE_CHANGES ) ;
2017-08-26 20:43:10 +02:00
if ( hide_spinner ) {
_menu_option ( SETTINGS_UPDATE_SPINNER_HIDE ) ;
}
2015-11-18 08:47:41 +01:00
2017-03-05 16:44:50 +01:00
scene_tree_dock = memnew ( SceneTreeDock ( this , scene_root , editor_selection , editor_data ) ) ;
2016-06-04 02:03:09 +02:00
dock_slot [ DOCK_SLOT_RIGHT_UL ] - > add_child ( scene_tree_dock ) ;
2017-11-26 02:59:31 +01:00
dock_slot [ DOCK_SLOT_RIGHT_UL ] - > set_tab_title ( scene_tree_dock - > get_index ( ) , TTR ( " Scene " ) ) ;
2016-06-04 02:03:09 +02:00
dock_slot [ DOCK_SLOT_LEFT_BR ] - > hide ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
VBoxContainer * prop_editor_base = memnew ( VBoxContainer ) ;
2017-11-26 02:59:31 +01:00
prop_editor_base - > set_name ( " Inspector " ) ;
2016-06-04 02:03:09 +02:00
dock_slot [ DOCK_SLOT_RIGHT_BL ] - > add_child ( prop_editor_base ) ;
2017-11-26 02:59:31 +01:00
dock_slot [ DOCK_SLOT_RIGHT_BL ] - > set_tab_title ( prop_editor_base - > get_index ( ) , TTR ( " Inspector " ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
HBoxContainer * prop_editor_hb = memnew ( HBoxContainer ) ;
2014-02-10 02:10:30 +01:00
2015-09-01 05:49:47 +02:00
prop_editor_base - > add_child ( prop_editor_hb ) ;
2017-03-05 16:44:50 +01:00
prop_editor_vb = prop_editor_base ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
resource_new_button = memnew ( ToolButton ) ;
2016-05-19 00:08:12 +02:00
resource_new_button - > set_tooltip ( TTR ( " Create a new resource in memory and edit it. " ) ) ;
2017-03-05 16:44:50 +01:00
resource_new_button - > set_icon ( gui_base - > get_icon ( " New " , " EditorIcons " ) ) ;
2015-09-01 05:49:47 +02:00
prop_editor_hb - > add_child ( resource_new_button ) ;
2017-03-05 16:44:50 +01:00
resource_new_button - > connect ( " pressed " , this , " _menu_option " , varray ( RESOURCE_NEW ) ) ;
2015-09-01 05:49:47 +02:00
resource_new_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-03-05 16:44:50 +01:00
resource_load_button = memnew ( ToolButton ) ;
2016-05-19 00:08:12 +02:00
resource_load_button - > set_tooltip ( TTR ( " Load an existing resource from disk and edit it. " ) ) ;
2017-03-05 16:44:50 +01:00
resource_load_button - > set_icon ( gui_base - > get_icon ( " Load " , " EditorIcons " ) ) ;
2015-09-01 05:49:47 +02:00
prop_editor_hb - > add_child ( resource_load_button ) ;
2017-03-05 16:44:50 +01:00
resource_load_button - > connect ( " pressed " , this , " _menu_option " , varray ( RESOURCE_LOAD ) ) ;
2015-09-01 05:49:47 +02:00
resource_load_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
2017-03-05 16:44:50 +01:00
resource_save_button = memnew ( MenuButton ) ;
2016-05-19 00:08:12 +02:00
resource_save_button - > set_tooltip ( TTR ( " Save the currently edited resource. " ) ) ;
2017-03-05 16:44:50 +01:00
resource_save_button - > set_icon ( gui_base - > get_icon ( " Save " , " EditorIcons " ) ) ;
2015-09-01 05:49:47 +02:00
prop_editor_hb - > add_child ( resource_save_button ) ;
2017-03-05 16:44:50 +01:00
resource_save_button - > get_popup ( ) - > add_item ( TTR ( " Save " ) , RESOURCE_SAVE ) ;
2018-04-22 19:36:01 +02:00
resource_save_button - > get_popup ( ) - > add_item ( TTR ( " Save As... " ) , RESOURCE_SAVE_AS ) ;
2017-03-05 16:44:50 +01:00
resource_save_button - > get_popup ( ) - > connect ( " id_pressed " , this , " _menu_option " ) ;
2015-09-01 05:49:47 +02:00
resource_save_button - > set_focus_mode ( Control : : FOCUS_NONE ) ;
resource_save_button - > set_disabled ( true ) ;
prop_editor_hb - > add_spacer ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
property_back = memnew ( ToolButton ) ;
property_back - > set_icon ( gui_base - > get_icon ( " Back " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
property_back - > set_flat ( true ) ;
2016-05-04 03:25:37 +02:00
property_back - > set_tooltip ( TTR ( " Go to the previous edited object in history. " ) ) ;
2015-09-01 05:49:47 +02:00
property_back - > set_disabled ( true ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
prop_editor_hb - > add_child ( property_back ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
property_forward = memnew ( ToolButton ) ;
property_forward - > set_icon ( gui_base - > get_icon ( " Forward " , " EditorIcons " ) ) ;
2014-02-10 02:10:30 +01:00
property_forward - > set_flat ( true ) ;
2016-05-04 03:25:37 +02:00
property_forward - > set_tooltip ( TTR ( " Go to the next edited object in history. " ) ) ;
2015-09-01 05:49:47 +02:00
property_forward - > set_disabled ( true ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
prop_editor_hb - > add_child ( property_forward ) ;
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
editor_history_menu = memnew ( MenuButton ) ;
2016-05-19 00:08:12 +02:00
editor_history_menu - > set_tooltip ( TTR ( " History of recently edited objects. " ) ) ;
2017-03-05 16:44:50 +01:00
editor_history_menu - > set_icon ( gui_base - > get_icon ( " History " , " EditorIcons " ) ) ;
2015-09-01 05:49:47 +02:00
prop_editor_hb - > add_child ( editor_history_menu ) ;
2017-03-05 16:44:50 +01:00
editor_history_menu - > connect ( " about_to_show " , this , " _prepare_history " ) ;
editor_history_menu - > get_popup ( ) - > connect ( " id_pressed " , this , " _select_history " ) ;
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
prop_editor_hb = memnew ( HBoxContainer ) ; //again...
2015-09-01 05:49:47 +02:00
prop_editor_base - > add_child ( prop_editor_hb ) ;
2017-08-26 17:46:49 +02:00
2017-03-05 16:44:50 +01:00
editor_path = memnew ( EditorPath ( & editor_history ) ) ;
2015-09-01 05:49:47 +02:00
editor_path - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
prop_editor_hb - > add_child ( editor_path ) ;
2017-03-05 16:44:50 +01:00
search_button = memnew ( ToolButton ) ;
2015-11-21 17:42:15 +01:00
search_button - > set_toggle_mode ( true ) ;
search_button - > set_pressed ( false ) ;
2017-07-12 20:38:47 +02:00
search_button - > set_icon ( gui_base - > get_icon ( " Search " , " EditorIcons " ) ) ;
2015-11-21 17:42:15 +01:00
prop_editor_hb - > add_child ( search_button ) ;
2017-03-05 16:44:50 +01:00
search_button - > connect ( " toggled " , this , " _toggle_search_bar " ) ;
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
object_menu = memnew ( MenuButton ) ;
object_menu - > set_icon ( gui_base - > get_icon ( " Tools " , " EditorIcons " ) ) ;
prop_editor_hb - > add_child ( object_menu ) ;
2016-05-04 03:25:37 +02:00
object_menu - > set_tooltip ( TTR ( " Object properties. " ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
create_dialog = memnew ( CreateDialog ) ;
2015-09-01 05:49:47 +02:00
gui_base - > add_child ( create_dialog ) ;
create_dialog - > set_base_type ( " Resource " ) ;
2017-03-05 16:44:50 +01:00
create_dialog - > connect ( " create " , this , " _resource_created " ) ;
2015-09-01 05:49:47 +02:00
2017-03-05 16:44:50 +01:00
search_bar = memnew ( HBoxContainer ) ;
2015-11-21 17:42:15 +01:00
search_bar - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
prop_editor_base - > add_child ( search_bar ) ;
search_bar - > hide ( ) ;
2017-03-05 16:44:50 +01:00
Label * l = memnew ( Label ( TTR ( " Search: " ) + " " ) ) ;
2015-11-21 17:42:15 +01:00
search_bar - > add_child ( l ) ;
2017-03-05 16:44:50 +01:00
search_box = memnew ( LineEdit ) ;
2015-11-21 17:42:15 +01:00
search_box - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
search_bar - > add_child ( search_box ) ;
2017-03-05 16:44:50 +01:00
ToolButton * clear_button = memnew ( ToolButton ) ;
clear_button - > set_icon ( gui_base - > get_icon ( " Close " , " EditorIcons " ) ) ;
2015-11-21 17:42:15 +01:00
search_bar - > add_child ( clear_button ) ;
2017-03-05 16:44:50 +01:00
clear_button - > connect ( " pressed " , this , " _clear_search_box " ) ;
2015-09-01 05:49:47 +02:00
2017-09-15 00:38:38 +02:00
property_editable_warning = memnew ( Button ) ;
2017-09-14 16:30:16 +02:00
property_editable_warning - > set_text ( TTR ( " Changes may be lost! " ) ) ;
2017-09-14 15:38:59 +02:00
prop_editor_base - > add_child ( property_editable_warning ) ;
2017-09-15 00:38:38 +02:00
property_editable_warning_dialog = memnew ( AcceptDialog ) ;
2017-09-14 15:38:59 +02:00
gui_base - > add_child ( property_editable_warning_dialog ) ;
property_editable_warning - > hide ( ) ;
2017-09-15 00:38:38 +02:00
property_editable_warning - > connect ( " pressed " , this , " _property_editable_warning_pressed " ) ;
2017-09-14 15:38:59 +02:00
2017-03-05 16:44:50 +01:00
property_editor = memnew ( PropertyEditor ) ;
2015-09-01 05:49:47 +02:00
property_editor - > set_autoclear ( true ) ;
property_editor - > set_show_categories ( true ) ;
property_editor - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
property_editor - > set_use_doc_hints ( true ) ;
2017-07-18 02:05:38 +02:00
property_editor - > set_hide_script ( false ) ;
2017-09-29 18:52:56 +02:00
property_editor - > set_enable_capitalize_paths ( bool ( EDITOR_DEF ( " interface/editor/capitalize_properties " , true ) ) ) ;
2017-12-06 23:06:18 +01:00
property_editor - > set_use_folding ( ! bool ( EDITOR_DEF ( " interface/editor/disable_inspector_folding " , false ) ) ) ;
2015-09-01 05:49:47 +02:00
property_editor - > hide_top_label ( ) ;
2015-11-21 17:42:15 +01:00
property_editor - > register_text_enter ( search_box ) ;
2015-09-01 05:49:47 +02:00
2017-09-14 15:38:59 +02:00
Button * property_editable_warning ;
2017-03-05 16:44:50 +01:00
prop_editor_base - > add_child ( property_editor ) ;
2015-09-01 05:49:47 +02:00
property_editor - > set_undo_redo ( & editor_data . get_undo_redo ( ) ) ;
2017-03-05 16:44:50 +01:00
import_dock = memnew ( ImportDock ) ;
2017-02-01 13:45:45 +01:00
dock_slot [ DOCK_SLOT_RIGHT_UL ] - > add_child ( import_dock ) ;
2017-11-26 02:59:31 +01:00
dock_slot [ DOCK_SLOT_RIGHT_UL ] - > set_tab_title ( import_dock - > get_index ( ) , TTR ( " Import " ) ) ;
2017-02-01 13:45:45 +01:00
2017-03-24 17:39:16 +01:00
bool use_single_dock_column = ( OS : : get_singleton ( ) - > get_screen_size ( OS : : get_singleton ( ) - > get_current_screen ( ) ) . x < 1200 ) ;
2017-03-05 16:44:50 +01:00
node_dock = memnew ( NodeDock ) ;
2016-09-13 16:20:09 +02:00
if ( use_single_dock_column ) {
dock_slot [ DOCK_SLOT_RIGHT_UL ] - > add_child ( node_dock ) ;
2017-11-26 02:59:31 +01:00
dock_slot [ DOCK_SLOT_RIGHT_UL ] - > set_tab_title ( node_dock - > get_index ( ) , TTR ( " Node " ) ) ;
2016-09-13 16:20:09 +02:00
} else {
dock_slot [ DOCK_SLOT_RIGHT_BL ] - > add_child ( node_dock ) ;
2017-11-26 02:59:31 +01:00
dock_slot [ DOCK_SLOT_RIGHT_BL ] - > set_tab_title ( node_dock - > get_index ( ) , TTR ( " Node " ) ) ;
2016-09-13 16:20:09 +02:00
}
2016-06-04 02:03:09 +02:00
2017-03-05 16:44:50 +01:00
filesystem_dock = memnew ( FileSystemDock ( this ) ) ;
2017-01-21 13:07:29 +01:00
filesystem_dock - > set_display_mode ( int ( EditorSettings : : get_singleton ( ) - > get ( " docks/filesystem/display_mode " ) ) ) ;
2016-09-13 16:20:09 +02:00
if ( use_single_dock_column ) {
2017-01-21 13:07:29 +01:00
dock_slot [ DOCK_SLOT_RIGHT_BL ] - > add_child ( filesystem_dock ) ;
2017-11-26 02:59:31 +01:00
dock_slot [ DOCK_SLOT_RIGHT_BL ] - > set_tab_title ( filesystem_dock - > get_index ( ) , TTR ( " FileSystem " ) ) ;
2016-09-13 16:20:09 +02:00
left_r_vsplit - > hide ( ) ;
dock_slot [ DOCK_SLOT_LEFT_UR ] - > hide ( ) ;
dock_slot [ DOCK_SLOT_LEFT_BR ] - > hide ( ) ;
} else {
2017-01-21 13:07:29 +01:00
dock_slot [ DOCK_SLOT_LEFT_UR ] - > add_child ( filesystem_dock ) ;
2017-11-26 02:59:31 +01:00
dock_slot [ DOCK_SLOT_LEFT_UR ] - > set_tab_title ( filesystem_dock - > get_index ( ) , TTR ( " FileSystem " ) ) ;
2016-09-13 16:20:09 +02:00
}
2017-03-05 16:44:50 +01:00
filesystem_dock - > connect ( " open " , this , " open_request " ) ;
filesystem_dock - > connect ( " instance " , this , " _instance_request " ) ;
2014-02-10 02:10:30 +01:00
2015-11-22 19:11:17 +01:00
const String docks_section = " docks " ;
2017-03-05 16:44:50 +01:00
overridden_default_layout = - 1 ;
2016-01-11 22:23:45 +01:00
default_layout . instance ( ) ;
2017-11-26 02:59:31 +01:00
default_layout - > set_value ( docks_section , " dock_3 " , " FileSystem " ) ;
default_layout - > set_value ( docks_section , " dock_5 " , " Scene,Import " ) ;
default_layout - > set_value ( docks_section , " dock_6 " , " Inspector,Node " ) ;
2015-11-22 19:11:17 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + )
default_layout - > set_value ( docks_section , " dock_hsplit_ " + itos ( i + 1 ) , 0 ) ;
for ( int i = 0 ; i < DOCK_SLOT_MAX / 2 ; i + + )
default_layout - > set_value ( docks_section , " dock_split_ " + itos ( i + 1 ) , 0 ) ;
2014-02-10 02:10:30 +01:00
2015-11-22 19:11:17 +01:00
_update_layouts_menu ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bottom_panel = memnew ( PanelContainer ) ;
2017-07-15 06:40:17 +02:00
bottom_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " panel " , " TabContainer " ) ) ;
2016-01-18 00:03:57 +01:00
center_split - > add_child ( bottom_panel ) ;
center_split - > set_dragger_visibility ( SplitContainer : : DRAGGER_HIDDEN ) ;
2015-11-18 08:47:41 +01:00
2017-03-05 16:44:50 +01:00
bottom_panel_vb = memnew ( VBoxContainer ) ;
2016-01-18 00:03:57 +01:00
bottom_panel - > add_child ( bottom_panel_vb ) ;
2015-11-18 08:47:41 +01:00
2017-03-05 16:44:50 +01:00
bottom_panel_hb = memnew ( HBoxContainer ) ;
2016-01-18 00:03:57 +01:00
bottom_panel_vb - > add_child ( bottom_panel_hb ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
log = memnew ( EditorLog ) ;
2018-03-11 14:20:32 +01:00
ToolButton * output_button = add_bottom_panel_item ( TTR ( " Output " ) , log ) ;
log - > set_tool_button ( output_button ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
old_split_ofs = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
center_split - > connect ( " resized " , this , " _vp_resized " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
orphan_resources = memnew ( OrphanResourcesDialog ) ;
2015-11-29 05:08:31 +01:00
gui_base - > add_child ( orphan_resources ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
confirmation = memnew ( ConfirmationDialog ) ;
2014-02-10 02:10:30 +01:00
gui_base - > add_child ( confirmation ) ;
2017-03-05 16:44:50 +01:00
confirmation - > connect ( " confirmed " , this , " _menu_confirm_current " ) ;
2014-02-10 02:10:30 +01:00
2017-06-21 06:15:39 +02:00
save_confirmation = memnew ( ConfirmationDialog ) ;
save_confirmation - > add_button ( TTR ( " Don't Save " ) , OS : : get_singleton ( ) - > get_swap_ok_cancel ( ) , " discard " ) ;
gui_base - > add_child ( save_confirmation ) ;
save_confirmation - > connect ( " confirmed " , this , " _menu_confirm_current " ) ;
save_confirmation - > connect ( " custom_action " , this , " _discard_changes " ) ;
2017-11-10 23:45:08 +01:00
file_templates = memnew ( EditorFileDialog ) ;
2016-05-19 00:08:12 +02:00
file_templates - > set_title ( TTR ( " Import Templates From ZIP File " ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
gui_base - > add_child ( file_templates ) ;
2017-11-10 23:45:08 +01:00
file_templates - > set_mode ( EditorFileDialog : : MODE_OPEN_FILE ) ;
file_templates - > set_access ( EditorFileDialog : : ACCESS_FILESYSTEM ) ;
2014-02-10 02:10:30 +01:00
file_templates - > clear_filters ( ) ;
2014-04-15 03:43:44 +02:00
file_templates - > add_filter ( " *.tpz ; Template Package " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
file = memnew ( EditorFileDialog ) ;
2014-02-10 02:10:30 +01:00
gui_base - > add_child ( file ) ;
file - > set_current_dir ( " res:// " ) ;
2017-11-10 23:45:08 +01:00
file_export = memnew ( EditorFileDialog ) ;
file_export - > set_access ( EditorFileDialog : : ACCESS_FILESYSTEM ) ;
2014-02-10 02:10:30 +01:00
gui_base - > add_child ( file_export ) ;
2016-05-04 03:25:37 +02:00
file_export - > set_title ( TTR ( " Export Project " ) ) ;
2017-03-05 16:44:50 +01:00
file_export - > connect ( " file_selected " , this , " _dialog_action " ) ;
2014-02-10 02:10:30 +01:00
2017-11-10 23:45:08 +01:00
file_export_lib = memnew ( EditorFileDialog ) ;
2016-05-04 03:25:37 +02:00
file_export_lib - > set_title ( TTR ( " Export Library " ) ) ;
2017-11-10 23:45:08 +01:00
file_export_lib - > set_mode ( EditorFileDialog : : MODE_SAVE_FILE ) ;
2017-03-05 16:44:50 +01:00
file_export_lib - > connect ( " file_selected " , this , " _dialog_action " ) ;
file_export_lib_merge = memnew ( CheckButton ) ;
2016-05-04 03:25:37 +02:00
file_export_lib_merge - > set_text ( TTR ( " Merge With Existing " ) ) ;
2014-02-10 02:10:30 +01:00
file_export_lib_merge - > set_pressed ( true ) ;
file_export_lib - > get_vbox ( ) - > add_child ( file_export_lib_merge ) ;
gui_base - > add_child ( file_export_lib ) ;
2017-03-05 16:44:50 +01:00
file_export_password = memnew ( LineEdit ) ;
2014-02-10 02:10:30 +01:00
file_export_password - > set_secret ( true ) ;
file_export_password - > set_editable ( false ) ;
2017-03-05 16:44:50 +01:00
file_export - > get_vbox ( ) - > add_margin_child ( TTR ( " Password: " ) , file_export_password ) ;
2014-02-10 02:10:30 +01:00
2017-11-10 23:45:08 +01:00
file_script = memnew ( EditorFileDialog ) ;
2016-05-04 03:25:37 +02:00
file_script - > set_title ( TTR ( " Open & Run a Script " ) ) ;
2017-11-10 23:45:08 +01:00
file_script - > set_access ( EditorFileDialog : : ACCESS_FILESYSTEM ) ;
file_script - > set_mode ( EditorFileDialog : : MODE_OPEN_FILE ) ;
2014-02-21 03:01:44 +01:00
List < String > sexts ;
2017-03-05 16:44:50 +01:00
ResourceLoader : : get_recognized_extensions_for_type ( " Script " , & sexts ) ;
for ( List < String > : : Element * E = sexts . front ( ) ; E ; E = E - > next ( ) ) {
file_script - > add_filter ( " *. " + E - > get ( ) ) ;
2014-02-21 03:01:44 +01:00
}
gui_base - > add_child ( file_script ) ;
2017-03-05 16:44:50 +01:00
file_script - > connect ( " file_selected " , this , " _dialog_action " ) ;
2014-02-21 03:01:44 +01:00
2017-03-05 16:44:50 +01:00
property_forward - > connect ( " pressed " , this , " _property_editor_forward " ) ;
property_back - > connect ( " pressed " , this , " _property_editor_back " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
file_menu - > get_popup ( ) - > connect ( " id_pressed " , this , " _menu_option " ) ;
object_menu - > get_popup ( ) - > connect ( " id_pressed " , this , " _menu_option " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
settings_menu - > get_popup ( ) - > connect ( " id_pressed " , this , " _menu_option " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
file - > connect ( " file_selected " , this , " _dialog_action " ) ;
file_templates - > connect ( " file_selected " , this , " _dialog_action " ) ;
property_editor - > connect ( " resource_selected " , this , " _resource_selected " ) ;
property_editor - > connect ( " property_keyed " , this , " _property_keyed " ) ;
2016-01-18 00:03:57 +01:00
2014-02-10 02:10:30 +01:00
//plugin stuff
2017-03-05 16:44:50 +01:00
file_server = memnew ( EditorFileServer ) ;
2016-01-18 00:03:57 +01:00
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( AnimationPlayerEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( CanvasItemEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( SpatialEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( ScriptEditorPlugin ( this ) ) ) ;
2017-01-21 23:00:25 +01:00
2017-01-25 18:30:40 +01:00
EditorAudioBuses * audio_bus_editor = EditorAudioBuses : : register_editor ( ) ;
2017-01-21 23:00:25 +01:00
2016-08-03 00:11:05 +02:00
ScriptTextEditor : : register_editor ( ) ; //register one for text scripts
2016-06-10 03:47:43 +02:00
if ( StreamPeerSSL : : is_available ( ) ) {
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( AssetLibraryEditorPlugin ( this ) ) ) ;
2016-06-10 03:47:43 +02:00
} else {
WARN_PRINT ( " Asset Library not available, as it requires SSL to work. " ) ;
}
2017-08-26 15:32:15 +02:00
//add interface before adding plugins
editor_interface = memnew ( EditorInterface ) ;
add_child ( editor_interface ) ;
2016-01-18 00:03:57 +01:00
//more visually meaningful to have this later
raise_bottom_panel_item ( AnimationPlayerEditor : : singleton ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( ShaderEditorPlugin ( this ) ) ) ;
2017-08-26 17:46:49 +02:00
// FIXME: Disabled for Godot 3.0 as made incompatible, it needs to be ported to the new API.
//add_editor_plugin(memnew(ShaderGraphEditorPlugin(this)));
2016-10-07 16:31:18 +02:00
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( CameraEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( ThemeEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( MultiMeshEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( MeshInstanceEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( AnimationTreeEditorPlugin ( this ) ) ) ;
2017-08-15 16:41:17 +02:00
add_editor_plugin ( memnew ( MeshLibraryEditorPlugin ( this ) ) ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( StyleBoxEditorPlugin ( this ) ) ) ;
2018-02-21 13:38:21 +01:00
add_editor_plugin ( memnew ( SpriteEditorPlugin ( this ) ) ) ;
2018-02-21 21:23:27 +01:00
add_editor_plugin ( memnew ( Skeleton2DEditorPlugin ( this ) ) ) ;
2017-04-07 04:36:37 +02:00
add_editor_plugin ( memnew ( ParticlesEditorPlugin ( this ) ) ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( ResourcePreloaderEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( ItemListEditorPlugin ( this ) ) ) ;
2018-04-28 02:52:15 +02:00
add_editor_plugin ( memnew ( Polygon3DEditorPlugin ( this ) ) ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( CollisionPolygon2DEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( TileSetEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( TileMapEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( SpriteFramesEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( TextureRegionEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( Particles2DEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( GIProbeEditorPlugin ( this ) ) ) ;
2017-12-14 12:59:46 +01:00
add_editor_plugin ( memnew ( BakedLightmapEditorPlugin ( this ) ) ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( Path2DEditorPlugin ( this ) ) ) ;
2017-05-25 00:11:20 +02:00
add_editor_plugin ( memnew ( PathEditorPlugin ( this ) ) ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( Line2DEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( Polygon2DEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( LightOccluder2DEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( NavigationPolygonEditorPlugin ( this ) ) ) ;
2017-06-13 23:47:34 +02:00
add_editor_plugin ( memnew ( GradientEditorPlugin ( this ) ) ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( CollisionShape2DEditorPlugin ( this ) ) ) ;
2017-04-30 16:27:10 +02:00
add_editor_plugin ( memnew ( CurveEditorPlugin ( this ) ) ) ;
2017-03-05 16:44:50 +01:00
add_editor_plugin ( memnew ( TextureEditorPlugin ( this ) ) ) ;
2018-02-21 13:38:21 +01:00
add_editor_plugin ( memnew ( AudioBusesEditorPlugin ( audio_bus_editor ) ) ) ;
2017-08-26 17:46:49 +02:00
add_editor_plugin ( memnew ( AudioBusesEditorPlugin ( audio_bus_editor ) ) ) ;
2017-02-28 13:10:29 +01:00
add_editor_plugin ( memnew ( NavigationMeshEditorPlugin ( this ) ) ) ;
2017-10-03 18:49:32 +02:00
add_editor_plugin ( memnew ( SkeletonEditorPlugin ( this ) ) ) ;
add_editor_plugin ( memnew ( PhysicalBonePlugin ( this ) ) ) ;
2017-08-26 17:46:49 +02:00
// FIXME: Disabled as (according to reduz) users were complaining that it gets in the way
// Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored.
//add_editor_plugin(memnew(MaterialEditorPlugin(this)));
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < EditorPlugins : : get_plugin_count ( ) ; i + + )
add_editor_plugin ( EditorPlugins : : create ( i , this ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < plugin_init_callback_count ; i + + ) {
2016-08-07 00:00:54 +02:00
plugin_init_callbacks [ i ] ( ) ;
}
2015-05-31 06:59:42 +02:00
2017-06-09 05:23:50 +02:00
resource_preview - > add_preview_generator ( Ref < EditorTexturePreviewPlugin > ( memnew ( EditorTexturePreviewPlugin ) ) ) ;
resource_preview - > add_preview_generator ( Ref < EditorPackedScenePreviewPlugin > ( memnew ( EditorPackedScenePreviewPlugin ) ) ) ;
resource_preview - > add_preview_generator ( Ref < EditorMaterialPreviewPlugin > ( memnew ( EditorMaterialPreviewPlugin ) ) ) ;
resource_preview - > add_preview_generator ( Ref < EditorScriptPreviewPlugin > ( memnew ( EditorScriptPreviewPlugin ) ) ) ;
2017-08-26 17:46:49 +02:00
// FIXME: Needs to be rewritten for AudioStream in Godot 3.0+
2017-06-09 05:23:50 +02:00
//resource_preview->add_preview_generator( Ref<EditorSamplePreviewPlugin>( memnew(EditorSamplePreviewPlugin )));
resource_preview - > add_preview_generator ( Ref < EditorMeshPreviewPlugin > ( memnew ( EditorMeshPreviewPlugin ) ) ) ;
resource_preview - > add_preview_generator ( Ref < EditorBitmapPreviewPlugin > ( memnew ( EditorBitmapPreviewPlugin ) ) ) ;
2016-08-07 00:00:54 +02:00
2017-09-22 14:20:28 +02:00
{
Ref < SpatialMaterialConversionPlugin > spatial_mat_convert ;
spatial_mat_convert . instance ( ) ;
resource_conversion_plugins . push_back ( spatial_mat_convert ) ;
2017-10-12 13:12:50 +02:00
2017-11-14 19:44:51 +01:00
Ref < CanvasItemMaterialConversionPlugin > canvas_item_mat_convert ;
canvas_item_mat_convert . instance ( ) ;
resource_conversion_plugins . push_back ( canvas_item_mat_convert ) ;
2017-10-12 13:12:50 +02:00
Ref < ParticlesMaterialConversionPlugin > particles_mat_convert ;
particles_mat_convert . instance ( ) ;
resource_conversion_plugins . push_back ( particles_mat_convert ) ;
2017-09-22 14:20:28 +02:00
}
2017-03-05 16:44:50 +01:00
circle_step_msec = OS : : get_singleton ( ) - > get_ticks_msec ( ) ;
circle_step_frame = Engine : : get_singleton ( ) - > get_frames_drawn ( ) ;
circle_step = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
editor_plugin_screen = NULL ;
2016-03-30 01:02:53 +02:00
editor_plugins_over = memnew ( EditorPluginList ) ;
2017-10-29 20:32:09 +01:00
editor_plugins_force_over = memnew ( EditorPluginList ) ;
2017-06-08 19:57:35 +02:00
editor_plugins_force_input_forwarding = memnew ( EditorPluginList ) ;
2014-02-10 02:10:30 +01:00
2017-12-15 12:38:24 +01:00
Ref < EditorExportTextSceneToBinaryPlugin > export_text_to_binary_plugin ;
export_text_to_binary_plugin . instance ( ) ;
EditorExport : : get_singleton ( ) - > add_export_plugin ( export_text_to_binary_plugin ) ;
2014-02-10 02:10:30 +01:00
_edit_current ( ) ;
2017-03-05 16:44:50 +01:00
current = NULL ;
2014-02-10 02:10:30 +01:00
PhysicsServer : : get_singleton ( ) - > set_active ( false ) ; // no physics by default if editor
Physics2DServer : : get_singleton ( ) - > set_active ( false ) ; // no physics by default if editor
ScriptServer : : set_scripting_enabled ( false ) ; // no scripting by default if editor
2017-03-05 16:44:50 +01:00
reference_resource_mem = true ;
save_external_resources_mem = true ;
2014-02-10 02:10:30 +01:00
set_process ( true ) ;
2017-03-05 16:44:50 +01:00
open_imported = memnew ( ConfirmationDialog ) ;
2017-02-05 00:31:15 +01:00
open_imported - > get_ok ( ) - > set_text ( TTR ( " Open Anyway " ) ) ;
2017-08-23 22:25:14 +02:00
new_inherited_button = open_imported - > add_button ( TTR ( " New Inherited " ) , ! OS : : get_singleton ( ) - > get_swap_ok_cancel ( ) , " inherit " ) ;
2017-03-05 16:44:50 +01:00
open_imported - > connect ( " confirmed " , this , " _open_imported " ) ;
open_imported - > connect ( " custom_action " , this , " _inherit_imported " ) ;
2017-02-05 00:31:15 +01:00
gui_base - > add_child ( open_imported ) ;
2017-03-05 16:44:50 +01:00
saved_version = 1 ;
unsaved_cache = true ;
_last_instanced_scene = NULL ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
quick_open = memnew ( EditorQuickOpen ) ;
2014-02-10 02:10:30 +01:00
gui_base - > add_child ( quick_open ) ;
2017-03-05 16:44:50 +01:00
quick_open - > connect ( " quick_open " , this , " _quick_opened " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
quick_run = memnew ( EditorQuickOpen ) ;
2014-02-10 02:10:30 +01:00
gui_base - > add_child ( quick_run ) ;
2017-03-05 16:44:50 +01:00
quick_run - > connect ( " quick_open " , this , " _quick_run " ) ;
2014-02-10 02:10:30 +01:00
_update_recent_scenes ( ) ;
editor_data . restore_editor_global_states ( ) ;
2017-03-05 16:44:50 +01:00
convert_old = false ;
opening_prev = false ;
2014-02-10 02:10:30 +01:00
set_process_unhandled_input ( true ) ;
2017-03-05 16:44:50 +01:00
_playing_edited = false ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
load_errors = memnew ( RichTextLabel ) ;
load_error_dialog = memnew ( AcceptDialog ) ;
2014-02-10 02:10:30 +01:00
load_error_dialog - > add_child ( load_errors ) ;
2016-05-04 03:25:37 +02:00
load_error_dialog - > set_title ( TTR ( " Load Errors " ) ) ;
2016-06-28 00:59:33 +02:00
gui_base - > add_child ( load_error_dialog ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
EditorFileSystem : : get_singleton ( ) - > connect ( " sources_changed " , this , " _sources_changed " ) ;
EditorFileSystem : : get_singleton ( ) - > connect ( " filesystem_changed " , this , " _fs_changed " ) ;
2017-08-31 23:57:03 +02:00
EditorFileSystem : : get_singleton ( ) - > connect ( " resources_reimported " , this , " _resources_reimported " ) ;
2014-02-10 02:10:30 +01:00
2018-02-25 17:04:16 +01:00
_build_icon_type_cache ( ) ;
2014-02-10 02:10:30 +01:00
2014-02-23 00:28:19 +01:00
Node : : set_human_readable_collision_renaming ( true ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
pick_main_scene = memnew ( ConfirmationDialog ) ;
2016-06-28 00:59:33 +02:00
gui_base - > add_child ( pick_main_scene ) ;
2017-08-23 22:25:14 +02:00
pick_main_scene - > get_ok ( ) - > set_text ( TTR ( " Select " ) ) ;
2017-03-05 16:44:50 +01:00
pick_main_scene - > connect ( " confirmed " , this , " _menu_option " , varray ( SETTINGS_PICK_MAIN_SCENE ) ) ;
2015-06-14 03:12:53 +02:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < _init_callbacks . size ( ) ; i + + )
2014-02-25 13:31:47 +01:00
_init_callbacks [ i ] ( ) ;
2014-02-10 02:10:30 +01:00
2015-06-22 05:03:19 +02:00
editor_data . add_edited_scene ( - 1 ) ;
editor_data . set_edited_scene ( 0 ) ;
_update_scene_tabs ( ) ;
2017-07-23 16:44:42 +02:00
import_dock - > initialize_import_options ( ) ;
2016-02-28 03:10:44 +01:00
{
2017-03-05 16:44:50 +01:00
_initializing_addons = true ;
2017-04-23 10:32:52 +02:00
Vector < String > addons ;
2017-10-05 20:34:34 +02:00
if ( ProjectSettings : : get_singleton ( ) - > has_setting ( " editor_plugins/enabled " ) ) {
2017-07-19 22:00:46 +02:00
addons = ProjectSettings : : get_singleton ( ) - > get ( " editor_plugins/enabled " ) ;
2017-04-23 10:32:52 +02:00
}
2016-02-28 03:10:44 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < addons . size ( ) ; i + + ) {
set_addon_plugin_enabled ( addons [ i ] , true ) ;
2016-02-28 03:10:44 +01:00
}
2017-03-05 16:44:50 +01:00
_initializing_addons = false ;
2016-02-28 03:10:44 +01:00
}
2016-06-13 15:10:50 +02:00
FileAccess : : set_file_close_fail_notify_callback ( _file_access_close_error_notify ) ;
2015-06-22 05:03:19 +02:00
2017-03-05 16:44:50 +01:00
waiting_for_first_scan = true ;
2017-03-06 20:11:56 +01:00
_dimming = false ;
_dim_time = 0.0f ;
_dim_timer = memnew ( Timer ) ;
_dim_timer - > set_wait_time ( 0.01666f ) ;
_dim_timer - > connect ( " timeout " , this , " _dim_timeout " ) ;
add_child ( _dim_timer ) ;
2017-05-16 21:26:32 +02:00
2017-11-14 23:02:31 +01:00
print_handler . printfunc = _print_handler ;
print_handler . userdata = this ;
add_print_handler ( & print_handler ) ;
2017-07-15 14:35:29 +02:00
ED_SHORTCUT ( " editor/editor_2d " , TTR ( " Open 2D Editor " ) , KEY_F1 ) ;
ED_SHORTCUT ( " editor/editor_3d " , TTR ( " Open 3D Editor " ) , KEY_F2 ) ;
ED_SHORTCUT ( " editor/editor_script " , TTR ( " Open Script Editor " ) , KEY_F3 ) ; //hack neded for script editor F3 search to work :) Assign like this or don't use F3
ED_SHORTCUT ( " editor/editor_help " , TTR ( " Search Help " ) , KEY_F4 ) ;
2017-05-16 21:26:32 +02:00
ED_SHORTCUT ( " editor/editor_assetlib " , TTR ( " Open Asset Library " ) ) ;
ED_SHORTCUT ( " editor/editor_next " , TTR ( " Open the next Editor " ) ) ;
ED_SHORTCUT ( " editor/editor_prev " , TTR ( " Open the previous Editor " ) ) ;
2014-02-10 02:10:30 +01:00
}
2016-03-09 00:00:52 +01:00
EditorNode : : ~ EditorNode ( ) {
2016-05-21 15:29:25 +02:00
2017-11-14 23:02:31 +01:00
remove_print_handler ( & print_handler ) ;
2017-03-05 16:44:50 +01:00
memdelete ( EditorHelp : : get_doc_data ( ) ) ;
2014-02-10 02:10:30 +01:00
memdelete ( editor_selection ) ;
2016-03-30 01:02:53 +02:00
memdelete ( editor_plugins_over ) ;
2017-10-29 20:32:09 +01:00
memdelete ( editor_plugins_force_over ) ;
2017-06-08 19:57:35 +02:00
memdelete ( editor_plugins_force_input_forwarding ) ;
2014-02-10 02:10:30 +01:00
memdelete ( file_server ) ;
2017-08-24 18:51:28 +02:00
memdelete ( progress_hb ) ;
2014-02-10 02:10:30 +01:00
EditorSettings : : destroy ( ) ;
}
2016-03-30 01:02:53 +02:00
/*
* EDITOR PLUGIN LIST
*/
void EditorPluginList : : make_visible ( bool p_visible ) {
2016-09-10 21:44:03 +02:00
for ( int i = 0 ; i < plugins_list . size ( ) ; i + + ) {
plugins_list [ i ] - > make_visible ( p_visible ) ;
2016-03-30 01:02:53 +02:00
}
}
2017-03-05 16:44:50 +01:00
void EditorPluginList : : edit ( Object * p_object ) {
2016-09-10 21:44:03 +02:00
for ( int i = 0 ; i < plugins_list . size ( ) ; i + + ) {
plugins_list [ i ] - > edit ( p_object ) ;
2016-03-30 01:02:53 +02:00
}
}
2017-10-15 22:33:25 +02:00
bool EditorPluginList : : forward_gui_input ( const Ref < InputEvent > & p_event ) {
2016-09-10 21:44:03 +02:00
2016-03-30 01:02:53 +02:00
bool discard = false ;
2016-09-10 21:44:03 +02:00
for ( int i = 0 ; i < plugins_list . size ( ) ; i + + ) {
2017-10-15 22:33:25 +02:00
if ( plugins_list [ i ] - > forward_canvas_gui_input ( p_event ) ) {
2016-09-10 21:44:03 +02:00
discard = true ;
2016-03-30 01:02:53 +02:00
}
}
2016-09-10 21:44:03 +02:00
2016-03-30 01:02:53 +02:00
return discard ;
}
2017-06-08 19:57:35 +02:00
bool EditorPluginList : : forward_spatial_gui_input ( Camera * p_camera , const Ref < InputEvent > & p_event , bool serve_when_force_input_enabled ) {
2016-03-30 01:02:53 +02:00
bool discard = false ;
2016-09-10 21:44:03 +02:00
for ( int i = 0 ; i < plugins_list . size ( ) ; i + + ) {
2017-06-08 19:57:35 +02:00
if ( ( ! serve_when_force_input_enabled ) & & plugins_list [ i ] - > is_input_event_forwarding_always_enabled ( ) ) {
continue ;
}
2017-01-08 20:28:12 +01:00
if ( plugins_list [ i ] - > forward_spatial_gui_input ( p_camera , p_event ) ) {
2016-09-10 21:44:03 +02:00
discard = true ;
2016-03-30 01:02:53 +02:00
}
}
2016-09-10 21:44:03 +02:00
2016-03-30 01:02:53 +02:00
return discard ;
}
2017-10-29 20:32:09 +01:00
void EditorPluginList : : forward_draw_over_viewport ( Control * p_overlay ) {
2016-09-10 21:44:03 +02:00
for ( int i = 0 ; i < plugins_list . size ( ) ; i + + ) {
2017-10-29 20:32:09 +01:00
plugins_list [ i ] - > forward_draw_over_viewport ( p_overlay ) ;
}
}
void EditorPluginList : : forward_force_draw_over_viewport ( Control * p_overlay ) {
for ( int i = 0 ; i < plugins_list . size ( ) ; i + + ) {
plugins_list [ i ] - > forward_force_draw_over_viewport ( p_overlay ) ;
2016-09-10 21:44:03 +02:00
}
}
2017-06-08 19:57:35 +02:00
void EditorPluginList : : add_plugin ( EditorPlugin * p_plugin ) {
plugins_list . push_back ( p_plugin ) ;
}
2016-03-30 01:02:53 +02:00
bool EditorPluginList : : empty ( ) {
return plugins_list . empty ( ) ;
}
void EditorPluginList : : clear ( ) {
plugins_list . clear ( ) ;
}
EditorPluginList : : EditorPluginList ( ) {
}
EditorPluginList : : ~ EditorPluginList ( ) {
}