From 5dbf1809c6e3e905b94b8764e99491e608122261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 5 Mar 2017 16:44:50 +0100 Subject: A Whole New World (clang-format edition) I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code --- editor/plugins/animation_player_editor_plugin.cpp | 790 +++--- editor/plugins/animation_player_editor_plugin.h | 50 +- editor/plugins/animation_tree_editor_plugin.cpp | 1166 ++++----- editor/plugins/animation_tree_editor_plugin.h | 49 +- editor/plugins/baked_light_baker.cpp | 6 +- editor/plugins/baked_light_baker.h | 2 +- editor/plugins/baked_light_baker_cmpxchg.cpp | 58 +- editor/plugins/baked_light_editor_plugin.cpp | 7 +- editor/plugins/baked_light_editor_plugin.h | 5 +- editor/plugins/camera_editor_plugin.cpp | 50 +- editor/plugins/camera_editor_plugin.h | 13 +- editor/plugins/canvas_item_editor_plugin.cpp | 2381 ++++++++--------- editor/plugins/canvas_item_editor_plugin.h | 138 +- .../plugins/collision_polygon_2d_editor_plugin.cpp | 301 +-- .../plugins/collision_polygon_2d_editor_plugin.h | 18 +- editor/plugins/collision_polygon_editor_plugin.cpp | 6 +- editor/plugins/collision_polygon_editor_plugin.h | 4 +- .../plugins/collision_shape_2d_editor_plugin.cpp | 222 +- editor/plugins/collision_shape_2d_editor_plugin.h | 32 +- editor/plugins/color_ramp_editor_plugin.cpp | 44 +- editor/plugins/color_ramp_editor_plugin.h | 7 +- editor/plugins/cube_grid_theme_editor_plugin.cpp | 8 +- editor/plugins/cube_grid_theme_editor_plugin.h | 3 +- editor/plugins/editor_preview_plugins.cpp | 38 +- editor/plugins/gi_probe_editor_plugin.cpp | 22 +- editor/plugins/gi_probe_editor_plugin.h | 13 +- editor/plugins/item_list_editor_plugin.cpp | 189 +- editor/plugins/item_list_editor_plugin.h | 96 +- editor/plugins/light_occluder_2d_editor_plugin.cpp | 334 ++- editor/plugins/light_occluder_2d_editor_plugin.h | 20 +- editor/plugins/line_2d_editor_plugin.cpp | 88 +- editor/plugins/line_2d_editor_plugin.h | 20 +- editor/plugins/material_editor_plugin.cpp | 52 +- editor/plugins/material_editor_plugin.h | 6 +- editor/plugins/mesh_editor_plugin.h | 6 +- editor/plugins/mesh_instance_editor_plugin.cpp | 141 +- editor/plugins/mesh_instance_editor_plugin.h | 15 +- editor/plugins/multimesh_editor_plugin.cpp | 208 +- editor/plugins/multimesh_editor_plugin.h | 16 +- .../plugins/navigation_polygon_editor_plugin.cpp | 396 ++- editor/plugins/navigation_polygon_editor_plugin.h | 20 +- editor/plugins/particles_2d_editor_plugin.cpp | 110 +- editor/plugins/particles_2d_editor_plugin.h | 13 +- editor/plugins/particles_editor_plugin.cpp | 3 +- editor/plugins/particles_editor_plugin.h | 2 +- editor/plugins/path_2d_editor_plugin.cpp | 306 +-- editor/plugins/path_2d_editor_plugin.h | 20 +- editor/plugins/path_editor_plugin.cpp | 4 +- editor/plugins/path_editor_plugin.h | 3 +- editor/plugins/polygon_2d_editor_plugin.cpp | 741 +++--- editor/plugins/polygon_2d_editor_plugin.h | 19 +- .../plugins/resource_preloader_editor_plugin.cpp | 296 +-- editor/plugins/resource_preloader_editor_plugin.h | 31 +- editor/plugins/rich_text_editor_plugin.cpp | 62 +- editor/plugins/rich_text_editor_plugin.h | 18 +- editor/plugins/sample_editor_plugin.cpp | 4 +- editor/plugins/sample_editor_plugin.h | 2 +- editor/plugins/sample_library_editor_plugin.cpp | 6 +- editor/plugins/sample_library_editor_plugin.h | 9 +- editor/plugins/sample_player_editor_plugin.cpp | 2 - editor/plugins/sample_player_editor_plugin.h | 4 +- editor/plugins/script_editor_plugin.cpp | 1171 ++++----- editor/plugins/script_editor_plugin.h | 145 +- editor/plugins/script_text_editor.cpp | 644 +++-- editor/plugins/script_text_editor.h | 50 +- editor/plugins/shader_editor_plugin.cpp | 250 +- editor/plugins/shader_editor_plugin.h | 32 +- editor/plugins/shader_graph_editor_plugin.cpp | 6 +- editor/plugins/shader_graph_editor_plugin.h | 9 +- editor/plugins/spatial_editor_plugin.cpp | 2678 +++++++++----------- editor/plugins/spatial_editor_plugin.h | 166 +- editor/plugins/sprite_frames_editor_plugin.cpp | 611 ++--- editor/plugins/sprite_frames_editor_plugin.h | 35 +- editor/plugins/stream_editor_plugin.h | 2 +- editor/plugins/style_box_editor_plugin.cpp | 44 +- editor/plugins/style_box_editor_plugin.h | 22 +- editor/plugins/texture_editor_plugin.cpp | 84 +- editor/plugins/texture_editor_plugin.h | 13 +- editor/plugins/texture_region_editor_plugin.cpp | 755 +++--- editor/plugins/texture_region_editor_plugin.h | 23 +- editor/plugins/theme_editor_plugin.cpp | 610 ++--- editor/plugins/theme_editor_plugin.h | 34 +- editor/plugins/tile_map_editor_plugin.cpp | 781 +++--- editor/plugins/tile_map_editor_plugin.h | 54 +- editor/plugins/tile_set_editor_plugin.cpp | 156 +- editor/plugins/tile_set_editor_plugin.h | 27 +- 86 files changed, 7642 insertions(+), 9455 deletions(-) (limited to 'editor/plugins') diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 2e6792bbaa..90d2847103 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -28,17 +28,17 @@ /*************************************************************************/ #include "animation_player_editor_plugin.h" +#include "editor/animation_editor.h" +#include "editor/editor_settings.h" #include "global_config.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/keyboard.h" -#include "editor/editor_settings.h" -#include "editor/animation_editor.h" void AnimationPlayerEditor::_node_removed(Node *p_node) { if (player && player == p_node) { - player=NULL; + player = NULL; set_process(false); @@ -47,18 +47,15 @@ void AnimationPlayerEditor::_node_removed(Node *p_node) { key_editor->show_select_node_warning(true); _update_player(); //editor->animation_editor_make_visible(false); - } } void AnimationPlayerEditor::_gui_input(InputEvent p_event) { - - } void AnimationPlayerEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_PROCESS) { + if (p_what == NOTIFICATION_PROCESS) { if (!player) return; @@ -68,7 +65,7 @@ void AnimationPlayerEditor::_notification(int p_what) { if (player->is_playing()) { { - String animname=player->get_current_animation(); + String animname = player->get_current_animation(); if (player->has_animation(animname)) { Ref anim = player->get_animation(animname); @@ -88,41 +85,41 @@ void AnimationPlayerEditor::_notification(int p_what) { frame->set_value(player->get_current_animation_pos()); } - last_active=player->is_playing(); + last_active = player->is_playing(); //seek->set_val(player->get_pos()); updating = false; } - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { //editor->connect("hide_animation_player_editors",this,"_hide_anim_editors"); - add_anim->set_icon( get_icon("New","EditorIcons") ); - rename_anim->set_icon( get_icon("Rename","EditorIcons") ); - duplicate_anim->set_icon( get_icon("Duplicate","EditorIcons") ); - autoplay->set_icon( get_icon("AutoPlay","EditorIcons") ); - load_anim->set_icon( get_icon("Folder","EditorIcons") ); + add_anim->set_icon(get_icon("New", "EditorIcons")); + rename_anim->set_icon(get_icon("Rename", "EditorIcons")); + duplicate_anim->set_icon(get_icon("Duplicate", "EditorIcons")); + autoplay->set_icon(get_icon("AutoPlay", "EditorIcons")); + load_anim->set_icon(get_icon("Folder", "EditorIcons")); save_anim->set_icon(get_icon("Save", "EditorIcons")); save_anim->get_popup()->connect("id_pressed", this, "_animation_save_menu"); - remove_anim->set_icon( get_icon("Remove","EditorIcons") ); + remove_anim->set_icon(get_icon("Remove", "EditorIcons")); - blend_anim->set_icon( get_icon("Blend","EditorIcons") ); - play->set_icon( get_icon("PlayStart","EditorIcons") ); - play_from->set_icon( get_icon("Play","EditorIcons") ); - play_bw->set_icon( get_icon("PlayStartBackwards","EditorIcons") ); - play_bw_from->set_icon( get_icon("PlayBackwards","EditorIcons") ); + blend_anim->set_icon(get_icon("Blend", "EditorIcons")); + play->set_icon(get_icon("PlayStart", "EditorIcons")); + play_from->set_icon(get_icon("Play", "EditorIcons")); + play_bw->set_icon(get_icon("PlayStartBackwards", "EditorIcons")); + play_bw_from->set_icon(get_icon("PlayBackwards", "EditorIcons")); - autoplay_icon=get_icon("AutoPlay","EditorIcons"); - stop->set_icon( get_icon("Stop","EditorIcons") ); - resource_edit_anim->set_icon( get_icon("EditResource","EditorIcons") ); - pin->set_icon(get_icon("Pin","EditorIcons") ); - tool_anim->set_icon(get_icon("Tools","EditorIcons")); - tool_anim->get_popup()->connect("id_pressed",this,"_animation_tool_menu"); + autoplay_icon = get_icon("AutoPlay", "EditorIcons"); + stop->set_icon(get_icon("Stop", "EditorIcons")); + resource_edit_anim->set_icon(get_icon("EditResource", "EditorIcons")); + pin->set_icon(get_icon("Pin", "EditorIcons")); + tool_anim->set_icon(get_icon("Tools", "EditorIcons")); + tool_anim->get_popup()->connect("id_pressed", this, "_animation_tool_menu"); blend_editor.next->connect("item_selected", this, "_blend_editor_next_changed"); - nodename->set_icon(get_icon("AnimationPlayer","EditorIcons")); + nodename->set_icon(get_icon("AnimationPlayer", "EditorIcons")); -/* + /* anim_editor_load->set_normal_texture( get_icon("AnimGet","EditorIcons")); anim_editor_store->set_normal_texture( get_icon("AnimSet","EditorIcons")); anim_editor_load->set_pressed_texture( get_icon("AnimGet","EditorIcons")); @@ -131,7 +128,7 @@ void AnimationPlayerEditor::_notification(int p_what) { anim_editor_store->set_hover_texture( get_icon("AnimSetHl","EditorIcons")); */ - get_tree()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("node_removed", this, "_node_removed"); } } @@ -139,46 +136,44 @@ void AnimationPlayerEditor::_autoplay_pressed() { if (updating) return; - if (animation->get_item_count()==0) { + if (animation->get_item_count() == 0) { return; } - String current = animation->get_item_text( animation->get_selected() ); - if (player->get_autoplay()==current) { + String current = animation->get_item_text(animation->get_selected()); + if (player->get_autoplay() == current) { //unset undo_redo->create_action(TTR("Toggle Autoplay")); - undo_redo->add_do_method(player,"set_autoplay",""); - undo_redo->add_undo_method(player,"set_autoplay",player->get_autoplay()); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "set_autoplay", ""); + undo_redo->add_undo_method(player, "set_autoplay", player->get_autoplay()); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); - } else { //set undo_redo->create_action(TTR("Toggle Autoplay")); - undo_redo->add_do_method(player,"set_autoplay",current); - undo_redo->add_undo_method(player,"set_autoplay",player->get_autoplay()); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "set_autoplay", current); + undo_redo->add_undo_method(player, "set_autoplay", player->get_autoplay()); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); } - } void AnimationPlayerEditor::_play_pressed() { String current; - if (animation->get_selected()>=0 && animation->get_selected()get_item_count()) { + if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text( animation->get_selected() ); + current = animation->get_item_text(animation->get_selected()); } - if (current!="") { + if (current != "") { - if (current==player->get_current_animation()) + if (current == player->get_current_animation()) player->stop(); //so it wont blend with itself - player->play(current ); + player->play(current); } //unstop @@ -190,21 +185,21 @@ void AnimationPlayerEditor::_play_pressed() { void AnimationPlayerEditor::_play_from_pressed() { String current; - if (animation->get_selected()>=0 && animation->get_selected()get_item_count()) { + if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text( animation->get_selected() ); + current = animation->get_item_text(animation->get_selected()); } - if (current!="") { + if (current != "") { float time = player->get_current_animation_pos(); - if (current==player->get_current_animation() && player->is_playing()) { + if (current == player->get_current_animation() && player->is_playing()) { player->stop(); //so it wont blend with itself } - player->play( current ); + player->play(current); player->seek(time); } @@ -214,20 +209,19 @@ void AnimationPlayerEditor::_play_from_pressed() { //pause->set_pressed(false); } - void AnimationPlayerEditor::_play_bw_pressed() { String current; - if (animation->get_selected()>=0 && animation->get_selected()get_item_count()) { + if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text( animation->get_selected() ); + current = animation->get_item_text(animation->get_selected()); } - if (current!="") { + if (current != "") { - if (current==player->get_current_animation()) + if (current == player->get_current_animation()) player->stop(); //so it wont blend with itself - player->play(current,-1,-1,true); + player->play(current, -1, -1, true); } //unstop @@ -239,18 +233,18 @@ void AnimationPlayerEditor::_play_bw_pressed() { void AnimationPlayerEditor::_play_bw_from_pressed() { String current; - if (animation->get_selected()>=0 && animation->get_selected()get_item_count()) { + if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text( animation->get_selected() ); + current = animation->get_item_text(animation->get_selected()); } - if (current!="") { + if (current != "") { float time = player->get_current_animation_pos(); - if (current==player->get_current_animation()) + if (current == player->get_current_animation()) player->stop(); //so it wont blend with itself - player->play(current,-1,-1,true); + player->play(current, -1, -1, true); player->seek(time); } @@ -279,17 +273,16 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { // when selecting an animation, the idea is that the only interesting behavior // ui-wise is that it should play/blend the next one if currently playing String current; - if (animation->get_selected()>=0 && animation->get_selected()get_item_count()) { + if (animation->get_selected() >= 0 && animation->get_selected() < animation->get_item_count()) { - current = animation->get_item_text( animation->get_selected() ); + current = animation->get_item_text(animation->get_selected()); } - if (current!="") { - + if (current != "") { - player->set_current_animation( current ); + player->set_current_animation(current); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); { key_editor->set_animation(anim); @@ -304,76 +297,69 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { else frame->set_step(0.00001); - - } else { key_editor->set_animation(Ref()); key_editor->set_root(NULL); - } - - autoplay->set_pressed(current==player->get_autoplay()); + autoplay->set_pressed(current == player->get_autoplay()); } void AnimationPlayerEditor::_animation_new() { - renaming=false; + renaming = false; name_title->set_text(TTR("New Animation Name:")); - int count=1; - String base=TTR("New Anim"); - while(true) { - String attempt = base; - if (count>1) - attempt+=" ("+itos(count)+")"; + int count = 1; + String base = TTR("New Anim"); + while (true) { + String attempt = base; + if (count > 1) + attempt += " (" + itos(count) + ")"; if (player->has_animation(attempt)) { count++; continue; } - base=attempt; + base = attempt; break; } name->set_text(base); - name_dialog->popup_centered(Size2(300,90)); + name_dialog->popup_centered(Size2(300, 90)); name->select_all(); name->grab_focus(); } void AnimationPlayerEditor::_animation_rename() { - if (animation->get_item_count()==0) + if (animation->get_item_count() == 0) return; int selected = animation->get_selected(); String selected_name = animation->get_item_text(selected); name_title->set_text(TTR("Change Animation Name:")); name->set_text(selected_name); - renaming=true; - name_dialog->popup_centered(Size2(300,90)); + renaming = true; + name_dialog->popup_centered(Size2(300, 90)); name->select_all(); name->grab_focus(); - } void AnimationPlayerEditor::_animation_load() { ERR_FAIL_COND(!player); - file->set_mode( EditorFileDialog::MODE_OPEN_FILE ); + file->set_mode(EditorFileDialog::MODE_OPEN_FILE); file->clear_filters(); List extensions; - ResourceLoader::get_recognized_extensions_for_type("Animation",&extensions); - for (List::Element *E=extensions.front();E;E=E->next()) { - - file->add_filter("*."+E->get()+" ; "+E->get().to_upper() ); + ResourceLoader::get_recognized_extensions_for_type("Animation", &extensions); + for (List::Element *E = extensions.front(); E; E = E->next()) { + file->add_filter("*." + E->get() + " ; " + E->get().to_upper()); } file->popup_centered_ratio(); current_option = RESOURCE_LOAD; } - -void AnimationPlayerEditor::_animation_save_in_path(const Ref& p_resource, const String& p_path) { +void AnimationPlayerEditor::_animation_save_in_path(const Ref &p_resource, const String &p_path) { int flg = 0; if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) @@ -393,29 +379,27 @@ void AnimationPlayerEditor::_animation_save_in_path(const Ref& p_resou } //EditorFileSystem::get_singleton()->update_file(path,p_resource->get_type()); - ((Resource*)p_resource.ptr())->set_path(path); + ((Resource *)p_resource.ptr())->set_path(path); editor->emit_signal("resource_saved", p_resource); - } -void AnimationPlayerEditor::_animation_save(const Ref& p_resource) { +void AnimationPlayerEditor::_animation_save(const Ref &p_resource) { if (p_resource->get_path().is_resource_file()) { _animation_save_in_path(p_resource, p_resource->get_path()); - } - else { + } else { _animation_save_as(p_resource); } } -void AnimationPlayerEditor::_animation_save_as(const Ref& p_resource) { +void AnimationPlayerEditor::_animation_save_as(const Ref &p_resource) { file->set_mode(EditorFileDialog::MODE_SAVE_FILE); List extensions; ResourceSaver::get_recognized_extensions(p_resource, &extensions); file->clear_filters(); - for (int i = 0; iadd_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } @@ -429,20 +413,17 @@ void AnimationPlayerEditor::_animation_save_as(const Ref& p_resource) file->set_current_path(p_resource->get_path().replacen("." + ext, "." + extensions.front()->get())); } } - } - else { + } else { String existing; if (extensions.size()) { - if( p_resource->get_name() != "" ) { + if (p_resource->get_name() != "") { existing = p_resource->get_name() + "." + extensions.front()->get().to_lower(); - } - else { + } else { existing = "new_" + p_resource->get_class().to_lower() + "." + extensions.front()->get().to_lower(); } } file->set_current_path(existing); - } file->popup_centered_ratio(); file->set_title(TTR("Save Resource As..")); @@ -471,25 +452,23 @@ void AnimationPlayerEditor::_animation_remove_confirmed() { undo_redo->commit_action(); } -void AnimationPlayerEditor::_select_anim_by_name(const String& p_anim) { +void AnimationPlayerEditor::_select_anim_by_name(const String &p_anim) { - int idx=-1; - for(int i=0;iget_item_count();i++) { + int idx = -1; + for (int i = 0; i < animation->get_item_count(); i++) { - if (animation->get_item_text(i)==p_anim) { + if (animation->get_item_text(i) == p_anim) { - idx=i; + idx = i; break; } } - ERR_FAIL_COND(idx==-1); - + ERR_FAIL_COND(idx == -1); animation->select(idx); _animation_selected(idx); - } void AnimationPlayerEditor::_animation_name_edited() { @@ -497,13 +476,13 @@ void AnimationPlayerEditor::_animation_name_edited() { player->stop(); String new_name = name->get_text(); - if (new_name=="" || new_name.find(":")!=-1 || new_name.find("/")!=-1) { + if (new_name == "" || new_name.find(":") != -1 || new_name.find("/") != -1) { error_dialog->set_text(TTR("ERROR: Invalid animation name!")); error_dialog->popup_centered_minsize(); return; } - if (renaming && animation->get_item_count()>0 && animation->get_item_text(animation->get_selected())==new_name) { + if (renaming && animation->get_item_count() > 0 && animation->get_item_text(animation->get_selected()) == new_name) { name_dialog->hide(); return; } @@ -516,51 +495,49 @@ void AnimationPlayerEditor::_animation_name_edited() { if (renaming) { String current = animation->get_item_text(animation->get_selected()); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); undo_redo->create_action(TTR("Rename Animation")); - undo_redo->add_do_method(player,"rename_animation",current,new_name); - undo_redo->add_do_method(anim.ptr(),"set_name",new_name); - undo_redo->add_undo_method(player,"rename_animation",new_name,current); - undo_redo->add_undo_method(anim.ptr(),"set_name",current); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "rename_animation", current, new_name); + undo_redo->add_do_method(anim.ptr(), "set_name", new_name); + undo_redo->add_undo_method(player, "rename_animation", new_name, current); + undo_redo->add_undo_method(anim.ptr(), "set_name", current); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); _select_anim_by_name(new_name); } else { - Ref new_anim = Ref(memnew( Animation )); + Ref new_anim = Ref(memnew(Animation)); new_anim->set_name(new_name); undo_redo->create_action(TTR("Add Animation")); - undo_redo->add_do_method(player,"add_animation",new_name,new_anim); - undo_redo->add_undo_method(player,"remove_animation",new_name); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "add_animation", new_name, new_anim); + undo_redo->add_undo_method(player, "remove_animation", new_name); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); _select_anim_by_name(new_name); - } name_dialog->hide(); } - void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) { - if (animation->get_item_count()==0) + if (animation->get_item_count() == 0) return; String current = animation->get_item_text(animation->get_selected()); undo_redo->create_action(TTR("Blend Next Changed")); - undo_redo->add_do_method(player,"animation_set_next",current,blend_editor.next->get_item_text(p_idx)); - undo_redo->add_undo_method(player,"animation_set_next",current,player->animation_get_next(current)); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "animation_set_next", current, blend_editor.next->get_item_text(p_idx)); + undo_redo->add_undo_method(player, "animation_set_next", current, player->animation_get_next(current)); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); } @@ -571,37 +548,37 @@ void AnimationPlayerEditor::_animation_blend() { blend_editor.tree->clear(); - if (animation->get_item_count()==0) + if (animation->get_item_count() == 0) return; String current = animation->get_item_text(animation->get_selected()); - blend_editor.dialog->popup_centered(Size2(400,400)); + blend_editor.dialog->popup_centered(Size2(400, 400)); blend_editor.tree->set_hide_root(true); - blend_editor.tree->set_column_min_width(0,10); - blend_editor.tree->set_column_min_width(1,3); + blend_editor.tree->set_column_min_width(0, 10); + blend_editor.tree->set_column_min_width(1, 3); List anims; player->get_animation_list(&anims); TreeItem *root = blend_editor.tree->create_item(); - updating_blends=true; + updating_blends = true; int i = 0; bool anim_found = false; blend_editor.next->clear(); blend_editor.next->add_item("", i); - for(List::Element *E=anims.front();E;E=E->next()) { + for (List::Element *E = anims.front(); E; E = E->next()) { - String to=E->get(); - TreeItem *blend=blend_editor.tree->create_item(root); - blend->set_editable(0,false); - blend->set_editable(1,true); - blend->set_text(0,to); - blend->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); - blend->set_range_config(1,0,3600,0.001); - blend->set_range(1,player->get_blend_time(current,to)); + String to = E->get(); + TreeItem *blend = blend_editor.tree->create_item(root); + blend->set_editable(0, false); + blend->set_editable(1, true); + blend->set_text(0, to); + blend->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); + blend->set_range_config(1, 0, 3600, 0.001); + blend->set_range(1, player->get_blend_time(current, to)); i++; blend_editor.next->add_item(to, i); @@ -617,7 +594,7 @@ void AnimationPlayerEditor::_animation_blend() { player->animation_set_next(current, blend_editor.next->get_item_text(0)); } - updating_blends=false; + updating_blends = false; } void AnimationPlayerEditor::_blend_edited() { @@ -625,7 +602,7 @@ void AnimationPlayerEditor::_blend_edited() { if (updating_blends) return; - if (animation->get_item_count()==0) + if (animation->get_item_count() == 0) return; String current = animation->get_item_text(animation->get_selected()); @@ -634,18 +611,18 @@ void AnimationPlayerEditor::_blend_edited() { if (!selected) return; - updating_blends=true; - String to=selected->get_text(0); + updating_blends = true; + String to = selected->get_text(0); float blend_time = selected->get_range(1); - float prev_blend_time = player->get_blend_time(current,to); + float prev_blend_time = player->get_blend_time(current, to); undo_redo->create_action(TTR("Change Blend Time")); - undo_redo->add_do_method(player,"set_blend_time",current,to,blend_time); - undo_redo->add_undo_method(player,"set_blend_time",current,to,prev_blend_time); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "set_blend_time", current, to, blend_time); + undo_redo->add_undo_method(player, "set_blend_time", current, to, prev_blend_time); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); - updating_blends=false; + updating_blends = false; } void AnimationPlayerEditor::ensure_visibility() { @@ -658,20 +635,17 @@ void AnimationPlayerEditor::ensure_visibility() { Dictionary AnimationPlayerEditor::get_state() const { - Dictionary d; - d["visible"]=is_visible_in_tree(); + d["visible"] = is_visible_in_tree(); if (EditorNode::get_singleton()->get_edited_scene() && is_visible_in_tree() && player) { - d["player"]=EditorNode::get_singleton()->get_edited_scene()->get_path_to(player); - d["animation"]=player->get_current_animation(); - + d["player"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(player); + d["animation"] = player->get_current_animation(); } return d; - } -void AnimationPlayerEditor::set_state(const Dictionary& p_state) { +void AnimationPlayerEditor::set_state(const Dictionary &p_state) { if (p_state.has("visible") && p_state["visible"]) { @@ -680,7 +654,7 @@ void AnimationPlayerEditor::set_state(const Dictionary& p_state) { Node *n = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["player"]); if (n && n->cast_to() && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) { - player=n->cast_to(); + player = n->cast_to(); _update_player(); show(); set_process(true); @@ -692,28 +666,24 @@ void AnimationPlayerEditor::set_state(const Dictionary& p_state) { _select_anim_by_name(anim); _animation_edit(); } - } } - } - void AnimationPlayerEditor::_animation_resource_edit() { if (animation->get_item_count()) { String current = animation->get_item_text(animation->get_selected()); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); editor->edit_resource(anim); } - } void AnimationPlayerEditor::_animation_edit() { if (animation->get_item_count()) { String current = animation->get_item_text(animation->get_selected()); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); key_editor->set_animation(anim); Node *root = player->get_node(player->get_root()); if (root) { @@ -724,9 +694,7 @@ void AnimationPlayerEditor::_animation_edit() { key_editor->set_animation(Ref()); key_editor->set_root(NULL); - } - } void AnimationPlayerEditor::_dialog_action(String p_file) { @@ -740,12 +708,10 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { if (p_file.find_last("/") != -1) { p_file = p_file.substr(p_file.find_last("/") + 1, p_file.length()); - } if (p_file.find_last("\\") != -1) { p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length()); - } if (p_file.find(".") != -1) @@ -756,7 +722,6 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { undo_redo->add_undo_method(player, "remove_animation", p_file); if (player->has_animation(p_file)) { undo_redo->add_undo_method(player, "add_animation", p_file, player->get_animation(p_file)); - } undo_redo->add_do_method(this, "_animation_player_changed", player); undo_redo->add_undo_method(this, "_animation_player_changed", player); @@ -771,7 +736,7 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { ERR_FAIL_COND(!anim->cast_to()) - RES current_res = RES(anim->cast_to()); + RES current_res = RES(anim->cast_to()); _animation_save_in_path(current_res, p_file); } @@ -779,7 +744,7 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { } } -void AnimationPlayerEditor::_scale_changed(const String& p_scale) { +void AnimationPlayerEditor::_scale_changed(const String &p_scale) { player->set_speed_scale(p_scale.to_double()); } @@ -789,8 +754,7 @@ void AnimationPlayerEditor::_update_animation() { // the purpose of _update_animation is to reflect the current state // of the animation player in the current editor.. - updating=true; - + updating = true; if (player->is_playing()) { @@ -803,24 +767,23 @@ void AnimationPlayerEditor::_update_animation() { stop->set_pressed(true); } - scale->set_text( String::num(player->get_speed_scale(),2) ); - String current=player->get_current_animation(); + scale->set_text(String::num(player->get_speed_scale(), 2)); + String current = player->get_current_animation(); - for (int i=0;iget_item_count();i++) { + for (int i = 0; i < animation->get_item_count(); i++) { - if (animation->get_item_text(i)==current) { + if (animation->get_item_text(i) == current) { animation->select(i); break; } } - updating=false; + updating = false; } void AnimationPlayerEditor::_update_player() { - - updating=true; + updating = true; List animlist; if (player) player->get_animation_list(&animlist); @@ -831,78 +794,70 @@ void AnimationPlayerEditor::_update_player() { else nodename->set_text(""); - - add_anim->set_disabled(player==NULL); - load_anim->set_disabled(player==NULL); - stop->set_disabled(animlist.size()==0); - play->set_disabled(animlist.size()==0); - play_bw->set_disabled(animlist.size()==0); - play_bw_from->set_disabled(animlist.size()==0); - play_from->set_disabled(animlist.size()==0); - autoplay->set_disabled(animlist.size()==0); - duplicate_anim->set_disabled(animlist.size()==0); - rename_anim->set_disabled(animlist.size()==0); - blend_anim->set_disabled(animlist.size()==0); - remove_anim->set_disabled(animlist.size()==0); - resource_edit_anim->set_disabled(animlist.size()==0); + add_anim->set_disabled(player == NULL); + load_anim->set_disabled(player == NULL); + stop->set_disabled(animlist.size() == 0); + play->set_disabled(animlist.size() == 0); + play_bw->set_disabled(animlist.size() == 0); + play_bw_from->set_disabled(animlist.size() == 0); + play_from->set_disabled(animlist.size() == 0); + autoplay->set_disabled(animlist.size() == 0); + duplicate_anim->set_disabled(animlist.size() == 0); + rename_anim->set_disabled(animlist.size() == 0); + blend_anim->set_disabled(animlist.size() == 0); + remove_anim->set_disabled(animlist.size() == 0); + resource_edit_anim->set_disabled(animlist.size() == 0); save_anim->set_disabled(animlist.size() == 0); - tool_anim->set_disabled(player==NULL); + tool_anim->set_disabled(player == NULL); + int active_idx = -1; + for (List::Element *E = animlist.front(); E; E = E->next()) { - int active_idx=-1; - for (List::Element *E=animlist.front();E;E=E->next()) { - - if (player->get_autoplay()==E->get()) - animation->add_icon_item(autoplay_icon,E->get()); + if (player->get_autoplay() == E->get()) + animation->add_icon_item(autoplay_icon, E->get()); else animation->add_item(E->get()); - if (player->get_current_animation()==E->get()) - active_idx=animation->get_item_count()-1; - + if (player->get_current_animation() == E->get()) + active_idx = animation->get_item_count() - 1; } if (!player) return; - updating=false; - if (active_idx!=-1) { + updating = false; + if (active_idx != -1) { animation->select(active_idx); - autoplay->set_pressed(animation->get_item_text(active_idx)==player->get_autoplay()); + autoplay->set_pressed(animation->get_item_text(active_idx) == player->get_autoplay()); _animation_selected(active_idx); - } else if (animation->get_item_count()>0){ + } else if (animation->get_item_count() > 0) { animation->select(0); - autoplay->set_pressed(animation->get_item_text(0)==player->get_autoplay()); + autoplay->set_pressed(animation->get_item_text(0) == player->get_autoplay()); _animation_selected(0); } //pause->set_pressed(player->is_paused()); - if (animation->get_item_count()) { String current = animation->get_item_text(animation->get_selected()); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); key_editor->set_animation(anim); Node *root = player->get_node(player->get_root()); if (root) { key_editor->set_root(root); } - } _update_animation(); } - - void AnimationPlayerEditor::edit(AnimationPlayer *p_player) { - if (player && pin->is_pressed()) return; //ignore, pinned - player=p_player; + player = p_player; if (player) { _update_player(); @@ -911,29 +866,25 @@ void AnimationPlayerEditor::edit(AnimationPlayer *p_player) { key_editor->show_select_node_warning(true); //hide(); - } - } - void AnimationPlayerEditor::_animation_duplicate() { - if (!animation->get_item_count()) return; String current = animation->get_item_text(animation->get_selected()); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); if (!anim.is_valid()) return; - Ref new_anim = memnew( Animation ); + Ref new_anim = memnew(Animation); List plist; anim->get_property_list(&plist); - for (List::Element *E=plist.front();E;E=E->next()) { + for (List::Element *E = plist.front(); E; E = E->next()) { - if (E->get().usage&PROPERTY_USAGE_STORAGE) { + if (E->get().usage & PROPERTY_USAGE_STORAGE) { new_anim->set(E->get().name, anim->get(E->get().name)); } @@ -941,78 +892,73 @@ void AnimationPlayerEditor::_animation_duplicate() { new_anim->set_path(""); String new_name = current; - while(player->has_animation(new_name)) { + while (player->has_animation(new_name)) { - new_name=new_name+" (copy)"; + new_name = new_name + " (copy)"; } - undo_redo->create_action(TTR("Duplicate Animation")); - undo_redo->add_do_method(player,"add_animation",new_name,new_anim); - undo_redo->add_undo_method(player,"remove_animation",new_name); - undo_redo->add_do_method(player,"animation_set_next",new_name,player->animation_get_next(current)); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "add_animation", new_name, new_anim); + undo_redo->add_undo_method(player, "remove_animation", new_name); + undo_redo->add_do_method(player, "animation_set_next", new_name, player->animation_get_next(current)); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); + for (int i = 0; i < animation->get_item_count(); i++) { - for(int i=0;iget_item_count();i++) { - - if (animation->get_item_text(i)==new_name) { + if (animation->get_item_text(i) == new_name) { animation->select(i); _animation_selected(i); return; } } - } -void AnimationPlayerEditor::_seek_value_changed(float p_value,bool p_set) { +void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { if (updating || !player || player->is_playing()) { return; }; - - updating=true; - String current=player->get_current_animation(); //animation->get_item_text( animation->get_selected() ); + updating = true; + String current = player->get_current_animation(); //animation->get_item_text( animation->get_selected() ); if (current == "" || !player->has_animation(current)) { - updating=false; - current=""; + updating = false; + current = ""; return; }; Ref anim; - anim=player->get_animation(current); + anim = player->get_animation(current); float pos = anim->get_length() * (p_value / frame->get_max()); float step = anim->get_step(); if (step) { - pos=Math::stepify(pos, step); - if (pos<0) - pos=0; - if (pos>=anim->get_length()) - pos=anim->get_length(); + pos = Math::stepify(pos, step); + if (pos < 0) + pos = 0; + if (pos >= anim->get_length()) + pos = anim->get_length(); } if (player->is_valid() && !p_set) { float cpos = player->get_current_animation_pos(); - player->seek_delta(pos,pos-cpos); + player->seek_delta(pos, pos - cpos); } else { - player->seek(pos,true); + player->seek(pos, true); } - key_editor->set_anim_pos(pos); - updating=true; + updating = true; }; void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) { - if (player==p_pl && is_visible_in_tree()) { + if (player == p_pl && is_visible_in_tree()) { _update_player(); if (blend_editor.dialog->is_visible_in_tree()) @@ -1020,11 +966,9 @@ void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) { } } - - void AnimationPlayerEditor::_list_changed() { - if(is_visible_in_tree()) + if (is_visible_in_tree()) _update_player(); } #if 0 @@ -1095,9 +1039,7 @@ void AnimationPlayerEditor::_editor_load(){ void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) { - frame->set_max(p_len); - } void AnimationPlayerEditor::_animation_key_editor_anim_step_changed(float p_len) { @@ -1106,49 +1048,43 @@ void AnimationPlayerEditor::_animation_key_editor_anim_step_changed(float p_len) frame->set_step(p_len); else frame->set_step(0.00001); - } - -void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos,bool p_drag) { +void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) { if (!is_visible_in_tree()) return; if (!player) return; - if (player->is_playing() ) + if (player->is_playing()) return; - updating=true; - frame->set_value(p_pos); - updating=false; - _seek_value_changed(p_pos,!p_drag); + updating = true; + frame->set_value(p_pos); + updating = false; + _seek_value_changed(p_pos, !p_drag); EditorNode::get_singleton()->get_property_editor()->refresh(); - - //seekit } void AnimationPlayerEditor::_hide_anim_editors() { - player=NULL; + player = NULL; hide(); set_process(false); key_editor->set_animation(Ref()); key_editor->set_root(NULL); key_editor->show_select_node_warning(true); - //editor->animation_editor_make_visible(false); - + //editor->animation_editor_make_visible(false); } - void AnimationPlayerEditor::_animation_tool_menu(int p_option) { - switch(p_option) { + switch (p_option) { case TOOL_COPY_ANIM: { @@ -1159,7 +1095,7 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { } String current = animation->get_item_text(animation->get_selected()); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); //editor->edit_resource(anim); EditorSettings::get_singleton()->set_resource_clipboard(anim); @@ -1174,28 +1110,27 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { } String name = anim->get_name(); - if (name=="") { - name=TTR("Pasted Animation"); + if (name == "") { + name = TTR("Pasted Animation"); } - int idx=1; + int idx = 1; String base = name; while (player->has_animation(name)) { idx++; - name=base+" "+itos(idx); + name = base + " " + itos(idx); } undo_redo->create_action(TTR("Paste Animation")); - undo_redo->add_do_method(player,"add_animation",name,anim); - undo_redo->add_undo_method(player,"remove_animation",name); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "add_animation", name, anim); + undo_redo->add_undo_method(player, "remove_animation", name); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); _select_anim_by_name(name); - } break; case TOOL_EDIT_RESOURCE: { @@ -1206,11 +1141,10 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) { } String current = animation->get_item_text(animation->get_selected()); - Ref anim = player->get_animation(current); + Ref anim = player->get_animation(current); editor->edit_resource(anim); } break; - } } @@ -1221,21 +1155,21 @@ void AnimationPlayerEditor::_animation_save_menu(int p_option) { Ref anim = player->get_animation(current); switch (p_option) { - case ANIM_SAVE: - _animation_save(anim); - break; - case ANIM_SAVE_AS: - _animation_save_as(anim); - break; + case ANIM_SAVE: + _animation_save(anim); + break; + case ANIM_SAVE_AS: + _animation_save_as(anim); + break; } } } -void AnimationPlayerEditor::_unhandled_key_input(const InputEvent& p_ev) { +void AnimationPlayerEditor::_unhandled_key_input(const InputEvent &p_ev) { - if (is_visible_in_tree() && p_ev.type==InputEvent::KEY && p_ev.key.pressed && !p_ev.key.echo && !p_ev.key.mod.alt && !p_ev.key.mod.control && !p_ev.key.mod.meta) { + if (is_visible_in_tree() && p_ev.type == InputEvent::KEY && p_ev.key.pressed && !p_ev.key.echo && !p_ev.key.mod.alt && !p_ev.key.mod.control && !p_ev.key.mod.meta) { - switch(p_ev.key.scancode) { + switch (p_ev.key.scancode) { case KEY_A: { if (!p_ev.key.mod.shift) @@ -1258,130 +1192,119 @@ void AnimationPlayerEditor::_unhandled_key_input(const InputEvent& p_ev) { void AnimationPlayerEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"),&AnimationPlayerEditor::_gui_input); - ClassDB::bind_method(D_METHOD("_node_removed"),&AnimationPlayerEditor::_node_removed); - ClassDB::bind_method(D_METHOD("_play_pressed"),&AnimationPlayerEditor::_play_pressed); - ClassDB::bind_method(D_METHOD("_play_from_pressed"),&AnimationPlayerEditor::_play_from_pressed); - ClassDB::bind_method(D_METHOD("_play_bw_pressed"),&AnimationPlayerEditor::_play_bw_pressed); - ClassDB::bind_method(D_METHOD("_play_bw_from_pressed"),&AnimationPlayerEditor::_play_bw_from_pressed); - ClassDB::bind_method(D_METHOD("_stop_pressed"),&AnimationPlayerEditor::_stop_pressed); - ClassDB::bind_method(D_METHOD("_autoplay_pressed"),&AnimationPlayerEditor::_autoplay_pressed); - ClassDB::bind_method(D_METHOD("_pause_pressed"),&AnimationPlayerEditor::_pause_pressed); - ClassDB::bind_method(D_METHOD("_animation_selected"),&AnimationPlayerEditor::_animation_selected); - ClassDB::bind_method(D_METHOD("_animation_name_edited"),&AnimationPlayerEditor::_animation_name_edited); - ClassDB::bind_method(D_METHOD("_animation_new"),&AnimationPlayerEditor::_animation_new); - ClassDB::bind_method(D_METHOD("_animation_rename"),&AnimationPlayerEditor::_animation_rename); - ClassDB::bind_method(D_METHOD("_animation_load"),&AnimationPlayerEditor::_animation_load); - ClassDB::bind_method(D_METHOD("_animation_remove"),&AnimationPlayerEditor::_animation_remove); - ClassDB::bind_method(D_METHOD("_animation_remove_confirmed"),&AnimationPlayerEditor::_animation_remove_confirmed); - ClassDB::bind_method(D_METHOD("_animation_blend"),&AnimationPlayerEditor::_animation_blend); - ClassDB::bind_method(D_METHOD("_animation_edit"),&AnimationPlayerEditor::_animation_edit); - ClassDB::bind_method(D_METHOD("_animation_resource_edit"),&AnimationPlayerEditor::_animation_resource_edit); - ClassDB::bind_method(D_METHOD("_dialog_action"),&AnimationPlayerEditor::_dialog_action); - ClassDB::bind_method(D_METHOD("_seek_value_changed"),&AnimationPlayerEditor::_seek_value_changed,DEFVAL(true)); - ClassDB::bind_method(D_METHOD("_animation_player_changed"),&AnimationPlayerEditor::_animation_player_changed); - ClassDB::bind_method(D_METHOD("_blend_edited"),&AnimationPlayerEditor::_blend_edited); + ClassDB::bind_method(D_METHOD("_gui_input"), &AnimationPlayerEditor::_gui_input); + ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationPlayerEditor::_node_removed); + ClassDB::bind_method(D_METHOD("_play_pressed"), &AnimationPlayerEditor::_play_pressed); + ClassDB::bind_method(D_METHOD("_play_from_pressed"), &AnimationPlayerEditor::_play_from_pressed); + ClassDB::bind_method(D_METHOD("_play_bw_pressed"), &AnimationPlayerEditor::_play_bw_pressed); + ClassDB::bind_method(D_METHOD("_play_bw_from_pressed"), &AnimationPlayerEditor::_play_bw_from_pressed); + ClassDB::bind_method(D_METHOD("_stop_pressed"), &AnimationPlayerEditor::_stop_pressed); + ClassDB::bind_method(D_METHOD("_autoplay_pressed"), &AnimationPlayerEditor::_autoplay_pressed); + ClassDB::bind_method(D_METHOD("_pause_pressed"), &AnimationPlayerEditor::_pause_pressed); + ClassDB::bind_method(D_METHOD("_animation_selected"), &AnimationPlayerEditor::_animation_selected); + ClassDB::bind_method(D_METHOD("_animation_name_edited"), &AnimationPlayerEditor::_animation_name_edited); + ClassDB::bind_method(D_METHOD("_animation_new"), &AnimationPlayerEditor::_animation_new); + ClassDB::bind_method(D_METHOD("_animation_rename"), &AnimationPlayerEditor::_animation_rename); + ClassDB::bind_method(D_METHOD("_animation_load"), &AnimationPlayerEditor::_animation_load); + ClassDB::bind_method(D_METHOD("_animation_remove"), &AnimationPlayerEditor::_animation_remove); + ClassDB::bind_method(D_METHOD("_animation_remove_confirmed"), &AnimationPlayerEditor::_animation_remove_confirmed); + ClassDB::bind_method(D_METHOD("_animation_blend"), &AnimationPlayerEditor::_animation_blend); + ClassDB::bind_method(D_METHOD("_animation_edit"), &AnimationPlayerEditor::_animation_edit); + ClassDB::bind_method(D_METHOD("_animation_resource_edit"), &AnimationPlayerEditor::_animation_resource_edit); + ClassDB::bind_method(D_METHOD("_dialog_action"), &AnimationPlayerEditor::_dialog_action); + ClassDB::bind_method(D_METHOD("_seek_value_changed"), &AnimationPlayerEditor::_seek_value_changed, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("_animation_player_changed"), &AnimationPlayerEditor::_animation_player_changed); + ClassDB::bind_method(D_METHOD("_blend_edited"), &AnimationPlayerEditor::_blend_edited); //ClassDB::bind_method(D_METHOD("_seek_frame_changed"),&AnimationPlayerEditor::_seek_frame_changed); - ClassDB::bind_method(D_METHOD("_scale_changed"),&AnimationPlayerEditor::_scale_changed); + ClassDB::bind_method(D_METHOD("_scale_changed"), &AnimationPlayerEditor::_scale_changed); //ClassDB::bind_method(D_METHOD("_editor_store_all"),&AnimationPlayerEditor::_editor_store_all); //ClassDB::bind_method(D_METHOD("_editor_load_all"),&AnimationPlayerEditor::_editor_load_all); - ClassDB::bind_method(D_METHOD("_list_changed"),&AnimationPlayerEditor::_list_changed); - ClassDB::bind_method(D_METHOD("_animation_key_editor_seek"),&AnimationPlayerEditor::_animation_key_editor_seek); - ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_len_changed"),&AnimationPlayerEditor::_animation_key_editor_anim_len_changed); - ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_step_changed"),&AnimationPlayerEditor::_animation_key_editor_anim_step_changed); - ClassDB::bind_method(D_METHOD("_hide_anim_editors"),&AnimationPlayerEditor::_hide_anim_editors); - ClassDB::bind_method(D_METHOD("_animation_duplicate"),&AnimationPlayerEditor::_animation_duplicate); - ClassDB::bind_method(D_METHOD("_blend_editor_next_changed"),&AnimationPlayerEditor::_blend_editor_next_changed); - ClassDB::bind_method(D_METHOD("_unhandled_key_input"),&AnimationPlayerEditor::_unhandled_key_input); - ClassDB::bind_method(D_METHOD("_animation_tool_menu"),&AnimationPlayerEditor::_animation_tool_menu); + ClassDB::bind_method(D_METHOD("_list_changed"), &AnimationPlayerEditor::_list_changed); + ClassDB::bind_method(D_METHOD("_animation_key_editor_seek"), &AnimationPlayerEditor::_animation_key_editor_seek); + ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_len_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_len_changed); + ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_step_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_step_changed); + ClassDB::bind_method(D_METHOD("_hide_anim_editors"), &AnimationPlayerEditor::_hide_anim_editors); + ClassDB::bind_method(D_METHOD("_animation_duplicate"), &AnimationPlayerEditor::_animation_duplicate); + ClassDB::bind_method(D_METHOD("_blend_editor_next_changed"), &AnimationPlayerEditor::_blend_editor_next_changed); + ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &AnimationPlayerEditor::_unhandled_key_input); + ClassDB::bind_method(D_METHOD("_animation_tool_menu"), &AnimationPlayerEditor::_animation_tool_menu); ClassDB::bind_method(D_METHOD("_animation_save_menu"), &AnimationPlayerEditor::_animation_save_menu); - - - - } -AnimationPlayerEditor *AnimationPlayerEditor::singleton=NULL; +AnimationPlayerEditor *AnimationPlayerEditor::singleton = NULL; AnimationPlayer *AnimationPlayerEditor::get_player() const { return player; } AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { - editor=p_editor; - singleton=this; + editor = p_editor; + singleton = this; - updating=false; + updating = false; set_focus_mode(FOCUS_ALL); - player=NULL; - add_style_override("panel", get_stylebox("panel","Panel")); - + player = NULL; + add_style_override("panel", get_stylebox("panel", "Panel")); - Label * l; + Label *l; /*l= memnew( Label ); l->set_text("Animation Player:"); add_child(l);*/ - HBoxContainer *hb = memnew( HBoxContainer ); + HBoxContainer *hb = memnew(HBoxContainer); add_child(hb); - - play_bw_from = memnew( ToolButton ); + play_bw_from = memnew(ToolButton); play_bw_from->set_tooltip(TTR("Play selected animation backwards from current pos. (A)")); hb->add_child(play_bw_from); - play_bw = memnew( ToolButton ); + play_bw = memnew(ToolButton); play_bw->set_tooltip(TTR("Play selected animation backwards from end. (Shift+A)")); hb->add_child(play_bw); - stop = memnew( ToolButton ); + stop = memnew(ToolButton); stop->set_toggle_mode(true); hb->add_child(stop); stop->set_tooltip(TTR("Stop animation playback. (S)")); - play = memnew( ToolButton ); + play = memnew(ToolButton); play->set_tooltip(TTR("Play selected animation from start. (Shift+D)")); hb->add_child(play); - - play_from = memnew( ToolButton ); + play_from = memnew(ToolButton); play_from->set_tooltip(TTR("Play selected animation from current pos. (D)")); hb->add_child(play_from); - - //pause = memnew( Button ); //pause->set_toggle_mode(true); //hb->add_child(pause); - frame = memnew( SpinBox ); + frame = memnew(SpinBox); hb->add_child(frame); - frame->set_custom_minimum_size(Size2(60,0)); + frame->set_custom_minimum_size(Size2(60, 0)); frame->set_stretch_ratio(2); frame->set_tooltip(TTR("Animation position (in seconds).")); - hb->add_child( memnew( VSeparator)); + hb->add_child(memnew(VSeparator)); - scale = memnew( LineEdit ); + scale = memnew(LineEdit); hb->add_child(scale); scale->set_h_size_flags(SIZE_EXPAND_FILL); scale->set_stretch_ratio(1); scale->set_tooltip(TTR("Scale animation playback globally for the node.")); scale->hide(); - - add_anim = memnew( ToolButton ); + add_anim = memnew(ToolButton); ED_SHORTCUT("animation_player_editor/add_animation", TTR("Create new animation in player.")); add_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/add_animation")); add_anim->set_tooltip(TTR("Create new animation in player.")); hb->add_child(add_anim); - - load_anim = memnew( ToolButton ); + load_anim = memnew(ToolButton); ED_SHORTCUT("animation_player_editor/load_from_disk", TTR("Load animation from disk.")); add_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/load_from_disk")); load_anim->set_tooltip(TTR("Load an animation from disk.")); @@ -1402,159 +1325,146 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { add_child(delete_dialog); delete_dialog->connect("confirmed", this, "_animation_remove_confirmed"); - duplicate_anim = memnew( ToolButton ); + duplicate_anim = memnew(ToolButton); hb->add_child(duplicate_anim); ED_SHORTCUT("animation_player_editor/duplicate_animation", TTR("Duplicate Animation")); duplicate_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/duplicate_animation")); duplicate_anim->set_tooltip(TTR("Duplicate Animation")); - rename_anim = memnew( ToolButton ); + rename_anim = memnew(ToolButton); hb->add_child(rename_anim); ED_SHORTCUT("animation_player_editor/rename_animation", TTR("Rename Animation")); rename_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/rename_animation")); rename_anim->set_tooltip(TTR("Rename Animation")); - remove_anim = memnew( ToolButton ); + remove_anim = memnew(ToolButton); hb->add_child(remove_anim); ED_SHORTCUT("animation_player_editor/remove_animation", TTR("Remove Animation")); remove_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/remove_animation")); remove_anim->set_tooltip(TTR("Remove Animation")); - - animation = memnew( OptionButton ); + animation = memnew(OptionButton); hb->add_child(animation); animation->set_h_size_flags(SIZE_EXPAND_FILL); animation->set_tooltip(TTR("Display list of animations in player.")); animation->set_clip_text(true); - autoplay = memnew( ToolButton ); + autoplay = memnew(ToolButton); hb->add_child(autoplay); autoplay->set_tooltip(TTR("Autoplay on Load")); - - - blend_anim = memnew( ToolButton ); + blend_anim = memnew(ToolButton); hb->add_child(blend_anim); blend_anim->set_tooltip(TTR("Edit Target Blend Times")); - tool_anim = memnew( MenuButton); + tool_anim = memnew(MenuButton); //tool_anim->set_flat(false); tool_anim->set_tooltip(TTR("Animation Tools")); - tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/copy_animation", TTR("Copy Animation")),TOOL_COPY_ANIM); - tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/paste_animation", TTR("Paste Animation")),TOOL_PASTE_ANIM); + tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/copy_animation", TTR("Copy Animation")), TOOL_COPY_ANIM); + tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/paste_animation", TTR("Paste Animation")), TOOL_PASTE_ANIM); //tool_anim->get_popup()->add_separator(); //tool_anim->get_popup()->add_item("Edit Anim Resource",TOOL_PASTE_ANIM); hb->add_child(tool_anim); - nodename = memnew( Button ); + nodename = memnew(Button); hb->add_child(nodename); - pin = memnew( ToolButton ); + pin = memnew(ToolButton); pin->set_toggle_mode(true); hb->add_child(pin); - - - resource_edit_anim= memnew( Button ); + resource_edit_anim = memnew(Button); hb->add_child(resource_edit_anim); resource_edit_anim->hide(); - file = memnew(EditorFileDialog); add_child(file); - name_dialog = memnew( ConfirmationDialog ); + name_dialog = memnew(ConfirmationDialog); name_dialog->set_title(TTR("Create New Animation")); name_dialog->set_hide_on_ok(false); add_child(name_dialog); - name = memnew( LineEdit ); + name = memnew(LineEdit); name_dialog->add_child(name); - name->set_pos(Point2(18,30)); - name->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,10); + name->set_pos(Point2(18, 30)); + name->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 10); name_dialog->register_text_enter(name); - - l = memnew( Label ); + l = memnew(Label); l->set_text(TTR("Animation Name:")); - l->set_pos( Point2(10,10) ); + l->set_pos(Point2(10, 10)); name_dialog->add_child(l); - name_title=l; + name_title = l; - error_dialog = memnew( ConfirmationDialog ); + error_dialog = memnew(ConfirmationDialog); error_dialog->get_ok()->set_text(TTR("Close")); //error_dialog->get_cancel()->set_text("Close"); error_dialog->set_text(TTR("Error!")); add_child(error_dialog); - name_dialog->connect("confirmed", this,"_animation_name_edited"); + name_dialog->connect("confirmed", this, "_animation_name_edited"); - blend_editor.dialog = memnew( AcceptDialog ); + blend_editor.dialog = memnew(AcceptDialog); add_child(blend_editor.dialog); blend_editor.dialog->get_ok()->set_text(TTR("Close")); blend_editor.dialog->set_hide_on_ok(true); - VBoxContainer *blend_vb = memnew( VBoxContainer); + VBoxContainer *blend_vb = memnew(VBoxContainer); blend_editor.dialog->add_child(blend_vb); //blend_editor.dialog->set_child_rect(blend_vb); - blend_editor.tree = memnew( Tree ); + blend_editor.tree = memnew(Tree); blend_editor.tree->set_columns(2); - blend_vb->add_margin_child(TTR("Blend Times:"),blend_editor.tree,true); - blend_editor.next = memnew( OptionButton ); - blend_vb->add_margin_child(TTR("Next (Auto Queue):"),blend_editor.next); + blend_vb->add_margin_child(TTR("Blend Times:"), blend_editor.tree, true); + blend_editor.next = memnew(OptionButton); + blend_vb->add_margin_child(TTR("Next (Auto Queue):"), blend_editor.next); blend_editor.dialog->set_title(TTR("Cross-Animation Blend Times")); - updating_blends=false; + updating_blends = false; - blend_editor.tree->connect("item_edited",this,"_blend_edited"); + blend_editor.tree->connect("item_edited", this, "_blend_edited"); - - autoplay->connect("pressed", this,"_autoplay_pressed"); + autoplay->connect("pressed", this, "_autoplay_pressed"); autoplay->set_toggle_mode(true); - play->connect("pressed", this,"_play_pressed"); - play_from->connect("pressed", this,"_play_from_pressed"); - play_bw->connect("pressed", this,"_play_bw_pressed"); - play_bw_from->connect("pressed", this,"_play_bw_from_pressed"); - stop->connect("pressed", this,"_stop_pressed"); + play->connect("pressed", this, "_play_pressed"); + play_from->connect("pressed", this, "_play_from_pressed"); + play_bw->connect("pressed", this, "_play_bw_pressed"); + play_bw_from->connect("pressed", this, "_play_bw_from_pressed"); + stop->connect("pressed", this, "_stop_pressed"); //pause->connect("pressed", this,"_pause_pressed"); - add_anim->connect("pressed", this,"_animation_new"); - rename_anim->connect("pressed", this,"_animation_rename"); - load_anim->connect("pressed", this,"_animation_load"); - duplicate_anim->connect("pressed", this,"_animation_duplicate"); + add_anim->connect("pressed", this, "_animation_new"); + rename_anim->connect("pressed", this, "_animation_rename"); + load_anim->connect("pressed", this, "_animation_load"); + duplicate_anim->connect("pressed", this, "_animation_duplicate"); //frame->connect("text_entered", this,"_seek_frame_changed"); - blend_anim->connect("pressed", this,"_animation_blend"); - remove_anim->connect("pressed", this,"_animation_remove"); - animation->connect("item_selected", this,"_animation_selected",Vector(),true); - resource_edit_anim->connect("pressed", this,"_animation_resource_edit"); - file->connect("file_selected", this,"_dialog_action"); - frame->connect("value_changed", this, "_seek_value_changed",Vector(),true); - scale->connect("text_entered", this, "_scale_changed",Vector(),true); - + blend_anim->connect("pressed", this, "_animation_blend"); + remove_anim->connect("pressed", this, "_animation_remove"); + animation->connect("item_selected", this, "_animation_selected", Vector(), true); + resource_edit_anim->connect("pressed", this, "_animation_resource_edit"); + file->connect("file_selected", this, "_dialog_action"); + frame->connect("value_changed", this, "_seek_value_changed", Vector(), true); + scale->connect("text_entered", this, "_scale_changed", Vector(), true); - - renaming=false; - last_active=false; + renaming = false; + last_active = false; set_process_unhandled_key_input(true); - key_editor = memnew( AnimationKeyEditor); + key_editor = memnew(AnimationKeyEditor); add_child(key_editor); - add_constant_override("separation",get_constant("separation","VBoxContainer")); + add_constant_override("separation", get_constant("separation", "VBoxContainer")); key_editor->set_v_size_flags(SIZE_EXPAND_FILL); - key_editor->connect("timeline_changed",this,"_animation_key_editor_seek"); - key_editor->connect("animation_len_changed",this,"_animation_key_editor_anim_len_changed"); - key_editor->connect("animation_step_changed",this,"_animation_key_editor_anim_step_changed"); + key_editor->connect("timeline_changed", this, "_animation_key_editor_seek"); + key_editor->connect("animation_len_changed", this, "_animation_key_editor_anim_len_changed"); + key_editor->connect("animation_step_changed", this, "_animation_key_editor_anim_step_changed"); _update_player(); } - void AnimationPlayerEditorPlugin::edit(Object *p_object) { anim_editor->set_undo_redo(&get_undo_redo()); if (!p_object) return; anim_editor->edit(p_object->cast_to()); - - } bool AnimationPlayerEditorPlugin::handles(Object *p_object) const { @@ -1575,16 +1485,15 @@ void AnimationPlayerEditorPlugin::make_visible(bool p_visible) { //anim_editor->hide(); //anim_editor->set_idle_process(false); } - } AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) { - editor=p_node; - anim_editor = memnew( AnimationPlayerEditor(editor) ); + editor = p_node; + anim_editor = memnew(AnimationPlayerEditor(editor)); anim_editor->set_undo_redo(editor->get_undo_redo()); - editor->add_bottom_panel_item(TTR("Animation"),anim_editor); + editor->add_bottom_panel_item(TTR("Animation"), anim_editor); /* editor->get_viewport()->add_child(anim_editor); anim_editor->set_area_as_parent_rect(); @@ -1593,12 +1502,7 @@ AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) { anim_editor->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END); anim_editor->set_margin( MARGIN_RIGHT, 0 );*/ anim_editor->hide(); - - - } - -AnimationPlayerEditorPlugin::~AnimationPlayerEditorPlugin() -{ +AnimationPlayerEditorPlugin::~AnimationPlayerEditorPlugin() { } diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index d9b6ad52ff..0eee4afcd4 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -29,14 +29,13 @@ #ifndef ANIMATION_PLAYER_EDITOR_PLUGIN_H #define ANIMATION_PLAYER_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/animation/animation_player.h" #include "scene/gui/dialogs.h" -#include "scene/gui/texture_button.h" #include "scene/gui/slider.h" #include "scene/gui/spin_box.h" - +#include "scene/gui/texture_button.h" /** @author Juan Linietsky @@ -44,7 +43,7 @@ class AnimationKeyEditor; class AnimationPlayerEditor : public VBoxContainer { - GDCLASS(AnimationPlayerEditor, VBoxContainer ); + GDCLASS(AnimationPlayerEditor, VBoxContainer); EditorNode *editor; AnimationPlayer *player; @@ -65,7 +64,6 @@ class AnimationPlayerEditor : public VBoxContainer { RESOURCE_SAVE }; - OptionButton *animation; Button *stop; Button *play; @@ -97,30 +95,27 @@ class AnimationPlayerEditor : public VBoxContainer { EditorFileDialog *file; AcceptDialog *accept; - ConfirmationDialog* delete_dialog; + ConfirmationDialog *delete_dialog; int current_option; struct BlendEditor { - AcceptDialog * dialog; + AcceptDialog *dialog; Tree *tree; OptionButton *next; } blend_editor; - ConfirmationDialog *name_dialog; ConfirmationDialog *error_dialog; bool renaming; - bool updating; bool updating_blends; AnimationKeyEditor *key_editor; - - void _select_anim_by_name(const String& p_anim); + void _select_anim_by_name(const String &p_anim); void _play_pressed(); void _play_from_pressed(); void _play_bw_pressed(); @@ -134,9 +129,9 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_name_edited(); void _animation_load(); - void _animation_save_in_path(const Ref& p_resource, const String& p_path); - void _animation_save(const Ref& p_resource); - void _animation_save_as(const Ref& p_resource); + void _animation_save_in_path(const Ref &p_resource, const String &p_path); + void _animation_save(const Ref &p_resource); + void _animation_save_as(const Ref &p_resource); void _animation_remove(); void _animation_remove_confirmed(); @@ -144,10 +139,10 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_edit(); void _animation_duplicate(); void _animation_resource_edit(); - void _scale_changed(const String& p_scale); + void _scale_changed(const String &p_scale); void _dialog_action(String p_file); - void _seek_frame_changed(const String& p_frame); - void _seek_value_changed(float p_value, bool p_set=false); + void _seek_frame_changed(const String &p_frame); + void _seek_value_changed(float p_value, bool p_set = false); void _blend_editor_next_changed(const int p_idx); void _list_changed(); @@ -155,7 +150,6 @@ class AnimationPlayerEditor : public VBoxContainer { void _update_player(); void _blend_edited(); - void _hide_anim_editors(); void _animation_player_changed(Object *p_pl); @@ -164,46 +158,43 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_key_editor_anim_len_changed(float p_new); void _animation_key_editor_anim_step_changed(float p_len); - void _unhandled_key_input(const InputEvent& p_ev); + void _unhandled_key_input(const InputEvent &p_ev); void _animation_tool_menu(int p_option); void _animation_save_menu(int p_option); - AnimationPlayerEditor(); -protected: +protected: void _notification(int p_what); void _gui_input(InputEvent p_event); void _node_removed(Node *p_node); static void _bind_methods(); -public: +public: AnimationPlayer *get_player() const; static AnimationPlayerEditor *singleton; - AnimationKeyEditor* get_key_editor() { return key_editor; } + AnimationKeyEditor *get_key_editor() { return key_editor; } Dictionary get_state() const; - void set_state(const Dictionary& p_state); - + void set_state(const Dictionary &p_state); void ensure_visibility(); - void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo=p_undo_redo; } + void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } void edit(AnimationPlayer *p_player); AnimationPlayerEditor(EditorNode *p_editor); }; class AnimationPlayerEditorPlugin : public EditorPlugin { - GDCLASS( AnimationPlayerEditorPlugin, EditorPlugin ); + GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin); AnimationPlayerEditor *anim_editor; EditorNode *editor; public: - virtual Dictionary get_state() const { return anim_editor->get_state(); } - virtual void set_state(const Dictionary& p_state) { anim_editor->set_state(p_state); } + virtual void set_state(const Dictionary &p_state) { anim_editor->set_state(p_state); } virtual String get_name() const { return "Anim"; } bool has_main_screen() const { return false; } @@ -213,7 +204,6 @@ public: AnimationPlayerEditorPlugin(EditorNode *p_node); ~AnimationPlayerEditorPlugin(); - }; #endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 988136d475..7800fde7a8 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -28,18 +28,17 @@ /*************************************************************************/ #include "animation_tree_editor_plugin.h" -#include "scene/gui/menu_button.h" -#include "scene/gui/panel.h" -#include "scene/main/viewport.h" -#include "core/io/resource_loader.h" #include "core/global_config.h" +#include "core/io/resource_loader.h" #include "os/input.h" #include "os/keyboard.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/panel.h" +#include "scene/main/viewport.h" -void AnimationTreeEditor::edit(AnimationTreePlayer* p_anim_tree) { - +void AnimationTreeEditor::edit(AnimationTreePlayer *p_anim_tree) { - anim_tree=p_anim_tree; + anim_tree = p_anim_tree; if (!anim_tree) { hide(); @@ -55,59 +54,54 @@ void AnimationTreeEditor::edit(AnimationTreePlayer* p_anim_tree) { play_button->set_pressed(p_anim_tree->is_active()); //read the orders } - } Size2 AnimationTreeEditor::_get_maximum_size() { Size2 max; - for(List::Element *E=order.front();E;E=E->next()) { + for (List::Element *E = order.front(); E; E = E->next()) { Point2 pos = anim_tree->node_get_pos(E->get()); - if (click_type==CLICK_NODE && click_node==E->get()) { + if (click_type == CLICK_NODE && click_node == E->get()) { - pos+=click_motion-click_pos; + pos += click_motion - click_pos; } - pos+=get_node_size(E->get()); - if (pos.x>max.x) - max.x=pos.x; - if (pos.y>max.y) - max.y=pos.y; - + pos += get_node_size(E->get()); + if (pos.x > max.x) + max.x = pos.x; + if (pos.y > max.y) + max.y = pos.y; } return max; } +const char *AnimationTreeEditor::_node_type_names[] = { "Output", "Animation", "OneShot", "Mix", "Blend2", "Blend3", "Blend4", "TimeScale", "TimeSeek", "Transition" }; -const char* AnimationTreeEditor::_node_type_names[]={"Output","Animation","OneShot","Mix","Blend2","Blend3","Blend4","TimeScale","TimeSeek","Transition"}; - -Size2 AnimationTreeEditor::get_node_size(const StringName& p_node) const { +Size2 AnimationTreeEditor::get_node_size(const StringName &p_node) const { - AnimationTreePlayer::NodeType type=anim_tree->node_get_type(p_node); + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); - Ref style = get_stylebox("panel","PopupMenu"); - Ref font = get_font("font","PopupMenu"); + Ref style = get_stylebox("panel", "PopupMenu"); + Ref font = get_font("font", "PopupMenu"); Size2 size = style->get_minimum_size(); - int count=2; // title and name + int count = 2; // title and name int inputs = anim_tree->node_get_input_count(p_node); - count += inputs?inputs:1; + count += inputs ? inputs : 1; String name = p_node; + float name_w = font->get_string_size(name).width; + float type_w = font->get_string_size(String(_node_type_names[type])).width; + float max_w = MAX(name_w, type_w); - float name_w = font->get_string_size( name ).width; - float type_w = font->get_string_size( String(_node_type_names[type]) ).width; - float max_w=MAX(name_w,type_w); - - - - switch(type) { + switch (type) { case AnimationTreePlayer::NODE_TIMESEEK: - case AnimationTreePlayer::NODE_OUTPUT: {} break; + case AnimationTreePlayer::NODE_OUTPUT: { + } break; case AnimationTreePlayer::NODE_ANIMATION: case AnimationTreePlayer::NODE_ONESHOT: case AnimationTreePlayer::NODE_MIX: @@ -117,19 +111,18 @@ Size2 AnimationTreeEditor::get_node_size(const StringName& p_node) const { case AnimationTreePlayer::NODE_TIMESCALE: case AnimationTreePlayer::NODE_TRANSITION: { - - size.height+=font->get_height(); + size.height += font->get_height(); } break; - case AnimationTreePlayer::NODE_MAX: {} + case AnimationTreePlayer::NODE_MAX: { + } } - size.x+=max_w+20; - size.y+=count*(font->get_height()+get_constant("vseparation","PopupMenu")); + size.x += max_w + 20; + size.y += count * (font->get_height() + get_constant("vseparation", "PopupMenu")); return size; } - void AnimationTreeEditor::_edit_dialog_changede(String) { edit_dialog->hide(); @@ -152,69 +145,67 @@ void AnimationTreeEditor::_edit_dialog_changed() { if (renaming_edit) { - if (anim_tree->node_rename(edited_node,edit_line[0]->get_text())==OK) { - for(List::Element* E=order.front();E;E=E->next()) { + if (anim_tree->node_rename(edited_node, edit_line[0]->get_text()) == OK) { + for (List::Element *E = order.front(); E; E = E->next()) { if (E->get() == edited_node) - E->get()=edit_line[0]->get_text(); + E->get() = edit_line[0]->get_text(); } - edited_node=edit_line[0]->get_text(); + edited_node = edit_line[0]->get_text(); } update(); return; } - AnimationTreePlayer::NodeType type=anim_tree->node_get_type(edited_node); + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); - switch(type) { + switch (type) { - case AnimationTreePlayer::NODE_TIMESCALE: - anim_tree->timescale_node_set_scale(edited_node,edit_line[0]->get_text().to_double()); + case AnimationTreePlayer::NODE_TIMESCALE: + anim_tree->timescale_node_set_scale(edited_node, edit_line[0]->get_text().to_double()); break; - case AnimationTreePlayer::NODE_ONESHOT: - anim_tree->oneshot_node_set_fadein_time(edited_node,edit_line[0]->get_text().to_double()); - anim_tree->oneshot_node_set_fadeout_time(edited_node,edit_line[1]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart_delay(edited_node,edit_line[2]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart_random_delay(edited_node,edit_line[3]->get_text().to_double()); - anim_tree->oneshot_node_set_autorestart(edited_node,edit_check->is_pressed()); - anim_tree->oneshot_node_set_mix_mode(edited_node,edit_option->get_selected()); + case AnimationTreePlayer::NODE_ONESHOT: + anim_tree->oneshot_node_set_fadein_time(edited_node, edit_line[0]->get_text().to_double()); + anim_tree->oneshot_node_set_fadeout_time(edited_node, edit_line[1]->get_text().to_double()); + anim_tree->oneshot_node_set_autorestart_delay(edited_node, edit_line[2]->get_text().to_double()); + anim_tree->oneshot_node_set_autorestart_random_delay(edited_node, edit_line[3]->get_text().to_double()); + anim_tree->oneshot_node_set_autorestart(edited_node, edit_check->is_pressed()); + anim_tree->oneshot_node_set_mix_mode(edited_node, edit_option->get_selected()); break; - case AnimationTreePlayer::NODE_MIX: + case AnimationTreePlayer::NODE_MIX: - anim_tree->mix_node_set_amount(edited_node,edit_scroll[0]->get_value()); - break; - case AnimationTreePlayer::NODE_BLEND2: - anim_tree->blend2_node_set_amount(edited_node,edit_scroll[0]->get_value()); + anim_tree->mix_node_set_amount(edited_node, edit_scroll[0]->get_value()); + break; + case AnimationTreePlayer::NODE_BLEND2: + anim_tree->blend2_node_set_amount(edited_node, edit_scroll[0]->get_value()); - break; + break; - case AnimationTreePlayer::NODE_BLEND3: - anim_tree->blend3_node_set_amount(edited_node,edit_scroll[0]->get_value()); + case AnimationTreePlayer::NODE_BLEND3: + anim_tree->blend3_node_set_amount(edited_node, edit_scroll[0]->get_value()); - break; + break; case AnimationTreePlayer::NODE_BLEND4: - anim_tree->blend4_node_set_amount(edited_node,Point2(edit_scroll[0]->get_value(),edit_scroll[1]->get_value())); + anim_tree->blend4_node_set_amount(edited_node, Point2(edit_scroll[0]->get_value(), edit_scroll[1]->get_value())); break; - case AnimationTreePlayer::NODE_TRANSITION: { - anim_tree->transition_node_set_xfade_time(edited_node,edit_line[0]->get_text().to_double()); - if (anim_tree->transition_node_get_current(edited_node)!=edit_option->get_selected()) - anim_tree->transition_node_set_current(edited_node,edit_option->get_selected()); + case AnimationTreePlayer::NODE_TRANSITION: { + anim_tree->transition_node_set_xfade_time(edited_node, edit_line[0]->get_text().to_double()); + if (anim_tree->transition_node_get_current(edited_node) != edit_option->get_selected()) + anim_tree->transition_node_set_current(edited_node, edit_option->get_selected()); } break; default: {} } - } void AnimationTreeEditor::_edit_dialog_animation_changed() { - Ref anim = property_editor->get_variant().operator RefPtr(); - anim_tree->animation_node_set_animation(edited_node,anim); + anim_tree->animation_node_set_animation(edited_node, anim); update(); } @@ -235,26 +226,26 @@ void AnimationTreeEditor::_play_toggled() { anim_tree->set_active(play_button->is_pressed()); } - void AnimationTreeEditor::_master_anim_menu_item(int p_item) { - if(p_item == 0) _edit_filters(); + if (p_item == 0) + _edit_filters(); else { String str = master_anim_popup->get_item_text(p_item); - anim_tree->animation_node_set_master_animation(edited_node,str); + anim_tree->animation_node_set_master_animation(edited_node, str); } update(); } void AnimationTreeEditor::_popup_edit_dialog() { - updating_edit=true; + updating_edit = true; - for(int i=0;i<2;i++) + for (int i = 0; i < 2; i++) edit_scroll[i]->hide(); - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { edit_line[i]->hide(); edit_label[i]->hide(); @@ -265,32 +256,31 @@ void AnimationTreeEditor::_popup_edit_dialog() { filter_button->hide(); edit_check->hide(); - Point2 pos = anim_tree->node_get_pos(edited_node)-Point2(h_scroll->get_value(),v_scroll->get_value()); - Ref style = get_stylebox("panel","PopupMenu"); + Point2 pos = anim_tree->node_get_pos(edited_node) - Point2(h_scroll->get_value(), v_scroll->get_value()); + Ref style = get_stylebox("panel", "PopupMenu"); Size2 size = get_node_size(edited_node); - Point2 popup_pos( pos.x+style->get_margin(MARGIN_LEFT), pos.y+size.y-style->get_margin(MARGIN_BOTTOM)); - popup_pos+=get_global_pos(); + Point2 popup_pos(pos.x + style->get_margin(MARGIN_LEFT), pos.y + size.y - style->get_margin(MARGIN_BOTTOM)); + popup_pos += get_global_pos(); if (renaming_edit) { edit_label[0]->set_text(TTR("New name:")); - edit_label[0]->set_pos(Point2(5,5)); + edit_label[0]->set_pos(Point2(5, 5)); edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15,25)); + edit_line[0]->set_begin(Point2(15, 25)); edit_line[0]->set_text(edited_node); edit_line[0]->show(); - edit_dialog->set_size(Size2(150,50)); + edit_dialog->set_size(Size2(150, 50)); } else { - AnimationTreePlayer::NodeType type=anim_tree->node_get_type(edited_node); + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node); - - switch(type) { + switch (type) { case AnimationTreePlayer::NODE_ANIMATION: - if (anim_tree->get_master_player()!=NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && anim_tree->get_node(anim_tree->get_master_player())->cast_to()) { + if (anim_tree->get_master_player() != NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && anim_tree->get_node(anim_tree->get_master_player())->cast_to()) { AnimationPlayer *ap = anim_tree->get_node(anim_tree->get_master_player())->cast_to(); master_anim_popup->clear(); @@ -299,302 +289,293 @@ void AnimationTreeEditor::_popup_edit_dialog() { List sn; ap->get_animation_list(&sn); sn.sort_custom(); - for (List::Element *E=sn.front();E;E=E->next()) { + for (List::Element *E = sn.front(); E; E = E->next()) { master_anim_popup->add_item(E->get()); } master_anim_popup->set_pos(popup_pos); master_anim_popup->popup(); } else { - property_editor->edit(this,"",Variant::OBJECT,anim_tree->animation_node_get_animation(edited_node),PROPERTY_HINT_RESOURCE_TYPE,"Animation"); + property_editor->edit(this, "", Variant::OBJECT, anim_tree->animation_node_get_animation(edited_node), PROPERTY_HINT_RESOURCE_TYPE, "Animation"); property_editor->set_pos(popup_pos); property_editor->popup(); - updating_edit=false; + updating_edit = false; } return; - case AnimationTreePlayer::NODE_TIMESCALE: + case AnimationTreePlayer::NODE_TIMESCALE: edit_label[0]->set_text(TTR("Scale:")); - edit_label[0]->set_pos(Point2(5,5)); + edit_label[0]->set_pos(Point2(5, 5)); edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15,25)); + edit_line[0]->set_begin(Point2(15, 25)); edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node))); edit_line[0]->show(); - edit_dialog->set_size(Size2(150,50)); + edit_dialog->set_size(Size2(150, 50)); break; - case AnimationTreePlayer::NODE_ONESHOT: + case AnimationTreePlayer::NODE_ONESHOT: edit_label[0]->set_text(TTR("Fade In (s):")); - edit_label[0]->set_pos(Point2(5,5)); + edit_label[0]->set_pos(Point2(5, 5)); edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15,25)); + edit_line[0]->set_begin(Point2(15, 25)); edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node))); edit_line[0]->show(); edit_label[1]->set_text(TTR("Fade Out (s):")); - edit_label[1]->set_pos(Point2(5,55)); + edit_label[1]->set_pos(Point2(5, 55)); edit_label[1]->show(); - edit_line[1]->set_begin(Point2(15,75)); + edit_line[1]->set_begin(Point2(15, 75)); edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node))); edit_line[1]->show(); edit_option->clear(); - edit_option->add_item(TTR("Blend"),0); - edit_option->add_item(TTR("Mix"),1); - edit_option->set_begin(Point2(15,105)); + edit_option->add_item(TTR("Blend"), 0); + edit_option->add_item(TTR("Mix"), 1); + edit_option->set_begin(Point2(15, 105)); - edit_option->select( anim_tree->oneshot_node_get_mix_mode(edited_node)); + edit_option->select(anim_tree->oneshot_node_get_mix_mode(edited_node)); edit_option->show(); edit_check->set_text(TTR("Auto Restart:")); - edit_check->set_begin(Point2(15,125)); + edit_check->set_begin(Point2(15, 125)); edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node)); edit_check->show(); edit_label[2]->set_text(TTR("Restart (s):")); - edit_label[2]->set_pos(Point2(5,145)); + edit_label[2]->set_pos(Point2(5, 145)); edit_label[2]->show(); - edit_line[2]->set_begin(Point2(15,165)); + edit_line[2]->set_begin(Point2(15, 165)); edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node))); edit_line[2]->show(); edit_label[3]->set_text(TTR("Random Restart (s):")); - edit_label[3]->set_pos(Point2(5,195)); + edit_label[3]->set_pos(Point2(5, 195)); edit_label[3]->show(); - edit_line[3]->set_begin(Point2(15,215)); + edit_line[3]->set_begin(Point2(15, 215)); edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node))); edit_line[3]->show(); - filter_button->set_begin(Point2(10,245)); + filter_button->set_begin(Point2(10, 245)); filter_button->show(); - edit_button->set_begin(Point2(10,268)); + edit_button->set_begin(Point2(10, 268)); edit_button->set_text(TTR("Start!")); edit_button->show(); - edit_dialog->set_size(Size2(180,293)); + edit_dialog->set_size(Size2(180, 293)); + + break; + + case AnimationTreePlayer::NODE_MIX: + + edit_label[0]->set_text(TTR("Amount:")); + edit_label[0]->set_pos(Point2(5, 5)); + edit_label[0]->show(); + edit_scroll[0]->set_min(0); + edit_scroll[0]->set_max(1); + edit_scroll[0]->set_value(anim_tree->mix_node_get_amount(edited_node)); + edit_scroll[0]->set_begin(Point2(15, 25)); + edit_scroll[0]->show(); + edit_dialog->set_size(Size2(150, 50)); break; + case AnimationTreePlayer::NODE_BLEND2: + edit_label[0]->set_text(TTR("Blend:")); + edit_label[0]->set_pos(Point2(5, 5)); + edit_label[0]->show(); + edit_scroll[0]->set_min(0); + edit_scroll[0]->set_max(1); + edit_scroll[0]->set_value(anim_tree->blend2_node_get_amount(edited_node)); + edit_scroll[0]->set_begin(Point2(15, 25)); + edit_scroll[0]->show(); + filter_button->set_begin(Point2(10, 47)); + filter_button->show(); + edit_dialog->set_size(Size2(150, 74)); - case AnimationTreePlayer::NODE_MIX: - - edit_label[0]->set_text(TTR("Amount:")); - edit_label[0]->set_pos(Point2(5,5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_value(anim_tree->mix_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15,25)); - edit_scroll[0]->show(); - edit_dialog->set_size(Size2(150,50)); - - break; - case AnimationTreePlayer::NODE_BLEND2: - edit_label[0]->set_text(TTR("Blend:")); - edit_label[0]->set_pos(Point2(5,5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(0); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_value(anim_tree->blend2_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15,25)); - edit_scroll[0]->show(); - filter_button->set_begin(Point2(10,47)); - filter_button->show(); - edit_dialog->set_size(Size2(150,74)); - - break; - - case AnimationTreePlayer::NODE_BLEND3: - edit_label[0]->set_text(TTR("Blend:")); - edit_label[0]->set_pos(Point2(5,5)); - edit_label[0]->show(); - edit_scroll[0]->set_min(-1); - edit_scroll[0]->set_max(1); - edit_scroll[0]->set_value(anim_tree->blend3_node_get_amount(edited_node)); - edit_scroll[0]->set_begin(Point2(15,25)); - edit_scroll[0]->show(); - edit_dialog->set_size(Size2(150,50)); - - break; + break; + + case AnimationTreePlayer::NODE_BLEND3: + edit_label[0]->set_text(TTR("Blend:")); + edit_label[0]->set_pos(Point2(5, 5)); + edit_label[0]->show(); + edit_scroll[0]->set_min(-1); + edit_scroll[0]->set_max(1); + edit_scroll[0]->set_value(anim_tree->blend3_node_get_amount(edited_node)); + edit_scroll[0]->set_begin(Point2(15, 25)); + edit_scroll[0]->show(); + edit_dialog->set_size(Size2(150, 50)); + + break; case AnimationTreePlayer::NODE_BLEND4: edit_label[0]->set_text(TTR("Blend 0:")); - edit_label[0]->set_pos(Point2(5,5)); + edit_label[0]->set_pos(Point2(5, 5)); edit_label[0]->show(); edit_scroll[0]->set_min(0); edit_scroll[0]->set_max(1); edit_scroll[0]->set_value(anim_tree->blend4_node_get_amount(edited_node).x); - edit_scroll[0]->set_begin(Point2(15,25)); + edit_scroll[0]->set_begin(Point2(15, 25)); edit_scroll[0]->show(); edit_label[1]->set_text(TTR("Blend 1:")); - edit_label[1]->set_pos(Point2(5,55)); + edit_label[1]->set_pos(Point2(5, 55)); edit_label[1]->show(); edit_scroll[1]->set_min(0); edit_scroll[1]->set_max(1); edit_scroll[1]->set_value(anim_tree->blend4_node_get_amount(edited_node).y); - edit_scroll[1]->set_begin(Point2(15,75)); + edit_scroll[1]->set_begin(Point2(15, 75)); edit_scroll[1]->show(); - edit_dialog->set_size(Size2(150,100)); + edit_dialog->set_size(Size2(150, 100)); break; - case AnimationTreePlayer::NODE_TRANSITION: { - + case AnimationTreePlayer::NODE_TRANSITION: { - edit_label[0]->set_text(TTR("X-Fade Time (s):")); - edit_label[0]->set_pos(Point2(5,5)); - edit_label[0]->show(); - edit_line[0]->set_begin(Point2(15,25)); - edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node))); - edit_line[0]->show(); + edit_label[0]->set_text(TTR("X-Fade Time (s):")); + edit_label[0]->set_pos(Point2(5, 5)); + edit_label[0]->show(); + edit_line[0]->set_begin(Point2(15, 25)); + edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node))); + edit_line[0]->show(); - edit_label[1]->set_text(TTR("Current:")); - edit_label[1]->set_pos(Point2(5,55)); - edit_label[1]->show(); - edit_option->set_begin(Point2(15,75)); + edit_label[1]->set_text(TTR("Current:")); + edit_label[1]->set_pos(Point2(5, 55)); + edit_label[1]->show(); + edit_option->set_begin(Point2(15, 75)); - edit_option->clear(); + edit_option->clear(); - for(int i=0;itransition_node_get_input_count(edited_node);i++) { - edit_option->add_item(itos(i),i); - } + for (int i = 0; i < anim_tree->transition_node_get_input_count(edited_node); i++) { + edit_option->add_item(itos(i), i); + } - edit_option->select(anim_tree->transition_node_get_current(edited_node)); - edit_option->show(); - edit_dialog->set_size(Size2(150,100)); + edit_option->select(anim_tree->transition_node_get_current(edited_node)); + edit_option->show(); + edit_dialog->set_size(Size2(150, 100)); } break; default: {} - } - } - - edit_dialog->set_pos(popup_pos); edit_dialog->popup(); - updating_edit=false; + updating_edit = false; } -void AnimationTreeEditor::_draw_node(const StringName& p_node) { +void AnimationTreeEditor::_draw_node(const StringName &p_node) { RID ci = get_canvas_item(); - AnimationTreePlayer::NodeType type=anim_tree->node_get_type(p_node); - - Ref style = get_stylebox("panel","PopupMenu"); - Ref font = get_font("font","PopupMenu"); - Color font_color = get_color("font_color","PopupMenu"); - Color font_color_title = get_color("font_color_hover","PopupMenu"); - font_color_title.a*=0.8; - Ref slot_icon = get_icon("NodeRealSlot","EditorIcons"); + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); + Ref style = get_stylebox("panel", "PopupMenu"); + Ref font = get_font("font", "PopupMenu"); + Color font_color = get_color("font_color", "PopupMenu"); + Color font_color_title = get_color("font_color_hover", "PopupMenu"); + font_color_title.a *= 0.8; + Ref slot_icon = get_icon("NodeRealSlot", "EditorIcons"); - Size2 size=get_node_size(p_node); + Size2 size = get_node_size(p_node); Point2 pos = anim_tree->node_get_pos(p_node); - if (click_type==CLICK_NODE && click_node==p_node) { - - pos+=click_motion-click_pos; - if (pos.x<5) - pos.x=5; - if (pos.y<5) - pos.y=5; + if (click_type == CLICK_NODE && click_node == p_node) { + pos += click_motion - click_pos; + if (pos.x < 5) + pos.x = 5; + if (pos.y < 5) + pos.y = 5; } - pos-=Point2(h_scroll->get_value(),v_scroll->get_value()); + pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - style->draw(ci,Rect2(pos,size)); + style->draw(ci, Rect2(pos, size)); - float w = size.width-style->get_minimum_size().width; - float h = font->get_height()+get_constant("vseparation","PopupMenu"); + float w = size.width - style->get_minimum_size().width; + float h = font->get_height() + get_constant("vseparation", "PopupMenu"); - Point2 ofs=style->get_offset()+pos; - Point2 ascofs(0,font->get_ascent()); + Point2 ofs = style->get_offset() + pos; + Point2 ascofs(0, font->get_ascent()); Color bx = font_color_title; - bx.a*=0.1; - draw_rect(Rect2(ofs,Size2(size.width-style->get_minimum_size().width,font->get_height())),bx); - font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,String(_node_type_names[type]),font_color_title); + bx.a *= 0.1; + draw_rect(Rect2(ofs, Size2(size.width - style->get_minimum_size().width, font->get_height())), bx); + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, String(_node_type_names[type]), font_color_title); - ofs.y+=h; - font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,p_node,font_color); - ofs.y+=h; + ofs.y += h; + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, p_node, font_color); + ofs.y += h; - int count=2; // title and name + int count = 2; // title and name int inputs = anim_tree->node_get_input_count(p_node); - count += inputs?inputs:1; + count += inputs ? inputs : 1; - float icon_h_ofs = Math::floor(( font->get_height()-slot_icon->get_height())/2.0 )+1; + float icon_h_ofs = Math::floor((font->get_height() - slot_icon->get_height()) / 2.0) + 1; - if (type!=AnimationTreePlayer::NODE_OUTPUT) - slot_icon->draw(ci,ofs+Point2(w,icon_h_ofs)); //output + if (type != AnimationTreePlayer::NODE_OUTPUT) + slot_icon->draw(ci, ofs + Point2(w, icon_h_ofs)); //output if (inputs) { - for(int i=0;idraw(ci,ofs+Point2(-slot_icon->get_width(),icon_h_ofs)); + slot_icon->draw(ci, ofs + Point2(-slot_icon->get_width(), icon_h_ofs)); String text; - switch(type) { - - case AnimationTreePlayer::NODE_TIMESCALE: - case AnimationTreePlayer::NODE_TIMESEEK: text="in"; break; - case AnimationTreePlayer::NODE_OUTPUT: text="out"; break; - case AnimationTreePlayer::NODE_ANIMATION: break; - case AnimationTreePlayer::NODE_ONESHOT: text=(i==0?"in":"add"); break; - case AnimationTreePlayer::NODE_BLEND2: - case AnimationTreePlayer::NODE_MIX: text=(i==0?"a":"b"); break; - case AnimationTreePlayer::NODE_BLEND3: - switch(i) { - case 0: text="b-"; break; - case 1: text="a"; break; - case 2: text="b+"; break; - - } - break; - - - case AnimationTreePlayer::NODE_BLEND4: - switch(i) { - case 0: text="a0"; break; - case 1: text="b0"; break; - case 2: text="a1"; break; - case 3: text="b1"; break; - } - break; - - case AnimationTreePlayer::NODE_TRANSITION: - text=itos(i); - if (anim_tree->transition_node_has_input_auto_advance(p_node,i)) - text+="->"; - - break; - default: {} + switch (type) { + + case AnimationTreePlayer::NODE_TIMESCALE: + case AnimationTreePlayer::NODE_TIMESEEK: text = "in"; break; + case AnimationTreePlayer::NODE_OUTPUT: text = "out"; break; + case AnimationTreePlayer::NODE_ANIMATION: break; + case AnimationTreePlayer::NODE_ONESHOT: text = (i == 0 ? "in" : "add"); break; + case AnimationTreePlayer::NODE_BLEND2: + case AnimationTreePlayer::NODE_MIX: text = (i == 0 ? "a" : "b"); break; + case AnimationTreePlayer::NODE_BLEND3: + switch (i) { + case 0: text = "b-"; break; + case 1: text = "a"; break; + case 2: text = "b+"; break; + } + break; + + case AnimationTreePlayer::NODE_BLEND4: + switch (i) { + case 0: text = "a0"; break; + case 1: text = "b0"; break; + case 2: text = "a1"; break; + case 3: text = "b1"; break; + } + break; + + case AnimationTreePlayer::NODE_TRANSITION: + text = itos(i); + if (anim_tree->transition_node_has_input_auto_advance(p_node, i)) + text += "->"; + + break; + default: {} } - font->draw(ci,ofs+ascofs+Point2(3,0),text,font_color); + font->draw(ci, ofs + ascofs + Point2(3, 0), text, font_color); - ofs.y+=h; + ofs.y += h; } } else { - ofs.y+=h; + ofs.y += h; } - Ref pg_bg=get_stylebox("bg","ProgressBar"); - Ref pg_fill=get_stylebox("fill","ProgressBar"); - Rect2 pg_rect(ofs,Size2(w,h)); + Ref pg_bg = get_stylebox("bg", "ProgressBar"); + Ref pg_fill = get_stylebox("fill", "ProgressBar"); + Rect2 pg_rect(ofs, Size2(w, h)); - bool editable=true; - switch(type) { + bool editable = true; + switch (type) { case AnimationTreePlayer::NODE_ANIMATION: { Ref anim = anim_tree->animation_node_get_animation(p_node); String text; - if (anim_tree->animation_node_get_master_animation(p_node)!="") - text=anim_tree->animation_node_get_master_animation(p_node); + if (anim_tree->animation_node_get_master_animation(p_node) != "") + text = anim_tree->animation_node_get_master_animation(p_node); else if (anim.is_null()) - text="load.."; + text = "load.."; else - text=anim->get_name(); + text = anim->get_name(); - font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,text,font_color_title); + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, text, font_color_title); } break; case AnimationTreePlayer::NODE_ONESHOT: @@ -605,16 +586,16 @@ void AnimationTreeEditor::_draw_node(const StringName& p_node) { case AnimationTreePlayer::NODE_TIMESCALE: case AnimationTreePlayer::NODE_TRANSITION: { - font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,"edit..",font_color_title); + font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, "edit..", font_color_title); } break; - default: editable=false; + default: editable = false; } if (editable) { - Ref arrow = get_icon("arrow","Tree"); - Point2 arrow_ofs( w-arrow->get_width(),Math::floor( (h-arrow->get_height())/2) ); - arrow->draw(ci,ofs+arrow_ofs); + Ref arrow = get_icon("arrow", "Tree"); + Point2 arrow_ofs(w - arrow->get_width(), Math::floor((h - arrow->get_height()) / 2)); + arrow->draw(ci, ofs + arrow_ofs); } } @@ -627,110 +608,104 @@ void AnimationTreeEditor::_node_param_changed() { } #endif -AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2& p_click,StringName *p_node_id,int *p_slot_index) const { - +AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const { - Ref style = get_stylebox("panel","PopupMenu"); - Ref font = get_font("font","PopupMenu"); + Ref style = get_stylebox("panel", "PopupMenu"); + Ref font = get_font("font", "PopupMenu"); - float h = (font->get_height()+get_constant("vseparation","PopupMenu")); + float h = (font->get_height() + get_constant("vseparation", "PopupMenu")); - for(const List::Element *E=order.back();E;E=E->prev()) { + for (const List::Element *E = order.back(); E; E = E->prev()) { StringName node = E->get(); - AnimationTreePlayer::NodeType type=anim_tree->node_get_type(node); + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(node); Point2 pos = anim_tree->node_get_pos(node); Size2 size = get_node_size(node); - pos-=Point2(h_scroll->get_value(),v_scroll->get_value()); + pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - if (!Rect2(pos,size).has_point(p_click)) + if (!Rect2(pos, size).has_point(p_click)) continue; if (p_node_id) - *p_node_id=node; + *p_node_id = node; - pos=p_click-pos; + pos = p_click - pos; - float y = pos.y-style->get_offset().height; + float y = pos.y - style->get_offset().height; - if (y<2*h) + if (y < 2 * h) return CLICK_NODE; - y-=2*h; + y -= 2 * h; int inputs = anim_tree->node_get_input_count(node); - int count = MAX(inputs,1); + int count = MAX(inputs, 1); - if (inputs==0 || (pos.x > size.width/2 && type != AnimationTreePlayer::NODE_OUTPUT)) { + if (inputs == 0 || (pos.x > size.width / 2 && type != AnimationTreePlayer::NODE_OUTPUT)) { - if (y style = get_stylebox("panel","PopupMenu"); - Ref font = get_font("font","PopupMenu"); - Ref slot_icon = get_icon("NodeRealSlot","EditorIcons"); + Ref style = get_stylebox("panel", "PopupMenu"); + Ref font = get_font("font", "PopupMenu"); + Ref slot_icon = get_icon("NodeRealSlot", "EditorIcons"); - Size2 size=get_node_size(p_node); + Size2 size = get_node_size(p_node); Point2 pos = anim_tree->node_get_pos(p_node); - if (click_type==CLICK_NODE && click_node==p_node) { - - pos+=click_motion-click_pos; - if (pos.x<5) - pos.x=5; - if (pos.y<5) - pos.y=5; + if (click_type == CLICK_NODE && click_node == p_node) { + pos += click_motion - click_pos; + if (pos.x < 5) + pos.x = 5; + if (pos.y < 5) + pos.y = 5; } - pos-=Point2(h_scroll->get_value(),v_scroll->get_value()); + pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); + float w = size.width - style->get_minimum_size().width; + float h = font->get_height() + get_constant("vseparation", "PopupMenu"); - float w = size.width-style->get_minimum_size().width; - float h = font->get_height()+get_constant("vseparation","PopupMenu"); + pos += style->get_offset(); + pos.y += h * 2; - pos+=style->get_offset(); + pos.y += h * p_slot; - pos.y+=h*2; - - pos.y+=h*p_slot; - - pos+=Point2( -slot_icon->get_width()/2.0, h/2.0).floor(); - - if(!p_input) { - pos.x+=w+slot_icon->get_width(); + pos += Point2(-slot_icon->get_width() / 2.0, h / 2.0).floor(); + if (!p_input) { + pos.x += w + slot_icon->get_width(); } return pos; - } #if 0 @@ -761,123 +736,117 @@ void AnimationTreeEditor::_node_edit_property(const StringName& p_node) { void AnimationTreeEditor::_gui_input(InputEvent p_event) { - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { if (p_event.mouse_button.pressed) { - - if (p_event.mouse_button.button_index==1) { - click_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); - click_motion=click_pos; - click_type = _locate_click(click_pos,&click_node,&click_slot); - if( click_type!=CLICK_NONE) { + if (p_event.mouse_button.button_index == 1) { + click_pos = Point2(p_event.mouse_button.x, p_event.mouse_button.y); + click_motion = click_pos; + click_type = _locate_click(click_pos, &click_node, &click_slot); + if (click_type != CLICK_NONE) { order.erase(click_node); order.push_back(click_node); update(); } - switch(click_type) { + switch (click_type) { case CLICK_INPUT_SLOT: { - click_pos=_get_slot_pos(click_node,true,click_slot); + click_pos = _get_slot_pos(click_node, true, click_slot); } break; case CLICK_OUTPUT_SLOT: { - click_pos=_get_slot_pos(click_node,false,click_slot); + click_pos = _get_slot_pos(click_node, false, click_slot); } break; case CLICK_PARAMETER: { - edited_node=click_node; - renaming_edit=false; + edited_node = click_node; + renaming_edit = false; _popup_edit_dialog(); //open editor //_node_edit_property(click_node); } break; - default:{} + default: {} } } - if (p_event.mouse_button.button_index==2) { + if (p_event.mouse_button.button_index == 2) { - if (click_type!=CLICK_NONE) { - click_type=CLICK_NONE; + if (click_type != CLICK_NONE) { + click_type = CLICK_NONE; update(); } else { // try to disconnect/remove - Point2 rclick_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); - rclick_type = _locate_click(rclick_pos,&rclick_node,&rclick_slot); - if (rclick_type==CLICK_INPUT_SLOT || rclick_type==CLICK_OUTPUT_SLOT) { + Point2 rclick_pos = Point2(p_event.mouse_button.x, p_event.mouse_button.y); + rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot); + if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) { node_popup->clear(); - node_popup->add_item(TTR("Disconnect"),NODE_DISCONNECT); - if (anim_tree->node_get_type(rclick_node)==AnimationTreePlayer::NODE_TRANSITION) { - node_popup->add_item(TTR("Add Input"),NODE_ADD_INPUT); - if (rclick_type==CLICK_INPUT_SLOT) { - if (anim_tree->transition_node_has_input_auto_advance(rclick_node,rclick_slot)) - node_popup->add_item(TTR("Clear Auto-Advance"),NODE_CLEAR_AUTOADVANCE); + node_popup->add_item(TTR("Disconnect"), NODE_DISCONNECT); + if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) { + node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); + if (rclick_type == CLICK_INPUT_SLOT) { + if (anim_tree->transition_node_has_input_auto_advance(rclick_node, rclick_slot)) + node_popup->add_item(TTR("Clear Auto-Advance"), NODE_CLEAR_AUTOADVANCE); else - node_popup->add_item(TTR("Set Auto-Advance"),NODE_SET_AUTOADVANCE); - node_popup->add_item(TTR("Delete Input"),NODE_DELETE_INPUT); - + node_popup->add_item(TTR("Set Auto-Advance"), NODE_SET_AUTOADVANCE); + node_popup->add_item(TTR("Delete Input"), NODE_DELETE_INPUT); } } - node_popup->set_pos(rclick_pos+get_global_pos()); + node_popup->set_pos(rclick_pos + get_global_pos()); node_popup->popup(); - } - if (rclick_type==CLICK_NODE) { + if (rclick_type == CLICK_NODE) { node_popup->clear(); - node_popup->add_item(TTR("Rename"),NODE_RENAME); - node_popup->add_item(TTR("Remove"),NODE_ERASE); - if (anim_tree->node_get_type(rclick_node)==AnimationTreePlayer::NODE_TRANSITION) - node_popup->add_item(TTR("Add Input"),NODE_ADD_INPUT); - node_popup->set_pos(rclick_pos+get_global_pos()); + node_popup->add_item(TTR("Rename"), NODE_RENAME); + node_popup->add_item(TTR("Remove"), NODE_ERASE); + if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) + node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT); + node_popup->set_pos(rclick_pos + get_global_pos()); node_popup->popup(); } - - } } } else { - if (p_event.mouse_button.button_index==1 && click_type!=CLICK_NONE) { + if (p_event.mouse_button.button_index == 1 && click_type != CLICK_NONE) { - switch(click_type) { + switch (click_type) { case CLICK_INPUT_SLOT: case CLICK_OUTPUT_SLOT: { - Point2 dst_click_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); + Point2 dst_click_pos = Point2(p_event.mouse_button.x, p_event.mouse_button.y); StringName id; int slot; - ClickType dst_click_type = _locate_click(dst_click_pos,&id,&slot); + ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot); - if (dst_click_type==CLICK_INPUT_SLOT && click_type==CLICK_OUTPUT_SLOT) { - - anim_tree->connect_nodes(click_node,id,slot); + if (dst_click_type == CLICK_INPUT_SLOT && click_type == CLICK_OUTPUT_SLOT) { + anim_tree->connect_nodes(click_node, id, slot); } - if (click_type==CLICK_INPUT_SLOT && dst_click_type==CLICK_OUTPUT_SLOT) { + if (click_type == CLICK_INPUT_SLOT && dst_click_type == CLICK_OUTPUT_SLOT) { - anim_tree->connect_nodes(id,click_node,click_slot); + anim_tree->connect_nodes(id, click_node, click_slot); } } break; case CLICK_NODE: { - Point2 new_pos = anim_tree->node_get_pos(click_node)+(click_motion-click_pos); - if (new_pos.x<5) - new_pos.x=5; - if (new_pos.y<5) - new_pos.y=5; - anim_tree->node_set_pos(click_node,new_pos); + Point2 new_pos = anim_tree->node_get_pos(click_node) + (click_motion - click_pos); + if (new_pos.x < 5) + new_pos.x = 5; + if (new_pos.y < 5) + new_pos.y = 5; + anim_tree->node_set_pos(click_node, new_pos); } break; default: {} } - click_type=CLICK_NONE; + click_type = CLICK_NONE; update(); } } @@ -885,89 +854,85 @@ void AnimationTreeEditor::_gui_input(InputEvent p_event) { case InputEvent::MOUSE_MOTION: { - if (p_event.mouse_motion.button_mask&1 && click_type!=CLICK_NONE) { + if (p_event.mouse_motion.button_mask & 1 && click_type != CLICK_NONE) { - click_motion=Point2(p_event.mouse_button.x,p_event.mouse_button.y); + click_motion = Point2(p_event.mouse_button.x, p_event.mouse_button.y); update(); } - if ((p_event.mouse_motion.button_mask&4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) { + if ((p_event.mouse_motion.button_mask & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) { - h_scroll->set_value( h_scroll->get_value() - p_event.mouse_motion.relative_x ); - v_scroll->set_value( v_scroll->get_value() - p_event.mouse_motion.relative_y ); + h_scroll->set_value(h_scroll->get_value() - p_event.mouse_motion.relative_x); + v_scroll->set_value(v_scroll->get_value() - p_event.mouse_motion.relative_y); update(); } } break; } - } - -void AnimationTreeEditor::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) { +void AnimationTreeEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color) { static const int steps = 20; Rect2 r; - r.pos=p_from; + r.pos = p_from; r.expand_to(p_to); - Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1); + Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); bool flip = sign.x * sign.y < 0; Vector2 prev; - for(int i=0;i<=steps;i++) { + for (int i = 0; i <= steps; i++) { - float d = i/float(steps); - float c=-Math::cos(d*Math_PI) * 0.5+0.5; + float d = i / float(steps); + float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; if (flip) - c=1.0-c; - Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height); + c = 1.0 - c; + Vector2 p = r.pos + Vector2(d * r.size.width, c * r.size.height); - if (i>0) { + if (i > 0) { - draw_line(prev,p,p_color,2); + draw_line(prev, p, p_color, 2); } - prev=p; + prev = p; } } void AnimationTreeEditor::_notification(int p_what) { - - switch(p_what) { + switch (p_what) { case NOTIFICATION_ENTER_TREE: { - play_button->set_icon( get_icon("Play","EditorIcons") ); - add_menu->set_icon( get_icon("Add","EditorIcons") ); + play_button->set_icon(get_icon("Play", "EditorIcons")); + add_menu->set_icon(get_icon("Add", "EditorIcons")); } break; case NOTIFICATION_DRAW: { - _update_scrollbars(); //VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1)); - get_stylebox("bg","Tree")->draw(get_canvas_item(),Rect2(Point2(),get_size())); + get_stylebox("bg", "Tree")->draw(get_canvas_item(), Rect2(Point2(), get_size())); - for(List::Element *E=order.front();E;E=E->next()) { + for (List::Element *E = order.front(); E; E = E->next()) { _draw_node(E->get()); } - if (click_type==CLICK_INPUT_SLOT || click_type==CLICK_OUTPUT_SLOT) { + if (click_type == CLICK_INPUT_SLOT || click_type == CLICK_OUTPUT_SLOT) { - _draw_cos_line(click_pos,click_motion,Color(0.5,1,0.5,0.8)); + _draw_cos_line(click_pos, click_motion, Color(0.5, 1, 0.5, 0.8)); } List connections; anim_tree->get_connection_list(&connections); - for(List::Element *E=connections.front();E;E=E->next()) { + for (List::Element *E = connections.front(); E; E = E->next()) { - const AnimationTreePlayer::Connection &c=E->get(); - Point2 source = _get_slot_pos(c.src_node,false,0); - Point2 dest = _get_slot_pos(c.dst_node,true,c.dst_input); - Color col = Color(1,1,0.5,0.8); -/* + const AnimationTreePlayer::Connection &c = E->get(); + Point2 source = _get_slot_pos(c.src_node, false, 0); + Point2 dest = _get_slot_pos(c.dst_node, true, c.dst_input); + Color col = Color(1, 1, 0.5, 0.8); + /* if (click_type==CLICK_NODE && click_node==c.src_node) { source+=click_motion-click_pos; @@ -978,27 +943,25 @@ void AnimationTreeEditor::_notification(int p_what) { dest+=click_motion-click_pos; }*/ - _draw_cos_line(source,dest,col); - + _draw_cos_line(source, dest, col); } - switch(anim_tree->get_last_error()) { + switch (anim_tree->get_last_error()) { case AnimationTreePlayer::CONNECT_OK: { - Ref f = get_font("font","Label"); - f->draw(get_canvas_item(),Point2(5,25+f->get_ascent()),TTR("Animation tree is valid."),Color(0,1,0.6,0.8)); + Ref f = get_font("font", "Label"); + f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is valid."), Color(0, 1, 0.6, 0.8)); } break; default: { - Ref f = get_font("font","Label"); - f->draw(get_canvas_item(),Point2(5,25+f->get_ascent()),TTR("Animation tree is invalid."),Color(1,0.6,0.0,0.8)); + Ref f = get_font("font", "Label"); + f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is invalid."), Color(1, 0.6, 0.0, 0.8)); } break; } } break; } - } void AnimationTreeEditor::_update_scrollbars() { @@ -1007,72 +970,69 @@ void AnimationTreeEditor::_update_scrollbars() { Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); - v_scroll->set_begin( Point2(size.width - vmin.width, 0) ); - v_scroll->set_end( Point2(size.width, size.height) ); - - h_scroll->set_begin( Point2( 0, size.height - hmin.height) ); - h_scroll->set_end( Point2(size.width-vmin.width, size.height) ); + v_scroll->set_begin(Point2(size.width - vmin.width, 0)); + v_scroll->set_end(Point2(size.width, size.height)); + h_scroll->set_begin(Point2(0, size.height - hmin.height)); + h_scroll->set_end(Point2(size.width - vmin.width, size.height)); Size2 min = _get_maximum_size(); if (min.height < size.height - hmin.height) { v_scroll->hide(); - offset.y=0; + offset.y = 0; } else { v_scroll->show(); v_scroll->set_max(min.height); v_scroll->set_page(size.height - hmin.height); - offset.y=v_scroll->get_value(); + offset.y = v_scroll->get_value(); } if (min.width < size.width - vmin.width) { h_scroll->hide(); - offset.x=0; + offset.x = 0; } else { h_scroll->show(); h_scroll->set_max(min.width); h_scroll->set_page(size.width - vmin.width); - offset.x=h_scroll->get_value(); + offset.x = h_scroll->get_value(); } } void AnimationTreeEditor::_scroll_moved(float) { - offset.x=h_scroll->get_value(); - offset.y=v_scroll->get_value(); + offset.x = h_scroll->get_value(); + offset.y = v_scroll->get_value(); update(); } - void AnimationTreeEditor::_node_menu_item(int p_item) { - switch(p_item) { + switch (p_item) { case NODE_DISCONNECT: { - if (rclick_type==CLICK_INPUT_SLOT) { + if (rclick_type == CLICK_INPUT_SLOT) { - anim_tree->disconnect_nodes(rclick_node,rclick_slot); + anim_tree->disconnect_nodes(rclick_node, rclick_slot); update(); } - if (rclick_type==CLICK_OUTPUT_SLOT) { - + if (rclick_type == CLICK_OUTPUT_SLOT) { List connections; anim_tree->get_connection_list(&connections); - for(List::Element *E=connections.front();E;E=E->next()) { + for (List::Element *E = connections.front(); E; E = E->next()) { - const AnimationTreePlayer::Connection &c=E->get(); - if( c.dst_node==rclick_node) { + const AnimationTreePlayer::Connection &c = E->get(); + if (c.dst_node == rclick_node) { - anim_tree->disconnect_nodes(c.dst_node,c.dst_input); + anim_tree->disconnect_nodes(c.dst_node, c.dst_input); } } update(); @@ -1081,37 +1041,37 @@ void AnimationTreeEditor::_node_menu_item(int p_item) { } break; case NODE_RENAME: { - renaming_edit=true; - edited_node=rclick_node; + renaming_edit = true; + edited_node = rclick_node; _popup_edit_dialog(); } break; case NODE_ADD_INPUT: { - anim_tree->transition_node_set_input_count(rclick_node, anim_tree->transition_node_get_input_count(rclick_node)+1); + anim_tree->transition_node_set_input_count(rclick_node, anim_tree->transition_node_get_input_count(rclick_node) + 1); update(); } break; - case NODE_DELETE_INPUT: { + case NODE_DELETE_INPUT: { - anim_tree->transition_node_delete_input(rclick_node, rclick_slot); - update(); - } break; + anim_tree->transition_node_delete_input(rclick_node, rclick_slot); + update(); + } break; case NODE_SET_AUTOADVANCE: { - anim_tree->transition_node_set_input_auto_advance(rclick_node,rclick_slot,true); + anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, true); update(); } break; - case NODE_CLEAR_AUTOADVANCE: { + case NODE_CLEAR_AUTOADVANCE: { - anim_tree->transition_node_set_input_auto_advance(rclick_node,rclick_slot,false); + anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, false); update(); } break; case NODE_ERASE: { - if (rclick_node=="out") + if (rclick_node == "out") break; order.erase(rclick_node); anim_tree->remove_node(rclick_node); @@ -1122,7 +1082,7 @@ void AnimationTreeEditor::_node_menu_item(int p_item) { StringName AnimationTreeEditor::_add_node(int p_item) { - static const char* bname[] = { + static const char *bname[] = { "out", "anim", "oneshot", @@ -1136,27 +1096,26 @@ StringName AnimationTreeEditor::_add_node(int p_item) { }; String name; - int idx=1; + int idx = 1; - while(true) { + while (true) { name = bname[p_item]; - if (idx>1) - name+=" "+itos(idx); + if (idx > 1) + name += " " + itos(idx); if (anim_tree->node_exists(name)) idx++; else break; } - - anim_tree->add_node((AnimationTreePlayer::NodeType)p_item,name); - anim_tree->node_set_pos(name,Point2(last_x,last_y)); + anim_tree->add_node((AnimationTreePlayer::NodeType)p_item, name); + anim_tree->node_set_pos(name, Point2(last_x, last_y)); order.push_back(name); - last_x+=10; - last_y+=10; - last_x=last_x % (int)get_size().width; - last_y=last_y % (int)get_size().height; + last_x += 10; + last_y += 10; + last_x = last_x % (int)get_size().width; + last_y = last_y % (int)get_size().height; update(); return name; @@ -1166,27 +1125,27 @@ void AnimationTreeEditor::_file_dialog_selected(String p_path) { switch (file_op) { - case MENU_IMPORT_ANIMATIONS: { - Vector files = file_dialog->get_selected_files(); + case MENU_IMPORT_ANIMATIONS: { + Vector files = file_dialog->get_selected_files(); - for (int i=0; ianimation_node_set_animation(node,anim); - //anim_tree->node_set_name(node, files[i].get_file()); - }; - } break; + RES anim = ResourceLoader::load(files[i]); + anim_tree->animation_node_set_animation(node, anim); + //anim_tree->node_set_name(node, files[i].get_file()); + }; + } break; - default: - break; + default: + break; }; }; void AnimationTreeEditor::_add_menu_item(int p_item) { - if (p_item==MENU_GRAPH_CLEAR) { + if (p_item == MENU_GRAPH_CLEAR) { //clear } else if (p_item == MENU_IMPORT_ANIMATIONS) { @@ -1203,49 +1162,46 @@ void AnimationTreeEditor::_add_menu_item(int p_item) { Size2 AnimationTreeEditor::get_minimum_size() const { - return Size2(10,200); + return Size2(10, 200); } -void AnimationTreeEditor::_find_paths_for_filter(const StringName& p_node,Set& paths) { +void AnimationTreeEditor::_find_paths_for_filter(const StringName &p_node, Set &paths) { - ERR_FAIL_COND( !anim_tree->node_exists(p_node) ); + ERR_FAIL_COND(!anim_tree->node_exists(p_node)); - for(int i=0;inode_get_input_count(p_node);i++) { + for (int i = 0; i < anim_tree->node_get_input_count(p_node); i++) { - StringName port = anim_tree->node_get_input_source(p_node,i); - if (port==StringName()) + StringName port = anim_tree->node_get_input_source(p_node, i); + if (port == StringName()) continue; - _find_paths_for_filter(port,paths); + _find_paths_for_filter(port, paths); } - if (anim_tree->node_get_type(p_node)==AnimationTreePlayer::NODE_ANIMATION) { + if (anim_tree->node_get_type(p_node) == AnimationTreePlayer::NODE_ANIMATION) { Ref anim = anim_tree->animation_node_get_animation(p_node); if (anim.is_valid()) { - for(int i=0;iget_track_count();i++) { + for (int i = 0; i < anim->get_track_count(); i++) { paths.insert(anim->track_get_path(i)); } } } } - void AnimationTreeEditor::_filter_edited() { - TreeItem *ed = filter->get_edited(); if (!ed) return; - if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_ONESHOT) { - anim_tree->oneshot_node_set_filter_path(edited_node,ed->get_metadata(0),ed->is_checked(0)); - } else if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_BLEND2) { - anim_tree->blend2_node_set_filter_path(edited_node,ed->get_metadata(0),ed->is_checked(0)); - } else if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_ANIMATION) { - anim_tree->animation_node_set_filter_path(edited_node,ed->get_metadata(0),ed->is_checked(0)); + if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { + anim_tree->oneshot_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { + anim_tree->blend2_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { + anim_tree->animation_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0)); } - } void AnimationTreeEditor::_edit_filters() { @@ -1254,47 +1210,44 @@ void AnimationTreeEditor::_edit_filters() { filter->clear(); Set npb; - _find_paths_for_filter(edited_node,npb); + _find_paths_for_filter(edited_node, npb); TreeItem *root = filter->create_item(); filter->set_hide_root(true); - Map pm; + Map pm; - Node *base = anim_tree->get_node( anim_tree->get_base_path() ); + Node *base = anim_tree->get_node(anim_tree->get_base_path()); - for(Set::Element *E=npb.front();E;E=E->next()) { + for (Set::Element *E = npb.front(); E; E = E->next()) { - TreeItem *parent=root; - String descr=E->get(); + TreeItem *parent = root; + String descr = E->get(); if (base) { NodePath np = E->get(); - if (np.get_property()!=StringName()) { + if (np.get_property() != StringName()) { Node *n = base->get_node(np); Skeleton *s = n->cast_to(); if (s) { - String skelbase = E->get().substr(0,E->get().find(":")); - + String skelbase = E->get().substr(0, E->get().find(":")); int bidx = s->find_bone(np.get_property()); - if (bidx!=-1) { + if (bidx != -1) { int bparent = s->get_bone_parent(bidx); // - if (bparent!=-1) { - + if (bparent != -1) { - String bpn = skelbase+":"+s->get_bone_name(bparent); + String bpn = skelbase + ":" + s->get_bone_name(bparent); if (pm.has(bpn)) { - parent=pm[bpn]; - descr=np.get_property(); + parent = pm[bpn]; + descr = np.get_property(); } } else { if (pm.has(skelbase)) { - parent=pm[skelbase]; - + parent = pm[skelbase]; } } } @@ -1303,43 +1256,40 @@ void AnimationTreeEditor::_edit_filters() { } TreeItem *it = filter->create_item(parent); - it->set_cell_mode(0,TreeItem::CELL_MODE_CHECK); - it->set_text(0,descr); - it->set_metadata(0,NodePath(E->get())); - it->set_editable(0,true); - if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_ONESHOT) { - it->set_checked(0, anim_tree->oneshot_node_is_path_filtered(edited_node,E->get())); - } else if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_BLEND2) { - it->set_checked(0, anim_tree->blend2_node_is_path_filtered(edited_node,E->get())); - } else if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_ANIMATION) { - it->set_checked(0, anim_tree->animation_node_is_path_filtered(edited_node,E->get())); + it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + it->set_text(0, descr); + it->set_metadata(0, NodePath(E->get())); + it->set_editable(0, true); + if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) { + it->set_checked(0, anim_tree->oneshot_node_is_path_filtered(edited_node, E->get())); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) { + it->set_checked(0, anim_tree->blend2_node_is_path_filtered(edited_node, E->get())); + } else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) { + it->set_checked(0, anim_tree->animation_node_is_path_filtered(edited_node, E->get())); } - pm[E->get()]=it; + pm[E->get()] = it; } - - } void AnimationTreeEditor::_bind_methods() { - ClassDB::bind_method( "_add_menu_item", &AnimationTreeEditor::_add_menu_item ); - ClassDB::bind_method( "_node_menu_item", &AnimationTreeEditor::_node_menu_item ); - ClassDB::bind_method( "_gui_input", &AnimationTreeEditor::_gui_input ); + ClassDB::bind_method("_add_menu_item", &AnimationTreeEditor::_add_menu_item); + ClassDB::bind_method("_node_menu_item", &AnimationTreeEditor::_node_menu_item); + ClassDB::bind_method("_gui_input", &AnimationTreeEditor::_gui_input); //ClassDB::bind_method( "_node_param_changed", &AnimationTreeEditor::_node_param_changed ); - ClassDB::bind_method( "_scroll_moved", &AnimationTreeEditor::_scroll_moved ); - ClassDB::bind_method( "_edit_dialog_changeds", &AnimationTreeEditor::_edit_dialog_changeds ); - ClassDB::bind_method( "_edit_dialog_changede", &AnimationTreeEditor::_edit_dialog_changede ); - ClassDB::bind_method( "_edit_dialog_changedf", &AnimationTreeEditor::_edit_dialog_changedf ); - ClassDB::bind_method( "_edit_dialog_changed", &AnimationTreeEditor::_edit_dialog_changed ); - ClassDB::bind_method( "_edit_dialog_animation_changed", &AnimationTreeEditor::_edit_dialog_animation_changed ); - ClassDB::bind_method( "_edit_dialog_edit_animation", &AnimationTreeEditor::_edit_dialog_edit_animation ); - ClassDB::bind_method( "_play_toggled", &AnimationTreeEditor::_play_toggled ); - ClassDB::bind_method( "_edit_oneshot_start", &AnimationTreeEditor::_edit_oneshot_start ); - ClassDB::bind_method( "_file_dialog_selected", &AnimationTreeEditor::_file_dialog_selected); - ClassDB::bind_method( "_master_anim_menu_item", &AnimationTreeEditor::_master_anim_menu_item); - ClassDB::bind_method( "_edit_filters", &AnimationTreeEditor::_edit_filters); - ClassDB::bind_method( "_filter_edited", &AnimationTreeEditor::_filter_edited); - + ClassDB::bind_method("_scroll_moved", &AnimationTreeEditor::_scroll_moved); + ClassDB::bind_method("_edit_dialog_changeds", &AnimationTreeEditor::_edit_dialog_changeds); + ClassDB::bind_method("_edit_dialog_changede", &AnimationTreeEditor::_edit_dialog_changede); + ClassDB::bind_method("_edit_dialog_changedf", &AnimationTreeEditor::_edit_dialog_changedf); + ClassDB::bind_method("_edit_dialog_changed", &AnimationTreeEditor::_edit_dialog_changed); + ClassDB::bind_method("_edit_dialog_animation_changed", &AnimationTreeEditor::_edit_dialog_animation_changed); + ClassDB::bind_method("_edit_dialog_edit_animation", &AnimationTreeEditor::_edit_dialog_edit_animation); + ClassDB::bind_method("_play_toggled", &AnimationTreeEditor::_play_toggled); + ClassDB::bind_method("_edit_oneshot_start", &AnimationTreeEditor::_edit_oneshot_start); + ClassDB::bind_method("_file_dialog_selected", &AnimationTreeEditor::_file_dialog_selected); + ClassDB::bind_method("_master_anim_menu_item", &AnimationTreeEditor::_master_anim_menu_item); + ClassDB::bind_method("_edit_filters", &AnimationTreeEditor::_edit_filters); + ClassDB::bind_method("_filter_edited", &AnimationTreeEditor::_filter_edited); } AnimationTreeEditor::AnimationTreeEditor() { @@ -1349,149 +1299,141 @@ AnimationTreeEditor::AnimationTreeEditor() { PopupMenu *p; List defaults; - add_menu = memnew( MenuButton ); + add_menu = memnew(MenuButton); //add_menu->set_ - add_menu->set_pos( Point2( 0,0) ); - add_menu->set_size( Point2( 25,15) ); - add_child( add_menu ); - - p=add_menu->get_popup(); - p->add_item(TTR("Animation Node"),AnimationTreePlayer::NODE_ANIMATION); - p->add_item(TTR("OneShot Node"),AnimationTreePlayer::NODE_ONESHOT); - p->add_item(TTR("Mix Node"),AnimationTreePlayer::NODE_MIX); - p->add_item(TTR("Blend2 Node"),AnimationTreePlayer::NODE_BLEND2); - p->add_item(TTR("Blend3 Node"),AnimationTreePlayer::NODE_BLEND3); - p->add_item(TTR("Blend4 Node"),AnimationTreePlayer::NODE_BLEND4); - p->add_item(TTR("TimeScale Node"),AnimationTreePlayer::NODE_TIMESCALE); - p->add_item(TTR("TimeSeek Node"),AnimationTreePlayer::NODE_TIMESEEK); - p->add_item(TTR("Transition Node"),AnimationTreePlayer::NODE_TRANSITION); + add_menu->set_pos(Point2(0, 0)); + add_menu->set_size(Point2(25, 15)); + add_child(add_menu); + + p = add_menu->get_popup(); + p->add_item(TTR("Animation Node"), AnimationTreePlayer::NODE_ANIMATION); + p->add_item(TTR("OneShot Node"), AnimationTreePlayer::NODE_ONESHOT); + p->add_item(TTR("Mix Node"), AnimationTreePlayer::NODE_MIX); + p->add_item(TTR("Blend2 Node"), AnimationTreePlayer::NODE_BLEND2); + p->add_item(TTR("Blend3 Node"), AnimationTreePlayer::NODE_BLEND3); + p->add_item(TTR("Blend4 Node"), AnimationTreePlayer::NODE_BLEND4); + p->add_item(TTR("TimeScale Node"), AnimationTreePlayer::NODE_TIMESCALE); + p->add_item(TTR("TimeSeek Node"), AnimationTreePlayer::NODE_TIMESEEK); + p->add_item(TTR("Transition Node"), AnimationTreePlayer::NODE_TRANSITION); p->add_separator(); p->add_item(TTR("Import Animations.."), MENU_IMPORT_ANIMATIONS); // wtf p->add_separator(); - p->add_item(TTR("Clear"),MENU_GRAPH_CLEAR); + p->add_item(TTR("Clear"), MENU_GRAPH_CLEAR); - p->connect("id_pressed", this,"_add_menu_item"); + p->connect("id_pressed", this, "_add_menu_item"); play_button = memnew(Button); - play_button->set_pos(Point2(25,0)); - play_button->set_size(Point2(25,15)); + play_button->set_pos(Point2(25, 0)); + play_button->set_size(Point2(25, 15)); add_child(play_button); play_button->set_toggle_mode(true); - play_button->connect("pressed", this,"_play_toggled"); - - + play_button->connect("pressed", this, "_play_toggled"); + last_x = 50; + last_y = 50; - - last_x=50; - last_y=50; - - property_editor = memnew( CustomPropertyEditor ); + property_editor = memnew(CustomPropertyEditor); add_child(property_editor); - property_editor->connect("variant_changed", this,"_edit_dialog_animation_changed"); - property_editor->connect("resource_edit_request", this, "_edit_dialog_edit_animation"); + property_editor->connect("variant_changed", this, "_edit_dialog_animation_changed"); + property_editor->connect("resource_edit_request", this, "_edit_dialog_edit_animation"); - h_scroll = memnew( HScrollBar ); - v_scroll = memnew( VScrollBar ); + h_scroll = memnew(HScrollBar); + v_scroll = memnew(VScrollBar); add_child(h_scroll); add_child(v_scroll); - h_scroll->connect("value_changed", this,"_scroll_moved"); - v_scroll->connect("value_changed", this,"_scroll_moved"); + h_scroll->connect("value_changed", this, "_scroll_moved"); + v_scroll->connect("value_changed", this, "_scroll_moved"); - node_popup= memnew(PopupMenu ); + node_popup = memnew(PopupMenu); add_child(node_popup); node_popup->set_as_toplevel(true); - master_anim_popup = memnew( PopupMenu ); + master_anim_popup = memnew(PopupMenu); add_child(master_anim_popup); - master_anim_popup->connect("id_pressed",this,"_master_anim_menu_item"); + master_anim_popup->connect("id_pressed", this, "_master_anim_menu_item"); + node_popup->connect("id_pressed", this, "_node_menu_item"); - node_popup->connect("id_pressed", this,"_node_menu_item"); + updating_edit = false; - updating_edit=false; - - edit_dialog = memnew( PopupPanel ); + edit_dialog = memnew(PopupPanel); //edit_dialog->get_ok()->hide(); //edit_dialog->get_cancel()->hide(); add_child(edit_dialog); - edit_option = memnew( OptionButton ); - edit_option->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + edit_option = memnew(OptionButton); + edit_option->set_anchor(MARGIN_RIGHT, ANCHOR_END); edit_option->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(edit_option); - edit_option->connect("item_selected", this,"_edit_dialog_changedf"); + edit_option->connect("item_selected", this, "_edit_dialog_changedf"); edit_option->hide(); - - for(int i=0;i<2;i++) { - edit_scroll[i] = memnew ( HSlider ); - edit_scroll[i]->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + for (int i = 0; i < 2; i++) { + edit_scroll[i] = memnew(HSlider); + edit_scroll[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); edit_scroll[i]->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(edit_scroll[i]); edit_scroll[i]->hide(); - edit_scroll[i]->connect("value_changed", this,"_edit_dialog_changedf"); + edit_scroll[i]->connect("value_changed", this, "_edit_dialog_changedf"); } - for(int i=0;i<4;i++) { - edit_line[i] = memnew ( LineEdit ); - edit_line[i]->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + for (int i = 0; i < 4; i++) { + edit_line[i] = memnew(LineEdit); + edit_line[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END); edit_line[i]->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(edit_line[i]); edit_line[i]->hide(); - edit_line[i]->connect("text_changed", this,"_edit_dialog_changeds"); - edit_line[i]->connect("text_entered", this,"_edit_dialog_changede"); - edit_label[i] = memnew ( Label ); + edit_line[i]->connect("text_changed", this, "_edit_dialog_changeds"); + edit_line[i]->connect("text_entered", this, "_edit_dialog_changede"); + edit_label[i] = memnew(Label); edit_dialog->add_child(edit_label[i]); edit_label[i]->hide(); } - edit_button = memnew( Button ); - edit_button->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + edit_button = memnew(Button); + edit_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); edit_button->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(edit_button); edit_button->hide(); - edit_button->connect("pressed", this,"_edit_oneshot_start"); + edit_button->connect("pressed", this, "_edit_oneshot_start"); - edit_check = memnew( CheckButton ); - edit_check->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + edit_check = memnew(CheckButton); + edit_check->set_anchor(MARGIN_RIGHT, ANCHOR_END); edit_check->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(edit_check); edit_check->hide(); - edit_check->connect("pressed", this,"_edit_dialog_changed"); + edit_check->connect("pressed", this, "_edit_dialog_changed"); - file_dialog = memnew( EditorFileDialog ); + file_dialog = memnew(EditorFileDialog); file_dialog->set_enable_multiple_selection(true); file_dialog->set_current_dir(GlobalConfig::get_singleton()->get_resource_path()); add_child(file_dialog); - file_dialog->connect("file_selected", this, "_file_dialog_selected"); + file_dialog->connect("file_selected", this, "_file_dialog_selected"); - filter_dialog = memnew( AcceptDialog ); + filter_dialog = memnew(AcceptDialog); filter_dialog->set_title(TTR("Edit Node Filters")); add_child(filter_dialog); - filter = memnew( Tree ); + filter = memnew(Tree); filter_dialog->add_child(filter); //filter_dialog->set_child_rect(filter); - filter->connect("item_edited",this,"_filter_edited"); + filter->connect("item_edited", this, "_filter_edited"); - filter_button = memnew( Button ); - filter_button->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + filter_button = memnew(Button); + filter_button->set_anchor(MARGIN_RIGHT, ANCHOR_END); filter_button->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(filter_button); filter_button->hide(); filter_button->set_text(TTR("Filters..")); - filter_button->connect("pressed", this,"_edit_filters"); + filter_button->connect("pressed", this, "_edit_filters"); set_clip_contents(true); } - void AnimationTreeEditorPlugin::edit(Object *p_object) { anim_tree_editor->edit(p_object->cast_to()); - } bool AnimationTreeEditorPlugin::handles(Object *p_object) const { @@ -1518,19 +1460,13 @@ void AnimationTreeEditorPlugin::make_visible(bool p_visible) { AnimationTreeEditorPlugin::AnimationTreeEditorPlugin(EditorNode *p_node) { - editor=p_node; - anim_tree_editor = memnew( AnimationTreeEditor ); - anim_tree_editor->set_custom_minimum_size(Size2(0,300)); + editor = p_node; + anim_tree_editor = memnew(AnimationTreeEditor); + anim_tree_editor->set_custom_minimum_size(Size2(0, 300)); - button=editor->add_bottom_panel_item("AnimationTree",anim_tree_editor); + button = editor->add_bottom_panel_item("AnimationTree", anim_tree_editor); button->hide(); - - - } - -AnimationTreeEditorPlugin::~AnimationTreeEditorPlugin() -{ +AnimationTreeEditorPlugin::~AnimationTreeEditorPlugin() { } - diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h index 4e5fb871f1..d998cb99ae 100644 --- a/editor/plugins/animation_tree_editor_plugin.h +++ b/editor/plugins/animation_tree_editor_plugin.h @@ -29,22 +29,22 @@ #ifndef ANIMATION_TREE_EDITOR_PLUGIN_H #define ANIMATION_TREE_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "editor/property_editor.h" #include "scene/animation/animation_tree_player.h" -#include "scene/gui/tree.h" #include "scene/gui/button.h" #include "scene/gui/popup.h" -#include "editor/property_editor.h" +#include "scene/gui/tree.h" /** @author Juan Linietsky */ class AnimationTreeEditor : public Control { - GDCLASS(AnimationTreeEditor, Control ); + GDCLASS(AnimationTreeEditor, Control); - static const char* _node_type_names[]; + static const char *_node_type_names[]; enum ClickType { CLICK_NONE, @@ -57,8 +57,8 @@ class AnimationTreeEditor : public Control { enum { - MENU_GRAPH_CLEAR=100, - MENU_IMPORT_ANIMATIONS=101, + MENU_GRAPH_CLEAR = 100, + MENU_IMPORT_ANIMATIONS = 101, NODE_DISCONNECT, NODE_RENAME, NODE_ERASE, @@ -79,27 +79,26 @@ class AnimationTreeEditor : public Control { Button *edit_button; Button *filter_button; CheckButton *edit_check; - EditorFileDialog* file_dialog; + EditorFileDialog *file_dialog; int file_op; void _popup_edit_dialog(); - - void _setup_edit_dialog(const StringName& p_node); + void _setup_edit_dialog(const StringName &p_node); PopupMenu *master_anim_popup; PopupMenu *node_popup; PopupMenu *add_popup; HScrollBar *h_scroll; VScrollBar *v_scroll; - MenuButton* add_menu; + MenuButton *add_menu; CustomPropertyEditor *property_editor; - AnimationTreePlayer* anim_tree; + AnimationTreePlayer *anim_tree; List order; Set active_nodes; - int last_x,last_y; + int last_x, last_y; Point2 offset; ClickType click_type; @@ -115,18 +114,16 @@ class AnimationTreeEditor : public Control { Size2 _get_maximum_size(); Size2 get_node_size(const StringName &p_node) const; - void _draw_node(const StringName& p_node); + void _draw_node(const StringName &p_node); AcceptDialog *filter_dialog; Tree *filter; - - - void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color); + void _draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color); void _update_scrollbars(); void _scroll_moved(float); void _play_toggled(); -/* + /* void _node_param_changed(); void _node_add_callback(); void _node_add(VisualServer::AnimationTreeNodeType p_type); @@ -137,12 +134,10 @@ class AnimationTreeEditor : public Control { void _node_menu_item(int p_item); void _add_menu_item(int p_item); - void _filter_edited(); - void _find_paths_for_filter(const StringName& p_node,Set& paths); + void _find_paths_for_filter(const StringName &p_node, Set &paths); void _edit_filters(); - void _edit_oneshot_start(); void _edit_dialog_animation_changed(); void _edit_dialog_edit_animation(); @@ -151,20 +146,18 @@ class AnimationTreeEditor : public Control { void _edit_dialog_changedf(float); void _edit_dialog_changed(); void _dialog_changed() const; - ClickType _locate_click(const Point2& p_click,StringName *p_node_id,int *p_slot_index) const; - Point2 _get_slot_pos(const StringName& p_node_id,bool p_input,int p_slot); + ClickType _locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const; + Point2 _get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot); StringName _add_node(int p_item); void _file_dialog_selected(String p_path); - protected: void _notification(int p_what); void _gui_input(InputEvent p_event); static void _bind_methods(); -public: - +public: virtual Size2 get_minimum_size() const; void edit(AnimationTreePlayer *p_player); AnimationTreeEditor(); @@ -172,14 +165,13 @@ public: class AnimationTreeEditorPlugin : public EditorPlugin { - GDCLASS( AnimationTreeEditorPlugin, EditorPlugin ); + GDCLASS(AnimationTreeEditorPlugin, EditorPlugin); AnimationTreeEditor *anim_tree_editor; EditorNode *editor; Button *button; public: - virtual String get_name() const { return "AnimTree"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -188,7 +180,6 @@ public: AnimationTreeEditorPlugin(EditorNode *p_node); ~AnimationTreeEditorPlugin(); - }; #endif // ANIMATION_TREE_EDITOR_PLUGIN_H diff --git a/editor/plugins/baked_light_baker.cpp b/editor/plugins/baked_light_baker.cpp index e491fe012e..de2b78b8dd 100644 --- a/editor/plugins/baked_light_baker.cpp +++ b/editor/plugins/baked_light_baker.cpp @@ -28,11 +28,11 @@ /*************************************************************************/ #include "baked_light_baker.h" -#include -#include -#include "io/marshalls.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" +#include "io/marshalls.h" +#include +#include #if 0 void baked_light_baker_add_64f(double *dst,double value); diff --git a/editor/plugins/baked_light_baker.h b/editor/plugins/baked_light_baker.h index 89788338d9..f328062b1e 100644 --- a/editor/plugins/baked_light_baker.h +++ b/editor/plugins/baked_light_baker.h @@ -29,10 +29,10 @@ #ifndef BAKED_LIGHT_BAKER_H #define BAKED_LIGHT_BAKER_H +#include "os/thread.h" #include "scene/3d/baked_light_instance.h" #include "scene/3d/light.h" #include "scene/3d/mesh_instance.h" -#include "os/thread.h" #if 0 diff --git a/editor/plugins/baked_light_baker_cmpxchg.cpp b/editor/plugins/baked_light_baker_cmpxchg.cpp index 5e9228b7de..f84c001f78 100644 --- a/editor/plugins/baked_light_baker_cmpxchg.cpp +++ b/editor/plugins/baked_light_baker_cmpxchg.cpp @@ -28,85 +28,77 @@ /*************************************************************************/ #include "typedefs.h" - #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 -void baked_light_baker_add_64f(double *dst,double value) { - +void baked_light_baker_add_64f(double *dst, double value) { union { int64_t i; double f; } swapy; - - while(true) { - swapy.f=*dst; + while (true) { + swapy.f = *dst; int64_t from = swapy.i; - swapy.f+=value; - int64_t to=swapy.i; - if (__sync_bool_compare_and_swap((int64_t*)dst,from,to)) + swapy.f += value; + int64_t to = swapy.i; + if (__sync_bool_compare_and_swap((int64_t *)dst, from, to)) break; } } -void baked_light_baker_add_64i(int64_t *dst,int64_t value) { - - while(!__sync_bool_compare_and_swap(dst,*dst,(*dst)+value)) {} +void baked_light_baker_add_64i(int64_t *dst, int64_t value) { + while (!__sync_bool_compare_and_swap(dst, *dst, (*dst) + value)) { + } } #elif defined(WINDOWS_ENABLED) #include "windows.h" -void baked_light_baker_add_64f(double *dst,double value) { +void baked_light_baker_add_64f(double *dst, double value) { union { int64_t i; double f; } swapy; - - while(true) { - swapy.f=*dst; + while (true) { + swapy.f = *dst; int64_t from = swapy.i; - swapy.f+=value; - int64_t to=swapy.i; - int64_t result = InterlockedCompareExchange64((int64_t*)dst,to,from); - if (result==from) + swapy.f += value; + int64_t to = swapy.i; + int64_t result = InterlockedCompareExchange64((int64_t *)dst, to, from); + if (result == from) break; } - } -void baked_light_baker_add_64i(int64_t *dst,int64_t value) { +void baked_light_baker_add_64i(int64_t *dst, int64_t value) { - while(true) { + while (true) { int64_t from = *dst; - int64_t to = from+value; - int64_t result = InterlockedCompareExchange64(dst,to,from); - if (result==from) + int64_t to = from + value; + int64_t result = InterlockedCompareExchange64(dst, to, from); + if (result == from) break; } } - #else //in goder (the god of programmers) we trust #warning seems this platform or compiler does not support safe cmpxchg, your baked lighting may be funny -void baked_light_baker_add_64f(double *dst,double value) { - - *dst+=value; +void baked_light_baker_add_64f(double *dst, double value) { + *dst += value; } -void baked_light_baker_add_64i(int64_t *dst,int64_t value) { - - *dst+=value; +void baked_light_baker_add_64i(int64_t *dst, int64_t value) { + *dst += value; } #endif diff --git a/editor/plugins/baked_light_editor_plugin.cpp b/editor/plugins/baked_light_editor_plugin.cpp index 6a7e708b85..5ac4b54600 100644 --- a/editor/plugins/baked_light_editor_plugin.cpp +++ b/editor/plugins/baked_light_editor_plugin.cpp @@ -28,11 +28,10 @@ /*************************************************************************/ #include "baked_light_editor_plugin.h" -#include "scene/gui/box_container.h" -#include "scene/3d/mesh_instance.h" #include "io/marshalls.h" #include "io/resource_saver.h" - +#include "scene/3d/mesh_instance.h" +#include "scene/gui/box_container.h" #if 0 @@ -153,7 +152,6 @@ void BakedLightEditor::_notification(int p_option) { it->create_from_image(img); ResourceSaver::save("baked_octree.png",it); - #endif @@ -375,5 +373,4 @@ BakedLightEditorPlugin::~BakedLightEditorPlugin() { } - #endif diff --git a/editor/plugins/baked_light_editor_plugin.h b/editor/plugins/baked_light_editor_plugin.h index a71de12bcc..036407a574 100644 --- a/editor/plugins/baked_light_editor_plugin.h +++ b/editor/plugins/baked_light_editor_plugin.h @@ -29,13 +29,11 @@ #ifndef BAKED_LIGHT_EDITOR_PLUGIN_H #define BAKED_LIGHT_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "editor/plugins/baked_light_baker.h" #include "scene/gui/spin_box.h" - - /** @author Juan Linietsky */ @@ -117,4 +115,3 @@ public: #endif // MULTIMESH_EDITOR_PLUGIN_H #endif - diff --git a/editor/plugins/camera_editor_plugin.cpp b/editor/plugins/camera_editor_plugin.cpp index 7073acd2c0..96b6da51fd 100644 --- a/editor/plugins/camera_editor_plugin.cpp +++ b/editor/plugins/camera_editor_plugin.cpp @@ -30,45 +30,41 @@ #include "spatial_editor_plugin.h" - void CameraEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { -/* case NOTIFICATION_PROCESS: { + /* case NOTIFICATION_PROCESS: { if (preview->is_pressed() && node) node->call("make_current"); } break;*/ } - } void CameraEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; SpatialEditor::get_singleton()->set_custom_camera(NULL); hide(); } - } void CameraEditor::_pressed() { - Node *sn = (node && preview->is_pressed())?node:NULL; + Node *sn = (node && preview->is_pressed()) ? node : NULL; SpatialEditor::get_singleton()->set_custom_camera(sn); } void CameraEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_pressed"),&CameraEditor::_pressed); - + ClassDB::bind_method(D_METHOD("_pressed"), &CameraEditor::_pressed); } void CameraEditor::edit(Node *p_camera) { - node=p_camera; + node = p_camera; if (!node) { preview->set_pressed(false); @@ -82,25 +78,22 @@ void CameraEditor::edit(Node *p_camera) { } } - CameraEditor::CameraEditor() { - preview = memnew( Button ); + preview = memnew(Button); add_child(preview); preview->set_text(TTR("Preview")); preview->set_toggle_mode(true); - preview->set_anchor(MARGIN_LEFT,Control::ANCHOR_END); - preview->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END); - preview->set_margin(MARGIN_LEFT,60); - preview->set_margin(MARGIN_RIGHT,0); - preview->set_margin(MARGIN_TOP,0); - preview->set_margin(MARGIN_BOTTOM,10); - preview->connect("pressed",this,"_pressed"); - + preview->set_anchor(MARGIN_LEFT, Control::ANCHOR_END); + preview->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); + preview->set_margin(MARGIN_LEFT, 60); + preview->set_margin(MARGIN_RIGHT, 0); + preview->set_margin(MARGIN_TOP, 0); + preview->set_margin(MARGIN_BOTTOM, 10); + preview->connect("pressed", this, "_pressed"); } - void CameraEditorPlugin::edit(Object *p_object) { SpatialEditor::get_singleton()->set_can_preview(p_object->cast_to()); @@ -119,13 +112,12 @@ void CameraEditorPlugin::make_visible(bool p_visible) { } else { SpatialEditor::get_singleton()->set_can_preview(NULL); } - } CameraEditorPlugin::CameraEditorPlugin(EditorNode *p_node) { - editor=p_node; -/* camera_editor = memnew( CameraEditor ); + editor = p_node; + /* camera_editor = memnew( CameraEditor ); editor->get_viewport()->add_child(camera_editor); camera_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END); @@ -138,13 +130,7 @@ CameraEditorPlugin::CameraEditorPlugin(EditorNode *p_node) { camera_editor->hide(); */ - - } - -CameraEditorPlugin::~CameraEditorPlugin() -{ +CameraEditorPlugin::~CameraEditorPlugin() { } - - diff --git a/editor/plugins/camera_editor_plugin.h b/editor/plugins/camera_editor_plugin.h index b5817b9960..f23b0d5cc8 100644 --- a/editor/plugins/camera_editor_plugin.h +++ b/editor/plugins/camera_editor_plugin.h @@ -29,8 +29,8 @@ #ifndef CAMERA_EDITOR_PLUGIN_H #define CAMERA_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/3d/camera.h" /** @@ -39,32 +39,32 @@ class CameraEditor : public Control { - GDCLASS(CameraEditor, Control ); + GDCLASS(CameraEditor, Control); Panel *panel; - Button * preview; + Button *preview; Node *node; void _pressed(); + protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); -public: +public: void edit(Node *p_camera); CameraEditor(); }; class CameraEditorPlugin : public EditorPlugin { - GDCLASS( CameraEditorPlugin, EditorPlugin ); + GDCLASS(CameraEditorPlugin, EditorPlugin); //CameraEditor *camera_editor; EditorNode *editor; public: - virtual String get_name() const { return "Camera"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -73,7 +73,6 @@ public: CameraEditorPlugin(EditorNode *p_node); ~CameraEditorPlugin(); - }; #endif // CAMERA_EDITOR_PLUGIN_H diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 1a0791d864..ebf2fa5a3a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -28,37 +28,35 @@ /*************************************************************************/ #include "canvas_item_editor_plugin.h" -#include "print_string.h" +#include "editor/animation_editor.h" #include "editor/editor_node.h" +#include "editor/editor_settings.h" +#include "editor/plugins/animation_player_editor_plugin.h" +#include "editor/plugins/script_editor_plugin.h" +#include "editor/script_editor_debugger.h" +#include "global_config.h" +#include "os/input.h" #include "os/keyboard.h" -#include "scene/main/viewport.h" -#include "scene/main/canvas_layer.h" -#include "scene/2d/sprite.h" +#include "print_string.h" #include "scene/2d/light_2d.h" #include "scene/2d/particles_2d.h" #include "scene/2d/polygon_2d.h" #include "scene/2d/screen_button.h" -#include "global_config.h" -#include "os/input.h" -#include "editor/editor_settings.h" +#include "scene/2d/sprite.h" #include "scene/gui/grid_container.h" #include "scene/gui/patch_9_rect.h" -#include "editor/animation_editor.h" -#include "editor/plugins/animation_player_editor_plugin.h" -#include "editor/script_editor_debugger.h" -#include "editor/plugins/script_editor_plugin.h" +#include "scene/main/canvas_layer.h" +#include "scene/main/viewport.h" #include "scene/resources/packed_scene.h" - #define MIN_ZOOM 0.01 #define MAX_ZOOM 100 - class SnapDialog : public ConfirmationDialog { - GDCLASS(SnapDialog,ConfirmationDialog); + GDCLASS(SnapDialog, ConfirmationDialog); -friend class CanvasItemEditor; + friend class CanvasItemEditor; SpinBox *grid_offset_x; SpinBox *grid_offset_y; @@ -68,7 +66,8 @@ friend class CanvasItemEditor; SpinBox *rotation_step; public: - SnapDialog() : ConfirmationDialog() { + SnapDialog() + : ConfirmationDialog() { const int SPIN_BOX_GRID_RANGE = 256; const int SPIN_BOX_ROTATION_RANGE = 360; Label *label; @@ -78,71 +77,71 @@ public: set_title(TTR("Configure Snap")); get_ok()->set_text(TTR("Close")); - container = memnew( VBoxContainer ); + container = memnew(VBoxContainer); add_child(container); //set_child_rect(container); - child_container = memnew( GridContainer ); + child_container = memnew(GridContainer); child_container->set_columns(3); container->add_child(child_container); - label = memnew( Label ); + label = memnew(Label); label->set_text(TTR("Grid Offset:")); child_container->add_child(label); label->set_h_size_flags(SIZE_EXPAND_FILL); - grid_offset_x = memnew( SpinBox ); + grid_offset_x = memnew(SpinBox); grid_offset_x->set_min(-SPIN_BOX_GRID_RANGE); grid_offset_x->set_max(SPIN_BOX_GRID_RANGE); grid_offset_x->set_suffix("px"); child_container->add_child(grid_offset_x); - grid_offset_y = memnew( SpinBox ); + grid_offset_y = memnew(SpinBox); grid_offset_y->set_min(-SPIN_BOX_GRID_RANGE); grid_offset_y->set_max(SPIN_BOX_GRID_RANGE); grid_offset_y->set_suffix("px"); child_container->add_child(grid_offset_y); - label = memnew( Label ); + label = memnew(Label); label->set_text(TTR("Grid Step:")); child_container->add_child(label); label->set_h_size_flags(SIZE_EXPAND_FILL); - grid_step_x = memnew( SpinBox ); + grid_step_x = memnew(SpinBox); grid_step_x->set_min(-SPIN_BOX_GRID_RANGE); grid_step_x->set_max(SPIN_BOX_GRID_RANGE); grid_step_x->set_suffix("px"); child_container->add_child(grid_step_x); - grid_step_y = memnew( SpinBox ); + grid_step_y = memnew(SpinBox); grid_step_y->set_min(-SPIN_BOX_GRID_RANGE); grid_step_y->set_max(SPIN_BOX_GRID_RANGE); grid_step_y->set_suffix("px"); child_container->add_child(grid_step_y); - container->add_child( memnew( HSeparator ) ); + container->add_child(memnew(HSeparator)); - child_container = memnew( GridContainer ); + child_container = memnew(GridContainer); child_container->set_columns(2); container->add_child(child_container); - label = memnew( Label ); + label = memnew(Label); label->set_text(TTR("Rotation Offset:")); child_container->add_child(label); label->set_h_size_flags(SIZE_EXPAND_FILL); - rotation_offset = memnew( SpinBox ); + rotation_offset = memnew(SpinBox); rotation_offset->set_min(-SPIN_BOX_ROTATION_RANGE); rotation_offset->set_max(SPIN_BOX_ROTATION_RANGE); rotation_offset->set_suffix("deg"); child_container->add_child(rotation_offset); - label = memnew( Label ); + label = memnew(Label); label->set_text(TTR("Rotation Step:")); child_container->add_child(label); label->set_h_size_flags(SIZE_EXPAND_FILL); - rotation_step = memnew( SpinBox ); + rotation_step = memnew(SpinBox); rotation_step->set_min(-SPIN_BOX_ROTATION_RANGE); rotation_step->set_max(SPIN_BOX_ROTATION_RANGE); rotation_step->set_suffix("deg"); @@ -168,12 +167,12 @@ public: } }; -void CanvasItemEditor::_edit_set_pivot(const Vector2& mouse_pos) { - List &selection = editor_selection->get_selected_node_list(); +void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) { + List &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Move Pivot")); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { Node2D *n2d = E->get()->cast_to(); @@ -184,31 +183,27 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2& mouse_pos) { Vector2 local_mouse_pos = n2d->get_canvas_transform().affine_inverse().xform(mouse_pos); - Vector2 motion_ofs = gpos-local_mouse_pos; + Vector2 motion_ofs = gpos - local_mouse_pos; - undo_redo->add_do_method(n2d,"set_global_pos",local_mouse_pos); - undo_redo->add_do_method(n2d,"edit_set_pivot",offset+n2d->get_global_transform().affine_inverse().basis_xform(motion_ofs)); - undo_redo->add_undo_method(n2d,"set_global_pos",gpos); - undo_redo->add_undo_method(n2d,"edit_set_pivot",offset); - for(int i=0;iget_child_count();i++) { + undo_redo->add_do_method(n2d, "set_global_pos", local_mouse_pos); + undo_redo->add_do_method(n2d, "edit_set_pivot", offset + n2d->get_global_transform().affine_inverse().basis_xform(motion_ofs)); + undo_redo->add_undo_method(n2d, "set_global_pos", gpos); + undo_redo->add_undo_method(n2d, "edit_set_pivot", offset); + for (int i = 0; i < n2d->get_child_count(); i++) { Node2D *n2dc = n2d->get_child(i)->cast_to(); if (!n2dc) continue; - undo_redo->add_do_method(n2dc,"set_global_pos",n2dc->get_global_position()); - undo_redo->add_undo_method(n2dc,"set_global_pos",n2dc->get_global_position()); - + undo_redo->add_do_method(n2dc, "set_global_pos", n2dc->get_global_position()); + undo_redo->add_undo_method(n2dc, "set_global_pos", n2dc->get_global_position()); } - } - } undo_redo->commit_action(); - } -void CanvasItemEditor::_unhandled_key_input(const InputEvent& p_ev) { +void CanvasItemEditor::_unhandled_key_input(const InputEvent &p_ev) { if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack()) return; @@ -216,42 +211,37 @@ void CanvasItemEditor::_unhandled_key_input(const InputEvent& p_ev) { if (p_ev.key.mod.control) return; - if (p_ev.key.pressed && !p_ev.key.echo && p_ev.key.scancode==KEY_V && drag==DRAG_NONE && can_move_pivot) { + if (p_ev.key.pressed && !p_ev.key.echo && p_ev.key.scancode == KEY_V && drag == DRAG_NONE && can_move_pivot) { if (p_ev.key.mod.shift) { //move drag pivot - drag=DRAG_PIVOT; + drag = DRAG_PIVOT; } else if (!Input::get_singleton()->is_mouse_button_pressed(0)) { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); Vector2 mouse_pos = viewport->get_local_mouse_pos(); if (selection.size() && viewport->get_rect().has_point(mouse_pos)) { //just in case, make it work if over viewport - mouse_pos=transform.affine_inverse().xform(mouse_pos); - mouse_pos=snap_point(mouse_pos); + mouse_pos = transform.affine_inverse().xform(mouse_pos); + mouse_pos = snap_point(mouse_pos); _edit_set_pivot(mouse_pos); } - } } - } void CanvasItemEditor::_tool_select(int p_index) { + ToolButton *tb[TOOL_MAX] = { select_button, list_select_button, move_button, rotate_button, pivot_button, pan_button }; + for (int i = 0; i < TOOL_MAX; i++) { - ToolButton *tb[TOOL_MAX]={select_button,list_select_button,move_button,rotate_button,pivot_button,pan_button}; - for(int i=0;iset_pressed(i==p_index); + tb[i]->set_pressed(i == p_index); } - viewport->update(); - tool=(Tool)p_index; - + tool = (Tool)p_index; } Object *CanvasItemEditor::_get_editor_data(Object *p_what) { @@ -260,7 +250,7 @@ Object *CanvasItemEditor::_get_editor_data(Object *p_what) { if (!ci) return NULL; - return memnew( CanvasItemEditorSelectedItem ); + return memnew(CanvasItemEditorSelectedItem); } inline float _snap_scalar(float p_offset, float p_step, bool p_snap_relative, float p_target, float p_start) { @@ -286,89 +276,88 @@ float CanvasItemEditor::snap_angle(float p_target, float p_start) const { Dictionary CanvasItemEditor::get_state() const { Dictionary state; - state["zoom"]=zoom; - state["ofs"]=Point2(h_scroll->get_value(),v_scroll->get_value()); + state["zoom"] = zoom; + state["ofs"] = Point2(h_scroll->get_value(), v_scroll->get_value()); //state["ofs"]=-transform.get_origin(); - state["snap_offset"]=snap_offset; - state["snap_step"]=snap_step; - state["snap_rotation_offset"]=snap_rotation_offset; - state["snap_rotation_step"]=snap_rotation_step; - state["snap_grid"]=snap_grid; - state["snap_show_grid"]=snap_show_grid; - state["snap_rotation"]=snap_rotation; - state["snap_relative"]=snap_relative; - state["snap_pixel"]=snap_pixel; - state["skeleton_show_bones"]=skeleton_show_bones; + state["snap_offset"] = snap_offset; + state["snap_step"] = snap_step; + state["snap_rotation_offset"] = snap_rotation_offset; + state["snap_rotation_step"] = snap_rotation_step; + state["snap_grid"] = snap_grid; + state["snap_show_grid"] = snap_show_grid; + state["snap_rotation"] = snap_rotation; + state["snap_relative"] = snap_relative; + state["snap_pixel"] = snap_pixel; + state["skeleton_show_bones"] = skeleton_show_bones; return state; } -void CanvasItemEditor::set_state(const Dictionary& p_state){ +void CanvasItemEditor::set_state(const Dictionary &p_state) { - Dictionary state=p_state; + Dictionary state = p_state; if (state.has("zoom")) { - zoom=p_state["zoom"]; + zoom = p_state["zoom"]; } if (state.has("ofs")) { _update_scrollbars(); // i wonder how safe is calling this here.. - Point2 ofs=p_state["ofs"]; + Point2 ofs = p_state["ofs"]; h_scroll->set_value(ofs.x); v_scroll->set_value(ofs.y); } if (state.has("snap_step")) { - snap_step=state["snap_step"]; + snap_step = state["snap_step"]; } if (state.has("snap_offset")) { - snap_offset=state["snap_offset"]; + snap_offset = state["snap_offset"]; } if (state.has("snap_rotation_step")) { - snap_rotation_step=state["snap_rotation_step"]; + snap_rotation_step = state["snap_rotation_step"]; } if (state.has("snap_rotation_offset")) { - snap_rotation_offset=state["snap_rotation_offset"]; + snap_rotation_offset = state["snap_rotation_offset"]; } if (state.has("snap_grid")) { - snap_grid=state["snap_grid"]; + snap_grid = state["snap_grid"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE); - edit_menu->get_popup()->set_item_checked(idx,snap_grid); + edit_menu->get_popup()->set_item_checked(idx, snap_grid); } if (state.has("snap_show_grid")) { - snap_show_grid=state["snap_show_grid"]; + snap_show_grid = state["snap_show_grid"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID); - edit_menu->get_popup()->set_item_checked(idx,snap_show_grid); + edit_menu->get_popup()->set_item_checked(idx, snap_show_grid); } if (state.has("snap_rotation")) { - snap_rotation=state["snap_rotation"]; + snap_rotation = state["snap_rotation"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION); - edit_menu->get_popup()->set_item_checked(idx,snap_rotation); + edit_menu->get_popup()->set_item_checked(idx, snap_rotation); } if (state.has("snap_relative")) { - snap_relative=state["snap_relative"]; + snap_relative = state["snap_relative"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE); - edit_menu->get_popup()->set_item_checked(idx,snap_relative); + edit_menu->get_popup()->set_item_checked(idx, snap_relative); } if (state.has("snap_pixel")) { - snap_pixel=state["snap_pixel"]; + snap_pixel = state["snap_pixel"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL); - edit_menu->get_popup()->set_item_checked(idx,snap_pixel); + edit_menu->get_popup()->set_item_checked(idx, snap_pixel); } if (state.has("skeleton_show_bones")) { - skeleton_show_bones=state["skeleton_show_bones"]; + skeleton_show_bones = state["skeleton_show_bones"]; int idx = skeleton_menu->get_item_index(SKELETON_SHOW_BONES); - skeleton_menu->set_item_checked(idx,skeleton_show_bones); + skeleton_menu->set_item_checked(idx, skeleton_show_bones); } } - void CanvasItemEditor::_add_canvas_item(CanvasItem *p_canvas_item) { editor_selection->add_node(p_canvas_item); @@ -388,7 +377,6 @@ void CanvasItemEditor::_remove_canvas_item(CanvasItem *p_canvas_item) { p_canvas_item->disconnect("hide",this,"_visibility_changed"); canvas_items.erase(p_canvas_item); #endif - } void CanvasItemEditor::_clear_canvas_items() { @@ -413,7 +401,6 @@ void CanvasItemEditor::_visibility_changed(ObjectID p_canvas_item) { #endif } - void CanvasItemEditor::_node_removed(Node *p_node) { #if 0 CanvasItem *canvas_item = (CanvasItem*)p_node; //not a good cast, but safe @@ -434,32 +421,31 @@ void CanvasItemEditor::_keying_changed() { bool CanvasItemEditor::_is_part_of_subscene(CanvasItem *p_item) { - Node* scene_node = get_tree()->get_edited_scene_root(); - Node* item_owner = p_item->get_owner(); + Node *scene_node = get_tree()->get_edited_scene_root(); + Node *item_owner = p_item->get_owner(); - return item_owner && item_owner!=scene_node && p_item!=scene_node && item_owner->get_filename()!=""; + return item_owner && item_owner != scene_node && p_item != scene_node && item_owner->get_filename() != ""; } // slow but modern computers should have no problem -CanvasItem* CanvasItemEditor::_select_canvas_item_at_pos(const Point2& p_pos,Node* p_node,const Transform2D& p_parent_xform,const Transform2D& p_canvas_xform) { +CanvasItem *CanvasItemEditor::_select_canvas_item_at_pos(const Point2 &p_pos, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) { if (!p_node) return NULL; if (p_node->cast_to()) return NULL; - CanvasItem *c=p_node->cast_to(); - + CanvasItem *c = p_node->cast_to(); - for (int i=p_node->get_child_count()-1;i>=0;i--) { + for (int i = p_node->get_child_count() - 1; i >= 0; i--) { - CanvasItem *r=NULL; + CanvasItem *r = NULL; if (c && !c->is_set_as_toplevel()) - r=_select_canvas_item_at_pos(p_pos,p_node->get_child(i),p_parent_xform * c->get_transform(),p_canvas_xform); + r = _select_canvas_item_at_pos(p_pos, p_node->get_child(i), p_parent_xform * c->get_transform(), p_canvas_xform); else { CanvasLayer *cl = p_node->cast_to(); - r=_select_canvas_item_at_pos(p_pos,p_node->get_child(i),transform ,cl ? cl->get_transform() : p_canvas_xform); //use base transform + r = _select_canvas_item_at_pos(p_pos, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform); //use base transform } if (r) @@ -471,79 +457,73 @@ CanvasItem* CanvasItemEditor::_select_canvas_item_at_pos(const Point2& p_pos,Nod Rect2 rect = c->get_item_rect(); Point2 local_pos = (p_parent_xform * p_canvas_xform * c->get_transform()).affine_inverse().xform(p_pos); - if (rect.has_point(local_pos)) return c; - } return NULL; } -void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos,Node* p_node,const Transform2D& p_parent_xform,const Transform2D& p_canvas_xform, Vector<_SelectResult> &r_items) { +void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, Vector<_SelectResult> &r_items) { if (!p_node) return; if (p_node->cast_to()) return; - CanvasItem *c=p_node->cast_to(); + CanvasItem *c = p_node->cast_to(); - for (int i=p_node->get_child_count()-1;i>=0;i--) { + for (int i = p_node->get_child_count() - 1; i >= 0; i--) { if (c && !c->is_set_as_toplevel()) - _find_canvas_items_at_pos(p_pos,p_node->get_child(i),p_parent_xform * c->get_transform(),p_canvas_xform, r_items); + _find_canvas_items_at_pos(p_pos, p_node->get_child(i), p_parent_xform * c->get_transform(), p_canvas_xform, r_items); else { CanvasLayer *cl = p_node->cast_to(); - _find_canvas_items_at_pos(p_pos,p_node->get_child(i),transform ,cl ? cl->get_transform() : p_canvas_xform, r_items); //use base transform + _find_canvas_items_at_pos(p_pos, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform, r_items); //use base transform } } - if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !c->cast_to()) { Rect2 rect = c->get_item_rect(); Point2 local_pos = (p_parent_xform * p_canvas_xform * c->get_transform()).affine_inverse().xform(p_pos); - if (rect.has_point(local_pos)) { - Node2D *node=c->cast_to(); + Node2D *node = c->cast_to(); _SelectResult res; - res.item=c; - res.z=node?node->get_z():0; - res.has_z=node; + res.item = c; + res.z = node ? node->get_z() : 0; + res.has_z = node; r_items.push_back(res); } - } return; } -void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2& p_rect,Node* p_node,const Transform2D& p_parent_xform,const Transform2D& p_canvas_xform,List *r_items) { +void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, List *r_items) { if (!p_node) return; if (p_node->cast_to()) return; - CanvasItem *c=p_node->cast_to(); - + CanvasItem *c = p_node->cast_to(); - bool inherited=p_node!=get_tree()->get_edited_scene_root() && p_node->get_filename()!=""; - bool editable=false; - if (inherited){ - editable=EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node); + bool inherited = p_node != get_tree()->get_edited_scene_root() && p_node->get_filename() != ""; + bool editable = false; + if (inherited) { + editable = EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node); } - bool lock_children=p_node->has_meta("_edit_group_") && p_node->get_meta("_edit_group_"); + bool lock_children = p_node->has_meta("_edit_group_") && p_node->get_meta("_edit_group_"); if (!lock_children && (!inherited || editable)) { - for (int i=p_node->get_child_count()-1;i>=0;i--) { + for (int i = p_node->get_child_count() - 1; i >= 0; i--) { if (c && !c->is_set_as_toplevel()) - _find_canvas_items_at_rect(p_rect,p_node->get_child(i),p_parent_xform * c->get_transform(),p_canvas_xform,r_items); + _find_canvas_items_at_rect(p_rect, p_node->get_child(i), p_parent_xform * c->get_transform(), p_canvas_xform, r_items); else { CanvasLayer *cl = p_node->cast_to(); - _find_canvas_items_at_rect(p_rect,p_node->get_child(i),transform,cl?cl->get_transform():p_canvas_xform,r_items); + _find_canvas_items_at_rect(p_rect, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform, r_items); } } } @@ -553,17 +533,14 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2& p_rect,Node* p_no Rect2 rect = c->get_item_rect(); Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform(); - if ( p_rect.has_point( xform.xform( rect.pos ) ) && - p_rect.has_point( xform.xform( rect.pos+Vector2(rect.size.x,0) ) ) && - p_rect.has_point( xform.xform( rect.pos+Vector2(rect.size.x,rect.size.y) ) ) && - p_rect.has_point( xform.xform( rect.pos+Vector2(0,rect.size.y) ) ) ) { + if (p_rect.has_point(xform.xform(rect.pos)) && + p_rect.has_point(xform.xform(rect.pos + Vector2(rect.size.x, 0))) && + p_rect.has_point(xform.xform(rect.pos + Vector2(rect.size.x, rect.size.y))) && + p_rect.has_point(xform.xform(rect.pos + Vector2(0, rect.size.y)))) { r_items->push_back(c); - } } - - } bool CanvasItemEditor::_select(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag) { @@ -574,10 +551,10 @@ bool CanvasItemEditor::_select(CanvasItem *item, Point2 p_click_pos, bool p_appe if (!item) { if (p_drag) { - drag_from=transform.affine_inverse().xform(p_click_pos); + drag_from = transform.affine_inverse().xform(p_click_pos); - box_selecting=true; - box_selecting_to=drag_from; + box_selecting = true; + box_selecting_to = drag_from; } return false; //nothing to add @@ -590,7 +567,6 @@ bool CanvasItemEditor::_select(CanvasItem *item, Point2 p_click_pos, bool p_appe viewport->update(); return false; - } _append_canvas_item(item); viewport->update(); @@ -605,10 +581,10 @@ bool CanvasItemEditor::_select(CanvasItem *item, Point2 p_click_pos, bool p_appe editor_selection->clear(); if (p_drag) { - drag_from=transform.affine_inverse().xform(p_click_pos); + drag_from = transform.affine_inverse().xform(p_click_pos); - box_selecting=true; - box_selecting_to=drag_from; + box_selecting = true; + box_selecting_to = drag_from; } viewport->update(); @@ -621,88 +597,83 @@ bool CanvasItemEditor::_select(CanvasItem *item, Point2 p_click_pos, bool p_appe editor_selection->add_node(item); //reselect if (get_tree()->is_editor_hint()) { - editor->call("edit_node",item); + editor->call("edit_node", item); } - } if (p_drag) { //prepare to move! - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; - se->undo_state=canvas_item->edit_get_state(); + se->undo_state = canvas_item->edit_get_state(); if (canvas_item->cast_to()) - se->undo_pivot=canvas_item->cast_to()->edit_get_pivot(); - + se->undo_pivot = canvas_item->cast_to()->edit_get_pivot(); } - drag=DRAG_ALL; - drag_from=transform.affine_inverse().xform(p_click_pos); - drag_point_from=_find_topleftmost_point(); + drag = DRAG_ALL; + drag_from = transform.affine_inverse().xform(p_click_pos); + drag_point_from = _find_topleftmost_point(); } viewport->update(); return true; - } } -void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE p_move_mode) { - +void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode) { - if (drag!=DRAG_NONE) + if (drag != DRAG_NONE) return; if (editor_selection->get_selected_node_list().empty()) return; - undo_redo->create_action(TTR("Move Action"),UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Move Action"), UndoRedo::MERGE_ENDS); - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; if (canvas_item->has_meta("_edit_lock_")) continue; - Vector2 drag = p_dir; if (p_snap) - drag*=snap_step; + drag *= snap_step; - undo_redo->add_undo_method(canvas_item,"edit_set_state",canvas_item->edit_get_state()); + undo_redo->add_undo_method(canvas_item, "edit_set_state", canvas_item->edit_get_state()); - if (p_move_mode == MOVE_VIEW_BASE) { + if (p_move_mode == MOVE_VIEW_BASE) { // drag = transform.affine_inverse().basis_xform(p_dir); // zoom sensitive drag = canvas_item->get_global_transform_with_canvas().affine_inverse().basis_xform(drag); Rect2 local_rect = canvas_item->get_item_rect(); - local_rect.pos+=drag; - undo_redo->add_do_method(canvas_item,"edit_set_rect",local_rect); + local_rect.pos += drag; + undo_redo->add_do_method(canvas_item, "edit_set_rect", local_rect); } else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT @@ -710,14 +681,14 @@ void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE if (p_move_mode == MOVE_LOCAL_WITH_ROT) { Transform2D m; - m.rotate( node_2d->get_rotation() ); + m.rotate(node_2d->get_rotation()); drag = m.xform(drag); } node_2d->set_position(node_2d->get_position() + drag); } else if (Control *control = canvas_item->cast_to()) { - control->set_pos(control->get_pos()+drag); + control->set_pos(control->get_pos() + drag); } } } @@ -727,53 +698,44 @@ void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE Point2 CanvasItemEditor::_find_topleftmost_point() { - - - Vector2 tl=Point2(1e10,1e10); + Vector2 tl = Point2(1e10, 1e10); Rect2 r2; - r2.pos=tl; - + r2.pos = tl; - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - - - - Rect2 rect=canvas_item->get_item_rect(); - Transform2D xform=canvas_item->get_global_transform_with_canvas(); + Rect2 rect = canvas_item->get_item_rect(); + Transform2D xform = canvas_item->get_global_transform_with_canvas(); r2.expand_to(xform.xform(rect.pos)); - r2.expand_to(xform.xform(rect.pos+Vector2(rect.size.x,0))); - r2.expand_to(xform.xform(rect.pos+rect.size)); - r2.expand_to(xform.xform(rect.pos+Vector2(0,rect.size.y))); - + r2.expand_to(xform.xform(rect.pos + Vector2(rect.size.x, 0))); + r2.expand_to(xform.xform(rect.pos + rect.size)); + r2.expand_to(xform.xform(rect.pos + Vector2(0, rect.size.y))); } return r2.pos; } - - int CanvasItemEditor::get_item_count() { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - int ic=0; - for(List::Element *E=selection.front();E;E=E->next()) { + int ic = 0; + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; ic++; @@ -784,55 +746,54 @@ int CanvasItemEditor::get_item_count() { CanvasItem *CanvasItemEditor::get_single_item() { + Map &selection = editor_selection->get_selection(); - Map &selection = editor_selection->get_selection(); - - CanvasItem *single_item=NULL; + CanvasItem *single_item = NULL; - for(Map::Element *E=selection.front();E;E=E->next()) { + for (Map::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; if (single_item) return NULL; //morethan one - single_item=canvas_item; + single_item = canvas_item; }; return single_item; } -CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Transform2D& p_xform, const Rect2& p_local_rect, const Point2& p_click, Vector2& r_point) { +CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Transform2D &p_xform, const Rect2 &p_local_rect, const Point2 &p_click, Vector2 &r_point) { CanvasItem *canvas_item = get_single_item(); - ERR_FAIL_COND_V(!canvas_item,DRAG_NONE); + ERR_FAIL_COND_V(!canvas_item, DRAG_NONE); - Rect2 rect=canvas_item->get_item_rect(); - Transform2D xforml=canvas_item->get_global_transform_with_canvas(); - Transform2D xform=transform * xforml; + Rect2 rect = canvas_item->get_item_rect(); + Transform2D xforml = canvas_item->get_global_transform_with_canvas(); + Transform2D xform = transform * xforml; - Vector2 endpoints[4]={ + Vector2 endpoints[4] = { xform.xform(rect.pos), - xform.xform(rect.pos+Vector2(rect.size.x,0)), - xform.xform(rect.pos+rect.size), - xform.xform(rect.pos+Vector2(0,rect.size.y)) + xform.xform(rect.pos + Vector2(rect.size.x, 0)), + xform.xform(rect.pos + rect.size), + xform.xform(rect.pos + Vector2(0, rect.size.y)) }; - Vector2 endpointsl[4]={ + Vector2 endpointsl[4] = { xforml.xform(rect.pos), - xforml.xform(rect.pos+Vector2(rect.size.x,0)), - xforml.xform(rect.pos+rect.size), - xforml.xform(rect.pos+Vector2(0,rect.size.y)) + xforml.xform(rect.pos + Vector2(rect.size.x, 0)), + xforml.xform(rect.pos + rect.size), + xforml.xform(rect.pos + Vector2(0, rect.size.y)) }; - DragType dragger[]={ + DragType dragger[] = { DRAG_TOP_LEFT, DRAG_TOP, DRAG_TOP_RIGHT, @@ -843,34 +804,32 @@ CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Transform2D& DRAG_LEFT }; - float radius = (select_handle->get_size().width/2)*1.5; + float radius = (select_handle->get_size().width / 2) * 1.5; //try draggers - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { - int prev = (i+3)%4; - int next = (i+1)%4; + int prev = (i + 3) % 4; + int next = (i + 1) % 4; - r_point=endpointsl[i]; + r_point = endpointsl[i]; Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized(); - ofs*=1.4144*(select_handle->get_size().width/2); + ofs *= 1.4144 * (select_handle->get_size().width / 2); - ofs+=endpoints[i]; + ofs += endpoints[i]; - if (ofs.distance_to(p_click)get_size().width/2); + ofs = (endpoints[i] + endpoints[next]) / 2; + ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2); - r_point=(endpointsl[i]+endpointsl[next])/2; - - - if (ofs.distance_to(p_click)add_node(c); - } - void CanvasItemEditor::_snap_changed() { ((SnapDialog *)snap_dialog)->get_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step); viewport->update(); @@ -958,16 +913,16 @@ void CanvasItemEditor::_dialog_value_changed(double) { if (updating_value_dialog) return; - switch(last_option) { + switch (last_option) { case ZOOM_SET: { - zoom=dialog_val->get_value()/100.0; + zoom = dialog_val->get_value() / 100.0; _update_scroll(0); viewport->update(); } break; - default:{} + default: {} } } @@ -976,7 +931,7 @@ void CanvasItemEditor::_selection_result_pressed(int p_result) { if (selection_results.size() <= p_result) return; - CanvasItem *item=selection_results[p_result].item; + CanvasItem *item = selection_results[p_result].item; if (item) _select(item, Point2(), additive_selection, false); @@ -989,31 +944,28 @@ void CanvasItemEditor::_selection_menu_hide() { selection_menu->set_size(Vector2(0, 0)); } -bool CanvasItemEditor::get_remove_list(List *p_list) { +bool CanvasItemEditor::get_remove_list(List *p_list) { - - return false;//!p_list->empty(); + return false; //!p_list->empty(); } +void CanvasItemEditor::_list_select(const InputEventMouseButton &b) { -void CanvasItemEditor::_list_select(const InputEventMouseButton& b) { - - Point2 click=Point2(b.x,b.y); + Point2 click = Point2(b.x, b.y); - Node* scene = editor->get_edited_scene(); + Node *scene = editor->get_edited_scene(); if (!scene) return; - _find_canvas_items_at_pos(click, scene,transform,Transform2D(), selection_results); + _find_canvas_items_at_pos(click, scene, transform, Transform2D(), selection_results); - for(int i=0;iget_owner()!=scene && !scene->is_editable_instance(item->get_owner())) { + for (int i = 0; i < selection_results.size(); i++) { + CanvasItem *item = selection_results[i].item; + if (item != scene && item->get_owner() != scene && !scene->is_editable_instance(item->get_owner())) { //invalid result selection_results.remove(i); i--; } - } if (selection_results.size() == 1) { @@ -1021,7 +973,7 @@ void CanvasItemEditor::_list_select(const InputEventMouseButton& b) { CanvasItem *item = selection_results[0].item; selection_results.clear(); - additive_selection=b.mod.shift; + additive_selection = b.mod.shift; if (!_select(item, click, additive_selection, false)) return; @@ -1030,50 +982,47 @@ void CanvasItemEditor::_list_select(const InputEventMouseButton& b) { selection_results.sort(); NodePath root_path = get_tree()->get_edited_scene_root()->get_path(); - StringName root_name = root_path.get_name(root_path.get_name_count()-1); + StringName root_name = root_path.get_name(root_path.get_name_count() - 1); for (int i = 0; i < selection_results.size(); i++) { - CanvasItem *item=selection_results[i].item; - + CanvasItem *item = selection_results[i].item; Ref icon; if (item->has_meta("_editor_icon")) - icon=item->get_meta("_editor_icon"); + icon = item->get_meta("_editor_icon"); else - icon=get_icon( has_icon(item->get_class(),"EditorIcons")?item->get_class():String("Object"),"EditorIcons"); + icon = get_icon(has_icon(item->get_class(), "EditorIcons") ? item->get_class() : String("Object"), "EditorIcons"); - String node_path="/"+root_name+"/"+root_path.rel_path_to(item->get_path()); + String node_path = "/" + root_name + "/" + root_path.rel_path_to(item->get_path()); selection_menu->add_item(item->get_name()); - selection_menu->set_item_icon(i, icon ); + selection_menu->set_item_icon(i, icon); selection_menu->set_item_metadata(i, node_path); - selection_menu->set_item_tooltip(i,String(item->get_name())+ - "\nType: "+item->get_class()+"\nPath: "+node_path); + selection_menu->set_item_tooltip(i, String(item->get_name()) + + "\nType: " + item->get_class() + "\nPath: " + node_path); } - additive_selection=b.mod.shift; + additive_selection = b.mod.shift; - selection_menu->set_global_pos(Vector2( b.global_x, b.global_y )); + selection_menu->set_global_pos(Vector2(b.global_x, b.global_y)); selection_menu->popup(); selection_menu->call_deferred("grab_click_focus"); selection_menu->set_invalidate_click_until_motion(); - return; } - } -void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { +void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) { - { + { EditorNode *en = editor; EditorPluginList *over_plugin_list = en->get_editor_plugins_over(); if (!over_plugin_list->empty()) { - bool discard = over_plugin_list->forward_gui_input(transform,p_event); + bool discard = over_plugin_list->forward_gui_input(transform, p_event); if (discard) { accept_event(); return; @@ -1081,42 +1030,40 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { } } + if (p_event.type == InputEvent::MOUSE_BUTTON) { - if (p_event.type==InputEvent::MOUSE_BUTTON) { - - const InputEventMouseButton &b=p_event.mouse_button; + const InputEventMouseButton &b = p_event.mouse_button; + if (b.button_index == BUTTON_WHEEL_DOWN) { - if (b.button_index==BUTTON_WHEEL_DOWN) { - - if (zoomset_value( h_scroll->get_value() + ofs.x ); - v_scroll->set_value( v_scroll->get_value() + ofs.y ); + Point2 ofs(b.x, b.y); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); } _update_scroll(0); viewport->update(); return; } - if (b.button_index==BUTTON_WHEEL_UP) { + if (b.button_index == BUTTON_WHEEL_UP) { - if (zoom>MAX_ZOOM) + if (zoom > MAX_ZOOM) return; - float prev_zoom=zoom; - zoom=zoom*(1.0/0.95); + float prev_zoom = zoom; + zoom = zoom * (1.0 / 0.95); { - Point2 ofs(b.x,b.y); - ofs = ofs/prev_zoom - ofs/zoom; - h_scroll->set_value( h_scroll->get_value() + ofs.x ); - v_scroll->set_value( v_scroll->get_value() + ofs.y ); + Point2 ofs(b.x, b.y); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); } _update_scroll(0); @@ -1124,21 +1071,20 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { return; } - if (b.button_index==BUTTON_RIGHT) { - + if (b.button_index == BUTTON_RIGHT) { - if (b.pressed && (tool==TOOL_SELECT && b.mod.alt)) { + if (b.pressed && (tool == TOOL_SELECT && b.mod.alt)) { _list_select(b); return; } - if (get_item_count() > 0 && drag!=DRAG_NONE) { + if (get_item_count() > 0 && drag != DRAG_NONE) { //cancel drag if (bone_ik_list.size()) { - for(List::Element *E=bone_ik_list.back();E;E=E->prev()) { + for (List::Element *E = bone_ik_list.back(); E; E = E->prev()) { E->get().node->edit_set_state(E->get().orig_state); } @@ -1147,35 +1093,32 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { } else { + List &selection = editor_selection->get_selected_node_list(); - List &selection = editor_selection->get_selected_node_list(); - - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; canvas_item->edit_set_state(se->undo_state); if (canvas_item->cast_to()) canvas_item->cast_to()->edit_set_pivot(se->undo_pivot); - } } - drag=DRAG_NONE; + drag = DRAG_NONE; viewport->update(); - can_move_pivot=false; + can_move_pivot = false; } else if (box_selecting) { - box_selecting=false; + box_selecting = false; viewport->update(); } else if (b.pressed) { #if 0 @@ -1193,49 +1136,44 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { return; */ - if (b.button_index==BUTTON_LEFT && tool==TOOL_LIST_SELECT) { + if (b.button_index == BUTTON_LEFT && tool == TOOL_LIST_SELECT) { if (b.pressed) _list_select(b); return; } - - if (b.button_index==BUTTON_LEFT && tool==TOOL_EDIT_PIVOT) { + if (b.button_index == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) { if (b.pressed) { - Point2 mouse_pos(b.x,b.y); - mouse_pos=transform.affine_inverse().xform(mouse_pos); - mouse_pos=snap_point(mouse_pos); + Point2 mouse_pos(b.x, b.y); + mouse_pos = transform.affine_inverse().xform(mouse_pos); + mouse_pos = snap_point(mouse_pos); _edit_set_pivot(mouse_pos); } return; } - - - if (tool==TOOL_PAN || b.button_index!=BUTTON_LEFT || Input::get_singleton()->is_key_pressed(KEY_SPACE)) + if (tool == TOOL_PAN || b.button_index != BUTTON_LEFT || Input::get_singleton()->is_key_pressed(KEY_SPACE)) return; if (!b.pressed) { - if (drag!=DRAG_NONE) { + if (drag != DRAG_NONE) { if (undo_redo) { - if (bone_ik_list.size()) { - undo_redo->create_action(TTR("Edit IK Chain")); - for(List::Element *E=bone_ik_list.back();E;E=E->prev()) { + for (List::Element *E = bone_ik_list.back(); E; E = E->prev()) { - undo_redo->add_do_method(E->get().node,"edit_set_state",E->get().node->edit_get_state()); - undo_redo->add_undo_method(E->get().node,"edit_set_state",E->get().orig_state); + undo_redo->add_do_method(E->get().node, "edit_set_state", E->get().node->edit_get_state()); + undo_redo->add_undo_method(E->get().node, "edit_set_state", E->get().orig_state); } - undo_redo->add_do_method(viewport,"update"); - undo_redo->add_undo_method(viewport,"update"); + undo_redo->add_do_method(viewport, "update"); + undo_redo->add_undo_method(viewport, "update"); bone_ik_list.clear(); @@ -1244,29 +1182,28 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { undo_redo->create_action(TTR("Edit CanvasItem")); + List &selection = editor_selection->get_selected_node_list(); - List &selection = editor_selection->get_selected_node_list(); - - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; - Variant state=canvas_item->edit_get_state(); - undo_redo->add_do_method(canvas_item,"edit_set_state",state); - undo_redo->add_undo_method(canvas_item,"edit_set_state",se->undo_state); + Variant state = canvas_item->edit_get_state(); + undo_redo->add_do_method(canvas_item, "edit_set_state", state); + undo_redo->add_undo_method(canvas_item, "edit_set_state", se->undo_state); if (canvas_item->cast_to()) { Node2D *pvt = canvas_item->cast_to(); if (pvt->edit_has_pivot()) { - undo_redo->add_do_method(canvas_item,"edit_set_pivot",pvt->edit_get_pivot()); - undo_redo->add_undo_method(canvas_item,"edit_set_pivot",se->undo_pivot); + undo_redo->add_do_method(canvas_item, "edit_set_pivot", pvt->edit_get_pivot()); + undo_redo->add_undo_method(canvas_item, "edit_set_pivot", se->undo_pivot); } } } @@ -1274,10 +1211,9 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { } } - drag=DRAG_NONE; + drag = DRAG_NONE; viewport->update(); - can_move_pivot=false; - + can_move_pivot = false; } if (box_selecting) { @@ -1286,110 +1222,102 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { if ( box_selection_end() ) return; #endif - Node* scene = editor->get_edited_scene(); + Node *scene = editor->get_edited_scene(); if (scene) { - List selitems; + List selitems; Point2 bsfrom = transform.xform(drag_from); - Point2 bsto= transform.xform(box_selecting_to); - if (bsfrom.x>bsto.x) - SWAP(bsfrom.x,bsto.x); - if (bsfrom.y>bsto.y) - SWAP(bsfrom.y,bsto.y); + Point2 bsto = transform.xform(box_selecting_to); + if (bsfrom.x > bsto.x) + SWAP(bsfrom.x, bsto.x); + if (bsfrom.y > bsto.y) + SWAP(bsfrom.y, bsto.y); - _find_canvas_items_at_rect(Rect2(bsfrom,bsto-bsfrom),scene,transform,Transform2D(),&selitems); + _find_canvas_items_at_rect(Rect2(bsfrom, bsto - bsfrom), scene, transform, Transform2D(), &selitems); - for(List::Element *E=selitems.front();E;E=E->next()) { + for (List::Element *E = selitems.front(); E; E = E->next()) { _append_canvas_item(E->get()); } - } - box_selecting=false; + box_selecting = false; viewport->update(); - } return; } - - Map::Element *Cbone=NULL; //closest + Map::Element *Cbone = NULL; //closest { bone_ik_list.clear(); - float closest_dist=1e20; + float closest_dist = 1e20; int bone_width = EditorSettings::get_singleton()->get("editors/2d/bone_width"); - for(Map::Element *E=bone_list.front();E;E=E->next()) { + for (Map::Element *E = bone_list.front(); E; E = E->next()) { if (E->get().from == E->get().to) continue; - Vector2 s[2]={ + Vector2 s[2] = { E->get().from, E->get().to }; - Vector2 p = Geometry::get_closest_point_to_segment_2d(Vector2(b.x,b.y),s); - float d = p.distance_to(Vector2(b.x,b.y)); - if (dget().bone); + Node2D *b = NULL; + Object *obj = ObjectDB::get_instance(Cbone->get().bone); if (obj) - b=obj->cast_to(); + b = obj->cast_to(); if (b) { + bool ik_found = false; + bool first = true; - bool ik_found=false; - bool first=true; - - + while (b) { - while(b) { - - CanvasItem *pi=b->get_parent_item(); + CanvasItem *pi = b->get_parent_item(); if (!pi) break; - float len=pi->get_global_transform().get_origin().distance_to(b->get_global_position()); - b=pi->cast_to(); + float len = pi->get_global_transform().get_origin().distance_to(b->get_global_position()); + b = pi->cast_to(); if (!b) break; if (first) { - bone_orig_xform=b->get_global_transform(); - first=false; + bone_orig_xform = b->get_global_transform(); + first = false; } BoneIK bik; - bik.node=b; - bik.len=len; - bik.orig_state=b->edit_get_state(); + bik.node = b; + bik.len = len; + bik.orig_state = b->edit_get_state(); bone_ik_list.push_back(bik); if (b->has_meta("_edit_ik_")) { - ik_found=bone_ik_list.size()>1; + ik_found = bone_ik_list.size() > 1; break; } if (!pi->has_meta("_edit_bone_")) break; - } if (!ik_found) bone_ik_list.clear(); - } } } @@ -1400,92 +1328,86 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { //try single canvas_item edit CanvasItem *canvas_item = single_item; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); ERR_FAIL_COND(!se); + Point2 click(b.x, b.y); - Point2 click(b.x,b.y); - - if ((b.mod.control && tool==TOOL_SELECT) || tool==TOOL_ROTATE) { + if ((b.mod.control && tool == TOOL_SELECT) || tool == TOOL_ROTATE) { - drag=DRAG_ROTATE; - drag_from=transform.affine_inverse().xform(click); - se->undo_state=canvas_item->edit_get_state(); + drag = DRAG_ROTATE; + drag_from = transform.affine_inverse().xform(click); + se->undo_state = canvas_item->edit_get_state(); if (canvas_item->cast_to()) - se->undo_pivot=canvas_item->cast_to()->edit_get_pivot(); + se->undo_pivot = canvas_item->cast_to()->edit_get_pivot(); if (canvas_item->cast_to()) - se->undo_pivot=Vector2(); + se->undo_pivot = Vector2(); return; } Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); - Rect2 rect=canvas_item->get_item_rect(); + Rect2 rect = canvas_item->get_item_rect(); //float handle_radius = handle_len * 1.4144; //magic number, guess what it means! - if (tool==TOOL_SELECT) { - drag = _find_drag_type(xform,rect,click,drag_point_from); + if (tool == TOOL_SELECT) { + drag = _find_drag_type(xform, rect, click, drag_point_from); if (b.doubleclick) { - if (canvas_item->get_filename()!="" && canvas_item!=editor->get_edited_scene()) { + if (canvas_item->get_filename() != "" && canvas_item != editor->get_edited_scene()) { editor->open_request(canvas_item->get_filename()); return; } } - if (drag!=DRAG_NONE && (!Cbone || drag!=DRAG_ALL)) { - drag_from=transform.affine_inverse().xform(click); - se->undo_state=canvas_item->edit_get_state(); + if (drag != DRAG_NONE && (!Cbone || drag != DRAG_ALL)) { + drag_from = transform.affine_inverse().xform(click); + se->undo_state = canvas_item->edit_get_state(); if (canvas_item->cast_to()) - se->undo_pivot=canvas_item->cast_to()->edit_get_pivot(); + se->undo_pivot = canvas_item->cast_to()->edit_get_pivot(); return; } } else { - drag=DRAG_NONE; + drag = DRAG_NONE; } } //multi canvas_item edit + Point2 click = Point2(b.x, b.y); - Point2 click=Point2(b.x,b.y); + if ((b.mod.alt || tool == TOOL_MOVE) && get_item_count()) { - if ((b.mod.alt || tool==TOOL_MOVE) && get_item_count()) { + List &selection = editor_selection->get_selected_node_list(); - - List &selection = editor_selection->get_selected_node_list(); - - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; - se->undo_state=canvas_item->edit_get_state(); + se->undo_state = canvas_item->edit_get_state(); if (canvas_item->cast_to()) - se->undo_pivot=canvas_item->cast_to()->edit_get_pivot(); - + se->undo_pivot = canvas_item->cast_to()->edit_get_pivot(); } - - drag=DRAG_ALL; - drag_from=transform.affine_inverse().xform(click); - drag_point_from=_find_topleftmost_point(); + drag = DRAG_ALL; + drag_from = transform.affine_inverse().xform(click); + drag_point_from = _find_topleftmost_point(); viewport->update(); return; - } - Node* scene = editor->get_edited_scene(); + Node *scene = editor->get_edited_scene(); if (!scene) return; @@ -1494,33 +1416,30 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { //no window.... ? click-=current_window->get_scroll(); }*/ - CanvasItem *c=NULL; + CanvasItem *c = NULL; if (Cbone) { - Object* obj=ObjectDB::get_instance(Cbone->get().bone); + Object *obj = ObjectDB::get_instance(Cbone->get().bone); if (obj) - c=obj->cast_to(); + c = obj->cast_to(); if (c) - c=c->get_parent_item(); - - + c = c->get_parent_item(); } if (!c) { - c =_select_canvas_item_at_pos(click, scene,transform,Transform2D()); - + c = _select_canvas_item_at_pos(click, scene, transform, Transform2D()); - CanvasItem* cn = c; + CanvasItem *cn = c; - while(cn) { + while (cn) { if (cn->has_meta("_edit_group_")) { - c=cn; + c = cn; } - cn=cn->get_parent_item(); + cn = cn->get_parent_item(); } } - Node* n = c; + Node *n = c; while ((n && n != scene && n->get_owner() != scene) || (n && !n->is_class("CanvasItem"))) { n = n->get_parent(); @@ -1530,57 +1449,50 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { if ( b.pressed ) box_selection_start( click ); #endif - additive_selection=b.mod.shift; + additive_selection = b.mod.shift; if (!_select(c, click, additive_selection)) return; - } - if (p_event.type==InputEvent::MOUSE_MOTION) { + if (p_event.type == InputEvent::MOUSE_MOTION) { if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) viewport->call_deferred("grab_focus"); - const InputEventMouseMotion &m=p_event.mouse_motion; + const InputEventMouseMotion &m = p_event.mouse_motion; if (box_selecting) { - box_selecting_to=transform.affine_inverse().xform(Point2(m.x,m.y)); + box_selecting_to = transform.affine_inverse().xform(Point2(m.x, m.y)); viewport->update(); return; - } + if (drag == DRAG_NONE) { - if (drag==DRAG_NONE) { - - - if ( (m.button_mask&BUTTON_MASK_LEFT && tool == TOOL_PAN) || m.button_mask&BUTTON_MASK_MIDDLE || (m.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) { - h_scroll->set_value( h_scroll->get_value() - m.relative_x/zoom); - v_scroll->set_value( v_scroll->get_value() - m.relative_y/zoom); + if ((m.button_mask & BUTTON_MASK_LEFT && tool == TOOL_PAN) || m.button_mask & BUTTON_MASK_MIDDLE || (m.button_mask & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) { + h_scroll->set_value(h_scroll->get_value() - m.relative_x / zoom); + v_scroll->set_value(v_scroll->get_value() - m.relative_y / zoom); } return; - } - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; - bool dragging_bone = drag==DRAG_ALL && selection.size()==1 && bone_ik_list.size(); - + bool dragging_bone = drag == DRAG_ALL && selection.size() == 1 && bone_ik_list.size(); if (!dragging_bone) { canvas_item->edit_set_state(se->undo_state); //reset state and reapply @@ -1588,23 +1500,20 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { canvas_item->cast_to()->edit_set_pivot(se->undo_pivot); } - Vector2 dfrom = drag_from; - Vector2 dto = transform.affine_inverse().xform(Point2(m.x,m.y)); + Vector2 dto = transform.affine_inverse().xform(Point2(m.x, m.y)); if (canvas_item->has_meta("_edit_lock_")) continue; - - if (drag==DRAG_ROTATE) { + if (drag == DRAG_ROTATE) { Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin(); { Node2D *node = canvas_item->cast_to(); - if (node) { real_t angle = node->get_rotation(); - node->set_rotation(snap_angle( angle + (dfrom - center).angle_to(dto-center), angle )); + node->set_rotation(snap_angle(angle + (dfrom - center).angle_to(dto - center), angle)); display_rotate_to = dto; display_rotate_from = center; viewport->update(); @@ -1614,10 +1523,9 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { { Control *node = canvas_item->cast_to(); - if (node) { real_t angle = node->get_rotation(); - node->set_rotation(snap_angle( angle + (dfrom - center).angle_to(dto-center), angle )); + node->set_rotation(snap_angle(angle + (dfrom - center).angle_to(dto - center), angle)); display_rotate_to = dto; display_rotate_from = center; viewport->update(); @@ -1627,14 +1535,13 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { continue; } - bool uniform = m.mod.shift; - bool symmetric=m.mod.alt; + bool symmetric = m.mod.alt; dto = dto - (drag == DRAG_ALL ? drag_from - drag_point_from : Vector2(0, 0)); - if(uniform && drag == DRAG_ALL) { - if(ABS(dto.x - drag_point_from.x) > ABS(dto.y - drag_point_from.y)) { + if (uniform && drag == DRAG_ALL) { + if (ABS(dto.x - drag_point_from.x) > ABS(dto.y - drag_point_from.y)) { dto.y = drag_point_from.y; } else { dto.x = drag_point_from.x; @@ -1649,128 +1556,118 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dfrom); Rect2 local_rect = canvas_item->get_item_rect(); - Vector2 begin=local_rect.pos; - Vector2 end=local_rect.pos+local_rect.size; + Vector2 begin = local_rect.pos; + Vector2 end = local_rect.pos + local_rect.size; Vector2 minsize = canvas_item->edit_get_minimum_size(); if (uniform) { float aspect = local_rect.size.aspect(); - switch(drag) { + switch (drag) { case DRAG_BOTTOM_LEFT: case DRAG_TOP_RIGHT: { if (aspect > 1.0) { // width > height, take x as reference - drag_vector.y = -drag_vector.x/aspect; + drag_vector.y = -drag_vector.x / aspect; } else { // height > width, take y as reference - drag_vector.x = -drag_vector.y*aspect; + drag_vector.x = -drag_vector.y * aspect; } } break; case DRAG_BOTTOM_RIGHT: case DRAG_TOP_LEFT: { if (aspect > 1.0) { // width > height, take x as reference - drag_vector.y = drag_vector.x/aspect; + drag_vector.y = drag_vector.x / aspect; } else { // height > width, take y as reference - drag_vector.x = drag_vector.y*aspect; + drag_vector.x = drag_vector.y * aspect; } } break; default: {} } } - switch(drag) { + switch (drag) { case DRAG_ALL: { - begin+=drag_vector; - end+=drag_vector; + begin += drag_vector; + end += drag_vector; } break; case DRAG_RIGHT: { - incend(begin.x,end.x,drag_vector.x,minsize.x,symmetric); + incend(begin.x, end.x, drag_vector.x, minsize.x, symmetric); } break; case DRAG_BOTTOM: { - incend(begin.y,end.y,drag_vector.y,minsize.y,symmetric); + incend(begin.y, end.y, drag_vector.y, minsize.y, symmetric); } break; case DRAG_BOTTOM_RIGHT: { - incend(begin.x,end.x,drag_vector.x,minsize.x,symmetric); - incend(begin.y,end.y,drag_vector.y,minsize.y,symmetric); + incend(begin.x, end.x, drag_vector.x, minsize.x, symmetric); + incend(begin.y, end.y, drag_vector.y, minsize.y, symmetric); } break; case DRAG_TOP_LEFT: { - incbeg(begin.x,end.x,drag_vector.x,minsize.x,symmetric); - incbeg(begin.y,end.y,drag_vector.y,minsize.y,symmetric); + incbeg(begin.x, end.x, drag_vector.x, minsize.x, symmetric); + incbeg(begin.y, end.y, drag_vector.y, minsize.y, symmetric); } break; case DRAG_TOP: { - incbeg(begin.y,end.y,drag_vector.y,minsize.y,symmetric); + incbeg(begin.y, end.y, drag_vector.y, minsize.y, symmetric); } break; case DRAG_LEFT: { - incbeg(begin.x,end.x,drag_vector.x,minsize.x,symmetric); + incbeg(begin.x, end.x, drag_vector.x, minsize.x, symmetric); } break; case DRAG_TOP_RIGHT: { - incbeg(begin.y,end.y,drag_vector.y,minsize.y,symmetric); - incend(begin.x,end.x,drag_vector.x,minsize.x,symmetric); + incbeg(begin.y, end.y, drag_vector.y, minsize.y, symmetric); + incend(begin.x, end.x, drag_vector.x, minsize.x, symmetric); } break; case DRAG_BOTTOM_LEFT: { - incbeg(begin.x,end.x,drag_vector.x,minsize.x,symmetric); - incend(begin.y,end.y,drag_vector.y,minsize.y,symmetric); + incbeg(begin.x, end.x, drag_vector.x, minsize.x, symmetric); + incend(begin.y, end.y, drag_vector.y, minsize.y, symmetric); } break; case DRAG_PIVOT: { if (canvas_item->cast_to()) { - Node2D *n2d =canvas_item->cast_to(); - n2d->edit_set_pivot(se->undo_pivot+drag_vector); - + Node2D *n2d = canvas_item->cast_to(); + n2d->edit_set_pivot(se->undo_pivot + drag_vector); } continue; } break; - default:{} + default: {} } - - if (!dragging_bone) { - local_rect.pos=begin; - local_rect.size=end-begin; + local_rect.pos = begin; + local_rect.size = end - begin; canvas_item->edit_set_rect(local_rect); } else { //ok, all that had to be done was done, now solve IK - - - Node2D *n2d = canvas_item->cast_to(); Transform2D final_xform = bone_orig_xform; - - if (n2d) { float total_len = 0; - for (List::Element *E=bone_ik_list.front();E;E=E->next()) { + for (List::Element *E = bone_ik_list.front(); E; E = E->next()) { if (E->prev()) - total_len+=E->get().len; + total_len += E->get().len; E->get().pos = E->get().node->get_global_transform().get_origin(); } { - final_xform.elements[2]+=dto-dfrom;//final_xform.affine_inverse().basis_xform_inv(drag_vector); + final_xform.elements[2] += dto - dfrom; //final_xform.affine_inverse().basis_xform_inv(drag_vector); //n2d->set_global_transform(final_xform); - } - CanvasItem *last = bone_ik_list.back()->get().node; if (!last) break; @@ -1783,70 +1680,64 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { //print_line("TOO FAR!"); Vector2 rel = leaf_pos - root_pos; rel = rel.normalized() * total_len; - leaf_pos=root_pos+rel; - + leaf_pos = root_pos + rel; } - bone_ik_list.front()->get().pos=leaf_pos; + bone_ik_list.front()->get().pos = leaf_pos; //print_line("BONE IK LIST "+itos(bone_ik_list.size())); + if (bone_ik_list.size() > 2) { + int solver_iterations = 64; + float solver_k = 0.3; - if (bone_ik_list.size()>2) { - int solver_iterations=64; - float solver_k=0.3; - - for(int i=0;i::Element *E=bone_ik_list.front();E;E=E->next()) { - + for (int i = 0; i < solver_iterations; i++) { + for (List::Element *E = bone_ik_list.front(); E; E = E->next()) { - if (E==bone_ik_list.back()) { + if (E == bone_ik_list.back()) { break; } float len = E->next()->get().len; - if (E->next()==bone_ik_list.back()) { + if (E->next() == bone_ik_list.back()) { //print_line("back"); Vector2 rel = E->get().pos - E->next()->get().pos; //print_line("PREV "+E->get().pos); - Vector2 desired = E->next()->get().pos+rel.normalized()*len; + Vector2 desired = E->next()->get().pos + rel.normalized() * len; //print_line("DESIRED "+desired); - E->get().pos=E->get().pos.linear_interpolate(desired,solver_k); + E->get().pos = E->get().pos.linear_interpolate(desired, solver_k); //print_line("POST "+E->get().pos); - - } else if (E==bone_ik_list.front()) { + } else if (E == bone_ik_list.front()) { //only adjust parent //print_line("front"); Vector2 rel = E->next()->get().pos - E->get().pos; //print_line("PREV "+E->next()->get().pos); - Vector2 desired = E->get().pos+rel.normalized()*len; + Vector2 desired = E->get().pos + rel.normalized() * len; //print_line("DESIRED "+desired); - E->next()->get().pos=E->next()->get().pos.linear_interpolate(desired,solver_k); + E->next()->get().pos = E->next()->get().pos.linear_interpolate(desired, solver_k); //print_line("POST "+E->next()->get().pos); } else { Vector2 rel = E->next()->get().pos - E->get().pos; - Vector2 cen = (E->next()->get().pos + E->get().pos)*0.5; - rel=rel.linear_interpolate(rel.normalized()*len,solver_k); - rel*=0.5; - E->next()->get().pos=cen+rel; - E->get().pos=cen-rel; + Vector2 cen = (E->next()->get().pos + E->get().pos) * 0.5; + rel = rel.linear_interpolate(rel.normalized() * len, solver_k); + rel *= 0.5; + E->next()->get().pos = cen + rel; + E->get().pos = cen - rel; //print_line("mid"); - } } } } } - for (List::Element *E=bone_ik_list.back();E;E=E->prev()) { + for (List::Element *E = bone_ik_list.back(); E; E = E->prev()) { Node2D *n = E->get().node; @@ -1859,90 +1750,81 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { Vector2 rel = (E->prev()->get().node->get_global_position() - n->get_global_position()).normalized(); Vector2 rel2 = (E->prev()->get().pos - E->get().pos).normalized(); float rot = rel.angle_to(rel2); - if (n->get_global_transform().basis_determinant()<0) { + if (n->get_global_transform().basis_determinant() < 0) { //mirrored, rotate the other way - rot=-rot; + rot = -rot; } n->rotate(rot); } - } - - break; } } } - if (p_event.type==InputEvent::KEY) { + if (p_event.type == InputEvent::KEY) { - const InputEventKey &k=p_event.key; + const InputEventKey &k = p_event.key; - if (k.pressed && drag==DRAG_NONE) { + if (k.pressed && drag == DRAG_NONE) { KeyMoveMODE move_mode = MOVE_VIEW_BASE; if (k.mod.alt) move_mode = MOVE_LOCAL_BASE; if (k.mod.control || k.mod.meta) move_mode = MOVE_LOCAL_WITH_ROT; - if (k.scancode==KEY_UP) - _key_move( Vector2(0,-1), k.mod.shift, move_mode ); - else if (k.scancode==KEY_DOWN) - _key_move( Vector2(0,1), k.mod.shift, move_mode ); - else if (k.scancode==KEY_LEFT) - _key_move( Vector2(-1,0), k.mod.shift, move_mode ); - else if (k.scancode==KEY_RIGHT) - _key_move( Vector2(1,0), k.mod.shift, move_mode ); - else if (k.scancode==KEY_ESCAPE) { + if (k.scancode == KEY_UP) + _key_move(Vector2(0, -1), k.mod.shift, move_mode); + else if (k.scancode == KEY_DOWN) + _key_move(Vector2(0, 1), k.mod.shift, move_mode); + else if (k.scancode == KEY_LEFT) + _key_move(Vector2(-1, 0), k.mod.shift, move_mode); + else if (k.scancode == KEY_RIGHT) + _key_move(Vector2(1, 0), k.mod.shift, move_mode); + else if (k.scancode == KEY_ESCAPE) { editor_selection->clear(); viewport->update(); - } - else + } else return; accept_event(); } - } - - - - } void CanvasItemEditor::_viewport_draw() { // TODO fetch the viewport? - Ref pivot = get_icon("EditorPivot","EditorIcons"); + Ref pivot = get_icon("EditorPivot", "EditorIcons"); _update_scrollbars(); - RID ci=viewport->get_canvas_item(); + RID ci = viewport->get_canvas_item(); if (snap_show_grid) { Size2 s = viewport->get_size(); int last_cell; Transform2D xform = transform.affine_inverse(); - if (snap_step.x!=0) { - for(int i=0;idraw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3)); - last_cell=cell; + if (snap_step.x != 0) { + for (int i = 0; i < s.width; i++) { + int cell = Math::fast_ftoi(Math::floor((xform.xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x)); + if (i == 0) + last_cell = cell; + if (last_cell != cell) + viewport->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } } - if (snap_step.y!=0) { - for(int i=0;idraw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3)); - last_cell=cell; + if (snap_step.y != 0) { + for (int i = 0; i < s.height; i++) { + int cell = Math::fast_ftoi(Math::floor((xform.xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y)); + if (i == 0) + last_cell = cell; + if (last_cell != cell) + viewport->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } } } @@ -1950,168 +1832,150 @@ void CanvasItemEditor::_viewport_draw() { if (viewport->has_focus()) { Size2 size = viewport->get_size(); if (v_scroll->is_visible_in_tree()) - size.width-=v_scroll->get_size().width; + size.width -= v_scroll->get_size().width; if (h_scroll->is_visible_in_tree()) - size.height-=h_scroll->get_size().height; + size.height -= h_scroll->get_size().height; - get_stylebox("EditorFocus","EditorStyles")->draw(ci,Rect2(Point2(),size)); + get_stylebox("EditorFocus", "EditorStyles")->draw(ci, Rect2(Point2(), size)); } - Ref lock = get_icon("Lock","EditorIcons"); - Ref group = get_icon("Group","EditorIcons"); + Ref lock = get_icon("Lock", "EditorIcons"); + Ref group = get_icon("Group", "EditorIcons"); + bool single = get_single_item() != NULL; - bool single = get_single_item()!=NULL; + Map &selection = editor_selection->get_selection(); - Map &selection = editor_selection->get_selection(); - - bool pivot_found=false; - - for(Map::Element *E=selection.front();E;E=E->next()) { + bool pivot_found = false; + for (Map::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; + Rect2 rect = canvas_item->get_item_rect(); - Rect2 rect=canvas_item->get_item_rect(); + Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); + VisualServer::get_singleton()->canvas_item_add_set_transform(ci, xform); - Transform2D xform=transform * canvas_item->get_global_transform_with_canvas(); - VisualServer::get_singleton()->canvas_item_add_set_transform(ci,xform); - - Vector2 endpoints[4]={ + Vector2 endpoints[4] = { xform.xform(rect.pos), - xform.xform(rect.pos+Vector2(rect.size.x,0)), - xform.xform(rect.pos+rect.size), - xform.xform(rect.pos+Vector2(0,rect.size.y)) + xform.xform(rect.pos + Vector2(rect.size.x, 0)), + xform.xform(rect.pos + rect.size), + xform.xform(rect.pos + Vector2(0, rect.size.y)) }; - Color c = Color(1,0.6,0.4,0.7); + Color c = Color(1, 0.6, 0.4, 0.7); - VisualServer::get_singleton()->canvas_item_add_set_transform(ci,Transform2D()); + VisualServer::get_singleton()->canvas_item_add_set_transform(ci, Transform2D()); - for(int i=0;i<4;i++) { - viewport->draw_line(endpoints[i],endpoints[(i+1)%4],c,2); + for (int i = 0; i < 4; i++) { + viewport->draw_line(endpoints[i], endpoints[(i + 1) % 4], c, 2); } - if (single && (tool==TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_ROTATE || tool==TOOL_EDIT_PIVOT)) { //kind of sucks + if (single && (tool == TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_ROTATE || tool == TOOL_EDIT_PIVOT)) { //kind of sucks if (canvas_item->cast_to()) { - if (canvas_item->cast_to()->edit_has_pivot()) { - viewport->draw_texture(pivot,xform.get_origin()+(-pivot->get_size()/2).floor()); - can_move_pivot=true; - pivot_found=true; + viewport->draw_texture(pivot, xform.get_origin() + (-pivot->get_size() / 2).floor()); + can_move_pivot = true; + pivot_found = true; } - } + if (tool == TOOL_SELECT) { - if (tool==TOOL_SELECT) { - + for (int i = 0; i < 4; i++) { - for(int i=0;i<4;i++) { - - int prev = (i+3)%4; - int next = (i+1)%4; + int prev = (i + 3) % 4; + int next = (i + 1) % 4; Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized(); - ofs*=1.4144*(select_handle->get_size().width/2); - - select_handle->draw(ci,(endpoints[i]+ofs-(select_handle->get_size()/2)).floor()); + ofs *= 1.4144 * (select_handle->get_size().width / 2); - ofs = (endpoints[i]+endpoints[next])/2; - ofs += (endpoints[next]-endpoints[i]).tangent().normalized()*(select_handle->get_size().width/2); + select_handle->draw(ci, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor()); - select_handle->draw(ci,(ofs-(select_handle->get_size()/2)).floor()); + ofs = (endpoints[i] + endpoints[next]) / 2; + ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2); + select_handle->draw(ci, (ofs - (select_handle->get_size() / 2)).floor()); } - } } - - //DRAW_EMPTY_RECT( Rect2( current_window->get_scroll()-Point2(1,1), get_size()+Size2(2,2)), Color(0.8,0.8,1.0,0.8) ); //E->get().last_rect = rect; } pivot_button->set_disabled(!pivot_found); - VisualServer::get_singleton()->canvas_item_add_set_transform(ci,Transform2D()); + VisualServer::get_singleton()->canvas_item_add_set_transform(ci, Transform2D()); + Color x_axis_color(1.0, 0.4, 0.4, 0.6); + Color y_axis_color(0.4, 1.0, 0.4, 0.6); + Color area_axis_color(0.4, 0.4, 1.0, 0.4); + Color rotate_color(0.4, 0.7, 1.0, 0.8); - - Color x_axis_color(1.0,0.4,0.4,0.6); - Color y_axis_color(0.4,1.0,0.4,0.6); - Color area_axis_color(0.4,0.4,1.0,0.4); - Color rotate_color(0.4,0.7,1.0,0.8); - - VisualServer::get_singleton()->canvas_item_add_line(ci,Point2(h_scroll->get_min(),0)+transform.get_origin(),Point2(h_scroll->get_max(),0)+transform.get_origin(),x_axis_color); - VisualServer::get_singleton()->canvas_item_add_line(ci,Point2(0,v_scroll->get_min())+transform.get_origin(),Point2(0,v_scroll->get_max())+transform.get_origin(),y_axis_color); - + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(h_scroll->get_min(), 0) + transform.get_origin(), Point2(h_scroll->get_max(), 0) + transform.get_origin(), x_axis_color); + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(0, v_scroll->get_min()) + transform.get_origin(), Point2(0, v_scroll->get_max()) + transform.get_origin(), y_axis_color); if (box_selecting) { Point2 bsfrom = transform.xform(drag_from); - Point2 bsto= transform.xform(box_selecting_to); + Point2 bsto = transform.xform(box_selecting_to); - - VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(bsfrom,bsto-bsfrom),Color(0.7,0.7,1.0,0.3)); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(bsfrom, bsto - bsfrom), Color(0.7, 0.7, 1.0, 0.3)); } - if (drag==DRAG_ROTATE) { - VisualServer::get_singleton()->canvas_item_add_line(ci,transform.xform(display_rotate_from), transform.xform(display_rotate_to),rotate_color); + if (drag == DRAG_ROTATE) { + VisualServer::get_singleton()->canvas_item_add_line(ci, transform.xform(display_rotate_from), transform.xform(display_rotate_to), rotate_color); } - Size2 screen_size = Size2( GlobalConfig::get_singleton()->get("display/window/width"), GlobalConfig::get_singleton()->get("display/window/height") ); + Size2 screen_size = Size2(GlobalConfig::get_singleton()->get("display/window/width"), GlobalConfig::get_singleton()->get("display/window/height")); - Vector2 screen_endpoints[4]= { - transform.xform(Vector2(0,0)), - transform.xform(Vector2(screen_size.width,0)), - transform.xform(Vector2(screen_size.width,screen_size.height)), - transform.xform(Vector2(0,screen_size.height)) + Vector2 screen_endpoints[4] = { + transform.xform(Vector2(0, 0)), + transform.xform(Vector2(screen_size.width, 0)), + transform.xform(Vector2(screen_size.width, screen_size.height)), + transform.xform(Vector2(0, screen_size.height)) }; - for(int i=0;i<4;i++) { - - VisualServer::get_singleton()->canvas_item_add_line(ci,screen_endpoints[i], screen_endpoints[(i+1)%4],area_axis_color); + for (int i = 0; i < 4; i++) { + VisualServer::get_singleton()->canvas_item_add_line(ci, screen_endpoints[i], screen_endpoints[(i + 1) % 4], area_axis_color); } - for(List::Element*E=lock_list.front();E;E=E->next()) { + for (List::Element *E = lock_list.front(); E; E = E->next()) { Vector2 ofs = transform.xform(E->get().pos); if (E->get().lock) { - lock->draw(ci,ofs); - ofs.x+=lock->get_width(); + lock->draw(ci, ofs); + ofs.x += lock->get_width(); } if (E->get().group) { - group->draw(ci,ofs); + group->draw(ci, ofs); } - } { - EditorNode *en = editor; - EditorPluginList *over_plugin_list = en->get_editor_plugins_over(); - - if (!over_plugin_list->empty()) { + EditorNode *en = editor; + EditorPluginList *over_plugin_list = en->get_editor_plugins_over(); - over_plugin_list->forward_draw_over_canvas(transform,viewport); + if (!over_plugin_list->empty()) { - } - } + over_plugin_list->forward_draw_over_canvas(transform, viewport); + } + } if (skeleton_show_bones) { int bone_width = EditorSettings::get_singleton()->get("editors/2d/bone_width"); @@ -2120,16 +1984,16 @@ void CanvasItemEditor::_viewport_draw() { Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2d/bone_ik_color"); Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color"); - for(Map::Element*E=bone_list.front();E;E=E->next()) { + for (Map::Element *E = bone_list.front(); E; E = E->next()) { - E->get().from=Vector2(); - E->get().to=Vector2(); + E->get().from = Vector2(); + E->get().to = Vector2(); Object *obj = ObjectDB::get_instance(E->get().bone); if (!obj) continue; - Node2D* n2d = obj->cast_to(); + Node2D *n2d = obj->cast_to(); if (!n2d) continue; @@ -2138,8 +2002,7 @@ void CanvasItemEditor::_viewport_draw() { CanvasItem *pi = n2d->get_parent_item(); - - Node2D* pn2d=n2d->get_parent()->cast_to(); + Node2D *pn2d = n2d->get_parent()->cast_to(); if (!pn2d) continue; @@ -2147,19 +2010,17 @@ void CanvasItemEditor::_viewport_draw() { Vector2 from = transform.xform(pn2d->get_global_position()); Vector2 to = transform.xform(n2d->get_global_position()); - E->get().from=from; - E->get().to=to; - - Vector2 rel = to-from; - Vector2 relt = rel.tangent().normalized()*bone_width; - + E->get().from = from; + E->get().to = to; + Vector2 rel = to - from; + Vector2 relt = rel.tangent().normalized() * bone_width; Vector bone_shape; bone_shape.push_back(from); - bone_shape.push_back(from+rel*0.2+relt); + bone_shape.push_back(from + rel * 0.2 + relt); bone_shape.push_back(to); - bone_shape.push_back(from+rel*0.2-relt); + bone_shape.push_back(from + rel * 0.2 - relt); Vector colors; if (pi->has_meta("_edit_ik_")) { @@ -2174,57 +2035,54 @@ void CanvasItemEditor::_viewport_draw() { colors.push_back(bone_color2); } - - VisualServer::get_singleton()->canvas_item_add_primitive(ci,bone_shape,colors,Vector(),RID()); + VisualServer::get_singleton()->canvas_item_add_primitive(ci, bone_shape, colors, Vector(), RID()); if (editor_selection->is_selected(pi)) { - for(int i=0;icanvas_item_add_line(ci,bone_shape[i],bone_shape[(i+1)%bone_shape.size()],bone_selected_color,2); + VisualServer::get_singleton()->canvas_item_add_line(ci, bone_shape[i], bone_shape[(i + 1) % bone_shape.size()], bone_selected_color, 2); } } - } } } void CanvasItemEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_FIXED_PROCESS) { + if (p_what == NOTIFICATION_FIXED_PROCESS) { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - bool all_control=true; - bool has_control=false; + bool all_control = true; + bool has_control = false; - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; if (canvas_item->cast_to()) - has_control=true; + has_control = true; else - all_control=false; + all_control = false; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(canvas_item); if (!se) continue; - Rect2 r=canvas_item->get_item_rect(); + Rect2 r = canvas_item->get_item_rect(); Transform2D xform = canvas_item->get_transform(); - if (r != se->prev_rect || xform!=se->prev_xform) { + if (r != se->prev_rect || xform != se->prev_xform) { viewport->update(); - se->prev_rect=r; - se->prev_xform=xform; + se->prev_rect = r; + se->prev_xform = xform; } - } bool show_anchor = all_control && has_control; @@ -2235,7 +2093,7 @@ void CanvasItemEditor::_notification(int p_what) { anchor_menu->hide(); } - for(Map::Element *E=bone_list.front();E;E=E->next()) { + for (Map::Element *E = bone_list.front(); E; E = E->next()) { Object *b = ObjectDB::get_instance(E->get().bone); if (!b) { @@ -2249,123 +2107,110 @@ void CanvasItemEditor::_notification(int p_what) { continue; } - if (b2->get_global_transform()!=E->get().xform) { + if (b2->get_global_transform() != E->get().xform) { - E->get().xform=b2->get_global_transform(); + E->get().xform = b2->get_global_transform(); viewport->update(); } } } - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - select_sb->set_texture( get_icon("EditorRect2D","EditorIcons") ); - for(int i=0;i<4;i++) { - select_sb->set_margin_size(Margin(i),4); - select_sb->set_default_margin(Margin(i),4); + select_sb->set_texture(get_icon("EditorRect2D", "EditorIcons")); + for (int i = 0; i < 4; i++) { + select_sb->set_margin_size(Margin(i), 4); + select_sb->set_default_margin(Margin(i), 4); } - select_button->set_icon( get_icon("ToolSelect","EditorIcons")); - list_select_button->set_icon( get_icon("ListSelect","EditorIcons")); - move_button->set_icon( get_icon("ToolMove","EditorIcons")); - rotate_button->set_icon( get_icon("ToolRotate","EditorIcons")); - pan_button->set_icon( get_icon("ToolPan", "EditorIcons")); - pivot_button->set_icon( get_icon("EditPivot", "EditorIcons")); - select_handle=get_icon("EditorHandle","EditorIcons"); - lock_button->set_icon(get_icon("Lock","EditorIcons")); - unlock_button->set_icon(get_icon("Unlock","EditorIcons")); - group_button->set_icon(get_icon("Group","EditorIcons")); - ungroup_button->set_icon(get_icon("Ungroup","EditorIcons")); - key_insert_button->set_icon(get_icon("Key","EditorIcons")); - + select_button->set_icon(get_icon("ToolSelect", "EditorIcons")); + list_select_button->set_icon(get_icon("ListSelect", "EditorIcons")); + move_button->set_icon(get_icon("ToolMove", "EditorIcons")); + rotate_button->set_icon(get_icon("ToolRotate", "EditorIcons")); + pan_button->set_icon(get_icon("ToolPan", "EditorIcons")); + pivot_button->set_icon(get_icon("EditPivot", "EditorIcons")); + select_handle = get_icon("EditorHandle", "EditorIcons"); + lock_button->set_icon(get_icon("Lock", "EditorIcons")); + unlock_button->set_icon(get_icon("Unlock", "EditorIcons")); + group_button->set_icon(get_icon("Group", "EditorIcons")); + ungroup_button->set_icon(get_icon("Ungroup", "EditorIcons")); + key_insert_button->set_icon(get_icon("Key", "EditorIcons")); //anchor_menu->add_icon_override("Align Top Left"); - anchor_menu->set_icon(get_icon("Anchor","EditorIcons")); - PopupMenu *p=anchor_menu->get_popup(); + anchor_menu->set_icon(get_icon("Anchor", "EditorIcons")); + PopupMenu *p = anchor_menu->get_popup(); - p->add_icon_item(get_icon("ControlAlignTopLeft","EditorIcons"),"Top Left",ANCHOR_ALIGN_TOP_LEFT); - p->add_icon_item(get_icon("ControlAlignTopRight","EditorIcons"),"Top Right",ANCHOR_ALIGN_TOP_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomRight","EditorIcons"),"Bottom Right",ANCHOR_ALIGN_BOTTOM_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomLeft","EditorIcons"),"Bottom Left",ANCHOR_ALIGN_BOTTOM_LEFT); + p->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHOR_ALIGN_TOP_LEFT); + p->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHOR_ALIGN_TOP_RIGHT); + p->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHOR_ALIGN_BOTTOM_RIGHT); + p->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHOR_ALIGN_BOTTOM_LEFT); p->add_separator(); - p->add_icon_item(get_icon("ControlAlignLeftCenter","EditorIcons"),"Center Left",ANCHOR_ALIGN_CENTER_LEFT); - p->add_icon_item(get_icon("ControlAlignTopCenter","EditorIcons"),"Center Top",ANCHOR_ALIGN_CENTER_TOP); - p->add_icon_item(get_icon("ControlAlignRightCenter","EditorIcons"),"Center Right",ANCHOR_ALIGN_CENTER_RIGHT); - p->add_icon_item(get_icon("ControlAlignBottomCenter","EditorIcons"),"Center Bottom",ANCHOR_ALIGN_CENTER_BOTTOM); - p->add_icon_item(get_icon("ControlAlignCenter","EditorIcons"),"Center",ANCHOR_ALIGN_CENTER); + p->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHOR_ALIGN_CENTER_LEFT); + p->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHOR_ALIGN_CENTER_TOP); + p->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHOR_ALIGN_CENTER_RIGHT); + p->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHOR_ALIGN_CENTER_BOTTOM); + p->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHOR_ALIGN_CENTER); p->add_separator(); - p->add_icon_item(get_icon("ControlAlignLeftWide","EditorIcons"),"Left Wide",ANCHOR_ALIGN_LEFT_WIDE); - p->add_icon_item(get_icon("ControlAlignTopWide","EditorIcons"),"Top Wide",ANCHOR_ALIGN_TOP_WIDE); - p->add_icon_item(get_icon("ControlAlignRightWide","EditorIcons"),"Right Wide",ANCHOR_ALIGN_RIGHT_WIDE); - p->add_icon_item(get_icon("ControlAlignBottomWide","EditorIcons"),"Bottom Wide",ANCHOR_ALIGN_BOTTOM_WIDE); - p->add_icon_item(get_icon("ControlVcenterWide","EditorIcons"),"VCenter Wide ",ANCHOR_ALIGN_VCENTER_WIDE); - p->add_icon_item(get_icon("ControlHcenterWide","EditorIcons"),"HCenter Wide ",ANCHOR_ALIGN_HCENTER_WIDE); + p->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHOR_ALIGN_LEFT_WIDE); + p->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHOR_ALIGN_TOP_WIDE); + p->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHOR_ALIGN_RIGHT_WIDE); + p->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHOR_ALIGN_BOTTOM_WIDE); + p->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHOR_ALIGN_VCENTER_WIDE); + p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHOR_ALIGN_HCENTER_WIDE); p->add_separator(); - p->add_icon_item(get_icon("ControlAlignWide","EditorIcons"),"Full Rect",ANCHOR_ALIGN_WIDE); + p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHOR_ALIGN_WIDE); - - AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed",this,"_keying_changed"); + AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed"); _keying_changed(); } - if (p_what==NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY) { - get_tree()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("node_removed", this, "_node_removed"); } - if (p_what==NOTIFICATION_DRAW) { - - - + if (p_what == NOTIFICATION_DRAW) { } } void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { - drag=DRAG_NONE; + drag = DRAG_NONE; - editor_selection->clear();//_clear_canvas_items(); + editor_selection->clear(); //_clear_canvas_items(); editor_selection->add_node(p_canvas_item); //_add_canvas_item(p_canvas_item); viewport->update(); - } - -void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2& r_rect, const Transform2D& p_xform) { - - +void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2 &r_rect, const Transform2D &p_xform) { if (!p_node) return; - CanvasItem *c=p_node->cast_to(); - + CanvasItem *c = p_node->cast_to(); - for (int i=p_node->get_child_count()-1;i>=0;i--) { + for (int i = p_node->get_child_count() - 1; i >= 0; i--) { //CanvasItem *r=NULL; if (c && !c->is_set_as_toplevel()) - _find_canvas_items_span(p_node->get_child(i),r_rect,p_xform * c->get_transform()); + _find_canvas_items_span(p_node->get_child(i), r_rect, p_xform * c->get_transform()); else - _find_canvas_items_span(p_node->get_child(i),r_rect,Transform2D()); + _find_canvas_items_span(p_node->get_child(i), r_rect, Transform2D()); } - - if (c && c->is_visible_in_tree()) { Rect2 rect = c->get_item_rect(); Transform2D xform = p_xform * c->get_transform(); - LockList lock; - lock.lock=c->has_meta("_edit_lock_"); - lock.group=c->has_meta("_edit_group_"); + lock.lock = c->has_meta("_edit_lock_"); + lock.group = c->has_meta("_edit_group_"); if (lock.group || lock.lock) { - lock.pos=xform.xform(rect.pos); + lock.pos = xform.xform(rect.pos); lock_list.push_back(lock); } @@ -2374,221 +2219,205 @@ void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2& r_rect, cons ObjectID id = c->get_instance_ID(); if (!bone_list.has(id)) { BoneList bone; - bone.bone=id; - bone_list[id]=bone; + bone.bone = id; + bone_list[id] = bone; } - bone_list[id].last_pass=bone_last_frame; + bone_list[id].last_pass = bone_last_frame; } - r_rect.expand_to( xform.xform(rect.pos) ); - r_rect.expand_to( xform.xform(rect.pos+Point2(rect.size.x,0)) ); - r_rect.expand_to( xform.xform(rect.pos+Point2(0,rect.size.y)) ); - r_rect.expand_to( xform.xform(rect.pos+rect.size) ); - + r_rect.expand_to(xform.xform(rect.pos)); + r_rect.expand_to(xform.xform(rect.pos + Point2(rect.size.x, 0))); + r_rect.expand_to(xform.xform(rect.pos + Point2(0, rect.size.y))); + r_rect.expand_to(xform.xform(rect.pos + rect.size)); } - } void CanvasItemEditor::_update_scrollbars() { - - updating_scroll=true; + updating_scroll = true; Size2 size = viewport->get_size(); Size2 hmin = h_scroll->get_minimum_size(); Size2 vmin = v_scroll->get_minimum_size(); - v_scroll->set_begin( Point2(size.width - vmin.width, 0) ); - v_scroll->set_end( Point2(size.width, size.height) ); - - h_scroll->set_begin( Point2( 0, size.height - hmin.height) ); - h_scroll->set_end( Point2(size.width-vmin.width, size.height) ); + v_scroll->set_begin(Point2(size.width - vmin.width, 0)); + v_scroll->set_end(Point2(size.width, size.height)); + h_scroll->set_begin(Point2(0, size.height - hmin.height)); + h_scroll->set_end(Point2(size.width - vmin.width, size.height)); - Size2 screen_rect = Size2( GlobalConfig::get_singleton()->get("display/window/width"), GlobalConfig::get_singleton()->get("display/window/height") ); + Size2 screen_rect = Size2(GlobalConfig::get_singleton()->get("display/window/width"), GlobalConfig::get_singleton()->get("display/window/height")); + Rect2 local_rect = Rect2(Point2(), viewport->get_size() - Size2(vmin.width, hmin.height)); - Rect2 local_rect = Rect2(Point2(),viewport->get_size()-Size2(vmin.width,hmin.height)); - - Rect2 canvas_item_rect=Rect2(Point2(),screen_rect); + Rect2 canvas_item_rect = Rect2(Point2(), screen_rect); lock_list.clear(); bone_last_frame++; - - if (editor->get_edited_scene()) - _find_canvas_items_span(editor->get_edited_scene(),canvas_item_rect,Transform2D()); + _find_canvas_items_span(editor->get_edited_scene(), canvas_item_rect, Transform2D()); - List::Element*> bone_to_erase; + List::Element *> bone_to_erase; - for(Map::Element*E=bone_list.front();E;E=E->next()) { + for (Map::Element *E = bone_list.front(); E; E = E->next()) { - if (E->get().last_pass!=bone_last_frame) { + if (E->get().last_pass != bone_last_frame) { bone_to_erase.push_back(E); } } - while(bone_to_erase.size()) { + while (bone_to_erase.size()) { bone_list.erase(bone_to_erase.front()->get()); bone_to_erase.pop_front(); } //expand area so it's easier to do animations and stuff at 0,0 - canvas_item_rect.size+=screen_rect*2; - canvas_item_rect.pos-=screen_rect; + canvas_item_rect.size += screen_rect * 2; + canvas_item_rect.pos -= screen_rect; Point2 ofs; - - if (canvas_item_rect.size.height <= (local_rect.size.y/zoom)) { + if (canvas_item_rect.size.height <= (local_rect.size.y / zoom)) { v_scroll->hide(); - ofs.y=canvas_item_rect.pos.y; + ofs.y = canvas_item_rect.pos.y; } else { v_scroll->show(); v_scroll->set_min(canvas_item_rect.pos.y); - v_scroll->set_max(canvas_item_rect.pos.y+canvas_item_rect.size.y); - v_scroll->set_page(local_rect.size.y/zoom); + v_scroll->set_max(canvas_item_rect.pos.y + canvas_item_rect.size.y); + v_scroll->set_page(local_rect.size.y / zoom); if (first_update) { //so 0,0 is visible v_scroll->set_value(-10); h_scroll->set_value(-10); - first_update=false; - + first_update = false; } - ofs.y=v_scroll->get_value(); + ofs.y = v_scroll->get_value(); } - if (canvas_item_rect.size.width <= (local_rect.size.x/zoom)) { + if (canvas_item_rect.size.width <= (local_rect.size.x / zoom)) { h_scroll->hide(); - ofs.x=canvas_item_rect.pos.x; + ofs.x = canvas_item_rect.pos.x; } else { h_scroll->show(); h_scroll->set_min(canvas_item_rect.pos.x); - h_scroll->set_max(canvas_item_rect.pos.x+canvas_item_rect.size.x); - h_scroll->set_page(local_rect.size.x/zoom); - ofs.x=h_scroll->get_value(); + h_scroll->set_max(canvas_item_rect.pos.x + canvas_item_rect.size.x); + h_scroll->set_page(local_rect.size.x / zoom); + ofs.x = h_scroll->get_value(); } //transform=Matrix32(); - transform.elements[2]=-ofs*zoom; + transform.elements[2] = -ofs * zoom; editor->get_scene_root()->set_global_canvas_transform(transform); - - updating_scroll=false; + updating_scroll = false; //transform.scale_basis(Vector2(zoom,zoom)); - - } void CanvasItemEditor::_update_scroll(float) { - if (updating_scroll) return; Point2 ofs; - ofs.x=h_scroll->get_value(); - ofs.y=v_scroll->get_value(); + ofs.x = h_scroll->get_value(); + ofs.y = v_scroll->get_value(); //current_window->set_scroll(-ofs); - transform=Transform2D(); + transform = Transform2D(); - transform.scale_basis(Size2(zoom,zoom)); - transform.elements[2]=-ofs; + transform.scale_basis(Size2(zoom, zoom)); + transform.elements[2] = -ofs; editor->get_scene_root()->set_global_canvas_transform(transform); - viewport->update(); - } -void CanvasItemEditor::_set_anchor(Control::AnchorType p_left,Control::AnchorType p_top,Control::AnchorType p_right,Control::AnchorType p_bottom) { - List &selection = editor_selection->get_selected_node_list(); +void CanvasItemEditor::_set_anchor(Control::AnchorType p_left, Control::AnchorType p_top, Control::AnchorType p_right, Control::AnchorType p_bottom) { + List &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Change Anchors")); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { Control *c = E->get()->cast_to(); - undo_redo->add_do_method(c,"set_anchor",MARGIN_LEFT,p_left); - undo_redo->add_do_method(c,"set_anchor",MARGIN_TOP,p_top); - undo_redo->add_do_method(c,"set_anchor",MARGIN_RIGHT,p_right); - undo_redo->add_do_method(c,"set_anchor",MARGIN_BOTTOM,p_bottom); - undo_redo->add_undo_method(c,"set_anchor",MARGIN_LEFT,c->get_anchor(MARGIN_LEFT)); - undo_redo->add_undo_method(c,"set_anchor",MARGIN_TOP,c->get_anchor(MARGIN_TOP)); - undo_redo->add_undo_method(c,"set_anchor",MARGIN_RIGHT,c->get_anchor(MARGIN_RIGHT)); - undo_redo->add_undo_method(c,"set_anchor",MARGIN_BOTTOM,c->get_anchor(MARGIN_BOTTOM)); + undo_redo->add_do_method(c, "set_anchor", MARGIN_LEFT, p_left); + undo_redo->add_do_method(c, "set_anchor", MARGIN_TOP, p_top); + undo_redo->add_do_method(c, "set_anchor", MARGIN_RIGHT, p_right); + undo_redo->add_do_method(c, "set_anchor", MARGIN_BOTTOM, p_bottom); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT)); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_TOP, c->get_anchor(MARGIN_TOP)); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_RIGHT, c->get_anchor(MARGIN_RIGHT)); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_BOTTOM, c->get_anchor(MARGIN_BOTTOM)); } undo_redo->commit_action(); - } void CanvasItemEditor::_popup_callback(int p_op) { - last_option=MenuOption(p_op); - switch(p_op) { + last_option = MenuOption(p_op); + switch (p_op) { case SNAP_USE: { snap_grid = !snap_grid; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE); - edit_menu->get_popup()->set_item_checked(idx,snap_grid); + edit_menu->get_popup()->set_item_checked(idx, snap_grid); } break; case SNAP_SHOW_GRID: { snap_show_grid = !snap_show_grid; int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID); - edit_menu->get_popup()->set_item_checked(idx,snap_show_grid); + edit_menu->get_popup()->set_item_checked(idx, snap_show_grid); viewport->update(); } break; case SNAP_USE_ROTATION: { snap_rotation = !snap_rotation; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION); - edit_menu->get_popup()->set_item_checked(idx,snap_rotation); + edit_menu->get_popup()->set_item_checked(idx, snap_rotation); } break; case SNAP_RELATIVE: { snap_relative = !snap_relative; int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE); - edit_menu->get_popup()->set_item_checked(idx,snap_relative); + edit_menu->get_popup()->set_item_checked(idx, snap_relative); } break; case SNAP_USE_PIXEL: { snap_pixel = !snap_pixel; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL); - edit_menu->get_popup()->set_item_checked(idx,snap_pixel); + edit_menu->get_popup()->set_item_checked(idx, snap_pixel); } break; case SNAP_CONFIGURE: { ((SnapDialog *)snap_dialog)->set_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step); - snap_dialog->popup_centered(Size2(220,160)); + snap_dialog->popup_centered(Size2(220, 160)); } break; case SKELETON_SHOW_BONES: { skeleton_show_bones = !skeleton_show_bones; int idx = skeleton_menu->get_item_index(SKELETON_SHOW_BONES); - skeleton_menu->set_item_checked(idx,skeleton_show_bones); + skeleton_menu->set_item_checked(idx, skeleton_show_bones); viewport->update(); } break; case ZOOM_IN: { - if (zoom>MAX_ZOOM) + if (zoom > MAX_ZOOM) return; - zoom=zoom*(1.0/0.5); + zoom = zoom * (1.0 / 0.5); _update_scroll(0); viewport->update(); return; } break; case ZOOM_OUT: { - if (zoomupdate(); return; @@ -2596,7 +2425,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case ZOOM_RESET: { - zoom=1; + zoom = 1; _update_scroll(0); viewport->update(); return; @@ -2604,51 +2433,49 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case ZOOM_SET: { - updating_value_dialog=true; + updating_value_dialog = true; dialog_label->set_text(TTR("Zoom (%):")); dialog_val->set_min(0.1); dialog_val->set_step(0.1); dialog_val->set_max(800); - dialog_val->set_value(zoom*100); - value_dialog->popup_centered(Size2(200,85)); - updating_value_dialog=false; - + dialog_val->set_value(zoom * 100); + value_dialog->popup_centered(Size2(200, 85)); + updating_value_dialog = false; } break; case LOCK_SELECTED: { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - canvas_item->set_meta("_edit_lock_",true); + canvas_item->set_meta("_edit_lock_", true); emit_signal("item_lock_status_changed"); } viewport->update(); } break; case UNLOCK_SELECTED: { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - - canvas_item->set_meta("_edit_lock_",Variant()); + canvas_item->set_meta("_edit_lock_", Variant()); emit_signal("item_lock_status_changed"); } @@ -2657,36 +2484,36 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case GROUP_SELECTED: { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - canvas_item->set_meta("_edit_group_",true); + canvas_item->set_meta("_edit_group_", true); emit_signal("item_group_status_changed"); } viewport->update(); } break; case UNGROUP_SELECTED: { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - canvas_item->set_meta("_edit_group_",Variant()); + canvas_item->set_meta("_edit_group_", Variant()); emit_signal("item_group_status_changed"); } @@ -2696,23 +2523,21 @@ void CanvasItemEditor::_popup_callback(int p_op) { case EXPAND_TO_PARENT: { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - Control *c = canvas_item->cast_to(); if (!c) continue; c->set_area_as_parent_rect(); - } viewport->update(); @@ -2763,114 +2588,111 @@ void CanvasItemEditor::_popup_callback(int p_op) { //space_selected_items< proj_vector2_y, compare_items_y >(); } break; case ANCHOR_ALIGN_TOP_LEFT: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_BEGIN,ANCHOR_BEGIN,ANCHOR_BEGIN); + _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN); } break; case ANCHOR_ALIGN_TOP_RIGHT: { - _set_anchor(ANCHOR_END,ANCHOR_BEGIN,ANCHOR_END,ANCHOR_BEGIN); + _set_anchor(ANCHOR_END, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_BEGIN); } break; case ANCHOR_ALIGN_BOTTOM_LEFT: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_END,ANCHOR_BEGIN,ANCHOR_END); + _set_anchor(ANCHOR_BEGIN, ANCHOR_END, ANCHOR_BEGIN, ANCHOR_END); } break; case ANCHOR_ALIGN_BOTTOM_RIGHT: { - _set_anchor(ANCHOR_END,ANCHOR_END,ANCHOR_END,ANCHOR_END); + _set_anchor(ANCHOR_END, ANCHOR_END, ANCHOR_END, ANCHOR_END); } break; case ANCHOR_ALIGN_CENTER_LEFT: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_CENTER,ANCHOR_BEGIN,ANCHOR_CENTER); + _set_anchor(ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_BEGIN, ANCHOR_CENTER); } break; case ANCHOR_ALIGN_CENTER_RIGHT: { - _set_anchor(ANCHOR_END,ANCHOR_CENTER,ANCHOR_END,ANCHOR_CENTER); + _set_anchor(ANCHOR_END, ANCHOR_CENTER, ANCHOR_END, ANCHOR_CENTER); } break; case ANCHOR_ALIGN_CENTER_TOP: { - _set_anchor(ANCHOR_CENTER,ANCHOR_BEGIN,ANCHOR_CENTER,ANCHOR_BEGIN); + _set_anchor(ANCHOR_CENTER, ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_BEGIN); } break; case ANCHOR_ALIGN_CENTER_BOTTOM: { - _set_anchor(ANCHOR_CENTER,ANCHOR_END,ANCHOR_CENTER,ANCHOR_END); + _set_anchor(ANCHOR_CENTER, ANCHOR_END, ANCHOR_CENTER, ANCHOR_END); } break; case ANCHOR_ALIGN_CENTER: { - _set_anchor(ANCHOR_CENTER,ANCHOR_CENTER,ANCHOR_CENTER,ANCHOR_CENTER); + _set_anchor(ANCHOR_CENTER, ANCHOR_CENTER, ANCHOR_CENTER, ANCHOR_CENTER); } break; case ANCHOR_ALIGN_TOP_WIDE: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_BEGIN,ANCHOR_END,ANCHOR_BEGIN); + _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_BEGIN); } break; case ANCHOR_ALIGN_LEFT_WIDE: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_BEGIN,ANCHOR_BEGIN,ANCHOR_END); + _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_END); } break; case ANCHOR_ALIGN_RIGHT_WIDE: { - _set_anchor(ANCHOR_END,ANCHOR_BEGIN,ANCHOR_END,ANCHOR_END); + _set_anchor(ANCHOR_END, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_END); } break; case ANCHOR_ALIGN_BOTTOM_WIDE: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_END,ANCHOR_END,ANCHOR_END); + _set_anchor(ANCHOR_BEGIN, ANCHOR_END, ANCHOR_END, ANCHOR_END); } break; case ANCHOR_ALIGN_VCENTER_WIDE: { - _set_anchor(ANCHOR_CENTER,ANCHOR_BEGIN,ANCHOR_CENTER,ANCHOR_END); + _set_anchor(ANCHOR_CENTER, ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_END); } break; case ANCHOR_ALIGN_HCENTER_WIDE: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_CENTER,ANCHOR_END,ANCHOR_CENTER); + _set_anchor(ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_END, ANCHOR_CENTER); } break; case ANCHOR_ALIGN_WIDE: { - _set_anchor(ANCHOR_BEGIN,ANCHOR_BEGIN,ANCHOR_END,ANCHOR_END); + _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_END); } break; case ANIM_INSERT_KEY: case ANIM_INSERT_KEY_EXISTING: { - bool existing = p_op==ANIM_INSERT_KEY_EXISTING; + bool existing = p_op == ANIM_INSERT_KEY_EXISTING; - Map &selection = editor_selection->get_selection(); + Map &selection = editor_selection->get_selection(); - for(Map::Element *E=selection.front();E;E=E->next()) { + for (Map::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; if (canvas_item->cast_to()) { Node2D *n2d = canvas_item->cast_to(); if (key_pos) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d,"transform/pos",n2d->get_position(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "transform/pos", n2d->get_position(), existing); if (key_rot) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d,"transform/rot",Math::rad2deg(n2d->get_rotation()),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "transform/rot", Math::rad2deg(n2d->get_rotation()), existing); if (key_scale) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d,"transform/scale",n2d->get_scale(),existing); - + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "transform/scale", n2d->get_scale(), existing); if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) { //look for an IK chain - List ik_chain; + List ik_chain; Node2D *n = n2d->get_parent_item()->cast_to(); - bool has_chain=false; + bool has_chain = false; - while(n) { + while (n) { ik_chain.push_back(n); if (n->has_meta("_edit_ik_")) { - has_chain=true; + has_chain = true; break; } if (!n->get_parent_item()) break; - n=n->get_parent_item()->cast_to(); + n = n->get_parent_item()->cast_to(); } if (has_chain && ik_chain.size()) { - for(List::Element *F=ik_chain.front();F;F=F->next()) { + for (List::Element *F = ik_chain.front(); F; F = F->next()) { if (key_pos) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(),"transform/pos",F->get()->get_position(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "transform/pos", F->get()->get_position(), existing); if (key_rot) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(),"transform/rot",Math::rad2deg(F->get()->get_rotation()),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "transform/rot", Math::rad2deg(F->get()->get_rotation()), existing); if (key_scale) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(),"transform/scale",F->get()->get_scale(),existing); - - + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "transform/scale", F->get()->get_scale(), existing); } } } @@ -2880,11 +2702,10 @@ void CanvasItemEditor::_popup_callback(int p_op) { Control *ctrl = canvas_item->cast_to(); if (key_pos) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/pos",ctrl->get_pos(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect/pos", ctrl->get_pos(), existing); if (key_scale) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size(),existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect/size", ctrl->get_size(), existing); } - } } break; @@ -2900,7 +2721,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { key_scale = key_scale_button->is_pressed(); } break; - /* + /* case ANIM_INSERT_POS_ROT case ANIM_INSERT_POS_SCALE: case ANIM_INSERT_ROT_SCALE: @@ -2929,32 +2750,29 @@ void CanvasItemEditor::_popup_callback(int p_op) { pose_clipboard.clear(); + Map &selection = editor_selection->get_selection(); - Map &selection = editor_selection->get_selection(); - - for(Map::Element *E=selection.front();E;E=E->next()) { + for (Map::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - if (canvas_item->cast_to()) { Node2D *n2d = canvas_item->cast_to(); PoseClipboard pc; - pc.pos=n2d->get_position(); - pc.rot=n2d->get_rotation(); - pc.scale=n2d->get_scale(); - pc.id=n2d->get_instance_ID(); + pc.pos = n2d->get_position(); + pc.rot = n2d->get_rotation(); + pc.scale = n2d->get_scale(); + pc.id = n2d->get_instance_ID(); pose_clipboard.push_back(pc); } } - } break; case ANIM_PASTE_POSE: { @@ -2962,7 +2780,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { break; undo_redo->create_action(TTR("Paste Pose")); - for (List::Element *E=pose_clipboard.front();E;E=E->next()) { + for (List::Element *E = pose_clipboard.front(); E; E = E->next()) { Object *o = ObjectDB::get_instance(E->get().id); if (!o) @@ -2970,27 +2788,27 @@ void CanvasItemEditor::_popup_callback(int p_op) { Node2D *n2d = o->cast_to(); if (!n2d) continue; - undo_redo->add_do_method(n2d,"set_pos",E->get().pos); - undo_redo->add_do_method(n2d,"set_rot",E->get().rot); - undo_redo->add_do_method(n2d,"set_scale",E->get().scale); - undo_redo->add_undo_method(n2d,"set_pos",n2d->get_position()); - undo_redo->add_undo_method(n2d,"set_rot",n2d->get_rotation()); - undo_redo->add_undo_method(n2d,"set_scale",n2d->get_scale()); + undo_redo->add_do_method(n2d, "set_pos", E->get().pos); + undo_redo->add_do_method(n2d, "set_rot", E->get().rot); + undo_redo->add_do_method(n2d, "set_scale", E->get().scale); + undo_redo->add_undo_method(n2d, "set_pos", n2d->get_position()); + undo_redo->add_undo_method(n2d, "set_rot", n2d->get_rotation()); + undo_redo->add_undo_method(n2d, "set_scale", n2d->get_scale()); } undo_redo->commit_action(); } break; case ANIM_CLEAR_POSE: { - Map &selection = editor_selection->get_selection(); + Map &selection = editor_selection->get_selection(); - for(Map::Element *E=selection.front();E;E=E->next()) { + for (Map::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; if (canvas_item->cast_to()) { @@ -3001,7 +2819,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (key_rot) n2d->set_rotation(0); if (key_scale) - n2d->set_scale(Vector2(1,1)); + n2d->set_scale(Vector2(1, 1)); } else if (canvas_item->cast_to()) { Control *ctrl = canvas_item->cast_to(); @@ -3013,10 +2831,8 @@ void CanvasItemEditor::_popup_callback(int p_op) { AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size()); */ } - } - } break; case VIEW_CENTER_TO_SELECTION: case VIEW_FRAME_TO_SELECTION: { @@ -3026,11 +2842,9 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case SKELETON_MAKE_BONES: { + Map &selection = editor_selection->get_selection(); - - Map &selection = editor_selection->get_selection(); - - for(Map::Element *E=selection.front();E;E=E->next()) { + for (Map::Element *E = selection.front(); E; E = E->next()) { Node2D *n2d = E->key()->cast_to(); if (!n2d) @@ -3040,19 +2854,18 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (!n2d->get_parent_item()) continue; - n2d->set_meta("_edit_bone_",true); + n2d->set_meta("_edit_bone_", true); if (!skeleton_show_bones) skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES)); - } viewport->update(); } break; case SKELETON_CLEAR_BONES: { - Map &selection = editor_selection->get_selection(); + Map &selection = editor_selection->get_selection(); - for(Map::Element *E=selection.front();E;E=E->next()) { + for (Map::Element *E = selection.front(); E; E = E->next()) { Node2D *n2d = E->key()->cast_to(); if (!n2d) @@ -3060,31 +2873,29 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (!n2d->is_visible_in_tree()) continue; - n2d->set_meta("_edit_bone_",Variant()); + n2d->set_meta("_edit_bone_", Variant()); if (!skeleton_show_bones) skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES)); - } viewport->update(); } break; case SKELETON_SET_IK_CHAIN: { - List &selection = editor_selection->get_selected_node_list(); + List &selection = editor_selection->get_selected_node_list(); - for(List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); if (!canvas_item || !canvas_item->is_visible_in_tree()) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - canvas_item->set_meta("_edit_ik_",true); + canvas_item->set_meta("_edit_ik_", true); if (!skeleton_show_bones) skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES)); - } viewport->update(); @@ -3092,9 +2903,9 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case SKELETON_CLEAR_IK_CHAIN: { - Map &selection = editor_selection->get_selection(); + Map &selection = editor_selection->get_selection(); - for(Map::Element *E=selection.front();E;E=E->next()) { + for (Map::Element *E = selection.front(); E; E = E->next()) { CanvasItem *n2d = E->key()->cast_to(); if (!n2d) @@ -3102,15 +2913,13 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (!n2d->is_visible_in_tree()) continue; - n2d->set_meta("_edit_ik_",Variant()); + n2d->set_meta("_edit_ik_", Variant()); if (!skeleton_show_bones) skeleton_menu->activate_item(skeleton_menu->get_item_index(SKELETON_SHOW_BONES)); - } viewport->update(); } break; - } } #if 0 @@ -3142,20 +2951,18 @@ template< class P, class C > void CanvasItemEditor::space_selected_items() { } #endif - void CanvasItemEditor::_focus_selection(int p_op) { Vector2 center(0.f, 0.f); Rect2 rect; int count = 0; - Map &selection = editor_selection->get_selection(); - for(Map::Element *E=selection.front();E;E=E->next()) { + Map &selection = editor_selection->get_selection(); + for (Map::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); if (!canvas_item) continue; - if (canvas_item->get_viewport()!=EditorNode::get_singleton()->get_scene_root()) + if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - // counting invisible items, for now //if (!canvas_item->is_visible_in_tree()) continue; ++count; @@ -3166,30 +2973,30 @@ void CanvasItemEditor::_focus_selection(int p_op) { Vector2 scale = canvas_item->get_global_transform().get_scale(); real_t angle = canvas_item->get_global_transform().get_rotation(); - Transform2D t(angle, Vector2(0.f,0.f)); + Transform2D t(angle, Vector2(0.f, 0.f)); item_rect = t.xform(item_rect); - Rect2 canvas_item_rect(pos + scale*item_rect.pos, scale*item_rect.size); + Rect2 canvas_item_rect(pos + scale * item_rect.pos, scale * item_rect.size); if (count == 1) { rect = canvas_item_rect; } else { rect = rect.merge(canvas_item_rect); } }; - if (count==0) return; + if (count == 0) return; if (p_op == VIEW_CENTER_TO_SELECTION) { - center = rect.pos + rect.size/2; - Vector2 offset = viewport->get_size()/2 - editor->get_scene_root()->get_global_canvas_transform().xform(center); - h_scroll->set_value(h_scroll->get_value() - offset.x/zoom); - v_scroll->set_value(v_scroll->get_value() - offset.y/zoom); + center = rect.pos + rect.size / 2; + Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center); + h_scroll->set_value(h_scroll->get_value() - offset.x / zoom); + v_scroll->set_value(v_scroll->get_value() - offset.y / zoom); } else { // VIEW_FRAME_TO_SELECTION if (rect.size.x > CMP_EPSILON && rect.size.y > CMP_EPSILON) { - float scale_x = viewport->get_size().x/rect.size.x; - float scale_y = viewport->get_size().y/rect.size.y; - zoom = scale_x < scale_y? scale_x:scale_y; + float scale_x = viewport->get_size().x / rect.size.x; + float scale_y = viewport->get_size().y / rect.size.y; + zoom = scale_x < scale_y ? scale_x : scale_y; zoom *= 0.90; _update_scroll(0); call_deferred("_popup_callback", VIEW_CENTER_TO_SELECTION); @@ -3197,27 +3004,25 @@ void CanvasItemEditor::_focus_selection(int p_op) { } } - void CanvasItemEditor::_bind_methods() { - ClassDB::bind_method("_node_removed",&CanvasItemEditor::_node_removed); - ClassDB::bind_method("_update_scroll",&CanvasItemEditor::_update_scroll); - ClassDB::bind_method("_popup_callback",&CanvasItemEditor::_popup_callback); - ClassDB::bind_method("_visibility_changed",&CanvasItemEditor::_visibility_changed); - ClassDB::bind_method("_dialog_value_changed",&CanvasItemEditor::_dialog_value_changed); - ClassDB::bind_method("_get_editor_data",&CanvasItemEditor::_get_editor_data); - ClassDB::bind_method("_tool_select",&CanvasItemEditor::_tool_select); - ClassDB::bind_method("_keying_changed",&CanvasItemEditor::_keying_changed); - ClassDB::bind_method("_unhandled_key_input",&CanvasItemEditor::_unhandled_key_input); - ClassDB::bind_method("_viewport_draw",&CanvasItemEditor::_viewport_draw); - ClassDB::bind_method("_viewport_gui_input",&CanvasItemEditor::_viewport_gui_input); - ClassDB::bind_method("_snap_changed",&CanvasItemEditor::_snap_changed); - ClassDB::bind_method(D_METHOD("_selection_result_pressed"),&CanvasItemEditor::_selection_result_pressed); - ClassDB::bind_method(D_METHOD("_selection_menu_hide"),&CanvasItemEditor::_selection_menu_hide); - - ADD_SIGNAL( MethodInfo("item_lock_status_changed") ); - ADD_SIGNAL( MethodInfo("item_group_status_changed") ); - + ClassDB::bind_method("_node_removed", &CanvasItemEditor::_node_removed); + ClassDB::bind_method("_update_scroll", &CanvasItemEditor::_update_scroll); + ClassDB::bind_method("_popup_callback", &CanvasItemEditor::_popup_callback); + ClassDB::bind_method("_visibility_changed", &CanvasItemEditor::_visibility_changed); + ClassDB::bind_method("_dialog_value_changed", &CanvasItemEditor::_dialog_value_changed); + ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data); + ClassDB::bind_method("_tool_select", &CanvasItemEditor::_tool_select); + ClassDB::bind_method("_keying_changed", &CanvasItemEditor::_keying_changed); + ClassDB::bind_method("_unhandled_key_input", &CanvasItemEditor::_unhandled_key_input); + ClassDB::bind_method("_viewport_draw", &CanvasItemEditor::_viewport_draw); + ClassDB::bind_method("_viewport_gui_input", &CanvasItemEditor::_viewport_gui_input); + ClassDB::bind_method("_snap_changed", &CanvasItemEditor::_snap_changed); + ClassDB::bind_method(D_METHOD("_selection_result_pressed"), &CanvasItemEditor::_selection_result_pressed); + ClassDB::bind_method(D_METHOD("_selection_menu_hide"), &CanvasItemEditor::_selection_menu_hide); + + ADD_SIGNAL(MethodInfo("item_lock_status_changed")); + ADD_SIGNAL(MethodInfo("item_group_status_changed")); } #if 0 @@ -3303,142 +3108,135 @@ VSplitContainer *CanvasItemEditor::get_bottom_split() { return bottom_split; } - void CanvasItemEditor::focus_selection() { _focus_selection(VIEW_CENTER_TO_SELECTION); } - CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { tool = TOOL_SELECT; - undo_redo=p_editor->get_undo_redo(); - editor=p_editor; - editor_selection=p_editor->get_editor_selection(); + undo_redo = p_editor->get_undo_redo(); + editor = p_editor; + editor_selection = p_editor->get_editor_selection(); editor_selection->add_editor_plugin(this); - editor_selection->connect("selection_changed",this,"update"); + editor_selection->connect("selection_changed", this, "update"); - - hb = memnew( HBoxContainer ); - add_child( hb ); + hb = memnew(HBoxContainer); + add_child(hb); hb->set_area_as_parent_rect(); - bottom_split = memnew( VSplitContainer ); + bottom_split = memnew(VSplitContainer); bottom_split->set_v_size_flags(SIZE_EXPAND_FILL); add_child(bottom_split); - palette_split = memnew( HSplitContainer); + palette_split = memnew(HSplitContainer); palette_split->set_v_size_flags(SIZE_EXPAND_FILL); bottom_split->add_child(palette_split); - Control *vp_base = memnew (Control); + Control *vp_base = memnew(Control); vp_base->set_v_size_flags(SIZE_EXPAND_FILL); palette_split->add_child(vp_base); - ViewportContainer *vp = memnew (ViewportContainer); + ViewportContainer *vp = memnew(ViewportContainer); vp->set_stretch(true); vp_base->add_child(vp); vp->set_area_as_parent_rect(); vp->add_child(p_editor->get_scene_root()); - - viewport = memnew( CanvasItemEditorViewport(p_editor, this) ); + viewport = memnew(CanvasItemEditorViewport(p_editor, this)); vp_base->add_child(viewport); viewport->set_area_as_parent_rect(); viewport->set_clip_contents(true); - h_scroll = memnew( HScrollBar ); - v_scroll = memnew( VScrollBar ); + h_scroll = memnew(HScrollBar); + v_scroll = memnew(VScrollBar); viewport->add_child(h_scroll); viewport->add_child(v_scroll); - viewport->connect("draw",this,"_viewport_draw"); - viewport->connect("gui_input",this,"_viewport_gui_input"); + viewport->connect("draw", this, "_viewport_draw"); + viewport->connect("gui_input", this, "_viewport_gui_input"); - - h_scroll->connect("value_changed", this,"_update_scroll",Vector(),Object::CONNECT_DEFERRED); - v_scroll->connect("value_changed", this,"_update_scroll",Vector(),Object::CONNECT_DEFERRED); + h_scroll->connect("value_changed", this, "_update_scroll", Vector(), Object::CONNECT_DEFERRED); + v_scroll->connect("value_changed", this, "_update_scroll", Vector(), Object::CONNECT_DEFERRED); h_scroll->hide(); v_scroll->hide(); - updating_scroll=false; + updating_scroll = false; viewport->set_focus_mode(FOCUS_ALL); - handle_len=10; - first_update=true; - + handle_len = 10; + first_update = true; - select_button = memnew( ToolButton ); + select_button = memnew(ToolButton); select_button->set_toggle_mode(true); hb->add_child(select_button); - select_button->connect("pressed",this,"_tool_select",make_binds(TOOL_SELECT)); + select_button->connect("pressed", this, "_tool_select", make_binds(TOOL_SELECT)); select_button->set_pressed(true); - select_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/select_mode",TTR("Select Mode"),KEY_Q)); - select_button->set_tooltip(TTR("Select Mode")+" $sc\n"+keycode_get_string(KEY_MASK_CMD)+TTR("Drag: Rotate")+"\n"+TTR("Alt+Drag: Move")+"\n"+TTR("Press 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).")+"\n"+TTR("Alt+RMB: Depth list selection")); + select_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/select_mode", TTR("Select Mode"), KEY_Q)); + select_button->set_tooltip(TTR("Select Mode") + " $sc\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate") + "\n" + TTR("Alt+Drag: Move") + "\n" + TTR("Press 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).") + "\n" + TTR("Alt+RMB: Depth list selection")); - - move_button = memnew( ToolButton ); + move_button = memnew(ToolButton); move_button->set_toggle_mode(true); hb->add_child(move_button); - move_button->connect("pressed",this,"_tool_select",make_binds(TOOL_MOVE)); - move_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/move_mode",TTR("Move Mode"),KEY_W)); + move_button->connect("pressed", this, "_tool_select", make_binds(TOOL_MOVE)); + move_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/move_mode", TTR("Move Mode"), KEY_W)); move_button->set_tooltip(TTR("Move Mode")); - rotate_button = memnew( ToolButton ); + rotate_button = memnew(ToolButton); rotate_button->set_toggle_mode(true); hb->add_child(rotate_button); - rotate_button->connect("pressed",this,"_tool_select",make_binds(TOOL_ROTATE)); - rotate_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/rotate_mode",TTR("Rotate Mode"),KEY_E)); + rotate_button->connect("pressed", this, "_tool_select", make_binds(TOOL_ROTATE)); + rotate_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/rotate_mode", TTR("Rotate Mode"), KEY_E)); rotate_button->set_tooltip(TTR("Rotate Mode")); hb->add_child(memnew(VSeparator)); - list_select_button = memnew( ToolButton ); + list_select_button = memnew(ToolButton); list_select_button->set_toggle_mode(true); hb->add_child(list_select_button); - list_select_button->connect("pressed",this,"_tool_select",make_binds(TOOL_LIST_SELECT)); + list_select_button->connect("pressed", this, "_tool_select", make_binds(TOOL_LIST_SELECT)); list_select_button->set_tooltip(TTR("Show a list of all objects at the position clicked\n(same as Alt+RMB in select mode).")); - pivot_button = memnew( ToolButton ); + pivot_button = memnew(ToolButton); pivot_button->set_toggle_mode(true); hb->add_child(pivot_button); - pivot_button->connect("pressed",this,"_tool_select",make_binds(TOOL_EDIT_PIVOT)); + pivot_button->connect("pressed", this, "_tool_select", make_binds(TOOL_EDIT_PIVOT)); pivot_button->set_tooltip(TTR("Click to change object's rotation pivot.")); - pan_button = memnew( ToolButton ); + pan_button = memnew(ToolButton); pan_button->set_toggle_mode(true); hb->add_child(pan_button); - pan_button->connect("pressed",this,"_tool_select",make_binds(TOOL_PAN)); + pan_button->connect("pressed", this, "_tool_select", make_binds(TOOL_PAN)); pan_button->set_tooltip(TTR("Pan Mode")); hb->add_child(memnew(VSeparator)); - lock_button = memnew( ToolButton ); + lock_button = memnew(ToolButton); hb->add_child(lock_button); - lock_button->connect("pressed",this,"_popup_callback",varray(LOCK_SELECTED)); + lock_button->connect("pressed", this, "_popup_callback", varray(LOCK_SELECTED)); lock_button->set_tooltip(TTR("Lock the selected object in place (can't be moved).")); - unlock_button = memnew( ToolButton ); + unlock_button = memnew(ToolButton); hb->add_child(unlock_button); - unlock_button->connect("pressed",this,"_popup_callback",varray(UNLOCK_SELECTED)); + unlock_button->connect("pressed", this, "_popup_callback", varray(UNLOCK_SELECTED)); unlock_button->set_tooltip(TTR("Unlock the selected object (can be moved).")); - group_button = memnew( ToolButton ); + group_button = memnew(ToolButton); hb->add_child(group_button); - group_button->connect("pressed",this,"_popup_callback",varray(GROUP_SELECTED)); + group_button->connect("pressed", this, "_popup_callback", varray(GROUP_SELECTED)); group_button->set_tooltip(TTR("Makes sure the object's children are not selectable.")); - ungroup_button = memnew( ToolButton ); + ungroup_button = memnew(ToolButton); hb->add_child(ungroup_button); - ungroup_button->connect("pressed",this,"_popup_callback",varray(UNGROUP_SELECTED)); + ungroup_button->connect("pressed", this, "_popup_callback", varray(UNGROUP_SELECTED)); ungroup_button->set_tooltip(TTR("Restores the object's children's ability to be selected.")); hb->add_child(memnew(VSeparator)); - edit_menu = memnew( MenuButton ); + edit_menu = memnew(MenuButton); edit_menu->set_text(TTR("Edit")); hb->add_child(edit_menu); - edit_menu->get_popup()->connect("id_pressed", this,"_popup_callback"); + edit_menu->get_popup()->connect("id_pressed", this, "_popup_callback"); PopupMenu *p; p = edit_menu->get_popup(); @@ -3452,19 +3250,18 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_separator(); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/expand_to_parent", TTR("Expand to Parent"), KEY_MASK_CMD | KEY_P), EXPAND_TO_PARENT); p->add_separator(); - p->add_submenu_item(TTR("Skeleton.."),"skeleton"); + p->add_submenu_item(TTR("Skeleton.."), "skeleton"); skeleton_menu = memnew(PopupMenu); p->add_child(skeleton_menu); skeleton_menu->set_name("skeleton"); - skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_make_bones", TTR("Make Bones"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B ),SKELETON_MAKE_BONES); + skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_make_bones", TTR("Make Bones"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B), SKELETON_MAKE_BONES); skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_bones", TTR("Clear Bones")), SKELETON_CLEAR_BONES); skeleton_menu->add_separator(); skeleton_menu->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_show_bones", TTR("Show Bones")), SKELETON_SHOW_BONES); skeleton_menu->add_separator(); skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_set_ik_chain", TTR("Make IK Chain")), SKELETON_SET_IK_CHAIN); skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_ik_chain", TTR("Clear IK Chain")), SKELETON_CLEAR_IK_CHAIN); - skeleton_menu->connect("id_pressed", this,"_popup_callback"); - + skeleton_menu->connect("id_pressed", this, "_popup_callback"); /* p->add_item("Align Horizontal",ALIGN_HORIZONTAL); @@ -3472,10 +3269,10 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_item("Space Horizontal",SPACE_HORIZONTAL); p->add_item("Space Vertical",SPACE_VERTICAL);*/ - view_menu = memnew( MenuButton ); + view_menu = memnew(MenuButton); view_menu->set_text(TTR("View")); hb->add_child(view_menu); - view_menu->get_popup()->connect("id_pressed", this,"_popup_callback"); + view_menu->get_popup()->connect("id_pressed", this, "_popup_callback"); p = view_menu->get_popup(); @@ -3487,123 +3284,121 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION); - anchor_menu = memnew( MenuButton ); + anchor_menu = memnew(MenuButton); anchor_menu->set_text(TTR("Anchor")); hb->add_child(anchor_menu); - anchor_menu->get_popup()->connect("id_pressed", this,"_popup_callback"); + anchor_menu->get_popup()->connect("id_pressed", this, "_popup_callback"); anchor_menu->hide(); //p = anchor_menu->get_popup(); - - - animation_hb = memnew( HBoxContainer ); + animation_hb = memnew(HBoxContainer); hb->add_child(animation_hb); - animation_hb->add_child( memnew( VSeparator )); + animation_hb->add_child(memnew(VSeparator)); animation_hb->hide(); - key_loc_button = memnew( Button("loc")); + key_loc_button = memnew(Button("loc")); key_loc_button->set_toggle_mode(true); key_loc_button->set_pressed(true); key_loc_button->set_focus_mode(FOCUS_NONE); - key_loc_button->add_color_override("font_color",Color(1,0.6,0.6)); - key_loc_button->add_color_override("font_color_pressed",Color(0.6,1,0.6)); - key_loc_button->connect("pressed",this,"_popup_callback",varray(ANIM_INSERT_POS)); + key_loc_button->add_color_override("font_color", Color(1, 0.6, 0.6)); + key_loc_button->add_color_override("font_color_pressed", Color(0.6, 1, 0.6)); + key_loc_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_POS)); animation_hb->add_child(key_loc_button); - key_rot_button = memnew( Button("rot")); + key_rot_button = memnew(Button("rot")); key_rot_button->set_toggle_mode(true); key_rot_button->set_pressed(true); key_rot_button->set_focus_mode(FOCUS_NONE); - key_rot_button->add_color_override("font_color",Color(1,0.6,0.6)); - key_rot_button->add_color_override("font_color_pressed",Color(0.6,1,0.6)); - key_rot_button->connect("pressed",this,"_popup_callback",varray(ANIM_INSERT_ROT)); + key_rot_button->add_color_override("font_color", Color(1, 0.6, 0.6)); + key_rot_button->add_color_override("font_color_pressed", Color(0.6, 1, 0.6)); + key_rot_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_ROT)); animation_hb->add_child(key_rot_button); - key_scale_button = memnew( Button("scl")); + key_scale_button = memnew(Button("scl")); key_scale_button->set_toggle_mode(true); key_scale_button->set_focus_mode(FOCUS_NONE); - key_scale_button->add_color_override("font_color",Color(1,0.6,0.6)); - key_scale_button->add_color_override("font_color_pressed",Color(0.6,1,0.6)); - key_scale_button->connect("pressed",this,"_popup_callback",varray(ANIM_INSERT_SCALE)); + key_scale_button->add_color_override("font_color", Color(1, 0.6, 0.6)); + key_scale_button->add_color_override("font_color_pressed", Color(0.6, 1, 0.6)); + key_scale_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_SCALE)); animation_hb->add_child(key_scale_button); - key_insert_button = memnew( Button ); + key_insert_button = memnew(Button); key_insert_button->set_focus_mode(FOCUS_NONE); - key_insert_button->connect("pressed",this,"_popup_callback",varray(ANIM_INSERT_KEY)); + key_insert_button->connect("pressed", this, "_popup_callback", varray(ANIM_INSERT_KEY)); key_insert_button->set_tooltip(TTR("Insert Keys")); key_insert_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key", TTR("Insert Key"), KEY_INSERT)); animation_hb->add_child(key_insert_button); - animation_menu = memnew( MenuButton ); + animation_menu = memnew(MenuButton); animation_menu->set_text(TTR("Animation")); animation_hb->add_child(animation_menu); - animation_menu->get_popup()->connect("id_pressed", this,"_popup_callback"); + animation_menu->get_popup()->connect("id_pressed", this, "_popup_callback"); p = animation_menu->get_popup(); p->add_shortcut(ED_GET_SHORTCUT("canvas_item_editor/anim_insert_key"), ANIM_INSERT_KEY); - p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key_existing_tracks", TTR("Insert Key (Existing Tracks)"), KEY_MASK_CMD+KEY_INSERT), ANIM_INSERT_KEY_EXISTING); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key_existing_tracks", TTR("Insert Key (Existing Tracks)"), KEY_MASK_CMD + KEY_INSERT), ANIM_INSERT_KEY_EXISTING); p->add_separator(); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_copy_pose", TTR("Copy Pose")), ANIM_COPY_POSE); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_paste_pose", TTR("Paste Pose")), ANIM_PASTE_POSE); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_clear_pose", TTR("Clear Pose"), KEY_MASK_SHIFT | KEY_K), ANIM_CLEAR_POSE); - snap_dialog = memnew( SnapDialog ); - snap_dialog->connect("confirmed",this,"_snap_changed"); + snap_dialog = memnew(SnapDialog); + snap_dialog->connect("confirmed", this, "_snap_changed"); add_child(snap_dialog); - value_dialog = memnew( AcceptDialog ); + value_dialog = memnew(AcceptDialog); value_dialog->set_title(TTR("Set a Value")); value_dialog->get_ok()->set_text(TTR("Close")); add_child(value_dialog); Label *l = memnew(Label); l->set_text(TTR("Snap (Pixels):")); - l->set_pos(Point2(5,5)); + l->set_pos(Point2(5, 5)); value_dialog->add_child(l); - dialog_label=l; + dialog_label = l; - dialog_val=memnew(SpinBox); - dialog_val->set_anchor(MARGIN_RIGHT,ANCHOR_END); - dialog_val->set_begin(Point2(15,25)); - dialog_val->set_end(Point2(10,25)); + dialog_val = memnew(SpinBox); + dialog_val->set_anchor(MARGIN_RIGHT, ANCHOR_END); + dialog_val->set_begin(Point2(15, 25)); + dialog_val->set_end(Point2(10, 25)); value_dialog->add_child(dialog_val); - dialog_val->connect("value_changed",this,"_dialog_value_changed"); - select_sb = Ref( memnew( StyleBoxTexture) ); + dialog_val->connect("value_changed", this, "_dialog_value_changed"); + select_sb = Ref(memnew(StyleBoxTexture)); - selection_menu = memnew( PopupMenu ); + selection_menu = memnew(PopupMenu); add_child(selection_menu); selection_menu->set_custom_minimum_size(Vector2(100, 0)); selection_menu->connect("id_pressed", this, "_selection_result_pressed"); selection_menu->connect("popup_hide", this, "_selection_menu_hide"); - key_pos=true; - key_rot=true; - key_scale=false; - - zoom=1; - snap_offset=Vector2(0, 0); - snap_step=Vector2(10, 10); - snap_rotation_offset=0; - snap_rotation_step=15 / (180 / Math_PI); - snap_grid=false; - snap_show_grid=false; - snap_rotation=false; - snap_pixel=false; - skeleton_show_bones=true; - skeleton_menu->set_item_checked(skeleton_menu->get_item_index(SKELETON_SHOW_BONES),true); - updating_value_dialog=false; - box_selecting=false; + key_pos = true; + key_rot = true; + key_scale = false; + + zoom = 1; + snap_offset = Vector2(0, 0); + snap_step = Vector2(10, 10); + snap_rotation_offset = 0; + snap_rotation_step = 15 / (180 / Math_PI); + snap_grid = false; + snap_show_grid = false; + snap_rotation = false; + snap_pixel = false; + skeleton_show_bones = true; + skeleton_menu->set_item_checked(skeleton_menu->get_item_index(SKELETON_SHOW_BONES), true); + updating_value_dialog = false; + box_selecting = false; //zoom=0.5; - singleton=this; + singleton = this; set_process_unhandled_key_input(true); - can_move_pivot=false; - drag=DRAG_NONE; - bone_last_frame=0; - additive_selection=false; + can_move_pivot = false; + drag = DRAG_NONE; + bone_last_frame = 0; + additive_selection = false; } -CanvasItemEditor *CanvasItemEditor::singleton=NULL; +CanvasItemEditor *CanvasItemEditor::singleton = NULL; void CanvasItemEditorPlugin::edit(Object *p_object) { @@ -3621,88 +3416,83 @@ void CanvasItemEditorPlugin::make_visible(bool p_visible) { if (p_visible) { canvas_item_editor->show(); canvas_item_editor->set_fixed_process(true); - VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(),false); + VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), false); canvas_item_editor->viewport->grab_focus(); } else { canvas_item_editor->hide(); canvas_item_editor->set_fixed_process(false); - VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(),true); + VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), true); } - } Dictionary CanvasItemEditorPlugin::get_state() const { return canvas_item_editor->get_state(); } -void CanvasItemEditorPlugin::set_state(const Dictionary& p_state) { +void CanvasItemEditorPlugin::set_state(const Dictionary &p_state) { canvas_item_editor->set_state(p_state); } CanvasItemEditorPlugin::CanvasItemEditorPlugin(EditorNode *p_node) { - editor=p_node; - canvas_item_editor = memnew( CanvasItemEditor(editor) ); + editor = p_node; + canvas_item_editor = memnew(CanvasItemEditor(editor)); canvas_item_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); editor->get_viewport()->add_child(canvas_item_editor); canvas_item_editor->set_area_as_parent_rect(); canvas_item_editor->hide(); - } - -CanvasItemEditorPlugin::~CanvasItemEditorPlugin() -{ +CanvasItemEditorPlugin::~CanvasItemEditorPlugin() { } - void CanvasItemEditorViewport::_on_mouse_exit() { - if (!selector->is_visible()){ + if (!selector->is_visible()) { _remove_preview(); } } -void CanvasItemEditorViewport::_on_select_type(Object* selected) { - CheckBox* check = selected->cast_to(); +void CanvasItemEditorViewport::_on_select_type(Object *selected) { + CheckBox *check = selected->cast_to(); String type = check->get_text(); - selector_label->set_text(vformat(TTR("Add %s"),type)); - label->set_text(vformat(TTR("Adding %s..."),type)); + selector_label->set_text(vformat(TTR("Add %s"), type)); + label->set_text(vformat(TTR("Adding %s..."), type)); } void CanvasItemEditorViewport::_on_change_type() { if (!button_group->get_pressed_button()) return; - CheckBox* check=button_group->get_pressed_button()->cast_to(); - default_type=check->get_text(); + CheckBox *check = button_group->get_pressed_button()->cast_to(); + default_type = check->get_text(); _perform_drop_data(); selector->hide(); } -void CanvasItemEditorViewport::_create_preview(const Vector& files) const { - label->set_pos(get_global_pos()+Point2(14,14)); - label_desc->set_pos(label->get_pos()+Point2(0,label->get_size().height)); - for (int i=0;iget_class(); - if (type=="ImageTexture" || type=="PackedScene") { - if (type=="ImageTexture") { - Ref texture=Ref ( ResourceCache::get(path)->cast_to() ); - Sprite* sprite=memnew(Sprite); +void CanvasItemEditorViewport::_create_preview(const Vector &files) const { + label->set_pos(get_global_pos() + Point2(14, 14)); + label_desc->set_pos(label->get_pos() + Point2(0, label->get_size().height)); + for (int i = 0; i < files.size(); i++) { + String path = files[i]; + RES res = ResourceLoader::load(path); + String type = res->get_class(); + if (type == "ImageTexture" || type == "PackedScene") { + if (type == "ImageTexture") { + Ref texture = Ref(ResourceCache::get(path)->cast_to()); + Sprite *sprite = memnew(Sprite); sprite->set_texture(texture); - sprite->set_modulate(Color(1,1,1,0.7f)); + sprite->set_modulate(Color(1, 1, 1, 0.7f)); preview->add_child(sprite); label->show(); label_desc->show(); - } else if (type=="PackedScene") { - Ref scn=ResourceLoader::load(path); - if (scn.is_valid()){ - Node* instance=scn->instance(); - if (instance){ + } else if (type == "PackedScene") { + Ref scn = ResourceLoader::load(path); + if (scn.is_valid()) { + Node *instance = scn->instance(); + if (instance) { preview->add_child(instance); } } @@ -3713,10 +3503,10 @@ void CanvasItemEditorViewport::_create_preview(const Vector& files) cons } void CanvasItemEditorViewport::_remove_preview() { - if (preview->get_parent()){ + if (preview->get_parent()) { editor->get_scene_root()->remove_child(preview); - for (int i=preview->get_child_count()-1;i>=0;i--){ - Node* node=preview->get_child(i); + for (int i = preview->get_child_count() - 1; i >= 0; i--) { + Node *node = preview->get_child(i); memdelete(node); } label->hide(); @@ -3724,152 +3514,159 @@ void CanvasItemEditorViewport::_remove_preview() { } } -bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node) { - if (p_desired_node->get_filename()==p_target_scene_path) { +bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) { + if (p_desired_node->get_filename() == p_target_scene_path) { return true; } - int childCount=p_desired_node->get_child_count(); - for (int i=0;iget_child(i); - if(_cyclical_dependency_exists(p_target_scene_path,child)) { + int childCount = p_desired_node->get_child_count(); + for (int i = 0; i < childCount; i++) { + Node *child = p_desired_node->get_child(i); + if (_cyclical_dependency_exists(p_target_scene_path, child)) { return true; } } return false; } -void CanvasItemEditorViewport::_create_nodes(Node* parent, Node* child, String& path, const Point2& p_point) { +void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) { child->set_name(path.get_file().get_basename()); - Ref texture=Ref ( ResourceCache::get(path)->cast_to() ); + Ref texture = Ref(ResourceCache::get(path)->cast_to()); Size2 texture_size = texture->get_size(); - editor_data->get_undo_redo().add_do_method(parent,"add_child",child); - editor_data->get_undo_redo().add_do_method(child,"set_owner",editor->get_edited_scene()); + editor_data->get_undo_redo().add_do_method(parent, "add_child", child); + editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene()); editor_data->get_undo_redo().add_do_reference(child); - editor_data->get_undo_redo().add_undo_method(parent,"remove_child",child); + editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child); - String new_name=parent->validate_child_name(child); - ScriptEditorDebugger *sed=ScriptEditor::get_singleton()->get_debugger(); - editor_data->get_undo_redo().add_do_method(sed,"live_debug_create_node",editor->get_edited_scene()->get_path_to(parent),child->get_class(),new_name); - editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(editor->get_edited_scene()->get_path_to(parent))+"/"+new_name)); + String new_name = parent->validate_child_name(child); + ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); + editor_data->get_undo_redo().add_do_method(sed, "live_debug_create_node", editor->get_edited_scene()->get_path_to(parent), child->get_class(), new_name); + editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); // handle with different property for texture String property = "texture"; List props; child->get_property_list(&props); - for(const List::Element *E=props.front();E;E=E->next() ) { - if (E->get().name=="config/texture") { // Particles2D - property="config/texture"; + for (const List::Element *E = props.front(); E; E = E->next()) { + if (E->get().name == "config/texture") { // Particles2D + property = "config/texture"; break; - } else if (E->get().name=="texture/texture") { // Polygon2D - property="texture/texture"; + } else if (E->get().name == "texture/texture") { // Polygon2D + property = "texture/texture"; break; - } else if (E->get().name=="normal") { // TouchScreenButton - property="normal"; + } else if (E->get().name == "normal") { // TouchScreenButton + property = "normal"; break; } } - editor_data->get_undo_redo().add_do_property(child,property,texture); + editor_data->get_undo_redo().add_do_property(child, property, texture); // make visible for certain node type - if (default_type=="Patch9Rect") { - editor_data->get_undo_redo().add_do_property(child,"rect/size",texture_size); - } else if (default_type=="Polygon2D") { + if (default_type == "Patch9Rect") { + editor_data->get_undo_redo().add_do_property(child, "rect/size", texture_size); + } else if (default_type == "Polygon2D") { PoolVector list; - list.push_back(Vector2(0,0)); - list.push_back(Vector2(texture_size.width,0)); - list.push_back(Vector2(texture_size.width,texture_size.height)); - list.push_back(Vector2(0,texture_size.height)); - editor_data->get_undo_redo().add_do_property(child,"polygon",list); + list.push_back(Vector2(0, 0)); + list.push_back(Vector2(texture_size.width, 0)); + list.push_back(Vector2(texture_size.width, texture_size.height)); + list.push_back(Vector2(0, texture_size.height)); + editor_data->get_undo_redo().add_do_property(child, "polygon", list); } // locate at preview position Point2 pos; if (parent->has_method("get_global_pos")) { - pos=parent->call("get_global_pos"); + pos = parent->call("get_global_pos"); } - Transform2D trans=canvas->get_canvas_transform(); - Point2 target_pos = (p_point-trans.get_origin())/trans.get_scale().x-pos; - if (default_type=="Polygon2D" || default_type=="TouchScreenButton" || default_type=="TextureRect" || default_type=="Patch9Rect") { - target_pos -= texture_size/2; + Transform2D trans = canvas->get_canvas_transform(); + Point2 target_pos = (p_point - trans.get_origin()) / trans.get_scale().x - pos; + if (default_type == "Polygon2D" || default_type == "TouchScreenButton" || default_type == "TextureRect" || default_type == "Patch9Rect") { + target_pos -= texture_size / 2; } - editor_data->get_undo_redo().add_do_method(child,"set_pos",target_pos); + editor_data->get_undo_redo().add_do_method(child, "set_pos", target_pos); } -bool CanvasItemEditorViewport::_create_instance(Node* parent, String& path, const Point2& p_point) { - Ref sdata=ResourceLoader::load(path); +bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, const Point2 &p_point) { + Ref sdata = ResourceLoader::load(path); if (!sdata.is_valid()) { // invalid scene return false; } - Node* instanced_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); + Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instanced_scene) { // error on instancing return false; } - if (editor->get_edited_scene()->get_filename()!="") { // cyclical instancing + if (editor->get_edited_scene()->get_filename() != "") { // cyclical instancing if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instanced_scene)) { memdelete(instanced_scene); return false; } } - instanced_scene->set_filename( GlobalConfig::get_singleton()->localize_path(path) ); + instanced_scene->set_filename(GlobalConfig::get_singleton()->localize_path(path)); - editor_data->get_undo_redo().add_do_method(parent,"add_child",instanced_scene); - editor_data->get_undo_redo().add_do_method(instanced_scene,"set_owner",editor->get_edited_scene()); + editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene); + editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", editor->get_edited_scene()); editor_data->get_undo_redo().add_do_reference(instanced_scene); - editor_data->get_undo_redo().add_undo_method(parent,"remove_child",instanced_scene); + editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instanced_scene); - String new_name=parent->validate_child_name(instanced_scene); - ScriptEditorDebugger *sed=ScriptEditor::get_singleton()->get_debugger(); - editor_data->get_undo_redo().add_do_method(sed,"live_debug_instance_node",editor->get_edited_scene()->get_path_to(parent),path,new_name); - editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(editor->get_edited_scene()->get_path_to(parent))+"/"+new_name)); + String new_name = parent->validate_child_name(instanced_scene); + ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); + editor_data->get_undo_redo().add_do_method(sed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name); + editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); Point2 pos; - Node2D* parent_node2d=parent->cast_to(); + Node2D *parent_node2d = parent->cast_to(); if (parent_node2d) { - pos=parent_node2d->get_global_position(); + pos = parent_node2d->get_global_position(); } else { - Control* parent_control=parent->cast_to(); + Control *parent_control = parent->cast_to(); if (parent_control) { - pos=parent_control->get_global_pos(); + pos = parent_control->get_global_pos(); } } - Transform2D trans=canvas->get_canvas_transform(); - editor_data->get_undo_redo().add_do_method(instanced_scene,"set_pos",(p_point-trans.get_origin())/trans.get_scale().x-pos); + Transform2D trans = canvas->get_canvas_transform(); + editor_data->get_undo_redo().add_do_method(instanced_scene, "set_pos", (p_point - trans.get_origin()) / trans.get_scale().x - pos); return true; } -void CanvasItemEditorViewport::_perform_drop_data(){ +void CanvasItemEditorViewport::_perform_drop_data() { _remove_preview(); Vector error_files; editor_data->get_undo_redo().create_action(TTR("Create Node")); - for (int i=0;iget_class(); - if (type=="ImageTexture") { - Node* child; - if (default_type=="Light2D") child=memnew(Light2D); - else if (default_type=="Particles2D") child=memnew(Particles2D); - else if (default_type=="Polygon2D") child=memnew(Polygon2D); - else if (default_type=="TouchScreenButton") child=memnew(TouchScreenButton); - else if (default_type=="TextureRect") child=memnew(TextureRect); - else if (default_type=="Patch9Rect") child=memnew(NinePatchRect); - else child=memnew(Sprite); // default + String type = res->get_class(); + if (type == "ImageTexture") { + Node *child; + if (default_type == "Light2D") + child = memnew(Light2D); + else if (default_type == "Particles2D") + child = memnew(Particles2D); + else if (default_type == "Polygon2D") + child = memnew(Polygon2D); + else if (default_type == "TouchScreenButton") + child = memnew(TouchScreenButton); + else if (default_type == "TextureRect") + child = memnew(TextureRect); + else if (default_type == "Patch9Rect") + child = memnew(NinePatchRect); + else + child = memnew(Sprite); // default _create_nodes(target_node, child, path, drop_pos); - } else if (type=="PackedScene") { - bool success=_create_instance(target_node, path, drop_pos); + } else if (type == "PackedScene") { + bool success = _create_instance(target_node, path, drop_pos); if (!success) { error_files.push_back(path); } @@ -3878,48 +3675,48 @@ void CanvasItemEditorViewport::_perform_drop_data(){ editor_data->get_undo_redo().commit_action(); - if (error_files.size()>0) { + if (error_files.size() > 0) { String files_str; - for (int i=0;iget_ok()->set_text(TTR("Ugh")); - accept->set_text(vformat(TTR("Error instancing scene from %s"),files_str.c_str())); + accept->set_text(vformat(TTR("Error instancing scene from %s"), files_str.c_str())); accept->popup_centered_minsize(); } } -bool CanvasItemEditorViewport::can_drop_data(const Point2& p_point,const Variant& p_data) const { - Dictionary d=p_data; +bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Variant &p_data) const { + Dictionary d = p_data; if (d.has("type")) { - if (String(d["type"])=="files") { - Vector files=d["files"]; - bool can_instance=false; - for (int i=0;i files = d["files"]; + bool can_instance = false; + for (int i = 0; i < files.size(); i++) { // check if dragged files contain resource or scene can be created at least one + RES res = ResourceLoader::load(files[i]); if (res.is_null()) { continue; } - String type=res->get_class(); - if (type=="PackedScene") { - Ref sdata=ResourceLoader::load(files[i]); - Node* instanced_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); + String type = res->get_class(); + if (type == "PackedScene") { + Ref sdata = ResourceLoader::load(files[i]); + Node *instanced_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instanced_scene) { continue; } memdelete(instanced_scene); } - can_instance=true; + can_instance = true; break; } if (can_instance) { - if (!preview->get_parent()){ // create preview only once + if (!preview->get_parent()) { // create preview only once _create_preview(files); } - Transform2D trans=canvas->get_canvas_transform(); - preview->set_position((p_point-trans.get_origin())/trans.get_scale().x); - label->set_text(vformat(TTR("Adding %s..."),default_type)); + Transform2D trans = canvas->get_canvas_transform(); + preview->set_position((p_point - trans.get_origin()) / trans.get_scale().x); + label->set_text(vformat(TTR("Adding %s..."), default_type)); } return can_instance; } @@ -3928,25 +3725,25 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2& p_point,const Variant return false; } -void CanvasItemEditorViewport::drop_data(const Point2& p_point,const Variant& p_data) { - bool is_shift=Input::get_singleton()->is_key_pressed(KEY_SHIFT); - bool is_alt=Input::get_singleton()->is_key_pressed(KEY_ALT); +void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) { + bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT); + bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT); selected_files.clear(); - Dictionary d=p_data; - if (d.has("type") && String(d["type"])=="files"){ - selected_files=d["files"]; + Dictionary d = p_data; + if (d.has("type") && String(d["type"]) == "files") { + selected_files = d["files"]; } - List list=editor->get_editor_selection()->get_selected_node_list(); - if (list.size()==0) { + List list = editor->get_editor_selection()->get_selected_node_list(); + if (list.size() == 0) { accept->get_ok()->set_text(TTR("OK :(")); accept->set_text(TTR("No parent to instance a child at.")); accept->popup_centered_minsize(); _remove_preview(); return; } - if (list.size()!=1) { + if (list.size() != 1) { accept->get_ok()->set_text(TTR("I see..")); accept->set_text(TTR("This operation requires a single selected node.")); accept->popup_centered_minsize(); @@ -3954,21 +3751,21 @@ void CanvasItemEditorViewport::drop_data(const Point2& p_point,const Variant& p_ return; } - target_node=list[0]; - if (is_shift && target_node!=editor->get_edited_scene()) { - target_node=target_node->get_parent(); + target_node = list[0]; + if (is_shift && target_node != editor->get_edited_scene()) { + target_node = target_node->get_parent(); } - drop_pos=p_point; + drop_pos = p_point; if (is_alt) { - List btn_list; + List btn_list; button_group->get_buttons(&btn_list); - for (int i=0;icast_to(); - check->set_pressed(check->get_text()==default_type); + for (int i = 0; i < btn_list.size(); i++) { + CheckBox *check = btn_list[i]->cast_to(); + check->set_pressed(check->get_text() == default_type); } - selector_label->set_text(vformat(TTR("Add %s"),default_type)); + selector_label->set_text(vformat(TTR("Add %s"), default_type)); selector->popup_centered_minsize(); } else { _perform_drop_data(); @@ -3976,21 +3773,21 @@ void CanvasItemEditorViewport::drop_data(const Point2& p_point,const Variant& p_ } void CanvasItemEditorViewport::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { - connect("mouse_exited",this,"_on_mouse_exit"); - } else if (p_what==NOTIFICATION_EXIT_TREE) { - disconnect("mouse_exited",this,"_on_mouse_exit"); + if (p_what == NOTIFICATION_ENTER_TREE) { + connect("mouse_exited", this, "_on_mouse_exit"); + } else if (p_what == NOTIFICATION_EXIT_TREE) { + disconnect("mouse_exited", this, "_on_mouse_exit"); } } void CanvasItemEditorViewport::_bind_methods() { - ClassDB::bind_method(D_METHOD("_on_select_type"),&CanvasItemEditorViewport::_on_select_type); - ClassDB::bind_method(D_METHOD("_on_change_type"),&CanvasItemEditorViewport::_on_change_type); - ClassDB::bind_method(D_METHOD("_on_mouse_exit"),&CanvasItemEditorViewport::_on_mouse_exit); + ClassDB::bind_method(D_METHOD("_on_select_type"), &CanvasItemEditorViewport::_on_select_type); + ClassDB::bind_method(D_METHOD("_on_change_type"), &CanvasItemEditorViewport::_on_change_type); + ClassDB::bind_method(D_METHOD("_on_mouse_exit"), &CanvasItemEditorViewport::_on_mouse_exit); } -CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor* p_canvas) { - default_type="Sprite"; +CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas) { + default_type = "Sprite"; // Node2D types.push_back("Sprite"); types.push_back("Light2D"); @@ -4001,42 +3798,42 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte types.push_back("TextureRect"); types.push_back("Patch9Rect"); - target_node=NULL; - editor=p_node; - editor_data=editor->get_scene_tree_dock()->get_editor_data(); - canvas=p_canvas; - preview=memnew( Node2D ); - accept=memnew( AcceptDialog ); + target_node = NULL; + editor = p_node; + editor_data = editor->get_scene_tree_dock()->get_editor_data(); + canvas = p_canvas; + preview = memnew(Node2D); + accept = memnew(AcceptDialog); editor->get_gui_base()->add_child(accept); - selector=memnew( WindowDialog ); + selector = memnew(WindowDialog); selector->set_title(TTR("Change default type")); - VBoxContainer* vbc=memnew(VBoxContainer); - vbc->add_constant_override("separation",10*EDSCALE); - vbc->set_custom_minimum_size(Size2(200,260)*EDSCALE); + VBoxContainer *vbc = memnew(VBoxContainer); + vbc->add_constant_override("separation", 10 * EDSCALE); + vbc->set_custom_minimum_size(Size2(200, 260) * EDSCALE); - selector_label=memnew(Label); + selector_label = memnew(Label); selector_label->set_align(Label::ALIGN_CENTER); selector_label->set_valign(Label::VALIGN_BOTTOM); - selector_label->set_custom_minimum_size(Size2(0,30)*EDSCALE); + selector_label->set_custom_minimum_size(Size2(0, 30) * EDSCALE); vbc->add_child(selector_label); button_group.instance(); - btn_group=memnew( VBoxContainer ); + btn_group = memnew(VBoxContainer); btn_group->set_h_size_flags(0); btn_group->connect("button_selected", this, "_on_select_type"); - for (int i=0;iset_text(types[i]); btn_group->add_child(check); check->set_button_group(button_group); } vbc->add_child(btn_group); - Button* ok=memnew(Button); + Button *ok = memnew(Button); ok->set_text(TTR("OK")); ok->set_h_size_flags(0); vbc->add_child(ok); @@ -4045,18 +3842,18 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte selector->add_child(vbc); editor->get_gui_base()->add_child(selector); - label=memnew(Label); - label->add_color_override("font_color", Color(1,1,0,1)); - label->add_color_override("font_color_shadow", Color(0,0,0,1)); - label->add_constant_override("shadow_as_outline", 1*EDSCALE); + label = memnew(Label); + label->add_color_override("font_color", Color(1, 1, 0, 1)); + label->add_color_override("font_color_shadow", Color(0, 0, 0, 1)); + label->add_constant_override("shadow_as_outline", 1 * EDSCALE); label->hide(); editor->get_gui_base()->add_child(label); - label_desc=memnew(Label); + label_desc = memnew(Label); label_desc->set_text(TTR("Drag & drop + Shift : Add node as sibling\nDrag & drop + Alt : Change node type")); - label_desc->add_color_override("font_color", Color(0.6,0.6,0.6,1)); - label_desc->add_color_override("font_color_shadow", Color(0.2,0.2,0.2,1)); - label_desc->add_constant_override("shadow_as_outline", 1*EDSCALE); + label_desc->add_color_override("font_color", Color(0.6, 0.6, 0.6, 1)); + label_desc->add_color_override("font_color_shadow", Color(0.2, 0.2, 0.2, 1)); + label_desc->add_constant_override("shadow_as_outline", 1 * EDSCALE); label_desc->add_constant_override("line_spacing", 0); label_desc->hide(); editor->get_gui_base()->add_child(label_desc); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 0c2dcdff3d..5f22437d39 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -29,15 +29,15 @@ #ifndef CONTROL_EDITOR_PLUGIN_H #define CONTROL_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "scene/2d/canvas_item.h" +#include "scene/gui/box_container.h" #include "scene/gui/button_group.h" #include "scene/gui/check_box.h" #include "scene/gui/label.h" -#include "scene/gui/spin_box.h" #include "scene/gui/panel_container.h" -#include "scene/gui/box_container.h" -#include "scene/2d/canvas_item.h" +#include "scene/gui/spin_box.h" /** @author Juan Linietsky */ @@ -46,7 +46,8 @@ class CanvasItemEditorViewport; class CanvasItemEditorSelectedItem : public Object { - GDCLASS(CanvasItemEditorSelectedItem,Object); + GDCLASS(CanvasItemEditorSelectedItem, Object); + public: Variant undo_state; Vector2 undo_pivot; @@ -55,16 +56,15 @@ public: float prev_rot; Rect2 prev_rect; - CanvasItemEditorSelectedItem() { prev_rot=0; } + CanvasItemEditorSelectedItem() { prev_rot = 0; } }; class CanvasItemEditor : public VBoxContainer { - GDCLASS(CanvasItemEditor, VBoxContainer ); + GDCLASS(CanvasItemEditor, VBoxContainer); EditorNode *editor; - enum Tool { TOOL_SELECT, @@ -186,15 +186,14 @@ class CanvasItemEditor : public VBoxContainer { void _tool_select(int p_index); - MenuOption last_option; struct _SelectResult { - CanvasItem* item; + CanvasItem *item; float z; bool has_z; - _FORCE_INLINE_ bool operator<(const _SelectResult& p_rr) const { + _FORCE_INLINE_ bool operator<(const _SelectResult &p_rr) const { return has_z && p_rr.has_z ? p_rr.z < z : p_rr.has_z; } }; @@ -205,7 +204,10 @@ class CanvasItemEditor : public VBoxContainer { Point2 pos; bool lock; bool group; - LockList() { lock=false; group=false; } + LockList() { + lock = false; + group = false; + } }; List lock_list; @@ -220,7 +222,7 @@ class CanvasItemEditor : public VBoxContainer { }; uint64_t bone_last_frame; - Map bone_list; + Map bone_list; Transform2D bone_orig_xform; @@ -272,7 +274,6 @@ class CanvasItemEditor : public VBoxContainer { PopupMenu *selection_menu; - //PopupMenu *popup; DragType drag; Point2 drag_from; @@ -297,14 +298,13 @@ class CanvasItemEditor : public VBoxContainer { Ref select_sb; Ref select_handle; - int handle_len; bool _is_part_of_subscene(CanvasItem *p_item); - CanvasItem* _select_canvas_item_at_pos(const Point2 &p_pos,Node* p_node,const Transform2D& p_parent_xform,const Transform2D& p_canvas_xform); - void _find_canvas_items_at_pos(const Point2 &p_pos,Node* p_node,const Transform2D& p_parent_xform,const Transform2D& p_canvas_xform, Vector<_SelectResult> &r_items); - void _find_canvas_items_at_rect(const Rect2& p_rect,Node* p_node,const Transform2D& p_parent_xform,const Transform2D& p_canvas_xform,List *r_items); + CanvasItem *_select_canvas_item_at_pos(const Point2 &p_pos, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform); + void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, Vector<_SelectResult> &r_items); + void _find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, List *r_items); - bool _select(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag=true); + bool _select(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag = true); ConfirmationDialog *snap_dialog; @@ -314,22 +314,22 @@ class CanvasItemEditor : public VBoxContainer { CanvasItem *ref_item; - void _edit_set_pivot(const Vector2& mouse_pos); + void _edit_set_pivot(const Vector2 &mouse_pos); void _add_canvas_item(CanvasItem *p_canvas_item); void _remove_canvas_item(CanvasItem *p_canvas_item); void _clear_canvas_items(); void _visibility_changed(ObjectID p_canvas_item); - void _key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE p_move_mode); - void _list_select(const InputEventMouseButton& b); + void _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode); + void _list_select(const InputEventMouseButton &b); - DragType _find_drag_type(const Transform2D& p_xform, const Rect2& p_local_rect, const Point2& p_click, Vector2& r_point); + DragType _find_drag_type(const Transform2D &p_xform, const Rect2 &p_local_rect, const Point2 &p_click, Vector2 &r_point); void _popup_callback(int p_op); bool updating_scroll; void _update_scroll(float); void _update_scrollbars(); - void incbeg(float& beg,float& end, float inc, float minsize,bool p_symmetric); - void incend(float& beg,float& end, float inc, float minsize,bool p_symmetric); + void incbeg(float &beg, float &end, float inc, float minsize, bool p_symmetric); + void incend(float &beg, float &end, float inc, float minsize, bool p_symmetric); void _append_canvas_item(CanvasItem *p_item); void _dialog_value_changed(double); @@ -341,9 +341,7 @@ class CanvasItemEditor : public VBoxContainer { Point2 _find_topleftmost_point(); - - void _find_canvas_items_span(Node *p_node, Rect2& r_rect, const Transform2D& p_xform); - + void _find_canvas_items_span(Node *p_node, Rect2 &r_rect, const Transform2D &p_xform); Object *_get_editor_data(Object *p_what); @@ -351,59 +349,59 @@ class CanvasItemEditor : public VBoxContainer { int get_item_count(); void _keying_changed(); - void _unhandled_key_input(const InputEvent& p_ev); + void _unhandled_key_input(const InputEvent &p_ev); - void _viewport_gui_input(const InputEvent& p_event); + void _viewport_gui_input(const InputEvent &p_event); void _viewport_draw(); void _focus_selection(int p_op); - void _set_anchor(Control::AnchorType p_left,Control::AnchorType p_top,Control::AnchorType p_right,Control::AnchorType p_bottom); + void _set_anchor(Control::AnchorType p_left, Control::AnchorType p_top, Control::AnchorType p_right, Control::AnchorType p_bottom); HSplitContainer *palette_split; VSplitContainer *bottom_split; -friend class CanvasItemEditorPlugin; -protected: - + friend class CanvasItemEditorPlugin; +protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); void end_drag(); - void box_selection_start( Point2 &click ); + void box_selection_start(Point2 &click); bool box_selection_end(); HBoxContainer *get_panel_hb() { return hb; } struct compare_items_x { - bool operator()( const CanvasItem *a, const CanvasItem *b ) const { + bool operator()(const CanvasItem *a, const CanvasItem *b) const { return a->get_global_transform().elements[2].x < b->get_global_transform().elements[2].x; } }; struct compare_items_y { - bool operator()( const CanvasItem *a, const CanvasItem *b ) const { + bool operator()(const CanvasItem *a, const CanvasItem *b) const { return a->get_global_transform().elements[2].y < b->get_global_transform().elements[2].y; } }; struct proj_vector2_x { - float get( const Vector2 &v ) { return v.x; } - void set( Vector2 &v, float f ) { v.x = f; } + float get(const Vector2 &v) { return v.x; } + void set(Vector2 &v, float f) { v.x = f; } }; struct proj_vector2_y { - float get( const Vector2 &v ) { return v.y; } - void set( Vector2 &v, float f ) { v.y = f; } + float get(const Vector2 &v) { return v.y; } + void set(Vector2 &v, float f) { v.y = f; } }; - template< class P, class C > void space_selected_items(); + template + void space_selected_items(); static CanvasItemEditor *singleton; -public: +public: Vector2 snap_point(Vector2 p_target, Vector2 p_start = Vector2(0, 0)) const; float snap_angle(float p_target, float p_start = 0) const; @@ -411,7 +409,7 @@ public: static CanvasItemEditor *get_singleton() { return singleton; } Dictionary get_state() const; - void set_state(const Dictionary& p_state); + void set_state(const Dictionary &p_state); void add_control_to_menu_panel(Control *p_control); @@ -420,8 +418,8 @@ public: Control *get_viewport_control() { return viewport; } - bool get_remove_list(List *p_list); - void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; } + bool get_remove_list(List *p_list); + void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } void edit(CanvasItem *p_canvas_item); void focus_selection(); @@ -431,61 +429,59 @@ public: class CanvasItemEditorPlugin : public EditorPlugin { - GDCLASS( CanvasItemEditorPlugin, EditorPlugin ); + GDCLASS(CanvasItemEditorPlugin, EditorPlugin); CanvasItemEditor *canvas_item_editor; EditorNode *editor; public: - virtual String get_name() const { return "2D"; } bool has_main_screen() const { return true; } virtual void edit(Object *p_object); virtual bool handles(Object *p_object) const; virtual void make_visible(bool p_visible); - virtual bool get_remove_list(List *p_list) { return canvas_item_editor->get_remove_list(p_list); } + virtual bool get_remove_list(List *p_list) { return canvas_item_editor->get_remove_list(p_list); } virtual Dictionary get_state() const; - virtual void set_state(const Dictionary& p_state); + virtual void set_state(const Dictionary &p_state); CanvasItemEditor *get_canvas_item_editor() { return canvas_item_editor; } CanvasItemEditorPlugin(EditorNode *p_node); ~CanvasItemEditorPlugin(); - }; class CanvasItemEditorViewport : public Control { - GDCLASS( CanvasItemEditorViewport, Control ); + GDCLASS(CanvasItemEditorViewport, Control); String default_type; Vector types; Vector selected_files; - Node* target_node; + Node *target_node; Point2 drop_pos; - EditorNode* editor; - EditorData* editor_data; - CanvasItemEditor* canvas; - Node2D* preview; - AcceptDialog* accept; - WindowDialog* selector; - Label* selector_label; - Label* label; - Label* label_desc; - VBoxContainer* btn_group; + EditorNode *editor; + EditorData *editor_data; + CanvasItemEditor *canvas; + Node2D *preview; + AcceptDialog *accept; + WindowDialog *selector; + Label *selector_label; + Label *label; + Label *label_desc; + VBoxContainer *btn_group; Ref button_group; void _on_mouse_exit(); - void _on_select_type(Object* selected); + void _on_select_type(Object *selected); void _on_change_type(); - void _create_preview(const Vector& files) const; + void _create_preview(const Vector &files) const; void _remove_preview(); - bool _cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node); - void _create_nodes(Node* parent, Node* child, String& path, const Point2& p_point); - bool _create_instance(Node* parent, String& path, const Point2& p_point); + bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node); + void _create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point); + bool _create_instance(Node *parent, String &path, const Point2 &p_point); void _perform_drop_data(); static void _bind_methods(); @@ -494,10 +490,10 @@ protected: void _notification(int p_what); public: - virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const; - virtual void drop_data(const Point2& p_point,const Variant& p_data); + virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const; + virtual void drop_data(const Point2 &p_point, const Variant &p_data); - CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor* p_canvas); + CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas); }; #endif diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp index 5a45267c85..0f7e3a3990 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp @@ -29,193 +29,177 @@ #include "collision_polygon_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "os/file_access.h" #include "editor/editor_settings.h" - +#include "os/file_access.h" void CollisionPolygon2DEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_READY: { - button_create->set_icon( get_icon("Edit","EditorIcons")); - button_edit->set_icon( get_icon("MovePoint","EditorIcons")); + button_create->set_icon(get_icon("Edit", "EditorIcons")); + button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); button_edit->set_pressed(true); - get_tree()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("node_removed", this, "_node_removed"); } break; case NOTIFICATION_FIXED_PROCESS: { - } break; } - } void CollisionPolygon2DEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); canvas_item_editor->get_viewport_control()->update(); } - } - void CollisionPolygon2DEditor::_menu_option(int p_option) { - switch(p_option) { + switch (p_option) { case MODE_CREATE: { - mode=MODE_CREATE; + mode = MODE_CREATE; button_create->set_pressed(true); button_edit->set_pressed(false); } break; case MODE_EDIT: { - mode=MODE_EDIT; + mode = MODE_EDIT; button_create->set_pressed(false); button_edit->set_pressed(true); } break; - } } void CollisionPolygon2DEditor::_wip_close() { undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node,"set_polygon",node->get_polygon()); - undo_redo->add_do_method(node,"set_polygon",wip); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(node, "set_polygon", node->get_polygon()); + undo_redo->add_do_method(node, "set_polygon", wip); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); wip.clear(); - wip_active=false; - mode=MODE_EDIT; + wip_active = false; + mode = MODE_EDIT; button_edit->set_pressed(true); button_create->set_pressed(false); - edited_point=-1; + edited_point = -1; } -bool CollisionPolygon2DEditor::forward_gui_input(const InputEvent& p_event) { - +bool CollisionPolygon2DEditor::forward_gui_input(const InputEvent &p_event) { if (!node) return false; - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - const InputEventMouseButton &mb=p_event.mouse_button; + const InputEventMouseButton &mb = p_event.mouse_button; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = Point2(mb.x,mb.y); + Vector2 gpoint = Point2(mb.x, mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); Vector poly = node->get_polygon(); //first check if a point is to be added (segment split) - real_t grab_treshold=EDITOR_DEF("editors/poly_editor/point_grab_radius",8); - - switch(mode) { + real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + switch (mode) { case MODE_CREATE: { - if (mb.button_index==BUTTON_LEFT && mb.pressed) { - + if (mb.button_index == BUTTON_LEFT && mb.pressed) { if (!wip_active) { wip.clear(); - wip.push_back( cpoint ); - wip_active=true; - edited_point_pos=cpoint; + wip.push_back(cpoint); + wip_active = true; + edited_point_pos = cpoint; canvas_item_editor->get_viewport_control()->update(); - edited_point=1; + edited_point = 1; return true; } else { - - if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint) 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) { //wip closed _wip_close(); return true; } else { - wip.push_back( cpoint ); - edited_point=wip.size(); + wip.push_back(cpoint); + edited_point = wip.size(); canvas_item_editor->get_viewport_control()->update(); return true; //add wip point } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) { _wip_close(); } - - } break; case MODE_EDIT: { - if (mb.button_index==BUTTON_LEFT) { + if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { if (mb.mod.control) { - if (poly.size() < 3) { undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_undo_method(node,"set_polygon",poly); + undo_redo->add_undo_method(node, "set_polygon", poly); poly.push_back(cpoint); - undo_redo->add_do_method(node,"set_polygon",poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node, "set_polygon", poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return true; } //search edges - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;i=0) { + if (closest_idx >= 0) { - pre_move_edit=poly; - poly.insert(closest_idx+1,xform.affine_inverse().xform(closest_pos)); - edited_point=closest_idx+1; - edited_point_pos=xform.affine_inverse().xform(closest_pos); + pre_move_edit = poly; + poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos)); + edited_point = closest_idx + 1; + edited_point_pos = xform.affine_inverse().xform(closest_pos); node->set_polygon(poly); canvas_item_editor->get_viewport_control()->update(); return true; @@ -224,106 +208,95 @@ bool CollisionPolygon2DEditor::forward_gui_input(const InputEvent& p_event) { //look for points to move - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;i=0) { + if (closest_idx >= 0) { - pre_move_edit=poly; - edited_point=closest_idx; - edited_point_pos=xform.affine_inverse().xform(closest_pos); + pre_move_edit = poly; + edited_point = closest_idx; + edited_point_pos = xform.affine_inverse().xform(closest_pos); canvas_item_editor->get_viewport_control()->update(); return true; } } } else { - if (edited_point!=-1) { + if (edited_point != -1) { //apply - ERR_FAIL_INDEX_V(edited_point,poly.size(),false); - poly[edited_point]=edited_point_pos; + ERR_FAIL_INDEX_V(edited_point, poly.size(), false); + poly[edited_point] = edited_point_pos; undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node,"set_polygon",poly); - undo_redo->add_undo_method(node,"set_polygon",pre_move_edit); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node, "set_polygon", poly); + undo_redo->add_undo_method(node, "set_polygon", pre_move_edit); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); - edited_point=-1; + edited_point = -1; return true; } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) { - + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) { - - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;i=0) { - + if (closest_idx >= 0) { undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node,"set_polygon",poly); + undo_redo->add_undo_method(node, "set_polygon", poly); poly.remove(closest_idx); - undo_redo->add_do_method(node,"set_polygon",poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node, "set_polygon", poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return true; } - } - - } break; } - - } break; case InputEvent::MOUSE_MOTION: { - const InputEventMouseMotion &mm=p_event.mouse_motion; + const InputEventMouseMotion &mm = p_event.mouse_motion; - if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { + if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) { - Vector2 gpoint = Point2(mm.x,mm.y); + Vector2 gpoint = Point2(mm.x, mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); - } } break; @@ -341,90 +314,83 @@ void CollisionPolygon2DEditor::_canvas_draw() { Vector poly; if (wip_active) - poly=wip; + poly = wip; else - poly=node->get_polygon(); - + poly = node->get_polygon(); Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref handle= get_icon("EditorHandle","EditorIcons"); - - for(int i=0;i handle = get_icon("EditorHandle", "EditorIcons"); + for (int i = 0; i < poly.size(); i++) { - Vector2 p,p2; - p = i==edited_point ? edited_point_pos : poly[i]; - if ((wip_active && i==poly.size()-1) || (((i+1)%poly.size())==edited_point)) - p2=edited_point_pos; + Vector2 p, p2; + p = i == edited_point ? edited_point_pos : poly[i]; + if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) + p2 = edited_point_pos; else - p2 = poly[(i+1)%poly.size()]; + p2 = poly[(i + 1) % poly.size()]; Vector2 point = xform.xform(p); Vector2 next_point = xform.xform(p2); - Color col=Color(1,0.3,0.1,0.8); - vpc->draw_line(point,next_point,col,2); - vpc->draw_texture(handle,point-handle->get_size()*0.5); + Color col = Color(1, 0.3, 0.1, 0.8); + vpc->draw_line(point, next_point, col, 2); + vpc->draw_texture(handle, point - handle->get_size() * 0.5); } } - - void CollisionPolygon2DEditor::edit(Node *p_collision_polygon) { if (!canvas_item_editor) { - canvas_item_editor=CanvasItemEditor::get_singleton(); + canvas_item_editor = CanvasItemEditor::get_singleton(); } if (p_collision_polygon) { - node=p_collision_polygon->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"); + node = p_collision_polygon->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"); wip.clear(); - wip_active=false; - edited_point=-1; + wip_active = false; + edited_point = -1; canvas_item_editor->get_viewport_control()->update(); } else { - node=NULL; - - 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; + if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); } - } void CollisionPolygon2DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_option"),&CollisionPolygon2DEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"),&CollisionPolygon2DEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_node_removed"),&CollisionPolygon2DEditor::_node_removed); - + ClassDB::bind_method(D_METHOD("_menu_option"), &CollisionPolygon2DEditor::_menu_option); + ClassDB::bind_method(D_METHOD("_canvas_draw"), &CollisionPolygon2DEditor::_canvas_draw); + ClassDB::bind_method(D_METHOD("_node_removed"), &CollisionPolygon2DEditor::_node_removed); } CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) { - node=NULL; - canvas_item_editor=NULL; - editor=p_editor; + node = NULL; + canvas_item_editor = NULL; + editor = p_editor; undo_redo = editor->get_undo_redo(); - add_child( memnew( VSeparator )); - button_create = memnew( ToolButton ); + add_child(memnew(VSeparator)); + button_create = memnew(ToolButton); add_child(button_create); - button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE)); + button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); button_create->set_toggle_mode(true); button_create->set_tooltip(TTR("Create a new polygon from scratch.")); - button_edit = memnew( ToolButton ); + button_edit = memnew(ToolButton); add_child(button_edit); - button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT)); + button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); button_edit->set_toggle_mode(true); button_edit->set_tooltip("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point."); - //add_constant_override("separation",0); +//add_constant_override("separation",0); #if 0 options = memnew( MenuButton ); @@ -436,11 +402,9 @@ CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) { #endif mode = MODE_EDIT; - wip_active=false; - + wip_active = false; } - void CollisionPolygon2DEditorPlugin::edit(Object *p_object) { collision_polygon_editor->edit(p_object->cast_to()); @@ -460,23 +424,16 @@ void CollisionPolygon2DEditorPlugin::make_visible(bool p_visible) { collision_polygon_editor->hide(); collision_polygon_editor->edit(NULL); } - } CollisionPolygon2DEditorPlugin::CollisionPolygon2DEditorPlugin(EditorNode *p_node) { - editor=p_node; - collision_polygon_editor = memnew( CollisionPolygon2DEditor(p_node) ); + editor = p_node; + collision_polygon_editor = memnew(CollisionPolygon2DEditor(p_node)); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); collision_polygon_editor->hide(); - - - } - -CollisionPolygon2DEditorPlugin::~CollisionPolygon2DEditorPlugin() -{ +CollisionPolygon2DEditorPlugin::~CollisionPolygon2DEditorPlugin() { } - diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.h b/editor/plugins/collision_polygon_2d_editor_plugin.h index 796328753d..abd723cce9 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -29,12 +29,11 @@ #ifndef COLLISION_POLYGON_2D_EDITOR_PLUGIN_H #define COLLISION_POLYGON_2D_EDITOR_PLUGIN_H - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/collision_polygon_2d.h" -#include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" +#include "scene/gui/tool_button.h" /** @author Juan Linietsky @@ -43,7 +42,7 @@ class CanvasItemEditor; class CollisionPolygon2DEditor : public HBoxContainer { - GDCLASS(CollisionPolygon2DEditor, HBoxContainer ); + GDCLASS(CollisionPolygon2DEditor, HBoxContainer); UndoRedo *undo_redo; enum Mode { @@ -70,7 +69,6 @@ class CollisionPolygon2DEditor : public HBoxContainer { Vector wip; bool wip_active; - void _wip_close(); void _canvas_draw(); void _menu_option(int p_option); @@ -79,23 +77,22 @@ protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); -public: - bool forward_gui_input(const InputEvent& p_event); +public: + bool forward_gui_input(const InputEvent &p_event); void edit(Node *p_collision_polygon); CollisionPolygon2DEditor(EditorNode *p_editor); }; class CollisionPolygon2DEditorPlugin : public EditorPlugin { - GDCLASS( CollisionPolygon2DEditorPlugin, EditorPlugin ); + GDCLASS(CollisionPolygon2DEditorPlugin, EditorPlugin); CollisionPolygon2DEditor *collision_polygon_editor; EditorNode *editor; public: - - virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); } + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); } virtual String get_name() const { return "CollisionPolygon2D"; } bool has_main_screen() const { return false; } @@ -105,7 +102,6 @@ public: CollisionPolygon2DEditorPlugin(EditorNode *p_node); ~CollisionPolygon2DEditorPlugin(); - }; #endif // COLLISION_POLYGON_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp index 3aad53b420..62426a7699 100644 --- a/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_editor_plugin.cpp @@ -28,11 +28,11 @@ /*************************************************************************/ #include "collision_polygon_editor_plugin.h" -#include "spatial_editor_plugin.h" -#include "os/file_access.h" +#include "canvas_item_editor_plugin.h" #include "editor/editor_settings.h" +#include "os/file_access.h" #include "scene/3d/camera.h" -#include "canvas_item_editor_plugin.h" +#include "spatial_editor_plugin.h" #if 0 diff --git a/editor/plugins/collision_polygon_editor_plugin.h b/editor/plugins/collision_polygon_editor_plugin.h index aaad2174fe..ace8c3429f 100644 --- a/editor/plugins/collision_polygon_editor_plugin.h +++ b/editor/plugins/collision_polygon_editor_plugin.h @@ -29,13 +29,13 @@ #ifndef COLLISION_POLYGON_EDITOR_PLUGIN_H #define COLLISION_POLYGON_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/3d/collision_polygon.h" #include "scene/3d/immediate_geometry.h" #include "scene/3d/mesh_instance.h" -#include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" +#include "scene/gui/tool_button.h" /** @author Juan Linietsky diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index a05eeb7a27..3538878877 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -29,23 +29,23 @@ #include "collision_shape_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "scene/resources/segment_shape_2d.h" -#include "scene/resources/shape_line_2d.h" -#include "scene/resources/circle_shape_2d.h" -#include "scene/resources/rectangle_shape_2d.h" #include "scene/resources/capsule_shape_2d.h" -#include "scene/resources/convex_polygon_shape_2d.h" +#include "scene/resources/circle_shape_2d.h" #include "scene/resources/concave_polygon_shape_2d.h" +#include "scene/resources/convex_polygon_shape_2d.h" +#include "scene/resources/rectangle_shape_2d.h" +#include "scene/resources/segment_shape_2d.h" +#include "scene/resources/shape_line_2d.h" Variant CollisionShape2DEditor::get_handle_value(int idx) const { - switch ( shape_type ) { + switch (shape_type) { case CAPSULE_SHAPE: { Ref capsule = node->get_shape(); - if (idx==0) { + if (idx == 0) { return capsule->get_radius(); - } else if (idx==1) { + } else if (idx == 1) { return capsule->get_height(); } @@ -54,7 +54,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case CIRCLE_SHAPE: { Ref circle = node->get_shape(); - if (idx==0) { + if (idx == 0) { return circle->get_radius(); } @@ -71,7 +71,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case LINE_SHAPE: { Ref line = node->get_shape(); - if (idx==0) { + if (idx == 0) { return line->get_d(); } else { return line->get_normal(); @@ -82,7 +82,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case RAY_SHAPE: { Ref ray = node->get_shape(); - if (idx==0) { + if (idx == 0) { return ray->get_length(); } @@ -91,7 +91,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case RECTANGLE_SHAPE: { Ref rect = node->get_shape(); - if (idx<2) { + if (idx < 2) { return rect->get_extents().abs(); } @@ -100,9 +100,9 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case SEGMENT_SHAPE: { Ref seg = node->get_shape(); - if (idx==0) { + if (idx == 0) { return seg->get_a(); - } else if (idx==1) { + } else if (idx == 1) { return seg->get_b(); } @@ -112,19 +112,19 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { return Variant(); } -void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) { +void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { - switch ( shape_type ) { + 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) { + if (idx == 0) { capsule->set_radius(parameter); - } else if (idx==1){ - capsule->set_height(parameter*2 - capsule->get_radius()*2); + } else if (idx == 1) { + capsule->set_height(parameter * 2 - capsule->get_radius() * 2); } canvas_item_editor->get_viewport_control()->update(); @@ -149,19 +149,18 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) { } break; case LINE_SHAPE: { - if (idx<2) { + if (idx < 2) { Ref line = node->get_shape(); - if (idx==0){ + if (idx == 0) { line->set_d(p_point.length()); - }else{ + } else { line->set_normal(p_point.normalized()); } canvas_item_editor->get_viewport_control()->update(); } - } break; case RAY_SHAPE: { @@ -174,7 +173,7 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) { } break; case RECTANGLE_SHAPE: { - if (idx<2) { + if (idx < 2) { Ref rect = node->get_shape(); Vector2 extents = rect->get_extents(); @@ -191,9 +190,9 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) { if (edit_handle < 2) { Ref seg = node->get_shape(); - if (idx==0) { + if (idx == 0) { seg->set_a(p_point); - } else if (idx==1) { + } else if (idx == 1) { seg->set_b(p_point); } @@ -204,25 +203,25 @@ void CollisionShape2DEditor::set_handle(int idx, Point2& p_point) { } } -void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) { +void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { - Control* c = canvas_item_editor->get_viewport_control(); + Control *c = canvas_item_editor->get_viewport_control(); undo_redo->create_action(TTR("Set Handle")); - switch ( shape_type ) { + 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"); + 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; @@ -230,10 +229,10 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) { 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"); + 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; @@ -248,16 +247,16 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) { case LINE_SHAPE: { Ref line = node->get_shape(); - if (idx==0) { - undo_redo->add_do_method(line.ptr(),"set_d",line->get_d()); - undo_redo->add_do_method(c,"update"); - undo_redo->add_undo_method(line.ptr(),"set_d",p_org); - undo_redo->add_undo_method(c,"update"); + if (idx == 0) { + undo_redo->add_do_method(line.ptr(), "set_d", line->get_d()); + undo_redo->add_do_method(c, "update"); + undo_redo->add_undo_method(line.ptr(), "set_d", p_org); + undo_redo->add_undo_method(c, "update"); } else { - undo_redo->add_do_method(line.ptr(),"set_normal",line->get_normal()); - undo_redo->add_do_method(c,"update"); - undo_redo->add_undo_method(line.ptr(),"set_normal",p_org); - undo_redo->add_undo_method(c,"update"); + undo_redo->add_do_method(line.ptr(), "set_normal", line->get_normal()); + undo_redo->add_do_method(c, "update"); + undo_redo->add_undo_method(line.ptr(), "set_normal", p_org); + undo_redo->add_undo_method(c, "update"); } } break; @@ -265,35 +264,35 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) { 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"); + 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"); + 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"); + 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; @@ -302,7 +301,7 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant& p_org) { undo_redo->commit_action(); } -bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) { +bool CollisionShape2DEditor::forward_gui_input(const InputEvent &p_event) { if (!node) { return false; @@ -316,13 +315,13 @@ bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) { return false; } - switch( p_event.type ) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - const InputEventMouseButton& mb = p_event.mouse_button; + const InputEventMouseButton &mb = p_event.mouse_button; Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Point2 gpoint(mb.x,mb.y); + Point2 gpoint(mb.x, mb.y); if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { @@ -334,7 +333,7 @@ bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) { } } - if (edit_handle==-1) { + if (edit_handle == -1) { pressed = false; return false; @@ -362,13 +361,13 @@ bool CollisionShape2DEditor::forward_gui_input(const InputEvent& p_event) { } break; case InputEvent::MOUSE_MOTION: { - const InputEventMouseMotion& mm = p_event.mouse_motion; + const InputEventMouseMotion &mm = p_event.mouse_motion; if (edit_handle == -1 || !pressed) { return false; } - Point2 gpoint = Point2(mm.x,mm.y); + 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); @@ -437,8 +436,8 @@ void CollisionShape2DEditor::_canvas_draw() { Control *c = canvas_item_editor->get_viewport_control(); Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref h = get_icon("EditorHandle","EditorIcons"); - Vector2 size = h->get_size()*0.5; + Ref h = get_icon("EditorHandle", "EditorIcons"); + Vector2 size = h->get_size() * 0.5; handles.clear(); @@ -448,13 +447,13 @@ void CollisionShape2DEditor::_canvas_draw() { handles.resize(2); float radius = shape->get_radius(); - float height = shape->get_height()/2; + float height = shape->get_height() / 2; handles[0] = Point2(radius, -height); - handles[1] = Point2(0,-(height + radius)); + handles[1] = Point2(0, -(height + radius)); - c->draw_texture(h, gt.xform(handles[0])-size); - c->draw_texture(h, gt.xform(handles[1])-size); + c->draw_texture(h, gt.xform(handles[0]) - size); + c->draw_texture(h, gt.xform(handles[1]) - size); } break; @@ -462,9 +461,9 @@ void CollisionShape2DEditor::_canvas_draw() { Ref shape = node->get_shape(); handles.resize(1); - handles[0] = Point2(shape->get_radius(),0); + handles[0] = Point2(shape->get_radius(), 0); - c->draw_texture(h, gt.xform(handles[0])-size); + c->draw_texture(h, gt.xform(handles[0]) - size); } break; @@ -483,8 +482,8 @@ void CollisionShape2DEditor::_canvas_draw() { handles[0] = shape->get_normal() * shape->get_d(); handles[1] = shape->get_normal() * (shape->get_d() + 30.0); - c->draw_texture(h,gt.xform(handles[0])-size); - c->draw_texture(h,gt.xform(handles[1])-size); + c->draw_texture(h, gt.xform(handles[0]) - size); + c->draw_texture(h, gt.xform(handles[1]) - size); } break; @@ -492,9 +491,9 @@ void CollisionShape2DEditor::_canvas_draw() { Ref shape = node->get_shape(); handles.resize(1); - handles[0] = Point2(0,shape->get_length()); + handles[0] = Point2(0, shape->get_length()); - c->draw_texture(h,gt.xform(handles[0])-size); + c->draw_texture(h, gt.xform(handles[0]) - size); } break; @@ -503,11 +502,11 @@ void CollisionShape2DEditor::_canvas_draw() { handles.resize(2); Vector2 ext = shape->get_extents(); - handles[0] = Point2(ext.x,0); - handles[1] = Point2(0,-ext.y); + 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); + c->draw_texture(h, gt.xform(handles[0]) - size); + c->draw_texture(h, gt.xform(handles[1]) - size); } break; @@ -518,24 +517,24 @@ void CollisionShape2DEditor::_canvas_draw() { 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); + 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) { +void CollisionShape2DEditor::edit(Node *p_node) { if (!canvas_item_editor) { - canvas_item_editor=CanvasItemEditor::get_singleton(); + canvas_item_editor = CanvasItemEditor::get_singleton(); } if (p_node) { - node=p_node->cast_to(); + 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"); + 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(); @@ -543,10 +542,10 @@ void CollisionShape2DEditor::edit(Node* p_node) { 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"); + 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; + node = NULL; } canvas_item_editor->get_viewport_control()->update(); @@ -554,11 +553,11 @@ void CollisionShape2DEditor::edit(Node* p_node) { void CollisionShape2DEditor::_bind_methods() { - ClassDB::bind_method("_canvas_draw",&CollisionShape2DEditor::_canvas_draw); - ClassDB::bind_method("_get_current_shape_type",&CollisionShape2DEditor::_get_current_shape_type); + ClassDB::bind_method("_canvas_draw", &CollisionShape2DEditor::_canvas_draw); + ClassDB::bind_method("_get_current_shape_type", &CollisionShape2DEditor::_get_current_shape_type); } -CollisionShape2DEditor::CollisionShape2DEditor(EditorNode* p_editor) { +CollisionShape2DEditor::CollisionShape2DEditor(EditorNode *p_editor) { node = NULL; canvas_item_editor = NULL; @@ -570,12 +569,12 @@ CollisionShape2DEditor::CollisionShape2DEditor(EditorNode* p_editor) { pressed = false; } -void CollisionShape2DEditorPlugin::edit(Object* p_obj) { +void CollisionShape2DEditorPlugin::edit(Object *p_obj) { collision_shape_2d_editor->edit(p_obj->cast_to()); } -bool CollisionShape2DEditorPlugin::handles(Object* p_obj) const { +bool CollisionShape2DEditorPlugin::handles(Object *p_obj) const { return p_obj->is_class("CollisionShape2D"); } @@ -587,14 +586,13 @@ void CollisionShape2DEditorPlugin::make_visible(bool visible) { } } -CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin(EditorNode* p_node) { +CollisionShape2DEditorPlugin::CollisionShape2DEditorPlugin(EditorNode *p_node) { - editor=p_node; + editor = p_node; - collision_shape_2d_editor = memnew( CollisionShape2DEditor(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/editor/plugins/collision_shape_2d_editor_plugin.h b/editor/plugins/collision_shape_2d_editor_plugin.h index f7e6da8b4e..75331a1d61 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.h +++ b/editor/plugins/collision_shape_2d_editor_plugin.h @@ -29,8 +29,8 @@ #ifndef COLLISION_SHAPE_2D_EDITOR_PLUGIN_H #define COLLISION_SHAPE_2D_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/collision_shape_2d.h" @@ -50,10 +50,10 @@ class CollisionShape2DEditor : public Control { SEGMENT_SHAPE }; - EditorNode* editor; - UndoRedo* undo_redo; - CanvasItemEditor* canvas_item_editor; - CollisionShape2D* node; + EditorNode *editor; + UndoRedo *undo_redo; + CanvasItemEditor *canvas_item_editor; + CollisionShape2D *node; Vector handles; @@ -63,8 +63,8 @@ class CollisionShape2DEditor : public Control { 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 set_handle(int idx, Point2 &p_point); + void commit_handle(int idx, Variant &p_org); void _get_current_shape_type(); void _canvas_draw(); @@ -73,28 +73,28 @@ protected: static void _bind_methods(); public: - bool forward_gui_input(const InputEvent& p_event); - void edit(Node* p_node); + bool forward_gui_input(const InputEvent &p_event); + void edit(Node *p_node); - CollisionShape2DEditor(EditorNode* p_editor); + CollisionShape2DEditor(EditorNode *p_editor); }; class CollisionShape2DEditorPlugin : public EditorPlugin { GDCLASS(CollisionShape2DEditorPlugin, EditorPlugin); - CollisionShape2DEditor* collision_shape_2d_editor; - EditorNode* editor; + CollisionShape2DEditor *collision_shape_2d_editor; + EditorNode *editor; public: - virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform,const InputEvent& p_event) { return collision_shape_2d_editor->forward_gui_input(p_event); } + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_shape_2d_editor->forward_gui_input(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 edit(Object *p_obj); + virtual bool handles(Object *p_obj) const; virtual void make_visible(bool visible); - CollisionShape2DEditorPlugin(EditorNode* p_editor); + CollisionShape2DEditorPlugin(EditorNode *p_editor); ~CollisionShape2DEditorPlugin(); }; diff --git a/editor/plugins/color_ramp_editor_plugin.cpp b/editor/plugins/color_ramp_editor_plugin.cpp index 82674fabb8..1d1d654bd5 100644 --- a/editor/plugins/color_ramp_editor_plugin.cpp +++ b/editor/plugins/color_ramp_editor_plugin.cpp @@ -28,16 +28,15 @@ /*************************************************************************/ #include "color_ramp_editor_plugin.h" -#include "spatial_editor_plugin.h" #include "canvas_item_editor_plugin.h" +#include "spatial_editor_plugin.h" ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) { - editor=p_node; - ramp_editor = memnew( ColorRampEdit ); - + editor = p_node; + ramp_editor = memnew(ColorRampEdit); - add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,ramp_editor); + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, ramp_editor); ramp_editor->set_custom_minimum_size(Size2(100, 48)); ramp_editor->hide(); @@ -46,7 +45,7 @@ ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) { void ColorRampEditorPlugin::edit(Object *p_object) { - ColorRamp* color_ramp = p_object->cast_to(); + ColorRamp *color_ramp = p_object->cast_to(); if (!color_ramp) return; color_ramp_ref = Ref(color_ramp); @@ -56,7 +55,6 @@ void ColorRampEditorPlugin::edit(Object *p_object) { bool ColorRampEditorPlugin::handles(Object *p_object) const { return p_object->is_class("ColorRamp"); - } void ColorRampEditorPlugin::make_visible(bool p_visible) { @@ -66,36 +64,34 @@ void ColorRampEditorPlugin::make_visible(bool p_visible) { } else { ramp_editor->hide(); } - } void ColorRampEditorPlugin::_ramp_changed() { - if(color_ramp_ref.is_valid()) - { + if (color_ramp_ref.is_valid()) { - UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); //Not sure if I should convert this data to PoolVector - Vector new_offsets=ramp_editor->get_offsets(); - Vector new_colors=ramp_editor->get_colors(); - Vector old_offsets=color_ramp_ref->get_offsets(); - Vector old_colors=color_ramp_ref->get_colors(); + Vector new_offsets = ramp_editor->get_offsets(); + Vector new_colors = ramp_editor->get_colors(); + Vector old_offsets = color_ramp_ref->get_offsets(); + Vector old_colors = color_ramp_ref->get_colors(); - if (old_offsets.size()!=new_offsets.size()) + if (old_offsets.size() != new_offsets.size()) ur->create_action(TTR("Add/Remove Color Ramp Point")); else - ur->create_action(TTR("Modify Color Ramp"),UndoRedo::MERGE_ENDS); - ur->add_do_method(this,"undo_redo_color_ramp",new_offsets,new_colors); - ur->add_undo_method(this,"undo_redo_color_ramp",old_offsets,old_colors); + ur->create_action(TTR("Modify Color Ramp"), UndoRedo::MERGE_ENDS); + ur->add_do_method(this, "undo_redo_color_ramp", new_offsets, new_colors); + ur->add_undo_method(this, "undo_redo_color_ramp", old_offsets, old_colors); ur->commit_action(); //color_ramp_ref->set_points(ramp_editor->get_points()); } } -void ColorRampEditorPlugin::_undo_redo_color_ramp(const Vector& offsets, - const Vector& colors) { +void ColorRampEditorPlugin::_undo_redo_color_ramp(const Vector &offsets, + const Vector &colors) { color_ramp_ref->set_offsets(offsets); color_ramp_ref->set_colors(colors); @@ -103,10 +99,10 @@ void ColorRampEditorPlugin::_undo_redo_color_ramp(const Vector& offsets, ramp_editor->update(); } -ColorRampEditorPlugin::~ColorRampEditorPlugin(){ +ColorRampEditorPlugin::~ColorRampEditorPlugin() { } void ColorRampEditorPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("ramp_changed"),&ColorRampEditorPlugin::_ramp_changed); - ClassDB::bind_method(D_METHOD("undo_redo_color_ramp","offsets","colors"),&ColorRampEditorPlugin::_undo_redo_color_ramp); + ClassDB::bind_method(D_METHOD("ramp_changed"), &ColorRampEditorPlugin::_ramp_changed); + ClassDB::bind_method(D_METHOD("undo_redo_color_ramp", "offsets", "colors"), &ColorRampEditorPlugin::_undo_redo_color_ramp); } diff --git a/editor/plugins/color_ramp_editor_plugin.h b/editor/plugins/color_ramp_editor_plugin.h index 0323bd7a46..45ac53c669 100644 --- a/editor/plugins/color_ramp_editor_plugin.h +++ b/editor/plugins/color_ramp_editor_plugin.h @@ -29,13 +29,13 @@ #ifndef TOOLS_EDITOR_PLUGINS_COLOR_RAMP_EDITOR_PLUGIN_H_ #define TOOLS_EDITOR_PLUGINS_COLOR_RAMP_EDITOR_PLUGIN_H_ -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/gui/color_ramp_edit.h" class ColorRampEditorPlugin : public EditorPlugin { - GDCLASS( ColorRampEditorPlugin, EditorPlugin ); + GDCLASS(ColorRampEditorPlugin, EditorPlugin); bool _2d; Ref color_ramp_ref; @@ -45,7 +45,7 @@ class ColorRampEditorPlugin : public EditorPlugin { protected: static void _bind_methods(); void _ramp_changed(); - void _undo_redo_color_ramp(const Vector& offsets, const Vector& colors); + void _undo_redo_color_ramp(const Vector &offsets, const Vector &colors); public: virtual String get_name() const { return "ColorRamp"; } @@ -56,7 +56,6 @@ public: ColorRampEditorPlugin(EditorNode *p_node); ~ColorRampEditorPlugin(); - }; #endif /* TOOLS_EDITOR_PLUGINS_COLOR_RAMP_EDITOR_PLUGIN_H_ */ diff --git a/editor/plugins/cube_grid_theme_editor_plugin.cpp b/editor/plugins/cube_grid_theme_editor_plugin.cpp index b8abd2e9cc..e73a9b31af 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.cpp +++ b/editor/plugins/cube_grid_theme_editor_plugin.cpp @@ -29,14 +29,14 @@ #include "cube_grid_theme_editor_plugin.h" #if 0 +#include "editor/editor_node.h" +#include "editor/editor_settings.h" +#include "main/main.h" #include "scene/3d/mesh_instance.h" +#include "scene/3d/navigation_mesh.h" #include "scene/3d/physics_body.h" #include "scene/main/viewport.h" #include "scene/resources/packed_scene.h" -#include "editor/editor_node.h" -#include "main/main.h" -#include "editor/editor_settings.h" -#include "scene/3d/navigation_mesh.h" void MeshLibraryEditor::edit(const Ref& p_theme) { diff --git a/editor/plugins/cube_grid_theme_editor_plugin.h b/editor/plugins/cube_grid_theme_editor_plugin.h index 07e7c7cadd..af3929e616 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.h +++ b/editor/plugins/cube_grid_theme_editor_plugin.h @@ -29,8 +29,8 @@ #ifndef CUBE_GRID_THEME_EDITOR_PLUGIN_H #define CUBE_GRID_THEME_EDITOR_PLUGIN_H -#include "scene/resources/mesh_library.h" #include "editor/editor_node.h" +#include "scene/resources/mesh_library.h" #if 0 class MeshLibraryEditor : public Control { @@ -91,6 +91,5 @@ public: }; - #endif // CUBE_GRID_THEME_EDITOR_PLUGIN_H #endif diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 3f31f1e0f1..eaadf3976b 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -28,15 +28,15 @@ /*************************************************************************/ #include "editor_preview_plugins.h" -#include "io/resource_loader.h" #include "editor/editor_settings.h" #include "io/file_access_memory.h" +#include "io/resource_loader.h" #include "os/os.h" #include "scene/resources/material.h" //#include "scene/resources/sample.h" -#include "scene/resources/mesh.h" -#include "scene/resources/bit_mask.h" #include "editor/editor_scale.h" +#include "scene/resources/bit_mask.h" +#include "scene/resources/mesh.h" #if 0 bool EditorTexturePreviewPlugin::handles(const String& p_type) const { @@ -345,21 +345,23 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { Vector3(x0 * zr0, z0, y0 *zr0) }; -#define ADD_POINT(m_idx) \ - normals.push_back(v[m_idx]);\ - vertices.push_back(v[m_idx]*radius);\ - { Vector2 uv(Math::atan2(v[m_idx].x,v[m_idx].z),Math::atan2(-v[m_idx].y,v[m_idx].z));\ - uv/=Math_PI;\ - uv*=4.0;\ - uv=uv*0.5+Vector2(0.5,0.5);\ - uvs.push_back(uv);\ - }\ - { Vector3 t = tt.xform(v[m_idx]);\ - tangents.push_back(t.x);\ - tangents.push_back(t.y);\ - tangents.push_back(t.z);\ - tangents.push_back(1.0);\ - } +#define ADD_POINT(m_idx) \ + normals.push_back(v[m_idx]); \ + vertices.push_back(v[m_idx] * radius); \ + { \ + Vector2 uv(Math::atan2(v[m_idx].x, v[m_idx].z), Math::atan2(-v[m_idx].y, v[m_idx].z)); \ + uv /= Math_PI; \ + uv *= 4.0; \ + uv = uv * 0.5 + Vector2(0.5, 0.5); \ + uvs.push_back(uv); \ + } \ + { \ + Vector3 t = tt.xform(v[m_idx]); \ + tangents.push_back(t.x); \ + tangents.push_back(t.y); \ + tangents.push_back(t.z); \ + tangents.push_back(1.0); \ + } diff --git a/editor/plugins/gi_probe_editor_plugin.cpp b/editor/plugins/gi_probe_editor_plugin.cpp index 925ac8ef11..0930c91e94 100644 --- a/editor/plugins/gi_probe_editor_plugin.cpp +++ b/editor/plugins/gi_probe_editor_plugin.cpp @@ -28,7 +28,6 @@ /*************************************************************************/ #include "gi_probe_editor_plugin.h" - void GIProbeEditorPlugin::_bake() { if (gi_probe) { @@ -36,14 +35,13 @@ void GIProbeEditorPlugin::_bake() { } } - void GIProbeEditorPlugin::edit(Object *p_object) { - GIProbe * s = p_object->cast_to(); + GIProbe *s = p_object->cast_to(); if (!s) return; - gi_probe=s; + gi_probe = s; } bool GIProbeEditorPlugin::handles(Object *p_object) const { @@ -59,25 +57,23 @@ void GIProbeEditorPlugin::make_visible(bool p_visible) { bake->hide(); } - } void GIProbeEditorPlugin::_bind_methods() { - ClassDB::bind_method("_bake",&GIProbeEditorPlugin::_bake); + ClassDB::bind_method("_bake", &GIProbeEditorPlugin::_bake); } GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) { - editor=p_node; - bake = memnew( Button ); - bake->set_icon(editor->get_gui_base()->get_icon("BakedLight","EditorIcons")); + editor = p_node; + bake = memnew(Button); + bake->set_icon(editor->get_gui_base()->get_icon("BakedLight", "EditorIcons")); bake->hide(); - bake->connect("pressed",this,"_bake"); - add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU,bake); - gi_probe=NULL; + bake->connect("pressed", this, "_bake"); + add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake); + gi_probe = NULL; } - GIProbeEditorPlugin::~GIProbeEditorPlugin() { } diff --git a/editor/plugins/gi_probe_editor_plugin.h b/editor/plugins/gi_probe_editor_plugin.h index 982a549368..14d831a01a 100644 --- a/editor/plugins/gi_probe_editor_plugin.h +++ b/editor/plugins/gi_probe_editor_plugin.h @@ -29,16 +29,14 @@ #ifndef GIPROBEEDITORPLUGIN_H #define GIPROBEEDITORPLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "scene/resources/material.h" +#include "editor/editor_plugin.h" #include "scene/3d/gi_probe.h" - - +#include "scene/resources/material.h" class GIProbeEditorPlugin : public EditorPlugin { - GDCLASS( GIProbeEditorPlugin, EditorPlugin ); + GDCLASS(GIProbeEditorPlugin, EditorPlugin); GIProbe *gi_probe; @@ -46,11 +44,11 @@ class GIProbeEditorPlugin : public EditorPlugin { EditorNode *editor; void _bake(); -protected: +protected: static void _bind_methods(); -public: +public: virtual String get_name() const { return "GIProbe"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -59,7 +57,6 @@ public: GIProbeEditorPlugin(EditorNode *p_node); ~GIProbeEditorPlugin(); - }; #endif // GIPROBEEDITORPLUGIN_H diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp index f31074a9dc..fabbf07a15 100644 --- a/editor/plugins/item_list_editor_plugin.cpp +++ b/editor/plugins/item_list_editor_plugin.cpp @@ -30,81 +30,81 @@ #include "io/resource_loader.h" -bool ItemListPlugin::_set(const StringName& p_name, const Variant& p_value) { +bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; - int idx = name.get_slice("/",0).to_int(); - String what=name.get_slice("/",1); - - if (what=="text") - set_item_text(idx,p_value); - else if (what=="icon") - set_item_icon(idx,p_value); - else if (what=="checkable") - set_item_checkable(idx,p_value); - else if (what=="checked") - set_item_checked(idx,p_value); - else if (what=="id") - set_item_id(idx,p_value); - else if (what=="enabled") - set_item_enabled(idx,p_value); - else if (what=="separator") - set_item_separator(idx,p_value); + int idx = name.get_slice("/", 0).to_int(); + String what = name.get_slice("/", 1); + + if (what == "text") + set_item_text(idx, p_value); + else if (what == "icon") + set_item_icon(idx, p_value); + else if (what == "checkable") + set_item_checkable(idx, p_value); + else if (what == "checked") + set_item_checked(idx, p_value); + else if (what == "id") + set_item_id(idx, p_value); + else if (what == "enabled") + set_item_enabled(idx, p_value); + else if (what == "separator") + set_item_separator(idx, p_value); else return false; return true; } -bool ItemListPlugin::_get(const StringName& p_name,Variant &r_ret) const { +bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; - int idx = name.get_slice("/",0).to_int(); - String what=name.get_slice("/",1); - - if (what=="text") - r_ret=get_item_text(idx); - else if (what=="icon") - r_ret=get_item_icon(idx); - else if (what=="checkable") - r_ret=is_item_checkable(idx); - else if (what=="checked") - r_ret=is_item_checked(idx); - else if (what=="id") - r_ret=get_item_id(idx); - else if (what=="enabled") - r_ret=is_item_enabled(idx); - else if (what=="separator") - r_ret=is_item_separator(idx); + int idx = name.get_slice("/", 0).to_int(); + String what = name.get_slice("/", 1); + + if (what == "text") + r_ret = get_item_text(idx); + else if (what == "icon") + r_ret = get_item_icon(idx); + else if (what == "checkable") + r_ret = is_item_checkable(idx); + else if (what == "checked") + r_ret = is_item_checked(idx); + else if (what == "id") + r_ret = get_item_id(idx); + else if (what == "enabled") + r_ret = is_item_enabled(idx); + else if (what == "separator") + r_ret = is_item_separator(idx); else return false; return true; } -void ItemListPlugin::_get_property_list( List *p_list) const { +void ItemListPlugin::_get_property_list(List *p_list) const { - for(int i=0;ipush_back( PropertyInfo(Variant::STRING,base+"text") ); - p_list->push_back( PropertyInfo(Variant::OBJECT,base+"icon",PROPERTY_HINT_RESOURCE_TYPE,"Texture") ); + p_list->push_back(PropertyInfo(Variant::STRING, base + "text")); + p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture")); int flags = get_flags(); - if (flags&FLAG_CHECKABLE) { - p_list->push_back( PropertyInfo(Variant::BOOL,base+"checkable") ); - p_list->push_back( PropertyInfo(Variant::BOOL,base+"checked") ); + if (flags & FLAG_CHECKABLE) { + p_list->push_back(PropertyInfo(Variant::BOOL, base + "checkable")); + p_list->push_back(PropertyInfo(Variant::BOOL, base + "checked")); } - if (flags&FLAG_ID) - p_list->push_back( PropertyInfo(Variant::INT,base+"id",PROPERTY_HINT_RANGE,"-1,4096") ); + if (flags & FLAG_ID) + p_list->push_back(PropertyInfo(Variant::INT, base + "id", PROPERTY_HINT_RANGE, "-1,4096")); - if (flags&FLAG_ENABLE) - p_list->push_back( PropertyInfo(Variant::BOOL,base+"enabled") ); + if (flags & FLAG_ENABLE) + p_list->push_back(PropertyInfo(Variant::BOOL, base + "enabled")); - if (flags&FLAG_SEPARATOR) - p_list->push_back( PropertyInfo(Variant::BOOL,base+"separator") ); + if (flags & FLAG_SEPARATOR) + p_list->push_back(PropertyInfo(Variant::BOOL, base + "separator")); } } @@ -124,12 +124,12 @@ bool ItemListOptionButtonPlugin::handles(Object *p_object) const { int ItemListOptionButtonPlugin::get_flags() const { - return FLAG_ICON|FLAG_ID|FLAG_ENABLE; + return FLAG_ICON | FLAG_ID | FLAG_ENABLE; } void ItemListOptionButtonPlugin::add_item() { - ob->add_item( vformat(TTR("Item %d"),ob->get_item_count())); + ob->add_item(vformat(TTR("Item %d"), ob->get_item_count())); _change_notify(); } @@ -146,7 +146,7 @@ void ItemListOptionButtonPlugin::erase(int p_idx) { ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() { - ob=NULL; + ob = NULL; } /////////////////////////////////////////////////////////////// @@ -166,12 +166,12 @@ bool ItemListPopupMenuPlugin::handles(Object *p_object) const { int ItemListPopupMenuPlugin::get_flags() const { - return FLAG_ICON|FLAG_CHECKABLE|FLAG_ID|FLAG_ENABLE|FLAG_SEPARATOR; + return FLAG_ICON | FLAG_CHECKABLE | FLAG_ID | FLAG_ENABLE | FLAG_SEPARATOR; } void ItemListPopupMenuPlugin::add_item() { - pp->add_item( vformat(TTR("Item %d"),pp->get_item_count())); + pp->add_item(vformat(TTR("Item %d"), pp->get_item_count())); _change_notify(); } @@ -188,7 +188,7 @@ void ItemListPopupMenuPlugin::erase(int p_idx) { ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() { - pp=NULL; + pp = NULL; } /////////////////////////////////////////////////////////////// @@ -197,8 +197,8 @@ ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() { void ItemListEditor::_node_removed(Node *p_node) { - if(p_node==item_list) { - item_list=NULL; + if (p_node == item_list) { + item_list = NULL; hide(); dialog->hide(); } @@ -206,16 +206,16 @@ void ItemListEditor::_node_removed(Node *p_node) { void ItemListEditor::_notification(int p_notification) { - if (p_notification==NOTIFICATION_ENTER_TREE) { + if (p_notification == NOTIFICATION_ENTER_TREE) { - add_button->set_icon(get_icon("Add","EditorIcons")); - del_button->set_icon(get_icon("Remove","EditorIcons")); + add_button->set_icon(get_icon("Add", "EditorIcons")); + del_button->set_icon(get_icon("Remove", "EditorIcons")); } } void ItemListEditor::_add_pressed() { - if (selected_idx==-1) + if (selected_idx == -1) return; item_plugins[selected_idx]->add_item(); @@ -228,12 +228,12 @@ void ItemListEditor::_delete_pressed() { if (!ti) return; - if (ti->get_parent()!=tree->get_root()) + if (ti->get_parent() != tree->get_root()) return; int idx = ti->get_text(0).to_int(); - if (selected_idx==-1) + if (selected_idx == -1) return; item_plugins[selected_idx]->erase(idx); @@ -246,15 +246,15 @@ void ItemListEditor::_edit_items() { void ItemListEditor::edit(Node *p_item_list) { - item_list=p_item_list; + item_list = p_item_list; if (!item_list) { - selected_idx=-1; + selected_idx = -1; property_editor->edit(NULL); return; } - for(int i=0;ihandles(p_item_list)) { item_plugins[i]->set_object(p_item_list); @@ -265,18 +265,18 @@ void ItemListEditor::edit(Node *p_item_list) { else toolbar_button->set_icon(Ref()); - selected_idx=i; + selected_idx = i; return; } } - selected_idx=-1; + selected_idx = -1; property_editor->edit(NULL); } bool ItemListEditor::handles(Object *p_object) const { - for(int i=0;ihandles(p_object)) { return true; } @@ -287,47 +287,47 @@ bool ItemListEditor::handles(Object *p_object) const { void ItemListEditor::_bind_methods() { - ClassDB::bind_method("_edit_items",&ItemListEditor::_edit_items); - ClassDB::bind_method("_add_button",&ItemListEditor::_add_pressed); - ClassDB::bind_method("_delete_button",&ItemListEditor::_delete_pressed); + ClassDB::bind_method("_edit_items", &ItemListEditor::_edit_items); + ClassDB::bind_method("_add_button", &ItemListEditor::_add_pressed); + ClassDB::bind_method("_delete_button", &ItemListEditor::_delete_pressed); } ItemListEditor::ItemListEditor() { - selected_idx=-1; + selected_idx = -1; - add_child( memnew( VSeparator ) ); + add_child(memnew(VSeparator)); - toolbar_button = memnew( ToolButton ); + toolbar_button = memnew(ToolButton); toolbar_button->set_text(TTR("Items")); add_child(toolbar_button); - toolbar_button->connect("pressed",this,"_edit_items"); + toolbar_button->connect("pressed", this, "_edit_items"); - dialog = memnew( AcceptDialog ); + dialog = memnew(AcceptDialog); dialog->set_title(TTR("Item List Editor")); - add_child( dialog ); + add_child(dialog); - VBoxContainer *vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew(VBoxContainer); dialog->add_child(vbc); //dialog->set_child_rect(vbc); - HBoxContainer *hbc = memnew( HBoxContainer ); + HBoxContainer *hbc = memnew(HBoxContainer); hbc->set_h_size_flags(SIZE_EXPAND_FILL); vbc->add_child(hbc); - add_button = memnew( Button ); + add_button = memnew(Button); add_button->set_text(TTR("Add")); hbc->add_child(add_button); - add_button->connect("pressed",this,"_add_button"); + add_button->connect("pressed", this, "_add_button"); hbc->add_spacer(); - del_button = memnew( Button ); + del_button = memnew(Button); del_button->set_text(TTR("Delete")); hbc->add_child(del_button); - del_button->connect("pressed",this,"_delete_button"); + del_button->connect("pressed", this, "_delete_button"); - property_editor = memnew( PropertyEditor ); + property_editor = memnew(PropertyEditor); property_editor->hide_top_label(); property_editor->set_subsection_selectable(true); vbc->add_child(property_editor); @@ -338,8 +338,8 @@ ItemListEditor::ItemListEditor() { ItemListEditor::~ItemListEditor() { - for(int i=0;iadd_control_to_menu_panel(item_list_editor); item_list_editor->hide(); - item_list_editor->add_plugin( memnew( ItemListOptionButtonPlugin ) ); - item_list_editor->add_plugin( memnew( ItemListPopupMenuPlugin ) ); + item_list_editor->add_plugin(memnew(ItemListOptionButtonPlugin)); + item_list_editor->add_plugin(memnew(ItemListPopupMenuPlugin)); } -ItemListEditorPlugin::~ItemListEditorPlugin() -{ +ItemListEditorPlugin::~ItemListEditorPlugin() { } - - diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h index 25d6ed6757..064c43bda5 100644 --- a/editor/plugins/item_list_editor_plugin.h +++ b/editor/plugins/item_list_editor_plugin.h @@ -29,69 +29,66 @@ #ifndef ITEM_LIST_EDITOR_PLUGIN_H #define ITEM_LIST_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" -#include "editor/editor_node.h" #include "canvas_item_editor_plugin.h" +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" -#include "scene/gui/option_button.h" #include "scene/gui/menu_button.h" +#include "scene/gui/option_button.h" #include "scene/gui/popup_menu.h" /** @author Juan Linietsky */ - class ItemListPlugin : public Object { - GDCLASS(ItemListPlugin,Object); + GDCLASS(ItemListPlugin, Object); protected: - - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list( List *p_list) const; + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; public: - enum Flags { - FLAG_ICON=1, - FLAG_CHECKABLE=2, - FLAG_ID=4, - FLAG_ENABLE=8, - FLAG_SEPARATOR=16 + FLAG_ICON = 1, + FLAG_CHECKABLE = 2, + FLAG_ID = 4, + FLAG_ENABLE = 8, + FLAG_SEPARATOR = 16 }; - virtual void set_object(Object *p_object)=0; - virtual bool handles(Object *p_object) const=0; + virtual void set_object(Object *p_object) = 0; + virtual bool handles(Object *p_object) const = 0; - virtual int get_flags() const=0; + virtual int get_flags() const = 0; - virtual void set_item_text(int p_idx, const String& p_text) {} - virtual String get_item_text(int p_idx) const{ return ""; }; + virtual void set_item_text(int p_idx, const String &p_text) {} + virtual String get_item_text(int p_idx) const { return ""; }; - virtual void set_item_icon(int p_idx, const Ref& p_tex) {} - virtual Ref get_item_icon(int p_idx) const{ return Ref(); }; + virtual void set_item_icon(int p_idx, const Ref &p_tex) {} + virtual Ref get_item_icon(int p_idx) const { return Ref(); }; virtual void set_item_checkable(int p_idx, bool p_check) {} - virtual bool is_item_checkable(int p_idx) const{ return false; }; + virtual bool is_item_checkable(int p_idx) const { return false; }; virtual void set_item_checked(int p_idx, bool p_checked) {} - virtual bool is_item_checked(int p_idx) const{ return false; }; + virtual bool is_item_checked(int p_idx) const { return false; }; virtual void set_item_enabled(int p_idx, int p_enabled) {} - virtual bool is_item_enabled(int p_idx) const{ return false; }; + virtual bool is_item_enabled(int p_idx) const { return false; }; virtual void set_item_id(int p_idx, int p_id) {} - virtual int get_item_id(int p_idx) const{ return -1; }; + virtual int get_item_id(int p_idx) const { return -1; }; virtual void set_item_separator(int p_idx, bool p_separator) {} virtual bool is_item_separator(int p_idx) const { return false; }; - virtual void add_item()=0; - virtual int get_item_count() const=0; - virtual void erase(int p_idx)=0; + virtual void add_item() = 0; + virtual int get_item_count() const = 0; + virtual void erase(int p_idx) = 0; ItemListPlugin() {} }; @@ -100,25 +97,25 @@ public: class ItemListOptionButtonPlugin : public ItemListPlugin { - GDCLASS(ItemListOptionButtonPlugin,ItemListPlugin); + GDCLASS(ItemListOptionButtonPlugin, ItemListPlugin); OptionButton *ob; -public: +public: virtual void set_object(Object *p_object); virtual bool handles(Object *p_object) const; virtual int get_flags() const; - virtual void set_item_text(int p_idx, const String& p_text) { ob->set_item_text(p_idx,p_text); } + virtual void set_item_text(int p_idx, const String &p_text) { ob->set_item_text(p_idx, p_text); } virtual String get_item_text(int p_idx) const { return ob->get_item_text(p_idx); } - virtual void set_item_icon(int p_idx, const Ref& p_tex) { ob->set_item_icon(p_idx, p_tex); } + virtual void set_item_icon(int p_idx, const Ref &p_tex) { ob->set_item_icon(p_idx, p_tex); } virtual Ref get_item_icon(int p_idx) const { return ob->get_item_icon(p_idx); } virtual void set_item_enabled(int p_idx, int p_enabled) { ob->set_item_disabled(p_idx, !p_enabled); } virtual bool is_item_enabled(int p_idx) const { return !ob->is_item_disabled(p_idx); } - virtual void set_item_id(int p_idx, int p_id) { ob->set_item_ID(p_idx,p_id); } + virtual void set_item_id(int p_idx, int p_id) { ob->set_item_ID(p_idx, p_id); } virtual int get_item_id(int p_idx) const { return ob->get_item_ID(p_idx); } virtual void add_item(); @@ -130,34 +127,34 @@ public: class ItemListPopupMenuPlugin : public ItemListPlugin { - GDCLASS(ItemListPopupMenuPlugin,ItemListPlugin); + GDCLASS(ItemListPopupMenuPlugin, ItemListPlugin); PopupMenu *pp; -public: +public: virtual void set_object(Object *p_object); virtual bool handles(Object *p_object) const; virtual int get_flags() const; - virtual void set_item_text(int p_idx, const String& p_text) { pp->set_item_text(p_idx,p_text); } + virtual void set_item_text(int p_idx, const String &p_text) { pp->set_item_text(p_idx, p_text); } virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); } - virtual void set_item_icon(int p_idx, const Ref& p_tex) { pp->set_item_icon(p_idx,p_tex); } + virtual void set_item_icon(int p_idx, const Ref &p_tex) { pp->set_item_icon(p_idx, p_tex); } virtual Ref get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); } - virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx,p_check); } + virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx, p_check); } virtual bool is_item_checkable(int p_idx) const { return pp->is_item_checkable(p_idx); } - virtual void set_item_checked(int p_idx, bool p_checked) { pp->set_item_checked(p_idx,p_checked); } + virtual void set_item_checked(int p_idx, bool p_checked) { pp->set_item_checked(p_idx, p_checked); } virtual bool is_item_checked(int p_idx) const { return pp->is_item_checked(p_idx); } - virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx,!p_enabled); } + virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx, !p_enabled); } virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); } - virtual void set_item_id(int p_idx, int p_id) { pp->set_item_ID(p_idx,p_idx); } + virtual void set_item_id(int p_idx, int p_id) { pp->set_item_ID(p_idx, p_idx); } virtual int get_item_id(int p_idx) const { return pp->get_item_ID(p_idx); } - virtual void set_item_separator(int p_idx, bool p_separator) { pp->set_item_as_separator(p_idx,p_separator); } + virtual void set_item_separator(int p_idx, bool p_separator) { pp->set_item_as_separator(p_idx, p_separator); } virtual bool is_item_separator(int p_idx) const { return pp->is_item_separator(p_idx); } virtual void add_item(); @@ -171,7 +168,7 @@ public: class ItemListEditor : public HBoxContainer { - GDCLASS(ItemListEditor,HBoxContainer); + GDCLASS(ItemListEditor, HBoxContainer); Node *item_list; @@ -185,7 +182,7 @@ class ItemListEditor : public HBoxContainer { int selected_idx; - Vector item_plugins; + Vector item_plugins; void _edit_items(); @@ -195,27 +192,25 @@ class ItemListEditor : public HBoxContainer { void _node_removed(Node *p_node); protected: - void _notification(int p_notification); static void _bind_methods(); -public: +public: void edit(Node *p_item_list); bool handles(Object *p_object) const; - void add_plugin(ItemListPlugin* p_plugin) { item_plugins.push_back(p_plugin); } + void add_plugin(ItemListPlugin *p_plugin) { item_plugins.push_back(p_plugin); } ItemListEditor(); ~ItemListEditor(); }; class ItemListEditorPlugin : public EditorPlugin { - GDCLASS(ItemListEditorPlugin,EditorPlugin); + GDCLASS(ItemListEditorPlugin, EditorPlugin); ItemListEditor *item_list_editor; EditorNode *editor; public: - virtual String get_name() const { return "ItemList"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -224,7 +219,6 @@ public: ItemListEditorPlugin(EditorNode *p_node); ~ItemListEditorPlugin(); - }; #endif // ITEM_LIST_EDITOR_PLUGIN_H diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp index be9e52e241..6db25e8455 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -29,208 +29,193 @@ #include "light_occluder_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "os/file_access.h" #include "editor/editor_settings.h" +#include "os/file_access.h" void LightOccluder2DEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_READY: { - button_create->set_icon( get_icon("Edit","EditorIcons")); - button_edit->set_icon( get_icon("MovePoint","EditorIcons")); + button_create->set_icon(get_icon("Edit", "EditorIcons")); + button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); button_edit->set_pressed(true); - get_tree()->connect("node_removed",this,"_node_removed"); - create_poly->connect("confirmed",this,"_create_poly"); + get_tree()->connect("node_removed", this, "_node_removed"); + create_poly->connect("confirmed", this, "_create_poly"); } break; case NOTIFICATION_FIXED_PROCESS: { - } break; } - } void LightOccluder2DEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); canvas_item_editor->get_viewport_control()->update(); } - } - void LightOccluder2DEditor::_menu_option(int p_option) { - switch(p_option) { + switch (p_option) { case MODE_CREATE: { - mode=MODE_CREATE; + mode = MODE_CREATE; button_create->set_pressed(true); button_edit->set_pressed(false); } break; case MODE_EDIT: { - mode=MODE_EDIT; + mode = MODE_EDIT; button_create->set_pressed(false); button_edit->set_pressed(true); } break; - } } void LightOccluder2DEditor::_wip_close(bool p_closed) { undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",node->get_occluder_polygon()->get_polygon()); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",wip); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_closed",node->get_occluder_polygon()->is_closed()); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_closed",p_closed); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", node->get_occluder_polygon()->get_polygon()); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", wip); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_closed", node->get_occluder_polygon()->is_closed()); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_closed", p_closed); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); wip.clear(); - wip_active=false; - mode=MODE_EDIT; + wip_active = false; + mode = MODE_EDIT; button_edit->set_pressed(true); button_create->set_pressed(false); - edited_point=-1; + edited_point = -1; } -bool LightOccluder2DEditor::forward_gui_input(const InputEvent& p_event) { - +bool LightOccluder2DEditor::forward_gui_input(const InputEvent &p_event) { if (!node) return false; if (node->get_occluder_polygon().is_null()) { - if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) { create_poly->set_text("No OccluderPolygon2D resource on this node.\nCreate and assign one?"); create_poly->popup_centered_minsize(); } - return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1); + return (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1); } - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - const InputEventMouseButton &mb=p_event.mouse_button; + const InputEventMouseButton &mb = p_event.mouse_button; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = Point2(mb.x,mb.y); + Vector2 gpoint = Point2(mb.x, mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); Vector poly = Variant(node->get_occluder_polygon()->get_polygon()); //first check if a point is to be added (segment split) - real_t grab_treshold=EDITOR_DEF("editors/poly_editor/point_grab_radius",8); - - switch(mode) { + real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + switch (mode) { case MODE_CREATE: { - if (mb.button_index==BUTTON_LEFT && mb.pressed) { - + if (mb.button_index == BUTTON_LEFT && mb.pressed) { if (!wip_active) { wip.clear(); - wip.push_back( cpoint ); - wip_active=true; - edited_point_pos=cpoint; + wip.push_back(cpoint); + wip_active = true; + edited_point_pos = cpoint; canvas_item_editor->get_viewport_control()->update(); - edited_point=1; + edited_point = 1; return true; } else { - - if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint) 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) { //wip closed _wip_close(true); return true; - } else if (wip.size()>1 && xform.xform(wip[wip.size()-1]).distance_to(gpoint) 1 && xform.xform(wip[wip.size() - 1]).distance_to(gpoint) < grab_treshold) { + //wip closed + _wip_close(false); + return true; } else { - wip.push_back( cpoint ); - edited_point=wip.size(); + wip.push_back(cpoint); + edited_point = wip.size(); canvas_item_editor->get_viewport_control()->update(); return true; //add wip point } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) { _wip_close(true); } - - } break; case MODE_EDIT: { - if (mb.button_index==BUTTON_LEFT) { + if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { if (mb.mod.control) { - if (poly.size() < 3) { undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); poly.push_back(cpoint); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return true; } //search edges - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;i=0) { + if (closest_idx >= 0) { - pre_move_edit=poly; - poly.insert(closest_idx+1,xform.affine_inverse().xform(closest_pos)); - edited_point=closest_idx+1; - edited_point_pos=xform.affine_inverse().xform(closest_pos); + pre_move_edit = poly; + poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos)); + edited_point = closest_idx + 1; + edited_point_pos = xform.affine_inverse().xform(closest_pos); node->get_occluder_polygon()->set_polygon(Variant(poly)); canvas_item_editor->get_viewport_control()->update(); return true; @@ -239,106 +224,95 @@ bool LightOccluder2DEditor::forward_gui_input(const InputEvent& p_event) { //look for points to move - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;i=0) { + if (closest_idx >= 0) { - pre_move_edit=poly; - edited_point=closest_idx; - edited_point_pos=xform.affine_inverse().xform(closest_pos); + pre_move_edit = poly; + edited_point = closest_idx; + edited_point_pos = xform.affine_inverse().xform(closest_pos); canvas_item_editor->get_viewport_control()->update(); return true; } } } else { - if (edited_point!=-1) { + if (edited_point != -1) { //apply - ERR_FAIL_INDEX_V(edited_point,poly.size(),false); - poly[edited_point]=edited_point_pos; + ERR_FAIL_INDEX_V(edited_point, poly.size(), false); + poly[edited_point] = edited_point_pos; undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",pre_move_edit); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", pre_move_edit); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); - edited_point=-1; + edited_point = -1; return true; } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) { - - - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;i=0) { - + if (closest_idx >= 0) { undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); poly.remove(closest_idx); - undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return true; } - } - - } break; } - - } break; case InputEvent::MOUSE_MOTION: { - const InputEventMouseMotion &mm=p_event.mouse_motion; + const InputEventMouseMotion &mm = p_event.mouse_motion; - if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { + if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) { - Vector2 gpoint = Point2(mm.x,mm.y); + Vector2 gpoint = Point2(mm.x, mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); - } } break; @@ -356,111 +330,102 @@ void LightOccluder2DEditor::_canvas_draw() { Vector poly; if (wip_active) - poly=wip; + poly = wip; else - poly=Variant(node->get_occluder_polygon()->get_polygon()); - + poly = Variant(node->get_occluder_polygon()->get_polygon()); Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref handle= get_icon("EditorHandle","EditorIcons"); - - for(int i=0;i handle = get_icon("EditorHandle", "EditorIcons"); + for (int i = 0; i < poly.size(); i++) { - Vector2 p,p2; - p = i==edited_point ? edited_point_pos : poly[i]; - if ((wip_active && i==poly.size()-1) || (((i+1)%poly.size())==edited_point)) - p2=edited_point_pos; + Vector2 p, p2; + p = i == edited_point ? edited_point_pos : poly[i]; + if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) + p2 = edited_point_pos; else - p2 = poly[(i+1)%poly.size()]; + p2 = poly[(i + 1) % poly.size()]; Vector2 point = xform.xform(p); Vector2 next_point = xform.xform(p2); - Color col=Color(1,0.3,0.1,0.8); + Color col = Color(1, 0.3, 0.1, 0.8); - if (i==poly.size()-1 && (!node->get_occluder_polygon()->is_closed() || wip_active)) { + if (i == poly.size() - 1 && (!node->get_occluder_polygon()->is_closed() || wip_active)) { } else { - vpc->draw_line(point,next_point,col,2); + vpc->draw_line(point, next_point, col, 2); } - vpc->draw_texture(handle,point-handle->get_size()*0.5); + vpc->draw_texture(handle, point - handle->get_size() * 0.5); } } - - void LightOccluder2DEditor::edit(Node *p_collision_polygon) { if (!canvas_item_editor) { - canvas_item_editor=CanvasItemEditor::get_singleton(); + canvas_item_editor = CanvasItemEditor::get_singleton(); } if (p_collision_polygon) { - node=p_collision_polygon->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"); + node = p_collision_polygon->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"); wip.clear(); - wip_active=false; - edited_point=-1; + wip_active = false; + edited_point = -1; canvas_item_editor->get_viewport_control()->update(); } else { - node=NULL; - - 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; + if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); } - } -void LightOccluder2DEditor::_create_poly() { +void LightOccluder2DEditor::_create_poly() { if (!node) return; undo_redo->create_action(TTR("Create Occluder Polygon")); - undo_redo->add_do_method(node,"set_occluder_polygon",Ref(memnew( OccluderPolygon2D))); - undo_redo->add_undo_method(node,"set_occluder_polygon",Variant(REF())); + undo_redo->add_do_method(node, "set_occluder_polygon", Ref(memnew(OccluderPolygon2D))); + undo_redo->add_undo_method(node, "set_occluder_polygon", Variant(REF())); undo_redo->commit_action(); } void LightOccluder2DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_option"),&LightOccluder2DEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"),&LightOccluder2DEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_node_removed"),&LightOccluder2DEditor::_node_removed); - ClassDB::bind_method(D_METHOD("_create_poly"),&LightOccluder2DEditor::_create_poly); - + ClassDB::bind_method(D_METHOD("_menu_option"), &LightOccluder2DEditor::_menu_option); + ClassDB::bind_method(D_METHOD("_canvas_draw"), &LightOccluder2DEditor::_canvas_draw); + ClassDB::bind_method(D_METHOD("_node_removed"), &LightOccluder2DEditor::_node_removed); + ClassDB::bind_method(D_METHOD("_create_poly"), &LightOccluder2DEditor::_create_poly); } - LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) { - node=NULL; - canvas_item_editor=NULL; - editor=p_editor; + node = NULL; + canvas_item_editor = NULL; + editor = p_editor; undo_redo = editor->get_undo_redo(); - add_child( memnew( VSeparator )); - button_create = memnew( ToolButton ); + add_child(memnew(VSeparator)); + button_create = memnew(ToolButton); add_child(button_create); - button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE)); + button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); button_create->set_toggle_mode(true); button_create->set_tooltip(TTR("Create a new polygon from scratch.")); - button_edit = memnew( ToolButton ); + button_edit = memnew(ToolButton); add_child(button_edit); - button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT)); + button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); button_edit->set_toggle_mode(true); - button_edit->set_tooltip(TTR("Edit existing polygon:")+"\n"+TTR("LMB: Move Point.")+"\n"+TTR("Ctrl+LMB: Split Segment.")+"\n"+TTR("RMB: Erase Point.")); + button_edit->set_tooltip(TTR("Edit existing polygon:") + "\n" + TTR("LMB: Move Point.") + "\n" + TTR("Ctrl+LMB: Split Segment.") + "\n" + TTR("RMB: Erase Point.")); - create_poly = memnew( ConfirmationDialog ); + create_poly = memnew(ConfirmationDialog); add_child(create_poly); create_poly->get_ok()->set_text(TTR("Create")); - - //add_constant_override("separation",0); +//add_constant_override("separation",0); #if 0 options = memnew( MenuButton ); @@ -472,11 +437,9 @@ LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) { #endif mode = MODE_EDIT; - wip_active=false; - + wip_active = false; } - void LightOccluder2DEditorPlugin::edit(Object *p_object) { collision_polygon_editor->edit(p_object->cast_to()); @@ -496,23 +459,16 @@ void LightOccluder2DEditorPlugin::make_visible(bool p_visible) { collision_polygon_editor->hide(); collision_polygon_editor->edit(NULL); } - } LightOccluder2DEditorPlugin::LightOccluder2DEditorPlugin(EditorNode *p_node) { - editor=p_node; - collision_polygon_editor = memnew( LightOccluder2DEditor(p_node) ); + editor = p_node; + collision_polygon_editor = memnew(LightOccluder2DEditor(p_node)); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); collision_polygon_editor->hide(); - - - } - -LightOccluder2DEditorPlugin::~LightOccluder2DEditorPlugin() -{ +LightOccluder2DEditorPlugin::~LightOccluder2DEditorPlugin() { } - diff --git a/editor/plugins/light_occluder_2d_editor_plugin.h b/editor/plugins/light_occluder_2d_editor_plugin.h index 1f1c6e86eb..68e5e3f729 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.h +++ b/editor/plugins/light_occluder_2d_editor_plugin.h @@ -29,13 +29,11 @@ #ifndef LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H #define LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H - - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/light_occluder_2d.h" -#include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" +#include "scene/gui/tool_button.h" /** @author Juan Linietsky @@ -44,7 +42,7 @@ class CanvasItemEditor; class LightOccluder2DEditor : public HBoxContainer { - GDCLASS(LightOccluder2DEditor, HBoxContainer ); + GDCLASS(LightOccluder2DEditor, HBoxContainer); UndoRedo *undo_redo; enum Mode { @@ -82,24 +80,23 @@ protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); -public: - Vector2 snap_point(const Vector2& p_point) const; - bool forward_gui_input(const InputEvent& p_event); +public: + Vector2 snap_point(const Vector2 &p_point) const; + bool forward_gui_input(const InputEvent &p_event); void edit(Node *p_collision_polygon); LightOccluder2DEditor(EditorNode *p_editor); }; class LightOccluder2DEditorPlugin : public EditorPlugin { - GDCLASS( LightOccluder2DEditorPlugin, EditorPlugin ); + GDCLASS(LightOccluder2DEditorPlugin, EditorPlugin); LightOccluder2DEditor *collision_polygon_editor; EditorNode *editor; public: - - virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); } + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); } virtual String get_name() const { return "LightOccluder2D"; } bool has_main_screen() const { return false; } @@ -109,7 +106,6 @@ public: LightOccluder2DEditorPlugin(EditorNode *p_node); ~LightOccluder2DEditorPlugin(); - }; #endif // LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/line_2d_editor_plugin.cpp b/editor/plugins/line_2d_editor_plugin.cpp index 4a0f90a2b4..b3afe0bb93 100644 --- a/editor/plugins/line_2d_editor_plugin.cpp +++ b/editor/plugins/line_2d_editor_plugin.cpp @@ -29,37 +29,33 @@ #include "line_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "os/file_access.h" #include "editor/editor_settings.h" +#include "os/file_access.h" #include "os/keyboard.h" - //---------------------------------------------------------------------------- // Line2DEditor //---------------------------------------------------------------------------- void Line2DEditor::_node_removed(Node *p_node) { - if(p_node == node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); } } void Line2DEditor::_notification(int p_what) { - switch(p_what) { - case NOTIFICATION_VISIBILITY_CHANGED: - // This widget is not a child but should have the same visibility state - base_hb->set_visible(is_visible()); - break; + switch (p_what) { + case NOTIFICATION_VISIBILITY_CHANGED: + // This widget is not a child but should have the same visibility state + base_hb->set_visible(is_visible()); + break; } } Vector2 Line2DEditor::mouse_to_local_pos(Vector2 gpoint, bool alt) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - return !alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) - : node->get_global_transform().affine_inverse().xform( - canvas_item_editor->snap_point( - canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); + return !alt ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); } int Line2DEditor::get_point_index_at(Vector2 gpos) { @@ -68,9 +64,9 @@ int Line2DEditor::get_point_index_at(Vector2 gpos) { real_t grab_treshold = EDITOR_DEF("poly_editor/point_grab_radius", 8); Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - for(int i = 0; i < node->get_point_count(); ++i) { - Point2 p = xform.xform( node->get_point_pos(i) ); - if(gpos.distance_to(p) < grab_treshold) { + for (int i = 0; i < node->get_point_count(); ++i) { + Point2 p = xform.xform(node->get_point_pos(i)); + if (gpos.distance_to(p) < grab_treshold) { return i; } } @@ -78,7 +74,7 @@ int Line2DEditor::get_point_index_at(Vector2 gpos) { return -1; } -bool Line2DEditor::forward_gui_input(const InputEvent& p_event) { +bool Line2DEditor::forward_gui_input(const InputEvent &p_event) { if (!node) return false; @@ -86,25 +82,24 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) { if (!node->is_visible()) return false; - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton &mb = p_event.mouse_button; - Vector2 gpoint = Point2(mb.x,mb.y); + Vector2 gpoint = Point2(mb.x, mb.y); Vector2 cpoint = mouse_to_local_pos(gpoint, mb.mod.alt); - if(mb.pressed && _dragging == false) { + if (mb.pressed && _dragging == false) { int i = get_point_index_at(gpoint); - if(i != -1) { + if (i != -1) { if (mb.button_index == BUTTON_LEFT && !mb.mod.shift && mode == MODE_EDIT) { _dragging = true; action_point = i; moving_from = node->get_point_pos(i); moving_screen_from = gpoint; - } - else if((mb.button_index == BUTTON_RIGHT && mode == MODE_EDIT) || (mb.button_index == BUTTON_LEFT && mode == MODE_DELETE)) { + } else if ((mb.button_index == BUTTON_RIGHT && mode == MODE_EDIT) || (mb.button_index == BUTTON_LEFT && mode == MODE_DELETE)) { undo_redo->create_action(TTR("Remove Point from Line2D")); undo_redo->add_do_method(node, "remove_point", i); undo_redo->add_undo_method(node, "add_point", node->get_point_pos(i), i); @@ -116,7 +111,7 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) { } } - if(mb.pressed && mb.button_index == BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) { + if (mb.pressed && mb.button_index == BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) { undo_redo->create_action(TTR("Add Point to Line2D")); undo_redo->add_do_method(node, "add_point", cpoint); @@ -126,7 +121,7 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) { undo_redo->commit_action(); _dragging = true; - action_point = node->get_point_count()-1; + action_point = node->get_point_count() - 1; moving_from = node->get_point_pos(action_point); moving_screen_from = gpoint; @@ -135,7 +130,7 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) { return true; } - if(!mb.pressed && mb.button_index == BUTTON_LEFT && _dragging) { + if (!mb.pressed && mb.button_index == BUTTON_LEFT && _dragging) { undo_redo->create_action(TTR("Move Point in Line2D")); undo_redo->add_do_method(node, "set_point_pos", action_point, cpoint); undo_redo->add_undo_method(node, "set_point_pos", action_point, moving_from); @@ -145,19 +140,17 @@ bool Line2DEditor::forward_gui_input(const InputEvent& p_event) { _dragging = false; return true; } - } - break; + } break; case InputEvent::MOUSE_MOTION: { if (_dragging) { const InputEventMouseMotion &mm = p_event.mouse_motion; Vector2 cpoint = mouse_to_local_pos(Vector2(mm.x, mm.y), mm.mod.alt); - node->set_point_pos(action_point,cpoint); + node->set_point_pos(action_point, cpoint); canvas_item_editor->get_viewport_control()->update(); return true; } - } - break; + } break; } return false; @@ -178,7 +171,7 @@ void Line2DEditor::_canvas_draw() { int len = node->get_point_count(); Control *vpc = canvas_item_editor->get_viewport_control(); - for(int i=0; i < len; ++i) { + for (int i = 0; i < len; ++i) { Vector2 point = xform.xform(node->get_point_pos(i)); vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false); } @@ -201,8 +194,7 @@ void Line2DEditor::edit(Node *p_line2d) { canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw"); if (!node->is_connected("visibility_changed", this, "_node_visibility_changed")) node->connect("visibility_changed", this, "_node_visibility_changed"); - } - else { + } else { 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 may have been deleted at this point @@ -219,7 +211,7 @@ void Line2DEditor::_bind_methods() { } void Line2DEditor::_mode_selected(int p_mode) { - for(unsigned int i = 0; i < _MODE_COUNT; ++i) { + for (unsigned int i = 0; i < _MODE_COUNT; ++i) { toolbar_buttons[i]->set_pressed(i == p_mode); } mode = Mode(p_mode); @@ -233,41 +225,37 @@ Line2DEditor::Line2DEditor(EditorNode *p_editor) { _dragging = false; - base_hb = memnew( HBoxContainer ); + base_hb = memnew(HBoxContainer); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(base_hb); - sep = memnew( VSeparator); + sep = memnew(VSeparator); base_hb->add_child(sep); { - ToolButton * b = memnew(ToolButton); + ToolButton *b = memnew(ToolButton); b->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit", "EditorIcons")); b->set_toggle_mode(true); b->set_focus_mode(Control::FOCUS_NONE); b->set_tooltip( - TTR("Select Points")+"\n" - + TTR("Shift+Drag: Select Control Points")+"\n" - + keycode_get_string(KEY_MASK_CMD) - + TTR("Click: Add Point")+"\n" - + TTR("Right Click: Delete Point")); + TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point")); b->connect("pressed", this, "_mode_selected", varray(MODE_EDIT)); toolbar_buttons[MODE_EDIT] = b; base_hb->add_child(b); } { - ToolButton * b = memnew(ToolButton); + ToolButton *b = memnew(ToolButton); b->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate", "EditorIcons")); b->set_toggle_mode(true); b->set_focus_mode(Control::FOCUS_NONE); - b->set_tooltip(TTR("Add Point (in empty space)")+"\n"+TTR("Split Segment (in line)")); + b->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in line)")); b->connect("pressed", this, "_mode_selected", varray(MODE_CREATE)); toolbar_buttons[MODE_CREATE] = b; base_hb->add_child(b); } { - ToolButton * b = memnew( ToolButton ); + ToolButton *b = memnew(ToolButton); b->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete", "EditorIcons")); b->set_toggle_mode(true); b->set_focus_mode(Control::FOCUS_NONE); @@ -297,15 +285,13 @@ bool Line2DEditorPlugin::handles(Object *p_object) const { void Line2DEditorPlugin::make_visible(bool p_visible) { line2d_editor->set_visible(p_visible); - if(p_visible == false) + if (p_visible == false) line2d_editor->edit(NULL); } Line2DEditorPlugin::Line2DEditorPlugin(EditorNode *p_node) { - editor=p_node; - line2d_editor = memnew( Line2DEditor(p_node) ); + editor = p_node; + line2d_editor = memnew(Line2DEditor(p_node)); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(line2d_editor); line2d_editor->hide(); } - - diff --git a/editor/plugins/line_2d_editor_plugin.h b/editor/plugins/line_2d_editor_plugin.h index 6e0da7df38..6bade92da4 100644 --- a/editor/plugins/line_2d_editor_plugin.h +++ b/editor/plugins/line_2d_editor_plugin.h @@ -29,13 +29,12 @@ #ifndef LINE_2D_EDITOR_PLUGIN_H #define LINE_2D_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "scene/2d/line_2d.h" #include "scene/2d/path_2d.h" -#include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" -#include "scene/2d/line_2d.h" - +#include "scene/gui/tool_button.h" class CanvasItemEditor; @@ -43,7 +42,7 @@ class Line2DEditor : public HBoxContainer { GDCLASS(Line2DEditor, HBoxContainer) public: - bool forward_gui_input(const InputEvent& p_event); + bool forward_gui_input(const InputEvent &p_event); void edit(Node *p_line2d); Line2DEditor(EditorNode *p_editor); @@ -81,7 +80,7 @@ private: }; Mode mode; - ToolButton* toolbar_buttons[_MODE_COUNT]; + ToolButton *toolbar_buttons[_MODE_COUNT]; bool _dragging; int action_point; @@ -90,13 +89,12 @@ private: }; class Line2DEditorPlugin : public EditorPlugin { - GDCLASS( Line2DEditorPlugin, EditorPlugin ) + GDCLASS(Line2DEditorPlugin, EditorPlugin) public: virtual bool forward_canvas_gui_input( - const Transform2D& p_canvas_xform, - const InputEvent& p_event) - { + const Transform2D &p_canvas_xform, + const InputEvent &p_event) { return line2d_editor->forward_gui_input(p_event); } @@ -111,8 +109,6 @@ public: private: Line2DEditor *line2d_editor; EditorNode *editor; - }; #endif // LINE_2D_EDITOR_PLUGIN_H - diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index cdf7c70d39..8716349cb4 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -205,21 +205,23 @@ MaterialEditor::MaterialEditor() { Vector3(x0 * zr0, z0, y0 *zr0) }; - #define ADD_POINT(m_idx) \ - normals.push_back(v[m_idx]);\ - vertices.push_back(v[m_idx]*radius);\ - { Vector2 uv(Math::atan2(v[m_idx].x,v[m_idx].z),Math::atan2(-v[m_idx].y,v[m_idx].z));\ - uv/=Math_PI;\ - uv*=4.0;\ - uv=uv*0.5+Vector2(0.5,0.5);\ - uvs.push_back(uv);\ - }\ - { Vector3 t = tt.xform(v[m_idx]);\ - tangents.push_back(t.x);\ - tangents.push_back(t.y);\ - tangents.push_back(t.z);\ - tangents.push_back(1.0);\ - } +#define ADD_POINT(m_idx) \ + normals.push_back(v[m_idx]); \ + vertices.push_back(v[m_idx] * radius); \ + { \ + Vector2 uv(Math::atan2(v[m_idx].x, v[m_idx].z), Math::atan2(-v[m_idx].y, v[m_idx].z)); \ + uv /= Math_PI; \ + uv *= 4.0; \ + uv = uv * 0.5 + Vector2(0.5, 0.5); \ + uvs.push_back(uv); \ + } \ + { \ + Vector3 t = tt.xform(v[m_idx]); \ + tangents.push_back(t.x); \ + tangents.push_back(t.y); \ + tangents.push_back(t.z); \ + tangents.push_back(1.0); \ + } @@ -256,15 +258,16 @@ MaterialEditor::MaterialEditor() { PoolVector uvs; int vtx_idx=0; - #define ADD_VTX(m_idx);\ - vertices.push_back( face_points[m_idx] );\ - normals.push_back( normal_points[m_idx] );\ - tangents.push_back( normal_points[m_idx][1] );\ - tangents.push_back( normal_points[m_idx][2] );\ - tangents.push_back( normal_points[m_idx][0] );\ - tangents.push_back( 1.0 );\ - uvs.push_back( Vector3(uv_points[m_idx*2+0],uv_points[m_idx*2+1],0) );\ - vtx_idx++;\ +#define ADD_VTX(m_idx) \ + ; \ + vertices.push_back(face_points[m_idx]); \ + normals.push_back(normal_points[m_idx]); \ + tangents.push_back(normal_points[m_idx][1]); \ + tangents.push_back(normal_points[m_idx][2]); \ + tangents.push_back(normal_points[m_idx][0]); \ + tangents.push_back(1.0); \ + uvs.push_back(Vector3(uv_points[m_idx * 2 + 0], uv_points[m_idx * 2 + 1], 0)); \ + vtx_idx++;\ for (int i=0;i<6;i++) { @@ -409,5 +412,4 @@ MaterialEditorPlugin::~MaterialEditorPlugin() { } - #endif diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index 604e7e61bd..30bed67a5e 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -29,12 +29,12 @@ #ifndef MATERIAL_EDITOR_PLUGIN_H #define MATERIAL_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "scene/resources/material.h" +#include "editor/editor_plugin.h" +#include "scene/3d/camera.h" #include "scene/3d/light.h" #include "scene/3d/mesh_instance.h" -#include "scene/3d/camera.h" +#include "scene/resources/material.h" #if 0 class MaterialEditor : public Control { diff --git a/editor/plugins/mesh_editor_plugin.h b/editor/plugins/mesh_editor_plugin.h index 80504ae445..ec6d67e2f7 100644 --- a/editor/plugins/mesh_editor_plugin.h +++ b/editor/plugins/mesh_editor_plugin.h @@ -31,12 +31,12 @@ #if 0 -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "scene/resources/material.h" +#include "editor/editor_plugin.h" +#include "scene/3d/camera.h" #include "scene/3d/light.h" #include "scene/3d/mesh_instance.h" -#include "scene/3d/camera.h" +#include "scene/resources/material.h" class MeshEditor : public Control { diff --git a/editor/plugins/mesh_instance_editor_plugin.cpp b/editor/plugins/mesh_instance_editor_plugin.cpp index 322e212534..972e92e51e 100644 --- a/editor/plugins/mesh_instance_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_editor_plugin.cpp @@ -28,27 +28,23 @@ /*************************************************************************/ #include "mesh_instance_editor_plugin.h" -#include "scene/3d/physics_body.h" #include "scene/3d/body_shape.h" -#include "scene/gui/box_container.h" #include "scene/3d/navigation_mesh.h" +#include "scene/3d/physics_body.h" +#include "scene/gui/box_container.h" #include "spatial_editor_plugin.h" void MeshInstanceEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; options->hide(); } - } - - void MeshInstanceEditor::edit(MeshInstance *p_mesh) { - node=p_mesh; - + node = p_mesh; } void MeshInstanceEditor::_menu_option(int p_option) { @@ -60,39 +56,39 @@ void MeshInstanceEditor::_menu_option(int p_option) { return; } - switch(p_option) { + switch (p_option) { case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: { - bool trimesh_shape = (p_option==MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + bool trimesh_shape = (p_option == MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_selected_node_list(); if (selection.empty()) { Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); if (shape.is_null()) return; - CollisionShape *cshape = memnew( CollisionShape ); + CollisionShape *cshape = memnew(CollisionShape); cshape->set_shape(shape); - StaticBody *body = memnew( StaticBody ); + StaticBody *body = memnew(StaticBody); body->add_child(cshape); - Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); + Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner(); if (trimesh_shape) ur->create_action(TTR("Create Static Trimesh Body")); else ur->create_action(TTR("Create Static Convex Body")); - ur->add_do_method(node,"add_child",body); - ur->add_do_method(body,"set_owner",owner); - ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_method(node, "add_child", body); + ur->add_do_method(body, "set_owner", owner); + ur->add_do_method(cshape, "set_owner", owner); ur->add_do_reference(body); - ur->add_undo_method(node,"remove_child",body); + ur->add_undo_method(node, "remove_child", body); ur->commit_action(); return; } @@ -102,7 +98,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { else ur->create_action(TTR("Create Static Convex Body")); - for (List::Element *E=selection.front();E;E=E->next()) { + for (List::Element *E = selection.front(); E; E = E->next()) { MeshInstance *instance = E->get()->cast_to(); if (!instance) @@ -116,18 +112,18 @@ void MeshInstanceEditor::_menu_option(int p_option) { if (shape.is_null()) continue; - CollisionShape *cshape = memnew( CollisionShape ); + CollisionShape *cshape = memnew(CollisionShape); cshape->set_shape(shape); - StaticBody *body = memnew( StaticBody ); + StaticBody *body = memnew(StaticBody); body->add_child(cshape); - Node *owner = instance==get_tree()->get_edited_scene_root() ? instance : instance->get_owner(); + Node *owner = instance == get_tree()->get_edited_scene_root() ? instance : instance->get_owner(); - ur->add_do_method(instance,"add_child",body); - ur->add_do_method(body,"set_owner",owner); - ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_method(instance, "add_child", body); + ur->add_do_method(body, "set_owner", owner); + ur->add_do_method(cshape, "set_owner", owner); ur->add_do_reference(body); - ur->add_undo_method(instance,"remove_child",body); + ur->add_undo_method(instance, "remove_child", body); } ur->commit_action(); @@ -137,22 +133,22 @@ void MeshInstanceEditor::_menu_option(int p_option) { case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { - if (node==get_tree()->get_edited_scene_root()) { + if (node == get_tree()->get_edited_scene_root()) { err_dialog->set_text(TTR("This doesn't work on scene root!")); err_dialog->popup_centered_minsize(); return; } - bool trimesh_shape = (p_option==MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); + bool trimesh_shape = (p_option == MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); Ref shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); if (shape.is_null()) return; - CollisionShape *cshape = memnew( CollisionShape ); + CollisionShape *cshape = memnew(CollisionShape); cshape->set_shape(shape); - Node *owner = node->get_owner(); + Node *owner = node->get_owner(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); @@ -161,36 +157,36 @@ void MeshInstanceEditor::_menu_option(int p_option) { else ur->create_action(TTR("Create Convex Shape")); - ur->add_do_method(node->get_parent(),"add_child",cshape); - ur->add_do_method(node->get_parent(),"move_child",cshape,node->get_index()+1); - ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_method(node->get_parent(), "add_child", cshape); + ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1); + ur->add_do_method(cshape, "set_owner", owner); ur->add_do_reference(cshape); - ur->add_undo_method(node->get_parent(),"remove_child",cshape); + ur->add_undo_method(node->get_parent(), "remove_child", cshape); ur->commit_action(); } break; case MENU_OPTION_CREATE_NAVMESH: { - Ref nmesh = memnew( NavigationMesh ); + Ref nmesh = memnew(NavigationMesh); if (nmesh.is_null()) return; nmesh->create_from_mesh(mesh); - NavigationMeshInstance *nmi = memnew( NavigationMeshInstance ); + NavigationMeshInstance *nmi = memnew(NavigationMeshInstance); nmi->set_navigation_mesh(nmesh); - Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); + Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action(TTR("Create Navigation Mesh")); - ur->add_do_method(node,"add_child",nmi); - ur->add_do_method(nmi,"set_owner",owner); + ur->add_do_method(node, "add_child", nmi); + ur->add_do_method(nmi, "set_owner", owner); ur->add_do_reference(nmi); - ur->add_undo_method(node,"remove_child",nmi); + ur->add_undo_method(node, "remove_child", nmi); ur->commit_action(); } break; @@ -199,7 +195,6 @@ void MeshInstanceEditor::_menu_option(int p_option) { outline_dialog->popup_centered(Vector2(200, 90)); } break; } - } void MeshInstanceEditor::_create_outline_mesh() { @@ -225,76 +220,73 @@ void MeshInstanceEditor::_create_outline_mesh() { return; } - MeshInstance *mi = memnew( MeshInstance ); + MeshInstance *mi = memnew(MeshInstance); mi->set_mesh(mesho); - Node *owner=node->get_owner(); - if (get_tree()->get_edited_scene_root()==node) { - owner=node; + Node *owner = node->get_owner(); + if (get_tree()->get_edited_scene_root() == node) { + owner = node; } UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action(TTR("Create Outline")); - ur->add_do_method(node,"add_child",mi); - ur->add_do_method(mi,"set_owner",owner); + ur->add_do_method(node, "add_child", mi); + ur->add_do_method(mi, "set_owner", owner); ur->add_do_reference(mi); - ur->add_undo_method(node,"remove_child",mi); + ur->add_undo_method(node, "remove_child", mi); ur->commit_action(); } void MeshInstanceEditor::_bind_methods() { - ClassDB::bind_method("_menu_option",&MeshInstanceEditor::_menu_option); - ClassDB::bind_method("_create_outline_mesh",&MeshInstanceEditor::_create_outline_mesh); + ClassDB::bind_method("_menu_option", &MeshInstanceEditor::_menu_option); + ClassDB::bind_method("_create_outline_mesh", &MeshInstanceEditor::_create_outline_mesh); } MeshInstanceEditor::MeshInstanceEditor() { - - options = memnew( MenuButton ); + options = memnew(MenuButton); SpatialEditor::get_singleton()->add_control_to_menu_panel(options); options->set_text(TTR("Mesh")); - options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance","EditorIcons")); + options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance", "EditorIcons")); - options->get_popup()->add_item(TTR("Create Trimesh Static Body"),MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); - options->get_popup()->add_item(TTR("Create Convex Static Body"),MENU_OPTION_CREATE_STATIC_CONVEX_BODY); + options->get_popup()->add_item(TTR("Create Trimesh Static Body"), MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + options->get_popup()->add_item(TTR("Create Convex Static Body"), MENU_OPTION_CREATE_STATIC_CONVEX_BODY); options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"),MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); - options->get_popup()->add_item(TTR("Create Convex Collision Sibling"),MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE); + options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"), MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); + options->get_popup()->add_item(TTR("Create Convex Collision Sibling"), MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE); options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Create Navigation Mesh"),MENU_OPTION_CREATE_NAVMESH); + options->get_popup()->add_item(TTR("Create Navigation Mesh"), MENU_OPTION_CREATE_NAVMESH); options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Create Outline Mesh.."),MENU_OPTION_CREATE_OUTLINE_MESH); + options->get_popup()->add_item(TTR("Create Outline Mesh.."), MENU_OPTION_CREATE_OUTLINE_MESH); - options->get_popup()->connect("id_pressed", this,"_menu_option"); + options->get_popup()->connect("id_pressed", this, "_menu_option"); - outline_dialog = memnew( ConfirmationDialog ); + outline_dialog = memnew(ConfirmationDialog); outline_dialog->set_title(TTR("Create Outline Mesh")); outline_dialog->get_ok()->set_text(TTR("Create")); - VBoxContainer *outline_dialog_vbc = memnew( VBoxContainer ); + VBoxContainer *outline_dialog_vbc = memnew(VBoxContainer); outline_dialog->add_child(outline_dialog_vbc); //outline_dialog->set_child_rect(outline_dialog_vbc); - outline_size = memnew( SpinBox ); + outline_size = memnew(SpinBox); outline_size->set_min(0.001); outline_size->set_max(1024); outline_size->set_step(0.001); outline_size->set_value(0.05); - outline_dialog_vbc->add_margin_child(TTR("Outline Size:"),outline_size); + outline_dialog_vbc->add_margin_child(TTR("Outline Size:"), outline_size); add_child(outline_dialog); - outline_dialog->connect("confirmed",this,"_create_outline_mesh"); + outline_dialog->connect("confirmed", this, "_create_outline_mesh"); - err_dialog = memnew( AcceptDialog ); + err_dialog = memnew(AcceptDialog); add_child(err_dialog); - } - void MeshInstanceEditorPlugin::edit(Object *p_object) { mesh_editor->edit(p_object->cast_to()); @@ -314,21 +306,16 @@ void MeshInstanceEditorPlugin::make_visible(bool p_visible) { mesh_editor->options->hide(); mesh_editor->edit(NULL); } - } MeshInstanceEditorPlugin::MeshInstanceEditorPlugin(EditorNode *p_node) { - editor=p_node; - mesh_editor = memnew( MeshInstanceEditor ); + editor = p_node; + mesh_editor = memnew(MeshInstanceEditor); editor->get_viewport()->add_child(mesh_editor); mesh_editor->options->hide(); } - -MeshInstanceEditorPlugin::~MeshInstanceEditorPlugin() -{ +MeshInstanceEditorPlugin::~MeshInstanceEditorPlugin() { } - - diff --git a/editor/plugins/mesh_instance_editor_plugin.h b/editor/plugins/mesh_instance_editor_plugin.h index de5be2fbbb..54d42d1a01 100644 --- a/editor/plugins/mesh_instance_editor_plugin.h +++ b/editor/plugins/mesh_instance_editor_plugin.h @@ -29,17 +29,14 @@ #ifndef MESH_INSTANCE_EDITOR_PLUGIN_H #define MESH_INSTANCE_EDITOR_PLUGIN_H - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/3d/mesh_instance.h" #include "scene/gui/spin_box.h" - class MeshInstanceEditor : public Node { - GDCLASS(MeshInstanceEditor, Node ); - + GDCLASS(MeshInstanceEditor, Node); enum Menu { @@ -63,26 +60,25 @@ class MeshInstanceEditor : public Node { void _menu_option(int p_option); void _create_outline_mesh(); -friend class MeshInstanceEditorPlugin; + friend class MeshInstanceEditorPlugin; protected: void _node_removed(Node *p_node); static void _bind_methods(); -public: +public: void edit(MeshInstance *p_mesh); MeshInstanceEditor(); }; class MeshInstanceEditorPlugin : public EditorPlugin { - GDCLASS( MeshInstanceEditorPlugin, EditorPlugin ); + GDCLASS(MeshInstanceEditorPlugin, EditorPlugin); MeshInstanceEditor *mesh_editor; EditorNode *editor; public: - virtual String get_name() const { return "MeshInstance"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -91,7 +87,6 @@ public: MeshInstanceEditorPlugin(EditorNode *p_node); ~MeshInstanceEditorPlugin(); - }; #endif // MESH_EDITOR_PLUGIN_H diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index 6259ddf473..126927480a 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -28,29 +28,26 @@ /*************************************************************************/ #include "multimesh_editor_plugin.h" -#include "scene/gui/box_container.h" #include "scene/3d/mesh_instance.h" +#include "scene/gui/box_container.h" #include "spatial_editor_plugin.h" void MultiMeshEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); } - } - void MultiMeshEditor::_populate() { - if(!node) + if (!node) return; - Ref mesh; - if (mesh_source->get_text()=="") { + if (mesh_source->get_text() == "") { Ref multimesh; multimesh = node->get_multimesh(); @@ -88,7 +85,7 @@ void MultiMeshEditor::_populate() { return; } - mesh=ms_instance->get_mesh(); + mesh = ms_instance->get_mesh(); if (mesh.is_null()) { @@ -96,10 +93,9 @@ void MultiMeshEditor::_populate() { err_dialog->popup_centered_minsize(); return; } - } - if (surface_source->get_text()=="") { + if (surface_source->get_text() == "") { err_dialog->set_text(TTR("No surface source specified.")); err_dialog->popup_centered_minsize(); @@ -128,7 +124,7 @@ void MultiMeshEditor::_populate() { PoolVector geometry = ss_instance->get_faces(VisualInstance::FACES_SOLID); - if (geometry.size()==0) { + if (geometry.size() == 0) { err_dialog->set_text(TTR("Surface source is invalid (no faces).")); err_dialog->popup_centered_minsize(); @@ -140,14 +136,12 @@ void MultiMeshEditor::_populate() { int gc = geometry.size(); PoolVector::Write w = geometry.write(); - for(int i=0;i::Write(); #if 0 node->get_multimesh()->set_instance_count(populate_amount->get_val()); @@ -167,34 +161,31 @@ void MultiMeshEditor::_populate() { #endif PoolVector faces = geometry; ERR_EXPLAIN(TTR("Parent has no solid faces to populate.")); - int facecount=faces.size(); + int facecount = faces.size(); ERR_FAIL_COND(!facecount); PoolVector::Read r = faces.read(); - - - float area_accum=0; - Map triangle_area_map; - for(int i=0;i triangle_area_map; + for (int i = 0; i < facecount; i++) { float area = r[i].get_area(); - if (area multimesh = memnew( MultiMesh ); + Ref multimesh = memnew(MultiMesh); multimesh->set_mesh(mesh); - int instance_count=populate_amount->get_value(); + int instance_count = populate_amount->get_value(); multimesh->set_transform_format(MultiMesh::TRANSFORM_3D); multimesh->set_color_format(MultiMesh::COLOR_NONE); @@ -207,21 +198,21 @@ void MultiMeshEditor::_populate() { int axis = populate_axis->get_selected(); Transform axis_xform; - if (axis==Vector3::AXIS_Z) { - axis_xform.rotate(Vector3(1,0,0),-Math_PI*0.5); + if (axis == Vector3::AXIS_Z) { + axis_xform.rotate(Vector3(1, 0, 0), -Math_PI * 0.5); } - if (axis==Vector3::AXIS_X) { - axis_xform.rotate(Vector3(0,0,1),-Math_PI*0.5); + if (axis == Vector3::AXIS_X) { + axis_xform.rotate(Vector3(0, 0, 1), -Math_PI * 0.5); } - for(int i=0;i::Element *E = triangle_area_map.find_closest(areapos); + Map::Element *E = triangle_area_map.find_closest(areapos); ERR_FAIL_COND(!E) int index = E->get(); - ERR_FAIL_INDEX(index,facecount); + ERR_FAIL_INDEX(index, facecount); // ok FINALLY get face Face3 face = r[index]; @@ -229,41 +220,33 @@ void MultiMeshEditor::_populate() { Vector3 pos = face.get_random_point_inside(); Vector3 normal = face.get_plane().normal; - Vector3 op_axis = (face.vertex[0]-face.vertex[1]).normalized(); + Vector3 op_axis = (face.vertex[0] - face.vertex[1]).normalized(); Transform xform; - xform.set_look_at(pos, pos+op_axis,normal); + xform.set_look_at(pos, pos + op_axis, normal); xform = xform * axis_xform; - Basis post_xform; - post_xform.rotate(xform.basis.get_axis(1),-Math::random(-_rotate_random,_rotate_random)*Math_PI); - post_xform.rotate(xform.basis.get_axis(2),-Math::random(-_tilt_random,_tilt_random)*Math_PI); - post_xform.rotate(xform.basis.get_axis(0),-Math::random(-_tilt_random,_tilt_random)*Math_PI); + post_xform.rotate(xform.basis.get_axis(1), -Math::random(-_rotate_random, _rotate_random) * Math_PI); + post_xform.rotate(xform.basis.get_axis(2), -Math::random(-_tilt_random, _tilt_random) * Math_PI); + post_xform.rotate(xform.basis.get_axis(0), -Math::random(-_tilt_random, _tilt_random) * Math_PI); xform.basis = post_xform * xform.basis; //xform.basis.orthonormalize(); + xform.basis.scale(Vector3(1, 1, 1) * (_scale + Math::random(-_scale_random, _scale_random))); - xform.basis.scale(Vector3(1,1,1)*(_scale+Math::random(-_scale_random,_scale_random))); - - - multimesh->set_instance_transform(i,xform); - + multimesh->set_instance_transform(i, xform); } - - node->set_multimesh(multimesh); - } -void MultiMeshEditor::_browsed(const NodePath& p_path) { - +void MultiMeshEditor::_browsed(const NodePath &p_path) { - NodePath path = node->get_path_to( get_node(p_path) ); + NodePath path = node->get_path_to(get_node(p_path)); if (browsing_source) mesh_source->set_text(path); @@ -273,14 +256,11 @@ void MultiMeshEditor::_browsed(const NodePath& p_path) { void MultiMeshEditor::_menu_option(int p_option) { - - switch(p_option) { - + switch (p_option) { case MENU_OPTION_POPULATE: { - if (_last_pp_node!=node) { - + if (_last_pp_node != node) { surface_source->set_text(".."); mesh_source->set_text(".."); @@ -291,25 +271,23 @@ void MultiMeshEditor::_menu_option(int p_option) { populate_scale->set_value(1); populate_amount->set_value(128); - _last_pp_node=node; + _last_pp_node = node; } - populate_dialog->popup_centered(Size2(250,380)); + populate_dialog->popup_centered(Size2(250, 380)); } break; } } - void MultiMeshEditor::edit(MultiMeshInstance *p_multimesh) { - node=p_multimesh; - + node = p_multimesh; } void MultiMeshEditor::_browse(bool p_source) { - browsing_source=p_source; - std->get_scene_tree()->set_marked(node,false); + browsing_source = p_source; + std->get_scene_tree()->set_marked(node, false); std->popup_centered_ratio(); if (p_source) std->set_title(TTR("Select a Source Mesh:")); @@ -319,113 +297,108 @@ void MultiMeshEditor::_browse(bool p_source) { void MultiMeshEditor::_bind_methods() { - ClassDB::bind_method("_menu_option",&MultiMeshEditor::_menu_option); - ClassDB::bind_method("_populate",&MultiMeshEditor::_populate); - ClassDB::bind_method("_browsed",&MultiMeshEditor::_browsed); - ClassDB::bind_method("_browse",&MultiMeshEditor::_browse); + ClassDB::bind_method("_menu_option", &MultiMeshEditor::_menu_option); + ClassDB::bind_method("_populate", &MultiMeshEditor::_populate); + ClassDB::bind_method("_browsed", &MultiMeshEditor::_browsed); + ClassDB::bind_method("_browse", &MultiMeshEditor::_browse); } MultiMeshEditor::MultiMeshEditor() { - - options = memnew( MenuButton ); + options = memnew(MenuButton); SpatialEditor::get_singleton()->add_control_to_menu_panel(options); options->set_text("MultiMesh"); - options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MultiMeshInstance","EditorIcons")); + options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MultiMeshInstance", "EditorIcons")); options->get_popup()->add_item(TTR("Populate Surface")); - options->get_popup()->connect("id_pressed", this,"_menu_option"); + options->get_popup()->connect("id_pressed", this, "_menu_option"); - populate_dialog = memnew( ConfirmationDialog ); + populate_dialog = memnew(ConfirmationDialog); populate_dialog->set_title(TTR("Populate MultiMesh")); add_child(populate_dialog); - VBoxContainer *vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew(VBoxContainer); populate_dialog->add_child(vbc); //populate_dialog->set_child_rect(vbc); - HBoxContainer *hbc = memnew( HBoxContainer ); + HBoxContainer *hbc = memnew(HBoxContainer); - surface_source = memnew( LineEdit ); + surface_source = memnew(LineEdit); hbc->add_child(surface_source); surface_source->set_h_size_flags(SIZE_EXPAND_FILL); - Button *b = memnew( Button ); + Button *b = memnew(Button); hbc->add_child(b); b->set_text(".."); - b->connect("pressed",this,"_browse",make_binds(false)); + b->connect("pressed", this, "_browse", make_binds(false)); - vbc->add_margin_child(TTR("Target Surface:"),hbc); + vbc->add_margin_child(TTR("Target Surface:"), hbc); - hbc = memnew( HBoxContainer ); - mesh_source = memnew( LineEdit ); + hbc = memnew(HBoxContainer); + mesh_source = memnew(LineEdit); hbc->add_child(mesh_source); mesh_source->set_h_size_flags(SIZE_EXPAND_FILL); - b = memnew( Button ); + b = memnew(Button); hbc->add_child(b); b->set_text(".."); - vbc->add_margin_child(TTR("Source Mesh:"),hbc); - b->connect("pressed",this,"_browse",make_binds(true)); + vbc->add_margin_child(TTR("Source Mesh:"), hbc); + b->connect("pressed", this, "_browse", make_binds(true)); - - populate_axis = memnew( OptionButton ); + populate_axis = memnew(OptionButton); populate_axis->add_item(TTR("X-Axis")); populate_axis->add_item(TTR("Y-Axis")); populate_axis->add_item(TTR("Z-Axis")); populate_axis->select(2); - vbc->add_margin_child(TTR("Mesh Up Axis:"),populate_axis); + vbc->add_margin_child(TTR("Mesh Up Axis:"), populate_axis); - populate_rotate_random = memnew( HSlider ); + populate_rotate_random = memnew(HSlider); populate_rotate_random->set_max(1); populate_rotate_random->set_step(0.01); - vbc->add_margin_child(TTR("Random Rotation:"),populate_rotate_random); + vbc->add_margin_child(TTR("Random Rotation:"), populate_rotate_random); - populate_tilt_random = memnew( HSlider ); + populate_tilt_random = memnew(HSlider); populate_tilt_random->set_max(1); populate_tilt_random->set_step(0.01); - vbc->add_margin_child(TTR("Random Tilt:"),populate_tilt_random); - + vbc->add_margin_child(TTR("Random Tilt:"), populate_tilt_random); - populate_scale_random = memnew( SpinBox ); + populate_scale_random = memnew(SpinBox); populate_scale_random->set_min(0); populate_scale_random->set_max(1); populate_scale_random->set_value(0); populate_scale_random->set_step(0.01); - vbc->add_margin_child(TTR("Random Scale:"),populate_scale_random); + vbc->add_margin_child(TTR("Random Scale:"), populate_scale_random); - populate_scale = memnew( SpinBox ); + populate_scale = memnew(SpinBox); populate_scale->set_min(0.001); populate_scale->set_max(4096); populate_scale->set_value(1); populate_scale->set_step(0.01); - vbc->add_margin_child(TTR("Scale:"),populate_scale); + vbc->add_margin_child(TTR("Scale:"), populate_scale); - - populate_amount = memnew( SpinBox ); - populate_amount->set_anchor(MARGIN_RIGHT,ANCHOR_END); - populate_amount->set_begin( Point2(20,232)); - populate_amount->set_end( Point2(5,237)); + populate_amount = memnew(SpinBox); + populate_amount->set_anchor(MARGIN_RIGHT, ANCHOR_END); + populate_amount->set_begin(Point2(20, 232)); + populate_amount->set_end(Point2(5, 237)); populate_amount->set_min(1); populate_amount->set_max(65536); populate_amount->set_value(128); - vbc->add_margin_child(TTR("Amount:"),populate_amount); + vbc->add_margin_child(TTR("Amount:"), populate_amount); populate_dialog->get_ok()->set_text(TTR("Populate")); - populate_dialog->get_ok()->connect("pressed", this,"_populate"); - std = memnew( SceneTreeDialog ); + populate_dialog->get_ok()->connect("pressed", this, "_populate"); + std = memnew(SceneTreeDialog); populate_dialog->add_child(std); - std->connect("selected",this,"_browsed"); + std->connect("selected", this, "_browsed"); - _last_pp_node=NULL; + _last_pp_node = NULL; - err_dialog = memnew( AcceptDialog ); + err_dialog = memnew(AcceptDialog); add_child(err_dialog); } - void MultiMeshEditorPlugin::edit(Object *p_object) { multimesh_editor->edit(p_object->cast_to()); @@ -445,21 +418,16 @@ void MultiMeshEditorPlugin::make_visible(bool p_visible) { multimesh_editor->options->hide(); multimesh_editor->edit(NULL); } - } MultiMeshEditorPlugin::MultiMeshEditorPlugin(EditorNode *p_node) { - editor=p_node; - multimesh_editor = memnew( MultiMeshEditor ); + editor = p_node; + multimesh_editor = memnew(MultiMeshEditor); editor->get_viewport()->add_child(multimesh_editor); multimesh_editor->options->hide(); } - -MultiMeshEditorPlugin::~MultiMeshEditorPlugin() -{ +MultiMeshEditorPlugin::~MultiMeshEditorPlugin() { } - - diff --git a/editor/plugins/multimesh_editor_plugin.h b/editor/plugins/multimesh_editor_plugin.h index a97b3758a1..eb46733082 100644 --- a/editor/plugins/multimesh_editor_plugin.h +++ b/editor/plugins/multimesh_editor_plugin.h @@ -29,8 +29,8 @@ #ifndef MULTIMESH_EDITOR_PLUGIN_H #define MULTIMESH_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/3d/multimesh_instance.h" #include "scene/gui/spin_box.h" @@ -40,12 +40,12 @@ class MultiMeshEditor : public Control { - GDCLASS(MultiMeshEditor, Control ); + GDCLASS(MultiMeshEditor, Control); -friend class MultiMeshEditorPlugin; + friend class MultiMeshEditorPlugin; AcceptDialog *err_dialog; - MenuButton * options; + MenuButton *options; MultiMeshInstance *_last_pp_node; bool browsing_source; @@ -70,7 +70,7 @@ friend class MultiMeshEditorPlugin; MENU_OPTION_POPULATE }; - void _browsed(const NodePath& p_path); + void _browsed(const NodePath &p_path); void _menu_option(int); void _populate(); void _browse(bool p_source); @@ -78,21 +78,20 @@ friend class MultiMeshEditorPlugin; protected: void _node_removed(Node *p_node); static void _bind_methods(); -public: +public: void edit(MultiMeshInstance *p_multimesh); MultiMeshEditor(); }; class MultiMeshEditorPlugin : public EditorPlugin { - GDCLASS( MultiMeshEditorPlugin, EditorPlugin ); + GDCLASS(MultiMeshEditorPlugin, EditorPlugin); MultiMeshEditor *multimesh_editor; EditorNode *editor; public: - virtual String get_name() const { return "MultiMesh"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -101,7 +100,6 @@ public: MultiMeshEditorPlugin(EditorNode *p_node); ~MultiMeshEditorPlugin(); - }; #endif // MULTIMESH_EDITOR_PLUGIN_H diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index 654afb754e..e5b2594872 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -29,372 +29,342 @@ #include "navigation_polygon_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "os/file_access.h" #include "editor/editor_settings.h" +#include "os/file_access.h" void NavigationPolygonEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_READY: { - button_create->set_icon( get_icon("Edit","EditorIcons")); - button_edit->set_icon( get_icon("MovePoint","EditorIcons")); + button_create->set_icon(get_icon("Edit", "EditorIcons")); + button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); button_edit->set_pressed(true); - get_tree()->connect("node_removed",this,"_node_removed"); - create_nav->connect("confirmed",this,"_create_nav"); + get_tree()->connect("node_removed", this, "_node_removed"); + create_nav->connect("confirmed", this, "_create_nav"); } break; case NOTIFICATION_FIXED_PROCESS: { - } break; } - } void NavigationPolygonEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); canvas_item_editor->get_viewport_control()->update(); } - } -void NavigationPolygonEditor::_create_nav() { +void NavigationPolygonEditor::_create_nav() { if (!node) return; undo_redo->create_action(TTR("Create Navigation Polygon")); - undo_redo->add_do_method(node,"set_navigation_polygon",Ref(memnew( NavigationPolygon))); - undo_redo->add_undo_method(node,"set_navigation_polygon",Variant(REF())); + undo_redo->add_do_method(node, "set_navigation_polygon", Ref(memnew(NavigationPolygon))); + undo_redo->add_undo_method(node, "set_navigation_polygon", Variant(REF())); undo_redo->commit_action(); } void NavigationPolygonEditor::_menu_option(int p_option) { - switch(p_option) { + switch (p_option) { case MODE_CREATE: { - mode=MODE_CREATE; + mode = MODE_CREATE; button_create->set_pressed(true); button_edit->set_pressed(false); } break; case MODE_EDIT: { - mode=MODE_EDIT; + mode = MODE_EDIT; button_create->set_pressed(false); button_edit->set_pressed(true); } break; - } } void NavigationPolygonEditor::_wip_close() { - - if (wip.size()>=3) { + if (wip.size() >= 3) { undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"remove_outline",node->get_navigation_polygon()->get_outline_count()); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"add_outline",wip); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "remove_outline", node->get_navigation_polygon()->get_outline_count()); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "add_outline", wip); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); - mode=MODE_EDIT; + mode = MODE_EDIT; button_edit->set_pressed(true); button_create->set_pressed(false); } wip.clear(); - wip_active=false; - edited_point=-1; + wip_active = false; + edited_point = -1; } -bool NavigationPolygonEditor::forward_gui_input(const InputEvent& p_event) { - +bool NavigationPolygonEditor::forward_gui_input(const InputEvent &p_event) { if (!node) return false; if (node->get_navigation_polygon().is_null()) { - if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) { create_nav->set_text("No NavigationPolygon resource on this node.\nCreate and assign one?"); create_nav->popup_centered_minsize(); } - return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1); + return (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1); } - - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - const InputEventMouseButton &mb=p_event.mouse_button; + const InputEventMouseButton &mb = p_event.mouse_button; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = Point2(mb.x,mb.y); + Vector2 gpoint = Point2(mb.x, mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); - - //first check if a point is to be added (segment split) - real_t grab_treshold=EDITOR_DEF("editors/poly_editor/point_grab_radius",8); - - switch(mode) { + real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + switch (mode) { case MODE_CREATE: { - if (mb.button_index==BUTTON_LEFT && mb.pressed) { - + if (mb.button_index == BUTTON_LEFT && mb.pressed) { if (!wip_active) { wip.clear(); - wip.push_back( cpoint ); - wip_active=true; - edited_point_pos=cpoint; - edited_outline=-1; + wip.push_back(cpoint); + wip_active = true; + edited_point_pos = cpoint; + edited_outline = -1; canvas_item_editor->get_viewport_control()->update(); - edited_point=1; + edited_point = 1; return true; } else { - - if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint) 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) { //wip closed _wip_close(); return true; } else { - wip.push_back( cpoint ); - edited_point=wip.size(); + wip.push_back(cpoint); + edited_point = wip.size(); canvas_item_editor->get_viewport_control()->update(); return true; //add wip point } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) { _wip_close(); } - - } break; case MODE_EDIT: { - if (mb.button_index==BUTTON_LEFT) { + if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { if (mb.mod.control) { - //search edges - int closest_outline=-1; - int closest_idx=-1; + int closest_outline = -1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - - for(int j=0;jget_navigation_polygon()->get_outline_count();j++) { + real_t closest_dist = 1e10; + for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) { - PoolVector points=node->get_navigation_polygon()->get_outline(j); + PoolVector points = node->get_navigation_polygon()->get_outline(j); - int pc=points.size(); - PoolVector::Read poly=points.read(); + int pc = points.size(); + PoolVector::Read poly = points.read(); - for(int i=0;i=0) { + if (closest_idx >= 0) { - pre_move_edit=node->get_navigation_polygon()->get_outline(closest_outline); + pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline); PoolVector poly = pre_move_edit; - poly.insert(closest_idx+1,xform.affine_inverse().xform(closest_pos)); - edited_point=closest_idx+1; - edited_outline=closest_outline; - edited_point_pos=xform.affine_inverse().xform(closest_pos); - node->get_navigation_polygon()->set_outline(closest_outline,poly); + poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos)); + edited_point = closest_idx + 1; + edited_outline = closest_outline; + edited_point_pos = xform.affine_inverse().xform(closest_pos); + node->get_navigation_polygon()->set_outline(closest_outline, poly); canvas_item_editor->get_viewport_control()->update(); return true; } } else { //look for points to move - int closest_outline=-1; - int closest_idx=-1; + int closest_outline = -1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - - for(int j=0;jget_navigation_polygon()->get_outline_count();j++) { + real_t closest_dist = 1e10; + for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) { - PoolVector points=node->get_navigation_polygon()->get_outline(j); + PoolVector points = node->get_navigation_polygon()->get_outline(j); - int pc=points.size(); - PoolVector::Read poly=points.read(); + int pc = points.size(); + PoolVector::Read poly = points.read(); - for(int i=0;i=0) { + if (closest_idx >= 0) { - pre_move_edit=node->get_navigation_polygon()->get_outline(closest_outline); - edited_point=closest_idx; - edited_outline=closest_outline; - edited_point_pos=xform.affine_inverse().xform(closest_pos); + pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline); + edited_point = closest_idx; + edited_outline = closest_outline; + edited_point_pos = xform.affine_inverse().xform(closest_pos); canvas_item_editor->get_viewport_control()->update(); return true; } } } else { - if (edited_point!=-1) { + if (edited_point != -1) { //apply PoolVector poly = node->get_navigation_polygon()->get_outline(edited_outline); - ERR_FAIL_INDEX_V(edited_point,poly.size(),false); - poly.set(edited_point,edited_point_pos); + ERR_FAIL_INDEX_V(edited_point, poly.size(), false); + poly.set(edited_point, edited_point_pos); undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"set_outline",edited_outline,poly); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"set_outline",edited_outline,pre_move_edit); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, poly); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, pre_move_edit); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); - edited_point=-1; + edited_point = -1; return true; } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) { - int closest_outline=-1; - int closest_idx=-1; + int closest_outline = -1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - - for(int j=0;jget_navigation_polygon()->get_outline_count();j++) { - + real_t closest_dist = 1e10; - PoolVector points=node->get_navigation_polygon()->get_outline(j); + for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) { - int pc=points.size(); - PoolVector::Read poly=points.read(); + PoolVector points = node->get_navigation_polygon()->get_outline(j); - for(int i=0;i::Read poly = points.read(); + for (int i = 0; i < pc; i++) { - Vector2 cp =xform.xform(poly[i]); + Vector2 cp = xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); - if (d=0) { - + if (closest_idx >= 0) { PoolVector poly = node->get_navigation_polygon()->get_outline(closest_outline); - if (poly.size()>3) { + if (poly.size() > 3) { undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"set_outline",closest_outline,poly); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly); poly.remove(closest_idx); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"set_outline",closest_outline,poly); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); } else { undo_redo->create_action(TTR("Remove Poly And Point")); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"add_outline_at_index",poly,closest_outline); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "add_outline_at_index", poly, closest_outline); poly.remove(closest_idx); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"remove_outline",closest_outline); - undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "remove_outline", closest_outline); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); - } return true; } } - - } break; } - - } break; case InputEvent::MOUSE_MOTION: { - const InputEventMouseMotion &mm=p_event.mouse_motion; + const InputEventMouseMotion &mm = p_event.mouse_motion; - if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { + if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) { - Vector2 gpoint = Point2(mm.x,mm.y); + Vector2 gpoint = Point2(mm.x, mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); - } } break; @@ -409,105 +379,96 @@ void NavigationPolygonEditor::_canvas_draw() { Control *vpc = canvas_item_editor->get_viewport_control(); if (node->get_navigation_polygon().is_null()) - return; + return; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref handle= get_icon("EditorHandle","EditorIcons"); - - + Ref handle = get_icon("EditorHandle", "EditorIcons"); - for(int j=-1;jget_navigation_polygon()->get_outline_count();j++) { + for (int j = -1; j < node->get_navigation_polygon()->get_outline_count(); j++) { Vector poly; - if (wip_active && j==edited_outline) { - poly=wip; + if (wip_active && j == edited_outline) { + poly = wip; } else { - if (j==-1) + if (j == -1) continue; poly = Variant(node->get_navigation_polygon()->get_outline(j)); } - for(int i=0;idraw_line(point,next_point,col,2); - vpc->draw_texture(handle,point-handle->get_size()*0.5); + Color col = Color(1, 0.3, 0.1, 0.8); + vpc->draw_line(point, next_point, col, 2); + vpc->draw_texture(handle, point - handle->get_size() * 0.5); } } } - - void NavigationPolygonEditor::edit(Node *p_collision_polygon) { if (!canvas_item_editor) { - canvas_item_editor=CanvasItemEditor::get_singleton(); + canvas_item_editor = CanvasItemEditor::get_singleton(); } if (p_collision_polygon) { - node=p_collision_polygon->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"); + node = p_collision_polygon->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"); wip.clear(); - wip_active=false; - edited_point=-1; + wip_active = false; + edited_point = -1; canvas_item_editor->get_viewport_control()->update(); } else { - node=NULL; - - 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; + if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); } - } void NavigationPolygonEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_option"),&NavigationPolygonEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"),&NavigationPolygonEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_node_removed"),&NavigationPolygonEditor::_node_removed); - ClassDB::bind_method(D_METHOD("_create_nav"),&NavigationPolygonEditor::_create_nav); - + ClassDB::bind_method(D_METHOD("_menu_option"), &NavigationPolygonEditor::_menu_option); + ClassDB::bind_method(D_METHOD("_canvas_draw"), &NavigationPolygonEditor::_canvas_draw); + ClassDB::bind_method(D_METHOD("_node_removed"), &NavigationPolygonEditor::_node_removed); + ClassDB::bind_method(D_METHOD("_create_nav"), &NavigationPolygonEditor::_create_nav); } NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) { - node=NULL; - canvas_item_editor=NULL; - editor=p_editor; + node = NULL; + canvas_item_editor = NULL; + editor = p_editor; undo_redo = editor->get_undo_redo(); - add_child( memnew( VSeparator )); - button_create = memnew( ToolButton ); + add_child(memnew(VSeparator)); + button_create = memnew(ToolButton); add_child(button_create); - button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE)); + button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); button_create->set_toggle_mode(true); button_create->set_tooltip(TTR("Create a new polygon from scratch.")); - button_edit = memnew( ToolButton ); + button_edit = memnew(ToolButton); add_child(button_edit); - button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT)); + button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); button_edit->set_toggle_mode(true); - button_edit->set_tooltip(TTR("Edit existing polygon:")+"\n"+TTR("LMB: Move Point.")+"\n"+TTR("Ctrl+LMB: Split Segment.")+"\n"+TTR("RMB: Erase Point.")); - create_nav = memnew( ConfirmationDialog ); + button_edit->set_tooltip(TTR("Edit existing polygon:") + "\n" + TTR("LMB: Move Point.") + "\n" + TTR("Ctrl+LMB: Split Segment.") + "\n" + TTR("RMB: Erase Point.")); + create_nav = memnew(ConfirmationDialog); add_child(create_nav); create_nav->get_ok()->set_text(TTR("Create")); - - //add_constant_override("separation",0); +//add_constant_override("separation",0); #if 0 options = memnew( MenuButton ); @@ -519,12 +480,10 @@ NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) { #endif mode = MODE_EDIT; - wip_active=false; - edited_outline=-1; - + wip_active = false; + edited_outline = -1; } - void NavigationPolygonEditorPlugin::edit(Object *p_object) { collision_polygon_editor->edit(p_object->cast_to()); @@ -544,23 +503,16 @@ void NavigationPolygonEditorPlugin::make_visible(bool p_visible) { collision_polygon_editor->hide(); collision_polygon_editor->edit(NULL); } - } NavigationPolygonEditorPlugin::NavigationPolygonEditorPlugin(EditorNode *p_node) { - editor=p_node; - collision_polygon_editor = memnew( NavigationPolygonEditor(p_node) ); + editor = p_node; + collision_polygon_editor = memnew(NavigationPolygonEditor(p_node)); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); collision_polygon_editor->hide(); - - - } - -NavigationPolygonEditorPlugin::~NavigationPolygonEditorPlugin() -{ +NavigationPolygonEditorPlugin::~NavigationPolygonEditorPlugin() { } - diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h index 0d5e67e352..ba18756869 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.h +++ b/editor/plugins/navigation_polygon_editor_plugin.h @@ -29,13 +29,11 @@ #ifndef NAVIGATIONPOLYGONEDITORPLUGIN_H #define NAVIGATIONPOLYGONEDITORPLUGIN_H - - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/navigation_polygon.h" -#include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" +#include "scene/gui/tool_button.h" /** @author Juan Linietsky @@ -44,7 +42,7 @@ class CanvasItemEditor; class NavigationPolygonEditor : public HBoxContainer { - GDCLASS(NavigationPolygonEditor, HBoxContainer ); + GDCLASS(NavigationPolygonEditor, HBoxContainer); UndoRedo *undo_redo; enum Mode { @@ -74,7 +72,6 @@ class NavigationPolygonEditor : public HBoxContainer { Vector wip; bool wip_active; - void _wip_close(); void _canvas_draw(); void _create_nav(); @@ -85,23 +82,22 @@ protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); -public: - bool forward_gui_input(const InputEvent& p_event); +public: + bool forward_gui_input(const InputEvent &p_event); void edit(Node *p_collision_polygon); NavigationPolygonEditor(EditorNode *p_editor); }; class NavigationPolygonEditorPlugin : public EditorPlugin { - GDCLASS( NavigationPolygonEditorPlugin, EditorPlugin ); + GDCLASS(NavigationPolygonEditorPlugin, EditorPlugin); NavigationPolygonEditor *collision_polygon_editor; EditorNode *editor; public: - - virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); } + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); } virtual String get_name() const { return "NavigationPolygonInstance"; } bool has_main_screen() const { return false; } @@ -111,8 +107,6 @@ public: NavigationPolygonEditorPlugin(EditorNode *p_node); ~NavigationPolygonEditorPlugin(); - }; - #endif // NAVIGATIONPOLYGONEDITORPLUGIN_H diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index 1efdbe9e68..94644cd410 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -35,9 +35,9 @@ void Particles2DEditorPlugin::edit(Object *p_object) { if (p_object) { - particles=p_object->cast_to(); + particles = p_object->cast_to(); } else { - particles=NULL; + particles = NULL; } } @@ -55,145 +55,135 @@ void Particles2DEditorPlugin::make_visible(bool p_visible) { toolbar->hide(); } - } -void Particles2DEditorPlugin::_file_selected(const String& p_file) { +void Particles2DEditorPlugin::_file_selected(const String &p_file) { - print_line("file: "+p_file); + print_line("file: " + p_file); - int epc=epoints->get_value(); + int epc = epoints->get_value(); Image img; - Error err = ImageLoader::load_image(p_file,&img); - ERR_EXPLAIN(TTR("Error loading image:")+" "+p_file); - ERR_FAIL_COND(err!=OK); + Error err = ImageLoader::load_image(p_file, &img); + ERR_EXPLAIN(TTR("Error loading image:") + " " + p_file); + ERR_FAIL_COND(err != OK); img.convert(Image::FORMAT_LA8); - ERR_FAIL_COND(img.get_format()!=Image::FORMAT_LA8); - Size2i s = Size2(img.get_width(),img.get_height()); - ERR_FAIL_COND(s.width==0 || s.height==0); + ERR_FAIL_COND(img.get_format() != Image::FORMAT_LA8); + Size2i s = Size2(img.get_width(), img.get_height()); + ERR_FAIL_COND(s.width == 0 || s.height == 0); PoolVector data = img.get_data(); PoolVector::Read r = data.read(); Vector valid_positions; - valid_positions.resize(s.width*s.height); - int vpc=0; - + valid_positions.resize(s.width * s.height); + int vpc = 0; - for(int i=0;i128) { - valid_positions[vpc++]=Point2i(i%s.width,i/s.width); + uint8_t a = r[i * 2 + 1]; + if (a > 128) { + valid_positions[vpc++] = Point2i(i % s.width, i / s.width); } } valid_positions.resize(vpc); ERR_EXPLAIN(TTR("No pixels with transparency > 128 in image..")); - ERR_FAIL_COND(valid_positions.size()==0); + ERR_FAIL_COND(valid_positions.size() == 0); PoolVector epoints; epoints.resize(epc); PoolVector::Write w = epoints.write(); - Size2 extents = Size2(img.get_width()*0.5,img.get_height()*0.5); + Size2 extents = Size2(img.get_width() * 0.5, img.get_height() * 0.5); - for(int i=0;i::Write(); undo_redo->create_action(TTR("Set Emission Mask")); - undo_redo->add_do_method(particles,"set_emission_points",epoints); - undo_redo->add_do_method(particles,"set_emission_half_extents",extents); - undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points()); - undo_redo->add_undo_method(particles,"set_emission_half_extents",particles->get_emission_half_extents()); + undo_redo->add_do_method(particles, "set_emission_points", epoints); + undo_redo->add_do_method(particles, "set_emission_half_extents", extents); + undo_redo->add_undo_method(particles, "set_emission_points", particles->get_emission_points()); + undo_redo->add_undo_method(particles, "set_emission_half_extents", particles->get_emission_half_extents()); undo_redo->commit_action(); - } void Particles2DEditorPlugin::_menu_callback(int p_idx) { - switch(p_idx) { + switch (p_idx) { case MENU_LOAD_EMISSION_MASK: { - file->popup_centered_ratio(); } break; case MENU_CLEAR_EMISSION_MASK: { undo_redo->create_action(TTR("Clear Emission Mask")); - undo_redo->add_do_method(particles,"set_emission_points",PoolVector()); - undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points()); + undo_redo->add_do_method(particles, "set_emission_points", PoolVector()); + undo_redo->add_undo_method(particles, "set_emission_points", particles->get_emission_points()); undo_redo->commit_action(); } break; } - } - void Particles2DEditorPlugin::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - menu->get_popup()->connect("id_pressed",this,"_menu_callback"); - menu->set_icon(menu->get_popup()->get_icon("Particles2D","EditorIcons")); - file->connect("file_selected",this,"_file_selected"); + menu->get_popup()->connect("id_pressed", this, "_menu_callback"); + menu->set_icon(menu->get_popup()->get_icon("Particles2D", "EditorIcons")); + file->connect("file_selected", this, "_file_selected"); } } void Particles2DEditorPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_callback"),&Particles2DEditorPlugin::_menu_callback); - ClassDB::bind_method(D_METHOD("_file_selected"),&Particles2DEditorPlugin::_file_selected); + ClassDB::bind_method(D_METHOD("_menu_callback"), &Particles2DEditorPlugin::_menu_callback); + ClassDB::bind_method(D_METHOD("_file_selected"), &Particles2DEditorPlugin::_file_selected); } - - Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) { - particles=NULL; - editor=p_node; - undo_redo=editor->get_undo_redo(); + particles = NULL; + editor = p_node; + undo_redo = editor->get_undo_redo(); - toolbar = memnew( HBoxContainer ); + toolbar = memnew(HBoxContainer); add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, toolbar); toolbar->hide(); - toolbar->add_child( memnew( VSeparator ) ); + toolbar->add_child(memnew(VSeparator)); - menu = memnew( MenuButton ); - menu->get_popup()->add_item(TTR("Load Emission Mask"),MENU_LOAD_EMISSION_MASK); - menu->get_popup()->add_item(TTR("Clear Emission Mask"),MENU_CLEAR_EMISSION_MASK); + menu = memnew(MenuButton); + menu->get_popup()->add_item(TTR("Load Emission Mask"), MENU_LOAD_EMISSION_MASK); + menu->get_popup()->add_item(TTR("Clear Emission Mask"), MENU_CLEAR_EMISSION_MASK); menu->set_text("Particles"); toolbar->add_child(menu); - file = memnew( EditorFileDialog ); + file = memnew(EditorFileDialog); List ext; ImageLoader::get_recognized_extensions(&ext); - for(List::Element *E=ext.front();E;E=E->next()) { - file->add_filter("*."+E->get()+"; "+E->get().to_upper()); + for (List::Element *E = ext.front(); E; E = E->next()) { + file->add_filter("*." + E->get() + "; " + E->get().to_upper()); } file->set_mode(EditorFileDialog::MODE_OPEN_FILE); toolbar->add_child(file); - epoints = memnew( SpinBox ); + epoints = memnew(SpinBox); epoints->set_min(1); epoints->set_max(8192); epoints->set_step(1); epoints->set_value(512); - file->get_vbox()->add_margin_child(TTR("Generated Point Count:"),epoints); + file->get_vbox()->add_margin_child(TTR("Generated Point Count:"), epoints); } -Particles2DEditorPlugin::~Particles2DEditorPlugin() -{ +Particles2DEditorPlugin::~Particles2DEditorPlugin() { } - diff --git a/editor/plugins/particles_2d_editor_plugin.h b/editor/plugins/particles_2d_editor_plugin.h index ea71c739f3..56122c4354 100644 --- a/editor/plugins/particles_2d_editor_plugin.h +++ b/editor/plugins/particles_2d_editor_plugin.h @@ -29,17 +29,17 @@ #ifndef PARTICLES_2D_EDITOR_PLUGIN_H #define PARTICLES_2D_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/collision_polygon_2d.h" +#include "scene/2d/particles_2d.h" #include "scene/gui/box_container.h" #include "scene/gui/file_dialog.h" -#include "scene/2d/particles_2d.h" class Particles2DEditorPlugin : public EditorPlugin { - GDCLASS( Particles2DEditorPlugin, EditorPlugin ); + GDCLASS(Particles2DEditorPlugin, EditorPlugin); enum { @@ -58,15 +58,14 @@ class Particles2DEditorPlugin : public EditorPlugin { SpinBox *epoints; UndoRedo *undo_redo; - void _file_selected(const String& p_file); + void _file_selected(const String &p_file); void _menu_callback(int p_idx); + protected: void _notification(int p_what); static void _bind_methods(); public: - - virtual String get_name() const { return "Particles2D"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -75,8 +74,6 @@ public: Particles2DEditorPlugin(EditorNode *p_node); ~Particles2DEditorPlugin(); - }; - #endif // PARTICLES_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index 4ce1f5eb54..fd26674a0e 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -29,9 +29,9 @@ #if 0 #include "particles_editor_plugin.h" +#include "editor/plugins/spatial_editor_plugin.h" #include "io/resource_loader.h" #include "servers/visual/particle_system_sw.h" -#include "editor/plugins/spatial_editor_plugin.h" void ParticlesEditor::_node_removed(Node *p_node) { @@ -457,5 +457,4 @@ ParticlesEditorPlugin::~ParticlesEditorPlugin() { } - #endif diff --git a/editor/plugins/particles_editor_plugin.h b/editor/plugins/particles_editor_plugin.h index 06134ddef2..420e20d641 100644 --- a/editor/plugins/particles_editor_plugin.h +++ b/editor/plugins/particles_editor_plugin.h @@ -29,8 +29,8 @@ #ifndef PARTICLES_EDITOR_PLUGIN_H #define PARTICLES_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/3d/particles.h" #include "scene/gui/spin_box.h" diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 00b026e25b..36605c118f 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -29,12 +29,12 @@ #include "path_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "os/file_access.h" #include "editor/editor_settings.h" +#include "os/file_access.h" #include "os/keyboard.h" void Path2DEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_READY: { @@ -43,26 +43,21 @@ void Path2DEditor::_notification(int p_what) { //set_pressed_button(button_edit); //button_edit->set_pressed(true); - } break; case NOTIFICATION_FIXED_PROCESS: { - } break; } - } void Path2DEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); } - } - -bool Path2DEditor::forward_gui_input(const InputEvent& p_event) { +bool Path2DEditor::forward_gui_input(const InputEvent &p_event) { if (!node) return false; @@ -73,160 +68,151 @@ bool Path2DEditor::forward_gui_input(const InputEvent& p_event) { if (!node->get_curve().is_valid()) return false; - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - const InputEventMouseButton &mb=p_event.mouse_button; + const InputEventMouseButton &mb = p_event.mouse_button; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = Point2(mb.x,mb.y); - Vector2 cpoint = !mb.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) - : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); + Vector2 gpoint = Point2(mb.x, mb.y); + Vector2 cpoint = !mb.mod.alt ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); //first check if a point is to be added (segment split) - real_t grab_treshold=EDITOR_DEF("editors/poly_editor/point_grab_radius",8); - - + real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); // Test move point!! - if ( mb.pressed && action==ACTION_NONE ) { + if (mb.pressed && action == ACTION_NONE) { Ref curve = node->get_curve(); - for(int i=0;iget_point_count();i++) { + for (int i = 0; i < curve->get_point_count(); i++) { - bool pointunder=false; + bool pointunder = false; { - Point2 p = xform.xform( curve->get_point_pos(i) ); - if (gpoint.distance_to(p) < grab_treshold ) { + Point2 p = xform.xform(curve->get_point_pos(i)); + if (gpoint.distance_to(p) < grab_treshold) { - if (mb.button_index==BUTTON_LEFT && !mb.mod.shift && mode==MODE_EDIT) { + if (mb.button_index == BUTTON_LEFT && !mb.mod.shift && mode == MODE_EDIT) { - action=ACTION_MOVING_POINT; - action_point=i; - moving_from=curve->get_point_pos(i); - moving_screen_from=gpoint; + action = ACTION_MOVING_POINT; + action_point = i; + moving_from = curve->get_point_pos(i); + moving_screen_from = gpoint; return true; - } else if ((mb.button_index==BUTTON_RIGHT && mode==MODE_EDIT) || (mb.button_index==BUTTON_LEFT && mode==MODE_DELETE)) { + } else if ((mb.button_index == BUTTON_RIGHT && mode == MODE_EDIT) || (mb.button_index == BUTTON_LEFT && mode == MODE_DELETE)) { undo_redo->create_action(TTR("Remove Point from Curve")); - undo_redo->add_do_method(curve.ptr(),"remove_point",i); - undo_redo->add_undo_method(curve.ptr(),"add_point",curve->get_point_pos(i),curve->get_point_in(i),curve->get_point_out(i),i); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(curve.ptr(), "remove_point", i); + undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_pos(i), curve->get_point_in(i), curve->get_point_out(i), i); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return true; } else - pointunder=true; + pointunder = true; } } - if (mb.button_index==BUTTON_LEFT && i<(curve->get_point_count()-1)) { - Point2 p = xform.xform( curve->get_point_pos(i)+curve->get_point_out(i) ); - if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode==MODE_EDIT_CURVE) ) { + if (mb.button_index == BUTTON_LEFT && i < (curve->get_point_count() - 1)) { + Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_out(i)); + if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - action=ACTION_MOVING_OUT; - action_point=i; - moving_from=curve->get_point_out(i); - moving_screen_from=gpoint; + action = ACTION_MOVING_OUT; + action_point = i; + moving_from = curve->get_point_out(i); + moving_screen_from = gpoint; return true; } } - if (mb.button_index==BUTTON_LEFT && i>0) { - Point2 p = xform.xform( curve->get_point_pos(i)+curve->get_point_in(i) ); - if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode==MODE_EDIT_CURVE)) { + if (mb.button_index == BUTTON_LEFT && i > 0) { + Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_in(i)); + if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) { - action=ACTION_MOVING_IN; - action_point=i; - moving_from=curve->get_point_in(i); - moving_screen_from=gpoint; + action = ACTION_MOVING_IN; + action_point = i; + moving_from = curve->get_point_in(i); + moving_screen_from = gpoint; return true; } } if (pointunder) return true; - } - } // Test add point in empty space! - if ( mb.pressed && mb.button_index==BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) { + if (mb.pressed && mb.button_index == BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) { Ref curve = node->get_curve(); undo_redo->create_action(TTR("Add Point to Curve")); - undo_redo->add_do_method(curve.ptr(),"add_point",cpoint); - undo_redo->add_undo_method(curve.ptr(),"remove_point",curve->get_point_count()); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(curve.ptr(), "add_point", cpoint); + undo_redo->add_undo_method(curve.ptr(), "remove_point", curve->get_point_count()); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); - action=ACTION_MOVING_POINT; - action_point=curve->get_point_count()-1; - moving_from=curve->get_point_pos(action_point); - moving_screen_from=gpoint; + action = ACTION_MOVING_POINT; + action_point = curve->get_point_count() - 1; + moving_from = curve->get_point_pos(action_point); + moving_screen_from = gpoint; canvas_item_editor->get_viewport_control()->update(); return true; } - if ( !mb.pressed && mb.button_index==BUTTON_LEFT && action!=ACTION_NONE) { - + if (!mb.pressed && mb.button_index == BUTTON_LEFT && action != ACTION_NONE) { Ref curve = node->get_curve(); Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); - switch(action) { + switch (action) { case ACTION_MOVING_POINT: { - undo_redo->create_action(TTR("Move Point in Curve")); - undo_redo->add_do_method(curve.ptr(),"set_point_pos",action_point,cpoint); - undo_redo->add_undo_method(curve.ptr(),"set_point_pos",action_point,moving_from); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(curve.ptr(), "set_point_pos", action_point, cpoint); + undo_redo->add_undo_method(curve.ptr(), "set_point_pos", action_point, moving_from); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); } break; case ACTION_MOVING_IN: { undo_redo->create_action(TTR("Move In-Control in Curve")); - undo_redo->add_do_method(curve.ptr(),"set_point_in",action_point,new_pos); - undo_redo->add_undo_method(curve.ptr(),"set_point_in",action_point,moving_from); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(curve.ptr(), "set_point_in", action_point, new_pos); + undo_redo->add_undo_method(curve.ptr(), "set_point_in", action_point, moving_from); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); } break; case ACTION_MOVING_OUT: { undo_redo->create_action(TTR("Move Out-Control in Curve")); - undo_redo->add_do_method(curve.ptr(),"set_point_out",action_point,new_pos); - undo_redo->add_undo_method(curve.ptr(),"set_point_out",action_point,moving_from); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(curve.ptr(), "set_point_out", action_point, new_pos); + undo_redo->add_undo_method(curve.ptr(), "set_point_out", action_point, moving_from); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); } break; - } - action=ACTION_NONE; + action = ACTION_NONE; return true; } - #if 0 switch(mode) { @@ -411,44 +397,40 @@ bool Path2DEditor::forward_gui_input(const InputEvent& p_event) { } break; } - #endif } break; case InputEvent::MOUSE_MOTION: { - const InputEventMouseMotion &mm=p_event.mouse_motion; - + const InputEventMouseMotion &mm = p_event.mouse_motion; - if ( action!=ACTION_NONE) { + if (action != ACTION_NONE) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = Point2(mm.x,mm.y); - Vector2 cpoint = !mm.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) - : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); + Vector2 gpoint = Point2(mm.x, mm.y); + Vector2 cpoint = !mm.mod.alt ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); Ref curve = node->get_curve(); Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); - switch(action) { + switch (action) { case ACTION_MOVING_POINT: { - curve->set_point_pos(action_point,cpoint); + curve->set_point_pos(action_point, cpoint); } break; case ACTION_MOVING_IN: { - curve->set_point_in(action_point,new_pos); + curve->set_point_in(action_point, new_pos); } break; case ACTION_MOVING_OUT: { - curve->set_point_out(action_point,new_pos); + curve->set_point_out(action_point, new_pos); } break; } - canvas_item_editor->get_viewport_control()->update(); return true; } @@ -473,16 +455,16 @@ bool Path2DEditor::forward_gui_input(const InputEvent& p_event) { void Path2DEditor::_canvas_draw() { if (!node) - return ; + return; if (!node->is_visible_in_tree()) return; if (!node->get_curve().is_valid()) - return ; + return; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref handle= get_icon("EditorHandle","EditorIcons"); + Ref handle = get_icon("EditorHandle", "EditorIcons"); Size2 handle_size = handle->get_size(); Ref curve = node->get_curve(); @@ -490,27 +472,23 @@ void Path2DEditor::_canvas_draw() { int len = curve->get_point_count(); Control *vpc = canvas_item_editor->get_viewport_control(); - - for(int i=0;iget_point_pos(i)); - vpc->draw_texture_rect(handle,Rect2(point-handle_size*0.5,handle_size),false,Color(1,1,1,1)); + vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false, Color(1, 1, 1, 1)); - if (iget_point_pos(i)+curve->get_point_out(i)); - vpc->draw_line(point,pointout,Color(0.5,0.5,1.0,0.8),1.0); - vpc->draw_texture_rect(handle, Rect2(pointout-handle_size*0.5,handle_size),false,Color(1,0.5,1,0.3)); + if (i < len - 1) { + Vector2 pointout = xform.xform(curve->get_point_pos(i) + curve->get_point_out(i)); + vpc->draw_line(point, pointout, Color(0.5, 0.5, 1.0, 0.8), 1.0); + vpc->draw_texture_rect(handle, Rect2(pointout - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); } - if (i>0) { - Vector2 pointin = xform.xform(curve->get_point_pos(i)+curve->get_point_in(i)); - vpc->draw_line(point,pointin,Color(0.5,0.5,1.0,0.8),1.0); - vpc->draw_texture_rect(handle, Rect2(pointin-handle_size*0.5,handle_size),false,Color(1,0.5,1,0.3)); + if (i > 0) { + Vector2 pointin = xform.xform(curve->get_point_pos(i) + curve->get_point_in(i)); + vpc->draw_line(point, pointin, Color(0.5, 0.5, 1.0, 0.8), 1.0); + vpc->draw_texture_rect(handle, Rect2(pointin - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); } - } - } void Path2DEditor::_node_visibility_changed() { @@ -523,101 +501,98 @@ void Path2DEditor::_node_visibility_changed() { void Path2DEditor::edit(Node *p_path2d) { if (!canvas_item_editor) { - canvas_item_editor=CanvasItemEditor::get_singleton(); + canvas_item_editor = CanvasItemEditor::get_singleton(); } if (p_path2d) { - node=p_path2d->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"); + node = p_path2d->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"); if (!node->is_connected("visibility_changed", this, "_node_visibility_changed")) node->connect("visibility_changed", this, "_node_visibility_changed"); - } else { - if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) - canvas_item_editor->get_viewport_control()->disconnect("draw",this,"_canvas_draw"); + 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 may have been deleted at this point if (node && node->is_connected("visibility_changed", this, "_node_visibility_changed")) node->disconnect("visibility_changed", this, "_node_visibility_changed"); - node=NULL; + node = NULL; } - } void Path2DEditor::_bind_methods() { //ClassDB::bind_method(D_METHOD("_menu_option"),&Path2DEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"),&Path2DEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_node_visibility_changed"),&Path2DEditor::_node_visibility_changed); - ClassDB::bind_method(D_METHOD("_mode_selected"),&Path2DEditor::_mode_selected); + ClassDB::bind_method(D_METHOD("_canvas_draw"), &Path2DEditor::_canvas_draw); + ClassDB::bind_method(D_METHOD("_node_visibility_changed"), &Path2DEditor::_node_visibility_changed); + ClassDB::bind_method(D_METHOD("_mode_selected"), &Path2DEditor::_mode_selected); } void Path2DEditor::_mode_selected(int p_mode) { - if (p_mode==MODE_CREATE) { + if (p_mode == MODE_CREATE) { curve_create->set_pressed(true); curve_edit->set_pressed(false); curve_edit_curve->set_pressed(false); curve_del->set_pressed(false); - } else if (p_mode==MODE_EDIT) { + } else if (p_mode == MODE_EDIT) { curve_create->set_pressed(false); curve_edit->set_pressed(true); curve_edit_curve->set_pressed(false); curve_del->set_pressed(false); - } else if (p_mode==MODE_EDIT_CURVE) { + } else if (p_mode == MODE_EDIT_CURVE) { curve_create->set_pressed(false); curve_edit->set_pressed(false); curve_edit_curve->set_pressed(true); curve_del->set_pressed(false); - } else if (p_mode==MODE_DELETE) { + } else if (p_mode == MODE_DELETE) { curve_create->set_pressed(false); curve_edit->set_pressed(false); curve_edit_curve->set_pressed(false); curve_del->set_pressed(true); - } else if (p_mode==ACTION_CLOSE) { + } else if (p_mode == ACTION_CLOSE) { //? if (!node->get_curve().is_valid()) - return ; - if (node->get_curve()->get_point_count()<3) + return; + if (node->get_curve()->get_point_count() < 3) return; Vector2 begin = node->get_curve()->get_point_pos(0); - Vector2 end = node->get_curve()->get_point_pos( node->get_curve()->get_point_count() -1 ); - if (begin.distance_to(end)get_curve()->get_point_pos(node->get_curve()->get_point_count() - 1); + if (begin.distance_to(end) < CMP_EPSILON) return; undo_redo->create_action(TTR("Remove Point from Curve")); - undo_redo->add_do_method(node->get_curve().ptr(),"add_point",begin); - undo_redo->add_undo_method(node->get_curve().ptr(),"remove_point",node->get_curve()->get_point_count()); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node->get_curve().ptr(), "add_point", begin); + undo_redo->add_undo_method(node->get_curve().ptr(), "remove_point", node->get_curve()->get_point_count()); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return; } - mode=Mode(p_mode); - + mode = Mode(p_mode); } Path2DEditor::Path2DEditor(EditorNode *p_editor) { - canvas_item_editor=NULL; - editor=p_editor; + canvas_item_editor = NULL; + editor = p_editor; undo_redo = editor->get_undo_redo(); - mode=MODE_EDIT; + mode = MODE_EDIT; - action=ACTION_NONE; + action = ACTION_NONE; #if 0 options = memnew( MenuButton ); add_child(options); @@ -627,55 +602,50 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) { options->get_popup()->connect("id_pressed", this,"_menu_option"); #endif - base_hb = memnew( HBoxContainer ); + base_hb = memnew(HBoxContainer); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(base_hb); - sep = memnew( VSeparator); + sep = memnew(VSeparator); base_hb->add_child(sep); - curve_edit = memnew( ToolButton ); - curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit","EditorIcons")); + curve_edit = memnew(ToolButton); + curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit", "EditorIcons")); curve_edit->set_toggle_mode(true); curve_edit->set_focus_mode(Control::FOCUS_NONE); - curve_edit->set_tooltip(TTR("Select Points")+"\n"+TTR("Shift+Drag: Select Control Points")+"\n"+keycode_get_string(KEY_MASK_CMD)+TTR("Click: Add Point")+"\n"+TTR("Right Click: Delete Point")); - curve_edit->connect("pressed",this,"_mode_selected",varray(MODE_EDIT)); + curve_edit->set_tooltip(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point")); + curve_edit->connect("pressed", this, "_mode_selected", varray(MODE_EDIT)); base_hb->add_child(curve_edit); - curve_edit_curve = memnew( ToolButton ); - curve_edit_curve->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCurve","EditorIcons")); + curve_edit_curve = memnew(ToolButton); + curve_edit_curve->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCurve", "EditorIcons")); curve_edit_curve->set_toggle_mode(true); curve_edit_curve->set_focus_mode(Control::FOCUS_NONE); curve_edit_curve->set_tooltip(TTR("Select Control Points (Shift+Drag)")); - curve_edit_curve->connect("pressed",this,"_mode_selected",varray(MODE_EDIT_CURVE)); + curve_edit_curve->connect("pressed", this, "_mode_selected", varray(MODE_EDIT_CURVE)); base_hb->add_child(curve_edit_curve); - curve_create = memnew( ToolButton ); - curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate","EditorIcons")); + curve_create = memnew(ToolButton); + curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate", "EditorIcons")); curve_create->set_toggle_mode(true); curve_create->set_focus_mode(Control::FOCUS_NONE); - curve_create->set_tooltip(TTR("Add Point (in empty space)")+"\n"+TTR("Split Segment (in curve)")); - curve_create->connect("pressed",this,"_mode_selected",varray(MODE_CREATE)); + curve_create->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)")); + curve_create->connect("pressed", this, "_mode_selected", varray(MODE_CREATE)); base_hb->add_child(curve_create); - curve_del = memnew( ToolButton ); - curve_del->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete","EditorIcons")); + curve_del = memnew(ToolButton); + curve_del->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete", "EditorIcons")); curve_del->set_toggle_mode(true); curve_del->set_focus_mode(Control::FOCUS_NONE); curve_del->set_tooltip(TTR("Delete Point")); - curve_del->connect("pressed",this,"_mode_selected",varray(MODE_DELETE)); + curve_del->connect("pressed", this, "_mode_selected", varray(MODE_DELETE)); base_hb->add_child(curve_del); - curve_close = memnew( ToolButton ); - curve_close->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveClose","EditorIcons")); + curve_close = memnew(ToolButton); + curve_close->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveClose", "EditorIcons")); curve_close->set_focus_mode(Control::FOCUS_NONE); curve_close->set_tooltip(TTR("Close Curve")); - curve_close->connect("pressed",this,"_mode_selected",varray(ACTION_CLOSE)); + curve_close->connect("pressed", this, "_mode_selected", varray(ACTION_CLOSE)); base_hb->add_child(curve_close); base_hb->hide(); - - curve_edit->set_pressed(true); - - } - void Path2DEditorPlugin::edit(Object *p_object) { path2d_editor->edit(p_object->cast_to()); @@ -698,21 +668,15 @@ void Path2DEditorPlugin::make_visible(bool p_visible) { path2d_editor->base_hb->hide(); path2d_editor->edit(NULL); } - } Path2DEditorPlugin::Path2DEditorPlugin(EditorNode *p_node) { - editor=p_node; - path2d_editor = memnew( Path2DEditor(p_node) ); + editor = p_node; + path2d_editor = memnew(Path2DEditor(p_node)); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(path2d_editor); path2d_editor->hide(); - - } - -Path2DEditorPlugin::~Path2DEditorPlugin() -{ +Path2DEditorPlugin::~Path2DEditorPlugin() { } - diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h index 89f42d94cc..32dd6868bb 100644 --- a/editor/plugins/path_2d_editor_plugin.h +++ b/editor/plugins/path_2d_editor_plugin.h @@ -29,11 +29,11 @@ #ifndef PATH_2D_EDITOR_PLUGIN_H #define PATH_2D_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/path_2d.h" -#include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" +#include "scene/gui/tool_button.h" /** @author Juan Linietsky @@ -77,7 +77,6 @@ class Path2DEditor : public HBoxContainer { ACTION_MOVING_OUT, }; - Action action; int action_point; Point2 moving_from; @@ -87,28 +86,28 @@ class Path2DEditor : public HBoxContainer { void _canvas_draw(); void _node_visibility_changed(); -friend class Path2DEditorPlugin; + friend class Path2DEditorPlugin; + protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); -public: - bool forward_gui_input(const InputEvent& p_event); +public: + bool forward_gui_input(const InputEvent &p_event); void edit(Node *p_path2d); Path2DEditor(EditorNode *p_editor); }; class Path2DEditorPlugin : public EditorPlugin { - GDCLASS( Path2DEditorPlugin, EditorPlugin ); + GDCLASS(Path2DEditorPlugin, EditorPlugin); Path2DEditor *path2d_editor; EditorNode *editor; public: - - virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform,const InputEvent& p_event) { return path2d_editor->forward_gui_input(p_event); } + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return path2d_editor->forward_gui_input(p_event); } virtual String get_name() const { return "Path2D"; } bool has_main_screen() const { return false; } @@ -118,9 +117,6 @@ public: Path2DEditorPlugin(EditorNode *p_node); ~Path2DEditorPlugin(); - }; - - #endif // PATH_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp index a3df39fdaa..0b3587bc5e 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -28,9 +28,9 @@ /*************************************************************************/ #include "path_editor_plugin.h" -#include "spatial_editor_plugin.h" -#include "scene/resources/curve.h" #include "os/keyboard.h" +#include "scene/resources/curve.h" +#include "spatial_editor_plugin.h" #if 0 String PathSpatialGizmo::get_handle_name(int p_idx) const { diff --git a/editor/plugins/path_editor_plugin.h b/editor/plugins/path_editor_plugin.h index fe1c5ad159..9d0f6eb9f2 100644 --- a/editor/plugins/path_editor_plugin.h +++ b/editor/plugins/path_editor_plugin.h @@ -29,10 +29,9 @@ #ifndef PATH_EDITOR_PLUGIN_H #define PATH_EDITOR_PLUGIN_H - #include "editor/spatial_editor_gizmos.h" #include "scene/3d/path.h" -# if 0 +#if 0 class PathSpatialGizmo : public EditorSpatialGizmo { GDCLASS(PathSpatialGizmo,EditorSpatialGizmo); diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 3a41b2cb6b..8d208f9cee 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -29,66 +29,62 @@ #include "polygon_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "os/file_access.h" #include "editor/editor_settings.h" -#include "os/keyboard.h" +#include "os/file_access.h" #include "os/input.h" +#include "os/keyboard.h" void Polygon2DEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_READY: { - button_create->set_icon( get_icon("Edit","EditorIcons")); - button_edit->set_icon( get_icon("MovePoint","EditorIcons")); + button_create->set_icon(get_icon("Edit", "EditorIcons")); + button_edit->set_icon(get_icon("MovePoint", "EditorIcons")); button_edit->set_pressed(true); - button_uv->set_icon( get_icon("Uv","EditorIcons")); + button_uv->set_icon(get_icon("Uv", "EditorIcons")); - uv_button[UV_MODE_EDIT_POINT]->set_icon(get_icon("ToolSelect","EditorIcons")); - uv_button[UV_MODE_MOVE]->set_icon(get_icon("ToolMove","EditorIcons")); - uv_button[UV_MODE_ROTATE]->set_icon(get_icon("ToolRotate","EditorIcons")); - uv_button[UV_MODE_SCALE]->set_icon(get_icon("ToolScale","EditorIcons")); + uv_button[UV_MODE_EDIT_POINT]->set_icon(get_icon("ToolSelect", "EditorIcons")); + uv_button[UV_MODE_MOVE]->set_icon(get_icon("ToolMove", "EditorIcons")); + uv_button[UV_MODE_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons")); + uv_button[UV_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons")); - b_snap_grid->set_icon( get_icon("Grid", "EditorIcons")); - b_snap_enable->set_icon( get_icon("Snap", "EditorIcons")); - uv_icon_zoom->set_texture( get_icon("Zoom", "EditorIcons")); + b_snap_grid->set_icon(get_icon("Grid", "EditorIcons")); + b_snap_enable->set_icon(get_icon("Snap", "EditorIcons")); + uv_icon_zoom->set_texture(get_icon("Zoom", "EditorIcons")); get_tree()->connect("node_removed", this, "_node_removed"); } break; case NOTIFICATION_FIXED_PROCESS: { - } break; } - } void Polygon2DEditor::_node_removed(Node *p_node) { - if(p_node==node) { + if (p_node == node) { edit(NULL); hide(); canvas_item_editor->get_viewport_control()->update(); } - } - void Polygon2DEditor::_menu_option(int p_option) { - switch(p_option) { + switch (p_option) { case MODE_CREATE: { - mode=MODE_CREATE; + mode = MODE_CREATE; button_create->set_pressed(true); button_edit->set_pressed(false); } break; case MODE_EDIT: { - mode=MODE_EDIT; + mode = MODE_EDIT; button_create->set_pressed(false); button_edit->set_pressed(true); } break; @@ -101,238 +97,216 @@ void Polygon2DEditor::_menu_option(int p_option) { return; } - PoolVector points = node->get_polygon(); PoolVector uvs = node->get_uv(); - if (uvs.size()!=points.size()) { + if (uvs.size() != points.size()) { undo_redo->create_action(TTR("Create UV Map")); - undo_redo->add_do_method(node,"set_uv",points); - undo_redo->add_undo_method(node,"set_uv",uvs); - undo_redo->add_do_method(uv_edit_draw,"update"); - undo_redo->add_undo_method(uv_edit_draw,"update"); + undo_redo->add_do_method(node, "set_uv", points); + undo_redo->add_undo_method(node, "set_uv", uvs); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); - } - uv_edit->popup_centered_ratio(0.85); } break; case UVEDIT_POLYGON_TO_UV: { PoolVector points = node->get_polygon(); - if (points.size()==0) + if (points.size() == 0) break; PoolVector uvs = node->get_uv(); undo_redo->create_action(TTR("Create UV Map")); - undo_redo->add_do_method(node,"set_uv",points); - undo_redo->add_undo_method(node,"set_uv",uvs); - undo_redo->add_do_method(uv_edit_draw,"update"); - undo_redo->add_undo_method(uv_edit_draw,"update"); + undo_redo->add_do_method(node, "set_uv", points); + undo_redo->add_undo_method(node, "set_uv", uvs); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); - } break; case UVEDIT_UV_TO_POLYGON: { PoolVector points = node->get_polygon(); PoolVector uvs = node->get_uv(); - if (uvs.size()==0) + if (uvs.size() == 0) break; undo_redo->create_action(TTR("Create UV Map")); - undo_redo->add_do_method(node,"set_polygon",uvs); - undo_redo->add_undo_method(node,"set_polygon",points); - undo_redo->add_do_method(uv_edit_draw,"update"); - undo_redo->add_undo_method(uv_edit_draw,"update"); + undo_redo->add_do_method(node, "set_polygon", uvs); + undo_redo->add_undo_method(node, "set_polygon", points); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); } break; case UVEDIT_UV_CLEAR: { PoolVector uvs = node->get_uv(); - if (uvs.size()==0) + if (uvs.size() == 0) break; undo_redo->create_action(TTR("Create UV Map")); - undo_redo->add_do_method(node,"set_uv",PoolVector()); - undo_redo->add_undo_method(node,"set_uv",uvs); - undo_redo->add_do_method(uv_edit_draw,"update"); - undo_redo->add_undo_method(uv_edit_draw,"update"); + undo_redo->add_do_method(node, "set_uv", PoolVector()); + undo_redo->add_undo_method(node, "set_uv", uvs); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); } break; - - } } -void Polygon2DEditor::_set_use_snap(bool p_use) -{ - use_snap=p_use; +void Polygon2DEditor::_set_use_snap(bool p_use) { + use_snap = p_use; } -void Polygon2DEditor::_set_show_grid(bool p_show) -{ - snap_show_grid=p_show; +void Polygon2DEditor::_set_show_grid(bool p_show) { + snap_show_grid = p_show; uv_edit_draw->update(); } -void Polygon2DEditor::_set_snap_off_x(float p_val) -{ - snap_offset.x=p_val; +void Polygon2DEditor::_set_snap_off_x(float p_val) { + snap_offset.x = p_val; uv_edit_draw->update(); } -void Polygon2DEditor::_set_snap_off_y(float p_val) -{ - snap_offset.y=p_val; +void Polygon2DEditor::_set_snap_off_y(float p_val) { + snap_offset.y = p_val; uv_edit_draw->update(); } -void Polygon2DEditor::_set_snap_step_x(float p_val) -{ - snap_step.x=p_val; +void Polygon2DEditor::_set_snap_step_x(float p_val) { + snap_step.x = p_val; uv_edit_draw->update(); } -void Polygon2DEditor::_set_snap_step_y(float p_val) -{ - snap_step.y=p_val; +void Polygon2DEditor::_set_snap_step_y(float p_val) { + snap_step.y = p_val; uv_edit_draw->update(); } void Polygon2DEditor::_wip_close() { undo_redo->create_action(TTR("Create Poly")); - undo_redo->add_undo_method(node,"set_polygon",node->get_polygon()); - undo_redo->add_do_method(node,"set_polygon",wip); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(node, "set_polygon", node->get_polygon()); + undo_redo->add_do_method(node, "set_polygon", wip); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); wip.clear(); - wip_active=false; - mode=MODE_EDIT; + wip_active = false; + mode = MODE_EDIT; button_edit->set_pressed(true); button_create->set_pressed(false); - edited_point=-1; + edited_point = -1; } -bool Polygon2DEditor::forward_gui_input(const InputEvent& p_event) { +bool Polygon2DEditor::forward_gui_input(const InputEvent &p_event) { - if (node==NULL) + if (node == NULL) return false; - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - const InputEventMouseButton &mb=p_event.mouse_button; + const InputEventMouseButton &mb = p_event.mouse_button; Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - - Vector2 gpoint = Point2(mb.x,mb.y); + Vector2 gpoint = Point2(mb.x, mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); - Vector poly = Variant(node->get_polygon()); //first check if a point is to be added (segment split) - real_t grab_treshold=EDITOR_DEF("editors/poly_editor/point_grab_radius",8); - - switch(mode) { + real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); + switch (mode) { case MODE_CREATE: { - if (mb.button_index==BUTTON_LEFT && mb.pressed) { - + if (mb.button_index == BUTTON_LEFT && mb.pressed) { if (!wip_active) { wip.clear(); - wip.push_back( cpoint-node->get_offset() ); - wip_active=true; - edited_point_pos=cpoint; + wip.push_back(cpoint - node->get_offset()); + wip_active = true; + edited_point_pos = cpoint; canvas_item_editor->get_viewport_control()->update(); - edited_point=1; + edited_point = 1; return true; } else { - - if (wip.size()>1 && xform.xform(wip[0]+node->get_offset()).distance_to(gpoint) 1 && xform.xform(wip[0] + node->get_offset()).distance_to(gpoint) < grab_treshold) { //wip closed _wip_close(); return true; } else { - wip.push_back( cpoint-node->get_offset() ); - edited_point=wip.size(); + wip.push_back(cpoint - node->get_offset()); + edited_point = wip.size(); canvas_item_editor->get_viewport_control()->update(); return true; //add wip point } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) { _wip_close(); } - - } break; case MODE_EDIT: { - if (mb.button_index==BUTTON_LEFT) { + if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { if (mb.mod.control) { - if (poly.size() < 3) { undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_undo_method(node,"set_polygon",poly); + undo_redo->add_undo_method(node, "set_polygon", poly); poly.push_back(cpoint); - undo_redo->add_do_method(node,"set_polygon",poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node, "set_polygon", poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return true; } //search edges - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;iget_offset()), - xform.xform(poly[(i+1)%poly.size()]+node->get_offset()) }; + Vector2 points[2] = { xform.xform(poly[i] + node->get_offset()), + xform.xform(poly[(i + 1) % poly.size()] + node->get_offset()) }; - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points); - if (cp.distance_squared_to(points[0])=0) { + if (closest_idx >= 0) { - pre_move_edit=poly; - poly.insert(closest_idx+1,xform.affine_inverse().xform(closest_pos)-node->get_offset()); - edited_point=closest_idx+1; - edited_point_pos=xform.affine_inverse().xform(closest_pos); + pre_move_edit = poly; + poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos) - node->get_offset()); + edited_point = closest_idx + 1; + edited_point_pos = xform.affine_inverse().xform(closest_pos); node->set_polygon(Variant(poly)); canvas_item_editor->get_viewport_control()->update(); return true; @@ -341,106 +315,95 @@ bool Polygon2DEditor::forward_gui_input(const InputEvent& p_event) { //look for points to move - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;iget_offset()); + Vector2 cp = xform.xform(poly[i] + node->get_offset()); real_t d = cp.distance_to(gpoint); - if (d=0) { + if (closest_idx >= 0) { - pre_move_edit=poly; - edited_point=closest_idx; - edited_point_pos=xform.affine_inverse().xform(closest_pos); + pre_move_edit = poly; + edited_point = closest_idx; + edited_point_pos = xform.affine_inverse().xform(closest_pos); canvas_item_editor->get_viewport_control()->update(); return true; } } } else { - if (edited_point!=-1) { + if (edited_point != -1) { //apply - ERR_FAIL_INDEX_V(edited_point,poly.size(),false); - poly[edited_point]=edited_point_pos-node->get_offset(); + ERR_FAIL_INDEX_V(edited_point, poly.size(), false); + poly[edited_point] = edited_point_pos - node->get_offset(); undo_redo->create_action(TTR("Edit Poly")); - undo_redo->add_do_method(node,"set_polygon",poly); - undo_redo->add_undo_method(node,"set_polygon",pre_move_edit); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node, "set_polygon", poly); + undo_redo->add_undo_method(node, "set_polygon", pre_move_edit); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); - edited_point=-1; + edited_point = -1; return true; } } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) { - - - int closest_idx=-1; + int closest_idx = -1; Vector2 closest_pos; - real_t closest_dist=1e10; - for(int i=0;iget_offset()); + Vector2 cp = xform.xform(poly[i] + node->get_offset()); real_t d = cp.distance_to(gpoint); - if (d=0) { - + if (closest_idx >= 0) { undo_redo->create_action(TTR("Edit Poly (Remove Point)")); - undo_redo->add_undo_method(node,"set_polygon",poly); + undo_redo->add_undo_method(node, "set_polygon", poly); poly.remove(closest_idx); - undo_redo->add_do_method(node,"set_polygon",poly); - undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); - undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_do_method(node, "set_polygon", poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update"); undo_redo->commit_action(); return true; } - } - - } break; } - - } break; case InputEvent::MOUSE_MOTION: { - const InputEventMouseMotion &mm=p_event.mouse_motion; + const InputEventMouseMotion &mm = p_event.mouse_motion; - if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { + if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) { - Vector2 gpoint = Point2(mm.x,mm.y); + Vector2 gpoint = Point2(mm.x, mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); - } } break; @@ -458,170 +421,159 @@ void Polygon2DEditor::_canvas_draw() { Vector poly; if (wip_active) - poly=wip; + poly = wip; else - poly=Variant(node->get_polygon()); - + poly = Variant(node->get_polygon()); Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref handle= get_icon("EditorHandle","EditorIcons"); + Ref handle = get_icon("EditorHandle", "EditorIcons"); - for(int i=0;iget_offset()); - if ((wip_active && i==poly.size()-1) || (((i+1)%poly.size())==edited_point)) - p2=edited_point_pos; + Vector2 p, p2; + p = i == edited_point ? edited_point_pos : (poly[i] + node->get_offset()); + if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) + p2 = edited_point_pos; else - p2 = poly[(i+1)%poly.size()]+node->get_offset(); + p2 = poly[(i + 1) % poly.size()] + node->get_offset(); Vector2 point = xform.xform(p); Vector2 next_point = xform.xform(p2); - Color col=Color(1,0.3,0.1,0.8); - vpc->draw_line(point,next_point,col,2); - vpc->draw_texture(handle,point-handle->get_size()*0.5); + Color col = Color(1, 0.3, 0.1, 0.8); + vpc->draw_line(point, next_point, col, 2); + vpc->draw_texture(handle, point - handle->get_size() * 0.5); } } - void Polygon2DEditor::_uv_mode(int p_mode) { - - uv_mode=UVMode(p_mode); - for(int i=0;iset_pressed(p_mode==i); + uv_mode = UVMode(p_mode); + for (int i = 0; i < UV_MODE_MAX; i++) { + uv_button[i]->set_pressed(p_mode == i); } } - -void Polygon2DEditor::_uv_input(const InputEvent& p_input) { - +void Polygon2DEditor::_uv_input(const InputEvent &p_input) { Transform2D mtx; - mtx.elements[2]=-uv_draw_ofs; - mtx.scale_basis(Vector2(uv_draw_zoom,uv_draw_zoom)); - - if (p_input.type==InputEvent::MOUSE_BUTTON) { + mtx.elements[2] = -uv_draw_ofs; + mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom)); + if (p_input.type == InputEvent::MOUSE_BUTTON) { - const InputEventMouseButton &mb=p_input.mouse_button; - - if (mb.button_index==BUTTON_LEFT) { + const InputEventMouseButton &mb = p_input.mouse_button; + if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { - uv_drag_from=Vector2(mb.x,mb.y); - uv_drag=true; - uv_prev=node->get_uv(); - uv_move_current=uv_mode; - if (uv_move_current==UV_MODE_EDIT_POINT) { + uv_drag_from = Vector2(mb.x, mb.y); + uv_drag = true; + uv_prev = node->get_uv(); + uv_move_current = uv_mode; + if (uv_move_current == UV_MODE_EDIT_POINT) { if (mb.mod.shift && mb.mod.command) - uv_move_current=UV_MODE_SCALE; + uv_move_current = UV_MODE_SCALE; else if (mb.mod.shift) - uv_move_current=UV_MODE_MOVE; + uv_move_current = UV_MODE_MOVE; else if (mb.mod.command) - uv_move_current=UV_MODE_ROTATE; + uv_move_current = UV_MODE_ROTATE; } - if (uv_move_current==UV_MODE_EDIT_POINT) { + if (uv_move_current == UV_MODE_EDIT_POINT) { - uv_drag_index=-1; - for(int i=0;icreate_action(TTR("Transform UV Map")); - undo_redo->add_do_method(node,"set_uv",node->get_uv()); - undo_redo->add_undo_method(node,"set_uv",uv_prev); - undo_redo->add_do_method(uv_edit_draw,"update"); - undo_redo->add_undo_method(uv_edit_draw,"update"); + undo_redo->add_do_method(node, "set_uv", node->get_uv()); + undo_redo->add_undo_method(node, "set_uv", uv_prev); + undo_redo->add_do_method(uv_edit_draw, "update"); + undo_redo->add_undo_method(uv_edit_draw, "update"); undo_redo->commit_action(); - uv_drag=false; + uv_drag = false; } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed) { if (uv_drag) { - uv_drag=false; + uv_drag = false; node->set_uv(uv_prev); uv_edit_draw->update(); } - } else if (mb.button_index==BUTTON_WHEEL_UP && mb.pressed) { + } else if (mb.button_index == BUTTON_WHEEL_UP && mb.pressed) { - uv_zoom->set_value( uv_zoom->get_value()/0.9 ); - } else if (mb.button_index==BUTTON_WHEEL_DOWN && mb.pressed) { + uv_zoom->set_value(uv_zoom->get_value() / 0.9); + } else if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) { - uv_zoom->set_value( uv_zoom->get_value()*0.9); + uv_zoom->set_value(uv_zoom->get_value() * 0.9); } - } else if (p_input.type==InputEvent::MOUSE_MOTION) { + } else if (p_input.type == InputEvent::MOUSE_MOTION) { - const InputEventMouseMotion &mm=p_input.mouse_motion; + const InputEventMouseMotion &mm = p_input.mouse_motion; - if (mm.button_mask&BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) { + if (mm.button_mask & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) { - Vector2 drag(mm.relative_x,mm.relative_y); - uv_hscroll->set_value( uv_hscroll->get_value()-drag.x ); - uv_vscroll->set_value( uv_vscroll->get_value()-drag.y ); + Vector2 drag(mm.relative_x, mm.relative_y); + uv_hscroll->set_value(uv_hscroll->get_value() - drag.x); + uv_vscroll->set_value(uv_vscroll->get_value() - drag.y); } else if (uv_drag) { - Vector2 uv_drag_to=snap_point(Vector2(mm.x,mm.y)); + Vector2 uv_drag_to = snap_point(Vector2(mm.x, mm.y)); Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from); - - switch(uv_move_current) { + switch (uv_move_current) { case UV_MODE_EDIT_POINT: { - PoolVector uv_new=uv_prev; - uv_new.set( uv_drag_index, uv_new[uv_drag_index]+drag ); + PoolVector uv_new = uv_prev; + uv_new.set(uv_drag_index, uv_new[uv_drag_index] + drag); node->set_uv(uv_new); } break; case UV_MODE_MOVE: { - PoolVector uv_new=uv_prev; - for(int i=0;i uv_new = uv_prev; + for (int i = 0; i < uv_new.size(); i++) + uv_new.set(i, uv_new[i] + drag); node->set_uv(uv_new); - } break; case UV_MODE_ROTATE: { Vector2 center; - PoolVector uv_new=uv_prev; + PoolVector uv_new = uv_prev; - for(int i=0;iset_uv(uv_new); @@ -630,47 +582,41 @@ void Polygon2DEditor::_uv_input(const InputEvent& p_input) { case UV_MODE_SCALE: { Vector2 center; - PoolVector uv_new=uv_prev; + PoolVector uv_new = uv_prev; - for(int i=0;iset_uv(uv_new); } break; - - } uv_edit_draw->update(); } - } - } - void Polygon2DEditor::_uv_scroll_changed(float) { if (updating_uv_scroll) return; - uv_draw_ofs.x=uv_hscroll->get_value(); - uv_draw_ofs.y=uv_vscroll->get_value(); - uv_draw_zoom=uv_zoom->get_value(); + uv_draw_ofs.x = uv_hscroll->get_value(); + uv_draw_ofs.y = uv_vscroll->get_value(); + uv_draw_zoom = uv_zoom->get_value(); uv_edit_draw->update(); } @@ -681,115 +627,110 @@ void Polygon2DEditor::_uv_draw() { return; Transform2D mtx; - mtx.elements[2]=-uv_draw_ofs; - mtx.scale_basis(Vector2(uv_draw_zoom,uv_draw_zoom)); + mtx.elements[2] = -uv_draw_ofs; + mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom)); - VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(),mtx); - uv_edit_draw->draw_texture(base_tex,Point2()); - VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(),Transform2D()); + VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), mtx); + uv_edit_draw->draw_texture(base_tex, Point2()); + VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D()); if (snap_show_grid) { Size2 s = uv_edit_draw->get_size(); int last_cell; - if (snap_step.x!=0) { - for(int i=0;idraw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3)); - last_cell=cell; + if (snap_step.x != 0) { + for (int i = 0; i < s.width; i++) { + int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x)); + if (i == 0) + last_cell = cell; + if (last_cell != cell) + uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } } - if (snap_step.y!=0) { - for(int i=0;idraw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3)); - last_cell=cell; + if (snap_step.y != 0) { + for (int i = 0; i < s.height; i++) { + int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y)); + if (i == 0) + last_cell = cell; + if (last_cell != cell) + uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } } } PoolVector uvs = node->get_uv(); - Ref handle = get_icon("EditorHandle","EditorIcons"); + Ref handle = get_icon("EditorHandle", "EditorIcons"); - Rect2 rect(Point2(),mtx.basis_xform(base_tex->get_size())); + Rect2 rect(Point2(), mtx.basis_xform(base_tex->get_size())); rect.expand_to(mtx.basis_xform(uv_edit_draw->get_size())); - for(int i=0;idraw_line(mtx.xform(uvs[i]),mtx.xform(uvs[next]),Color(0.9,0.5,0.5),2); - uv_edit_draw->draw_texture(handle,mtx.xform(uvs[i])-handle->get_size()*0.5); + int next = (i + 1) % uvs.size(); + uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(uvs[next]), Color(0.9, 0.5, 0.5), 2); + uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5); rect.expand_to(mtx.basis_xform(uvs[i])); } - rect=rect.grow(200); - updating_uv_scroll=true; + rect = rect.grow(200); + updating_uv_scroll = true; uv_hscroll->set_min(rect.pos.x); - uv_hscroll->set_max(rect.pos.x+rect.size.x); + uv_hscroll->set_max(rect.pos.x + rect.size.x); uv_hscroll->set_page(uv_edit_draw->get_size().x); uv_hscroll->set_value(uv_draw_ofs.x); uv_hscroll->set_step(0.001); uv_vscroll->set_min(rect.pos.y); - uv_vscroll->set_max(rect.pos.y+rect.size.y); + uv_vscroll->set_max(rect.pos.y + rect.size.y); uv_vscroll->set_page(uv_edit_draw->get_size().y); uv_vscroll->set_value(uv_draw_ofs.y); uv_vscroll->set_step(0.001); - updating_uv_scroll=false; - + updating_uv_scroll = false; } void Polygon2DEditor::edit(Node *p_collision_polygon) { if (!canvas_item_editor) { - canvas_item_editor=CanvasItemEditor::get_singleton(); + canvas_item_editor = CanvasItemEditor::get_singleton(); } if (p_collision_polygon) { - node=p_collision_polygon->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"); + node = p_collision_polygon->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"); wip.clear(); - wip_active=false; - edited_point=-1; + wip_active = false; + edited_point = -1; } else { - node=NULL; - - 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; + if (canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw", this, "_canvas_draw"); } - } void Polygon2DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_option"),&Polygon2DEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"),&Polygon2DEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_uv_mode"),&Polygon2DEditor::_uv_mode); - ClassDB::bind_method(D_METHOD("_uv_draw"),&Polygon2DEditor::_uv_draw); - ClassDB::bind_method(D_METHOD("_uv_input"),&Polygon2DEditor::_uv_input); - ClassDB::bind_method(D_METHOD("_uv_scroll_changed"),&Polygon2DEditor::_uv_scroll_changed); - ClassDB::bind_method(D_METHOD("_node_removed"),&Polygon2DEditor::_node_removed); - ClassDB::bind_method(D_METHOD("_set_use_snap"),&Polygon2DEditor::_set_use_snap); - ClassDB::bind_method(D_METHOD("_set_show_grid"),&Polygon2DEditor::_set_show_grid); - ClassDB::bind_method(D_METHOD("_set_snap_off_x"),&Polygon2DEditor::_set_snap_off_x); - ClassDB::bind_method(D_METHOD("_set_snap_off_y"),&Polygon2DEditor::_set_snap_off_y); - ClassDB::bind_method(D_METHOD("_set_snap_step_x"),&Polygon2DEditor::_set_snap_step_x); - ClassDB::bind_method(D_METHOD("_set_snap_step_y"),&Polygon2DEditor::_set_snap_step_y); - - + ClassDB::bind_method(D_METHOD("_menu_option"), &Polygon2DEditor::_menu_option); + ClassDB::bind_method(D_METHOD("_canvas_draw"), &Polygon2DEditor::_canvas_draw); + ClassDB::bind_method(D_METHOD("_uv_mode"), &Polygon2DEditor::_uv_mode); + ClassDB::bind_method(D_METHOD("_uv_draw"), &Polygon2DEditor::_uv_draw); + ClassDB::bind_method(D_METHOD("_uv_input"), &Polygon2DEditor::_uv_input); + ClassDB::bind_method(D_METHOD("_uv_scroll_changed"), &Polygon2DEditor::_uv_scroll_changed); + ClassDB::bind_method(D_METHOD("_node_removed"), &Polygon2DEditor::_node_removed); + ClassDB::bind_method(D_METHOD("_set_use_snap"), &Polygon2DEditor::_set_use_snap); + ClassDB::bind_method(D_METHOD("_set_show_grid"), &Polygon2DEditor::_set_show_grid); + ClassDB::bind_method(D_METHOD("_set_snap_off_x"), &Polygon2DEditor::_set_snap_off_x); + ClassDB::bind_method(D_METHOD("_set_snap_off_y"), &Polygon2DEditor::_set_snap_off_y); + ClassDB::bind_method(D_METHOD("_set_snap_step_x"), &Polygon2DEditor::_set_snap_step_x); + ClassDB::bind_method(D_METHOD("_set_snap_step_y"), &Polygon2DEditor::_set_snap_step_y); } inline float _snap_scalar(float p_offset, float p_step, float p_target) { @@ -798,8 +739,8 @@ inline float _snap_scalar(float p_offset, float p_step, float p_target) { Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const { if (use_snap) { - p_target.x = _snap_scalar(snap_offset.x*uv_draw_zoom-uv_draw_ofs.x, snap_step.x*uv_draw_zoom, p_target.x); - p_target.y = _snap_scalar(snap_offset.y*uv_draw_zoom-uv_draw_ofs.y, snap_step.y*uv_draw_zoom, p_target.y); + p_target.x = _snap_scalar(snap_offset.x * uv_draw_zoom - uv_draw_ofs.x, snap_step.x * uv_draw_zoom, p_target.x); + p_target.y = _snap_scalar(snap_offset.y * uv_draw_zoom - uv_draw_ofs.y, snap_step.y * uv_draw_zoom, p_target.y); } return p_target; @@ -807,31 +748,31 @@ Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const { Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { - node=NULL; - canvas_item_editor=NULL; - editor=p_editor; + node = NULL; + canvas_item_editor = NULL; + editor = p_editor; undo_redo = editor->get_undo_redo(); - snap_step=Vector2(10,10); - use_snap=false; - snap_show_grid=false; + snap_step = Vector2(10, 10); + use_snap = false; + snap_show_grid = false; - add_child( memnew( VSeparator )); - button_create = memnew( ToolButton ); + add_child(memnew(VSeparator)); + button_create = memnew(ToolButton); add_child(button_create); - button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE)); + button_create->connect("pressed", this, "_menu_option", varray(MODE_CREATE)); button_create->set_toggle_mode(true); - button_edit = memnew( ToolButton ); + button_edit = memnew(ToolButton); add_child(button_edit); - button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT)); + button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT)); button_edit->set_toggle_mode(true); - button_uv = memnew( ToolButton ); + button_uv = memnew(ToolButton); add_child(button_uv); - button_uv->connect("pressed",this,"_menu_option",varray(MODE_EDIT_UV)); + button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV)); - //add_constant_override("separation",0); +//add_constant_override("separation",0); #if 0 options = memnew( MenuButton ); @@ -843,73 +784,73 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { #endif mode = MODE_EDIT; - wip_active=false; + wip_active = false; - uv_mode=UV_MODE_EDIT_POINT; - uv_edit = memnew( AcceptDialog ); + uv_mode = UV_MODE_EDIT_POINT; + uv_edit = memnew(AcceptDialog); add_child(uv_edit); uv_edit->set_title(TTR("Polygon 2D UV Editor")); - uv_edit->set_self_modulate(Color(1,1,1,0.9)); + uv_edit->set_self_modulate(Color(1, 1, 1, 0.9)); - VBoxContainer *uv_main_vb = memnew( VBoxContainer ); + VBoxContainer *uv_main_vb = memnew(VBoxContainer); uv_edit->add_child(uv_main_vb); //uv_edit->set_child_rect(uv_main_vb); - HBoxContainer *uv_mode_hb = memnew( HBoxContainer ); + HBoxContainer *uv_mode_hb = memnew(HBoxContainer); uv_main_vb->add_child(uv_mode_hb); - for(int i=0;iset_toggle_mode(true); uv_mode_hb->add_child(uv_button[i]); - uv_button[i]->connect("pressed",this,"_uv_mode",varray(i)); + uv_button[i]->connect("pressed", this, "_uv_mode", varray(i)); uv_button[i]->set_focus_mode(FOCUS_NONE); } - uv_button[0]->set_tooltip(TTR("Move Point")+"\n"+TTR("Ctrl: Rotate")+"\n"+TTR("Shift: Move All")+"\n"+TTR("Shift+Ctrl: Scale")); + uv_button[0]->set_tooltip(TTR("Move Point") + "\n" + TTR("Ctrl: Rotate") + "\n" + TTR("Shift: Move All") + "\n" + TTR("Shift+Ctrl: Scale")); uv_button[1]->set_tooltip(TTR("Move Polygon")); uv_button[2]->set_tooltip(TTR("Rotate Polygon")); uv_button[3]->set_tooltip(TTR("Scale Polygon")); uv_button[0]->set_pressed(true); - HBoxContainer *uv_main_hb = memnew( HBoxContainer ); + HBoxContainer *uv_main_hb = memnew(HBoxContainer); uv_main_vb->add_child(uv_main_hb); - uv_edit_draw = memnew( Control ); + uv_edit_draw = memnew(Control); uv_main_hb->add_child(uv_edit_draw); uv_main_hb->set_v_size_flags(SIZE_EXPAND_FILL); uv_edit_draw->set_h_size_flags(SIZE_EXPAND_FILL); - uv_menu = memnew( MenuButton ); + uv_menu = memnew(MenuButton); uv_mode_hb->add_child(uv_menu); uv_menu->set_text(TTR("Edit")); - uv_menu->get_popup()->add_item(TTR("Polygon->UV"),UVEDIT_POLYGON_TO_UV); - uv_menu->get_popup()->add_item(TTR("UV->Polygon"),UVEDIT_UV_TO_POLYGON); + uv_menu->get_popup()->add_item(TTR("Polygon->UV"), UVEDIT_POLYGON_TO_UV); + uv_menu->get_popup()->add_item(TTR("UV->Polygon"), UVEDIT_UV_TO_POLYGON); uv_menu->get_popup()->add_separator(); - uv_menu->get_popup()->add_item(TTR("Clear UV"),UVEDIT_UV_CLEAR); - uv_menu->get_popup()->connect("id_pressed",this,"_menu_option"); + uv_menu->get_popup()->add_item(TTR("Clear UV"), UVEDIT_UV_CLEAR); + uv_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - uv_mode_hb->add_child( memnew( VSeparator )); + uv_mode_hb->add_child(memnew(VSeparator)); - b_snap_enable = memnew( ToolButton ); + b_snap_enable = memnew(ToolButton); uv_mode_hb->add_child(b_snap_enable); b_snap_enable->set_text(TTR("Snap")); b_snap_enable->set_focus_mode(FOCUS_NONE); b_snap_enable->set_toggle_mode(true); b_snap_enable->set_pressed(use_snap); b_snap_enable->set_tooltip(TTR("Enable Snap")); - b_snap_enable->connect("toggled",this,"_set_use_snap"); + b_snap_enable->connect("toggled", this, "_set_use_snap"); - b_snap_grid = memnew( ToolButton ); + b_snap_grid = memnew(ToolButton); uv_mode_hb->add_child(b_snap_grid); b_snap_grid->set_text(TTR("Grid")); b_snap_grid->set_focus_mode(FOCUS_NONE); b_snap_grid->set_toggle_mode(true); b_snap_grid->set_pressed(snap_show_grid); b_snap_grid->set_tooltip(TTR("Show Grid")); - b_snap_grid->connect("toggled",this,"_set_show_grid"); + b_snap_grid->connect("toggled", this, "_set_show_grid"); - uv_mode_hb->add_child( memnew( VSeparator )); - uv_mode_hb->add_child( memnew( Label(TTR("Grid Offset:")) ) ); + uv_mode_hb->add_child(memnew(VSeparator)); + uv_mode_hb->add_child(memnew(Label(TTR("Grid Offset:")))); - SpinBox *sb_off_x = memnew( SpinBox ); + SpinBox *sb_off_x = memnew(SpinBox); sb_off_x->set_min(-256); sb_off_x->set_max(256); sb_off_x->set_step(1); @@ -918,7 +859,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { sb_off_x->connect("value_changed", this, "_set_snap_off_x"); uv_mode_hb->add_child(sb_off_x); - SpinBox *sb_off_y = memnew( SpinBox ); + SpinBox *sb_off_y = memnew(SpinBox); sb_off_y->set_min(-256); sb_off_y->set_max(256); sb_off_y->set_step(1); @@ -927,10 +868,10 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { sb_off_y->connect("value_changed", this, "_set_snap_off_y"); uv_mode_hb->add_child(sb_off_y); - uv_mode_hb->add_child( memnew( VSeparator )); - uv_mode_hb->add_child( memnew( Label(TTR("Grid Step:")) ) ); + uv_mode_hb->add_child(memnew(VSeparator)); + uv_mode_hb->add_child(memnew(Label(TTR("Grid Step:")))); - SpinBox *sb_step_x = memnew( SpinBox ); + SpinBox *sb_step_x = memnew(SpinBox); sb_step_x->set_min(-256); sb_step_x->set_max(256); sb_step_x->set_step(1); @@ -939,7 +880,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { sb_step_x->connect("value_changed", this, "_set_snap_step_x"); uv_mode_hb->add_child(sb_step_x); - SpinBox *sb_step_y = memnew( SpinBox ); + SpinBox *sb_step_y = memnew(SpinBox); sb_step_y->set_min(-256); sb_step_y->set_max(256); sb_step_y->set_step(1); @@ -948,49 +889,44 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { sb_step_y->connect("value_changed", this, "_set_snap_step_y"); uv_mode_hb->add_child(sb_step_y); - uv_mode_hb->add_child( memnew( VSeparator )); - uv_icon_zoom = memnew( TextureRect ); - uv_mode_hb->add_child( uv_icon_zoom ); - uv_zoom = memnew( HSlider ); + uv_mode_hb->add_child(memnew(VSeparator)); + uv_icon_zoom = memnew(TextureRect); + uv_mode_hb->add_child(uv_icon_zoom); + uv_zoom = memnew(HSlider); uv_zoom->set_min(0.01); uv_zoom->set_max(4); uv_zoom->set_value(1); uv_zoom->set_step(0.01); uv_mode_hb->add_child(uv_zoom); - uv_zoom->set_custom_minimum_size(Size2(200,0)); - uv_zoom_value = memnew( SpinBox ); + uv_zoom->set_custom_minimum_size(Size2(200, 0)); + uv_zoom_value = memnew(SpinBox); uv_zoom->share(uv_zoom_value); - uv_zoom_value->set_custom_minimum_size(Size2(50,0)); + uv_zoom_value->set_custom_minimum_size(Size2(50, 0)); uv_mode_hb->add_child(uv_zoom_value); - uv_zoom->connect("value_changed",this,"_uv_scroll_changed"); - + uv_zoom->connect("value_changed", this, "_uv_scroll_changed"); - - uv_vscroll = memnew( VScrollBar); + uv_vscroll = memnew(VScrollBar); uv_main_hb->add_child(uv_vscroll); - uv_vscroll->connect("value_changed",this,"_uv_scroll_changed"); - uv_hscroll = memnew( HScrollBar ); + uv_vscroll->connect("value_changed", this, "_uv_scroll_changed"); + uv_hscroll = memnew(HScrollBar); uv_main_vb->add_child(uv_hscroll); - uv_hscroll->connect("value_changed",this,"_uv_scroll_changed"); + uv_hscroll->connect("value_changed", this, "_uv_scroll_changed"); - uv_edit_draw->connect("draw",this,"_uv_draw"); - uv_edit_draw->connect("gui_input",this,"_uv_input"); - uv_draw_zoom=1.0; - uv_drag_index=-1; - uv_drag=false; - updating_uv_scroll=false; + uv_edit_draw->connect("draw", this, "_uv_draw"); + uv_edit_draw->connect("gui_input", this, "_uv_input"); + uv_draw_zoom = 1.0; + uv_drag_index = -1; + uv_drag = false; + updating_uv_scroll = false; - error = memnew( AcceptDialog); + error = memnew(AcceptDialog); add_child(error); uv_edit_draw->set_clip_contents(true); - } - void Polygon2DEditorPlugin::edit(Object *p_object) { - collision_polygon_editor->edit(p_object->cast_to()); } @@ -1008,21 +944,16 @@ void Polygon2DEditorPlugin::make_visible(bool p_visible) { collision_polygon_editor->hide(); collision_polygon_editor->edit(NULL); } - } Polygon2DEditorPlugin::Polygon2DEditorPlugin(EditorNode *p_node) { - editor=p_node; - collision_polygon_editor = memnew( Polygon2DEditor(p_node) ); + editor = p_node; + collision_polygon_editor = memnew(Polygon2DEditor(p_node)); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); collision_polygon_editor->hide(); - } - -Polygon2DEditorPlugin::~Polygon2DEditorPlugin() -{ +Polygon2DEditorPlugin::~Polygon2DEditorPlugin() { } - diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index c994867705..94eb3f49e8 100644 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -29,11 +29,11 @@ #ifndef POLYGON_2D_EDITOR_PLUGIN_H #define POLYGON_2D_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/polygon_2d.h" -#include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" +#include "scene/gui/tool_button.h" /** @author Juan Linietsky @@ -42,7 +42,7 @@ class CanvasItemEditor; class Polygon2DEditor : public HBoxContainer { - GDCLASS(Polygon2DEditor, HBoxContainer ); + GDCLASS(Polygon2DEditor, HBoxContainer); UndoRedo *undo_redo; enum Mode { @@ -88,8 +88,6 @@ class Polygon2DEditor : public HBoxContainer { Vector2 uv_drag_from; bool updating_uv_scroll; - - AcceptDialog *error; ToolButton *button_create; @@ -114,7 +112,7 @@ class Polygon2DEditor : public HBoxContainer { Vector2 snap_step; void _uv_scroll_changed(float); - void _uv_input(const InputEvent& p_input); + void _uv_input(const InputEvent &p_input); void _uv_draw(); void _uv_mode(int p_mode); void _wip_close(); @@ -136,22 +134,20 @@ protected: Vector2 snap_point(Vector2 p_target) const; public: - - bool forward_gui_input(const InputEvent& p_event); + bool forward_gui_input(const InputEvent &p_event); void edit(Node *p_collision_polygon); Polygon2DEditor(EditorNode *p_editor); }; class Polygon2DEditorPlugin : public EditorPlugin { - GDCLASS( Polygon2DEditorPlugin, EditorPlugin ); + GDCLASS(Polygon2DEditorPlugin, EditorPlugin); Polygon2DEditor *collision_polygon_editor; EditorNode *editor; public: - - virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform,const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); } + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); } virtual String get_name() const { return "Polygon2D"; } bool has_main_screen() const { return false; } @@ -161,7 +157,6 @@ public: Polygon2DEditorPlugin(EditorNode *p_node); ~Polygon2DEditorPlugin(); - }; #endif // POLYGON_2D_EDITOR_PLUGIN_H diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index e876fa55c6..2cdbff8d97 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -28,40 +28,35 @@ /*************************************************************************/ #include "resource_preloader_editor_plugin.h" -#include "io/resource_loader.h" -#include "global_config.h" #include "editor/editor_settings.h" - +#include "global_config.h" +#include "io/resource_loader.h" void ResourcePreloaderEditor::_gui_input(InputEvent p_event) { - - } void ResourcePreloaderEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_FIXED_PROCESS) { - + if (p_what == NOTIFICATION_FIXED_PROCESS) { } - if (p_what==NOTIFICATION_ENTER_TREE) { - load->set_icon( get_icon("Folder","EditorIcons") ); - _delete->set_icon( get_icon("Del","EditorIcons") ); + if (p_what == NOTIFICATION_ENTER_TREE) { + load->set_icon(get_icon("Folder", "EditorIcons")); + _delete->set_icon(get_icon("Del", "EditorIcons")); } - if (p_what==NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY) { //NodePath("/root")->connect("node_removed", this,"_node_removed",Vector(),true); } - if (p_what==NOTIFICATION_DRAW) { - + if (p_what == NOTIFICATION_DRAW) { } } -void ResourcePreloaderEditor::_files_load_request(const Vector& p_paths) { +void ResourcePreloaderEditor::_files_load_request(const Vector &p_paths) { - for(int i=0;i& p_paths) return; ///beh should show an error i guess } - String basename = path.get_file().get_basename(); - String name=basename; - int counter=1; - while(preloader->has_resource(name)) { + String name = basename; + int counter = 1; + while (preloader->has_resource(name)) { counter++; - name=basename+" "+itos(counter); + name = basename + " " + itos(counter); } undo_redo->create_action(TTR("Add Resource")); - undo_redo->add_do_method(preloader,"add_resource",name,resource); - undo_redo->add_undo_method(preloader,"remove_resource",name); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(preloader, "add_resource", name, resource); + undo_redo->add_undo_method(preloader, "remove_resource", name); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); } } void ResourcePreloaderEditor::_load_pressed() { - loading_scene=false; + loading_scene = false; file->clear_filters(); List extensions; - ResourceLoader::get_recognized_extensions_for_type("",&extensions); - for(int i=0;iadd_filter("*."+extensions[i]); + ResourceLoader::get_recognized_extensions_for_type("", &extensions); + for (int i = 0; i < extensions.size(); i++) + file->add_filter("*." + extensions[i]); file->set_mode(EditorFileDialog::MODE_OPEN_FILES); file->popup_centered_ratio(); - } - void ResourcePreloaderEditor::_item_edited() { if (!tree->get_selected()) @@ -119,32 +111,29 @@ void ResourcePreloaderEditor::_item_edited() { TreeItem *s = tree->get_selected(); - if (tree->get_selected_column()==0) { + if (tree->get_selected_column() == 0) { // renamed - String old_name=s->get_metadata(0); - String new_name=s->get_text(0); - if (old_name==new_name) + String old_name = s->get_metadata(0); + String new_name = s->get_text(0); + if (old_name == new_name) return; - if (new_name=="" || new_name.find("\\")!=-1 || new_name.find("/")!=-1 || preloader->has_resource(new_name)) { + if (new_name == "" || new_name.find("\\") != -1 || new_name.find("/") != -1 || preloader->has_resource(new_name)) { - s->set_text(0,old_name); + s->set_text(0, old_name); return; } RES samp = preloader->get_resource(old_name); undo_redo->create_action(TTR("Rename Resource")); - undo_redo->add_do_method(preloader,"remove_resource",old_name); - undo_redo->add_do_method(preloader,"add_resource",new_name,samp); - undo_redo->add_undo_method(preloader,"remove_resource",new_name); - undo_redo->add_undo_method(preloader,"add_resource",old_name,samp); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(preloader, "remove_resource", old_name); + undo_redo->add_do_method(preloader, "add_resource", new_name, samp); + undo_redo->add_undo_method(preloader, "remove_resource", new_name); + undo_redo->add_undo_method(preloader, "add_resource", old_name, samp); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } - - } void ResourcePreloaderEditor::_delete_confirm_pressed() { @@ -154,17 +143,16 @@ void ResourcePreloaderEditor::_delete_confirm_pressed() { String to_remove = tree->get_selected()->get_text(0); undo_redo->create_action(TTR("Delete Resource")); - undo_redo->add_do_method(preloader,"remove_resource",to_remove); - undo_redo->add_undo_method(preloader,"add_resource",to_remove,preloader->get_resource(to_remove)); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(preloader, "remove_resource", to_remove); + undo_redo->add_undo_method(preloader, "add_resource", to_remove, preloader->get_resource(to_remove)); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); } - void ResourcePreloaderEditor::_paste_pressed() { - RES r=EditorSettings::get_singleton()->get_resource_clipboard(); + RES r = EditorSettings::get_singleton()->get_resource_clipboard(); if (!r.is_valid()) { dialog->set_text(TTR("Resource clipboard is empty!")); dialog->set_title(TTR("Error!")); @@ -175,31 +163,28 @@ void ResourcePreloaderEditor::_paste_pressed() { } String name = r->get_name(); - if (name=="") - name=r->get_path().get_file(); - if (name=="") - name=r->get_class(); + if (name == "") + name = r->get_path().get_file(); + if (name == "") + name = r->get_class(); String basename = name; - int counter=1; - while(preloader->has_resource(name)) { + int counter = 1; + while (preloader->has_resource(name)) { counter++; - name=basename+" "+itos(counter); + name = basename + " " + itos(counter); } undo_redo->create_action(TTR("Paste Resource")); - undo_redo->add_do_method(preloader,"add_resource",name,r); - undo_redo->add_undo_method(preloader,"remove_resource",name); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(preloader, "add_resource", name, r); + undo_redo->add_undo_method(preloader, "remove_resource", name); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } - void ResourcePreloaderEditor::_delete_pressed() { - if (!tree->get_selected()) return; @@ -211,10 +196,8 @@ void ResourcePreloaderEditor::_delete_pressed() { //dialog->get_ok()->show(); dialog->get_ok()->set_text("Remove"); dialog->popup_centered(Size2(300,60));*/ - } - void ResourcePreloaderEditor::_update_library() { tree->clear(); @@ -225,46 +208,40 @@ void ResourcePreloaderEditor::_update_library() { preloader->get_resource_list(&rnames); List names; - for(List::Element *E=rnames.front();E;E=E->next()) { + for (List::Element *E = rnames.front(); E; E = E->next()) { names.push_back(E->get()); } names.sort(); - for(List::Element *E=names.front();E;E=E->next()) { + for (List::Element *E = names.front(); E; E = E->next()) { TreeItem *ti = tree->create_item(root); - ti->set_cell_mode(0,TreeItem::CELL_MODE_STRING); - ti->set_editable(0,true); - ti->set_selectable(0,true); - ti->set_text(0,E->get()); - ti->set_metadata(0,E->get()); - - + ti->set_cell_mode(0, TreeItem::CELL_MODE_STRING); + ti->set_editable(0, true); + ti->set_selectable(0, true); + ti->set_text(0, E->get()); + ti->set_metadata(0, E->get()); RES r = preloader->get_resource(E->get()); ERR_CONTINUE(r.is_null()); - ti->set_tooltip(0,r->get_path()); + ti->set_tooltip(0, r->get_path()); String type = r->get_class(); - ti->set_text(1,type); - ti->set_selectable(1,false); - - if (has_icon(type,"EditorIcons")) - ti->set_icon( 1, get_icon(type,"EditorIcons") ); + ti->set_text(1, type); + ti->set_selectable(1, false); + if (has_icon(type, "EditorIcons")) + ti->set_icon(1, get_icon(type, "EditorIcons")); } //player->add_resource("default",resource); } +void ResourcePreloaderEditor::edit(ResourcePreloader *p_preloader) { - -void ResourcePreloaderEditor::edit(ResourcePreloader* p_preloader) { - - preloader=p_preloader; - + preloader = p_preloader; if (p_preloader) { _update_library(); @@ -273,14 +250,11 @@ void ResourcePreloaderEditor::edit(ResourcePreloader* p_preloader) { hide(); set_fixed_process(false); } - } +Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - -Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) { - - TreeItem*ti =tree->get_item_at_pos(p_point); + TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return Variant(); @@ -290,45 +264,40 @@ Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2& p_point,Control* if (!res.is_valid()) return Variant(); - return EditorNode::get_singleton()->drag_resource(res,p_from); - + return EditorNode::get_singleton()->drag_resource(res, p_from); } -bool ResourcePreloaderEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const { - - +bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { Dictionary d = p_data; if (!d.has("type")) return false; - if (d.has("from") && (Object*)(d["from"])==tree) + if (d.has("from") && (Object *)(d["from"]) == tree) return false; - if (String(d["type"])=="resource" && d.has("resource")) { - RES r=d["resource"]; + if (String(d["type"]) == "resource" && d.has("resource")) { + RES r = d["resource"]; return r.is_valid(); } - - if (String(d["type"])=="files") { + if (String(d["type"]) == "files") { Vector files = d["files"]; - if (files.size()==0) + if (files.size() == 0) return false; return true; - } return false; } -void ResourcePreloaderEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) { +void ResourcePreloaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (!can_drop_data_fw(p_point,p_data,p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) return; Dictionary d = p_data; @@ -336,39 +305,37 @@ void ResourcePreloaderEditor::drop_data_fw(const Point2& p_point,const Variant& if (!d.has("type")) return; - - if (String(d["type"])=="resource" && d.has("resource")) { - RES r=d["resource"]; + if (String(d["type"]) == "resource" && d.has("resource")) { + RES r = d["resource"]; if (r.is_valid()) { String basename; - if (r->get_name()!="") { - basename=r->get_name(); + if (r->get_name() != "") { + basename = r->get_name(); } else if (r->get_path().is_resource_file()) { basename = r->get_path().get_basename(); } else { - basename="Resource"; + basename = "Resource"; } - String name=basename; - int counter=0; - while(preloader->has_resource(name)) { + String name = basename; + int counter = 0; + while (preloader->has_resource(name)) { counter++; - name=basename+"_"+itos(counter); + name = basename + "_" + itos(counter); } undo_redo->create_action(TTR("Add Resource")); - undo_redo->add_do_method(preloader,"add_resource",name,r); - undo_redo->add_undo_method(preloader,"remove_resource",name); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(preloader, "add_resource", name, r); + undo_redo->add_undo_method(preloader, "remove_resource", name); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); } } - - if (String(d["type"])=="files") { + if (String(d["type"]) == "files") { Vector files = d["files"]; @@ -376,83 +343,73 @@ void ResourcePreloaderEditor::drop_data_fw(const Point2& p_point,const Variant& } } - - void ResourcePreloaderEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"),&ResourcePreloaderEditor::_gui_input); - ClassDB::bind_method(D_METHOD("_load_pressed"),&ResourcePreloaderEditor::_load_pressed); - ClassDB::bind_method(D_METHOD("_item_edited"),&ResourcePreloaderEditor::_item_edited); - ClassDB::bind_method(D_METHOD("_delete_pressed"),&ResourcePreloaderEditor::_delete_pressed); - ClassDB::bind_method(D_METHOD("_paste_pressed"),&ResourcePreloaderEditor::_paste_pressed); - ClassDB::bind_method(D_METHOD("_delete_confirm_pressed"),&ResourcePreloaderEditor::_delete_confirm_pressed); - ClassDB::bind_method(D_METHOD("_files_load_request"),&ResourcePreloaderEditor::_files_load_request); - ClassDB::bind_method(D_METHOD("_update_library"),&ResourcePreloaderEditor::_update_library); - + ClassDB::bind_method(D_METHOD("_gui_input"), &ResourcePreloaderEditor::_gui_input); + ClassDB::bind_method(D_METHOD("_load_pressed"), &ResourcePreloaderEditor::_load_pressed); + ClassDB::bind_method(D_METHOD("_item_edited"), &ResourcePreloaderEditor::_item_edited); + ClassDB::bind_method(D_METHOD("_delete_pressed"), &ResourcePreloaderEditor::_delete_pressed); + ClassDB::bind_method(D_METHOD("_paste_pressed"), &ResourcePreloaderEditor::_paste_pressed); + ClassDB::bind_method(D_METHOD("_delete_confirm_pressed"), &ResourcePreloaderEditor::_delete_confirm_pressed); + ClassDB::bind_method(D_METHOD("_files_load_request"), &ResourcePreloaderEditor::_files_load_request); + ClassDB::bind_method(D_METHOD("_update_library"), &ResourcePreloaderEditor::_update_library); ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ResourcePreloaderEditor::get_drag_data_fw); ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ResourcePreloaderEditor::can_drop_data_fw); ClassDB::bind_method(D_METHOD("drop_data_fw"), &ResourcePreloaderEditor::drop_data_fw); - - } ResourcePreloaderEditor::ResourcePreloaderEditor() { //add_style_override("panel", get_stylebox("panel","Panel")); - VBoxContainer *vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); - HBoxContainer *hbc = memnew( HBoxContainer ); + HBoxContainer *hbc = memnew(HBoxContainer); vbc->add_child(hbc); - load = memnew( Button ); + load = memnew(Button); load->set_tooltip(TTR("Load Resource")); hbc->add_child(load); - - - _delete = memnew( Button ); + _delete = memnew(Button); hbc->add_child(_delete); - paste = memnew( Button ); + paste = memnew(Button); paste->set_text(TTR("Paste")); hbc->add_child(paste); - file = memnew( EditorFileDialog ); + file = memnew(EditorFileDialog); add_child(file); - - tree = memnew( Tree ); + tree = memnew(Tree); tree->set_columns(2); - tree->set_column_min_width(0,3); - tree->set_column_min_width(1,1); - tree->set_column_expand(0,true); - tree->set_column_expand(1,true); + tree->set_column_min_width(0, 3); + tree->set_column_min_width(1, 1); + tree->set_column_expand(0, true); + tree->set_column_expand(1, true); tree->set_v_size_flags(SIZE_EXPAND_FILL); tree->set_drag_forwarding(this); vbc->add_child(tree); - dialog = memnew( AcceptDialog ); - add_child( dialog ); + dialog = memnew(AcceptDialog); + add_child(dialog); - load->connect("pressed", this,"_load_pressed"); - _delete->connect("pressed", this,"_delete_pressed"); - paste->connect("pressed", this,"_paste_pressed"); - file->connect("files_selected", this,"_files_load_request"); + load->connect("pressed", this, "_load_pressed"); + _delete->connect("pressed", this, "_delete_pressed"); + paste->connect("pressed", this, "_paste_pressed"); + file->connect("files_selected", this, "_files_load_request"); //dialog->connect("confirmed", this,"_delete_confirm_pressed"); - tree->connect("item_edited", this,"_item_edited"); - loading_scene=false; - + tree->connect("item_edited", this, "_item_edited"); + loading_scene = false; } - void ResourcePreloaderEditorPlugin::edit(Object *p_object) { preloader_editor->set_undo_redo(&get_undo_redo()); - ResourcePreloader * s = p_object->cast_to(); + ResourcePreloader *s = p_object->cast_to(); if (!s) return; @@ -479,29 +436,20 @@ void ResourcePreloaderEditorPlugin::make_visible(bool p_visible) { //preloader_editor->hide(); //preloader_editor->set_process(false); } - } ResourcePreloaderEditorPlugin::ResourcePreloaderEditorPlugin(EditorNode *p_node) { - editor=p_node; - preloader_editor = memnew( ResourcePreloaderEditor ); - preloader_editor->set_custom_minimum_size(Size2(0,250)); + editor = p_node; + preloader_editor = memnew(ResourcePreloaderEditor); + preloader_editor->set_custom_minimum_size(Size2(0, 250)); - button=editor->add_bottom_panel_item("ResourcePreloader",preloader_editor); + button = editor->add_bottom_panel_item("ResourcePreloader", preloader_editor); button->hide(); //preloader_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END); //preloader_editor->set_margin( MARGIN_TOP, 120 ); - - - - } - -ResourcePreloaderEditorPlugin::~ResourcePreloaderEditorPlugin() -{ +ResourcePreloaderEditorPlugin::~ResourcePreloaderEditorPlugin() { } - - diff --git a/editor/plugins/resource_preloader_editor_plugin.h b/editor/plugins/resource_preloader_editor_plugin.h index 54ccad4341..946a3887ef 100644 --- a/editor/plugins/resource_preloader_editor_plugin.h +++ b/editor/plugins/resource_preloader_editor_plugin.h @@ -29,18 +29,16 @@ #ifndef RESOURCE_PRELOADER_EDITOR_PLUGIN_H #define RESOURCE_PRELOADER_EDITOR_PLUGIN_H - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "scene/gui/dialogs.h" +#include "scene/gui/file_dialog.h" #include "scene/gui/tree.h" #include "scene/main/resource_preloader.h" -#include "scene/gui/file_dialog.h" -#include "scene/gui/dialogs.h" - class ResourcePreloaderEditor : public PanelContainer { - GDCLASS(ResourcePreloaderEditor, PanelContainer ); + GDCLASS(ResourcePreloaderEditor, PanelContainer); Button *load; Button *_delete; @@ -48,17 +46,15 @@ class ResourcePreloaderEditor : public PanelContainer { Tree *tree; bool loading_scene; - EditorFileDialog *file; AcceptDialog *dialog; ResourcePreloader *preloader; - void _load_pressed(); void _load_scene_pressed(); - void _files_load_request(const Vector& p_paths); + void _files_load_request(const Vector &p_paths); void _paste_pressed(); void _delete_pressed(); void _delete_confirm_pressed(); @@ -67,33 +63,31 @@ class ResourcePreloaderEditor : public PanelContainer { UndoRedo *undo_redo; - Variant get_drag_data_fw(const Point2& p_point,Control* p_from); - bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; - void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); - + Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); + bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; + void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); protected: void _notification(int p_what); void _gui_input(InputEvent p_event); static void _bind_methods(); -public: - void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; } +public: + void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } - void edit(ResourcePreloader* p_preloader); + void edit(ResourcePreloader *p_preloader); ResourcePreloaderEditor(); }; class ResourcePreloaderEditorPlugin : public EditorPlugin { - GDCLASS( ResourcePreloaderEditorPlugin, EditorPlugin ); + GDCLASS(ResourcePreloaderEditorPlugin, EditorPlugin); ResourcePreloaderEditor *preloader_editor; EditorNode *editor; Button *button; public: - virtual String get_name() const { return "ResourcePreloader"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -102,7 +96,6 @@ public: ResourcePreloaderEditorPlugin(EditorNode *p_node); ~ResourcePreloaderEditorPlugin(); - }; #endif // RESOURCE_PRELOADER_EDITOR_PLUGIN_H diff --git a/editor/plugins/rich_text_editor_plugin.cpp b/editor/plugins/rich_text_editor_plugin.cpp index 797ee8e8ea..72a9278e62 100644 --- a/editor/plugins/rich_text_editor_plugin.cpp +++ b/editor/plugins/rich_text_editor_plugin.cpp @@ -28,39 +28,35 @@ /*************************************************************************/ #include "rich_text_editor_plugin.h" -#include "os/file_access.h" #include "canvas_item_editor_plugin.h" +#include "os/file_access.h" void RichTextEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_FIXED_PROCESS: { - } break; } - } void RichTextEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); } - } - -void RichTextEditor::_file_selected(const String& p_path) { +void RichTextEditor::_file_selected(const String &p_path) { CharString cs; - FileAccess *fa = FileAccess::open(p_path,FileAccess::READ); + FileAccess *fa = FileAccess::open(p_path, FileAccess::READ); if (!fa) { ERR_FAIL(); } - while(!fa->eof_reached()) + while (!fa->eof_reached()) cs.push_back(fa->get_8()); cs.push_back(0); memdelete(fa); @@ -68,12 +64,11 @@ void RichTextEditor::_file_selected(const String& p_path) { String bbcode; bbcode.parse_utf8(&cs[0]); node->parse_bbcode(bbcode); - } void RichTextEditor::_menu_option(int p_option) { - switch(p_option) { + switch (p_option) { case PARSE_BBCODE: { @@ -84,42 +79,38 @@ void RichTextEditor::_menu_option(int p_option) { node->clear(); } break; - } } void RichTextEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_menu_option"),&RichTextEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_file_selected"),&RichTextEditor::_file_selected); - + ClassDB::bind_method(D_METHOD("_menu_option"), &RichTextEditor::_menu_option); + ClassDB::bind_method(D_METHOD("_file_selected"), &RichTextEditor::_file_selected); } void RichTextEditor::edit(Node *p_rich_text) { - node=p_rich_text->cast_to(); - + node = p_rich_text->cast_to(); } RichTextEditor::RichTextEditor() { - options = memnew( MenuButton ); + options = memnew(MenuButton); //add_child(options); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(options); options->set_area_as_parent_rect(); options->set_text("RichText"); - options->get_popup()->add_item(TTR("Parse BBCode"),PARSE_BBCODE); - options->get_popup()->add_item(TTR("Clear"),CLEAR); + options->get_popup()->add_item(TTR("Parse BBCode"), PARSE_BBCODE); + options->get_popup()->add_item(TTR("Clear"), CLEAR); - options->get_popup()->connect("id_pressed", this,"_menu_option"); - file_dialog = memnew( EditorFileDialog ); + options->get_popup()->connect("id_pressed", this, "_menu_option"); + file_dialog = memnew(EditorFileDialog); add_child(file_dialog); file_dialog->add_filter("*.txt"); file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); - file_dialog->connect("file_selected",this,"_file_selected"); + file_dialog->connect("file_selected", this, "_file_selected"); } - void RichTextEditorPlugin::edit(Object *p_object) { rich_text_editor->edit(p_object->cast_to()); @@ -139,26 +130,21 @@ void RichTextEditorPlugin::make_visible(bool p_visible) { rich_text_editor->options->hide(); rich_text_editor->edit(NULL); } - } RichTextEditorPlugin::RichTextEditorPlugin(EditorNode *p_node) { - editor=p_node; - rich_text_editor = memnew( RichTextEditor ); + editor = p_node; + rich_text_editor = memnew(RichTextEditor); editor->get_viewport()->add_child(rich_text_editor); - rich_text_editor->set_margin(MARGIN_LEFT,184); - rich_text_editor->set_margin(MARGIN_RIGHT,230); - rich_text_editor->set_margin(MARGIN_TOP,0); - rich_text_editor->set_margin(MARGIN_BOTTOM,10); + rich_text_editor->set_margin(MARGIN_LEFT, 184); + rich_text_editor->set_margin(MARGIN_RIGHT, 230); + rich_text_editor->set_margin(MARGIN_TOP, 0); + rich_text_editor->set_margin(MARGIN_BOTTOM, 10); rich_text_editor->options->hide(); - } - -RichTextEditorPlugin::~RichTextEditorPlugin() -{ +RichTextEditorPlugin::~RichTextEditorPlugin() { } - diff --git a/editor/plugins/rich_text_editor_plugin.h b/editor/plugins/rich_text_editor_plugin.h index c7f95fb479..ab3c252fcf 100644 --- a/editor/plugins/rich_text_editor_plugin.h +++ b/editor/plugins/rich_text_editor_plugin.h @@ -29,10 +29,10 @@ #ifndef RICH_TEXT_EDITOR_PLUGIN_H #define RICH_TEXT_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "scene/gui/rich_text_label.h" +#include "editor/editor_plugin.h" #include "scene/gui/file_dialog.h" +#include "scene/gui/rich_text_label.h" /** @author Juan Linietsky @@ -40,9 +40,9 @@ class RichTextEditor : public Control { - GDCLASS(RichTextEditor, Control ); + GDCLASS(RichTextEditor, Control); - friend class RichTextEditorPlugin; + friend class RichTextEditorPlugin; enum { @@ -51,32 +51,31 @@ class RichTextEditor : public Control { }; Panel *panel; - MenuButton *options; + MenuButton *options; RichTextLabel *node; EditorFileDialog *file_dialog; - void _file_selected(const String& p_path); + void _file_selected(const String &p_path); void _menu_option(int p_option); protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); -public: +public: void edit(Node *p_rich_text); RichTextEditor(); }; class RichTextEditorPlugin : public EditorPlugin { - GDCLASS( RichTextEditorPlugin, EditorPlugin ); + GDCLASS(RichTextEditorPlugin, EditorPlugin); RichTextEditor *rich_text_editor; EditorNode *editor; public: - virtual String get_name() const { return "RichText"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -85,7 +84,6 @@ public: RichTextEditorPlugin(EditorNode *p_node); ~RichTextEditorPlugin(); - }; #endif // RICH_TEXT_EDITOR_PLUGIN_H diff --git a/editor/plugins/sample_editor_plugin.cpp b/editor/plugins/sample_editor_plugin.cpp index b6b96c946e..4d685f4289 100644 --- a/editor/plugins/sample_editor_plugin.cpp +++ b/editor/plugins/sample_editor_plugin.cpp @@ -29,9 +29,9 @@ #include "sample_editor_plugin.h" #if 0 -#include "io/resource_loader.h" -#include "global_config.h" #include "editor/editor_settings.h" +#include "global_config.h" +#include "io/resource_loader.h" diff --git a/editor/plugins/sample_editor_plugin.h b/editor/plugins/sample_editor_plugin.h index dae9cef9f4..0e7bccffa7 100644 --- a/editor/plugins/sample_editor_plugin.h +++ b/editor/plugins/sample_editor_plugin.h @@ -30,8 +30,8 @@ #define SAMPLE_EDITOR_PLUGIN_H #if 0 -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/audio/sample_player.h" #include "scene/resources/sample.h" #include "scene/resources/sample_library.h" diff --git a/editor/plugins/sample_library_editor_plugin.cpp b/editor/plugins/sample_library_editor_plugin.cpp index 4ead1d2709..c164428553 100644 --- a/editor/plugins/sample_library_editor_plugin.cpp +++ b/editor/plugins/sample_library_editor_plugin.cpp @@ -30,11 +30,11 @@ #if 0 #include "sample_library_editor_plugin.h" -#include "io/resource_loader.h" -#include "global_config.h" #include "editor/editor_settings.h" -#include "scene/main/viewport.h" +#include "global_config.h" +#include "io/resource_loader.h" #include "sample_editor_plugin.h" +#include "scene/main/viewport.h" void SampleLibraryEditor::_gui_input(InputEvent p_event) { diff --git a/editor/plugins/sample_library_editor_plugin.h b/editor/plugins/sample_library_editor_plugin.h index 4bbc29b147..a41e1538b4 100644 --- a/editor/plugins/sample_library_editor_plugin.h +++ b/editor/plugins/sample_library_editor_plugin.h @@ -29,15 +29,14 @@ #ifndef SAMPLE_LIBRARY_EDITOR_PLUGIN_H #define SAMPLE_LIBRARY_EDITOR_PLUGIN_H - #if 0 -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/audio/sample_player.h" -#include "scene/resources/sample.h" -#include "scene/gui/tree.h" -#include "scene/gui/file_dialog.h" #include "scene/gui/dialogs.h" +#include "scene/gui/file_dialog.h" +#include "scene/gui/tree.h" +#include "scene/resources/sample.h" class SampleLibraryEditor : public Panel { diff --git a/editor/plugins/sample_player_editor_plugin.cpp b/editor/plugins/sample_player_editor_plugin.cpp index 7e2683dedf..a550d96d5c 100644 --- a/editor/plugins/sample_player_editor_plugin.cpp +++ b/editor/plugins/sample_player_editor_plugin.cpp @@ -30,7 +30,6 @@ #if 0 #include "sample_player_editor_plugin.h" - #include "scene/resources/sample_library.h" @@ -199,5 +198,4 @@ SamplePlayerEditorPlugin::~SamplePlayerEditorPlugin() { } - #endif diff --git a/editor/plugins/sample_player_editor_plugin.h b/editor/plugins/sample_player_editor_plugin.h index c1d599540a..10a08b8a17 100644 --- a/editor/plugins/sample_player_editor_plugin.h +++ b/editor/plugins/sample_player_editor_plugin.h @@ -31,11 +31,11 @@ #if 0 -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/3d/spatial_sample_player.h" -#include "scene/gui/option_button.h" #include "scene/audio/sample_player.h" +#include "scene/gui/option_button.h" /** @author Juan Linietsky diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 3631d39f9a..4e7a0709fa 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -28,44 +28,41 @@ /*************************************************************************/ #include "script_editor_plugin.h" +#include "editor/editor_node.h" #include "editor/editor_settings.h" +#include "editor/script_editor_debugger.h" +#include "global_config.h" #include "io/resource_loader.h" #include "io/resource_saver.h" +#include "os/file_access.h" +#include "os/input.h" +#include "os/keyboard.h" #include "os/keyboard.h" #include "os/os.h" -#include "editor/editor_node.h" -#include "editor/script_editor_debugger.h" -#include "global_config.h" -#include "os/file_access.h" #include "scene/main/viewport.h" -#include "os/keyboard.h" -#include "os/input.h" /*** SCRIPT EDITOR ****/ - - void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("name_changed")); - ADD_SIGNAL(MethodInfo("request_help_search",PropertyInfo(Variant::STRING,"topic"))); - ADD_SIGNAL(MethodInfo("request_open_script_at_line",PropertyInfo(Variant::OBJECT,"script"),PropertyInfo(Variant::INT,"line"))); + ADD_SIGNAL(MethodInfo("request_help_search", PropertyInfo(Variant::STRING, "topic"))); + ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line"))); ADD_SIGNAL(MethodInfo("request_save_history")); - ADD_SIGNAL(MethodInfo("go_to_help",PropertyInfo(Variant::STRING,"what"))); - + ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what"))); } -static bool _can_open_in_editor(Script* p_script) { +static bool _can_open_in_editor(Script *p_script) { String path = p_script->get_path(); - if (path.find("::")!=-1) { + if (path.find("::") != -1) { //refuse handling this if it can't be edited - bool valid=false; - for(int i=0;iget_editor_data().get_edited_scene_count();i++) { + bool valid = false; + for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_edited_scene_count(); i++) { if (path.begins_with(EditorNode::get_singleton()->get_editor_data().get_scene_path(i))) { - valid=true; + valid = true; break; } } @@ -76,68 +73,63 @@ static bool _can_open_in_editor(Script* p_script) { return true; } - class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { - struct Cache { uint64_t time_loaded; RES cache; }; - Map cached; - + Map cached; public: - uint64_t max_time_cache; int max_cache_size; void cleanup() { - List< Map::Element * > to_clean; + List::Element *> to_clean; - - Map::Element *I=cached.front(); - while(I) { - if ((OS::get_singleton()->get_ticks_msec()-I->get().time_loaded)>max_time_cache) { + Map::Element *I = cached.front(); + while (I) { + if ((OS::get_singleton()->get_ticks_msec() - I->get().time_loaded) > max_time_cache) { to_clean.push_back(I); } - I=I->next(); + I = I->next(); } - while(to_clean.front()) { + while (to_clean.front()) { cached.erase(to_clean.front()->get()); to_clean.pop_front(); } } - RES get_cached_resource(const String& p_path) { + RES get_cached_resource(const String &p_path) { - Map::Element *E=cached.find(p_path); + Map::Element *E = cached.find(p_path); if (!E) { Cache c; - c.cache=ResourceLoader::load(p_path); - E=cached.insert(p_path,c); + c.cache = ResourceLoader::load(p_path); + E = cached.insert(p_path, c); } - E->get().time_loaded=OS::get_singleton()->get_ticks_msec(); + E->get().time_loaded = OS::get_singleton()->get_ticks_msec(); - if (cached.size()>max_cache_size) { + if (cached.size() > max_cache_size) { uint64_t older; - Map::Element *O=cached.front(); - older=O->get().time_loaded; - Map::Element *I=O; - while(I) { - if (I->get().time_loaded::Element *O = cached.front(); + older = O->get().time_loaded; + Map::Element *I = O; + while (I) { + if (I->get().time_loaded < older) { older = I->get().time_loaded; - O=I; + O = I; } - I=I->next(); + I = I->next(); } - if (O!=E) {//should never heppane.. + if (O != E) { //should never heppane.. cached.erase(O); } } @@ -145,18 +137,16 @@ public: return E->get().cache; } - EditorScriptCodeCompletionCache() { - max_cache_size=128; - max_time_cache=5*60*1000; //minutes, five + max_cache_size = 128; + max_time_cache = 5 * 60 * 1000; //minutes, five } - }; #define SORT_SCRIPT_LIST -void ScriptEditorQuickOpen::popup(const Vector& p_functions, bool p_dontclear) { +void ScriptEditorQuickOpen::popup(const Vector &p_functions, bool p_dontclear) { popup_centered_ratio(0.6); if (p_dontclear) @@ -164,55 +154,45 @@ void ScriptEditorQuickOpen::popup(const Vector& p_functions, bool p_dont else search_box->clear(); search_box->grab_focus(); - functions=p_functions; + functions = p_functions; _update_search(); - - } - -void ScriptEditorQuickOpen::_text_changed(const String& p_newtext) { +void ScriptEditorQuickOpen::_text_changed(const String &p_newtext) { _update_search(); } -void ScriptEditorQuickOpen::_sbox_input(const InputEvent& p_ie) { +void ScriptEditorQuickOpen::_sbox_input(const InputEvent &p_ie) { - if (p_ie.type==InputEvent::KEY && ( - p_ie.key.scancode == KEY_UP || - p_ie.key.scancode == KEY_DOWN || - p_ie.key.scancode == KEY_PAGEUP || - p_ie.key.scancode == KEY_PAGEDOWN ) ) { + if (p_ie.type == InputEvent::KEY && (p_ie.key.scancode == KEY_UP || + p_ie.key.scancode == KEY_DOWN || + p_ie.key.scancode == KEY_PAGEUP || + p_ie.key.scancode == KEY_PAGEDOWN)) { - search_options->call("_gui_input",p_ie); + search_options->call("_gui_input", p_ie); search_box->accept_event(); } - } - - void ScriptEditorQuickOpen::_update_search() { - search_options->clear(); TreeItem *root = search_options->create_item(); - for(int i=0;iget_text()=="" || file.findn(search_box->get_text())!=-1)) { + if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) { TreeItem *ti = search_options->create_item(root); - ti->set_text(0,file); - if (root->get_children()==ti) + ti->set_text(0, file); + if (root->get_children() == ti) ti->select(0); - } } - get_ok()->set_disabled(root->get_children()==NULL); - + get_ok()->set_disabled(root->get_children() == NULL); } void ScriptEditorQuickOpen::_confirmed() { @@ -220,88 +200,79 @@ void ScriptEditorQuickOpen::_confirmed() { TreeItem *ti = search_options->get_selected(); if (!ti) return; - int line = ti->get_text(0).get_slice(":",1).to_int(); + int line = ti->get_text(0).get_slice(":", 1).to_int(); - emit_signal("goto_line",line-1); + emit_signal("goto_line", line - 1); hide(); } void ScriptEditorQuickOpen::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { - - connect("confirmed",this,"_confirmed"); - + if (p_what == NOTIFICATION_ENTER_TREE) { + connect("confirmed", this, "_confirmed"); } } - - - void ScriptEditorQuickOpen::_bind_methods() { - ClassDB::bind_method(D_METHOD("_text_changed"),&ScriptEditorQuickOpen::_text_changed); - ClassDB::bind_method(D_METHOD("_confirmed"),&ScriptEditorQuickOpen::_confirmed); - ClassDB::bind_method(D_METHOD("_sbox_input"),&ScriptEditorQuickOpen::_sbox_input); - - ADD_SIGNAL(MethodInfo("goto_line",PropertyInfo(Variant::INT,"line"))); + ClassDB::bind_method(D_METHOD("_text_changed"), &ScriptEditorQuickOpen::_text_changed); + ClassDB::bind_method(D_METHOD("_confirmed"), &ScriptEditorQuickOpen::_confirmed); + ClassDB::bind_method(D_METHOD("_sbox_input"), &ScriptEditorQuickOpen::_sbox_input); + ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line"))); } - ScriptEditorQuickOpen::ScriptEditorQuickOpen() { - - VBoxContainer *vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); //set_child_rect(vbc); - search_box = memnew( LineEdit ); - vbc->add_margin_child(TTR("Search:"),search_box); - search_box->connect("text_changed",this,"_text_changed"); - search_box->connect("gui_input",this,"_sbox_input"); - search_options = memnew( Tree ); - vbc->add_margin_child(TTR("Matches:"),search_options,true); + search_box = memnew(LineEdit); + vbc->add_margin_child(TTR("Search:"), search_box); + search_box->connect("text_changed", this, "_text_changed"); + search_box->connect("gui_input", this, "_sbox_input"); + search_options = memnew(Tree); + vbc->add_margin_child(TTR("Matches:"), search_options, true); get_ok()->set_text(TTR("Open")); get_ok()->set_disabled(true); register_text_enter(search_box); set_hide_on_ok(false); - search_options->connect("item_activated",this,"_confirmed"); + search_options->connect("item_activated", this, "_confirmed"); search_options->set_hide_root(true); } - ///////////////////////////////// -ScriptEditor *ScriptEditor::script_editor=NULL; +ScriptEditor *ScriptEditor::script_editor = NULL; /*** SCRIPT EDITOR ******/ -String ScriptEditor::_get_debug_tooltip(const String&p_text,Node *_se) { +String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) { //ScriptEditorBase *se=_se->cast_to(); String val = debugger->get_var_value(p_text); - if (val!=String()) { - return p_text+": "+val; + if (val != String()) { + return p_text + ": " + val; } else { return String(); } } -void ScriptEditor::_breaked(bool p_breaked,bool p_can_debug) { +void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) { if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) { return; } - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), !(p_breaked && p_can_debug)); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), !(p_breaked && p_can_debug) ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), p_breaked ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), !p_breaked ); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), !(p_breaked && p_can_debug)); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), !(p_breaked && p_can_debug)); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), p_breaked); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), !p_breaked); - for(int i=0;iget_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to(); if (!se) { @@ -311,7 +282,6 @@ void ScriptEditor::_breaked(bool p_breaked,bool p_can_debug) { se->set_debugger_active(p_breaked); } - } void ScriptEditor::_show_debugger(bool p_show) { @@ -323,11 +293,10 @@ void ScriptEditor::_script_created(Ref