2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* editor_settings.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
2017-01-01 21:01:57 +00:00
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
2017-04-07 22:45:00 +00:00
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
2014-02-10 01:10:30 +00: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/dir_access.h"
# include "os/file_access.h"
# include "os/os.h"
2017-03-18 23:36:26 +00:00
2014-02-10 01:10:30 +00:00
# include "editor_node.h"
# include "globals.h"
2017-03-18 23:36:26 +00:00
# include "io/compression.h"
# include "io/config_file.h"
2016-05-27 22:58:28 +00:00
# include "io/file_access_memory.h"
2017-03-18 23:36:26 +00:00
# include "io/resource_loader.h"
# include "io/resource_saver.h"
2016-05-27 22:58:28 +00:00
# include "io/translation_loader_po.h"
2016-06-05 00:31:29 +00:00
# include "os/keyboard.h"
2017-03-18 23:36:26 +00:00
# include "os/os.h"
# include "scene/main/node.h"
# include "scene/main/scene_main_loop.h"
# include "scene/main/viewport.h"
# include "translations.h"
# include "version.h"
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
Ref < EditorSettings > EditorSettings : : singleton = NULL ;
2014-02-10 01:10:30 +00:00
EditorSettings * EditorSettings : : get_singleton ( ) {
return singleton . ptr ( ) ;
}
2017-03-18 23:36:26 +00:00
bool EditorSettings : : _set ( const StringName & p_name , const Variant & p_value ) {
2014-02-10 01:10:30 +00:00
_THREAD_SAFE_METHOD_
2016-06-05 00:31:29 +00:00
2017-03-18 23:36:26 +00:00
if ( p_name . operator String ( ) = = " shortcuts " ) {
2016-06-05 00:31:29 +00:00
2017-03-18 23:36:26 +00:00
Array arr = p_value ;
ERR_FAIL_COND_V ( arr . size ( ) & & arr . size ( ) & 1 , true ) ;
for ( int i = 0 ; i < arr . size ( ) ; i + = 2 ) {
2016-06-05 00:31:29 +00:00
String name = arr [ i ] ;
2017-03-18 23:36:26 +00:00
InputEvent shortcut = arr [ i + 1 ] ;
2016-06-05 00:31:29 +00:00
Ref < ShortCut > sc ;
sc . instance ( ) ;
sc - > set_shortcut ( shortcut ) ;
2017-03-18 23:36:26 +00:00
add_shortcut ( name , sc ) ;
2016-06-05 00:31:29 +00:00
}
return true ;
}
2017-03-18 23:36:26 +00:00
if ( p_value . get_type ( ) = = Variant : : NIL )
2014-02-10 01:10:30 +00:00
props . erase ( p_name ) ;
else {
if ( props . has ( p_name ) )
2017-03-18 23:36:26 +00:00
props [ p_name ] . variant = p_value ;
2014-02-10 01:10:30 +00:00
else
2017-03-18 23:36:26 +00:00
props [ p_name ] = VariantContainer ( p_value , last_order + + ) ;
2016-06-12 00:16:14 +00:00
if ( save_changed_setting ) {
2017-03-18 23:36:26 +00:00
props [ p_name ] . save = true ;
2016-06-12 00:16:14 +00:00
}
2014-02-10 01:10:30 +00:00
}
emit_signal ( " settings_changed " ) ;
return true ;
}
2017-03-18 23:36:26 +00:00
bool EditorSettings : : _get ( const StringName & p_name , Variant & r_ret ) const {
2014-02-10 01:10:30 +00:00
_THREAD_SAFE_METHOD_
2017-03-18 23:36:26 +00:00
if ( p_name . operator String ( ) = = " shortcuts " ) {
2016-06-05 00:31:29 +00:00
Array arr ;
2017-03-18 23:36:26 +00:00
for ( const Map < String , Ref < ShortCut > > : : Element * E = shortcuts . front ( ) ; E ; E = E - > next ( ) ) {
2016-06-05 00:31:29 +00:00
2017-03-18 23:36:26 +00:00
Ref < ShortCut > sc = E - > get ( ) ;
2016-06-05 00:31:29 +00:00
2016-07-03 22:13:45 +00:00
if ( optimize_save ) {
if ( ! sc - > has_meta ( " original " ) ) {
continue ; //this came from settings but is not any longer used
}
InputEvent original = sc - > get_meta ( " original " ) ;
2017-03-18 23:36:26 +00:00
if ( sc - > is_shortcut ( original ) | | ( original . type = = InputEvent : : NONE & & sc - > get_shortcut ( ) . type = = InputEvent : : NONE ) )
2016-07-03 22:13:45 +00:00
continue ; //not changed from default, don't save
}
2016-06-05 00:31:29 +00:00
arr . push_back ( E - > key ( ) ) ;
arr . push_back ( sc - > get_shortcut ( ) ) ;
}
2017-03-18 23:36:26 +00:00
r_ret = arr ;
2016-06-05 00:31:29 +00:00
return true ;
}
2017-03-18 23:36:26 +00:00
const VariantContainer * v = props . getptr ( p_name ) ;
2014-02-10 01:10:30 +00:00
if ( ! v )
return false ;
r_ret = v - > variant ;
return true ;
}
struct _EVCSort {
String name ;
Variant : : Type type ;
int order ;
2016-06-12 00:16:14 +00:00
bool save ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
bool operator < ( const _EVCSort & p_vcs ) const { return order < p_vcs . order ; }
2014-02-10 01:10:30 +00:00
} ;
void EditorSettings : : _get_property_list ( List < PropertyInfo > * p_list ) const {
_THREAD_SAFE_METHOD_
2017-03-18 23:36:26 +00:00
const String * k = NULL ;
2014-02-10 01:10:30 +00:00
Set < _EVCSort > vclist ;
2017-03-18 23:36:26 +00:00
while ( ( k = props . next ( k ) ) ) {
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
const VariantContainer * v = props . getptr ( * k ) ;
2014-02-10 01:10:30 +00:00
if ( v - > hide_from_editor )
continue ;
_EVCSort vc ;
2017-03-18 23:36:26 +00:00
vc . name = * k ;
vc . order = v - > order ;
vc . type = v - > variant . get_type ( ) ;
vc . save = v - > save ;
2014-02-10 01:10:30 +00:00
vclist . insert ( vc ) ;
}
2017-03-18 23:36:26 +00:00
for ( Set < _EVCSort > : : Element * E = vclist . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 01:10:30 +00:00
2016-06-12 00:16:14 +00:00
int pinfo = 0 ;
2016-07-03 22:13:45 +00:00
if ( E - > get ( ) . save | | ! optimize_save ) {
2017-03-18 23:36:26 +00:00
pinfo | = PROPERTY_USAGE_STORAGE ;
2016-06-12 00:16:14 +00:00
}
2016-06-12 18:34:58 +00:00
if ( ! E - > get ( ) . name . begins_with ( " _ " ) & & ! E - > get ( ) . name . begins_with ( " projects/ " ) ) {
2017-03-18 23:36:26 +00:00
pinfo | = PROPERTY_USAGE_EDITOR ;
2016-06-12 00:16:14 +00:00
} else {
2017-03-18 23:36:26 +00:00
pinfo | = PROPERTY_USAGE_STORAGE ; //hiddens must always be saved
2016-06-12 00:16:14 +00:00
}
2014-02-10 01:10:30 +00:00
PropertyInfo pi ( E - > get ( ) . type , E - > get ( ) . name ) ;
2017-03-18 23:36:26 +00:00
pi . usage = pinfo ;
2014-02-10 01:10:30 +00:00
if ( hints . has ( E - > get ( ) . name ) )
2017-03-18 23:36:26 +00:00
pi = hints [ E - > get ( ) . name ] ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
p_list - > push_back ( pi ) ;
2014-02-10 01:10:30 +00:00
}
2016-06-05 00:31:29 +00:00
2017-03-18 23:36:26 +00:00
p_list - > push_back ( PropertyInfo ( Variant : : ARRAY , " shortcuts " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NOEDITOR ) ) ; //do not edit
2014-02-10 01:10:30 +00:00
}
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 ) ;
}
2017-03-18 23:36:26 +00:00
void EditorSettings : : raise_order ( const String & p_name ) {
2014-02-10 01:10:30 +00:00
_THREAD_SAFE_METHOD_
ERR_FAIL_COND ( ! props . has ( p_name ) ) ;
2017-03-18 23:36:26 +00:00
props [ p_name ] . order = + + last_order ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
Variant _EDITOR_DEF ( const String & p_var , const Variant & p_default ) {
2014-02-10 01:10:30 +00:00
if ( EditorSettings : : get_singleton ( ) - > has ( p_var ) )
return EditorSettings : : get_singleton ( ) - > get ( p_var ) ;
2017-03-18 23:36:26 +00:00
EditorSettings : : get_singleton ( ) - > set ( p_var , p_default ) ;
2014-02-10 01:10:30 +00:00
return p_default ;
}
void EditorSettings : : create ( ) {
if ( singleton . ptr ( ) )
return ; //pointless
2017-03-18 23:36:26 +00:00
DirAccess * dir = NULL ;
2014-02-10 01:10:30 +00:00
Variant meta ;
String config_path ;
String config_dir ;
2016-06-05 00:31:29 +00:00
//String config_file="editor_settings.xml";
2016-02-21 23:15:47 +00:00
Ref < ConfigFile > extra_config = memnew ( ConfigFile ) ;
2014-02-10 01:10:30 +00:00
2016-02-19 07:41:08 +00:00
String exe_path = OS : : get_singleton ( ) - > get_executable_path ( ) . get_base_dir ( ) ;
2017-03-18 23:36:26 +00:00
DirAccess * d = DirAccess : : create_for_path ( exe_path ) ;
2017-02-09 10:26:18 +00:00
bool self_contained = false ;
2016-02-19 07:41:08 +00:00
if ( d - > file_exists ( exe_path + " /._sc_ " ) ) {
2017-02-09 10:26:18 +00:00
self_contained = true ;
extra_config - > load ( exe_path + " /._sc_ " ) ;
} else if ( d - > file_exists ( exe_path + " /_sc_ " ) ) {
self_contained = true ;
extra_config - > load ( exe_path + " /_sc_ " ) ;
}
2014-02-10 01:10:30 +00:00
2017-02-09 10:26:18 +00:00
if ( self_contained ) {
2016-02-19 07:41:08 +00:00
// editor is self contained
config_path = exe_path ;
config_dir = " editor_data " ;
} else {
if ( OS : : get_singleton ( ) - > has_environment ( " APPDATA " ) ) {
// Most likely under windows, save here
2017-03-18 23:36:26 +00:00
config_path = OS : : get_singleton ( ) - > get_environment ( " APPDATA " ) ;
config_dir = String ( _MKSTR ( VERSION_SHORT_NAME ) ) . capitalize ( ) ;
2016-02-19 07:41:08 +00:00
} else if ( OS : : get_singleton ( ) - > has_environment ( " HOME " ) ) {
2017-03-18 23:36:26 +00:00
config_path = OS : : get_singleton ( ) - > get_environment ( " HOME " ) ;
config_dir = " . " + String ( _MKSTR ( VERSION_SHORT_NAME ) ) . to_lower ( ) ;
2016-02-19 07:41:08 +00:00
}
} ;
2014-02-10 01:10:30 +00:00
ObjectTypeDB : : register_type < EditorSettings > ( ) ; //otherwise it can't be unserialized
String config_file_path ;
2017-03-18 23:36:26 +00:00
if ( config_path ! = " " ) {
2014-02-10 01:10:30 +00:00
dir = DirAccess : : create ( DirAccess : : ACCESS_FILESYSTEM ) ;
2017-03-18 23:36:26 +00:00
if ( dir - > change_dir ( config_path ) ! = OK ) {
2014-02-10 01:10:30 +00:00
ERR_PRINT ( " Cannot find path for config directory! " ) ;
memdelete ( dir ) ;
goto fail ;
}
2017-03-18 23:36:26 +00:00
if ( dir - > change_dir ( config_dir ) ! = OK ) {
2014-02-10 01:10:30 +00:00
dir - > make_dir ( config_dir ) ;
2017-03-18 23:36:26 +00:00
if ( dir - > change_dir ( config_dir ) ! = OK ) {
2014-02-10 01:10:30 +00:00
ERR_PRINT ( " Cannot create config directory! " ) ;
memdelete ( dir ) ;
goto fail ;
}
}
2017-03-18 23:36:26 +00:00
if ( dir - > change_dir ( " templates " ) ! = OK ) {
2014-02-10 01:10:30 +00:00
dir - > make_dir ( " templates " ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
2017-03-18 23:36:26 +00:00
if ( dir - > change_dir ( " text_editor_themes " ) ! = OK ) {
2016-04-12 14:45:31 +00:00
dir - > make_dir ( " text_editor_themes " ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
2017-03-18 23:36:26 +00:00
if ( dir - > change_dir ( " tmp " ) ! = OK ) {
2014-02-10 01:10:30 +00:00
dir - > make_dir ( " tmp " ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
2017-03-18 23:36:26 +00:00
if ( dir - > change_dir ( " config " ) ! = OK ) {
2015-06-06 12:44:38 +00:00
dir - > make_dir ( " config " ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
dir - > change_dir ( " config " ) ;
2017-03-18 23:36:26 +00:00
String pcp = Globals : : get_singleton ( ) - > get_resource_path ( ) ;
2015-06-06 12:44:38 +00:00
if ( pcp . ends_with ( " / " ) )
2017-03-18 23:36:26 +00:00
pcp = config_path . substr ( 0 , pcp . size ( ) - 1 ) ;
pcp = pcp . get_file ( ) + " - " + pcp . md5_text ( ) ;
2015-06-06 12:44:38 +00:00
if ( dir - > change_dir ( pcp ) ) {
dir - > make_dir ( pcp ) ;
} else {
dir - > change_dir ( " .. " ) ;
}
dir - > change_dir ( " .. " ) ;
2014-02-10 01:10:30 +00:00
// path at least is validated, so validate config file
2017-03-18 23:36:26 +00:00
config_file_path = config_path + " / " + config_dir + " /editor_settings.tres " ;
2014-02-10 01:10:30 +00:00
2016-06-05 00:31:29 +00:00
String open_path = config_file_path ;
if ( ! dir - > file_exists ( " editor_settings.tres " ) ) {
2017-03-18 23:36:26 +00:00
open_path = config_path + " / " + config_dir + " /editor_settings.xml " ;
2016-06-05 00:31:29 +00:00
if ( ! dir - > file_exists ( " editor_settings.xml " ) ) {
memdelete ( dir ) ;
WARN_PRINT ( " Config file does not exist, creating. " ) ;
goto fail ;
}
2014-02-10 01:10:30 +00:00
}
memdelete ( dir ) ;
2017-03-18 23:36:26 +00:00
singleton = ResourceLoader : : load ( open_path , " EditorSettings " ) ;
2016-06-05 00:31:29 +00:00
2014-02-10 01:10:30 +00:00
if ( singleton . is_null ( ) ) {
WARN_PRINT ( " Could not open config file. " ) ;
goto fail ;
}
2017-03-18 23:36:26 +00:00
singleton - > save_changed_setting = true ;
singleton - > config_file_path = config_file_path ;
singleton - > project_config_path = pcp ;
singleton - > settings_path = config_path + " / " + config_dir ;
2014-02-10 01:10:30 +00:00
if ( OS : : get_singleton ( ) - > is_stdout_verbose ( ) ) {
2016-05-04 13:28:37 +00:00
print_line ( " EditorSettings: Load OK! " ) ;
2014-02-10 01:10:30 +00:00
}
2016-05-27 22:58:28 +00:00
singleton - > setup_language ( ) ;
2015-08-06 05:37:40 +00:00
singleton - > setup_network ( ) ;
2015-06-06 12:44:38 +00:00
singleton - > load_favorites ( ) ;
2016-04-12 14:45:31 +00:00
singleton - > list_text_editor_themes ( ) ;
2014-02-10 01:10:30 +00:00
return ;
}
2017-03-18 23:36:26 +00:00
fail :
2014-02-10 01:10:30 +00:00
2016-02-21 23:15:47 +00:00
// patch init projects
if ( extra_config - > has_section ( " init_projects " ) ) {
Vector < String > list = extra_config - > get_value ( " init_projects " , " list " ) ;
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
2016-02-21 23:15:47 +00:00
list [ i ] = exe_path + " / " + list [ i ] ;
} ;
extra_config - > set_value ( " init_projects " , " list " , list ) ;
} ;
2017-03-18 23:36:26 +00:00
singleton = Ref < EditorSettings > ( memnew ( EditorSettings ) ) ;
singleton - > save_changed_setting = true ;
singleton - > config_file_path = config_file_path ;
singleton - > settings_path = config_path + " / " + config_dir ;
2016-06-15 17:10:19 +00:00
singleton - > _load_defaults ( extra_config ) ;
2016-05-27 22:58:28 +00:00
singleton - > setup_language ( ) ;
2015-08-06 05:37:40 +00:00
singleton - > setup_network ( ) ;
2016-04-12 14:45:31 +00:00
singleton - > list_text_editor_themes ( ) ;
2014-02-10 01:10:30 +00:00
}
String EditorSettings : : get_settings_path ( ) const {
return settings_path ;
}
2016-05-27 22:58:28 +00:00
void EditorSettings : : setup_language ( ) {
String lang = get ( " global/editor_language " ) ;
2017-03-18 23:36:26 +00:00
if ( lang = = " en " )
2016-05-27 22:58:28 +00:00
return ; //none to do
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < translations . size ( ) ; i + + ) {
if ( translations [ i ] - > get_locale ( ) = = lang ) {
2016-05-27 22:58:28 +00:00
TranslationServer : : get_singleton ( ) - > set_tool_translation ( translations [ i ] ) ;
break ;
}
}
}
2015-08-06 05:37:40 +00:00
void EditorSettings : : setup_network ( ) {
List < IP_Address > local_ip ;
IP : : get_singleton ( ) - > get_local_addresses ( & local_ip ) ;
String lip ;
String hint ;
2017-05-26 16:46:59 +00:00
String current = has ( " network/debug_host " ) ? get ( " network/debug_host " ) : " " ;
2017-05-12 17:27:16 +00:00
int port = has ( " network/debug_port " ) ? ( int ) get ( " network/debug_port " ) : 6007 ;
2015-08-06 05:37:40 +00:00
2017-03-18 23:36:26 +00:00
for ( List < IP_Address > : : Element * E = local_ip . front ( ) ; E ; E = E - > next ( ) ) {
2015-08-06 05:37:40 +00:00
String ip = E - > get ( ) ;
2017-03-18 23:36:26 +00:00
if ( lip = = " " )
lip = ip ;
if ( ip = = current )
lip = current ; //so it saves
if ( hint ! = " " )
hint + = " , " ;
hint + = ip ;
2015-08-06 05:37:40 +00:00
}
2017-03-18 23:36:26 +00:00
set ( " network/debug_host " , lip ) ;
add_property_hint ( PropertyInfo ( Variant : : STRING , " network/debug_host " , PROPERTY_HINT_ENUM , hint ) ) ;
2017-05-12 17:27:16 +00:00
set ( " network/debug_port " , port ) ;
add_property_hint ( PropertyInfo ( Variant : : INT , " network/debug_port " , PROPERTY_HINT_RANGE , " 1,65535,1 " ) ) ;
2015-08-06 05:37:40 +00:00
}
2014-02-10 01:10:30 +00:00
void EditorSettings : : save ( ) {
//_THREAD_SAFE_METHOD_
if ( ! singleton . ptr ( ) )
return ;
2017-03-18 23:36:26 +00:00
if ( singleton - > config_file_path = = " " ) {
2014-02-10 01:10:30 +00:00
ERR_PRINT ( " Cannot save EditorSettings config, no valid path " ) ;
return ;
}
2017-03-18 23:36:26 +00:00
Error err = ResourceSaver : : save ( singleton - > config_file_path , singleton ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
if ( err ! = OK ) {
2014-02-10 01:10:30 +00:00
ERR_PRINT ( " Can't Save! " ) ;
return ;
}
if ( OS : : get_singleton ( ) - > is_stdout_verbose ( ) ) {
2016-05-04 13:28:37 +00:00
print_line ( " EditorSettings Save OK! " ) ;
2014-02-10 01:10:30 +00:00
}
}
void EditorSettings : : destroy ( ) {
if ( ! singleton . ptr ( ) )
return ;
save ( ) ;
2017-03-18 23:36:26 +00:00
singleton = Ref < EditorSettings > ( ) ;
2014-02-10 01:10:30 +00:00
}
2016-02-21 23:15:47 +00:00
void EditorSettings : : _load_defaults ( Ref < ConfigFile > p_extra_config ) {
2014-02-10 01:10:30 +00:00
_THREAD_SAFE_METHOD_
2016-05-27 22:58:28 +00:00
{
2017-03-18 23:36:26 +00:00
String lang_hint = " en " ;
2016-05-27 22:58:28 +00:00
String host_lang = OS : : get_singleton ( ) - > get_locale ( ) ;
String best ;
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < translations . size ( ) ; i + + ) {
2016-05-27 22:58:28 +00:00
String locale = translations [ i ] - > get_locale ( ) ;
2017-03-18 23:36:26 +00:00
lang_hint + = " , " ;
lang_hint + = locale ;
2016-05-27 22:58:28 +00:00
2017-03-18 23:36:26 +00:00
if ( host_lang = = locale ) {
best = locale ;
2016-05-27 22:58:28 +00:00
}
2017-03-18 23:36:26 +00:00
if ( best = = String ( ) & & host_lang . begins_with ( locale ) ) {
best = locale ;
2016-05-27 22:58:28 +00:00
}
}
2017-03-18 23:36:26 +00:00
if ( best = = String ( ) ) {
best = " en " ;
2016-05-27 22:58:28 +00:00
}
2017-03-18 23:36:26 +00:00
set ( " global/editor_language " , best ) ;
hints [ " global/editor_language " ] = PropertyInfo ( Variant : : STRING , " global/editor_language " , PROPERTY_HINT_ENUM , lang_hint , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED ) ;
2016-05-27 22:58:28 +00:00
}
2017-03-18 23:36:26 +00:00
set ( " global/hidpi_mode " , 0 ) ;
hints [ " global/hidpi_mode " ] = PropertyInfo ( Variant : : INT , " global/hidpi_mode " , PROPERTY_HINT_ENUM , " Auto,LoDPI,HiDPI " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED ) ;
set ( " global/show_script_in_scene_tabs " , false ) ;
set ( " global/font_size " , 14 ) ;
hints [ " global/font_size " ] = PropertyInfo ( Variant : : INT , " global/font_size " , PROPERTY_HINT_RANGE , " 10,40,1 " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED ) ;
set ( " global/source_font_size " , 14 ) ;
hints [ " global/source_font_size " ] = PropertyInfo ( Variant : : INT , " global/source_font_size " , PROPERTY_HINT_RANGE , " 8,96,1 " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED ) ;
set ( " global/custom_font " , " " ) ;
hints [ " global/custom_font " ] = PropertyInfo ( Variant : : STRING , " global/custom_font " , PROPERTY_HINT_GLOBAL_FILE , " *.fnt " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED ) ;
set ( " global/custom_theme " , " " ) ;
hints [ " global/custom_theme " ] = PropertyInfo ( Variant : : STRING , " global/custom_theme " , PROPERTY_HINT_GLOBAL_FILE , " *.res,*.tres,*.theme " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED ) ;
set ( " global/autoscan_project_path " , " " ) ;
hints [ " global/autoscan_project_path " ] = PropertyInfo ( Variant : : STRING , " global/autoscan_project_path " , PROPERTY_HINT_GLOBAL_DIR ) ;
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 ) ;
set ( " global/show_script_in_scene_tabs " , false ) ;
set ( " text_editor/color_theme " , " Default " ) ;
hints [ " text_editor/color_theme " ] = PropertyInfo ( Variant : : STRING , " text_editor/color_theme " , PROPERTY_HINT_ENUM , " Default " ) ;
2016-04-12 14:45:31 +00:00
_load_default_text_editor_theme ( ) ;
2014-02-10 01:10:30 +00:00
2016-03-30 18:32:45 +00:00
set ( " text_editor/syntax_highlighting " , true ) ;
2016-03-16 21:20:42 +00:00
set ( " text_editor/highlight_all_occurrences " , true ) ;
2016-03-07 02:32:51 +00:00
set ( " text_editor/scroll_past_end_of_file " , false ) ;
2016-03-11 18:10:01 +00:00
set ( " text_editor/tab_size " , 4 ) ;
2017-03-18 23:36:26 +00:00
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 12:49:18 +00:00
set ( " text_editor/draw_tabs " , true ) ;
2016-03-11 18:10:01 +00:00
2016-10-10 08:38:12 +00:00
set ( " text_editor/line_numbers_zero_padded " , true ) ;
2016-03-30 18:16:52 +00:00
set ( " text_editor/show_line_numbers " , true ) ;
2016-05-26 13:17:14 +00:00
set ( " text_editor/show_breakpoint_gutter " , true ) ;
2016-03-30 18:16:52 +00:00
2016-10-10 08:38:12 +00:00
set ( " text_editor/show_line_length_guideline " , false ) ;
set ( " text_editor/line_length_guideline_column " , 80 ) ;
2017-03-18 23:36:26 +00:00
hints [ " text_editor/line_length_guideline_column " ] = PropertyInfo ( Variant : : INT , " text_editor/line_length_guideline_column " , PROPERTY_HINT_RANGE , " 20, 160, 10 " ) ;
2016-10-10 08:38:12 +00:00
2016-04-23 18:21:34 +00:00
set ( " text_editor/trim_trailing_whitespace_on_save " , false ) ;
2017-03-18 23:36:26 +00:00
set ( " text_editor/idle_parse_delay " , 2 ) ;
set ( " text_editor/create_signal_callbacks " , true ) ;
set ( " text_editor/autosave_interval_secs " , 0 ) ;
2015-06-22 03:03:19 +00:00
2016-07-12 15:07:17 +00:00
set ( " text_editor/block_caret " , false ) ;
2016-05-09 18:21:55 +00:00
set ( " text_editor/caret_blink " , false ) ;
set ( " text_editor/caret_blink_speed " , 0.65 ) ;
2017-03-18 23:36:26 +00:00
hints [ " text_editor/caret_blink_speed " ] = PropertyInfo ( Variant : : REAL , " text_editor/caret_blink_speed " , PROPERTY_HINT_RANGE , " 0.1, 10, 0.1 " ) ;
2016-05-09 18:21:55 +00:00
2017-03-18 23:36:26 +00:00
set ( " text_editor/font " , " " ) ;
hints [ " text_editor/font " ] = PropertyInfo ( Variant : : STRING , " text_editor/font " , PROPERTY_HINT_GLOBAL_FILE , " *.fnt " ) ;
2014-08-25 01:20:45 +00:00
set ( " text_editor/auto_brace_complete " , false ) ;
2017-03-18 23:36:26 +00:00
set ( " text_editor/restore_scripts_on_load " , true ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00: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 " ) ;
2016-05-17 21:27:15 +00:00
//set("scenetree_editor/display_old_action_buttons",false);
2017-03-18 23:36:26 +00:00
set ( " scenetree_editor/start_create_dialog_fully_expanded " , false ) ;
set ( " scenetree_editor/draw_relationship_lines " , false ) ;
set ( " scenetree_editor/relationship_line_color " , Color : : html ( " 464646 " ) ) ;
2015-01-11 05:08:32 +00:00
2016-08-21 01:34:39 +00:00
set ( " grid_map/pick_distance " , 5000.0 ) ;
2015-01-11 05:08:32 +00:00
2017-03-18 23:36:26 +00:00
set ( " 3d_editor/grid_color " , Color ( 0 , 1 , 0 , 0.2 ) ) ;
hints [ " 3d_editor/grid_color " ] = PropertyInfo ( Variant : : COLOR , " 3d_editor/grid_color " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED ) ;
2017-06-16 10:07:07 +00:00
set ( " 3d_editor/default_fov " , 55.0 ) ;
2017-03-18 23:36:26 +00:00
set ( " 3d_editor/default_z_near " , 0.1 ) ;
set ( " 3d_editor/default_z_far " , 500.0 ) ;
set ( " 3d_editor/navigation_scheme " , 0 ) ;
hints [ " 3d_editor/navigation_scheme " ] = PropertyInfo ( Variant : : INT , " 3d_editor/navigation_scheme " , PROPERTY_HINT_ENUM , " Godot,Maya,Modo " ) ;
set ( " 3d_editor/zoom_style " , 0 ) ;
hints [ " 3d_editor/zoom_style " ] = PropertyInfo ( Variant : : INT , " 3d_editor/zoom_style " , PROPERTY_HINT_ENUM , " Vertical, Horizontal " ) ;
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 " ) ;
set ( " 3d_editor/emulate_numpad " , false ) ;
2016-06-21 10:16:06 +00:00
set ( " 3d_editor/emulate_3_button_mouse " , false ) ;
2017-03-22 20:18:47 +00:00
set ( " 3d_editor/warped_mouse_panning " , true ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00: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 ) ) ;
2016-05-21 13:29:25 +00:00
2016-05-10 17:20:28 +00:00
set ( " 2d_editor/keep_margins_when_changing_anchors " , false ) ;
2014-07-06 14:49:27 +00:00
2017-03-22 20:18:47 +00:00
set ( " 2d_editor/warped_mouse_panning " , true ) ;
2017-05-26 10:35:39 +00:00
set ( " 2d_editor/scroll_to_pan " , false ) ;
set ( " 2d_editor/pan_speed " , 20 ) ;
2017-03-22 20:18:47 +00:00
2017-06-12 19:10:20 +00:00
set ( " game_window_placement/rect " , 1 ) ;
2017-03-18 23:36:26 +00:00
hints [ " game_window_placement/rect " ] = PropertyInfo ( Variant : : INT , " game_window_placement/rect " , PROPERTY_HINT_ENUM , " Default,Centered,Custom Position,Force Maximized,Force Full Screen " ) ;
String screen_hints = TTR ( " Default (Same as Editor) " ) ;
for ( int i = 0 ; i < OS : : get_singleton ( ) - > get_screen_count ( ) ; i + + ) {
screen_hints + = " ,Monitor " + itos ( i + 1 ) ;
2015-08-31 02:36:46 +00:00
}
2017-03-18 23:36:26 +00:00
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 05:37:40 +00:00
2017-03-18 23:36:26 +00:00
set ( " on_save/compress_binary_resources " , true ) ;
set ( " on_save/save_modified_external_resources " , true ) ;
2016-07-22 13:39:46 +00:00
//set("on_save/save_paths_as_relative",false);
//set("on_save/save_paths_without_extension",false);
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
set ( " text_editor/create_signal_callbacks " , true ) ;
2014-02-10 01:10:30 +00:00
2015-03-21 17:33:32 +00:00
set ( " file_dialog/show_hidden_files " , false ) ;
2015-12-15 16:39:13 +00:00
set ( " file_dialog/display_mode " , 0 ) ;
2017-03-18 23:36:26 +00:00
hints [ " file_dialog/display_mode " ] = PropertyInfo ( Variant : : INT , " file_dialog/display_mode " , PROPERTY_HINT_ENUM , " Thumbnails,List " ) ;
2015-05-31 04:59:42 +00:00
set ( " file_dialog/thumbnail_size " , 64 ) ;
2017-03-18 23:36:26 +00:00
hints [ " file_dialog/thumbnail_size " ] = PropertyInfo ( Variant : : INT , " file_dialog/thumbnail_size " , PROPERTY_HINT_RANGE , " 32,128,16 " ) ;
2014-02-10 01:10:30 +00:00
2016-08-16 16:25:42 +00:00
set ( " filesystem_dock/display_mode " , 0 ) ;
2017-03-18 23:36:26 +00:00
hints [ " filesystem_dock/display_mode " ] = PropertyInfo ( Variant : : INT , " filesystem_dock/display_mode " , PROPERTY_HINT_ENUM , " Thumbnails,List " ) ;
2016-08-16 16:25:42 +00:00
set ( " filesystem_dock/thumbnail_size " , 64 ) ;
2017-03-18 23:36:26 +00:00
hints [ " filesystem_dock/thumbnail_size " ] = PropertyInfo ( Variant : : INT , " filesystem_dock/thumbnail_size " , PROPERTY_HINT_RANGE , " 32,128,16 " ) ;
2016-08-16 16:25:42 +00:00
2017-03-18 23:36:26 +00:00
set ( " animation/autorename_animation_tracks " , true ) ;
set ( " animation/confirm_insert_track " , true ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
set ( " property_editor/texture_preview_width " , 48 ) ;
set ( " property_editor/auto_refresh_interval " , 0.3 ) ;
set ( " help/doc_path " , " " ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
set ( " import/ask_save_before_reimport " , false ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
set ( " import/pvrtc_texture_tool " , " " ) ;
2014-02-10 01:10:30 +00:00
# ifdef WINDOWS_ENABLED
2017-03-18 23:36:26 +00:00
hints [ " import/pvrtc_texture_tool " ] = PropertyInfo ( Variant : : STRING , " import/pvrtc_texture_tool " , PROPERTY_HINT_GLOBAL_FILE , " *.exe " ) ;
2014-02-10 01:10:30 +00:00
# else
2017-03-18 23:36:26 +00:00
hints [ " import/pvrtc_texture_tool " ] = PropertyInfo ( Variant : : STRING , " import/pvrtc_texture_tool " , PROPERTY_HINT_GLOBAL_FILE , " " ) ;
2014-02-10 01:10:30 +00:00
# endif
2016-05-18 22:08:12 +00:00
// TODO: Rename to "import/pvrtc_fast_conversion" to match other names?
2017-03-18 23:36:26 +00:00
set ( " PVRTC/fast_conversion " , false ) ;
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
set ( " run/auto_save_before_running " , true ) ;
set ( " resources/save_compressed_resources " , true ) ;
set ( " resources/auto_reload_modified_images " , true ) ;
2016-02-21 23:15:47 +00:00
2017-03-21 11:47:05 +00:00
set ( " run/always_close_output_on_stop " , false ) ;
2017-03-18 23:36:26 +00:00
set ( " import/automatic_reimport_on_sources_changed " , true ) ;
2016-05-27 17:18:40 +00:00
2016-02-27 15:11:40 +00:00
if ( p_extra_config . is_valid ( ) ) {
2016-02-21 23:15:47 +00:00
2016-02-27 15:11:40 +00: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 " ) ;
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
2016-02-27 15:11:40 +00:00
String name = list [ i ] . replace ( " / " , " :: " ) ;
2017-03-18 23:36:26 +00:00
set ( " projects/ " + name , list [ i ] ) ;
2016-02-27 15:11:40 +00:00
} ;
} ;
if ( p_extra_config - > has_section ( " presets " ) ) {
List < String > keys ;
p_extra_config - > get_section_keys ( " presets " , & keys ) ;
2017-03-18 23:36:26 +00:00
for ( List < String > : : Element * E = keys . front ( ) ; E ; E = E - > next ( ) ) {
2016-02-21 23:15:47 +00:00
2016-02-27 15:11:40 +00:00
String key = E - > get ( ) ;
Variant val = p_extra_config - > get_value ( " presets " , key ) ;
set ( key , val ) ;
} ;
2016-02-21 23:15:47 +00:00
} ;
} ;
2016-04-12 14:45:31 +00:00
}
void EditorSettings : : _load_default_text_editor_theme ( ) {
2016-10-10 08:38:12 +00:00
2017-03-18 23:36:26 +00:00
set ( " text_editor/background_color " , Color : : html ( " 3b000000 " ) ) ;
2016-06-21 15:50:31 +00:00
set ( " text_editor/completion_background_color " , Color : : html ( " 2C2A32 " ) ) ;
2016-06-21 16:21:55 +00:00
set ( " text_editor/completion_selected_color " , Color : : html ( " 434244 " ) ) ;
2016-06-21 16:34:38 +00:00
set ( " text_editor/completion_existing_color " , Color : : html ( " 21dfdfdf " ) ) ;
2016-07-11 13:11:34 +00:00
set ( " text_editor/completion_scroll_color " , Color : : html ( " ffffff " ) ) ;
2016-07-11 13:25:56 +00:00
set ( " text_editor/completion_font_color " , Color : : html ( " aaaaaa " ) ) ;
2017-03-18 23:36:26 +00:00
set ( " text_editor/caret_color " , Color : : html ( " aaaaaa " ) ) ;
2016-07-12 15:07:17 +00:00
set ( " text_editor/caret_background_color " , Color : : html ( " 000000 " ) ) ;
2017-03-18 23:36:26 +00:00
set ( " text_editor/line_number_color " , Color : : html ( " 66aaaaaa " ) ) ;
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 " ) ) ;
set ( " text_editor/function_color " , Color : : html ( " 66a2ce " ) ) ;
set ( " text_editor/member_variable_color " , Color : : html ( " e64e59 " ) ) ;
set ( " text_editor/comment_color " , Color : : html ( " 676767 " ) ) ;
set ( " text_editor/string_color " , Color : : html ( " ef6ebe " ) ) ;
set ( " text_editor/number_color " , Color : : html ( " EB9532 " ) ) ;
set ( " text_editor/symbol_color " , Color : : html ( " badfff " ) ) ;
set ( " text_editor/selection_color " , Color : : html ( " 7b5dbe " ) ) ;
set ( " text_editor/brace_mismatch_color " , Color ( 1 , 0.2 , 0.2 ) ) ;
set ( " text_editor/current_line_color " , Color ( 0.3 , 0.5 , 0.8 , 0.15 ) ) ;
set ( " text_editor/line_length_guideline_color " , Color ( 0.3 , 0.5 , 0.8 , 0.1 ) ) ;
set ( " text_editor/mark_color " , Color ( 1.0 , 0.4 , 0.4 , 0.4 ) ) ;
set ( " text_editor/breakpoint_color " , Color ( 0.8 , 0.8 , 0.4 , 0.2 ) ) ;
set ( " text_editor/word_highlighted_color " , Color ( 0.8 , 0.9 , 0.9 , 0.15 ) ) ;
set ( " text_editor/search_result_color " , Color ( 0.05 , 0.25 , 0.05 , 1 ) ) ;
set ( " text_editor/search_result_border_color " , Color ( 0.1 , 0.45 , 0.1 , 1 ) ) ;
2014-02-10 01:10:30 +00:00
}
void EditorSettings : : notify_changes ( ) {
_THREAD_SAFE_METHOD_
2017-03-18 23:36:26 +00:00
SceneTree * sml = NULL ;
2014-02-10 01:10:30 +00:00
if ( OS : : get_singleton ( ) - > get_main_loop ( ) )
2014-11-06 00:20:42 +00:00
sml = OS : : get_singleton ( ) - > get_main_loop ( ) - > cast_to < SceneTree > ( ) ;
2014-02-10 01:10:30 +00:00
if ( ! sml ) {
return ;
}
Node * root = sml - > get_root ( ) - > get_child ( 0 ) ;
if ( ! root ) {
return ;
}
root - > propagate_notification ( NOTIFICATION_EDITOR_SETTINGS_CHANGED ) ;
}
2017-03-18 23:36:26 +00:00
void EditorSettings : : _add_property_info_bind ( const Dictionary & p_info ) {
2016-08-16 20:10:53 +00:00
ERR_FAIL_COND ( ! p_info . has ( " name " ) ) ;
ERR_FAIL_COND ( ! p_info . has ( " type " ) ) ;
PropertyInfo pinfo ;
pinfo . name = p_info [ " name " ] ;
ERR_FAIL_COND ( ! props . has ( pinfo . name ) ) ;
pinfo . type = Variant : : Type ( p_info [ " type " ] . operator int ( ) ) ;
ERR_FAIL_INDEX ( pinfo . type , Variant : : VARIANT_MAX ) ;
if ( p_info . has ( " hint " ) )
pinfo . hint = PropertyHint ( p_info [ " hint " ] . operator int ( ) ) ;
if ( p_info . has ( " hint_string " ) )
pinfo . hint_string = p_info [ " hint_string " ] ;
add_property_hint ( pinfo ) ;
}
2017-03-18 23:36:26 +00:00
void EditorSettings : : add_property_hint ( const PropertyInfo & p_hint ) {
2014-02-10 01:10:30 +00:00
_THREAD_SAFE_METHOD_
2017-03-18 23:36:26 +00:00
hints [ p_hint . name ] = p_hint ;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
void EditorSettings : : set_favorite_dirs ( const Vector < String > & p_favorites ) {
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
favorite_dirs = p_favorites ;
FileAccess * f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " favorite_dirs " ) , FileAccess : : WRITE ) ;
2015-06-06 12:44:38 +00:00
if ( f ) {
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < favorite_dirs . size ( ) ; i + + )
2015-06-06 12:44:38 +00:00
f - > store_line ( favorite_dirs [ i ] ) ;
memdelete ( f ) ;
}
}
Vector < String > EditorSettings : : get_favorite_dirs ( ) const {
return favorite_dirs ;
}
2017-03-18 23:36:26 +00:00
void EditorSettings : : set_recent_dirs ( const Vector < String > & p_recent ) {
2015-06-06 12:44:38 +00:00
2017-03-18 23:36:26 +00:00
recent_dirs = p_recent ;
FileAccess * f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " recent_dirs " ) , FileAccess : : WRITE ) ;
2015-06-06 12:44:38 +00:00
if ( f ) {
2017-03-18 23:36:26 +00:00
for ( int i = 0 ; i < recent_dirs . size ( ) ; i + + )
2015-06-06 12:44:38 +00:00
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 ( ) {
2017-03-18 23:36:26 +00:00
FileAccess * f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " favorite_dirs " ) , FileAccess : : READ ) ;
2015-06-06 12:44:38 +00:00
if ( f ) {
String line = f - > get_line ( ) . strip_edges ( ) ;
2017-03-18 23:36:26 +00:00
while ( line ! = " " ) {
2015-06-06 12:44:38 +00:00
favorite_dirs . push_back ( line ) ;
line = f - > get_line ( ) . strip_edges ( ) ;
}
memdelete ( f ) ;
}
2017-03-18 23:36:26 +00:00
f = FileAccess : : open ( get_project_settings_path ( ) . plus_file ( " recent_dirs " ) , FileAccess : : READ ) ;
2015-06-06 12:44:38 +00:00
if ( f ) {
String line = f - > get_line ( ) . strip_edges ( ) ;
2017-03-18 23:36:26 +00:00
while ( line ! = " " ) {
2015-06-06 12:44:38 +00:00
recent_dirs . push_back ( line ) ;
line = f - > get_line ( ) . strip_edges ( ) ;
}
memdelete ( f ) ;
}
}
2016-04-12 14:45:31 +00:00
void EditorSettings : : list_text_editor_themes ( ) {
2017-03-18 23:36:26 +00:00
String themes = " Default " ;
2016-04-12 14:45:31 +00:00
DirAccess * d = DirAccess : : open ( settings_path + " /text_editor_themes " ) ;
if ( d ) {
d - > list_dir_begin ( ) ;
String file = d - > get_next ( ) ;
2017-03-18 23:36:26 +00:00
while ( file ! = String ( ) ) {
2016-04-12 14:45:31 +00:00
if ( file . extension ( ) = = " tet " & & file . basename ( ) . to_lower ( ) ! = " default " ) {
themes + = " , " + file . basename ( ) ;
}
file = d - > get_next ( ) ;
}
d - > list_dir_end ( ) ;
memdelete ( d ) ;
}
2017-03-18 23:36:26 +00:00
add_property_hint ( PropertyInfo ( Variant : : STRING , " text_editor/color_theme " , PROPERTY_HINT_ENUM , themes ) ) ;
2016-04-12 14:45:31 +00:00
}
void EditorSettings : : load_text_editor_theme ( ) {
if ( get ( " text_editor/color_theme " ) = = " Default " ) {
2017-03-18 23:36:26 +00:00
_load_default_text_editor_theme ( ) ; // sorry for "Settings changed" console spam
2016-04-12 14:45:31 +00:00
return ;
}
String theme_path = get_settings_path ( ) + " /text_editor_themes/ " + get ( " text_editor/color_theme " ) + " .tet " ;
2017-03-18 23:36:26 +00:00
Ref < ConfigFile > cf = memnew ( ConfigFile ) ;
2016-04-12 14:45:31 +00:00
Error err = cf - > load ( theme_path ) ;
if ( err ! = OK ) {
return ;
}
List < String > keys ;
cf - > get_section_keys ( " color_theme " , & keys ) ;
2017-03-18 23:36:26 +00:00
for ( List < String > : : Element * E = keys . front ( ) ; E ; E = E - > next ( ) ) {
2016-04-12 14:45:31 +00:00
String key = E - > get ( ) ;
String val = cf - > get_value ( " color_theme " , key ) ;
// don't load if it's not already there!
if ( has ( " text_editor/ " + key ) ) {
// make sure it is actually a color
if ( val . is_valid_html_color ( ) & & key . find ( " color " ) > = 0 ) {
2017-03-18 23:36:26 +00:00
props [ " text_editor/ " + key ] . variant = Color : : html ( val ) ; // change manually to prevent "Settings changed" console spam
2016-04-12 14:45:31 +00:00
}
}
}
emit_signal ( " settings_changed " ) ;
// if it doesn't load just use what is currently loaded
}
bool EditorSettings : : import_text_editor_theme ( String p_file ) {
if ( ! p_file . ends_with ( " .tet " ) ) {
return false ;
} else {
if ( p_file . get_file ( ) . to_lower ( ) = = " default.tet " ) {
return false ;
}
DirAccess * d = DirAccess : : open ( settings_path + " /text_editor_themes " ) ;
if ( d ) {
d - > copy ( p_file , settings_path + " /text_editor_themes/ " + p_file . get_file ( ) ) ;
memdelete ( d ) ;
return true ;
}
}
return false ;
}
bool EditorSettings : : save_text_editor_theme ( ) {
String p_file = get ( " text_editor/color_theme " ) ;
if ( p_file . get_file ( ) . to_lower ( ) = = " default " ) {
return false ;
}
String theme_path = get_settings_path ( ) + " /text_editor_themes/ " + p_file + " .tet " ;
return _save_text_editor_theme ( theme_path ) ;
}
bool EditorSettings : : save_text_editor_theme_as ( String p_file ) {
if ( ! p_file . ends_with ( " .tet " ) ) {
p_file + = " .tet " ;
}
if ( p_file . get_file ( ) . to_lower ( ) = = " default.tet " ) {
return false ;
}
2017-03-18 23:36:26 +00:00
if ( _save_text_editor_theme ( p_file ) ) {
2016-04-12 14:45:31 +00:00
// switch to theme is saved in the theme directory
list_text_editor_themes ( ) ;
String theme_name = p_file . substr ( 0 , p_file . length ( ) - 4 ) . get_file ( ) ;
if ( p_file . get_base_dir ( ) = = get_settings_path ( ) + " /text_editor_themes " ) {
set ( " text_editor/color_theme " , theme_name ) ;
load_text_editor_theme ( ) ;
}
return true ;
}
return false ;
}
bool EditorSettings : : _save_text_editor_theme ( String p_file ) {
String theme_section = " color_theme " ;
2017-03-18 23:36:26 +00:00
Ref < ConfigFile > cf = memnew ( ConfigFile ) ; // hex is better?
2016-10-10 08:38:12 +00:00
2016-04-12 14:45:31 +00:00
cf - > set_value ( theme_section , " background_color " , ( ( Color ) get ( " text_editor/background_color " ) ) . to_html ( ) ) ;
2016-06-21 15:50:31 +00:00
cf - > set_value ( theme_section , " completion_background_color " , ( ( Color ) get ( " text_editor/completion_background_color " ) ) . to_html ( ) ) ;
2016-06-21 16:21:55 +00:00
cf - > set_value ( theme_section , " completion_selected_color " , ( ( Color ) get ( " text_editor/completion_selected_color " ) ) . to_html ( ) ) ;
2016-06-21 16:34:38 +00:00
cf - > set_value ( theme_section , " completion_existing_color " , ( ( Color ) get ( " text_editor/completion_existing_color " ) ) . to_html ( ) ) ;
2016-07-11 13:11:34 +00:00
cf - > set_value ( theme_section , " completion_scroll_color " , ( ( Color ) get ( " text_editor/completion_scroll_color " ) ) . to_html ( ) ) ;
2016-07-11 13:25:56 +00:00
cf - > set_value ( theme_section , " completion_font_color " , ( ( Color ) get ( " text_editor/completion_font_color " ) ) . to_html ( ) ) ;
2016-04-12 14:45:31 +00:00
cf - > set_value ( theme_section , " caret_color " , ( ( Color ) get ( " text_editor/caret_color " ) ) . to_html ( ) ) ;
2016-07-12 15:07:17 +00:00
cf - > set_value ( theme_section , " caret_background_color " , ( ( Color ) get ( " text_editor/caret_background_color " ) ) . to_html ( ) ) ;
2016-05-23 15:23:05 +00:00
cf - > set_value ( theme_section , " line_number_color " , ( ( Color ) get ( " text_editor/line_number_color " ) ) . to_html ( ) ) ;
2016-04-12 14:45:31 +00:00
cf - > set_value ( theme_section , " text_color " , ( ( Color ) get ( " text_editor/text_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " text_selected_color " , ( ( Color ) get ( " text_editor/text_selected_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " keyword_color " , ( ( Color ) get ( " text_editor/keyword_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " base_type_color " , ( ( Color ) get ( " text_editor/base_type_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " engine_type_color " , ( ( Color ) get ( " text_editor/engine_type_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " function_color " , ( ( Color ) get ( " text_editor/function_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " member_variable_color " , ( ( Color ) get ( " text_editor/member_variable_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " comment_color " , ( ( Color ) get ( " text_editor/comment_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " string_color " , ( ( Color ) get ( " text_editor/string_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " number_color " , ( ( Color ) get ( " text_editor/number_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " symbol_color " , ( ( Color ) get ( " text_editor/symbol_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " selection_color " , ( ( Color ) get ( " text_editor/selection_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " brace_mismatch_color " , ( ( Color ) get ( " text_editor/brace_mismatch_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " current_line_color " , ( ( Color ) get ( " text_editor/current_line_color " ) ) . to_html ( ) ) ;
2016-10-10 08:38:12 +00:00
cf - > set_value ( theme_section , " line_length_guideline_color " , ( ( Color ) get ( " text_editor/line_length_guideline_color " ) ) . to_html ( ) ) ;
2016-05-25 15:57:33 +00:00
cf - > set_value ( theme_section , " mark_color " , ( ( Color ) get ( " text_editor/mark_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " breakpoint_color " , ( ( Color ) get ( " text_editor/breakpoint_color " ) ) . to_html ( ) ) ;
2016-04-12 14:45:31 +00:00
cf - > set_value ( theme_section , " word_highlighted_color " , ( ( Color ) get ( " text_editor/word_highlighted_color " ) ) . to_html ( ) ) ;
2016-05-28 16:25:45 +00:00
cf - > set_value ( theme_section , " search_result_color " , ( ( Color ) get ( " text_editor/search_result_color " ) ) . to_html ( ) ) ;
cf - > set_value ( theme_section , " search_result_border_color " , ( ( Color ) get ( " text_editor/search_result_border_color " ) ) . to_html ( ) ) ;
2016-10-10 08:38:12 +00:00
2016-04-12 14:45:31 +00:00
Error err = cf - > save ( p_file ) ;
if ( err = = OK ) {
return true ;
}
return false ;
}
2014-02-10 01:10:30 +00:00
2017-03-18 23:36:26 +00:00
void EditorSettings : : add_shortcut ( const String & p_name , Ref < ShortCut > & p_shortcut ) {
2016-06-05 00:31:29 +00:00
2017-03-18 23:36:26 +00:00
shortcuts [ p_name ] = p_shortcut ;
2016-06-05 00:31:29 +00:00
}
2017-03-18 23:36:26 +00:00
bool EditorSettings : : is_shortcut ( const String & p_name , const InputEvent & p_event ) const {
2016-06-05 00:31:29 +00:00
2017-03-18 23:36:26 +00:00
const Map < String , Ref < ShortCut > > : : Element * E = shortcuts . find ( p_name ) ;
2016-06-05 00:31:29 +00:00
if ( ! E ) {
2017-03-18 23:36:26 +00:00
ERR_EXPLAIN ( " Unknown Shortcut: " + p_name ) ;
2016-06-05 00:31:29 +00:00
ERR_FAIL_V ( false ) ;
}
return E - > get ( ) - > is_shortcut ( p_event ) ;
}
2017-03-18 23:36:26 +00:00
Ref < ShortCut > EditorSettings : : get_shortcut ( const String & p_name ) const {
2016-06-05 00:31:29 +00:00
2017-03-18 23:36:26 +00:00
const Map < String , Ref < ShortCut > > : : Element * E = shortcuts . find ( p_name ) ;
2016-06-05 00:31:29 +00:00
if ( ! E )
return Ref < ShortCut > ( ) ;
return E - > get ( ) ;
}
void EditorSettings : : get_shortcut_list ( List < String > * r_shortcuts ) {
2017-03-18 23:36:26 +00:00
for ( const Map < String , Ref < ShortCut > > : : Element * E = shortcuts . front ( ) ; E ; E = E - > next ( ) ) {
2016-06-05 00:31:29 +00:00
r_shortcuts - > push_back ( E - > key ( ) ) ;
}
}
2016-07-03 22:13:45 +00:00
void EditorSettings : : set_optimize_save ( bool p_optimize ) {
2017-03-18 23:36:26 +00:00
optimize_save = p_optimize ;
2016-07-03 22:13:45 +00:00
}
2016-06-05 00:31:29 +00:00
2014-02-10 01:10:30 +00:00
void EditorSettings : : _bind_methods ( ) {
2017-03-18 23:36:26 +00: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 ) ;
2016-02-27 03:32:00 +00:00
2017-03-18 23:36:26 +00:00
ObjectTypeDB : : bind_method ( _MD ( " add_property_info " , " info " ) , & EditorSettings : : _add_property_info_bind ) ;
2016-08-16 20:10:53 +00:00
2017-03-18 23:36:26 +00:00
ObjectTypeDB : : bind_method ( _MD ( " set_favorite_dirs " , " dirs " ) , & EditorSettings : : set_favorite_dirs ) ;
ObjectTypeDB : : bind_method ( _MD ( " get_favorite_dirs " ) , & EditorSettings : : get_favorite_dirs ) ;
2016-02-27 03:32:00 +00:00
2017-03-18 23:36:26 +00:00
ObjectTypeDB : : bind_method ( _MD ( " set_recent_dirs " , " dirs " ) , & EditorSettings : : set_recent_dirs ) ;
ObjectTypeDB : : bind_method ( _MD ( " get_recent_dirs " ) , & EditorSettings : : get_recent_dirs ) ;
2016-02-27 03:32:00 +00:00
2014-02-10 01:10:30 +00:00
ADD_SIGNAL ( MethodInfo ( " settings_changed " ) ) ;
}
EditorSettings : : EditorSettings ( ) {
//singleton=this;
2017-03-18 23:36:26 +00:00
last_order = 0 ;
optimize_save = true ;
save_changed_setting = true ;
2016-05-27 22:58:28 +00:00
2017-03-18 23:36:26 +00:00
EditorTranslationList * etl = _editor_translations ;
2016-05-27 22:58:28 +00:00
2017-03-18 23:36:26 +00:00
while ( etl - > data ) {
2016-05-27 22:58:28 +00:00
Vector < uint8_t > data ;
data . resize ( etl - > uncomp_size ) ;
2017-03-18 23:36:26 +00:00
Compression : : decompress ( data . ptr ( ) , etl - > uncomp_size , etl - > data , etl - > comp_size , Compression : : MODE_DEFLATE ) ;
2016-05-27 22:58:28 +00:00
2017-03-18 23:36:26 +00:00
FileAccessMemory * fa = memnew ( FileAccessMemory ) ;
fa - > open_custom ( data . ptr ( ) , data . size ( ) ) ;
2016-05-27 22:58:28 +00:00
2017-03-18 23:36:26 +00:00
Ref < Translation > tr = TranslationLoaderPO : : load_translation ( fa , NULL , " translation_ " + String ( etl - > lang ) ) ;
2016-05-27 22:58:28 +00:00
if ( tr . is_valid ( ) ) {
tr - > set_locale ( etl - > lang ) ;
translations . push_back ( tr ) ;
}
etl + + ;
}
2014-02-10 01:10:30 +00:00
_load_defaults ( ) ;
}
EditorSettings : : ~ EditorSettings ( ) {
2017-03-18 23:36:26 +00:00
// singleton=NULL;
2014-02-10 01:10:30 +00:00
}
2017-03-18 23:36:26 +00:00
Ref < ShortCut > ED_GET_SHORTCUT ( const String & p_path ) {
2016-06-05 00:31:29 +00:00
Ref < ShortCut > sc = EditorSettings : : get_singleton ( ) - > get_shortcut ( p_path ) ;
if ( ! sc . is_valid ( ) ) {
2017-03-18 23:36:26 +00:00
ERR_EXPLAIN ( " Used ED_GET_SHORTCUT with invalid shortcut: " + p_path ) ;
ERR_FAIL_COND_V ( ! sc . is_valid ( ) , sc ) ;
2016-06-05 00:31:29 +00:00
}
return sc ;
}
2017-03-18 23:36:26 +00:00
Ref < ShortCut > ED_SHORTCUT ( const String & p_path , const String & p_name , uint32_t p_keycode ) {
2016-06-05 00:31:29 +00:00
InputEvent ie ;
if ( p_keycode ) {
2017-03-18 23:36:26 +00:00
ie . type = InputEvent : : KEY ;
ie . key . unicode = p_keycode & KEY_CODE_MASK ;
ie . key . scancode = p_keycode & KEY_CODE_MASK ;
ie . key . mod . shift = bool ( p_keycode & KEY_MASK_SHIFT ) ;
ie . key . mod . alt = bool ( p_keycode & KEY_MASK_ALT ) ;
ie . key . mod . control = bool ( p_keycode & KEY_MASK_CTRL ) ;
ie . key . mod . meta = bool ( p_keycode & KEY_MASK_META ) ;
2016-06-05 00:31:29 +00:00
}
Ref < ShortCut > sc = EditorSettings : : get_singleton ( ) - > get_shortcut ( p_path ) ;
if ( sc . is_valid ( ) ) {
sc - > set_name ( p_name ) ; //keep name (the ones that come from disk have no name)
2017-03-18 23:36:26 +00:00
sc - > set_meta ( " original " , ie ) ; //to compare against changes
2016-06-05 00:31:29 +00:00
return sc ;
}
sc . instance ( ) ;
sc - > set_name ( p_name ) ;
sc - > set_shortcut ( ie ) ;
2017-03-18 23:36:26 +00:00
sc - > set_meta ( " original " , ie ) ; //to compare against changes
EditorSettings : : get_singleton ( ) - > add_shortcut ( p_path , sc ) ;
2016-06-05 00:31:29 +00:00
return sc ;
}