2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* editor_settings.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
2016-01-01 14:50:53 +01:00
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
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. */
/*************************************************************************/
# include "editor_settings.h"
# include "os/os.h"
# include "os/dir_access.h"
# include "os/file_access.h"
2014-10-07 06:31:49 +02:00
2014-02-10 02:10:30 +01:00
# include "version.h"
# include "scene/main/scene_main_loop.h"
# include "os/os.h"
# include "scene/main/node.h"
# include "io/resource_loader.h"
# include "io/resource_saver.h"
# include "scene/main/viewport.h"
# include "io/config_file.h"
# include "editor_node.h"
# include "globals.h"
Ref < EditorSettings > EditorSettings : : singleton = NULL ;
EditorSettings * EditorSettings : : get_singleton ( ) {
return singleton . ptr ( ) ;
}
bool EditorSettings : : _set ( const StringName & p_name , const Variant & p_value ) {
_THREAD_SAFE_METHOD_
if ( p_value . get_type ( ) = = Variant : : NIL )
props . erase ( p_name ) ;
else {
if ( props . has ( p_name ) )
props [ p_name ] . variant = p_value ;
else
props [ p_name ] = VariantContainer ( p_value , last_order + + ) ;
}
emit_signal ( " settings_changed " ) ;
return true ;
}
bool EditorSettings : : _get ( const StringName & p_name , Variant & r_ret ) const {
_THREAD_SAFE_METHOD_
const VariantContainer * v = props . getptr ( p_name ) ;
if ( ! v )
return false ;
r_ret = v - > variant ;
return true ;
}
struct _EVCSort {
String name ;
Variant : : Type type ;
int order ;
bool operator < ( const _EVCSort & p_vcs ) const { return order < p_vcs . order ; }
} ;
void EditorSettings : : _get_property_list ( List < PropertyInfo > * p_list ) const {
_THREAD_SAFE_METHOD_
const String * k = NULL ;
Set < _EVCSort > vclist ;
while ( ( k = props . next ( k ) ) ) {
const VariantContainer * v = props . getptr ( * k ) ;
if ( v - > hide_from_editor )
continue ;
_EVCSort vc ;
vc . name = * k ;
vc . order = v - > order ;
vc . type = v - > variant . get_type ( ) ;
vclist . insert ( vc ) ;
}
for ( Set < _EVCSort > : : Element * E = vclist . front ( ) ; E ; E = E - > next ( ) ) {
int pinfo = PROPERTY_USAGE_STORAGE ;
if ( ! E - > get ( ) . name . begins_with ( " _ " ) )
pinfo | = PROPERTY_USAGE_EDITOR ;
PropertyInfo pi ( E - > get ( ) . type , E - > get ( ) . name ) ;
pi . usage = pinfo ;
if ( hints . has ( E - > get ( ) . name ) )
pi = hints [ E - > get ( ) . name ] ;
p_list - > push_back ( pi ) ;
}
}
bool EditorSettings : : has ( String p_var ) const {
_THREAD_SAFE_METHOD_
return props . has ( p_var ) ;
}
void EditorSettings : : erase ( String p_var ) {
_THREAD_SAFE_METHOD_
props . erase ( p_var ) ;
}
void EditorSettings : : raise_order ( const String & p_name ) {
_THREAD_SAFE_METHOD_
ERR_FAIL_COND ( ! props . has ( p_name ) ) ;
props [ p_name ] . order = + + last_order ;
}
Variant _EDITOR_DEF ( const String & p_var , const Variant & p_default ) {
if ( EditorSettings : : get_singleton ( ) - > has ( p_var ) )
return EditorSettings : : get_singleton ( ) - > get ( p_var ) ;
EditorSettings : : get_singleton ( ) - > set ( p_var , p_default ) ;
return p_default ;
}
void EditorSettings : : create ( ) {
if ( singleton . ptr ( ) )
return ; //pointless
DirAccess * dir = NULL ;
Variant meta ;
String config_path ;
String config_dir ;
String config_file = " editor_settings.xml " ;
2016-02-22 00:15:47 +01:00
Ref < ConfigFile > extra_config = memnew ( ConfigFile ) ;
2014-02-10 02:10:30 +01:00
2016-02-19 08:41:08 +01:00
String exe_path = OS : : get_singleton ( ) - > get_executable_path ( ) . get_base_dir ( ) ;
DirAccess * d = DirAccess : : create_for_path ( exe_path ) ;
if ( d - > file_exists ( exe_path + " /._sc_ " ) ) {
2014-02-10 02:10:30 +01:00
2016-02-19 08:41:08 +01:00
// editor is self contained
config_path = exe_path ;
config_dir = " editor_data " ;
2016-02-22 00:15:47 +01:00
extra_config - > load ( exe_path + " /._sc_ " ) ;
2016-02-19 08:41:08 +01:00
} else {
if ( OS : : get_singleton ( ) - > has_environment ( " APPDATA " ) ) {
// Most likely under windows, save here
config_path = OS : : get_singleton ( ) - > get_environment ( " APPDATA " ) ;
config_dir = String ( _MKSTR ( VERSION_SHORT_NAME ) ) . capitalize ( ) ;
} else if ( OS : : get_singleton ( ) - > has_environment ( " HOME " ) ) {
config_path = OS : : get_singleton ( ) - > get_environment ( " HOME " ) ;
config_dir = " . " + String ( _MKSTR ( VERSION_SHORT_NAME ) ) . to_lower ( ) ;
}
} ;
2014-02-10 02:10:30 +01:00
ObjectTypeDB : : register_type < EditorSettings > ( ) ; //otherwise it can't be unserialized
String config_file_path ;
if ( config_path ! = " " ) {
dir = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
if ( dir - > change_dir ( config_path ) ! = OK ) {
ERR_PRINT ( " Cannot find path for config directory! " ) ;
memdelete ( dir ) ;
goto fail ;
}
if ( dir - > change_dir ( config_dir ) ! = OK ) {
dir - > make_dir ( config_dir ) ;
if ( dir - > change_dir ( config_dir ) ! = OK ) {
ERR_PRINT ( " Cannot create config directory! " ) ;
memdelete ( dir ) ;
goto fail ;
}
}
if ( dir - > change_dir ( " templates " ) ! = OK ) {
dir - > make_dir ( " templates " ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
if ( dir - > change_dir ( " tmp " ) ! = OK ) {
dir - > make_dir ( " tmp " ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
2015-06-06 14:44:38 +02:00
if ( dir - > change_dir ( " config " ) ! = OK ) {
dir - > make_dir ( " config " ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
dir - > change_dir ( " config " ) ;
String pcp = Globals : : get_singleton ( ) - > get_resource_path ( ) ;
if ( pcp . ends_with ( " / " ) )
pcp = config_path . substr ( 0 , pcp . size ( ) - 1 ) ;
pcp = pcp . get_file ( ) + " - " + pcp . md5_text ( ) ;
if ( dir - > change_dir ( pcp ) ) {
dir - > make_dir ( pcp ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
dir - > change_dir ( " .. " ) ;
2014-02-10 02:10:30 +01:00
// path at least is validated, so validate config file
config_file_path = config_path + " / " + config_dir + " / " + config_file ;
if ( ! dir - > file_exists ( config_file ) ) {
memdelete ( dir ) ;
2016-05-04 03:25:37 +02:00
WARN_PRINT ( " Config file does not exist, creating. " ) ;
2014-02-10 02:10:30 +01:00
goto fail ;
}
memdelete ( dir ) ;
2016-05-04 03:25:37 +02:00
singleton = ResourceLoader : : load ( config_file_path , TTR ( " EditorSettings " ) ) ;
2014-02-10 02:10:30 +01:00
if ( singleton . is_null ( ) ) {
WARN_PRINT ( " Could not open config file. " ) ;
goto fail ;
}
singleton - > config_file_path = config_file_path ;
2015-06-06 14:44:38 +02:00
singleton - > project_config_path = pcp ;
2014-02-10 02:10:30 +01:00
singleton - > settings_path = config_path + " / " + config_dir ;
if ( OS : : get_singleton ( ) - > is_stdout_verbose ( ) ) {
2016-05-04 15:28:37 +02:00
print_line ( " EditorSettings: Load OK! " ) ;
2014-02-10 02:10:30 +01:00
}
2015-08-06 07:37:40 +02:00
singleton - > setup_network ( ) ;
2015-06-06 14:44:38 +02:00
singleton - > load_favorites ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
fail :
2016-02-22 00:15:47 +01:00
// patch init projects
if ( extra_config - > has_section ( " init_projects " ) ) {
Vector < String > list = extra_config - > get_value ( " init_projects " , " list " ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
list [ i ] = exe_path + " / " + list [ i ] ;
} ;
extra_config - > set_value ( " init_projects " , " list " , list ) ;
} ;
2014-02-10 02:10:30 +01:00
singleton = Ref < EditorSettings > ( memnew ( EditorSettings ) ) ;
singleton - > config_file_path = config_file_path ;
2015-04-29 01:36:46 +02:00
singleton - > settings_path = config_path + " / " + config_dir ;
2016-02-22 00:15:47 +01:00
singleton - > _load_defaults ( extra_config ) ;
2015-08-06 07:37:40 +02:00
singleton - > setup_network ( ) ;
2014-02-10 02:10:30 +01:00
}
String EditorSettings : : get_settings_path ( ) const {
return settings_path ;
}
2015-08-06 07:37:40 +02:00
void EditorSettings : : setup_network ( ) {
List < IP_Address > local_ip ;
IP : : get_singleton ( ) - > get_local_addresses ( & local_ip ) ;
String lip ;
String hint ;
String current = get ( " network/debug_host " ) ;
for ( List < IP_Address > : : Element * E = local_ip . front ( ) ; E ; E = E - > next ( ) ) {
String ip = E - > get ( ) ;
if ( ip = = " 127.0.0.1 " )
continue ;
if ( lip ! = " " )
lip = ip ;
if ( ip = = current )
lip = current ; //so it saves
if ( hint ! = " " )
hint + = " , " ;
hint + = ip ;
}
set ( " network/debug_host " , lip ) ;
add_property_hint ( PropertyInfo ( Variant : : STRING , " network/debug_host " , PROPERTY_HINT_ENUM , hint ) ) ;
}
2014-02-10 02:10:30 +01:00
void EditorSettings : : save ( ) {
//_THREAD_SAFE_METHOD_
if ( ! singleton . ptr ( ) )
return ;
if ( singleton - > config_file_path = = " " ) {
ERR_PRINT ( " Cannot save EditorSettings config, no valid path " ) ;
return ;
}
Error err = ResourceSaver : : save ( singleton - > config_file_path , singleton ) ;
if ( err ! = OK ) {
ERR_PRINT ( " Can't Save! " ) ;
return ;
}
if ( OS : : get_singleton ( ) - > is_stdout_verbose ( ) ) {
2016-05-04 15:28:37 +02:00
print_line ( " EditorSettings Save OK! " ) ;
2014-02-10 02:10:30 +01:00
}
}
void EditorSettings : : destroy ( ) {
if ( ! singleton . ptr ( ) )
return ;
save ( ) ;
singleton = Ref < EditorSettings > ( ) ;
}
2016-02-22 00:15:47 +01:00
void EditorSettings : : _load_defaults ( Ref < ConfigFile > p_extra_config ) {
2014-02-10 02:10:30 +01:00
_THREAD_SAFE_METHOD_
2014-04-05 17:39:30 +02:00
set ( " global/font " , " " ) ;
hints [ " global/font " ] = PropertyInfo ( Variant : : STRING , " global/font " , PROPERTY_HINT_GLOBAL_FILE , " *.fnt " ) ;
2014-11-01 07:06:29 +01:00
set ( " global/autoscan_project_path " , " " ) ;
hints [ " global/autoscan_project_path " ] = PropertyInfo ( Variant : : STRING , " global/autoscan_project_path " , PROPERTY_HINT_GLOBAL_DIR ) ;
2014-08-25 03:20:45 +02:00
set ( " global/default_project_path " , " " ) ;
hints [ " global/default_project_path " ] = PropertyInfo ( Variant : : STRING , " global/default_project_path " , PROPERTY_HINT_GLOBAL_DIR ) ;
set ( " global/default_project_export_path " , " " ) ;
hints [ " global/default_project_export_path " ] = PropertyInfo ( Variant : : STRING , " global/default_project_export_path " , PROPERTY_HINT_GLOBAL_DIR ) ;
2015-11-18 08:47:41 +01:00
set ( " global/show_script_in_scene_tabs " , false ) ;
2014-02-10 02:10:30 +01:00
set ( " text_editor/background_color " , Color : : html ( " 3b000000 " ) ) ;
2016-04-05 18:06:56 +02:00
set ( " text_editor/caret_color " , Color : : html ( " aaaaaa " ) ) ;
2016-04-08 21:05:50 +02:00
set ( " text_editor/line_number_color " , Color : : html ( " 66aaaaaa " ) ) ;
2014-02-10 02:10:30 +01:00
set ( " text_editor/text_color " , Color : : html ( " aaaaaa " ) ) ;
set ( " text_editor/text_selected_color " , Color : : html ( " 000000 " ) ) ;
set ( " text_editor/keyword_color " , Color : : html ( " ffffb3 " ) ) ;
set ( " text_editor/base_type_color " , Color : : html ( " a4ffd4 " ) ) ;
set ( " text_editor/engine_type_color " , Color : : html ( " 83d3ff " ) ) ;
2016-04-02 21:46:42 +02:00
set ( " text_editor/function_color " , Color : : html ( " 66a2ce " ) ) ;
2016-04-05 16:50:54 +02:00
set ( " text_editor/member_variable_color " , Color : : html ( " e64e59 " ) ) ;
2014-02-10 02:10:30 +01:00
set ( " text_editor/comment_color " , Color : : html ( " 983d1b " ) ) ;
set ( " text_editor/string_color " , Color : : html ( " ef6ebe " ) ) ;
2016-03-21 16:45:38 +01:00
set ( " text_editor/number_color " , Color : : html ( " EB9532 " ) ) ;
2014-02-10 02:10:30 +01:00
set ( " text_editor/symbol_color " , Color : : html ( " badfff " ) ) ;
set ( " text_editor/selection_color " , Color : : html ( " 7b5dbe " ) ) ;
2014-12-17 05:53:34 +01:00
set ( " text_editor/brace_mismatch_color " , Color ( 1 , 0.2 , 0.2 ) ) ;
2014-12-27 03:28:16 +01:00
set ( " text_editor/current_line_color " , Color ( 0.3 , 0.5 , 0.8 , 0.15 ) ) ;
2016-03-16 22:20:42 +01:00
set ( " text_editor/word_highlighted_color " , Color ( 0.8 , 0.9 , 0.9 , 0.15 ) ) ;
2014-02-10 02:10:30 +01:00
2016-03-30 20:32:45 +02:00
set ( " text_editor/syntax_highlighting " , true ) ;
2016-03-16 22:20:42 +01:00
set ( " text_editor/highlight_all_occurrences " , true ) ;
2016-03-07 03:32:51 +01:00
set ( " text_editor/scroll_past_end_of_file " , false ) ;
2016-03-11 19:10:01 +01:00
set ( " text_editor/tab_size " , 4 ) ;
hints [ " text_editor/tab_size " ] = PropertyInfo ( Variant : : INT , " text_editor/tab_size " , PROPERTY_HINT_RANGE , " 1, 64, 1 " ) ; // size of 0 crashes.
2016-03-18 13:49:18 +01:00
set ( " text_editor/draw_tabs " , true ) ;
2016-03-11 19:10:01 +01:00
2016-03-30 20:16:52 +02:00
set ( " text_editor/show_line_numbers " , true ) ;
2016-04-23 20:21:34 +02:00
set ( " text_editor/trim_trailing_whitespace_on_save " , false ) ;
2014-02-10 02:10:30 +01:00
set ( " text_editor/idle_parse_delay " , 2 ) ;
set ( " text_editor/create_signal_callbacks " , true ) ;
2015-05-05 04:32:40 +02:00
set ( " text_editor/autosave_interval_secs " , 0 ) ;
2015-06-22 05:03:19 +02:00
2014-04-05 17:39:30 +02:00
set ( " text_editor/font " , " " ) ;
hints [ " text_editor/font " ] = PropertyInfo ( Variant : : STRING , " text_editor/font " , PROPERTY_HINT_GLOBAL_FILE , " *.fnt " ) ;
2014-08-25 03:20:45 +02:00
set ( " text_editor/auto_brace_complete " , false ) ;
2015-06-22 05:03:19 +02:00
set ( " text_editor/restore_scripts_on_load " , true ) ;
2014-04-05 17:39:30 +02:00
2014-02-10 02:10:30 +01:00
2015-01-11 06:08:32 +01:00
set ( " scenetree_editor/duplicate_node_name_num_separator " , 0 ) ;
hints [ " scenetree_editor/duplicate_node_name_num_separator " ] = PropertyInfo ( Variant : : INT , " scenetree_editor/duplicate_node_name_num_separator " , PROPERTY_HINT_ENUM , " None,Space,Underscore,Dash " ) ;
2015-07-10 04:51:49 +02:00
set ( " gridmap_editor/pick_distance " , 5000.0 ) ;
2015-01-11 06:08:32 +01:00
2014-02-10 02:10:30 +01:00
set ( " 3d_editor/default_fov " , 45.0 ) ;
set ( " 3d_editor/default_z_near " , 0.1 ) ;
set ( " 3d_editor/default_z_far " , 500.0 ) ;
2014-03-31 05:07:21 +02:00
set ( " 3d_editor/navigation_scheme " , 0 ) ;
2014-03-31 09:52:27 +02:00
hints [ " 3d_editor/navigation_scheme " ] = PropertyInfo ( Variant : : INT , " 3d_editor/navigation_scheme " , PROPERTY_HINT_ENUM , " Godot,Maya,Modo " ) ;
2014-12-28 14:01:08 +01:00
set ( " 3d_editor/zoom_style " , 0 ) ;
hints [ " 3d_editor/zoom_style " ] = PropertyInfo ( Variant : : INT , " 3d_editor/zoom_style " , PROPERTY_HINT_ENUM , " Vertical, Horizontal " ) ;
2014-02-10 02:10:30 +01:00
set ( " 3d_editor/orbit_modifier " , 0 ) ;
hints [ " 3d_editor/orbit_modifier " ] = PropertyInfo ( Variant : : INT , " 3d_editor/orbit_modifier " , PROPERTY_HINT_ENUM , " None,Shift,Alt,Meta,Ctrl " ) ;
set ( " 3d_editor/pan_modifier " , 1 ) ;
hints [ " 3d_editor/pan_modifier " ] = PropertyInfo ( Variant : : INT , " 3d_editor/pan_modifier " , PROPERTY_HINT_ENUM , " None,Shift,Alt,Meta,Ctrl " ) ;
set ( " 3d_editor/zoom_modifier " , 4 ) ;
hints [ " 3d_editor/zoom_modifier " ] = PropertyInfo ( Variant : : INT , " 3d_editor/zoom_modifier " , PROPERTY_HINT_ENUM , " None,Shift,Alt,Meta,Ctrl " ) ;
2016-02-07 19:48:13 +01:00
set ( " 3d_editor/emulate_numpad " , false ) ;
2016-04-12 03:37:35 +02:00
set ( " 3d_editor/trackpad_hint " , false ) ;
2014-02-10 02:10:30 +01:00
2014-07-06 16:49:27 +02:00
set ( " 2d_editor/bone_width " , 5 ) ;
set ( " 2d_editor/bone_color1 " , Color ( 1.0 , 1.0 , 1.0 , 0.9 ) ) ;
set ( " 2d_editor/bone_color2 " , Color ( 0.75 , 0.75 , 0.75 , 0.9 ) ) ;
set ( " 2d_editor/bone_selected_color " , Color ( 0.9 , 0.45 , 0.45 , 0.9 ) ) ;
set ( " 2d_editor/bone_ik_color " , Color ( 0.9 , 0.9 , 0.45 , 0.9 ) ) ;
2015-08-31 04:36:46 +02:00
set ( " game_window_placement/rect " , 0 ) ;
hints [ " game_window_placement/rect " ] = PropertyInfo ( Variant : : INT , " game_window_placement/rect " , PROPERTY_HINT_ENUM , " Default,Centered,Custom Position,Force Maximized,Force Full Screen " ) ;
2016-05-04 03:25:37 +02:00
String screen_hints = TTR ( " Default (Same as Editor) " ) ;
2015-08-31 04:36:46 +02:00
for ( int i = 0 ; i < OS : : get_singleton ( ) - > get_screen_count ( ) ; i + + ) {
screen_hints + = " ,Monitor " + itos ( i + 1 ) ;
}
set ( " game_window_placement/rect_custom_position " , Vector2 ( ) ) ;
set ( " game_window_placement/screen " , 0 ) ;
hints [ " game_window_placement/screen " ] = PropertyInfo ( Variant : : INT , " game_window_placement/screen " , PROPERTY_HINT_ENUM , screen_hints ) ;
2015-08-06 07:37:40 +02:00
2014-02-10 02:10:30 +01:00
set ( " on_save/compress_binary_resources " , true ) ;
set ( " on_save/save_modified_external_resources " , true ) ;
set ( " on_save/save_paths_as_relative " , false ) ;
2014-02-25 13:31:47 +01:00
set ( " on_save/save_paths_without_extension " , false ) ;
2014-02-10 02:10:30 +01:00
set ( " text_editor/create_signal_callbacks " , true ) ;
2015-03-21 18:33:32 +01:00
set ( " file_dialog/show_hidden_files " , false ) ;
2015-12-15 17:39:13 +01:00
set ( " file_dialog/display_mode " , 0 ) ;
hints [ " file_dialog/display_mode " ] = PropertyInfo ( Variant : : INT , " file_dialog/display_mode " , PROPERTY_HINT_ENUM , " Thumbnails,List " ) ;
2015-05-31 06:59:42 +02:00
set ( " file_dialog/thumbnail_size " , 64 ) ;
hints [ " file_dialog/thumbnail_size " ] = PropertyInfo ( Variant : : INT , " file_dialog/thumbnail_size " , PROPERTY_HINT_RANGE , " 32,128,16 " ) ;
2014-02-10 02:10:30 +01:00
set ( " animation/autorename_animation_tracks " , true ) ;
2014-12-08 10:35:06 +01:00
set ( " animation/confirm_insert_track " , true ) ;
2014-02-10 02:10:30 +01:00
set ( " property_editor/texture_preview_width " , 48 ) ;
2015-01-03 19:39:01 +01:00
set ( " property_editor/auto_refresh_interval " , 0.3 ) ;
2014-02-10 02:10:30 +01:00
set ( " help/doc_path " , " " ) ;
set ( " import/ask_save_before_reimport " , false ) ;
set ( " import/pvrtc_texture_tool " , " " ) ;
# ifdef WINDOWS_ENABLED
2014-04-05 17:39:30 +02:00
hints [ " import/pvrtc_texture_tool " ] = PropertyInfo ( Variant : : STRING , " import/pvrtc_texture_tool " , PROPERTY_HINT_GLOBAL_FILE , " *.exe " ) ;
2014-02-10 02:10:30 +01:00
# else
2014-04-05 17:39:30 +02:00
hints [ " import/pvrtc_texture_tool " ] = PropertyInfo ( Variant : : STRING , " import/pvrtc_texture_tool " , PROPERTY_HINT_GLOBAL_FILE , " " ) ;
2014-02-10 02:10:30 +01:00
# endif
2016-05-04 03:25:37 +02:00
set ( TTR ( " PVRTC/fast_conversion " ) , false ) ;
2014-02-10 02:10:30 +01:00
set ( " run/auto_save_before_running " , true ) ;
set ( " resources/save_compressed_resources " , true ) ;
2014-05-05 03:50:23 +02:00
set ( " resources/auto_reload_modified_images " , true ) ;
2016-02-22 00:15:47 +01:00
2016-02-27 16:11:40 +01:00
if ( p_extra_config . is_valid ( ) ) {
2016-02-22 00:15:47 +01:00
2016-02-27 16:11:40 +01:00
if ( p_extra_config - > has_section ( " init_projects " ) & & p_extra_config - > has_section_key ( " init_projects " , " list " ) ) {
Vector < String > list = p_extra_config - > get_value ( " init_projects " , " list " ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
String name = list [ i ] . replace ( " / " , " :: " ) ;
set ( " projects/ " + name , list [ i ] ) ;
} ;
} ;
if ( p_extra_config - > has_section ( " presets " ) ) {
List < String > keys ;
p_extra_config - > get_section_keys ( " presets " , & keys ) ;
for ( List < String > : : Element * E = keys . front ( ) ; E ; E = E - > next ( ) ) {
2016-02-22 00:15:47 +01:00
2016-02-27 16:11:40 +01:00
String key = E - > get ( ) ;
Variant val = p_extra_config - > get_value ( " presets " , key ) ;
set ( key , val ) ;
} ;
2016-02-22 00:15:47 +01:00
} ;
} ;
2014-02-10 02:10:30 +01:00
}
void EditorSettings : : notify_changes ( ) {
_THREAD_SAFE_METHOD_
2014-11-06 01:20:42 +01:00
SceneTree * sml = NULL ;
2014-02-10 02:10:30 +01:00
if ( OS : : get_singleton ( ) - > get_main_loop ( ) )
2014-11-06 01:20:42 +01:00
sml = OS : : get_singleton ( ) - > get_main_loop ( ) - > cast_to < SceneTree > ( ) ;
2014-02-10 02:10:30 +01:00
if ( ! sml ) {
print_line ( " not SML " ) ;
return ;
}
Node * root = sml - > get_root ( ) - > get_child ( 0 ) ;
if ( ! root ) {
return ;
}
root - > propagate_notification ( NOTIFICATION_EDITOR_SETTINGS_CHANGED ) ;
}
void EditorSettings : : add_property_hint ( const PropertyInfo & p_hint ) {
_THREAD_SAFE_METHOD_
hints [ p_hint . name ] = p_hint ;
}
2015-06-06 14:44:38 +02:00
void EditorSettings : : set_favorite_dirs ( const Vector < String > & p_favorites ) {
favorite_dirs = p_favorites ;
FileAccess * f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " favorite_dirs " ) , FileAccess : : WRITE ) ;
if ( f ) {
for ( int i = 0 ; i < favorite_dirs . size ( ) ; i + + )
f - > store_line ( favorite_dirs [ i ] ) ;
memdelete ( f ) ;
}
}
Vector < String > EditorSettings : : get_favorite_dirs ( ) const {
return favorite_dirs ;
}
void EditorSettings : : set_recent_dirs ( const Vector < String > & p_recent ) {
recent_dirs = p_recent ;
FileAccess * f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " recent_dirs " ) , FileAccess : : WRITE ) ;
if ( f ) {
for ( int i = 0 ; i < recent_dirs . size ( ) ; i + + )
f - > store_line ( recent_dirs [ i ] ) ;
memdelete ( f ) ;
}
}
Vector < String > EditorSettings : : get_recent_dirs ( ) const {
return recent_dirs ;
}
String EditorSettings : : get_project_settings_path ( ) const {
return get_settings_path ( ) . plus_file ( " config " ) . plus_file ( project_config_path ) ;
}
void EditorSettings : : load_favorites ( ) {
FileAccess * f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " favorite_dirs " ) , FileAccess : : READ ) ;
if ( f ) {
String line = f - > get_line ( ) . strip_edges ( ) ;
while ( line ! = " " ) {
favorite_dirs . push_back ( line ) ;
line = f - > get_line ( ) . strip_edges ( ) ;
}
memdelete ( f ) ;
}
f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " recent_dirs " ) , FileAccess : : READ ) ;
if ( f ) {
String line = f - > get_line ( ) . strip_edges ( ) ;
while ( line ! = " " ) {
recent_dirs . push_back ( line ) ;
line = f - > get_line ( ) . strip_edges ( ) ;
}
memdelete ( f ) ;
}
}
2014-02-10 02:10:30 +01:00
void EditorSettings : : _bind_methods ( ) {
2016-02-27 04:32:00 +01:00
ObjectTypeDB : : bind_method ( _MD ( " erase " , " property " ) , & EditorSettings : : erase ) ;
ObjectTypeDB : : bind_method ( _MD ( " get_settings_path " ) , & EditorSettings : : get_settings_path ) ;
ObjectTypeDB : : bind_method ( _MD ( " get_project_settings_path " ) , & EditorSettings : : get_project_settings_path ) ;
ObjectTypeDB : : bind_method ( _MD ( " set_favorite_dirs " , " dirs " ) , & EditorSettings : : set_favorite_dirs ) ;
ObjectTypeDB : : bind_method ( _MD ( " get_favorite_dirs " ) , & EditorSettings : : get_favorite_dirs ) ;
ObjectTypeDB : : bind_method ( _MD ( " set_recent_dirs " , " dirs " ) , & EditorSettings : : set_recent_dirs ) ;
ObjectTypeDB : : bind_method ( _MD ( " get_recent_dirs " ) , & EditorSettings : : get_recent_dirs ) ;
2014-02-10 02:10:30 +01:00
ADD_SIGNAL ( MethodInfo ( " settings_changed " ) ) ;
}
EditorSettings : : EditorSettings ( ) {
//singleton=this;
last_order = 0 ;
_load_defaults ( ) ;
}
EditorSettings : : ~ EditorSettings ( ) {
// singleton=NULL;
}