diff options
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 1 | ||||
-rw-r--r-- | editor/editor_node.cpp | 27 | ||||
-rw-r--r-- | editor/editor_node.h | 1 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 28 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.h | 1 | ||||
-rw-r--r-- | modules/gdscript/gd_editor.cpp | 53 |
6 files changed, 64 insertions, 47 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index c9e9dacdb5..c1504593cb 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1971,7 +1971,6 @@ FRAGMENT_SHADER_CODE #ifdef SHADELESS - frag_color=vec4(albedo,alpha); diffuse_buffer=vec4(albedo.rgb,0.0); specular_buffer=vec4(0.0); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index f724cba3ef..c376efca34 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -56,7 +56,6 @@ #include "editor/editor_help.h" #include "editor/editor_initialize_ssl.h" #include "editor/editor_settings.h" -#include "editor/editor_settings.h" #include "editor/editor_themes.h" #include "editor/import/editor_import_collada.h" #include "editor/import/editor_scene_importer_gltf.h" @@ -972,26 +971,6 @@ void EditorNode::_dialog_action(String p_file) { //would be nice to show the project manager opened with the highlighted field.. _run(false, ""); // automatically run the project } break; - case FILE_RUN_SCRIPT: { - - Ref<Script> scr = ResourceLoader::load(p_file, "Script", true); - if (scr.is_null()) { - add_io_error("Script Failed to Load:\n" + p_file); - return; - } - if (!scr->is_tool()) { - - add_io_error("Script is not tool, will not be able to run:\n" + p_file); - return; - } - - Ref<EditorScript> es = memnew(EditorScript); - es->set_script(scr.get_ref_ptr()); - es->set_editor(this); - es->_run(); - - get_undo_redo()->clear_history(); - } break; case FILE_CLOSE: case FILE_CLOSE_ALL_AND_QUIT: case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: @@ -1652,10 +1631,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { quick_open->set_title(TTR("Quick Open Script..")); } break; - case FILE_RUN_SCRIPT: { - - file_script->popup_centered_ratio(); - } break; case FILE_OPEN_PREV: { if (previous_scenes.empty()) @@ -4806,7 +4781,7 @@ EditorNode::EditorNode() { p->add_item(TTR("Project Settings"), RUN_SETTINGS); p->add_separator(); p->connect("id_pressed", this, "_menu_option"); - p->add_item(TTR("Run Script"), FILE_RUN_SCRIPT, KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_R); + //p->add_item(TTR("Run Script"), FILE_RUN_SCRIPT, KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_R); p->add_item(TTR("Export"), FILE_EXPORT_PROJECT); PopupMenu *tool_menu = memnew(PopupMenu); diff --git a/editor/editor_node.h b/editor/editor_node.h index 985f5cd894..08c7e11c85 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -129,7 +129,6 @@ private: FILE_OPEN_OLD_SCENE, FILE_QUICK_OPEN_SCENE, FILE_QUICK_OPEN_SCRIPT, - FILE_RUN_SCRIPT, FILE_OPEN_PREV, FILE_CLOSE, FILE_CLOSE_ALL_AND_QUIT, diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 316c76e4b2..6f35ca1b0c 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -965,7 +965,33 @@ void ScriptEditor::_menu_option(int p_option) { current->reload(p_option == FILE_TOOL_RELOAD_SOFT); } break; + case FILE_RUN: { + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) { + EditorNode::get_singleton()->show_warning("Can't obtain the script for running"); + break; + } + if (!scr->is_tool()) { + + EditorNode::get_singleton()->show_warning("Script is not in tool mode, will not be able to run"); + return; + } + + if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) { + + EditorNode::get_singleton()->show_warning("To run this script, it must inherit EditorScript and be set to tool mode"); + return; + } + + Ref<EditorScript> es = memnew(EditorScript); + es->set_script(scr.get_ref_ptr()); + es->set_editor(EditorNode::get_singleton()); + + es->_run(); + + EditorNode::get_undo_redo()->clear_history(); + } break; case FILE_CLOSE: { if (current->is_unsaved()) { _ask_close_current_unsaved_tab(current); @@ -2220,6 +2246,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL); file_menu->get_popup()->add_separator(); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/run_file", TTR("Run"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_X), FILE_RUN); + file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/toggle_scripts_panel", TTR("Toggle Scripts Panel"), KEY_MASK_CMD | KEY_BACKSLASH), TOGGLE_SCRIPTS_PANEL); file_menu->get_popup()->connect("id_pressed", this, "_menu_option"); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 17209de681..d2677c6a4a 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -131,6 +131,7 @@ class ScriptEditor : public PanelContainer { FILE_RELOAD_THEME, FILE_SAVE_THEME, FILE_SAVE_THEME_AS, + FILE_RUN, FILE_CLOSE, CLOSE_DOCS, CLOSE_ALL, diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index b0a18b4b4b..02fab6d17f 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -365,7 +365,7 @@ struct GDCompletionIdentifier { Variant value; //im case there is a value, also return it }; -static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant) { +static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant, bool p_allow_gdnative_class = false) { GDCompletionIdentifier t; t.type = p_variant.get_type(); @@ -373,14 +373,14 @@ static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant) { if (p_variant.get_type() == Variant::OBJECT) { Object *obj = p_variant; if (obj) { - /* - if (Object::cast_to<GDNativeClass>(obj)) { - t.obj_type=Object::cast_to<GDNativeClass>(obj)->get_name(); - t.value=Variant(); + + if (p_allow_gdnative_class && Object::cast_to<GDNativeClass>(obj)) { + t.obj_type = Object::cast_to<GDNativeClass>(obj)->get_name(); + t.value = Variant(); } else { - */ - t.obj_type = obj->get_class(); - //} + + t.obj_type = obj->get_class(); + } } } return t; @@ -513,9 +513,9 @@ static GDCompletionIdentifier _get_native_class(GDCompletionContext &context) { return id; } -static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type); +static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type, bool p_for_indexing); -static bool _guess_expression_type(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, GDCompletionIdentifier &r_type) { +static bool _guess_expression_type(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, GDCompletionIdentifier &r_type, bool p_for_indexing = false) { if (p_node->type == GDParser::Node::TYPE_CONSTANT) { @@ -566,7 +566,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: return true; } else if (p_node->type == GDParser::Node::TYPE_IDENTIFIER) { - return _guess_identifier_type(context, p_line - 1, static_cast<const GDParser::IdentifierNode *>(p_node)->name, r_type); + return _guess_identifier_type(context, p_line - 1, static_cast<const GDParser::IdentifierNode *>(p_node)->name, r_type, p_for_indexing); } else if (p_node->type == GDParser::Node::TYPE_SELF) { //eeh... @@ -812,23 +812,38 @@ 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 base_type = p1.obj_type; + + if (p1.obj_type == "GDNativeClass") { + //native enum + Ref<GDNativeClass> gdn = p1.value; + if (gdn.is_valid()) { + + base_type = gdn->get_name(); + } + } StringName index = p2.value; bool valid; - Variant::Type t = ClassDB::get_property_type(p1.obj_type, index, &valid); + Variant::Type t = ClassDB::get_property_type(base_type, index, &valid); if (t != Variant::NIL && valid) { r_type.type = t; - if (t == Variant::INT) { + if (t == Variant::INT || t == Variant::OBJECT) { //check for enum! #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) - StringName getter = ClassDB::get_property_getter(p1.obj_type, index); + StringName getter = ClassDB::get_property_getter(base_type, index); if (getter != StringName()) { - MethodBind *mb = ClassDB::get_method(p1.obj_type, getter); + MethodBind *mb = ClassDB::get_method(base_type, getter); if (mb) { PropertyInfo rt = mb->get_return_info(); - if (rt.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { + if (rt.usage & PROPERTY_USAGE_CLASS_IS_ENUM && t == Variant::INT) { r_type.enumeration = rt.class_name; + } else if (t == Variant::OBJECT) { + + r_type.obj_type = rt.class_name; } } } @@ -1056,7 +1071,7 @@ static bool _guess_identifier_from_assignment_in_function(GDCompletionContext &c return false; } -static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type) { +static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type, bool p_for_indexing) { //go to block first @@ -1210,7 +1225,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con for (Map<StringName, int>::Element *E = GDScriptLanguage::get_singleton()->get_global_map().front(); E; E = E->next()) { if (E->key() == p_identifier) { - r_type = _get_type_from_variant(GDScriptLanguage::get_singleton()->get_global_array()[E->get()]); + r_type = _get_type_from_variant(GDScriptLanguage::get_singleton()->get_global_array()[E->get()], !p_for_indexing); return true; } } @@ -2082,7 +2097,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base break; GDCompletionIdentifier t; - if (_guess_expression_type(context, static_cast<const GDParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t)) { + if (_guess_expression_type(context, static_cast<const GDParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t, true)) { if (t.type == Variant::OBJECT && t.obj_type == "GDNativeClass") { //native enum |