From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- modules/visual_script/visual_script_editor.cpp | 200 ------------------------- 1 file changed, 200 deletions(-) (limited to 'modules/visual_script/visual_script_editor.cpp') diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 3649486724..f7e9e30ed6 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -46,7 +46,6 @@ #ifdef TOOLS_ENABLED class VisualScriptEditorSignalEdit : public Object { - GDCLASS(VisualScriptEditorSignalEdit, Object); StringName sig; @@ -62,18 +61,15 @@ protected: } void _sig_changed() { - _change_notify(); emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { - if (sig == StringName()) return false; if (p_name == "argument_count") { - int new_argc = p_value; int argc = script->custom_signal_get_argument_count(sig); if (argc == new_argc) @@ -87,9 +83,7 @@ protected: undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", sig, script->custom_signal_get_argument_name(sig, i), script->custom_signal_get_argument_type(sig, i), -1); } } else if (new_argc > argc) { - for (int i = argc; i < new_argc; i++) { - undo_redo->add_do_method(script.ptr(), "custom_signal_add_argument", sig, Variant::NIL, "arg" + itos(i + 1), -1); undo_redo->add_undo_method(script.ptr(), "custom_signal_remove_argument", sig, argc); } @@ -107,7 +101,6 @@ protected: ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false); String what = String(p_name).get_slice("/", 2); if (what == "type") { - int old_type = script->custom_signal_get_argument_type(sig, idx); int new_type = p_value; undo_redo->create_action(TTR("Change Argument Type")); @@ -119,7 +112,6 @@ protected: } if (what == "name") { - String old_name = script->custom_signal_get_argument_name(sig, idx); String new_name = p_value; undo_redo->create_action(TTR("Change Argument name")); @@ -134,7 +126,6 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - if (sig == StringName()) return false; @@ -159,7 +150,6 @@ protected: return false; } void _get_property_list(List *p_list) const { - if (sig == StringName()) return; @@ -177,7 +167,6 @@ protected: public: void edit(const StringName &p_sig) { - sig = p_sig; _change_notify(); } @@ -186,7 +175,6 @@ public: }; class VisualScriptEditorVariableEdit : public Object { - GDCLASS(VisualScriptEditorVariableEdit, Object); StringName var; @@ -203,18 +191,15 @@ protected: } void _var_changed() { - _change_notify(); emit_signal("changed"); } void _var_value_changed() { - _change_notify("value"); //so the whole tree is not redrawn, makes editing smoother in general emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { - if (var == StringName()) return false; @@ -232,7 +217,6 @@ protected: Dictionary d = script->call("get_variable_info", var); if (String(p_name) == "type") { - Dictionary dc = d.duplicate(); dc["type"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -245,7 +229,6 @@ protected: } if (String(p_name) == "hint") { - Dictionary dc = d.duplicate(); dc["hint"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -258,7 +241,6 @@ protected: } if (String(p_name) == "hint_string") { - Dictionary dc = d.duplicate(); dc["hint_string"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -280,7 +262,6 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - if (var == StringName()) return false; @@ -312,7 +293,6 @@ protected: return false; } void _get_property_list(List *p_list) const { - if (var == StringName()) return; @@ -330,7 +310,6 @@ protected: public: void edit(const StringName &p_var) { - var = p_var; _change_notify(); } @@ -557,7 +536,6 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { } void VisualScriptEditor::_update_graph_connections() { - graph->clear_connections(); List funcs; @@ -569,12 +547,10 @@ void VisualScriptEditor::_update_graph_connections() { } for (List::Element *F = funcs.front(); F; F = F->next()) { - List sequence_conns; script->get_sequence_connection_list(F->get(), &sequence_conns); for (List::Element *E = sequence_conns.front(); E; E = E->next()) { - graph->connect_node(itos(E->get().from_node), E->get().from_output, itos(E->get().to_node), 0); } @@ -582,7 +558,6 @@ void VisualScriptEditor::_update_graph_connections() { script->get_data_connection_list(F->get(), &data_conns); for (List::Element *E = data_conns.front(); E; E = E->next()) { - VisualScript::DataConnection dc = E->get(); Ref from_node = script->get_node(F->get(), E->get().from_node); @@ -600,7 +575,6 @@ void VisualScriptEditor::_update_graph_connections() { } void VisualScriptEditor::_update_graph(int p_only_id) { - if (updating_graph) return; @@ -614,9 +588,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { memdelete(gid); } } else { - for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to(graph->get_child(i))) { memdelete(graph->get_child(i)); i--; @@ -681,7 +653,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { StringName editor_icons = "EditorIcons"; for (List::Element *E = ids.front(); E; E = E->next()) { - if (p_only_id >= 0 && p_only_id != E->get()) continue; @@ -807,12 +778,10 @@ void VisualScriptEditor::_update_graph(int p_only_id) { int mixed_seq_ports = 0; if (!single_seq_output) { - if (node->has_mixed_input_and_sequence_ports()) { mixed_seq_ports = node->get_output_sequence_port_count(); } else { for (int i = 0; i < node->get_output_sequence_port_count(); i++) { - Label *text2 = memnew(Label); text2->set_text(node->get_output_sequence_port_text(i)); text2->set_align(Label::ALIGN_RIGHT); @@ -824,7 +793,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } for (int i = 0; i < MAX(node->get_output_value_port_count(), MAX(mixed_seq_ports, node->get_input_value_port_count())); i++) { - bool left_ok = false; Variant::Type left_type = Variant::NIL; String left_name; @@ -852,7 +820,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { vbc->add_child(hbc); vbc->add_child(hbc2); if (left_ok) { - Ref t; if (left_type >= 0 && left_type < Variant::VARIANT_MAX) { t = type_icons[left_type]; @@ -897,7 +864,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } if (left_type != Variant::NIL && !script->is_input_value_port_connected(F->get(), E->get(), i)) { - PropertyInfo pi = node->get_input_value_port_info(i); Button *button = memnew(Button); Variant value = node->get_default_input_value(i); @@ -913,7 +879,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { button->set_custom_minimum_size(Size2(30, 0) * EDSCALE); button->connect("draw", callable_mp(this, &VisualScriptEditor::_draw_color_over_button), varray(button, value)); } else if (left_type == Variant::OBJECT && Ref(value).is_valid()) { - Ref res = value; Array arr; arr.push_back(button->get_instance_id()); @@ -921,10 +886,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) { EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr); } else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) { - button->set_text(pi.hint_string.get_slice(",", value)); } else { - button->set_text(value); } button->connect("pressed", callable_mp(this, &VisualScriptEditor::_default_value_edited), varray(button, E->get(), i)); @@ -940,7 +903,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { hbc2->add_spacer(); if (i < mixed_seq_ports) { - Label *text2 = memnew(Label); text2->set_text(node->get_output_sequence_port_text(i)); text2->set_align(Label::ALIGN_RIGHT); @@ -948,7 +910,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } if (right_ok) { - if (is_vslist) { Button *rmbtn = memnew(Button); rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons")); @@ -1019,7 +980,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, bool is_input) { - StringName func = _get_function_of_node(p_id); Ref vsn = script->get_node(func, p_id); @@ -1038,7 +998,6 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b } void VisualScriptEditor::_update_node_size(int p_id) { - Node *node = graph->get_node(itos(p_id)); if (Object::cast_to(node)) Object::cast_to(node)->set_size(Vector2(1, 1)); //shrink if text is smaller @@ -1086,7 +1045,6 @@ void VisualScriptEditor::_update_members() { List func_names; script->get_function_list(&func_names); for (List::Element *E = func_names.front(); E; E = E->next()) { - if (E->get() == default_func) { continue; } @@ -1189,7 +1147,6 @@ void VisualScriptEditor::_update_members() { } void VisualScriptEditor::_member_selected() { - if (updating_members) return; @@ -1199,7 +1156,6 @@ void VisualScriptEditor::_member_selected() { selected = ti->get_metadata(0); if (ti->get_parent() == members->get_root()->get_children()) { - #ifdef OSX_ENABLED bool held_ctrl = Input::get_singleton()->is_key_pressed(KEY_META); #else @@ -1213,7 +1169,6 @@ void VisualScriptEditor::_member_selected() { } void VisualScriptEditor::_member_edited() { - if (updating_members) return; @@ -1227,7 +1182,6 @@ void VisualScriptEditor::_member_edited() { return; if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); updating_members = true; ti->set_text(0, name); @@ -1236,7 +1190,6 @@ void VisualScriptEditor::_member_edited() { } if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); updating_members = true; ti->set_text(0, name); @@ -1247,7 +1200,6 @@ void VisualScriptEditor::_member_edited() { TreeItem *root = members->get_root(); if (ti->get_parent() == root->get_children()) { - selected = new_name; int node_id = script->get_function_node_id(name); @@ -1292,7 +1244,6 @@ void VisualScriptEditor::_member_edited() { } if (ti->get_parent() == root->get_children()->get_next()) { - selected = new_name; undo_redo->create_action(TTR("Rename Variable")); undo_redo->add_do_method(script.ptr(), "rename_variable", name, new_name); @@ -1309,7 +1260,6 @@ void VisualScriptEditor::_member_edited() { } if (ti->get_parent() == root->get_children()->get_next()->get_next()) { - selected = new_name; undo_redo->create_action(TTR("Rename Signal")); undo_redo->add_do_method(script.ptr(), "rename_custom_signal", name, new_name); @@ -1431,7 +1381,6 @@ void VisualScriptEditor::_deselect_input_names() { } void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) { - TreeItem *ti = Object::cast_to(p_item); TreeItem *root = members->get_root(); @@ -1446,7 +1395,6 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt return; } else if (p_button == 0) { - String name = _validate_name("new_function"); selected = name; Vector2 ofs = _get_available_pos(); @@ -1514,7 +1462,6 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } void VisualScriptEditor::_add_input_port(int p_id) { - StringName func = _get_function_of_node(p_id); Ref vsn = script->get_node(func, p_id); @@ -1536,7 +1483,6 @@ void VisualScriptEditor::_add_input_port(int p_id) { } void VisualScriptEditor::_add_output_port(int p_id) { - StringName func = _get_function_of_node(p_id); Ref vsn = script->get_node(func, p_id); @@ -1558,7 +1504,6 @@ void VisualScriptEditor::_add_output_port(int p_id) { } void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { - StringName func = _get_function_of_node(p_id); Ref vsn = script->get_node(func, p_id); @@ -1590,7 +1535,6 @@ void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { } void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { - StringName func = _get_function_of_node(p_id); Ref vsn = script->get_node(func, p_id); @@ -1634,7 +1578,6 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { } void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id) { - StringName func = _get_function_of_node(p_id); Ref vse = script->get_node(func, p_id); @@ -1694,12 +1637,10 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const } String VisualScriptEditor::_validate_name(const String &p_name) const { - String valid = p_name; int counter = 1; while (true) { - bool exists = script->has_function(valid) || script->has_variable(valid) || script->has_custom_signal(valid); if (exists) { @@ -1715,7 +1656,6 @@ String VisualScriptEditor::_validate_name(const String &p_name) const { } void VisualScriptEditor::_on_nodes_delete() { - // delete all the selected nodes List to_erase; @@ -1735,7 +1675,6 @@ void VisualScriptEditor::_on_nodes_delete() { undo_redo->create_action(TTR("Remove VisualScript Nodes")); for (List::Element *F = to_erase.front(); F; F = F->next()) { - int cr_node = F->get(); StringName func = _get_function_of_node(cr_node); @@ -1747,7 +1686,6 @@ void VisualScriptEditor::_on_nodes_delete() { script->get_sequence_connection_list(func, &sequence_conns); for (List::Element *E = sequence_conns.front(); E; E = E->next()) { - if (E->get().from_node == cr_node || E->get().to_node == cr_node) { undo_redo->add_undo_method(script.ptr(), "sequence_connect", func, E->get().from_node, E->get().from_output, E->get().to_node); } @@ -1757,7 +1695,6 @@ void VisualScriptEditor::_on_nodes_delete() { script->get_data_connection_list(func, &data_conns); for (List::Element *E = data_conns.front(); E; E = E->next()) { - if (E->get().from_node == F->get() || E->get().to_node == F->get()) { undo_redo->add_undo_method(script.ptr(), "data_connect", func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); } @@ -1770,7 +1707,6 @@ void VisualScriptEditor::_on_nodes_delete() { } void VisualScriptEditor::_on_nodes_duplicate() { - Set to_duplicate; List funcs; @@ -1795,7 +1731,6 @@ void VisualScriptEditor::_on_nodes_duplicate() { HashMap remap; for (Set::Element *F = to_duplicate.front(); F; F = F->next()) { - // duplicate from the specific function but place it into the default func as it would lack the connections StringName func = _get_function_of_node(F->get()); Ref node = script->get_node(func, F->get()); @@ -1884,7 +1819,6 @@ void VisualScriptEditor::_graph_gui_input(const Ref &p_event) { } void VisualScriptEditor::_members_gui_input(const Ref &p_event) { - Ref key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { if (members->has_focus()) { @@ -1920,15 +1854,12 @@ void VisualScriptEditor::_members_gui_input(const Ref &p_event) { } void VisualScriptEditor::_rename_function(const String &name, const String &new_name) { - if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); return; } if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); return; } @@ -1973,7 +1904,6 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_ } void VisualScriptEditor::_fn_name_box_input(const Ref &p_event) { - if (!function_name_edit->is_visible()) return; @@ -1986,9 +1916,7 @@ void VisualScriptEditor::_fn_name_box_input(const Ref &p_event) { } Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - if (p_from == members) { - TreeItem *it = members->get_item_at_position(p_point); if (!it) return Variant(); @@ -2002,15 +1930,12 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f TreeItem *root = members->get_root(); if (it->get_parent() == root->get_children()) { - dd["type"] = "visual_script_function_drag"; dd["function"] = type; } else if (it->get_parent() == root->get_children()->get_next()) { - dd["type"] = "visual_script_variable_drag"; dd["variable"] = type; } else if (it->get_parent() == root->get_children()->get_next()->get_next()) { - dd["type"] = "visual_script_signal_drag"; dd["signal"] = type; @@ -2027,9 +1952,7 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f } bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - if (p_from == graph) { - Dictionary d = p_data; if (d.has("type") && (String(d["type"]) == "visual_script_node_drag" || @@ -2040,9 +1963,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & String(d["type"]) == "resource" || String(d["type"]) == "files" || String(d["type"]) == "nodes")) { - if (String(d["type"]) == "obj_property") { - #ifdef OSX_ENABLED const_cast(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(KEY_META))); #else @@ -2051,7 +1972,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } if (String(d["type"]) == "nodes") { - #ifdef OSX_ENABLED const_cast(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(KEY_META))); #else @@ -2060,7 +1980,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } if (String(d["type"]) == "visual_script_variable_drag") { - #ifdef OSX_ENABLED const_cast(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(KEY_META))); #else @@ -2076,7 +1995,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref