diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdnative/gd_native_library_editor.cpp | 148 | ||||
-rw-r--r-- | modules/gdnative/gd_native_library_editor.h | 55 | ||||
-rw-r--r-- | modules/gdnative/gdnative/variant.cpp | 17 | ||||
-rw-r--r-- | modules/gdnative/register_types.cpp | 11 | ||||
-rw-r--r-- | modules/gridmap/config.py | 6 | ||||
-rw-r--r-- | modules/gridmap/doc_classes/GridMap.xml | 175 | ||||
-rw-r--r-- | modules/gridmap/doc_classes/README.md | 1 | ||||
-rw-r--r-- | modules/recast/SCsub | 38 | ||||
-rw-r--r-- | modules/recast/config.py | 7 | ||||
-rw-r--r-- | modules/recast/register_types.cpp | 34 | ||||
-rw-r--r-- | modules/recast/register_types.h | 32 | ||||
-rw-r--r-- | modules/svg/image_loader_svg.cpp | 57 | ||||
-rw-r--r-- | modules/svg/image_loader_svg.h | 12 | ||||
-rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.cpp | 59 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 597 | ||||
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.cpp | 20 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 17 |
17 files changed, 958 insertions, 328 deletions
diff --git a/modules/gdnative/gd_native_library_editor.cpp b/modules/gdnative/gd_native_library_editor.cpp new file mode 100644 index 0000000000..cc2c2b69a6 --- /dev/null +++ b/modules/gdnative/gd_native_library_editor.cpp @@ -0,0 +1,148 @@ +/*************************************************************************/ +/* gd_native_library_editor.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifdef TOOLS_ENABLED +#include "gd_native_library_editor.h" + +#include "gdnative.h" + +void GDNativeLibraryEditor::_find_gdnative_singletons(EditorFileSystemDirectory *p_dir, const Set<String> &enabled_list) { + + // check children + + for (int i = 0; i < p_dir->get_file_count(); i++) { + String file_type = p_dir->get_file_type(i); + + if (file_type != "GDNativeLibrary") { + continue; + } + + Ref<GDNativeLibrary> lib = ResourceLoader::load(p_dir->get_file_path(i)); + if (lib.is_valid() && lib->is_singleton_gdnative()) { + String path = p_dir->get_file_path(i); + TreeItem *ti = libraries->create_item(libraries->get_root()); + ti->set_text(0, path.get_file()); + ti->set_tooltip(0, path); + ti->set_metadata(0, path); + ti->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); + ti->set_text(1, "Disabled,Enabled"); + bool enabled = enabled_list.has(path) ? true : false; + + ti->set_range(1, enabled ? 1 : 0); + ti->set_custom_color(1, enabled ? Color(0, 1, 0) : Color(1, 0, 0)); + } + } + + // check subdirectories + for (int i = 0; i < p_dir->get_subdir_count(); i++) { + _find_gdnative_singletons(p_dir->get_subdir(i), enabled_list); + } +} + +void GDNativeLibraryEditor::_update_libraries() { + + updating = true; + libraries->clear(); + libraries->create_item(); //rppt + + Vector<String> enabled_paths; + if (ProjectSettings::get_singleton()->has("gdnative/singletons")) { + enabled_paths = ProjectSettings::get_singleton()->get("gdnative/singletons"); + } + Set<String> enabled_list; + for (int i = 0; i < enabled_paths.size(); i++) { + enabled_list.insert(enabled_paths[i]); + } + + EditorFileSystemDirectory *fs = EditorFileSystem::get_singleton()->get_filesystem(); + if (fs) { + _find_gdnative_singletons(fs, enabled_list); + } + + updating = false; +} + +void GDNativeLibraryEditor::_item_edited() { + if (updating) + return; + + TreeItem *item = libraries->get_edited(); + if (!item) + return; + + bool enabled = item->get_range(1); + String path = item->get_metadata(0); + + Vector<String> enabled_paths; + if (ProjectSettings::get_singleton()->has("gdnative/singletons")) { + enabled_paths = ProjectSettings::get_singleton()->get("gdnative/singletons"); + } + + if (enabled) { + if (enabled_paths.find(path) == -1) { + enabled_paths.push_back(path); + } + } else { + enabled_paths.erase(path); + } + + if (enabled_paths.size()) { + ProjectSettings::get_singleton()->set("gdnative/singletons", enabled_paths); + } else { + ProjectSettings::get_singleton()->set("gdnative/singletons", Variant()); + } +} + +void GDNativeLibraryEditor::_notification(int p_what) { + + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + if (is_visible_in_tree()) { + _update_libraries(); + } + } +} + +void GDNativeLibraryEditor::_bind_methods() { + + ClassDB::bind_method(D_METHOD("_item_edited"), &GDNativeLibraryEditor::_item_edited); +} + +GDNativeLibraryEditor::GDNativeLibraryEditor() { + libraries = memnew(Tree); + libraries->set_columns(2); + libraries->set_column_titles_visible(true); + libraries->set_column_title(0, TTR("Library")); + libraries->set_column_title(1, TTR("Status")); + libraries->set_hide_root(true); + add_margin_child(TTR("Libraries: "), libraries, true); + updating = false; + libraries->connect("item_edited", this, "_item_edited"); +} + +#endif // TOOLS_ENABLED diff --git a/modules/gdnative/gd_native_library_editor.h b/modules/gdnative/gd_native_library_editor.h new file mode 100644 index 0000000000..a11c4620dd --- /dev/null +++ b/modules/gdnative/gd_native_library_editor.h @@ -0,0 +1,55 @@ +/*************************************************************************/ +/* gd_native_library_editor.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GD_NATIVE_LIBRARY_EDITOR_H +#define GD_NATIVE_LIBRARY_EDITOR_H + +#ifdef TOOLS_ENABLED +#include "editor/editor_file_system.h" +#include "editor/project_settings_editor.h" + +class GDNativeLibraryEditor : public VBoxContainer { + Tree *libraries; + + bool updating; + void _update_libraries(); + + void _find_gdnative_singletons(EditorFileSystemDirectory *p_dir, const Set<String> &enabled_list); + void _item_edited(); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + GDNativeLibraryEditor(); +}; + +#endif +#endif // GD_NATIVE_LIBRARY_EDITOR_H diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp index b61f80b1f9..1b2aae607f 100644 --- a/modules/gdnative/gdnative/variant.cpp +++ b/modules/gdnative/gdnative/variant.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "gdnative/variant.h" +#include "core/reference.h" #include "core/variant.h" #ifdef __cplusplus @@ -158,7 +159,21 @@ void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid) void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj) { Variant *dest = (Variant *)r_dest; Object *obj = (Object *)p_obj; - memnew_placement_custom(dest, Variant, Variant(obj)); + Reference *reference = Object::cast_to<Reference>(obj); + REF ref; + if (reference) { + ref = REF(reference); + } + if (!ref.is_null()) { + memnew_placement_custom(dest, Variant, Variant(ref.get_ref_ptr())); + } else { +#if defined(DEBUG_METHODS_ENABLED) + if (reference) { + ERR_PRINT("Reference object has 0 refcount in godot_variant_new_object - you lost it somewhere."); + } +#endif + memnew_placement_custom(dest, Variant, Variant(obj)); + } } void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict) { diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 559e9fa455..997c342045 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -43,7 +43,7 @@ #ifdef TOOLS_ENABLED #include "editor/editor_node.h" - +#include "gd_native_library_editor.h" // Class used to discover singleton gdnative files void actual_discoverer_handler(); @@ -115,7 +115,12 @@ void actual_discoverer_handler() { GDNativeSingletonDiscover *discoverer = NULL; -void discoverer_callback() { +static void editor_init_callback() { + + GDNativeLibraryEditor *library_editor = memnew(GDNativeLibraryEditor); + library_editor->set_name(TTR("GDNative")); + ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(library_editor); + discoverer = memnew(GDNativeSingletonDiscover); EditorFileSystem::get_singleton()->connect("filesystem_changed", discoverer, "get_class"); } @@ -184,7 +189,7 @@ void register_gdnative_types() { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { - EditorNode::add_init_callback(discoverer_callback); + EditorNode::add_init_callback(editor_init_callback); } #endif diff --git a/modules/gridmap/config.py b/modules/gridmap/config.py index 5698a37295..b3dbb9f46a 100644 --- a/modules/gridmap/config.py +++ b/modules/gridmap/config.py @@ -6,3 +6,9 @@ def can_build(platform): def configure(env): pass + +def get_doc_classes(): + return ["GridMap"] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml new file mode 100644 index 0000000000..3676570ec1 --- /dev/null +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="GridMap" inherits="Spatial" category="Core" version="3.0.alpha.custom_build"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="clear"> + <return type="void"> + </return> + <description> + </description> + </method> + <method name="get_cell_item" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="x" type="int"> + </argument> + <argument index="1" name="y" type="int"> + </argument> + <argument index="2" name="z" type="int"> + </argument> + <description> + </description> + </method> + <method name="get_cell_item_orientation" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="x" type="int"> + </argument> + <argument index="1" name="y" type="int"> + </argument> + <argument index="2" name="z" type="int"> + </argument> + <description> + </description> + </method> + <method name="get_cell_size" qualifiers="const"> + <return type="Vector3"> + </return> + <description> + </description> + </method> + <method name="get_center_x" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="get_center_y" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="get_center_z" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="get_meshes"> + <return type="Array"> + </return> + <description> + </description> + </method> + <method name="get_octant_size" qualifiers="const"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="get_theme" qualifiers="const"> + <return type="MeshLibrary"> + </return> + <description> + </description> + </method> + <method name="resource_changed"> + <return type="void"> + </return> + <argument index="0" name="resource" type="Resource"> + </argument> + <description> + </description> + </method> + <method name="set_cell_item"> + <return type="void"> + </return> + <argument index="0" name="x" type="int"> + </argument> + <argument index="1" name="y" type="int"> + </argument> + <argument index="2" name="z" type="int"> + </argument> + <argument index="3" name="item" type="int"> + </argument> + <argument index="4" name="orientation" type="int" default="0"> + </argument> + <description> + </description> + </method> + <method name="set_cell_size"> + <return type="void"> + </return> + <argument index="0" name="size" type="Vector3"> + </argument> + <description> + </description> + </method> + <method name="set_center_x"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="set_center_y"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="set_center_z"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="set_clip"> + <return type="void"> + </return> + <argument index="0" name="enabled" type="bool"> + </argument> + <argument index="1" name="clipabove" type="bool" default="true"> + </argument> + <argument index="2" name="floor" type="int" default="0"> + </argument> + <argument index="3" name="axis" type="int" enum="Vector3.Axis" default="0"> + </argument> + <description> + </description> + </method> + <method name="set_octant_size"> + <return type="void"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <description> + </description> + </method> + <method name="set_theme"> + <return type="void"> + </return> + <argument index="0" name="theme" type="MeshLibrary"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + <constant name="INVALID_CELL_ITEM" value="-1" enum=""> + </constant> + </constants> +</class> diff --git a/modules/gridmap/doc_classes/README.md b/modules/gridmap/doc_classes/README.md new file mode 100644 index 0000000000..b1ec9058c8 --- /dev/null +++ b/modules/gridmap/doc_classes/README.md @@ -0,0 +1 @@ +Doc classes will appear here when generating
\ No newline at end of file diff --git a/modules/recast/SCsub b/modules/recast/SCsub new file mode 100644 index 0000000000..349bd22efb --- /dev/null +++ b/modules/recast/SCsub @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +Import('env') + +# Not building in a separate env as core needs it + +# Thirdparty source files +if (env['builtin_recast'] != 'no'): + thirdparty_dir = "#thirdparty/recastnavigation/Recast/" + thirdparty_sources = [ + "Source/Recast.cpp", + "Source/RecastAlloc.cpp", + "Source/RecastArea.cpp", + "Source/RecastAssert.cpp", + "Source/RecastContour.cpp", + "Source/RecastFilter.cpp", + "Source/RecastLayers.cpp", + "Source/RecastMesh.cpp", + "Source/RecastMeshDetail.cpp", + "Source/RecastRasterization.cpp", + "Source/RecastRegion.cpp", + ] + thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + + env.Append(CPPPATH=[thirdparty_dir, thirdparty_dir + "/Include"]) + + # also requires recast headers + if (env['builtin_recast'] != 'no'): + env.Append(CPPPATH=["#thirdparty/recastnavigation/Recast"]) + + lib = env.Library("recast_builtin", thirdparty_sources) + env.Append(LIBS=[lib]) + +# Godot source files +env.add_source_files(env.modules_sources, "*.cpp") +env.Append(CCFLAGS=['-DRECAST_ENABLED']) + +Export('env') diff --git a/modules/recast/config.py b/modules/recast/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/recast/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/recast/register_types.cpp b/modules/recast/register_types.cpp new file mode 100644 index 0000000000..654ceec373 --- /dev/null +++ b/modules/recast/register_types.cpp @@ -0,0 +1,34 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "register_types.h" + +void register_recast_types() {} +void unregister_recast_types() {} diff --git a/modules/recast/register_types.h b/modules/recast/register_types.h new file mode 100644 index 0000000000..90587bc11f --- /dev/null +++ b/modules/recast/register_types.h @@ -0,0 +1,32 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +void register_recast_types(); +void unregister_recast_types(); diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index 935a412ed1..c575edbba3 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -63,33 +63,39 @@ inline void change_nsvg_paint_color(NSVGpaint *p_paint, const uint32_t p_old, co } } } -void ImageLoaderSVG::_convert_colors(NSVGimage *p_svg_image, const Dictionary p_colors) { - List<uint32_t> replace_colors_i; - List<uint32_t> new_colors_i; - List<Color> replace_colors; - List<Color> new_colors; - - for (int i = 0; i < p_colors.keys().size(); i++) { - Variant r_c = p_colors.keys()[i]; - Variant n_c = p_colors[p_colors.keys()[i]]; - if (r_c.get_type() == Variant::COLOR && n_c.get_type() == Variant::COLOR) { - Color replace_color = r_c; - Color new_color = n_c; - replace_colors_i.push_back(replace_color.to_abgr32()); - new_colors_i.push_back(new_color.to_abgr32()); - } - } + +void ImageLoaderSVG::_convert_colors(NSVGimage *p_svg_image) { for (NSVGshape *shape = p_svg_image->shapes; shape != NULL; shape = shape->next) { - for (int i = 0; i < replace_colors_i.size(); i++) { - change_nsvg_paint_color(&(shape->stroke), replace_colors_i[i], new_colors_i[i]); - change_nsvg_paint_color(&(shape->fill), replace_colors_i[i], new_colors_i[i]); + for (int i = 0; i < replace_colors.old_colors.size(); i++) { + change_nsvg_paint_color(&(shape->stroke), replace_colors.old_colors[i], replace_colors.new_colors[i]); + change_nsvg_paint_color(&(shape->fill), replace_colors.old_colors[i], replace_colors.new_colors[i]); + } + } +} + +void ImageLoaderSVG::set_convert_colors(Dictionary *p_replace_color) { + + if (p_replace_color) { + Dictionary replace_color = *p_replace_color; + for (int i = 0; i < replace_color.keys().size(); i++) { + Variant o_c = replace_color.keys()[i]; + Variant n_c = replace_color[replace_color.keys()[i]]; + if (o_c.get_type() == Variant::COLOR && n_c.get_type() == Variant::COLOR) { + Color old_color = o_c; + Color new_color = n_c; + replace_colors.old_colors.push_back(old_color.to_abgr32()); + replace_colors.new_colors.push_back(new_color.to_abgr32()); + } } + } else { + replace_colors.old_colors.clear(); + replace_colors.new_colors.clear(); } } -Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t> *p_data, float p_scale, bool upsample, const Dictionary *p_replace_colors) { +Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t> *p_data, float p_scale, bool upsample, bool convert_colors) { NSVGimage *svg_image; PoolVector<uint8_t>::Read src_r = p_data->read(); svg_image = nsvgParse((char *)src_r.ptr(), "px", 96); @@ -97,10 +103,9 @@ Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t ERR_PRINT("SVG Corrupted"); return ERR_FILE_CORRUPT; } + if (convert_colors) + _convert_colors(svg_image); - if (p_replace_colors != NULL) { - _convert_colors(svg_image, *p_replace_colors); - } float upscale = upsample ? 2.0 : 1.0; int w = (int)(svg_image->width * p_scale * upscale); @@ -123,7 +128,7 @@ Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t return OK; } -Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *svg_str, float p_scale, bool upsample, const Dictionary *p_replace_colors) { +Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *svg_str, float p_scale, bool upsample, bool convert_colors) { size_t str_len = strlen(svg_str); PoolVector<uint8_t> src_data; @@ -131,7 +136,7 @@ Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *s PoolVector<uint8_t>::Write src_w = src_data.write(); memcpy(src_w.ptr(), svg_str, str_len + 1); - return _create_image(p_image, &src_data, p_scale, upsample, p_replace_colors); + return _create_image(p_image, &src_data, p_scale, upsample, convert_colors); } Error ImageLoaderSVG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { @@ -154,3 +159,5 @@ void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const ImageLoaderSVG::ImageLoaderSVG() { } + +ImageLoaderSVG::ReplaceColors ImageLoaderSVG::replace_colors;
\ No newline at end of file diff --git a/modules/svg/image_loader_svg.h b/modules/svg/image_loader_svg.h index f692b1b28c..332ac214a5 100644 --- a/modules/svg/image_loader_svg.h +++ b/modules/svg/image_loader_svg.h @@ -52,13 +52,17 @@ public: }; class ImageLoaderSVG : public ImageFormatLoader { - + static struct ReplaceColors { + List<uint32_t> old_colors; + List<uint32_t> new_colors; + } replace_colors; static SVGRasterizer rasterizer; - static void _convert_colors(NSVGimage *p_svg_imge, const Dictionary p_colors); - static Error _create_image(Ref<Image> p_image, const PoolVector<uint8_t> *p_data, float p_scale, bool upsample, const Dictionary *p_replace_color = NULL); + static void _convert_colors(NSVGimage *p_svg_imge); + static Error _create_image(Ref<Image> p_image, const PoolVector<uint8_t> *p_data, float p_scale, bool upsample, bool convert_colors = false); public: - static Error create_image_from_string(Ref<Image> p_image, const char *p_svg_str, float p_scale, bool upsample, const Dictionary *p_replace_color = NULL); + static void set_convert_colors(Dictionary *p_replace_color = NULL); + static Error create_image_from_string(Ref<Image> p_image, const char *p_svg_str, float p_scale, bool upsample, bool convert_colors = false); virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale); virtual void get_recognized_extensions(List<String> *p_extensions) const; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 2c8796820e..972be5f5a4 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -1175,6 +1175,65 @@ void VisualScriptBuiltinFunc::_bind_methods() { cc += func_name[i]; } ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, cc), "set_func", "get_func"); + + BIND_ENUM_CONSTANT(MATH_SIN); + BIND_ENUM_CONSTANT(MATH_COS); + BIND_ENUM_CONSTANT(MATH_TAN); + BIND_ENUM_CONSTANT(MATH_SINH); + BIND_ENUM_CONSTANT(MATH_COSH); + BIND_ENUM_CONSTANT(MATH_TANH); + BIND_ENUM_CONSTANT(MATH_ASIN); + BIND_ENUM_CONSTANT(MATH_ACOS); + BIND_ENUM_CONSTANT(MATH_ATAN); + BIND_ENUM_CONSTANT(MATH_ATAN2); + BIND_ENUM_CONSTANT(MATH_SQRT); + BIND_ENUM_CONSTANT(MATH_FMOD); + BIND_ENUM_CONSTANT(MATH_FPOSMOD); + BIND_ENUM_CONSTANT(MATH_FLOOR); + BIND_ENUM_CONSTANT(MATH_CEIL); + BIND_ENUM_CONSTANT(MATH_ROUND); + BIND_ENUM_CONSTANT(MATH_ABS); + BIND_ENUM_CONSTANT(MATH_SIGN); + BIND_ENUM_CONSTANT(MATH_POW); + BIND_ENUM_CONSTANT(MATH_LOG); + BIND_ENUM_CONSTANT(MATH_EXP); + BIND_ENUM_CONSTANT(MATH_ISNAN); + BIND_ENUM_CONSTANT(MATH_ISINF); + BIND_ENUM_CONSTANT(MATH_EASE); + BIND_ENUM_CONSTANT(MATH_DECIMALS); + BIND_ENUM_CONSTANT(MATH_STEPIFY); + BIND_ENUM_CONSTANT(MATH_LERP); + BIND_ENUM_CONSTANT(MATH_DECTIME); + BIND_ENUM_CONSTANT(MATH_RANDOMIZE); + BIND_ENUM_CONSTANT(MATH_RAND); + BIND_ENUM_CONSTANT(MATH_RANDF); + BIND_ENUM_CONSTANT(MATH_RANDOM); + BIND_ENUM_CONSTANT(MATH_SEED); + BIND_ENUM_CONSTANT(MATH_RANDSEED); + BIND_ENUM_CONSTANT(MATH_DEG2RAD); + BIND_ENUM_CONSTANT(MATH_RAD2DEG); + BIND_ENUM_CONSTANT(MATH_LINEAR2DB); + BIND_ENUM_CONSTANT(MATH_DB2LINEAR); + BIND_ENUM_CONSTANT(LOGIC_MAX); + BIND_ENUM_CONSTANT(LOGIC_MIN); + BIND_ENUM_CONSTANT(LOGIC_CLAMP); + BIND_ENUM_CONSTANT(LOGIC_NEAREST_PO2); + BIND_ENUM_CONSTANT(OBJ_WEAKREF); + BIND_ENUM_CONSTANT(FUNC_FUNCREF); + BIND_ENUM_CONSTANT(TYPE_CONVERT); + BIND_ENUM_CONSTANT(TYPE_OF); + BIND_ENUM_CONSTANT(TYPE_EXISTS); + BIND_ENUM_CONSTANT(TEXT_CHAR); + BIND_ENUM_CONSTANT(TEXT_STR); + BIND_ENUM_CONSTANT(TEXT_PRINT); + BIND_ENUM_CONSTANT(TEXT_PRINTERR); + BIND_ENUM_CONSTANT(TEXT_PRINTRAW); + BIND_ENUM_CONSTANT(VAR_TO_STR); + BIND_ENUM_CONSTANT(STR_TO_VAR); + BIND_ENUM_CONSTANT(VAR_TO_BYTES); + BIND_ENUM_CONSTANT(BYTES_TO_VAR); + BIND_ENUM_CONSTANT(COLORN); + BIND_ENUM_CONSTANT(FUNC_MAX); } VisualScriptBuiltinFunc::VisualScriptBuiltinFunc() { diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index d415618383..671a507377 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1397,415 +1397,424 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (p_from == graph) { + if (p_from != graph) { + return; + } - Dictionary d = p_data; - if (d.has("type") && String(d["type"]) == "visual_script_node_drag") { + Dictionary d = p_data; - Vector2 ofs = graph->get_scroll_ofs() + p_point; + if (!d.has("type")) { + return; + } - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + if (String(d["type"]) == "visual_script_node_drag") { + if (!d.has("node_type") || String(d["node_type"]) == "Null") { + return; + } - ofs /= EDSCALE; + Vector2 ofs = graph->get_scroll_ofs() + p_point; - Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(d["node_type"]); - int new_id = script->get_available_id(); + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } - undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + ofs /= EDSCALE; - Node *node = graph->get_node(itos(new_id)); - if (node) { - graph->set_selected(node); - _node_selected(node); - } + Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(d["node_type"]); + int new_id = script->get_available_id(); + + undo_redo->create_action(TTR("Add Node")); + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); + + Node *node = graph->get_node(itos(new_id)); + if (node) { + graph->set_selected(node); + _node_selected(node); } + } - if (d.has("type") && String(d["type"]) == "visual_script_variable_drag") { + if (String(d["type"]) == "visual_script_variable_drag") { #ifdef OSX_ENABLED - bool use_set = Input::get_singleton()->is_key_pressed(KEY_META); + bool use_set = Input::get_singleton()->is_key_pressed(KEY_META); #else - bool use_set = Input::get_singleton()->is_key_pressed(KEY_CONTROL); + bool use_set = Input::get_singleton()->is_key_pressed(KEY_CONTROL); #endif - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + Vector2 ofs = graph->get_scroll_ofs() + p_point; + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } - ofs /= EDSCALE; + ofs /= EDSCALE; - Ref<VisualScriptNode> vnode; - if (use_set) { - Ref<VisualScriptVariableSet> vnodes; - vnodes.instance(); - vnodes->set_variable(d["variable"]); - vnode = vnodes; - } else { + Ref<VisualScriptNode> vnode; + if (use_set) { + Ref<VisualScriptVariableSet> vnodes; + vnodes.instance(); + vnodes->set_variable(d["variable"]); + vnode = vnodes; + } else { - Ref<VisualScriptVariableGet> vnodeg; - vnodeg.instance(); - vnodeg->set_variable(d["variable"]); - vnode = vnodeg; - } + Ref<VisualScriptVariableGet> vnodeg; + vnodeg.instance(); + vnodeg->set_variable(d["variable"]); + vnode = vnodeg; + } - int new_id = script->get_available_id(); + int new_id = script->get_available_id(); - undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + undo_redo->create_action(TTR("Add Node")); + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); - Node *node = graph->get_node(itos(new_id)); - if (node) { - graph->set_selected(node); - _node_selected(node); - } + Node *node = graph->get_node(itos(new_id)); + if (node) { + graph->set_selected(node); + _node_selected(node); } + } - if (d.has("type") && String(d["type"]) == "visual_script_function_drag") { + if (String(d["type"]) == "visual_script_function_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + Vector2 ofs = graph->get_scroll_ofs() + p_point; + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } - ofs /= EDSCALE; + ofs /= EDSCALE; - Ref<VisualScriptFunctionCall> vnode; - vnode.instance(); - vnode->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SELF); + Ref<VisualScriptFunctionCall> vnode; + vnode.instance(); + vnode->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SELF); - int new_id = script->get_available_id(); + int new_id = script->get_available_id(); - undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); - undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type()); - undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]); + undo_redo->create_action(TTR("Add Node")); + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); + undo_redo->add_do_method(vnode.ptr(), "set_base_type", script->get_instance_base_type()); + undo_redo->add_do_method(vnode.ptr(), "set_function", d["function"]); - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); - Node *node = graph->get_node(itos(new_id)); - if (node) { - graph->set_selected(node); - _node_selected(node); - } + Node *node = graph->get_node(itos(new_id)); + if (node) { + graph->set_selected(node); + _node_selected(node); } + } - if (d.has("type") && String(d["type"]) == "visual_script_signal_drag") { + if (String(d["type"]) == "visual_script_signal_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + Vector2 ofs = graph->get_scroll_ofs() + p_point; + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } - ofs /= EDSCALE; + ofs /= EDSCALE; - Ref<VisualScriptEmitSignal> vnode; - vnode.instance(); - vnode->set_signal(d["signal"]); + Ref<VisualScriptEmitSignal> vnode; + vnode.instance(); + vnode->set_signal(d["signal"]); - int new_id = script->get_available_id(); + int new_id = script->get_available_id(); - undo_redo->create_action(TTR("Add Node")); - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + undo_redo->create_action(TTR("Add Node")); + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, vnode, ofs); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); - Node *node = graph->get_node(itos(new_id)); - if (node) { - graph->set_selected(node); - _node_selected(node); - } + Node *node = graph->get_node(itos(new_id)); + if (node) { + graph->set_selected(node); + _node_selected(node); } + } - if (d.has("type") && String(d["type"]) == "resource") { + if (String(d["type"]) == "resource") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + Vector2 ofs = graph->get_scroll_ofs() + p_point; + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } - ofs /= EDSCALE; + ofs /= EDSCALE; - Ref<VisualScriptPreload> prnode; - prnode.instance(); - prnode->set_preload(d["resource"]); + Ref<VisualScriptPreload> prnode; + prnode.instance(); + prnode->set_preload(d["resource"]); - int new_id = script->get_available_id(); + int new_id = script->get_available_id(); - undo_redo->create_action(TTR("Add Preload Node")); - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs); - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + undo_redo->create_action(TTR("Add Preload Node")); + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); - Node *node = graph->get_node(itos(new_id)); - if (node) { - graph->set_selected(node); - _node_selected(node); - } + Node *node = graph->get_node(itos(new_id)); + if (node) { + graph->set_selected(node); + _node_selected(node); } + } - if (d.has("type") && String(d["type"]) == "files") { - - Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + if (String(d["type"]) == "files") { - ofs /= EDSCALE; + Vector2 ofs = graph->get_scroll_ofs() + p_point; + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } - Array files = d["files"]; + ofs /= EDSCALE; - List<int> new_ids; - int new_id = script->get_available_id(); + Array files = d["files"]; - if (files.size()) { - undo_redo->create_action(TTR("Add Preload Node")); + List<int> new_ids; + int new_id = script->get_available_id(); - for (int i = 0; i < files.size(); i++) { + if (files.size()) { + undo_redo->create_action(TTR("Add Preload Node")); - Ref<Resource> res = ResourceLoader::load(files[i]); - if (!res.is_valid()) - continue; + for (int i = 0; i < files.size(); i++) { - Ref<VisualScriptPreload> prnode; - prnode.instance(); - prnode->set_preload(res); + Ref<Resource> res = ResourceLoader::load(files[i]); + if (!res.is_valid()) + continue; - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs); - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); - new_ids.push_back(new_id); - new_id++; - ofs += Vector2(20, 20) * EDSCALE; - } + Ref<VisualScriptPreload> prnode; + prnode.instance(); + prnode->set_preload(res); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, new_id, prnode, ofs); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, new_id); + new_ids.push_back(new_id); + new_id++; + ofs += Vector2(20, 20) * EDSCALE; } - for (List<int>::Element *E = new_ids.front(); E; E = E->next()) { + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); + } + + for (List<int>::Element *E = new_ids.front(); E; E = E->next()) { - Node *node = graph->get_node(itos(E->get())); - if (node) { - graph->set_selected(node); - _node_selected(node); - } + Node *node = graph->get_node(itos(E->get())); + if (node) { + graph->set_selected(node); + _node_selected(node); } } + } - if (d.has("type") && String(d["type"]) == "nodes") { + if (String(d["type"]) == "nodes") { - Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); + Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); - if (!sn) { - EditorNode::get_singleton()->show_warning("Can't drop nodes because script '" + get_name() + "' is not used in this scene."); - return; - } + if (!sn) { + EditorNode::get_singleton()->show_warning("Can't drop nodes because script '" + get_name() + "' is not used in this scene."); + return; + } #ifdef OSX_ENABLED - bool use_node = Input::get_singleton()->is_key_pressed(KEY_META); + bool use_node = Input::get_singleton()->is_key_pressed(KEY_META); #else - bool use_node = Input::get_singleton()->is_key_pressed(KEY_CONTROL); + bool use_node = Input::get_singleton()->is_key_pressed(KEY_CONTROL); #endif - Array nodes = d["nodes"]; + Array nodes = d["nodes"]; - Vector2 ofs = graph->get_scroll_ofs() + p_point; + Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - ofs /= EDSCALE; + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } + ofs /= EDSCALE; - undo_redo->create_action(TTR("Add Node(s) From Tree")); - int base_id = script->get_available_id(); + undo_redo->create_action(TTR("Add Node(s) From Tree")); + int base_id = script->get_available_id(); - if (nodes.size() > 1) { - use_node = true; - } + if (nodes.size() > 1) { + use_node = true; + } - for (int i = 0; i < nodes.size(); i++) { + for (int i = 0; i < nodes.size(); i++) { - NodePath np = nodes[i]; - Node *node = get_node(np); - if (!node) { - continue; - } - - Ref<VisualScriptNode> n; + NodePath np = nodes[i]; + Node *node = get_node(np); + if (!node) { + continue; + } - if (use_node) { - Ref<VisualScriptSceneNode> scene_node; - scene_node.instance(); - scene_node->set_node_path(sn->get_path_to(node)); - n = scene_node; + Ref<VisualScriptNode> n; - } else { - Ref<VisualScriptFunctionCall> call; - call.instance(); - call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH); - call->set_base_path(sn->get_path_to(node)); - call->set_base_type(node->get_class()); - n = call; - - method_select->select_method_from_instance(node); - selecting_method_id = base_id; - } + if (use_node) { + Ref<VisualScriptSceneNode> scene_node; + scene_node.instance(); + scene_node->set_node_path(sn->get_path_to(node)); + n = scene_node; - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, n, ofs); - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id); + } else { + Ref<VisualScriptFunctionCall> call; + call.instance(); + call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH); + call->set_base_path(sn->get_path_to(node)); + call->set_base_type(node->get_class()); + n = call; - base_id++; - ofs += Vector2(25, 25); + method_select->select_method_from_instance(node); + selecting_method_id = base_id; } - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, n, ofs); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id); + + base_id++; + ofs += Vector2(25, 25); } + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); + } - if (d.has("type") && String(d["type"]) == "obj_property") { + if (String(d["type"]) == "obj_property") { - Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); + Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); - if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { - EditorNode::get_singleton()->show_warning("Can't drop properties because script '" + get_name() + "' is not used in this scene.\nDrop holding 'Shift' to just copy the signature."); - return; - } + if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + EditorNode::get_singleton()->show_warning("Can't drop properties because script '" + get_name() + "' is not used in this scene.\nDrop holding 'Shift' to just copy the signature."); + return; + } - Object *obj = d["object"]; + Object *obj = d["object"]; - if (!obj) - return; + if (!obj) + return; - Node *node = Object::cast_to<Node>(obj); - Vector2 ofs = graph->get_scroll_ofs() + p_point; + Node *node = Object::cast_to<Node>(obj); + Vector2 ofs = graph->get_scroll_ofs() + p_point; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } - ofs /= EDSCALE; + ofs /= EDSCALE; #ifdef OSX_ENABLED - bool use_get = Input::get_singleton()->is_key_pressed(KEY_META); + bool use_get = Input::get_singleton()->is_key_pressed(KEY_META); #else - bool use_get = Input::get_singleton()->is_key_pressed(KEY_CONTROL); + bool use_get = Input::get_singleton()->is_key_pressed(KEY_CONTROL); #endif - if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { - if (use_get) - undo_redo->create_action(TTR("Add Getter Property")); - else - undo_redo->create_action(TTR("Add Setter Property")); + if (use_get) + undo_redo->create_action(TTR("Add Getter Property")); + else + undo_redo->create_action(TTR("Add Setter Property")); - int base_id = script->get_available_id(); + int base_id = script->get_available_id(); - Ref<VisualScriptNode> vnode; + Ref<VisualScriptNode> vnode; - if (!use_get) { + if (!use_get) { - Ref<VisualScriptPropertySet> pset; - pset.instance(); - pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE); - pset->set_base_type(obj->get_class()); - /*if (use_value) { + Ref<VisualScriptPropertySet> pset; + pset.instance(); + pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE); + pset->set_base_type(obj->get_class()); + /*if (use_value) { pset->set_use_builtin_value(true); pset->set_builtin_value(d["value"]); }*/ - vnode = pset; - } else { - - Ref<VisualScriptPropertyGet> pget; - pget.instance(); - pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE); - pget->set_base_type(obj->get_class()); + vnode = pset; + } else { - vnode = pget; - } + Ref<VisualScriptPropertyGet> pget; + pget.instance(); + pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE); + pget->set_base_type(obj->get_class()); - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs); - undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]); - if (!use_get) { - undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]); - } + vnode = pget; + } - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id); + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs); + undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]); + if (!use_get) { + undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]); + } - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id); - } else { + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); - if (use_get) - undo_redo->create_action(TTR("Add Getter Property")); - else - undo_redo->create_action(TTR("Add Setter Property")); + } else { - int base_id = script->get_available_id(); + if (use_get) + undo_redo->create_action(TTR("Add Getter Property")); + else + undo_redo->create_action(TTR("Add Setter Property")); - Ref<VisualScriptNode> vnode; + int base_id = script->get_available_id(); - if (!use_get) { + Ref<VisualScriptNode> vnode; - Ref<VisualScriptPropertySet> pset; - pset.instance(); - if (sn == node) { - pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF); - } else { - pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH); - pset->set_base_path(sn->get_path_to(node)); - } + if (!use_get) { - vnode = pset; + Ref<VisualScriptPropertySet> pset; + pset.instance(); + if (sn == node) { + pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF); } else { - - Ref<VisualScriptPropertyGet> pget; - pget.instance(); - if (sn == node) { - pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF); - } else { - pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_NODE_PATH); - pget->set_base_path(sn->get_path_to(node)); - } - vnode = pget; + pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH); + pset->set_base_path(sn->get_path_to(node)); } - undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs); - undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]); - if (!use_get) { - undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]); - } - undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - undo_redo->commit_action(); + vnode = pset; + } else { + + Ref<VisualScriptPropertyGet> pget; + pget.instance(); + if (sn == node) { + pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF); + } else { + pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_NODE_PATH); + pget->set_base_path(sn->get_path_to(node)); + } + vnode = pget; } + undo_redo->add_do_method(script.ptr(), "add_node", edited_func, base_id, vnode, ofs); + undo_redo->add_do_method(vnode.ptr(), "set_property", d["property"]); + if (!use_get) { + undo_redo->add_do_method(vnode.ptr(), "set_default_input_value", 0, d["value"]); + } + undo_redo->add_undo_method(script.ptr(), "remove_node", edited_func, base_id); + + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->commit_action(); } } } diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 5fcc5b0ad9..267946750f 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -748,6 +748,13 @@ void VisualScriptFunctionCall::_bind_methods() { BIND_ENUM_CONSTANT(CALL_MODE_NODE_PATH); BIND_ENUM_CONSTANT(CALL_MODE_INSTANCE); BIND_ENUM_CONSTANT(CALL_MODE_BASIC_TYPE); + BIND_ENUM_CONSTANT(CALL_MODE_SINGLETON); + + BIND_ENUM_CONSTANT(RPC_DISABLED); + BIND_ENUM_CONSTANT(RPC_RELIABLE); + BIND_ENUM_CONSTANT(RPC_UNRELIABLE); + BIND_ENUM_CONSTANT(RPC_RELIABLE_TO_ID); + BIND_ENUM_CONSTANT(RPC_UNRELIABLE_TO_ID); } class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance { @@ -1487,6 +1494,19 @@ void VisualScriptPropertySet::_bind_methods() { BIND_ENUM_CONSTANT(CALL_MODE_SELF); BIND_ENUM_CONSTANT(CALL_MODE_NODE_PATH); BIND_ENUM_CONSTANT(CALL_MODE_INSTANCE); + BIND_ENUM_CONSTANT(CALL_MODE_BASIC_TYPE); + + BIND_ENUM_CONSTANT(ASSIGN_OP_NONE); + BIND_ENUM_CONSTANT(ASSIGN_OP_ADD); + BIND_ENUM_CONSTANT(ASSIGN_OP_SUB); + BIND_ENUM_CONSTANT(ASSIGN_OP_MUL); + BIND_ENUM_CONSTANT(ASSIGN_OP_DIV); + BIND_ENUM_CONSTANT(ASSIGN_OP_MOD); + BIND_ENUM_CONSTANT(ASSIGN_OP_SHIFT_LEFT); + BIND_ENUM_CONSTANT(ASSIGN_OP_SHIFT_RIGHT); + BIND_ENUM_CONSTANT(ASSIGN_OP_BIT_AND); + BIND_ENUM_CONSTANT(ASSIGN_OP_BIT_OR); + BIND_ENUM_CONSTANT(ASSIGN_OP_BIT_XOR); } class VisualScriptNodeInstancePropertySet : public VisualScriptNodeInstance { diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 093f01c49f..b617c11bab 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -1882,6 +1882,16 @@ void VisualScriptMathConstant::_bind_methods() { cc += const_name[i]; } ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); + + BIND_ENUM_CONSTANT(MATH_CONSTANT_ONE); + BIND_ENUM_CONSTANT(MATH_CONSTANT_PI); + BIND_ENUM_CONSTANT(MATH_CONSTANT_2PI); + BIND_ENUM_CONSTANT(MATH_CONSTANT_HALF_PI); + BIND_ENUM_CONSTANT(MATH_CONSTANT_E); + BIND_ENUM_CONSTANT(MATH_CONSTANT_SQRT2); + BIND_ENUM_CONSTANT(MATH_CONSTANT_INF); + BIND_ENUM_CONSTANT(MATH_CONSTANT_NAN); + BIND_ENUM_CONSTANT(MATH_CONSTANT_MAX); } VisualScriptMathConstant::VisualScriptMathConstant() { @@ -2002,7 +2012,7 @@ void VisualScriptEngineSingleton::_bind_methods() { cc += E->get().name; } - ADD_PROPERTY(PropertyInfo(Variant::STRING, "/constant", PROPERTY_HINT_ENUM, cc), "set_singleton", "get_singleton"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, cc), "set_singleton", "get_singleton"); } VisualScriptEngineSingleton::VisualScriptEngineSingleton() { @@ -3535,6 +3545,11 @@ void VisualScriptInputAction::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action_name", "get_action_name"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Pressed,Released,JustPressed,JustReleased"), "set_action_mode", "get_action_mode"); + + BIND_ENUM_CONSTANT(MODE_PRESSED); + BIND_ENUM_CONSTANT(MODE_RELEASED); + BIND_ENUM_CONSTANT(MODE_JUST_PRESSED); + BIND_ENUM_CONSTANT(MODE_JUST_RELEASED); } VisualScriptInputAction::VisualScriptInputAction() { |