diff options
29 files changed, 994 insertions, 442 deletions
diff --git a/SConstruct b/SConstruct index 01b1f2ce8e..d168820f66 100644 --- a/SConstruct +++ b/SConstruct @@ -73,6 +73,7 @@ env_base.android_java_dirs=[] env_base.android_res_dirs=[] env_base.android_aidl_dirs=[] env_base.android_jni_dirs=[] +env_base.android_default_config=[] env_base.android_manifest_chunk="" env_base.android_permission_chunk="" env_base.android_appattributes_chunk="" @@ -88,6 +89,7 @@ env_base.__class__.android_add_java_dir=methods.android_add_java_dir env_base.__class__.android_add_res_dir=methods.android_add_res_dir env_base.__class__.android_add_aidl_dir=methods.android_add_aidl_dir env_base.__class__.android_add_jni_dir=methods.android_add_jni_dir +env_base.__class__.android_add_default_config=methods.android_add_default_config env_base.__class__.android_add_to_manifest = methods.android_add_to_manifest env_base.__class__.android_add_to_permissions = methods.android_add_to_permissions env_base.__class__.android_add_to_attributes = methods.android_add_to_attributes diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index ace7e7c7b7..6edc292b62 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -435,6 +435,18 @@ String _OS::get_locale() const { return OS::get_singleton()->get_locale(); } +String _OS::get_latin_keyboard_variant() const { + switch( OS::get_singleton()->get_latin_keyboard_variant() ) { + case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY"; + case OS::LATIN_KEYBOARD_QWERTZ: return "QWERTZ"; + case OS::LATIN_KEYBOARD_AZERTY: return "AZERTY"; + case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY"; + case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK"; + case OS::LATIN_KEYBOARD_NEO : return "NEO"; + default: return "ERROR"; + } +} + String _OS::get_model_name() const { return OS::get_singleton()->get_model_name(); @@ -1097,6 +1109,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec); ObjectTypeDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec); ObjectTypeDB::bind_method(_MD("get_locale"),&_OS::get_locale); + ObjectTypeDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant); ObjectTypeDB::bind_method(_MD("get_model_name"),&_OS::get_model_name); ObjectTypeDB::bind_method(_MD("get_custom_level"),&_OS::get_custom_level); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 856d942d02..5bd427578a 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -192,6 +192,8 @@ public: Vector<String> get_cmdline_args(); String get_locale() const; + String get_latin_keyboard_variant() const; + String get_model_name() const; MainLoop *get_main_loop() const; diff --git a/doc/base/classes.xml b/doc/base/classes.xml index cffbd68939..dd00a0312c 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -6676,6 +6676,17 @@ Force the camera to update scroll immediately. </description> </method> + <method name="reset_smoothing"> + <description> + Set the camera's position immediately to its current smoothing destination. + This has no effect if smoothing is disabled. + </description> + </method> + <method name="align"> + <description> + Align the camera to the tracked node + </description> + </method> <method name="get_anchor_mode" qualifiers="const"> <return type="int"> </return> @@ -21677,6 +21688,12 @@ <description> </description> </method> + <method name="is_displayed_folded" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> <method name="is_fixed_processing" qualifiers="const"> <return type="bool"> </return> @@ -21802,6 +21819,12 @@ <description> </description> </method> + <method name="set_display_folded"> + <argument index="0" name="fold" type="bool"> + </argument> + <description> + </description> + </method> <method name="set_filename"> <argument index="0" name="filename" type="String"> </argument> @@ -31551,6 +31574,13 @@ <description> </description> </method> + <method name="get_text"> + <return type="String"> + </return> + <description> + Returns the raw text, stripping out the formatting information. + </description> + </method> <method name="get_total_character_count" qualifiers="const"> <return type="int"> </return> diff --git a/main/input_default.cpp b/main/input_default.cpp index 4fcb450bce..e975d4141f 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -30,6 +30,7 @@ #include "servers/visual_server.h" #include "os/os.h" #include "input_map.h" +#include "scene/resources/texture.h" void InputDefault::SpeedTrack::update(const Vector2& p_delta_p) { @@ -463,9 +464,11 @@ void InputDefault::set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_ set_mouse_mode(MOUSE_MODE_VISIBLE); VisualServer::get_singleton()->cursor_set_visible(false); } else { + Ref<AtlasTexture> atex = custom_cursor; + Rect2 region = atex.is_valid() ? atex->get_region() : Rect2(); set_mouse_mode(MOUSE_MODE_HIDDEN); VisualServer::get_singleton()->cursor_set_visible(true); - VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(),p_hotspot); + VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(),p_hotspot, 0, region); VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos()); } } diff --git a/methods.py b/methods.py index 7128b334ec..74c282b8cf 100755 --- a/methods.py +++ b/methods.py @@ -1326,7 +1326,9 @@ def android_add_aidl_dir(self,subpath): def android_add_jni_dir(self,subpath): base_path = self.Dir(".").abspath+"/modules/"+self.current_module+"/"+subpath self.android_jni_dirs.append(base_path) - +def android_add_default_config(self,config): + self.android_default_config.append(config) + def android_add_to_manifest(self,file): base_path = self.Dir(".").abspath+"/modules/"+self.current_module+"/"+file f = open(base_path,"rb") diff --git a/platform/android/SCsub b/platform/android/SCsub index c8feac8690..0814f4a7bc 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -79,6 +79,11 @@ for x in env.android_jni_dirs: gradle_asset_dirs_text="" +gradle_default_config_text="" + +for x in env.android_default_config: + gradle_default_config_text+=x+"\n\t\t" + gradle_text = gradle_text.replace("$$GRADLE_REPOSITORY_URLS$$",gradle_maven_repos_text) gradle_text = gradle_text.replace("$$GRADLE_DEPENDENCIES$$",gradle_maven_dependencies_text) gradle_text = gradle_text.replace("$$GRADLE_JAVA_DIRS$$",gradle_java_dirs_text) @@ -86,6 +91,7 @@ gradle_text = gradle_text.replace("$$GRADLE_RES_DIRS$$",gradle_res_dirs_text) gradle_text = gradle_text.replace("$$GRADLE_ASSET_DIRS$$",gradle_asset_dirs_text) gradle_text = gradle_text.replace("$$GRADLE_AIDL_DIRS$$",gradle_aidl_dirs_text) gradle_text = gradle_text.replace("$$GRADLE_JNI_DIRS$$",gradle_jni_dirs_text) +gradle_text = gradle_text.replace("$$GRADLE_DEFAULT_CONFIG$$",gradle_default_config_text) gradle_baseout.write( gradle_text ) diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template index 1e1461ef29..9e617a9e9e 100644 --- a/platform/android/build.gradle.template +++ b/platform/android/build.gradle.template @@ -39,6 +39,7 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 23 + $$GRADLE_DEFAULT_CONFIG$$ } sourceSets { main { diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 89de969cff..b0a50ca4b8 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2178,6 +2178,68 @@ String OS_Windows::get_locale() const { return "en"; } + +OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const { + + unsigned long azerty[] = { + 0x00020401, // Arabic (102) AZERTY + 0x0001080c, // Belgian (Comma) + 0x0000080c, // Belgian French + 0x0000040c, // French + 0 // <--- STOP MARK + }; + unsigned long qwertz[] = { + 0x0000041a, // Croation + 0x00000405, // Czech + 0x00000407, // German + 0x00010407, // German (IBM) + 0x0000040e, // Hungarian + 0x0000046e, // Luxembourgish + 0x00010415, // Polish (214) + 0x00000418, // Romanian (Legacy) + 0x0000081a, // Serbian (Latin) + 0x0000041b, // Slovak + 0x00000424, // Slovenian + 0x0001042e, // Sorbian Extended + 0x0002042e, // Sorbian Standard + 0x0000042e, // Sorbian Standard (Legacy) + 0x0000100c, // Swiss French + 0x00000807, // Swiss German + 0 // <--- STOP MARK + }; + unsigned long dvorak[] = { + 0x00010409, // US-Dvorak + 0x00030409, // US-Dvorak for left hand + 0x00040409, // US-Dvorak for right hand + 0 // <--- STOP MARK + }; + + char name[ KL_NAMELENGTH + 1 ]; name[0] = 0; + GetKeyboardLayoutNameA( name ); + + unsigned long hex = strtoul(name, NULL, 16); + + int i=0; + while( azerty[i] != 0 ) { + if (azerty[i] == hex) return LATIN_KEYBOARD_AZERTY; + i++; + } + + i = 0; + while( qwertz[i] != 0 ) { + if (qwertz[i] == hex) return LATIN_KEYBOARD_QWERTZ; + i++; + } + + i = 0; + while( dvorak[i] != 0 ) { + if (dvorak[i] == hex) return LATIN_KEYBOARD_DVORAK; + i++; + } + + return LATIN_KEYBOARD_QWERTY; +} + void OS_Windows::release_rendering_thread() { gl_context->release_current(); diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index d2249bf352..5acb300c0f 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -266,6 +266,7 @@ public: virtual String get_executable_path() const; virtual String get_locale() const; + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; virtual void move_window_to_foreground(); virtual String get_data_dir() const; diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 27e07a35be..f98a50e3e0 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -408,6 +408,35 @@ void Camera2D::force_update_scroll() { _update_scroll(); } +void Camera2D::reset_smoothing() { + + smoothed_camera_pos = camera_pos; + _update_scroll(); +} + +void Camera2D::align() { + + Size2 screen_size = get_viewport_rect().size; + screen_size=get_viewport_rect().size; + Point2 current_camera_pos = get_global_transform().get_origin(); + if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) { + if (h_ofs<0) { + camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs; + } else { + camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs; + } + if (v_ofs<0) { + camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs; + } else { + camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; + } + } else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){ + + camera_pos=current_camera_pos; + } + + _update_scroll(); +} void Camera2D::set_follow_smoothing(float p_speed) { @@ -543,6 +572,8 @@ void Camera2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_follow_smoothing_enabled"),&Camera2D::is_follow_smoothing_enabled); ObjectTypeDB::bind_method(_MD("force_update_scroll"),&Camera2D::force_update_scroll); + ObjectTypeDB::bind_method(_MD("reset_smoothing"),&Camera2D::reset_smoothing); + ObjectTypeDB::bind_method(_MD("align"),&Camera2D::align); ObjectTypeDB::bind_method(_MD("_set_old_smoothing","follow_smoothing"),&Camera2D::_set_old_smoothing); diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 22e5bc382a..b3f55d798d 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -128,6 +128,8 @@ public: Vector2 get_camera_pos() const; void force_update_scroll(); + void reset_smoothing(); + void align(); Camera2D(); }; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index d6c018ae8e..6c47072b33 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -31,6 +31,7 @@ #include "os/os.h" #include "print_string.h" #include "label.h" +#include "translation.h" #ifdef TOOLS_ENABLED #include "tools/editor/editor_settings.h" #endif @@ -947,7 +948,7 @@ String LineEdit::get_text() const { void LineEdit::set_placeholder(String p_text) { - placeholder = p_text; + placeholder = XL_MESSAGE(p_text); update(); } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 31cef85aa0..b4fa463cde 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -662,8 +662,7 @@ void RichTextLabel::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - if (use_bbcode) - parse_bbcode(bbcode); + set_bbcode(bbcode); main->first_invalid_line=0; //invalidate ALL update(); @@ -1440,7 +1439,6 @@ bool RichTextLabel::is_scroll_following() const { Error RichTextLabel::parse_bbcode(const String& p_bbcode) { - clear(); return append_bbcode(p_bbcode); } @@ -1858,6 +1856,10 @@ void RichTextLabel::set_bbcode(const String& p_bbcode) { bbcode=p_bbcode; if (is_inside_tree() && use_bbcode) parse_bbcode(p_bbcode); + else { // raw text + clear(); + add_text(p_bbcode); + } } String RichTextLabel::get_bbcode() const { @@ -1869,19 +1871,37 @@ void RichTextLabel::set_use_bbcode(bool p_enable) { if (use_bbcode==p_enable) return; use_bbcode=p_enable; - if (is_inside_tree() && use_bbcode) - parse_bbcode(bbcode); + set_bbcode(bbcode); } bool RichTextLabel::is_using_bbcode() const { return use_bbcode; } + +String RichTextLabel::get_text() { + String text = ""; + Item *it = main; + while (it) { + if (it->type == ITEM_TEXT) { + ItemText *t = static_cast<ItemText*>(it); + text += t->text; + } else if (it->type == ITEM_NEWLINE) { + text += "\n"; + } else if (it->type == ITEM_INDENT) { + text += "\t"; + } + it=_get_next_item(it,true); + } + return text; +} + void RichTextLabel::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&RichTextLabel::_input_event); ObjectTypeDB::bind_method(_MD("_scroll_changed"),&RichTextLabel::_scroll_changed); + ObjectTypeDB::bind_method(_MD("get_text"),&RichTextLabel::get_text); ObjectTypeDB::bind_method(_MD("add_text","text"),&RichTextLabel::add_text); ObjectTypeDB::bind_method(_MD("add_image","image:Texture"),&RichTextLabel::add_image); ObjectTypeDB::bind_method(_MD("newline"),&RichTextLabel::add_newline); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 635fe87ad4..5147905a0e 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -280,6 +280,7 @@ protected: public: + String get_text(); void add_text(const String& p_text); void add_image(const Ref<Texture>& p_image); void add_newline(); diff --git a/scene/resources/sample_library.cpp b/scene/resources/sample_library.cpp index 73517b180e..67481f267d 100644 --- a/scene/resources/sample_library.cpp +++ b/scene/resources/sample_library.cpp @@ -106,9 +106,9 @@ void SampleLibrary::remove_sample(const StringName& p_name) { sample_map.erase(p_name); } -void SampleLibrary::get_sample_list(List<StringName> *p_samples) { +void SampleLibrary::get_sample_list(List<StringName> *p_samples) const { - for(Map<StringName,SampleData >::Element *E=sample_map.front();E;E=E->next()) { + for(const Map<StringName,SampleData >::Element *E=sample_map.front();E;E=E->next()) { p_samples->push_back(E->key()); } @@ -177,7 +177,20 @@ float SampleLibrary::sample_get_pitch_scale(const StringName& p_name) const{ return sample_map[p_name].pitch_scale; } +Array SampleLibrary::_get_sample_list() const { + List<StringName> snames; + get_sample_list(&snames); + + snames.sort_custom<StringName::AlphCompare>(); + + Array ret; + for (List<StringName>::Element *E=snames.front();E;E=E->next()) { + ret.push_back(E->get()); + } + + return ret; +} void SampleLibrary::_bind_methods() { @@ -186,6 +199,8 @@ void SampleLibrary::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_sample","name"),&SampleLibrary::has_sample ); ObjectTypeDB::bind_method(_MD("remove_sample","name"),&SampleLibrary::remove_sample ); + ObjectTypeDB::bind_method(_MD("get_sample_list"),&SampleLibrary::_get_sample_list ); + ObjectTypeDB::bind_method(_MD("sample_set_volume_db","name","db"),&SampleLibrary::sample_set_volume_db ); ObjectTypeDB::bind_method(_MD("sample_get_volume_db","name"),&SampleLibrary::sample_get_volume_db ); diff --git a/scene/resources/sample_library.h b/scene/resources/sample_library.h index 8377967106..e572aa215a 100644 --- a/scene/resources/sample_library.h +++ b/scene/resources/sample_library.h @@ -47,6 +47,8 @@ class SampleLibrary : public Resource { }; Map<StringName,SampleData > sample_map; + + Array _get_sample_list() const; protected: bool _set(const StringName& p_name, const Variant& p_value); @@ -66,7 +68,7 @@ public: void sample_set_pitch_scale(const StringName& p_name, float p_pitch); float sample_get_pitch_scale(const StringName& p_name) const; Ref<Sample> get_sample(const StringName& p_name) const; - void get_sample_list(List<StringName> *p_samples); + void get_sample_list(List<StringName> *p_samples) const; void remove_sample(const StringName& p_name); StringName get_sample_idx(int p_idx) const; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 526179c41f..d89ea887fa 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -4448,12 +4448,13 @@ void VisualServerRaster::cursor_set_rotation(float p_rotation, int p_cursor) { cursors[p_cursor].rot = p_rotation; }; -void VisualServerRaster::cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor) { +void VisualServerRaster::cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor, const Rect2 &p_region) { VS_CHANGED; ERR_FAIL_INDEX(p_cursor, MAX_CURSORS); cursors[p_cursor].texture = p_texture; cursors[p_cursor].center = p_center_offset; + cursors[p_cursor].region = p_region; }; void VisualServerRaster::cursor_set_visible(bool p_visible, int p_cursor) { @@ -7530,8 +7531,13 @@ void VisualServerRaster::_draw_cursors_and_margins() { RID tex = cursors[i].texture?cursors[i].texture:default_cursor_texture; ERR_CONTINUE( !tex ); - Point2 size(texture_get_width(tex), texture_get_height(tex)); - rasterizer->canvas_draw_rect(Rect2(cursors[i].pos, size), 0, Rect2(), tex, Color(1, 1, 1, 1)); + if (cursors[i].region.has_no_area()) { + Point2 size(texture_get_width(tex), texture_get_height(tex)); + rasterizer->canvas_draw_rect(Rect2(cursors[i].pos, size), 0, Rect2(), tex, Color(1, 1, 1, 1)); + } else { + Point2 size = cursors[i].region.size; + rasterizer->canvas_draw_rect(Rect2(cursors[i].pos, size), Rasterizer::CANVAS_RECT_REGION, cursors[i].region, tex, Color(1, 1, 1, 1)); + } }; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 0480d9f5cb..228a4a7c44 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -544,10 +544,12 @@ class VisualServerRaster : public VisualServer { RID texture; Point2 center; bool visible; + Rect2 region; Cursor() { rot = 0; visible = false; + region = Rect2(); }; }; @@ -1240,7 +1242,7 @@ public: /* CURSOR */ virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0); // radians - virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor=0); + virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor=0, const Rect2 &p_region=Rect2()); virtual void cursor_set_visible(bool p_visible, int p_cursor = 0); virtual void cursor_set_pos(const Point2& p_pos, int p_cursor = 0); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index a97b232c03..8c39b0bea1 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -680,7 +680,7 @@ public: /* CURSOR */ FUNC2(cursor_set_rotation,float , int ); // radians - FUNC3(cursor_set_texture,RID , const Point2 &, int ); + FUNC4(cursor_set_texture,RID , const Point2 &, int, const Rect2 &); FUNC2(cursor_set_visible,bool , int ); FUNC2(cursor_set_pos,const Point2& , int ); diff --git a/servers/visual_server.h b/servers/visual_server.h index f330a6faee..64318dfd72 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -1110,7 +1110,7 @@ public: /* CURSOR */ virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0)=0; // radians - virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor=0)=0; + virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor=0, const Rect2 &p_region=Rect2())=0; virtual void cursor_set_visible(bool p_visible, int p_cursor = 0)=0; virtual void cursor_set_pos(const Point2& p_pos, int p_cursor = 0)=0; diff --git a/tools/editor/editor_autoload_settings.cpp b/tools/editor/editor_autoload_settings.cpp new file mode 100644 index 0000000000..1cf0090e7e --- /dev/null +++ b/tools/editor/editor_autoload_settings.cpp @@ -0,0 +1,618 @@ +/*************************************************************************/ +/* editor_autoload_settings.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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_autoload_settings.h" + +#include "globals.h" +#include "global_constants.h" + +#include "editor_node.h" + +#define PREVIEW_LIST_MAX_SIZE 10 + +StringName EditorAutoloadSettings::autoload_changed = StringName(); + +void EditorAutoloadSettings::_notification(int p_what) { + + if (p_what == NOTIFICATION_ENTER_TREE) { + + List<String> afn; + ResourceLoader::get_recognized_extensions_for_type("Script", &afn); + ResourceLoader::get_recognized_extensions_for_type("PackedScene", &afn); + + EditorFileDialog *file_dialog = autoload_add_path->get_file_dialog(); + + for (List<String>::Element *E = afn.front(); E; E = E->next()) { + + file_dialog->add_filter("*." + E->get()); + } + } +} + +bool EditorAutoloadSettings::_autoload_name_is_valid(const String& p_name, String* r_error) { + + if (!p_name.is_valid_identifier()) { + if (r_error) + *r_error = TTR("Invalid name.") + "\n" + TTR("Valid characters:")+" a-z, A-Z, 0-9 or _"; + + return false; + } + + if (ObjectTypeDB::type_exists(p_name)) { + if (r_error) + *r_error = TTR("Invalid name. Must not collide with an existing engine class name."); + + return false; + } + + for (int i = 0; i < Variant::VARIANT_MAX; i++) { + if (Variant::get_type_name( Variant::Type(i) ) == p_name) { + if (r_error) + *r_error = TTR("Invalid name. Must not collide with an existing buit-in type name."); + + return false; + } + } + + for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { + if (GlobalConstants::get_global_constant_name(i) == p_name) { + if (r_error) + *r_error = TTR("Invalid name. Must not collide with an existing global constant name."); + + return false; + } + } + + return true; +} + +void EditorAutoloadSettings::_autoload_add() { + + String name = autoload_add_name->get_text(); + + String error; + if (!_autoload_name_is_valid(name, &error)) { + EditorNode::get_singleton()->show_warning(error); + return; + } + + String path = autoload_add_path->get_line_edit()->get_text(); + if (!FileAccess::exists(path)) { + EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist.")); + return; + } + + if (!path.begins_with("res://")) { + EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n"+ TTR("Not in resource path.")); + return; + } + + name = "autoload/" + name; + + UndoRedo* undo_redo = EditorNode::get_singleton()->get_undo_redo(); + + undo_redo->create_action(TTR("Add AutoLoad")); + undo_redo->add_do_property(Globals::get_singleton(), name, "*" + path); + undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, true); + + if (Globals::get_singleton()->has(name)) { + undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name)); + } else { + undo_redo->add_undo_property(Globals::get_singleton(), name, Variant()); + } + + undo_redo->add_do_method(this, "update_autoload"); + undo_redo->add_undo_method(this, "update_autoload"); + + undo_redo->add_do_method(this, "emit_signal", autoload_changed); + undo_redo->add_undo_method(this, "emit_signal", autoload_changed); + + undo_redo->commit_action(); + + autoload_add_path->get_line_edit()->set_text(""); + autoload_add_name->set_text(""); +} + +void EditorAutoloadSettings::_autoload_selected() { + + TreeItem *ti = tree->get_selected(); + + if (!ti) + return; + + selected_autoload = "autoload/" + ti->get_text(0); +} + +void EditorAutoloadSettings::_autoload_edited() { + + if (updating_autoload) + return; + + TreeItem *ti = tree->get_edited(); + int column = tree->get_edited_column(); + + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + if (column == 0) { + String name = ti->get_text(0); + String old_name = selected_autoload.get_slice("/", 1); + + if (name == old_name) + return; + + String error; + if (!_autoload_name_is_valid(name, &error)) { + ti->set_text(0, old_name); + EditorNode::get_singleton()->show_warning(error); + return; + } + + if (Globals::get_singleton()->has("autoload/" + name)) { + ti->set_text(0, old_name); + EditorNode::get_singleton()->show_warning(vformat(TTR("Autoload '%s' already exists!"), name)); + return; + } + + updating_autoload = true; + + name = "autoload/" + name; + + bool persisting = Globals::get_singleton()->get(selected_autoload); + int order = Globals::get_singleton()->get(selected_autoload); + String path = Globals::get_singleton()->get(selected_autoload); + + undo_redo->create_action(TTR("Rename Autoload")); + + undo_redo->add_do_property(Globals::get_singleton(), name, path); + undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, persisting); + undo_redo->add_do_method(Globals::get_singleton(), "set_order", name, order); + undo_redo->add_do_method(Globals::get_singleton(), "clear", selected_autoload); + + undo_redo->add_undo_property(Globals::get_singleton(), selected_autoload, path); + undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", selected_autoload, persisting); + undo_redo->add_undo_method(Globals::get_singleton(), "set_order", selected_autoload, order); + undo_redo->add_undo_method(Globals::get_singleton(), "clear", name); + + undo_redo->add_do_method(this, "update_autoload"); + undo_redo->add_undo_method(this, "update_autoload"); + + undo_redo->add_do_method(this, "emit_signal", autoload_changed); + undo_redo->add_undo_method(this, "emit_signal", autoload_changed); + + undo_redo->commit_action(); + + selected_autoload = name; + } else if (column == 2) { + updating_autoload = true; + + bool checked = ti->is_checked(2); + String base = "autoload/" + ti->get_text(0); + + int order = Globals::get_singleton()->get_order(base); + String path = Globals::get_singleton()->get(base); + + if (path.begins_with("*")) + path = path.substr(1, path.length()); + + if (checked) + path = "*" + path; + + undo_redo->create_action(TTR("Toggle AutoLoad Globals")); + + undo_redo->add_do_property(Globals::get_singleton(), base, path); + undo_redo->add_undo_property(Globals::get_singleton(), base, Globals::get_singleton()->get(base)); + + undo_redo->add_do_method(Globals::get_singleton(),"set_order", base, order); + undo_redo->add_undo_method(Globals::get_singleton(),"set_order", base, order); + + undo_redo->add_do_method(this, "update_autoload"); + undo_redo->add_undo_method(this, "update_autoload"); + + undo_redo->add_do_method(this, "emit_signal", autoload_changed); + undo_redo->add_undo_method(this, "emit_signal", autoload_changed); + + undo_redo->commit_action(); + } + + updating_autoload = false; +} + +void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_column, int p_button) { + + TreeItem *ti = p_item->cast_to<TreeItem>(); + + String name = "autoload/" + ti->get_text(0); + + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + switch (p_button) { + + case BUTTON_MOVE_UP: + case BUTTON_MOVE_DOWN: { + + TreeItem *swap = NULL; + + if (p_button == BUTTON_MOVE_UP) { + swap = ti->get_prev(); + } else { + swap = ti->get_next(); + } + + if (!swap) + return; + + String swap_name = "autoload/" + swap->get_text(0); + + int order = Globals::get_singleton()->get_order(name); + int swap_order = Globals::get_singleton()->get_order(swap_name); + + undo_redo->create_action(TTR("Move Autoload")); + + undo_redo->add_do_method(Globals::get_singleton(), "set_order", name, swap_order); + undo_redo->add_undo_method(Globals::get_singleton(), "set_order", name, order); + + undo_redo->add_do_method(Globals::get_singleton(), "set_order", swap_name, order); + undo_redo->add_undo_method(Globals::get_singleton(), "set_order", swap_name, swap_order); + + undo_redo->add_do_method(this, "update_autoload"); + undo_redo->add_undo_method(this, "update_autoload"); + + undo_redo->add_do_method(this, "emit_signal", autoload_changed); + undo_redo->add_undo_method(this, "emit_signal", autoload_changed); + + undo_redo->commit_action(); + } break; + case BUTTON_DELETE: { + + int order = Globals::get_singleton()->get_order(name); + + undo_redo->create_action(TTR("Remove Autoload")); + + undo_redo->add_do_property(Globals::get_singleton(), name, Variant()); + + undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name)); + undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", name, true); + undo_redo->add_undo_method(Globals::get_singleton(), "set_order", order); + + undo_redo->add_do_method(this, "update_autoload"); + undo_redo->add_undo_method(this, "update_autoload"); + + undo_redo->add_do_method(this, "emit_signal", autoload_changed); + undo_redo->add_undo_method(this, "emit_signal", autoload_changed); + + undo_redo->commit_action(); + } break; + } +} + +void EditorAutoloadSettings::_autoload_file_callback(const String& p_path) { + + autoload_add_name->set_text(p_path.get_file().basename()); +} + +void EditorAutoloadSettings::update_autoload() { + + if (updating_autoload) + return; + + updating_autoload = true; + + autoload_cache.clear(); + + tree->clear(); + TreeItem *root = tree->create_item(); + + List<PropertyInfo> props; + Globals::get_singleton()->get_property_list(&props); + + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + + const PropertyInfo &pi = E->get(); + + if (!pi.name.begins_with("autoload/")) + continue; + + String name = pi.name.get_slice("/", 1); + String path = Globals::get_singleton()->get(pi.name); + + if (name.empty()) + continue; + + AutoLoadInfo info; + info.name = pi.name; + info.order = Globals::get_singleton()->get_order(pi.name); + + autoload_cache.push_back(info); + + bool global = false; + + if (path.begins_with("*")) { + global = true; + path = path.substr(1, path.length()); + } + + TreeItem *item = tree->create_item(root); + item->set_text(0, name); + item->set_editable(0, true); + + item->set_text(1, path); + item->set_selectable(1, false); + + item->set_cell_mode(2, TreeItem::CELL_MODE_CHECK); + item->set_editable(2, true); + item->set_text(2, TTR("Enable")); + item->set_checked(2, global); + + item->add_button(3, get_icon("MoveUp","EditorIcons"), BUTTON_MOVE_UP); + item->add_button(3, get_icon("MoveDown","EditorIcons"), BUTTON_MOVE_DOWN); + item->add_button(3, get_icon("Del","EditorIcons"), BUTTON_DELETE); + item->set_selectable(3, false); + } + + updating_autoload = false; +} + +Variant EditorAutoloadSettings::get_drag_data_fw(const Point2& p_point, Control *p_control) { + + if (autoload_cache.size() <= 1) + return false; + + StringArray autoloads; + + TreeItem *next = tree->get_next_selected(NULL); + + while (next) { + autoloads.push_back(next->get_text(0)); + next = tree->get_next_selected(next); + } + + if (autoloads.size() == 0 || autoloads.size() == autoload_cache.size()) + return Variant(); + + VBoxContainer *preview = memnew( VBoxContainer ); + + int max_size = MIN(PREVIEW_LIST_MAX_SIZE, autoloads.size()); + + for (int i = 0; i < max_size; i++) { + Label *label = memnew( Label(autoloads[i]) ); + label->set_self_opacity(Math::lerp(1, 0, float(i)/PREVIEW_LIST_MAX_SIZE)); + + preview->add_child(label); + } + + tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); + tree->set_drag_preview(preview); + + Dictionary drop_data; + drop_data["type"] = "autoload"; + drop_data["autoloads"] = autoloads; + + return drop_data; +} + +bool EditorAutoloadSettings::can_drop_data_fw(const Point2& p_point, const Variant& p_data, Control *p_control) const { + if (updating_autoload) + return false; + + Dictionary drop_data = p_data; + + if (!drop_data.has("type")) + return false; + + if (drop_data.has("type")) { + TreeItem *ti = tree->get_item_at_pos(p_point); + + if (!ti) + return false; + + int section = tree->get_drop_section_at_pos(p_point); + + if (section < -1) + return false; + + return true; + } + + return false; +} + +void EditorAutoloadSettings::drop_data_fw(const Point2& p_point, const Variant& p_data, Control *p_control) { + + TreeItem *ti = tree->get_item_at_pos(p_point); + + if (!ti) + return; + + int section = tree->get_drop_section_at_pos(p_point); + + if (section < -1) + return; + + String name; + bool move_to_back = false; + + if (section < 0) { + name = ti->get_text(0); + } else if (ti->get_next()) { + name = ti->get_next()->get_text(0); + } else { + name = ti->get_text(0); + move_to_back = true; + } + + int order = Globals::get_singleton()->get_order("autoload/" + name); + + AutoLoadInfo aux; + List<AutoLoadInfo>::Element *E = NULL; + + if (!move_to_back) { + aux.order = order; + E = autoload_cache.find(aux); + } + + Dictionary drop_data = p_data; + StringArray autoloads = drop_data["autoloads"]; + + Vector<int> orders; + orders.resize(autoload_cache.size()); + + for (int i = 0; i < autoloads.size(); i++) { + aux.order = Globals::get_singleton()->get_order("autoload/" + autoloads[i]); + + List<AutoLoadInfo>::Element *I = autoload_cache.find(aux); + + if (move_to_back) { + autoload_cache.move_to_back(I); + } else if (E != I) { + autoload_cache.move_before(I, E); + } else if (E->next()) { + E = E->next(); + } else { + break; + } + } + + int i = 0; + + for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { + orders[i++] = E->get().order; + } + + orders.sort(); + + UndoRedo *undo_redo = EditorNode::get_undo_redo(); + + undo_redo->create_action(TTR("Rearrange Autoloads")); + + i = 0; + + for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { + undo_redo->add_do_method(Globals::get_singleton(), "set_order", E->get().name, orders[i++]); + undo_redo->add_undo_method(Globals::get_singleton(), "set_order", E->get().name, E->get().order); + } + + orders.clear(); + + undo_redo->add_do_method(this, "update_autoload"); + undo_redo->add_undo_method(this, "update_autoload"); + + undo_redo->add_do_method(this, "emit_signal", autoload_changed); + undo_redo->add_undo_method(this, "emit_signal", autoload_changed); + + undo_redo->commit_action(); +} + +void EditorAutoloadSettings::_bind_methods() { + + ObjectTypeDB::bind_method("_autoload_add", &EditorAutoloadSettings::_autoload_add); + ObjectTypeDB::bind_method("_autoload_selected", &EditorAutoloadSettings::_autoload_selected); + ObjectTypeDB::bind_method("_autoload_edited", &EditorAutoloadSettings::_autoload_edited); + ObjectTypeDB::bind_method("_autoload_button_pressed", &EditorAutoloadSettings::_autoload_button_pressed); + ObjectTypeDB::bind_method("_autoload_file_callback", &EditorAutoloadSettings::_autoload_file_callback); + + ObjectTypeDB::bind_method("get_drag_data_fw", &EditorAutoloadSettings::get_drag_data_fw); + ObjectTypeDB::bind_method("can_drop_data_fw", &EditorAutoloadSettings::can_drop_data_fw); + ObjectTypeDB::bind_method("drop_data_fw", &EditorAutoloadSettings::drop_data_fw); + + ObjectTypeDB::bind_method("update_autoload", &EditorAutoloadSettings::update_autoload); + + ADD_SIGNAL(MethodInfo("autoload_changed")); +} + +EditorAutoloadSettings::EditorAutoloadSettings() { + + autoload_changed = "autoload_changed"; + + updating_autoload = false; + selected_autoload = ""; + + HBoxContainer *hbc = memnew( HBoxContainer ); + add_child(hbc); + + VBoxContainer *vbc_path = memnew( VBoxContainer ); + vbc_path->set_h_size_flags(SIZE_EXPAND_FILL); + + autoload_add_path = memnew( EditorLineEditFileChooser ); + autoload_add_path->set_h_size_flags(SIZE_EXPAND_FILL); + + autoload_add_path->get_file_dialog()->set_mode(EditorFileDialog::MODE_OPEN_FILE); + autoload_add_path->get_file_dialog()->connect("file_selected", this, "_autoload_file_callback"); + + vbc_path->add_margin_child(TTR("Path:"), autoload_add_path); + hbc->add_child(vbc_path); + + VBoxContainer *vbc_name = memnew( VBoxContainer ); + vbc_name->set_h_size_flags(SIZE_EXPAND_FILL); + + HBoxContainer *hbc_name = memnew( HBoxContainer ); + + autoload_add_name = memnew( LineEdit ); + autoload_add_name->set_h_size_flags(SIZE_EXPAND_FILL); + hbc_name->add_child(autoload_add_name); + + Button *add_autoload = memnew( Button ); + add_autoload->set_text(TTR("Add")); + hbc_name->add_child(add_autoload); + add_autoload->connect("pressed", this, "_autoload_add"); + + vbc_name->add_margin_child(TTR("Node Name:"), hbc_name); + hbc->add_child(vbc_name); + + tree = memnew( Tree ); + tree->set_hide_root(true); + tree->set_select_mode(Tree::SELECT_MULTI); + tree->set_single_select_cell_editing_only_when_already_selected(true); + + tree->set_drag_forwarding(this); + + tree->set_columns(4); + tree->set_column_titles_visible(true); + + tree->set_column_title(0,TTR("Name")); + tree->set_column_expand(0,true); + tree->set_column_min_width(0,100); + + tree->set_column_title(1,TTR("Path")); + tree->set_column_expand(1,true); + tree->set_column_min_width(1,100); + + tree->set_column_title(2,TTR("Singleton")); + tree->set_column_expand(2,false); + tree->set_column_min_width(2,80); + + tree->set_column_expand(3,false); + tree->set_column_min_width(3,80); + + tree->connect("cell_selected", this, "_autoload_selected"); + tree->connect("item_edited", this, "_autoload_edited"); + tree->connect("button_pressed", this, "_autoload_button_pressed"); + + add_margin_child(TTR("List:"), tree, true); +} + diff --git a/tools/editor/editor_autoload_settings.h b/tools/editor/editor_autoload_settings.h new file mode 100644 index 0000000000..b8825f807c --- /dev/null +++ b/tools/editor/editor_autoload_settings.h @@ -0,0 +1,94 @@ +/*************************************************************************/ +/* editor_autoload_settings.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ + +#ifndef EDITOR_AUTOLOAD_SETTINGS_H +#define EDITOR_AUTOLOAD_SETTINGS_H + +#include "scene/gui/tree.h" + +#include "editor_file_dialog.h" + +class EditorAutoloadSettings : public VBoxContainer { + + OBJ_TYPE( EditorAutoloadSettings, VBoxContainer ); + + enum { + BUTTON_MOVE_UP, + BUTTON_MOVE_DOWN, + BUTTON_DELETE + }; + + static StringName autoload_changed; + + struct AutoLoadInfo { + String name; + int order; + + bool operator==(const AutoLoadInfo& p_info) { + return order == p_info.order; + } + }; + + List<AutoLoadInfo> autoload_cache; + + bool updating_autoload; + int number_of_autoloads; + String selected_autoload; + + Tree *tree; + EditorLineEditFileChooser *autoload_add_path; + LineEdit *autoload_add_name; + + bool _autoload_name_is_valid(const String& p_string, String *r_error = NULL); + + void _autoload_add(); + void _autoload_selected(); + void _autoload_edited(); + void _autoload_button_pressed(Object *p_item, int p_column, int p_button); + void _autoload_file_callback(const String& p_path); + + Variant get_drag_data_fw(const Point2& p_point, Control *p_from); + bool can_drop_data_fw(const Point2& p_point, const Variant& p_data, Control *p_from) const; + void drop_data_fw(const Point2& p_point, const Variant& p_data, Control *p_from); + +protected: + + void _notification(int p_what); + static void _bind_methods(); + +public: + + void update_autoload(); + + EditorAutoloadSettings(); + +}; + +#endif + diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 91a347c69b..a70df78697 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -77,21 +77,30 @@ void SpatialEditorViewport::_update_camera() { String SpatialEditorGizmo::get_handle_name(int p_idx) const { + if (get_script_instance() && get_script_instance()->has_method("get_handle_name")) + return get_script_instance()->call("get_handle_name", p_idx); + return ""; } Variant SpatialEditorGizmo::get_handle_value(int p_idx) const{ + if (get_script_instance() && get_script_instance()->has_method("get_handle_value")) + return get_script_instance()->call("get_handle_value", p_idx); + return Variant(); } void SpatialEditorGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_point) { + if (get_script_instance() && get_script_instance()->has_method("set_handle")) + get_script_instance()->call("set_handle", p_idx, p_camera, p_point); } void SpatialEditorGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_cancel){ - + if (get_script_instance() && get_script_instance()->has_method("commit_handle")) + get_script_instance()->call("commit_handle", p_idx, p_restore, p_cancel); } bool SpatialEditorGizmo::intersect_frustum(const Camera *p_camera,const Vector<Plane> &p_frustum) { diff --git a/tools/editor/plugins/tile_set_editor_plugin.cpp b/tools/editor/plugins/tile_set_editor_plugin.cpp index a2c7147bf3..39a15189e7 100644 --- a/tools/editor/plugins/tile_set_editor_plugin.cpp +++ b/tools/editor/plugins/tile_set_editor_plugin.cpp @@ -73,24 +73,24 @@ void TileSetEditor::_import_scene(Node *scene, Ref<TileSet> p_library, bool p_me p_library->tile_set_name(id,mi->get_name()); } - - p_library->tile_set_texture(id,texture); p_library->tile_set_material(id,material); Vector2 phys_offset; + Size2 s; - if (mi->is_centered()) { - Size2 s; - if (mi->is_region()) { - s=mi->get_region_rect().size; - } else { - s=texture->get_size(); - } - phys_offset+=-s/2; - } if (mi->is_region()) { + s=mi->get_region_rect().size; p_library->tile_set_region(id,mi->get_region_rect()); + } else { + const int frame = mi->get_frame(); + const int hframes = mi->get_hframes(); + s=texture->get_size()/Size2(hframes,mi->get_vframes()); + p_library->tile_set_region(id,Rect2(Vector2(frame%hframes,frame/hframes)*s,s)); + } + + if (mi->is_centered()) { + phys_offset+=-s/2; } Vector<Ref<Shape2D> >collisions; diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index 6822e50b73..6be1abf52f 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -100,16 +100,6 @@ void ProjectSettings::_notification(int p_what) { translation_res_file_open->add_filter("*."+E->get()); translation_res_option_file_open->add_filter("*."+E->get()); } - - List<String> afn; - ResourceLoader::get_recognized_extensions_for_type("Script",&afn); - ResourceLoader::get_recognized_extensions_for_type("PackedScene",&afn); - - for (List<String>::Element *E=afn.front();E;E=E->next()) { - - autoload_file_open->add_filter("*."+E->get()); - } - } } @@ -564,7 +554,7 @@ void ProjectSettings::popup_project_settings() { popup_centered_ratio(); globals_editor->update_category_list(); _update_translations(); - _update_autoload(); + autoload_settings->update_autoload(); plugin_settings->update_plugins(); } @@ -616,10 +606,26 @@ void ProjectSettings::_item_add() { String name = catname!="" ? catname+"/"+propname : propname; - Globals::get_singleton()->set(name,value); + undo_redo->create_action("Add Global Property"); + + undo_redo->add_do_property(Globals::get_singleton(), name, value); + undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, true); + + if (Globals::get_singleton()->has(name)) { + undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name)); + } else { + undo_redo->add_undo_property(Globals::get_singleton(), name, Variant()); + } + + undo_redo->add_do_method(globals_editor, "update_category_list"); + undo_redo->add_undo_method(globals_editor, "update_category_list"); + + undo_redo->add_do_method(this, "_settings_changed"); + undo_redo->add_undo_method(this, "_settings_changed"); + + undo_redo->commit_action(); globals_editor->set_current_section(catname); - globals_editor->update_category_list(); _settings_changed(); } @@ -633,10 +639,20 @@ void ProjectSettings::_item_del() { String name = catname!="" ? catname+"/"+propname : propname; - Globals::get_singleton()->set(name,Variant()); + undo_redo->create_action("Delete Global Property"); - globals_editor->set_current_section(catname); - globals_editor->update_category_list(); + undo_redo->add_do_property(Globals::get_singleton(), name, Variant()); + + undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name)); + undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", name, Globals::get_singleton()->is_persisting(name)); + + undo_redo->add_do_method(globals_editor, "update_category_list"); + undo_redo->add_undo_method(globals_editor, "update_category_list"); + + undo_redo->add_do_method(this, "_settings_changed"); + undo_redo->add_undo_method(this, "_settings_changed"); + + undo_redo->commit_action(); _settings_changed(); } @@ -811,263 +827,6 @@ void ProjectSettings::_translation_file_open() { translation_file_open->popup_centered_ratio(); } - -void ProjectSettings::_autoload_file_callback(const String& p_path) { - - autoload_add_path->set_text(p_path); - //if (autoload_add_name->get_text().strip_edges()==String()) { - - autoload_add_name->set_text( p_path.get_file().basename() ); - //} - - //_translation_add(p_translation); -} - -void ProjectSettings::_autoload_file_open() { - - autoload_file_open->popup_centered_ratio(); -} - -void ProjectSettings::_autoload_edited() { - - if (updating_autoload) - return; - - TreeItem *ti = autoload_list->get_edited(); - int column = autoload_list->get_edited_column(); - - if (!ti || (column != 0 && column != 2)) - return; - - if (column == 0) { - String name = ti->get_text(0); - String old_name = selected_autoload.substr(selected_autoload.find("/")+1,selected_autoload.length()); - - if (!name.is_valid_identifier()) { - ti->set_text(0,old_name); - message->set_text(TTR("Invalid name.")+"\n"+TTR("Valid characters:")+" a-z, A-Z, 0-9 or _"); - message->popup_centered(Size2(300,100)); - return; - } - - if (ObjectTypeDB::type_exists(name)) { - ti->set_text(0,old_name); - message->set_text(TTR("Invalid name. Must not collide with an existing engine class name.")); - message->popup_centered(Size2(400,100)); - return; - } - - for(int i=0;i<Variant::VARIANT_MAX;i++) { - if (Variant::get_type_name(Variant::Type(i))==name) { - ti->set_text(0,old_name); - message->set_text(TTR("Invalid name. Must not collide with an existing buit-in type name.")); - message->popup_centered(Size2(400,100)); - return; - } - } - - for(int i=0;i<GlobalConstants::get_global_constant_count();i++) { - if (GlobalConstants::get_global_constant_name(i)==name) { - ti->set_text(0,old_name); - message->set_text(TTR("Invalid name. Must not collide with an existing global constant name.")); - message->popup_centered(Size2(400,100)); - return; - } - } - - if (Globals::get_singleton()->has("autoload/"+name)) { - ti->set_text(0,old_name); - message->set_text(vformat(TTR("Autoload '%s' already exists!"),name)); - message->popup_centered(Size2(300,100)); - return; - } - - updating_autoload = true; - - name = "autoload/"+name; - String path = Globals::get_singleton()->get(selected_autoload); - bool is_persisting = Globals::get_singleton()->is_persisting(selected_autoload); - int order = Globals::get_singleton()->get_order(selected_autoload); - - undo_redo->create_action(TTR("Rename Autoload")); - undo_redo->add_do_property(Globals::get_singleton(),name,path); - undo_redo->add_do_method(Globals::get_singleton(),"set_persisting",name,is_persisting); - undo_redo->add_do_method(Globals::get_singleton(),"set_order",name,order); - undo_redo->add_do_method(Globals::get_singleton(),"clear",selected_autoload); - undo_redo->add_undo_property(Globals::get_singleton(),selected_autoload,path); - undo_redo->add_undo_method(Globals::get_singleton(),"set_persisting",selected_autoload,is_persisting); - undo_redo->add_undo_method(Globals::get_singleton(),"set_order",selected_autoload,order); - undo_redo->add_undo_method(Globals::get_singleton(),"clear",name); - undo_redo->add_do_method(this,"_update_autoload"); - undo_redo->add_undo_method(this,"_update_autoload"); - undo_redo->add_do_method(this,"_settings_changed"); - undo_redo->add_undo_method(this,"_settings_changed"); - undo_redo->commit_action(); - - selected_autoload = name; - } else if (column == 2) { - updating_autoload = true; - - bool checked = ti->is_checked(2); - String base = "autoload/"+ti->get_text(0); - String path = Globals::get_singleton()->get(base); - int order = Globals::get_singleton()->get_order(base); - - if (path.begins_with("*")) - path = path.substr(1,path.length()); - - if (checked) - path = "*" + path; - - undo_redo->create_action(TTR("Toggle AutoLoad Globals")); - undo_redo->add_do_property(Globals::get_singleton(),base,path); - undo_redo->add_undo_property(Globals::get_singleton(),base,Globals::get_singleton()->get(base)); - undo_redo->add_do_method(Globals::get_singleton(),"set_order",base,order); // keep order, as config order matters for these - undo_redo->add_undo_method(Globals::get_singleton(),"set_order",base,order); - undo_redo->add_do_method(this,"_update_autoload"); - undo_redo->add_undo_method(this,"_update_autoload"); - undo_redo->add_do_method(this,"_settings_changed"); - undo_redo->add_undo_method(this,"_settings_changed"); - undo_redo->commit_action(); - } - - updating_autoload = false; -} - -void ProjectSettings::_autoload_add() { - - String name = autoload_add_name->get_text(); - if (!name.is_valid_identifier()) { - message->set_text(TTR("Invalid name.")+"\n"+TTR("Valid characters:")+" a-z, A-Z, 0-9 or _"); - message->popup_centered(Size2(300,100)); - return; - - } - - if (ObjectTypeDB::type_exists(name)) { - - message->set_text(TTR("Invalid name. Must not collide with an existing engine class name.")); - message->popup_centered(Size2(300,100)); - return; - - } - - for(int i=0;i<Variant::VARIANT_MAX;i++) { - if (Variant::get_type_name(Variant::Type(i))==name) { - - message->set_text(TTR("Invalid name. Must not collide with an existing buit-in type name.")); - message->popup_centered(Size2(300,100)); - return; - - } - } - - for(int i=0;i<GlobalConstants::get_global_constant_count();i++) { - - if (GlobalConstants::get_global_constant_name(i)==name) { - - message->set_text(TTR("Invalid name. Must not collide with an existing global constant name.")); - message->popup_centered(Size2(300,100)); - return; - } - - } - - String path = autoload_add_path->get_text(); - if (!FileAccess::exists(path)) { - message->set_text("Invalid Path.\nFile does not exist."); - message->popup_centered(Size2(300,100)); - return; - - } - if (!path.begins_with("res://")) { - message->set_text("Invalid Path.\nNot in resource path."); - message->popup_centered(Size2(300,100)); - return; - - } - - undo_redo->create_action(TTR("Add Autoload")); - name = "autoload/"+name; - undo_redo->add_do_property(Globals::get_singleton(),name,"*"+path); - if (Globals::get_singleton()->has(name)) - undo_redo->add_undo_property(Globals::get_singleton(),name,Globals::get_singleton()->get(name)); - else - undo_redo->add_undo_property(Globals::get_singleton(),name,Variant()); - - undo_redo->add_do_method(Globals::get_singleton(),"set_persisting",name,true); - undo_redo->add_do_method(this,"_update_autoload"); - undo_redo->add_undo_method(this,"_update_autoload"); - undo_redo->add_do_method(this,"_settings_changed"); - undo_redo->add_undo_method(this,"_settings_changed"); - undo_redo->commit_action(); - - autoload_add_path->set_text(""); - autoload_add_name->set_text(""); - - //autoload_file_open->popup_centered_ratio(); -} - -void ProjectSettings::_autoload_delete(Object *p_item,int p_column, int p_button) { - - - TreeItem *ti=p_item->cast_to<TreeItem>(); - String name = "autoload/"+ti->get_text(0); - - if (p_button==0) { - //delete - int order = Globals::get_singleton()->get_order(name); - undo_redo->create_action(TTR("Remove Autoload")); - undo_redo->add_do_property(Globals::get_singleton(),name,Variant()); - undo_redo->add_undo_property(Globals::get_singleton(),name,Globals::get_singleton()->get(name)); - undo_redo->add_undo_method(Globals::get_singleton(),"set_persisting",name,true); - undo_redo->add_undo_method(Globals::get_singleton(),"set_order",name,order); - undo_redo->add_do_method(this,"_update_autoload"); - undo_redo->add_undo_method(this,"_update_autoload"); - undo_redo->add_do_method(this,"_settings_changed"); - undo_redo->add_undo_method(this,"_settings_changed"); - undo_redo->commit_action(); - } else { - - TreeItem *swap = NULL; - - if (p_button==1) { - swap=ti->get_prev(); - } else if (p_button==2) { - swap=ti->get_next(); - } - if (!swap) - return; - - String swap_name= "autoload/"+swap->get_text(0); - - int order = Globals::get_singleton()->get_order(name); - int swap_order = Globals::get_singleton()->get_order(swap_name); - - undo_redo->create_action(TTR("Move Autoload")); - undo_redo->add_do_method(Globals::get_singleton(),"set_order",swap_name,order); - undo_redo->add_do_method(Globals::get_singleton(),"set_order",name,swap_order); - undo_redo->add_undo_method(Globals::get_singleton(),"set_order",swap_name,swap_order); - undo_redo->add_undo_method(Globals::get_singleton(),"set_order",name,order); - undo_redo->add_do_method(this,"_update_autoload"); - undo_redo->add_undo_method(this,"_update_autoload"); - undo_redo->add_do_method(this,"_settings_changed"); - undo_redo->add_undo_method(this,"_settings_changed"); - undo_redo->commit_action(); - - } - -} - -void ProjectSettings::_autoload_selected() { - TreeItem *ti = autoload_list->get_selected(); - - if (!ti) - return; - - selected_autoload = "autoload/"+ti->get_text(0); -} - void ProjectSettings::_translation_delete(Object *p_item,int p_column, int p_button) { TreeItem *ti = p_item->cast_to<TreeItem>(); @@ -1393,55 +1152,6 @@ void ProjectSettings::_update_translations() { } -void ProjectSettings::_update_autoload() { - - if (updating_autoload) - return; - - updating_autoload=true; - - autoload_list->clear(); - TreeItem *root = autoload_list->create_item(); - autoload_list->set_hide_root(true); - - List<PropertyInfo> props; - Globals::get_singleton()->get_property_list(&props); - - for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { - - const PropertyInfo &pi=E->get(); - if (!pi.name.begins_with("autoload/")) - continue; - - String name = pi.name.get_slice("/",1); - String path = Globals::get_singleton()->get(pi.name); - - if (name=="") - continue; - bool global=false; - if (path.begins_with("*")) { - path=path.substr(1,path.length()); - global=true; - } - TreeItem *t = autoload_list->create_item(root); - t->set_text(0,name); - t->set_editable(0,true); - t->set_text(1,path); - t->set_cell_mode(2,TreeItem::CELL_MODE_CHECK); - t->set_editable(2,true); - t->set_text(2,TTR("Enable")); - t->set_checked(2,global); - t->add_button(3,get_icon("MoveUp","EditorIcons"),1); - t->add_button(3,get_icon("MoveDown","EditorIcons"),2); - t->add_button(3,get_icon("Del","EditorIcons"),0); - - - } - - updating_autoload=false; - -} - void ProjectSettings::_toggle_search_bar(bool p_pressed) { globals_editor->get_property_editor()->set_use_filter(p_pressed); @@ -1508,14 +1218,6 @@ void ProjectSettings::_bind_methods() { ObjectTypeDB::bind_method(_MD("_translation_res_delete"),&ProjectSettings::_translation_res_delete); ObjectTypeDB::bind_method(_MD("_translation_res_option_delete"),&ProjectSettings::_translation_res_option_delete); - ObjectTypeDB::bind_method(_MD("_autoload_add"),&ProjectSettings::_autoload_add); - ObjectTypeDB::bind_method(_MD("_autoload_file_open"),&ProjectSettings::_autoload_file_open); - ObjectTypeDB::bind_method(_MD("_autoload_file_callback"),&ProjectSettings::_autoload_file_callback); - ObjectTypeDB::bind_method(_MD("_update_autoload"),&ProjectSettings::_update_autoload); - ObjectTypeDB::bind_method(_MD("_autoload_delete"),&ProjectSettings::_autoload_delete); - ObjectTypeDB::bind_method(_MD("_autoload_edited"),&ProjectSettings::_autoload_edited); - ObjectTypeDB::bind_method(_MD("_autoload_selected"),&ProjectSettings::_autoload_selected); - ObjectTypeDB::bind_method(_MD("_clear_search_box"),&ProjectSettings::_clear_search_box); ObjectTypeDB::bind_method(_MD("_toggle_search_bar"),&ProjectSettings::_toggle_search_bar); @@ -1858,69 +1560,10 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { { - VBoxContainer *avb = memnew( VBoxContainer ); - tab_container->add_child(avb); - avb->set_name(TTR("AutoLoad")); - HBoxContainer *ahb = memnew( HBoxContainer); - avb->add_child(ahb); - - - VBoxContainer *avb_path = memnew( VBoxContainer ); - avb_path->set_h_size_flags(SIZE_EXPAND_FILL); - HBoxContainer *ahb_path = memnew( HBoxContainer ); - autoload_add_path = memnew(LineEdit); - autoload_add_path->set_h_size_flags(SIZE_EXPAND_FILL); - ahb_path->add_child(autoload_add_path); - Button *browseaa = memnew( Button("..") ); - ahb_path->add_child(browseaa); - browseaa->connect("pressed",this,"_autoload_file_open"); - - avb_path->add_margin_child(TTR("Path:"),ahb_path); - ahb->add_child(avb_path); - - VBoxContainer *avb_name = memnew( VBoxContainer ); - avb_name->set_h_size_flags(SIZE_EXPAND_FILL); - - HBoxContainer *ahb_name = memnew( HBoxContainer ); - autoload_add_name = memnew(LineEdit); - autoload_add_name->set_h_size_flags(SIZE_EXPAND_FILL); - ahb_name->add_child(autoload_add_name); - avb_name->add_margin_child(TTR("Node Name:"),ahb_name); - Button *addaa = memnew( Button(TTR("Add")) ); - ahb_name->add_child(addaa); - addaa->connect("pressed",this,"_autoload_add"); - - ahb->add_child(avb_name); - - autoload_list = memnew( Tree ); - autoload_list->set_v_size_flags(SIZE_EXPAND_FILL); - avb->add_margin_child(TTR("List:"),autoload_list,true); - - autoload_file_open=memnew( EditorFileDialog ); - add_child(autoload_file_open); - autoload_file_open->set_mode(EditorFileDialog::MODE_OPEN_FILE); - autoload_file_open->connect("file_selected",this,"_autoload_file_callback"); - - autoload_list->set_columns(4); - autoload_list->set_column_titles_visible(true); - autoload_list->set_column_title(0,TTR("Name")); - autoload_list->set_column_expand(0,true); - autoload_list->set_column_min_width(0,100); - autoload_list->set_column_title(1,TTR("Path")); - autoload_list->set_column_expand(1,true); - autoload_list->set_column_min_width(1,100); - autoload_list->set_column_title(2,TTR("Singleton")); - autoload_list->set_column_expand(2,false); - autoload_list->set_column_min_width(2,80); - autoload_list->set_column_expand(3,false); - autoload_list->set_column_min_width(3,80); - - autoload_list->connect("button_pressed",this,"_autoload_delete"); - autoload_list->connect("item_edited",this,"_autoload_edited"); - autoload_list->connect("cell_selected", this, "_autoload_selected"); - - updating_autoload=false; - + autoload_settings = memnew( EditorAutoloadSettings ); + autoload_settings->set_name(TTR("AutoLoad")); + tab_container->add_child(autoload_settings); + autoload_settings->connect("autoload_changed", this, "_settings_changed"); } { diff --git a/tools/editor/project_settings.h b/tools/editor/project_settings.h index 79e1acf75e..46e98f69ad 100644 --- a/tools/editor/project_settings.h +++ b/tools/editor/project_settings.h @@ -34,6 +34,7 @@ #include "undo_redo.h" #include "editor_data.h" #include "scene/gui/tab_container.h" +#include "editor_autoload_settings.h" #include "editor_plugin_settings.h" //#include "project_export_settings.h" @@ -88,26 +89,10 @@ class ProjectSettings : public AcceptDialog { Tree *translation_remap; Tree *translation_remap_options; - - Tree *autoload_list; - String selected_autoload; - EditorFileDialog *autoload_file_open; - LineEdit *autoload_add_name; - LineEdit *autoload_add_path; - + EditorAutoloadSettings *autoload_settings; EditorPluginSettings *plugin_settings; - void _update_autoload(); - void _autoload_file_callback(const String& p_path); - void _autoload_add(); - void _autoload_edited(); - void _autoload_file_open(); - void _autoload_delete(Object *p_item,int p_column, int p_button); - void _autoload_selected(); - bool updating_autoload; - - void _item_selected(); void _item_adds(String); void _item_add(); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 7816dd9bc7..ceb62d5ff0 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -4187,6 +4187,8 @@ public: void SectionedPropertyEditor::_bind_methods() { ObjectTypeDB::bind_method("_section_selected",&SectionedPropertyEditor::_section_selected); + + ObjectTypeDB::bind_method("update_category_list", &SectionedPropertyEditor::update_category_list); } void SectionedPropertyEditor::_section_selected(int p_which) { diff --git a/tools/editor/spatial_editor_gizmos.cpp b/tools/editor/spatial_editor_gizmos.cpp index edc2fc513d..480d33fd0a 100644 --- a/tools/editor/spatial_editor_gizmos.cpp +++ b/tools/editor/spatial_editor_gizmos.cpp @@ -623,12 +623,11 @@ void EditorSpatialGizmo::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_unscaled_billboard","material:Material","default_scale"),&EditorSpatialGizmo::add_unscaled_billboard,DEFVAL(1)); ObjectTypeDB::bind_method(_MD("add_handles","handles","billboard","secondary"),&EditorSpatialGizmo::add_handles,DEFVAL(false),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("set_spatial_node","node:Spatial"),&EditorSpatialGizmo::_set_spatial_node); + ObjectTypeDB::bind_method(_MD("clear"),&EditorSpatialGizmo::clear); BIND_VMETHOD( MethodInfo("redraw")); BIND_VMETHOD( MethodInfo(Variant::STRING,"get_handle_name",PropertyInfo(Variant::INT,"index"))); - { - BIND_VMETHOD( MethodInfo("get_handle_value:Variant",PropertyInfo(Variant::INT,"index"))); - } + BIND_VMETHOD( MethodInfo("get_handle_value:Variant",PropertyInfo(Variant::INT,"index"))); BIND_VMETHOD( MethodInfo("set_handle",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::OBJECT,"camera:Camera"),PropertyInfo(Variant::VECTOR2,"point"))); MethodInfo cm = MethodInfo("commit_handle",PropertyInfo(Variant::INT,"index"),PropertyInfo(Variant::NIL,"restore:Variant"),PropertyInfo(Variant::BOOL,"cancel")); cm.default_arguments.push_back(false); |