diff options
46 files changed, 1324 insertions, 449 deletions
diff --git a/.gitignore b/.gitignore index 0e516e4a68..537ed7d32a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ core/global_defaults.cpp core/method_bind_ext.inc core/method_bind.inc core/script_encryption_key.cpp -core/version.h +core/version_generated.h drivers/gles2/shaders/*.h drivers/gles3/shaders/*.h drivers/unix/os_unix_global_settings_path.cpp diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21ce52d6e3..23ab874a2e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,7 +90,7 @@ The Godot Engine community has [many communication channels](https://godotengine To communicate with developers (e.g. to discuss a feature you want to implement or a bug you want to fix), the following channels can be used: - [GitHub issues](https://github.com/godotengine/godot/issues): If there is an existing issue about a topic you want to discuss, just add a comment to it - all developers watch the repository and will get an email notification. You can also create a new issue - please keep in mind to create issues only to discuss quite specific points about the development, and not general user feedback or support requests. -- [#godotengine-devel IRC channel on Freenode](http://webchat.freenode.net/?channels=godotengine-devel): You will find most core developers there, so it's the go-to channel for direct chat about Godot Engine development. Feel free to start discussing something there to get some early feedback before writing up a detailed proposal in a GitHub issue. +- [#godotengine-devel IRC channel on Freenode](https://webchat.freenode.net/?channels=godotengine-devel): You will find most core developers there, so it's the go-to channel for direct chat about Godot Engine development. Feel free to start discussing something there to get some early feedback before writing up a detailed proposal in a GitHub issue. - [devel@godotengine.org mailing list](https://listengine.tuxfamily.org/godotengine.org/devel/): Mailing list for Godot developers, used primarily to announce developer meetings on IRC and other important discussions that need to reach people directly in their mailbox. See the [index page](https://listengine.tuxfamily.org/godotengine.org/devel/) for subscription instructions. Thanks! diff --git a/core/global_config.cpp b/core/global_config.cpp index d37c67c84a..f9a0877c23 100644 --- a/core/global_config.cpp +++ b/core/global_config.cpp @@ -53,6 +53,11 @@ String GlobalConfig::get_resource_path() const { return resource_path; }; +String GlobalConfig::get_project_file_name() const { + + return project_file_name; +} + String GlobalConfig::localize_path(const String &p_path) const { if (resource_path == "") @@ -236,13 +241,43 @@ bool GlobalConfig::_load_resource_pack(const String &p_pack) { return true; } +static String _find_project_file(DirAccess *p_diraccess, bool p_res = false) { + p_diraccess->list_dir_begin(); + String ret = ""; + while (true) { + bool isdir; + String file = p_diraccess->get_next(&isdir); + if (file == "") + break; + + if (!isdir) { + if (file.get_extension() == "godot") { + + if (p_res) { + ret = "res://" + file; + } else { + ret = p_diraccess->get_current_dir() + "/" + file; + } + } + } + } + p_diraccess->list_dir_end(); + return ret; +} + +static String _find_project_file() { + DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES); + String ret = _find_project_file(dir, true); + memdelete(dir); + return ret; +} + Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { //If looking for files in network, just use network! - if (FileAccessNetworkClient::get_singleton()) { - - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { _load_settings("res://override.cfg"); } @@ -258,8 +293,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { bool ok = _load_resource_pack(p_main_pack); ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN); - - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { //load override from location of the main pack _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg")); } @@ -272,7 +307,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { if (_load_resource_pack(exec_path.get_basename() + ".pck")) { - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { //load override from location of executable _load_settings(exec_path.get_base_dir().plus_file("override.cfg")); } @@ -292,15 +328,15 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { // data.pck and data.zip are deprecated and no longer supported, apologies. // make sure this is loaded from the resource path - - if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) { + String gdproj = _find_project_file(); + if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) { _load_settings("res://override.cfg"); } return OK; } - //Nothing was found, try to find a godot.cfg somewhere! + //Nothing was found, try to find a *.godot somewhere! DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); ERR_FAIL_COND_V(!d, ERR_CANT_CREATE); @@ -313,8 +349,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) { while (true) { //try to load settings in ascending through dirs shape! - - if (_load_settings(current_dir + "/godot.cfg") == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) { + String gdproj = _find_project_file(d); + if (_load_settings(gdproj) == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) { _load_settings(current_dir + "/override.cfg"); candidate = current_dir; @@ -428,6 +464,7 @@ Error GlobalConfig::_load_settings(const String p_path) { err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); if (err == ERR_FILE_EOF) { memdelete(f); + project_file_name = p_path.get_file(); return OK; } else if (err != OK) { ERR_PRINTS("GlobalConfig::load - " + p_path + ":" + itos(lines) + " error: " + error_text); @@ -449,6 +486,7 @@ Error GlobalConfig::_load_settings(const String p_path) { } } + project_file_name = p_path.get_file(); memdelete(f); return OK; @@ -474,7 +512,12 @@ void GlobalConfig::clear(const String &p_name) { Error GlobalConfig::save() { - return save_custom(get_resource_path() + "/godot.cfg"); + if (project_file_name.empty()) { + String name = ((String)get("application/name")).replace(" ", "_"); + return save_custom(get_resource_path() + "/" + name + ".godot"); + } else { + return save_custom(get_resource_path() + "/" + project_file_name); + } } Error GlobalConfig::_save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom) { @@ -483,7 +526,7 @@ Error GlobalConfig::_save_settings_binary(const String &p_file, const Map<String FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); if (err != OK) { - ERR_EXPLAIN("Coudln't save godot.cfb at " + p_file); + ERR_EXPLAIN("Couldn't save godot.cfb at " + p_file); ERR_FAIL_COND_V(err, err) } @@ -548,7 +591,7 @@ Error GlobalConfig::_save_settings_text(const String &p_file, const Map<String, FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err); if (err) { - ERR_EXPLAIN("Coudln't save godot.cfg - " + p_file); + ERR_EXPLAIN("Couldn't save project file - " + p_file); ERR_FAIL_COND_V(err, err) } @@ -658,7 +701,7 @@ Error GlobalConfig::save_custom(const String &p_path, const CustomMap &p_custom, props[category].push_back(name); } - if (p_path.ends_with(".cfg")) + if (p_path.ends_with(".godot")) return _save_settings_text(p_path, props, p_custom); else if (p_path.ends_with(".cfb")) return _save_settings_binary(p_path, props, p_custom); @@ -828,6 +871,7 @@ void GlobalConfig::_bind_methods() { ClassDB::bind_method(D_METHOD("clear", "name"), &GlobalConfig::clear); ClassDB::bind_method(D_METHOD("localize_path", "path"), &GlobalConfig::localize_path); ClassDB::bind_method(D_METHOD("globalize_path", "path"), &GlobalConfig::globalize_path); + ClassDB::bind_method(D_METHOD("get_project_file_name"), &GlobalConfig::get_project_file_name); ClassDB::bind_method(D_METHOD("save"), &GlobalConfig::save); ClassDB::bind_method(D_METHOD("has_singleton", "name"), &GlobalConfig::has_singleton); ClassDB::bind_method(D_METHOD("get_singleton", "name"), &GlobalConfig::get_singleton_object); diff --git a/core/global_config.h b/core/global_config.h index d0f64dc23c..5148c4377e 100644 --- a/core/global_config.h +++ b/core/global_config.h @@ -111,6 +111,8 @@ protected: void _add_property_info_bind(const Dictionary &p_info); + String project_file_name; + protected: static void _bind_methods(); @@ -124,6 +126,7 @@ public: Variant property_get_revert(const String &p_name); String get_resource_path() const; + String get_project_file_name() const; static GlobalConfig *get_singleton(); diff --git a/core/hashfuncs.h b/core/hashfuncs.h index fbd2e161b3..8392984565 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -81,24 +81,6 @@ static inline uint32_t hash_one_uint64(const uint64_t p_int) { return (int)v; } -static inline uint32_t hash_djb2_one_float(float p_in, uint32_t p_prev = 5381) { - union { - float f; - uint32_t i; - } u; - - // Normalize +/- 0.0 and NaN values so they hash the same. - if (p_in == 0.0f) - u.f = 0.0; - else if (Math::is_nan(p_in)) - u.f = Math_NAN; - else - u.f = p_in; - - return ((p_prev << 5) + p_prev) + u.i; -} - -// Overload for real_t size changes static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381) { union { double d; diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 6a46b9fbe3..9f5a9c193a 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -30,7 +30,7 @@ #include "math_funcs.h" #include "core/os/os.h" -pcg32_random_t Math::default_pcg = { 1, PCG_DEFAULT_INC_64 }; +pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 }; #define PHI 0x9e3779b9 @@ -51,9 +51,7 @@ void Math::seed(uint64_t x) { } void Math::randomize() { - - OS::Time time = OS::get_singleton()->get_time(); - seed(OS::get_singleton()->get_ticks_usec() * (time.hour + 1) * (time.min + 1) * (time.sec + 1) * rand()); // TODO: can be simplified. + seed(OS::get_singleton()->get_ticks_usec() * default_pcg.state + PCG_DEFAULT_INC_64); } uint32_t Math::rand() { diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 10426c9243..d71d9bd792 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -157,7 +157,7 @@ public: static uint32_t larger_prime(uint32_t p_val); - static void seed(uint64_t x = 0); + static void seed(uint64_t x); static void randomize(); static uint32_t rand_from_seed(uint64_t *seed); static uint32_t rand(); diff --git a/core/os/os.cpp b/core/os/os.cpp index ab03bb8016..e323e03829 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -507,7 +507,6 @@ OS::OS() { _render_thread_mode = RENDER_THREAD_SAFE; _allow_hidpi = true; - Math::seed(1234567); } OS::~OS() { diff --git a/core/variant.cpp b/core/variant.cpp index 6e675d07de..67ce8af483 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -2839,7 +2839,7 @@ uint32_t Variant::hash() const { } #define hash_compare_scalar(p_lhs, p_rhs) \ - ((p_lhs) == (p_rhs)) || (Math::is_nan(p_lhs) == Math::is_nan(p_rhs)) + ((p_lhs) == (p_rhs)) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs)) #define hash_compare_vector2(p_lhs, p_rhs) \ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \ diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 7f9bb4a972..9b1f8c788b 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -6929,7 +6929,7 @@ <argument index="1" name="phi" type="float"> </argument> <description> - Introduce an additional rotation around the given axis by phi. Only relevant when the matrix is being used as a part of [Transform]. The axis must be a normalized vector. + Introduce an additional rotation around the given axis by phi (radians). Only relevant when the matrix is being used as a part of [Transform]. The axis must be a normalized vector. </description> </method> <method name="scaled"> @@ -8333,7 +8333,7 @@ <argument index="0" name="state" type="Variant"> </argument> <description> - Set the transform state of this CanvasItem. For [Node2D], this is an [Array] with (in order) a [Vector2] for position, a float for rotation and another [Vector2] for scale. For [Control] this is a [Rect2] with the position and size. + Set the transform state of this CanvasItem. For [Node2D], this is an [Array] with (in order) a [Vector2] for position, a float for rotation (radians) and another [Vector2] for scale. For [Control] this is a [Rect2] with the position and size. </description> </method> <method name="get_canvas" qualifiers="const"> @@ -8708,14 +8708,14 @@ <return type="float"> </return> <description> - Return the base rotation for this layer (helper). + Return the base rotation for this layer in radians (helper). </description> </method> <method name="get_rotationd" qualifiers="const"> <return type="float"> </return> <description> - Get rotation of the layer in degree. + Return the base rotation for this layer in degrees. </description> </method> <method name="get_scale" qualifiers="const"> @@ -8763,14 +8763,14 @@ <argument index="0" name="radians" type="float"> </argument> <description> - Set the base rotation for this layer (helper). + Set the base rotation for this layer in radians (helper). </description> </method> <method name="set_rotationd"> <argument index="0" name="degrees" type="float"> </argument> <description> - Set rotation of the layer in degree. + Set the base rotation for this layer in degrees (helper). </description> </method> <method name="set_scale"> @@ -10865,12 +10865,14 @@ <return type="float"> </return> <description> + Return the rotation (in radians) </description> </method> <method name="get_rotation_deg" qualifiers="const"> <return type="float"> </return> <description> + Return the rotation (in degrees) </description> </method> <method name="get_scale" qualifiers="const"> @@ -11185,12 +11187,14 @@ <argument index="0" name="radians" type="float"> </argument> <description> + Set the rotation (in radians). </description> </method> <method name="set_rotation_deg"> <argument index="0" name="degrees" type="float"> </argument> <description> + Set the rotation (in degrees). </description> </method> <method name="set_scale"> @@ -16414,7 +16418,7 @@ Contains global variables accessible from everywhere. </brief_description> <description> - Contains global variables accessible from everywhere. Use the normal [Object] API, such as "Globals.get(variable)", "Globals.set(variable,value)" or "Globals.has(variable)" to access them. Variables stored in godot.cfg are also loaded into globals, making this object very useful for reading custom game configuration options. + Contains global variables accessible from everywhere. Use the normal [Object] API, such as "Globals.get(variable)", "Globals.set(variable,value)" or "Globals.has(variable)" to access them. Variables stored in the project file (*.godot) are also loaded into globals, making this object very useful for reading custom game configuration options. </description> <methods> <method name="add_property_info"> @@ -25812,7 +25816,7 @@ <argument index="0" name="radians" type="float"> </argument> <description> - Apply a 'radians' rotation to the 2D node, starting from its current rotation. + Apply a rotation (in radians) to the 2D node, starting from its current rotation. </description> </method> <method name="scale"> @@ -39597,12 +39601,14 @@ <return type="Vector3"> </return> <description> + Return the rotation (in radians). </description> </method> <method name="get_rotation_deg" qualifiers="const"> <return type="Vector3"> </return> <description> + Return the rotation (in degrees). </description> </method> <method name="get_scale" qualifiers="const"> @@ -39771,12 +39777,14 @@ <argument index="0" name="rotation_rad" type="Vector3"> </argument> <description> + Set the rotation (in radians). </description> </method> <method name="set_rotation_deg"> <argument index="0" name="rotation_deg" type="Vector3"> </argument> <description> + Set the rotation (in degrees). </description> </method> <method name="set_scale"> @@ -46106,6 +46114,7 @@ <return type="float"> </return> <description> + Return the rotation (in radians). </description> </method> <method name="get_scale"> @@ -48386,6 +48395,7 @@ do_property]. <return type="float"> </return> <description> + Return the steering angle (in radians). </description> </method> <method name="set_brake"> @@ -48416,6 +48426,7 @@ do_property]. <argument index="0" name="steering" type="float"> </argument> <description> + Set the steering angle (in radians). </description> </method> </methods> diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index beed923a58..9316b025eb 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -5534,7 +5534,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glGenTextures(1, &rt->depth); glBindTexture(GL_TEXTURE_2D, rt->depth); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, rt->width, rt->height, 0, - GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); + GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -6500,7 +6500,7 @@ void RasterizerStorageGLES3::initialize() { frame.count = 0; frame.prev_tick = 0; frame.delta = 0; - frame.current_rt=NULL; + frame.current_rt = NULL; config.keep_original_textures = false; } diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index f789be24cf..fa12dd7408 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -101,7 +101,7 @@ void main() { restart_phase*= (1.0-explosiveness); bool restart=false; - bool active = velocity_active.a > 0.5; + bool shader_active = velocity_active.a > 0.5; if (system_phase > prev_system_phase) { if (prev_system_phase < restart_phase && system_phase >= restart_phase) { @@ -134,7 +134,7 @@ void main() { uint particle_number = current_cycle * uint(total_particles) + uint(gl_VertexID); if (restart) { - active=emitting; + shader_active=emitting; } mat4 xform; @@ -148,7 +148,7 @@ void main() { out_velocity_active=vec4(0.0); out_custom=vec4(0.0); if (!restart) - active=false; + shader_active=false; xform = mat4( vec4(1.0,0.0,0.0,0.0), @@ -163,7 +163,7 @@ void main() { xform = transpose(mat4(xform_1,xform_2,xform_3,vec4(vec3(0.0),1.0))); } - if (active) { + if (shader_active) { //execute shader { @@ -178,7 +178,7 @@ VERTEX_SHADER_CODE for(int i=0;i<attractor_count;i++) { vec3 rel_vec = xform[3].xyz - attractors[i].pos; - float dist = rel_vec.length(); + float dist = length(rel_vec); if (attractors[i].radius < dist) continue; if (attractors[i].eat_radius>0 && attractors[i].eat_radius > dist) { @@ -215,7 +215,7 @@ VERTEX_SHADER_CODE xform = transpose(xform); - out_velocity_active.a = mix(0.0,1.0,active); + out_velocity_active.a = mix(0.0,1.0,shader_active); out_xform_1 = xform[0]; out_xform_2 = xform[1]; diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 20525dd028..4ec2a3c391 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1071,7 +1071,8 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); - text_editor->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size")); + text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type") == "Tabs" ? 0 : 1); + text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); text_editor->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/line_numbers/line_numbers_zero_padded")); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 2612a2af16..3fb2923696 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -487,6 +487,22 @@ bool EditorFileSystem::_check_missing_imported_files(const String &p_path) { return true; } +static bool _find_project(const String &p_path) { + DirAccess *dir_access = DirAccess::create_for_path(p_path); + bool ret = false; + while (true) { + bool is_dir; + String file = dir_access->get_next(&is_dir); + if (file == "") + break; + if (file.ends_with(".godot")) { + ret = true; + } + } + memdelete(dir_access); + return ret; +} + void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess *da, const ScanProgress &p_progress) { List<String> dirs; @@ -509,8 +525,9 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess if (f.begins_with(".")) //ignore hidden and . / .. continue; - if (FileAccess::exists(cd.plus_file(f).plus_file("godot.cfg"))) // skip if another project inside this + if (_find_project(cd.plus_file(f))) { continue; + } dirs.push_back(f); @@ -676,34 +693,35 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const while (true) { bool isdir; - String f = da->get_next(&isdir); - if (f == "") + String file = da->get_next(&isdir); + if (file == "") break; if (isdir) { - if (f.begins_with(".")) //ignore hidden and . / .. + if (file.begins_with(".")) //ignore hidden and . / .. continue; - int idx = p_dir->find_dir_index(f); + int idx = p_dir->find_dir_index(file); if (idx == -1) { - if (FileAccess::exists(cd.plus_file(f).plus_file("godot.cfg"))) // skip if another project inside this + if (_find_project(cd.plus_file(file))) { continue; + } EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory); efd->parent = p_dir; - efd->name = f; + efd->name = file; DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); - d->change_dir(cd.plus_file(f)); + d->change_dir(cd.plus_file(file)); _scan_new_dir(efd, d, p_progress.get_sub(1, 1)); memdelete(d); ItemAction ia; ia.action = ItemAction::ACTION_DIR_ADD; ia.dir = p_dir; - ia.file = f; + ia.file = file; ia.new_dir = efd; scan_actions.push_back(ia); } else { @@ -711,16 +729,16 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const } } else { - String ext = f.get_extension().to_lower(); + String ext = file.get_extension().to_lower(); if (!valid_extensions.has(ext)) continue; //invalid - int idx = p_dir->find_file_index(f); + int idx = p_dir->find_file_index(file); if (idx == -1) { //never seen this file, add actition to add it EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo); - fi->file = f; + fi->file = file; String path = cd.plus_file(fi->file); fi->modified_time = FileAccess::get_modified_time(path); @@ -731,7 +749,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const ItemAction ia; ia.action = ItemAction::ACTION_FILE_ADD; ia.dir = p_dir; - ia.file = f; + ia.file = file; ia.new_file = fi; scan_actions.push_back(ia); } @@ -739,14 +757,14 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const if (import_extensions.has(ext)) { //if it can be imported, and it was added, it needs to be reimported print_line("REIMPORT: file was not found before, reimport"); - print_line("at dir: " + p_dir->get_path() + " file: " + f); + print_line("at dir: " + p_dir->get_path() + " file: " + file); for (int i = 0; i < p_dir->files.size(); i++) { print_line(itos(i) + ": " + p_dir->files[i]->file); } ItemAction ia; ia.action = ItemAction::ACTION_FILE_REIMPORT; ia.dir = p_dir; - ia.file = f; + ia.file = file; scan_actions.push_back(ia); } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 9baa203790..cc7ee44902 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -447,18 +447,6 @@ void EditorNode::_sources_changed(bool p_exist) { void EditorNode::_vp_resized() { } -void EditorNode::_rebuild_import_menu() { - PopupMenu *p = import_menu->get_popup(); - p->clear(); -//p->add_item(TTR("Node From Scene"), FILE_IMPORT_SUBSCENE); -//p->add_separator(); -#if 0 - for (int i = 0; i < editor_import_export->get_import_plugin_count(); i++) { - p->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(), IMPORT_PLUGIN_BASE + i); - } -#endif -} - void EditorNode::_node_renamed() { if (property_editor) @@ -4862,9 +4850,9 @@ EditorNode::EditorNode() { import_wav.instance(); ResourceFormatImporter::get_singleton()->add_importer(import_wav); - //Ref<ResourceImporterOBJ> import_obj; - //import_obj.instance(); - //ResourceFormatImporter::get_singleton()->add_importer(import_obj); + Ref<ResourceImporterOBJ> import_obj; + import_obj.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_obj); Ref<ResourceImporterScene> import_scene; import_scene.instance(); @@ -5257,15 +5245,6 @@ EditorNode::EditorNode() { menu_panel->add_child( resource_menu ); #endif - import_menu = memnew(MenuButton); - import_menu->set_tooltip(TTR("Import assets to the project.")); - import_menu->set_text(TTR("Import")); - //import_menu->set_icon(gui_base->get_icon("Save","EditorIcons")); - left_menu_hb->add_child(import_menu); - - p = import_menu->get_popup(); - p->connect("id_pressed", this, "_menu_option"); - tool_menu = memnew(MenuButton); tool_menu->set_tooltip(TTR("Miscellaneous project or scene-wide tools.")); tool_menu->set_text(TTR("Tools")); @@ -5960,8 +5939,6 @@ EditorNode::EditorNode() { circle_step_frame = Engine::get_singleton()->get_frames_drawn(); circle_step = 0; - _rebuild_import_menu(); - editor_plugin_screen = NULL; editor_plugins_over = memnew(EditorPluginList); diff --git a/editor/editor_node.h b/editor/editor_node.h index e7f4085fc5..7de713eae9 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -242,7 +242,6 @@ private: HBoxContainer *menu_hb; Control *viewport; MenuButton *file_menu; - MenuButton *import_menu; MenuButton *tool_menu; ToolButton *export_button; ToolButton *prev_scene; @@ -447,8 +446,6 @@ private: void _show_messages(); void _vp_resized(); - void _rebuild_import_menu(); - void _save_scene(String p_file, int idx = -1); void _instance_request(const Vector<String> &p_files); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 8ea5d16bbf..35373eb815 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -506,7 +506,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("interface/dim_editor_on_dialog_popup", true); set("interface/dim_amount", 0.6f); hints["interface/dim_amount"] = PropertyInfo(Variant::REAL, "interface/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT); - set("interface/dim_transition_time", 0.11f); + set("interface/dim_transition_time", 0.08f); hints["interface/dim_transition_time"] = PropertyInfo(Variant::REAL, "interface/dim_transition_time", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_DEFAULT); set("filesystem/directories/autoscan_project_path", ""); @@ -529,8 +529,11 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("text_editor/highlighting/highlight_all_occurrences", true); set("text_editor/cursor/scroll_past_end_of_file", false); - set("text_editor/indent/tab_size", 4); - hints["text_editor/indent/tab_size"] = PropertyInfo(Variant::INT, "text_editor/indent/tab_size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. + set("text_editor/indent/type", 0); + hints["text_editor/indent/type"] = PropertyInfo(Variant::STRING, "text_editor/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces"); + set("text_editor/indent/size", 4); + hints["text_editor/indent/size"] = PropertyInfo(Variant::INT, "text_editor/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. + set("text_editor/indent/convert_indent_on_save", false); set("text_editor/indent/draw_tabs", true); set("text_editor/line_numbers/show_line_numbers", true); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 8ce0f51211..48a2897e7a 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -530,6 +530,15 @@ void ScriptEditor::_resave_scripts(const String &p_str) { if (trim_trailing_whitespace_on_save) { se->trim_trailing_whitespace(); } + + if (convert_indent_on_save) { + if (use_space_indentation) { + se->convert_indent_to_spaces(); + } else { + se->convert_indent_to_tabs(); + } + } + editor->save_resource(script); se->tag_saved_version(); } @@ -795,12 +804,28 @@ void ScriptEditor::_menu_option(int p_option) { if (trim_trailing_whitespace_on_save) current->trim_trailing_whitespace(); + + if (convert_indent_on_save) { + if (use_space_indentation) { + current->convert_indent_to_spaces(); + } else { + current->convert_indent_to_tabs(); + } + } editor->save_resource(current->get_edited_script()); } break; case FILE_SAVE_AS: { current->trim_trailing_whitespace(); + + if (convert_indent_on_save) { + if (use_space_indentation) { + current->convert_indent_to_spaces(); + } else { + current->convert_indent_to_tabs(); + } + } editor->push_item(current->get_edited_script()->cast_to<Object>()); editor->save_resource_as(current->get_edited_script()); @@ -878,28 +903,29 @@ void ScriptEditor::_menu_option(int p_option) { } } } - } + } else { - EditorHelp *help = tab_container->get_current_tab_control()->cast_to<EditorHelp>(); - if (help) { + EditorHelp *help = tab_container->get_current_tab_control()->cast_to<EditorHelp>(); + if (help) { - switch (p_option) { + switch (p_option) { - case HELP_SEARCH_FIND: { - help->popup_search(); - } break; - case HELP_SEARCH_FIND_NEXT: { - help->search_again(); - } break; - case FILE_CLOSE: { - _close_current_tab(); - } break; - case CLOSE_DOCS: { - _close_docs_tab(); - } break; - case CLOSE_ALL: { - _close_all_tabs(); - } break; + case HELP_SEARCH_FIND: { + help->popup_search(); + } break; + case HELP_SEARCH_FIND_NEXT: { + help->search_again(); + } break; + case FILE_CLOSE: { + _close_current_tab(); + } break; + case CLOSE_DOCS: { + _close_docs_tab(); + } break; + case CLOSE_ALL: { + _close_all_tabs(); + } break; + } } } } @@ -1483,6 +1509,14 @@ void ScriptEditor::save_all_scripts() { se->trim_trailing_whitespace(); } + if (convert_indent_on_save) { + if (use_space_indentation) { + se->convert_indent_to_spaces(); + } else { + se->convert_indent_to_tabs(); + } + } + Ref<Script> script = se->get_edited_script(); if (script.is_valid()) se->apply_code(); @@ -1582,6 +1616,9 @@ void ScriptEditor::_save_layout() { void ScriptEditor::_editor_settings_changed() { trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/files/trim_trailing_whitespace_on_save"); + convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save"); + use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type") == "Tabs" ? 0 : 1; + float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs"); if (autosave_time > 0) { autosave_timer->set_wait_time(autosave_time); @@ -2160,6 +2197,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { edit_pass = 0; trim_trailing_whitespace_on_save = false; + convert_indent_on_save = false; + use_space_indentation = false; ScriptServer::edit_request_func = _open_script_request; } diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 51d9bd3fc8..fde3432b51 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -91,6 +91,8 @@ public: virtual void set_edit_state(const Variant &p_state) = 0; virtual void goto_line(int p_line, bool p_with_error = false) = 0; virtual void trim_trailing_whitespace() = 0; + virtual void convert_indent_to_spaces() = 0; + virtual void convert_indent_to_tabs() = 0; virtual void ensure_focus() = 0; virtual void tag_saved_version() = 0; virtual void reload(bool p_soft) = 0; @@ -252,6 +254,8 @@ class ScriptEditor : public VBoxContainer { void _res_saved_callback(const Ref<Resource> &p_res); bool trim_trailing_whitespace_on_save; + bool use_space_indentation; + bool convert_indent_on_save; void _trim_trailing_whitespace(TextEdit *tx); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index f020e36247..0eb53d1a66 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -290,6 +290,96 @@ void ScriptTextEditor::trim_trailing_whitespace() { } } +void ScriptTextEditor::convert_indent_to_spaces() { + TextEdit *tx = code_editor->get_text_edit(); + Ref<Script> scr = get_edited_script(); + + if (scr.is_null()) { + return; + } + + int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); + String indent = ""; + + for (int i = 0; i < indent_size; i++) { + indent += " "; + } + + bool changed_indentation = false; + for (int i = 0; i < tx->get_line_count(); i++) { + String line = tx->get_line(i); + + if (line.length() <= 0) { + continue; + } + + int j = 0; + while (j < line.length() && (line[j] == ' ' || line[j] == '\t')) { + if (line[j] == '\t') { + if (!changed_indentation) { + tx->begin_complex_operation(); + changed_indentation = true; + } + line = line.left(j) + indent + line.right(j + 1); + } + j++; + } + tx->set_line(i, line); + } + if (changed_indentation) { + tx->end_complex_operation(); + tx->update(); + } +} + +void ScriptTextEditor::convert_indent_to_tabs() { + TextEdit *tx = code_editor->get_text_edit(); + Ref<Script> scr = get_edited_script(); + + if (scr.is_null()) { + return; + } + + int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); + indent_size -= 1; + + bool changed_indentation = false; + for (int i = 0; i < tx->get_line_count(); i++) { + String line = tx->get_line(i); + + if (line.length() <= 0) { + continue; + } + + int j = 0; + int space_count = -1; + while (j < line.length() && (line[j] == ' ' || line[j] == '\t')) { + if (line[j] != '\t') { + space_count++; + + if (space_count == indent_size) { + if (!changed_indentation) { + tx->begin_complex_operation(); + changed_indentation = true; + } + + line = line.left(j - indent_size) + "\t" + line.right(j + 1); + j = 0; + space_count = -1; + } + } else { + space_count = -1; + } + j++; + } + tx->set_line(i, line); + } + if (changed_indentation) { + tx->end_complex_operation(); + tx->update(); + } +} + void ScriptTextEditor::tag_saved_version() { code_editor->get_text_edit()->tag_saved_version(); @@ -827,6 +917,12 @@ void ScriptTextEditor::_edit_option(int p_op) { case EDIT_TRIM_TRAILING_WHITESAPCE: { trim_trailing_whitespace(); } break; + case EDIT_CONVERT_INDENT_TO_SPACES: { + convert_indent_to_spaces(); + } break; + case EDIT_CONVERT_INDENT_TO_TABS: { + convert_indent_to_tabs(); + } break; case EDIT_PICK_COLOR: { color_panel->popup(); } break; @@ -1237,6 +1333,8 @@ ScriptTextEditor::ScriptTextEditor() { edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE); #endif edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/auto_indent"), EDIT_AUTO_INDENT); edit_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_menu->get_popup()->add_separator(); @@ -1305,6 +1403,8 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE); #endif ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CTRL | KEY_MASK_ALT | KEY_T); + ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent To Spaces"), KEY_MASK_CTRL | KEY_MASK_SHIFT | KEY_Y); + ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent To Tabs"), KEY_MASK_CTRL | KEY_MASK_SHIFT | KEY_X); ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I); ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 0649e39ab7..01f58c6fdc 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -67,6 +67,8 @@ class ScriptTextEditor : public ScriptEditorBase { EDIT_COMPLETE, EDIT_AUTO_INDENT, EDIT_TRIM_TRAILING_WHITESAPCE, + EDIT_CONVERT_INDENT_TO_SPACES, + EDIT_CONVERT_INDENT_TO_TABS, EDIT_TOGGLE_COMMENT, EDIT_MOVE_LINE_UP, EDIT_MOVE_LINE_DOWN, @@ -125,6 +127,8 @@ public: virtual void set_edit_state(const Variant &p_state); virtual void ensure_focus(); virtual void trim_trailing_whitespace(); + virtual void convert_indent_to_spaces(); + virtual void convert_indent_to_tabs(); virtual void tag_saved_version(); virtual void goto_line(int p_line, bool p_with_error = false); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index b693913e45..b5edd12b9c 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -370,7 +370,8 @@ void ShaderEditor::_editor_settings_changed() { shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); - shader_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size")); + shader_editor->get_text_edit()->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); + shader_editor->get_text_edit()->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type") == "Tabs" ? 0 : 1); shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 7e9dc5f4f1..35b8973818 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -50,6 +50,19 @@ #include "scene/gui/tool_button.h" #include "version.h" +static String _find_project_file(DirAccess *p_da) { + p_da->list_dir_begin(); + while (true) { + String f = p_da->get_next(); + if (f == "") + break; + if (f.get_extension() == "godot") + return p_da->get_current_dir() + "/" + f; + } + p_da->list_dir_end(); + return ""; +} + class NewProjectDialog : public ConfirmationDialog { GDCLASS(NewProjectDialog, ConfirmationDialog); @@ -92,18 +105,18 @@ private: if (mode != MODE_IMPORT) { - if (d->file_exists("godot.cfg")) { + if (_find_project_file(d) != "") { - error->set_text(TTR("Invalid project path, godot.cfg must not exist.")); + error->set_text(TTR("Invalid project path, *.godot must not exist.")); memdelete(d); return ""; } } else { - if (valid_path != "" && !d->file_exists("godot.cfg")) { + if (valid_path != "" && _find_project_file(d) == "") { - error->set_text(TTR("Invalid project path, godot.cfg must exist.")); + error->set_text(TTR("Invalid project path, *.godot must exist.")); memdelete(d); return ""; } @@ -136,7 +149,7 @@ private: String p = p_path; if (mode == MODE_IMPORT) { - if (p.ends_with("godot.cfg")) { + if (p.get_extension() == "godot") { p = p.get_base_dir(); } @@ -162,7 +175,7 @@ private: fdialog->set_mode(FileDialog::MODE_OPEN_FILE); fdialog->clear_filters(); - fdialog->add_filter("godot.cfg ; " _MKSTR(VERSION_NAME) " Project"); + fdialog->add_filter("*.godot ; " _MKSTR(VERSION_NAME) " Project"); } else { fdialog->set_mode(FileDialog::MODE_OPEN_DIR); } @@ -186,9 +199,9 @@ private: } else { if (mode == MODE_NEW) { - FileAccess *f = FileAccess::open(dir.plus_file("/godot.cfg"), FileAccess::WRITE); + FileAccess *f = FileAccess::open(dir.plus_file("/" + project_name->get_text().replace(" ", "_") + ".godot"), FileAccess::WRITE); if (!f) { - error->set_text(TTR("Couldn't create godot.cfg in project path.")); + error->set_text(TTR("Couldn't create *.godot project file in project path.")); } else { f->store_line("; Engine configuration file."); @@ -741,10 +754,17 @@ void ProjectManager::_load_recent_projects() { continue; String project = _name.get_slice("/", 1); - String conf = path.plus_file("godot.cfg"); + DirAccess *dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + if (dir_access->change_dir(path) != OK) { + EditorSettings::get_singleton()->erase(_name); + continue; + } + String conf = _find_project_file(dir_access); + memdelete(dir_access); bool favorite = (_name.begins_with("favorite_projects/")) ? true : false; uint64_t last_modified = 0; + if (FileAccess::exists(conf)) { last_modified = FileAccess::get_modified_time(conf); @@ -1006,7 +1026,7 @@ void ProjectManager::_scan_dir(DirAccess *da, float pos, float total, List<Strin while (n != String()) { if (da->current_is_dir() && !n.begins_with(".")) { subdirs.push_front(n); - } else if (n == "godot.cfg") { + } else if (n.get_extension() == "godot") { r_projects->push_back(da->get_current_dir()); } n = da->get_next(); @@ -1117,7 +1137,7 @@ void ProjectManager::_files_dropped(PoolStringArray p_files, int p_screen) { dir->list_dir_begin(); String file = dir->get_next(); while (confirm && file != String()) { - if (!dir->current_is_dir() && file.ends_with("godot.cfg")) { + if (!dir->current_is_dir() && file.get_extension() == "godot") { confirm = false; } file = dir->get_next(); diff --git a/editor/project_settings.cpp b/editor/project_settings.cpp index a45ea26086..bc1bdcf8af 100644 --- a/editor/project_settings.cpp +++ b/editor/project_settings.cpp @@ -1168,7 +1168,8 @@ void ProjectSettings::_bind_methods() { ProjectSettings::ProjectSettings(EditorData *p_data) { singleton = this; - set_title(TTR("Project Settings (godot.cfg)")); + String project_file = "(" + GlobalConfig::get_singleton()->get_project_file_name() + ")"; + set_title(TTR("Project Settings " + project_file)); set_resizable(true); undo_redo = &p_data->get_undo_redo(); data = p_data; diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 86136fa78b..666bfa20b5 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -2388,6 +2388,10 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p RES res = obj->get(p_name).operator RefPtr(); if (res->is_class("Texture")) { int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); + Vector2 size(res->call("get_width"), res->call("get_height")); + if (size.width < size.height) { + tw = MAX((size.width / size.height) * tw, 1); + } p_item->set_icon_max_width(1, tw); p_item->set_icon(1, res); p_item->set_text(1, ""); @@ -2427,7 +2431,9 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p } } - if (!res->is_class("Texture")) { + if (res->is_class("Script")) { + p_item->set_text(1, res->get_path().get_file()); + } else if (!res->is_class("Texture")) { //texture already previews via itself EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_resource_preview_done", p_item->get_instance_ID()); } @@ -3618,6 +3624,10 @@ void PropertyEditor::update_tree() { if (res->is_class("Texture")) { int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); + Vector2 size(res->call("get_width"), res->call("get_height")); + if (size.width < size.height) { + tw = MAX((size.width / size.height) * tw, 1); + } item->set_icon_max_width(1, tw); item->set_icon(1, res); item->set_text(1, ""); @@ -3641,7 +3651,9 @@ void PropertyEditor::update_tree() { } else if (res.is_valid()) { item->set_tooltip(1, res->get_name() + " (" + res->get_class() + ")"); } - if (!res->is_class("Texture")) { + if (res->is_class("Script")) { + item->set_text(1, res->get_path().get_file()); + } else if (!res->is_class("Texture")) { //texture already previews via itself EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_resource_preview_done", item->get_instance_ID()); } @@ -4389,6 +4401,7 @@ PropertyEditor::PropertyEditor() { capitalize_paths = true; autoclear = false; tree->set_column_titles_visible(false); + tree->add_constant_override("button_margin", 0); keying = false; read_only = false; diff --git a/main/main.cpp b/main/main.cpp index 0fa795b214..c294926045 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -129,7 +129,7 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(VERSION_FULL_NAME " (c) 2008-2017 Juan Linietsky, Ariel Manzur.\n"); OS::get_singleton()->print("Usage: %s [options] [scene]\n", p_binary); OS::get_singleton()->print("Options:\n"); - OS::get_singleton()->print("\t-path [dir] : Path to a game, containing godot.cfg\n"); + OS::get_singleton()->print("\t-path [dir] : Path to a game, containing *.godot\n"); #ifdef TOOLS_ENABLED OS::get_singleton()->print("\t-e,-editor : Bring up the editor instead of running the scene.\n"); #endif @@ -447,6 +447,23 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else { goto error; } + } else if (I->get().ends_with(".godot")) { + String path; + String file = I->get(); + int sep = MAX(file.find_last("/"), file.find_last("\\")); + if (sep == -1) + path = "."; + else { + path = file.substr(0, sep); + } + if (OS::get_singleton()->set_cwd(path) == OK) { + + } else { + game_path = path; + } +#ifdef TOOLS_ENABLED + editor = true; +#endif } else if (I->get() == "-bp") { // /breakpoints if (I->next()) { @@ -673,7 +690,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph else input_map->load_from_globals(); //keys for game - if (video_driver == "") // specified in godot.cfg + if (video_driver == "") // specified in *.godot video_driver = GLOBAL_DEF("display/driver/name", Variant((const char *)OS::get_singleton()->get_video_driver_name(0))); if (!force_res && use_custom_res && globals->has("display/window/width")) @@ -725,7 +742,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph /* Determine Video Driver */ - if (audio_driver == "") { // specified in godot.cfg + if (audio_driver == "") { // specified in *.godot audio_driver = GLOBAL_DEF("audio/driver", OS::get_singleton()->get_audio_driver_name(0)); } @@ -1235,7 +1252,7 @@ bool Main::start() { String stretch_mode = GLOBAL_DEF("display/stretch/mode", "disabled"); String stretch_aspect = GLOBAL_DEF("display/stretch/aspect", "ignore"); - Size2i stretch_size = Size2(GLOBAL_DEF("display/screen/width", 0), GLOBAL_DEF("display/screen/height", 0)); + Size2i stretch_size = Size2(GLOBAL_DEF("display/window/width", 0), GLOBAL_DEF("display/window/height", 0)); SceneTree::StretchMode sml_sm = SceneTree::STRETCH_MODE_DISABLED; if (stretch_mode == "2d") diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index b543a486d3..09859d95bd 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -391,6 +391,54 @@ void GDNativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { } } +Variant GDNativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + + /* STEP 1, CREATE */ + + if (!library.is_valid() || ((String)script_name).empty() || !script_data) { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); + } + + r_error.error = Variant::CallError::CALL_OK; + REF ref; + Object *owner = NULL; + + GDNativeScriptData *_baseptr = script_data; + while (_baseptr->base_data) { + _baseptr = _baseptr->base_data; + } + + if (!(_baseptr->base_native_type == "")) { + owner = ClassDB::instance(_baseptr->base_native_type); + } else { + owner = memnew(Reference); //by default, no base means use reference + } + + Reference *r = owner->cast_to<Reference>(); + if (r) { + ref = REF(r); + } + + // GDScript does it like this: _create_instance(p_args, p_argcount, owner, r != NULL, r_error); + // @Todo support varargs for constructors. + GDNativeInstance *instance = (GDNativeInstance *)instance_create(owner); + + owner->set_script_instance(instance); + if (!instance) { + if (ref.is_null()) { + memdelete(owner); //no owner, sorry + } + return Variant(); + } + + if (ref.is_valid()) { + return ref; + } else { + return owner; + } +} + Ref<GDNativeLibrary> GDNativeScript::get_library() const { return library; } @@ -438,6 +486,8 @@ void GDNativeScript::_bind_methods() { ClassDB::bind_method(D_METHOD("get_script_name"), &GDNativeScript::get_script_name); ClassDB::bind_method(D_METHOD("set_script_name", "script_name"), &GDNativeScript::set_script_name); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDNativeScript::_new, MethodInfo(Variant::OBJECT, "new")); + ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "script_name"), "set_script_name", "get_script_name"); } diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index 89270b4e26..27e0c3788b 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -184,6 +184,8 @@ public: virtual void get_script_method_list(List<MethodInfo> *p_list) const; virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + Ref<GDNativeLibrary> get_library() const; void set_library(Ref<GDNativeLibrary> p_library); diff --git a/modules/gdnative/godot.h b/modules/gdnative/godot.h index 0d7aece23b..88d2a9bac2 100644 --- a/modules/gdnative/godot.h +++ b/modules/gdnative/godot.h @@ -38,12 +38,26 @@ extern "C" { #define GDAPI_EXPORT #endif -#if !defined(_WIN32) && !defined(_MSC_VER) +#ifdef _WIN32 +#if defined(GDAPI_EXPORT) +#define GDCALLINGCONV __cdecl +#define GDAPI __declspec(dllexport) GDCALLINGCONV +#else +#define GDCALLINGCONV __cdecl +#define GDAPI __declspec(dllimport) GDCALLINGCONV +#endif +#elif defined(__APPLE__) +#include "TargetConditionals.h" +#if TARGET_OS_IPHONE +#define GDCALLINGCONV #define GDAPI -#elif defined(GDAPI_EXPORT) -#define GDAPI __declspec(dllexport) +#elif TARGET_OS_MAC +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV +#endif #else -#define GDAPI __declspec(dllimport) +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV #endif #include <stdbool.h> @@ -314,16 +328,16 @@ typedef struct godot_property_attributes { typedef struct godot_instance_create_func { // instance pointer, method_data - return user data - void *(*create_func)(godot_object *, void *); + GDCALLINGCONV void *(*create_func)(godot_object *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_create_func; typedef struct godot_instance_destroy_func { // instance pointer, method data, user data - void (*destroy_func)(godot_object *, void *, void *); + GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_destroy_func; void GDAPI godot_script_register_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func); @@ -332,25 +346,25 @@ void GDAPI godot_script_register_tool_class(const char *p_name, const char *p_ba typedef struct godot_instance_method { // instance pointer, method data, user data, num args, args - return result as varaint - godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **); + GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_method; void GDAPI godot_script_register_method(const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method); typedef struct godot_property_set_func { // instance pointer, method data, user data, value - void (*set_func)(godot_object *, void *, void *, godot_variant); + GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_property_set_func; typedef struct godot_property_get_func { // instance pointer, method data, user data, value - godot_variant (*get_func)(godot_object *, void *, void *); + GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_property_get_func; void GDAPI godot_script_register_property(const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func); @@ -376,6 +390,7 @@ void GDAPI godot_script_register_signal(const char *p_name, const godot_signal * void GDAPI *godot_native_get_userdata(godot_object *p_instance); +// Calling convention? typedef godot_object *(*godot_class_constructor)(); godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname); diff --git a/modules/gdnative/godot/godot_basis.cpp b/modules/gdnative/godot/godot_basis.cpp index 4322acc401..474cd3d448 100644 --- a/modules/gdnative/godot/godot_basis.cpp +++ b/modules/gdnative/godot/godot_basis.cpp @@ -38,48 +38,176 @@ extern "C" { void _basis_api_anchor() { } -void GDAPI godot_basis_new(godot_basis *p_basis) { - Basis *basis = (Basis *)p_basis; - *basis = Basis(); +void GDAPI godot_basis_new(godot_basis *p_v) { + Basis *v = (Basis *)p_v; + *v = Basis(); } -void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_basis, const godot_quat *p_euler) { - Basis *basis = (Basis *)p_basis; +void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_v, const godot_quat *p_euler) { + Basis *v = (Basis *)p_v; Quat *euler = (Quat *)p_euler; - *basis = Basis(*euler); + *v = Basis(*euler); } -void GDAPI godot_basis_new_with_euler(godot_basis *p_basis, const godot_vector3 *p_euler) { - Basis *basis = (Basis *)p_basis; - Vector3 *euler = (Vector3 *)p_euler; - *basis = Basis(*euler); +void GDAPI godot_basis_new_with_euler(godot_basis *p_v, const godot_vector3 p_euler) { + Basis *v = (Basis *)p_v; + Vector3 *euler = (Vector3 *)&p_euler; + *v = Basis(*euler); } -godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_basis) { - const Basis *basis = (const Basis *)p_basis; +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi) { + Basis *v = (Basis *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + *v = Basis(*axis, p_phi); +} + +void GDAPI godot_basis_new_with_rows(godot_basis *p_v, const godot_vector3 p_row0, const godot_vector3 p_row1, const godot_vector3 p_row2) { + Basis *v = (Basis *)p_v; + const Vector3 *row0 = (Vector3 *)&p_row0; + const Vector3 *row1 = (Vector3 *)&p_row1; + const Vector3 *row2 = (Vector3 *)&p_row2; + *v = Basis(*row0, *row1, *row2); +} + +godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_v) { + const Basis *v = (const Basis *)p_v; godot_quat quat; Quat *p_quat = (Quat *)&quat; - *p_quat = basis->operator Quat(); + *p_quat = v->operator Quat(); return quat; } -godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_basis) { - const Basis *basis = (const Basis *)p_basis; - godot_vector3 euler; - Vector3 *p_euler = (Vector3 *)&euler; - *p_euler = basis->get_euler(); - return euler; -} - /* * p_elements is a pointer to an array of 3 (!!) vector3 */ -void GDAPI godot_basis_get_elements(godot_basis *p_basis, godot_vector3 *p_elements) { - Basis *basis = (Basis *)p_basis; +void GDAPI godot_basis_get_elements(godot_basis *p_v, godot_vector3 *p_elements) { + Basis *v = (Basis *)p_v; Vector3 *elements = (Vector3 *)p_elements; - elements[0] = basis->elements[0]; - elements[1] = basis->elements[1]; - elements[2] = basis->elements[2]; + elements[0] = v->elements[0]; + elements[1] = v->elements[1]; + elements[2] = v->elements[2]; +} + +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_v, const godot_int p_axis) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_axis(p_axis); + return dest; +} + +void GDAPI godot_basis_set_axis(godot_basis *p_v, const godot_int p_axis, const godot_vector3 p_value) { + Basis *v = (Basis *)p_v; + const Vector3 *value = (Vector3 *)&p_value; + v->set_axis(p_axis, *value); +} + +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_v, const godot_int p_row) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_row(p_row); + return dest; +} + +void GDAPI godot_basis_set_row(godot_basis *p_v, const godot_int p_row, const godot_vector3 p_value) { + Basis *v = (Basis *)p_v; + const Vector3 *value = (Vector3 *)&p_value; + v->set_row(p_row, *value); +} + +godot_real godot_basis_determinant(const godot_basis *p_v) { + Basis *v = (Basis *)p_v; + return v->determinant(); +} + +godot_vector3 godot_basis_get_euler(const godot_basis *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_euler(); + return dest; +} + +godot_int godot_basis_get_orthogonal_index(const godot_basis *p_v) { + const Basis *v = (Basis *)p_v; + return v->get_orthogonal_index(); +} + +godot_vector3 godot_basis_get_scale(const godot_basis *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + *d = v->get_scale(); + return dest; +} + +void godot_basis_inverse(godot_basis *p_dest, const godot_basis *p_v) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + *d = v->inverse(); +} + +void godot_basis_orthonormalized(godot_basis *p_dest, const godot_basis *p_v) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + *d = v->orthonormalized(); +} + +void godot_basis_rotated(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + *d = v->rotated(*axis, p_phi); +} + +void godot_basis_scaled(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_scale) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + const Vector3 *scale = (Vector3 *)&p_scale; + *d = v->scaled(*scale); +} + +godot_real godot_basis_tdotx(const godot_basis *p_v, const godot_vector3 p_with) { + const Basis *v = (Basis *)p_v; + const Vector3 *with = (Vector3 *)&p_with; + return v->tdotx(*with); +} + +godot_real godot_basis_tdoty(const godot_basis *p_v, const godot_vector3 p_with) { + const Basis *v = (Basis *)p_v; + const Vector3 *with = (Vector3 *)&p_with; + return v->tdoty(*with); +} + +godot_real godot_basis_tdotz(const godot_basis *p_v, const godot_vector3 p_with) { + const Basis *v = (Basis *)p_v; + const Vector3 *with = (Vector3 *)&p_with; + return v->tdotz(*with); +} + +void godot_basis_transposed(godot_basis *p_dest, const godot_basis *p_v) { + Basis *d = (Basis *)p_dest; + const Basis *v = (Basis *)p_v; + *d = v->transposed(); +} + +godot_vector3 godot_basis_xform(const godot_basis *p_v, const godot_vector3 p_vect) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + const Vector3 *vect = (Vector3 *)&p_vect; + *d = v->xform(*vect); + return dest; +} + +godot_vector3 godot_basis_xform_inv(const godot_basis *p_v, const godot_vector3 p_vect) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *v = (Basis *)p_v; + const Vector3 *vect = (Vector3 *)&p_vect; + *d = v->xform_inv(*vect); + return dest; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_basis.h b/modules/gdnative/godot/godot_basis.h index a8f19bfde5..2803396997 100644 --- a/modules/gdnative/godot/godot_basis.h +++ b/modules/gdnative/godot/godot_basis.h @@ -43,18 +43,39 @@ typedef struct godot_basis { #endif #include "../godot.h" +#include "godot_quat.h" -void GDAPI godot_basis_new(godot_basis *p_basis); -void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_basis, const godot_quat *p_euler); -void GDAPI godot_basis_new_with_euler(godot_basis *p_basis, const godot_vector3 *p_euler); +void GDAPI godot_basis_new(godot_basis *p_v); +void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_v, const godot_quat *p_euler); +void GDAPI godot_basis_new_with_euler(godot_basis *p_v, const godot_vector3 p_euler); +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi); +void GDAPI godot_basis_new_with_rows(godot_basis *p_v, const godot_vector3 p_row0, const godot_vector3 p_row1, const godot_vector3 p_row2); -godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_basis); -godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_basis); +godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_v); /* * p_elements is a pointer to an array of 3 (!!) vector3 */ -void GDAPI godot_basis_get_elements(godot_basis *p_basis, godot_vector3 *p_elements); +void GDAPI godot_basis_get_elements(godot_basis *p_v, godot_vector3 *p_elements); +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_v, const godot_int p_axis); +void GDAPI godot_basis_set_axis(godot_basis *p_v, const godot_int p_axis, const godot_vector3 p_value); +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_v, const godot_int p_row); +void GDAPI godot_basis_set_row(godot_basis *p_v, const godot_int p_row, const godot_vector3 p_value); + +godot_real godot_basis_determinant(const godot_basis *p_v); +godot_vector3 godot_basis_get_euler(const godot_basis *p_v); +godot_int godot_basis_get_orthogonal_index(const godot_basis *p_v); +godot_vector3 godot_basis_get_scale(const godot_basis *p_v); +void godot_basis_inverse(godot_basis *p_dest, const godot_basis *p_v); +void godot_basis_orthonormalized(godot_basis *p_dest, const godot_basis *p_v); +void godot_basis_rotated(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_axis, const godot_real p_phi); +void godot_basis_scaled(godot_basis *p_dest, const godot_basis *p_v, const godot_vector3 p_scale); +godot_real godot_basis_tdotx(const godot_basis *p_v, const godot_vector3 p_with); +godot_real godot_basis_tdoty(const godot_basis *p_v, const godot_vector3 p_with); +godot_real godot_basis_tdotz(const godot_basis *p_v, const godot_vector3 p_with); +void godot_basis_transposed(godot_basis *p_dest, const godot_basis *p_v); +godot_vector3 godot_basis_xform(const godot_basis *p_v, const godot_vector3 p_vect); +godot_vector3 godot_basis_xform_inv(const godot_basis *p_v, const godot_vector3 p_vect); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_string.cpp b/modules/gdnative/godot/godot_string.cpp index 757b8510cf..92c0b04041 100644 --- a/modules/gdnative/godot/godot_string.cpp +++ b/modules/gdnative/godot/godot_string.cpp @@ -80,6 +80,11 @@ const char GDAPI *godot_string_c_str(const godot_string *p_str) { return s->utf8().get_data(); } +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_str) { + const String *s = (const String *)p_str; + return s->c_str(); +} + godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b) { String *a = (String *)p_a; String *b = (String *)p_b; diff --git a/modules/gdnative/godot/godot_string.h b/modules/gdnative/godot/godot_string.h index 9289531c5e..83ed5d6ec1 100644 --- a/modules/gdnative/godot/godot_string.h +++ b/modules/gdnative/godot/godot_string.h @@ -35,6 +35,7 @@ extern "C" { #endif #include <stdint.h> +#include <wchar.h> #ifndef GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED typedef struct godot_string { @@ -53,6 +54,7 @@ void GDAPI godot_string_copy_string(const godot_string *p_dest, const godot_stri wchar_t GDAPI *godot_string_operator_index(godot_string *p_str, const godot_int p_idx); const char GDAPI *godot_string_c_str(const godot_string *p_str); +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_str); godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b); godot_bool GDAPI godot_string_operator_less(const godot_string *p_a, const godot_string *p_b); diff --git a/modules/gdnative/godot/godot_vector2.cpp b/modules/gdnative/godot/godot_vector2.cpp index dce4c03b5d..87e60b6245 100644 --- a/modules/gdnative/godot/godot_vector2.cpp +++ b/modules/gdnative/godot/godot_vector2.cpp @@ -35,13 +35,14 @@ extern "C" { #endif -void _vector2_api_anchor() { -} +void _vector2_api_anchor() {} -void GDAPI godot_vector2_new(godot_vector2 *p_v, godot_real p_x, godot_real p_y) { - Vector2 *v = (Vector2 *)p_v; +godot_vector2 GDAPI godot_vector2_new(const godot_real p_x, const godot_real p_y) { + godot_vector2 value; + Vector2 *v = (Vector2 *)&value; v->x = p_x; v->y = p_y; + return value; } void GDAPI godot_vector2_set_x(godot_vector2 *p_v, const godot_real p_x) { @@ -55,11 +56,11 @@ void GDAPI godot_vector2_set_y(godot_vector2 *p_v, const godot_real p_y) { } godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; + const Vector2 *v = (Vector2 *)p_v; return v->x; } godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; + const Vector2 *v = (Vector2 *)p_v; return v->y; } @@ -67,85 +68,227 @@ void GDAPI godot_vector2_normalize(godot_vector2 *p_v) { Vector2 *v = (Vector2 *)p_v; v->normalize(); } -void GDAPI godot_vector2_normalized(godot_vector2 *p_dest, const godot_vector2 *p_src) { - Vector2 *v = (Vector2 *)p_src; - Vector2 *d = (Vector2 *)p_dest; +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_v) { + godot_vector2 dest; + const Vector2 *v = (Vector2 *)p_v; + Vector2 *d = (Vector2 *)&dest; *d = v->normalized(); + return dest; } godot_real GDAPI godot_vector2_length(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; + const Vector2 *v = (Vector2 *)p_v; return v->length(); } godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; + const Vector2 *v = (Vector2 *)p_v; return v->length_squared(); } -godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *a = (Vector2 *)p_a; - Vector2 *b = (Vector2 *)p_b; - return a->distance_to(*b); +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return v->distance_to(*b); +} + +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return v->distance_squared_to(*b); +} + +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v + *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_subtract(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v - *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v * *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_v, const godot_real p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = *v * p_b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_v, const godot_vector2 p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = *v / *b; + return dest; +} + +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_v, const godot_real p_b) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = *v / p_b; + return dest; +} + +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return *v == *b; +} + +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_v, const godot_vector2 p_b) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + return *v < *b; +} + +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_v) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->abs(); + return dest; +} + +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->angle(); +} + +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_v, const godot_vector2 p_to) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *to = (Vector2 *)&p_to; + return v->angle_to(*to); +} + +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_v, const godot_vector2 p_to) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *to = (Vector2 *)&p_to; + return v->angle_to_point(*to); +} + +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_v, const godot_real length) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->clamped(length); + return dest; +} + +godot_vector2 GDAPI godot_vector2_cubic_interpolate( + const godot_vector2 *p_v, const godot_vector2 p_b, const godot_vector2 p_pre_a, + const godot_vector2 p_post_b, godot_real t) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + const Vector2 *pre_a = (Vector2 *)&p_pre_a; + const Vector2 *post_b = (Vector2 *)&p_post_b; + *d = v->cubic_interpolate(*b, *pre_a, *post_b, t); + return dest; +} + +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_v, const godot_vector2 p_with) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *with = (Vector2 *)&p_with; + return v->dot(*with); } -godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *a = (Vector2 *)p_a; - Vector2 *b = (Vector2 *)p_b; - return a->distance_squared_to(*b); +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_v) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->floor(); + return dest; } -void GDAPI godot_vector2_operator_add(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a + *b; +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_v) { + const Vector2 *v = (Vector2 *)p_v; + return v->aspect(); } -void GDAPI godot_vector2_operator_subtract(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a - *b; +godot_vector2 GDAPI godot_vector2_linear_interpolate( + const godot_vector2 *p_v, + const godot_vector2 p_b, + godot_real t) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *b = (Vector2 *)&p_b; + *d = v->linear_interpolate(*b, t); + return dest; } -void GDAPI godot_vector2_operator_multiply_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a * *b; +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_v, const godot_vector2 p_vec) { + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *vec = (Vector2 *)&p_vec; + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + *d = v->reflect(*vec); + return dest; } -void GDAPI godot_vector2_operator_multiply_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - *dest = *a * p_b; +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_v, godot_real phi) { + const Vector2 *v = (Vector2 *)p_v; + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + *d = v->rotated(phi); + return dest; } -void GDAPI godot_vector2_operator_divide_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a / *b; +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_v, godot_vector2 p_vec) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *vec = (Vector2 *)&p_vec; + *d = v->slide(*vec); + return dest; } -void GDAPI godot_vector2_operator_divide_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - *dest = *a / p_b; +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_v, godot_vector2 p_by) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + const Vector2 *by = (Vector2 *)&p_by; + *d = v->snapped(*by); + return dest; } -godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_a, const godot_vector2 *p_b) { - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - return *a == *b; +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_v) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = v->tangent(); + return dest; } -godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_a, const godot_vector2 *p_b) { - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - return *a < *b; +godot_string GDAPI godot_vector2_to_string(const godot_vector2 *p_v) { + godot_string dest; + String *d = (String *)&dest; + const Vector2 *v = (Vector2 *)p_v; + *d = "(" + *v + ")"; + return dest; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_vector2.h b/modules/gdnative/godot/godot_vector2.h index afda8aa10b..36a4f01d03 100644 --- a/modules/gdnative/godot/godot_vector2.h +++ b/modules/gdnative/godot/godot_vector2.h @@ -45,7 +45,7 @@ typedef struct godot_vector2 { #include "../godot.h" -void GDAPI godot_vector2_new(godot_vector2 *p_v, const godot_real p_x, const godot_real p_y); +godot_vector2 GDAPI godot_vector2_new(const godot_real p_x, const godot_real p_y); void GDAPI godot_vector2_set_x(godot_vector2 *p_v, const godot_real p_x); void GDAPI godot_vector2_set_y(godot_vector2 *p_v, const godot_real p_y); @@ -53,52 +53,43 @@ godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_v); godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_v); void GDAPI godot_vector2_normalize(godot_vector2 *p_v); -void GDAPI godot_vector2_normalized(godot_vector2 *p_dest, const godot_vector2 *p_src); +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_v); godot_real GDAPI godot_vector2_length(const godot_vector2 *p_v); godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_v); -godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_a, const godot_vector2 *p_b); -godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_a, const godot_vector2 *p_b); +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_v, const godot_vector2 p_b); -// @Incomplete -/* - * missing: - * - * angle_to - * angle_to_point - * dot - * cross_vector - * cross_scalar - * project - * plane_project - * clamped - * linear_interpolate - * cubic_interpolate - * cubic_interpolate_soft - * slide - * reflect - * angle - * abs - * rotated - * tangent - * floor - * snapped - * aspect - * - * - * to_string - */ +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_v, const godot_vector2 p_to); +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_v, const godot_vector2 p_to); +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_v, godot_real length); +godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_v, + const godot_vector2 p_b, const godot_vector2 p_pre_a, + const godot_vector2 p_post_b, godot_real t); +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_v, const godot_vector2 p_with); +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_v); +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_v); +godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_v, + const godot_vector2 p_b, godot_real t); +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_v, const godot_vector2 p_vec); +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_v, godot_real phi); +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_v, godot_vector2 p_vec); +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_v, godot_vector2 p_by); +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_v); +godot_string GDAPI godot_vector2_to_string(const godot_vector2 *p_v); -void GDAPI godot_vector2_operator_add(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_subtract(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_multiply_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_multiply_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b); -void GDAPI godot_vector2_operator_divide_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_divide_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b); +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_subtract(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_v, const godot_real p_b); +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_v, const godot_real p_b); -godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_a, const godot_vector2 *p_b); -godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_a, const godot_vector2 *p_b); +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_v, const godot_vector2 p_b); +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_v, const godot_vector2 p_b); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_vector3.cpp b/modules/gdnative/godot/godot_vector3.cpp index f08bfbcf06..5f71b9f7e4 100644 --- a/modules/gdnative/godot/godot_vector3.cpp +++ b/modules/gdnative/godot/godot_vector3.cpp @@ -38,9 +38,11 @@ extern "C" { void _vector3_api_anchor() { } -void GDAPI godot_vector3_new(godot_vector3 *p_v, const godot_real p_x, const godot_real p_y, const godot_real p_z) { - Vector3 *v = (Vector3 *)p_v; +godot_vector3 GDAPI godot_vector3_new(const godot_real p_x, const godot_real p_y, const godot_real p_z) { + godot_vector3 value; + Vector3 *v = (Vector3 *)&value; *v = Vector3(p_x, p_y, p_z); + return value; } void GDAPI godot_vector3_set_axis(godot_vector3 *p_v, const godot_int p_axis, const godot_real p_val) { @@ -78,100 +80,261 @@ void GDAPI godot_vector3_normalize(godot_vector3 *p_v) { v->normalize(); } -void GDAPI godot_vector3_normalized(godot_vector3 *p_dest, const godot_vector3 *p_src) { - Vector3 *src = (Vector3 *)p_src; - Vector3 *dest = (Vector3 *)p_dest; - *dest = src->normalized(); +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + *d = v->normalized(); + return dest; +} + +godot_vector3 godot_vector3_inverse(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->inverse(); + return dest; +} + +void godot_vector3_zero(godot_vector3 *p_v) { + Vector3 *v = (Vector3 *)p_v; + v->zero(); +} + +void godot_vector3_snap(godot_vector3 *p_v, const godot_real val) { + Vector3 *v = (Vector3 *)p_v; + v->snap(val); +} + +godot_vector3 godot_vector3_snapped(const godot_vector3 *p_v, const godot_real val) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->snapped(val); + return dest; +} + +void godot_vector3_rotate(godot_vector3 *p_v, const godot_vector3 p_axis, const godot_real phi) { + Vector3 *v = (Vector3 *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + v->rotate(*axis, phi); +} + +godot_vector3 godot_vector3_rotated(const godot_vector3 *p_v, const godot_vector3 p_axis, const godot_real phi) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *axis = (Vector3 *)&p_axis; + *d = v->rotated(*axis, phi); + return dest; +} + +godot_vector3 godot_vector3_linear_interpolate(const godot_vector3 *p_v, const godot_vector3 p_b, const godot_real t) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + *d = v->linear_interpolate(*b, t); + return dest; +} + +godot_vector3 godot_vector3_cubic_interpolate(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + const Vector3 *pre_a = (Vector3 *)&p_pre_a; + const Vector3 *post_b = (Vector3 *)&p_post_b; + *d = v->cubic_interpolate(*b, *pre_a, *post_b, t); + return dest; +} + +godot_vector3 godot_vector3_cubic_interpolaten(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + const Vector3 *pre_a = (Vector3 *)&p_pre_a; + const Vector3 *post_b = (Vector3 *)&p_post_b; + *d = v->cubic_interpolaten(*b, *pre_a, *post_b, t); + return dest; +} + +godot_vector3 godot_vector3_cross(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + *d = v->cross(*b); + return dest; +} + +godot_real godot_vector3_dot(const godot_vector3 *p_v, const godot_vector3 p_b) { + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + return v->dot(*b); +} + +godot_basis godot_vector3_outer(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_basis dest; + Basis *d = (Basis *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *b = (Vector3 *)&p_b; + *d = v->outer(*b); + return dest; +} + +godot_basis godot_vector3_to_diagonal_matrix(const godot_vector3 *p_v) { + godot_basis dest; + Basis *d = (Basis *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->to_diagonal_matrix(); + return dest; +} + +godot_vector3 godot_vector3_abs(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->abs(); + return dest; +} + +godot_vector3 godot_vector3_floor(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->floor(); + return dest; +} + +godot_vector3 godot_vector3_ceil(const godot_vector3 *p_v) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = v->ceil(); + return dest; +} + +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return v->distance_to(*b); +} + +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return v->distance_squared_to(*b); } -/* - * inverse - * zero - * snap - * snapped - * rotate - * rotated - * - * - * linear_interpolate - * cubic_interpolate - * cubic_interpolaten - * cross - * dot - * outer - * to_diagonal_matrix - * abs - * floor - * ceil - */ +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return v->angle_to(*b); +} -godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return a->distance_to(*b); +godot_vector3 godot_vector3_slide(const godot_vector3 *p_v, const godot_vector3 p_vec) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *vec = (Vector3 *)&p_vec; + *d = v->slide(*vec); + return dest; } -godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return a->distance_squared_to(*b); +godot_vector3 godot_vector3_bounce(const godot_vector3 *p_v, const godot_vector3 p_vec) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *vec = (Vector3 *)&p_vec; + *d = v->bounce(*vec); + return dest; } -/* - * slide - * reflect - */ +godot_vector3 godot_vector3_reflect(const godot_vector3 *p_v, const godot_vector3 p_vec) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Vector3 *v = (Vector3 *)p_v; + const Vector3 *vec = (Vector3 *)&p_vec; + *d = v->reflect(*vec); + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v + *b; + return dest; +} -void GDAPI godot_vector3_operator_add(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a + *b; +godot_vector3 GDAPI godot_vector3_operator_subtract(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v - *b; + return dest; } -void GDAPI godot_vector3_operator_subtract(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a - *b; +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v * *b; + return dest; } -void GDAPI godot_vector3_operator_multiply_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a * *b; +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_v, const godot_real p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + *d = *v * p_b; + return dest; } -void GDAPI godot_vector3_operator_multiply_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - *dest = *a * p_b; +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_v, const godot_vector3 p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + *d = *v / *b; + return dest; } -void GDAPI godot_vector3_operator_divide_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a / *b; +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_v, const godot_real p_b) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + Vector3 *v = (Vector3 *)p_v; + *d = *v / p_b; + return dest; } -void GDAPI godot_vector3_operator_divide_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - *dest = *a / p_b; +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return *v == *b; } -godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return *a == *b; +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_v, const godot_vector3 p_b) { + Vector3 *v = (Vector3 *)p_v; + Vector3 *b = (Vector3 *)&p_b; + return *v < *b; } -godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return *a < *b; +godot_string GDAPI godot_vector3_to_string(const godot_vector3 *p_v) { + godot_string dest; + String *d = (String *)&dest; + const Vector3 *v = (Vector3 *)p_v; + *d = "(" + *v + ")"; + return dest; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_vector3.h b/modules/gdnative/godot/godot_vector3.h index b7dc40965d..654ddd7792 100644 --- a/modules/gdnative/godot/godot_vector3.h +++ b/modules/gdnative/godot/godot_vector3.h @@ -42,9 +42,14 @@ typedef struct godot_vector3 { } godot_vector3; #endif +#define GODOT_VECTOR3_AXIX_X 0 +#define GODOT_VECTOR3_AXIX_Y 1 +#define GODOT_VECTOR3_AXIX_Z 2 + #include "../godot.h" +#include "godot_basis.h" -void GDAPI godot_vector3_new(godot_vector3 *p_v, const godot_real p_x, const godot_real p_y, const godot_real p_z); +godot_vector3 GDAPI godot_vector3_new(const godot_real p_x, const godot_real p_y, const godot_real p_z); void GDAPI godot_vector3_set_axis(godot_vector3 *p_v, const godot_int p_axis, const godot_real p_val); godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_v, const godot_int p_axis); @@ -56,53 +61,50 @@ godot_real GDAPI godot_vector3_length(const godot_vector3 *p_v); godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_v); void GDAPI godot_vector3_normalize(godot_vector3 *p_v); -void GDAPI godot_vector3_normalized(godot_vector3 *p_dest, const godot_vector3 *p_src); - -// @Incomplete - -/* - * inverse - * zero - * snap - * snapped - * rotate - * rotated - * - * - * linear_interpolate - * cubic_interpolate - * cubic_interpolaten - * cross - * dot - * outer - * to_diagonal_matrix - * abs - * floor - * ceil - */ - -godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_a, const godot_vector3 *p_b); -godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_a, const godot_vector3 *p_b); - -// @Incomplete -/* - * slide - * reflect - */ - -void GDAPI godot_vector3_operator_add(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_subtract(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_multiply_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_multiply_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b); -void GDAPI godot_vector3_operator_divide_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_divide_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b); - -godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_a, const godot_vector3 *p_b); -godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_a, const godot_vector3 *p_b); - -/* - * to_string - */ +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_v); +void GDAPI godot_vector3_zero(godot_vector3 *p_v); +void GDAPI godot_vector3_snap(godot_vector3 *p_v, const godot_real val); +godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_v, const godot_real val); +void GDAPI godot_vector3_rotate(godot_vector3 *p_v, const godot_vector3 p_axis, const godot_real phi); +godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_v, + const godot_vector3 p_axis, const godot_real phi); +godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_real t); +godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t); +godot_vector3 GDAPI godot_vector3_cubic_interpolaten(const godot_vector3 *p_v, + const godot_vector3 p_b, const godot_vector3 p_pre_a, + const godot_vector3 p_post_b, const godot_real t); +godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_v); +godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_v); +godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_v); +godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_v); + +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_v, const godot_vector3 p_b); + +godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_v, const godot_vector3 p_vec); +godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_v, const godot_vector3 p_vec); +godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_v, const godot_vector3 p_vec); + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_subtract(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_v, const godot_real p_b); +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_v, const godot_real p_b); + +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_v, const godot_vector3 p_b); +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_v, const godot_vector3 p_b); + +godot_string GDAPI godot_vector3_to_string(const godot_vector3 *p_v); #ifdef __cplusplus } diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index ae5bb5694c..c2f14f5466 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "editor/editor_settings.h" #include "gd_compiler.h" #include "gd_script.h" #include "global_config.h" @@ -2391,8 +2392,27 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base #endif +String GDScriptLanguage::_get_indentation() const { +#ifdef TOOLS_ENABLED + bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", "Tabs") == "Tabs" ? 0 : 1; + + if (use_space_indentation) { + int indent_size = EDITOR_DEF("text_editor/indent/size", 4); + + String space_indent = ""; + for (int i = 0; i < indent_size; i++) { + space_indent += " "; + } + return space_indent; + } +#endif + return "\t"; +} + void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { + String indent = _get_indentation(); + Vector<String> lines = p_code.split("\n"); List<int> indent_stack; @@ -2432,8 +2452,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t if (i >= p_from_line) { l = ""; - for (int j = 0; j < indent_stack.size(); j++) - l += "\t"; + for (int j = 0; j < indent_stack.size(); j++) { + l += indent; + } l += st; } else if (i > p_to_line) { diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 93f8ee8721..f92c11b9e0 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -390,6 +390,7 @@ public: #ifdef TOOLS_ENABLED virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result); #endif + virtual String _get_indentation() const; virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const; virtual void add_global_constant(const StringName &p_variable, const Variant &p_value); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 7247636920..30178c32ff 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2163,6 +2163,12 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { void VisualScriptEditor::trim_trailing_whitespace() { } +void VisualScriptEditor::convert_indent_to_spaces() { +} + +void VisualScriptEditor::convert_indent_to_tabs() { +} + void VisualScriptEditor::ensure_focus() { graph->grab_focus(); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 7322da5cfb..0b23fa92f4 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -240,6 +240,8 @@ public: virtual void set_edit_state(const Variant &p_state); virtual void goto_line(int p_line, bool p_with_error = false); virtual void trim_trailing_whitespace(); + virtual void convert_indent_to_spaces(); + virtual void convert_indent_to_tabs(); virtual void ensure_focus(); virtual void tag_saved_version(); virtual void reload(bool p_soft); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 5b57da46d7..99b6890913 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1990,7 +1990,6 @@ String OS_Windows::get_executable_path() const { wchar_t bufname[4096]; GetModuleFileNameW(NULL, bufname, 4096); String s = bufname; - print_line("EXEC PATHP??: " + s); return s; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 69a90535df..90d1352dc7 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -101,15 +101,15 @@ void TextEdit::Text::set_font(const Ref<Font> &p_font) { font = p_font; } -void TextEdit::Text::set_tab_size(int p_tab_size) { +void TextEdit::Text::set_indent_size(int p_indent_size) { - tab_size = p_tab_size; + indent_size = p_indent_size; } void TextEdit::Text::_update_line_cache(int p_line) const { int w = 0; - int tab_w = font->get_char_size(' ').width * tab_size; + int tab_w = font->get_char_size(' ').width * indent_size; int len = text[p_line].data.length(); const CharType *str = text[p_line].data.c_str(); @@ -456,7 +456,7 @@ void TextEdit::_notification(int p_what) { int visible_rows = get_visible_rows(); - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; Color color = cache.font_color; int in_region = -1; @@ -1305,7 +1305,38 @@ void TextEdit::backspace_at_cursor() { _is_pair_left_symbol(text[cursor.line][cursor.column - 1])) { _consume_backspace_for_pair_symbol(prev_line, prev_column); } else { - _remove_text(prev_line, prev_column, cursor.line, cursor.column); + // handle space indentation + if (cursor.column - indent_size >= 0 && indent_using_spaces) { + + // if there is enough spaces to count as a tab + bool unindent = true; + for (int i = 1; i <= indent_size; i++) { + if (text[cursor.line][cursor.column - i] != ' ') { + unindent = false; + break; + } + } + + // and it is before the first character + int i = 0; + while (i < cursor.column && i < text[cursor.line].length()) { + if (text[cursor.line][i] != ' ' && text[cursor.line][i] != '\t') { + unindent = false; + break; + } + i++; + } + + // then we can remove it as a single character. + if (unindent) { + _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column); + prev_column = cursor.column - indent_size; + } else { + _remove_text(prev_line, prev_column, cursor.line, cursor.column); + } + } else { + _remove_text(prev_line, prev_column, cursor.line, cursor.column); + } } cursor_set_line(prev_line); @@ -1328,7 +1359,11 @@ void TextEdit::indent_selection_right() { for (int i = start_line; i <= end_line; i++) { String line_text = get_line(i); - line_text = '\t' + line_text; + if (indent_using_spaces) { + line_text = space_indent + line_text; + } else { + line_text = '\t' + line_text; + } set_line(i, line_text); } @@ -1359,8 +1394,8 @@ void TextEdit::indent_selection_left() { if (line_text.begins_with("\t")) { line_text = line_text.substr(1, line_text.length()); set_line(i, line_text); - } else if (line_text.begins_with(" ")) { - line_text = line_text.substr(4, line_text.length()); + } else if (line_text.begins_with(space_indent)) { + line_text = line_text.substr(indent_size, line_text.length()); set_line(i, line_text); } } @@ -1931,17 +1966,39 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { String ins = "\n"; //keep indentation + int space_count = 0; for (int i = 0; i < text[cursor.line].length(); i++) { - if (text[cursor.line][i] == '\t') - ins += "\t"; - else + if (text[cursor.line][i] == '\t') { + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } + space_count = 0; + } else if (text[cursor.line][i] == ' ') { + space_count++; + + if (space_count == indent_size) { + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } + space_count = 0; + } + } else { break; + } } if (auto_indent) { // indent once again if previous line will end with ':' // (i.e. colon precedes current cursor position) if (cursor.column > 0 && text[cursor.line][cursor.column - 1] == ':') { - ins += "\t"; + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } } } @@ -1987,15 +2044,36 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { } else { if (k.mod.shift) { + //simple unindent int cc = cursor.column; - if (cc > 0 && cc <= text[cursor.line].length() && text[cursor.line][cursor.column - 1] == '\t') { - //simple unindent + if (cc > 0 && cc <= text[cursor.line].length()) { + if (text[cursor.line][cursor.column - 1] == '\t') { + backspace_at_cursor(); + } else { + if (cursor.column - indent_size >= 0) { + + bool unindent = true; + for (int i = 1; i <= indent_size; i++) { + if (text[cursor.line][cursor.column - i] != ' ') { + unindent = false; + break; + } + } - backspace_at_cursor(); + if (unindent) { + _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column); + cursor_set_column(cursor.column - indent_size); + } + } + } } } else { //simple indent - _insert_text_at_cursor("\t"); + if (indent_using_spaces) { + _insert_text_at_cursor(space_indent); + } else { + _insert_text_at_cursor("\t"); + } } } @@ -3103,7 +3181,7 @@ int TextEdit::get_char_pos_for(int p_px, String p_str) const { int px = 0; int c = 0; - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; while (c < p_str.length()) { @@ -3135,7 +3213,7 @@ int TextEdit::get_column_x_offset(int p_char, String p_str) { int px = 0; - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; for (int i = 0; i < p_char; i++) { @@ -3952,10 +4030,24 @@ void TextEdit::_push_current_op() { current_op.chain_forward = false; } -void TextEdit::set_tab_size(const int p_size) { +void TextEdit::set_indent_using_spaces(const bool p_use_spaces) { + indent_using_spaces = p_use_spaces; +} + +bool TextEdit::is_indent_using_spaces() const { + return indent_using_spaces; +} + +void TextEdit::set_indent_size(const int p_size) { ERR_FAIL_COND(p_size <= 0); - tab_size = p_size; - text.set_tab_size(p_size); + indent_size = p_size; + text.set_indent_size(p_size); + + space_indent = ""; + for (int i = 0; i < p_size; i++) { + space_indent += " "; + } + update(); } @@ -4542,8 +4634,8 @@ TextEdit::TextEdit() { cache.breakpoint_gutter_width = 0; breakpoint_gutter_width = 0; - tab_size = 4; - text.set_tab_size(tab_size); + indent_size = 4; + text.set_indent_size(indent_size); text.clear(); //text.insert(1,"Mongolia.."); //text.insert(2,"PAIS GENEROSO!!"); @@ -4631,6 +4723,8 @@ TextEdit::TextEdit() { auto_brace_completion_enabled = false; brace_matching_enabled = false; highlight_all_occurrences = false; + indent_using_spaces = false; + space_indent = " "; auto_indent = false; insert_mode = false; window_has_focus = true; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index d5fe2950f4..905ea46bd7 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -141,12 +141,12 @@ class TextEdit : public Control { const Vector<ColorRegion> *color_regions; mutable Vector<Line> text; Ref<Font> font; - int tab_size; + int indent_size; void _update_line_cache(int p_line) const; public: - void set_tab_size(int p_tab_size); + void set_indent_size(int p_indent_size); void set_font(const Ref<Font> &p_font); void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; } int get_line_width(int p_line) const; @@ -163,7 +163,7 @@ class TextEdit : public Control { void clear(); void clear_caches(); _FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; } - Text() { tab_size = 4; } + Text() { indent_size = 4; } }; struct TextOperation { @@ -221,7 +221,9 @@ class TextEdit : public Control { int max_chars; bool readonly; bool syntax_coloring; - int tab_size; + bool indent_using_spaces; + int indent_size; + String space_indent; Timer *caret_blink_timer; bool caret_blink_enabled; @@ -461,7 +463,9 @@ public: void redo(); void clear_undo_history(); - void set_tab_size(const int p_size); + void set_indent_using_spaces(const bool p_use_spaces); + bool is_indent_using_spaces() const; + void set_indent_size(const int p_size); void set_draw_tabs(bool p_draw); bool is_drawing_tabs() const; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 8db602ca02..3a824a56a3 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -284,16 +284,10 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< // ToolButton - Ref<StyleBox> tb_empty = memnew(StyleBoxEmpty); - tb_empty->set_default_margin(MARGIN_LEFT, 6 * scale); - tb_empty->set_default_margin(MARGIN_RIGHT, 6 * scale); - tb_empty->set_default_margin(MARGIN_TOP, 4 * scale); - tb_empty->set_default_margin(MARGIN_BOTTOM, 4 * scale); - - t->set_stylebox("normal", "ToolButton", tb_empty); - t->set_stylebox("pressed", "ToolButton", make_stylebox(button_pressed_png, 4, 4, 4, 4)); - t->set_stylebox("hover", "ToolButton", make_stylebox(button_normal_png, 4, 4, 4, 4)); - t->set_stylebox("disabled", "ToolButton", make_empty_stylebox(4, 4, 4, 4)); + t->set_stylebox("normal", "ToolButton", make_empty_stylebox(6, 4, 6, 4)); + t->set_stylebox("pressed", "ToolButton", make_stylebox(button_pressed_png, 4, 4, 4, 4, 6, 4, 6, 4)); + t->set_stylebox("hover", "ToolButton", make_stylebox(button_normal_png, 4, 4, 4, 4, 6, 4, 6, 4)); + t->set_stylebox("disabled", "ToolButton", make_empty_stylebox(6, 4, 6, 4)); t->set_stylebox("focus", "ToolButton", focus); t->set_font("font", "ToolButton", default_font); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 7738157330..50fbb6a162 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1775,7 +1775,7 @@ void PackedScene::set_path(const String &p_path, bool p_take_over) { void PackedScene::_bind_methods() { ClassDB::bind_method(D_METHOD("pack", "path:Node"), &PackedScene::pack); - ClassDB::bind_method(D_METHOD("instance:Node", "edit_state"), &PackedScene::instance, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("instance:Node", "edit_state"), &PackedScene::instance, DEFVAL(GEN_EDIT_STATE_DISABLED)); ClassDB::bind_method(D_METHOD("can_instance"), &PackedScene::can_instance); ClassDB::bind_method(D_METHOD("_set_bundled_scene"), &PackedScene::_set_bundled_scene); ClassDB::bind_method(D_METHOD("_get_bundled_scene"), &PackedScene::_get_bundled_scene); |