diff options
Diffstat (limited to 'modules/visual_script')
18 files changed, 172 insertions, 165 deletions
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index a54d306aff..c50ba17c35 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/modules/visual_script/register_types.h b/modules/visual_script/register_types.h index 2c0ee56268..4fb03bc227 100644 --- a/modules/visual_script/register_types.h +++ b/modules/visual_script/register_types.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index d1cf0f1dce..88012d2031 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -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>() && OS::get_singleton()->get_main_loop()->cast_to<SceneTree>()->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(); } } @@ -1578,12 +1580,15 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p VisualScriptNodeInstance::StartMode start_mode; { - if (p_resuming_yield) + if (p_resuming_yield) { start_mode = VisualScriptNodeInstance::START_MODE_RESUME_YIELD; - else if (!flow_stack || !(flow_stack[flow_stack_pos] & VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT)) //if there is a push bit, it means we are continuing a sequence - start_mode = VisualScriptNodeInstance::START_MODE_BEGIN_SEQUENCE; - else + p_resuming_yield = false; // should resume only the first time + } else if (flow_stack && (flow_stack[flow_stack_pos] & VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT)) { + //if there is a push bit, it means we are continuing a sequence start_mode = VisualScriptNodeInstance::START_MODE_CONTINUE_SEQUENCE; + } else { + start_mode = VisualScriptNodeInstance::START_MODE_BEGIN_SEQUENCE; + } } VSDEBUG("STEP - STARTSEQ: " + itos(start_mode)); @@ -1998,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")) @@ -2091,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.h b/modules/visual_script/visual_script.h index 63ac5769c6..b2e7a6aa27 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -291,8 +291,8 @@ public: void data_disconnect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port); bool has_data_connection(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const; void get_data_connection_list(const StringName &p_func, List<DataConnection> *r_connection) const; - bool is_input_value_port_connected(const StringName &p_name, int p_node, int p_port) const; - bool get_input_value_port_connection_source(const StringName &p_name, int p_node, int p_port, int *r_node, int *r_port) const; + bool is_input_value_port_connected(const StringName &p_func, int p_node, int p_port) const; + bool get_input_value_port_connection_source(const StringName &p_func, int p_node, int p_port, int *r_node, int *r_port) const; void add_variable(const StringName &p_name, const Variant &p_default_value = Variant(), bool p_export = false); bool has_variable(const StringName &p_name) const; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 203e0bb483..2c8796820e 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -915,7 +915,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in VALIDATE_ARG_NUM(0); int64_t num = *p_inputs[0]; - *r_return = nearest_power_of_2(num); + *r_return = next_power_of_2(num); } break; case VisualScriptBuiltinFunc::OBJ_WEAKREF: { diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 8e9c0eca76..97ab307039 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 8912227692..05ceb7a38f 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -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); @@ -886,6 +886,8 @@ void VisualScriptEditor::_member_edited() { undo_redo->add_undo_method(this, "_update_members"); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); + undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); + undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); undo_redo->commit_action(); // _update_graph(); @@ -901,6 +903,8 @@ void VisualScriptEditor::_member_edited() { undo_redo->add_undo_method(script.ptr(), "rename_variable", new_name, name); undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); + undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); + undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); undo_redo->commit_action(); return; //or crash because it will become invalid @@ -914,6 +918,8 @@ void VisualScriptEditor::_member_edited() { undo_redo->add_undo_method(script.ptr(), "rename_custom_signal", new_name, name); undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); + undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); + undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); undo_redo->commit_action(); return; //or crash because it will become invalid @@ -964,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(); @@ -1051,7 +1057,8 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->add_undo_method(this, "_update_members"); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); - + undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); + undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); undo_redo->commit_action(); _update_graph(); @@ -1070,6 +1077,8 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->add_undo_method(script.ptr(), "remove_variable", name); undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); + undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); + undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); undo_redo->commit_action(); return; //or crash because it will become invalid } @@ -1084,6 +1093,8 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->add_undo_method(script.ptr(), "remove_custom_signal", name); undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); + undo_redo->add_do_method(this, "emit_signal", "edited_script_changed"); + undo_redo->add_undo_method(this, "emit_signal", "edited_script_changed"); undo_redo->commit_action(); return; //or crash because it will become invalid } @@ -1106,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; } @@ -1242,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()); @@ -1253,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()) { @@ -1291,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()); @@ -1302,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; @@ -1324,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)); @@ -1788,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()) { @@ -1907,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; @@ -1926,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()) { @@ -2039,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; @@ -2199,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"); @@ -2247,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() { @@ -2259,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); } @@ -2273,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)); @@ -2334,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()); @@ -2387,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()); @@ -2410,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; @@ -2450,17 +2456,17 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro port_action_popup->popup(); } -VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node, int p_output, Set<int> &visited_nodes) { +VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes) { VisualScriptNode::TypeGuess tg; tg.type = Variant::NIL; - if (visited_nodes.has(p_node)) + if (visited_nodes.has(p_port_action_node)) return tg; //no loop - visited_nodes.insert(p_node); + visited_nodes.insert(p_port_action_node); - Ref<VisualScriptNode> node = script->get_node(edited_func, p_node); + Ref<VisualScriptNode> node = script->get_node(edited_func, p_port_action_node); if (!node.is_valid()) { @@ -2479,7 +2485,7 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node, i int from_node; int from_port; - if (script->get_input_value_port_connection_source(edited_func, p_node, i, &from_node, &from_port)) { + if (script->get_input_value_port_connection_source(edited_func, p_port_action_node, i, &from_node, &from_port)) { g = _guess_output_type(from_node, from_port, visited_nodes); } else { @@ -2501,7 +2507,7 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_node, i in_guesses.push_back(g); } - return node->guess_output_type(in_guesses.ptr(), p_output); + return node->guess_output_type(in_guesses.ptr(), p_port_action_output); } void VisualScriptEditor::_port_action_menu(int p_option) { @@ -2680,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); @@ -2705,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)); @@ -2735,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) @@ -2801,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; @@ -2832,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(); @@ -2848,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); } @@ -2869,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()) { @@ -2924,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; @@ -2983,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)); @@ -3156,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); @@ -3223,7 +3234,7 @@ VisualScriptEditor::VisualScriptEditor() { members->connect("button_pressed", this, "_member_button"); members->connect("item_edited", this, "_member_edited"); members->connect("cell_selected", this, "_member_selected", varray(), CONNECT_DEFERRED); - members->set_single_select_cell_editing_only_when_already_selected(true); + members->set_allow_reselect(true); members->set_hide_folding(true); members->set_drag_forwarding(this); @@ -3268,10 +3279,9 @@ VisualScriptEditor::VisualScriptEditor() { select_func_text->set_valign(Label::VALIGN_CENTER); select_func_text->set_h_size_flags(SIZE_EXPAND_FILL); add_child(select_func_text); - graph->set_area_as_parent_rect(); hint_text = memnew(Label); - hint_text->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, 100); + hint_text->set_anchor_and_margin(MARGIN_TOP, ANCHOR_END, -100); hint_text->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); hint_text->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); hint_text->set_align(Label::ALIGN_CENTER); @@ -3354,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); @@ -3375,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..dd051ef8e4 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -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_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 78b70934c0..6bd052fe26 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -585,7 +585,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { r_token.type = TK_BASIC_TYPE; r_token.value = i; return OK; - break; } } diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index 4a9f59ebc3..2636e79842 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 77f3111d94..59d9540239 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index d27fd47f84..380eb76c45 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 3c057cdbd5..5fcc5b0ad9 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -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; @@ -341,12 +338,12 @@ String VisualScriptFunctionCall::get_base_script() const { return base_script; } -void VisualScriptFunctionCall::set_singleton(const StringName &p_path) { +void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { - if (singleton == p_path) + if (singleton == p_type) return; - singleton = p_path; + singleton = p_type; Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); if (obj) { base_type = obj->get_class(); @@ -747,10 +744,10 @@ void VisualScriptFunctionCall::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "validate"), "set_validate", "get_validate"); ADD_PROPERTY(PropertyInfo(Variant::INT, "rpc_call_mode", PROPERTY_HINT_ENUM, "Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"), "set_rpc_call_mode", "get_rpc_call_mode"); //when set, if loaded properly, will override argument count. - BIND_CONSTANT(CALL_MODE_SELF); - BIND_CONSTANT(CALL_MODE_NODE_PATH); - BIND_CONSTANT(CALL_MODE_INSTANCE); - BIND_CONSTANT(CALL_MODE_BASIC_TYPE); + BIND_ENUM_CONSTANT(CALL_MODE_SELF); + BIND_ENUM_CONSTANT(CALL_MODE_NODE_PATH); + BIND_ENUM_CONSTANT(CALL_MODE_INSTANCE); + BIND_ENUM_CONSTANT(CALL_MODE_BASIC_TYPE); } class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance { @@ -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,12 +1154,10 @@ 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 (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise + if (!Engine::get_singleton()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise return; if (call_mode == CALL_MODE_BASIC_TYPE) { @@ -1490,9 +1483,10 @@ void VisualScriptPropertySet::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "index"), "set_index", "get_index"); ADD_PROPERTY(PropertyInfo(Variant::INT, "assign_op", PROPERTY_HINT_ENUM, "Assign,Add,Sub,Mul,Div,Mod,ShiftLeft,ShiftRight,BitAnd,BitOr,Bitxor"), "set_assign_op", "get_assign_op"); - BIND_CONSTANT(CALL_MODE_SELF); - BIND_CONSTANT(CALL_MODE_NODE_PATH); - BIND_CONSTANT(CALL_MODE_INSTANCE); + + BIND_ENUM_CONSTANT(CALL_MODE_SELF); + BIND_ENUM_CONSTANT(CALL_MODE_NODE_PATH); + BIND_ENUM_CONSTANT(CALL_MODE_INSTANCE); } class VisualScriptNodeInstancePropertySet : public VisualScriptNodeInstance { @@ -1594,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!"; @@ -1602,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; @@ -1729,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; @@ -2202,9 +2194,9 @@ void VisualScriptPropertyGet::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "index", PROPERTY_HINT_ENUM), "set_index", "get_index"); - BIND_CONSTANT(CALL_MODE_SELF); - BIND_CONSTANT(CALL_MODE_NODE_PATH); - BIND_CONSTANT(CALL_MODE_INSTANCE); + BIND_ENUM_CONSTANT(CALL_MODE_SELF); + BIND_ENUM_CONSTANT(CALL_MODE_NODE_PATH); + BIND_ENUM_CONSTANT(CALL_MODE_INSTANCE); } class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance { @@ -2241,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!"); @@ -2249,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_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 7839748661..a9a0bd083f 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -70,7 +70,7 @@ private: MethodInfo method_cache; void _update_method_cache(); - void _set_argument_cache(const Dictionary &p_args); + void _set_argument_cache(const Dictionary &p_cache); Dictionary _get_argument_cache() const; protected: diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 923e425997..1decc004ab 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -1208,6 +1208,7 @@ void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { preload = p_preload; ports_changed_notify(); } + Ref<Resource> VisualScriptPreload::get_preload() const { return preload; @@ -2078,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!"; @@ -2086,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; @@ -2142,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; @@ -2180,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; @@ -2273,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!"; @@ -2707,13 +2702,16 @@ void VisualScriptCustomNode::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category")); BIND_VMETHOD(MethodInfo(Variant::INT, "_get_working_memory_size")); - BIND_VMETHOD(MethodInfo(Variant::NIL, "_step:Variant", PropertyInfo(Variant::ARRAY, "inputs"), PropertyInfo(Variant::ARRAY, "outputs"), PropertyInfo(Variant::INT, "start_mode"), PropertyInfo(Variant::ARRAY, "working_mem"))); + + MethodInfo stepmi(Variant::NIL, "_step", PropertyInfo(Variant::ARRAY, "inputs"), PropertyInfo(Variant::ARRAY, "outputs"), PropertyInfo(Variant::INT, "start_mode"), PropertyInfo(Variant::ARRAY, "working_mem")); + stepmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + BIND_VMETHOD(stepmi); ClassDB::bind_method(D_METHOD("_script_changed"), &VisualScriptCustomNode::_script_changed); - BIND_CONSTANT(START_MODE_BEGIN_SEQUENCE); - BIND_CONSTANT(START_MODE_CONTINUE_SEQUENCE); - BIND_CONSTANT(START_MODE_RESUME_YIELD); + BIND_ENUM_CONSTANT(START_MODE_BEGIN_SEQUENCE); + BIND_ENUM_CONSTANT(START_MODE_CONTINUE_SEQUENCE); + BIND_ENUM_CONSTANT(START_MODE_RESUME_YIELD); BIND_CONSTANT(STEP_PUSH_STACK_BIT); BIND_CONSTANT(STEP_GO_BACK_BIT); @@ -2844,7 +2842,9 @@ VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_ void VisualScriptSubCall::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::NIL, "_subcall:Variant", PropertyInfo(Variant::NIL, "arguments:Variant"))); + MethodInfo scmi(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments")); + scmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + BIND_VMETHOD(scmi); } VisualScriptSubCall::VisualScriptSubCall() { diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index ff49417114..694fb96cfa 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -196,7 +196,7 @@ public: virtual String get_text() const; virtual String get_category() const { return "data"; } - void set_variable(StringName p_var); + void set_variable(StringName p_variable); StringName get_variable() const; virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); @@ -230,7 +230,7 @@ public: virtual String get_text() const; virtual String get_category() const { return "data"; } - void set_variable(StringName p_var); + void set_variable(StringName p_variable); StringName get_variable() const; virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); @@ -301,7 +301,7 @@ public: virtual String get_text() const; virtual String get_category() const { return "data"; } - void set_preload(const Ref<Resource> &p_value); + void set_preload(const Ref<Resource> &p_preload); Ref<Resource> get_preload() const; virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); @@ -727,6 +727,8 @@ public: VisualScriptCustomNode(); }; +VARIANT_ENUM_CAST(VisualScriptCustomNode::StartMode); + class VisualScriptSubCall : public VisualScriptNode { GDCLASS(VisualScriptSubCall, VisualScriptNode) diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 2e111511b7..4b8e17421b 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -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; @@ -189,9 +189,9 @@ void VisualScriptYield::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Frame,FixedFrame,Time", PROPERTY_USAGE_NOEDITOR), "set_yield_mode", "get_yield_mode"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wait_time"), "set_wait_time", "get_wait_time"); - BIND_CONSTANT(YIELD_FRAME); - BIND_CONSTANT(YIELD_FIXED_FRAME); - BIND_CONSTANT(YIELD_WAIT); + BIND_ENUM_CONSTANT(YIELD_FRAME); + BIND_ENUM_CONSTANT(YIELD_FIXED_FRAME); + BIND_ENUM_CONSTANT(YIELD_WAIT); } VisualScriptYield::VisualScriptYield() { @@ -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; @@ -493,9 +490,9 @@ void VisualScriptYieldSignal::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "signal"), "set_signal", "get_signal"); - BIND_CONSTANT(CALL_MODE_SELF); - BIND_CONSTANT(CALL_MODE_NODE_PATH); - BIND_CONSTANT(CALL_MODE_INSTANCE); + BIND_ENUM_CONSTANT(CALL_MODE_SELF); + BIND_ENUM_CONSTANT(CALL_MODE_NODE_PATH); + BIND_ENUM_CONSTANT(CALL_MODE_INSTANCE); } class VisualScriptNodeInstanceYieldSignal : public VisualScriptNodeInstance { @@ -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; diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h index 638b7b5b41..d074962471 100644 --- a/modules/visual_script/visual_script_yield_nodes.h +++ b/modules/visual_script/visual_script_yield_nodes.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ |