From 7c0051beac315ad9c8896064d24ae362f5a65f7f Mon Sep 17 00:00:00 2001 From: Jaguar Date: Sat, 13 Jun 2015 14:10:06 -0400 Subject: Fixed variables being set before calling the setter method --- modules/gdscript/gd_script.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index ceca1ff2b9..70a5fd985c 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -2131,7 +2131,6 @@ bool GDInstance::set(const StringName& p_name, const Variant& p_value) { { const Map::Element *E = script->member_indices.find(p_name); if (E) { - members[E->get().index]=p_value; if (E->get().setter) { const Variant *val=&p_value; Variant::CallError err; @@ -2140,6 +2139,8 @@ bool GDInstance::set(const StringName& p_name, const Variant& p_value) { return true; //function exists, call was successful } } + else + members[E->get().index] = p_value; return true; } } -- cgit v1.2.3 From e9bbb97acccc08ae03fde41e4cc6d2dc6722021a Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 22 Jun 2015 00:03:19 -0300 Subject: Multiple scene editing *POTENTIALLY UNSTABLE* -ability to edit multiple scenes at the same time -resource internal IDs are now persistent, this makes multiple scene editing possible but maaaaay result in file corruption bugs (tested and could not find anything but possibility exists because core code changed, report immediately if you find this). -properly save settings, layout, etc when edited -script editing is independent from scene editing now -show a yellow box when a script belongs to the scene --- modules/gdscript/gd_editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index f59dbd91d3..0edfd6b9a4 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -1195,7 +1195,7 @@ static void _find_identifiers(GDCompletionContext& context,int p_line,bool p_onl } static const char*_type_names[Variant::VARIANT_MAX]={ - "null","bool","int","float","String","Vector2","Rect2","Vector3","Matrix32","Plane","Quat","AABB","Matrix3","Trasnform", + "null","bool","int","float","String","Vector2","Rect2","Vector3","Matrix32","Plane","Quat","AABB","Matrix3","Transform", "Color","Image","NodePath","RID","Object","InputEvent","Dictionary","Array","RawArray","IntArray","FloatArray","StringArray", "Vector2Array","Vector3Array","ColorArray"}; -- cgit v1.2.3 From d68a33b47383d4c1e0c6cc501d33ce8ce4ed4e8d Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Mon, 22 Jun 2015 10:05:03 -0300 Subject: Grid/Tile map editor new item palette --- modules/gridmap/grid_map_editor_plugin.cpp | 125 +++++++++++++++++------------ modules/gridmap/grid_map_editor_plugin.h | 14 +++- 2 files changed, 84 insertions(+), 55 deletions(-) (limited to 'modules') diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 39f83b806a..8875333307 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -61,7 +61,7 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_CONFIGURE: { - + } break; case MENU_OPTION_LOCK_VIEW: { @@ -706,9 +706,40 @@ struct _CGMEItemSort { }; +void GridMapEditor::_set_display_mode(int p_mode) { + if (display_mode==p_mode) { + return; + } + + if (p_mode == DISPLAY_LIST) { + mode_list->set_pressed(true); + mode_thumbnail->set_pressed(false); + } else if (p_mode == DISPLAY_THUMBNAIL) { + mode_list->set_pressed(false); + mode_thumbnail->set_pressed(true); + } + + display_mode=p_mode; + + update_pallete(); +} + void GridMapEditor::update_pallete() { + int selected = theme_pallete->get_current(); theme_pallete->clear(); + if (display_mode == DISPLAY_THUMBNAIL) { + theme_pallete->set_max_columns(0); + theme_pallete->set_icon_mode(ItemList::ICON_MODE_TOP); + } else if (display_mode == DISPLAY_LIST){ + theme_pallete->set_max_columns(1); + theme_pallete->set_icon_mode(ItemList::ICON_MODE_LEFT); + } + + float min_size = EDITOR_DEF("grid_map/preview_size",64); + theme_pallete->set_min_icon_size(Size2(min_size, min_size)); + theme_pallete->set_fixed_column_width(min_size + 4); + theme_pallete->set_max_text_lines(2); Ref theme = node->get_theme(); @@ -720,10 +751,6 @@ void GridMapEditor::update_pallete() { Vector ids; ids = theme->get_item_list(); - TreeItem *root = theme_pallete->create_item(NULL); - theme_pallete->set_hide_root(true); - TreeItem *selected=NULL; - List<_CGMEItemSort> il; for(int i=0;i::Element *E=il.front();E;E=E->next()) { - int id = E->get().id; - if (col==0) { - ti = theme_pallete->create_item(root); - } + theme_pallete->add_item(""); String name=theme->get_item_name(id); Ref preview = theme->get_item_preview(id); if (!preview.is_null()) { - - ti->set_cell_mode(col,TreeItem::CELL_MODE_ICON); - ti->set_icon(col,preview); - ti->set_tooltip(col,name); - } else { - - ti->set_text(col,name); + theme_pallete->set_item_icon(item, preview); + theme_pallete->set_item_tooltip(item, name); } - ti->set_metadata(col,id); - - if (selected_pallete==id) { - selected=ti; - selected_col=col; + if (name!="") { + theme_pallete->set_item_text(item,name); } + theme_pallete->set_item_metadata(item, id); - col++; - if (col==theme_pallete->get_columns()) - col=0; - + item++; } - if (selected) - selected->select(selected_col); + if (selected!=-1) { + theme_pallete->select(selected); + } last_theme=theme.operator->(); } @@ -842,6 +855,9 @@ void GridMapEditor::edit(GridMap *p_gridmap) { VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,false); } + + VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance, VS::INSTANCE_FLAG_VISIBLE,false); + _clear_areas(); return; @@ -951,7 +967,7 @@ void GridMapEditor::update_grid() { grid_xform.origin.x-=1; //force update in hackish way.. what do i care - VS *vs = VS::get_singleton(); + //VS *vs = VS::get_singleton(); grid_ofs[edit_axis]=edit_floor[edit_axis]*node->get_cell_size(); @@ -976,7 +992,7 @@ void GridMapEditor::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { - theme_pallete->connect("cell_selected", this,"_item_selected_cbk"); + 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"); @@ -1014,7 +1030,7 @@ void GridMapEditor::_notification(int p_what) { if (xf!=grid_xform) { for(int i=0;i<3;i++) { - + VS::get_singleton()->instance_set_transform(grid_instance[i],xf * edit_grid_xform); } grid_xform=xf; @@ -1063,18 +1079,8 @@ void GridMapEditor::_update_cursor_instance() { } -void GridMapEditor::_item_selected_cbk() { - - TreeItem *it = theme_pallete->get_selected(); - if (it) { - - selected_pallete=it->get_metadata(theme_pallete->get_selected_column()); - - } else { - - selected_pallete=-1; - - } +void GridMapEditor::_item_selected_cbk(int idx) { + selected_pallete=theme_pallete->get_item_metadata(idx); _update_cursor_instance(); @@ -1179,7 +1185,7 @@ void GridMapEditor::_bind_methods() { ObjectTypeDB::bind_method("_area_selected",&GridMapEditor::_area_selected); ObjectTypeDB::bind_method("_floor_changed",&GridMapEditor::_floor_changed); - + ObjectTypeDB::bind_method(_MD("_set_display_mode","mode"), &GridMapEditor::_set_display_mode); } @@ -1240,6 +1246,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { clip_mode=CLIP_DISABLED; options->get_popup()->connect("item_pressed", this,"_menu_option"); + HBoxContainer *hb = memnew( HBoxContainer ); + add_child(hb); + hb->set_h_size_flags(SIZE_EXPAND_FILL); edit_mode = memnew(OptionButton); edit_mode->set_area_as_parent_rect(); @@ -1247,13 +1256,27 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14);; edit_mode->add_item("Tiles"); edit_mode->add_item("Areas"); - add_child(edit_mode); - + 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); + mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail","EditorIcons")); + hb->add_child(mode_thumbnail); + mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL)); + + mode_list = memnew( ToolButton ); + mode_list->set_toggle_mode(true); + mode_list->set_pressed(false); + mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons")); + hb->add_child(mode_list); + mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST)); + + display_mode = DISPLAY_THUMBNAIL; selected_area=-1; - - theme_pallete = memnew( Tree ); - theme_pallete->set_columns(3); + theme_pallete = memnew( ItemList ); add_child(theme_pallete); theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index 716ef66f0d..26fe8f20dc 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -40,10 +40,8 @@ class SpatialEditorPlugin; class GridMapEditor : public VBoxContainer { - OBJ_TYPE(GridMapEditor, VBoxContainer ); - enum { GRID_CURSOR_SIZE=50 @@ -66,6 +64,10 @@ class GridMapEditor : public VBoxContainer { CLIP_BELOW }; + enum DisplayMode { + DISPLAY_THUMBNAIL, + DISPLAY_LIST + }; UndoRedo *undo_redo; InputAction input_action; @@ -73,6 +75,8 @@ class GridMapEditor : public VBoxContainer { MenuButton * options; SpinBox *floor; OptionButton *edit_mode; + ToolButton *mode_thumbnail; + ToolButton *mode_list; HBoxContainer *spatial_editor_hb; struct SetItem { @@ -132,6 +136,7 @@ class GridMapEditor : public VBoxContainer { Vector3 cursor_origin; Vector3 last_mouseover; + int display_mode; int selected_pallete; int selected_area; int cursor_rot; @@ -183,9 +188,10 @@ class GridMapEditor : public VBoxContainer { void _configure(); void _menu_option(int); void update_pallete(); - Tree *theme_pallete; + void _set_display_mode(int p_mode); + ItemList *theme_pallete; Tree *area_list; - void _item_selected_cbk(); + void _item_selected_cbk(int idx); void _update_cursor_transform(); void _update_cursor_instance(); void _update_clip(); -- cgit v1.2.3 From 0159cecd6950a11853c243d09867ad20d8ac5cec Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Mon, 22 Jun 2015 11:10:13 -0300 Subject: Small fixes for Grid/Tile map editor palette --- modules/gridmap/grid_map_editor_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 8875333307..40dd0603fb 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -738,7 +738,7 @@ void GridMapEditor::update_pallete() { float min_size = EDITOR_DEF("grid_map/preview_size",64); theme_pallete->set_min_icon_size(Size2(min_size, min_size)); - theme_pallete->set_fixed_column_width(min_size + 4); + theme_pallete->set_fixed_column_width(min_size*3/2); theme_pallete->set_max_text_lines(2); Ref theme = node->get_theme(); -- cgit v1.2.3 From faf8b410b1e5b48ee5210e06c81cf3f4edb6469d Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Tue, 23 Jun 2015 12:07:17 -0300 Subject: Fix for issue related to GridMap editor * closes #2102 --- modules/gridmap/grid_map_editor_plugin.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 40dd0603fb..3d56b04cac 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -522,7 +522,9 @@ void GridMapEditor::_duplicate_paste() { } bool GridMapEditor::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) { - + if (!node) { + return false; + } if (edit_mode->get_selected()==0) { // regular click switch (p_event.type) { @@ -1059,7 +1061,9 @@ void GridMapEditor::_notification(int p_what) { } void GridMapEditor::_update_cursor_instance() { - + if (!node) { + return; + } if (cursor_instance.is_valid()) VisualServer::get_singleton()->free(cursor_instance); @@ -1098,7 +1102,9 @@ void GridMapEditor::_clear_areas() { } void GridMapEditor::_update_areas_display() { - + if (!node) { + return; + } _clear_areas(); List areas; -- cgit v1.2.3 From 48f1d02da4795ba9d485fe5fe2bea907be2fc467 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 24 Jun 2015 13:29:23 -0300 Subject: added ability to define signals in script closes #2175 --- modules/gdscript/gd_compiler.cpp | 40 ++++++++++++++++------ modules/gdscript/gd_parser.cpp | 71 ++++++++++++++++++++++++++++++++++----- modules/gdscript/gd_parser.h | 7 ++++ modules/gdscript/gd_script.cpp | 48 ++++++++++++++++++++++++++ modules/gdscript/gd_script.h | 4 +++ modules/gdscript/gd_tokenizer.cpp | 1 + modules/gdscript/gd_tokenizer.h | 1 + 7 files changed, 154 insertions(+), 18 deletions(-) (limited to 'modules') diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index b405555ec6..a62225f663 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -28,15 +28,6 @@ /*************************************************************************/ #include "gd_compiler.h" #include "gd_script.h" -/* TODO: - - *AND and OR need early abort - -Inheritance properly process (done?) - *create built in initializer and constructor - *assign operators - *build arrays and dictionaries - *call parent constructor - */ void GDCompiler::_set_error(const String& p_error,const GDParser::Node *p_node) { @@ -1397,13 +1388,14 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars int index_from=0; + Ref native; if (p_class->extends_used) { //do inheritance String path = p_class->extends_file; Ref script; - Ref native; + if (path!="") { //path (and optionally subclasses) @@ -1573,7 +1565,35 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars //p_script->constants[constant->value].make_const(); } + for(int i=0;i_signals.size();i++) { + + StringName name = p_class->_signals[i].name; + + GDScript *c = p_script; + while(c) { + + if (c->_signals.has(name)) { + _set_error("Signal '"+name+"' redefined (in current or parent class)",p_class); + return ERR_ALREADY_EXISTS; + } + + if (c->base.is_valid()) { + c=c->base.ptr(); + } else { + c=NULL; + } + } + + if (native.is_valid()) { + if (ObjectTypeDB::has_signal(native->get_name(),name)) { + _set_error("Signal '"+name+"' redefined (original in native class '"+String(native->get_name())+"')",p_class); + return ERR_ALREADY_EXISTS; + } + } + + p_script->_signals[name]=p_class->_signals[i].arguments; + } //parse sub-classes for(int i=0;isubclasses.size();i++) { diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 6242400663..71af9ab10d 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1520,8 +1520,10 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { op->arguments.push_back(assigned); p_block->statements.push_back(op); - _end_statement(); - + if (!_end_statement()) { + _set_error("Expected end of statement (var)"); + return; + } } break; case GDTokenizer::TK_CF_IF: { @@ -1946,8 +1948,10 @@ void GDParser::_parse_class(ClassNode *p_class) { _parse_extends(p_class); if (error_set) return; - _end_statement(); - + if (!_end_statement()) { + _set_error("Expected end of statement after extends"); + return; + } } break; case GDTokenizer::TK_PR_TOOL: { @@ -2227,6 +2231,53 @@ void GDParser::_parse_class(ClassNode *p_class) { //arguments } break; + case GDTokenizer::TK_PR_SIGNAL: { + tokenizer->advance(); + + if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) { + _set_error("Expected identifier after 'signal'."); + return; + } + + ClassNode::Signal sig; + sig.name = tokenizer->get_token_identifier(); + tokenizer->advance(); + + + if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_OPEN) { + tokenizer->advance(); + while(true) { + + + if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) { + tokenizer->advance(); + break; + } + + if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) { + _set_error("Expected identifier in signal argument."); + return; + } + + sig.arguments.push_back(tokenizer->get_token_identifier()); + tokenizer->advance(); + + if (tokenizer->get_token()==GDTokenizer::TK_COMMA) { + tokenizer->advance(); + } else if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) { + _set_error("Expected ',' or ')' after signal parameter identifier."); + return; + } + } + } + + p_class->_signals.push_back(sig); + + if (!_end_statement()) { + _set_error("Expected end of statement (signal)"); + return; + } + } break; case GDTokenizer::TK_PR_EXPORT: { tokenizer->advance(); @@ -2644,8 +2695,10 @@ void GDParser::_parse_class(ClassNode *p_class) { p_class->variables.push_back(member); - _end_statement(); - + if (!_end_statement()) { + _set_error("Expected end of statement (continue)"); + return; + } } break; case GDTokenizer::TK_PR_CONST: { //variale declaration and (eventual) initialization @@ -2682,8 +2735,10 @@ void GDParser::_parse_class(ClassNode *p_class) { p_class->constant_expressions.push_back(constant); - _end_statement(); - + if (!_end_statement()) { + _set_error("Expected end of statement (constant)"); + return; + } } break; diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index bf2c8c9ef2..fd5c0802ea 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -76,6 +76,7 @@ public: StringName extends_file; Vector extends_class; + struct Member { PropertyInfo _export; #ifdef TOOLS_ENABLED @@ -92,11 +93,17 @@ public: Node *expression; }; + struct Signal { + StringName name; + Vector arguments; + }; + Vector subclasses; Vector variables; Vector constant_expressions; Vector functions; Vector static_functions; + Vector _signals; BlockNode *initializer; ClassNode *owner; //Vector initializers; diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 70a5fd985c..b6ad7aa716 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1756,6 +1756,12 @@ bool GDScript::_update_exports() { //print_line("found "+c->variables[i]._export.name); member_default_values_cache[c->variables[i].identifier]=c->variables[i].default_value; } + + _signals.clear(); + + for(int i=0;i_signals.size();i++) { + _signals[c->_signals[i].name]=c->_signals[i].arguments; + } } } else { //print_line("unchaged is "+get_path()); @@ -2100,6 +2106,47 @@ Ref GDScript::get_base() const { return base; } +bool GDScript::has_script_signal(const StringName& p_signal) const { + if (_signals.has(p_signal)) + return true; + if (base.is_valid()) { + return base->has_script_signal(p_signal); + } +#ifdef TOOLS_ENABLED + else if (base_cache.is_valid()){ + return base_cache->has_script_signal(p_signal); + } + +#endif + return false; +} +void GDScript::get_script_signal_list(List *r_signals) const { + + for(const Map >::Element *E=_signals.front();E;E=E->next()) { + + MethodInfo mi; + mi.name=E->key(); + for(int i=0;iget().size();i++) { + PropertyInfo arg; + arg.name=E->get()[i]; + mi.arguments.push_back(arg); + } + r_signals->push_back(mi); + } + + if (base.is_valid()) { + base->get_script_signal_list(r_signals); + } +#ifdef TOOLS_ENABLED + else if (base_cache.is_valid()){ + base_cache->get_script_signal_list(r_signals); + } + +#endif + +} + + GDScript::GDScript() { @@ -2594,6 +2641,7 @@ void GDScriptLanguage::get_reserved_words(List *p_words) const { "static", "float", "int", + "signal", 0}; diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index f505d51ba4..4672f3b8be 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -260,6 +260,7 @@ friend class GDScriptLanguage; Map member_functions; Map member_indices; //members are just indices to the instanced script. Map > subclasses; + Map > _signals; #ifdef TOOLS_ENABLED @@ -318,6 +319,9 @@ public: const Map& get_member_functions() const { return member_functions; } const Ref& get_native() const { return native; } + virtual bool has_script_signal(const StringName& p_signal) const; + virtual void get_script_signal_list(List *r_signals) const; + bool is_tool() const { return tool; } Ref get_base() const; diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 0745baafe6..656a015c66 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -856,6 +856,7 @@ void GDTokenizerText::_advance() { {TK_PR_PRELOAD,"preload"}, {TK_PR_ASSERT,"assert"}, {TK_PR_YIELD,"yield"}, + {TK_PR_SIGNAL,"signal"}, {TK_PR_CONST,"const"}, //controlflow {TK_CF_IF,"if"}, diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index b63687d2b4..d6bd63c5b8 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -104,6 +104,7 @@ public: TK_PR_PRELOAD, TK_PR_ASSERT, TK_PR_YIELD, + TK_PR_SIGNAL, TK_BRACKET_OPEN, TK_BRACKET_CLOSE, TK_CURLY_BRACKET_OPEN, -- cgit v1.2.3 From a67486a39ee629acac068a6d014015944cf83bb3 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 26 Jun 2015 01:14:31 -0300 Subject: improved get_node(), connect(), etc code completion. -properly completes text arguments -includes the "/root" autoloads --- modules/gdscript/gd_editor.cpp | 26 ++++++++++++++++++++++++-- modules/gdscript/gd_parser.cpp | 21 +++++++++++++++++++-- modules/gdscript/gd_parser.h | 3 ++- modules/gdscript/gd_tokenizer.cpp | 33 ++++++++++++++++++--------------- 4 files changed, 63 insertions(+), 20 deletions(-) (limited to 'modules') diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 0edfd6b9a4..c374f509c0 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -381,7 +381,12 @@ static Ref _get_parent_class(GDCompletionContext& context) { path=context.base_path.plus_file(path); } - script = ResourceLoader::load(path); + + if (ScriptCodeCompletionCache::get_sigleton()) + script = ScriptCodeCompletionCache::get_sigleton()->get_cached_resource(path); + else + script = ResourceLoader::load(path); + if (script.is_null()) { return REF(); } @@ -1322,6 +1327,21 @@ static void _find_type_arguments(const GDParser::Node*p_node,int p_line,const St if (obj) { List options; obj->get_argument_options(p_method,p_argidx,&options); + if (obj->is_type("Node") && p_argidx==0 && (String(p_method)=="get_node" || String(p_method)=="has_node")) { + + List props; + Globals::get_singleton()->get_property_list(&props); + + for(List::Element *E=props.front();E;E=E->next()) { + + String s = E->get().name; + if (!s.begins_with("autoload/")) + continue; + // print_line("found "+s); + String name = s.get_slice("/",1); + options.push_back("\"/root/"+name+"\""); + } + } for(List::Element *E=options.front();E;E=E->next()) { result.insert(E->get()); @@ -1661,7 +1681,9 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base //print_line( p_code.replace(String::chr(0xFFFF),"")); GDParser p; - Error err = p.parse(p_code,p_base_path,true); + //Error parse(const String& p_code, const String& p_base_path="", bool p_just_validate=false,const String& p_self_path="",bool p_for_completion=false); + + Error err = p.parse(p_code,p_base_path,false,"",true); bool isfunction=false; Set options; diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 71af9ab10d..afe8c9aa71 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -30,6 +30,7 @@ #include "print_string.h" #include "io/resource_loader.h" #include "os/file_access.h" +#include "script_language.h" template T* GDParser::alloc_node() { @@ -116,6 +117,14 @@ bool GDParser::_parse_arguments(Node* p_parent,Vector& p_args,bool p_stat if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) { _make_completable_call(argidx); completion_node=p_parent; + } else if (tokenizer->get_token()==GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type()==Variant::STRING && tokenizer->get_token(1)==GDTokenizer::TK_CURSOR) { + //completing a string argument.. + completion_cursor=tokenizer->get_token_constant(); + + _make_completable_call(argidx); + completion_node=p_parent; + tokenizer->advance(1); + return false; } Node*arg = _parse_expression(p_parent,p_static); @@ -277,7 +286,11 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ if (!validating) { //this can be too slow for just validating code - res = ResourceLoader::load(path); + if (for_completion && ScriptCodeCompletionCache::get_sigleton()) { + res = ScriptCodeCompletionCache::get_sigleton()->get_cached_resource(path); + } else { + res = ResourceLoader::load(path); + } if (!res.is_valid()) { _set_error("Can't preload resource at path: "+path); return NULL; @@ -2814,6 +2827,8 @@ Error GDParser::_parse(const String& p_base_path) { Error GDParser::parse_bytecode(const Vector &p_bytecode,const String& p_base_path, const String &p_self_path) { + for_completion=false; + validating=false; completion_type=COMPLETION_NONE; completion_node=NULL; completion_class=NULL; @@ -2834,7 +2849,7 @@ Error GDParser::parse_bytecode(const Vector &p_bytecode,const String& p } -Error GDParser::parse(const String& p_code, const String& p_base_path, bool p_just_validate, const String &p_self_path) { +Error GDParser::parse(const String& p_code, const String& p_base_path, bool p_just_validate, const String &p_self_path,bool p_for_completion) { completion_type=COMPLETION_NONE; completion_node=NULL; @@ -2851,6 +2866,7 @@ Error GDParser::parse(const String& p_code, const String& p_base_path, bool p_ju tt->set_code(p_code); validating=p_just_validate; + for_completion=p_for_completion; tokenizer=tt; Error ret = _parse(p_base_path); memdelete(tt); @@ -2886,6 +2902,7 @@ void GDParser::clear() { current_function=NULL; validating=false; + for_completion=false; error_set=false; tab_level.clear(); tab_level.push_back(0); diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index fd5c0802ea..fd8a2576fa 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -387,6 +387,7 @@ private: T* alloc_node(); bool validating; + bool for_completion; int parenthesis; bool error_set; String error; @@ -443,7 +444,7 @@ public: String get_error() const; int get_error_line() const; int get_error_column() const; - Error parse(const String& p_code, const String& p_base_path="", bool p_just_validate=false,const String& p_self_path=""); + Error parse(const String& p_code, const String& p_base_path="", bool p_just_validate=false,const String& p_self_path="",bool p_for_completion=false); Error parse_bytecode(const Vector &p_bytecode,const String& p_base_path="",const String& p_self_path=""); const Node *get_parse_tree() const; diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 656a015c66..2844edfddc 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -568,7 +568,10 @@ void GDTokenizerText::_advance() { } else if( string_mode!=STRING_MULTILINE && CharType(GETCHAR(i))=='\n') { _make_error("Unexpected EOL at String."); return; - + } else if( CharType(GETCHAR(i))==0xFFFF) { + //string ends here, next will be TK + i--; + break; } else if (CharType(GETCHAR(i))=='\\') { //escaped characters... i++; @@ -670,19 +673,19 @@ void GDTokenizerText::_advance() { while(true) { if (GETCHAR(i)=='.') { if (period_found || exponent_found) { - _make_error("Invalid numeric constant at '.'"); + _make_error("Invalid numeric constant at '.'"); return; } period_found=true; } else if (GETCHAR(i)=='x') { - if (hexa_found || str.length()!=1 || !( (i==1 && str[0]=='0') || (i==2 && str[1]=='0' && str[0]=='-') ) ) { - _make_error("Invalid numeric constant at 'x'"); + if (hexa_found || str.length()!=1 || !( (i==1 && str[0]=='0') || (i==2 && str[1]=='0' && str[0]=='-') ) ) { + _make_error("Invalid numeric constant at 'x'"); return; } hexa_found=true; - } else if (!hexa_found && GETCHAR(i)=='e') { + } else if (!hexa_found && GETCHAR(i)=='e') { if (hexa_found || exponent_found) { - _make_error("Invalid numeric constant at 'e'"); + _make_error("Invalid numeric constant at 'e'"); return; } exponent_found=true; @@ -692,7 +695,7 @@ void GDTokenizerText::_advance() { } else if ((GETCHAR(i)=='-' || GETCHAR(i)=='+') && exponent_found) { if (sign_found) { - _make_error("Invalid numeric constant at '-'"); + _make_error("Invalid numeric constant at '-'"); return; } sign_found=true; @@ -703,20 +706,20 @@ void GDTokenizerText::_advance() { i++; } - if (!( _is_number(str[str.length()-1]) || (hexa_found && _is_hex(str[str.length()-1])))) { - _make_error("Invalid numeric constant: "+str); + if (!( _is_number(str[str.length()-1]) || (hexa_found && _is_hex(str[str.length()-1])))) { + _make_error("Invalid numeric constant: "+str); return; } INCPOS(str.length()); - if (hexa_found) { - int val = str.hex_to_int(); - _make_constant(val); - } else if (period_found) { + if (hexa_found) { + int val = str.hex_to_int(); + _make_constant(val); + } else if (period_found) { real_t val = str.to_double(); //print_line("*%*%*%*% to convert: "+str+" result: "+rtos(val)); _make_constant(val); - } else { + } else { int val = str.to_int(); _make_constant(val); @@ -825,7 +828,7 @@ void GDTokenizerText::_advance() { _make_built_in_func(GDFunctions::Function(i)); found=true; - break; + break; } } -- cgit v1.2.3 From 2b64f73b0459190d20b2f6de39275ee7979317c4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 27 Jun 2015 15:52:39 -0300 Subject: more code completion improvements -calltip dissapears with more types of keypresses or when pressing ')' -properly looks into autoloaded scripts or nodes with another script for script functions/variables/etc. --- modules/gdscript/gd_editor.cpp | 546 ++++++++++++++++++++++++++++++++------ modules/gdscript/gd_tokenizer.cpp | 2 +- 2 files changed, 465 insertions(+), 83 deletions(-) (limited to 'modules') diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index c374f509c0..7cb9882f3a 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -29,6 +29,7 @@ #include "gd_script.h" #include "gd_compiler.h" #include "globals.h" +#include "os/file_access.h" void GDScriptLanguage::get_comment_delimiters(List *p_delimiters) const { @@ -238,26 +239,26 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level,List *p if (_debug_parse_err_line>=0) return; - ERR_FAIL_INDEX(p_level,_debug_call_stack_pos); - int l = _debug_call_stack_pos - p_level -1; + ERR_FAIL_INDEX(p_level,_debug_call_stack_pos); + int l = _debug_call_stack_pos - p_level -1; - GDInstance *instance = _call_stack[l].instance; + GDInstance *instance = _call_stack[l].instance; - if (!instance) - return; + if (!instance) + return; - Ref script = instance->get_script(); - ERR_FAIL_COND( script.is_null() ); + Ref script = instance->get_script(); + ERR_FAIL_COND( script.is_null() ); - const Map& mi = script->debug_get_member_indices(); + const Map& mi = script->debug_get_member_indices(); - for(const Map::Element *E=mi.front();E;E=E->next()) { + for(const Map::Element *E=mi.front();E;E=E->next()) { - p_members->push_back(E->key()); - p_values->push_back( instance->debug_get_member_by_index(E->get().index)); - } + p_members->push_back(E->key()); + p_values->push_back( instance->debug_get_member_by_index(E->get().index)); + } } void GDScriptLanguage::debug_get_globals(List *p_locals, List *p_values, int p_max_subitems,int p_max_depth) { @@ -317,6 +318,7 @@ String GDScriptLanguage::make_function(const String& p_class,const String& p_nam struct GDCompletionIdentifier { StringName obj_type; + Ref script; Variant::Type type; Variant value; //im case there is a value, also return it }; @@ -446,7 +448,7 @@ static Ref _get_parent_class(GDCompletionContext& context) { base_class=base_class->subclasses[subclass]; } else { - print_line("Could not find subclass: "+subclass); + //print_line("Could not find subclass: "+subclass); return _get_type_from_class(context); //fail please } } @@ -631,7 +633,9 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser:: //try calling the function if constant and all args are constant, should not crash.. Object *baseptr = base.value; - if (baseptr && mb->is_const() && pi.type==Variant::OBJECT) { + + if (mb->is_const() && pi.type==Variant::OBJECT) { + bool all_valid=true; Vector args; for(int i=2;iarguments.size();i++) { @@ -648,25 +652,88 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser:: all_valid=false; } } - if (all_valid) { - Vector argptr; - for(int i=0;icall(baseptr,argptr.ptr(),argptr.size(),ce); + if (all_valid && String(id)=="get_node" && ObjectTypeDB::is_type(base.obj_type,"Node") && args.size()) { + + String arg1=args[0]; + if (arg1.begins_with("/root/")) { + String which = arg1.get_slice("/",2); + if (which!="") { + List props; + Globals::get_singleton()->get_property_list(&props); + //print_line("find singleton"); + + for(List::Element *E=props.front();E;E=E->next()) { + + String s = E->get().name; + if (!s.begins_with("autoload/")) + continue; + //print_line("found "+s); + String name = s.get_slice("/",1); + //print_line("name: "+name+", which: "+which); + if (name==which) { + String script = Globals::get_singleton()->get(s); + if (!script.begins_with("res://")) { + script="res://"+script; + } - if (ce.error==Variant::CallError::CALL_OK && ret.get_type()!=Variant::NIL) { + if (!script.ends_with(".gd")) { + //not a script, try find the script anyway, + //may have some success + script=script.basename()+".gd"; + } - if (ret.get_type()!=Variant::OBJECT || ret.operator Object*()!=NULL) { + if (FileAccess::exists(script)) { - r_type=_get_type_from_variant(ret); - return true; + //print_line("is a script"); + + + Ref