diff options
Diffstat (limited to 'modules')
21 files changed, 463 insertions, 1011 deletions
diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py index 9f57b9bb74..4f89ca0d4c 100644 --- a/modules/gdnative/config.py +++ b/modules/gdnative/config.py @@ -1,7 +1,7 @@ def can_build(platform): - return True + return False def configure(env): diff --git a/modules/gdnative/godot/rid.cpp b/modules/gdnative/godot/rid.cpp index eb9538e692..09ce3a5979 100644 --- a/modules/gdnative/godot/rid.cpp +++ b/modules/gdnative/godot/rid.cpp @@ -50,7 +50,7 @@ godot_int GDAPI godot_rid_get_id(const godot_rid *p_self) { } void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from) { - const Resource *res_from = ((const Object *)p_from)->cast_to<Resource>(); + const Resource *res_from = Object::cast_to<Resource>((Object *)p_from); godot_rid_new(r_dest); if (res_from) { RID *dest = (RID *)r_dest; diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index c243f88b7a..2aa24e88a9 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1971,7 +1971,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa p_script->placeholders.erase(psi); //remove placeholder GDInstance *instance = memnew(GDInstance); - instance->base_ref = E->get()->cast_to<Reference>(); + instance->base_ref = Object::cast_to<Reference>(E->get()); instance->members.resize(p_script->member_indices.size()); instance->script = Ref<GDScript>(p_script); instance->owner = E->get(); diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 3fa0a38024..905c784ab9 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -30,6 +30,7 @@ #include "editor/editor_settings.h" #include "gd_compiler.h" #include "gd_script.h" +#include "global_constants.h" #include "os/file_access.h" #include "project_settings.h" #ifdef TOOLS_ENABLED @@ -355,6 +356,7 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na struct GDCompletionIdentifier { + String enumeration; StringName obj_type; Ref<GDScript> script; Variant::Type type; @@ -370,8 +372,8 @@ static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant) { Object *obj = p_variant; if (obj) { /* - if (obj->cast_to<GDNativeClass>()) { - t.obj_type=obj->cast_to<GDNativeClass>()->get_name(); + if (Object::cast_to<GDNativeClass>(obj)) { + t.obj_type=Object::cast_to<GDNativeClass>(obj)->get_name(); t.value=Variant(); } else { */ @@ -595,8 +597,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: if (id.operator String() == "new" && base.value.get_type() == Variant::OBJECT) { Object *obj = base.value; - if (obj && obj->cast_to<GDNativeClass>()) { - GDNativeClass *gdnc = obj->cast_to<GDNativeClass>(); + if (GDNativeClass *gdnc = Object::cast_to<GDNativeClass>(obj)) { r_type.type = Variant::OBJECT; r_type.value = Variant(); r_type.obj_type = gdnc->get_name(); @@ -608,7 +609,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: #ifdef TOOLS_ENABLED MethodBind *mb = ClassDB::get_method(base.obj_type, id); - PropertyInfo pi = mb->get_argument_info(-1); + PropertyInfo pi = mb->get_return_info(); //try calling the function if constant and all args are constant, should not crash.. Object *baseptr = base.value; @@ -809,6 +810,32 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: if (p1.value.get_type() == Variant::OBJECT) { //?? + if (p1.obj_type != StringName() && p2.type == Variant::STRING) { + StringName index = p2.value; + bool valid; + Variant::Type t = ClassDB::get_property_type(p1.obj_type, index, &valid); + if (t != Variant::NIL && valid) { + r_type.type = t; + if (t == Variant::INT) { +//check for enum! +#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) + + StringName getter = ClassDB::get_property_getter(p1.obj_type, index); + if (getter != StringName()) { + MethodBind *mb = ClassDB::get_method(p1.obj_type, getter); + if (mb) { + PropertyInfo rt = mb->get_return_info(); + if (rt.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { + r_type.enumeration = rt.class_name; + } + } + } +#endif + } + + return true; + } + } } else if (p1.value.get_type() != Variant::NIL) { bool valid; @@ -902,12 +929,42 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type) { + if (context.block->if_condition && context.block->if_condition->type == GDParser::Node::TYPE_OPERATOR && static_cast<const GDParser::OperatorNode *>(context.block->if_condition)->op == GDParser::OperatorNode::OP_IS) { + //is used, check if identifier is in there! this helps resolve in blocks that are (if (identifier is value)): which are very common.. + //super dirty hack, but very useful + //credit: Zylann + //TODO: this could be hacked to detect ANDed conditions too.. + const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(context.block->if_condition); + if (op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER && static_cast<const GDParser::IdentifierNode *>(op->arguments[0])->name == p_identifier) { + //bingo + if (_guess_expression_type(context, op->arguments[1], op->line, r_type)) { + return true; + } + } + } + GDCompletionIdentifier gdi = _get_native_class(context); if (gdi.obj_type != StringName()) { bool valid; Variant::Type t = ClassDB::get_property_type(gdi.obj_type, p_identifier, &valid); if (t != Variant::NIL && valid) { r_type.type = t; + if (t == Variant::INT) { +//check for enum! +#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) + + StringName getter = ClassDB::get_property_getter(gdi.obj_type, p_identifier); + if (getter != StringName()) { + MethodBind *mb = ClassDB::get_method(gdi.obj_type, getter); + if (mb) { + PropertyInfo rt = mb->get_return_info(); + if (rt.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { + r_type.enumeration = rt.class_name; + } + } + } +#endif + } return true; } } @@ -1041,11 +1098,11 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con PropertyInfo arg = E->get().arguments[argindex]; - int scp = arg.name.find(":"); + int scp = String(arg.name).find(":"); if (scp != -1) { r_type.type = Variant::OBJECT; - r_type.obj_type = arg.name.substr(scp + 1, arg.name.length()); + r_type.obj_type = String(arg.name).substr(scp + 1, String(arg.name).length()); return true; } else { @@ -1271,7 +1328,7 @@ static void _find_identifiers_in_class(GDCompletionContext &context, bool p_stat for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY)) continue; - if (E->get().name.find("/") != -1) + if (String(E->get().name).find("/") != -1) continue; result.insert(E->get().name); } @@ -1436,7 +1493,7 @@ void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_lis } } -static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) { +static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, bool &r_forced, String &arghint) { //print_line("find type arguments?"); if (id.type == Variant::OBJECT && id.obj_type != StringName()) { @@ -1451,46 +1508,45 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (id.value.get_type()) { Object *obj = id.value; - if (obj) { - - GDScript *scr = obj->cast_to<GDScript>(); - if (scr) { - while (scr) { + GDScript *scr = Object::cast_to<GDScript>(obj); + if (scr) { + while (scr) { - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { - if (E->get()->is_static() && p_method == E->get()->get_name()) { - arghint = "static func " + String(p_method) + "("; - for (int i = 0; i < E->get()->get_argument_count(); i++) { - if (i > 0) - arghint += ", "; - else - arghint += " "; - if (i == p_argidx) { - arghint += String::chr(0xFFFF); - } - arghint += "var " + E->get()->get_argument_name(i); - int deffrom = E->get()->get_argument_count() - E->get()->get_default_argument_count(); - if (i >= deffrom) { - int defidx = deffrom - i; - if (defidx >= 0 && defidx < E->get()->get_default_argument_count()) { - arghint += "=" + E->get()->get_default_argument(defidx).get_construct_string(); - } - } - if (i == p_argidx) { - arghint += String::chr(0xFFFF); + for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + if (E->get()->is_static() && p_method == E->get()->get_name()) { + arghint = "static func " + String(p_method) + "("; + for (int i = 0; i < E->get()->get_argument_count(); i++) { + if (i > 0) + arghint += ", "; + else + arghint += " "; + if (i == p_argidx) { + arghint += String::chr(0xFFFF); + } + arghint += "var " + E->get()->get_argument_name(i); + int deffrom = E->get()->get_argument_count() - E->get()->get_default_argument_count(); + if (i >= deffrom) { + int defidx = deffrom - i; + if (defidx >= 0 && defidx < E->get()->get_default_argument_count()) { + arghint += "=" + E->get()->get_default_argument(defidx).get_construct_string(); } } - arghint += ")"; - return; //found + if (i == p_argidx) { + arghint += String::chr(0xFFFF); + } } + arghint += ")"; + return; //found } - - if (scr->get_base().is_valid()) - scr = scr->get_base().ptr(); - else - scr = NULL; } - } else { + + if (scr->get_base().is_valid()) + scr = scr->get_base().ptr(); + else + scr = NULL; + } + } else { + if (obj) { on_script = obj->get_script(); } } @@ -1642,8 +1698,43 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N } } else { - //regular method +//regular method +#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) + if (p_argidx < m->get_argument_count()) { + PropertyInfo pi = m->get_argument_info(p_argidx); + + if (pi.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { + String enumeration = pi.class_name; + if (enumeration.find(".") != -1) { + //class constant + List<StringName> constants; + String cls = enumeration.get_slice(".", 0); + String enm = enumeration.get_slice(".", 1); + + ClassDB::get_enum_constants(cls, enm, &constants); + //constants.sort_custom<StringName::AlphCompare>(); + for (List<StringName>::Element *E = constants.front(); E; E = E->next()) { + String add = cls + "." + E->get(); + result.insert(add); + r_forced = true; + } + } else { + + //global constant + StringName current_enum = enumeration; + + for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { + if (GlobalConstants::get_global_constant_enum(i) == current_enum) { + result.insert(GlobalConstants::get_global_constant_name(i)); + r_forced = true; + } + } + //global + } + } + } +#endif if (p_method.operator String() == "connect" || (p_method.operator String() == "emit_signal" && p_argidx == 0)) { if (p_argidx == 0) { @@ -1664,6 +1755,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N for (List<MethodInfo>::Element *E = sigs.front(); E; E = E->next()) { result.insert("\"" + E->get().name + "\""); + r_forced = true; } } else if (p_argidx == 2) { @@ -1671,6 +1763,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (context._class) { for (int i = 0; i < context._class->functions.size(); i++) { result.insert("\"" + context._class->functions[i]->name + "\""); + r_forced = true; } } } @@ -1696,6 +1789,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N //print_line("found "+s); String name = s.get_slice("/", 1); result.insert("\"/root/" + name + "\""); + r_forced = true; } } @@ -1707,11 +1801,12 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N for (List<String>::Element *E = options.front(); E; E = E->next()) { result.insert(E->get()); + r_forced = true; } } } - arghint = _get_visual_datatype(m->get_argument_info(-1), false) + " " + p_method.operator String() + String("("); + arghint = _get_visual_datatype(m->get_return_info(), false) + " " + p_method.operator String() + String("("); for (int i = 0; i < m->get_argument_count(); i++) { if (i > 0) @@ -1750,7 +1845,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N } } -static void _find_call_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, int p_argidx, Set<String> &result, String &arghint) { +static void _find_call_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, int p_argidx, Set<String> &result, bool &r_forced, String &arghint) { if (!p_node || p_node->type != GDParser::Node::TYPE_OPERATOR) { @@ -1905,7 +2000,7 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N if (!context._class->owner) ci.value = context.base; - _find_type_arguments(context, p_node, p_line, id->name, ci, p_argidx, result, arghint); + _find_type_arguments(context, p_node, p_line, id->name, ci, p_argidx, result, r_forced, arghint); //guess type.. /* List<MethodInfo> methods; @@ -1927,7 +2022,7 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N GDCompletionIdentifier ci; if (_guess_expression_type(context, op->arguments[0], p_line, ci)) { - _find_type_arguments(context, p_node, p_line, id->name, ci, p_argidx, result, arghint); + _find_type_arguments(context, p_node, p_line, id->name, ci, p_argidx, result, r_forced, arghint); return; } } @@ -2027,14 +2122,14 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N #endif } -Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint) { +Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint) { GDParser p; p.parse(p_code, p_base_path, false, "", true); bool isfunction = false; Set<String> options; - + r_forced = false; GDCompletionContext context; context._class = p.get_completion_class(); context.block = p.get_completion_block(); @@ -2073,6 +2168,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base String opt = E->get().strip_edges(); if (opt.begins_with("\"") && opt.ends_with("\"")) { + r_forced = true; String idopt = opt.substr(1, opt.length() - 2); if (idopt.replace("/", "_").is_valid_identifier()) { options.insert(idopt); @@ -2111,7 +2207,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY)) continue; - if (E->get().name.find("/") != -1) + if (String(E->get().name).find("/") != -1) continue; options.insert(E->get().name); } @@ -2123,28 +2219,27 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base if (t.value.get_type()) { Object *obj = t.value; - if (obj) { - - GDScript *scr = obj->cast_to<GDScript>(); - if (scr) { - while (scr) { + GDScript *scr = Object::cast_to<GDScript>(obj); + if (scr) { + while (scr) { - if (!isfunction) { - for (const Map<StringName, Variant>::Element *E = scr->get_constants().front(); E; E = E->next()) { - options.insert(E->key()); - } + if (!isfunction) { + for (const Map<StringName, Variant>::Element *E = scr->get_constants().front(); E; E = E->next()) { + options.insert(E->key()); } - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { - if (E->get()->is_static()) - options.insert(E->key()); - } - - if (scr->get_base().is_valid()) - scr = scr->get_base().ptr(); - else - scr = NULL; } - } else { + for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + if (E->get()->is_static()) + options.insert(E->key()); + } + + if (scr->get_base().is_valid()) + scr = scr->get_base().ptr(); + else + scr = NULL; + } + } else { + if (obj) { on_script = obj->get_script(); } } @@ -2245,7 +2340,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY)) continue; - if (E->get().name.find("/") != -1) + if (String(E->get().name).find("/") != -1) continue; r_options->push_back(E->get().name); } @@ -2277,7 +2372,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base t.value.get_property_list(&pl); for (List<PropertyInfo>::Element *E = pl.front(); E; E = E->next()) { - if (E->get().name.find("/") == -1) + if (String(E->get().name).find("/") == -1) options.insert(E->get().name); } } @@ -2297,7 +2392,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } break; case GDParser::COMPLETION_CALL_ARGUMENTS: { - _find_call_arguments(context, p.get_completion_node(), p.get_completion_line(), p.get_completion_argument_index(), options, r_call_hint); + _find_call_arguments(context, p.get_completion_node(), p.get_completion_line(), p.get_completion_argument_index(), options, r_forced, r_call_hint); } break; case GDParser::COMPLETION_VIRTUAL_FUNC: { @@ -2344,6 +2439,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base ClassDB::get_signal_list(t.obj_type, &sigs); for (List<MethodInfo>::Element *E = sigs.front(); E; E = E->next()) { options.insert("\"" + E->get().name + "\""); + r_forced = true; } } @@ -2353,6 +2449,42 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base if (EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths")) get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), options); } break; + case GDParser::COMPLETION_ASSIGN: { +#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) + + GDCompletionIdentifier ci; + if (_guess_expression_type(context, p.get_completion_node(), p.get_completion_line(), ci)) { + + String enumeration = ci.enumeration; + if (enumeration.find(".") != -1) { + //class constant + List<StringName> constants; + String cls = enumeration.get_slice(".", 0); + String enm = enumeration.get_slice(".", 1); + + ClassDB::get_enum_constants(cls, enm, &constants); + //constants.sort_custom<StringName::AlphCompare>(); + for (List<StringName>::Element *E = constants.front(); E; E = E->next()) { + String add = cls + "." + E->get(); + r_options->push_back(add); + r_forced = true; + } + } else { + + //global constant + StringName current_enum = enumeration; + + for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { + if (GlobalConstants::get_global_constant_enum(i) == current_enum) { + r_options->push_back(GlobalConstants::get_global_constant_name(i)); + r_forced = true; + } + } + //global + } + } +#endif + } break; } for (Set<String>::Element *E = options.front(); E; E = E->next()) { @@ -2364,7 +2496,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base #else -Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint) { +Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint) { return OK; } @@ -2701,9 +2833,9 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol Object *obj = value; if (obj) { - if (obj->cast_to<GDNativeClass>()) { + if (Object::cast_to<GDNativeClass>(obj)) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; - r_result.class_name = obj->cast_to<GDNativeClass>()->get_name(); + r_result.class_name = Object::cast_to<GDNativeClass>(obj)->get_name(); } else { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 13a7480a36..3b78573f58 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -371,7 +371,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a Object *obj_A = *a; Object *obj_B = *b; - GDScript *scr_B = obj_B->cast_to<GDScript>(); + GDScript *scr_B = Object::cast_to<GDScript>(obj_B); bool extends_ok = false; @@ -397,7 +397,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } else { - GDNativeClass *nc = obj_B->cast_to<GDNativeClass>(); + GDNativeClass *nc = Object::cast_to<GDNativeClass>(obj_B); if (!nc) { @@ -1434,7 +1434,7 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount // If the return value is a GDFunctionState reference, // then the function did yield again after resuming. if (ret.is_ref()) { - GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>(); + GDFunctionState *gdfs = Object::cast_to<GDFunctionState>((Object *)&ret); if (gdfs && gdfs->function == function) completed = false; } @@ -1490,7 +1490,7 @@ Variant GDFunctionState::resume(const Variant &p_arg) { // If the return value is a GDFunctionState reference, // then the function did yield again after resuming. if (ret.is_ref()) { - GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>(); + GDFunctionState *gdfs = Object::cast_to<GDFunctionState>((Object *)&ret); if (gdfs && gdfs->function == function) completed = false; } diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 7d3857266e..48da2135fa 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1044,6 +1044,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool return NULL; \ } \ p_allow_assign = false; + switch (tokenizer->get_token()) { //see operator case GDTokenizer::TK_OP_IN: op = OperatorNode::OP_IN; break; @@ -1065,7 +1066,22 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool //case GDTokenizer::TK_OP_NEG: op=OperatorNode::OP_NEG ; break; case GDTokenizer::TK_OP_SHIFT_LEFT: op = OperatorNode::OP_SHIFT_LEFT; break; case GDTokenizer::TK_OP_SHIFT_RIGHT: op = OperatorNode::OP_SHIFT_RIGHT; break; - case GDTokenizer::TK_OP_ASSIGN: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN; break; + case GDTokenizer::TK_OP_ASSIGN: { + _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN; + + if (tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) { + //code complete assignment + completion_type = COMPLETION_ASSIGN; + completion_node = expr; + completion_class = current_class; + completion_function = current_function; + completion_line = tokenizer->get_token_line(); + completion_block = current_block; + completion_found = true; + tokenizer->advance(); + } + + } break; case GDTokenizer::TK_OP_ASSIGN_ADD: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_ADD; break; case GDTokenizer::TK_OP_ASSIGN_SUB: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SUB; break; case GDTokenizer::TK_OP_ASSIGN_MUL: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_MUL; break; @@ -1894,7 +1910,26 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { return NULL; } - if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { + if (value->type == Node::TYPE_OPERATOR) { + // Maybe it's SomeEnum.VALUE + Node *current_value = value; + + while (current_value->type == Node::TYPE_OPERATOR) { + OperatorNode *op_node = static_cast<OperatorNode *>(current_value); + + if (op_node->op != OperatorNode::OP_INDEX_NAMED) { + _set_error("Invalid operator in pattern. Only index (`A.B`) is allowed"); + return NULL; + } + current_value = op_node->arguments[0]; + } + + if (current_value->type != Node::TYPE_IDENTIFIER) { + _set_error("Only constant expression or variables allowed in a pattern"); + return NULL; + } + + } else if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { _set_error("Only constant expressions or variables allowed in a pattern"); return NULL; } @@ -2435,6 +2470,8 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { cf_if->body = alloc_node<BlockNode>(); cf_if->body->parent_block = p_block; + cf_if->body->if_condition = condition; //helps code completion + p_block->sub_blocks.push_back(cf_if->body); if (!_enter_indent_block(cf_if->body)) { @@ -3922,7 +3959,7 @@ void GDParser::_parse_class(ClassNode *p_class) { member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; if (cn->value.get_type() == Variant::OBJECT) { Object *obj = cn->value; - Resource *res = obj->cast_to<Resource>(); + Resource *res = Object::cast_to<Resource>(obj); if (res == NULL) { _set_error("Exported constant not a type or resource."); return; diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 3ad3466624..177552d279 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -146,10 +146,13 @@ public: Vector<StringName> variables; Vector<int> variable_lines; + Node *if_condition; //tiny hack to improve code completion on if () blocks + //the following is useful for code completion List<BlockNode *> sub_blocks; int end_line; BlockNode() { + if_condition = NULL; type = TYPE_BLOCK; end_line = -1; parent_block = NULL; @@ -441,6 +444,7 @@ public: COMPLETION_INDEX, COMPLETION_VIRTUAL_FUNC, COMPLETION_YIELD, + COMPLETION_ASSIGN, }; private: diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 23201dc1b0..68c1fb3635 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -73,7 +73,7 @@ Variant GDNativeClass::_new() { ERR_FAIL_COND_V(!o, Variant()); } - Reference *ref = o->cast_to<Reference>(); + Reference *ref = Object::cast_to<Reference>(o); if (ref) { return REF(ref); } else { @@ -161,7 +161,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Variant::CallErro owner = memnew(Reference); //by default, no base means use reference } - Reference *r = owner->cast_to<Reference>(); + Reference *r = Object::cast_to<Reference>(owner); if (r) { ref = REF(r); } @@ -397,7 +397,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { } Variant::CallError unchecked_error; - return _create_instance(NULL, 0, p_this, p_this->cast_to<Reference>(), unchecked_error); + return _create_instance(NULL, 0, p_this, Object::cast_to<Reference>(p_this), unchecked_error); } bool GDScript::instance_has(const Object *p_this) const { @@ -575,9 +575,7 @@ void GDScript::update_exports() { //print_line("update exports for "+get_path()+" ic: "+itos(copy.size())); for (Set<ObjectID>::Element *E = copy.front(); E; E = E->next()) { Object *id = ObjectDB::get_instance(E->get()); - if (!id) - continue; - GDScript *s = id->cast_to<GDScript>(); + GDScript *s = Object::cast_to<GDScript>(id); if (!s) continue; s->update_exports(); @@ -616,7 +614,7 @@ Error GDScript::reload(bool p_keep_state) { if (basedir != "") basedir = basedir.get_base_dir(); - if (basedir != "" && basedir.find("res://") == -1 && basedir.find("user://") == -1) { + if (source.find("%BASE%") != -1) { //loading a template, don't parse return OK; } @@ -2006,11 +2004,11 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou void ResourceFormatSaverGDScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (p_resource->cast_to<GDScript>()) { + if (Object::cast_to<GDScript>(*p_resource)) { p_extensions->push_back("gd"); } } bool ResourceFormatSaverGDScript::recognize(const RES &p_resource) const { - return p_resource->cast_to<GDScript>() != NULL; + return Object::cast_to<GDScript>(*p_resource) != NULL; } diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 17e7b0bc03..441f87474e 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -390,7 +390,7 @@ public: virtual int find_function(const String &p_function, const String &p_code) const; virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const; virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return OK; } - virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint); + virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint); #ifdef TOOLS_ENABLED virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result); #endif diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 1205776882..b444664878 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -96,25 +96,6 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { } _recreate_octant_data(); - } else if (name.begins_with("areas/")) { - int which = name.get_slicec('/', 1).to_int(); - String what = name.get_slicec('/', 2); - if (what == "bounds") { - ERR_FAIL_COND_V(area_map.has(which), false); - create_area(which, p_value); - return true; - } - - ERR_FAIL_COND_V(!area_map.has(which), false); - - if (what == "name") - area_set_name(which, p_value); - else if (what == "disable_distance") - area_set_portal_disable_distance(which, p_value); - else if (what == "exterior_portal") - area_set_portal_disable_color(which, p_value); - else - return false; } else return false; @@ -158,19 +139,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { d["cells"] = cells; r_ret = d; - } else if (name.begins_with("areas/")) { - int which = name.get_slicec('/', 1).to_int(); - String what = name.get_slicec('/', 2); - if (what == "bounds") - r_ret = area_get_bounds(which); - else if (what == "name") - r_ret = area_get_name(which); - else if (what == "disable_distance") - r_ret = area_get_portal_disable_distance(which); - else if (what == "exterior_portal") - r_ret = area_is_exterior_portal(which); - else - return false; } else return false; @@ -189,16 +157,6 @@ void GridMap::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::REAL, "cell_scale")); p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); - - for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - - String base = "areas/" + itos(E->key()) + "/"; - p_list->push_back(PropertyInfo(Variant::RECT3, base + "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); - p_list->push_back(PropertyInfo(Variant::STRING, base + "name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); - p_list->push_back(PropertyInfo(Variant::REAL, base + "disable_distance", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); - p_list->push_back(PropertyInfo(Variant::COLOR, base + "disable_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); - p_list->push_back(PropertyInfo(Variant::BOOL, base + "exterior_portal", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); - } } void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) { @@ -268,20 +226,6 @@ bool GridMap::get_center_z() const { return center_z; } -int GridMap::_find_area(const IndexKey &p_pos) const { - - for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - //this should somehow be faster... - const Area &a = *E->get(); - if (p_pos.x >= a.from.x && p_pos.x < a.to.x && - p_pos.y >= a.from.y && p_pos.y < a.to.y && - p_pos.z >= a.from.z && p_pos.z < a.to.z) { - return E->key(); - } - } - - return 0; -} void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { ERR_FAIL_INDEX(ABS(p_x), 1 << 20); @@ -297,7 +241,6 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { ok.x = p_x / octant_size; ok.y = p_y / octant_size; ok.z = p_z / octant_size; - ok.area = _find_area(key); if (cell_map.has(key)) { @@ -485,19 +428,12 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { if (g.collision_debug_instance.is_valid()) { VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world()->get_scenario()); VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform()); - if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(g.collision_debug_instance, area_map[p_key.area]->instance); - } } for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) { VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, get_world()->get_scenario()); VS::get_singleton()->instance_set_transform(E->get().multimesh_instance, get_global_transform()); //print_line("INSTANCEPOS: "+get_global_transform()); - - if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(E->get().multimesh_instance, area_map[p_key.area]->instance); - } } } @@ -655,7 +591,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { if (g.collision_debug_instance.is_valid()) { - VS::get_singleton()->instance_set_room(g.collision_debug_instance, RID()); VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID()); } @@ -663,7 +598,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, RID()); //VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); - VS::get_singleton()->instance_set_room(E->get().multimesh_instance, RID()); } } @@ -673,8 +607,6 @@ void GridMap::_notification(int p_what) { case NOTIFICATION_ENTER_WORLD: { - _update_area_instances(); - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { //IndexKey ik; //ik.key = E->key().indexkey; @@ -715,12 +647,12 @@ void GridMap::_notification(int p_what) { Spatial *c = this; while (c) { - navigation = c->cast_to<Navigation>(); + navigation = Object::cast_to<Navigation>(c); if (navigation) { break; } - c = c->get_parent()->cast_to<Spatial>(); + c = Object::cast_to<Spatial>(c->get_parent()); } if (navigation) { @@ -761,14 +693,14 @@ void GridMap::_queue_dirty_map() { void GridMap::_recreate_octant_data() { Map<IndexKey, Cell> cell_copy = cell_map; - _clear_internal(true); + _clear_internal(); for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) { set_cell_item(E->key().x, E->key().y, E->key().z, E->get().item, E->get().rot); } } -void GridMap::_clear_internal(bool p_keep_areas) { +void GridMap::_clear_internal() { for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { if (is_inside_world()) @@ -790,20 +722,6 @@ void GridMap::_clear_internal(bool p_keep_areas) { octant_map.clear(); cell_map.clear(); - - if (p_keep_areas) - return; - - for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - - VS::get_singleton()->free(E->get()->base_portal); - VS::get_singleton()->free(E->get()->instance); - for (int i = 0; i < E->get()->portals.size(); i++) { - VS::get_singleton()->free(E->get()->portals[i].instance); - } - - memdelete(E->get()); - } } void GridMap::clear() { @@ -856,19 +774,6 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_clip", "enabled", "clipabove", "floor", "axis"), &GridMap::set_clip, DEFVAL(true), DEFVAL(0), DEFVAL(Vector3::AXIS_X)); - ClassDB::bind_method(D_METHOD("create_area", "id", "area"), &GridMap::create_area); - ClassDB::bind_method(D_METHOD("area_get_bounds", "area"), &GridMap::area_get_bounds); - ClassDB::bind_method(D_METHOD("area_set_exterior_portal", "area", "enable"), &GridMap::area_set_exterior_portal); - ClassDB::bind_method(D_METHOD("area_set_name", "area", "name"), &GridMap::area_set_name); - ClassDB::bind_method(D_METHOD("area_get_name", "area"), &GridMap::area_get_name); - ClassDB::bind_method(D_METHOD("area_is_exterior_portal", "area"), &GridMap::area_is_exterior_portal); - ClassDB::bind_method(D_METHOD("area_set_portal_disable_distance", "area", "distance"), &GridMap::area_set_portal_disable_distance); - ClassDB::bind_method(D_METHOD("area_get_portal_disable_distance", "area"), &GridMap::area_get_portal_disable_distance); - ClassDB::bind_method(D_METHOD("area_set_portal_disable_color", "area", "color"), &GridMap::area_set_portal_disable_color); - ClassDB::bind_method(D_METHOD("area_get_portal_disable_color", "area"), &GridMap::area_get_portal_disable_color); - ClassDB::bind_method(D_METHOD("erase_area", "area"), &GridMap::erase_area); - ClassDB::bind_method(D_METHOD("get_unused_area_id"), &GridMap::get_unused_area_id); - ClassDB::bind_method(D_METHOD("clear"), &GridMap::clear); ClassDB::bind_method(D_METHOD("get_meshes"), &GridMap::get_meshes); @@ -898,334 +803,6 @@ void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3:: _update_dirty_map_callback(); } -void GridMap::_update_areas() { - - //clear the portals - for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - //this should somehow be faster... - Area &a = *E->get(); - a.portals.clear(); - if (a.instance.is_valid()) { - VisualServer::get_singleton()->free(a.instance); - a.instance = RID(); - } - } - - //test all areas against all areas and create portals - this sucks (slow :( ) - for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - Area &a = *E->get(); - if (a.exterior_portal) //that's pretty much all it does... yes it is - continue; - Vector3 from_a(a.from.x, a.from.y, a.from.z); - Vector3 to_a(a.to.x, a.to.y, a.to.z); - - for (Map<int, Area *>::Element *F = area_map.front(); F; F = F->next()) { - - Area &b = *F->get(); - Vector3 from_b(b.from.x, b.from.y, b.from.z); - Vector3 to_b(b.to.x, b.to.y, b.to.z); - - // initially test intersection and discards - int axis = -1; - float sign = 0; - bool valid = true; - Vector3 axmin, axmax; - - for (int i = 0; i < 3; i++) { - - if (from_a[i] == to_b[i]) { - - if (axis != -1) { - valid = false; - break; - } - - axis = i; - sign = -1; - } else if (from_b[i] == to_a[i]) { - - if (axis != -1) { - valid = false; - break; - } - axis = i; - sign = +1; - } - - if (from_a[i] > to_b[i] || to_a[i] < from_b[i]) { - valid = false; - break; - } else { - - axmin[i] = (from_a[i] > from_b[i]) ? from_a[i] : from_b[i]; - axmax[i] = (to_a[i] < to_b[i]) ? to_a[i] : to_b[i]; - } - } - - if (axis == -1 || !valid) - continue; - - Transform xf; - - for (int i = 0; i < 3; i++) { - - int ax = (axis + i) % 3; - Vector3 axis_vec; - float scale = (i == 0) ? sign : ((axmax[ax] - axmin[ax]) * cell_size); - axis_vec[ax] = scale; - xf.basis.set_axis((2 + i) % 3, axis_vec); - xf.origin[i] = axmin[i] * cell_size; - } - - Area::Portal portal; - portal.xform = xf; - a.portals.push_back(portal); - } - } - - _update_area_instances(); -} - -void GridMap::_update_area_instances() { - - Transform base_xform; - if (_in_tree) - base_xform = get_global_transform(); - - for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - //this should somehow be faster... - Area &a = *E->get(); - if (a.instance.is_valid() != _in_tree) { - - if (!_in_tree) { - - for (int i = 0; i < a.portals.size(); i++) { - - Area::Portal &p = a.portals[i]; - ERR_CONTINUE(!p.instance.is_valid()); - VisualServer::get_singleton()->free(p.instance); - p.instance = RID(); - } - - VisualServer::get_singleton()->free(a.instance); - a.instance = RID(); - - } else { - - //a.instance = VisualServer::get_singleton()->instance_create2(base_room,get_world()->get_scenario()); - for (int i = 0; i < a.portals.size(); i++) { - - Area::Portal &p = a.portals[i]; - ERR_CONTINUE(p.instance.is_valid()); - p.instance = VisualServer::get_singleton()->instance_create2(a.base_portal, get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_room(p.instance, a.instance); - } - } - } - - if (a.instance.is_valid()) { - Transform xform; - - Vector3 from_a(a.from.x, a.from.y, a.from.z); - Vector3 to_a(a.to.x, a.to.y, a.to.z); - - for (int i = 0; i < 3; i++) { - xform.origin[i] = from_a[i] * cell_size; - Vector3 s; - s[i] = (to_a[i] - from_a[i]) * cell_size; - xform.basis.set_axis(i, s); - } - - VisualServer::get_singleton()->instance_set_transform(a.instance, base_xform * xform); - - for (int i = 0; i < a.portals.size(); i++) { - - Area::Portal &p = a.portals[i]; - ERR_CONTINUE(!p.instance.is_valid()); - - VisualServer::get_singleton()->instance_set_transform(p.instance, base_xform * xform); - } - } - } -} - -Error GridMap::create_area(int p_id, const Rect3 &p_area) { - - ERR_FAIL_COND_V(area_map.has(p_id), ERR_ALREADY_EXISTS); - ERR_EXPLAIN("ID 0 is taken as global area, start from 1"); - ERR_FAIL_COND_V(p_id == 0, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(p_area.has_no_area(), ERR_INVALID_PARAMETER); - - // FIRST VALIDATE AREA - IndexKey from, to; - from.x = p_area.position.x; - from.y = p_area.position.y; - from.z = p_area.position.z; - to.x = p_area.position.x + p_area.size.x; - to.y = p_area.position.y + p_area.size.y; - to.z = p_area.position.z + p_area.size.z; - - for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - //this should somehow be faster... - Area &a = *E->get(); - - //does it interset with anything else? - - if (from.x >= a.to.x || - to.x <= a.from.x || - from.y >= a.to.y || - to.y <= a.from.y || - from.z >= a.to.z || - to.z <= a.from.z) { - - // all good - } else { - - return ERR_INVALID_PARAMETER; - } - } - - Area *area = memnew(Area); - area->from = from; - area->to = to; - area->portal_disable_distance = 0; - area->exterior_portal = false; - area->name = "Area " + itos(p_id); - area_map[p_id] = area; - _recreate_octant_data(); - return OK; -} - -Rect3 GridMap::area_get_bounds(int p_area) const { - - ERR_FAIL_COND_V(!area_map.has(p_area), Rect3()); - - const Area *a = area_map[p_area]; - Rect3 aabb; - aabb.position = Vector3(a->from.x, a->from.y, a->from.z); - aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.position; - - return aabb; -} - -void GridMap::area_set_name(int p_area, const String &p_name) { - - ERR_FAIL_COND(!area_map.has(p_area)); - - Area *a = area_map[p_area]; - a->name = p_name; -} - -String GridMap::area_get_name(int p_area) const { - - ERR_FAIL_COND_V(!area_map.has(p_area), ""); - - const Area *a = area_map[p_area]; - return a->name; -} - -void GridMap::area_set_exterior_portal(int p_area, bool p_enable) { - - ERR_FAIL_COND(!area_map.has(p_area)); - - Area *a = area_map[p_area]; - if (a->exterior_portal == p_enable) - return; - a->exterior_portal = p_enable; - - _recreate_octant_data(); -} - -bool GridMap::area_is_exterior_portal(int p_area) const { - - ERR_FAIL_COND_V(!area_map.has(p_area), false); - - const Area *a = area_map[p_area]; - return a->exterior_portal; -} - -void GridMap::area_set_portal_disable_distance(int p_area, float p_distance) { - - ERR_FAIL_COND(!area_map.has(p_area)); - - Area *a = area_map[p_area]; - a->portal_disable_distance = p_distance; -} - -float GridMap::area_get_portal_disable_distance(int p_area) const { - - ERR_FAIL_COND_V(!area_map.has(p_area), 0); - - const Area *a = area_map[p_area]; - return a->portal_disable_distance; -} - -void GridMap::area_set_portal_disable_color(int p_area, Color p_color) { - - ERR_FAIL_COND(!area_map.has(p_area)); - - Area *a = area_map[p_area]; - a->portal_disable_color = p_color; -} - -Color GridMap::area_get_portal_disable_color(int p_area) const { - - ERR_FAIL_COND_V(!area_map.has(p_area), Color()); - - const Area *a = area_map[p_area]; - return a->portal_disable_color; -} - -void GridMap::get_area_list(List<int> *p_areas) const { - - for (const Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { - - p_areas->push_back(E->key()); - } -} - -GridMap::Area::Portal::~Portal() { - - if (instance.is_valid()) - VisualServer::get_singleton()->free(instance); -} - -GridMap::Area::Area() { - - base_portal = VisualServer::get_singleton()->portal_create(); - Vector<Point2> points; - points.push_back(Point2(0, 1)); - points.push_back(Point2(1, 1)); - points.push_back(Point2(1, 0)); - points.push_back(Point2(0, 0)); - VisualServer::get_singleton()->portal_set_shape(base_portal, points); -} - -GridMap::Area::~Area() { - - if (instance.is_valid()) - VisualServer::get_singleton()->free(instance); - VisualServer::get_singleton()->free(base_portal); -} - -void GridMap::erase_area(int p_area) { - - ERR_FAIL_COND(!area_map.has(p_area)); - - Area *a = area_map[p_area]; - memdelete(a); - area_map.erase(p_area); - _recreate_octant_data(); -} - -int GridMap::get_unused_area_id() const { - - if (area_map.empty()) - return 1; - else - return area_map.back()->key() + 1; -} - void GridMap::set_cell_scale(float p_scale) { cell_scale = p_scale; diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 106bf82dc2..7af1e08eb2 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -120,7 +120,7 @@ class GridMap : public Spatial { int16_t x; int16_t y; int16_t z; - int16_t area; + int16_t empty; }; uint64_t key; @@ -148,35 +148,10 @@ class GridMap : public Spatial { int clip_floor; Vector3::Axis clip_axis; - /** - * @brief An Area is something like a room: it has doors, and Octants can choose to belong to it. - */ - struct Area { - - String name; - RID base_portal; - RID instance; - IndexKey from; - IndexKey to; - struct Portal { - Transform xform; - RID instance; - ~Portal(); - }; - Vector<Portal> portals; - float portal_disable_distance; - Color portal_disable_color; - bool exterior_portal; - - Area(); - ~Area(); - }; - Ref<MeshLibrary> theme; Map<OctantKey, Octant *> octant_map; Map<IndexKey, Cell> cell_map; - Map<int, Area *> area_map; void _recreate_octant_data(); @@ -188,8 +163,6 @@ class GridMap : public Spatial { float param[VS::LIGHT_PARAM_MAX]; }; - _FORCE_INLINE_ int _find_area(const IndexKey &p_pos) const; - _FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const { return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size; @@ -208,10 +181,7 @@ class GridMap : public Spatial { void resource_changed(const RES &p_res); - void _update_areas(); - void _update_area_instances(); - - void _clear_internal(bool p_keep_areas = false); + void _clear_internal(); protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -248,20 +218,6 @@ public: void set_clip(bool p_enabled, bool p_clip_above = true, int p_floor = 0, Vector3::Axis p_axis = Vector3::AXIS_X); - Error create_area(int p_id, const Rect3 &p_area); - Rect3 area_get_bounds(int p_area) const; - void area_set_exterior_portal(int p_area, bool p_enable); - void area_set_name(int p_area, const String &p_name); - String area_get_name(int p_area) const; - bool area_is_exterior_portal(int p_area) const; - void area_set_portal_disable_distance(int p_area, float p_distance); - float area_get_portal_disable_distance(int p_area) const; - void area_set_portal_disable_color(int p_area, Color p_color); - Color area_get_portal_disable_color(int p_area) const; - void get_area_list(List<int> *p_areas) const; - void erase_area(int p_area); - int get_unused_area_id() const; - void set_cell_scale(float p_scale); float get_cell_scale() const; diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 7bb80c2510..3bab1bfbc1 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -178,30 +178,6 @@ void GridMapEditor::_menu_option(int p_option) { int idx = options->get_popup()->get_item_index(MENU_OPTION_DUPLICATE_SELECTS); options->get_popup()->set_item_checked(idx, !options->get_popup()->is_item_checked(idx)); } break; - case MENU_OPTION_SELECTION_MAKE_AREA: - case MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR: { - - if (!selection.active) - break; - int area = node->get_unused_area_id(); - Error err = node->create_area(area, Rect3(selection.begin, selection.end - selection.begin + Vector3(1, 1, 1))); - if (err != OK) { - } - if (p_option == MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR) { - - node->area_set_exterior_portal(area, true); - } - _update_areas_display(); - update_areas(); - - } break; - case MENU_OPTION_REMOVE_AREA: { - if (selected_area < 1) - return; - node->erase_area(selected_area); - _update_areas_display(); - update_areas(); - } break; case MENU_OPTION_SELECTION_DUPLICATE: if (!(selection.active && input_action == INPUT_NONE)) return; @@ -403,7 +379,7 @@ void GridMapEditor::_delete_selection() { if (!selection.active) return; - undo_redo->create_action("GridMap Delete Selection"); + undo_redo->create_action(TTR("GridMap Delete Selection")); for (int i = selection.begin.x; i <= selection.end.x; i++) { for (int j = selection.begin.y; j <= selection.end.y; j++) { @@ -487,7 +463,7 @@ void GridMapEditor::_duplicate_paste() { Vector3 ofs = selection.current - selection.click; if (items.size()) { - undo_redo->create_action("GridMap Duplicate Selection"); + undo_redo->create_action(TTR("GridMap Duplicate Selection")); for (List<__Item>::Element *E = items.front(); E; E = E->next()) { __Item &it = E->get(); Vector3 pos = it.pos + ofs; @@ -513,146 +489,96 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu return false; } - if (edit_mode->get_selected() == 0) { // regular click - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid()) { - - if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { - if (mb->is_pressed()) - floor->set_value(floor->get_value() + mb->get_factor()); - - return true; //eaten - } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { - if (mb->is_pressed()) - floor->set_value(floor->get_value() - mb->get_factor()); - return true; - } - - if (mb->is_pressed()) { - - if (mb->get_button_index() == BUTTON_LEFT) { + Ref<InputEventMouseButton> mb = p_event; - if (input_action == INPUT_DUPLICATE) { - - //paste - _duplicate_paste(); - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else if (mb->get_shift()) { - input_action = INPUT_SELECT; - } else if (mb->get_command()) - input_action = INPUT_COPY; - else { - input_action = INPUT_PAINT; - set_items.clear(); - } - } else if (mb->get_button_index() == BUTTON_RIGHT) - if (input_action == INPUT_DUPLICATE) { - - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else { - input_action = INPUT_ERASE; - set_items.clear(); - } - else - return false; + if (mb.is_valid()) { - return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); - } else { + if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() + mb->get_factor()); - if ( - (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || - (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) { + return true; //eaten + } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() - mb->get_factor()); + return true; + } - if (set_items.size()) { - undo_redo->create_action("GridMap Paint"); - for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { + if (mb->is_pressed()) { - const SetItem &si = E->get(); - undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); - } - for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { + if (mb->get_button_index() == BUTTON_LEFT) { - const SetItem &si = E->get(); - undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); - } + if (input_action == INPUT_DUPLICATE) { - undo_redo->commit_action(); - } - set_items.clear(); + //paste + _duplicate_paste(); input_action = INPUT_NONE; - return true; - } - - if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { - + _update_duplicate_indicator(); + } else if (mb->get_shift()) { + input_action = INPUT_SELECT; + } else if (mb->get_command()) + input_action = INPUT_COPY; + else { + input_action = INPUT_PAINT; set_items.clear(); - input_action = INPUT_NONE; - return true; } - if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { + } else if (mb->get_button_index() == BUTTON_RIGHT) + if (input_action == INPUT_DUPLICATE) { + input_action = INPUT_NONE; - return true; + _update_duplicate_indicator(); + } else { + input_action = INPUT_ERASE; + set_items.clear(); } - } - } - - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - return do_input_action(p_camera, mm->get_position(), false); - } - - } else if (edit_mode->get_selected() == 1) { - //area mode, select an area + else + return false; - Ref<InputEventMouseButton> mb = p_event; + return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); + } else { - if (mb.is_valid()) { + if ( + (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || + (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) { - if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { + if (set_items.size()) { + undo_redo->create_action("GridMap Paint"); + for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { - Point2 point = mb->get_position(); - - Camera *camera = p_camera; - Vector3 from = camera->project_ray_origin(point); - Vector3 normal = camera->project_ray_normal(point); - Transform local_xform = node->get_global_transform().affine_inverse(); - from = local_xform.xform(from); - normal = local_xform.basis.xform(normal).normalized(); + const SetItem &si = E->get(); + undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); + } + for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { - List<int> areas; - node->get_area_list(&areas); + const SetItem &si = E->get(); + undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); + } - float min_d = 1e10; - int min_area = -1; + undo_redo->commit_action(); + } + set_items.clear(); + input_action = INPUT_NONE; + return true; + } - for (List<int>::Element *E = areas.front(); E; E = E->next()) { + if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { - int area = E->get(); - Rect3 aabb = node->area_get_bounds(area); - aabb.position *= node->get_cell_size(); - aabb.size *= node->get_cell_size(); + set_items.clear(); + input_action = INPUT_NONE; + return true; + } + if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { + input_action = INPUT_NONE; + return true; + } + } + } - Vector3 rclip, rnormal; - if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) - continue; + Ref<InputEventMouseMotion> mm = p_event; - float d = normal.dot(rclip); - if (d < min_d) { - min_d = d; - min_area = area; - } - } + if (mm.is_valid()) { - selected_area = min_area; - update_areas(); - } - } + return do_input_action(p_camera, mm->get_position(), false); } return false; @@ -749,52 +675,6 @@ void GridMapEditor::update_pallete() { last_theme = theme.operator->(); } -void GridMapEditor::_area_renamed() { - - TreeItem *it = area_list->get_selected(); - int area = it->get_metadata(0); - if (area < 1) - return; - node->area_set_name(area, it->get_text(0)); -} - -void GridMapEditor::_area_selected() { - - TreeItem *it = area_list->get_selected(); - int area = it->get_metadata(0); - if (area < 1) - return; - selected_area = area; -} - -void GridMapEditor::update_areas() { - - area_list->clear(); - - List<int> areas; - node->get_area_list(&areas); - - TreeItem *root = area_list->create_item(NULL); - area_list->set_hide_root(true); - TreeItem *selected = NULL; - - for (List<int>::Element *E = areas.front(); E; E = E->next()) { - - int area = E->get(); - TreeItem *ti = area_list->create_item(root); - String name = node->area_get_name(area); - - ti->set_metadata(0, area); - ti->set_text(0, name); - ti->set_editable(0, true); - if (area == selected_area) - selected = ti; - } - - if (selected) - selected->select(0); -} - void GridMapEditor::edit(GridMap *p_gridmap) { node = p_gridmap; @@ -806,7 +686,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) { _update_selection_transform(); _update_duplicate_indicator(); - spatial_editor = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>(); + spatial_editor = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen()); if (!node) { set_process(false); @@ -816,13 +696,10 @@ void GridMapEditor::edit(GridMap *p_gridmap) { VisualServer::get_singleton()->instance_set_visible(cursor_instance, false); - _clear_areas(); - return; } update_pallete(); - update_areas(); set_process(true); @@ -894,7 +771,6 @@ void GridMapEditor::edit(GridMap *p_gridmap) { update_grid(); _update_clip(); - _update_areas_display(); } void GridMapEditor::_update_clip() { @@ -931,9 +807,6 @@ void GridMapEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { theme_pallete->connect("item_selected", this, "_item_selected_cbk"); - edit_mode->connect("item_selected", this, "_edit_mode_changed"); - area_list->connect("item_edited", this, "_area_renamed"); - area_list->connect("item_selected", this, "_area_selected"); for (int i = 0; i < 3; i++) { grid[i] = VS::get_singleton()->mesh_create(); @@ -962,6 +835,9 @@ void GridMapEditor::_notification(int p_what) { duplicate_instance = RID(); } else if (p_what == NOTIFICATION_PROCESS) { + if (!node) { + return; + } Transform xf = node->get_global_transform(); @@ -978,14 +854,14 @@ void GridMapEditor::_notification(int p_what) { if (lock_view) { - EditorNode *editor = get_tree()->get_root()->get_child(0)->cast_to<EditorNode>(); + EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); Plane p; p.normal[edit_axis] = 1.0; p.d = edit_floor[edit_axis] * node->get_cell_size(); p = node->get_transform().xform(p); // plane to snap - SpatialEditorPlugin *sep = editor->get_editor_plugin_screen()->cast_to<SpatialEditorPlugin>(); + SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen()); if (sep) sep->snap_cursor_to_plane(p); //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p); @@ -1021,85 +897,6 @@ void GridMapEditor::_item_selected_cbk(int idx) { _update_cursor_instance(); } -void GridMapEditor::_clear_areas() { - - for (int i = 0; i < areas.size(); i++) { - - VisualServer::get_singleton()->free(areas[i].instance); - VisualServer::get_singleton()->free(areas[i].mesh); - } - - areas.clear(); -} - -void GridMapEditor::_update_areas_display() { - if (!node) { - return; - } -#if 0 - _clear_areas(); - List<int> areas; - node->get_area_list(&areas); - - Transform global_xf = node->get_global_transform(); - - for(List<int>::Element *E=areas.front();E;E=E->next()) { - - int area = E->get(); - Color color; - if (node->area_is_exterior_portal(area)) - color=Color(1,1,1,0.2); - else - color.set_hsv(Math::fmod(area*0.37,1),Math::fmod(area*0.75,1),1.0,0.2); - - - RID material = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_DIFFUSE,color ); - VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_EMISSION,0.5 ); - VisualServer::get_singleton()->fixed_material_set_flag( material, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); - - - RID mesh = VisualServer::get_singleton()->mesh_create(); - - PoolVector<Plane> planes; - for(int i=0;i<3;i++) { - - Vector3 axis; - axis[i]=1.0; - planes.push_back(Plane(axis,1)); - planes.push_back(Plane(-axis,0)); - } - - VisualServer::get_singleton()->mesh_add_surface_from_planes(mesh,planes); - VisualServer::get_singleton()->mesh_surface_set_material(mesh,0,material,true); - - AreaDisplay ad; - ad.mesh=mesh; - ad.instance = VisualServer::get_singleton()->instance_create2(mesh,node->get_world()->get_scenario()); - Transform xform; - Rect3 aabb = node->area_get_bounds(area); - xform.origin=aabb.pos * node->get_cell_size(); - xform.basis.scale(aabb.size * node->get_cell_size()); - VisualServer::get_singleton()->instance_set_transform(ad.instance,global_xf * xform); - this->areas.push_back(ad); - - } -#endif -} - -void GridMapEditor::_edit_mode_changed(int p_what) { - - if (p_what == 0) { - - theme_pallete->show(); - area_list->hide(); - } else { - - theme_pallete->hide(); - area_list->show(); - } -} - void GridMapEditor::_floor_changed(float p_value) { if (updating) @@ -1116,9 +913,6 @@ void GridMapEditor::_bind_methods() { ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option); ClassDB::bind_method("_configure", &GridMapEditor::_configure); ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk); - ClassDB::bind_method("_edit_mode_changed", &GridMapEditor::_edit_mode_changed); - ClassDB::bind_method("_area_renamed", &GridMapEditor::_area_renamed); - ClassDB::bind_method("_area_selected", &GridMapEditor::_area_selected); ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed); ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode); @@ -1142,45 +936,43 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { spatial_editor_hb->hide(); options->set_text("Grid"); - options->get_popup()->add_check_item("Snap View", MENU_OPTION_LOCK_VIEW); + options->get_popup()->add_check_item(TTR("Snap View"), MENU_OPTION_LOCK_VIEW); options->get_popup()->add_separator(); - options->get_popup()->add_item("Prev Level (" + keycode_get_string(KEY_MASK_CMD) + "Down Wheel)", MENU_OPTION_PREV_LEVEL); - options->get_popup()->add_item("Next Level (" + keycode_get_string(KEY_MASK_CMD) + "Up Wheel)", MENU_OPTION_NEXT_LEVEL); + options->get_popup()->add_item(vformat(TTR("Prev Level (%sDown Wheel)"), keycode_get_string(KEY_MASK_CMD)), MENU_OPTION_PREV_LEVEL); + options->get_popup()->add_item(vformat(TTR("Next Level (%sUp Wheel)"), keycode_get_string(KEY_MASK_CMD)), MENU_OPTION_NEXT_LEVEL); options->get_popup()->add_separator(); - options->get_popup()->add_check_item("Clip Disabled", MENU_OPTION_CLIP_DISABLED); + options->get_popup()->add_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED); options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true); - options->get_popup()->add_check_item("Clip Above", MENU_OPTION_CLIP_ABOVE); - options->get_popup()->add_check_item("Clip Below", MENU_OPTION_CLIP_BELOW); + options->get_popup()->add_check_item(TTR("Clip Above"), MENU_OPTION_CLIP_ABOVE); + options->get_popup()->add_check_item(TTR("Clip Below"), MENU_OPTION_CLIP_BELOW); options->get_popup()->add_separator(); - options->get_popup()->add_check_item("Edit X Axis", MENU_OPTION_X_AXIS, KEY_Z); - options->get_popup()->add_check_item("Edit Y Axis", MENU_OPTION_Y_AXIS, KEY_X); - options->get_popup()->add_check_item("Edit Z Axis", MENU_OPTION_Z_AXIS, KEY_C); + options->get_popup()->add_check_item(TTR("Edit X Axis"), MENU_OPTION_X_AXIS, KEY_Z); + options->get_popup()->add_check_item(TTR("Edit Y Axis"), MENU_OPTION_Y_AXIS, KEY_X); + options->get_popup()->add_check_item(TTR("Edit Z Axis"), MENU_OPTION_Z_AXIS, KEY_C); options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true); options->get_popup()->add_separator(); - options->get_popup()->add_item("Cursor Rotate X", MENU_OPTION_CURSOR_ROTATE_X, KEY_A); - options->get_popup()->add_item("Cursor Rotate Y", MENU_OPTION_CURSOR_ROTATE_Y, KEY_S); - options->get_popup()->add_item("Cursor Rotate Z", MENU_OPTION_CURSOR_ROTATE_Z, KEY_D); - options->get_popup()->add_item("Cursor Back Rotate X", MENU_OPTION_CURSOR_BACK_ROTATE_X, KEY_MASK_SHIFT + KEY_A); - options->get_popup()->add_item("Cursor Back Rotate Y", MENU_OPTION_CURSOR_BACK_ROTATE_Y, KEY_MASK_SHIFT + KEY_S); - options->get_popup()->add_item("Cursor Back Rotate Z", MENU_OPTION_CURSOR_BACK_ROTATE_Z, KEY_MASK_SHIFT + KEY_D); - options->get_popup()->add_item("Cursor Clear Rotation", MENU_OPTION_CURSOR_CLEAR_ROTATION, KEY_W); + options->get_popup()->add_item(TTR("Cursor Rotate X"), MENU_OPTION_CURSOR_ROTATE_X, KEY_A); + options->get_popup()->add_item(TTR("Cursor Rotate Y"), MENU_OPTION_CURSOR_ROTATE_Y, KEY_S); + options->get_popup()->add_item(TTR("Cursor Rotate Z"), MENU_OPTION_CURSOR_ROTATE_Z, KEY_D); + options->get_popup()->add_item(TTR("Cursor Back Rotate X"), MENU_OPTION_CURSOR_BACK_ROTATE_X, KEY_MASK_SHIFT + KEY_A); + options->get_popup()->add_item(TTR("Cursor Back Rotate Y"), MENU_OPTION_CURSOR_BACK_ROTATE_Y, KEY_MASK_SHIFT + KEY_S); + options->get_popup()->add_item(TTR("Cursor Back Rotate Z"), MENU_OPTION_CURSOR_BACK_ROTATE_Z, KEY_MASK_SHIFT + KEY_D); + options->get_popup()->add_item(TTR("Cursor Clear Rotation"), MENU_OPTION_CURSOR_CLEAR_ROTATION, KEY_W); options->get_popup()->add_separator(); options->get_popup()->add_check_item("Duplicate Selects", MENU_OPTION_DUPLICATE_SELECTS); options->get_popup()->add_separator(); - options->get_popup()->add_item("Create Area", MENU_OPTION_SELECTION_MAKE_AREA, KEY_CONTROL + KEY_C); - options->get_popup()->add_item("Create Exterior Connector", MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR); - options->get_popup()->add_item("Erase Area", MENU_OPTION_REMOVE_AREA); + options->get_popup()->add_item(TTR("Create Area"), MENU_OPTION_SELECTION_MAKE_AREA, KEY_CONTROL + KEY_C); + options->get_popup()->add_item(TTR("Create Exterior Connector"), MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR); + options->get_popup()->add_item(TTR("Erase Area"), MENU_OPTION_REMOVE_AREA); options->get_popup()->add_separator(); - options->get_popup()->add_item("Selection -> Duplicate", MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_INSERT); - options->get_popup()->add_item("Selection -> Clear", MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_DELETE); - //options->get_popup()->add_separator(); - //options->get_popup()->add_item("Configure",MENU_OPTION_CONFIGURE); + options->get_popup()->add_item(TTR("Selection -> Duplicate"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_INSERT); + options->get_popup()->add_item(TTR("Selection -> Clear"), MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_DELETE); options->get_popup()->add_separator(); - options->get_popup()->add_item("Settings", MENU_OPTION_GRIDMAP_SETTINGS); + options->get_popup()->add_item(TTR("Settings"), MENU_OPTION_GRIDMAP_SETTINGS); settings_dialog = memnew(ConfirmationDialog); - settings_dialog->set_title("GridMap Settings"); + settings_dialog->set_title(TTR("GridMap Settings")); add_child(settings_dialog); settings_vbc = memnew(VBoxContainer); settings_vbc->set_custom_minimum_size(Size2(200, 0)); @@ -1191,7 +983,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { settings_pick_distance->set_min(500.0f); settings_pick_distance->set_step(1.0f); settings_pick_distance->set_value(EDITOR_DEF("editors/grid_map/pick_distance", 5000.0)); - settings_vbc->add_margin_child("Pick Distance:", settings_pick_distance); + settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance); clip_mode = CLIP_DISABLED; options->get_popup()->connect("id_pressed", this, "_menu_option"); @@ -1200,15 +992,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { add_child(hb); hb->set_h_size_flags(SIZE_EXPAND_FILL); - edit_mode = memnew(OptionButton); - edit_mode->set_area_as_parent_rect(); - edit_mode->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_BEGIN, 24); - edit_mode->set_margin(MARGIN_RIGHT, -14); - edit_mode->add_item("Tiles"); - edit_mode->add_item("Areas"); - hb->add_child(edit_mode); - edit_mode->set_h_size_flags(SIZE_EXPAND_FILL); - mode_thumbnail = memnew(ToolButton); mode_thumbnail->set_toggle_mode(true); mode_thumbnail->set_pressed(true); @@ -1226,17 +1009,11 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { EDITOR_DEF("editors/grid_map/preview_size", 64); display_mode = DISPLAY_THUMBNAIL; - selected_area = -1; theme_pallete = memnew(ItemList); add_child(theme_pallete); theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL); - area_list = memnew(Tree); - add_child(area_list); - area_list->set_v_size_flags(SIZE_EXPAND_FILL); - area_list->hide(); - spatial_editor_hb->add_child(memnew(VSeparator)); Label *fl = memnew(Label); fl->set_text(" Floor: "); @@ -1365,13 +1142,11 @@ GridMapEditor::~GridMapEditor() { VisualServer::get_singleton()->free(duplicate_mesh); if (duplicate_instance.is_valid()) VisualServer::get_singleton()->free(duplicate_instance); - - _clear_areas(); } void GridMapEditorPlugin::edit(Object *p_object) { - gridmap_editor->edit(p_object ? p_object->cast_to<GridMap>() : NULL); + gridmap_editor->edit(Object::cast_to<GridMap>(p_object)); } bool GridMapEditorPlugin::handles(Object *p_object) const { diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index a1b2c96ccd..6c7c0ab331 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -75,7 +75,6 @@ class GridMapEditor : public VBoxContainer { Panel *panel; MenuButton *options; SpinBox *floor; - OptionButton *edit_mode; ToolButton *mode_thumbnail; ToolButton *mode_list; HBoxContainer *spatial_editor_hb; @@ -137,7 +136,6 @@ class GridMapEditor : public VBoxContainer { int display_mode; int selected_pallete; - int selected_area; int cursor_rot; enum Menu { @@ -177,18 +175,12 @@ class GridMapEditor : public VBoxContainer { RID instance; }; - Vector<AreaDisplay> areas; - - void _update_areas_display(); - void _clear_areas(); - void update_grid(); void _configure(); void _menu_option(int); void update_pallete(); void _set_display_mode(int p_mode); ItemList *theme_pallete; - Tree *area_list; void _item_selected_cbk(int idx); void _update_cursor_transform(); void _update_cursor_instance(); @@ -199,14 +191,9 @@ class GridMapEditor : public VBoxContainer { void _update_selection_transform(); void _validate_selection(); - void _edit_mode_changed(int p_what); - void _area_renamed(); - void _area_selected(); - void _floor_changed(float p_value); void _delete_selection(); - void update_areas(); EditorNode *editor; bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click); diff --git a/modules/nativescript/config.py b/modules/nativescript/config.py index 9f57b9bb74..4f89ca0d4c 100644 --- a/modules/nativescript/config.py +++ b/modules/nativescript/config.py @@ -1,7 +1,7 @@ def can_build(platform): - return True + return False def configure(env): diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp index d428834d59..b495c7bf4d 100644 --- a/modules/nativescript/nativescript.cpp +++ b/modules/nativescript/nativescript.cpp @@ -399,7 +399,7 @@ Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::Call owner = memnew(Reference); } - Reference *r = owner->cast_to<Reference>(); + Reference *r = Object::cast_to<Reference>(owner); if (r) { ref = REF(r); } @@ -1203,11 +1203,11 @@ Error ResourceFormatSaverNativeScript::save(const String &p_path, const RES &p_r } bool ResourceFormatSaverNativeScript::recognize(const RES &p_resource) const { - return p_resource->cast_to<NativeScript>() != NULL; + return Object::cast_to<NativeScript>(*p_resource) != NULL; } void ResourceFormatSaverNativeScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (p_resource->cast_to<NativeScript>()) { + if (Object::cast_to<NativeScript>(*p_resource)) { p_extensions->push_back("gdns"); } } diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index b4bdbe16b4..6b69ffdf8d 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -273,7 +273,9 @@ void VisualScript::_node_ports_changed(int p_id) { Function &func = functions[function]; Ref<VisualScriptNode> vsn = func.nodes[p_id].node; - if (OS::get_singleton()->get_main_loop() && OS::get_singleton()->get_main_loop()->cast_to<SceneTree>() && Engine::get_singleton()->is_editor_hint()) { + if (OS::get_singleton()->get_main_loop() && + Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop()) && + Engine::get_singleton()->is_editor_hint()) { vsn->validate_input_default_values(); //force validate default values when editing on editor } @@ -336,7 +338,7 @@ void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<Visual Function &func = functions[p_func]; - if (p_node->cast_to<VisualScriptFunction>()) { + if (Object::cast_to<VisualScriptFunction>(*p_node)) { //the function indeed ERR_EXPLAIN("A function node already has been set here."); ERR_FAIL_COND(func.function_id >= 0); @@ -393,7 +395,7 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } } - if (func.nodes[p_id].node->cast_to<VisualScriptFunction>()) { + if (Object::cast_to<VisualScriptFunction>(func.nodes[p_id].node.ptr())) { func.function_id = -1; //revert to invalid } @@ -1086,7 +1088,7 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED if (has_function(p_member)) { for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { - if (E->get().node->cast_to<VisualScriptFunction>()) + if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) return E->key(); } } @@ -2001,9 +2003,9 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o max_input_args = 0; max_output_args = 0; - if (p_owner->cast_to<Node>()) { + if (Object::cast_to<Node>(p_owner)) { //turn on these if they exist and base is a node - Node *node = p_owner->cast_to<Node>(); + Node *node = Object::cast_to<Node>(p_owner); if (p_script->functions.has("_process")) node->set_process(true); if (p_script->functions.has("_fixed_process")) @@ -2094,16 +2096,16 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } } - if (node->cast_to<VisualScriptLocalVar>() || node->cast_to<VisualScriptLocalVarSet>()) { + if (Object::cast_to<VisualScriptLocalVar>(node.ptr()) || Object::cast_to<VisualScriptLocalVarSet>(*node)) { //working memory is shared only for this node, for the same variables Ref<VisualScriptLocalVar> vslv = node; StringName var_name; - if (node->cast_to<VisualScriptLocalVar>()) - var_name = String(node->cast_to<VisualScriptLocalVar>()->get_var_name()).strip_edges(); + if (Object::cast_to<VisualScriptLocalVar>(*node)) + var_name = String(Object::cast_to<VisualScriptLocalVar>(*node)->get_var_name()).strip_edges(); else - var_name = String(node->cast_to<VisualScriptLocalVarSet>()->get_var_name()).strip_edges(); + var_name = String(Object::cast_to<VisualScriptLocalVarSet>(*node)->get_var_name()).strip_edges(); if (!local_var_indices.has(var_name)) { local_var_indices[var_name] = function.max_stack; diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index b9e7a6ffc4..e93d6ec4d1 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -73,7 +73,7 @@ protected: if (argc == new_argc) return true; - undo_redo->create_action("Change Signal Arguments"); + undo_redo->create_action(TTR("Change Signal Arguments")); if (new_argc < argc) { for (int i = new_argc; i < argc; i++) { @@ -104,7 +104,7 @@ protected: int old_type = script->custom_signal_get_argument_type(sig, idx); int new_type = p_value; - undo_redo->create_action("Change Argument Type"); + undo_redo->create_action(TTR("Change Argument Type")); undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, new_type); undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_type", sig, idx, old_type); undo_redo->commit_action(); @@ -116,7 +116,7 @@ protected: String old_name = script->custom_signal_get_argument_name(sig, idx); String new_name = p_value; - undo_redo->create_action("Change Argument name"); + undo_redo->create_action(TTR("Change Argument name")); undo_redo->add_do_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, new_name); undo_redo->add_undo_method(script.ptr(), "custom_signal_set_argument_name", sig, idx, old_name); undo_redo->commit_action(); @@ -213,7 +213,7 @@ protected: return false; if (String(p_name) == "value") { - undo_redo->create_action("Set Variable Default Value"); + undo_redo->create_action(TTR("Set Variable Default Value")); Variant current = script->get_variable_default_value(var); undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, p_value); undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, current); @@ -229,7 +229,7 @@ protected: Dictionary dc = d.copy(); dc["type"] = p_value; - undo_redo->create_action("Set Variable Type"); + undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); undo_redo->add_do_method(this, "_var_changed"); @@ -242,7 +242,7 @@ protected: Dictionary dc = d.copy(); dc["hint"] = p_value; - undo_redo->create_action("Set Variable Type"); + undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); undo_redo->add_do_method(this, "_var_changed"); @@ -255,7 +255,7 @@ protected: Dictionary dc = d.copy(); dc["hint_string"] = p_value; - undo_redo->create_action("Set Variable Type"); + undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); undo_redo->add_do_method(this, "_var_changed"); @@ -422,7 +422,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { for (int i = 0; i < graph->get_child_count(); i++) { - if (graph->get_child(i)->cast_to<GraphNode>()) { + if (Object::cast_to<GraphNode>(graph->get_child(i))) { memdelete(graph->get_child(i)); i--; } @@ -506,7 +506,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->set_show_close_button(true); } - if (node->cast_to<VisualScriptExpression>()) { + if (Object::cast_to<VisualScriptExpression>(*node)) { LineEdit *line_edit = memnew(LineEdit); line_edit->set_text(node->get_text()); @@ -520,7 +520,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->add_child(text); } - if (node->cast_to<VisualScriptComment>()) { + if (Object::cast_to<VisualScriptExpression>(*node)) { Ref<VisualScriptComment> vsc = node; gnode->set_comment(true); gnode->set_resizeable(true); @@ -970,7 +970,7 @@ void VisualScriptEditor::_override_pressed(int p_id) { void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) { - TreeItem *ti = p_item->cast_to<TreeItem>(); + TreeItem *ti = Object::cast_to<TreeItem>(p_item); TreeItem *root = members->get_root(); @@ -1117,8 +1117,8 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id undo_redo->commit_action(); Node *node = graph->get_node(itos(p_id)); - if (node->cast_to<Control>()) - node->cast_to<Control>()->set_size(Vector2(1, 1)); //shrink if text is smaller + if (Object::cast_to<Control>(node)) + Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller updating_graph = false; } @@ -1253,7 +1253,7 @@ void VisualScriptEditor::_on_nodes_delete() { List<int> to_erase; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected() && gn->is_close_button_visible()) { to_erase.push_back(gn->get_name().operator String().to_int()); @@ -1264,7 +1264,7 @@ void VisualScriptEditor::_on_nodes_delete() { if (to_erase.empty()) return; - undo_redo->create_action("Remove VisualScript Nodes"); + undo_redo->create_action(TTR("Remove VisualScript Nodes")); for (List<int>::Element *F = to_erase.front(); F; F = F->next()) { @@ -1302,7 +1302,7 @@ void VisualScriptEditor::_on_nodes_duplicate() { List<int> to_duplicate; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected() && gn->is_close_button_visible()) { to_duplicate.push_back(gn->get_name().operator String().to_int()); @@ -1313,7 +1313,7 @@ void VisualScriptEditor::_on_nodes_duplicate() { if (to_duplicate.empty()) return; - undo_redo->create_action("Duplicate VisualScript Nodes"); + undo_redo->create_action(TTR("Duplicate VisualScript Nodes")); int idc = script->get_available_id() + 1; Set<int> to_select; @@ -1335,7 +1335,7 @@ void VisualScriptEditor::_on_nodes_duplicate() { undo_redo->commit_action(); for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { int id = gn->get_name().operator String().to_int(); gn->set_selected(to_select.has(id)); @@ -1799,7 +1799,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (!obj) return; - Node *node = obj->cast_to<Node>(); + Node *node = Object::cast_to<Node>(obj); Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { @@ -1918,7 +1918,7 @@ void VisualScriptEditor::_selected_method(const String &p_method) { void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) { - Button *button = obj->cast_to<Button>(); + Button *button = Object::cast_to<Button>(obj); if (!button) return; @@ -1937,7 +1937,7 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const if (!obj) return; - Button *b = obj->cast_to<Button>(); + Button *b = Object::cast_to<Button>(obj); ERR_FAIL_COND(!b); if (p_preview.is_null()) { @@ -2050,9 +2050,7 @@ void VisualScriptEditor::set_edit_state(const Variant &p_state) { void VisualScriptEditor::_center_on_node(int p_id) { Node *n = graph->get_node(itos(p_id)); - if (!n) - return; - GraphNode *gn = n->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(n); if (gn) { gn->set_selected(true); Vector2 new_scroll = gn->get_offset() - graph->get_size() * 0.5 + gn->get_size() * 0.5; @@ -2210,7 +2208,7 @@ void VisualScriptEditor::_change_base_type_callback() { String bt = select_base_type->get_selected_type(); ERR_FAIL_COND(bt == String()); - undo_redo->create_action("Change Base Type"); + undo_redo->create_action(TTR("Change Base Type")); undo_redo->add_do_method(script.ptr(), "set_instance_base_type", bt); undo_redo->add_undo_method(script.ptr(), "set_instance_base_type", script->get_instance_base_type()); undo_redo->add_do_method(this, "_update_members"); @@ -2258,7 +2256,7 @@ static bool _get_in_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r void VisualScriptEditor::_begin_node_move() { - undo_redo->create_action("Move Node(s)"); + undo_redo->create_action(TTR("Move Node(s)")); } void VisualScriptEditor::_end_node_move() { @@ -2270,8 +2268,8 @@ void VisualScriptEditor::_move_node(String func, int p_id, const Vector2 &p_to) if (func == String(edited_func)) { Node *node = graph->get_node(itos(p_id)); - if (node && node->cast_to<GraphNode>()) - node->cast_to<GraphNode>()->set_offset(p_to); + if (Object::cast_to<GraphNode>(node)) + Object::cast_to<GraphNode>(node)->set_offset(p_to); } script->set_node_pos(edited_func, p_id, p_to / EDSCALE); } @@ -2284,7 +2282,7 @@ void VisualScriptEditor::_node_moved(Vector2 p_from, Vector2 p_to, int p_id) { void VisualScriptEditor::_remove_node(int p_id) { - undo_redo->create_action("Remove VisualScript Node"); + undo_redo->create_action(TTR("Remove VisualScript Node")); undo_redo->add_do_method(script.ptr(), "remove_node", edited_func, p_id); undo_redo->add_undo_method(script.ptr(), "add_node", edited_func, p_id, script->get_node(edited_func, p_id), script->get_node_pos(edited_func, p_id)); @@ -2345,7 +2343,7 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, ERR_FAIL_COND(from_seq != to_seq); - undo_redo->create_action("Connect Nodes"); + undo_redo->create_action(TTR("Connect Nodes")); if (from_seq) { undo_redo->add_do_method(script.ptr(), "sequence_connect", edited_func, p_from.to_int(), from_port, p_to.to_int()); @@ -2398,7 +2396,7 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl ERR_FAIL_COND(from_seq != to_seq); - undo_redo->create_action("Connect Nodes"); + undo_redo->create_action(TTR("Connect Nodes")); if (from_seq) { undo_redo->add_do_method(script.ptr(), "sequence_disconnect", edited_func, p_from.to_int(), from_port, p_to.to_int()); @@ -2421,10 +2419,7 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos) { Node *node = graph->get_node(p_from); - if (!node) - return; - - GraphNode *gn = node->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(node); if (!gn) return; @@ -2691,21 +2686,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 (vsn->cast_to<VisualScriptFunctionCall>()) { + if (Object::cast_to<VisualScriptFunctionCall>(*vsn)) { 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 (vsn->cast_to<VisualScriptPropertySet>()) { + if (Object::cast_to<VisualScriptPropertySet>(*vsn)) { 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 (vsn->cast_to<VisualScriptPropertyGet>()) { + if (Object::cast_to<VisualScriptPropertyGet>(*vsn)) { Ref<VisualScriptPropertyGet> vsp = vsn; vsp->set_property(p_text); @@ -2716,13 +2711,19 @@ void VisualScriptEditor::_selected_connect_node_method_or_setget(const String &p _update_graph_connections(); } +void VisualScriptEditor::_cancel_connect_node_method_or_setget() { + + script->remove_node(edited_func, port_action_new_node); + _update_graph(); +} + void VisualScriptEditor::_default_value_changed() { Ref<VisualScriptNode> vsn = script->get_node(edited_func, editing_id); if (vsn.is_null()) return; - undo_redo->create_action("Change Input Value"); + undo_redo->create_action(TTR("Change Input Value")); undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, default_value_edit->get_variant()); undo_redo->add_undo_method(vsn.ptr(), "set_default_input_value", editing_input, vsn->get_default_input_value(editing_input)); @@ -2746,7 +2747,7 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i existing = Variant::construct(pinfo.type, &existingp, 1, ce, false); } - default_value_edit->set_position(p_button->cast_to<Control>()->get_global_position() + Vector2(0, p_button->cast_to<Control>()->get_size().y)); + default_value_edit->set_position(Object::cast_to<Control>(p_button)->get_global_position() + Vector2(0, Object::cast_to<Control>(p_button)->get_size().y)); default_value_edit->set_size(Size2(1, 1)); if (default_value_edit->edit(NULL, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) { if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) @@ -2812,9 +2813,7 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_ return; Node *node = graph->get_node(itos(p_node)); - if (!node) - return; - GraphNode *gn = node->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(node); if (!gn) return; @@ -2843,7 +2842,7 @@ void VisualScriptEditor::_menu_option(int p_what) { List<String> reselect; for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected()) { int id = String(gn->get_name()).to_int(); @@ -2859,7 +2858,7 @@ void VisualScriptEditor::_menu_option(int p_what) { _update_graph(); for (List<String>::Element *E = reselect.front(); E; E = E->next()) { - GraphNode *gn = graph->get_node(E->get())->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(E->get())); gn->set_selected(true); } @@ -2880,14 +2879,14 @@ void VisualScriptEditor::_menu_option(int p_what) { clipboard->sequence_connections.clear(); for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected()) { int id = String(gn->get_name()).to_int(); Ref<VisualScriptNode> node = script->get_node(edited_func, id); - if (node->cast_to<VisualScriptFunction>()) { - EditorNode::get_singleton()->show_warning("Can't copy the function node."); + if (Object::cast_to<VisualScriptFunction>(*node)) { + EditorNode::get_singleton()->show_warning(TTR("Can't copy the function node.")); return; } if (node.is_valid()) { @@ -2935,13 +2934,13 @@ void VisualScriptEditor::_menu_option(int p_what) { break; if (clipboard->nodes.empty()) { - EditorNode::get_singleton()->show_warning("Clipboard is empty!"); + EditorNode::get_singleton()->show_warning(TTR("Clipboard is empty!")); break; } Map<int, int> remap; - undo_redo->create_action("Paste VisualScript Nodes"); + undo_redo->create_action(TTR("Paste VisualScript Nodes")); int idc = script->get_available_id() + 1; Set<int> to_select; @@ -2994,7 +2993,7 @@ void VisualScriptEditor::_menu_option(int p_what) { undo_redo->commit_action(); for (int i = 0; i < graph->get_child_count(); i++) { - GraphNode *gn = graph->get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { int id = gn->get_name().operator String().to_int(); gn->set_selected(to_select.has(id)); @@ -3167,6 +3166,7 @@ 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("_cancel_connect_node_method_or_setget", &VisualScriptEditor::_cancel_connect_node_method_or_setget); ClassDB::bind_method("_expression_text_changed", &VisualScriptEditor::_expression_text_changed); ClassDB::bind_method("get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw); @@ -3364,6 +3364,7 @@ VisualScriptEditor::VisualScriptEditor() { new_connect_node_select = memnew(PropertySelector); add_child(new_connect_node_select); 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"); port_action_popup = memnew(PopupMenu); add_child(port_action_popup); @@ -3385,7 +3386,7 @@ VisualScriptEditor::~VisualScriptEditor() { static ScriptEditorBase *create_editor(const Ref<Script> &p_script) { - if (p_script->cast_to<VisualScript>()) { + if (Object::cast_to<VisualScript>(*p_script)) { return memnew(VisualScriptEditor); } diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index fee4e27bd5..e68711a036 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -176,6 +176,7 @@ class VisualScriptEditor : public ScriptEditorBase { int port_action_new_node; 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(); int error_line; diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 47cdfff494..b51ef6beef 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -85,10 +85,7 @@ Node *VisualScriptFunctionCall::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -776,7 +773,7 @@ public: if (!p_base) return false; - Node *node = p_base->cast_to<Node>(); + Node *node = Object::cast_to<Node>(p_base); if (!node) return false; @@ -817,7 +814,7 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; @@ -825,7 +822,7 @@ public: } Node *another = node->get_node(node_path); - if (!node) { + if (!another) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Path does not lead Node!"; return 0; @@ -961,10 +958,8 @@ Node *VisualScriptPropertySet::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -1159,9 +1154,7 @@ String VisualScriptPropertySet::get_base_script() const { void VisualScriptPropertySet::_update_cache() { - if (!OS::get_singleton()->get_main_loop()) - return; - if (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>()) + if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) return; if (!Engine::get_singleton()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise @@ -1595,7 +1588,7 @@ public: } break; case VisualScriptPropertySet::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; @@ -1603,7 +1596,7 @@ public: } Node *another = node->get_node(node_path); - if (!node) { + if (!another) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Path does not lead Node!"; return 0; @@ -1730,10 +1723,8 @@ Node *VisualScriptPropertyGet::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -2242,7 +2233,7 @@ public: } break; case VisualScriptPropertyGet::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("Base object is not a Node!"); @@ -2250,7 +2241,7 @@ public: } Node *another = node->get_node(node_path); - if (!node) { + if (!another) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("Path does not lead Node!"); return 0; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 15e25c99ee..5e74c970e3 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -2079,7 +2079,7 @@ public: virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::CallError &r_error, String &r_error_str) { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; @@ -2087,7 +2087,7 @@ public: } Node *another = node->get_node(path); - if (!node) { + if (!another) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Path does not lead Node!"; return 0; @@ -2143,10 +2143,7 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu return tg; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return tg; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return tg; @@ -2181,10 +2178,7 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { return; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return; @@ -2274,7 +2268,7 @@ public: virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Variant::CallError &r_error, String &r_error_str) { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index df88d2e7f7..08adc13193 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -105,7 +105,7 @@ public: } else { //yield - SceneTree *tree = OS::get_singleton()->get_main_loop()->cast_to<SceneTree>(); + SceneTree *tree = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop()); if (!tree) { r_error_str = "Main Loop is not SceneTree"; r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -252,10 +252,7 @@ Node *VisualScriptYieldSignal::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); + SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); if (!scene_tree) return NULL; @@ -530,7 +527,7 @@ public: } break; case VisualScriptYieldSignal::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to<Node>(); + Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; @@ -538,7 +535,7 @@ public: } Node *another = node->get_node(node_path); - if (!node) { + if (!another) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Path does not lead Node!"; return 0; |