diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdnative/gdnative/color.cpp | 8 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/color.h | 4 | ||||
-rw-r--r-- | modules/gdnative/register_types.cpp | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_editor.cpp | 6 | ||||
-rw-r--r-- | modules/gdscript/gd_functions.cpp | 18 | ||||
-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/pvr/texture_loader_pvr.cpp | 8 | ||||
-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/theora/video_stream_theora.cpp | 3 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 808 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.h | 8 | ||||
-rw-r--r-- | modules/visual_script/visual_script_expression.cpp | 1 | ||||
-rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 20 |
20 files changed, 770 insertions, 478 deletions
diff --git a/modules/gdnative/gdnative/color.cpp b/modules/gdnative/gdnative/color.cpp index 3f8912d896..2a5c0887a1 100644 --- a/modules/gdnative/gdnative/color.cpp +++ b/modules/gdnative/gdnative/color.cpp @@ -112,14 +112,14 @@ godot_string GDAPI godot_color_as_string(const godot_color *p_self) { return ret; } -godot_int GDAPI godot_color_to_32(const godot_color *p_self) { +godot_int GDAPI godot_color_to_rgba32(const godot_color *p_self) { const Color *self = (const Color *)p_self; - return self->to_32(); + return self->to_rgba32(); } -godot_int GDAPI godot_color_to_ARGB32(const godot_color *p_self) { +godot_int GDAPI godot_color_to_argb32(const godot_color *p_self) { const Color *self = (const Color *)p_self; - return self->to_ARGB32(); + return self->to_argb32(); } godot_real GDAPI godot_color_gray(const godot_color *p_self) { diff --git a/modules/gdnative/include/gdnative/color.h b/modules/gdnative/include/gdnative/color.h index 90dccf75aa..14265466b9 100644 --- a/modules/gdnative/include/gdnative/color.h +++ b/modules/gdnative/include/gdnative/color.h @@ -69,9 +69,9 @@ godot_real godot_color_get_v(const godot_color *p_self); godot_string GDAPI godot_color_as_string(const godot_color *p_self); -godot_int GDAPI godot_color_to_32(const godot_color *p_self); +godot_int GDAPI godot_color_to_rgba32(const godot_color *p_self); -godot_int GDAPI godot_color_to_ARGB32(const godot_color *p_self); +godot_int GDAPI godot_color_to_argb32(const godot_color *p_self); godot_real GDAPI godot_color_gray(const godot_color *p_self); diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index d809109987..559e9fa455 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -248,7 +248,7 @@ void unregister_gdnative_types() { memdelete(GDNativeCallRegistry::singleton); #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { + if (Engine::get_singleton()->is_editor_hint() && discoverer != NULL) { memdelete(discoverer); } #endif diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 70e7da5748..bc51b84047 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -866,7 +866,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: MethodBind *mb = ClassDB::get_method(base_type, getter); if (mb) { PropertyInfo rt = mb->get_return_info(); - if (rt.usage & PROPERTY_USAGE_CLASS_IS_ENUM && t == Variant::INT) { + if ((rt.usage & PROPERTY_USAGE_CLASS_IS_ENUM) && t == Variant::INT) { r_type.enumeration = rt.class_name; } else if (t == Variant::OBJECT) { @@ -1903,11 +1903,11 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N arghint += ", "; else arghint += " "; - if (i == p_argidx || (mi.flags & METHOD_FLAG_VARARG && i > p_argidx)) { + if (i == p_argidx || ((mi.flags & METHOD_FLAG_VARARG) && i > p_argidx)) { arghint += String::chr(0xFFFF); } arghint += _get_visual_datatype(mi.arguments[i]) + " " + mi.arguments[i].name; - if (i == p_argidx || (mi.flags & METHOD_FLAG_VARARG && i > p_argidx)) { + if (i == p_argidx || ((mi.flags & METHOD_FLAG_VARARG) && i > p_argidx)) { arghint += String::chr(0xFFFF); } } diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index f0cfdd6258..34d01c6beb 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -1177,20 +1177,28 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, VALIDATE_ARG_COUNT(1); switch (p_args[0]->get_type()) { + case Variant::STRING: { + + String d = *p_args[0]; + r_ret = d.length(); + } break; case Variant::DICTIONARY: { + Dictionary d = *p_args[0]; r_ret = d.size(); } break; case Variant::ARRAY: { + Array d = *p_args[0]; r_ret = d.size(); } break; case Variant::POOL_BYTE_ARRAY: { + PoolVector<uint8_t> d = *p_args[0]; r_ret = d.size(); - } break; case Variant::POOL_INT_ARRAY: { + PoolVector<int> d = *p_args[0]; r_ret = d.size(); } break; @@ -1200,14 +1208,14 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, r_ret = d.size(); } break; case Variant::POOL_STRING_ARRAY: { + PoolVector<String> d = *p_args[0]; r_ret = d.size(); - } break; case Variant::POOL_VECTOR2_ARRAY: { + PoolVector<Vector2> d = *p_args[0]; r_ret = d.size(); - } break; case Variant::POOL_VECTOR3_ARRAY: { @@ -1412,12 +1420,12 @@ MethodInfo GDFunctions::get_info(Function p_func) { } break; case MATH_ISNAN: { MethodInfo mi("is_nan", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + mi.return_val.type = Variant::BOOL; return mi; } break; case MATH_ISINF: { MethodInfo mi("is_inf", PropertyInfo(Variant::REAL, "s")); - mi.return_val.type = Variant::REAL; + mi.return_val.type = Variant::BOOL; return mi; } break; case MATH_EASE: { 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/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 9989785c70..90ee164b6f 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -74,15 +74,11 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, uint32_t mipmaps = f->get_32(); uint32_t flags = f->get_32(); uint32_t surfsize = f->get_32(); - uint32_t bpp = f->get_32(); - uint32_t rmask = f->get_32(); - uint32_t gmask = f->get_32(); - uint32_t bmask = f->get_32(); - uint32_t amask = f->get_32(); + f->seek(f->get_pos() + 20); // bpp, rmask, gmask, bmask, amask uint8_t pvrid[5] = { 0, 0, 0, 0, 0 }; f->get_buffer(pvrid, 4); ERR_FAIL_COND_V(String((char *)pvrid) != "PVR!", RES()); - uint32_t surfcount = f->get_32(); + f->get_32(); // surfcount /* print_line("height: "+itos(height)); 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 f5c379d32e..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/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 2a24f8d4d1..02b994f8db 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -414,7 +414,8 @@ void VideoStreamPlaybackTheora::update(float p_delta) { bool buffer_full = false; /* if there's pending, decoded audio, grab it */ - if ((ret = vorbis_synthesis_pcmout(&vd, &pcm)) > 0) { + ret = vorbis_synthesis_pcmout(&vd, &pcm); + if (ret > 0) { const int AUXBUF_LEN = 4096; int to_read = ret; diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 37bd730d08..671a507377 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -491,9 +491,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->set_overlay(GraphNode::OVERLAY_BREAKPOINT); } - if (EditorSettings::get_singleton()->has("editors/visual_script/color_" + node->get_category())) { - Color c = EditorSettings::get_singleton()->get("editors/visual_script/color_" + node->get_category()); - gnode->set_self_modulate(c); + if (node_styles.has(node->get_category())) { + gnode->add_style_override("frame", node_styles[node->get_category()]); } gnode->set_meta("__vnode", node); @@ -506,7 +505,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->set_show_close_button(true); } - if (Object::cast_to<VisualScriptExpression>(*node)) { + if (Object::cast_to<VisualScriptExpression>(node.ptr())) { LineEdit *line_edit = memnew(LineEdit); line_edit->set_text(node->get_text()); @@ -520,7 +519,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->add_child(text); } - if (Object::cast_to<VisualScriptExpression>(*node)) { + if (Object::cast_to<VisualScriptComment>(node.ptr())) { Ref<VisualScriptComment> vsc = node; gnode->set_comment(true); gnode->set_resizable(true); @@ -926,48 +925,6 @@ void VisualScriptEditor::_member_edited() { } } -void VisualScriptEditor::_override_pressed(int p_id) { - - //override a virtual function or method from base type - - ERR_FAIL_COND(!virtuals_in_menu.has(p_id)); - - VirtualInMenu vim = virtuals_in_menu[p_id]; - - String name = _validate_name(vim.name); - selected = name; - edited_func = selected; - Ref<VisualScriptFunction> func_node; - func_node.instance(); - func_node->set_name(vim.name); - - undo_redo->create_action(TTR("Add Function")); - undo_redo->add_do_method(script.ptr(), "add_function", name); - for (int i = 0; i < vim.args.size(); i++) { - func_node->add_argument(vim.args[i].first, vim.args[i].second); - } - - undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id(), func_node); - if (vim.ret != Variant::NIL || vim.ret_variant) { - Ref<VisualScriptReturn> ret_node; - ret_node.instance(); - ret_node->set_return_type(vim.ret); - ret_node->set_enable_return_value(true); - ret_node->set_name(vim.name); - undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id() + 1, ret_node, Vector2(500, 0)); - } - - undo_redo->add_undo_method(script.ptr(), "remove_function", name); - undo_redo->add_do_method(this, "_update_members"); - undo_redo->add_undo_method(this, "_update_members"); - undo_redo->add_do_method(this, "_update_graph"); - undo_redo->add_undo_method(this, "_update_graph"); - - undo_redo->commit_action(); - - _update_graph(); -} - void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) { TreeItem *ti = Object::cast_to<TreeItem>(p_item); @@ -980,64 +937,9 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt //add function, this one uses menu if (p_button == 1) { - new_function_menu->clear(); - new_function_menu->set_size(Size2(0, 0)); - int idx = 0; - - virtuals_in_menu.clear(); - - List<MethodInfo> mi; - ClassDB::get_method_list(script->get_instance_base_type(), &mi); - for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) { - MethodInfo mi = E->get(); - if (mi.flags & METHOD_FLAG_VIRTUAL) { - - VirtualInMenu vim; - vim.name = mi.name; - vim.ret = mi.return_val.type; - if (mi.return_val.name != String()) - vim.ret_variant = true; - else - vim.ret_variant = false; - - String desc; - - if (mi.return_val.type == Variant::NIL) - desc = "var"; - else - desc = Variant::get_type_name(mi.return_val.type); - desc += " " + mi.name + " ( "; - - for (int i = 0; i < mi.arguments.size(); i++) { - - if (i > 0) - desc += ", "; - - if (mi.arguments[i].type == Variant::NIL) - desc += "var "; - else - desc += Variant::get_type_name(mi.arguments[i].type) + " "; - - desc += mi.arguments[i].name; - - Pair<Variant::Type, String> p; - p.first = mi.arguments[i].type; - p.second = mi.arguments[i].name; - vim.args.push_back(p); - } - desc += " )"; + new_virtual_method_select->select_method_from_base_type(script->get_instance_base_type(), String(), true); - virtuals_in_menu[idx] = vim; - - new_function_menu->add_item(desc, idx); - idx++; - } - } - - Rect2 pos = members->get_item_rect(ti); - new_function_menu->set_position(members->get_global_position() + pos.position + Vector2(0, pos.size.y)); - new_function_menu->popup(); return; } else if (p_button == 0) { @@ -1495,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"]; - - Vector2 ofs = graph->get_scroll_ofs() + p_point; + Array nodes = d["nodes"]; - if (graph->is_using_snap()) { - int snap = graph->get_snap(); - ofs = ofs.snapped(Vector2(snap, snap)); - } - ofs /= EDSCALE; + Vector2 ofs = graph->get_scroll_ofs() + p_point; - undo_redo->create_action(TTR("Add Node(s) From Tree")); - int base_id = script->get_available_id(); + if (graph->is_using_snap()) { + int snap = graph->get_snap(); + ofs = ofs.snapped(Vector2(snap, snap)); + } + ofs /= EDSCALE; - if (nodes.size() > 1) { - use_node = true; - } + undo_redo->create_action(TTR("Add Node(s) From Tree")); + int base_id = script->get_available_id(); - for (int i = 0; i < nodes.size(); i++) { + if (nodes.size() > 1) { + use_node = true; + } - NodePath np = nodes[i]; - Node *node = get_node(np); - if (!node) { - continue; - } + for (int i = 0; i < nodes.size(); i++) { - 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(); } } } @@ -2686,21 +2597,21 @@ void VisualScriptEditor::_selected_connect_node_method_or_setget(const String &p Ref<VisualScriptNode> vsn = script->get_node(edited_func, port_action_new_node); - if (Object::cast_to<VisualScriptFunctionCall>(*vsn)) { + if (Object::cast_to<VisualScriptFunctionCall>(vsn.ptr())) { Ref<VisualScriptFunctionCall> vsfc = vsn; vsfc->set_function(p_text); script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0); } - if (Object::cast_to<VisualScriptPropertySet>(*vsn)) { + if (Object::cast_to<VisualScriptPropertySet>(vsn.ptr())) { Ref<VisualScriptPropertySet> vsp = vsn; vsp->set_property(p_text); script->data_connect(edited_func, port_action_node, port_action_output, port_action_new_node, 0); } - if (Object::cast_to<VisualScriptPropertyGet>(*vsn)) { + if (Object::cast_to<VisualScriptPropertyGet>(vsn.ptr())) { Ref<VisualScriptPropertyGet> vsp = vsn; vsp->set_property(p_text); @@ -2711,6 +2622,63 @@ void VisualScriptEditor::_selected_connect_node_method_or_setget(const String &p _update_graph_connections(); } +void VisualScriptEditor::_selected_new_virtual_method(const String &p_text) { + + String name = p_text; + if (script->has_function(name)) { + EditorNode::get_singleton()->show_warning(vformat(TTR("Script already has function '%s'"), name)); + return; + } + + MethodInfo minfo; + { + List<MethodInfo> methods; + bool found = false; + ClassDB::get_virtual_methods(script->get_instance_base_type(), &methods); + for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { + if (E->get().name == name) { + minfo = E->get(); + found = true; + } + } + + ERR_FAIL_COND(!found); + } + + selected = name; + edited_func = selected; + Ref<VisualScriptFunction> func_node; + func_node.instance(); + func_node->set_name(name); + + undo_redo->create_action(TTR("Add Function")); + undo_redo->add_do_method(script.ptr(), "add_function", name); + + for (int i = 0; i < minfo.arguments.size(); i++) { + func_node->add_argument(minfo.arguments[i].type, minfo.arguments[i].name); + } + + undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id(), func_node); + if (minfo.return_val.type != Variant::NIL || minfo.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT) { + Ref<VisualScriptReturn> ret_node; + ret_node.instance(); + ret_node->set_return_type(minfo.return_val.type); + ret_node->set_enable_return_value(true); + ret_node->set_name(name); + undo_redo->add_do_method(script.ptr(), "add_node", name, script->get_available_id() + 1, ret_node, Vector2(500, 0)); + } + + undo_redo->add_undo_method(script.ptr(), "remove_function", name); + undo_redo->add_do_method(this, "_update_members"); + undo_redo->add_undo_method(this, "_update_members"); + undo_redo->add_do_method(this, "_update_graph"); + undo_redo->add_undo_method(this, "_update_graph"); + + undo_redo->commit_action(); + + _update_graph(); +} + void VisualScriptEditor::_cancel_connect_node_method_or_setget() { script->remove_node(edited_func, port_action_new_node); @@ -2783,6 +2751,27 @@ void VisualScriptEditor::_notification(int p_what) { node_filter->add_icon_override("right_icon", Control::get_icon("Search", "EditorIcons")); variable_editor->connect("changed", this, "_update_members"); signal_editor->connect("changed", this, "_update_members"); + + List<Pair<String, Color> > colors; + colors.push_back(Pair<String, Color>("functions", Color(1, 0.9, 0.9))); + colors.push_back(Pair<String, Color>("data", Color(0.9, 1.0, 0.9))); + colors.push_back(Pair<String, Color>("operators", Color(0.9, 0.9, 1.0))); + colors.push_back(Pair<String, Color>("flow_control", Color(1.0, 1.0, 1.0))); + colors.push_back(Pair<String, Color>("custom", Color(0.8, 1.0, 1.0))); + colors.push_back(Pair<String, Color>("constants", Color(1.0, 0.8, 1.0))); + + for (List<Pair<String, Color> >::Element *E = colors.front(); E; E = E->next()) { + print_line(E->get().first); + Ref<StyleBoxFlat> sb = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("frame", "GraphNode"); + if (sb != NULL) { + Ref<StyleBoxFlat> frame_style = sb->duplicate(); + Color c = sb->get_border_color(MARGIN_TOP); + Color cn = E->get().second; + cn.a = c.a; + frame_style->set_border_color_all(cn); + node_styles[E->get().first] = frame_style; + } + } } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { left_vsplit->set_visible(is_visible_in_tree()); @@ -3014,7 +3003,7 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { TreeItem *root = members->get_root(); - Ref<Texture> del_icon = Control::get_icon("Del", "EditorIcons"); + Ref<Texture> del_icon = Control::get_icon("Remove", "EditorIcons"); Ref<Texture> edit_icon = Control::get_icon("Edit", "EditorIcons"); @@ -3147,7 +3136,6 @@ void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members); ClassDB::bind_method("_change_base_type", &VisualScriptEditor::_change_base_type); ClassDB::bind_method("_change_base_type_callback", &VisualScriptEditor::_change_base_type_callback); - ClassDB::bind_method("_override_pressed", &VisualScriptEditor::_override_pressed); ClassDB::bind_method("_node_selected", &VisualScriptEditor::_node_selected); ClassDB::bind_method("_node_moved", &VisualScriptEditor::_node_moved); ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node); @@ -3166,6 +3154,8 @@ void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_button_resource_previewed", &VisualScriptEditor::_button_resource_previewed); ClassDB::bind_method("_port_action_menu", &VisualScriptEditor::_port_action_menu); ClassDB::bind_method("_selected_connect_node_method_or_setget", &VisualScriptEditor::_selected_connect_node_method_or_setget); + ClassDB::bind_method("_selected_new_virtual_method", &VisualScriptEditor::_selected_new_virtual_method); + ClassDB::bind_method("_cancel_connect_node_method_or_setget", &VisualScriptEditor::_cancel_connect_node_method_or_setget); ClassDB::bind_method("_expression_text_changed", &VisualScriptEditor::_expression_text_changed); @@ -3344,9 +3334,6 @@ VisualScriptEditor::VisualScriptEditor() { undo_redo = EditorNode::get_singleton()->get_undo_redo(); - new_function_menu = memnew(PopupMenu); - new_function_menu->connect("id_pressed", this, "_override_pressed"); - add_child(new_function_menu); updating_members = false; set_process_input(true); //for revert on drag @@ -3366,6 +3353,11 @@ VisualScriptEditor::VisualScriptEditor() { new_connect_node_select->connect("selected", this, "_selected_connect_node_method_or_setget"); new_connect_node_select->get_cancel()->connect("pressed", this, "_cancel_connect_node_method_or_setget"); + new_virtual_method_select = memnew(PropertySelector); + add_child(new_virtual_method_select); + new_virtual_method_select->connect("selected", this, "_selected_new_virtual_method"); + new_virtual_method_select->get_cancel()->connect("pressed", this, "_selected_new_virtual_method"); + port_action_popup = memnew(PopupMenu); add_child(port_action_popup); port_action_popup->connect("id_pressed", this, "_port_action_menu"); @@ -3403,12 +3395,6 @@ void VisualScriptEditor::free_clipboard() { static void register_editor_callback() { ScriptEditor::register_create_script_editor_function(create_editor); - EditorSettings::get_singleton()->set("editors/visual_script/color_functions", Color(1, 0.9, 0.9)); - EditorSettings::get_singleton()->set("editors/visual_script/color_data", Color(0.9, 1.0, 0.9)); - EditorSettings::get_singleton()->set("editors/visual_script/color_operators", Color(0.9, 0.9, 1.0)); - EditorSettings::get_singleton()->set("editors/visual_script/color_flow_control", Color(1.0, 1.0, 1.0)); - EditorSettings::get_singleton()->set("editors/visual_script/color_custom", Color(0.8, 1.0, 1.0)); - EditorSettings::get_singleton()->set("editors/visual_script/color_constants", Color(1.0, 0.8, 1.0)); ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected")); ED_SHORTCUT("visual_script_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index dd051ef8e4..db54d10300 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -103,6 +103,7 @@ class VisualScriptEditor : public ScriptEditorBase { PropertySelector *method_select; PropertySelector *new_connect_node_select; + PropertySelector *new_virtual_method_select; VisualScriptEditorVariableEdit *variable_editor; @@ -135,10 +136,7 @@ class VisualScriptEditor : public ScriptEditorBase { Vector<Pair<Variant::Type, String> > args; }; - Map<int, VirtualInMenu> virtuals_in_menu; - - PopupMenu *new_function_menu; - + HashMap<StringName, Ref<StyleBox>, StringNameHasher> node_styles; StringName edited_func; void _update_graph_connections(); @@ -177,6 +175,7 @@ class VisualScriptEditor : public ScriptEditorBase { void _port_action_menu(int p_option); void _selected_connect_node_method_or_setget(const String &p_text); void _cancel_connect_node_method_or_setget(); + void _selected_new_virtual_method(const String &p_text); int error_line; @@ -188,7 +187,6 @@ class VisualScriptEditor : public ScriptEditorBase { void _change_base_type(); void _member_selected(); void _member_edited(); - void _override_pressed(int p_id); void _begin_node_move(); void _end_node_move(); diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index d0e9b5bb86..eae866d167 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -831,7 +831,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { case TK_BUILTIN_FUNC: { //builtin function - Variant::Type bt = Variant::Type(int(tk.value)); _get_token(tk); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '('"); diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 1decc004ab..093f01c49f 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -1493,7 +1493,7 @@ void VisualScriptGlobalConstant::_bind_methods() { cc += ","; cc += GlobalConstants::get_global_constant_name(i); } - ADD_PROPERTY(PropertyInfo(Variant::INT, "constant/constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant"); } VisualScriptGlobalConstant::VisualScriptGlobalConstant() { @@ -1622,7 +1622,7 @@ void VisualScriptClassConstant::_bind_methods() { ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptClassConstant::get_base_type); ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant/constant", PROPERTY_HINT_ENUM, ""), "set_class_constant", "get_class_constant"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, ""), "set_class_constant", "get_class_constant"); } VisualScriptClassConstant::VisualScriptClassConstant() { @@ -1760,7 +1760,7 @@ void VisualScriptBasicTypeConstant::_bind_methods() { } ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, argt), "set_basic_type", "get_basic_type"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant/constant", PROPERTY_HINT_ENUM, ""), "set_basic_type_constant", "get_basic_type_constant"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, ""), "set_basic_type_constant", "get_basic_type_constant"); } VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() { @@ -1881,7 +1881,7 @@ void VisualScriptMathConstant::_bind_methods() { cc += ","; cc += const_name[i]; } - ADD_PROPERTY(PropertyInfo(Variant::INT, "constant/constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); } VisualScriptMathConstant::VisualScriptMathConstant() { @@ -2002,7 +2002,7 @@ void VisualScriptEngineSingleton::_bind_methods() { cc += E->get().name; } - ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant/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() { @@ -3727,11 +3727,11 @@ void register_visual_script_nodes() { VisualScriptLanguage::singleton->add_register_func("data/preload", create_node_generic<VisualScriptPreload>); VisualScriptLanguage::singleton->add_register_func("data/action", create_node_generic<VisualScriptInputAction>); - VisualScriptLanguage::singleton->add_register_func("constant/constants/constant", create_node_generic<VisualScriptConstant>); - VisualScriptLanguage::singleton->add_register_func("constant/constants/math_constant", create_node_generic<VisualScriptMathConstant>); - VisualScriptLanguage::singleton->add_register_func("constant/constants/class_constant", create_node_generic<VisualScriptClassConstant>); - VisualScriptLanguage::singleton->add_register_func("constant/constants/global_constant", create_node_generic<VisualScriptGlobalConstant>); - VisualScriptLanguage::singleton->add_register_func("constant/constants/basic_type_constant", create_node_generic<VisualScriptBasicTypeConstant>); + VisualScriptLanguage::singleton->add_register_func("constants/constant", create_node_generic<VisualScriptConstant>); + VisualScriptLanguage::singleton->add_register_func("constants/math_constant", create_node_generic<VisualScriptMathConstant>); + VisualScriptLanguage::singleton->add_register_func("constants/class_constant", create_node_generic<VisualScriptClassConstant>); + VisualScriptLanguage::singleton->add_register_func("constants/global_constant", create_node_generic<VisualScriptGlobalConstant>); + VisualScriptLanguage::singleton->add_register_func("constants/basic_type_constant", create_node_generic<VisualScriptBasicTypeConstant>); VisualScriptLanguage::singleton->add_register_func("custom/custom_node", create_node_generic<VisualScriptCustomNode>); VisualScriptLanguage::singleton->add_register_func("custom/sub_call", create_node_generic<VisualScriptSubCall>); |