From 282c3924663128f6a2b7ecd86772b01a1b4c82f0 Mon Sep 17 00:00:00 2001 From: tommy3 Date: Thu, 14 May 2015 23:50:15 +0200 Subject: [PATCH 01/23] set initial flag 'show_hidden_files' for file dialogs in project manager initialization --- scene/gui/file_dialog.cpp | 2 +- tools/editor/project_manager.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 13cf87ac2b..285de269b9 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -692,7 +692,7 @@ void FileDialog::set_default_show_hidden_files(bool p_show) { FileDialog::FileDialog() { - show_hidden_files=true; + show_hidden_files=default_show_hidden_files; VBoxContainer *vbc = memnew( VBoxContainer ); add_child(vbc); diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp index 00956919b7..f1eecd53b0 100644 --- a/tools/editor/project_manager.cpp +++ b/tools/editor/project_manager.cpp @@ -819,6 +819,7 @@ ProjectManager::ProjectManager() { if (!EditorSettings::get_singleton()) EditorSettings::create(); + FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files")); set_area_as_parent_rect(); Panel *panel = memnew( Panel ); From b459bc549698c9358050030519c487abb6882d8e Mon Sep 17 00:00:00 2001 From: Peace Sells Date: Sun, 24 May 2015 01:04:26 -0600 Subject: [PATCH 02/23] Setting build vs properties in scons. --- SConstruct | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SConstruct b/SConstruct index 11b35e0b4b..a1a3238305 100644 --- a/SConstruct +++ b/SConstruct @@ -360,6 +360,11 @@ if selected_platform in platform_list: AddToVSProject(env.scene_sources) AddToVSProject(env.servers_sources) AddToVSProject(env.tool_sources) + + #env['MSVS_VERSION']='9.0' + env['MSVSBUILDCOM'] = "scons platform=" + selected_platform + " target=" + env["target"] + " bits=" + env["bits"] + " tools=yes" + env['MSVSREBUILDCOM'] = "scons platform=" + selected_platform + " target=" + env["target"] + " bits=" + env["bits"] + " tools=yes" + env['MSVSCLEANCOM'] = "scons platform=" + selected_platform + " target=" + env["target"] + " bits=" + env["bits"] + " tools=yes" debug_variants = ['Debug|Win32']+['Debug|x64'] release_variants = ['Release|Win32']+['Release|x64'] From 5ffa3f4ff01352fe047cffeddc8681e71af264fc Mon Sep 17 00:00:00 2001 From: volzhs Date: Wed, 10 Jun 2015 02:23:47 +0900 Subject: [PATCH 03/23] add bind method for create_from_fnt (load fnt made by BMFont) --- scene/resources/font.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index a598c69089..44fa7eadbd 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -510,6 +510,7 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ void Font::_bind_methods() { + ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt); ObjectTypeDB::bind_method(_MD("set_height","px"),&Font::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Font::get_height); From 9bee9e7498c701f7dfbb0f68b69272143216693f Mon Sep 17 00:00:00 2001 From: volzhs Date: Wed, 10 Jun 2015 02:25:34 +0900 Subject: [PATCH 04/23] add bind method for create_from_fnt (load fnt made by BMFont) --- scene/resources/font.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 44fa7eadbd..2d93113b40 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -510,7 +510,7 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ void Font::_bind_methods() { - ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt); + ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt); ObjectTypeDB::bind_method(_MD("set_height","px"),&Font::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Font::get_height); From 394276c45f4e1b256d6450a3ae7341368ace5fca Mon Sep 17 00:00:00 2001 From: krzycho Date: Thu, 11 Jun 2015 04:36:11 +0200 Subject: [PATCH 05/23] ColorRamp new features: - hold alt and left-click to duplicate color - hold shift while grabbing color node to snap selected one to the nearest one if close enough --- scene/gui/color_ramp_edit.cpp | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index 382c0dc103..c39893ac97 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -73,6 +73,31 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) { } } + //Hold alt key to duplicate selected color + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed && p_event.key.mod.alt ) { + + int x = p_event.mouse_button.x; + grabbed=_get_point_from_pos(x); + + if( grabbed != -1 ) { + int total_w = get_size().width-get_size().height-3; + ColorRamp::Point newPoint = points[grabbed]; + newPoint.offset=CLAMP(x/float(total_w),0,1); + + points.push_back(newPoint); + points.sort(); + for(int i=0;i Date: Thu, 11 Jun 2015 05:18:13 +0200 Subject: [PATCH 06/23] founded and fixed a bug that freezed godot when deleting while grabbing color in ColorRamp --- scene/gui/color_ramp_edit.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index c39893ac97..14a48fe3d3 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -48,6 +48,7 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) { points.remove(grabbed); grabbed=-1; + grabbing=false; update(); emit_signal("ramp_changed"); accept_event(); @@ -67,6 +68,7 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) { { points.remove(grabbed); grabbed=-1; + grabbing=false; update(); emit_signal("ramp_changed"); accept_event(); From 2287d030a25d8c52d1ebe2303794d6cfa740e6a0 Mon Sep 17 00:00:00 2001 From: krzycho Date: Thu, 11 Jun 2015 14:39:50 +0200 Subject: [PATCH 07/23] fixed problem with crashing godot when changing number of steps while no animation added --- tools/editor/animation_editor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/editor/animation_editor.cpp b/tools/editor/animation_editor.cpp index bb6f7e9a6f..d431af6c8d 100644 --- a/tools/editor/animation_editor.cpp +++ b/tools/editor/animation_editor.cpp @@ -3319,7 +3319,8 @@ void AnimationKeyEditor::_insert_delay() { void AnimationKeyEditor::_step_changed(float p_len) { updating=true; - animation->set_step(p_len); + if (!animation.is_null()) + animation->set_step(p_len); updating=false; } From 5a0de04eb739606a49ba828634c051c0e7552291 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Sat, 13 Jun 2015 14:43:12 +0300 Subject: [PATCH 08/23] Resolved a merge conflict. --- demos/2d/motion/engine.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/demos/2d/motion/engine.cfg b/demos/2d/motion/engine.cfg index 29c4d0da20..261111904c 100644 --- a/demos/2d/motion/engine.cfg +++ b/demos/2d/motion/engine.cfg @@ -3,12 +3,9 @@ name="Motion Test" main_scene="res://motion.scn" -<<<<<<< HEAD -======= [display] width=800 height=600 stretch_mode="2d" stretch_aspect="keep" ->>>>>>> ab99671bb835a5fe24a092ec34afe1ad862ac254 From 852bf95c0c531ec1b0821dbfdb1c6f4744b8324d Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Sat, 13 Jun 2015 14:47:22 +0300 Subject: [PATCH 09/23] Delete .fscache from fog_of_war demo, closes #2079. --- demos/2d/fog_of_war/.fscache | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 demos/2d/fog_of_war/.fscache diff --git a/demos/2d/fog_of_war/.fscache b/demos/2d/fog_of_war/.fscache deleted file mode 100644 index ba5e3995f3..0000000000 --- a/demos/2d/fog_of_war/.fscache +++ /dev/null @@ -1,11 +0,0 @@ -::res://::1422910453 -floor.png::ImageTexture::1422910453:: -fog.gd::GDScript::1422910025:: -fog.png::ImageTexture::1422908128:: -fog.scn::PackedScene::1422909435:: -fog.xml::TileSet::1422909324:: -icon.png::ImageTexture::1422811193:: -tile_edit.scn::PackedScene::1422909313:: -troll.gd::GDScript::1422909940:: -troll.png::ImageTexture::1418669358:: -troll.scn::PackedScene::1418669358:: From 7c0051beac315ad9c8896064d24ae362f5a65f7f Mon Sep 17 00:00:00 2001 From: Jaguar Date: Sat, 13 Jun 2015 14:10:06 -0400 Subject: [PATCH 10/23] Fixed variables being set before calling the setter method --- modules/gdscript/gd_script.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } } From 839d69502c5c1769c662bb353e0f6db3517e2de2 Mon Sep 17 00:00:00 2001 From: volzhs Date: Mon, 15 Jun 2015 08:57:14 +0900 Subject: [PATCH 11/23] fix register Physics2DTestMotionResult --- servers/register_server_types.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index d35b6e1e5f..3634a03dbc 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -55,7 +55,7 @@ void register_server_types() { ObjectTypeDB::register_virtual_type(); ObjectTypeDB::register_virtual_type(); ObjectTypeDB::register_virtual_type(); - ObjectTypeDB::register_virtual_type(); + ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); From 14cd70faf3b9e431821613b06397973f047cbfc0 Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Tue, 16 Jun 2015 15:15:10 +0800 Subject: [PATCH 12/23] Script editor: restore line/column after script reload --- tools/editor/plugins/script_editor_plugin.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index f5ba6a08e6..c04f74475c 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -286,8 +286,19 @@ void ScriptTextEditor::reload_text() { ERR_FAIL_COND(script.is_null()) ; - get_text_edit()->set_text(script->get_source_code()); - get_text_edit()->clear_undo_history(); + TextEdit *te = get_text_edit(); + int column = te->cursor_get_column(); + int row = te->cursor_get_line(); + int h = te->get_h_scroll(); + int v = te->get_v_scroll(); + + te->set_text(script->get_source_code()); + te->clear_undo_history(); + te->cursor_set_line(row); + te->cursor_set_column(column); + te->set_h_scroll(h); + te->set_v_scroll(v); + _line_col_changed(); } From aa4211d47773f7b2f3f20dad0166f9e30ff4c6d4 Mon Sep 17 00:00:00 2001 From: Peace Sells Date: Fri, 19 Jun 2015 21:40:38 -0600 Subject: [PATCH 13/23] Hide projects folder. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index fbb3ba6cb4..613eff442a 100644 --- a/.gitignore +++ b/.gitignore @@ -281,3 +281,5 @@ cscope.out cscope.in.out cscope.po.out godot.creator.* + +projects/ \ No newline at end of file From acbaefcc0274e17fc25736f0d7c6cd7feb176129 Mon Sep 17 00:00:00 2001 From: Guido Berhoerster Date: Sat, 20 Jun 2015 14:47:06 +0200 Subject: [PATCH 14/23] Fix typo that produced invalid markup for images --- tools/export/blender25/io_scene_dae/export_dae.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/export/blender25/io_scene_dae/export_dae.py b/tools/export/blender25/io_scene_dae/export_dae.py index 9568ccb645..5245f32b82 100644 --- a/tools/export/blender25/io_scene_dae/export_dae.py +++ b/tools/export/blender25/io_scene_dae/export_dae.py @@ -228,7 +228,7 @@ class DaeExporter: # imgpath="images/"+image.name+".png" self.writel(S_IMGS,1,'') - self.writel(S_IMGS,2,''+imgpath+'"/>') + self.writel(S_IMGS,2,''+imgpath+'') self.writel(S_IMGS,1,'') self.image_cache[image]=imgid return imgid From 6edbab0a9fed4a3ea9988b4054c42ce96a43d143 Mon Sep 17 00:00:00 2001 From: Peace Sells Date: Sun, 24 May 2015 01:04:26 -0600 Subject: [PATCH 15/23] Setting build vs properties in scons. --- SConstruct | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SConstruct b/SConstruct index 11b35e0b4b..a1a3238305 100644 --- a/SConstruct +++ b/SConstruct @@ -360,6 +360,11 @@ if selected_platform in platform_list: AddToVSProject(env.scene_sources) AddToVSProject(env.servers_sources) AddToVSProject(env.tool_sources) + + #env['MSVS_VERSION']='9.0' + env['MSVSBUILDCOM'] = "scons platform=" + selected_platform + " target=" + env["target"] + " bits=" + env["bits"] + " tools=yes" + env['MSVSREBUILDCOM'] = "scons platform=" + selected_platform + " target=" + env["target"] + " bits=" + env["bits"] + " tools=yes" + env['MSVSCLEANCOM'] = "scons platform=" + selected_platform + " target=" + env["target"] + " bits=" + env["bits"] + " tools=yes" debug_variants = ['Debug|Win32']+['Debug|x64'] release_variants = ['Release|Win32']+['Release|x64'] From d65455185a2e72bbbf5aaa8943643a49cd811fce Mon Sep 17 00:00:00 2001 From: krzycho Date: Sun, 21 Jun 2015 21:55:47 +0200 Subject: [PATCH 16/23] - added GDscript bidings for UndoRedo class mechanizm - registered UndoRedo --- core/undo_redo.cpp | 120 +++++++++++++++++++++++++++++++++++ core/undo_redo.h | 7 ++ doc/base/classes.xml | 2 +- tools/editor/editor_node.cpp | 1 + 4 files changed, 129 insertions(+), 1 deletion(-) diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 5e7df3be7e..a93e469f3f 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -339,3 +339,123 @@ UndoRedo::~UndoRedo() { clear_history(); } + +Variant UndoRedo::_add_do_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { + + if (p_argcount<1) { + r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument=0; + return Variant(); + } + + if (p_args[0]->get_type()!=Variant::OBJECT) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::OBJECT; + return Variant(); + } + + if (p_args[1]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=1; + r_error.expected=Variant::STRING; + return Variant(); + } + + r_error.error=Variant::CallError::CALL_OK; + + Object* object = *p_args[0]; + String method = *p_args[1]; + + Variant v[VARIANT_ARG_MAX]; + + + for(int i=0;iget_type()!=Variant::OBJECT) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::OBJECT; + return Variant(); + } + + if (p_args[1]->get_type()!=Variant::STRING) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=1; + r_error.expected=Variant::STRING; + return Variant(); + } + + r_error.error=Variant::CallError::CALL_OK; + + Object* object = *p_args[0]; + String method = *p_args[1]; + + Variant v[VARIANT_ARG_MAX]; + + + for(int i=0;i defargs; + for(int i=0;i defargs; + for(int i=0;i - + diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 373c8aba73..ce96e0b6f5 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -3236,6 +3236,7 @@ void EditorNode::register_editor_types() { ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); //ObjectTypeDB::register_type(); From fafcc52d1cdf13a57fad613944109169b3be5594 Mon Sep 17 00:00:00 2001 From: krzycho Date: Mon, 22 Jun 2015 14:42:52 +0200 Subject: [PATCH 17/23] added some missing biddings --- core/undo_redo.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index a93e469f3f..bb001c9f73 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -458,4 +458,7 @@ void UndoRedo::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_undo_property","object", "property", "value"),&UndoRedo::add_undo_property); ObjectTypeDB::bind_method(_MD("add_do_reference","object"),&UndoRedo::add_do_reference); ObjectTypeDB::bind_method(_MD("add_undo_reference","object"),&UndoRedo::add_undo_reference); + ObjectTypeDB::bind_method(_MD("clear_history"),&UndoRedo::clear_history); + ObjectTypeDB::bind_method(_MD("get_current_action_name"),&UndoRedo::get_current_action_name); + ObjectTypeDB::bind_method(_MD("get_version"),&UndoRedo::get_version); } \ No newline at end of file From d68a33b47383d4c1e0c6cc501d33ce8ce4ed4e8d Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Mon, 22 Jun 2015 10:05:03 -0300 Subject: [PATCH 18/23] Grid/Tile map editor new item palette --- modules/gridmap/grid_map_editor_plugin.cpp | 123 +++++++++++------- modules/gridmap/grid_map_editor_plugin.h | 14 +- .../editor/plugins/tile_map_editor_plugin.cpp | 123 +++++++++++++----- tools/editor/plugins/tile_map_editor_plugin.h | 11 +- 4 files changed, 180 insertions(+), 91 deletions(-) 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(); diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp index 5c82973da4..7d5f2669aa 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.cpp +++ b/tools/editor/plugins/tile_map_editor_plugin.cpp @@ -71,22 +71,19 @@ void TileMapEditor::_canvas_mouse_exit() { } int TileMapEditor::get_selected_tile() const { - - TreeItem *item = palette->get_selected(); - if (!item) + int item = palette->get_current(); + if (item==-1) return TileMap::INVALID_CELL; - return item->get_metadata(0); + return palette->get_item_metadata(item); } void TileMapEditor::set_selected_tile(int p_tile) { - TreeItem *item = palette->get_root()->get_children(); - while (item) { - if ((int)item->get_metadata(0) == p_tile) { - item->select(0); - palette->ensure_cursor_is_visible(); - break; - } - item = item->get_next(); + for (int i = 0; i < palette->get_item_count(); i++) { + if (palette->get_item_metadata(i).operator int() == p_tile) { + palette->select(i,true); + palette->ensure_current_is_visible(); + break; + } } } @@ -95,7 +92,7 @@ void TileMapEditor::_set_cell_shortened(const Point2& p_pos,int p_value,bool p_f ERR_FAIL_COND(!node); node->set_cell(floor(p_pos.x), floor(p_pos.y), p_value, p_flip_h, p_flip_v, p_transpose); } - + void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bool p_flip_v, bool p_transpose,bool p_with_undo) { ERR_FAIL_COND(!node); @@ -120,42 +117,77 @@ void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bo } +void TileMapEditor::_set_display_mode(int p_mode) { + if (display_mode == p_mode) { + return; + } + + switch (p_mode) { + case DISPLAY_THUMBNAIL: { + button_thumbnail->set_pressed(true); + button_list->set_pressed(false); + } break; + case DISPLAY_LIST: { + button_thumbnail->set_pressed(false); + button_list->set_pressed(true); + } break; + } + + display_mode = p_mode; + + _update_palette(); +} + void TileMapEditor::_update_palette() { if (!node) return; - palette->clear();; + palette->clear(); Ref tileset=node->get_tileset(); if (!tileset.is_valid()) return; - - TreeItem *root = palette->create_item(); - palette->set_hide_root(true); List tiles; tileset->get_tile_list(&tiles); + if (display_mode == DISPLAY_THUMBNAIL) { + palette->set_max_columns(0); + palette->set_icon_mode(ItemList::ICON_MODE_TOP); + } else if (display_mode == DISPLAY_LIST) { + palette->set_max_columns(1); + palette->set_icon_mode(ItemList::ICON_MODE_LEFT); + } + + palette->set_max_text_lines(2); + for(List::Element *E=tiles.front();E;E=E->next()) { + palette->add_item(""); - TreeItem *tile = palette->create_item(root); - - tile->set_icon_max_width(0,64); Ref tex = tileset->tile_get_texture(E->get()); + if (tex.is_valid()) { - tile->set_icon(0,tex); Rect2 region = tileset->tile_get_region(E->get()); - if (region!=Rect2()) - tile->set_icon_region(0,region); - } else if (tileset->tile_get_name(E->get())!="") - tile->set_text(0,tileset->tile_get_name(E->get())); - else - tile->set_text(0,"#"+itos(E->get())); + if (region==Rect2()) { + continue; + } - tile->set_metadata(0,E->get()); + Image data = VS::get_singleton()->texture_get_data(tex->get_rid()); + Ref img = memnew( ImageTexture ); + img->create_from_image(data.get_rect(region)); + + palette->set_item_icon(palette->get_item_count()-1, img); + } + + if (tileset->tile_get_name(E->get())!="") { + palette->set_item_text(palette->get_item_count()-1, tileset->tile_get_name(E->get())); + } else { + palette->set_item_text(palette->get_item_count()-1, "#"+itos(E->get())); + } + palette->set_item_metadata(palette->get_item_count()-1, E->get()); } } @@ -387,7 +419,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { } if (tool==TOOL_ERASING) { - Point2i local =over_tile; + Point2i local =over_tile; if (!paint_undo.has(over_tile)) { paint_undo[over_tile]=_get_op_from_cell(over_tile); } @@ -641,7 +673,7 @@ void TileMapEditor::_canvas_draw() { Ref t = ts->tile_get_texture(st); if (t.is_valid()) { Vector2 from = node->map_to_world(over_tile)+node->get_cell_draw_offset(); - Rect2 r = ts->tile_get_region(st); + Rect2 r = ts->tile_get_region(st); Size2 sc = xform.get_scale(); if (mirror_x->is_pressed()) sc.x*=-1.0; @@ -755,7 +787,7 @@ void TileMapEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_tileset_settings_changed"),&TileMapEditor::_tileset_settings_changed); ObjectTypeDB::bind_method(_MD("_update_transform_buttons"),&TileMapEditor::_update_transform_buttons); ObjectTypeDB::bind_method(_MD("_set_cell_shortened","pos","tile","flip_x","flip_y","transpose"),&TileMapEditor::_set_cell_shortened,DEFVAL(false),DEFVAL(false),DEFVAL(false)); - + ObjectTypeDB::bind_method(_MD("_set_display_mode","mode"),&TileMapEditor::_set_display_mode); } TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i& p_pos) @@ -777,7 +809,7 @@ void TileMapEditor::_update_transform_buttons(Object *p_button) { //ERR_FAIL_NULL(p_button); ToolButton *b=p_button->cast_to(); //ERR_FAIL_COND(!b); - + mirror_x->set_block_signals(true); mirror_y->set_block_signals(true); transpose->set_block_signals(true); @@ -785,7 +817,7 @@ void TileMapEditor::_update_transform_buttons(Object *p_button) { rotate_90->set_block_signals(true); rotate_180->set_block_signals(true); rotate_270->set_block_signals(true); - + if (b == rotate_0) { mirror_x->set_pressed(false); mirror_y->set_pressed(false); @@ -806,7 +838,7 @@ void TileMapEditor::_update_transform_buttons(Object *p_button) { mirror_y->set_pressed(true); transpose->set_pressed(true); } - + rotate_0->set_pressed(!mirror_x->is_pressed() && !mirror_y->is_pressed() && !transpose->is_pressed()); rotate_90->set_pressed(mirror_x->is_pressed() && !mirror_y->is_pressed() && transpose->is_pressed()); rotate_180->set_pressed(mirror_x->is_pressed() && mirror_y->is_pressed() && !transpose->is_pressed()); @@ -833,8 +865,27 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { ec->set_custom_minimum_size(Size2(mw,0)); add_child(ec); + HBoxContainer *hb = memnew( HBoxContainer ); + add_child(hb); + hb->set_h_size_flags(SIZE_EXPAND_FILL); + hb->add_spacer(true); + + button_thumbnail = memnew( ToolButton ); + button_thumbnail->set_toggle_mode(true); + button_thumbnail->set_pressed(true); + button_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail","EditorIcons")); + hb->add_child(button_thumbnail); + button_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL)); + + button_list = memnew( ToolButton ); + button_list->set_toggle_mode(true); + button_list->set_pressed(false); + button_list->set_icon(p_editor->get_gui_base()->get_icon("FileList","EditorIcons")); + hb->add_child(button_list); + button_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST)); + // Add tile palette - palette = memnew( Tree ); + palette = memnew( ItemList ); palette->set_v_size_flags(SIZE_EXPAND_FILL); add_child(palette); @@ -886,7 +937,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { rotate_270->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_270)); canvas_item_editor_hb->add_child(rotate_270); canvas_item_editor_hb->hide(); - + rotate_0->set_pressed(true); tool=TOOL_NONE; selection_active=false; diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h index eaa5c256d7..74d1573d0f 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.h +++ b/tools/editor/plugins/tile_map_editor_plugin.h @@ -55,10 +55,18 @@ class TileMapEditor : public VBoxContainer { TOOL_PICKING }; + enum DisplayMode { + DISPLAY_THUMBNAIL, + DISPLAY_LIST + }; + Tool tool; Control *canvas_item_editor; - Tree *palette; + int display_mode; + ItemList *palette; + ToolButton *button_thumbnail; + ToolButton *button_list; EditorNode *editor; Panel *panel; TileMap *node; @@ -95,6 +103,7 @@ class TileMapEditor : public VBoxContainer { int get_selected_tile() const; void set_selected_tile(int p_tile); + void _set_display_mode(int p_mode); void _update_palette(); void _canvas_draw(); void _menu_option(int p_option); From 0159cecd6950a11853c243d09867ad20d8ac5cec Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Mon, 22 Jun 2015 11:10:13 -0300 Subject: [PATCH 19/23] Small fixes for Grid/Tile map editor palette --- modules/gridmap/grid_map_editor_plugin.cpp | 2 +- .../editor/plugins/tile_map_editor_plugin.cpp | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) 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(); diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp index 7d5f2669aa..017a26441d 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.cpp +++ b/tools/editor/plugins/tile_map_editor_plugin.cpp @@ -79,11 +79,11 @@ int TileMapEditor::get_selected_tile() const { void TileMapEditor::set_selected_tile(int p_tile) { for (int i = 0; i < palette->get_item_count(); i++) { - if (palette->get_item_metadata(i).operator int() == p_tile) { - palette->select(i,true); - palette->ensure_current_is_visible(); - break; - } + if (palette->get_item_metadata(i).operator int() == p_tile) { + palette->select(i,true); + palette->ensure_current_is_visible(); + break; + } } } @@ -170,16 +170,16 @@ void TileMapEditor::_update_palette() { if (tex.is_valid()) { Rect2 region = tileset->tile_get_region(E->get()); - if (region==Rect2()) { - continue; + if (!region.has_no_area()) { + Image data = VS::get_singleton()->texture_get_data(tex->get_rid()); + + Ref img = memnew( ImageTexture ); + img->create_from_image(data.get_rect(region)); + + palette->set_item_icon(palette->get_item_count()-1, img); + } else { + palette->set_item_icon(palette->get_item_count()-1,tex); } - - Image data = VS::get_singleton()->texture_get_data(tex->get_rid()); - - Ref img = memnew( ImageTexture ); - img->create_from_image(data.get_rect(region)); - - palette->set_item_icon(palette->get_item_count()-1, img); } if (tileset->tile_get_name(E->get())!="") { @@ -187,6 +187,7 @@ void TileMapEditor::_update_palette() { } else { palette->set_item_text(palette->get_item_count()-1, "#"+itos(E->get())); } + palette->set_item_metadata(palette->get_item_count()-1, E->get()); } } From 956e0a85640bedd0ec7e23311cd3cf131bb3ffb7 Mon Sep 17 00:00:00 2001 From: Guilherme Felipe Date: Mon, 22 Jun 2015 14:07:26 -0300 Subject: [PATCH 20/23] Add .editorconfig --- .editorconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..e19057f0e8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = tab + +[.travis.yml] +indent_style = space +indent_size = 2 From 0805e83e59a5dd245176f3ced93cf5f637496bc8 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 22 Jun 2015 23:44:13 -0300 Subject: [PATCH 21/23] small in place fixes --- core/undo_redo.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 53b7078b39..f565070216 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -343,7 +343,7 @@ UndoRedo::~UndoRedo() { Variant UndoRedo::_add_do_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { - if (p_argcount<1) { + if (p_argcount<2) { r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument=0; return Variant(); @@ -382,7 +382,7 @@ Variant UndoRedo::_add_do_method(const Variant** p_args, int p_argcount, Variant Variant UndoRedo::_add_undo_method(const Variant** p_args, int p_argcount, Variant::CallError& r_error) { - if (p_argcount<1) { + if (p_argcount<2) { r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument=0; return Variant(); @@ -455,11 +455,11 @@ void UndoRedo::_bind_methods() { ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"add_undo_method",&UndoRedo::_add_undo_method,mi,defargs); } - ObjectTypeDB::bind_method(_MD("add_do_property","object", "property", "value"),&UndoRedo::add_do_property); - ObjectTypeDB::bind_method(_MD("add_undo_property","object", "property", "value"),&UndoRedo::add_undo_property); + ObjectTypeDB::bind_method(_MD("add_do_property","object", "property", "value:var"),&UndoRedo::add_do_property); + ObjectTypeDB::bind_method(_MD("add_undo_property","object", "property", "value:var"),&UndoRedo::add_undo_property); ObjectTypeDB::bind_method(_MD("add_do_reference","object"),&UndoRedo::add_do_reference); ObjectTypeDB::bind_method(_MD("add_undo_reference","object"),&UndoRedo::add_undo_reference); ObjectTypeDB::bind_method(_MD("clear_history"),&UndoRedo::clear_history); ObjectTypeDB::bind_method(_MD("get_current_action_name"),&UndoRedo::get_current_action_name); ObjectTypeDB::bind_method(_MD("get_version"),&UndoRedo::get_version); -} \ No newline at end of file +} From faf8b410b1e5b48ee5210e06c81cf3f4edb6469d Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Tue, 23 Jun 2015 12:07:17 -0300 Subject: [PATCH 22/23] Fix for issue related to GridMap editor * closes #2102 --- modules/gridmap/grid_map_editor_plugin.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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; From 5688b6157fc4c85719db3d3a6b8b5246738d82be Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Tue, 23 Jun 2015 12:20:34 -0300 Subject: [PATCH 23/23] CollisionShape2D visual editor --- tools/editor/editor_node.cpp | 2 + .../collision_shape_2d_editor_plugin.cpp | 533 ++++++++++++++++++ .../collision_shape_2d_editor_plugin.h | 73 +++ 3 files changed, 608 insertions(+) create mode 100644 tools/editor/plugins/collision_shape_2d_editor_plugin.cpp create mode 100644 tools/editor/plugins/collision_shape_2d_editor_plugin.h diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index f55a3d6894..a513451b48 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -92,6 +92,7 @@ #include "plugins/navigation_polygon_editor_plugin.h" #include "plugins/light_occluder_2d_editor_plugin.h" #include "plugins/color_ramp_editor_plugin.h" +#include "plugins/collision_shape_2d_editor_plugin.h" // end #include "tools/editor/io_plugins/editor_texture_import_plugin.h" #include "tools/editor/io_plugins/editor_scene_import_plugin.h" @@ -5051,6 +5052,7 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( LightOccluder2DEditorPlugin(this) ) ); add_editor_plugin( memnew( NavigationPolygonEditorPlugin(this) ) ); add_editor_plugin( memnew( ColorRampEditorPlugin(this) ) ); + add_editor_plugin( memnew( CollisionShape2DEditorPlugin(this) ) ); for(int i=0;i capsule = node->get_shape(); + + if (idx==0) { + return capsule->get_radius(); + } else if (idx==1) { + return capsule->get_height(); + } + + } break; + + case CIRCLE_SHAPE: { + Ref circle = node->get_shape(); + + if (idx==0) { + return circle->get_radius(); + } + + } break; + + case CONCAVE_POLYGON_SHAPE: { + + } break; + + case CONVEX_POLYGON_SHAPE: { + + } break; + + case LINE_SHAPE: { + + } break; + + case RAY_SHAPE: { + Ref ray = node->get_shape(); + + if (idx==0) { + return ray->get_length(); + } + + } break; + + case RECTANGLE_SHAPE: { + Ref rect = node->get_shape(); + + if (idx<2) { + return rect->get_extents().abs(); + } + + } break; + + case SEGMENT_SHAPE: { + Ref seg = node->get_shape(); + + if (idx==0) { + return seg->get_a(); + } else if (idx==1) { + return seg->get_b(); + } + + } break; + } + + return Variant(); +} + +void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) { + + switch ( shape_type ) { + case CAPSULE_SHAPE: { + if (idx < 2) { + Ref capsule = node->get_shape(); + + real_t parameter = Math::abs(p_point[idx]); + + if (idx==0) { + capsule->set_radius(parameter); + } else if (idx==1){ + capsule->set_height(parameter*2 - capsule->get_radius()*2); + } + + canvas_item_editor->get_viewport_control()->update(); + } + + } break; + + case CIRCLE_SHAPE: { + Ref circle = node->get_shape(); + circle->set_radius(p_point.length()); + + canvas_item_editor->get_viewport_control()->update(); + + } break; + + case CONCAVE_POLYGON_SHAPE: { + + } break; + + case CONVEX_POLYGON_SHAPE: { + + } break; + + case LINE_SHAPE: { + + } break; + + case RAY_SHAPE: { + Ref ray = node->get_shape(); + + ray->set_length(Math::abs(p_point.y)); + + canvas_item_editor->get_viewport_control()->update(); + + } break; + + case RECTANGLE_SHAPE: { + if (idx<2) { + Ref rect = node->get_shape(); + + Vector2 extents = rect->get_extents(); + extents[idx] = p_point[idx]; + + rect->set_extents(extents.abs()); + + canvas_item_editor->get_viewport_control()->update(); + } + + } break; + + case SEGMENT_SHAPE: { + if (edit_handle < 2) { + Ref seg = node->get_shape(); + + if (idx==0) { + seg->set_a(p_point); + } else if (idx==1) { + seg->set_b(p_point); + } + + canvas_item_editor->get_viewport_control()->update(); + } + + } break; + } +} + +void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) { + + Control* c = canvas_item_editor->get_viewport_control(); + undo_redo->create_action("Set Handle"); + + switch ( shape_type ) { + case CAPSULE_SHAPE: { + Ref capsule = node->get_shape(); + + if (idx==0) { + undo_redo->add_do_method(capsule.ptr(),"set_radius",capsule->get_radius()); + undo_redo->add_do_method(c,"update"); + undo_redo->add_undo_method(capsule.ptr(),"set_radius",p_org); + undo_redo->add_do_method(c,"update"); + } else if (idx==1) { + undo_redo->add_do_method(capsule.ptr(),"set_height",capsule->get_height()); + undo_redo->add_do_method(c,"update"); + undo_redo->add_undo_method(capsule.ptr(),"set_height",p_org); + undo_redo->add_undo_method(c,"update"); + } + + } break; + + case CIRCLE_SHAPE: { + Ref circle = node->get_shape(); + + undo_redo->add_do_method(circle.ptr(),"set_radius",circle->get_radius()); + undo_redo->add_do_method(c,"update"); + undo_redo->add_undo_method(circle.ptr(),"set_radius",p_org); + undo_redo->add_undo_method(c,"update"); + + } break; + + case CONCAVE_POLYGON_SHAPE: { + + } break; + + case CONVEX_POLYGON_SHAPE: { + + } break; + + case LINE_SHAPE: { + + } break; + + case RAY_SHAPE: { + Ref ray = node->get_shape(); + + undo_redo->add_do_method(ray.ptr(),"set_length",ray->get_length()); + undo_redo->add_do_method(c,"update"); + undo_redo->add_undo_method(ray.ptr(),"set_length",p_org); + undo_redo->add_undo_method(c,"update"); + + } break; + + case RECTANGLE_SHAPE: { + Ref rect = node->get_shape(); + + undo_redo->add_do_method(rect.ptr(),"set_extents",rect->get_extents()); + undo_redo->add_do_method(c,"update"); + undo_redo->add_undo_method(rect.ptr(),"set_extents",p_org); + undo_redo->add_undo_method(c,"update"); + + } break; + + case SEGMENT_SHAPE: { + Ref seg = node->get_shape(); + if (idx==0) { + undo_redo->add_do_method(seg.ptr(),"set_a",seg->get_a()); + undo_redo->add_do_method(c,"update"); + undo_redo->add_undo_method(seg.ptr(),"set_a",p_org); + undo_redo->add_undo_method(c,"update"); + } else if (idx==1) { + undo_redo->add_do_method(seg.ptr(),"set_b",seg->get_b()); + undo_redo->add_do_method(c,"update"); + undo_redo->add_undo_method(seg.ptr(),"set_b",p_org); + undo_redo->add_undo_method(c,"update"); + } + + } break; + } + + undo_redo->commit_action(); +} + +bool CollisionShape2DEditor::forward_input_event(const InputEvent& p_event) { + + if (!node) { + return false; + } + + if (!node->get_shape().is_valid()) { + return false; + } + + if (shape_type == -1) { + return false; + } + + switch( p_event.type ) { + case InputEvent::MOUSE_BUTTON: { + const InputEventMouseButton& mb = p_event.mouse_button; + + Matrix32 gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); + + Point2 gpoint(mb.x,mb.y); + + if (mb.button_index == BUTTON_LEFT) { + if (mb.pressed) { + for (int i = 0; i < handles.size(); i++) { + if (gt.xform(handles[i]).distance_to(gpoint) < 8) { + edit_handle = i; + + break; + } + } + + if (edit_handle==-1) { + pressed = false; + + return false; + } + + original = get_handle_value(edit_handle); + pressed = true; + + return true; + + } else { + if (pressed) { + commit_handle(edit_handle, original); + + edit_handle = -1; + pressed = false; + + return true; + } + } + } + + return false; + + } break; + + case InputEvent::MOUSE_MOTION: { + const InputEventMouseMotion& mm = p_event.mouse_motion; + + if (edit_handle == -1 || !pressed) { + return false; + } + + Point2 gpoint = Point2(mm.x,mm.y); + Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); + cpoint = canvas_item_editor->snap_point(cpoint); + cpoint = node->get_global_transform().affine_inverse().xform(cpoint); + + set_handle(edit_handle, cpoint); + + return true; + + } break; + } + + return false; +} + +void CollisionShape2DEditor::_get_current_shape_type() { + + if (!node) { + return; + } + + Ref s = node->get_shape(); + + if (!s.is_valid()) { + return; + } + + if (s->cast_to()) { + shape_type = CAPSULE_SHAPE; + } else if (s->cast_to()) { + shape_type = CIRCLE_SHAPE; + } else if (s->cast_to()) { + shape_type = CONCAVE_POLYGON_SHAPE; + } else if (s->cast_to()) { + shape_type = CONVEX_POLYGON_SHAPE; + } else if (s->cast_to()) { + shape_type = LINE_SHAPE; + } else if (s->cast_to()) { + shape_type = RAY_SHAPE; + } else if (s->cast_to()) { + shape_type = RECTANGLE_SHAPE; + } else if (s->cast_to()) { + shape_type = SEGMENT_SHAPE; + } else { + shape_type = -1; + } + + canvas_item_editor->get_viewport_control()->update(); +} + +void CollisionShape2DEditor::_canvas_draw() { + + if (!node) { + return; + } + + if (!node->get_shape().is_valid()) { + return; + } + + _get_current_shape_type(); + + if (shape_type == -1) { + return; + } + + Control *c = canvas_item_editor->get_viewport_control(); + Matrix32 gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); + + Ref h = get_icon("EditorHandle","EditorIcons"); + Vector2 size = h->get_size()*0.5; + + handles.clear(); + + switch (shape_type) { + case CAPSULE_SHAPE: { + Ref shape = node->get_shape(); + + handles.resize(2); + float radius = shape->get_radius(); + float height = shape->get_height()/2; + + handles[0] = Point2(radius, -height); + handles[1] = Point2(0,-(height + radius)); + + c->draw_texture(h, gt.xform(handles[0])-size); + c->draw_texture(h, gt.xform(handles[1])-size); + + } break; + + case CIRCLE_SHAPE: { + Ref shape = node->get_shape(); + + handles.resize(1); + handles[0] = Point2(shape->get_radius(),0); + + c->draw_texture(h, gt.xform(handles[0])-size); + + } break; + + case CONCAVE_POLYGON_SHAPE: { + + } break; + + case CONVEX_POLYGON_SHAPE: { + + } break; + + case LINE_SHAPE: { + + } break; + + case RAY_SHAPE: { + Ref shape = node->get_shape(); + + handles.resize(1); + handles[0] = Point2(0,shape->get_length()); + + c->draw_texture(h,gt.xform(handles[0])-size); + + } break; + + case RECTANGLE_SHAPE: { + Ref shape = node->get_shape(); + + handles.resize(2); + Vector2 ext = shape->get_extents(); + handles[0] = Point2(ext.x,0); + handles[1] = Point2(0,-ext.y); + + c->draw_texture(h,gt.xform(handles[0])-size); + c->draw_texture(h,gt.xform(handles[1])-size); + + } break; + + case SEGMENT_SHAPE: { + Ref shape = node->get_shape(); + + handles.resize(2); + handles[0] = shape->get_a(); + handles[1] = shape->get_b(); + + c->draw_texture(h, gt.xform(handles[0])-size); + c->draw_texture(h, gt.xform(handles[1])-size); + + } break; + } +} + +void CollisionShape2DEditor::edit(Node* p_node) { + + if (!canvas_item_editor) { + canvas_item_editor=CanvasItemEditor::get_singleton(); + } + + if (p_node) { + node=p_node->cast_to(); + + if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw"); + + _get_current_shape_type(); + + } else { + edit_handle = -1; + shape_type = -1; + + if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw",this,"_canvas_draw"); + + node=NULL; + } + + canvas_item_editor->get_viewport_control()->update(); +} + +void CollisionShape2DEditor::_bind_methods() { + + ObjectTypeDB::bind_method("_canvas_draw",&CollisionShape2DEditor::_canvas_draw); + ObjectTypeDB::bind_method("_get_current_shape_type",&CollisionShape2DEditor::_get_current_shape_type); +} + +CollisionShape2DEditor::CollisionShape2DEditor(EditorNode* p_editor) { + + node = NULL; + canvas_item_editor = NULL; + editor = p_editor; + + undo_redo = p_editor->get_undo_redo(); + + edit_handle = -1; + pressed = false; +} + +void CollisionShape2DEditorPlugin::edit(Object* p_obj) { + + collision_shape_2d_editor->edit(p_obj->cast_to()); +} + +bool CollisionShape2DEditorPlugin::handles(Object* p_obj) const { + + return p_obj->is_type("CollisionShape2D"); +} + +void CollisionShape2DEditorPlugin::make_visible(bool visible) { + + if (!visible) { + edit(NULL); + } +} + +CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin(EditorNode* p_node) { + + editor=p_node; + + collision_shape_2d_editor = memnew( CollisionShape2DEditor(p_node) ); + p_node->get_gui_base()->add_child(collision_shape_2d_editor); +} + +CollisionShape2DEditorPlugin::~CollisionShape2DEditorPlugin() { + +} diff --git a/tools/editor/plugins/collision_shape_2d_editor_plugin.h b/tools/editor/plugins/collision_shape_2d_editor_plugin.h new file mode 100644 index 0000000000..75e9b68ea7 --- /dev/null +++ b/tools/editor/plugins/collision_shape_2d_editor_plugin.h @@ -0,0 +1,73 @@ +#ifndef COLLISION_SHAPE_2D_EDITOR_PLUGIN_H +#define COLLISION_SHAPE_2D_EDITOR_PLUGIN_H + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" + +#include "scene/2d/collision_shape_2d.h" + +class CanvasItemEditor; + +class CollisionShape2DEditor : public Control { + OBJ_TYPE(CollisionShape2DEditor, Control); + + enum ShapeType { + CAPSULE_SHAPE, + CIRCLE_SHAPE, + CONCAVE_POLYGON_SHAPE, + CONVEX_POLYGON_SHAPE, + LINE_SHAPE, + RAY_SHAPE, + RECTANGLE_SHAPE, + SEGMENT_SHAPE + }; + + EditorNode* editor; + UndoRedo* undo_redo; + CanvasItemEditor* canvas_item_editor; + CollisionShape2D* node; + + Vector handles; + + int shape_type; + int edit_handle; + bool pressed; + Variant original; + + Variant get_handle_value(int idx) const; + void set_handle(int idx, Point2& p_point); + void commit_handle(int idx, Variant& p_org); + + void _get_current_shape_type(); + void _canvas_draw(); + +protected: + static void _bind_methods(); + +public: + bool forward_input_event(const InputEvent& p_event); + void edit(Node* p_node); + + CollisionShape2DEditor(EditorNode* p_editor); +}; + +class CollisionShape2DEditorPlugin : public EditorPlugin { + OBJ_TYPE(CollisionShape2DEditorPlugin, EditorPlugin); + + CollisionShape2DEditor* collision_shape_2d_editor; + EditorNode* editor; + +public: + virtual bool forward_input_event(const InputEvent& p_event) { return collision_shape_2d_editor->forward_input_event(p_event); } + + virtual String get_name() const { return "CollisionShape2D"; } + bool has_main_screen() const { return false; } + virtual void edit(Object* p_obj); + virtual bool handles(Object* p_obj) const; + virtual void make_visible(bool visible); + + CollisionShape2DEditorPlugin(EditorNode* p_editor); + ~CollisionShape2DEditorPlugin(); +}; + +#endif //COLLISION_SHAPE_2D_EDITOR_PLUGIN_H