/*************************************************************************/ /* visual_script_property_selector.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "visual_script_property_selector.h" #include "../visual_script.h" #include "../visual_script_builtin_funcs.h" #include "../visual_script_flow_control.h" #include "../visual_script_func_nodes.h" #include "../visual_script_nodes.h" #include "core/os/keyboard.h" #include "editor/doc_tools.h" #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" #include "scene/main/node.h" #include "scene/main/window.h" void VisualScriptPropertySelector::_update_icons() { search_box->set_right_icon(results_tree->get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); search_box->set_clear_button_enabled(true); search_box->add_theme_icon_override("right_icon", results_tree->get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); search_visual_script_nodes->set_icon(results_tree->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons"))); search_classes->set_icon(results_tree->get_theme_icon(SNAME("Object"), SNAME("EditorIcons"))); search_methods->set_icon(results_tree->get_theme_icon(SNAME("MemberMethod"), SNAME("EditorIcons"))); search_operators->set_icon(results_tree->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); search_signals->set_icon(results_tree->get_theme_icon(SNAME("MemberSignal"), SNAME("EditorIcons"))); search_constants->set_icon(results_tree->get_theme_icon(SNAME("MemberConstant"), SNAME("EditorIcons"))); search_properties->set_icon(results_tree->get_theme_icon(SNAME("MemberProperty"), SNAME("EditorIcons"))); search_theme_items->set_icon(results_tree->get_theme_icon(SNAME("MemberTheme"), SNAME("EditorIcons"))); case_sensitive_button->set_icon(results_tree->get_theme_icon(SNAME("MatchCase"), SNAME("EditorIcons"))); hierarchy_button->set_icon(results_tree->get_theme_icon(SNAME("ClassList"), SNAME("EditorIcons"))); } void VisualScriptPropertySelector::_sbox_input(const Ref &p_ie) { Ref k = p_ie; if (k.is_valid()) { switch (k->get_keycode()) { case Key::UP: case Key::DOWN: case Key::PAGEUP: case Key::PAGEDOWN: { results_tree->gui_input(k); search_box->accept_event(); } break; default: break; } } } void VisualScriptPropertySelector::_update_results_i(int p_int) { _update_results(); } void VisualScriptPropertySelector::_update_results_s(String p_string) { _update_results(); } void VisualScriptPropertySelector::_update_results() { _update_icons(); search_runner = Ref(memnew(SearchRunner(this, results_tree))); set_process(true); } void VisualScriptPropertySelector::_confirmed() { TreeItem *ti = results_tree->get_selected(); if (!ti) { return; } emit_signal(SNAME("selected"), ti->get_metadata(0), ti->get_metadata(1), connecting); set_visible(false); } void VisualScriptPropertySelector::_item_selected() { if (results_tree->get_selected()->has_meta("description")) { help_bit->set_text(results_tree->get_selected()->get_meta("description")); } else { help_bit->set_text("No description available"); } } void VisualScriptPropertySelector::_hide_requested() { _cancel_pressed(); // From AcceptDialog. } void VisualScriptPropertySelector::_notification(int p_what) { switch (p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { _update_icons(); } break; case NOTIFICATION_ENTER_TREE: { connect("confirmed", callable_mp(this, &VisualScriptPropertySelector::_confirmed)); } break; case NOTIFICATION_PROCESS: { // Update background search. if (search_runner.is_valid()) { if (search_runner->work()) { // Search done. get_ok_button()->set_disabled(!results_tree->get_selected()); search_runner = Ref(); set_process(false); } } else { // if one is valid set_process(false); } } break; } } void VisualScriptPropertySelector::select_method_from_base_type(const String &p_base, const bool p_virtuals_only, const bool p_connecting, bool clear_text) { set_title(TTR("Select method from base type")); base_type = p_base; base_script = ""; type = Variant::NIL; connecting = p_connecting; if (clear_text) { if (p_virtuals_only) { search_box->set_text("._"); // show all _methods search_box->set_caret_column(2); } else { search_box->set_text("."); // show all methods search_box->set_caret_column(1); } } search_visual_script_nodes->set_pressed(false); search_classes->set_pressed(false); search_methods->set_pressed(true); search_operators->set_pressed(false); search_signals->set_pressed(false); search_constants->set_pressed(false); search_properties->set_pressed(false); search_theme_items->set_pressed(false); scope_combo->select(2); //id0 = "Search Related" //id2 = "Search Base" //id3 = "Search Inheriters" //id4 = "Search Unrelated" results_tree->clear(); show_window(.5f); search_box->grab_focus(); _update_results(); } void VisualScriptPropertySelector::select_from_base_type(const String &p_base, const String &p_base_script, bool p_virtuals_only, const bool p_connecting, bool clear_text) { set_title(TTR("Select from base type")); base_type = p_base; base_script = p_base_script.lstrip("res://").quote(); // filepath to EditorHelp::get_doc_data().name type = Variant::NIL; connecting = p_connecting; if (clear_text) { if (p_virtuals_only) { search_box->set_text("_"); } else { search_box->set_text(" "); } } search_box->select_all(); search_visual_script_nodes->set_pressed(false); search_classes->set_pressed(false); search_methods->set_pressed(true); search_operators->set_pressed(false); search_signals->set_pressed(true); search_constants->set_pressed(false); search_properties->set_pressed(true); search_theme_items->set_pressed(false); // When class is Input only show inheritors scope_combo->select(0); //id0 = "Search Related" //id2 = "Search Base" //id3 = "Search Inheriters" //id4 = "Search Unrelated" results_tree->clear(); show_window(.5f); search_box->grab_focus(); _update_results(); } void VisualScriptPropertySelector::select_from_script(const Ref