diff options
Diffstat (limited to 'editor/plugins')
86 files changed, 7642 insertions, 9455 deletions
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<Animation> 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()<animation->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()<animation->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()<animation->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()<animation->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()<animation->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<Animation> anim = player->get_animation(current); + Ref<Animation> 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<Animation>()); 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<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("Animation",&extensions); - for (List<String>::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<String>::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<Resource>& p_resource, const String& p_path) { +void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &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<Resource>& 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<Resource>& p_resource) { +void AnimationPlayerEditor::_animation_save(const Ref<Resource> &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<Resource>& p_resource) { +void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource) { file->set_mode(EditorFileDialog::MODE_SAVE_FILE); List<String> extensions; ResourceSaver::get_recognized_extensions(p_resource, &extensions); file->clear_filters(); - for (int i = 0; i<extensions.size(); i++) { + for (int i = 0; i < extensions.size(); i++) { file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } @@ -429,20 +413,17 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource>& 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;i<animation->get_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<Animation> anim = player->get_animation(current); + Ref<Animation> 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<Animation> new_anim = Ref<Animation>(memnew( Animation )); + Ref<Animation> new_anim = Ref<Animation>(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<StringName> 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<StringName>::Element *E=anims.front();E;E=E->next()) { + for (List<StringName>::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<AnimationPlayer>() && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) { - player=n->cast_to<AnimationPlayer>(); + player = n->cast_to<AnimationPlayer>(); _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<Animation> anim = player->get_animation(current); + Ref<Animation> 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<Animation> anim = player->get_animation(current); + Ref<Animation> 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<Animation>()); 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<Resource>()) - RES current_res = RES(anim->cast_to<Resource>()); + RES current_res = RES(anim->cast_to<Resource>()); _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;i<animation->get_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<StringName> animlist; if (player) player->get_animation_list(&animlist); @@ -831,78 +794,70 @@ void AnimationPlayerEditor::_update_player() { else nodename->set_text("<empty>"); - - 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<StringName>::Element *E = animlist.front(); E; E = E->next()) { - int active_idx=-1; - for (List<StringName>::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<Animation> anim = player->get_animation(current); + Ref<Animation> 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<Animation> anim = player->get_animation(current); + Ref<Animation> anim = player->get_animation(current); if (!anim.is_valid()) return; - Ref<Animation> new_anim = memnew( Animation ); + Ref<Animation> new_anim = memnew(Animation); List<PropertyInfo> plist; anim->get_property_list(&plist); - for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { + for (List<PropertyInfo>::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;i<animation->get_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<Animation> 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<Animation>()); 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<Animation> anim = player->get_animation(current); + Ref<Animation> 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<Animation> anim = player->get_animation(current); + Ref<Animation> anim = player->get_animation(current); editor->edit_resource(anim); } break; - } } @@ -1221,21 +1155,21 @@ void AnimationPlayerEditor::_animation_save_menu(int p_option) { Ref<Animation> 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<Variant>(),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<Variant>(),true); - scale->connect("text_entered", this, "_scale_changed",Vector<Variant>(),true); - + blend_anim->connect("pressed", this, "_animation_blend"); + remove_anim->connect("pressed", this, "_animation_remove"); + animation->connect("item_selected", this, "_animation_selected", Vector<Variant>(), 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<Variant>(), true); + scale->connect("text_entered", this, "_scale_changed", Vector<Variant>(), 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<AnimationPlayer>()); - - } 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 <reduzio@gmail.com> @@ -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<Resource>& p_resource, const String& p_path); - void _animation_save(const Ref<Resource>& p_resource); - void _animation_save_as(const Ref<Resource>& p_resource); + void _animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path); + void _animation_save(const Ref<Resource> &p_resource); + void _animation_save_as(const Ref<Resource> &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<StringName>::Element *E=order.front();E;E=E->next()) { + for (List<StringName>::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<StyleBox> style = get_stylebox("panel","PopupMenu"); - Ref<Font> font = get_font("font","PopupMenu"); + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> 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<StringName>::Element* E=order.front();E;E=E->next()) { + if (anim_tree->node_rename(edited_node, edit_line[0]->get_text()) == OK) { + for (List<StringName>::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<Animation> 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<StyleBox> style = get_stylebox("panel","PopupMenu"); + Point2 pos = anim_tree->node_get_pos(edited_node) - Point2(h_scroll->get_value(), v_scroll->get_value()); + Ref<StyleBox> 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<AnimationPlayer>()) { + 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>()) { AnimationPlayer *ap = anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>(); master_anim_popup->clear(); @@ -299,302 +289,293 @@ void AnimationTreeEditor::_popup_edit_dialog() { List<StringName> sn; ap->get_animation_list(&sn); sn.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E=sn.front();E;E=E->next()) { + for (List<StringName>::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;i<anim_tree->transition_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<StyleBox> style = get_stylebox("panel","PopupMenu"); - Ref<Font> 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<Texture> slot_icon = get_icon("NodeRealSlot","EditorIcons"); + AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node); + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> 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<Texture> 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;i<inputs;i++) { + for (int i = 0; i < inputs; i++) { - slot_icon->draw(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<StyleBox> pg_bg=get_stylebox("bg","ProgressBar"); - Ref<StyleBox> pg_fill=get_stylebox("fill","ProgressBar"); - Rect2 pg_rect(ofs,Size2(w,h)); + Ref<StyleBox> pg_bg = get_stylebox("bg", "ProgressBar"); + Ref<StyleBox> 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<Animation> 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<Texture> 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<Texture> 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<StyleBox> style = get_stylebox("panel","PopupMenu"); - Ref<Font> font = get_font("font","PopupMenu"); + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> 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<StringName>::Element *E=order.back();E;E=E->prev()) { + for (const List<StringName>::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<count*h) { + if (y < count * h) { if (p_slot_index) - *p_slot_index=0; + *p_slot_index = 0; return CLICK_OUTPUT_SLOT; } } - for(int i=0;i<count;i++) { + for (int i = 0; i < count; i++) { - if (y<h) { + if (y < h) { if (p_slot_index) - *p_slot_index=i; + *p_slot_index = i; return CLICK_INPUT_SLOT; } - y-=h; + y -= h; } - bool has_parameters = type!=AnimationTreePlayer::NODE_OUTPUT && type!=AnimationTreePlayer::NODE_TIMESEEK; + bool has_parameters = type != AnimationTreePlayer::NODE_OUTPUT && type != AnimationTreePlayer::NODE_TIMESEEK; return has_parameters ? CLICK_PARAMETER : CLICK_NODE; } return CLICK_NONE; } -Point2 AnimationTreeEditor::_get_slot_pos(const StringName& p_node,bool p_input,int p_slot) { +Point2 AnimationTreeEditor::_get_slot_pos(const StringName &p_node, bool p_input, int p_slot) { - Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); - Ref<Font> font = get_font("font","PopupMenu"); - Ref<Texture> slot_icon = get_icon("NodeRealSlot","EditorIcons"); + Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); + Ref<Font> font = get_font("font", "PopupMenu"); + Ref<Texture> 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<StringName>::Element *E=order.front();E;E=E->next()) { + for (List<StringName>::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<AnimationTreePlayer::Connection> connections; anim_tree->get_connection_list(&connections); - for(List<AnimationTreePlayer::Connection>::Element *E=connections.front();E;E=E->next()) { + for (List<AnimationTreePlayer::Connection>::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<Font> 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<Font> 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<Font> 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<Font> 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<AnimationTreePlayer::Connection> connections; anim_tree->get_connection_list(&connections); - for(List<AnimationTreePlayer::Connection>::Element *E=connections.front();E;E=E->next()) { + for (List<AnimationTreePlayer::Connection>::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<String> files = file_dialog->get_selected_files(); + case MENU_IMPORT_ANIMATIONS: { + Vector<String> files = file_dialog->get_selected_files(); - for (int i=0; i<files.size(); i++) { + for (int i = 0; i < files.size(); i++) { - StringName node = _add_node(AnimationTreePlayer::NODE_ANIMATION); + StringName node = _add_node(AnimationTreePlayer::NODE_ANIMATION); - 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; + 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<String>& paths) { +void AnimationTreeEditor::_find_paths_for_filter(const StringName &p_node, Set<String> &paths) { - ERR_FAIL_COND( !anim_tree->node_exists(p_node) ); + ERR_FAIL_COND(!anim_tree->node_exists(p_node)); - for(int i=0;i<anim_tree->node_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<Animation> anim = anim_tree->animation_node_get_animation(p_node); if (anim.is_valid()) { - for(int i=0;i<anim->get_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<String> 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<String,TreeItem*> pm; + Map<String, TreeItem *> 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<String>::Element *E=npb.front();E;E=E->next()) { + for (Set<String>::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<Skeleton>(); 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<PropertyInfo> 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<AnimationTreePlayer>()); - } 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 <reduzio@gmail.com> */ 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<StringName> order; Set<StringName> 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<String>& paths); + void _find_paths_for_filter(const StringName &p_node, Set<String> &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 <stdlib.h> -#include <cmath> -#include "io/marshalls.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" +#include "io/marshalls.h" +#include <stdlib.h> +#include <cmath> #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 <reduzio@gmail.com> */ @@ -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<Camera>()); @@ -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<Node*> &selection = editor_selection->get_selected_node_list(); +void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) { + List<Node *> &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Move Pivot")); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Node2D *n2d = E->get()->cast_to<Node2D>(); @@ -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;i<n2d->get_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<Node2D>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &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;i<TOOL_MAX;i++) { - - tb[i]->set_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<Viewport>()) return NULL; - CanvasItem *c=p_node->cast_to<CanvasItem>(); - + CanvasItem *c = p_node->cast_to<CanvasItem>(); - 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<CanvasLayer>(); - 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<Viewport>()) return; - CanvasItem *c=p_node->cast_to<CanvasItem>(); + CanvasItem *c = p_node->cast_to<CanvasItem>(); - 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<CanvasLayer>(); - _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<CanvasLayer>()) { 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>(); + Node2D *node = c->cast_to<Node2D>(); _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<CanvasItem*> *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<CanvasItem *> *r_items) { if (!p_node) return; if (p_node->cast_to<Viewport>()) return; - CanvasItem *c=p_node->cast_to<CanvasItem>(); - + CanvasItem *c = p_node->cast_to<CanvasItem>(); - 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<CanvasLayer>(); - _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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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<Node2D>()) - se->undo_pivot=canvas_item->cast_to<Node2D>()->edit_get_pivot(); - + se->undo_pivot = canvas_item->cast_to<Node2D>()->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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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>()) { - 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - int ic=0; - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + int ic = 0; + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Node *, Object *> &selection = editor_selection->get_selection(); - Map<Node*,Object*> &selection = editor_selection->get_selection(); - - CanvasItem *single_item=NULL; + CanvasItem *single_item = NULL; - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); 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)<radius) - return dragger[i*2]; + if (ofs.distance_to(p_click) < radius) + return dragger[i * 2]; - ofs = (endpoints[i]+endpoints[next])/2; - ofs += (endpoints[next]-endpoints[i]).tangent().normalized()*(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); - r_point=(endpointsl[i]+endpointsl[next])/2; - - - if (ofs.distance_to(p_click)<radius) - return dragger[i*2+1]; + r_point = (endpointsl[i] + endpointsl[next]) / 2; + if (ofs.distance_to(p_click) < radius) + return dragger[i * 2 + 1]; } /* @@ -884,70 +843,66 @@ CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Transform2D& return DRAG_NONE; } -void CanvasItemEditor::incbeg(float& beg,float &end, float inc, float minsize,bool p_symmetric) { +void CanvasItemEditor::incbeg(float &beg, float &end, float inc, float minsize, bool p_symmetric) { - if (minsize<0) { + if (minsize < 0) { - beg+=inc; + beg += inc; if (p_symmetric) - end-=inc; + end -= inc; } else { if (p_symmetric) { - beg+=inc; - end-=inc; - if (end-beg < minsize) { - float center = (beg+end)/2.0; - beg=center-minsize/2.0; - end=center+minsize/2.0; + beg += inc; + end -= inc; + if (end - beg < minsize) { + float center = (beg + end) / 2.0; + beg = center - minsize / 2.0; + end = center + minsize / 2.0; } } else { - if (end-(beg+inc) < minsize) - beg=end-minsize; + if (end - (beg + inc) < minsize) + beg = end - minsize; else - beg+=inc; + beg += inc; } - } } -void CanvasItemEditor::incend(float &beg,float& end, float inc, float minsize,bool p_symmetric) { +void CanvasItemEditor::incend(float &beg, float &end, float inc, float minsize, bool p_symmetric) { - if (minsize<0) { + if (minsize < 0) { - end+=inc; + end += inc; if (p_symmetric) - beg-=inc; + beg -= inc; } else { if (p_symmetric) { - end+=inc; - beg-=inc; - if (end-beg < minsize) { - float center = (beg+end)/2.0; - beg=center-minsize/2.0; - end=center+minsize/2.0; + end += inc; + beg -= inc; + if (end - beg < minsize) { + float center = (beg + end) / 2.0; + beg = center - minsize / 2.0; + end = center + minsize / 2.0; } } else { - if ((end+inc)-beg < minsize) - end=beg+minsize; + if ((end + inc) - beg < minsize) + end = beg + minsize; else - end+=inc; + end += inc; } - } } void CanvasItemEditor::_append_canvas_item(CanvasItem *c) { editor_selection->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<Node*> *p_list) { +bool CanvasItemEditor::get_remove_list(List<Node *> *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;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())) { + 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<Texture> 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 (zoom<MIN_ZOOM) + if (zoom < MIN_ZOOM) return; - float prev_zoom=zoom; - zoom=zoom*0.95; + float prev_zoom = zoom; + zoom = zoom * 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); 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<BoneIK>::Element *E=bone_ik_list.back();E;E=E->prev()) { + for (List<BoneIK>::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<Node *> &selection = editor_selection->get_selected_node_list(); - List<Node*> &selection = editor_selection->get_selected_node_list(); - - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (!se) continue; canvas_item->edit_set_state(se->undo_state); if (canvas_item->cast_to<Node2D>()) canvas_item->cast_to<Node2D>()->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<BoneIK>::Element *E=bone_ik_list.back();E;E=E->prev()) { + for (List<BoneIK>::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<Node *> &selection = editor_selection->get_selected_node_list(); - List<Node*> &selection = editor_selection->get_selected_node_list(); - - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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>()) { Node2D *pvt = canvas_item->cast_to<Node2D>(); 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<CanvasItem*> selitems; + List<CanvasItem *> 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<CanvasItem*>::Element *E=selitems.front();E;E=E->next()) { + for (List<CanvasItem *>::Element *E = selitems.front(); E; E = E->next()) { _append_canvas_item(E->get()); } - } - box_selecting=false; + box_selecting = false; viewport->update(); - } return; } - - Map<ObjectID,BoneList>::Element *Cbone=NULL; //closest + Map<ObjectID, BoneList>::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<ObjectID,BoneList>::Element *E=bone_list.front();E;E=E->next()) { + for (Map<ObjectID, BoneList>::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 (d<bone_width && d<closest_dist) { - Cbone=E; - closest_dist=d; + 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 (d < bone_width && d < closest_dist) { + Cbone = E; + closest_dist = d; } } if (Cbone) { - Node2D *b=NULL; - Object* obj=ObjectDB::get_instance(Cbone->get().bone); + Node2D *b = NULL; + Object *obj = ObjectDB::get_instance(Cbone->get().bone); if (obj) - b=obj->cast_to<Node2D>(); + b = obj->cast_to<Node2D>(); 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<Node2D>(); + float len = pi->get_global_transform().get_origin().distance_to(b->get_global_position()); + b = pi->cast_to<Node2D>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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<Node2D>()) - se->undo_pivot=canvas_item->cast_to<Node2D>()->edit_get_pivot(); + se->undo_pivot = canvas_item->cast_to<Node2D>()->edit_get_pivot(); if (canvas_item->cast_to<Control>()) - 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<Node2D>()) - se->undo_pivot=canvas_item->cast_to<Node2D>()->edit_get_pivot(); + se->undo_pivot = canvas_item->cast_to<Node2D>()->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<Node *> &selection = editor_selection->get_selected_node_list(); - - List<Node*> &selection = editor_selection->get_selected_node_list(); - - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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<Node2D>()) - se->undo_pivot=canvas_item->cast_to<Node2D>()->edit_get_pivot(); - + se->undo_pivot = canvas_item->cast_to<Node2D>()->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<CanvasItem>(); + c = obj->cast_to<CanvasItem>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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<Node2D>()->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<Node2D>(); - 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<Control>(); - 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>()) { - Node2D *n2d =canvas_item->cast_to<Node2D>(); - n2d->edit_set_pivot(se->undo_pivot+drag_vector); - + Node2D *n2d = canvas_item->cast_to<Node2D>(); + 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<Node2D>(); Transform2D final_xform = bone_orig_xform; - - if (n2d) { float total_len = 0; - for (List<BoneIK>::Element *E=bone_ik_list.front();E;E=E->next()) { + for (List<BoneIK>::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<solver_iterations;i++) { - - for (List<BoneIK>::Element *E=bone_ik_list.front();E;E=E->next()) { - + for (int i = 0; i < solver_iterations; i++) { + for (List<BoneIK>::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<BoneIK>::Element *E=bone_ik_list.back();E;E=E->prev()) { + for (List<BoneIK>::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<Texture> pivot = get_icon("EditorPivot","EditorIcons"); + Ref<Texture> 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;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.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;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; + 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<Texture> lock = get_icon("Lock","EditorIcons"); - Ref<Texture> group = get_icon("Group","EditorIcons"); + Ref<Texture> lock = get_icon("Lock", "EditorIcons"); + Ref<Texture> group = get_icon("Group", "EditorIcons"); + bool single = get_single_item() != NULL; - bool single = get_single_item()!=NULL; + Map<Node *, Object *> &selection = editor_selection->get_selection(); - Map<Node*,Object*> &selection = editor_selection->get_selection(); - - bool pivot_found=false; - - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + bool pivot_found = false; + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); 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<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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<Node2D>()) { - if (canvas_item->cast_to<Node2D>()->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<LockList>::Element*E=lock_list.front();E;E=E->next()) { + for (List<LockList>::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<ObjectID,BoneList>::Element*E=bone_list.front();E;E=E->next()) { + for (Map<ObjectID, BoneList>::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>(); + Node2D *n2d = obj->cast_to<Node2D>(); 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>(); + Node2D *pn2d = n2d->get_parent()->cast_to<Node2D>(); 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<Vector2> 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<Color> 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<Vector2>(),RID()); + VisualServer::get_singleton()->canvas_item_add_primitive(ci, bone_shape, colors, Vector<Vector2>(), RID()); if (editor_selection->is_selected(pi)) { - for(int i=0;i<bone_shape.size();i++) { + for (int i = 0; i < bone_shape.size(); i++) { - VisualServer::get_singleton()->canvas_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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &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<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Control>()) - has_control=true; + has_control = true; else - all_control=false; + all_control = false; - CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); + CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(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<ObjectID,BoneList>::Element *E=bone_list.front();E;E=E->next()) { + for (Map<ObjectID, BoneList>::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>(); - + CanvasItem *c = p_node->cast_to<CanvasItem>(); - 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<Map<ObjectID,BoneList>::Element*> bone_to_erase; + List<Map<ObjectID, BoneList>::Element *> bone_to_erase; - for(Map<ObjectID,BoneList>::Element*E=bone_list.front();E;E=E->next()) { + for (Map<ObjectID, BoneList>::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<Node*> &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<Node *> &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Change Anchors")); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Control *c = E->get()->cast_to<Control>(); - 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 (zoom<MIN_ZOOM) + if (zoom < MIN_ZOOM) return; - zoom=zoom*0.5; + zoom = zoom * 0.5; _update_scroll(0); viewport->update(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Control>(); 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<Node*,Object*> &selection = editor_selection->get_selection(); + Map<Node *, Object *> &selection = editor_selection->get_selection(); - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); 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>()) { Node2D *n2d = canvas_item->cast_to<Node2D>(); 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<Node2D*> ik_chain; + List<Node2D *> ik_chain; Node2D *n = n2d->get_parent_item()->cast_to<Node2D>(); - 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<Node2D>(); + n = n->get_parent_item()->cast_to<Node2D>(); } if (has_chain && ik_chain.size()) { - for(List<Node2D*>::Element *F=ik_chain.front();F;F=F->next()) { + for (List<Node2D *>::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<Control>(); 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<Node *, Object *> &selection = editor_selection->get_selection(); - Map<Node*,Object*> &selection = editor_selection->get_selection(); - - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); 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>()) { Node2D *n2d = canvas_item->cast_to<Node2D>(); 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<PoseClipboard>::Element *E=pose_clipboard.front();E;E=E->next()) { + for (List<PoseClipboard>::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<Node2D>(); 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<Node*,Object*> &selection = editor_selection->get_selection(); + Map<Node *, Object *> &selection = editor_selection->get_selection(); - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); 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>()) { @@ -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>()) { Control *ctrl = canvas_item->cast_to<Control>(); @@ -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<Node *, Object *> &selection = editor_selection->get_selection(); - - Map<Node*,Object*> &selection = editor_selection->get_selection(); - - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { Node2D *n2d = E->key()->cast_to<Node2D>(); 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<Node*,Object*> &selection = editor_selection->get_selection(); + Map<Node *, Object *> &selection = editor_selection->get_selection(); - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { Node2D *n2d = E->key()->cast_to<Node2D>(); 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<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); 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<Node*,Object*> &selection = editor_selection->get_selection(); + Map<Node *, Object *> &selection = editor_selection->get_selection(); - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *n2d = E->key()->cast_to<CanvasItem>(); 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<Node*,Object*> &selection = editor_selection->get_selection(); - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + Map<Node *, Object *> &selection = editor_selection->get_selection(); + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); 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<Variant>(),Object::CONNECT_DEFERRED); - v_scroll->connect("value_changed", this,"_update_scroll",Vector<Variant>(),Object::CONNECT_DEFERRED); + h_scroll->connect("value_changed", this, "_update_scroll", Vector<Variant>(), Object::CONNECT_DEFERRED); + v_scroll->connect("value_changed", this, "_update_scroll", Vector<Variant>(), 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<StyleBoxTexture>( memnew( StyleBoxTexture) ); + dialog_val->connect("value_changed", this, "_dialog_value_changed"); + select_sb = Ref<StyleBoxTexture>(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<CheckBox>(); +void CanvasItemEditorViewport::_on_select_type(Object *selected) { + CheckBox *check = selected->cast_to<CheckBox>(); 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<CheckBox>(); - default_type=check->get_text(); + CheckBox *check = button_group->get_pressed_button()->cast_to<CheckBox>(); + default_type = check->get_text(); _perform_drop_data(); selector->hide(); } -void CanvasItemEditorViewport::_create_preview(const Vector<String>& 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<ImageTexture> texture=Ref<ImageTexture> ( ResourceCache::get(path)->cast_to<ImageTexture>() ); - Sprite* sprite=memnew(Sprite); +void CanvasItemEditorViewport::_create_preview(const Vector<String> &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<ImageTexture> texture = Ref<ImageTexture>(ResourceCache::get(path)->cast_to<ImageTexture>()); + 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<PackedScene> scn=ResourceLoader::load(path); - if (scn.is_valid()){ - Node* instance=scn->instance(); - if (instance){ + } else if (type == "PackedScene") { + Ref<PackedScene> 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<String>& 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;i<childCount;i++) { - Node* child=p_desired_node->get_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<ImageTexture> texture=Ref<ImageTexture> ( ResourceCache::get(path)->cast_to<ImageTexture>() ); + Ref<ImageTexture> texture = Ref<ImageTexture>(ResourceCache::get(path)->cast_to<ImageTexture>()); 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<PropertyInfo> props; child->get_property_list(&props); - for(const List<PropertyInfo>::Element *E=props.front();E;E=E->next() ) { - if (E->get().name=="config/texture") { // Particles2D - property="config/texture"; + for (const List<PropertyInfo>::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<Vector2> 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<PackedScene> sdata=ResourceLoader::load(path); +bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, const Point2 &p_point) { + Ref<PackedScene> 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>(); + Node2D *parent_node2d = parent->cast_to<Node2D>(); if (parent_node2d) { - pos=parent_node2d->get_global_position(); + pos = parent_node2d->get_global_position(); } else { - Control* parent_control=parent->cast_to<Control>(); + Control *parent_control = parent->cast_to<Control>(); 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<String> error_files; editor_data->get_undo_redo().create_action(TTR("Create Node")); - for (int i=0;i<selected_files.size();i++) { - String path=selected_files[i]; - RES res=ResourceLoader::load(path); + for (int i = 0; i < selected_files.size(); i++) { + String path = selected_files[i]; + RES res = ResourceLoader::load(path); if (res.is_null()) { continue; } - 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 + 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;i<error_files.size();i++) { + for (int i = 0; i < error_files.size(); i++) { files_str += error_files[i].get_file().get_basename() + ","; } - files_str=files_str.substr(0,files_str.length()-1); + files_str = files_str.substr(0, files_str.length() - 1); accept->get_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<String> 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 (String(d["type"]) == "files") { + Vector<String> 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<PackedScene> sdata=ResourceLoader::load(files[i]); - Node* instanced_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); + String type = res->get_class(); + if (type == "PackedScene") { + Ref<PackedScene> 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<Node*> list=editor->get_editor_selection()->get_selected_node_list(); - if (list.size()==0) { + List<Node *> 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<BaseButton*> btn_list; + List<BaseButton *> btn_list; button_group->get_buttons(&btn_list); - for (int i=0;i<btn_list.size();i++) { - CheckBox* check=btn_list[i]->cast_to<CheckBox>(); - check->set_pressed(check->get_text()==default_type); + for (int i = 0; i < btn_list.size(); i++) { + CheckBox *check = btn_list[i]->cast_to<CheckBox>(); + 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;i<types.size();i++) { - CheckBox* check=memnew(CheckBox); + for (int i = 0; i < types.size(); i++) { + CheckBox *check = memnew(CheckBox); check->set_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 <reduzio@gmail.com> */ @@ -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<LockList> lock_list; @@ -220,7 +222,7 @@ class CanvasItemEditor : public VBoxContainer { }; uint64_t bone_last_frame; - Map<ObjectID,BoneList> bone_list; + Map<ObjectID, BoneList> 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<StyleBoxTexture> select_sb; Ref<Texture> 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<CanvasItem*> *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<CanvasItem *> *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 <class P, class C> + 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<Node*> *p_list); - void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; } + bool get_remove_list(List<Node *> *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<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); } + virtual bool get_remove_list(List<Node *> *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<String> types; Vector<String> 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<ButtonGroup> 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<String>& files) const; + void _create_preview(const Vector<String> &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<Vector2> 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)<grab_treshold) { + if (wip.size() > 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<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 points[2] ={ xform.xform(poly[i]), - xform.xform(poly[(i+1)%poly.size()]) }; + Vector2 points[2] = { xform.xform(poly[i]), + xform.xform(poly[(i + 1) % poly.size()]) }; - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points); - if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2) + Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); + if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) continue; //not valid to reuse point real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - - } - if (closest_idx>=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<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 cp =xform.xform(poly[i]); + Vector2 cp = xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - } - if (closest_idx>=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<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 cp =xform.xform(poly[i]); + Vector2 cp = xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - } - if (closest_idx>=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<Vector2> 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<Texture> handle= get_icon("EditorHandle","EditorIcons"); - - for(int i=0;i<poly.size();i++) { + Ref<Texture> 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<CollisionPolygon2D>(); - 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<CollisionPolygon2D>(); + 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<Node>()); @@ -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 <reduzio@gmail.com> @@ -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<Vector2> 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 <reduzio@gmail.com> 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<CapsuleShape2D> 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<CircleShape2D> 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<LineShape2D> 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<RayShape2D> 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<RectangleShape2D> 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<SegmentShape2D> 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<CapsuleShape2D> 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<LineShape2D> 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<RectangleShape2D> 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<SegmentShape2D> 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<CapsuleShape2D> 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<CircleShape2D> 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<LineShape2D> 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<RayShape2D> 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<RectangleShape2D> 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<SegmentShape2D> 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<Texture> h = get_icon("EditorHandle","EditorIcons"); - Vector2 size = h->get_size()*0.5; + Ref<Texture> 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<CircleShape2D> 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<RayShape2D> 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<CollisionShape2D>(); + node = p_node->cast_to<CollisionShape2D>(); - 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<Node>()); } -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<Point2> 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>(); + ColorRamp *color_ramp = p_object->cast_to<ColorRamp>(); if (!color_ramp) return; color_ramp_ref = Ref<ColorRamp>(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<float> new_offsets=ramp_editor->get_offsets(); - Vector<Color> new_colors=ramp_editor->get_colors(); - Vector<float> old_offsets=color_ramp_ref->get_offsets(); - Vector<Color> old_colors=color_ramp_ref->get_colors(); + Vector<float> new_offsets = ramp_editor->get_offsets(); + Vector<Color> new_colors = ramp_editor->get_colors(); + Vector<float> old_offsets = color_ramp_ref->get_offsets(); + Vector<Color> 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<float>& offsets, - const Vector<Color>& colors) { +void ColorRampEditorPlugin::_undo_redo_color_ramp(const Vector<float> &offsets, + const Vector<Color> &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<float>& 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<ColorRamp> 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<float>& offsets, const Vector<Color>& colors); + void _undo_redo_color_ramp(const Vector<float> &offsets, const Vector<Color> &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<MeshLibrary>& 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>(); + GIProbe *s = p_object->cast_to<GIProbe>(); 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<PropertyInfo> *p_list) const { +void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const { - for(int i=0;i<get_item_count();i++) { + for (int i = 0; i < get_item_count(); i++) { - String base=itos(i)+"/"; + String base = itos(i) + "/"; - p_list->push_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;i<item_plugins.size();i++) { + for (int i = 0; i < item_plugins.size(); i++) { if (item_plugins[i]->handles(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<Texture>()); - 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;i<item_plugins.size();i++) { + for (int i = 0; i < item_plugins.size(); i++) { if (item_plugins[i]->handles(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;i<item_plugins.size();i++) - memdelete( item_plugins[i] ); + for (int i = 0; i < item_plugins.size(); i++) + memdelete(item_plugins[i]); } void ItemListEditorPlugin::edit(Object *p_object) { @@ -365,17 +365,14 @@ void ItemListEditorPlugin::make_visible(bool p_visible) { ItemListEditorPlugin::ItemListEditorPlugin(EditorNode *p_node) { - editor=p_node; - item_list_editor = memnew( ItemListEditor ); + editor = p_node; + item_list_editor = memnew(ItemListEditor); CanvasItemEditor::get_singleton()->add_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 <reduzio@gmail.com> */ - 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<PropertyInfo> *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<PropertyInfo> *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<Texture>& p_tex) {} - virtual Ref<Texture> get_item_icon(int p_idx) const{ return Ref<Texture>(); }; + virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) {} + virtual Ref<Texture> get_item_icon(int p_idx) const { return Ref<Texture>(); }; 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<Texture>& p_tex) { ob->set_item_icon(p_idx, p_tex); } + virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { ob->set_item_icon(p_idx, p_tex); } virtual Ref<Texture> 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<Texture>& p_tex) { pp->set_item_icon(p_idx,p_tex); } + virtual void set_item_icon(int p_idx, const Ref<Texture> &p_tex) { pp->set_item_icon(p_idx, p_tex); } virtual Ref<Texture> 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<ItemListPlugin*> item_plugins; + Vector<ItemListPlugin *> 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<Vector2> 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)<grab_treshold) { + if (wip.size() > 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)<grab_treshold) { - //wip closed - _wip_close(false); - return true; + } else if (wip.size() > 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<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 points[2] ={ xform.xform(poly[i]), - xform.xform(poly[(i+1)%poly.size()]) }; + Vector2 points[2] = { xform.xform(poly[i]), + xform.xform(poly[(i + 1) % poly.size()]) }; - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points); - if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2) + Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); + if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) continue; //not valid to reuse point real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - - } - if (closest_idx>=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<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 cp =xform.xform(poly[i]); + Vector2 cp = xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - } - if (closest_idx>=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<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 cp =xform.xform(poly[i]); + Vector2 cp = xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - } - if (closest_idx>=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<Vector2> 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<Texture> handle= get_icon("EditorHandle","EditorIcons"); - - for(int i=0;i<poly.size();i++) { + Ref<Texture> 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<LightOccluder2D>(); - 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<LightOccluder2D>(); + 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<OccluderPolygon2D>(memnew( OccluderPolygon2D))); - undo_redo->add_undo_method(node,"set_occluder_polygon",Variant(REF())); + undo_redo->add_do_method(node, "set_occluder_polygon", Ref<OccluderPolygon2D>(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<Node>()); @@ -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 <reduzio@gmail.com> @@ -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<Vector3> 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<Node*> selection = editor_selection->get_selected_node_list(); + List<Node *> selection = editor_selection->get_selected_node_list(); if (selection.empty()) { Ref<Shape> 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<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { MeshInstance *instance = E->get()->cast_to<MeshInstance>(); 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> 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<NavigationMesh> nmesh = memnew( NavigationMesh ); + Ref<NavigationMesh> 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<MeshInstance>()); @@ -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> mesh; - if (mesh_source->get_text()=="") { + if (mesh_source->get_text() == "") { Ref<MultiMesh> 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<Face3> 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<Face3>::Write w = geometry.write(); - for(int i=0;i<gc;i++) { - for(int j=0;j<3;j++) { - w[i].vertex[j] = geom_xform.xform( w[i].vertex[j] ); + for (int i = 0; i < gc; i++) { + for (int j = 0; j < 3; j++) { + w[i].vertex[j] = geom_xform.xform(w[i].vertex[j]); } } - - w = PoolVector<Face3>::Write(); #if 0 node->get_multimesh()->set_instance_count(populate_amount->get_val()); @@ -167,34 +161,31 @@ void MultiMeshEditor::_populate() { #endif PoolVector<Face3> 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<Face3>::Read r = faces.read(); - - - float area_accum=0; - Map<float,int> triangle_area_map; - for(int i=0;i<facecount;i++) { + float area_accum = 0; + Map<float, int> triangle_area_map; + for (int i = 0; i < facecount; i++) { float area = r[i].get_area(); - if (area<CMP_EPSILON) + if (area < CMP_EPSILON) continue; - triangle_area_map[area_accum]=i; - area_accum+=area; + triangle_area_map[area_accum] = i; + area_accum += area; } ERR_EXPLAIN(TTR("Couldn't map area.")); - ERR_FAIL_COND(triangle_area_map.size()==0); + ERR_FAIL_COND(triangle_area_map.size() == 0); ERR_EXPLAIN(TTR("Couldn't map area.")); - ERR_FAIL_COND(area_accum==0); - + ERR_FAIL_COND(area_accum == 0); - Ref<MultiMesh> multimesh = memnew( MultiMesh ); + Ref<MultiMesh> 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<instance_count;i++) { + for (int i = 0; i < instance_count; i++) { - float areapos = Math::random(0.0f,area_accum); + float areapos = Math::random(0.0f, area_accum); - Map<float,int>::Element *E = triangle_area_map.find_closest(areapos); + Map<float, int>::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<MultiMeshInstance>()); @@ -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<NavigationPolygon>(memnew( NavigationPolygon))); - undo_redo->add_undo_method(node,"set_navigation_polygon",Variant(REF())); + undo_redo->add_do_method(node, "set_navigation_polygon", Ref<NavigationPolygon>(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)<grab_treshold) { + if (wip.size() > 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;j<node->get_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<Vector2> points=node->get_navigation_polygon()->get_outline(j); + PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j); - int pc=points.size(); - PoolVector<Vector2>::Read poly=points.read(); + int pc = points.size(); + PoolVector<Vector2>::Read poly = points.read(); - for(int i=0;i<pc;i++) { + for (int i = 0; i < pc; i++) { - Vector2 points[2] ={ xform.xform(poly[i]), - xform.xform(poly[(i+1)%pc]) }; + Vector2 points[2] = { xform.xform(poly[i]), + xform.xform(poly[(i + 1) % pc]) }; - Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points); - if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2) + Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); + if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) continue; //not valid to reuse point real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_outline=j; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_outline = j; + closest_pos = cp; + closest_idx = i; } - - } } - if (closest_idx>=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<Point2> 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;j<node->get_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<Vector2> points=node->get_navigation_polygon()->get_outline(j); + PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j); - int pc=points.size(); - PoolVector<Vector2>::Read poly=points.read(); + int pc = points.size(); + PoolVector<Vector2>::Read poly = points.read(); - for(int i=0;i<pc;i++) { + 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<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_outline=j; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_outline = j; + closest_idx = i; } } } - if (closest_idx>=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<Vector2> 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;j<node->get_navigation_polygon()->get_outline_count();j++) { - + real_t closest_dist = 1e10; - PoolVector<Vector2> 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<Vector2>::Read poly=points.read(); + PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j); - for(int i=0;i<pc;i++) { + int pc = points.size(); + PoolVector<Vector2>::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<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_outline=j; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_outline = j; + closest_idx = i; } } } - if (closest_idx>=0) { - + if (closest_idx >= 0) { PoolVector<Vector2> 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<Texture> handle= get_icon("EditorHandle","EditorIcons"); - - + Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - for(int j=-1;j<node->get_navigation_polygon()->get_outline_count();j++) { + for (int j = -1; j < node->get_navigation_polygon()->get_outline_count(); j++) { Vector<Vector2> 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;i<poly.size();i++) { + for (int i = 0; i < poly.size(); i++) { - - Vector2 p,p2; - p = (j==edited_outline && i==edited_point) ? edited_point_pos : poly[i]; - if (j==edited_outline && ((wip_active && i==poly.size()-1) || (((i+1)%poly.size())==edited_point))) - p2=edited_point_pos; + Vector2 p, p2; + p = (j == edited_outline && i == edited_point) ? edited_point_pos : poly[i]; + if (j == edited_outline && ((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 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<NavigationPolygonInstance>(); - 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<NavigationPolygonInstance>(); + 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<Node>()); @@ -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 <reduzio@gmail.com> @@ -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<Vector2> 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<Particles2D>(); + particles = p_object->cast_to<Particles2D>(); } 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<uint8_t> data = img.get_data(); PoolVector<uint8_t>::Read r = data.read(); Vector<Point2i> 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;i<s.width*s.height;i++) { + for (int i = 0; i < s.width * s.height; i++) { - uint8_t a = r[i*2+1]; - if (a>128) { - 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<Point2> epoints; epoints.resize(epc); PoolVector<Point2>::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<epc;i++) { + for (int i = 0; i < epc; i++) { - Point2 p = valid_positions[Math::rand()%vpc]; - p-=s/2; - w[i]=p/extents; + Point2 p = valid_positions[Math::rand() % vpc]; + p -= s / 2; + w[i] = p / extents; } w = PoolVector<Point2>::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<Vector2>()); - undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points()); + undo_redo->add_do_method(particles, "set_emission_points", PoolVector<Vector2>()); + 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<String> ext; ImageLoader::get_recognized_extensions(&ext); - for(List<String>::Element *E=ext.front();E;E=E->next()) { - file->add_filter("*."+E->get()+"; "+E->get().to_upper()); + for (List<String>::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<Curve2D> curve = node->get_curve(); - for(int i=0;i<curve->get_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<Curve2D> 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<Curve2D> 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<Curve2D> 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<Texture> handle= get_icon("EditorHandle","EditorIcons"); + Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); Size2 handle_size = handle->get_size(); Ref<Curve2D> 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;i<len;i++) { - + for (int i = 0; i < len; i++) { Vector2 point = xform.xform(curve->get_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 (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 < 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<Path2D>(); - 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<Path2D>(); + 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)<CMP_EPSILON) + Vector2 end = node->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<Node>()); @@ -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 <reduzio@gmail.com> @@ -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<Vector2> points = node->get_polygon(); PoolVector<Vector2> 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<Vector2> points = node->get_polygon(); - if (points.size()==0) + if (points.size() == 0) break; PoolVector<Vector2> 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<Vector2> points = node->get_polygon(); PoolVector<Vector2> 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<Vector2> 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<Vector2>()); - 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<Vector2>()); + 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<Vector2> 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)<grab_treshold) { + if (wip.size() > 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;i<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 points[2] ={ xform.xform(poly[i]+node->get_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])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2) + Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points); + if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) continue; //not valid to reuse point real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - - } - if (closest_idx>=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;i<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 cp =xform.xform(poly[i]+node->get_offset()); + Vector2 cp = xform.xform(poly[i] + node->get_offset()); real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - } - if (closest_idx>=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;i<poly.size();i++) { + real_t closest_dist = 1e10; + for (int i = 0; i < poly.size(); i++) { - Vector2 cp =xform.xform(poly[i]+node->get_offset()); + Vector2 cp = xform.xform(poly[i] + node->get_offset()); real_t d = cp.distance_to(gpoint); - if (d<closest_dist && d<grab_treshold) { - closest_dist=d; - closest_pos=cp; - closest_idx=i; + if (d < closest_dist && d < grab_treshold) { + closest_dist = d; + closest_pos = cp; + closest_idx = i; } - } - if (closest_idx>=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<Vector2> 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<Texture> handle= get_icon("EditorHandle","EditorIcons"); + Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - for(int i=0;i<poly.size();i++) { + for (int i = 0; i < poly.size(); i++) { - - 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; + 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;i<UV_MODE_MAX;i++) { - uv_button[i]->set_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;i<uv_prev.size();i++) { + uv_drag_index = -1; + for (int i = 0; i < uv_prev.size(); i++) { - Vector2 tuv=mtx.xform(uv_prev[i]); - if (tuv.distance_to(Vector2(mb.x,mb.y))<8) { - uv_drag_from=tuv; - uv_drag_index=i; + Vector2 tuv = mtx.xform(uv_prev[i]); + if (tuv.distance_to(Vector2(mb.x, mb.y)) < 8) { + uv_drag_from = tuv; + uv_drag_index = i; } } - if (uv_drag_index==-1) { - uv_drag=false; + if (uv_drag_index == -1) { + uv_drag = false; } - } } else if (uv_drag) { undo_redo->create_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<Vector2> uv_new=uv_prev; - uv_new.set( uv_drag_index, uv_new[uv_drag_index]+drag ); + PoolVector<Vector2> 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<Vector2> uv_new=uv_prev; - for(int i=0;i<uv_new.size();i++) - uv_new.set( i, uv_new[i]+drag ); + PoolVector<Vector2> 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<Vector2> uv_new=uv_prev; + PoolVector<Vector2> uv_new = uv_prev; - for(int i=0;i<uv_new.size();i++) - center+=uv_prev[i]; - center/=uv_new.size(); + for (int i = 0; i < uv_new.size(); i++) + center += uv_prev[i]; + center /= uv_new.size(); - float angle = (uv_drag_from - mtx.xform(center)).normalized().angle_to( (uv_drag_to - mtx.xform(center)).normalized() ); + float angle = (uv_drag_from - mtx.xform(center)).normalized().angle_to((uv_drag_to - mtx.xform(center)).normalized()); - for(int i=0;i<uv_new.size();i++) { + for (int i = 0; i < uv_new.size(); i++) { Vector2 rel = uv_prev[i] - center; - rel=rel.rotated(angle); - uv_new.set(i,center+rel); + rel = rel.rotated(angle); + uv_new.set(i, center + rel); } node->set_uv(uv_new); @@ -630,47 +582,41 @@ void Polygon2DEditor::_uv_input(const InputEvent& p_input) { case UV_MODE_SCALE: { Vector2 center; - PoolVector<Vector2> uv_new=uv_prev; + PoolVector<Vector2> uv_new = uv_prev; - for(int i=0;i<uv_new.size();i++) - center+=uv_prev[i]; - center/=uv_new.size(); + for (int i = 0; i < uv_new.size(); i++) + center += uv_prev[i]; + center /= uv_new.size(); float from_dist = uv_drag_from.distance_to(mtx.xform(center)); float to_dist = uv_drag_to.distance_to(mtx.xform(center)); - if (from_dist<2) + if (from_dist < 2) break; - float scale = to_dist/from_dist; + float scale = to_dist / from_dist; - - for(int i=0;i<uv_new.size();i++) { + for (int i = 0; i < uv_new.size(); i++) { Vector2 rel = uv_prev[i] - center; - rel=rel*scale; - uv_new.set(i,center+rel); + rel = rel * scale; + uv_new.set(i, center + rel); } node->set_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;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.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;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; + 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<Vector2> uvs = node->get_uv(); - Ref<Texture> handle = get_icon("EditorHandle","EditorIcons"); + Ref<Texture> 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;i<uvs.size();i++) { + for (int i = 0; i < uvs.size(); i++) { - 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); + 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<Polygon2D>(); - 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<Polygon2D>(); + 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;i<UV_MODE_MAX;i++) { + for (int i = 0; i < UV_MODE_MAX; i++) { - uv_button[i]=memnew( ToolButton ); + uv_button[i] = memnew(ToolButton); uv_button[i]->set_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<Node>()); } @@ -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 <reduzio@gmail.com> @@ -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<Variant>(),true); } - if (p_what==NOTIFICATION_DRAW) { - + if (p_what == NOTIFICATION_DRAW) { } } -void ResourcePreloaderEditor::_files_load_request(const Vector<String>& p_paths) { +void ResourcePreloaderEditor::_files_load_request(const Vector<String> &p_paths) { - for(int i=0;i<p_paths.size();i++) { + for (int i = 0; i < p_paths.size(); i++) { String path = p_paths[i]; @@ -77,41 +72,38 @@ void ResourcePreloaderEditor::_files_load_request(const Vector<String>& 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<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("",&extensions); - for(int i=0;i<extensions.size();i++) - file->add_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<String> names; - for(List<StringName>::Element *E=rnames.front();E;E=E->next()) { + for (List<StringName>::Element *E = rnames.front(); E; E = E->next()) { names.push_back(E->get()); } names.sort(); - for(List<String>::Element *E=names.front();E;E=E->next()) { + for (List<String>::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<String> 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<String> 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>(); + ResourcePreloader *s = p_object->cast_to<ResourcePreloader>(); 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<String>& p_paths); + void _files_load_request(const Vector<String> &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<RichTextLabel>(); - + node = p_rich_text->cast_to<RichTextLabel>(); } 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<Node>()); @@ -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 <reduzio@gmail.com> @@ -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 <reduzio@gmail.com> 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;i<EditorNode::get_singleton()->get_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<String,Cache> cached; - + Map<String, Cache> cached; public: - uint64_t max_time_cache; int max_cache_size; void cleanup() { - List< Map<String,Cache>::Element * > to_clean; + List<Map<String, Cache>::Element *> to_clean; - - Map<String,Cache>::Element *I=cached.front(); - while(I) { - if ((OS::get_singleton()->get_ticks_msec()-I->get().time_loaded)>max_time_cache) { + Map<String, Cache>::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<String,Cache>::Element *E=cached.find(p_path); + Map<String, Cache>::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<String,Cache>::Element *O=cached.front(); - older=O->get().time_loaded; - Map<String,Cache>::Element *I=O; - while(I) { - if (I->get().time_loaded<older) { + Map<String, Cache>::Element *O = cached.front(); + older = O->get().time_loaded; + Map<String, Cache>::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<String>& p_functions, bool p_dontclear) { +void ScriptEditorQuickOpen::popup(const Vector<String> &p_functions, bool p_dontclear) { popup_centered_ratio(0.6); if (p_dontclear) @@ -164,55 +154,45 @@ void ScriptEditorQuickOpen::popup(const Vector<String>& 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;i<functions.size();i++) { + for (int i = 0; i < functions.size(); i++) { String file = functions[i]; - if ((search_box->get_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<ScriptEditorBase>(); 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;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); 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<Script> p_script) { editor->push_item(p_script.operator->()); } - void ScriptEditor::_goto_script_line2(int p_line) { int selected = tab_container->get_current_tab(); - if (selected<0 || selected>=tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) return; ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>(); @@ -335,54 +304,49 @@ void ScriptEditor::_goto_script_line2(int p_line) { return; current->goto_line(p_line); - } -void ScriptEditor::_goto_script_line(REF p_script,int p_line) { - +void ScriptEditor::_goto_script_line(REF p_script, int p_line) { editor->push_item(p_script.ptr()); int selected = tab_container->get_current_tab(); - if (selected<0 || selected>=tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) return; ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>(); if (!current) return; - current->goto_line(p_line,true); - + current->goto_line(p_line, true); } - void ScriptEditor::_update_history_arrows() { - script_back->set_disabled( history_pos<=0 ); - script_forward->set_disabled( history_pos>=history.size()-1 ); + script_back->set_disabled(history_pos <= 0); + script_forward->set_disabled(history_pos >= history.size() - 1); } void ScriptEditor::_save_history() { - - if (history_pos>=0 && history_pos<history.size() && history[history_pos].control==tab_container->get_current_tab_control()) { + if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) { Node *n = tab_container->get_current_tab_control(); if (n->cast_to<ScriptEditorBase>()) { - history[history_pos].state=n->cast_to<ScriptEditorBase>()->get_edit_state(); + history[history_pos].state = n->cast_to<ScriptEditorBase>()->get_edit_state(); } if (n->cast_to<EditorHelp>()) { - history[history_pos].state=n->cast_to<EditorHelp>()->get_scroll(); + history[history_pos].state = n->cast_to<EditorHelp>()->get_scroll(); } } - history.resize(history_pos+1); + history.resize(history_pos + 1); ScriptHistory sh; - sh.control=tab_container->get_current_tab_control(); - sh.state=Variant(); + sh.control = tab_container->get_current_tab_control(); + sh.state = Variant(); history.push_back(sh); history_pos++; @@ -390,7 +354,6 @@ void ScriptEditor::_save_history() { _update_history_arrows(); } - void ScriptEditor::_go_to_tab(int p_idx) { Node *cn = tab_container->get_child(p_idx); @@ -400,29 +363,28 @@ void ScriptEditor::_go_to_tab(int p_idx) { if (!c) return; - if (history_pos>=0 && history_pos<history.size() && history[history_pos].control==tab_container->get_current_tab_control()) { + if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) { Node *n = tab_container->get_current_tab_control(); if (n->cast_to<ScriptEditorBase>()) { - history[history_pos].state=n->cast_to<ScriptEditorBase>()->get_edit_state(); + history[history_pos].state = n->cast_to<ScriptEditorBase>()->get_edit_state(); } if (n->cast_to<EditorHelp>()) { - history[history_pos].state=n->cast_to<EditorHelp>()->get_scroll(); + history[history_pos].state = n->cast_to<EditorHelp>()->get_scroll(); } } - history.resize(history_pos+1); + history.resize(history_pos + 1); ScriptHistory sh; - sh.control=c; - sh.state=Variant(); + sh.control = c; + sh.state = Variant(); history.push_back(sh); history_pos++; - tab_container->set_current_tab(p_idx); c = tab_container->get_current_tab_control(); @@ -437,23 +399,21 @@ void ScriptEditor::_go_to_tab(int p_idx) { if (c->cast_to<EditorHelp>()) { script_name_label->set_text(c->cast_to<EditorHelp>()->get_class()); - script_icon->set_texture(get_icon("Help","EditorIcons")); + script_icon->set_texture(get_icon("Help", "EditorIcons")); if (is_visible_in_tree()) c->cast_to<EditorHelp>()->set_focused(); } - - - c->set_meta("__editor_pass",++edit_pass); + c->set_meta("__editor_pass", ++edit_pass); _update_history_arrows(); - _update_script_colors(); + _update_script_colors(); _update_selected_editor_menu(); } void ScriptEditor::_close_tab(int p_idx, bool p_save) { int selected = p_idx; - if (selected<0 || selected>=tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) return; Node *tselected = tab_container->get_child(selected); @@ -468,27 +428,27 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) { } //remove from history - history.resize(history_pos+1); + history.resize(history_pos + 1); - for(int i=0;i<history.size();i++) { - if (history[i].control==tselected) { + for (int i = 0; i < history.size(); i++) { + if (history[i].control == tselected) { history.remove(i); i--; history_pos--; } } - if (history_pos>=history.size()) { - history_pos=history.size()-1; + if (history_pos >= history.size()) { + history_pos = history.size() - 1; } int idx = tab_container->get_current_tab(); memdelete(tselected); - if (idx>=tab_container->get_child_count()) - idx=tab_container->get_child_count()-1; - if (idx>=0) { + if (idx >= tab_container->get_child_count()) + idx = tab_container->get_child_count() - 1; + if (idx >= 0) { - if (history_pos>=0) { + if (history_pos >= 0) { idx = history[history_pos].control->get_index(); } tab_container->set_current_tab(idx); @@ -496,11 +456,8 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) { //script_list->select(idx); } - _update_history_arrows(); - - _update_script_names(); _save_layout(); } @@ -508,10 +465,9 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) { void ScriptEditor::_close_current_tab() { _close_tab(tab_container->get_current_tab()); - } -void ScriptEditor::_close_discard_current_tab(const String& p_str) { +void ScriptEditor::_close_discard_current_tab(const String &p_str) { _close_tab(tab_container->get_current_tab(), false); erase_tab_confirm->hide(); } @@ -519,22 +475,20 @@ void ScriptEditor::_close_discard_current_tab(const String& p_str) { void ScriptEditor::_close_docs_tab() { int child_count = tab_container->get_child_count(); - for (int i = child_count-1; i>=0; i--) { + for (int i = child_count - 1; i >= 0; i--) { EditorHelp *se = tab_container->get_child(i)->cast_to<EditorHelp>(); if (se) { _close_tab(i); } - } - } void ScriptEditor::_close_all_tabs() { int child_count = tab_container->get_child_count(); - for (int i = child_count-1; i>=0; i--) { + for (int i = child_count - 1; i >= 0; i--) { tab_container->set_current_tab(i); ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); @@ -546,34 +500,30 @@ void ScriptEditor::_close_all_tabs() { _ask_close_current_unsaved_tab(se); continue; } - } _close_current_tab(); } - } void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) { - erase_tab_confirm->set_text("Close and save changes?\n\""+current->get_name()+"\""); + erase_tab_confirm->set_text("Close and save changes?\n\"" + current->get_name() + "\""); erase_tab_confirm->popup_centered_minsize(); } - -void ScriptEditor::_resave_scripts(const String& p_str) { +void ScriptEditor::_resave_scripts(const String &p_str) { apply_scripts(); - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) continue; - Ref<Script> script = se->get_edited_script(); - if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) + if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) continue; //internal script, who cares if (trim_trailing_whitespace_on_save) { @@ -584,14 +534,11 @@ void ScriptEditor::_resave_scripts(const String& p_str) { } disk_changed->hide(); - } -void ScriptEditor::_reload_scripts(){ - +void ScriptEditor::_reload_scripts() { - - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) { @@ -599,46 +546,36 @@ void ScriptEditor::_reload_scripts(){ continue; } - Ref<Script> script = se->get_edited_script(); - if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) { + if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) { continue; //internal script, who cares } - uint64_t last_date = script->get_last_modified_time(); uint64_t date = FileAccess::get_modified_time(script->get_path()); //printf("last date: %lli vs date: %lli\n",last_date,date); - if (last_date==date) { + if (last_date == date) { continue; } - - Ref<Script> rel_script = ResourceLoader::load(script->get_path(),script->get_class(),true); + Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true); ERR_CONTINUE(!rel_script.is_valid()); - script->set_source_code( rel_script->get_source_code() ); - script->set_last_modified_time( rel_script->get_last_modified_time() ); + script->set_source_code(rel_script->get_source_code()); + script->set_last_modified_time(rel_script->get_last_modified_time()); script->reload(); se->reload_text(); - - } disk_changed->hide(); _update_script_names(); - } +void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) { - -void ScriptEditor::_res_saved_callback(const Ref<Resource>& p_res) { - - - - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) { @@ -646,105 +583,94 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource>& p_res) { continue; } - Ref<Script> script = se->get_edited_script(); - if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) { + if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) { continue; //internal script, who cares } - if (script==p_res) { + if (script == p_res) { se->tag_saved_version(); } - } _update_script_names(); - if (!pending_auto_reload && auto_reload_running_scripts) { call_deferred("_live_auto_reload_running_scripts"); - pending_auto_reload=true; + pending_auto_reload = true; } } void ScriptEditor::_live_auto_reload_running_scripts() { - pending_auto_reload=false; + pending_auto_reload = false; debugger->reload_scripts(); } - bool ScriptEditor::_test_script_times_on_disk(Ref<Script> p_for_script) { - disk_changed_list->clear(); TreeItem *r = disk_changed_list->create_item(); disk_changed_list->set_hide_root(true); - bool need_ask=false; - bool need_reload=false; - bool use_autoreload=bool(EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change",false)); - + bool need_ask = false; + bool need_reload = false; + bool use_autoreload = bool(EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", false)); - - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (se) { Ref<Script> script = se->get_edited_script(); - if (p_for_script.is_valid() && p_for_script!=script) + if (p_for_script.is_valid() && p_for_script != script) continue; - if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) + if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) continue; //internal script, who cares - uint64_t last_date = script->get_last_modified_time(); uint64_t date = FileAccess::get_modified_time(script->get_path()); //printf("last date: %lli vs date: %lli\n",last_date,date); - if (last_date!=date) { + if (last_date != date) { TreeItem *ti = disk_changed_list->create_item(r); - ti->set_text(0,script->get_path().get_file()); + ti->set_text(0, script->get_path().get_file()); if (!use_autoreload || se->is_unsaved()) { - need_ask=true; + need_ask = true; } - need_reload=true; + need_reload = true; //r->set_metadata(0,); } } } - - if (need_reload) { if (!need_ask) { script_editor->_reload_scripts(); - need_reload=false; + need_reload = false; } else { - disk_changed->call_deferred("popup_centered_ratio",0.5); + disk_changed->call_deferred("popup_centered_ratio", 0.5); } } return need_reload; } - void ScriptEditor::_file_dialog_action(String p_file) { switch (file_dialog_option) { case FILE_SAVE_THEME_AS: { - if(!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) { + if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) { editor->show_warning(TTR("Error while saving theme"), TTR("Error saving")); } } break; case FILE_IMPORT_THEME: { - if(!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) { + if (!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) { editor->show_warning(TTR("Error importing theme"), TTR("Error importing")); } } break; @@ -754,11 +680,10 @@ void ScriptEditor::_file_dialog_action(String p_file) { void ScriptEditor::_menu_option(int p_option) { - - switch(p_option) { + switch (p_option) { case FILE_NEW: { script_create_dialog->config("Node", ".gd"); - script_create_dialog->popup_centered(Size2(300, 300)*EDSCALE); + script_create_dialog->popup_centered(Size2(300, 300) * EDSCALE); } break; case FILE_OPEN: { @@ -785,7 +710,7 @@ void ScriptEditor::_menu_option(int p_option) { EditorSettings::get_singleton()->load_text_editor_theme(); } break; case FILE_SAVE_THEME: { - if(!EditorSettings::get_singleton()->save_text_editor_theme()) { + if (!EditorSettings::get_singleton()->save_text_editor_theme()) { editor->show_warning(TTR("Error while saving theme"), TTR("Error saving")); } } break; @@ -807,17 +732,17 @@ void ScriptEditor::_menu_option(int p_option) { String current; - if (tab_container->get_tab_count()>0) { - EditorHelp *eh = tab_container->get_child( tab_container->get_current_tab() )->cast_to<EditorHelp>(); + if (tab_container->get_tab_count() > 0) { + EditorHelp *eh = tab_container->get_child(tab_container->get_current_tab())->cast_to<EditorHelp>(); if (eh) { - current=eh->get_class(); + current = eh->get_class(); } } help_index->popup(); - if (current!="") { - help_index->call_deferred("select_class",current); + if (current != "") { + help_index->call_deferred("select_class", current); } } break; case SEARCH_WEBSITE: { @@ -834,8 +759,8 @@ void ScriptEditor::_menu_option(int p_option) { } break; case DEBUG_SHOW: { if (debugger) { - bool visible = debug_menu->get_popup()->is_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW) ); - debug_menu->get_popup()->set_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW), !visible); + bool visible = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW), !visible); if (visible) debugger->hide(); else @@ -843,25 +768,24 @@ void ScriptEditor::_menu_option(int p_option) { } } break; case DEBUG_SHOW_KEEP_OPEN: { - bool visible = debug_menu->get_popup()->is_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN) ); + bool visible = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN)); if (debugger) debugger->set_hide_on_stop(visible); - debug_menu->get_popup()->set_item_checked( debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN), !visible); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN), !visible); } break; } - int selected = tab_container->get_current_tab(); - if (selected<0 || selected>=tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) return; ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>(); if (current) { - switch(p_option) { + switch (p_option) { case FILE_NEW: { script_create_dialog->config("Node", ".gd"); - script_create_dialog->popup_centered(Size2(300, 300)*EDSCALE); + script_create_dialog->popup_centered(Size2(300, 300) * EDSCALE); } break; case FILE_SAVE: { @@ -870,21 +794,21 @@ void ScriptEditor::_menu_option(int p_option) { if (trim_trailing_whitespace_on_save) current->trim_trailing_whitespace(); - editor->save_resource( current->get_edited_script() ); + editor->save_resource(current->get_edited_script()); } break; case FILE_SAVE_AS: { current->trim_trailing_whitespace(); editor->push_item(current->get_edited_script()->cast_to<Object>()); - editor->save_resource_as( current->get_edited_script() ); + editor->save_resource_as(current->get_edited_script()); } break; case FILE_TOOL_RELOAD: case FILE_TOOL_RELOAD_SOFT: { - current->reload(p_option==FILE_TOOL_RELOAD_SOFT); + current->reload(p_option == FILE_TOOL_RELOAD_SOFT); } break; @@ -926,32 +850,30 @@ void ScriptEditor::_menu_option(int p_option) { } break; case WINDOW_MOVE_LEFT: { - if (tab_container->get_current_tab()>0) { - tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()-1); - script_list->call_deferred("select",tab_container->get_current_tab()-1); - tab_container->move_child(current,tab_container->get_current_tab()-1); + if (tab_container->get_current_tab() > 0) { + tab_container->call_deferred("set_current_tab", tab_container->get_current_tab() - 1); + script_list->call_deferred("select", tab_container->get_current_tab() - 1); + tab_container->move_child(current, tab_container->get_current_tab() - 1); _update_script_names(); } } break; case WINDOW_MOVE_RIGHT: { - if (tab_container->get_current_tab()<tab_container->get_child_count()-1) { - tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()+1); - script_list->call_deferred("select",tab_container->get_current_tab()+1); - tab_container->move_child(current,tab_container->get_current_tab()+1); + if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) { + tab_container->call_deferred("set_current_tab", tab_container->get_current_tab() + 1); + script_list->call_deferred("select", tab_container->get_current_tab() + 1); + tab_container->move_child(current, tab_container->get_current_tab() + 1); _update_script_names(); } - } break; default: { - if (p_option>=WINDOW_SELECT_BASE) { - - tab_container->set_current_tab(p_option-WINDOW_SELECT_BASE); - script_list->select(p_option-WINDOW_SELECT_BASE); + if (p_option >= WINDOW_SELECT_BASE) { + tab_container->set_current_tab(p_option - WINDOW_SELECT_BASE); + script_list->select(p_option - WINDOW_SELECT_BASE); } } } @@ -960,7 +882,7 @@ void ScriptEditor::_menu_option(int p_option) { EditorHelp *help = tab_container->get_current_tab_control()->cast_to<EditorHelp>(); if (help) { - switch(p_option) { + switch (p_option) { case HELP_SEARCH_FIND: { help->popup_search(); @@ -977,12 +899,8 @@ void ScriptEditor::_menu_option(int p_option) { case CLOSE_ALL: { _close_all_tabs(); } break; - - } } - - } void ScriptEditor::_tab_changed(int p_which) { @@ -992,19 +910,19 @@ void ScriptEditor::_tab_changed(int p_which) { void ScriptEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - editor->connect("play_pressed",this,"_editor_play"); - editor->connect("pause_pressed",this,"_editor_pause"); - editor->connect("stop_pressed",this,"_editor_stop"); - editor->connect("script_add_function_request",this,"_add_callback"); - editor->connect("resource_saved",this,"_res_saved_callback"); - script_list->connect("item_selected",this,"_script_selected"); - script_split->connect("dragged",this,"_script_split_dragged"); - autosave_timer->connect("timeout",this,"_autosave_scripts"); + editor->connect("play_pressed", this, "_editor_play"); + editor->connect("pause_pressed", this, "_editor_pause"); + editor->connect("stop_pressed", this, "_editor_stop"); + editor->connect("script_add_function_request", this, "_add_callback"); + editor->connect("resource_saved", this, "_res_saved_callback"); + script_list->connect("item_selected", this, "_script_selected"); + script_split->connect("dragged", this, "_script_split_dragged"); + autosave_timer->connect("timeout", this, "_autosave_scripts"); { float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs"); - if (autosave_time>0) { + if (autosave_time > 0) { autosave_timer->set_wait_time(autosave_time); autosave_timer->start(); } else { @@ -1012,65 +930,54 @@ void ScriptEditor::_notification(int p_what) { } } - EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed"); - help_search->set_icon(get_icon("Help","EditorIcons")); - site_search->set_icon(get_icon("Godot","EditorIcons")); - class_search->set_icon(get_icon("ClassList","EditorIcons")); - - script_forward->set_icon(get_icon("Forward","EditorIcons")); - script_back->set_icon(get_icon("Back","EditorIcons")); - - - + EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); + help_search->set_icon(get_icon("Help", "EditorIcons")); + site_search->set_icon(get_icon("Godot", "EditorIcons")); + class_search->set_icon(get_icon("ClassList", "EditorIcons")); + script_forward->set_icon(get_icon("Forward", "EditorIcons")); + script_back->set_icon(get_icon("Back", "EditorIcons")); } - if (p_what==NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY) { - get_tree()->connect("tree_changed",this,"_tree_changed"); - editor->connect("request_help",this,"_request_help"); + get_tree()->connect("tree_changed", this, "_tree_changed"); + editor->connect("request_help", this, "_request_help"); } - if (p_what==NOTIFICATION_EXIT_TREE) { - - editor->disconnect("play_pressed",this,"_editor_play"); - editor->disconnect("pause_pressed",this,"_editor_pause"); - editor->disconnect("stop_pressed",this,"_editor_stop"); + if (p_what == NOTIFICATION_EXIT_TREE) { + editor->disconnect("play_pressed", this, "_editor_play"); + editor->disconnect("pause_pressed", this, "_editor_pause"); + editor->disconnect("stop_pressed", this, "_editor_stop"); } - if (p_what==MainLoop::NOTIFICATION_WM_FOCUS_IN) { + if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) { _test_script_times_on_disk(); _update_modified_scripts_for_external_editor(); } - if (p_what==NOTIFICATION_PROCESS) { - + if (p_what == NOTIFICATION_PROCESS) { } - } bool ScriptEditor::can_take_away_focus() const { int selected = tab_container->get_current_tab(); - if (selected<0 || selected>=tab_container->get_child_count()) + if (selected < 0 || selected >= tab_container->get_child_count()) return true; ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>(); if (!current) return true; - return current->can_lose_focus_on_node_selection(); - } -void ScriptEditor::close_builtin_scripts_from_scene(const String& p_scene) { - +void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) { - - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); @@ -1080,32 +987,27 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String& p_scene) { if (!script.is_valid()) continue; - if (script->get_path().find("::")!=-1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed + if (script->get_path().find("::") != -1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed _close_tab(i); i--; - } } - } - - } void ScriptEditor::edited_scene_changed() { _update_modified_scripts_for_external_editor(); - } -static const Node * _find_node_with_script(const Node* p_node, const RefPtr & p_script) { +static const Node *_find_node_with_script(const Node *p_node, const RefPtr &p_script) { - if (p_node->get_script()==p_script) + if (p_node->get_script() == p_script) return p_node; - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { - const Node *result = _find_node_with_script(p_node->get_child(i),p_script); + const Node *result = _find_node_with_script(p_node->get_child(i), p_script); if (result) return result; } @@ -1115,7 +1017,6 @@ static const Node * _find_node_with_script(const Node* p_node, const RefPtr & p_ Dictionary ScriptEditor::get_state() const { - //apply_scripts(); Dictionary state; @@ -1155,7 +1056,7 @@ Dictionary ScriptEditor::get_state() const { #endif return state; } -void ScriptEditor::set_state(const Dictionary& p_state) { +void ScriptEditor::set_state(const Dictionary &p_state) { #if 0 print_line("attempt set state: "+String(Variant(p_state))); @@ -1195,7 +1096,6 @@ void ScriptEditor::set_state(const Dictionary& p_state) { tab_container->set_current_tab(p_state["current"]); } #endif - } void ScriptEditor::clear() { #if 0 @@ -1224,15 +1124,11 @@ void ScriptEditor::clear() { } #endif - - } - void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) { - - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) @@ -1242,27 +1138,23 @@ void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) { se->get_breakpoints(&bpoints); Ref<Script> script = se->get_edited_script(); String base = script->get_path(); - ERR_CONTINUE( base.begins_with("local://") || base=="" ); + ERR_CONTINUE(base.begins_with("local://") || base == ""); - for(List<int>::Element *E=bpoints.front();E;E=E->next()) { + for (List<int>::Element *E = bpoints.front(); E; E = E->next()) { - p_breakpoints->push_back(base+":"+itos(E->get()+1)); + p_breakpoints->push_back(base + ":" + itos(E->get() + 1)); } } - } - - - - void ScriptEditor::ensure_focus_current() { if (!is_inside_tree()) return; int cidx = tab_container->get_current_tab(); - if (cidx<0 || cidx>=tab_container->get_tab_count()); + if (cidx < 0 || cidx >= tab_container->get_tab_count()) + ; Control *c = tab_container->get_child(cidx)->cast_to<Control>(); if (!c) return; @@ -1277,17 +1169,15 @@ void ScriptEditor::_script_selected(int p_idx) { grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing _go_to_tab(script_list->get_item_metadata(p_idx)); - grab_focus_block=false; + grab_focus_block = false; } void ScriptEditor::ensure_select_current() { - - if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) { + if (tab_container->get_child_count() && tab_container->get_current_tab() >= 0) { Node *current = tab_container->get_child(tab_container->get_current_tab()); - ScriptEditorBase *se = current->cast_to<ScriptEditorBase>(); if (se) { @@ -1296,11 +1186,8 @@ void ScriptEditor::ensure_select_current() { if (!grab_focus_block && is_visible_in_tree()) se->ensure_focus(); - //edit_menu->show(); //search_menu->show(); - - } EditorHelp *eh = current->cast_to<EditorHelp>(); @@ -1309,18 +1196,14 @@ void ScriptEditor::ensure_select_current() { //edit_menu->hide(); //search_menu->hide(); //script_search_menu->show(); - } } _update_selected_editor_menu(); - - - } -void ScriptEditor::_find_scripts(Node* p_base, Node* p_current, Set<Ref<Script> > &used) { - if (p_current!=p_base && p_current->get_owner()!=p_base) +void ScriptEditor::_find_scripts(Node *p_base, Node *p_current, Set<Ref<Script> > &used) { + if (p_current != p_base && p_current->get_owner() != p_base) return; if (p_current->get_script_instance()) { @@ -1329,10 +1212,9 @@ void ScriptEditor::_find_scripts(Node* p_base, Node* p_current, Set<Ref<Script> used.insert(scr); } - for(int i=0;i<p_current->get_child_count();i++) { - _find_scripts(p_base,p_current->get_child(i),used); + for (int i = 0; i < p_current->get_child_count(); i++) { + _find_scripts(p_base, p_current->get_child(i), used); } - } struct _ScriptEditorItemData { @@ -1345,32 +1227,29 @@ struct _ScriptEditorItemData { bool used; int category; + bool operator<(const _ScriptEditorItemData &id) const { - bool operator<(const _ScriptEditorItemData& id) const { - - return category==id.category?sort_key<id.sort_key:category<id.category; + return category == id.category ? sort_key < id.sort_key : category < id.category; } - }; - void ScriptEditor::_update_script_colors() { bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_enabled"); bool highlight_current = EditorSettings::get_singleton()->get("text_editor/open_scripts/highlight_current_script"); int hist_size = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_history_size"); - Color hot_color=EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_hot_color"); - Color cold_color=EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_cold_color"); + Color hot_color = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_hot_color"); + Color cold_color = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_cold_color"); - for(int i=0;i<script_list->get_item_count();i++) { + for (int i = 0; i < script_list->get_item_count(); i++) { int c = script_list->get_item_metadata(i); Node *n = tab_container->get_child(c); if (!n) continue; - script_list->set_item_custom_bg_color(i,Color(0,0,0,0)); + script_list->set_item_custom_bg_color(i, Color(0, 0, 0, 0)); bool current = tab_container->get_current_tab() == c; if (current && highlight_current) { @@ -1382,15 +1261,15 @@ void ScriptEditor::_update_script_colors() { continue; } - int pass=n->get_meta("__editor_pass"); + int pass = n->get_meta("__editor_pass"); int h = edit_pass - pass; - if (h>hist_size) { + if (h > hist_size) { continue; } - int non_zero_hist_size = ( hist_size == 0 ) ? 1 : hist_size; - float v = Math::ease((edit_pass-pass)/float(non_zero_hist_size),0.4); + int non_zero_hist_size = (hist_size == 0) ? 1 : hist_size; + float v = Math::ease((edit_pass - pass) / float(non_zero_hist_size), 0.4); - script_list->set_item_custom_bg_color(i,hot_color.linear_interpolate(cold_color,v)); + script_list->set_item_custom_bg_color(i, hot_color.linear_interpolate(cold_color, v)); } } } @@ -1400,22 +1279,21 @@ void ScriptEditor::_update_script_names() { if (restoring_layout) return; - waiting_update_names=false; + waiting_update_names = false; Set<Ref<Script> > used; - Node* edited = EditorNode::get_singleton()->get_edited_scene(); + Node *edited = EditorNode::get_singleton()->get_edited_scene(); if (edited) { - _find_scripts(edited,edited,used); + _find_scripts(edited, edited, used); } script_list->clear(); bool split_script_help = EditorSettings::get_singleton()->get("text_editor/open_scripts/group_help_pages"); - ScriptSortBy sort_by = (ScriptSortBy) (int) EditorSettings::get_singleton()->get("text_editor/open_scripts/sort_scripts_by"); - ScriptListName display_as = (ScriptListName) (int) EditorSettings::get_singleton()->get("text_editor/open_scripts/list_script_names_as"); + ScriptSortBy sort_by = (ScriptSortBy)(int)EditorSettings::get_singleton()->get("text_editor/open_scripts/sort_scripts_by"); + ScriptListName display_as = (ScriptListName)(int)EditorSettings::get_singleton()->get("text_editor/open_scripts/list_script_names_as"); Vector<_ScriptEditorItemData> sedata; - for(int i=0;i<tab_container->get_child_count();i++) { - + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (se) { @@ -1425,39 +1303,38 @@ void ScriptEditor::_update_script_names() { String path = se->get_edited_script()->get_path(); _ScriptEditorItemData sd; - sd.icon=icon; - sd.name=name; - sd.tooltip=path; - sd.index=i; - sd.used=used.has(se->get_edited_script()); - sd.category=0; - + sd.icon = icon; + sd.name = name; + sd.tooltip = path; + sd.index = i; + sd.used = used.has(se->get_edited_script()); + sd.category = 0; + switch (sort_by) { case SORT_BY_NAME: { - sd.sort_key=name.to_lower(); + sd.sort_key = name.to_lower(); } break; case SORT_BY_PATH: { - sd.sort_key=path; + sd.sort_key = path; } break; } - + switch (display_as) { case DISPLAY_NAME: { - sd.name=name; + sd.name = name; } break; case DISPLAY_DIR_AND_NAME: { if (!path.get_base_dir().get_file().empty()) { - sd.name=path.get_base_dir().get_file() + "/" + name; + sd.name = path.get_base_dir().get_file() + "/" + name; } else { - sd.name=name; + sd.name = name; } } break; case DISPLAY_FULL_PATH: { - sd.name=path; + sd.name = path; } break; } - sedata.push_back(sd); } @@ -1465,62 +1342,50 @@ void ScriptEditor::_update_script_names() { if (eh) { String name = eh->get_class(); - Ref<Texture> icon = get_icon("Help","EditorIcons"); - String tooltip = name+" Class Reference"; + Ref<Texture> icon = get_icon("Help", "EditorIcons"); + String tooltip = name + " Class Reference"; _ScriptEditorItemData sd; - sd.icon=icon; - sd.name=name; - sd.sort_key=name; - sd.tooltip=tooltip; - sd.index=i; - sd.used=false; - sd.category=split_script_help?1:0; + sd.icon = icon; + sd.name = name; + sd.sort_key = name; + sd.tooltip = tooltip; + sd.index = i; + sd.used = false; + sd.category = split_script_help ? 1 : 0; sedata.push_back(sd); - } - } sedata.sort(); - for(int i=0;i<sedata.size();i++) { + for (int i = 0; i < sedata.size(); i++) { - script_list->add_item(sedata[i].name,sedata[i].icon); - int index = script_list->get_item_count()-1; - script_list->set_item_tooltip(index,sedata[i].tooltip); - script_list->set_item_metadata(index,sedata[i].index); + script_list->add_item(sedata[i].name, sedata[i].icon); + int index = script_list->get_item_count() - 1; + script_list->set_item_tooltip(index, sedata[i].tooltip); + script_list->set_item_metadata(index, sedata[i].index); if (sedata[i].used) { - script_list->set_item_custom_bg_color(index,Color(88/255.0,88/255.0,60/255.0)); + script_list->set_item_custom_bg_color(index, Color(88 / 255.0, 88 / 255.0, 60 / 255.0)); } - if (tab_container->get_current_tab()==sedata[i].index) { + if (tab_container->get_current_tab() == sedata[i].index) { script_list->select(index); script_name_label->set_text(sedata[i].name); script_icon->set_texture(sedata[i].icon); - } } _update_script_colors(); - - - - } - - -void ScriptEditor::edit(const Ref<Script>& p_script, bool p_grab_focus) { +void ScriptEditor::edit(const Ref<Script> &p_script, bool p_grab_focus) { if (p_script.is_null()) return; // refuse to open built-in if scene is not loaded - - - // see if already has it bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change"); @@ -1530,33 +1395,32 @@ void ScriptEditor::edit(const Ref<Script>& p_script, bool p_grab_focus) { String path = EditorSettings::get_singleton()->get("text_editor/external/exec_path"); String flags = EditorSettings::get_singleton()->get("text_editor/external/exec_flags"); List<String> args; - flags=flags.strip_edges(); - if (flags!=String()) { - Vector<String> flagss = flags.split(" ",false); - for(int i=0;i<flagss.size();i++) + flags = flags.strip_edges(); + if (flags != String()) { + Vector<String> flagss = flags.split(" ", false); + for (int i = 0; i < flagss.size(); i++) args.push_back(flagss[i]); } args.push_back(GlobalConfig::get_singleton()->globalize_path(p_script->get_path())); - Error err = OS::get_singleton()->execute(path,args,false); - if (err==OK) + Error err = OS::get_singleton()->execute(path, args, false); + if (err == OK) return; WARN_PRINT("Couldn't open external text editor, using internal"); } - - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) continue; - if (se->get_edited_script()==p_script) { + if (se->get_edited_script() == p_script) { if (open_dominant || !EditorNode::get_singleton()->is_changing_scene()) { - if (tab_container->get_current_tab()!=i) { + if (tab_container->get_current_tab() != i) { _go_to_tab(i); - script_list->select( script_list->find_metadata(i) ); + script_list->select(script_list->find_metadata(i)); } if (is_visible_in_tree()) se->ensure_focus(); @@ -1569,7 +1433,7 @@ void ScriptEditor::edit(const Ref<Script>& p_script, bool p_grab_focus) { ScriptEditorBase *se; - for(int i=script_editor_func_count-1;i>=0;i--) { + for (int i = script_editor_func_count - 1; i >= 0; i--) { se = script_editor_funcs[i](p_script); if (se) break; @@ -1578,50 +1442,39 @@ void ScriptEditor::edit(const Ref<Script>& p_script, bool p_grab_focus) { tab_container->add_child(se); se->set_edited_script(p_script); - se->set_tooltip_request_func("_get_debug_tooltip",this); + se->set_tooltip_request_func("_get_debug_tooltip", this); if (se->get_edit_menu()) { se->get_edit_menu()->hide(); menu_hb->add_child(se->get_edit_menu()); - menu_hb->move_child(se->get_edit_menu(),1); + menu_hb->move_child(se->get_edit_menu(), 1); } - if (p_grab_focus) { - _go_to_tab(tab_container->get_tab_count()-1); + _go_to_tab(tab_container->get_tab_count() - 1); } - - - - _update_script_names(); _save_layout(); - se->connect("name_changed",this,"_update_script_names"); - se->connect("request_help_search",this,"_help_search"); - se->connect("request_open_script_at_line",this,"_goto_script_line"); - se->connect("go_to_help",this,"_help_class_goto"); - se->connect("request_save_history",this,"_save_history"); - - - + se->connect("name_changed", this, "_update_script_names"); + se->connect("request_help_search", this, "_help_search"); + se->connect("request_open_script_at_line", this, "_goto_script_line"); + se->connect("go_to_help", this, "_help_class_goto"); + se->connect("request_save_history", this, "_save_history"); //test for modification, maybe the script was not edited but was loaded _test_script_times_on_disk(p_script); _update_modified_scripts_for_external_editor(p_script); - } void ScriptEditor::save_all_scripts() { - - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) continue; - if (!se->is_unsaved()) continue; @@ -1633,57 +1486,51 @@ void ScriptEditor::save_all_scripts() { if (script.is_valid()) se->apply_code(); - if (script->get_path()!="" && script->get_path().find("local://")==-1 &&script->get_path().find("::")==-1) { + if (script->get_path() != "" && script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) { //external script, save it editor->save_resource(script); //ResourceSaver::save(script->get_path(),script); - } - } _update_script_names(); - } void ScriptEditor::apply_scripts() const { - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) continue; se->apply_code(); } - } void ScriptEditor::_editor_play() { debugger->start(); debug_menu->get_popup()->grab_focus(); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), true ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), false ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true ); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), false); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true); - //debugger_gui->start_listening(Globals::get_singleton()->get("debug/debug_port")); + //debugger_gui->start_listening(Globals::get_singleton()->get("debug/debug_port")); } void ScriptEditor::_editor_pause() { - - } void ScriptEditor::_editor_stop() { debugger->stop(); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), true ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true ); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true); - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) { @@ -1695,34 +1542,31 @@ void ScriptEditor::_editor_stop() { } } - -void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const PoolStringArray& p_args) { +void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const PoolStringArray &p_args) { //print_line("add callback! hohoho"); kinda sad to remove this ERR_FAIL_COND(!p_obj); Ref<Script> script = p_obj->get_script(); - ERR_FAIL_COND( !script.is_valid() ); + ERR_FAIL_COND(!script.is_valid()); editor->push_item(script.ptr()); - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) continue; - if (se->get_edited_script()!=script) + if (se->get_edited_script() != script) continue; - se->add_callback(p_function,p_args); + se->add_callback(p_function, p_args); _go_to_tab(i); - script_list->select( script_list->find_metadata(i) ); + script_list->select(script_list->find_metadata(i)); break; - } - } void ScriptEditor::_save_layout() { @@ -1738,7 +1582,7 @@ void ScriptEditor::_editor_settings_changed() { trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/files/trim_trailing_whitespace_on_save"); float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs"); - if (autosave_time>0) { + if (autosave_time > 0) { autosave_timer->set_wait_time(autosave_time); autosave_timer->start(); } else { @@ -1752,7 +1596,7 @@ void ScriptEditor::_editor_settings_changed() { EditorSettings::get_singleton()->load_text_editor_theme(); } - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (!se) @@ -1763,8 +1607,7 @@ void ScriptEditor::_editor_settings_changed() { _update_script_colors(); _update_script_names(); - ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save",true)); - + ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save", true)); } void ScriptEditor::_autosave_scripts() { @@ -1777,7 +1620,7 @@ void ScriptEditor::_tree_changed() { if (waiting_update_names) return; - waiting_update_names=true; + waiting_update_names = true; call_deferred("_update_script_names"); } @@ -1786,7 +1629,7 @@ void ScriptEditor::_script_split_dragged(float) { _save_layout(); } -void ScriptEditor::_unhandled_input(const InputEvent& p_event) { +void ScriptEditor::_unhandled_input(const InputEvent &p_event) { if (p_event.key.pressed || !is_visible_in_tree()) return; if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) { int next_tab = script_list->get_current() + 1; @@ -1804,21 +1647,21 @@ void ScriptEditor::_unhandled_input(const InputEvent& p_event) { void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { - if (!bool(EDITOR_DEF("text_editor/files/restore_scripts_on_load",true))) { + if (!bool(EDITOR_DEF("text_editor/files/restore_scripts_on_load", true))) { return; } - if (!p_layout->has_section_key("ScriptEditor","open_scripts") && !p_layout->has_section_key("ScriptEditor","open_help")) + if (!p_layout->has_section_key("ScriptEditor", "open_scripts") && !p_layout->has_section_key("ScriptEditor", "open_help")) return; - Array scripts = p_layout->get_value("ScriptEditor","open_scripts"); + Array scripts = p_layout->get_value("ScriptEditor", "open_scripts"); Array helps; - if (p_layout->has_section_key("ScriptEditor","open_help")) - helps=p_layout->get_value("ScriptEditor","open_help"); + if (p_layout->has_section_key("ScriptEditor", "open_help")) + helps = p_layout->get_value("ScriptEditor", "open_help"); - restoring_layout=true; + restoring_layout = true; - for(int i=0;i<scripts.size();i++) { + for (int i = 0; i < scripts.size(); i++) { String path = scripts[i]; if (!FileAccess::exists(path)) @@ -1829,22 +1672,21 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { } } - for(int i=0;i<helps.size();i++) { + for (int i = 0; i < helps.size(); i++) { String path = helps[i]; _help_class_open(path); } - for(int i=0;i<tab_container->get_child_count();i++) { - tab_container->get_child(i)->set_meta("__editor_pass",Variant()); + for (int i = 0; i < tab_container->get_child_count(); i++) { + tab_container->get_child(i)->set_meta("__editor_pass", Variant()); } - - if (p_layout->has_section_key("ScriptEditor","split_offset")) { - script_split->set_split_offset(p_layout->get_value("ScriptEditor","split_offset")); + if (p_layout->has_section_key("ScriptEditor", "split_offset")) { + script_split->set_split_offset(p_layout->get_value("ScriptEditor", "split_offset")); } - restoring_layout=false; + restoring_layout = false; _update_script_names(); } @@ -1854,7 +1696,7 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { Array scripts; Array helps; - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); if (se) { @@ -1872,26 +1714,23 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { helps.push_back(eh->get_class()); } - - } - p_layout->set_value("ScriptEditor","open_scripts",scripts); - p_layout->set_value("ScriptEditor","open_help",helps); - p_layout->set_value("ScriptEditor","split_offset",script_split->get_split_offset()); + p_layout->set_value("ScriptEditor", "open_scripts", scripts); + p_layout->set_value("ScriptEditor", "open_help", helps); + p_layout->set_value("ScriptEditor", "split_offset", script_split->get_split_offset()); } +void ScriptEditor::_help_class_open(const String &p_class) { -void ScriptEditor::_help_class_open(const String& p_class) { - - if (p_class=="") + if (p_class == "") return; - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>(); - if (eh && eh->get_class()==p_class) { + if (eh && eh->get_class() == p_class) { _go_to_tab(i); _update_script_names(); @@ -1899,27 +1738,26 @@ void ScriptEditor::_help_class_open(const String& p_class) { } } - EditorHelp * eh = memnew( EditorHelp ); - + EditorHelp *eh = memnew(EditorHelp); eh->set_name(p_class); tab_container->add_child(eh); - _go_to_tab(tab_container->get_tab_count()-1); - eh->go_to_class(p_class,0); - eh->connect("go_to_help",this,"_help_class_goto"); + _go_to_tab(tab_container->get_tab_count() - 1); + eh->go_to_class(p_class, 0); + eh->connect("go_to_help", this, "_help_class_goto"); _update_script_names(); _save_layout(); } -void ScriptEditor::_help_class_goto(const String& p_desc) { +void ScriptEditor::_help_class_goto(const String &p_desc) { - String cname=p_desc.get_slice(":",1); + String cname = p_desc.get_slice(":", 1); - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>(); - if (eh && eh->get_class()==cname) { + if (eh && eh->get_class() == cname) { _go_to_tab(i); eh->go_to_help(p_desc); @@ -1928,20 +1766,20 @@ void ScriptEditor::_help_class_goto(const String& p_desc) { } } - EditorHelp * eh = memnew( EditorHelp ); + EditorHelp *eh = memnew(EditorHelp); eh->set_name(cname); tab_container->add_child(eh); - _go_to_tab(tab_container->get_tab_count()-1); + _go_to_tab(tab_container->get_tab_count() - 1); eh->go_to_help(p_desc); - eh->connect("go_to_help",this,"_help_class_goto"); + eh->connect("go_to_help", this, "_help_class_goto"); _update_script_names(); _save_layout(); } void ScriptEditor::_update_selected_editor_menu() { - for(int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { bool current = tab_container->get_current_tab() == i; @@ -1953,10 +1791,9 @@ void ScriptEditor::_update_selected_editor_menu() { else se->get_edit_menu()->hide(); } - } - EditorHelp *eh=tab_container->get_current_tab_control()->cast_to<EditorHelp>(); + EditorHelp *eh = tab_container->get_current_tab_control()->cast_to<EditorHelp>(); if (eh) { script_search_menu->show(); } else { @@ -1970,14 +1807,14 @@ void ScriptEditor::_update_history_pos(int p_new_pos) { if (n->cast_to<ScriptEditorBase>()) { - history[history_pos].state=n->cast_to<ScriptEditorBase>()->get_edit_state(); + history[history_pos].state = n->cast_to<ScriptEditorBase>()->get_edit_state(); } if (n->cast_to<EditorHelp>()) { - history[history_pos].state=n->cast_to<EditorHelp>()->get_scroll(); + history[history_pos].state = n->cast_to<EditorHelp>()->get_scroll(); } - history_pos=p_new_pos; + history_pos = p_new_pos; tab_container->set_current_tab(history[history_pos].control->get_index()); n = history[history_pos].control; @@ -1994,28 +1831,26 @@ void ScriptEditor::_update_history_pos(int p_new_pos) { n->cast_to<EditorHelp>()->set_focused(); } - n->set_meta("__editor_pass",++edit_pass); + n->set_meta("__editor_pass", ++edit_pass); _update_script_names(); _update_history_arrows(); _update_selected_editor_menu(); - } void ScriptEditor::_history_forward() { - if (history_pos<history.size()-1) { - _update_history_pos(history_pos+1); + if (history_pos < history.size() - 1) { + _update_history_pos(history_pos + 1); } } -void ScriptEditor::_history_back(){ +void ScriptEditor::_history_back() { - if (history_pos>0) { - _update_history_pos(history_pos-1); + if (history_pos > 0) { + _update_history_pos(history_pos - 1); } - } -void ScriptEditor::set_scene_root_script( Ref<Script> p_script ) { +void ScriptEditor::set_scene_root_script(Ref<Script> p_script) { bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change"); @@ -2027,13 +1862,12 @@ void ScriptEditor::set_scene_root_script( Ref<Script> p_script ) { } } -bool ScriptEditor::script_go_to_method(Ref<Script> p_script, const String& p_method) { +bool ScriptEditor::script_go_to_method(Ref<Script> p_script, const String &p_method) { - - for (int i=0;i<tab_container->get_child_count();i++) { + for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *current = tab_container->get_child(i)->cast_to<ScriptEditorBase>(); - if (current && current->get_edited_script()==p_script) { + if (current && current->get_edited_script() == p_script) { if (current->goto_method(p_method)) { edit(p_script); return true; @@ -2046,123 +1880,118 @@ bool ScriptEditor::script_go_to_method(Ref<Script> p_script, const String& p_met void ScriptEditor::set_live_auto_reload_running_scripts(bool p_enabled) { - auto_reload_running_scripts=p_enabled; + auto_reload_running_scripts = p_enabled; } void ScriptEditor::_help_search(String p_text) { help_search_dialog->popup(p_text); } -void ScriptEditor::_open_script_request(const String& p_path) { +void ScriptEditor::_open_script_request(const String &p_path) { Ref<Script> script = ResourceLoader::load(p_path); if (script.is_valid()) { - script_editor->edit(script,false); + script_editor->edit(script, false); } } -int ScriptEditor::script_editor_func_count=0; +int ScriptEditor::script_editor_func_count = 0; CreateScriptEditorFunc ScriptEditor::script_editor_funcs[ScriptEditor::SCRIPT_EDITOR_FUNC_MAX]; void ScriptEditor::register_create_script_editor_function(CreateScriptEditorFunc p_func) { - ERR_FAIL_COND(script_editor_func_count==SCRIPT_EDITOR_FUNC_MAX); - script_editor_funcs[script_editor_func_count++]=p_func; + ERR_FAIL_COND(script_editor_func_count == SCRIPT_EDITOR_FUNC_MAX); + script_editor_funcs[script_editor_func_count++] = p_func; } void ScriptEditor::_bind_methods() { - ClassDB::bind_method("_file_dialog_action",&ScriptEditor::_file_dialog_action); - ClassDB::bind_method("_tab_changed",&ScriptEditor::_tab_changed); - ClassDB::bind_method("_menu_option",&ScriptEditor::_menu_option); - ClassDB::bind_method("_close_current_tab",&ScriptEditor::_close_current_tab); + ClassDB::bind_method("_file_dialog_action", &ScriptEditor::_file_dialog_action); + ClassDB::bind_method("_tab_changed", &ScriptEditor::_tab_changed); + ClassDB::bind_method("_menu_option", &ScriptEditor::_menu_option); + ClassDB::bind_method("_close_current_tab", &ScriptEditor::_close_current_tab); ClassDB::bind_method("_close_discard_current_tab", &ScriptEditor::_close_discard_current_tab); ClassDB::bind_method("_close_docs_tab", &ScriptEditor::_close_docs_tab); ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs); - ClassDB::bind_method("_editor_play",&ScriptEditor::_editor_play); - ClassDB::bind_method("_editor_pause",&ScriptEditor::_editor_pause); - ClassDB::bind_method("_editor_stop",&ScriptEditor::_editor_stop); - ClassDB::bind_method("_add_callback",&ScriptEditor::_add_callback); - ClassDB::bind_method("_reload_scripts",&ScriptEditor::_reload_scripts); - ClassDB::bind_method("_resave_scripts",&ScriptEditor::_resave_scripts); - ClassDB::bind_method("_res_saved_callback",&ScriptEditor::_res_saved_callback); - ClassDB::bind_method("_goto_script_line",&ScriptEditor::_goto_script_line); - ClassDB::bind_method("_goto_script_line2",&ScriptEditor::_goto_script_line2); - ClassDB::bind_method("_help_search",&ScriptEditor::_help_search); - ClassDB::bind_method("_save_history",&ScriptEditor::_save_history); - - - - ClassDB::bind_method("_breaked",&ScriptEditor::_breaked); - ClassDB::bind_method("_show_debugger",&ScriptEditor::_show_debugger); - ClassDB::bind_method("_get_debug_tooltip",&ScriptEditor::_get_debug_tooltip); - ClassDB::bind_method("_autosave_scripts",&ScriptEditor::_autosave_scripts); - ClassDB::bind_method("_editor_settings_changed",&ScriptEditor::_editor_settings_changed); - ClassDB::bind_method("_update_script_names",&ScriptEditor::_update_script_names); - ClassDB::bind_method("_tree_changed",&ScriptEditor::_tree_changed); - ClassDB::bind_method("_script_selected",&ScriptEditor::_script_selected); - ClassDB::bind_method("_script_created",&ScriptEditor::_script_created); - ClassDB::bind_method("_script_split_dragged",&ScriptEditor::_script_split_dragged); - ClassDB::bind_method("_help_class_open",&ScriptEditor::_help_class_open); - ClassDB::bind_method("_help_class_goto",&ScriptEditor::_help_class_goto); - ClassDB::bind_method("_request_help",&ScriptEditor::_help_class_open); - ClassDB::bind_method("_history_forward",&ScriptEditor::_history_forward); - ClassDB::bind_method("_history_back",&ScriptEditor::_history_back); - ClassDB::bind_method("_live_auto_reload_running_scripts",&ScriptEditor::_live_auto_reload_running_scripts); - ClassDB::bind_method("_unhandled_input",&ScriptEditor::_unhandled_input); - + ClassDB::bind_method("_editor_play", &ScriptEditor::_editor_play); + ClassDB::bind_method("_editor_pause", &ScriptEditor::_editor_pause); + ClassDB::bind_method("_editor_stop", &ScriptEditor::_editor_stop); + ClassDB::bind_method("_add_callback", &ScriptEditor::_add_callback); + ClassDB::bind_method("_reload_scripts", &ScriptEditor::_reload_scripts); + ClassDB::bind_method("_resave_scripts", &ScriptEditor::_resave_scripts); + ClassDB::bind_method("_res_saved_callback", &ScriptEditor::_res_saved_callback); + ClassDB::bind_method("_goto_script_line", &ScriptEditor::_goto_script_line); + ClassDB::bind_method("_goto_script_line2", &ScriptEditor::_goto_script_line2); + ClassDB::bind_method("_help_search", &ScriptEditor::_help_search); + ClassDB::bind_method("_save_history", &ScriptEditor::_save_history); + + ClassDB::bind_method("_breaked", &ScriptEditor::_breaked); + ClassDB::bind_method("_show_debugger", &ScriptEditor::_show_debugger); + ClassDB::bind_method("_get_debug_tooltip", &ScriptEditor::_get_debug_tooltip); + ClassDB::bind_method("_autosave_scripts", &ScriptEditor::_autosave_scripts); + ClassDB::bind_method("_editor_settings_changed", &ScriptEditor::_editor_settings_changed); + ClassDB::bind_method("_update_script_names", &ScriptEditor::_update_script_names); + ClassDB::bind_method("_tree_changed", &ScriptEditor::_tree_changed); + ClassDB::bind_method("_script_selected", &ScriptEditor::_script_selected); + ClassDB::bind_method("_script_created", &ScriptEditor::_script_created); + ClassDB::bind_method("_script_split_dragged", &ScriptEditor::_script_split_dragged); + ClassDB::bind_method("_help_class_open", &ScriptEditor::_help_class_open); + ClassDB::bind_method("_help_class_goto", &ScriptEditor::_help_class_goto); + ClassDB::bind_method("_request_help", &ScriptEditor::_help_class_open); + ClassDB::bind_method("_history_forward", &ScriptEditor::_history_forward); + ClassDB::bind_method("_history_back", &ScriptEditor::_history_back); + ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts); + ClassDB::bind_method("_unhandled_input", &ScriptEditor::_unhandled_input); } ScriptEditor::ScriptEditor(EditorNode *p_editor) { current_theme = ""; - completion_cache = memnew( EditorScriptCodeCompletionCache ); - restoring_layout=false; - waiting_update_names=false; - pending_auto_reload=false; - auto_reload_running_scripts=false; - editor=p_editor; + completion_cache = memnew(EditorScriptCodeCompletionCache); + restoring_layout = false; + waiting_update_names = false; + pending_auto_reload = false; + auto_reload_running_scripts = false; + editor = p_editor; - menu_hb = memnew( HBoxContainer ); + menu_hb = memnew(HBoxContainer); add_child(menu_hb); - - script_split = memnew( HSplitContainer ); + script_split = memnew(HSplitContainer); add_child(script_split); script_split->set_v_size_flags(SIZE_EXPAND_FILL); - script_list = memnew( ItemList ); + script_list = memnew(ItemList); script_split->add_child(script_list); - script_list->set_custom_minimum_size(Size2(0,0)); + script_list->set_custom_minimum_size(Size2(0, 0)); script_split->set_split_offset(140); - tab_container = memnew( TabContainer ); + tab_container = memnew(TabContainer); tab_container->set_tabs_visible(false); script_split->add_child(tab_container); - tab_container->set_h_size_flags(SIZE_EXPAND_FILL); ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_GREATER); ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_LESS); set_process_unhandled_input(true); - file_menu = memnew( MenuButton ); + file_menu = memnew(MenuButton); menu_hb->add_child(file_menu); file_menu->set_text(TTR("File")); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new", TTR("New")), FILE_NEW); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/open", TTR("Open")), FILE_OPEN); file_menu->get_popup()->add_separator(); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save", TTR("Save"), KEY_MASK_ALT|KEY_MASK_CMD|KEY_S), FILE_SAVE); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save", TTR("Save"), KEY_MASK_ALT | KEY_MASK_CMD | KEY_S), FILE_SAVE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_as", TTR("Save As..")), FILE_SAVE_AS); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_all", TTR("Save All"), KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_MASK_ALT|KEY_S), FILE_SAVE_ALL); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_all", TTR("Save All"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_S), FILE_SAVE_ALL); file_menu->get_popup()->add_separator(); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_script_soft", TTR("Soft Reload Script"), KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_R), FILE_TOOL_RELOAD_SOFT); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_script_soft", TTR("Soft Reload Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_R), FILE_TOOL_RELOAD_SOFT); file_menu->get_popup()->add_separator(); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Prev"), KEY_MASK_ALT|KEY_LEFT), WINDOW_PREV); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_next", TTR("History Next"), KEY_MASK_ALT|KEY_RIGHT), WINDOW_NEXT); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Prev"), KEY_MASK_ALT | KEY_LEFT), WINDOW_PREV); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_next", TTR("History Next"), KEY_MASK_ALT | KEY_RIGHT), WINDOW_NEXT); file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme")), FILE_IMPORT_THEME); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_theme", TTR("Reload Theme")), FILE_RELOAD_THEME); @@ -2172,20 +2001,17 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL); - file_menu->get_popup()->connect("id_pressed", this,"_menu_option"); - + file_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - - script_search_menu = memnew( MenuButton ); + script_search_menu = memnew(MenuButton); menu_hb->add_child(script_search_menu); script_search_menu->set_text(TTR("Search")); - script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD|KEY_F), HELP_SEARCH_FIND); + script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F), HELP_SEARCH_FIND); script_search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), HELP_SEARCH_FIND_NEXT); - script_search_menu->get_popup()->connect("id_pressed", this,"_menu_option"); + script_search_menu->get_popup()->connect("id_pressed", this, "_menu_option"); script_search_menu->hide(); - - debug_menu = memnew( MenuButton ); + debug_menu = memnew(MenuButton); menu_hb->add_child(debug_menu); debug_menu->set_text(TTR("Debug")); debug_menu->get_popup()->add_separator(); @@ -2197,13 +2023,12 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { debug_menu->get_popup()->add_separator(); //debug_menu->get_popup()->add_check_item("Show Debugger",DEBUG_SHOW); debug_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("debugger/keep_debugger_open", TTR("Keep Debugger Open")), DEBUG_SHOW_KEEP_OPEN); - debug_menu->get_popup()->connect("id_pressed", this,"_menu_option"); - - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_STEP), true ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true ); - debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true ); + debug_menu->get_popup()->connect("id_pressed", this, "_menu_option"); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_STEP), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true); + debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true); #if 0 window_menu = memnew( MenuButton ); @@ -2218,13 +2043,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { #endif - menu_hb->add_spacer(); - - script_icon = memnew( TextureRect ); + script_icon = memnew(TextureRect); menu_hb->add_child(script_icon); - script_name_label = memnew( Label ); + script_name_label = memnew(Label); menu_hb->add_child(script_name_label); script_icon->hide(); @@ -2232,46 +2055,44 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { menu_hb->add_spacer(); - site_search = memnew( ToolButton ); + site_search = memnew(ToolButton); site_search->set_text(TTR("Tutorials")); - site_search->connect("pressed",this,"_menu_option",varray(SEARCH_WEBSITE)); + site_search->connect("pressed", this, "_menu_option", varray(SEARCH_WEBSITE)); menu_hb->add_child(site_search); site_search->set_tooltip(TTR("Open https://godotengine.org at tutorials section.")); - class_search = memnew( ToolButton ); + class_search = memnew(ToolButton); class_search->set_text(TTR("Classes")); - class_search->connect("pressed",this,"_menu_option",varray(SEARCH_CLASSES)); + class_search->connect("pressed", this, "_menu_option", varray(SEARCH_CLASSES)); menu_hb->add_child(class_search); class_search->set_tooltip(TTR("Search the class hierarchy.")); - help_search = memnew( ToolButton ); + help_search = memnew(ToolButton); help_search->set_text(TTR("Search Help")); - help_search->connect("pressed",this,"_menu_option",varray(SEARCH_HELP)); + help_search->connect("pressed", this, "_menu_option", varray(SEARCH_HELP)); menu_hb->add_child(help_search); help_search->set_tooltip(TTR("Search the reference documentation.")); - menu_hb->add_child( memnew( VSeparator) ); + menu_hb->add_child(memnew(VSeparator)); - script_back = memnew( ToolButton ); - script_back->connect("pressed",this,"_history_back"); + script_back = memnew(ToolButton); + script_back->connect("pressed", this, "_history_back"); menu_hb->add_child(script_back); script_back->set_disabled(true); script_back->set_tooltip(TTR("Go to previous edited document.")); - script_forward = memnew( ToolButton ); - script_forward->connect("pressed",this,"_history_forward"); + script_forward = memnew(ToolButton); + script_forward->connect("pressed", this, "_history_forward"); menu_hb->add_child(script_forward); script_forward->set_disabled(true); script_forward->set_tooltip(TTR("Go to next edited document.")); + tab_container->connect("tab_changed", this, "_tab_changed"); - - tab_container->connect("tab_changed", this,"_tab_changed"); - - erase_tab_confirm = memnew( ConfirmationDialog ); + erase_tab_confirm = memnew(ConfirmationDialog); erase_tab_confirm->get_ok()->set_text(TTR("Save")); erase_tab_confirm->add_button(TTR("Discard"), OS::get_singleton()->get_swap_ok_cancel(), "discard"); - erase_tab_confirm->connect("confirmed", this,"_close_current_tab"); + erase_tab_confirm->connect("confirmed", this, "_close_current_tab"); erase_tab_confirm->connect("custom_action", this, "_close_discard_current_tab"); add_child(erase_tab_confirm); @@ -2281,74 +2102,67 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { script_create_dialog->connect("script_created", this, "_script_created"); file_dialog_option = -1; - file_dialog = memnew( EditorFileDialog ); + file_dialog = memnew(EditorFileDialog); add_child(file_dialog); - file_dialog->connect("file_selected", this,"_file_dialog_action"); - + file_dialog->connect("file_selected", this, "_file_dialog_action"); - debugger = memnew( ScriptEditorDebugger(editor) ); - debugger->connect("goto_script_line",this,"_goto_script_line"); - debugger->connect("show_debugger",this,"_show_debugger"); + debugger = memnew(ScriptEditorDebugger(editor)); + debugger->connect("goto_script_line", this, "_goto_script_line"); + debugger->connect("show_debugger", this, "_show_debugger"); - disk_changed = memnew( ConfirmationDialog ); + disk_changed = memnew(ConfirmationDialog); { - VBoxContainer *vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew(VBoxContainer); disk_changed->add_child(vbc); //disk_changed->set_child_rect(vbc); - Label *dl = memnew( Label ); + Label *dl = memnew(Label); dl->set_text(TTR("The following files are newer on disk.\nWhat action should be taken?:")); vbc->add_child(dl); - disk_changed_list = memnew( Tree ); + disk_changed_list = memnew(Tree); vbc->add_child(disk_changed_list); disk_changed_list->set_v_size_flags(SIZE_EXPAND_FILL); - disk_changed->connect("confirmed",this,"_reload_scripts"); + disk_changed->connect("confirmed", this, "_reload_scripts"); disk_changed->get_ok()->set_text(TTR("Reload")); - disk_changed->add_button(TTR("Resave"),!OS::get_singleton()->get_swap_ok_cancel(),"resave"); - disk_changed->connect("custom_action",this,"_resave_scripts"); - - + disk_changed->add_button(TTR("Resave"), !OS::get_singleton()->get_swap_ok_cancel(), "resave"); + disk_changed->connect("custom_action", this, "_resave_scripts"); } add_child(disk_changed); - script_editor=this; + script_editor = this; - - Button *db = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Debugger"),debugger); + Button *db = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Debugger"), debugger); debugger->set_tool_button(db); + debugger->connect("breaked", this, "_breaked"); - debugger->connect("breaked",this,"_breaked"); - - autosave_timer = memnew( Timer ); + autosave_timer = memnew(Timer); autosave_timer->set_one_shot(false); add_child(autosave_timer); - grab_focus_block=false; + grab_focus_block = false; - help_search_dialog = memnew( EditorHelpSearch ); + help_search_dialog = memnew(EditorHelpSearch); add_child(help_search_dialog); - help_search_dialog->connect("go_to_help",this,"_help_class_goto"); - + help_search_dialog->connect("go_to_help", this, "_help_class_goto"); - help_index = memnew( EditorHelpIndex ); + help_index = memnew(EditorHelpIndex); add_child(help_index); - help_index->connect("open_class",this,"_help_class_open"); + help_index->connect("open_class", this, "_help_class_open"); - history_pos=-1; + history_pos = -1; //debugger_gui->hide(); - edit_pass=0; + edit_pass = 0; trim_trailing_whitespace_on_save = false; - ScriptServer::edit_request_func=_open_script_request; + ScriptServer::edit_request_func = _open_script_request; } - ScriptEditor::~ScriptEditor() { memdelete(completion_cache); @@ -2360,7 +2174,6 @@ void ScriptEditorPlugin::edit(Object *p_object) { return; script_editor->edit(p_object->cast_to<Script>()); - } bool ScriptEditorPlugin::handles(Object *p_object) const { @@ -2389,7 +2202,6 @@ void ScriptEditorPlugin::make_visible(bool p_visible) { script_editor->hide(); script_editor->set_process(false); } - } void ScriptEditorPlugin::selected_notify() { @@ -2402,7 +2214,7 @@ Dictionary ScriptEditorPlugin::get_state() const { return script_editor->get_state(); } -void ScriptEditorPlugin::set_state(const Dictionary& p_state) { +void ScriptEditorPlugin::set_state(const Dictionary &p_state) { script_editor->set_state(p_state); } @@ -2422,12 +2234,9 @@ void ScriptEditorPlugin::apply_changes() { } void ScriptEditorPlugin::restore_global_state() { - - } void ScriptEditorPlugin::save_global_state() { - } void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { @@ -2435,15 +2244,13 @@ void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { script_editor->set_window_layout(p_layout); } -void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout){ +void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { script_editor->get_window_layout(p_layout); } - void ScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) { - return script_editor->get_breakpoints(p_breakpoints); } @@ -2452,40 +2259,34 @@ void ScriptEditorPlugin::edited_scene_changed() { script_editor->edited_scene_changed(); } - - ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { - editor=p_node; - script_editor = memnew( ScriptEditor(p_node) ); + editor = p_node; + script_editor = memnew(ScriptEditor(p_node)); editor->get_viewport()->add_child(script_editor); script_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); script_editor->hide(); - EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change",true); - ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save",true)); - EDITOR_DEF("text_editor/files/open_dominant_script_on_scene_change",true); - EDITOR_DEF("text_editor/external/use_external_editor",false); - EDITOR_DEF("text_editor/external/exec_path",""); - EDITOR_DEF("text_editor/open_scripts/script_temperature_enabled",true); + EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", true); + ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save", true)); + EDITOR_DEF("text_editor/files/open_dominant_script_on_scene_change", true); + EDITOR_DEF("text_editor/external/use_external_editor", false); + EDITOR_DEF("text_editor/external/exec_path", ""); + EDITOR_DEF("text_editor/open_scripts/script_temperature_enabled", true); EDITOR_DEF("text_editor/open_scripts/highlight_current_script", true); - EDITOR_DEF("text_editor/open_scripts/script_temperature_history_size",15); - EDITOR_DEF("text_editor/open_scripts/script_temperature_hot_color",Color(1,0,0,0.3)); - EDITOR_DEF("text_editor/open_scripts/script_temperature_cold_color",Color(0,0,1,0.3)); - EDITOR_DEF("text_editor/open_scripts/current_script_background_color",Color(0.81,0.81,0.14,0.63)); - EDITOR_DEF("text_editor/open_scripts/group_help_pages",true); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,"text_editor/open_scripts/sort_scripts_by",PROPERTY_HINT_ENUM,"Name,Path")); - EDITOR_DEF("text_editor/open_scripts/sort_scripts_by",0); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,"text_editor/open_scripts/list_script_names_as",PROPERTY_HINT_ENUM,"Name,Parent Directory And Name,Full Path")); - EDITOR_DEF("text_editor/open_scripts/list_script_names_as",0); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"text_editor/external/exec_path",PROPERTY_HINT_GLOBAL_FILE)); - EDITOR_DEF("text_editor/external/exec_flags",""); - - -} - - -ScriptEditorPlugin::~ScriptEditorPlugin() -{ + EDITOR_DEF("text_editor/open_scripts/script_temperature_history_size", 15); + EDITOR_DEF("text_editor/open_scripts/script_temperature_hot_color", Color(1, 0, 0, 0.3)); + EDITOR_DEF("text_editor/open_scripts/script_temperature_cold_color", Color(0, 0, 1, 0.3)); + EDITOR_DEF("text_editor/open_scripts/current_script_background_color", Color(0.81, 0.81, 0.14, 0.63)); + EDITOR_DEF("text_editor/open_scripts/group_help_pages", true); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/sort_scripts_by", PROPERTY_HINT_ENUM, "Name,Path")); + EDITOR_DEF("text_editor/open_scripts/sort_scripts_by", 0); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/list_script_names_as", PROPERTY_HINT_ENUM, "Name,Parent Directory And Name,Full Path")); + EDITOR_DEF("text_editor/open_scripts/list_script_names_as", 0); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_path", PROPERTY_HINT_GLOBAL_FILE)); + EDITOR_DEF("text_editor/external/exec_flags", ""); +} + +ScriptEditorPlugin::~ScriptEditorPlugin() { } diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index bf5316363c..a73e14423d 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -29,23 +29,23 @@ #ifndef SCRIPT_EDITOR_PLUGIN_H #define SCRIPT_EDITOR_PLUGIN_H +#include "editor/code_editor.h" +#include "editor/editor_help.h" #include "editor/editor_plugin.h" #include "editor/script_create_dialog.h" +#include "scene/gui/item_list.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/split_container.h" #include "scene/gui/tab_container.h" #include "scene/gui/text_edit.h" -#include "scene/gui/menu_button.h" #include "scene/gui/tool_button.h" #include "scene/gui/tree.h" #include "scene/main/timer.h" #include "script_language.h" -#include "editor/code_editor.h" -#include "scene/gui/split_container.h" -#include "scene/gui/item_list.h" -#include "editor/editor_help.h" class ScriptEditorQuickOpen : public ConfirmationDialog { - GDCLASS(ScriptEditorQuickOpen,ConfirmationDialog ) + GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog) LineEdit *search_box; Tree *search_options; @@ -53,73 +53,66 @@ class ScriptEditorQuickOpen : public ConfirmationDialog { void _update_search(); - void _sbox_input(const InputEvent& p_ie); + void _sbox_input(const InputEvent &p_ie); Vector<String> functions; - void _confirmed(); - void _text_changed(const String& p_newtext); + void _text_changed(const String &p_newtext); protected: - void _notification(int p_what); static void _bind_methods(); -public: - void popup(const Vector<String>& p_base,bool p_dontclear=false); +public: + void popup(const Vector<String> &p_base, bool p_dontclear = false); ScriptEditorQuickOpen(); }; - class ScriptEditorDebugger; - - class ScriptEditorBase : public Control { - GDCLASS( ScriptEditorBase, Control ); + GDCLASS(ScriptEditorBase, Control); + protected: static void _bind_methods(); -public: - virtual void apply_code()=0; - virtual Ref<Script> get_edited_script() const=0; - virtual Vector<String> get_functions()=0; - virtual void set_edited_script(const Ref<Script>& p_script)=0; - virtual void reload_text()=0; - virtual String get_name()=0; - virtual Ref<Texture> get_icon()=0; - virtual bool is_unsaved()=0; - virtual Variant get_edit_state()=0; - virtual void set_edit_state(const Variant& p_state)=0; - virtual void goto_line(int p_line,bool p_with_error=false)=0; - virtual void trim_trailing_whitespace()=0; - virtual void ensure_focus()=0; - virtual void tag_saved_version()=0; - virtual void reload(bool p_soft)=0; - virtual void get_breakpoints(List<int> *p_breakpoints)=0; - virtual bool goto_method(const String& p_method)=0; - virtual void add_callback(const String& p_function,PoolStringArray p_args)=0; - virtual void update_settings()=0; - virtual void set_debugger_active(bool p_active)=0; +public: + virtual void apply_code() = 0; + virtual Ref<Script> get_edited_script() const = 0; + virtual Vector<String> get_functions() = 0; + virtual void set_edited_script(const Ref<Script> &p_script) = 0; + virtual void reload_text() = 0; + virtual String get_name() = 0; + virtual Ref<Texture> get_icon() = 0; + virtual bool is_unsaved() = 0; + virtual Variant get_edit_state() = 0; + virtual void set_edit_state(const Variant &p_state) = 0; + virtual void goto_line(int p_line, bool p_with_error = false) = 0; + virtual void trim_trailing_whitespace() = 0; + virtual void ensure_focus() = 0; + virtual void tag_saved_version() = 0; + virtual void reload(bool p_soft) = 0; + virtual void get_breakpoints(List<int> *p_breakpoints) = 0; + virtual bool goto_method(const String &p_method) = 0; + virtual void add_callback(const String &p_function, PoolStringArray p_args) = 0; + virtual void update_settings() = 0; + virtual void set_debugger_active(bool p_active) = 0; virtual bool can_lose_focus_on_node_selection() { return true; } - virtual void set_tooltip_request_func(String p_method,Object* p_obj)=0; - virtual Control *get_edit_menu()=0; + virtual void set_tooltip_request_func(String p_method, Object *p_obj) = 0; + virtual Control *get_edit_menu() = 0; ScriptEditorBase() {} }; - -typedef ScriptEditorBase* (*CreateScriptEditorFunc)(const Ref<Script>& p_script); - +typedef ScriptEditorBase *(*CreateScriptEditorFunc)(const Ref<Script> &p_script); class EditorScriptCodeCompletionCache; class ScriptEditor : public VBoxContainer { - GDCLASS(ScriptEditor, VBoxContainer ); - + GDCLASS(ScriptEditor, VBoxContainer); EditorNode *editor; enum { @@ -152,14 +145,14 @@ class ScriptEditor : public VBoxContainer { WINDOW_MOVE_RIGHT, WINDOW_NEXT, WINDOW_PREV, - WINDOW_SELECT_BASE=100 + WINDOW_SELECT_BASE = 100 }; - + enum ScriptSortBy { SORT_BY_NAME, SORT_BY_PATH, }; - + enum ScriptListName { DISPLAY_NAME, DISPLAY_DIR_AND_NAME, @@ -185,7 +178,7 @@ class ScriptEditor : public VBoxContainer { EditorFileDialog *file_dialog; ConfirmationDialog *erase_tab_confirm; ScriptCreateDialog *script_create_dialog; - ScriptEditorDebugger* debugger; + ScriptEditorDebugger *debugger; ToolButton *scripts_visible; String current_theme; @@ -197,7 +190,7 @@ class ScriptEditor : public VBoxContainer { ToolButton *script_forward; enum { - SCRIPT_EDITOR_FUNC_MAX=32 + SCRIPT_EDITOR_FUNC_MAX = 32 }; static int script_editor_func_count; @@ -212,7 +205,6 @@ class ScriptEditor : public VBoxContainer { Vector<ScriptHistory> history; int history_pos; - EditorHelpIndex *help_index; void _tab_changed(int p_which); @@ -223,17 +215,17 @@ class ScriptEditor : public VBoxContainer { bool restoring_layout; - String _get_debug_tooltip(const String&p_text,Node *_ste); + String _get_debug_tooltip(const String &p_text, Node *_ste); - void _resave_scripts(const String& p_str); + void _resave_scripts(const String &p_str); void _reload_scripts(); - bool _test_script_times_on_disk(Ref<Script> p_for_script=Ref<Script>()); + bool _test_script_times_on_disk(Ref<Script> p_for_script = Ref<Script>()); - void _close_tab(int p_idx, bool p_save=true); + void _close_tab(int p_idx, bool p_save = true); void _close_current_tab(); - void _close_discard_current_tab(const String& p_str); + void _close_discard_current_tab(const String &p_str); void _close_docs_tab(); void _close_all_tabs(); @@ -255,16 +247,16 @@ class ScriptEditor : public VBoxContainer { int edit_pass; - void _add_callback(Object *p_obj, const String& p_function, const PoolStringArray& p_args); - void _res_saved_callback(const Ref<Resource>& p_res); + void _add_callback(Object *p_obj, const String &p_function, const PoolStringArray &p_args); + void _res_saved_callback(const Ref<Resource> &p_res); bool trim_trailing_whitespace_on_save; void _trim_trailing_whitespace(TextEdit *tx); void _goto_script_line2(int p_line); - void _goto_script_line(REF p_script,int p_line); - void _breaked(bool p_breaked,bool p_can_debug); + void _goto_script_line(REF p_script, int p_line); + void _breaked(bool p_breaked, bool p_can_debug); void _show_debugger(bool p_show); void _update_window_menu(); void _script_created(Ref<Script> p_script); @@ -277,13 +269,13 @@ class ScriptEditor : public VBoxContainer { void _script_selected(int p_idx); - void _find_scripts(Node* p_base, Node* p_current,Set<Ref<Script> >& used); + void _find_scripts(Node *p_base, Node *p_current, Set<Ref<Script> > &used); void _tree_changed(); void _script_split_dragged(float); - void _unhandled_input(const InputEvent& p_event); + void _unhandled_input(const InputEvent &p_event); void _help_search(String p_text); @@ -292,36 +284,37 @@ class ScriptEditor : public VBoxContainer { bool waiting_update_names; - void _help_class_open(const String& p_class); - void _help_class_goto(const String& p_desc); + void _help_class_open(const String &p_class); + void _help_class_goto(const String &p_desc); void _update_history_arrows(); void _save_history(); void _go_to_tab(int p_idx); void _update_history_pos(int p_new_pos); void _update_script_colors(); - void _update_modified_scripts_for_external_editor(Ref<Script> p_for_script=Ref<Script>()); + void _update_modified_scripts_for_external_editor(Ref<Script> p_for_script = Ref<Script>()); int file_dialog_option; void _file_dialog_action(String p_file); - static void _open_script_request(const String& p_path); + static void _open_script_request(const String &p_path); static ScriptEditor *script_editor; + protected: void _notification(int p_what); static void _bind_methods(); -public: +public: static ScriptEditor *get_singleton() { return script_editor; } void ensure_focus_current(); void apply_scripts() const; void ensure_select_current(); - void edit(const Ref<Script>& p_script,bool p_grab_focus=true); + void edit(const Ref<Script> &p_script, bool p_grab_focus = true); Dictionary get_state() const; - void set_state(const Dictionary& p_state); + void set_state(const Dictionary &p_state); void clear(); void get_breakpoints(List<String> *p_breakpoints); @@ -333,15 +326,15 @@ public: void set_window_layout(Ref<ConfigFile> p_layout); void get_window_layout(Ref<ConfigFile> p_layout); - void set_scene_root_script( Ref<Script> p_script ); + void set_scene_root_script(Ref<Script> p_script); - bool script_go_to_method(Ref<Script> p_script, const String& p_method); + bool script_go_to_method(Ref<Script> p_script, const String &p_method); virtual void edited_scene_changed(); - void close_builtin_scripts_from_scene(const String& p_scene); + void close_builtin_scripts_from_scene(const String &p_scene); - void goto_help(const String& p_desc) { _help_class_goto(p_desc); } + void goto_help(const String &p_desc) { _help_class_goto(p_desc); } bool can_take_away_focus() const; @@ -355,12 +348,12 @@ public: class ScriptEditorPlugin : public EditorPlugin { - GDCLASS( ScriptEditorPlugin, EditorPlugin ); + GDCLASS(ScriptEditorPlugin, EditorPlugin); ScriptEditor *script_editor; EditorNode *editor; -public: +public: virtual String get_name() const { return "Script"; } bool has_main_screen() const { return true; } virtual void edit(Object *p_node); @@ -369,7 +362,7 @@ public: virtual void selected_notify(); Dictionary get_state() const; - virtual void set_state(const Dictionary& p_state); + virtual void set_state(const Dictionary &p_state); virtual void clear(); virtual void save_external_data(); @@ -383,12 +376,10 @@ public: virtual void get_breakpoints(List<String> *p_breakpoints); - virtual void edited_scene_changed(); ScriptEditorPlugin(EditorNode *p_node); ~ScriptEditorPlugin(); - }; #endif // SCRIPT_EDITOR_PLUGIN_H diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 8723a863f0..7496ad8cca 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -28,30 +28,27 @@ /*************************************************************************/ #include "script_text_editor.h" +#include "editor/editor_node.h" #include "editor/editor_settings.h" -#include "os/keyboard.h" #include "editor/script_editor_debugger.h" -#include "editor/editor_node.h" - -Vector<String> ScriptTextEditor::get_functions() { +#include "os/keyboard.h" +Vector<String> ScriptTextEditor::get_functions() { String errortxt; - int line=-1,col; - TextEdit *te=code_editor->get_text_edit(); + int line = -1, col; + TextEdit *te = code_editor->get_text_edit(); String text = te->get_text(); List<String> fnc; - if (script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) { + if (script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) { //if valid rewrite functions to latest functions.clear(); - for (List<String>::Element *E=fnc.front();E;E=E->next()) { + for (List<String>::Element *E = fnc.front(); E; E = E->next()) { functions.push_back(E->get()); } - - } return functions; @@ -71,20 +68,19 @@ Ref<Script> ScriptTextEditor::get_edited_script() const { return script; } -bool ScriptTextEditor::goto_method(const String& p_method) { - +bool ScriptTextEditor::goto_method(const String &p_method) { Vector<String> functions = get_functions(); String method_search = p_method + ":"; - for (int i=0;i<functions.size();i++) { - String function=functions[i]; + for (int i = 0; i < functions.size(); i++) { + String function = functions[i]; if (function.begins_with(method_search)) { - int line=function.get_slice(":",1).to_int(); - goto_line(line-1); + int line = function.get_slice(":", 1).to_int(); + goto_line(line - 1); return true; } } @@ -100,105 +96,103 @@ void ScriptTextEditor::_load_theme_settings() { /* keyword color */ - - text_edit->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color",Color(0,0,0,0))); - text_edit->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0,0,0,0))); + text_edit->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0))); + text_edit->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0, 0, 0, 0))); text_edit->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/highlighting/completion_selected_color", Color::html("434244"))); text_edit->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf"))); text_edit->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/highlighting/completion_scroll_color", Color::html("ffffff"))); text_edit->add_color_override("completion_font_color", EDITOR_DEF("text_editor/highlighting/completion_font_color", Color::html("aaaaaa"))); - text_edit->add_color_override("font_color",EDITOR_DEF("text_editor/highlighting/text_color",Color(0,0,0))); - text_edit->add_color_override("line_number_color",EDITOR_DEF("text_editor/highlighting/line_number_color",Color(0,0,0))); - text_edit->add_color_override("caret_color",EDITOR_DEF("text_editor/highlighting/caret_color",Color(0,0,0))); - text_edit->add_color_override("caret_background_color",EDITOR_DEF("text_editor/highlighting/caret_background_color",Color(0,0,0))); - text_edit->add_color_override("font_selected_color",EDITOR_DEF("text_editor/highlighting/text_selected_color",Color(1,1,1))); - text_edit->add_color_override("selection_color",EDITOR_DEF("text_editor/highlighting/selection_color",Color(0.2,0.2,1))); - text_edit->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/highlighting/brace_mismatch_color",Color(1,0.2,0.2))); - text_edit->add_color_override("current_line_color",EDITOR_DEF("text_editor/highlighting/current_line_color",Color(0.3,0.5,0.8,0.15))); - text_edit->add_color_override("line_length_guideline_color", EDITOR_DEF("text_editor/highlighting/line_length_guideline_color", Color(0,0,0))); - text_edit->add_color_override("word_highlighted_color",EDITOR_DEF("text_editor/highlighting/word_highlighted_color",Color(0.8,0.9,0.9,0.15))); - text_edit->add_color_override("number_color",EDITOR_DEF("text_editor/highlighting/number_color",Color(0.9,0.6,0.0,2))); - text_edit->add_color_override("function_color",EDITOR_DEF("text_editor/highlighting/function_color",Color(0.4,0.6,0.8))); - text_edit->add_color_override("member_variable_color",EDITOR_DEF("text_editor/highlighting/member_variable_color",Color(0.9,0.3,0.3))); - text_edit->add_color_override("mark_color", EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0,0.4,0.4,0.4))); - text_edit->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8,0.8,0.4,0.2))); - text_edit->add_color_override("search_result_color",EDITOR_DEF("text_editor/highlighting/search_result_color",Color(0.05,0.25,0.05,1))); - text_edit->add_color_override("search_result_border_color",EDITOR_DEF("text_editor/highlighting/search_result_border_color",Color(0.1,0.45,0.1,1))); - text_edit->add_color_override("symbol_color",EDITOR_DEF("text_editor/highlighting/symbol_color",Color::hex(0x005291ff))); - text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing",4)); - - Color keyword_color= EDITOR_DEF("text_editor/highlighting/keyword_color",Color(0.5,0.0,0.2)); + text_edit->add_color_override("font_color", EDITOR_DEF("text_editor/highlighting/text_color", Color(0, 0, 0))); + text_edit->add_color_override("line_number_color", EDITOR_DEF("text_editor/highlighting/line_number_color", Color(0, 0, 0))); + text_edit->add_color_override("caret_color", EDITOR_DEF("text_editor/highlighting/caret_color", Color(0, 0, 0))); + text_edit->add_color_override("caret_background_color", EDITOR_DEF("text_editor/highlighting/caret_background_color", Color(0, 0, 0))); + text_edit->add_color_override("font_selected_color", EDITOR_DEF("text_editor/highlighting/text_selected_color", Color(1, 1, 1))); + text_edit->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1))); + text_edit->add_color_override("brace_mismatch_color", EDITOR_DEF("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2))); + text_edit->add_color_override("current_line_color", EDITOR_DEF("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15))); + text_edit->add_color_override("line_length_guideline_color", EDITOR_DEF("text_editor/highlighting/line_length_guideline_color", Color(0, 0, 0))); + text_edit->add_color_override("word_highlighted_color", EDITOR_DEF("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15))); + text_edit->add_color_override("number_color", EDITOR_DEF("text_editor/highlighting/number_color", Color(0.9, 0.6, 0.0, 2))); + text_edit->add_color_override("function_color", EDITOR_DEF("text_editor/highlighting/function_color", Color(0.4, 0.6, 0.8))); + text_edit->add_color_override("member_variable_color", EDITOR_DEF("text_editor/highlighting/member_variable_color", Color(0.9, 0.3, 0.3))); + text_edit->add_color_override("mark_color", EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4))); + text_edit->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2))); + text_edit->add_color_override("search_result_color", EDITOR_DEF("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1))); + text_edit->add_color_override("search_result_border_color", EDITOR_DEF("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1))); + text_edit->add_color_override("symbol_color", EDITOR_DEF("text_editor/highlighting/symbol_color", Color::hex(0x005291ff))); + text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 4)); + + Color keyword_color = EDITOR_DEF("text_editor/highlighting/keyword_color", Color(0.5, 0.0, 0.2)); List<String> keywords; script->get_language()->get_reserved_words(&keywords); - for(List<String>::Element *E=keywords.front();E;E=E->next()) { + for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - text_edit->add_keyword_color(E->get(),keyword_color); + text_edit->add_keyword_color(E->get(), keyword_color); } //colorize core types - Color basetype_color= EDITOR_DEF("text_editor/highlighting/base_type_color",Color(0.3,0.3,0.0)); - - text_edit->add_keyword_color("Vector2",basetype_color); - text_edit->add_keyword_color("Vector3",basetype_color); - text_edit->add_keyword_color("Plane",basetype_color); - text_edit->add_keyword_color("Quat",basetype_color); - text_edit->add_keyword_color("AABB",basetype_color); - text_edit->add_keyword_color("Matrix3",basetype_color); - text_edit->add_keyword_color("Transform",basetype_color); - text_edit->add_keyword_color("Color",basetype_color); - text_edit->add_keyword_color("Image",basetype_color); - text_edit->add_keyword_color("InputEvent",basetype_color); - text_edit->add_keyword_color("Rect2",basetype_color); - text_edit->add_keyword_color("NodePath",basetype_color); + Color basetype_color = EDITOR_DEF("text_editor/highlighting/base_type_color", Color(0.3, 0.3, 0.0)); + + text_edit->add_keyword_color("Vector2", basetype_color); + text_edit->add_keyword_color("Vector3", basetype_color); + text_edit->add_keyword_color("Plane", basetype_color); + text_edit->add_keyword_color("Quat", basetype_color); + text_edit->add_keyword_color("AABB", basetype_color); + text_edit->add_keyword_color("Matrix3", basetype_color); + text_edit->add_keyword_color("Transform", basetype_color); + text_edit->add_keyword_color("Color", basetype_color); + text_edit->add_keyword_color("Image", basetype_color); + text_edit->add_keyword_color("InputEvent", basetype_color); + text_edit->add_keyword_color("Rect2", basetype_color); + text_edit->add_keyword_color("NodePath", basetype_color); //colorize engine types - Color type_color= EDITOR_DEF("text_editor/highlighting/engine_type_color",Color(0.0,0.2,0.4)); + Color type_color = EDITOR_DEF("text_editor/highlighting/engine_type_color", Color(0.0, 0.2, 0.4)); List<StringName> types; ClassDB::get_class_list(&types); - for(List<StringName>::Element *E=types.front();E;E=E->next()) { + for (List<StringName>::Element *E = types.front(); E; E = E->next()) { String n = E->get(); if (n.begins_with("_")) n = n.substr(1, n.length()); - text_edit->add_keyword_color(n,type_color); + text_edit->add_keyword_color(n, type_color); } //colorize comments - Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color",Color::hex(0x797e7eff)); + Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color", Color::hex(0x797e7eff)); List<String> comments; script->get_language()->get_comment_delimiters(&comments); - for(List<String>::Element *E=comments.front();E;E=E->next()) { + for (List<String>::Element *E = comments.front(); E; E = E->next()) { String comment = E->get(); - String beg = comment.get_slice(" ",0); - String end = comment.get_slice_count(" ")>1?comment.get_slice(" ",1):String(); + String beg = comment.get_slice(" ", 0); + String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); - text_edit->add_color_region(beg,end,comment_color,end==""); + text_edit->add_color_region(beg, end, comment_color, end == ""); } //colorize strings - Color string_color = EDITOR_DEF("text_editor/highlighting/string_color",Color::hex(0x6b6f00ff)); + Color string_color = EDITOR_DEF("text_editor/highlighting/string_color", Color::hex(0x6b6f00ff)); List<String> strings; script->get_language()->get_string_delimiters(&strings); - for (List<String>::Element *E=strings.front();E;E=E->next()) { + for (List<String>::Element *E = strings.front(); E; E = E->next()) { String string = E->get(); - String beg = string.get_slice(" ",0); - String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String(); - text_edit->add_color_region(beg,end,string_color,end==""); + String beg = string.get_slice(" ", 0); + String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); + text_edit->add_color_region(beg, end, string_color, end == ""); } } - void ScriptTextEditor::reload_text() { - ERR_FAIL_COND(script.is_null()) ; + ERR_FAIL_COND(script.is_null()); TextEdit *te = code_editor->get_text_edit(); int column = te->cursor_get_column(); @@ -216,30 +210,29 @@ void ScriptTextEditor::reload_text() { te->tag_saved_version(); code_editor->update_line_and_column(); - } void ScriptTextEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY) { //emit_signal("name_changed"); } } -void ScriptTextEditor::add_callback(const String& p_function,PoolStringArray p_args) { +void ScriptTextEditor::add_callback(const String &p_function, PoolStringArray p_args) { String code = code_editor->get_text_edit()->get_text(); - int pos = script->get_language()->find_function(p_function,code); - if (pos==-1) { + int pos = script->get_language()->find_function(p_function, code); + if (pos == -1) { //does not exist code_editor->get_text_edit()->deselect(); - pos=code_editor->get_text_edit()->get_line_count()+2; - String func = script->get_language()->make_function("",p_function,p_args); + pos = code_editor->get_text_edit()->get_line_count() + 2; + String func = script->get_language()->make_function("", p_function, p_args); //code=code+func; - code_editor->get_text_edit()->cursor_set_line(pos+1); + code_editor->get_text_edit()->cursor_set_line(pos + 1); code_editor->get_text_edit()->cursor_set_column(1000000); //none shall be that big - code_editor->get_text_edit()->insert_text_at_cursor("\n\n"+func); + code_editor->get_text_edit()->insert_text_at_cursor("\n\n" + func); } code_editor->get_text_edit()->cursor_set_line(pos); code_editor->get_text_edit()->cursor_set_column(1); @@ -250,18 +243,18 @@ void ScriptTextEditor::update_settings() { code_editor->update_editor_settings(); } -bool ScriptTextEditor::is_unsaved() { +bool ScriptTextEditor::is_unsaved() { - return code_editor->get_text_edit()->get_version()!=code_editor->get_text_edit()->get_saved_version(); + return code_editor->get_text_edit()->get_version() != code_editor->get_text_edit()->get_saved_version(); } Variant ScriptTextEditor::get_edit_state() { Dictionary state; - state["scroll_pos"]=code_editor->get_text_edit()->get_v_scroll(); - state["column"]=code_editor->get_text_edit()->cursor_get_column(); - state["row"]=code_editor->get_text_edit()->cursor_get_line(); + state["scroll_pos"] = code_editor->get_text_edit()->get_v_scroll(); + state["column"] = code_editor->get_text_edit()->cursor_get_column(); + state["row"] = code_editor->get_text_edit()->cursor_get_line(); return state; } @@ -283,7 +276,7 @@ void ScriptTextEditor::trim_trailing_whitespace() { int end = 0; for (int j = line.length() - 1; j > -1; j--) { if (line[j] != ' ' && line[j] != '\t') { - end = j+1; + end = j + 1; break; } } @@ -310,12 +303,12 @@ void ScriptTextEditor::ensure_focus() { code_editor->get_text_edit()->grab_focus(); } -void ScriptTextEditor::set_edit_state(const Variant& p_state) { +void ScriptTextEditor::set_edit_state(const Variant &p_state) { - Dictionary state=p_state; + Dictionary state = p_state; code_editor->get_text_edit()->set_v_scroll(state["scroll_pos"]); - code_editor->get_text_edit()->cursor_set_column( state["column"]); - code_editor->get_text_edit()->cursor_set_line( state["row"] ); + code_editor->get_text_edit()->cursor_set_column(state["column"]); + code_editor->get_text_edit()->cursor_set_line(state["row"]); code_editor->get_text_edit()->grab_focus(); //int scroll_pos; @@ -323,40 +316,36 @@ void ScriptTextEditor::set_edit_state(const Variant& p_state) { //int cursor_row; } -String ScriptTextEditor::get_name() { +String ScriptTextEditor::get_name() { String name; - if (script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) { - name=script->get_path().get_file(); + if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) { + name = script->get_path().get_file(); if (is_unsaved()) { - name+="(*)"; + name += "(*)"; } - } else if (script->get_name()!="") - name=script->get_name(); + } else if (script->get_name() != "") + name = script->get_name(); else - name=script->get_class()+"("+itos(script->get_instance_ID())+")"; + name = script->get_class() + "(" + itos(script->get_instance_ID()) + ")"; return name; - } Ref<Texture> ScriptTextEditor::get_icon() { - if (get_parent_control() && get_parent_control()->has_icon(script->get_class(),"EditorIcons")) { - return get_parent_control()->get_icon(script->get_class(),"EditorIcons"); + if (get_parent_control() && get_parent_control()->has_icon(script->get_class(), "EditorIcons")) { + return get_parent_control()->get_icon(script->get_class(), "EditorIcons"); } return Ref<Texture>(); } - - -void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) { +void ScriptTextEditor::set_edited_script(const Ref<Script> &p_script) { ERR_FAIL_COND(!script.is_null()); - script=p_script; - + script = p_script; _load_theme_settings(); @@ -368,22 +357,21 @@ void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) { code_editor->update_line_and_column(); } - void ScriptTextEditor::_validate_script() { String errortxt; - int line=-1,col; - TextEdit *te=code_editor->get_text_edit(); + int line = -1, col; + TextEdit *te = code_editor->get_text_edit(); String text = te->get_text(); List<String> fnc; - if (!script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) { - String error_text="error("+itos(line)+","+itos(col)+"): "+errortxt; + if (!script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) { + String error_text = "error(" + itos(line) + "," + itos(col) + "): " + errortxt; code_editor->set_error(error_text); } else { code_editor->set_error(""); - line=-1; + line = -1; if (!script->is_tool()) { script->set_source_code(text); script->update_exports(); @@ -391,31 +379,29 @@ void ScriptTextEditor::_validate_script() { } functions.clear(); - for (List<String>::Element *E=fnc.front();E;E=E->next()) { + for (List<String>::Element *E = fnc.front(); E; E = E->next()) { functions.push_back(E->get()); } - } line--; - for(int i=0;i<te->get_line_count();i++) { - te->set_line_as_marked(i,line==i); + for (int i = 0; i < te->get_line_count(); i++) { + te->set_line_as_marked(i, line == i); } emit_signal("name_changed"); } +static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) { -static Node* _find_node_for_script(Node* p_base, Node*p_current, const Ref<Script>& p_script) { - - if (p_current->get_owner()!=p_base && p_base!=p_current) + if (p_current->get_owner() != p_base && p_base != p_current) return NULL; Ref<Script> c = p_current->get_script(); - if (c==p_script) + if (c == p_script) return p_current; - for(int i=0;i<p_current->get_child_count();i++) { - Node *found = _find_node_for_script(p_base,p_current->get_child(i),p_script); + for (int i = 0; i < p_current->get_child_count(); i++) { + Node *found = _find_node_for_script(p_base, p_current->get_child(i), p_script); if (found) return found; } @@ -423,19 +409,18 @@ static Node* _find_node_for_script(Node* p_base, Node*p_current, const Ref<Scrip return NULL; } -static void _find_changed_scripts_for_external_editor(Node* p_base, Node*p_current, Set<Ref<Script> > &r_scripts) { +static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, Set<Ref<Script> > &r_scripts) { - if (p_current->get_owner()!=p_base && p_base!=p_current) + if (p_current->get_owner() != p_base && p_base != p_current) return; Ref<Script> c = p_current->get_script(); if (c.is_valid()) r_scripts.insert(c); - for(int i=0;i<p_current->get_child_count();i++) { - _find_changed_scripts_for_external_editor(p_base,p_current->get_child(i),r_scripts); + for (int i = 0; i < p_current->get_child_count(); i++) { + _find_changed_scripts_for_external_editor(p_base, p_current->get_child(i), r_scripts); } - } void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) { @@ -447,17 +432,17 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo Node *base = get_tree()->get_edited_scene_root(); if (base) { - _find_changed_scripts_for_external_editor(base,base,scripts); + _find_changed_scripts_for_external_editor(base, base, scripts); } - for (Set<Ref<Script> >::Element *E=scripts.front();E;E=E->next()) { + for (Set<Ref<Script> >::Element *E = scripts.front(); E; E = E->next()) { Ref<Script> script = E->get(); - if (p_for_script.is_valid() && p_for_script!=script) + if (p_for_script.is_valid() && p_for_script != script) continue; - if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) { + if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) { continue; //internal script, who cares, though weird } @@ -465,128 +450,120 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo uint64_t last_date = script->get_last_modified_time(); uint64_t date = FileAccess::get_modified_time(script->get_path()); - if (last_date!=date) { + if (last_date != date) { - Ref<Script> rel_script = ResourceLoader::load(script->get_path(),script->get_class(),true); + Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true); ERR_CONTINUE(!rel_script.is_valid()); - script->set_source_code( rel_script->get_source_code() ); - script->set_last_modified_time( rel_script->get_last_modified_time() ); + script->set_source_code(rel_script->get_source_code()); + script->set_last_modified_time(rel_script->get_last_modified_time()); script->update_exports(); } - } } - -void ScriptTextEditor::_code_complete_scripts(void* p_ud,const String& p_code, List<String>* r_options) { +void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options) { ScriptTextEditor *ste = (ScriptTextEditor *)p_ud; - ste->_code_complete_script(p_code,r_options); + ste->_code_complete_script(p_code, r_options); } -void ScriptTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) { +void ScriptTextEditor::_code_complete_script(const String &p_code, List<String> *r_options) { if (color_panel->is_visible_in_tree()) return; Node *base = get_tree()->get_edited_scene_root(); if (base) { - base = _find_node_for_script(base,base,script); + base = _find_node_for_script(base, base, script); } String hint; - Error err = script->get_language()->complete_code(p_code,script->get_path().get_base_dir(),base,r_options,hint); - if (hint!="") { + Error err = script->get_language()->complete_code(p_code, script->get_path().get_base_dir(), base, r_options, hint); + if (hint != "") { code_editor->get_text_edit()->set_code_hint(hint); } - } void ScriptTextEditor::_breakpoint_toggled(int p_row) { - ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(script->get_path(),p_row+1,code_editor->get_text_edit()->is_line_set_as_breakpoint(p_row)); - + ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(script->get_path(), p_row + 1, code_editor->get_text_edit()->is_line_set_as_breakpoint(p_row)); } -static void swap_lines(TextEdit *tx, int line1, int line2) -{ - String tmp = tx->get_line(line1); - String tmp2 = tx->get_line(line2); - tx->set_line(line2, tmp); - tx->set_line(line1, tmp2); +static void swap_lines(TextEdit *tx, int line1, int line2) { + String tmp = tx->get_line(line1); + String tmp2 = tx->get_line(line2); + tx->set_line(line2, tmp); + tx->set_line(line1, tmp2); - tx->cursor_set_line(line2); + tx->cursor_set_line(line2); } -void ScriptTextEditor::_lookup_symbol(const String& p_symbol,int p_row, int p_column) { +void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) { Node *base = get_tree()->get_edited_scene_root(); if (base) { - base = _find_node_for_script(base,base,script); + base = _find_node_for_script(base, base, script); } - ScriptLanguage::LookupResult result; - if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(),p_symbol,script->get_path().get_base_dir(),base,result)==OK) { + if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), p_symbol, script->get_path().get_base_dir(), base, result) == OK) { _goto_line(p_row); - switch(result.type) { + switch (result.type) { case ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION: { if (result.script.is_valid()) { - emit_signal("request_open_script_at_line",result.script,result.location-1); + emit_signal("request_open_script_at_line", result.script, result.location - 1); } else { emit_signal("request_save_history"); - _goto_line(result.location-1); + _goto_line(result.location - 1); } } break; case ScriptLanguage::LookupResult::RESULT_CLASS: { - emit_signal("go_to_help","class_name:"+result.class_name); + emit_signal("go_to_help", "class_name:" + result.class_name); } break; case ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT: { StringName cname = result.class_name; bool success; - while(true) { - ClassDB::get_integer_constant(cname,result.class_member,&success); + while (true) { + ClassDB::get_integer_constant(cname, result.class_member, &success); if (success) { - result.class_name=cname; - cname=ClassDB::get_parent_class(cname); + result.class_name = cname; + cname = ClassDB::get_parent_class(cname); } else { break; } } - - emit_signal("go_to_help","class_constant:"+result.class_name+":"+result.class_member); + emit_signal("go_to_help", "class_constant:" + result.class_name + ":" + result.class_member); } break; case ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY: { - emit_signal("go_to_help","class_property:"+result.class_name+":"+result.class_member); + emit_signal("go_to_help", "class_property:" + result.class_name + ":" + result.class_member); } break; case ScriptLanguage::LookupResult::RESULT_CLASS_METHOD: { StringName cname = result.class_name; - while(true) { - if (ClassDB::has_method(cname,result.class_member)) { - result.class_name=cname; - cname=ClassDB::get_parent_class(cname); + while (true) { + if (ClassDB::has_method(cname, result.class_member)) { + result.class_name = cname; + cname = ClassDB::get_parent_class(cname); } else { break; } } - emit_signal("go_to_help","class_method:"+result.class_name+":"+result.class_member); + emit_signal("go_to_help", "class_method:" + result.class_name + ":" + result.class_member); } break; } - } } void ScriptTextEditor::_edit_option(int p_op) { - switch(p_op) { + switch (p_op) { case EDIT_UNDO: { code_editor->get_text_edit()->undo(); code_editor->get_text_edit()->call_deferred("grab_focus"); @@ -624,15 +601,13 @@ void ScriptTextEditor::_edit_option(int p_op) { return; tx->begin_complex_operation(); - if (tx->is_selection_active()) - { + if (tx->is_selection_active()) { int from_line = tx->get_selection_from_line(); - int from_col = tx->get_selection_from_column(); - int to_line = tx->get_selection_to_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); int to_column = tx->get_selection_to_column(); - for (int i = from_line; i <= to_line; i++) - { + for (int i = from_line; i <= to_line; i++) { int line_id = i; int next_id = i - 1; @@ -641,12 +616,10 @@ void ScriptTextEditor::_edit_option(int p_op) { swap_lines(tx, line_id, next_id); } - int from_line_up = from_line > 0 ? from_line-1 : from_line; - int to_line_up = to_line > 0 ? to_line-1 : to_line; + int from_line_up = from_line > 0 ? from_line - 1 : from_line; + int to_line_up = to_line > 0 ? to_line - 1 : to_line; tx->select(from_line_up, from_col, to_line_up, to_column); - } - else - { + } else { int line_id = tx->cursor_get_line(); int next_id = line_id - 1; @@ -667,33 +640,29 @@ void ScriptTextEditor::_edit_option(int p_op) { return; tx->begin_complex_operation(); - if (tx->is_selection_active()) - { + if (tx->is_selection_active()) { int from_line = tx->get_selection_from_line(); - int from_col = tx->get_selection_from_column(); - int to_line = tx->get_selection_to_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); int to_column = tx->get_selection_to_column(); - for (int i = to_line; i >= from_line; i--) - { + for (int i = to_line; i >= from_line; i--) { int line_id = i; int next_id = i + 1; - if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) + if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count()) return; swap_lines(tx, line_id, next_id); } - int from_line_down = from_line < tx->get_line_count() ? from_line+1 : from_line; - int to_line_down = to_line < tx->get_line_count() ? to_line+1 : to_line; + int from_line_down = from_line < tx->get_line_count() ? from_line + 1 : from_line; + int to_line_down = to_line < tx->get_line_count() ? to_line + 1 : to_line; tx->select(from_line_down, from_col, to_line_down, to_column); - } - else - { + } else { int line_id = tx->cursor_get_line(); int next_id = line_id + 1; - if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) + if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count()) return; swap_lines(tx, line_id, next_id); @@ -710,23 +679,18 @@ void ScriptTextEditor::_edit_option(int p_op) { return; tx->begin_complex_operation(); - if (tx->is_selection_active()) - { + if (tx->is_selection_active()) { tx->indent_selection_left(); - } - else - { + } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); // begins with tab - if (line_text.begins_with("\t")) - { + if (line_text.begins_with("\t")) { line_text = line_text.substr(1, line_text.length()); tx->set_line(begin, line_text); } // begins with 4 spaces - else if (line_text.begins_with(" ")) - { + else if (line_text.begins_with(" ")) { line_text = line_text.substr(4, line_text.length()); tx->set_line(begin, line_text); } @@ -744,12 +708,9 @@ void ScriptTextEditor::_edit_option(int p_op) { return; tx->begin_complex_operation(); - if (tx->is_selection_active()) - { + if (tx->is_selection_active()) { tx->indent_selection_right(); - } - else - { + } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); line_text = '\t' + line_text; @@ -782,7 +743,7 @@ void ScriptTextEditor::_edit_option(int p_op) { for (int i = from_line; i <= to_line; i++) { if (i >= tx->get_line_count() - 1) { - tx->set_line(i, tx->get_line(i) + "\n"); + tx->set_line(i, tx->get_line(i) + "\n"); } String line_clone = tx->get_line(i); tx->insert_at(line_clone, next_line); @@ -805,19 +766,16 @@ void ScriptTextEditor::_edit_option(int p_op) { if (scr.is_null()) return; - tx->begin_complex_operation(); - if (tx->is_selection_active()) - { + if (tx->is_selection_active()) { int begin = tx->get_selection_from_line(); int end = tx->get_selection_to_line(); // End of selection ends on the first column of the last line, ignore it. - if(tx->get_selection_to_column() == 0) + if (tx->get_selection_to_column() == 0) end -= 1; - for (int i = begin; i <= end; i++) - { + for (int i = begin; i <= end; i++) { String line_text = tx->get_line(i); if (line_text.begins_with("#")) @@ -826,9 +784,7 @@ void ScriptTextEditor::_edit_option(int p_op) { line_text = "#" + line_text; tx->set_line(i, line_text); } - } - else - { + } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); @@ -855,18 +811,17 @@ void ScriptTextEditor::_edit_option(int p_op) { Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; - int begin,end; + int begin, end; if (te->is_selection_active()) { - begin=te->get_selection_from_line(); - end=te->get_selection_to_line(); + begin = te->get_selection_from_line(); + end = te->get_selection_to_line(); } else { - begin=0; - end=te->get_line_count()-1; + begin = 0; + end = te->get_line_count() - 1; } - scr->get_language()->auto_indent_code(text,begin,end); + scr->get_language()->auto_indent_code(text, begin, end); te->set_text(text); - } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { trim_trailing_whitespace(); @@ -875,7 +830,6 @@ void ScriptTextEditor::_edit_option(int p_op) { color_panel->popup(); } break; - case SEARCH_FIND: { code_editor->get_find_replace_bar()->popup_search(); @@ -901,20 +855,20 @@ void ScriptTextEditor::_edit_option(int p_op) { goto_line_dialog->popup_find_line(code_editor->get_text_edit()); } break; case DEBUG_TOGGLE_BREAKPOINT: { - int line=code_editor->get_text_edit()->cursor_get_line(); + int line = code_editor->get_text_edit()->cursor_get_line(); bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); - code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak); - ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak); + code_editor->get_text_edit()->set_line_as_breakpoint(line, dobreak); + ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(), line + 1, dobreak); } break; case DEBUG_REMOVE_ALL_BREAKPOINTS: { List<int> bpoints; code_editor->get_text_edit()->get_breakpoints(&bpoints); - for(List<int>::Element *E=bpoints.front();E;E=E->next()) { + for (List<int>::Element *E = bpoints.front(); E; E = E->next()) { int line = E->get(); bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); - code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak); - ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak); + code_editor->get_text_edit()->set_line_as_breakpoint(line, dobreak); + ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(), line + 1, dobreak); } } case DEBUG_GOTO_NEXT_BREAKPOINT: { @@ -924,12 +878,12 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - int line=code_editor->get_text_edit()->cursor_get_line(); + int line = code_editor->get_text_edit()->cursor_get_line(); // wrap around if (line >= bpoints[bpoints.size() - 1]) { code_editor->get_text_edit()->cursor_set_line(bpoints[0]); } else { - for(List<int>::Element *E=bpoints.front();E;E=E->next()) { + for (List<int>::Element *E = bpoints.front(); E; E = E->next()) { int bline = E->get(); if (bline > line) { code_editor->get_text_edit()->cursor_set_line(bline); @@ -946,12 +900,12 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - int line=code_editor->get_text_edit()->cursor_get_line(); + int line = code_editor->get_text_edit()->cursor_get_line(); // wrap around if (line <= bpoints[0]) { code_editor->get_text_edit()->cursor_set_line(bpoints[bpoints.size() - 1]); } else { - for(List<int>::Element *E=bpoints.back();E;E=E->prev()) { + for (List<int>::Element *E = bpoints.back(); E; E = E->prev()) { int bline = E->get(); if (bline < line) { code_editor->get_text_edit()->cursor_set_line(bline); @@ -967,7 +921,7 @@ void ScriptTextEditor::_edit_option(int p_op) { if (text == "") text = code_editor->get_text_edit()->get_word_under_cursor(); if (text != "") { - emit_signal("request_help_search",text); + emit_signal("request_help_search", text); } } break; } @@ -975,20 +929,18 @@ void ScriptTextEditor::_edit_option(int p_op) { void ScriptTextEditor::_bind_methods() { - ClassDB::bind_method("_validate_script",&ScriptTextEditor::_validate_script); - ClassDB::bind_method("_load_theme_settings",&ScriptTextEditor::_load_theme_settings); - ClassDB::bind_method("_breakpoint_toggled",&ScriptTextEditor::_breakpoint_toggled); - ClassDB::bind_method("_edit_option",&ScriptTextEditor::_edit_option); - ClassDB::bind_method("_goto_line",&ScriptTextEditor::_goto_line); - ClassDB::bind_method("_lookup_symbol",&ScriptTextEditor::_lookup_symbol); + ClassDB::bind_method("_validate_script", &ScriptTextEditor::_validate_script); + ClassDB::bind_method("_load_theme_settings", &ScriptTextEditor::_load_theme_settings); + ClassDB::bind_method("_breakpoint_toggled", &ScriptTextEditor::_breakpoint_toggled); + ClassDB::bind_method("_edit_option", &ScriptTextEditor::_edit_option); + ClassDB::bind_method("_goto_line", &ScriptTextEditor::_goto_line); + ClassDB::bind_method("_lookup_symbol", &ScriptTextEditor::_lookup_symbol); ClassDB::bind_method("_text_edit_gui_input", &ScriptTextEditor::_text_edit_gui_input); ClassDB::bind_method("_color_changed", &ScriptTextEditor::_color_changed); - - ClassDB::bind_method("get_drag_data_fw",&ScriptTextEditor::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw",&ScriptTextEditor::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw",&ScriptTextEditor::drop_data_fw); - + ClassDB::bind_method("get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw); + ClassDB::bind_method("can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw); + ClassDB::bind_method("drop_data_fw", &ScriptTextEditor::drop_data_fw); } Control *ScriptTextEditor::get_edit_menu() { @@ -1003,67 +955,59 @@ void ScriptTextEditor::reload(bool p_soft) { if (scr.is_null()) return; scr->set_source_code(te->get_text()); - bool soft = p_soft || scr->get_instance_base_type()=="EditorPlugin"; //always soft-reload editor plugins + bool soft = p_soft || scr->get_instance_base_type() == "EditorPlugin"; //always soft-reload editor plugins - scr->get_language()->reload_tool_script(scr,soft); + scr->get_language()->reload_tool_script(scr, soft); } void ScriptTextEditor::get_breakpoints(List<int> *p_breakpoints) { code_editor->get_text_edit()->get_breakpoints(p_breakpoints); - } -void ScriptTextEditor::set_tooltip_request_func(String p_method,Object* p_obj) { +void ScriptTextEditor::set_tooltip_request_func(String p_method, Object *p_obj) { - code_editor->get_text_edit()->set_tooltip_request_func(p_obj,p_method,this); + code_editor->get_text_edit()->set_tooltip_request_func(p_obj, p_method, this); } void ScriptTextEditor::set_debugger_active(bool p_active) { - - } - -Variant ScriptTextEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) { +Variant ScriptTextEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { return Variant(); } -bool ScriptTextEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{ +bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { Dictionary d = p_data; if (d.has("type") && ( - String(d["type"])=="resource" || - String(d["type"])=="files" || - String(d["type"])=="nodes" - ) ) { + String(d["type"]) == "resource" || + String(d["type"]) == "files" || + String(d["type"]) == "nodes")) { - - return true; + return true; } - return false; - } #ifdef TOOLS_ENABLED -static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) { +static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - if (p_edited_scene!=p_current_node && p_current_node->get_owner()!=p_edited_scene) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) return NULL; Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr==script) + if (scr.is_valid() && scr == script) return p_current_node; - for(int i=0;i<p_current_node->get_child_count();i++) { - Node *n = _find_script_node(p_edited_scene,p_current_node->get_child(i),script); + for (int i = 0; i < p_current_node->get_child_count(); i++) { + Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); if (n) return n; } @@ -1073,20 +1017,17 @@ static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const R #else -static Node* _find_script_node(Node* p_edited_scene,Node* p_current_node,const Ref<Script> &script) { +static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { return NULL; } #endif - - - -void ScriptTextEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ +void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { Dictionary d = p_data; - if (d.has("type") && String(d["type"])=="resource") { + if (d.has("type") && String(d["type"]) == "resource") { Ref<Resource> res = d["resource"]; if (!res.is_valid()) { @@ -1099,44 +1040,38 @@ void ScriptTextEditor::drop_data_fw(const Point2& p_point,const Variant& p_data, } code_editor->get_text_edit()->insert_text_at_cursor(res->get_path()); - } - if (d.has("type") && String(d["type"])=="files") { - + if (d.has("type") && String(d["type"]) == "files") { Array files = d["files"]; String text_to_drop; - for(int i=0;i<files.size();i++) { - - if (i>0) - text_to_drop+=","; - text_to_drop+="\""+String(files[i]).c_escape()+"\""; + for (int i = 0; i < files.size(); i++) { + if (i > 0) + text_to_drop += ","; + text_to_drop += "\"" + String(files[i]).c_escape() + "\""; } code_editor->get_text_edit()->insert_text_at_cursor(text_to_drop); - } - if (d.has("type") && String(d["type"])=="nodes") { - - Node* sn = _find_script_node(get_tree()->get_edited_scene_root(),get_tree()->get_edited_scene_root(),script); + if (d.has("type") && String(d["type"]) == "nodes") { + Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); if (!sn) { - EditorNode::get_singleton()->show_warning("Can't drop nodes because script '"+get_name()+"' is not used in this scene."); + EditorNode::get_singleton()->show_warning("Can't drop nodes because script '" + get_name() + "' is not used in this scene."); return; } - Array nodes = d["nodes"]; String text_to_drop; - for(int i=0;i<nodes.size();i++) { + for (int i = 0; i < nodes.size(); i++) { - if (i>0) - text_to_drop+=","; + if (i > 0) + text_to_drop += ","; NodePath np = nodes[i]; Node *node = get_node(np); @@ -1144,32 +1079,23 @@ void ScriptTextEditor::drop_data_fw(const Point2& p_point,const Variant& p_data, continue; } - - String path = sn->get_path_to(node); - text_to_drop+="\""+path.c_escape()+"\""; - - + text_to_drop += "\"" + path.c_escape() + "\""; } code_editor->get_text_edit()->insert_text_at_cursor(text_to_drop); - - } - - - } -void ScriptTextEditor::_text_edit_gui_input(const InputEvent& ev) { +void ScriptTextEditor::_text_edit_gui_input(const InputEvent &ev) { if (ev.type == InputEvent::MOUSE_BUTTON) { InputEventMouseButton mb = ev.mouse_button; if (mb.button_index == BUTTON_RIGHT && !mb.pressed) { int col, row; - TextEdit* tx = code_editor->get_text_edit(); - tx->_get_mouse_pos(Point2i(mb.global_x, mb.global_y)-tx->get_global_pos(), row, col); - Vector2 mpos = Vector2(mb.global_x, mb.global_y)-tx->get_global_pos(); + TextEdit *tx = code_editor->get_text_edit(); + tx->_get_mouse_pos(Point2i(mb.global_x, mb.global_y) - tx->get_global_pos(), row, col); + Vector2 mpos = Vector2(mb.global_x, mb.global_y) - tx->get_global_pos(); bool have_selection = (tx->get_selection_text().length() > 0); bool have_color = (tx->get_word_at_pos(mpos) == "Color"); if (have_color) { @@ -1177,21 +1103,20 @@ void ScriptTextEditor::_text_edit_gui_input(const InputEvent& ev) { String line = tx->get_line(row); color_line = row; int begin = 0; - int end = 0; + int end = 0; bool valid = false; for (int i = col; i < line.length(); i++) { if (line[i] == '(') { begin = i; continue; - } - else if (line[i] == ')') { - end = i+1; + } else if (line[i] == ')') { + end = i + 1; valid = true; break; } } if (valid) { - color_args = line.substr(begin, end-begin); + color_args = line.substr(begin, end - begin); String stripped = color_args.replace(" ", "").replace("(", "").replace(")", ""); Vector<float> color = stripped.split_floats(","); if (color.size() > 2) { @@ -1199,7 +1124,7 @@ void ScriptTextEditor::_text_edit_gui_input(const InputEvent& ev) { color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); } color_panel->set_pos(get_global_transform().xform(get_local_mouse_pos())); - Size2 ms = Size2(300, color_picker->get_combined_minimum_size().height+10); + Size2 ms = Size2(300, color_picker->get_combined_minimum_size().height + 10); color_panel->set_size(ms); } else { have_color = false; @@ -1210,12 +1135,12 @@ void ScriptTextEditor::_text_edit_gui_input(const InputEvent& ev) { } } -void ScriptTextEditor::_color_changed(const Color& p_color) { +void ScriptTextEditor::_color_changed(const Color &p_color) { String new_args; if (p_color.a == 1.0f) { - new_args = String("("+rtos(p_color.r)+", "+rtos(p_color.g)+", "+rtos(p_color.b)+")"); + new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ")"); } else { - new_args = String("("+rtos(p_color.r)+", "+rtos(p_color.g)+", "+rtos(p_color.b)+", "+rtos(p_color.a)+")"); + new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ", " + rtos(p_color.a) + ")"); } String line = code_editor->get_text_edit()->get_line(color_line); @@ -1255,20 +1180,20 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) { ScriptTextEditor::ScriptTextEditor() { - code_editor = memnew( CodeTextEditor ); + code_editor = memnew(CodeTextEditor); add_child(code_editor); code_editor->set_area_as_parent_rect(); - code_editor->connect("validate_script",this,"_validate_script"); - code_editor->connect("load_theme_settings",this,"_load_theme_settings"); - code_editor->set_code_complete_func(_code_complete_scripts,this); + code_editor->connect("validate_script", this, "_validate_script"); + code_editor->connect("load_theme_settings", this, "_load_theme_settings"); + code_editor->set_code_complete_func(_code_complete_scripts, this); code_editor->get_text_edit()->connect("breakpoint_toggled", this, "_breakpoint_toggled"); code_editor->get_text_edit()->connect("symbol_lookup", this, "_lookup_symbol"); update_settings(); code_editor->get_text_edit()->set_callhint_settings( - EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"), - EditorSettings::get_singleton()->get("text_editor/completion/callhint_tooltip_offset")); + EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"), + EditorSettings::get_singleton()->get("text_editor/completion/callhint_tooltip_offset")); code_editor->get_text_edit()->set_select_identifiers_on_hover(true); code_editor->get_text_edit()->set_context_menu_enabled(false); @@ -1285,9 +1210,9 @@ ScriptTextEditor::ScriptTextEditor() { color_panel->set_child_rect(color_picker); //NOT color_picker->connect("color_changed", this, "_color_changed"); - edit_hb = memnew (HBoxContainer); + edit_hb = memnew(HBoxContainer); - edit_menu = memnew( MenuButton ); + edit_menu = memnew(MenuButton); edit_menu->set_text(TTR("Edit")); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); @@ -1312,14 +1237,14 @@ ScriptTextEditor::ScriptTextEditor() { #endif edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/auto_indent"), EDIT_AUTO_INDENT); - edit_menu->get_popup()->connect("id_pressed", this,"_edit_option"); + edit_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_breakpoint"), DEBUG_TOGGLE_BREAKPOINT); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_breakpoints"), DEBUG_REMOVE_ALL_BREAKPOINTS); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_breakpoint"), DEBUG_GOTO_NEXT_BREAKPOINT); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_breakpoint"), DEBUG_GOTO_PREV_BREAKPOINT); - search_menu = memnew( MenuButton ); + search_menu = memnew(MenuButton); edit_hb->add_child(search_menu); search_menu->set_text(TTR("Search")); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND); @@ -1332,25 +1257,24 @@ ScriptTextEditor::ScriptTextEditor() { search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL); - search_menu->get_popup()->connect("id_pressed", this,"_edit_option"); + search_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_hb->add_child(edit_menu); - quick_open = memnew( ScriptEditorQuickOpen ); + quick_open = memnew(ScriptEditorQuickOpen); add_child(quick_open); - quick_open->connect("goto_line",this,"_goto_line"); + quick_open->connect("goto_line", this, "_goto_line"); goto_line_dialog = memnew(GotoLineDialog); add_child(goto_line_dialog); - code_editor->get_text_edit()->set_drag_forwarding(this); } -static ScriptEditorBase * create_editor(const Ref<Script>& p_script) { +static ScriptEditorBase *create_editor(const Ref<Script> &p_script) { if (p_script->has_source_code()) { - return memnew( ScriptTextEditor ); + return memnew(ScriptTextEditor); } return NULL; @@ -1358,44 +1282,44 @@ static ScriptEditorBase * create_editor(const Ref<Script>& p_script) { void ScriptTextEditor::register_editor() { - ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD|KEY_Z); - ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD|KEY_Y); - ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD|KEY_X); - ED_SHORTCUT("script_text_editor/copy", TTR("Copy"), KEY_MASK_CMD|KEY_C); - ED_SHORTCUT("script_text_editor/paste", TTR("Paste"), KEY_MASK_CMD|KEY_V); - ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD|KEY_A); - ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT|KEY_UP); - ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT|KEY_DOWN); + ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z); + ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y); + ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X); + ED_SHORTCUT("script_text_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C); + ED_SHORTCUT("script_text_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V); + ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A); + ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT | KEY_UP); + ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN); //leave these at zero, same can be accomplished with tab/shift-tab, including selection //the next/previous in history shortcut in this case makes a lot more sene. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), 0); ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0); - ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD|KEY_K); - ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD|KEY_B); + ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K); + ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_B); #ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL|KEY_SPACE); + ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL | KEY_SPACE); #else - ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD|KEY_SPACE); + ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE); #endif - ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CTRL|KEY_MASK_ALT|KEY_T); - ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD|KEY_I); + ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CTRL | KEY_MASK_ALT | KEY_T); + ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I); ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); - ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CTRL|KEY_MASK_SHIFT|KEY_F9); - ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Goto Next Breakpoint"), KEY_MASK_CTRL|KEY_PERIOD); - ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Goto Previous Breakpoint"), KEY_MASK_CTRL|KEY_COMMA); + ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CTRL | KEY_MASK_SHIFT | KEY_F9); + ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Goto Next Breakpoint"), KEY_MASK_CTRL | KEY_PERIOD); + ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Goto Previous Breakpoint"), KEY_MASK_CTRL | KEY_COMMA); - ED_SHORTCUT("script_text_editor/find", TTR("Find.."), KEY_MASK_CMD|KEY_F); + ED_SHORTCUT("script_text_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F); ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_F3); - ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT|KEY_F3); - ED_SHORTCUT("script_text_editor/replace", TTR("Replace.."), KEY_MASK_CMD|KEY_R); + ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3); + ED_SHORTCUT("script_text_editor/replace", TTR("Replace.."), KEY_MASK_CMD | KEY_R); - ED_SHORTCUT("script_text_editor/goto_function", TTR("Goto Function.."), KEY_MASK_SHIFT|KEY_MASK_CMD|KEY_F); - ED_SHORTCUT("script_text_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD|KEY_L); + ED_SHORTCUT("script_text_editor/goto_function", TTR("Goto Function.."), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_F); + ED_SHORTCUT("script_text_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD | KEY_L); - ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_SHIFT|KEY_F1); + ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_SHIFT | KEY_F1); ScriptEditor::register_create_script_editor_function(create_editor); } diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index e30a78340e..c5f65fb1db 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -29,26 +29,24 @@ #ifndef SCRIPT_TEXT_EDITOR_H #define SCRIPT_TEXT_EDITOR_H -#include "script_editor_plugin.h" #include "scene/gui/color_picker.h" - +#include "script_editor_plugin.h" class ScriptTextEditor : public ScriptEditorBase { - GDCLASS( ScriptTextEditor, ScriptEditorBase ); + GDCLASS(ScriptTextEditor, ScriptEditorBase); CodeTextEditor *code_editor; Ref<Script> script; - Vector<String> functions; HBoxContainer *edit_hb; MenuButton *edit_menu; MenuButton *search_menu; - PopupMenu *context_menu; + PopupMenu *context_menu; GotoLineDialog *goto_line_dialog; ScriptEditorQuickOpen *quick_open; @@ -88,16 +86,13 @@ class ScriptTextEditor : public ScriptEditorBase { HELP_CONTEXTUAL, }; - protected: - - - static void _code_complete_scripts(void* p_ud,const String& p_code, List<String>* r_options); + static void _code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options); void _breakpoint_toggled(int p_row); //no longer virtual void _validate_script(); - void _code_complete_script(const String& p_code, List<String>* r_options); + void _code_complete_script(const String &p_code, List<String> *r_options); void _load_theme_settings(); void _notification(int p_what); @@ -105,43 +100,42 @@ protected: void _edit_option(int p_op); void _make_context_menu(bool p_selection, bool p_color); - void _text_edit_gui_input(const InputEvent& ev); - void _color_changed(const Color& p_color); + void _text_edit_gui_input(const InputEvent &ev); + void _color_changed(const Color &p_color); void _goto_line(int p_line) { goto_line(p_line); } - void _lookup_symbol(const String& p_symbol,int p_row, int p_column); + void _lookup_symbol(const String &p_symbol, int p_row, int p_column); - 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); public: - virtual void apply_code(); virtual Ref<Script> get_edited_script() const; - virtual Vector<String> get_functions() ; - virtual void set_edited_script(const Ref<Script>& p_script); + virtual Vector<String> get_functions(); + virtual void set_edited_script(const Ref<Script> &p_script); virtual void reload_text(); - virtual String get_name() ; - virtual Ref<Texture> get_icon() ; + virtual String get_name(); + virtual Ref<Texture> get_icon(); virtual bool is_unsaved(); virtual Variant get_edit_state(); - virtual void set_edit_state(const Variant& p_state); + virtual void set_edit_state(const Variant &p_state); virtual void ensure_focus(); virtual void trim_trailing_whitespace(); virtual void tag_saved_version(); - virtual void goto_line(int p_line,bool p_with_error=false); + virtual void goto_line(int p_line, bool p_with_error = false); virtual void reload(bool p_soft); virtual void get_breakpoints(List<int> *p_breakpoints); - virtual void add_callback(const String& p_function,PoolStringArray p_args); + virtual void add_callback(const String &p_function, PoolStringArray p_args); virtual void update_settings(); - virtual bool goto_method(const String& p_method); + virtual bool goto_method(const String &p_method); - virtual void set_tooltip_request_func(String p_method,Object* p_obj); + virtual void set_tooltip_request_func(String p_method, Object *p_obj); virtual void set_debugger_active(bool p_active); @@ -150,10 +144,6 @@ public: static void register_editor(); ScriptTextEditor(); - }; - - - #endif // SCRIPT_TEXT_EDITOR_H diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index c14d1650fd..c295a6679e 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -28,113 +28,99 @@ /*************************************************************************/ #include "shader_editor_plugin.h" +#include "editor/editor_node.h" #include "editor/editor_settings.h" -#include "spatial_editor_plugin.h" -#include "scene/resources/shader_graph.h" +#include "editor/property_editor.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/keyboard.h" -#include "editor/editor_node.h" -#include "editor/property_editor.h" #include "os/os.h" +#include "scene/resources/shader_graph.h" #include "servers/visual/shader_types.h" +#include "spatial_editor_plugin.h" /*** SETTINGS EDITOR ****/ - - - /*** SCRIPT EDITOR ****/ - Ref<Shader> ShaderTextEditor::get_edited_shader() const { return shader; } -void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader) { - - shader=p_shader; +void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) { + shader = p_shader; _load_theme_settings(); get_text_edit()->set_text(p_shader->get_code()); _line_col_changed(); - - } - void ShaderTextEditor::_load_theme_settings() { get_text_edit()->clear_colors(); /* keyword color */ - get_text_edit()->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color",Color(0,0,0,0))); - get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0,0,0,0))); + get_text_edit()->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0))); + get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0, 0, 0, 0))); get_text_edit()->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/highlighting/completion_selected_color", Color::html("434244"))); get_text_edit()->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf"))); get_text_edit()->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/highlighting/completion_scroll_color", Color::html("ffffff"))); get_text_edit()->add_color_override("completion_font_color", EDITOR_DEF("text_editor/highlighting/completion_font_color", Color::html("aaaaaa"))); - get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/highlighting/text_color",Color(0,0,0))); - get_text_edit()->add_color_override("line_number_color",EDITOR_DEF("text_editor/highlighting/line_number_color",Color(0,0,0))); - get_text_edit()->add_color_override("caret_color",EDITOR_DEF("text_editor/highlighting/caret_color",Color(0,0,0))); - get_text_edit()->add_color_override("caret_background_color",EDITOR_DEF("text_editor/highlighting/caret_background_color",Color(0,0,0))); - get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/highlighting/text_selected_color",Color(1,1,1))); - get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/highlighting/selection_color",Color(0.2,0.2,1))); - get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/highlighting/brace_mismatch_color",Color(1,0.2,0.2))); - get_text_edit()->add_color_override("current_line_color",EDITOR_DEF("text_editor/highlighting/current_line_color",Color(0.3,0.5,0.8,0.15))); - get_text_edit()->add_color_override("word_highlighted_color",EDITOR_DEF("text_editor/highlighting/word_highlighted_color",Color(0.8,0.9,0.9,0.15))); - get_text_edit()->add_color_override("number_color",EDITOR_DEF("text_editor/highlighting/number_color",Color(0.9,0.6,0.0,2))); - get_text_edit()->add_color_override("function_color",EDITOR_DEF("text_editor/highlighting/function_color",Color(0.4,0.6,0.8))); - get_text_edit()->add_color_override("member_variable_color",EDITOR_DEF("text_editor/highlighting/member_variable_color",Color(0.9,0.3,0.3))); - get_text_edit()->add_color_override("mark_color", EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0,0.4,0.4,0.4))); - get_text_edit()->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8,0.8,0.4,0.2))); - get_text_edit()->add_color_override("search_result_color",EDITOR_DEF("text_editor/highlighting/search_result_color",Color(0.05,0.25,0.05,1))); - get_text_edit()->add_color_override("search_result_border_color",EDITOR_DEF("text_editor/highlighting/search_result_border_color",Color(0.1,0.45,0.1,1))); - get_text_edit()->add_color_override("symbol_color",EDITOR_DEF("text_editor/highlighting/symbol_color",Color::hex(0x005291ff))); - - Color keyword_color= EDITOR_DEF("text_editor/highlighting/keyword_color",Color(0.5,0.0,0.2)); - + get_text_edit()->add_color_override("font_color", EDITOR_DEF("text_editor/highlighting/text_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("line_number_color", EDITOR_DEF("text_editor/highlighting/line_number_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("caret_color", EDITOR_DEF("text_editor/highlighting/caret_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("caret_background_color", EDITOR_DEF("text_editor/highlighting/caret_background_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("font_selected_color", EDITOR_DEF("text_editor/highlighting/text_selected_color", Color(1, 1, 1))); + get_text_edit()->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1))); + get_text_edit()->add_color_override("brace_mismatch_color", EDITOR_DEF("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2))); + get_text_edit()->add_color_override("current_line_color", EDITOR_DEF("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15))); + get_text_edit()->add_color_override("word_highlighted_color", EDITOR_DEF("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15))); + get_text_edit()->add_color_override("number_color", EDITOR_DEF("text_editor/highlighting/number_color", Color(0.9, 0.6, 0.0, 2))); + get_text_edit()->add_color_override("function_color", EDITOR_DEF("text_editor/highlighting/function_color", Color(0.4, 0.6, 0.8))); + get_text_edit()->add_color_override("member_variable_color", EDITOR_DEF("text_editor/highlighting/member_variable_color", Color(0.9, 0.3, 0.3))); + get_text_edit()->add_color_override("mark_color", EDITOR_DEF("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4))); + get_text_edit()->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2))); + get_text_edit()->add_color_override("search_result_color", EDITOR_DEF("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1))); + get_text_edit()->add_color_override("search_result_border_color", EDITOR_DEF("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1))); + get_text_edit()->add_color_override("symbol_color", EDITOR_DEF("text_editor/highlighting/symbol_color", Color::hex(0x005291ff))); + + Color keyword_color = EDITOR_DEF("text_editor/highlighting/keyword_color", Color(0.5, 0.0, 0.2)); List<String> keywords; ShaderLanguage::get_keyword_list(&keywords); if (shader.is_valid()) { + for (const Map<StringName, Map<StringName, ShaderLanguage::DataType> >::Element *E = ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) { - for(const Map< StringName, Map<StringName,ShaderLanguage::DataType> >::Element *E=ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front();E;E=E->next()) { - - for (const Map<StringName,ShaderLanguage::DataType>::Element *F=E->get().front();F;F=F->next()) { + for (const Map<StringName, ShaderLanguage::DataType>::Element *F = E->get().front(); F; F = F->next()) { keywords.push_back(F->key()); } - } - for(const Set<String>::Element *E =ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front();E;E=E->next()) { + for (const Set<String>::Element *E = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) { keywords.push_back(E->get()); - } } + for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - for(List<String>::Element *E=keywords.front();E;E=E->next()) { - - get_text_edit()->add_keyword_color(E->get(),keyword_color); + get_text_edit()->add_keyword_color(E->get(), keyword_color); } //colorize core types //Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0)); - //colorize comments - Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color",Color::hex(0x797e7eff)); + Color comment_color = EDITOR_DEF("text_editor/highlighting/comment_color", Color::hex(0x797e7eff)); - get_text_edit()->add_color_region("/*","*/",comment_color,false); - get_text_edit()->add_color_region("//","",comment_color,false); + get_text_edit()->add_color_region("/*", "*/", comment_color, false); + get_text_edit()->add_color_region("//", "", comment_color, false); /*//colorize strings Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff)); @@ -151,38 +137,38 @@ void ShaderTextEditor::_load_theme_settings() { }*/ } -void ShaderTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) { +void ShaderTextEditor::_code_complete_script(const String &p_code, List<String> *r_options) { print_line("code complete"); ShaderLanguage sl; String calltip; - Error err = sl.complete(p_code,ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())),ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())),r_options,calltip); + Error err = sl.complete(p_code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())), r_options, calltip); - if (calltip!="") { + if (calltip != "") { get_text_edit()->set_code_hint(calltip); } } void ShaderTextEditor::_validate_script() { - String code=get_text_edit()->get_text(); + String code = get_text_edit()->get_text(); //List<StringName> params; //shader->get_param_list(¶ms); ShaderLanguage sl; - Error err = sl.compile(code,ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())),ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode()))); + Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode()))); - if (err!=OK) { - String error_text="error("+itos(sl.get_error_line())+"): "+sl.get_error_text(); + if (err != OK) { + String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); set_error(error_text); - get_text_edit()->set_line_as_marked(sl.get_error_line(),true); + get_text_edit()->set_line_as_marked(sl.get_error_line(), true); } else { - for(int i=0;i<get_text_edit()->get_line_count();i++) - get_text_edit()->set_line_as_marked(i,false); + for (int i = 0; i < get_text_edit()->get_line_count(); i++) + get_text_edit()->set_line_as_marked(i, false); set_error(""); } @@ -191,29 +177,21 @@ void ShaderTextEditor::_validate_script() { void ShaderTextEditor::_bind_methods() { - //ADD_SIGNAL( MethodInfo("script_changed") ); - } ShaderTextEditor::ShaderTextEditor() { - - } /*** SCRIPT EDITOR ******/ - - void ShaderEditor::_menu_option(int p_option) { - ShaderTextEditor *current = shader_editor; - switch(p_option) { + switch (p_option) { case EDIT_UNDO: { - current->get_text_edit()->undo(); } break; case EDIT_REDO: { @@ -260,29 +238,21 @@ void ShaderEditor::_menu_option(int p_option) { goto_line_dialog->popup_find_line(current->get_text_edit()); } break; - } } - void ShaderEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { - - + if (p_what == NOTIFICATION_ENTER_TREE) { } - if (p_what==NOTIFICATION_DRAW) { + if (p_what == NOTIFICATION_DRAW) { RID ci = get_canvas_item(); - Ref<StyleBox> style = get_stylebox("panel","Panel"); - style->draw( ci, Rect2( Point2(), get_size() ) ); - + Ref<StyleBox> style = get_stylebox("panel", "Panel"); + style->draw(ci, Rect2(Point2(), get_size())); } - } - - Dictionary ShaderEditor::get_state() const { #if 0 apply_shaders(); @@ -326,7 +296,7 @@ Dictionary ShaderEditor::get_state() const { #endif return Dictionary(); } -void ShaderEditor::set_state(const Dictionary& p_state) { +void ShaderEditor::set_state(const Dictionary &p_state) { #if 0 print_line("setting state.."); if (!p_state.has("sources")) @@ -365,43 +335,41 @@ void ShaderEditor::set_state(const Dictionary& p_state) { #endif } void ShaderEditor::clear() { - } void ShaderEditor::_params_changed() { - shader_editor->_validate_script(); } void ShaderEditor::_editor_settings_changed() { - shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); - shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); - shader_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size")); - shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); - shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); - shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); - shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); - shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink")); - shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); - shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing")); - shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); + shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); + shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); + shader_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size")); + shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); + shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); + shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); + shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); + shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink")); + shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); + shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing")); + shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); } void ShaderEditor::_bind_methods() { - ClassDB::bind_method("_editor_settings_changed",&ShaderEditor::_editor_settings_changed); + ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed); - ClassDB::bind_method("_menu_option",&ShaderEditor::_menu_option); - ClassDB::bind_method("_params_changed",&ShaderEditor::_params_changed); - ClassDB::bind_method("apply_shaders",&ShaderEditor::apply_shaders); + ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option); + ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed); + ClassDB::bind_method("apply_shaders", &ShaderEditor::apply_shaders); //ClassDB::bind_method("_close_current_tab",&ShaderEditor::_close_current_tab); } void ShaderEditor::ensure_select_current() { -/* + /* if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) { ShaderTextEditor *ste = tab_container->get_child(tab_container->get_current_tab())->cast_to<ShaderTextEditor>(); @@ -412,20 +380,17 @@ void ShaderEditor::ensure_select_current() { }*/ } -void ShaderEditor::edit(const Ref<Shader>& p_shader) { +void ShaderEditor::edit(const Ref<Shader> &p_shader) { if (p_shader.is_null()) return; - - shader=p_shader; + shader = p_shader; shader_editor->set_edited_shader(p_shader); //vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX); // see if already has it - - } void ShaderEditor::save_external_data() { @@ -434,14 +399,13 @@ void ShaderEditor::save_external_data() { return; apply_shaders(); - if (shader->get_path()!="" && shader->get_path().find("local://")==-1 &&shader->get_path().find("::")==-1) { + if (shader->get_path() != "" && shader->get_path().find("local://") == -1 && shader->get_path().find("::") == -1) { //external shader, save it - ResourceSaver::save(shader->get_path(),shader); + ResourceSaver::save(shader->get_path(), shader); } } -void ShaderEditor::apply_shaders() { - +void ShaderEditor::apply_shaders() { if (shader.is_valid()) { shader->set_code(shader_editor->get_text_edit()->get_text()); @@ -449,75 +413,68 @@ void ShaderEditor::apply_shaders() { } } - ShaderEditor::ShaderEditor() { - - HBoxContainer *hbc = memnew( HBoxContainer); + HBoxContainer *hbc = memnew(HBoxContainer); add_child(hbc); - edit_menu = memnew( MenuButton ); + edit_menu = memnew(MenuButton); hbc->add_child(edit_menu); - edit_menu->set_pos(Point2(5,-1)); + edit_menu->set_pos(Point2(5, -1)); edit_menu->set_text(TTR("Edit")); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD|KEY_Z), EDIT_UNDO); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD|KEY_Y), EDIT_REDO); + edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z), EDIT_UNDO); + edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y), EDIT_REDO); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD|KEY_X), EDIT_CUT); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD|KEY_C), EDIT_COPY); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD|KEY_V), EDIT_PASTE); + edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X), EDIT_CUT); + edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C), EDIT_COPY); + edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V), EDIT_PASTE); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD|KEY_A), EDIT_SELECT_ALL); - edit_menu->get_popup()->connect("id_pressed", this,"_menu_option"); + edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A), EDIT_SELECT_ALL); + edit_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - - search_menu = memnew( MenuButton ); + search_menu = memnew(MenuButton); hbc->add_child(search_menu); - search_menu->set_pos(Point2(38,-1)); + search_menu->set_pos(Point2(38, -1)); search_menu->set_text(TTR("Search")); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD|KEY_F), SEARCH_FIND); + search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F), SEARCH_FIND); search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), SEARCH_FIND_NEXT); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT|KEY_F3), SEARCH_FIND_PREV); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD|KEY_R), SEARCH_REPLACE); + search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3), SEARCH_FIND_PREV); + search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD | KEY_R), SEARCH_REPLACE); search_menu->get_popup()->add_separator(); //search_menu->get_popup()->add_item("Locate Symbol..",SEARCH_LOCATE_SYMBOL,KEY_MASK_CMD|KEY_K); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD|KEY_L), SEARCH_GOTO_LINE); - search_menu->get_popup()->connect("id_pressed", this,"_menu_option"); - + search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD | KEY_L), SEARCH_GOTO_LINE); + search_menu->get_popup()->connect("id_pressed", this, "_menu_option"); goto_line_dialog = memnew(GotoLineDialog); add_child(goto_line_dialog); - shader_editor = memnew( ShaderTextEditor ); + shader_editor = memnew(ShaderTextEditor); add_child(shader_editor); shader_editor->set_v_size_flags(SIZE_EXPAND_FILL); - - shader_editor->connect("script_changed", this,"apply_shaders"); - EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed"); + shader_editor->connect("script_changed", this, "apply_shaders"); + EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); _editor_settings_changed(); } - void ShaderEditorPlugin::edit(Object *p_object) { - Shader* s = p_object->cast_to<Shader>(); + Shader *s = p_object->cast_to<Shader>(); shader_editor->edit(s); - } bool ShaderEditorPlugin::handles(Object *p_object) const { bool handles = true; - Shader *shader=p_object->cast_to<Shader>(); + Shader *shader = p_object->cast_to<Shader>(); /* if (!shader || shader->cast_to<ShaderGraph>()) // Dont handle ShaderGraph's handles = false; */ - return shader!=NULL; + return shader != NULL; } void ShaderEditorPlugin::make_visible(bool p_visible) { @@ -532,9 +489,7 @@ void ShaderEditorPlugin::make_visible(bool p_visible) { if (shader_editor->is_visible_in_tree()) editor->hide_bottom_panel(); shader_editor->apply_shaders(); - } - } void ShaderEditorPlugin::selected_notify() { @@ -547,7 +502,7 @@ Dictionary ShaderEditorPlugin::get_state() const { return shader_editor->get_state(); } -void ShaderEditorPlugin::set_state(const Dictionary& p_state) { +void ShaderEditorPlugin::set_state(const Dictionary &p_state) { shader_editor->set_state(p_state); } @@ -568,17 +523,12 @@ void ShaderEditorPlugin::apply_changes() { ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) { + editor = p_node; + shader_editor = memnew(ShaderEditor); - editor=p_node; - shader_editor = memnew( ShaderEditor ); - - shader_editor->set_custom_minimum_size(Size2(0,300)); - button=editor->add_bottom_panel_item("Shader",shader_editor); - + shader_editor->set_custom_minimum_size(Size2(0, 300)); + button = editor->add_bottom_panel_item("Shader", shader_editor); } - ShaderEditorPlugin::~ShaderEditorPlugin() { } - - diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 703913e431..4a56c14ecb 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -31,41 +31,36 @@ #include "editor/code_editor.h" #include "editor/editor_plugin.h" +#include "scene/gui/menu_button.h" #include "scene/gui/tab_container.h" #include "scene/gui/text_edit.h" -#include "scene/gui/menu_button.h" #include "scene/main/timer.h" #include "scene/resources/shader.h" #include "servers/visual/shader_language.h" class ShaderTextEditor : public CodeTextEditor { - GDCLASS( ShaderTextEditor, CodeTextEditor ); + GDCLASS(ShaderTextEditor, CodeTextEditor); Ref<Shader> shader; protected: - static void _bind_methods(); virtual void _load_theme_settings(); - virtual void _code_complete_script(const String& p_code, List<String>* r_options); + virtual void _code_complete_script(const String &p_code, List<String> *r_options); public: - virtual void _validate_script(); - Ref<Shader> get_edited_shader() const; - void set_edited_shader(const Ref<Shader>& p_shader); + void set_edited_shader(const Ref<Shader> &p_shader); ShaderTextEditor(); - }; - class ShaderEditor : public VBoxContainer { - GDCLASS(ShaderEditor, VBoxContainer ); + GDCLASS(ShaderEditor, VBoxContainer); enum { @@ -92,32 +87,29 @@ class ShaderEditor : public VBoxContainer { GotoLineDialog *goto_line_dialog; ConfirmationDialog *erase_tab_confirm; - ShaderTextEditor *shader_editor; - void _menu_option(int p_optin); void _params_changed(); mutable Ref<Shader> shader; - void _editor_settings_changed(); protected: void _notification(int p_what); static void _bind_methods(); -public: +public: void apply_shaders(); void ensure_select_current(); - void edit(const Ref<Shader>& p_shader); + void edit(const Ref<Shader> &p_shader); Dictionary get_state() const; - void set_state(const Dictionary& p_state); + void set_state(const Dictionary &p_state); void clear(); - virtual Size2 get_minimum_size() const { return Size2(0,200); } + virtual Size2 get_minimum_size() const { return Size2(0, 200); } void save_external_data(); ShaderEditor(); @@ -125,7 +117,7 @@ public: class ShaderEditorPlugin : public EditorPlugin { - GDCLASS( ShaderEditorPlugin, EditorPlugin ); + GDCLASS(ShaderEditorPlugin, EditorPlugin); bool _2d; ShaderEditor *shader_editor; @@ -133,7 +125,6 @@ class ShaderEditorPlugin : public EditorPlugin { Button *button; public: - virtual String get_name() const { return "Shader"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -142,7 +133,7 @@ public: virtual void selected_notify(); Dictionary get_state() const; - virtual void set_state(const Dictionary& p_state); + virtual void set_state(const Dictionary &p_state); virtual void clear(); virtual void save_external_data(); @@ -150,7 +141,6 @@ public: ShaderEditorPlugin(EditorNode *p_node); ~ShaderEditorPlugin(); - }; #endif diff --git a/editor/plugins/shader_graph_editor_plugin.cpp b/editor/plugins/shader_graph_editor_plugin.cpp index dac63b4a9f..d55c133dc9 100644 --- a/editor/plugins/shader_graph_editor_plugin.cpp +++ b/editor/plugins/shader_graph_editor_plugin.cpp @@ -30,12 +30,12 @@ #if 0 +#include "canvas_item_editor_plugin.h" +#include "os/keyboard.h" #include "scene/gui/check_box.h" #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" #include "spatial_editor_plugin.h" -#include "os/keyboard.h" -#include "canvas_item_editor_plugin.h" void GraphColorRampEdit::_gui_input(const InputEvent& p_event) { @@ -2943,6 +2943,4 @@ ShaderGraphEditorPlugin::~ShaderGraphEditorPlugin() { } - - #endif diff --git a/editor/plugins/shader_graph_editor_plugin.h b/editor/plugins/shader_graph_editor_plugin.h index 5143722242..e5c59f82f4 100644 --- a/editor/plugins/shader_graph_editor_plugin.h +++ b/editor/plugins/shader_graph_editor_plugin.h @@ -29,15 +29,14 @@ #ifndef SHADER_GRAPH_EDITOR_PLUGIN_H #define SHADER_GRAPH_EDITOR_PLUGIN_H - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "scene/resources/shader.h" -#include "scene/gui/tree.h" +#include "editor/editor_plugin.h" +#include "editor/property_editor.h" #include "scene/gui/button.h" #include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" -#include "editor/property_editor.h" +#include "scene/gui/tree.h" +#include "scene/resources/shader.h" #include "scene/resources/shader_graph.h" /** @author Juan Linietsky <reduzio@gmail.com> diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 8a7969c71b..fcfb20bd7d 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -28,35 +28,32 @@ /*************************************************************************/ #include "spatial_editor_plugin.h" -#include "print_string.h" -#include "os/keyboard.h" -#include "scene/3d/visual_instance.h" -#include "scene/3d/camera.h" #include "camera_matrix.h" -#include "sort.h" +#include "editor/animation_editor.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" -#include "scene/resources/surface_tool.h" +#include "editor/plugins/animation_player_editor_plugin.h" #include "editor/spatial_editor_gizmos.h" #include "global_config.h" -#include "editor/plugins/animation_player_editor_plugin.h" -#include "editor/animation_editor.h" +#include "os/keyboard.h" +#include "print_string.h" +#include "scene/3d/camera.h" +#include "scene/3d/visual_instance.h" +#include "scene/resources/surface_tool.h" +#include "sort.h" #define DISTANCE_DEFAULT 4 - #define GIZMO_ARROW_SIZE 0.3 #define GIZMO_RING_HALF_WIDTH 0.1 //#define GIZMO_SCALE_DEFAULT 0.28 #define GIZMO_SCALE_DEFAULT 0.15 - void SpatialEditorViewport::_update_camera() { if (orthogonal) { //camera->set_orthogonal(size.width*cursor.distance,get_znear(),get_zfar()); camera->set_orthogonal(2 * cursor.distance, 0.1, 8192); - } - else + } else camera->set_perspective(get_fov(), get_znear(), get_zfar()); Transform camera_transform; @@ -83,7 +80,7 @@ String SpatialEditorGizmo::get_handle_name(int p_idx) const { return ""; } -Variant SpatialEditorGizmo::get_handle_value(int p_idx) const{ +Variant SpatialEditorGizmo::get_handle_value(int p_idx) const { if (get_script_instance() && get_script_instance()->has_method("get_handle_value")) return get_script_instance()->call("get_handle_value", p_idx); @@ -91,49 +88,46 @@ Variant SpatialEditorGizmo::get_handle_value(int p_idx) const{ return Variant(); } -void SpatialEditorGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_point) { +void SpatialEditorGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) { if (get_script_instance() && get_script_instance()->has_method("set_handle")) get_script_instance()->call("set_handle", p_idx, p_camera, p_point); } -void SpatialEditorGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_cancel){ +void SpatialEditorGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { if (get_script_instance() && get_script_instance()->has_method("commit_handle")) get_script_instance()->call("commit_handle", p_idx, p_restore, p_cancel); } -bool SpatialEditorGizmo::intersect_frustum(const Camera *p_camera,const Vector<Plane> &p_frustum) { +bool SpatialEditorGizmo::intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum) { return false; } -bool SpatialEditorGizmo::intersect_ray(const Camera *p_camera, const Point2 &p_point, Vector3& r_pos, Vector3& r_normal,int *r_gizmo_handle,bool p_sec_first) { +bool SpatialEditorGizmo::intersect_ray(const Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle, bool p_sec_first) { return false; } -SpatialEditorGizmo::SpatialEditorGizmo(){ +SpatialEditorGizmo::SpatialEditorGizmo() { - selected=false; + selected = false; } - - int SpatialEditorViewport::get_selected_count() const { + Map<Node *, Object *> &selection = editor_selection->get_selection(); - Map<Node*,Object*> &selection = editor_selection->get_selection(); - - int count=0; + int count = 0; - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->key()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; @@ -143,36 +137,30 @@ int SpatialEditorViewport::get_selected_count() const { return count; } - - float SpatialEditorViewport::get_znear() const { float val = spatial_editor->get_znear(); - if (val<0.001) - val=0.001; + if (val < 0.001) + val = 0.001; return val; } -float SpatialEditorViewport::get_zfar() const{ +float SpatialEditorViewport::get_zfar() const { float val = spatial_editor->get_zfar(); - if (val<0.001) - val=0.001; + if (val < 0.001) + val = 0.001; return val; - } -float SpatialEditorViewport::get_fov() const{ +float SpatialEditorViewport::get_fov() const { float val = spatial_editor->get_fov(); - if (val<0.001) - val=0.001; - if (val>89) - val=89; + if (val < 0.001) + val = 0.001; + if (val > 89) + val = 89; return val; - } - - Transform SpatialEditorViewport::_get_camera_transform() const { return camera->get_global_transform(); @@ -183,29 +171,24 @@ Vector3 SpatialEditorViewport::_get_camera_pos() const { return _get_camera_transform().origin; } -Point2 SpatialEditorViewport::_point_to_screen(const Vector3& p_point) { +Point2 SpatialEditorViewport::_point_to_screen(const Vector3 &p_point) { return camera->unproject_position(p_point); - } -Vector3 SpatialEditorViewport::_get_ray_pos(const Vector2& p_pos) const { +Vector3 SpatialEditorViewport::_get_ray_pos(const Vector2 &p_pos) const { return camera->project_ray_origin(p_pos); } - Vector3 SpatialEditorViewport::_get_camera_normal() const { return -_get_camera_transform().basis.get_axis(2); } -Vector3 SpatialEditorViewport::_get_ray(const Vector2& p_pos) { - +Vector3 SpatialEditorViewport::_get_ray(const Vector2 &p_pos) { return camera->project_ray_normal(p_pos); - - } /* void SpatialEditorViewport::_clear_id(Spatial *p_node) { @@ -221,9 +204,7 @@ void SpatialEditorViewport::_clear_selected() { editor_selection->clear(); } - - -void SpatialEditorViewport::_select_clicked(bool p_append,bool p_single) { +void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single) { if (!clicked) return; @@ -232,18 +213,14 @@ void SpatialEditorViewport::_select_clicked(bool p_append,bool p_single) { if (!obj) return; - Spatial *sp = obj->cast_to<Spatial>(); if (!sp) return; - _select(sp, clicked_wants_append,true); + _select(sp, clicked_wants_append, true); } - - -void SpatialEditorViewport::_select(Spatial *p_node, bool p_append,bool p_single) { - +void SpatialEditorViewport::_select(Spatial *p_node, bool p_append, bool p_single) { if (!p_append) { @@ -261,34 +238,32 @@ void SpatialEditorViewport::_select(Spatial *p_node, bool p_append,bool p_single editor_selection->add_node(p_node); } - } - } -ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,bool &r_includes_current,int *r_gizmo_handle,bool p_alt_select) { +ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle, bool p_alt_select) { if (r_gizmo_handle) - *r_gizmo_handle=-1; + *r_gizmo_handle = -1; - Vector3 ray=_get_ray(p_pos); - Vector3 pos=_get_ray_pos(p_pos); + Vector3 ray = _get_ray(p_pos); + Vector3 pos = _get_ray_pos(p_pos); - Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() ); + Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario()); Set<Ref<SpatialEditorGizmo> > found_gizmos; - ObjectID closest=0; - Spatial *item=NULL; - float closest_dist=1e20; - int selected_handle=-1; + ObjectID closest = 0; + Spatial *item = NULL; + float closest_dist = 1e20; + int selected_handle = -1; - for (int i=0;i<instances.size();i++) { + for (int i = 0; i < instances.size(); i++) { - Object *obj=ObjectDB::get_instance(instances[i]); + Object *obj = ObjectDB::get_instance(instances[i]); if (!obj) continue; - Spatial *spat=obj->cast_to<Spatial>(); + Spatial *spat = obj->cast_to<Spatial>(); if (!spat) continue; @@ -305,62 +280,58 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b Vector3 point; Vector3 normal; - int handle=-1; - bool inters = seg->intersect_ray(camera,p_pos,point,normal,NULL,p_alt_select); + int handle = -1; + bool inters = seg->intersect_ray(camera, p_pos, point, normal, NULL, p_alt_select); if (!inters) continue; float dist = pos.distance_to(point); - if (dist<0) + if (dist < 0) continue; if (dist < closest_dist) { - closest=instances[i]; - closest_dist=dist; - selected_handle=handle; - item=spat; + closest = instances[i]; + closest_dist = dist; + selected_handle = handle; + item = spat; } - // if (editor_selection->is_selected(spat)) - // r_includes_current=true; - + // if (editor_selection->is_selected(spat)) + // r_includes_current=true; } - if (!item) return 0; - if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle>=0)) { + if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle >= 0)) { if (r_gizmo_handle) - *r_gizmo_handle=selected_handle; - + *r_gizmo_handle = selected_handle; } return closest; - } -void SpatialEditorViewport::_find_items_at_pos(const Point2& p_pos,bool &r_includes_current,Vector<_RayResult> &results,bool p_alt_select) { +void SpatialEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select) { - Vector3 ray=_get_ray(p_pos); - Vector3 pos=_get_ray_pos(p_pos); + Vector3 ray = _get_ray(p_pos); + Vector3 pos = _get_ray_pos(p_pos); - Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() ); + Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario()); Set<Ref<SpatialEditorGizmo> > found_gizmos; - r_includes_current=false; + r_includes_current = false; - for (int i=0;i<instances.size();i++) { + for (int i = 0; i < instances.size(); i++) { - Object *obj=ObjectDB::get_instance(instances[i]); + Object *obj = ObjectDB::get_instance(instances[i]); if (!obj) continue; - Spatial *spat=obj->cast_to<Spatial>(); + Spatial *spat = obj->cast_to<Spatial>(); if (!spat) continue; @@ -377,112 +348,100 @@ void SpatialEditorViewport::_find_items_at_pos(const Point2& p_pos,bool &r_inclu Vector3 point; Vector3 normal; - int handle=-1; - bool inters = seg->intersect_ray(camera,p_pos,point,normal,NULL,p_alt_select); + int handle = -1; + bool inters = seg->intersect_ray(camera, p_pos, point, normal, NULL, p_alt_select); if (!inters) continue; float dist = pos.distance_to(point); - if (dist<0) + if (dist < 0) continue; - - if (editor_selection->is_selected(spat)) - r_includes_current=true; + r_includes_current = true; _RayResult res; - res.item=spat; - res.depth=dist; - res.handle=handle; + res.item = spat; + res.depth = dist; + res.handle = handle; results.push_back(res); } - if (results.empty()) return; results.sort(); } - -Vector3 SpatialEditorViewport::_get_screen_to_space(const Vector3& p_pos) { - +Vector3 SpatialEditorViewport::_get_screen_to_space(const Vector3 &p_pos) { CameraMatrix cm; - cm.set_perspective(get_fov(),get_size().aspect(),get_znear(),get_zfar()); - float screen_w,screen_h; - cm.get_viewport_size(screen_w,screen_h); + cm.set_perspective(get_fov(), get_size().aspect(), get_znear(), get_zfar()); + float screen_w, screen_h; + cm.get_viewport_size(screen_w, screen_h); Transform camera_transform; - camera_transform.translate( cursor.pos ); - camera_transform.basis.rotate(Vector3(1,0,0),-cursor.x_rot); - camera_transform.basis.rotate(Vector3(0,1,0),-cursor.y_rot); - camera_transform.translate(0,0,cursor.distance); - - return camera_transform.xform(Vector3( ((p_pos.x/get_size().width)*2.0-1.0)*screen_w, ((1.0-(p_pos.y/get_size().height))*2.0-1.0)*screen_h,-get_znear())); + camera_transform.translate(cursor.pos); + camera_transform.basis.rotate(Vector3(1, 0, 0), -cursor.x_rot); + camera_transform.basis.rotate(Vector3(0, 1, 0), -cursor.y_rot); + camera_transform.translate(0, 0, cursor.distance); + return camera_transform.xform(Vector3(((p_pos.x / get_size().width) * 2.0 - 1.0) * screen_w, ((1.0 - (p_pos.y / get_size().height)) * 2.0 - 1.0) * screen_h, -get_znear())); } - void SpatialEditorViewport::_select_region() { - if (cursor.region_begin==cursor.region_end) + if (cursor.region_begin == cursor.region_end) return; //nothing really - Vector3 box[4]={ + Vector3 box[4] = { Vector3( - MIN( cursor.region_begin.x, cursor.region_end.x), - MIN( cursor.region_begin.y, cursor.region_end.y), - 0 - ), + MIN(cursor.region_begin.x, cursor.region_end.x), + MIN(cursor.region_begin.y, cursor.region_end.y), + 0), Vector3( - MAX( cursor.region_begin.x, cursor.region_end.x), - MIN( cursor.region_begin.y, cursor.region_end.y), - 0 - ), + MAX(cursor.region_begin.x, cursor.region_end.x), + MIN(cursor.region_begin.y, cursor.region_end.y), + 0), Vector3( - MAX( cursor.region_begin.x, cursor.region_end.x), - MAX( cursor.region_begin.y, cursor.region_end.y), - 0 - ), + MAX(cursor.region_begin.x, cursor.region_end.x), + MAX(cursor.region_begin.y, cursor.region_end.y), + 0), Vector3( - MIN( cursor.region_begin.x, cursor.region_end.x), - MAX( cursor.region_begin.y, cursor.region_end.y), - 0 - ) + MIN(cursor.region_begin.x, cursor.region_end.x), + MAX(cursor.region_begin.y, cursor.region_end.y), + 0) }; Vector<Plane> frustum; - Vector3 cam_pos=_get_camera_pos(); + Vector3 cam_pos = _get_camera_pos(); Set<Ref<SpatialEditorGizmo> > found_gizmos; - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { - Vector3 a=_get_screen_to_space(box[i]); - Vector3 b=_get_screen_to_space(box[(i+1)%4]); - frustum.push_back( Plane(a,b,cam_pos) ); + Vector3 a = _get_screen_to_space(box[i]); + Vector3 b = _get_screen_to_space(box[(i + 1) % 4]); + frustum.push_back(Plane(a, b, cam_pos)); } - Plane near( cam_pos, -_get_camera_normal() ); - near.d-=get_znear(); - - frustum.push_back( near ); + Plane near(cam_pos, -_get_camera_normal()); + near.d -= get_znear(); - Plane far=-near; - far.d+=500.0; + frustum.push_back(near); - frustum.push_back( far ); + Plane far = -near; + far.d += 500.0; - Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_convex(frustum,get_tree()->get_root()->get_world()->get_scenario()); + frustum.push_back(far); + Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_convex(frustum, get_tree()->get_root()->get_world()->get_scenario()); - for (int i=0;i<instances.size();i++) { + for (int i = 0; i < instances.size(); i++) { - Object *obj=ObjectDB::get_instance(instances[i]); + Object *obj = ObjectDB::get_instance(instances[i]); if (!obj) continue; Spatial *sp = obj->cast_to<Spatial>(); @@ -497,46 +456,44 @@ void SpatialEditorViewport::_select_region() { if (found_gizmos.has(seg)) continue; - if (seg->intersect_frustum(camera,frustum)) - _select(sp,true,false); + if (seg->intersect_frustum(camera, frustum)) + _select(sp, true, false); } - } void SpatialEditorViewport::_update_name() { - String ortho = orthogonal?TTR("Orthogonal"):TTR("Perspective"); + String ortho = orthogonal ? TTR("Orthogonal") : TTR("Perspective"); - if (name!="") - view_menu->set_text("[ "+name+" "+ortho+" ]"); + if (name != "") + view_menu->set_text("[ " + name + " " + ortho + " ]"); else - view_menu->set_text("[ "+ortho+" ]"); + view_menu->set_text("[ " + ortho + " ]"); } +void SpatialEditorViewport::_compute_edit(const Point2 &p_point) { -void SpatialEditorViewport::_compute_edit(const Point2& p_point) { - - _edit.click_ray=_get_ray( Vector2( p_point.x, p_point.y ) ); - _edit.click_ray_pos=_get_ray_pos( Vector2( p_point.x, p_point.y ) ); - _edit.plane=TRANSFORM_VIEW; + _edit.click_ray = _get_ray(Vector2(p_point.x, p_point.y)); + _edit.click_ray_pos = _get_ray_pos(Vector2(p_point.x, p_point.y)); + _edit.plane = TRANSFORM_VIEW; spatial_editor->update_transform_gizmo(); - _edit.center=spatial_editor->get_gizmo_transform().origin; + _edit.center = spatial_editor->get_gizmo_transform().origin; - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); //Vector3 center; //int nc=0; - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; - se->original=se->sp->get_global_transform(); + se->original = se->sp->get_global_transform(); //center+=se->original.origin; //nc++; } @@ -547,9 +504,9 @@ void SpatialEditorViewport::_compute_edit(const Point2& p_point) { */ } -static int _get_key_modifier(const String& p_property) { +static int _get_key_modifier(const String &p_property) { - switch(EditorSettings::get_singleton()->get(p_property).operator int()) { + switch (EditorSettings::get_singleton()->get(p_property).operator int()) { case 0: return 0; case 1: return KEY_SHIFT; @@ -560,181 +517,164 @@ static int _get_key_modifier(const String& p_property) { return 0; } -bool SpatialEditorViewport::_gizmo_select(const Vector2& p_screenpos,bool p_hilite_only) { +bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hilite_only) { if (!spatial_editor->is_gizmo_visible()) return false; - if (get_selected_count()==0) { + if (get_selected_count() == 0) { if (p_hilite_only) spatial_editor->select_gizmo_hilight_axis(-1); return false; } - - Vector3 ray_pos=_get_ray_pos( Vector2( p_screenpos.x, p_screenpos.y ) ); - Vector3 ray=_get_ray( Vector2( p_screenpos.x, p_screenpos.y ) ); + Vector3 ray_pos = _get_ray_pos(Vector2(p_screenpos.x, p_screenpos.y)); + Vector3 ray = _get_ray(Vector2(p_screenpos.x, p_screenpos.y)); Transform gt = spatial_editor->get_gizmo_transform(); - float gs=gizmo_scale; + float gs = gizmo_scale; - if (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_MOVE) { + if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_MOVE) { - int col_axis=-1; - float col_d=1e20; + int col_axis = -1; + float col_d = 1e20; - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { - Vector3 grabber_pos = gt.origin+gt.basis.get_axis(i)*gs; - float grabber_radius = gs*GIZMO_ARROW_SIZE; + Vector3 grabber_pos = gt.origin + gt.basis.get_axis(i) * gs; + float grabber_radius = gs * GIZMO_ARROW_SIZE; Vector3 r; - if (Geometry::segment_intersects_sphere(ray_pos,ray_pos+ray*10000.0,grabber_pos,grabber_radius,&r)) { + if (Geometry::segment_intersects_sphere(ray_pos, ray_pos + ray * 10000.0, grabber_pos, grabber_radius, &r)) { float d = r.distance_to(ray_pos); - if (d<col_d) { - col_d=d; - col_axis=i; + if (d < col_d) { + col_d = d; + col_axis = i; } } } - if (col_axis!=-1) { - + if (col_axis != -1) { if (p_hilite_only) { spatial_editor->select_gizmo_hilight_axis(col_axis); - } else { //handle rotate - _edit.mode=TRANSFORM_TRANSLATE; - _compute_edit(Point2(p_screenpos.x,p_screenpos.y)); - _edit.plane=TransformPlane(TRANSFORM_X_AXIS+col_axis); + _edit.mode = TRANSFORM_TRANSLATE; + _compute_edit(Point2(p_screenpos.x, p_screenpos.y)); + _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis); } return true; - - } - } + if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE) { - if (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_ROTATE) { + int col_axis = -1; + float col_d = 1e20; - int col_axis=-1; - float col_d=1e20; + for (int i = 0; i < 3; i++) { - for(int i=0;i<3;i++) { - - Plane plane(gt.origin,gt.basis.get_axis(i).normalized()); + Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); Vector3 r; - if (!plane.intersects_ray(ray_pos,ray,&r)) + if (!plane.intersects_ray(ray_pos, ray, &r)) continue; float dist = r.distance_to(gt.origin); - - - if (dist > gs*(1-GIZMO_RING_HALF_WIDTH) && dist < gs *(1+GIZMO_RING_HALF_WIDTH)) { + if (dist > gs * (1 - GIZMO_RING_HALF_WIDTH) && dist < gs * (1 + GIZMO_RING_HALF_WIDTH)) { float d = ray_pos.distance_to(r); - if (d<col_d) { - col_d=d; - col_axis=i; + if (d < col_d) { + col_d = d; + col_axis = i; } } } - if (col_axis!=-1) { + if (col_axis != -1) { if (p_hilite_only) { - spatial_editor->select_gizmo_hilight_axis(col_axis+3); + spatial_editor->select_gizmo_hilight_axis(col_axis + 3); } else { //handle rotate - _edit.mode=TRANSFORM_ROTATE; - _compute_edit(Point2(p_screenpos.x,p_screenpos.y)); - _edit.plane=TransformPlane(TRANSFORM_X_AXIS+col_axis); + _edit.mode = TRANSFORM_ROTATE; + _compute_edit(Point2(p_screenpos.x, p_screenpos.y)); + _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis); } return true; } } - if (p_hilite_only) spatial_editor->select_gizmo_hilight_axis(-1); return false; - } - void SpatialEditorViewport::_smouseenter() { - if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) - surface->grab_focus(); + if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) + surface->grab_focus(); } void SpatialEditorViewport::_list_select(InputEventMouseButton b) { - _find_items_at_pos(Vector2( b.x, b.y ),clicked_includes_current,selection_results,b.mod.shift); + _find_items_at_pos(Vector2(b.x, b.y), clicked_includes_current, selection_results, b.mod.shift); - Node *scene=editor->get_edited_scene(); + Node *scene = editor->get_edited_scene(); - for(int i=0;i<selection_results.size();i++) { - Spatial *item=selection_results[i].item; - if (item!=scene && item->get_owner()!=scene && !scene->is_editable_instance(item->get_owner())) { + for (int i = 0; i < selection_results.size(); i++) { + Spatial *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--; } - } - - clicked_wants_append=b.mod.shift; + clicked_wants_append = b.mod.shift; if (selection_results.size() == 1) { - clicked=selection_results[0].item->get_instance_ID(); + clicked = selection_results[0].item->get_instance_ID(); selection_results.clear(); if (clicked) { - _select_clicked(clicked_wants_append,true); - clicked=0; + _select_clicked(clicked_wants_append, true); + clicked = 0; } } else if (!selection_results.empty()) { 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++) { - Spatial *spat=selection_results[i].item; + Spatial *spat = selection_results[i].item; Ref<Texture> icon; if (spat->has_meta("_editor_icon")) - icon=spat->get_meta("_editor_icon"); + icon = spat->get_meta("_editor_icon"); else - icon=get_icon( has_icon(spat->get_class(),"EditorIcons")?spat->get_class():String("Object"),"EditorIcons"); + icon = get_icon(has_icon(spat->get_class(), "EditorIcons") ? spat->get_class() : String("Object"), "EditorIcons"); - String node_path="/"+root_name+"/"+root_path.rel_path_to(spat->get_path()); + String node_path = "/" + root_name + "/" + root_path.rel_path_to(spat->get_path()); selection_menu->add_item(spat->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(spat->get_name())+ - "\nType: "+spat->get_class()+"\nPath: "+node_path); + selection_menu->set_item_tooltip(i, String(spat->get_name()) + + "\nType: " + spat->get_class() + "\nPath: " + node_path); } - 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(); - - - } } void SpatialEditorViewport::_sinput(const InputEvent &p_event) { @@ -742,39 +682,37 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (previewing) return; //do NONE - { EditorNode *en = editor; EditorPluginList *over_plugin_list = en->get_editor_plugins_over(); if (!over_plugin_list->empty()) { - bool discard = over_plugin_list->forward_spatial_gui_input(camera,p_event); + bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event); if (discard) return; } } - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - const InputEventMouseButton &b=p_event.mouse_button; + const InputEventMouseButton &b = p_event.mouse_button; - switch(b.button_index) { + switch (b.button_index) { case BUTTON_WHEEL_UP: { - - cursor.distance/=1.08; - if (cursor.distance<0.001) - cursor.distance=0.001; + cursor.distance /= 1.08; + if (cursor.distance < 0.001) + cursor.distance = 0.001; } break; case BUTTON_WHEEL_DOWN: { - if (cursor.distance<0.001) - cursor.distance=0.001; - cursor.distance*=1.08; + if (cursor.distance < 0.001) + cursor.distance = 0.001; + cursor.distance *= 1.08; } break; case BUTTON_RIGHT: { @@ -783,81 +721,76 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (b.pressed && _edit.gizmo.is_valid()) { //restore - _edit.gizmo->commit_handle(_edit.gizmo_handle,_edit.gizmo_initial_value,true); - _edit.gizmo=Ref<SpatialEditorGizmo>(); + _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, true); + _edit.gizmo = Ref<SpatialEditorGizmo>(); } - if (_edit.mode==TRANSFORM_NONE && b.pressed) { - - Plane cursor_plane(cursor.cursor_pos,_get_camera_normal()); + if (_edit.mode == TRANSFORM_NONE && b.pressed) { - Vector3 ray_origin = _get_ray_pos(Vector2(b.x,b.y)); - Vector3 ray_dir = _get_ray(Vector2(b.x,b.y)); + Plane cursor_plane(cursor.cursor_pos, _get_camera_normal()); + Vector3 ray_origin = _get_ray_pos(Vector2(b.x, b.y)); + Vector3 ray_dir = _get_ray(Vector2(b.x, b.y)); //gizmo modify if (b.mod.control) { - Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(ray_origin,ray_dir,get_tree()->get_root()->get_world()->get_scenario() ); - - Plane p(ray_origin,_get_camera_normal()); + Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(ray_origin, ray_dir, get_tree()->get_root()->get_world()->get_scenario()); - float min_d=1e10; - bool found=false; + Plane p(ray_origin, _get_camera_normal()); - for (int i=0;i<instances.size();i++) { + float min_d = 1e10; + bool found = false; + for (int i = 0; i < instances.size(); i++) { - Object *obj=ObjectDB::get_instance(instances[i]); + Object *obj = ObjectDB::get_instance(instances[i]); if (!obj) continue; - VisualInstance *vi=obj->cast_to<VisualInstance>(); + VisualInstance *vi = obj->cast_to<VisualInstance>(); if (!vi) continue; //optimize by checking AABB (although should pre sort by distance) - Rect3 aabb = vi->get_global_transform().xform(vi->get_aabb()); - if (p.distance_to(aabb.get_support(-ray_dir))>min_d) + Rect3 aabb = vi->get_global_transform().xform(vi->get_aabb()); + if (p.distance_to(aabb.get_support(-ray_dir)) > min_d) continue; PoolVector<Face3> faces = vi->get_faces(VisualInstance::FACES_SOLID); int c = faces.size(); - if (c>0) { + if (c > 0) { PoolVector<Face3>::Read r = faces.read(); - for(int j=0;j<c;j++) { + for (int j = 0; j < c; j++) { Vector3 inters; - if (r[j].intersects_ray(ray_origin,ray_dir,&inters)) { + if (r[j].intersects_ray(ray_origin, ray_dir, &inters)) { float d = p.distance_to(inters); - if (d<0) + if (d < 0) continue; - if (d<min_d) { - min_d=d; - found=true; + if (d < min_d) { + min_d = d; + found = true; } } - } } - } if (found) { //cursor.cursor_pos=ray_origin+ray_dir*min_d; //VisualServer::get_singleton()->instance_set_transform(cursor_instance,Transform(Matrix3(),cursor.cursor_pos)); - } } else { Vector3 new_pos; - if (cursor_plane.intersects_ray(ray_origin,ray_dir,&new_pos)) { + if (cursor_plane.intersects_ray(ray_origin, ray_dir, &new_pos)) { //cursor.cursor_pos=new_pos; //VisualServer::get_singleton()->instance_set_transform(cursor_instance,Transform(Matrix3(),cursor.cursor_pos)); @@ -871,68 +804,65 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { _list_select(b); return; - } } - if (_edit.mode!=TRANSFORM_NONE && b.pressed) { + if (_edit.mode != TRANSFORM_NONE && b.pressed) { //cancel motion - _edit.mode=TRANSFORM_NONE; + _edit.mode = TRANSFORM_NONE; //_validate_selection(); - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; - sp->set_global_transform( se->original ); - + sp->set_global_transform(se->original); } surface->update(); //VisualServer::get_singleton()->poly_clear(indicators); - set_message(TTR("Transform Aborted."),3); + set_message(TTR("Transform Aborted."), 3); } } break; case BUTTON_MIDDLE: { - if (b.pressed && _edit.mode!=TRANSFORM_NONE) { + if (b.pressed && _edit.mode != TRANSFORM_NONE) { - switch(_edit.plane ) { + switch (_edit.plane) { case TRANSFORM_VIEW: { - _edit.plane=TRANSFORM_X_AXIS; - set_message(TTR("X-Axis Transform."),2); - name=""; + _edit.plane = TRANSFORM_X_AXIS; + set_message(TTR("X-Axis Transform."), 2); + name = ""; _update_name(); } break; case TRANSFORM_X_AXIS: { - _edit.plane=TRANSFORM_Y_AXIS; - set_message(TTR("Y-Axis Transform."),2); + _edit.plane = TRANSFORM_Y_AXIS; + set_message(TTR("Y-Axis Transform."), 2); } break; case TRANSFORM_Y_AXIS: { - _edit.plane=TRANSFORM_Z_AXIS; - set_message(TTR("Z-Axis Transform."),2); + _edit.plane = TRANSFORM_Z_AXIS; + set_message(TTR("Z-Axis Transform."), 2); } break; case TRANSFORM_Z_AXIS: { - _edit.plane=TRANSFORM_VIEW; - set_message(TTR("View Plane Transform."),2); + _edit.plane = TRANSFORM_VIEW; + set_message(TTR("View Plane Transform."), 2); } break; } - } } break; case BUTTON_LEFT: { @@ -940,108 +870,93 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (b.pressed) { NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int(); - if ( (nav_scheme==NAVIGATION_MAYA || nav_scheme==NAVIGATION_MODO) && b.mod.alt) { + if ((nav_scheme == NAVIGATION_MAYA || nav_scheme == NAVIGATION_MODO) && b.mod.alt) { break; } - if (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_LIST_SELECT) { + if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_LIST_SELECT) { _list_select(b); break; } - _edit.mouse_pos=Point2(b.x,b.y); - _edit.snap=false; - _edit.mode=TRANSFORM_NONE; - + _edit.mouse_pos = Point2(b.x, b.y); + _edit.snap = false; + _edit.mode = TRANSFORM_NONE; //gizmo has priority over everything - bool can_select_gizmos=true; + bool can_select_gizmos = true; { int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); - can_select_gizmos = view_menu->get_popup()->is_item_checked( idx ); + can_select_gizmos = view_menu->get_popup()->is_item_checked(idx); } - - if (can_select_gizmos && spatial_editor->get_selected()) { Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { - int handle=-1; + int handle = -1; Vector3 point; Vector3 normal; - bool inters = seg->intersect_ray(camera,_edit.mouse_pos,point,normal,&handle,b.mod.shift); - if (inters && handle!=-1) { + bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, b.mod.shift); + if (inters && handle != -1) { - _edit.gizmo=seg; - _edit.gizmo_handle=handle; + _edit.gizmo = seg; + _edit.gizmo_handle = handle; //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle); - _edit.gizmo_initial_value=seg->get_handle_value(handle); + _edit.gizmo_initial_value = seg->get_handle_value(handle); break; - } } } - - if (_gizmo_select(_edit.mouse_pos)) break; - clicked=0; - clicked_includes_current=false; - + clicked = 0; + clicked_includes_current = false; - if ((spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_SELECT && b.mod.control) || spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_ROTATE) { + if ((spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT && b.mod.control) || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE) { /* HANDLE ROTATION */ - if (get_selected_count()==0) + if (get_selected_count() == 0) break; //bye //handle rotate - _edit.mode=TRANSFORM_ROTATE; - _compute_edit(Point2(b.x,b.y)); + _edit.mode = TRANSFORM_ROTATE; + _compute_edit(Point2(b.x, b.y)); break; - } - if (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_MOVE) { + if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_MOVE) { - if (get_selected_count()==0) + if (get_selected_count() == 0) break; //bye //handle rotate - _edit.mode=TRANSFORM_TRANSLATE; - _compute_edit(Point2(b.x,b.y)); + _edit.mode = TRANSFORM_TRANSLATE; + _compute_edit(Point2(b.x, b.y)); break; - - } + if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SCALE) { - if (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_SCALE) { - - if (get_selected_count()==0) + if (get_selected_count() == 0) break; //bye //handle rotate - _edit.mode=TRANSFORM_SCALE; - _compute_edit(Point2(b.x,b.y)); + _edit.mode = TRANSFORM_SCALE; + _compute_edit(Point2(b.x, b.y)); break; - - } - - // todo scale - int gizmo_handle=-1; + int gizmo_handle = -1; - clicked=_select_ray(Vector2( b.x, b.y ),b.mod.shift,clicked_includes_current,&gizmo_handle,b.mod.shift); + clicked = _select_ray(Vector2(b.x, b.y), b.mod.shift, clicked_includes_current, &gizmo_handle, b.mod.shift); //clicking is always deferred to either move or release - clicked_wants_append=b.mod.shift; + clicked_wants_append = b.mod.shift; if (!clicked) { @@ -1049,131 +964,118 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { _clear_selected(); //default to regionselect - cursor.region_select=true; - cursor.region_begin=Point2(b.x,b.y); - cursor.region_end=Point2(b.x,b.y); + cursor.region_select = true; + cursor.region_begin = Point2(b.x, b.y); + cursor.region_end = Point2(b.x, b.y); } - if (clicked && gizmo_handle>=0) { + if (clicked && gizmo_handle >= 0) { - Object *obj=ObjectDB::get_instance(clicked); + Object *obj = ObjectDB::get_instance(clicked); if (obj) { Spatial *spa = obj->cast_to<Spatial>(); if (spa) { - Ref<SpatialEditorGizmo> seg=spa->get_gizmo(); + Ref<SpatialEditorGizmo> seg = spa->get_gizmo(); if (seg.is_valid()) { - _edit.gizmo=seg; - _edit.gizmo_handle=gizmo_handle; + _edit.gizmo = seg; + _edit.gizmo_handle = gizmo_handle; //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle); - _edit.gizmo_initial_value=seg->get_handle_value(gizmo_handle); + _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle); //print_line("GIZMO: "+itos(gizmo_handle)+" FROMPOS: "+_edit.orig_gizmo_pos); break; - } } - } //_compute_edit(Point2(b.x,b.y)); //in case a motion happens.. } - - surface->update(); } else { - if (_edit.gizmo.is_valid()) { - _edit.gizmo->commit_handle(_edit.gizmo_handle,_edit.gizmo_initial_value,false); - _edit.gizmo=Ref<SpatialEditorGizmo>(); + _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, false); + _edit.gizmo = Ref<SpatialEditorGizmo>(); break; } if (clicked) { - _select_clicked(clicked_wants_append,true); + _select_clicked(clicked_wants_append, true); //clickd processing was deferred - clicked=0; - - + clicked = 0; } if (cursor.region_select) { _select_region(); - cursor.region_select=false; + cursor.region_select = false; surface->update(); } + if (_edit.mode != TRANSFORM_NONE) { - if (_edit.mode!=TRANSFORM_NONE) { - - - static const char* _transform_name[4]={"None","Rotate","Translate","Scale"}; + static const char *_transform_name[4] = { "None", "Rotate", "Translate", "Scale" }; undo_redo->create_action(_transform_name[_edit.mode]); - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; - undo_redo->add_do_method(sp,"set_global_transform",sp->get_global_transform()); - undo_redo->add_undo_method(sp,"set_global_transform",se->original); + undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_transform()); + undo_redo->add_undo_method(sp, "set_global_transform", se->original); } undo_redo->commit_action(); - _edit.mode=TRANSFORM_NONE; + _edit.mode = TRANSFORM_NONE; //VisualServer::get_singleton()->poly_clear(indicators); set_message(""); } - surface->update(); } } break; } } break; case InputEvent::MOUSE_MOTION: { - const InputEventMouseMotion &m=p_event.mouse_motion; - _edit.mouse_pos=Point2(p_event.mouse_motion.x,p_event.mouse_motion.y); + const InputEventMouseMotion &m = p_event.mouse_motion; + _edit.mouse_pos = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y); if (spatial_editor->get_selected()) { - Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { - int selected_handle=-1; + int selected_handle = -1; - int handle=-1; + int handle = -1; Vector3 point; Vector3 normal; - bool inters = seg->intersect_ray(camera,_edit.mouse_pos,point,normal,&handle,false); - if (inters && handle!=-1) { - - selected_handle=handle; + bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, false); + if (inters && handle != -1) { + selected_handle = handle; } - if (selected_handle!=spatial_editor->get_over_gizmo_handle()) { + if (selected_handle != spatial_editor->get_over_gizmo_handle()) { spatial_editor->set_over_gizmo_handle(selected_handle); spatial_editor->get_selected()->update_gizmo(); - if (selected_handle!=-1) + if (selected_handle != -1) spatial_editor->select_gizmo_hilight_axis(-1); } } } - if (spatial_editor->get_over_gizmo_handle()==-1 && !(m.button_mask&1) && !_edit.gizmo.is_valid()) { - - _gizmo_select(_edit.mouse_pos,true); + if (spatial_editor->get_over_gizmo_handle() == -1 && !(m.button_mask & 1) && !_edit.gizmo.is_valid()) { + _gizmo_select(_edit.mouse_pos, true); } NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int(); @@ -1181,12 +1083,12 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (_edit.gizmo.is_valid()) { - _edit.gizmo->set_handle(_edit.gizmo_handle,camera,Vector2(m.x,m.y)); + _edit.gizmo->set_handle(_edit.gizmo_handle, camera, Vector2(m.x, m.y)); Variant v = _edit.gizmo->get_handle_value(_edit.gizmo_handle); String n = _edit.gizmo->get_handle_name(_edit.gizmo_handle); - set_message(n+": "+String(v)); + set_message(n + ": " + String(v)); - } else if (m.button_mask&1) { + } else if (m.button_mask & 1) { if (nav_scheme == NAVIGATION_MAYA && m.mod.alt) { nav_mode = NAVIGATION_ORBIT; @@ -1201,84 +1103,77 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (!clicked_includes_current) { - _select_clicked(clicked_wants_append,true); + _select_clicked(clicked_wants_append, true); //clickd processing was deferred } - _compute_edit(_edit.mouse_pos); - clicked=0; - - _edit.mode=TRANSFORM_TRANSLATE; + clicked = 0; + _edit.mode = TRANSFORM_TRANSLATE; } if (cursor.region_select && nav_mode == NAVIGATION_NONE) { - cursor.region_end=Point2(m.x,m.y); + cursor.region_end = Point2(m.x, m.y); surface->update(); return; } - if (_edit.mode==TRANSFORM_NONE && nav_mode == NAVIGATION_NONE) + if (_edit.mode == TRANSFORM_NONE && nav_mode == NAVIGATION_NONE) break; + Vector3 ray_pos = _get_ray_pos(Vector2(m.x, m.y)); + Vector3 ray = _get_ray(Vector2(m.x, m.y)); - Vector3 ray_pos=_get_ray_pos( Vector2( m.x, m.y ) ); - Vector3 ray=_get_ray( Vector2( m.x, m.y ) ); - - - switch(_edit.mode) { + switch (_edit.mode) { case TRANSFORM_SCALE: { - - Plane plane=Plane(_edit.center,_get_camera_normal()); - + Plane plane = Plane(_edit.center, _get_camera_normal()); Vector3 intersection; - if (!plane.intersects_ray(ray_pos,ray,&intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) break; Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos,_edit.click_ray,&click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) break; float center_click_dist = click.distance_to(_edit.center); float center_inters_dist = intersection.distance_to(_edit.center); - if (center_click_dist==0) + if (center_click_dist == 0) break; - float scale = (center_inters_dist / center_click_dist)*100.0; + float scale = (center_inters_dist / center_click_dist) * 100.0; if (_edit.snap || spatial_editor->is_snap_enabled()) { - scale = Math::stepify(scale,spatial_editor->get_scale_snap()); + scale = Math::stepify(scale, spatial_editor->get_scale_snap()); } - set_message(vformat(TTR("Scaling to %s%%."),String::num(scale,1))); - scale/=100.0; + set_message(vformat(TTR("Scaling to %s%%."), String::num(scale, 1))); + scale /= 100.0; Transform r; - r.basis.scale(Vector3(scale,scale,scale)); + r.basis.scale(Vector3(scale, scale, scale)); - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; + Transform original = se->original; - Transform original=se->original; - - Transform base=Transform( Basis(), _edit.center); - Transform t=base * (r * (base.inverse() * original)); + Transform base = Transform(Basis(), _edit.center); + Transform t = base * (r * (base.inverse() * original)); sp->set_global_transform(t); } @@ -1289,44 +1184,43 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { case TRANSFORM_TRANSLATE: { - Vector3 motion_mask; Plane plane; - switch( _edit.plane ) { + switch (_edit.plane) { case TRANSFORM_VIEW: - motion_mask=Vector3(0,0,0); - plane=Plane(_edit.center,_get_camera_normal()); - break; + motion_mask = Vector3(0, 0, 0); + plane = Plane(_edit.center, _get_camera_normal()); + break; case TRANSFORM_X_AXIS: - motion_mask=spatial_editor->get_gizmo_transform().basis.get_axis(0); - plane=Plane(_edit.center,motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); - break; + motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(0); + plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); + break; case TRANSFORM_Y_AXIS: - motion_mask=spatial_editor->get_gizmo_transform().basis.get_axis(1); - plane=Plane(_edit.center,motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); - break; + motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(1); + plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); + break; case TRANSFORM_Z_AXIS: - motion_mask=spatial_editor->get_gizmo_transform().basis.get_axis(2); - plane=Plane(_edit.center,motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); - break; + motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2); + plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); + break; } Vector3 intersection; - if (!plane.intersects_ray(ray_pos,ray,&intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) break; Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos,_edit.click_ray,&click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) break; //_validate_selection(); - Vector3 motion = intersection-click; - if (motion_mask!=Vector3()) { - motion=motion_mask.dot(motion)*motion_mask; + Vector3 motion = intersection - click; + if (motion_mask != Vector3()) { + motion = motion_mask.dot(motion) * motion_mask; } - float snap=0; + float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { @@ -1336,98 +1230,92 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { //set_message("Translating: "+motion); - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) { continue; } - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) { continue; } - Transform t=se->original; - t.origin+=motion; + Transform t = se->original; + t.origin += motion; sp->set_global_transform(t); } } break; case TRANSFORM_ROTATE: { - Plane plane; - switch( _edit.plane ) { + switch (_edit.plane) { case TRANSFORM_VIEW: - plane=Plane(_edit.center,_get_camera_normal()); - break; + plane = Plane(_edit.center, _get_camera_normal()); + break; case TRANSFORM_X_AXIS: - plane=Plane(_edit.center,spatial_editor->get_gizmo_transform().basis.get_axis(0)); - break; + plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0)); + break; case TRANSFORM_Y_AXIS: - plane=Plane(_edit.center,spatial_editor->get_gizmo_transform().basis.get_axis(1)); - break; + plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1)); + break; case TRANSFORM_Z_AXIS: - plane=Plane(_edit.center,spatial_editor->get_gizmo_transform().basis.get_axis(2)); - break; + plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2)); + break; } Vector3 intersection; - if (!plane.intersects_ray(ray_pos,ray,&intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) break; Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos,_edit.click_ray,&click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) break; + Vector3 y_axis = (click - _edit.center).normalized(); + Vector3 x_axis = plane.normal.cross(y_axis).normalized(); - Vector3 y_axis=(click-_edit.center).normalized(); - Vector3 x_axis=plane.normal.cross(y_axis).normalized(); - - float angle=Math::atan2( x_axis.dot(intersection-_edit.center), y_axis.dot(intersection-_edit.center) ); + float angle = Math::atan2(x_axis.dot(intersection - _edit.center), y_axis.dot(intersection - _edit.center)); if (_edit.snap || spatial_editor->is_snap_enabled()) { float snap = spatial_editor->get_rotate_snap(); if (snap) { - angle=Math::rad2deg(angle)+snap*0.5; //else it wont reach +180 - angle-=Math::fmod(angle,snap); - set_message(vformat(TTR("Rotating %s degrees."),rtos(angle))); - angle=Math::deg2rad(angle); + angle = Math::rad2deg(angle) + snap * 0.5; //else it wont reach +180 + angle -= Math::fmod(angle, snap); + set_message(vformat(TTR("Rotating %s degrees."), rtos(angle))); + angle = Math::deg2rad(angle); } else - set_message(vformat(TTR("Rotating %s degrees."),rtos(Math::rad2deg(angle)))); + set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle)))); } else { - set_message(vformat(TTR("Rotating %s degrees."),rtos(Math::rad2deg(angle)))); + set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle)))); } - - - Transform r; - r.basis.rotate(plane.normal,angle); + r.basis.rotate(plane.normal, angle); - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; + Transform original = se->original; - Transform original=se->original; - - Transform base=Transform( Basis(), _edit.center); - Transform t=base * r * base.inverse() * original; + Transform base = Transform(Basis(), _edit.center); + Transform t = base * r * base.inverse() * original; sp->set_global_transform(t); } @@ -1446,30 +1334,29 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { VisualServer::get_singleton()->poly_add_primitive(indicators,points,empty,colors,empty); */ } break; - default:{} + default: {} } - } - } else if (m.button_mask&2) { + } else if (m.button_mask & 2) { if (nav_scheme == NAVIGATION_MAYA && m.mod.alt) { nav_mode = NAVIGATION_ZOOM; } - } else if (m.button_mask&4) { + } else if (m.button_mask & 4) { if (nav_scheme == NAVIGATION_GODOT) { int mod = 0; if (m.mod.shift) - mod=KEY_SHIFT; + mod = KEY_SHIFT; if (m.mod.alt) - mod=KEY_ALT; + mod = KEY_ALT; if (m.mod.control) - mod=KEY_CONTROL; + mod = KEY_CONTROL; if (m.mod.meta) - mod=KEY_META; + mod = KEY_META; if (mod == _get_key_modifier("editors/3d/pan_modifier")) nav_mode = NAVIGATION_PAN; @@ -1483,19 +1370,19 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { nav_mode = NAVIGATION_PAN; } - } else if (EditorSettings::get_singleton()->get("editors/3d/emulate_3_button_mouse")) { + } else if (EditorSettings::get_singleton()->get("editors/3d/emulate_3_button_mouse")) { // Handle trackpad (no external mouse) use case int mod = 0; if (m.mod.shift) - mod=KEY_SHIFT; + mod = KEY_SHIFT; if (m.mod.alt) - mod=KEY_ALT; + mod = KEY_ALT; if (m.mod.control) - mod=KEY_CONTROL; + mod = KEY_CONTROL; if (m.mod.meta) - mod=KEY_META; + mod = KEY_META; - if(mod){ + if (mod) { if (mod == _get_key_modifier("editors/3d/pan_modifier")) nav_mode = NAVIGATION_PAN; else if (mod == _get_key_modifier("editors/3d/zoom_modifier")) @@ -1505,56 +1392,55 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { } } - switch(nav_mode) { - case NAVIGATION_PAN:{ + switch (nav_mode) { + case NAVIGATION_PAN: { - real_t pan_speed = 1/150.0; + real_t pan_speed = 1 / 150.0; int pan_speed_modifier = 10; - if (nav_scheme==NAVIGATION_MAYA && m.mod.shift) + if (nav_scheme == NAVIGATION_MAYA && m.mod.shift) pan_speed *= pan_speed_modifier; Transform camera_transform; camera_transform.translate(cursor.pos); - camera_transform.basis.rotate(Vector3(1,0,0),-cursor.x_rot); - camera_transform.basis.rotate(Vector3(0,1,0),-cursor.y_rot); - Vector3 translation(-m.relative_x*pan_speed,m.relative_y*pan_speed,0); - translation*=cursor.distance/DISTANCE_DEFAULT; + camera_transform.basis.rotate(Vector3(1, 0, 0), -cursor.x_rot); + camera_transform.basis.rotate(Vector3(0, 1, 0), -cursor.y_rot); + Vector3 translation(-m.relative_x * pan_speed, m.relative_y * pan_speed, 0); + translation *= cursor.distance / DISTANCE_DEFAULT; camera_transform.translate(translation); - cursor.pos=camera_transform.origin; + cursor.pos = camera_transform.origin; } break; case NAVIGATION_ZOOM: { - real_t zoom_speed = 1/80.0; + real_t zoom_speed = 1 / 80.0; int zoom_speed_modifier = 10; - if (nav_scheme==NAVIGATION_MAYA && m.mod.shift) + if (nav_scheme == NAVIGATION_MAYA && m.mod.shift) zoom_speed *= zoom_speed_modifier; NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/zoom_style").operator int(); if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) { - if ( m.relative_x > 0) - cursor.distance*=1-m.relative_x*zoom_speed; + if (m.relative_x > 0) + cursor.distance *= 1 - m.relative_x * zoom_speed; else if (m.relative_x < 0) - cursor.distance/=1+m.relative_x*zoom_speed; - } - else { - if ( m.relative_y > 0) - cursor.distance*=1+m.relative_y*zoom_speed; + cursor.distance /= 1 + m.relative_x * zoom_speed; + } else { + if (m.relative_y > 0) + cursor.distance *= 1 + m.relative_y * zoom_speed; else if (m.relative_y < 0) - cursor.distance/=1-m.relative_y*zoom_speed; + cursor.distance /= 1 - m.relative_y * zoom_speed; } } break; case NAVIGATION_ORBIT: { - cursor.x_rot+=m.relative_y/80.0; - cursor.y_rot+=m.relative_x/80.0; - if (cursor.x_rot>Math_PI/2.0) - cursor.x_rot=Math_PI/2.0; - if (cursor.x_rot<-Math_PI/2.0) - cursor.x_rot=-Math_PI/2.0; - name=""; + cursor.x_rot += m.relative_y / 80.0; + cursor.y_rot += m.relative_x / 80.0; + if (cursor.x_rot > Math_PI / 2.0) + cursor.x_rot = Math_PI / 2.0; + if (cursor.x_rot < -Math_PI / 2.0) + cursor.x_rot = -Math_PI / 2.0; + name = ""; _update_name(); } break; @@ -1568,57 +1454,57 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) { if (_edit.mode != TRANSFORM_NONE) { - _edit.snap=true; + _edit.snap = true; } } if (ED_IS_SHORTCUT("spatial_editor/bottom_view", p_event)) { cursor.y_rot = 0; - cursor.x_rot = -Math_PI/2.0; - set_message(TTR("Bottom View."),2); + cursor.x_rot = -Math_PI / 2.0; + set_message(TTR("Bottom View."), 2); name = TTR("Bottom"); _update_name(); } if (ED_IS_SHORTCUT("spatial_editor/top_view", p_event)) { cursor.y_rot = 0; - cursor.x_rot = Math_PI/2.0; - set_message(TTR("Top View."),2); + cursor.x_rot = Math_PI / 2.0; + set_message(TTR("Top View."), 2); name = TTR("Top"); _update_name(); } if (ED_IS_SHORTCUT("spatial_editor/rear_view", p_event)) { cursor.x_rot = 0; cursor.y_rot = Math_PI; - set_message(TTR("Rear View."),2); + set_message(TTR("Rear View."), 2); name = TTR("Rear"); _update_name(); } if (ED_IS_SHORTCUT("spatial_editor/front_view", p_event)) { cursor.x_rot = 0; - cursor.y_rot=0; - set_message(TTR("Front View."),2); - name=TTR("Front"); + cursor.y_rot = 0; + set_message(TTR("Front View."), 2); + name = TTR("Front"); _update_name(); } if (ED_IS_SHORTCUT("spatial_editor/left_view", p_event)) { - cursor.x_rot=0; - cursor.y_rot = Math_PI/2.0; - set_message(TTR("Left View."),2); + cursor.x_rot = 0; + cursor.y_rot = Math_PI / 2.0; + set_message(TTR("Left View."), 2); name = TTR("Left"); _update_name(); } if (ED_IS_SHORTCUT("spatial_editor/right_view", p_event)) { - cursor.x_rot=0; - cursor.y_rot = -Math_PI/2.0; - set_message(TTR("Right View."),2); + cursor.x_rot = 0; + cursor.y_rot = -Math_PI / 2.0; + set_message(TTR("Right View."), 2); name = TTR("Right"); _update_name(); } if (ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) { - _menu_option(orthogonal?VIEW_PERSPECTIVE:VIEW_ORTHOGONAL); + _menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL); _update_name(); } if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) { - if (!get_selected_count() || _edit.mode!=TRANSFORM_NONE) + if (!get_selected_count() || _edit.mode != TRANSFORM_NONE) break; if (!AnimationPlayerEditor::singleton->get_key_editor()->has_keying()) { @@ -1626,18 +1512,17 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { break; } - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - emit_signal("transform_key_request",sp,"",sp->get_transform()); + emit_signal("transform_key_request", sp, "", sp->get_transform()); } - set_message(TTR("Animation Key Inserted.")); } @@ -1646,26 +1531,20 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { } } break; - } - } -void SpatialEditorViewport::set_message(String p_message,float p_time) { - - message=p_message; - message_time=p_time; +void SpatialEditorViewport::set_message(String p_message, float p_time) { + message = p_message; + message_time = p_time; } - - void SpatialEditorViewport::_notification(int p_what) { + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { - - bool visible=is_visible_in_tree(); + bool visible = is_visible_in_tree(); set_process(visible); @@ -1675,14 +1554,12 @@ void SpatialEditorViewport::_notification(int p_what) { call_deferred("update_transform_gizmo_view"); } - if (p_what==NOTIFICATION_RESIZED) { + if (p_what == NOTIFICATION_RESIZED) { call_deferred("update_transform_gizmo_view"); - } - if (p_what==NOTIFICATION_PROCESS) { - + if (p_what == NOTIFICATION_PROCESS) { //force editr camera /* @@ -1695,56 +1572,53 @@ void SpatialEditorViewport::_notification(int p_what) { _update_camera(); - Map<Node*,Object*> &selection = editor_selection->get_selection(); + Map<Node *, Object *> &selection = editor_selection->get_selection(); - bool changed=false; - bool exist=false; + bool changed = false; + bool exist = false; - for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { + for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->key()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; - - VisualInstance *vi=sp->cast_to<VisualInstance>(); - + VisualInstance *vi = sp->cast_to<VisualInstance>(); if (se->aabb.has_no_surface()) { - se->aabb=vi?vi->get_aabb():Rect3( Vector3(-0.2,-0.2,-0.2),Vector3(0.4,0.4,0.4)); + se->aabb = vi ? vi->get_aabb() : Rect3(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4)); } - Transform t=sp->get_global_transform(); + Transform t = sp->get_global_transform(); t.translate(se->aabb.pos); - t.basis.scale( se->aabb.size ); + t.basis.scale(se->aabb.size); - exist=true; - if (se->last_xform==t) + exist = true; + if (se->last_xform == t) continue; - changed=true; - se->last_xform=t; - VisualServer::get_singleton()->instance_set_transform(se->sbox_instance,t); - + changed = true; + se->last_xform = t; + VisualServer::get_singleton()->instance_set_transform(se->sbox_instance, t); } if (changed || (spatial_editor->is_gizmo_visible() && !exist)) { spatial_editor->update_transform_gizmo(); } - if (message_time>0) { + if (message_time > 0) { - if (message!=last_message) { + if (message != last_message) { surface->update(); - last_message=message; + last_message = message; } - message_time-=get_fixed_process_delta_time(); - if (message_time<0) + message_time -= get_fixed_process_delta_time(); + if (message_time < 0) surface->update(); } @@ -1756,12 +1630,11 @@ void SpatialEditorViewport::_notification(int p_what) { int atlas_q2 = GlobalConfig::get_singleton()->get("rendering/shadow_atlas/quadrant_2_subdiv"); int atlas_q3 = GlobalConfig::get_singleton()->get("rendering/shadow_atlas/quadrant_3_subdiv"); - viewport->set_shadow_atlas_size(shadowmap_size); - viewport->set_shadow_atlas_quadrant_subdiv(0,Viewport::ShadowAtlasQuadrantSubdiv(atlas_q0)); - viewport->set_shadow_atlas_quadrant_subdiv(1,Viewport::ShadowAtlasQuadrantSubdiv(atlas_q1)); - viewport->set_shadow_atlas_quadrant_subdiv(2,Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2)); - viewport->set_shadow_atlas_quadrant_subdiv(3,Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3)); + viewport->set_shadow_atlas_quadrant_subdiv(0, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q0)); + viewport->set_shadow_atlas_quadrant_subdiv(1, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q1)); + viewport->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q2)); + viewport->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv(atlas_q3)); //update msaa if changed @@ -1770,164 +1643,145 @@ void SpatialEditorViewport::_notification(int p_what) { bool hdr = GlobalConfig::get_singleton()->get("rendering/quality/hdr"); viewport->set_hdr(hdr); - - } - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - surface->connect("draw",this,"_draw"); - surface->connect("gui_input",this,"_sinput"); - surface->connect("mouse_entered",this,"_smouseenter"); - preview_camera->set_icon(get_icon("Camera","EditorIcons")); + surface->connect("draw", this, "_draw"); + surface->connect("gui_input", this, "_sinput"); + surface->connect("mouse_entered", this, "_smouseenter"); + preview_camera->set_icon(get_icon("Camera", "EditorIcons")); _init_gizmo_instance(index); } - if (p_what==NOTIFICATION_EXIT_TREE) { - + if (p_what == NOTIFICATION_EXIT_TREE) { _finish_gizmo_instances(); - } - if (p_what==NOTIFICATION_MOUSE_ENTER) { - - + if (p_what == NOTIFICATION_MOUSE_ENTER) { } - - if (p_what==NOTIFICATION_DRAW) { - - - + if (p_what == NOTIFICATION_DRAW) { } - } void SpatialEditorViewport::_draw() { if (surface->has_focus()) { Size2 size = surface->get_size(); - Rect2 r =Rect2(Point2(),size); - get_stylebox("EditorFocus","EditorStyles")->draw(surface->get_canvas_item(),r); + Rect2 r = Rect2(Point2(), size); + get_stylebox("EditorFocus", "EditorStyles")->draw(surface->get_canvas_item(), r); } - - RID ci=surface->get_canvas_item(); + RID ci = surface->get_canvas_item(); if (cursor.region_select) { - VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor.region_begin,cursor.region_end-cursor.region_begin),Color(0.7,0.7,1.0,0.3)); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin), Color(0.7, 0.7, 1.0, 0.3)); } - if (message_time>0) { - Ref<Font> font = get_font("font","Label"); - Point2 msgpos=Point2(5,get_size().y-20); - font->draw(ci,msgpos+Point2(1,1),message,Color(0,0,0,0.8)); - font->draw(ci,msgpos+Point2(-1,-1),message,Color(0,0,0,0.8)); - font->draw(ci,msgpos,message,Color(1,1,1,1)); + if (message_time > 0) { + Ref<Font> font = get_font("font", "Label"); + Point2 msgpos = Point2(5, get_size().y - 20); + font->draw(ci, msgpos + Point2(1, 1), message, Color(0, 0, 0, 0.8)); + font->draw(ci, msgpos + Point2(-1, -1), message, Color(0, 0, 0, 0.8)); + font->draw(ci, msgpos, message, Color(1, 1, 1, 1)); } - - if (_edit.mode==TRANSFORM_ROTATE) { + if (_edit.mode == TRANSFORM_ROTATE) { Point2 center = _point_to_screen(_edit.center); - VisualServer::get_singleton()->canvas_item_add_line(ci,_edit.mouse_pos, center, Color(0.4,0.7,1.0,0.8)); - - + VisualServer::get_singleton()->canvas_item_add_line(ci, _edit.mouse_pos, center, Color(0.4, 0.7, 1.0, 0.8)); } if (previewing) { - - Size2 ss = Size2( GlobalConfig::get_singleton()->get("display/width"), GlobalConfig::get_singleton()->get("display/height") ); + Size2 ss = Size2(GlobalConfig::get_singleton()->get("display/width"), GlobalConfig::get_singleton()->get("display/height")); float aspect = ss.aspect(); Size2 s = get_size(); Rect2 draw_rect; - - switch(previewing->get_keep_aspect_mode()) { + switch (previewing->get_keep_aspect_mode()) { case Camera::KEEP_WIDTH: { - draw_rect.size = Size2(s.width,s.width/aspect); - draw_rect.pos.x=0; - draw_rect.pos.y=(s.height-draw_rect.size.y)*0.5; + draw_rect.size = Size2(s.width, s.width / aspect); + draw_rect.pos.x = 0; + draw_rect.pos.y = (s.height - draw_rect.size.y) * 0.5; } break; case Camera::KEEP_HEIGHT: { - draw_rect.size = Size2(s.height*aspect,s.height); - draw_rect.pos.y=0; - draw_rect.pos.x=(s.width-draw_rect.size.x)*0.5; + draw_rect.size = Size2(s.height * aspect, s.height); + draw_rect.pos.y = 0; + draw_rect.pos.x = (s.width - draw_rect.size.x) * 0.5; } break; } - draw_rect = Rect2(Vector2(),s).clip(draw_rect); + draw_rect = Rect2(Vector2(), s).clip(draw_rect); - surface->draw_line(draw_rect.pos,draw_rect.pos+Vector2(draw_rect.size.x,0),Color(0.6,0.6,0.1,0.5),2.0); - surface->draw_line(draw_rect.pos+Vector2(draw_rect.size.x,0),draw_rect.pos+draw_rect.size,Color(0.6,0.6,0.1,0.5),2.0); - surface->draw_line(draw_rect.pos+draw_rect.size,draw_rect.pos+Vector2(0,draw_rect.size.y),Color(0.6,0.6,0.1,0.5),2.0); - surface->draw_line(draw_rect.pos,draw_rect.pos+Vector2(0,draw_rect.size.y),Color(0.6,0.6,0.1,0.5),2.0); + surface->draw_line(draw_rect.pos, draw_rect.pos + Vector2(draw_rect.size.x, 0), Color(0.6, 0.6, 0.1, 0.5), 2.0); + surface->draw_line(draw_rect.pos + Vector2(draw_rect.size.x, 0), draw_rect.pos + draw_rect.size, Color(0.6, 0.6, 0.1, 0.5), 2.0); + surface->draw_line(draw_rect.pos + draw_rect.size, draw_rect.pos + Vector2(0, draw_rect.size.y), Color(0.6, 0.6, 0.1, 0.5), 2.0); + surface->draw_line(draw_rect.pos, draw_rect.pos + Vector2(0, draw_rect.size.y), Color(0.6, 0.6, 0.1, 0.5), 2.0); } - } - void SpatialEditorViewport::_menu_option(int p_option) { - switch(p_option) { + switch (p_option) { case VIEW_TOP: { - cursor.x_rot=Math_PI/2.0; - cursor.y_rot=0; - name=TTR("Top"); + cursor.x_rot = Math_PI / 2.0; + cursor.y_rot = 0; + name = TTR("Top"); _update_name(); } break; case VIEW_BOTTOM: { - cursor.x_rot=-Math_PI/2.0; - cursor.y_rot=0; - name=TTR("Bottom"); + cursor.x_rot = -Math_PI / 2.0; + cursor.y_rot = 0; + name = TTR("Bottom"); _update_name(); } break; case VIEW_LEFT: { - cursor.y_rot=Math_PI/2.0; - cursor.x_rot=0; - name=TTR("Left"); + cursor.y_rot = Math_PI / 2.0; + cursor.x_rot = 0; + name = TTR("Left"); _update_name(); } break; case VIEW_RIGHT: { - cursor.y_rot=-Math_PI/2.0; - cursor.x_rot=0; - name=TTR("Right"); + cursor.y_rot = -Math_PI / 2.0; + cursor.x_rot = 0; + name = TTR("Right"); _update_name(); } break; case VIEW_FRONT: { - cursor.y_rot=0; - cursor.x_rot=0; - name=TTR("Front"); + cursor.y_rot = 0; + cursor.x_rot = 0; + name = TTR("Front"); _update_name(); } break; case VIEW_REAR: { - cursor.y_rot=Math_PI; - cursor.x_rot=0; - name=TTR("Rear"); + cursor.y_rot = Math_PI; + cursor.x_rot = 0; + name = TTR("Rear"); _update_name(); } break; case VIEW_CENTER_TO_ORIGIN: { - cursor.pos = Vector3(0,0,0); + cursor.pos = Vector3(0, 0, 0); } break; case VIEW_CENTER_TO_SELECTION: { @@ -1942,32 +1796,32 @@ void SpatialEditorViewport::_menu_option(int p_option) { Transform camera_transform = camera->get_global_transform(); - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Align with view")); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; Transform xform = camera_transform; xform.scale_basis(sp->get_scale()); - undo_redo->add_do_method(sp,"set_global_transform",xform); - undo_redo->add_undo_method(sp,"set_global_transform",sp->get_global_transform()); + undo_redo->add_do_method(sp, "set_global_transform", xform); + undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); } undo_redo->commit_action(); } break; case VIEW_ENVIRONMENT: { int idx = view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT); - bool current = view_menu->get_popup()->is_item_checked( idx ); - current=!current; + bool current = view_menu->get_popup()->is_item_checked(idx); + current = !current; if (current) { camera->set_environment(RES()); @@ -1976,24 +1830,23 @@ void SpatialEditorViewport::_menu_option(int p_option) { camera->set_environment(SpatialEditor::get_singleton()->get_viewport_environment()); } - view_menu->get_popup()->set_item_checked( idx, current ); - + view_menu->get_popup()->set_item_checked(idx, current); } break; case VIEW_PERSPECTIVE: { - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), false ); - orthogonal=false; + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), false); + orthogonal = false; call_deferred("update_transform_gizmo_view"); _update_name(); } break; case VIEW_ORTHOGONAL: { - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), true ); - orthogonal=true; + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), true); + orthogonal = true; call_deferred("update_transform_gizmo_view"); _update_name(); @@ -2001,30 +1854,27 @@ void SpatialEditorViewport::_menu_option(int p_option) { case VIEW_AUDIO_LISTENER: { int idx = view_menu->get_popup()->get_item_index(VIEW_AUDIO_LISTENER); - bool current = view_menu->get_popup()->is_item_checked( idx ); - current=!current; + bool current = view_menu->get_popup()->is_item_checked(idx); + current = !current; viewport->set_as_audio_listener(current); - view_menu->get_popup()->set_item_checked( idx, current ); + view_menu->get_popup()->set_item_checked(idx, current); } break; case VIEW_GIZMOS: { int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); - bool current = view_menu->get_popup()->is_item_checked( idx ); - current=!current; + bool current = view_menu->get_popup()->is_item_checked(idx); + current = !current; if (current) - camera->set_cull_mask( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index))|(1<<GIZMO_EDIT_LAYER)|(1<<GIZMO_GRID_LAYER) ); + camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER)); else - camera->set_cull_mask( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index))|(1<<GIZMO_GRID_LAYER) ); - view_menu->get_popup()->set_item_checked( idx, current ); + camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_GRID_LAYER)); + view_menu->get_popup()->set_item_checked(idx, current); } break; - } - } - void SpatialEditorViewport::_preview_exited_scene() { preview_camera->set_pressed(false); @@ -2032,52 +1882,46 @@ void SpatialEditorViewport::_preview_exited_scene() { view_menu->show(); } - void SpatialEditorViewport::_init_gizmo_instance(int p_idx) { - uint32_t layer=1<<(GIZMO_BASE_LAYER+p_idx);//|(1<<GIZMO_GRID_LAYER); + uint32_t layer = 1 << (GIZMO_BASE_LAYER + p_idx); //|(1<<GIZMO_GRID_LAYER); - for(int i=0;i<3;i++) { - move_gizmo_instance[i]=VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_base(move_gizmo_instance[i],spatial_editor->get_move_gizmo(i)->get_rid()); - VS::get_singleton()->instance_set_scenario(move_gizmo_instance[i],get_tree()->get_root()->get_world()->get_scenario()); - VS::get_singleton()->instance_set_visible(move_gizmo_instance[i],false); + for (int i = 0; i < 3; i++) { + move_gizmo_instance[i] = VS::get_singleton()->instance_create(); + VS::get_singleton()->instance_set_base(move_gizmo_instance[i], spatial_editor->get_move_gizmo(i)->get_rid()); + VS::get_singleton()->instance_set_scenario(move_gizmo_instance[i], get_tree()->get_root()->get_world()->get_scenario()); + VS::get_singleton()->instance_set_visible(move_gizmo_instance[i], false); //VS::get_singleton()->instance_geometry_set_flag(move_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true); VS::get_singleton()->instance_geometry_set_cast_shadows_setting(move_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF); - VS::get_singleton()->instance_set_layer_mask(move_gizmo_instance[i],layer); + VS::get_singleton()->instance_set_layer_mask(move_gizmo_instance[i], layer); - rotate_gizmo_instance[i]=VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_base(rotate_gizmo_instance[i],spatial_editor->get_rotate_gizmo(i)->get_rid()); - VS::get_singleton()->instance_set_scenario(rotate_gizmo_instance[i],get_tree()->get_root()->get_world()->get_scenario()); - VS::get_singleton()->instance_set_visible(rotate_gizmo_instance[i],false); + rotate_gizmo_instance[i] = VS::get_singleton()->instance_create(); + VS::get_singleton()->instance_set_base(rotate_gizmo_instance[i], spatial_editor->get_rotate_gizmo(i)->get_rid()); + VS::get_singleton()->instance_set_scenario(rotate_gizmo_instance[i], get_tree()->get_root()->get_world()->get_scenario()); + VS::get_singleton()->instance_set_visible(rotate_gizmo_instance[i], false); //VS::get_singleton()->instance_geometry_set_flag(rotate_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true); VS::get_singleton()->instance_geometry_set_cast_shadows_setting(rotate_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF); - VS::get_singleton()->instance_set_layer_mask(rotate_gizmo_instance[i],layer); + VS::get_singleton()->instance_set_layer_mask(rotate_gizmo_instance[i], layer); } - } - void SpatialEditorViewport::_finish_gizmo_instances() { - - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { VS::get_singleton()->free(move_gizmo_instance[i]); VS::get_singleton()->free(rotate_gizmo_instance[i]); } - } void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { - ERR_FAIL_COND(p_activate && !preview); ERR_FAIL_COND(!p_activate && !previewing); if (!p_activate) { - previewing->disconnect("tree_exited",this,"_preview_exited_scene"); - previewing=NULL; - VS::get_singleton()->viewport_attach_camera( viewport->get_viewport_rid(), camera->get_camera() ); //restore + previewing->disconnect("tree_exited", this, "_preview_exited_scene"); + previewing = NULL; + VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore if (!preview) preview_camera->hide(); view_menu->show(); @@ -2085,12 +1929,11 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { } else { - previewing=preview; - previewing->connect("tree_exited",this,"_preview_exited_scene"); - VS::get_singleton()->viewport_attach_camera( viewport->get_viewport_rid(), preview->get_camera() ); //replace + previewing = preview; + previewing->connect("tree_exited", this, "_preview_exited_scene"); + VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), preview->get_camera()); //replace view_menu->hide(); surface->update(); - } } @@ -2099,11 +1942,11 @@ void SpatialEditorViewport::_selection_result_pressed(int p_result) { if (selection_results.size() <= p_result) return; - clicked=selection_results[p_result].item->get_instance_ID(); + clicked = selection_results[p_result].item->get_instance_ID(); if (clicked) { - _select_clicked(clicked_wants_append,true); - clicked=0; + _select_clicked(clicked_wants_append, true); + clicked = 0; } } @@ -2114,9 +1957,9 @@ void SpatialEditorViewport::_selection_menu_hide() { selection_menu->set_size(Vector2(0, 0)); } -void SpatialEditorViewport::set_can_preview(Camera* p_preview) { +void SpatialEditorViewport::set_can_preview(Camera *p_preview) { - preview=p_preview; + preview = p_preview; if (!preview_camera->is_pressed()) { @@ -2135,42 +1978,39 @@ void SpatialEditorViewport::update_transform_gizmo_view() { Transform xform = spatial_editor->get_gizmo_transform(); - Transform camera_xform = camera->get_transform(); Vector3 camz = -camera_xform.get_basis().get_axis(2).normalized(); Vector3 camy = -camera_xform.get_basis().get_axis(1).normalized(); - Plane p(camera_xform.origin,camz); - float gizmo_d = Math::abs( p.distance_to(xform.origin )); - float d0 = camera->unproject_position(camera_xform.origin+camz*gizmo_d).y; - float d1 = camera->unproject_position(camera_xform.origin+camz*gizmo_d+camy).y; - float dd = Math::abs(d0-d1); - if (dd==0) - dd=0.0001; + Plane p(camera_xform.origin, camz); + float gizmo_d = Math::abs(p.distance_to(xform.origin)); + float d0 = camera->unproject_position(camera_xform.origin + camz * gizmo_d).y; + float d1 = camera->unproject_position(camera_xform.origin + camz * gizmo_d + camy).y; + float dd = Math::abs(d0 - d1); + if (dd == 0) + dd = 0.0001; float gsize = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_size"); - gizmo_scale=(gsize/Math::abs(dd)); - Vector3 scale = Vector3(1,1,1) * gizmo_scale; + gizmo_scale = (gsize / Math::abs(dd)); + Vector3 scale = Vector3(1, 1, 1) * gizmo_scale; xform.basis.scale(scale); //xform.basis.scale(GIZMO_SCALE_DEFAULT*Vector3(1,1,1)); - - for(int i=0;i<3;i++) { - VisualServer::get_singleton()->instance_set_transform(move_gizmo_instance[i], xform ); - VisualServer::get_singleton()->instance_set_visible(move_gizmo_instance[i],spatial_editor->is_gizmo_visible()&& (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_MOVE) ); - VisualServer::get_singleton()->instance_set_transform(rotate_gizmo_instance[i], xform ); - VisualServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[i],spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode()==SpatialEditor::TOOL_MODE_ROTATE) ); + for (int i = 0; i < 3; i++) { + VisualServer::get_singleton()->instance_set_transform(move_gizmo_instance[i], xform); + VisualServer::get_singleton()->instance_set_visible(move_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_MOVE)); + VisualServer::get_singleton()->instance_set_transform(rotate_gizmo_instance[i], xform); + VisualServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE)); } - } -void SpatialEditorViewport::set_state(const Dictionary& p_state) { +void SpatialEditorViewport::set_state(const Dictionary &p_state) { - cursor.pos=p_state["pos"]; - cursor.x_rot=p_state["x_rot"]; - cursor.y_rot=p_state["y_rot"]; - cursor.distance=p_state["distance"]; + cursor.pos = p_state["pos"]; + cursor.x_rot = p_state["x_rot"]; + cursor.y_rot = p_state["y_rot"]; + cursor.distance = p_state["distance"]; bool env = p_state["use_environment"]; bool orth = p_state["use_orthogonal"]; if (orth) @@ -2184,15 +2024,15 @@ void SpatialEditorViewport::set_state(const Dictionary& p_state) { int idx = view_menu->get_popup()->get_item_index(VIEW_AUDIO_LISTENER); viewport->set_as_audio_listener(listener); - view_menu->get_popup()->set_item_checked( idx, listener ); + view_menu->get_popup()->set_item_checked(idx, listener); } if (p_state.has("previewing")) { Node *pv = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["previewing"]); if (pv && pv->cast_to<Camera>()) { - previewing=pv->cast_to<Camera>(); - previewing->connect("tree_exited",this,"_preview_exited_scene"); - VS::get_singleton()->viewport_attach_camera( viewport->get_viewport_rid(), previewing->get_camera() ); //replace + previewing = pv->cast_to<Camera>(); + previewing->connect("tree_exited", this, "_preview_exited_scene"); + VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), previewing->get_camera()); //replace view_menu->hide(); surface->update(); preview_camera->set_pressed(true); @@ -2204,127 +2044,121 @@ void SpatialEditorViewport::set_state(const Dictionary& p_state) { Dictionary SpatialEditorViewport::get_state() const { Dictionary d; - d["pos"]=cursor.pos; - d["x_rot"]=cursor.x_rot; - d["y_rot"]=cursor.y_rot; - d["distance"]=cursor.distance; - d["use_environment"]=camera->get_environment().is_valid(); - d["use_orthogonal"]=camera->get_projection()==Camera::PROJECTION_ORTHOGONAL; - d["listener"]=viewport->is_audio_listener(); + d["pos"] = cursor.pos; + d["x_rot"] = cursor.x_rot; + d["y_rot"] = cursor.y_rot; + d["distance"] = cursor.distance; + d["use_environment"] = camera->get_environment().is_valid(); + d["use_orthogonal"] = camera->get_projection() == Camera::PROJECTION_ORTHOGONAL; + d["listener"] = viewport->is_audio_listener(); if (previewing) { - d["previewing"]=EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing); + d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing); } return d; } +void SpatialEditorViewport::_bind_methods() { -void SpatialEditorViewport::_bind_methods(){ - - ClassDB::bind_method(D_METHOD("_draw"),&SpatialEditorViewport::_draw); - ClassDB::bind_method(D_METHOD("_smouseenter"),&SpatialEditorViewport::_smouseenter); - ClassDB::bind_method(D_METHOD("_sinput"),&SpatialEditorViewport::_sinput); - ClassDB::bind_method(D_METHOD("_menu_option"),&SpatialEditorViewport::_menu_option); - ClassDB::bind_method(D_METHOD("_toggle_camera_preview"),&SpatialEditorViewport::_toggle_camera_preview); - ClassDB::bind_method(D_METHOD("_preview_exited_scene"),&SpatialEditorViewport::_preview_exited_scene); - ClassDB::bind_method(D_METHOD("update_transform_gizmo_view"),&SpatialEditorViewport::update_transform_gizmo_view); - ClassDB::bind_method(D_METHOD("_selection_result_pressed"),&SpatialEditorViewport::_selection_result_pressed); - ClassDB::bind_method(D_METHOD("_selection_menu_hide"),&SpatialEditorViewport::_selection_menu_hide); + ClassDB::bind_method(D_METHOD("_draw"), &SpatialEditorViewport::_draw); + ClassDB::bind_method(D_METHOD("_smouseenter"), &SpatialEditorViewport::_smouseenter); + ClassDB::bind_method(D_METHOD("_sinput"), &SpatialEditorViewport::_sinput); + ClassDB::bind_method(D_METHOD("_menu_option"), &SpatialEditorViewport::_menu_option); + ClassDB::bind_method(D_METHOD("_toggle_camera_preview"), &SpatialEditorViewport::_toggle_camera_preview); + ClassDB::bind_method(D_METHOD("_preview_exited_scene"), &SpatialEditorViewport::_preview_exited_scene); + ClassDB::bind_method(D_METHOD("update_transform_gizmo_view"), &SpatialEditorViewport::update_transform_gizmo_view); + ClassDB::bind_method(D_METHOD("_selection_result_pressed"), &SpatialEditorViewport::_selection_result_pressed); + ClassDB::bind_method(D_METHOD("_selection_menu_hide"), &SpatialEditorViewport::_selection_menu_hide); - ADD_SIGNAL( MethodInfo("toggle_maximize_view", PropertyInfo(Variant::OBJECT, "viewport")) ); + ADD_SIGNAL(MethodInfo("toggle_maximize_view", PropertyInfo(Variant::OBJECT, "viewport"))); } - void SpatialEditorViewport::reset() { - orthogonal=false; - message_time=0; - message=""; - last_message=""; - name=""; + orthogonal = false; + message_time = 0; + message = ""; + last_message = ""; + name = ""; - cursor.x_rot=0.5; - cursor.y_rot=0.5; - cursor.distance=4; - cursor.region_select=false; + cursor.x_rot = 0.5; + cursor.y_rot = 0.5; + cursor.distance = 4; + cursor.region_select = false; _update_name(); } - void SpatialEditorViewport::focus_selection() { if (!get_selected_count()) return; Vector3 center; - int count=0; + int count = 0; - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; - center+=sp->get_global_transform().origin; + center += sp->get_global_transform().origin; count++; } - if( count != 0 ) { - center/=float(count); + if (count != 0) { + center /= float(count); } - cursor.pos=center; + cursor.pos = center; } - SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, EditorNode *p_editor, int p_index) { - _edit.mode=TRANSFORM_NONE; - _edit.plane=TRANSFORM_VIEW; - _edit.edited_gizmo=0; - _edit.snap=1; - _edit.gizmo_handle=0; - - - - index=p_index; - editor=p_editor; - editor_selection=editor->get_editor_selection(); - undo_redo=editor->get_undo_redo(); - clicked=0; - clicked_includes_current=false; - orthogonal=false; - message_time=0; - - spatial_editor=p_spatial_editor; - ViewportContainer *c=memnew(ViewportContainer); + _edit.mode = TRANSFORM_NONE; + _edit.plane = TRANSFORM_VIEW; + _edit.edited_gizmo = 0; + _edit.snap = 1; + _edit.gizmo_handle = 0; + + index = p_index; + editor = p_editor; + editor_selection = editor->get_editor_selection(); + undo_redo = editor->get_undo_redo(); + clicked = 0; + clicked_includes_current = false; + orthogonal = false; + message_time = 0; + + spatial_editor = p_spatial_editor; + ViewportContainer *c = memnew(ViewportContainer); c->set_stretch(true); add_child(c); c->set_area_as_parent_rect(); - viewport = memnew( Viewport ); + viewport = memnew(Viewport); viewport->set_disable_input(true); c->add_child(viewport); - surface = memnew( Control ); + surface = memnew(Control); add_child(surface); surface->set_area_as_parent_rect(); camera = memnew(Camera); camera->set_disable_gizmo(true); - camera->set_cull_mask( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+p_index))|(1<<GIZMO_EDIT_LAYER)|(1<<GIZMO_GRID_LAYER) ); + camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + p_index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER)); //camera->set_environment(SpatialEditor::get_singleton()->get_viewport_environment()); viewport->add_child(camera); camera->make_current(); surface->set_focus_mode(FOCUS_ALL); - view_menu = memnew( MenuButton ); + view_menu = memnew(MenuButton); surface->add_child(view_menu); - view_menu->set_pos( Point2(4,4)); - view_menu->set_self_modulate(Color(1,1,1,0.5)); + view_menu->set_pos(Point2(4, 4)); + view_menu->set_self_modulate(Color(1, 1, 1, 0.5)); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/top_view"), VIEW_TOP); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/bottom_view"), VIEW_BOTTOM); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/left_view"), VIEW_LEFT); @@ -2334,60 +2168,52 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_item(TTR("Perspective") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_PERSPECTIVE); view_menu->get_popup()->add_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE),true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("Environment")), VIEW_ENVIRONMENT); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT),true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT), true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER); view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("Gizmos")),VIEW_GIZMOS); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_GIZMOS),true); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("Gizmos")), VIEW_GIZMOS); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/focus_origin"), VIEW_CENTER_TO_ORIGIN); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/focus_selection"), VIEW_CENTER_TO_SELECTION); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_selection_with_view"), VIEW_ALIGN_SELECTION_WITH_VIEW); - view_menu->get_popup()->connect("id_pressed",this,"_menu_option"); + view_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - preview_camera = memnew( Button ); + preview_camera = memnew(Button); preview_camera->set_toggle_mode(true); - preview_camera->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,90); - preview_camera->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,10); + preview_camera->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, 90); + preview_camera->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 10); preview_camera->set_text("preview"); surface->add_child(preview_camera); preview_camera->hide(); - preview_camera->connect("toggled",this,"_toggle_camera_preview"); - previewing=NULL; - preview=NULL; - gizmo_scale=1.0; + preview_camera->connect("toggled", this, "_toggle_camera_preview"); + previewing = NULL; + preview = NULL; + gizmo_scale = 1.0; - 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"); - if (p_index==0) { - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUDIO_LISTENER),true); + if (p_index == 0) { + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUDIO_LISTENER), true); viewport->set_as_audio_listener(true); } - - name=TTR("Top"); + name = TTR("Top"); _update_name(); - EditorSettings::get_singleton()->connect("settings_changed",this,"update_transform_gizmo_view"); - + EditorSettings::get_singleton()->connect("settings_changed", this, "update_transform_gizmo_view"); } - - - - - - -SpatialEditor *SpatialEditor::singleton=NULL; +SpatialEditor *SpatialEditor::singleton = NULL; SpatialEditorSelectedItem::~SpatialEditorSelectedItem() { @@ -2395,183 +2221,172 @@ SpatialEditorSelectedItem::~SpatialEditorSelectedItem() { VisualServer::get_singleton()->free(sbox_instance); } - - void SpatialEditor::select_gizmo_hilight_axis(int p_axis) { + for (int i = 0; i < 3; i++) { - for(int i=0;i<3;i++) { - - move_gizmo[i]->surface_set_material(0,i==p_axis?gizmo_hl:gizmo_color[i]); - rotate_gizmo[i]->surface_set_material(0,(i+3)==p_axis?gizmo_hl:gizmo_color[i]); + move_gizmo[i]->surface_set_material(0, i == p_axis ? gizmo_hl : gizmo_color[i]); + rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_hl : gizmo_color[i]); } - } void SpatialEditor::update_transform_gizmo() { - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); Rect3 center; - bool first=true; + bool first = true; Basis gizmo_basis; - bool local_gizmo_coords = transform_menu->get_popup()->is_item_checked( transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS) ); + bool local_gizmo_coords = transform_menu->get_popup()->is_item_checked(transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS)); - - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; Transform xf = se->sp->get_global_transform(); if (first) { - center.pos=xf.origin; - first=false; + center.pos = xf.origin; + first = false; if (local_gizmo_coords) { - gizmo_basis=xf.basis; + gizmo_basis = xf.basis; gizmo_basis.orthonormalize(); } } else { center.expand_to(xf.origin); - gizmo_basis=Basis(); + gizmo_basis = Basis(); } //count++; } - Vector3 pcenter = center.pos+center.size*0.5; - gizmo.visible=!first; - gizmo.transform.origin=pcenter; - gizmo.transform.basis=gizmo_basis; + Vector3 pcenter = center.pos + center.size * 0.5; + gizmo.visible = !first; + gizmo.transform.origin = pcenter; + gizmo.transform.basis = gizmo_basis; - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { viewports[i]->update_transform_gizmo_view(); } - } - Object *SpatialEditor::_get_editor_data(Object *p_what) { Spatial *sp = p_what->cast_to<Spatial>(); if (!sp) return NULL; + SpatialEditorSelectedItem *si = memnew(SpatialEditorSelectedItem); - SpatialEditorSelectedItem *si = memnew( SpatialEditorSelectedItem ); - - si->sp=sp; - si->sbox_instance=VisualServer::get_singleton()->instance_create2(selection_box->get_rid(),sp->get_world()->get_scenario()); + si->sp = sp; + si->sbox_instance = VisualServer::get_singleton()->instance_create2(selection_box->get_rid(), sp->get_world()->get_scenario()); VS::get_singleton()->instance_geometry_set_cast_shadows_setting(si->sbox_instance, VS::SHADOW_CASTING_SETTING_OFF); if (get_tree()->is_editor_hint()) - editor->call("edit_node",sp); + editor->call("edit_node", sp); return si; } void SpatialEditor::_generate_selection_box() { - Rect3 aabb( Vector3(), Vector3(1,1,1) ); - aabb.grow_by( aabb.get_longest_axis_size()/20.0 ); + Rect3 aabb(Vector3(), Vector3(1, 1, 1)); + aabb.grow_by(aabb.get_longest_axis_size() / 20.0); - Ref<SurfaceTool> st = memnew( SurfaceTool ); + Ref<SurfaceTool> st = memnew(SurfaceTool); st->begin(Mesh::PRIMITIVE_LINES); - for (int i=0;i<12;i++) { + for (int i = 0; i < 12; i++) { - Vector3 a,b; - aabb.get_edge(i,a,b); + Vector3 a, b; + aabb.get_edge(i, a, b); /*Vector<Vector3> points; Vector<Color> colors; points.push_back(a); points.push_back(b);*/ - st->add_color( Color(1.0,1.0,0.8,0.8) ); + st->add_color(Color(1.0, 1.0, 0.8, 0.8)); st->add_vertex(a); - st->add_color( Color(1.0,1.0,0.8,0.4) ); - st->add_vertex(a.linear_interpolate(b,0.2)); + st->add_color(Color(1.0, 1.0, 0.8, 0.4)); + st->add_vertex(a.linear_interpolate(b, 0.2)); - st->add_color( Color(1.0,1.0,0.8,0.4) ); - st->add_vertex(a.linear_interpolate(b,0.8)); - st->add_color( Color(1.0,1.0,0.8,0.8) ); + st->add_color(Color(1.0, 1.0, 0.8, 0.4)); + st->add_vertex(a.linear_interpolate(b, 0.8)); + st->add_color(Color(1.0, 1.0, 0.8, 0.8)); st->add_vertex(b); - } - Ref<FixedSpatialMaterial> mat = memnew( FixedSpatialMaterial ); - mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); - mat->set_albedo(Color(1,1,1)); - mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); - mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true); - mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true); + Ref<FixedSpatialMaterial> mat = memnew(FixedSpatialMaterial); + mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); + mat->set_albedo(Color(1, 1, 1)); + mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); + mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); st->set_material(mat); selection_box = st->commit(); } - Dictionary SpatialEditor::get_state() const { - Dictionary d; - d["snap_enabled"]=snap_enabled; - d["translate_snap"]=get_translate_snap(); - d["rotate_snap"]=get_rotate_snap(); - d["scale_snap"]=get_scale_snap(); - - int local_coords_index=transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS); - d["local_coords"]=transform_menu->get_popup()->is_item_checked( local_coords_index ); - - int vc=0; - if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT) )) - vc=1; - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS) )) - vc=2; - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS) )) - vc=3; - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS) )) - vc=4; - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT) )) - vc=5; - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT) )) - vc=6; - - d["viewport_mode"]=vc; + d["snap_enabled"] = snap_enabled; + d["translate_snap"] = get_translate_snap(); + d["rotate_snap"] = get_rotate_snap(); + d["scale_snap"] = get_scale_snap(); + + int local_coords_index = transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS); + d["local_coords"] = transform_menu->get_popup()->is_item_checked(local_coords_index); + + int vc = 0; + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) + vc = 1; + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) + vc = 2; + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) + vc = 3; + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) + vc = 4; + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) + vc = 5; + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) + vc = 6; + + d["viewport_mode"] = vc; Array vpdata; - for(int i=0;i<4;i++) { - vpdata.push_back( viewports[i]->get_state() ); + for (int i = 0; i < 4; i++) { + vpdata.push_back(viewports[i]->get_state()); } - d["viewports"]=vpdata; + d["viewports"] = vpdata; - d["default_light"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT) ); - d["ambient_light_color"]=settings_ambient_color->get_pick_color(); + d["default_light"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT)); + d["ambient_light_color"] = settings_ambient_color->get_pick_color(); - d["default_srgb"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB) ); - d["show_grid"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_GRID) ); - d["show_origin"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN) ); - d["fov"]=get_fov(); - d["znear"]=get_znear(); - d["zfar"]=get_zfar(); - d["deflight_rot_x"]=settings_default_light_rot_x; - d["deflight_rot_y"]=settings_default_light_rot_y; + d["default_srgb"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB)); + d["show_grid"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID)); + d["show_origin"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN)); + d["fov"] = get_fov(); + d["znear"] = get_znear(); + d["zfar"] = get_zfar(); + d["deflight_rot_x"] = settings_default_light_rot_x; + d["deflight_rot_y"] = settings_default_light_rot_y; return d; } -void SpatialEditor::set_state(const Dictionary& p_state) { +void SpatialEditor::set_state(const Dictionary &p_state) { Dictionary d = p_state; if (d.has("snap_enabled")) { - snap_enabled=d["snap_enabled"]; - int snap_enabled_idx=transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_USE_SNAP); - transform_menu->get_popup()->set_item_checked( snap_enabled_idx, snap_enabled ); + snap_enabled = d["snap_enabled"]; + int snap_enabled_idx = transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_USE_SNAP); + transform_menu->get_popup()->set_item_checked(snap_enabled_idx, snap_enabled); } if (d.has("translate_snap")) @@ -2584,33 +2399,33 @@ void SpatialEditor::set_state(const Dictionary& p_state) { snap_scale->set_text(d["scale_snap"]); if (d.has("local_coords")) { - int local_coords_idx=transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS); - transform_menu->get_popup()->set_item_checked( local_coords_idx, d["local_coords"] ); + int local_coords_idx = transform_menu->get_popup()->get_item_index(MENU_TRANSFORM_LOCAL_COORDS); + transform_menu->get_popup()->set_item_checked(local_coords_idx, d["local_coords"]); update_transform_gizmo(); } if (d.has("viewport_mode")) { int vc = d["viewport_mode"]; - if (vc==1) + if (vc == 1) _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - else if (vc==2) + else if (vc == 2) _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS); - else if (vc==3) + else if (vc == 3) _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS); - else if (vc==4) + else if (vc == 4) _menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS); - else if (vc==5) + else if (vc == 5) _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT); - else if (vc==6) + else if (vc == 6) _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT); } if (d.has("viewports")) { Array vp = d["viewports"]; - ERR_FAIL_COND(vp.size()>4); + ERR_FAIL_COND(vp.size() > 4); - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { viewports[i]->set_state(vp[i]); } } @@ -2626,18 +2441,16 @@ void SpatialEditor::set_state(const Dictionary& p_state) { bool use = d["default_light"]; bool existing = light_instance.is_valid(); - if (use!=existing) { + if (use != existing) { if (existing) { VisualServer::get_singleton()->free(light_instance); - light_instance=RID(); + light_instance = RID(); } else { - light_instance=VisualServer::get_singleton()->instance_create2(light,get_tree()->get_root()->get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_transform(light_instance,light_transform); - + light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario()); + VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform); } - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), light_instance.is_valid() ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), light_instance.is_valid()); } - } if (d.has("ambient_light_color")) { settings_ambient_color->set_pick_color(d["ambient_light_color"]); @@ -2653,7 +2466,7 @@ void SpatialEditor::set_state(const Dictionary& p_state) { if (d.has("show_grid")) { bool use = d["show_grid"]; - if (use!=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_GRID))) { + if (use != view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID))) { _menu_item_pressed(MENU_VIEW_GRID); } } @@ -2661,26 +2474,23 @@ void SpatialEditor::set_state(const Dictionary& p_state) { if (d.has("show_origin")) { bool use = d["show_origin"]; - if (use!=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN))) { - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN), use ); - VisualServer::get_singleton()->instance_set_visible(origin_instance,use); + if (use != view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN))) { + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN), use); + VisualServer::get_singleton()->instance_set_visible(origin_instance, use); } } if (d.has("deflight_rot_x")) - settings_default_light_rot_x=d["deflight_rot_x"]; + settings_default_light_rot_x = d["deflight_rot_x"]; if (d.has("deflight_rot_y")) - settings_default_light_rot_y=d["deflight_rot_y"]; + settings_default_light_rot_y = d["deflight_rot_y"]; _update_default_light_angle(); - - } - void SpatialEditor::edit(Spatial *p_spatial) { - if (p_spatial!=selected) { + if (p_spatial != selected) { if (selected) { Ref<SpatialEditorGizmo> seg = selected->get_gizmo(); @@ -2690,8 +2500,8 @@ void SpatialEditor::edit(Spatial *p_spatial) { } } - selected=p_spatial; - over_gizmo_handle=-1; + selected = p_spatial; + over_gizmo_handle = -1; if (selected) { @@ -2723,32 +2533,31 @@ void SpatialEditor::_xform_dialog_action() { Vector3 rotate; Vector3 translate; - for(int i=0;i<3;i++) { - translate[i]=xform_translate[i]->get_text().to_double(); - rotate[i]=Math::deg2rad(xform_rotate[i]->get_text().to_double()); - scale[i]=xform_scale[i]->get_text().to_double(); + for (int i = 0; i < 3; i++) { + translate[i] = xform_translate[i]->get_text().to_double(); + rotate[i] = Math::deg2rad(xform_rotate[i]->get_text().to_double()); + scale[i] = xform_scale[i]->get_text().to_double(); } - + t.basis.scale(scale); t.basis.rotate(rotate); - t.origin=translate; - + t.origin = translate; undo_redo->create_action(TTR("XForm Dialog")); - List<Node*> &selection = editor_selection->get_selected_node_list(); + List<Node *> &selection = editor_selection->get_selected_node_list(); - for(List<Node*>::Element *E=selection.front();E;E=E->next()) { + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = E->get()->cast_to<Spatial>(); if (!sp) continue; - SpatialEditorSelectedItem *se=editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); if (!se) continue; - bool post = xform_type->get_selected()>0; + bool post = xform_type->get_selected() > 0; Transform tr = sp->get_global_transform(); if (post) @@ -2756,18 +2565,18 @@ void SpatialEditor::_xform_dialog_action() { else { tr.basis = t.basis * tr.basis; - tr.origin+=t.origin; + tr.origin += t.origin; } - undo_redo->add_do_method(sp,"set_global_transform",tr); - undo_redo->add_undo_method(sp,"set_global_transform",sp->get_global_transform()); + undo_redo->add_do_method(sp, "set_global_transform", tr); + undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); } undo_redo->commit_action(); } void SpatialEditor::_menu_item_pressed(int p_option) { - switch(p_option) { + switch (p_option) { case MENU_TOOL_SELECT: case MENU_TOOL_MOVE: @@ -2775,9 +2584,9 @@ void SpatialEditor::_menu_item_pressed(int p_option) { case MENU_TOOL_SCALE: case MENU_TOOL_LIST_SELECT: { - for(int i=0;i<TOOL_MAX;i++) - tool_button[i]->set_pressed(i==p_option); - tool_mode=(ToolMode)p_option; + for (int i = 0; i < TOOL_MAX; i++) + tool_button[i]->set_pressed(i == p_option); + tool_mode = (ToolMode)p_option; //static const char *_mode[]={"Selection Mode.","Translation Mode.","Rotation Mode.","Scale Mode.","List Selection Mode."}; //set_message(_mode[p_option],3); @@ -2786,55 +2595,53 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_TRANSFORM_USE_SNAP: { - bool is_checked = transform_menu->get_popup()->is_item_checked( transform_menu->get_popup()->get_item_index(p_option) ); - snap_enabled=!is_checked; - transform_menu->get_popup()->set_item_checked( transform_menu->get_popup()->get_item_index(p_option), snap_enabled ); + bool is_checked = transform_menu->get_popup()->is_item_checked(transform_menu->get_popup()->get_item_index(p_option)); + snap_enabled = !is_checked; + transform_menu->get_popup()->set_item_checked(transform_menu->get_popup()->get_item_index(p_option), snap_enabled); } break; case MENU_TRANSFORM_CONFIGURE_SNAP: { - snap_dialog->popup_centered(Size2(200,180)); + snap_dialog->popup_centered(Size2(200, 180)); } break; case MENU_TRANSFORM_LOCAL_COORDS: { - bool is_checked = transform_menu->get_popup()->is_item_checked( transform_menu->get_popup()->get_item_index(p_option) ); - transform_menu->get_popup()->set_item_checked( transform_menu->get_popup()->get_item_index(p_option), !is_checked ); + bool is_checked = transform_menu->get_popup()->is_item_checked(transform_menu->get_popup()->get_item_index(p_option)); + transform_menu->get_popup()->set_item_checked(transform_menu->get_popup()->get_item_index(p_option), !is_checked); update_transform_gizmo(); } break; case MENU_TRANSFORM_DIALOG: { - for(int i=0;i<3;i++) { - + for (int i = 0; i < 3; i++) { xform_translate[i]->set_text("0"); xform_rotate[i]->set_text("0"); xform_scale[i]->set_text("1"); - } - xform_dialog->popup_centered(Size2(200,200)); + xform_dialog->popup_centered(Size2(200, 200)); } break; case MENU_VIEW_USE_DEFAULT_LIGHT: { - bool is_checked = view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(p_option) ); + bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); if (is_checked) { VisualServer::get_singleton()->free(light_instance); - light_instance=RID(); + light_instance = RID(); } else { - light_instance=VisualServer::get_singleton()->instance_create2(light,get_tree()->get_root()->get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_transform(light_instance,light_transform); + light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario()); + VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform); _update_default_light_angle(); } - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(p_option), light_instance.is_valid() ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), light_instance.is_valid()); } break; case MENU_VIEW_USE_DEFAULT_SRGB: { - bool is_checked = view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(p_option) ); + bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); if (is_checked) { //viewport_environment->set_enable_fx(Environment::FX_SRGB,false); @@ -2842,82 +2649,77 @@ void SpatialEditor::_menu_item_pressed(int p_option) { //viewport_environment->set_enable_fx(Environment::FX_SRGB,true); } - is_checked = ! is_checked; - - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(p_option), is_checked ); + is_checked = !is_checked; + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), is_checked); } break; case MENU_VIEW_USE_1_VIEWPORT: { - for(int i=1;i<4;i++) { + for (int i = 1; i < 4; i++) { viewports[i]->hide(); } viewports[0]->set_area_as_parent_rect(); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false); } break; case MENU_VIEW_USE_2_VIEWPORTS: { - for(int i=1;i<4;i++) { + for (int i = 1; i < 4; i++) { - if (i==1 || i==3) + if (i == 1 || i == 3) viewports[i]->hide(); else viewports[i]->show(); - - } viewports[0]->set_area_as_parent_rect(); //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); viewports[2]->set_area_as_parent_rect(); //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false); } break; case MENU_VIEW_USE_2_VIEWPORTS_ALT: { - for(int i=1;i<4;i++) { + for (int i = 1; i < 4; i++) { - if (i==1 || i==3) + if (i == 1 || i == 3) viewports[i]->hide(); else viewports[i]->show(); - - } viewports[0]->set_area_as_parent_rect(); //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); viewports[2]->set_area_as_parent_rect(); //viewports[2]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false); } break; case MENU_VIEW_USE_3_VIEWPORTS: { - for(int i=1;i<4;i++) { + for (int i = 1; i < 4; i++) { - if (i==1) + if (i == 1) viewports[i]->hide(); else viewports[i]->show(); @@ -2931,19 +2733,19 @@ void SpatialEditor::_menu_item_pressed(int p_option) { //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false); } break; case MENU_VIEW_USE_3_VIEWPORTS_ALT: { - for(int i=1;i<4;i++) { + for (int i = 1; i < 4; i++) { - if (i==1) + if (i == 1) viewports[i]->hide(); else viewports[i]->show(); @@ -2957,17 +2759,17 @@ void SpatialEditor::_menu_item_pressed(int p_option) { viewports[3]->set_area_as_parent_rect(); //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), true ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), true); } break; case MENU_VIEW_USE_4_VIEWPORTS: { - for(int i=1;i<4;i++) { + for (int i = 1; i < 4; i++) { viewports[i]->show(); } @@ -2984,114 +2786,106 @@ void SpatialEditor::_menu_item_pressed(int p_option) { //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false); } break; case MENU_VIEW_DISPLAY_NORMAL: { + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_DISABLED); - VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_DISABLED ); - - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); } break; case MENU_VIEW_DISPLAY_WIREFRAME: { - VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_WIREFRAME ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false ); + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_WIREFRAME); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); } break; case MENU_VIEW_DISPLAY_OVERDRAW: { - VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), true ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false ); + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); } break; case MENU_VIEW_DISPLAY_SHADELESS: { - VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false ); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), true ); + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), true); } break; case MENU_VIEW_ORIGIN: { - bool is_checked = view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(p_option) ); + bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); - is_checked=!is_checked; - VisualServer::get_singleton()->instance_set_visible(origin_instance,is_checked); + is_checked = !is_checked; + VisualServer::get_singleton()->instance_set_visible(origin_instance, is_checked); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(p_option), is_checked); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), is_checked); } break; case MENU_VIEW_GRID: { - bool is_checked = view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(p_option) ); + bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); - grid_enabled=!is_checked; + grid_enabled = !is_checked; - for(int i=0;i<3;++i) { + for (int i = 0; i < 3; ++i) { if (grid_enable[i]) { - VisualServer::get_singleton()->instance_set_visible(grid_instance[i],grid_enabled); - grid_visible[i]=grid_enabled; + VisualServer::get_singleton()->instance_set_visible(grid_instance[i], grid_enabled); + grid_visible[i] = grid_enabled; } } - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(p_option), grid_enabled ); - + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), grid_enabled); } break; case MENU_VIEW_CAMERA_SETTINGS: { - settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size()+Size2(50,50)); + settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50)); } break; - } } - void SpatialEditor::_init_indicators() { //make sure that the camera indicator is not selectable - light=VisualServer::get_singleton()->light_create( VisualServer::LIGHT_DIRECTIONAL ); + light = VisualServer::get_singleton()->light_create(VisualServer::LIGHT_DIRECTIONAL); //VisualServer::get_singleton()->light_set_shadow( light, true ); - light_instance=VisualServer::get_singleton()->instance_create2(light,get_tree()->get_root()->get_world()->get_scenario()); - - - - light_transform.rotate(Vector3(1,0,0),-Math_PI/5.0); - VisualServer::get_singleton()->instance_set_transform(light_instance,light_transform); + light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario()); + light_transform.rotate(Vector3(1, 0, 0), -Math_PI / 5.0); + VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform); //RID mat = VisualServer::get_singleton()->fixed_material_create(); ///VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA,true); //VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); - { indicator_mat.instance(); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); //indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); - indicator_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); + indicator_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); PoolVector<Color> grid_colors[3]; PoolVector<Vector3> grid_points[3]; @@ -3100,185 +2894,165 @@ void SpatialEditor::_init_indicators() { Color grid_color = EditorSettings::get_singleton()->get("editors/3d/grid_color"); - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { Vector3 axis; - axis[i]=1; + axis[i] = 1; Vector3 axis_n1; - axis_n1[(i+1)%3]=1; + axis_n1[(i + 1) % 3] = 1; Vector3 axis_n2; - axis_n2[(i+2)%3]=1; + axis_n2[(i + 2) % 3] = 1; - origin_colors.push_back(Color(axis.x,axis.y,axis.z)); - origin_colors.push_back(Color(axis.x,axis.y,axis.z)); - origin_points.push_back(axis*4096); - origin_points.push_back(axis*-4096); + origin_colors.push_back(Color(axis.x, axis.y, axis.z)); + origin_colors.push_back(Color(axis.x, axis.y, axis.z)); + origin_points.push_back(axis * 4096); + origin_points.push_back(axis * -4096); #define ORIGIN_GRID_SIZE 25 - for(int j=-ORIGIN_GRID_SIZE;j<=ORIGIN_GRID_SIZE;j++) { - + for (int j = -ORIGIN_GRID_SIZE; j <= ORIGIN_GRID_SIZE; j++) { grid_colors[i].push_back(grid_color); grid_colors[i].push_back(grid_color); grid_colors[i].push_back(grid_color); grid_colors[i].push_back(grid_color); - grid_points[i].push_back(axis_n1*ORIGIN_GRID_SIZE+axis_n2*j); - grid_points[i].push_back(-axis_n1*ORIGIN_GRID_SIZE+axis_n2*j); - grid_points[i].push_back(axis_n2*ORIGIN_GRID_SIZE+axis_n1*j); - grid_points[i].push_back(-axis_n2*ORIGIN_GRID_SIZE+axis_n1*j); - + grid_points[i].push_back(axis_n1 * ORIGIN_GRID_SIZE + axis_n2 * j); + grid_points[i].push_back(-axis_n1 * ORIGIN_GRID_SIZE + axis_n2 * j); + grid_points[i].push_back(axis_n2 * ORIGIN_GRID_SIZE + axis_n1 * j); + grid_points[i].push_back(-axis_n2 * ORIGIN_GRID_SIZE + axis_n1 * j); } grid[i] = VisualServer::get_singleton()->mesh_create(); Array d; d.resize(VS::ARRAY_MAX); - d[VisualServer::ARRAY_VERTEX]=grid_points[i]; - d[VisualServer::ARRAY_COLOR]=grid_colors[i]; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i],VisualServer::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat->get_rid()); - grid_instance[i] = VisualServer::get_singleton()->instance_create2(grid[i],get_tree()->get_root()->get_world()->get_scenario()); - - grid_visible[i]=false; - grid_enable[i]=false; - VisualServer::get_singleton()->instance_set_visible(grid_instance[i],false); + d[VisualServer::ARRAY_VERTEX] = grid_points[i]; + d[VisualServer::ARRAY_COLOR] = grid_colors[i]; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], VisualServer::PRIMITIVE_LINES, d); + VisualServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid()); + grid_instance[i] = VisualServer::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario()); + + grid_visible[i] = false; + grid_enable[i] = false; + VisualServer::get_singleton()->instance_set_visible(grid_instance[i], false); VisualServer::get_singleton()->instance_geometry_set_cast_shadows_setting(grid_instance[i], VS::SHADOW_CASTING_SETTING_OFF); VS::get_singleton()->instance_set_layer_mask(grid_instance[i], 1 << SpatialEditorViewport::GIZMO_GRID_LAYER); - - } origin = VisualServer::get_singleton()->mesh_create(); Array d; d.resize(VS::ARRAY_MAX); - d[VisualServer::ARRAY_VERTEX]=origin_points; - d[VisualServer::ARRAY_COLOR]=origin_colors; - - VisualServer::get_singleton()->mesh_add_surface_from_arrays(origin,VisualServer::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(origin,0,indicator_mat->get_rid()); + d[VisualServer::ARRAY_VERTEX] = origin_points; + d[VisualServer::ARRAY_COLOR] = origin_colors; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(origin, VisualServer::PRIMITIVE_LINES, d); + VisualServer::get_singleton()->mesh_surface_set_material(origin, 0, indicator_mat->get_rid()); //origin = VisualServer::get_singleton()->poly_create(); //VisualServer::get_singleton()->poly_add_primitive(origin,origin_points,Vector<Vector3>(),origin_colors,Vector<Vector3>()); //VisualServer::get_singleton()->poly_set_material(origin,indicator_mat,true); - origin_instance = VisualServer::get_singleton()->instance_create2(origin,get_tree()->get_root()->get_world()->get_scenario()); - VS::get_singleton()->instance_set_layer_mask(origin_instance,1<<SpatialEditorViewport::GIZMO_GRID_LAYER); + origin_instance = VisualServer::get_singleton()->instance_create2(origin, get_tree()->get_root()->get_world()->get_scenario()); + VS::get_singleton()->instance_set_layer_mask(origin_instance, 1 << SpatialEditorViewport::GIZMO_GRID_LAYER); VisualServer::get_singleton()->instance_geometry_set_cast_shadows_setting(origin_instance, VS::SHADOW_CASTING_SETTING_OFF); - - - VisualServer::get_singleton()->instance_set_visible(grid_instance[1],true); - grid_enable[1]=true; - grid_visible[1]=true; - grid_enabled=true; - last_grid_snap=1; - + VisualServer::get_singleton()->instance_set_visible(grid_instance[1], true); + grid_enable[1] = true; + grid_visible[1] = true; + grid_enabled = true; + last_grid_snap = 1; } { cursor_mesh = VisualServer::get_singleton()->mesh_create(); PoolVector<Vector3> cursor_points; float cs = 0.25; - cursor_points.push_back(Vector3(+cs,0,0)); - cursor_points.push_back(Vector3(-cs,0,0)); - cursor_points.push_back(Vector3(0,+cs,0)); - cursor_points.push_back(Vector3(0,-cs,0)); - cursor_points.push_back(Vector3(0,0,+cs)); - cursor_points.push_back(Vector3(0,0,-cs)); + cursor_points.push_back(Vector3(+cs, 0, 0)); + cursor_points.push_back(Vector3(-cs, 0, 0)); + cursor_points.push_back(Vector3(0, +cs, 0)); + cursor_points.push_back(Vector3(0, -cs, 0)); + cursor_points.push_back(Vector3(0, 0, +cs)); + cursor_points.push_back(Vector3(0, 0, -cs)); cursor_material.instance(); - cursor_material->set_albedo(Color(0,1,1)); - cursor_material->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + cursor_material->set_albedo(Color(0, 1, 1)); + cursor_material->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); Array d; d.resize(VS::ARRAY_MAX); - d[VS::ARRAY_VERTEX]=cursor_points; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(cursor_mesh,VS::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(cursor_mesh,0,cursor_material->get_rid()); + d[VS::ARRAY_VERTEX] = cursor_points; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(cursor_mesh, VS::PRIMITIVE_LINES, d); + VisualServer::get_singleton()->mesh_surface_set_material(cursor_mesh, 0, cursor_material->get_rid()); - cursor_instance = VisualServer::get_singleton()->instance_create2(cursor_mesh,get_tree()->get_root()->get_world()->get_scenario()); - VS::get_singleton()->instance_set_layer_mask(cursor_instance,1<<SpatialEditorViewport::GIZMO_GRID_LAYER); + cursor_instance = VisualServer::get_singleton()->instance_create2(cursor_mesh, get_tree()->get_root()->get_world()->get_scenario()); + VS::get_singleton()->instance_set_layer_mask(cursor_instance, 1 << SpatialEditorViewport::GIZMO_GRID_LAYER); VisualServer::get_singleton()->instance_geometry_set_cast_shadows_setting(cursor_instance, VS::SHADOW_CASTING_SETTING_OFF); - - } - { //move gizmo - float gizmo_alph = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_opacity"); - gizmo_hl = Ref<FixedSpatialMaterial>( memnew( FixedSpatialMaterial ) ); + gizmo_hl = Ref<FixedSpatialMaterial>(memnew(FixedSpatialMaterial)); gizmo_hl->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); gizmo_hl->set_flag(FixedSpatialMaterial::FLAG_ONTOP, true); gizmo_hl->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); - gizmo_hl->set_albedo(Color(1,1,1,gizmo_alph+0.2f)); + gizmo_hl->set_albedo(Color(1, 1, 1, gizmo_alph + 0.2f)); - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { - move_gizmo[i]=Ref<Mesh>( memnew( Mesh ) ); - rotate_gizmo[i]=Ref<Mesh>( memnew( Mesh ) ); + move_gizmo[i] = Ref<Mesh>(memnew(Mesh)); + rotate_gizmo[i] = Ref<Mesh>(memnew(Mesh)); - - Ref<FixedSpatialMaterial> mat = memnew( FixedSpatialMaterial ); + Ref<FixedSpatialMaterial> mat = memnew(FixedSpatialMaterial); mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP, true); mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); Color col; - col[i]=1.0; - col.a= gizmo_alph; + col[i] = 1.0; + col.a = gizmo_alph; mat->set_albedo(col); - gizmo_color[i]=mat; - - - + gizmo_color[i] = mat; Vector3 ivec; - ivec[i]=1; + ivec[i] = 1; Vector3 nivec; - nivec[(i+1)%3]=1; - nivec[(i+2)%3]=1; + nivec[(i + 1) % 3] = 1; + nivec[(i + 2) % 3] = 1; Vector3 ivec2; - ivec2[(i+1)%3]=1; + ivec2[(i + 1) % 3] = 1; Vector3 ivec3; - ivec3[(i+2)%3]=1; - + ivec3[(i + 2) % 3] = 1; { - Ref<SurfaceTool> surftool = memnew( SurfaceTool ); + Ref<SurfaceTool> surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); //translate - const int arrow_points=5; - Vector3 arrow[5]={ - nivec*0.0+ivec*0.0, - nivec*0.01+ivec*0.0, - nivec*0.01+ivec*1.0, - nivec*0.1+ivec*1.0, - nivec*0.0+ivec*(1+GIZMO_ARROW_SIZE), + const int arrow_points = 5; + Vector3 arrow[5] = { + nivec * 0.0 + ivec * 0.0, + nivec * 0.01 + ivec * 0.0, + nivec * 0.01 + ivec * 1.0, + nivec * 0.1 + ivec * 1.0, + nivec * 0.0 + ivec * (1 + GIZMO_ARROW_SIZE), }; - int arrow_sides=6; + int arrow_sides = 6; + for (int k = 0; k < 7; k++) { - for(int k = 0; k < 7 ; k++) { + Basis ma(ivec, Math_PI * 2 * float(k) / arrow_sides); + Basis mb(ivec, Math_PI * 2 * float(k + 1) / arrow_sides); + for (int j = 0; j < arrow_points - 1; j++) { - Basis ma(ivec,Math_PI*2*float(k)/arrow_sides); - Basis mb(ivec,Math_PI*2*float(k+1)/arrow_sides); - - - for(int j=0;j<arrow_points-1;j++) { - - Vector3 points[4]={ + Vector3 points[4] = { ma.xform(arrow[j]), mb.xform(arrow[j]), - mb.xform(arrow[j+1]), - ma.xform(arrow[j+1]), + mb.xform(arrow[j + 1]), + ma.xform(arrow[j + 1]), }; surftool->add_vertex(points[0]); surftool->add_vertex(points[1]); @@ -3288,7 +3062,6 @@ void SpatialEditor::_init_indicators() { surftool->add_vertex(points[2]); surftool->add_vertex(points[3]); } - } surftool->set_material(mat); @@ -3297,33 +3070,29 @@ void SpatialEditor::_init_indicators() { { - - Ref<SurfaceTool> surftool = memnew( SurfaceTool ); + Ref<SurfaceTool> surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); - Vector3 circle[5]={ - ivec*0.02+ivec2*0.02+ivec2*1.0, - ivec*-0.02+ivec2*0.02+ivec2*1.0, - ivec*-0.02+ivec2*-0.02+ivec2*1.0, - ivec*0.02+ivec2*-0.02+ivec2*1.0, - ivec*0.02+ivec2*0.02+ivec2*1.0, + Vector3 circle[5] = { + ivec * 0.02 + ivec2 * 0.02 + ivec2 * 1.0, + ivec * -0.02 + ivec2 * 0.02 + ivec2 * 1.0, + ivec * -0.02 + ivec2 * -0.02 + ivec2 * 1.0, + ivec * 0.02 + ivec2 * -0.02 + ivec2 * 1.0, + ivec * 0.02 + ivec2 * 0.02 + ivec2 * 1.0, }; + for (int k = 0; k < 33; k++) { - for(int k = 0; k < 33 ; k++) { + Basis ma(ivec, Math_PI * 2 * float(k) / 32); + Basis mb(ivec, Math_PI * 2 * float(k + 1) / 32); + for (int j = 0; j < 4; j++) { - Basis ma(ivec,Math_PI*2*float(k)/32); - Basis mb(ivec,Math_PI*2*float(k+1)/32); - - - for(int j=0;j<4;j++) { - - Vector3 points[4]={ + Vector3 points[4] = { ma.xform(circle[j]), mb.xform(circle[j]), - mb.xform(circle[j+1]), - ma.xform(circle[j+1]), + mb.xform(circle[j + 1]), + ma.xform(circle[j + 1]), }; surftool->add_vertex(points[0]); surftool->add_vertex(points[1]); @@ -3333,15 +3102,11 @@ void SpatialEditor::_init_indicators() { surftool->add_vertex(points[2]); surftool->add_vertex(points[3]); } - } surftool->set_material(mat); surftool->commit(rotate_gizmo[i]); - } - - } } @@ -3352,18 +3117,16 @@ void SpatialEditor::_init_indicators() { _generate_selection_box(); - //get_scene()->get_root_node()->cast_to<EditorNode>()->get_scene_root()->add_child(camera); //current_camera=camera; - } void SpatialEditor::_finish_indicators() { VisualServer::get_singleton()->free(origin_instance); VisualServer::get_singleton()->free(origin); - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { VisualServer::get_singleton()->free(grid_instance[i]); VisualServer::get_singleton()->free(grid[i]); } @@ -3427,17 +3190,16 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) { } #endif - switch(p_event.type) { + switch (p_event.type) { case InputEvent::KEY: { - - const InputEventKey &k=p_event.key; + const InputEventKey &k = p_event.key; if (!k.pressed) break; - switch(k.scancode) { + switch (k.scancode) { case KEY_Q: _menu_item_pressed(MENU_TOOL_SELECT); break; case KEY_W: _menu_item_pressed(MENU_TOOL_MOVE); break; @@ -3448,7 +3210,7 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) { if (k.mod.shift || k.mod.control || k.mod.command) break; - if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME))) { + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME))) { _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL); } else { _menu_item_pressed(MENU_VIEW_DISPLAY_WIREFRAME); @@ -3464,55 +3226,51 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) { } void SpatialEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY) { - tool_button[SpatialEditor::TOOL_MODE_SELECT]->set_icon( get_icon("ToolSelect","EditorIcons") ); - tool_button[SpatialEditor::TOOL_MODE_MOVE]->set_icon( get_icon("ToolMove","EditorIcons") ); - tool_button[SpatialEditor::TOOL_MODE_ROTATE]->set_icon( get_icon("ToolRotate","EditorIcons") ); - tool_button[SpatialEditor::TOOL_MODE_SCALE]->set_icon( get_icon("ToolScale","EditorIcons") ); - tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon( get_icon("ListSelect","EditorIcons") ); - instance_button->set_icon( get_icon("SpatialAdd","EditorIcons") ); + tool_button[SpatialEditor::TOOL_MODE_SELECT]->set_icon(get_icon("ToolSelect", "EditorIcons")); + tool_button[SpatialEditor::TOOL_MODE_MOVE]->set_icon(get_icon("ToolMove", "EditorIcons")); + tool_button[SpatialEditor::TOOL_MODE_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons")); + tool_button[SpatialEditor::TOOL_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons")); + tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_icon("ListSelect", "EditorIcons")); + instance_button->set_icon(get_icon("SpatialAdd", "EditorIcons")); instance_button->hide(); - - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT),get_icon("Panels1","EditorIcons")); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS),get_icon("Panels2","EditorIcons")); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT),get_icon("Panels2Alt","EditorIcons")); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS),get_icon("Panels3","EditorIcons")); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT),get_icon("Panels3Alt","EditorIcons")); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS),get_icon("Panels4","EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_icon("Panels1", "EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_icon("Panels2", "EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), get_icon("Panels2Alt", "EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), get_icon("Panels3", "EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), get_icon("Panels3Alt", "EditorIcons")); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), get_icon("Panels4", "EditorIcons")); _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - get_tree()->connect("node_removed",this,"_node_removed"); - VS::get_singleton()->scenario_set_fallback_environment(get_viewport()->find_world()->get_scenario(),viewport_environment->get_rid()); - + get_tree()->connect("node_removed", this, "_node_removed"); + VS::get_singleton()->scenario_set_fallback_environment(get_viewport()->find_world()->get_scenario(), viewport_environment->get_rid()); } - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - gizmos = memnew( SpatialEditorGizmos ); + gizmos = memnew(SpatialEditorGizmos); _init_indicators(); _update_default_light_angle(); } - if (p_what==NOTIFICATION_EXIT_TREE) { + if (p_what == NOTIFICATION_EXIT_TREE) { _finish_indicators(); - memdelete( gizmos ); - + memdelete(gizmos); } } void SpatialEditor::add_control_to_menu_panel(Control *p_control) { - hbc_menu->add_child(p_control); } -void SpatialEditor::set_can_preview(Camera* p_preview) { +void SpatialEditor::set_can_preview(Camera *p_preview) { - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { viewports[i]->set_can_preview(p_preview); } } @@ -3527,17 +3285,16 @@ HSplitContainer *SpatialEditor::get_palette_split() { return palette_split; } +void SpatialEditor::_request_gizmo(Object *p_obj) { -void SpatialEditor::_request_gizmo(Object* p_obj) { - - Spatial *sp=p_obj->cast_to<Spatial>(); + Spatial *sp = p_obj->cast_to<Spatial>(); if (!sp) return; - if (editor->get_edited_scene() && (sp==editor->get_edited_scene() || sp->get_owner()==editor->get_edited_scene() || editor->get_edited_scene()->is_editable_instance(sp->get_owner()))) { + if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || sp->get_owner() == editor->get_edited_scene() || editor->get_edited_scene()->is_editable_instance(sp->get_owner()))) { Ref<SpatialEditorGizmo> seg; - for(int i=0;i<EditorNode::get_singleton()->get_editor_data().get_editor_plugin_count();i++) { + for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_editor_plugin_count(); i++) { seg = EditorNode::get_singleton()->get_editor_data().get_editor_plugin(i)->create_spatial_gizmo(sp); if (seg.is_valid()) @@ -3552,265 +3309,246 @@ void SpatialEditor::_request_gizmo(Object* p_obj) { sp->set_gizmo(seg); } - - if (seg.is_valid() && sp==selected) { + if (seg.is_valid() && sp == selected) { seg->set_selected(true); selected->update_gizmo(); } - } } -void SpatialEditor::_toggle_maximize_view(Object* p_viewport) { +void SpatialEditor::_toggle_maximize_view(Object *p_viewport) { if (!p_viewport) return; SpatialEditorViewport *current_viewport = p_viewport->cast_to<SpatialEditorViewport>(); if (!current_viewport) return; - int index=-1; + int index = -1; bool maximized = false; - for(int i=0;i<4;i++) { - if (viewports[i]==current_viewport) { - index=i; - if ( current_viewport->get_global_rect() == viewport_base->get_global_rect() ) - maximized=true; + for (int i = 0; i < 4; i++) { + if (viewports[i] == current_viewport) { + index = i; + if (current_viewport->get_global_rect() == viewport_base->get_global_rect()) + maximized = true; break; } } - if (index==-1) return; + if (index == -1) return; if (!maximized) { - for(int i=0;i<4;i++) { - if (i==index) + for (int i = 0; i < 4; i++) { + if (i == index) viewports[i]->set_area_as_parent_rect(); else viewports[i]->hide(); } } else { - for(int i=0;i<4;i++) + for (int i = 0; i < 4; i++) viewports[i]->show(); - if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT) )) + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS) )) + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS); - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT) )) + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT); - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS) )) + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS); - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT) )) + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT); - else if (view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS) )) + else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) _menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS); } - } +void SpatialEditor::_node_removed(Node *p_node) { -void SpatialEditor::_node_removed(Node* p_node) { - - if (p_node==selected) - selected=NULL; + if (p_node == selected) + selected = NULL; } void SpatialEditor::_bind_methods() { //ClassDB::bind_method("_gui_input",&SpatialEditor::_gui_input); - ClassDB::bind_method("_unhandled_key_input",&SpatialEditor::_unhandled_key_input); - ClassDB::bind_method("_node_removed",&SpatialEditor::_node_removed); - ClassDB::bind_method("_menu_item_pressed",&SpatialEditor::_menu_item_pressed); - ClassDB::bind_method("_xform_dialog_action",&SpatialEditor::_xform_dialog_action); - ClassDB::bind_method("_instance_scene",&SpatialEditor::_instance_scene); - ClassDB::bind_method("_get_editor_data",&SpatialEditor::_get_editor_data); - ClassDB::bind_method("_request_gizmo",&SpatialEditor::_request_gizmo); - ClassDB::bind_method("_default_light_angle_input",&SpatialEditor::_default_light_angle_input); - ClassDB::bind_method("_update_ambient_light_color",&SpatialEditor::_update_ambient_light_color); - ClassDB::bind_method("_toggle_maximize_view",&SpatialEditor::_toggle_maximize_view); - - ADD_SIGNAL( MethodInfo("transform_key_request") ); - + ClassDB::bind_method("_unhandled_key_input", &SpatialEditor::_unhandled_key_input); + ClassDB::bind_method("_node_removed", &SpatialEditor::_node_removed); + ClassDB::bind_method("_menu_item_pressed", &SpatialEditor::_menu_item_pressed); + ClassDB::bind_method("_xform_dialog_action", &SpatialEditor::_xform_dialog_action); + ClassDB::bind_method("_instance_scene", &SpatialEditor::_instance_scene); + ClassDB::bind_method("_get_editor_data", &SpatialEditor::_get_editor_data); + ClassDB::bind_method("_request_gizmo", &SpatialEditor::_request_gizmo); + ClassDB::bind_method("_default_light_angle_input", &SpatialEditor::_default_light_angle_input); + ClassDB::bind_method("_update_ambient_light_color", &SpatialEditor::_update_ambient_light_color); + ClassDB::bind_method("_toggle_maximize_view", &SpatialEditor::_toggle_maximize_view); + ADD_SIGNAL(MethodInfo("transform_key_request")); } void SpatialEditor::clear() { - settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov",60.0)); - settings_znear->set_value(EDITOR_DEF("editors/3d/default_z_near",0.1)); - settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far",1500.0)); + settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 60.0)); + settings_znear->set_value(EDITOR_DEF("editors/3d/default_z_near", 0.1)); + settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far", 1500.0)); - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { viewports[i]->reset(); } _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL); - - VisualServer::get_singleton()->instance_set_visible(origin_instance,true); - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN), true); - for(int i=0;i<3;++i) { + VisualServer::get_singleton()->instance_set_visible(origin_instance, true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN), true); + for (int i = 0; i < 3; ++i) { if (grid_enable[i]) { - VisualServer::get_singleton()->instance_set_visible(grid_instance[i],true); - grid_visible[i]=true; + VisualServer::get_singleton()->instance_set_visible(grid_instance[i], true); + grid_visible[i] = true; } } - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { - viewports[i]->view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(SpatialEditorViewport::VIEW_AUDIO_LISTENER),i==0); - viewports[i]->viewport->set_as_audio_listener(i==0); + viewports[i]->view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(SpatialEditorViewport::VIEW_AUDIO_LISTENER), i == 0); + viewports[i]->viewport->set_as_audio_listener(i == 0); } - view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_GRID), true ); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID), true); - settings_default_light_rot_x=Math_PI*0.3; - settings_default_light_rot_y=Math_PI*0.2; + settings_default_light_rot_x = Math_PI * 0.3; + settings_default_light_rot_y = Math_PI * 0.2; //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15)); - settings_ambient_color->set_pick_color(Color(0.15,0.15,0.15)); + settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15)); if (!light_instance.is_valid()) _menu_item_pressed(MENU_VIEW_USE_DEFAULT_LIGHT); _update_default_light_angle(); - - } - -void SpatialEditor::_update_ambient_light_color(const Color& p_color) { +void SpatialEditor::_update_ambient_light_color(const Color &p_color) { //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,settings_ambient_color->get_color()); - } void SpatialEditor::_update_default_light_angle() { Transform t; - t.basis.rotate(Vector3(1,0,0),-settings_default_light_rot_x); - t.basis.rotate(Vector3(0,1,0),-settings_default_light_rot_y); + t.basis.rotate(Vector3(1, 0, 0), -settings_default_light_rot_x); + t.basis.rotate(Vector3(0, 1, 0), -settings_default_light_rot_y); settings_dlight->set_transform(t); if (light_instance.is_valid()) { - VS::get_singleton()->instance_set_transform(light_instance,t); + VS::get_singleton()->instance_set_transform(light_instance, t); } - } -void SpatialEditor::_default_light_angle_input(const InputEvent& p_event) { - +void SpatialEditor::_default_light_angle_input(const InputEvent &p_event) { - if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&(0x1|0x2|0x4)) { + if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & (0x1 | 0x2 | 0x4)) { - settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - p_event.mouse_motion.relative_x*0.01,Math_PI*2.0); - settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - p_event.mouse_motion.relative_y*0.01,Math_PI*2.0); + settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - p_event.mouse_motion.relative_x * 0.01, Math_PI * 2.0); + settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - p_event.mouse_motion.relative_y * 0.01, Math_PI * 2.0); _update_default_light_angle(); } - } - SpatialEditor::SpatialEditor(EditorNode *p_editor) { - gizmo.visible=true; - gizmo.scale=1.0; + gizmo.visible = true; + gizmo.scale = 1.0; - viewport_environment = Ref<Environment>( memnew( Environment ) ); - undo_redo=p_editor->get_undo_redo(); + viewport_environment = Ref<Environment>(memnew(Environment)); + undo_redo = p_editor->get_undo_redo(); VBoxContainer *vbc = this; - custom_camera=NULL; - singleton=this; - editor=p_editor; - editor_selection=editor->get_editor_selection(); + custom_camera = NULL; + singleton = this; + editor = p_editor; + editor_selection = editor->get_editor_selection(); editor_selection->add_editor_plugin(this); - snap_enabled=false; + snap_enabled = false; tool_mode = TOOL_MODE_SELECT; //set_focus_mode(FOCUS_ALL); - hbc_menu = memnew( HBoxContainer ); + hbc_menu = memnew(HBoxContainer); vbc->add_child(hbc_menu); - Vector<Variant> button_binds; button_binds.resize(1); - tool_button[TOOL_MODE_SELECT] = memnew( ToolButton ); - hbc_menu->add_child( tool_button[TOOL_MODE_SELECT] ); + tool_button[TOOL_MODE_SELECT] = memnew(ToolButton); + hbc_menu->add_child(tool_button[TOOL_MODE_SELECT]); tool_button[TOOL_MODE_SELECT]->set_toggle_mode(true); tool_button[TOOL_MODE_SELECT]->set_flat(true); tool_button[TOOL_MODE_SELECT]->set_pressed(true); - button_binds[0]=MENU_TOOL_SELECT; - tool_button[TOOL_MODE_SELECT]->connect("pressed", this,"_menu_item_pressed",button_binds); - tool_button[TOOL_MODE_SELECT]->set_tooltip("Select Mode (Q)\n"+keycode_get_string(KEY_MASK_CMD)+"Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection"); - + button_binds[0] = MENU_TOOL_SELECT; + tool_button[TOOL_MODE_SELECT]->connect("pressed", this, "_menu_item_pressed", button_binds); + tool_button[TOOL_MODE_SELECT]->set_tooltip("Select Mode (Q)\n" + keycode_get_string(KEY_MASK_CMD) + "Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection"); - tool_button[TOOL_MODE_MOVE] = memnew( ToolButton ); + tool_button[TOOL_MODE_MOVE] = memnew(ToolButton); - hbc_menu->add_child( tool_button[TOOL_MODE_MOVE] ); + hbc_menu->add_child(tool_button[TOOL_MODE_MOVE]); tool_button[TOOL_MODE_MOVE]->set_toggle_mode(true); tool_button[TOOL_MODE_MOVE]->set_flat(true); - button_binds[0]=MENU_TOOL_MOVE; - tool_button[TOOL_MODE_MOVE]->connect("pressed", this,"_menu_item_pressed",button_binds); + button_binds[0] = MENU_TOOL_MOVE; + tool_button[TOOL_MODE_MOVE]->connect("pressed", this, "_menu_item_pressed", button_binds); tool_button[TOOL_MODE_MOVE]->set_tooltip(TTR("Move Mode (W)")); - tool_button[TOOL_MODE_ROTATE] = memnew( ToolButton ); - hbc_menu->add_child( tool_button[TOOL_MODE_ROTATE] ); + tool_button[TOOL_MODE_ROTATE] = memnew(ToolButton); + hbc_menu->add_child(tool_button[TOOL_MODE_ROTATE]); tool_button[TOOL_MODE_ROTATE]->set_toggle_mode(true); tool_button[TOOL_MODE_ROTATE]->set_flat(true); - button_binds[0]=MENU_TOOL_ROTATE; - tool_button[TOOL_MODE_ROTATE]->connect("pressed", this,"_menu_item_pressed",button_binds); + button_binds[0] = MENU_TOOL_ROTATE; + tool_button[TOOL_MODE_ROTATE]->connect("pressed", this, "_menu_item_pressed", button_binds); tool_button[TOOL_MODE_ROTATE]->set_tooltip(TTR("Rotate Mode (E)")); - tool_button[TOOL_MODE_SCALE] = memnew( ToolButton ); - hbc_menu->add_child( tool_button[TOOL_MODE_SCALE] ); + tool_button[TOOL_MODE_SCALE] = memnew(ToolButton); + hbc_menu->add_child(tool_button[TOOL_MODE_SCALE]); tool_button[TOOL_MODE_SCALE]->set_toggle_mode(true); tool_button[TOOL_MODE_SCALE]->set_flat(true); - button_binds[0]=MENU_TOOL_SCALE; - tool_button[TOOL_MODE_SCALE]->connect("pressed", this,"_menu_item_pressed",button_binds); + button_binds[0] = MENU_TOOL_SCALE; + tool_button[TOOL_MODE_SCALE]->connect("pressed", this, "_menu_item_pressed", button_binds); tool_button[TOOL_MODE_SCALE]->set_tooltip(TTR("Scale Mode (R)")); - instance_button = memnew( Button ); - hbc_menu->add_child( instance_button ); + instance_button = memnew(Button); + hbc_menu->add_child(instance_button); instance_button->set_flat(true); - instance_button->connect("pressed",this,"_instance_scene"); + instance_button->connect("pressed", this, "_instance_scene"); instance_button->hide(); - VSeparator *vs = memnew( VSeparator ); + VSeparator *vs = memnew(VSeparator); hbc_menu->add_child(vs); - tool_button[TOOL_MODE_LIST_SELECT] = memnew( ToolButton ); - hbc_menu->add_child( tool_button[TOOL_MODE_LIST_SELECT] ); + tool_button[TOOL_MODE_LIST_SELECT] = memnew(ToolButton); + hbc_menu->add_child(tool_button[TOOL_MODE_LIST_SELECT]); tool_button[TOOL_MODE_LIST_SELECT]->set_toggle_mode(true); tool_button[TOOL_MODE_LIST_SELECT]->set_flat(true); - button_binds[0]=MENU_TOOL_LIST_SELECT; - tool_button[TOOL_MODE_LIST_SELECT]->connect("pressed", this,"_menu_item_pressed",button_binds); + button_binds[0] = MENU_TOOL_LIST_SELECT; + tool_button[TOOL_MODE_LIST_SELECT]->connect("pressed", this, "_menu_item_pressed", button_binds); tool_button[TOOL_MODE_LIST_SELECT]->set_tooltip(TTR("Show a list of all objects at the position clicked\n(same as Alt+RMB in select mode).")); - vs = memnew( VSeparator ); + vs = memnew(VSeparator); hbc_menu->add_child(vs); - - ED_SHORTCUT("spatial_editor/bottom_view", TTR("Bottom View"), KEY_MASK_ALT+KEY_KP_7); + ED_SHORTCUT("spatial_editor/bottom_view", TTR("Bottom View"), KEY_MASK_ALT + KEY_KP_7); ED_SHORTCUT("spatial_editor/top_view", TTR("Top View"), KEY_KP_7); - ED_SHORTCUT("spatial_editor/rear_view", TTR("Rear View"), KEY_MASK_ALT+KEY_KP_1); + ED_SHORTCUT("spatial_editor/rear_view", TTR("Rear View"), KEY_MASK_ALT + KEY_KP_1); ED_SHORTCUT("spatial_editor/front_view", TTR("Front View"), KEY_KP_1); - ED_SHORTCUT("spatial_editor/left_view", TTR("Left View"), KEY_MASK_ALT+KEY_KP_3); + ED_SHORTCUT("spatial_editor/left_view", TTR("Left View"), KEY_MASK_ALT + KEY_KP_3); ED_SHORTCUT("spatial_editor/right_view", TTR("Right View"), KEY_KP_3); ED_SHORTCUT("spatial_editor/switch_perspective_orthogonal", TTR("Switch Perspective/Orthogonal view"), KEY_KP_5); ED_SHORTCUT("spatial_editor/snap", TTR("Snap"), KEY_S); ED_SHORTCUT("spatial_editor/insert_anim_key", TTR("Insert Animation Key"), KEY_K); ED_SHORTCUT("spatial_editor/focus_origin", TTR("Focus Origin"), KEY_O); ED_SHORTCUT("spatial_editor/focus_selection", TTR("Focus Selection"), KEY_F); - ED_SHORTCUT("spatial_editor/align_selection_with_view", TTR("Align Selection With View"), KEY_MASK_ALT+KEY_MASK_CMD+KEY_F); - + ED_SHORTCUT("spatial_editor/align_selection_with_view", TTR("Align Selection With View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_F); PopupMenu *p; - transform_menu = memnew( MenuButton ); + transform_menu = memnew(MenuButton); transform_menu->set_text(TTR("Transform")); - hbc_menu->add_child( transform_menu ); + hbc_menu->add_child(transform_menu); p = transform_menu->get_popup(); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_snap", TTR("Use Snap")), MENU_TRANSFORM_USE_SNAP); @@ -3821,12 +3559,12 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/transform_dialog", TTR("Transform Dialog..")), MENU_TRANSFORM_DIALOG); - p->connect("id_pressed", this,"_menu_item_pressed"); + p->connect("id_pressed", this, "_menu_item_pressed"); - view_menu = memnew( MenuButton ); + view_menu = memnew(MenuButton); view_menu->set_text(TTR("View")); - view_menu->set_pos( Point2( 212,0) ); - hbc_menu->add_child( view_menu ); + view_menu->set_pos(Point2(212, 0)); + hbc_menu->add_child(view_menu); p = view_menu->get_popup(); @@ -3834,12 +3572,12 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_default_srgb", TTR("Use Default sRGB")), MENU_VIEW_USE_DEFAULT_SRGB); p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/1_viewport", TTR("1 Viewport"), KEY_MASK_CMD+KEY_1), MENU_VIEW_USE_1_VIEWPORT); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports", TTR("2 Viewports"), KEY_MASK_CMD+KEY_2), MENU_VIEW_USE_2_VIEWPORTS); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports_alt", TTR("2 Viewports (Alt)"), KEY_MASK_ALT+KEY_MASK_CMD+KEY_2), MENU_VIEW_USE_2_VIEWPORTS_ALT); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports", TTR("3 Viewports"),KEY_MASK_CMD+KEY_3), MENU_VIEW_USE_3_VIEWPORTS); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports_alt", TTR("3 Viewports (Alt)"), KEY_MASK_ALT+KEY_MASK_CMD+KEY_3), MENU_VIEW_USE_3_VIEWPORTS_ALT); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/4_viewports", TTR("4 Viewports"), KEY_MASK_CMD+KEY_4), MENU_VIEW_USE_4_VIEWPORTS); + p->add_check_shortcut(ED_SHORTCUT("spatial_editor/1_viewport", TTR("1 Viewport"), KEY_MASK_CMD + KEY_1), MENU_VIEW_USE_1_VIEWPORT); + p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports", TTR("2 Viewports"), KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS); + p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports_alt", TTR("2 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS_ALT); + p->add_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports", TTR("3 Viewports"), KEY_MASK_CMD + KEY_3), MENU_VIEW_USE_3_VIEWPORTS); + p->add_check_shortcut(ED_SHORTCUT("spatial_editor/3_viewports_alt", TTR("3 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_3), MENU_VIEW_USE_3_VIEWPORTS_ALT); + p->add_check_shortcut(ED_SHORTCUT("spatial_editor/4_viewports", TTR("4 Viewports"), KEY_MASK_CMD + KEY_4), MENU_VIEW_USE_4_VIEWPORTS); p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_normal", TTR("Display Normal")), MENU_VIEW_DISPLAY_NORMAL); @@ -3852,212 +3590,195 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS); + p->set_item_checked(p->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), true); + p->set_item_checked(p->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true); + p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true); + p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true); - p->set_item_checked( p->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), true ); - p->set_item_checked( p->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true ); - p->set_item_checked( p->get_item_index(MENU_VIEW_ORIGIN), true ); - p->set_item_checked( p->get_item_index(MENU_VIEW_GRID), true ); - - - p->connect("id_pressed", this,"_menu_item_pressed"); - + p->connect("id_pressed", this, "_menu_item_pressed"); /* REST OF MENU */ - palette_split = memnew( HSplitContainer); + palette_split = memnew(HSplitContainer); palette_split->set_v_size_flags(SIZE_EXPAND_FILL); vbc->add_child(palette_split); - shader_split = memnew( VSplitContainer ); + shader_split = memnew(VSplitContainer); shader_split->set_h_size_flags(SIZE_EXPAND_FILL); palette_split->add_child(shader_split); - viewport_base = memnew( Control ); + viewport_base = memnew(Control); shader_split->add_child(viewport_base); viewport_base->set_v_size_flags(SIZE_EXPAND_FILL); - for(int i=0;i<4;i++) { + for (int i = 0; i < 4; i++) { - viewports[i] = memnew( SpatialEditorViewport(this,editor,i) ); - viewports[i]->connect("toggle_maximize_view",this,"_toggle_maximize_view"); + viewports[i] = memnew(SpatialEditorViewport(this, editor, i)); + viewports[i]->connect("toggle_maximize_view", this, "_toggle_maximize_view"); viewport_base->add_child(viewports[i]); } //vbc->add_child(viewport_base); - - - /* SNAP DIALOG */ - snap_dialog = memnew( ConfirmationDialog ); + snap_dialog = memnew(ConfirmationDialog); snap_dialog->set_title(TTR("Snap Settings")); add_child(snap_dialog); - VBoxContainer *snap_dialog_vbc = memnew( VBoxContainer ); + VBoxContainer *snap_dialog_vbc = memnew(VBoxContainer); snap_dialog->add_child(snap_dialog_vbc); //snap_dialog->set_child_rect(snap_dialog_vbc); - snap_translate = memnew( LineEdit ); + snap_translate = memnew(LineEdit); snap_translate->set_text("1"); - snap_dialog_vbc->add_margin_child(TTR("Translate Snap:"),snap_translate); + snap_dialog_vbc->add_margin_child(TTR("Translate Snap:"), snap_translate); - snap_rotate = memnew( LineEdit ); + snap_rotate = memnew(LineEdit); snap_rotate->set_text("5"); - snap_dialog_vbc->add_margin_child(TTR("Rotate Snap (deg.):"),snap_rotate); + snap_dialog_vbc->add_margin_child(TTR("Rotate Snap (deg.):"), snap_rotate); - snap_scale = memnew( LineEdit ); + snap_scale = memnew(LineEdit); snap_scale->set_text("5"); - snap_dialog_vbc->add_margin_child(TTR("Scale Snap (%):"),snap_scale); + snap_dialog_vbc->add_margin_child(TTR("Scale Snap (%):"), snap_scale); /* SETTINGS DIALOG */ - settings_dialog = memnew( ConfirmationDialog ); + settings_dialog = memnew(ConfirmationDialog); settings_dialog->set_title(TTR("Viewport Settings")); add_child(settings_dialog); - settings_vbc = memnew( VBoxContainer ); - settings_vbc->set_custom_minimum_size(Size2(200,0)); + settings_vbc = memnew(VBoxContainer); + settings_vbc->set_custom_minimum_size(Size2(200, 0)); settings_dialog->add_child(settings_vbc); //settings_dialog->set_child_rect(settings_vbc); - - - settings_light_base = memnew( ViewportContainer ); - settings_light_base->set_custom_minimum_size(Size2(128,128)); - settings_light_base->connect("gui_input",this,"_default_light_angle_input"); - settings_vbc->add_margin_child(TTR("Default Light Normal:"),settings_light_base); - settings_light_vp = memnew( Viewport ); + settings_light_base = memnew(ViewportContainer); + settings_light_base->set_custom_minimum_size(Size2(128, 128)); + settings_light_base->connect("gui_input", this, "_default_light_angle_input"); + settings_vbc->add_margin_child(TTR("Default Light Normal:"), settings_light_base); + settings_light_vp = memnew(Viewport); settings_light_vp->set_disable_input(true); settings_light_vp->set_use_own_world(true); settings_light_base->add_child(settings_light_vp); - settings_dlight = memnew( DirectionalLight ); + settings_dlight = memnew(DirectionalLight); settings_light_vp->add_child(settings_dlight); - settings_sphere = memnew( ImmediateGeometry ); - settings_sphere->begin(Mesh::PRIMITIVE_TRIANGLES,Ref<Texture>()); - settings_sphere->set_color(Color(1,1,1)); - settings_sphere->add_sphere(32,16,1); + settings_sphere = memnew(ImmediateGeometry); + settings_sphere->begin(Mesh::PRIMITIVE_TRIANGLES, Ref<Texture>()); + settings_sphere->set_color(Color(1, 1, 1)); + settings_sphere->add_sphere(32, 16, 1); settings_sphere->end(); settings_light_vp->add_child(settings_sphere); - settings_camera = memnew( Camera ); + settings_camera = memnew(Camera); settings_light_vp->add_child(settings_camera); - settings_camera->set_translation(Vector3(0,0,2)); - settings_camera->set_orthogonal(2.1,0.1,5); - - settings_default_light_rot_x=Math_PI*0.3; - settings_default_light_rot_y=Math_PI*0.2; - - + settings_camera->set_translation(Vector3(0, 0, 2)); + settings_camera->set_orthogonal(2.1, 0.1, 5); - settings_ambient_color = memnew( ColorPickerButton ); - settings_vbc->add_margin_child(TTR("Ambient Light Color:"),settings_ambient_color); - settings_ambient_color->connect("color_changed",this,"_update_ambient_light_color"); - settings_ambient_color->set_pick_color(Color(0.15,0.15,0.15)); + settings_default_light_rot_x = Math_PI * 0.3; + settings_default_light_rot_y = Math_PI * 0.2; + settings_ambient_color = memnew(ColorPickerButton); + settings_vbc->add_margin_child(TTR("Ambient Light Color:"), settings_ambient_color); + settings_ambient_color->connect("color_changed", this, "_update_ambient_light_color"); + settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15)); - settings_fov = memnew( SpinBox ); + settings_fov = memnew(SpinBox); settings_fov->set_max(179); settings_fov->set_min(1); settings_fov->set_step(0.01); - settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov",60.0)); - settings_vbc->add_margin_child(TTR("Perspective FOV (deg.):"),settings_fov); + settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 60.0)); + settings_vbc->add_margin_child(TTR("Perspective FOV (deg.):"), settings_fov); - settings_znear = memnew( SpinBox ); + settings_znear = memnew(SpinBox); settings_znear->set_max(10000); settings_znear->set_min(0.1); settings_znear->set_step(0.01); - settings_znear->set_value(EDITOR_DEF("editors/3d/default_z_near",0.1)); - settings_vbc->add_margin_child(TTR("View Z-Near:"),settings_znear); + settings_znear->set_value(EDITOR_DEF("editors/3d/default_z_near", 0.1)); + settings_vbc->add_margin_child(TTR("View Z-Near:"), settings_znear); - settings_zfar = memnew( SpinBox ); + settings_zfar = memnew(SpinBox); settings_zfar->set_max(10000); settings_zfar->set_min(0.1); settings_zfar->set_step(0.01); - settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far",1500)); - settings_vbc->add_margin_child(TTR("View Z-Far:"),settings_zfar); + settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far", 1500)); + settings_vbc->add_margin_child(TTR("View Z-Far:"), settings_zfar); //settings_dialog->get_cancel()->hide(); /* XFORM DIALOG */ - xform_dialog = memnew( ConfirmationDialog ); + xform_dialog = memnew(ConfirmationDialog); xform_dialog->set_title(TTR("Transform Change")); add_child(xform_dialog); Label *l = memnew(Label); l->set_text(TTR("Translate:")); - l->set_pos(Point2(5,5)); + l->set_pos(Point2(5, 5)); xform_dialog->add_child(l); - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { - xform_translate[i] = memnew( LineEdit ); - xform_translate[i]->set_pos( Point2(15+i*60,22) ); - xform_translate[i]->set_size( Size2(50,12 ) ); - xform_dialog->add_child( xform_translate[i] ); + xform_translate[i] = memnew(LineEdit); + xform_translate[i]->set_pos(Point2(15 + i * 60, 22)); + xform_translate[i]->set_size(Size2(50, 12)); + xform_dialog->add_child(xform_translate[i]); } l = memnew(Label); l->set_text(TTR("Rotate (deg.):")); - l->set_pos(Point2(5,45)); + l->set_pos(Point2(5, 45)); xform_dialog->add_child(l); - for(int i=0;i<3;i++) { - xform_rotate[i] = memnew( LineEdit ); - xform_rotate[i]->set_pos( Point2(15+i*60,62) ); - xform_rotate[i]->set_size( Size2(50,22 ) ); + for (int i = 0; i < 3; i++) { + xform_rotate[i] = memnew(LineEdit); + xform_rotate[i]->set_pos(Point2(15 + i * 60, 62)); + xform_rotate[i]->set_size(Size2(50, 22)); xform_dialog->add_child(xform_rotate[i]); } l = memnew(Label); l->set_text(TTR("Scale (ratio):")); - l->set_pos(Point2(5,85)); + l->set_pos(Point2(5, 85)); xform_dialog->add_child(l); - for(int i=0;i<3;i++) { - xform_scale[i] = memnew( LineEdit ); - xform_scale[i]->set_pos( Point2(15+i*60,102) ); - xform_scale[i]->set_size( Size2(50,22 ) ); + for (int i = 0; i < 3; i++) { + xform_scale[i] = memnew(LineEdit); + xform_scale[i]->set_pos(Point2(15 + i * 60, 102)); + xform_scale[i]->set_size(Size2(50, 22)); xform_dialog->add_child(xform_scale[i]); } l = memnew(Label); l->set_text(TTR("Transform Type")); - l->set_pos(Point2(5,125)); + l->set_pos(Point2(5, 125)); xform_dialog->add_child(l); - xform_type = memnew( OptionButton ); - xform_type->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - xform_type->set_begin( Point2(15,142) ); - xform_type->set_end( Point2(15,75) ); + xform_type = memnew(OptionButton); + xform_type->set_anchor(MARGIN_RIGHT, ANCHOR_END); + xform_type->set_begin(Point2(15, 142)); + xform_type->set_end(Point2(15, 75)); xform_type->add_item(TTR("Pre")); xform_type->add_item(TTR("Post")); xform_dialog->add_child(xform_type); - xform_dialog->connect("confirmed", this,"_xform_dialog_action"); + xform_dialog->connect("confirmed", this, "_xform_dialog_action"); - scenario_debug=VisualServer::SCENARIO_DEBUG_DISABLED; + scenario_debug = VisualServer::SCENARIO_DEBUG_DISABLED; - selected=NULL; + selected = NULL; set_process_unhandled_key_input(true); add_to_group("_spatial_editor_group"); - EDITOR_DEF("editors/3d/manipulator_gizmo_size",80); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,"editors/3d/manipulator_gizmo_size",PROPERTY_HINT_RANGE,"16,1024,1")); - EDITOR_DEF("editors/3d/manipulator_gizmo_opacity",0.2); + EDITOR_DEF("editors/3d/manipulator_gizmo_size", 80); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/3d/manipulator_gizmo_size", PROPERTY_HINT_RANGE, "16,1024,1")); + EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.2); - over_gizmo_handle=-1; + over_gizmo_handle = -1; } SpatialEditor::~SpatialEditor() { - - } - - - void SpatialEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - spatial_editor->show(); spatial_editor->set_process(true); //VisualServer::get_singleton()->viewport_set_hide_scenario(editor->get_scene_root()->get_viewport(),false); @@ -4068,9 +3789,7 @@ void SpatialEditorPlugin::make_visible(bool p_visible) { spatial_editor->hide(); spatial_editor->set_process(false); //VisualServer::get_singleton()->viewport_set_hide_scenario(editor->get_scene_root()->get_viewport(),true); - } - } void SpatialEditorPlugin::edit(Object *p_object) { @@ -4086,46 +3805,39 @@ Dictionary SpatialEditorPlugin::get_state() const { return spatial_editor->get_state(); } -void SpatialEditorPlugin::set_state(const Dictionary& p_state) { +void SpatialEditorPlugin::set_state(const Dictionary &p_state) { spatial_editor->set_state(p_state); } -void SpatialEditor::snap_cursor_to_plane(const Plane& p_plane) { +void SpatialEditor::snap_cursor_to_plane(const Plane &p_plane) { //cursor.pos=p_plane.project(cursor.pos); } void SpatialEditorPlugin::_bind_methods() { - ClassDB::bind_method("snap_cursor_to_plane",&SpatialEditorPlugin::snap_cursor_to_plane); - + ClassDB::bind_method("snap_cursor_to_plane", &SpatialEditorPlugin::snap_cursor_to_plane); } -void SpatialEditorPlugin::snap_cursor_to_plane(const Plane& p_plane) { - +void SpatialEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) { spatial_editor->snap_cursor_to_plane(p_plane); } - - - SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) { - editor=p_node; - spatial_editor = memnew( SpatialEditor(p_node) ); + editor = p_node; + spatial_editor = memnew(SpatialEditor(p_node)); spatial_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); editor->get_viewport()->add_child(spatial_editor); //spatial_editor->set_area_as_parent_rect(); spatial_editor->hide(); - spatial_editor->connect("transform_key_request",editor,"_transform_keyed"); + spatial_editor->connect("transform_key_request", editor, "_transform_keyed"); //spatial_editor->set_process(true); } - SpatialEditorPlugin::~SpatialEditorPlugin() { - } diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 44ce4a0281..e0d2a38956 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -29,11 +29,11 @@ #ifndef SPATIAL_EDITOR_PLUGIN_H #define SPATIAL_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "scene/3d/visual_instance.h" +#include "editor/editor_plugin.h" #include "scene/3d/immediate_geometry.h" #include "scene/3d/light.h" +#include "scene/3d/visual_instance.h" #include "scene/gui/panel_container.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -45,29 +45,28 @@ class SpatialEditorGizmos; class SpatialEditorGizmo : public SpatialGizmo { - GDCLASS(SpatialEditorGizmo,SpatialGizmo); + GDCLASS(SpatialEditorGizmo, SpatialGizmo); bool selected; -public: - void set_selected(bool p_selected) { selected=p_selected; } +public: + void set_selected(bool p_selected) { selected = p_selected; } bool is_selected() const { return selected; } virtual String get_handle_name(int p_idx) const; virtual Variant get_handle_value(int p_idx) const; - virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point); - virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false); + virtual void set_handle(int p_idx, Camera *p_camera, const Point2 &p_point); + virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false); - virtual bool intersect_frustum(const Camera *p_camera,const Vector<Plane> &p_frustum); - virtual bool intersect_ray(const Camera *p_camera,const Point2& p_point, Vector3& r_pos, Vector3& r_normal,int *r_gizmo_handle=NULL,bool p_sec_first=false); + virtual bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum); + virtual bool intersect_ray(const Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = NULL, bool p_sec_first = false); SpatialEditorGizmo(); }; - class SpatialEditorViewport : public Control { - GDCLASS( SpatialEditorViewport, Control ); -friend class SpatialEditor; + GDCLASS(SpatialEditorViewport, Control); + friend class SpatialEditor; enum { VIEW_TOP, @@ -85,12 +84,14 @@ friend class SpatialEditor; VIEW_AUDIO_LISTENER, VIEW_GIZMOS, }; + public: enum { - GIZMO_BASE_LAYER=27, - GIZMO_EDIT_LAYER=26, - GIZMO_GRID_LAYER=25 + GIZMO_BASE_LAYER = 27, + GIZMO_EDIT_LAYER = 26, + GIZMO_GRID_LAYER = 25 }; + private: int index; String name; @@ -114,31 +115,31 @@ private: struct _RayResult { - Spatial* item; + Spatial *item; float depth; int handle; - _FORCE_INLINE_ bool operator<(const _RayResult& p_rr) const { return depth<p_rr.depth; } + _FORCE_INLINE_ bool operator<(const _RayResult &p_rr) const { return depth < p_rr.depth; } }; void _update_name(); - void _compute_edit(const Point2& p_point); + void _compute_edit(const Point2 &p_point); void _clear_selected(); - void _select_clicked(bool p_append,bool p_single); - void _select(Spatial *p_node, bool p_append,bool p_single); - ObjectID _select_ray(const Point2& p_pos, bool p_append,bool &r_includes_current,int *r_gizmo_handle=NULL,bool p_alt_select=false); - void _find_items_at_pos(const Point2& p_pos,bool &r_includes_current,Vector<_RayResult> &results,bool p_alt_select=false); - Vector3 _get_ray_pos(const Vector2& p_pos) const; - Vector3 _get_ray(const Vector2& p_pos); - Point2 _point_to_screen(const Vector3& p_point); + void _select_clicked(bool p_append, bool p_single); + void _select(Spatial *p_node, bool p_append, bool p_single); + ObjectID _select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle = NULL, bool p_alt_select = false); + void _find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select = false); + Vector3 _get_ray_pos(const Vector2 &p_pos) const; + Vector3 _get_ray(const Vector2 &p_pos); + Point2 _point_to_screen(const Vector3 &p_point); Transform _get_camera_transform() const; int get_selected_count() const; Vector3 _get_camera_pos() const; Vector3 _get_camera_normal() const; - Vector3 _get_screen_to_space(const Vector3& p_vector3); + Vector3 _get_screen_to_space(const Vector3 &p_vector3); void _select_region(); - bool _gizmo_select(const Vector2& p_screenpos,bool p_hilite_only=false); + bool _gizmo_select(const Vector2 &p_screenpos, bool p_hilite_only = false); float get_znear() const; float get_zfar() const; @@ -204,32 +205,35 @@ private: Vector3 cursor_pos; Vector3 pos; - float x_rot,y_rot,distance; + float x_rot, y_rot, distance; bool region_select; - Point2 region_begin,region_end; + Point2 region_begin, region_end; - Cursor() { x_rot=y_rot=0.5; distance=4; region_select=false; } + Cursor() { + x_rot = y_rot = 0.5; + distance = 4; + region_select = false; + } } cursor; RID move_gizmo_instance[3], rotate_gizmo_instance[3]; - String last_message; String message; float message_time; - void set_message(String p_message,float p_time=5); + void set_message(String p_message, float p_time = 5); // void _update_camera(); void _draw(); void _smouseenter(); - void _sinput(const InputEvent& p_ie); + void _sinput(const InputEvent &p_ie); SpatialEditor *spatial_editor; - Camera* previewing; - Camera* preview; + Camera *previewing; + Camera *preview; void _preview_exited_scene(); void _toggle_camera_preview(bool); @@ -239,17 +243,15 @@ private: void _selection_menu_hide(); void _list_select(InputEventMouseButton b); - protected: - void _notification(int p_what); static void _bind_methods(); -public: +public: void update_transform_gizmo_view(); - void set_can_preview(Camera* p_preview); - void set_state(const Dictionary& p_state); + void set_can_preview(Camera *p_preview); + void set_state(const Dictionary &p_state); Dictionary get_state() const; void reset(); @@ -257,33 +259,29 @@ public: Viewport *get_viewport_node() { return viewport; } - - SpatialEditorViewport(SpatialEditor *p_spatial_editor,EditorNode *p_editor,int p_index); + SpatialEditorViewport(SpatialEditor *p_spatial_editor, EditorNode *p_editor, int p_index); }; - - class SpatialEditorSelectedItem : public Object { - GDCLASS(SpatialEditorSelectedItem,Object); + GDCLASS(SpatialEditorSelectedItem, Object); public: - Rect3 aabb; Transform original; // original location when moving Transform last_xform; // last transform Spatial *sp; RID sbox_instance; - SpatialEditorSelectedItem() { sp=NULL; } + SpatialEditorSelectedItem() { sp = NULL; } ~SpatialEditorSelectedItem(); }; class SpatialEditor : public VBoxContainer { - GDCLASS(SpatialEditor, VBoxContainer ); -public: + GDCLASS(SpatialEditor, VBoxContainer); +public: enum ToolMode { TOOL_MODE_SELECT, @@ -295,13 +293,10 @@ public: }; - private: EditorNode *editor; EditorSelection *editor_selection; - - Control *viewport_base; SpatialEditorViewport *viewports[4]; VSplitContainer *shader_split; @@ -312,14 +307,12 @@ private: ToolMode tool_mode; bool orthogonal; - VisualServer::ScenarioDebugMode scenario_debug; RID light; RID light_instance; Transform light_transform; - RID origin; RID origin_instance; RID grid[3]; @@ -333,11 +326,8 @@ private: Ref<FixedSpatialMaterial> gizmo_color[3]; Ref<FixedSpatialMaterial> gizmo_hl; - int over_gizmo_handle; - - Ref<Mesh> selection_box; RID indicators; RID indicators_instance; @@ -346,7 +336,7 @@ private: Ref<FixedSpatialMaterial> indicator_mat; Ref<FixedSpatialMaterial> cursor_material; -/* + /* struct Selected { AABB aabb; Transform original; // original location when moving @@ -364,9 +354,6 @@ private: Transform transform; } gizmo; - - - enum MenuOption { MENU_TOOL_SELECT, @@ -396,13 +383,11 @@ private: }; - Button *tool_button[TOOL_MAX]; Button *instance_button; - - MenuButton* transform_menu; - MenuButton* view_menu; + MenuButton *transform_menu; + MenuButton *view_menu; ConfirmationDialog *snap_dialog; ConfirmationDialog *xform_dialog; @@ -412,7 +397,7 @@ private: LineEdit *snap_translate; LineEdit *snap_rotate; LineEdit *snap_scale; - PanelContainer* menu_panel; + PanelContainer *menu_panel; LineEdit *xform_translate[3]; LineEdit *xform_rotate[3]; @@ -434,16 +419,13 @@ private: ColorPickerButton *settings_ambient_color; Image settings_light_dir_image; - void _xform_dialog_action(); void _menu_item_pressed(int p_option); HBoxContainer *hbc_menu; - - -// -// + // + // void _generate_selection_box(); UndoRedo *undo_redo; @@ -451,7 +433,7 @@ private: void _init_indicators(); void _finish_indicators(); - void _toggle_maximize_view(Object* p_viewport); + void _toggle_maximize_view(Object *p_viewport); Node *custom_camera; @@ -461,33 +443,28 @@ private: Spatial *selected; - void _request_gizmo(Object* p_obj); + void _request_gizmo(Object *p_obj); static SpatialEditor *singleton; - void _node_removed(Node* p_node); + void _node_removed(Node *p_node); SpatialEditorGizmos *gizmos; SpatialEditor(); - void _update_ambient_light_color(const Color& p_color); + void _update_ambient_light_color(const Color &p_color); void _update_default_light_angle(); - void _default_light_angle_input(const InputEvent& p_event); + void _default_light_angle_input(const InputEvent &p_event); protected: - - - - void _notification(int p_what); //void _gui_input(InputEvent p_event); void _unhandled_key_input(InputEvent p_event); static void _bind_methods(); -public: - +public: static SpatialEditor *get_singleton() { return singleton; } - void snap_cursor_to_plane(const Plane& p_plane); + void snap_cursor_to_plane(const Plane &p_plane); float get_znear() const { return settings_znear->get_value(); } float get_zfar() const { return settings_zfar->get_value(); } @@ -508,11 +485,11 @@ public: void update_transform_gizmo(); void select_gizmo_hilight_axis(int p_axis); - void set_custom_camera(Node *p_camera) { custom_camera=p_camera; } + void set_custom_camera(Node *p_camera) { custom_camera = p_camera; } - 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; } Dictionary get_state() const; - void set_state(const Dictionary& p_state); + void set_state(const Dictionary &p_state); Ref<Environment> get_viewport_environment() { return viewport_environment; } @@ -526,12 +503,12 @@ public: Spatial *get_selected() { return selected; } int get_over_gizmo_handle() const { return over_gizmo_handle; } - void set_over_gizmo_handle(int idx) { over_gizmo_handle=idx; } + void set_over_gizmo_handle(int idx) { over_gizmo_handle = idx; } - void set_can_preview(Camera* p_preview); + void set_can_preview(Camera *p_preview); SpatialEditorViewport *get_editor_viewport(int p_idx) { - ERR_FAIL_INDEX_V(p_idx,4,NULL); + ERR_FAIL_INDEX_V(p_idx, 4, NULL); return viewports[p_idx]; } @@ -544,15 +521,16 @@ public: class SpatialEditorPlugin : public EditorPlugin { - GDCLASS( SpatialEditorPlugin, EditorPlugin ); + GDCLASS(SpatialEditorPlugin, EditorPlugin); SpatialEditor *spatial_editor; EditorNode *editor; + protected: static void _bind_methods(); -public: - void snap_cursor_to_plane(const Plane& p_plane); +public: + void snap_cursor_to_plane(const Plane &p_plane); SpatialEditor *get_spatial_editor() { return spatial_editor; } virtual String get_name() const { return "3D"; } @@ -562,13 +540,11 @@ public: virtual bool handles(Object *p_object) const; virtual Dictionary get_state() const; - virtual void set_state(const Dictionary& p_state); + virtual void set_state(const Dictionary &p_state); virtual void clear() { spatial_editor->clear(); } - SpatialEditorPlugin(EditorNode *p_node); ~SpatialEditorPlugin(); - }; #endif diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 44d6d3c6e1..7adfb90e6f 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -28,51 +28,44 @@ /*************************************************************************/ #include "sprite_frames_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" #include "scene/3d/sprite_3d.h" - - void SpriteFramesEditor::_gui_input(InputEvent p_event) { - - } void SpriteFramesEditor::_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") ); - new_anim->set_icon( get_icon("New","EditorIcons") ); - remove_anim->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")); + new_anim->set_icon(get_icon("New", "EditorIcons")); + remove_anim->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<Variant>(),true); } - if (p_what==NOTIFICATION_DRAW) { - + if (p_what == NOTIFICATION_DRAW) { } } -void SpriteFramesEditor::_file_load_request(const PoolVector<String>& p_path,int p_at_pos) { +void SpriteFramesEditor::_file_load_request(const PoolVector<String> &p_path, int p_at_pos) { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - List< Ref<Texture> > resources; + List<Ref<Texture> > resources; - for(int i=0;i<p_path.size();i++) { + for (int i = 0; i < p_path.size(); i++) { - Ref<Texture> resource; + Ref<Texture> resource; resource = ResourceLoader::load(p_path[i]); if (resource.is_null()) { @@ -87,26 +80,24 @@ void SpriteFramesEditor::_file_load_request(const PoolVector<String>& p_path,int resources.push_back(resource); } - if (resources.empty()) { //print_line("added frames!"); return; } undo_redo->create_action(TTR("Add Frame")); - int fc=frames->get_frame_count(edited_anim); + int fc = frames->get_frame_count(edited_anim); - int count=0; + int count = 0; - for(List< Ref<Texture> >::Element *E=resources.front();E;E=E->next() ) { + for (List<Ref<Texture> >::Element *E = resources.front(); E; E = E->next()) { - undo_redo->add_do_method(frames,"add_frame",edited_anim,E->get(),p_at_pos==-1?-1:p_at_pos+count); - undo_redo->add_undo_method(frames,"remove_frame",edited_anim,p_at_pos==-1?fc:p_at_pos); + undo_redo->add_do_method(frames, "add_frame", edited_anim, E->get(), p_at_pos == -1 ? -1 : p_at_pos + count); + undo_redo->add_undo_method(frames, "remove_frame", edited_anim, p_at_pos == -1 ? fc : p_at_pos); count++; - } - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); //print_line("added frames!"); @@ -115,21 +106,19 @@ void SpriteFramesEditor::_file_load_request(const PoolVector<String>& p_path,int void SpriteFramesEditor::_load_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - loading_scene=false; + loading_scene = false; file->clear_filters(); List<String> extensions; - ResourceLoader::get_recognized_extensions_for_type("Texture",&extensions); - for(int i=0;i<extensions.size();i++) - file->add_filter("*."+extensions[i]); + ResourceLoader::get_recognized_extensions_for_type("Texture", &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 SpriteFramesEditor::_item_edited() { #if 0 @@ -163,38 +152,35 @@ void SpriteFramesEditor::_item_edited() { } #endif - } void SpriteFramesEditor::_delete_confirm_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - if (tree->get_current()<0) + if (tree->get_current() < 0) return; - sel-=1; - if (sel<0 && frames->get_frame_count(edited_anim)) - sel=0; + sel -= 1; + if (sel < 0 && frames->get_frame_count(edited_anim)) + sel = 0; int to_remove = tree->get_current(); - sel=to_remove; - Ref<Texture> r = frames->get_frame(edited_anim,to_remove); + sel = to_remove; + Ref<Texture> r = frames->get_frame(edited_anim, to_remove); undo_redo->create_action(TTR("Delete Resource")); - undo_redo->add_do_method(frames,"remove_frame",edited_anim,to_remove); - undo_redo->add_undo_method(frames,"add_frame",edited_anim,r,to_remove); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "remove_frame", edited_anim, to_remove); + undo_redo->add_undo_method(frames, "add_frame", edited_anim, r, to_remove); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } - void SpriteFramesEditor::_paste_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - Ref<Texture> r=EditorSettings::get_singleton()->get_resource_clipboard(); + Ref<Texture> r = EditorSettings::get_singleton()->get_resource_clipboard(); if (!r.is_valid()) { dialog->set_text(TTR("Resource clipboard is empty or not a texture!")); dialog->set_title(TTR("Error!")); @@ -204,131 +190,117 @@ void SpriteFramesEditor::_paste_pressed() { return; ///beh should show an error i guess } - undo_redo->create_action(TTR("Paste Frame")); - undo_redo->add_do_method(frames,"add_frame",edited_anim,r); - undo_redo->add_undo_method(frames,"remove_frame",edited_anim,frames->get_frame_count(edited_anim)); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "add_frame", edited_anim, r); + undo_redo->add_undo_method(frames, "remove_frame", edited_anim, frames->get_frame_count(edited_anim)); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } void SpriteFramesEditor::_empty_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - int from=-1; + int from = -1; - if (tree->get_current()>=0) { + if (tree->get_current() >= 0) { from = tree->get_current(); - sel=from; + sel = from; } else { - from=frames->get_frame_count(edited_anim); + from = frames->get_frame_count(edited_anim); } - - Ref<Texture> r; undo_redo->create_action(TTR("Add Empty")); - undo_redo->add_do_method(frames,"add_frame",edited_anim,r,from); - undo_redo->add_undo_method(frames,"remove_frame",edited_anim,from); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from); + undo_redo->add_undo_method(frames, "remove_frame", edited_anim, from); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } void SpriteFramesEditor::_empty2_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - int from=-1; + int from = -1; - if (tree->get_current()>=0) { + if (tree->get_current() >= 0) { from = tree->get_current(); - sel=from; + sel = from; } else { - from=frames->get_frame_count(edited_anim); + from = frames->get_frame_count(edited_anim); } - - Ref<Texture> r; undo_redo->create_action(TTR("Add Empty")); - undo_redo->add_do_method(frames,"add_frame",edited_anim,r,from+1); - undo_redo->add_undo_method(frames,"remove_frame",edited_anim,from+1); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "add_frame", edited_anim, r, from + 1); + undo_redo->add_undo_method(frames, "remove_frame", edited_anim, from + 1); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } void SpriteFramesEditor::_up_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - if (tree->get_current()<0) + if (tree->get_current() < 0) return; int to_move = tree->get_current(); - if (to_move<1) + if (to_move < 1) return; - sel=to_move; - sel-=1; + sel = to_move; + sel -= 1; - Ref<Texture> r = frames->get_frame(edited_anim,to_move); + Ref<Texture> r = frames->get_frame(edited_anim, to_move); undo_redo->create_action(TTR("Delete Resource")); - undo_redo->add_do_method(frames,"set_frame",edited_anim,to_move,frames->get_frame(edited_anim,to_move-1)); - undo_redo->add_do_method(frames,"set_frame",edited_anim,to_move-1,frames->get_frame(edited_anim,to_move)); - undo_redo->add_undo_method(frames,"set_frame",edited_anim,to_move,frames->get_frame(edited_anim,to_move)); - undo_redo->add_undo_method(frames,"set_frame",edited_anim,to_move-1,frames->get_frame(edited_anim,to_move-1)); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move - 1)); + undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move - 1, frames->get_frame(edited_anim, to_move)); + undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move)); + undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move - 1, frames->get_frame(edited_anim, to_move - 1)); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } void SpriteFramesEditor::_down_pressed() { ERR_FAIL_COND(!frames->has_animation(edited_anim)); - if (tree->get_current()<0) + if (tree->get_current() < 0) return; int to_move = tree->get_current(); - if (to_move<0 || to_move>=frames->get_frame_count(edited_anim)-1) + if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1) return; - sel=to_move; - sel+=1; + sel = to_move; + sel += 1; - Ref<Texture> r = frames->get_frame(edited_anim,to_move); + Ref<Texture> r = frames->get_frame(edited_anim, to_move); undo_redo->create_action(TTR("Delete Resource")); - undo_redo->add_do_method(frames,"set_frame",edited_anim,to_move,frames->get_frame(edited_anim,to_move+1)); - undo_redo->add_do_method(frames,"set_frame",edited_anim,to_move+1,frames->get_frame(edited_anim,to_move)); - undo_redo->add_undo_method(frames,"set_frame",edited_anim,to_move,frames->get_frame(edited_anim,to_move)); - undo_redo->add_undo_method(frames,"set_frame",edited_anim,to_move+1,frames->get_frame(edited_anim,to_move+1)); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move + 1)); + undo_redo->add_do_method(frames, "set_frame", edited_anim, to_move + 1, frames->get_frame(edited_anim, to_move)); + undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move, frames->get_frame(edited_anim, to_move)); + undo_redo->add_undo_method(frames, "set_frame", edited_anim, to_move + 1, frames->get_frame(edited_anim, to_move + 1)); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - - - } - void SpriteFramesEditor::_delete_pressed() { - - if (tree->get_current()<0) + if (tree->get_current() < 0) return; _delete_confirm_pressed(); //it has undo.. why bother with a dialog.. @@ -339,10 +311,8 @@ void SpriteFramesEditor::_delete_pressed() { //dialog->get_ok()->show(); dialog->get_ok()->set_text("Remove"); dialog->popup_centered(Size2(300,60));*/ - } - void SpriteFramesEditor::_animation_select() { if (updating) @@ -350,41 +320,38 @@ void SpriteFramesEditor::_animation_select() { TreeItem *selected = animations->get_selected(); ERR_FAIL_COND(!selected); - edited_anim=selected->get_text(0); + edited_anim = selected->get_text(0); _update_library(true); - } - -static void _find_anim_sprites(Node* p_node,List<Node*> *r_nodes,Ref<SpriteFrames> p_sfames) { +static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFrames> p_sfames) { Node *edited = EditorNode::get_singleton()->get_edited_scene(); if (!edited) return; - if (p_node!=edited && p_node->get_owner()!=edited) + if (p_node != edited && p_node->get_owner() != edited) return; { AnimatedSprite *as = p_node->cast_to<AnimatedSprite>(); - if (as && as->get_sprite_frames()==p_sfames) { + if (as && as->get_sprite_frames() == p_sfames) { r_nodes->push_back(p_node); } } { AnimatedSprite3D *as = p_node->cast_to<AnimatedSprite3D>(); - if (as && as->get_sprite_frames()==p_sfames) { + if (as && as->get_sprite_frames() == p_sfames) { r_nodes->push_back(p_node); } } - for(int i=0;i<p_node->get_child_count();i++) { - _find_anim_sprites(p_node->get_child(i),r_nodes,p_sfames); + for (int i = 0; i < p_node->get_child_count(); i++) { + _find_anim_sprites(p_node->get_child(i), r_nodes, p_sfames); } - } -void SpriteFramesEditor::_animation_name_edited(){ +void SpriteFramesEditor::_animation_name_edited() { if (updating) return; @@ -398,86 +365,77 @@ void SpriteFramesEditor::_animation_name_edited(){ String new_name = edited->get_text(0); - if (new_name==String(edited_anim)) + if (new_name == String(edited_anim)) return; - new_name=new_name.replace("/","_").replace(","," "); + new_name = new_name.replace("/", "_").replace(",", " "); - String name=new_name; - int counter=0; - while(frames->has_animation(name)) { + String name = new_name; + int counter = 0; + while (frames->has_animation(name)) { counter++; - name=new_name+" "+itos(counter); + name = new_name + " " + itos(counter); } - List<Node*> nodes; - _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(),&nodes,Ref<SpriteFrames>(frames)); + List<Node *> nodes; + _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(), &nodes, Ref<SpriteFrames>(frames)); undo_redo->create_action(TTR("Rename Animation")); - undo_redo->add_do_method(frames,"rename_animation",edited_anim,name); - undo_redo->add_undo_method(frames,"rename_animation",name,edited_anim); + undo_redo->add_do_method(frames, "rename_animation", edited_anim, name); + undo_redo->add_undo_method(frames, "rename_animation", name, edited_anim); - for(List<Node*>::Element *E=nodes.front();E;E=E->next()) { + for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { String current = E->get()->call("get_animation"); - if (current!=edited_anim) + if (current != edited_anim) continue; - undo_redo->add_do_method(E->get(),"set_animation",name); - undo_redo->add_undo_method(E->get(),"set_animation",edited_anim); - + undo_redo->add_do_method(E->get(), "set_animation", name); + undo_redo->add_undo_method(E->get(), "set_animation", edited_anim); } - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); - edited_anim=new_name; + edited_anim = new_name; undo_redo->commit_action(); - - - } -void SpriteFramesEditor::_animation_add(){ - +void SpriteFramesEditor::_animation_add() { String new_name = "New Anim"; - String name=new_name; - int counter=0; - while(frames->has_animation(name)) { + String name = new_name; + int counter = 0; + while (frames->has_animation(name)) { counter++; - name=new_name+" "+itos(counter); + name = new_name + " " + itos(counter); } - List<Node*> nodes; - _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(),&nodes,Ref<SpriteFrames>(frames)); - + List<Node *> nodes; + _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(), &nodes, Ref<SpriteFrames>(frames)); undo_redo->create_action(TTR("Add Animation")); - undo_redo->add_do_method(frames,"add_animation",name); - undo_redo->add_undo_method(frames,"remove_animation",name); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "add_animation", name); + undo_redo->add_undo_method(frames, "remove_animation", name); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); - - for(List<Node*>::Element *E=nodes.front();E;E=E->next()) { + for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { String current = E->get()->call("get_animation"); if (frames->has_animation(current)) continue; - undo_redo->add_do_method(E->get(),"set_animation",name); - undo_redo->add_undo_method(E->get(),"set_animation",current); - + undo_redo->add_do_method(E->get(), "set_animation", name); + undo_redo->add_undo_method(E->get(), "set_animation", current); } - edited_anim=new_name; + edited_anim = new_name; undo_redo->commit_action(); - } -void SpriteFramesEditor::_animation_remove(){ +void SpriteFramesEditor::_animation_remove() { //fuck everything if (updating) @@ -486,37 +444,33 @@ void SpriteFramesEditor::_animation_remove(){ if (!frames->has_animation(edited_anim)) return; - undo_redo->create_action(TTR("Remove Animation")); - undo_redo->add_do_method(frames,"remove_animation",edited_anim); - undo_redo->add_undo_method(frames,"add_animation",edited_anim); - undo_redo->add_undo_method(frames,"set_animation_speed",edited_anim,frames->get_animation_speed(edited_anim)); - undo_redo->add_undo_method(frames,"set_animation_loop",edited_anim,frames->get_animation_loop(edited_anim)); + undo_redo->add_do_method(frames, "remove_animation", edited_anim); + undo_redo->add_undo_method(frames, "add_animation", edited_anim); + undo_redo->add_undo_method(frames, "set_animation_speed", edited_anim, frames->get_animation_speed(edited_anim)); + undo_redo->add_undo_method(frames, "set_animation_loop", edited_anim, frames->get_animation_loop(edited_anim)); int fc = frames->get_frame_count(edited_anim); - for(int i=0;i<fc;i++) { - Ref<Texture> frame = frames->get_frame(edited_anim,i); - undo_redo->add_undo_method(frames,"add_frame",edited_anim,frame); + for (int i = 0; i < fc; i++) { + Ref<Texture> frame = frames->get_frame(edited_anim, i); + undo_redo->add_undo_method(frames, "add_frame", edited_anim, frame); } - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(this, "_update_library"); + undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); - } - void SpriteFramesEditor::_animation_loop_changed() { if (updating) return; undo_redo->create_action(TTR("Change Animation Loop")); - undo_redo->add_do_method(frames,"set_animation_loop",edited_anim,anim_loop->is_pressed()); - undo_redo->add_undo_method(frames,"set_animation_loop",edited_anim,frames->get_animation_loop(edited_anim)); - undo_redo->add_do_method(this,"_update_library",true); - undo_redo->add_undo_method(this,"_update_library",true); + undo_redo->add_do_method(frames, "set_animation_loop", edited_anim, anim_loop->is_pressed()); + undo_redo->add_undo_method(frames, "set_animation_loop", edited_anim, frames->get_animation_loop(edited_anim)); + undo_redo->add_do_method(this, "_update_library", true); + undo_redo->add_undo_method(this, "_update_library", true); undo_redo->commit_action(); - } void SpriteFramesEditor::_animation_fps_changed(double p_value) { @@ -524,24 +478,23 @@ void SpriteFramesEditor::_animation_fps_changed(double p_value) { if (updating) return; - undo_redo->create_action(TTR("Change Animation FPS"),UndoRedo::MERGE_ENDS); - undo_redo->add_do_method(frames,"set_animation_speed",edited_anim,p_value); - undo_redo->add_undo_method(frames,"set_animation_speed",edited_anim,frames->get_animation_speed(edited_anim)); - undo_redo->add_do_method(this,"_update_library",true); - undo_redo->add_undo_method(this,"_update_library",true); + undo_redo->create_action(TTR("Change Animation FPS"), UndoRedo::MERGE_ENDS); + undo_redo->add_do_method(frames, "set_animation_speed", edited_anim, p_value); + undo_redo->add_undo_method(frames, "set_animation_speed", edited_anim, frames->get_animation_speed(edited_anim)); + undo_redo->add_do_method(this, "_update_library", true); + undo_redo->add_undo_method(this, "_update_library", true); undo_redo->commit_action(); - } void SpriteFramesEditor::_update_library(bool p_skip_selector) { - updating=true; + updating = true; if (!p_skip_selector) { animations->clear(); - TreeItem *anim_root=animations->create_item(); + TreeItem *anim_root = animations->create_item(); List<StringName> anim_names; @@ -551,76 +504,69 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { anim_names.sort_custom<StringName::AlphCompare>(); - for(List<StringName>::Element *E=anim_names.front();E;E=E->next()) { + for (List<StringName>::Element *E = anim_names.front(); E; E = E->next()) { String name = E->get(); TreeItem *it = animations->create_item(anim_root); - it->set_metadata(0,name); + it->set_metadata(0, name); - it->set_text(0,name); - it->set_editable(0,true); + it->set_text(0, name); + it->set_editable(0, true); - if (E->get()==edited_anim) { + if (E->get() == edited_anim) { it->select(0); } } } - tree->clear(); if (!frames->has_animation(edited_anim)) { - updating=false; + updating = false; return; } + if (sel >= frames->get_frame_count(edited_anim)) + sel = frames->get_frame_count(edited_anim) - 1; + else if (sel < 0 && frames->get_frame_count(edited_anim)) + sel = 0; - if (sel>=frames->get_frame_count(edited_anim)) - sel=frames->get_frame_count(edited_anim)-1; - else if (sel<0 && frames->get_frame_count(edited_anim)) - sel=0; - - for(int i=0;i<frames->get_frame_count(edited_anim);i++) { - + for (int i = 0; i < frames->get_frame_count(edited_anim); i++) { String name; Ref<Texture> icon; + if (frames->get_frame(edited_anim, i).is_null()) { - if (frames->get_frame(edited_anim,i).is_null()) { - - name=itos(i)+": "+TTR("(empty)"); + name = itos(i) + ": " + TTR("(empty)"); } else { - name=itos(i)+": "+frames->get_frame(edited_anim,i)->get_name(); - icon=frames->get_frame(edited_anim,i); + name = itos(i) + ": " + frames->get_frame(edited_anim, i)->get_name(); + icon = frames->get_frame(edited_anim, i); } - tree->add_item(name,icon); - if (frames->get_frame(edited_anim,i).is_valid()) - tree->set_item_tooltip(tree->get_item_count()-1,frames->get_frame(edited_anim,i)->get_path()); - if (sel==i) - tree->select(tree->get_item_count()-1); + tree->add_item(name, icon); + if (frames->get_frame(edited_anim, i).is_valid()) + tree->set_item_tooltip(tree->get_item_count() - 1, frames->get_frame(edited_anim, i)->get_path()); + if (sel == i) + tree->select(tree->get_item_count() - 1); } anim_speed->set_value(frames->get_animation_speed(edited_anim)); anim_loop->set_pressed(frames->get_animation_loop(edited_anim)); - updating=false; + updating = false; //player->add_resource("default",resource); } +void SpriteFramesEditor::edit(SpriteFrames *p_frames) { - -void SpriteFramesEditor::edit(SpriteFrames* p_frames) { - - if (frames==p_frames) + if (frames == p_frames) return; - frames=p_frames; - + frames = p_frames; if (p_frames) { @@ -630,11 +576,10 @@ void SpriteFramesEditor::edit(SpriteFrames* p_frames) { frames->get_animation_list(&anim_names); anim_names.sort_custom<StringName::AlphCompare>(); if (anim_names.size()) { - edited_anim=anim_names.front()->get(); + edited_anim = anim_names.front()->get(); } else { - edited_anim=StringName(); + edited_anim = StringName(); } - } _update_library(); @@ -643,42 +588,38 @@ void SpriteFramesEditor::edit(SpriteFrames* p_frames) { hide(); //set_fixed_process(false); } - } - -Variant SpriteFramesEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) { +Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { if (!frames->has_animation(edited_anim)) return false; - int idx = tree->get_item_at_pos(p_point,true); + int idx = tree->get_item_at_pos(p_point, true); - if (idx<0 || idx>=frames->get_frame_count(edited_anim)) + if (idx < 0 || idx >= frames->get_frame_count(edited_anim)) return Variant(); - RES frame = frames->get_frame(edited_anim,idx); + RES frame = frames->get_frame(edited_anim, idx); if (frame.is_null()) return Variant(); - return EditorNode::get_singleton()->drag_resource(frame,p_from); - - + return EditorNode::get_singleton()->drag_resource(frame, p_from); } -bool SpriteFramesEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{ +bool SpriteFramesEditor::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"]; Ref<Texture> texture = r; @@ -688,33 +629,30 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2& p_point,const Variant& p } } - - if (String(d["type"])=="files") { + if (String(d["type"]) == "files") { Vector<String> files = d["files"]; - if (files.size()==0) + if (files.size() == 0) return false; - for(int i=0;i<files.size();i++) { + for (int i = 0; i < files.size(); i++) { String file = files[0]; String ftype = EditorFileSystem::get_singleton()->get_file_type(file); - if (!ClassDB::is_parent_class(ftype,"Texture")) { + if (!ClassDB::is_parent_class(ftype, "Texture")) { return false; } - } return true; - } return false; } -void SpriteFramesEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ +void SpriteFramesEditor::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; @@ -722,205 +660,188 @@ void SpriteFramesEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat if (!d.has("type")) return; - int at_pos = tree->get_item_at_pos(p_point,true); + int at_pos = tree->get_item_at_pos(p_point, true); - if (String(d["type"])=="resource" && d.has("resource")) { - RES r=d["resource"]; + if (String(d["type"]) == "resource" && d.has("resource")) { + RES r = d["resource"]; Ref<Texture> texture = r; if (texture.is_valid()) { undo_redo->create_action(TTR("Add Frame")); - undo_redo->add_do_method(frames,"add_frame",edited_anim,texture,at_pos==-1?-1:at_pos); - undo_redo->add_undo_method(frames,"remove_frame",edited_anim,at_pos==-1?frames->get_frame_count(edited_anim):at_pos); - undo_redo->add_do_method(this,"_update_library"); - undo_redo->add_undo_method(this,"_update_library"); + undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos); + undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) : at_pos); + 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") { PoolVector<String> files = d["files"]; - _file_load_request(files,at_pos); + _file_load_request(files, at_pos); } - } - void SpriteFramesEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"),&SpriteFramesEditor::_gui_input); - ClassDB::bind_method(D_METHOD("_load_pressed"),&SpriteFramesEditor::_load_pressed); - ClassDB::bind_method(D_METHOD("_empty_pressed"),&SpriteFramesEditor::_empty_pressed); - ClassDB::bind_method(D_METHOD("_empty2_pressed"),&SpriteFramesEditor::_empty2_pressed); - ClassDB::bind_method(D_METHOD("_item_edited"),&SpriteFramesEditor::_item_edited); - ClassDB::bind_method(D_METHOD("_delete_pressed"),&SpriteFramesEditor::_delete_pressed); - ClassDB::bind_method(D_METHOD("_paste_pressed"),&SpriteFramesEditor::_paste_pressed); - ClassDB::bind_method(D_METHOD("_delete_confirm_pressed"),&SpriteFramesEditor::_delete_confirm_pressed); - ClassDB::bind_method(D_METHOD("_file_load_request","files","atpos"),&SpriteFramesEditor::_file_load_request,DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("_update_library","skipsel"),&SpriteFramesEditor::_update_library,DEFVAL(false)); - ClassDB::bind_method(D_METHOD("_up_pressed"),&SpriteFramesEditor::_up_pressed); - ClassDB::bind_method(D_METHOD("_down_pressed"),&SpriteFramesEditor::_down_pressed); - ClassDB::bind_method(D_METHOD("_animation_select"),&SpriteFramesEditor::_animation_select); - ClassDB::bind_method(D_METHOD("_animation_name_edited"),&SpriteFramesEditor::_animation_name_edited); - ClassDB::bind_method(D_METHOD("_animation_add"),&SpriteFramesEditor::_animation_add); - ClassDB::bind_method(D_METHOD("_animation_remove"),&SpriteFramesEditor::_animation_remove); - ClassDB::bind_method(D_METHOD("_animation_loop_changed"),&SpriteFramesEditor::_animation_loop_changed); - ClassDB::bind_method(D_METHOD("_animation_fps_changed"),&SpriteFramesEditor::_animation_fps_changed); + ClassDB::bind_method(D_METHOD("_gui_input"), &SpriteFramesEditor::_gui_input); + ClassDB::bind_method(D_METHOD("_load_pressed"), &SpriteFramesEditor::_load_pressed); + ClassDB::bind_method(D_METHOD("_empty_pressed"), &SpriteFramesEditor::_empty_pressed); + ClassDB::bind_method(D_METHOD("_empty2_pressed"), &SpriteFramesEditor::_empty2_pressed); + ClassDB::bind_method(D_METHOD("_item_edited"), &SpriteFramesEditor::_item_edited); + ClassDB::bind_method(D_METHOD("_delete_pressed"), &SpriteFramesEditor::_delete_pressed); + ClassDB::bind_method(D_METHOD("_paste_pressed"), &SpriteFramesEditor::_paste_pressed); + ClassDB::bind_method(D_METHOD("_delete_confirm_pressed"), &SpriteFramesEditor::_delete_confirm_pressed); + ClassDB::bind_method(D_METHOD("_file_load_request", "files", "atpos"), &SpriteFramesEditor::_file_load_request, DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("_update_library", "skipsel"), &SpriteFramesEditor::_update_library, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("_up_pressed"), &SpriteFramesEditor::_up_pressed); + ClassDB::bind_method(D_METHOD("_down_pressed"), &SpriteFramesEditor::_down_pressed); + ClassDB::bind_method(D_METHOD("_animation_select"), &SpriteFramesEditor::_animation_select); + ClassDB::bind_method(D_METHOD("_animation_name_edited"), &SpriteFramesEditor::_animation_name_edited); + ClassDB::bind_method(D_METHOD("_animation_add"), &SpriteFramesEditor::_animation_add); + ClassDB::bind_method(D_METHOD("_animation_remove"), &SpriteFramesEditor::_animation_remove); + ClassDB::bind_method(D_METHOD("_animation_loop_changed"), &SpriteFramesEditor::_animation_loop_changed); + ClassDB::bind_method(D_METHOD("_animation_fps_changed"), &SpriteFramesEditor::_animation_fps_changed); ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw); ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SpriteFramesEditor::can_drop_data_fw); ClassDB::bind_method(D_METHOD("drop_data_fw"), &SpriteFramesEditor::drop_data_fw); - - } - SpriteFramesEditor::SpriteFramesEditor() { //add_style_override("panel", get_stylebox("panel","Panel")); - split = memnew( HSplitContainer ); + split = memnew(HSplitContainer); add_child(split); - VBoxContainer *vbc_animlist = memnew( VBoxContainer ); + VBoxContainer *vbc_animlist = memnew(VBoxContainer); split->add_child(vbc_animlist); - vbc_animlist->set_custom_minimum_size(Size2(150,0)); + vbc_animlist->set_custom_minimum_size(Size2(150, 0)); //vbc_animlist->set_v_size_flags(SIZE_EXPAND_FILL); - - VBoxContainer *sub_vb = memnew( VBoxContainer ); - vbc_animlist->add_margin_child(TTR("Animations"),sub_vb,true); + VBoxContainer *sub_vb = memnew(VBoxContainer); + vbc_animlist->add_margin_child(TTR("Animations"), sub_vb, true); sub_vb->set_v_size_flags(SIZE_EXPAND_FILL); - HBoxContainer *hbc_animlist = memnew( HBoxContainer ); + HBoxContainer *hbc_animlist = memnew(HBoxContainer); sub_vb->add_child(hbc_animlist); - new_anim = memnew( Button ); + new_anim = memnew(Button); hbc_animlist->add_child(new_anim); - new_anim->connect("pressed",this,"_animation_add"); - + new_anim->connect("pressed", this, "_animation_add"); hbc_animlist->add_spacer(); - remove_anim = memnew( Button ); + remove_anim = memnew(Button); hbc_animlist->add_child(remove_anim); - remove_anim->connect("pressed",this,"_animation_remove"); + remove_anim->connect("pressed", this, "_animation_remove"); - animations = memnew( Tree ); + animations = memnew(Tree); sub_vb->add_child(animations); animations->set_v_size_flags(SIZE_EXPAND_FILL); animations->set_hide_root(true); - animations->connect("cell_selected",this,"_animation_select"); - animations->connect("item_edited",this,"_animation_name_edited"); + animations->connect("cell_selected", this, "_animation_select"); + animations->connect("item_edited", this, "_animation_name_edited"); animations->set_single_select_cell_editing_only_when_already_selected(true); - - anim_speed = memnew( SpinBox); - vbc_animlist->add_margin_child(TTR("Speed (FPS):"),anim_speed); + anim_speed = memnew(SpinBox); + vbc_animlist->add_margin_child(TTR("Speed (FPS):"), anim_speed); anim_speed->set_min(0); anim_speed->set_max(100); anim_speed->set_step(0.01); - anim_speed->connect("value_changed",this,"_animation_fps_changed"); + anim_speed->connect("value_changed", this, "_animation_fps_changed"); - anim_loop = memnew( CheckButton ); + anim_loop = memnew(CheckButton); anim_loop->set_text(TTR("Loop")); vbc_animlist->add_child(anim_loop); - anim_loop->connect("pressed",this,"_animation_loop_changed"); + anim_loop->connect("pressed", this, "_animation_loop_changed"); - VBoxContainer *vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew(VBoxContainer); split->add_child(vbc); vbc->set_h_size_flags(SIZE_EXPAND_FILL); - sub_vb = memnew( VBoxContainer ); - vbc->add_margin_child(TTR("Animation Frames"),sub_vb,true); - + sub_vb = memnew(VBoxContainer); + vbc->add_margin_child(TTR("Animation Frames"), sub_vb, true); - HBoxContainer *hbc = memnew( HBoxContainer ); + HBoxContainer *hbc = memnew(HBoxContainer); sub_vb->add_child(hbc); //animations = memnew( ItemList ); - - load = memnew( Button ); + load = memnew(Button); load->set_tooltip(TTR("Load Resource")); hbc->add_child(load); - paste = memnew( Button ); + paste = memnew(Button); paste->set_text(TTR("Paste")); hbc->add_child(paste); - empty = memnew( Button ); + empty = memnew(Button); empty->set_text(TTR("Insert Empty (Before)")); hbc->add_child(empty); - empty2 = memnew( Button ); + empty2 = memnew(Button); empty2->set_text(TTR("Insert Empty (After)")); hbc->add_child(empty2); - move_up = memnew( Button ); + move_up = memnew(Button); move_up->set_text(TTR("Up")); hbc->add_child(move_up); - move_down = memnew( Button ); + move_down = memnew(Button); move_down->set_text(TTR("Down")); hbc->add_child(move_down); - _delete = memnew( Button ); + _delete = memnew(Button); hbc->add_child(_delete); - file = memnew( EditorFileDialog ); + file = memnew(EditorFileDialog); add_child(file); - - tree = memnew( ItemList ); + tree = memnew(ItemList); tree->set_v_size_flags(SIZE_EXPAND_FILL); tree->set_icon_mode(ItemList::ICON_MODE_TOP); int thumbnail_size = 96; tree->set_max_columns(0); tree->set_icon_mode(ItemList::ICON_MODE_TOP); - tree->set_fixed_column_width(thumbnail_size*3/2); + tree->set_fixed_column_width(thumbnail_size * 3 / 2); tree->set_max_text_lines(2); - tree->set_fixed_icon_size(Size2(thumbnail_size,thumbnail_size)); + tree->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); //tree->set_min_icon_size(Size2(thumbnail_size,thumbnail_size)); tree->set_drag_forwarding(this); - - sub_vb->add_child(tree); - dialog = memnew( AcceptDialog ); - add_child( dialog ); - - load->connect("pressed", this,"_load_pressed"); - _delete->connect("pressed", this,"_delete_pressed"); - paste->connect("pressed", this,"_paste_pressed"); - empty->connect("pressed", this,"_empty_pressed"); - empty2->connect("pressed", this,"_empty2_pressed"); - move_up->connect("pressed", this,"_up_pressed"); - move_down->connect("pressed", this,"_down_pressed"); - file->connect("files_selected", this,"_file_load_request"); + dialog = memnew(AcceptDialog); + add_child(dialog); + + load->connect("pressed", this, "_load_pressed"); + _delete->connect("pressed", this, "_delete_pressed"); + paste->connect("pressed", this, "_paste_pressed"); + empty->connect("pressed", this, "_empty_pressed"); + empty2->connect("pressed", this, "_empty2_pressed"); + move_up->connect("pressed", this, "_up_pressed"); + move_down->connect("pressed", this, "_down_pressed"); + file->connect("files_selected", this, "_file_load_request"); //dialog->connect("confirmed", this,"_delete_confirm_pressed"); //tree->connect("item_selected", this,"_item_edited"); - loading_scene=false; - sel=-1; - - updating=false; + loading_scene = false; + sel = -1; - edited_anim="default"; + updating = false; + edited_anim = "default"; } - void SpriteFramesEditorPlugin::edit(Object *p_object) { frames_editor->set_undo_redo(&get_undo_redo()); - SpriteFrames * s = p_object->cast_to<SpriteFrames>(); + SpriteFrames *s = p_object->cast_to<SpriteFrames>(); if (!s) return; @@ -946,24 +867,16 @@ void SpriteFramesEditorPlugin::make_visible(bool p_visible) { //frames_editor->set_process(false); } - } SpriteFramesEditorPlugin::SpriteFramesEditorPlugin(EditorNode *p_node) { - editor=p_node; - frames_editor = memnew( SpriteFramesEditor ); - frames_editor->set_custom_minimum_size(Size2(0,300)); - button=editor->add_bottom_panel_item("SpriteFrames",frames_editor); + editor = p_node; + frames_editor = memnew(SpriteFramesEditor); + frames_editor->set_custom_minimum_size(Size2(0, 300)); + button = editor->add_bottom_panel_item("SpriteFrames", frames_editor); button->hide(); - - - } - -SpriteFramesEditorPlugin::~SpriteFramesEditorPlugin() -{ +SpriteFramesEditorPlugin::~SpriteFramesEditorPlugin() { } - - diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h index 11f545b443..3e9ba710f3 100644 --- a/editor/plugins/sprite_frames_editor_plugin.h +++ b/editor/plugins/sprite_frames_editor_plugin.h @@ -29,19 +29,17 @@ #ifndef SPRITE_FRAMES_EDITOR_PLUGIN_H #define SPRITE_FRAMES_EDITOR_PLUGIN_H - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "scene/gui/tree.h" +#include "editor/editor_plugin.h" #include "scene/2d/animated_sprite.h" -#include "scene/gui/file_dialog.h" #include "scene/gui/dialogs.h" +#include "scene/gui/file_dialog.h" #include "scene/gui/split_container.h" - +#include "scene/gui/tree.h" class SpriteFramesEditor : public PanelContainer { - GDCLASS(SpriteFramesEditor, PanelContainer ); + GDCLASS(SpriteFramesEditor, PanelContainer); Button *load; Button *_delete; @@ -58,7 +56,6 @@ class SpriteFramesEditor : public PanelContainer { Button *new_anim; Button *remove_anim; - Tree *animations; SpinBox *anim_speed; CheckButton *anim_loop; @@ -73,7 +70,7 @@ class SpriteFramesEditor : public PanelContainer { void _load_pressed(); void _load_scene_pressed(); - void _file_load_request(const PoolVector<String>& p_path, int p_at_pos=-1); + void _file_load_request(const PoolVector<String> &p_path, int p_at_pos = -1); void _paste_pressed(); void _empty_pressed(); void _empty2_pressed(); @@ -81,11 +78,9 @@ class SpriteFramesEditor : public PanelContainer { void _delete_confirm_pressed(); void _up_pressed(); void _down_pressed(); - void _update_library(bool p_skip_selector=false); + void _update_library(bool p_skip_selector = false); void _item_edited(); - - void _animation_select(); void _animation_name_edited(); void _animation_add(); @@ -97,33 +92,32 @@ class SpriteFramesEditor : public PanelContainer { UndoRedo *undo_redo; - bool _is_drop_valid(const Dictionary& p_drag_data, const Dictionary& p_item_data) const; - 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); + bool _is_drop_valid(const Dictionary &p_drag_data, const Dictionary &p_item_data) const; + 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(SpriteFrames* p_frames); + void edit(SpriteFrames *p_frames); SpriteFramesEditor(); }; class SpriteFramesEditorPlugin : public EditorPlugin { - GDCLASS( SpriteFramesEditorPlugin, EditorPlugin ); + GDCLASS(SpriteFramesEditorPlugin, EditorPlugin); SpriteFramesEditor *frames_editor; EditorNode *editor; Button *button; public: - virtual String get_name() const { return "SpriteFrames"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -132,7 +126,6 @@ public: SpriteFramesEditorPlugin(EditorNode *p_node); ~SpriteFramesEditorPlugin(); - }; #endif // SPRITE_FRAMES_EDITOR_PLUGIN_H diff --git a/editor/plugins/stream_editor_plugin.h b/editor/plugins/stream_editor_plugin.h index 2ae3b7100e..6b68ba02f9 100644 --- a/editor/plugins/stream_editor_plugin.h +++ b/editor/plugins/stream_editor_plugin.h @@ -30,8 +30,8 @@ #define STREAM_EDITOR_PLUGIN_H #if 0 -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/audio/stream_player.h" /** diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp index 396ebd0052..093f25e2b0 100644 --- a/editor/plugins/style_box_editor_plugin.cpp +++ b/editor/plugins/style_box_editor_plugin.cpp @@ -28,16 +28,14 @@ /*************************************************************************/ #include "style_box_editor_plugin.h" - -void StyleBoxEditor::edit(const Ref<StyleBox>& p_stylebox) { +void StyleBoxEditor::edit(const Ref<StyleBox> &p_stylebox) { if (stylebox.is_valid()) - stylebox->disconnect("changed",this,"_sb_changed"); - stylebox=p_stylebox; + stylebox->disconnect("changed", this, "_sb_changed"); + stylebox = p_stylebox; if (p_stylebox.is_valid()) { - preview->add_style_override("panel",stylebox); - stylebox->connect("changed",this,"_sb_changed"); - + preview->add_style_override("panel", stylebox); + stylebox->connect("changed", this, "_sb_changed"); } } @@ -48,7 +46,7 @@ void StyleBoxEditor::_sb_changed() { void StyleBoxEditor::_bind_methods() { - ClassDB::bind_method("_sb_changed",&StyleBoxEditor::_sb_changed); + ClassDB::bind_method("_sb_changed", &StyleBoxEditor::_sb_changed); //ClassDB::bind_method("_import",&StyleBoxEditor::_import); //ClassDB::bind_method("_import_accept",&StyleBoxEditor::_import_accept); //ClassDB::bind_method("_preview_text_changed",&StyleBoxEditor::_preview_text_changed); @@ -56,39 +54,36 @@ void StyleBoxEditor::_bind_methods() { StyleBoxEditor::StyleBoxEditor() { - panel = memnew( Panel ); + panel = memnew(Panel); add_child(panel); panel->set_area_as_parent_rect(); - Label *l = memnew( Label ); + Label *l = memnew(Label); l->set_text(TTR("StyleBox Preview:")); - l->set_pos(Point2(5,5)); + l->set_pos(Point2(5, 5)); panel->add_child(l); - - preview = memnew( Panel ); + preview = memnew(Panel); panel->add_child(preview); - preview->set_pos(Point2(50,50)); - preview->set_size(Size2(200,100)); - - + preview->set_pos(Point2(50, 50)); + preview->set_size(Size2(200, 100)); } void StyleBoxEditorPlugin::edit(Object *p_node) { if (p_node && p_node->cast_to<StyleBox>()) { - stylebox_editor->edit( p_node->cast_to<StyleBox>() ); + stylebox_editor->edit(p_node->cast_to<StyleBox>()); stylebox_editor->show(); } else stylebox_editor->hide(); } -bool StyleBoxEditorPlugin::handles(Object *p_node) const{ +bool StyleBoxEditorPlugin::handles(Object *p_node) const { return p_node->is_class("StyleBox"); } -void StyleBoxEditorPlugin::make_visible(bool p_visible){ +void StyleBoxEditorPlugin::make_visible(bool p_visible) { if (p_visible) { button->show(); @@ -103,13 +98,10 @@ void StyleBoxEditorPlugin::make_visible(bool p_visible){ StyleBoxEditorPlugin::StyleBoxEditorPlugin(EditorNode *p_node) { - stylebox_editor = memnew( StyleBoxEditor ); - stylebox_editor->set_custom_minimum_size(Size2(0,250)); + stylebox_editor = memnew(StyleBoxEditor); + stylebox_editor->set_custom_minimum_size(Size2(0, 250)); //p_node->get_viewport()->add_child(stylebox_editor); - button = p_node->add_bottom_panel_item("StyleBox",stylebox_editor); + button = p_node->add_bottom_panel_item("StyleBox", stylebox_editor); button->hide(); - - } - diff --git a/editor/plugins/style_box_editor_plugin.h b/editor/plugins/style_box_editor_plugin.h index 01e636472b..1dfe48d97f 100644 --- a/editor/plugins/style_box_editor_plugin.h +++ b/editor/plugins/style_box_editor_plugin.h @@ -29,15 +29,14 @@ #ifndef STYLE_BOX_EDITOR_PLUGIN_H #define STYLE_BOX_EDITOR_PLUGIN_H -#include "scene/resources/style_box.h" -#include "scene/gui/texture_rect.h" -#include "scene/gui/option_button.h" #include "editor/editor_node.h" - +#include "scene/gui/option_button.h" +#include "scene/gui/texture_rect.h" +#include "scene/resources/style_box.h" class StyleBoxEditor : public Control { - GDCLASS( StyleBoxEditor, Control ); + GDCLASS(StyleBoxEditor, Control); Panel *panel; Panel *preview; @@ -47,28 +46,23 @@ class StyleBoxEditor : public Control { void _sb_changed(); protected: - - static void _bind_methods(); -public: - void edit(const Ref<StyleBox>& p_stylebox); +public: + void edit(const Ref<StyleBox> &p_stylebox); StyleBoxEditor(); }; - - class StyleBoxEditorPlugin : public EditorPlugin { - GDCLASS( StyleBoxEditorPlugin, EditorPlugin ); + GDCLASS(StyleBoxEditorPlugin, EditorPlugin); StyleBoxEditor *stylebox_editor; EditorNode *editor; Button *button; public: - virtual String get_name() const { return "StyleBox"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -76,8 +70,6 @@ public: virtual void make_visible(bool p_visible); StyleBoxEditorPlugin(EditorNode *p_node); - }; - #endif // STYLE_BOX_EDITOR_PLUGIN_H diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index af05094e5e..3d05e68cac 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -28,76 +28,68 @@ /*************************************************************************/ #include "texture_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 TextureEditor::_gui_input(InputEvent p_event) { - - } void TextureEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_FIXED_PROCESS) { - + if (p_what == NOTIFICATION_FIXED_PROCESS) { } - - if (p_what==NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); - } - if (p_what==NOTIFICATION_DRAW) { - + if (p_what == NOTIFICATION_DRAW) { - Ref<Texture> checkerboard = get_icon("Checkerboard","EditorIcons"); + Ref<Texture> checkerboard = get_icon("Checkerboard", "EditorIcons"); Size2 size = get_size(); - draw_texture_rect(checkerboard,Rect2(Point2(),size),true); + draw_texture_rect(checkerboard, Rect2(Point2(), size), true); - int tex_width = texture->get_width() * size.height / texture ->get_height(); + int tex_width = texture->get_width() * size.height / texture->get_height(); int tex_height = size.height; - if (tex_width>size.width) { - tex_width=size.width; - tex_height=texture->get_height() * tex_width / texture->get_width(); + if (tex_width > size.width) { + tex_width = size.width; + tex_height = texture->get_height() * tex_width / texture->get_width(); } - int ofs_x = (size.width - tex_width)/2; - int ofs_y = (size.height - tex_height)/2; + int ofs_x = (size.width - tex_width) / 2; + int ofs_y = (size.height - tex_height) / 2; - draw_texture_rect(texture,Rect2(ofs_x,ofs_y,tex_width,tex_height)); + draw_texture_rect(texture, Rect2(ofs_x, ofs_y, tex_width, tex_height)); - Ref<Font> font = get_font("font","Label"); + Ref<Font> font = get_font("font", "Label"); String format; if (texture->cast_to<ImageTexture>()) { format = Image::get_format_name(texture->cast_to<ImageTexture>()->get_format()); } else { - format=texture->get_class(); + format = texture->get_class(); } - String text = itos(texture->get_width())+"x"+itos(texture->get_height())+" "+format; + String text = itos(texture->get_width()) + "x" + itos(texture->get_height()) + " " + format; Size2 rect = font->get_string_size(text); - Vector2 draw_from = size-rect+Size2(-2,font->get_ascent()-2); - if (draw_from.x<0) - draw_from.x=0; + Vector2 draw_from = size - rect + Size2(-2, font->get_ascent() - 2); + if (draw_from.x < 0) + draw_from.x = 0; - draw_string(font,draw_from+Vector2(2,2),text,Color(0,0,0,0.5),size.width); - draw_string(font,draw_from-Vector2(2,2),text,Color(0,0,0,0.5),size.width); - draw_string(font,draw_from,text,Color(1,1,1,1),size.width); + draw_string(font, draw_from + Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width); + draw_string(font, draw_from - Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width); + draw_string(font, draw_from, text, Color(1, 1, 1, 1), size.width); } } - - void TextureEditor::edit(Ref<Texture> p_texture) { - texture=p_texture; + texture = p_texture; if (!texture.is_null()) update(); @@ -105,27 +97,21 @@ void TextureEditor::edit(Ref<Texture> p_texture) { hide(); } - } - - void TextureEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"),&TextureEditor::_gui_input); - + ClassDB::bind_method(D_METHOD("_gui_input"), &TextureEditor::_gui_input); } TextureEditor::TextureEditor() { - set_custom_minimum_size(Size2(1,150)); - + set_custom_minimum_size(Size2(1, 150)); } - void TextureEditorPlugin::edit(Object *p_object) { - Texture * s = p_object->cast_to<Texture>(); + Texture *s = p_object->cast_to<Texture>(); if (!s) return; @@ -147,23 +133,15 @@ void TextureEditorPlugin::make_visible(bool p_visible) { texture_editor->hide(); //texture_editor->set_process(false); } - } TextureEditorPlugin::TextureEditorPlugin(EditorNode *p_node) { - editor=p_node; - texture_editor = memnew( TextureEditor ); - add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,texture_editor); + editor = p_node; + texture_editor = memnew(TextureEditor); + add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, texture_editor); texture_editor->hide(); - - - } - -TextureEditorPlugin::~TextureEditorPlugin() -{ +TextureEditorPlugin::~TextureEditorPlugin() { } - - diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h index 7ad0e918cf..083fbada8b 100644 --- a/editor/plugins/texture_editor_plugin.h +++ b/editor/plugins/texture_editor_plugin.h @@ -29,40 +29,34 @@ #ifndef TEXTURE_EDITOR_PLUGIN_H #define TEXTURE_EDITOR_PLUGIN_H - - -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/resources/texture.h" - class TextureEditor : public Control { GDCLASS(TextureEditor, Control); - Ref<Texture> texture; protected: void _notification(int p_what); void _gui_input(InputEvent p_event); static void _bind_methods(); -public: +public: void edit(Ref<Texture> p_texture); TextureEditor(); }; - class TextureEditorPlugin : public EditorPlugin { - GDCLASS( TextureEditorPlugin, EditorPlugin ); + GDCLASS(TextureEditorPlugin, EditorPlugin); TextureEditor *texture_editor; EditorNode *editor; public: - virtual String get_name() const { return "Texture"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -71,7 +65,6 @@ public: TextureEditorPlugin(EditorNode *p_node); ~TextureEditorPlugin(); - }; #endif // TEXTURE_EDITOR_PLUGIN_H diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index aabf938577..5e992d3ec1 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -31,149 +31,148 @@ #include "texture_region_editor_plugin.h" #include "core/core_string_names.h" -#include "scene/gui/check_box.h" #include "os/input.h" #include "os/keyboard.h" +#include "scene/gui/check_box.h" -void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to){ - Vector2 line = (to-from).normalized() * 10; +void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to) { + Vector2 line = (to - from).normalized() * 10; while ((to - from).length_squared() > 200) { - edit_draw->draw_line(from, from + line,Color(0.97, 0.2, 0.2),2); - from += line*2; + edit_draw->draw_line(from, from + line, Color(0.97, 0.2, 0.2), 2); + from += line * 2; } } -void TextureRegionEditor::_region_draw() -{ +void TextureRegionEditor::_region_draw() { Ref<Texture> base_tex = NULL; - if(node_sprite) + if (node_sprite) base_tex = node_sprite->get_texture(); - else if(node_patch9) + else if (node_patch9) base_tex = node_patch9->get_texture(); - else if(obj_styleBox.is_valid()) + else if (obj_styleBox.is_valid()) base_tex = obj_styleBox->get_texture(); - else if(atlas_tex.is_valid()) + else if (atlas_tex.is_valid()) base_tex = atlas_tex->get_atlas(); if (base_tex.is_null()) return; Transform2D mtx; - mtx.elements[2]=-draw_ofs; - mtx.scale_basis(Vector2(draw_zoom,draw_zoom)); + mtx.elements[2] = -draw_ofs; + mtx.scale_basis(Vector2(draw_zoom, draw_zoom)); - VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(),mtx); - edit_draw->draw_texture(base_tex,Point2()); - VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(),Transform2D()); + VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), mtx); + edit_draw->draw_texture(base_tex, Point2()); + VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), Transform2D()); if (snap_mode == SNAP_GRID) { Size2 s = edit_draw->get_size(); int last_cell; - if (snap_step.x!=0) { + if (snap_step.x != 0) { if (snap_separation.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) - edit_draw->draw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3)); - last_cell=cell; + 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) + edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } else - 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+snap_separation.x))); - if (i==0) - last_cell=cell; - if (last_cell!=cell) - edit_draw->draw_rect(Rect2(i-snap_separation.x*draw_zoom,0,snap_separation.x*draw_zoom,s.height),Color(0.3,0.7,1,0.3)); - last_cell=cell; + 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 + snap_separation.x))); + if (i == 0) + last_cell = cell; + if (last_cell != cell) + edit_draw->draw_rect(Rect2(i - snap_separation.x * draw_zoom, 0, snap_separation.x * draw_zoom, s.height), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } } - if (snap_step.y!=0) { + if (snap_step.y != 0) { if (snap_separation.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) - edit_draw->draw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3)); - last_cell=cell; + 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) + edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } else - 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+snap_separation.y))); - if (i==0) - last_cell=cell; - if (last_cell!=cell) - edit_draw->draw_rect(Rect2(0,i-snap_separation.y*draw_zoom,s.width,snap_separation.y*draw_zoom),Color(0.3,0.7,1,0.3)); - last_cell=cell; + 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 + snap_separation.y))); + if (i == 0) + last_cell = cell; + if (last_cell != cell) + edit_draw->draw_rect(Rect2(0, i - snap_separation.y * draw_zoom, s.width, snap_separation.y * draw_zoom), Color(0.3, 0.7, 1, 0.3)); + last_cell = cell; } } } else if (snap_mode == SNAP_AUTOSLICE) { - for (List<Rect2>::Element *E = autoslice_cache.front();E;E=E->next()) { + for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { Rect2 r = E->get(); - Vector2 endpoints[4]={ + Vector2 endpoints[4] = { mtx.basis_xform(r.pos), - mtx.basis_xform(r.pos+Vector2(r.size.x,0)), - mtx.basis_xform(r.pos+r.size), - mtx.basis_xform(r.pos+Vector2(0,r.size.y)) + mtx.basis_xform(r.pos + Vector2(r.size.x, 0)), + mtx.basis_xform(r.pos + r.size), + mtx.basis_xform(r.pos + Vector2(0, r.size.y)) }; - for(int i=0;i<4;i++) { - int next = (i+1)%4; - edit_draw->draw_line(endpoints[i]-draw_ofs, endpoints[next]-draw_ofs, Color(0.3,0.7,1,1) , 2); + for (int i = 0; i < 4; i++) { + int next = (i + 1) % 4; + edit_draw->draw_line(endpoints[i] - draw_ofs, endpoints[next] - draw_ofs, Color(0.3, 0.7, 1, 1), 2); } } } - Ref<Texture> select_handle = get_icon("EditorHandle","EditorIcons"); + Ref<Texture> select_handle = get_icon("EditorHandle", "EditorIcons"); - Rect2 scroll_rect(Point2(),mtx.basis_xform(base_tex->get_size())); + Rect2 scroll_rect(Point2(), mtx.basis_xform(base_tex->get_size())); scroll_rect.expand_to(mtx.basis_xform(edit_draw->get_size())); - Vector2 endpoints[4]={ + Vector2 endpoints[4] = { mtx.basis_xform(rect.pos), - mtx.basis_xform(rect.pos+Vector2(rect.size.x,0)), - mtx.basis_xform(rect.pos+rect.size), - mtx.basis_xform(rect.pos+Vector2(0,rect.size.y)) + mtx.basis_xform(rect.pos + Vector2(rect.size.x, 0)), + mtx.basis_xform(rect.pos + rect.size), + mtx.basis_xform(rect.pos + Vector2(0, rect.size.y)) }; - Color color(0.9,0.5,0.5); - for(int i=0;i<4;i++) { + Color color(0.9, 0.5, 0.5); + 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); + ofs *= 1.4144 * (select_handle->get_size().width / 2); - edit_draw->draw_line(endpoints[i]-draw_ofs, endpoints[next]-draw_ofs, color , 2); + edit_draw->draw_line(endpoints[i] - draw_ofs, endpoints[next] - draw_ofs, color, 2); if (snap_mode != SNAP_AUTOSLICE) - edit_draw->draw_texture(select_handle,(endpoints[i]+ofs-(select_handle->get_size()/2)).floor()-draw_ofs); + edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs); - ofs = (endpoints[next]-endpoints[i])/2; - ofs += (endpoints[next]-endpoints[i]).tangent().normalized()*(select_handle->get_size().width/2); + ofs = (endpoints[next] - endpoints[i]) / 2; + ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2); if (snap_mode != SNAP_AUTOSLICE) - edit_draw->draw_texture(select_handle,(endpoints[i]+ofs-(select_handle->get_size()/2)).floor()-draw_ofs); + edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs); scroll_rect.expand_to(endpoints[i]); } - scroll_rect=scroll_rect.grow(200); - updating_scroll=true; + scroll_rect = scroll_rect.grow(200); + updating_scroll = true; hscroll->set_min(scroll_rect.pos.x); - hscroll->set_max(scroll_rect.pos.x+scroll_rect.size.x); + hscroll->set_max(scroll_rect.pos.x + scroll_rect.size.x); hscroll->set_page(edit_draw->get_size().x); hscroll->set_value(draw_ofs.x); hscroll->set_step(0.001); vscroll->set_min(scroll_rect.pos.y); - vscroll->set_max(scroll_rect.pos.y+scroll_rect.size.y); + vscroll->set_max(scroll_rect.pos.y + scroll_rect.size.y); vscroll->set_page(edit_draw->get_size().y); vscroll->set_value(draw_ofs.y); vscroll->set_step(0.001); - updating_scroll=false; + updating_scroll = false; float margins[4]; if (node_patch9 || obj_styleBox.is_valid()) { @@ -189,40 +188,40 @@ void TextureRegionEditor::_region_draw() margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); } Vector2 pos[4] = { - mtx.basis_xform(Vector2(0,margins[0]))+Vector2(0,endpoints[0].y-draw_ofs.y), - -mtx.basis_xform(Vector2(0,margins[1]))+Vector2(0,endpoints[2].y-draw_ofs.y), - mtx.basis_xform(Vector2(margins[2],0))+Vector2(endpoints[0].x-draw_ofs.x,0), - -mtx.basis_xform(Vector2(margins[3],0))+Vector2(endpoints[2].x-draw_ofs.x,0)}; - - draw_margin_line(edit_draw,pos[0],pos[0]+Vector2(edit_draw->get_size().x,0)); - draw_margin_line(edit_draw,pos[1],pos[1]+Vector2(edit_draw->get_size().x,0)); - draw_margin_line(edit_draw,pos[2],pos[2]+Vector2(0,edit_draw->get_size().y)); - draw_margin_line(edit_draw,pos[3],pos[3]+Vector2(0,edit_draw->get_size().y)); + mtx.basis_xform(Vector2(0, margins[0])) + Vector2(0, endpoints[0].y - draw_ofs.y), + -mtx.basis_xform(Vector2(0, margins[1])) + Vector2(0, endpoints[2].y - draw_ofs.y), + mtx.basis_xform(Vector2(margins[2], 0)) + Vector2(endpoints[0].x - draw_ofs.x, 0), + -mtx.basis_xform(Vector2(margins[3], 0)) + Vector2(endpoints[2].x - draw_ofs.x, 0) + }; + + draw_margin_line(edit_draw, pos[0], pos[0] + Vector2(edit_draw->get_size().x, 0)); + draw_margin_line(edit_draw, pos[1], pos[1] + Vector2(edit_draw->get_size().x, 0)); + draw_margin_line(edit_draw, pos[2], pos[2] + Vector2(0, edit_draw->get_size().y)); + draw_margin_line(edit_draw, pos[3], pos[3] + Vector2(0, edit_draw->get_size().y)); } } -void TextureRegionEditor::_region_input(const InputEvent& p_input) -{ +void TextureRegionEditor::_region_input(const InputEvent &p_input) { Transform2D mtx; - mtx.elements[2]=-draw_ofs; - mtx.scale_basis(Vector2(draw_zoom,draw_zoom)); - - Vector2 endpoints[8]={ - mtx.xform(rect.pos)+Vector2(-4,-4), - mtx.xform(rect.pos+Vector2(rect.size.x/2,0))+Vector2(0,-4), - mtx.xform(rect.pos+Vector2(rect.size.x,0))+Vector2(4,-4), - mtx.xform(rect.pos+Vector2(rect.size.x,rect.size.y/2))+Vector2(4,0), - mtx.xform(rect.pos+rect.size)+Vector2(4,4), - mtx.xform(rect.pos+Vector2(rect.size.x/2,rect.size.y))+Vector2(0,4), - mtx.xform(rect.pos+Vector2(0,rect.size.y))+Vector2(-4,4), - mtx.xform(rect.pos+Vector2(0,rect.size.y/2))+Vector2(-4,0) + mtx.elements[2] = -draw_ofs; + mtx.scale_basis(Vector2(draw_zoom, draw_zoom)); + + Vector2 endpoints[8] = { + mtx.xform(rect.pos) + Vector2(-4, -4), + mtx.xform(rect.pos + Vector2(rect.size.x / 2, 0)) + Vector2(0, -4), + mtx.xform(rect.pos + Vector2(rect.size.x, 0)) + Vector2(4, -4), + mtx.xform(rect.pos + Vector2(rect.size.x, rect.size.y / 2)) + Vector2(4, 0), + mtx.xform(rect.pos + rect.size) + Vector2(4, 4), + mtx.xform(rect.pos + Vector2(rect.size.x / 2, rect.size.y)) + Vector2(0, 4), + mtx.xform(rect.pos + Vector2(0, rect.size.y)) + Vector2(-4, 4), + mtx.xform(rect.pos + Vector2(0, rect.size.y / 2)) + Vector2(-4, 0) }; - if (p_input.type==InputEvent::MOUSE_BUTTON) { + if (p_input.type == InputEvent::MOUSE_BUTTON) { - const InputEventMouseButton &mb=p_input.mouse_button; + const InputEventMouseButton &mb = p_input.mouse_button; - if (mb.button_index==BUTTON_LEFT) { + if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { if (node_patch9 || obj_styleBox.is_valid()) { @@ -240,10 +239,11 @@ void TextureRegionEditor::_region_input(const InputEvent& p_input) margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); } Vector2 pos[4] = { - mtx.basis_xform(rect.pos+Vector2(0,margins[0]))-draw_ofs, - mtx.basis_xform(rect.pos+rect.size-Vector2(0,margins[1]))-draw_ofs, - mtx.basis_xform(rect.pos+Vector2(margins[2],0))-draw_ofs, - mtx.basis_xform(rect.pos+rect.size-Vector2(margins[3],0))-draw_ofs}; + mtx.basis_xform(rect.pos + Vector2(0, margins[0])) - draw_ofs, + mtx.basis_xform(rect.pos + rect.size - Vector2(0, margins[1])) - draw_ofs, + mtx.basis_xform(rect.pos + Vector2(margins[2], 0)) - draw_ofs, + mtx.basis_xform(rect.pos + rect.size - Vector2(margins[3], 0)) - draw_ofs + }; if (Math::abs(mb.y - pos[0].y) < 8) { edited_margin = 0; prev_margin = margins[0]; @@ -258,132 +258,130 @@ void TextureRegionEditor::_region_input(const InputEvent& p_input) prev_margin = margins[3]; } if (edited_margin >= 0) { - drag_from=Vector2(mb.x,mb.y); - drag=true; + drag_from = Vector2(mb.x, mb.y); + drag = true; } } - if ( edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) { - Vector2 point = mtx.affine_inverse().xform(Vector2(mb.x,mb.y)); - for (List<Rect2>::Element *E=autoslice_cache.front();E;E=E->next()) { + if (edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) { + Vector2 point = mtx.affine_inverse().xform(Vector2(mb.x, mb.y)); + for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { if (E->get().has_point(point)) { rect = E->get(); - if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)&&!(Input::get_singleton()->is_key_pressed(KEY_SHIFT|KEY_ALT))) { + if (Input::get_singleton()->is_key_pressed(KEY_CONTROL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) { Rect2 r; - if(node_sprite ) - r=node_sprite->get_region_rect(); - else if(node_patch9) - r=node_patch9->get_region_rect(); - else if(obj_styleBox.is_valid()) - r=obj_styleBox->get_region_rect(); - else if(atlas_tex.is_valid()) - r =atlas_tex->get_region(); + if (node_sprite) + r = node_sprite->get_region_rect(); + else if (node_patch9) + r = node_patch9->get_region_rect(); + else if (obj_styleBox.is_valid()) + r = obj_styleBox->get_region_rect(); + else if (atlas_tex.is_valid()) + r = atlas_tex->get_region(); rect.expand_to(r.pos); - rect.expand_to(r.pos+r.size); + rect.expand_to(r.pos + r.size); } undo_redo->create_action("Set Region Rect"); - if(node_sprite){ - undo_redo->add_do_method(node_sprite ,"set_region_rect",rect); - undo_redo->add_undo_method(node_sprite,"set_region_rect",node_sprite->get_region_rect()); - } else if(node_patch9){ - undo_redo->add_do_method(node_patch9 ,"set_region_rect",rect); - undo_redo->add_undo_method(node_patch9,"set_region_rect",node_patch9->get_region_rect()); + if (node_sprite) { + undo_redo->add_do_method(node_sprite, "set_region_rect", rect); + undo_redo->add_undo_method(node_sprite, "set_region_rect", node_sprite->get_region_rect()); + } else if (node_patch9) { + undo_redo->add_do_method(node_patch9, "set_region_rect", rect); + undo_redo->add_undo_method(node_patch9, "set_region_rect", node_patch9->get_region_rect()); } else if (obj_styleBox.is_valid()) { - undo_redo->add_do_method(obj_styleBox.ptr(),"set_region_rect",rect); - undo_redo->add_undo_method(obj_styleBox.ptr(),"set_region_rect",obj_styleBox->get_region_rect()); + undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", rect); + undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect()); } else if (atlas_tex.is_valid()) { - undo_redo->add_do_method(atlas_tex.ptr(),"set_region",rect); - undo_redo->add_undo_method(atlas_tex.ptr(),"set_region",atlas_tex->get_region()); + undo_redo->add_do_method(atlas_tex.ptr(), "set_region", rect); + undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region()); } - undo_redo->add_do_method(edit_draw,"update"); - undo_redo->add_undo_method(edit_draw,"update"); + undo_redo->add_do_method(edit_draw, "update"); + undo_redo->add_undo_method(edit_draw, "update"); undo_redo->commit_action(); break; } } } else if (edited_margin < 0) { - drag_from=mtx.affine_inverse().xform(Vector2(mb.x,mb.y)); + drag_from = mtx.affine_inverse().xform(Vector2(mb.x, mb.y)); if (snap_mode == SNAP_PIXEL) - drag_from = drag_from.snapped(Vector2(1,1)); + drag_from = drag_from.snapped(Vector2(1, 1)); else if (snap_mode == SNAP_GRID) - drag_from=snap_point(drag_from); - drag=true; - if(node_sprite ) - rect_prev=node_sprite->get_region_rect(); - else if(node_patch9) - rect_prev=node_patch9->get_region_rect(); - else if(obj_styleBox.is_valid()) - rect_prev=obj_styleBox->get_region_rect(); - else if(atlas_tex.is_valid()) - rect_prev=atlas_tex->get_region(); - - for (int i=0; i<8;i++) { - Vector2 tuv=endpoints[i]; - if (tuv.distance_to(Vector2(mb.x,mb.y))<8) { - drag_index=i; + drag_from = snap_point(drag_from); + drag = true; + if (node_sprite) + rect_prev = node_sprite->get_region_rect(); + else if (node_patch9) + rect_prev = node_patch9->get_region_rect(); + else if (obj_styleBox.is_valid()) + rect_prev = obj_styleBox->get_region_rect(); + else if (atlas_tex.is_valid()) + rect_prev = atlas_tex->get_region(); + + for (int i = 0; i < 8; i++) { + Vector2 tuv = endpoints[i]; + if (tuv.distance_to(Vector2(mb.x, mb.y)) < 8) { + drag_index = i; } } - if (drag_index==-1) { + if (drag_index == -1) { creating = true; - rect = Rect2(drag_from,Size2()); + rect = Rect2(drag_from, Size2()); } } } else if (drag) { if (edited_margin >= 0) { undo_redo->create_action("Set Margin"); - static Margin m[4] = {MARGIN_TOP,MARGIN_BOTTOM,MARGIN_LEFT,MARGIN_RIGHT}; + static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; if (node_patch9) { - undo_redo->add_do_method(node_patch9 ,"set_patch_margin",m[edited_margin],node_patch9->get_patch_margin(m[edited_margin])); - undo_redo->add_undo_method(node_patch9,"set_patch_margin",m[edited_margin],prev_margin); + undo_redo->add_do_method(node_patch9, "set_patch_margin", m[edited_margin], node_patch9->get_patch_margin(m[edited_margin])); + undo_redo->add_undo_method(node_patch9, "set_patch_margin", m[edited_margin], prev_margin); } else if (obj_styleBox.is_valid()) { - undo_redo->add_do_method(obj_styleBox.ptr() ,"set_margin_size",m[edited_margin],obj_styleBox->get_margin_size(m[edited_margin])); - undo_redo->add_undo_method(obj_styleBox.ptr(),"set_margin_size",m[edited_margin],prev_margin); + undo_redo->add_do_method(obj_styleBox.ptr(), "set_margin_size", m[edited_margin], obj_styleBox->get_margin_size(m[edited_margin])); + undo_redo->add_undo_method(obj_styleBox.ptr(), "set_margin_size", m[edited_margin], prev_margin); obj_styleBox->emit_signal(CoreStringNames::get_singleton()->changed); } edited_margin = -1; } else { undo_redo->create_action("Set Region Rect"); - if(node_sprite){ - undo_redo->add_do_method(node_sprite ,"set_region_rect",node_sprite->get_region_rect()); - undo_redo->add_undo_method(node_sprite,"set_region_rect",rect_prev); - } - else if(atlas_tex.is_valid()){ - undo_redo->add_do_method(atlas_tex.ptr() ,"set_region",atlas_tex->get_region()); - undo_redo->add_undo_method(atlas_tex.ptr(),"set_region",rect_prev); - } - else if(node_patch9){ + if (node_sprite) { + undo_redo->add_do_method(node_sprite, "set_region_rect", node_sprite->get_region_rect()); + undo_redo->add_undo_method(node_sprite, "set_region_rect", rect_prev); + } else if (atlas_tex.is_valid()) { + undo_redo->add_do_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region()); + undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", rect_prev); + } else if (node_patch9) { // FIXME: Is this intentional? - } else if(node_patch9){ - undo_redo->add_do_method(node_patch9 ,"set_region_rect",node_patch9->get_region_rect()); - undo_redo->add_undo_method(node_patch9,"set_region_rect",rect_prev); + } else if (node_patch9) { + undo_redo->add_do_method(node_patch9, "set_region_rect", node_patch9->get_region_rect()); + undo_redo->add_undo_method(node_patch9, "set_region_rect", rect_prev); } else if (obj_styleBox.is_valid()) { - undo_redo->add_do_method(obj_styleBox.ptr() ,"set_region_rect",obj_styleBox->get_region_rect()); - undo_redo->add_undo_method(obj_styleBox.ptr(),"set_region_rect",rect_prev); + undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect()); + undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", rect_prev); } drag_index = -1; } - undo_redo->add_do_method(edit_draw,"update"); - undo_redo->add_undo_method(edit_draw,"update"); + undo_redo->add_do_method(edit_draw, "update"); + undo_redo->add_undo_method(edit_draw, "update"); undo_redo->commit_action(); - drag=false; + drag = false; creating = false; } - } else if (mb.button_index==BUTTON_RIGHT && mb.pressed) { + } else if (mb.button_index == BUTTON_RIGHT && mb.pressed) { if (drag) { - drag=false; + drag = false; if (edited_margin >= 0) { - static Margin m[4] = {MARGIN_TOP,MARGIN_BOTTOM,MARGIN_LEFT,MARGIN_RIGHT}; + static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; if (node_patch9) - node_patch9->set_patch_margin(m[edited_margin],prev_margin); + node_patch9->set_patch_margin(m[edited_margin], prev_margin); if (obj_styleBox.is_valid()) - obj_styleBox->set_margin_size(m[edited_margin],prev_margin); + obj_styleBox->set_margin_size(m[edited_margin], prev_margin); edited_margin = -1; } else { apply_rect(rect_prev); - rect=rect_prev; + rect = rect_prev; edit_draw->update(); drag_index = -1; } @@ -393,124 +391,120 @@ void TextureRegionEditor::_region_input(const InputEvent& p_input) } else if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) { _zoom_out(); } - } 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 draged(mm.relative_x,mm.relative_y); - hscroll->set_value( hscroll->get_value()-draged.x ); - vscroll->set_value( vscroll->get_value()-draged.y ); + Vector2 draged(mm.relative_x, mm.relative_y); + hscroll->set_value(hscroll->get_value() - draged.x); + vscroll->set_value(vscroll->get_value() - draged.y); } else if (drag) { if (edited_margin >= 0) { float new_margin; if (edited_margin == 0) - new_margin = prev_margin + (mm.y-drag_from.y) / draw_zoom; + new_margin = prev_margin + (mm.y - drag_from.y) / draw_zoom; else if (edited_margin == 1) - new_margin = prev_margin - (mm.y-drag_from.y) / draw_zoom; + new_margin = prev_margin - (mm.y - drag_from.y) / draw_zoom; else if (edited_margin == 2) - new_margin = prev_margin + (mm.x-drag_from.x) / draw_zoom; + new_margin = prev_margin + (mm.x - drag_from.x) / draw_zoom; else if (edited_margin == 3) - new_margin = prev_margin - (mm.x-drag_from.x) / draw_zoom; + new_margin = prev_margin - (mm.x - drag_from.x) / draw_zoom; if (new_margin < 0) new_margin = 0; - static Margin m[4] = {MARGIN_TOP,MARGIN_BOTTOM,MARGIN_LEFT,MARGIN_RIGHT}; + static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; if (node_patch9) - node_patch9->set_patch_margin(m[edited_margin],new_margin); + node_patch9->set_patch_margin(m[edited_margin], new_margin); if (obj_styleBox.is_valid()) - obj_styleBox->set_margin_size(m[edited_margin],new_margin); + obj_styleBox->set_margin_size(m[edited_margin], new_margin); } else { - Vector2 new_pos = mtx.affine_inverse().xform(Vector2(mm.x,mm.y)); + Vector2 new_pos = mtx.affine_inverse().xform(Vector2(mm.x, mm.y)); if (snap_mode == SNAP_PIXEL) - new_pos = new_pos.snapped(Vector2(1,1)); + new_pos = new_pos.snapped(Vector2(1, 1)); else if (snap_mode == SNAP_GRID) - new_pos=snap_point(new_pos); + new_pos = snap_point(new_pos); if (creating) { - rect = Rect2(drag_from,Size2()); + rect = Rect2(drag_from, Size2()); rect.expand_to(new_pos); apply_rect(rect); edit_draw->update(); return; } - switch(drag_index) { - case 0: { - Vector2 p=rect_prev.pos+rect_prev.size; - rect = Rect2(p,Size2()); + switch (drag_index) { + case 0: { + Vector2 p = rect_prev.pos + rect_prev.size; + rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; - case 1: { - Vector2 p=rect_prev.pos+Vector2(0,rect_prev.size.y); - rect = Rect2(p,Size2(rect_prev.size.x,0)); + case 1: { + Vector2 p = rect_prev.pos + Vector2(0, rect_prev.size.y); + rect = Rect2(p, Size2(rect_prev.size.x, 0)); rect.expand_to(new_pos); apply_rect(rect); } break; - case 2: { - Vector2 p=rect_prev.pos+Vector2(0,rect_prev.size.y); - rect = Rect2(p,Size2()); + case 2: { + Vector2 p = rect_prev.pos + Vector2(0, rect_prev.size.y); + rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; - case 3: { - Vector2 p=rect_prev.pos; - rect = Rect2(p,Size2(0,rect_prev.size.y)); + case 3: { + Vector2 p = rect_prev.pos; + rect = Rect2(p, Size2(0, rect_prev.size.y)); rect.expand_to(new_pos); apply_rect(rect); } break; - case 4: { - Vector2 p=rect_prev.pos; - rect = Rect2(p,Size2()); + case 4: { + Vector2 p = rect_prev.pos; + rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; - case 5: { - Vector2 p=rect_prev.pos; - rect = Rect2(p,Size2(rect_prev.size.x,0)); + case 5: { + Vector2 p = rect_prev.pos; + rect = Rect2(p, Size2(rect_prev.size.x, 0)); rect.expand_to(new_pos); apply_rect(rect); } break; - case 6: { - Vector2 p=rect_prev.pos+Vector2(rect_prev.size.x,0); - rect = Rect2(p,Size2()); + case 6: { + Vector2 p = rect_prev.pos + Vector2(rect_prev.size.x, 0); + rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; - case 7: { - Vector2 p=rect_prev.pos+Vector2(rect_prev.size.x,0); - rect = Rect2(p,Size2(0,rect_prev.size.y)); + case 7: { + Vector2 p = rect_prev.pos + Vector2(rect_prev.size.x, 0); + rect = Rect2(p, Size2(0, rect_prev.size.y)); rect.expand_to(new_pos); apply_rect(rect); } break; - } } edit_draw->update(); } - } } -void TextureRegionEditor::_scroll_changed(float) -{ +void TextureRegionEditor::_scroll_changed(float) { if (updating_scroll) return; - draw_ofs.x=hscroll->get_value(); - draw_ofs.y=vscroll->get_value(); + draw_ofs.x = hscroll->get_value(); + draw_ofs.y = vscroll->get_value(); edit_draw->update(); } -void TextureRegionEditor::_set_snap_mode(int p_mode) -{ - snap_mode_button->get_popup()->set_item_checked(snap_mode,false); +void TextureRegionEditor::_set_snap_mode(int p_mode) { + snap_mode_button->get_popup()->set_item_checked(snap_mode, false); snap_mode = p_mode; snap_mode_button->set_text(snap_mode_button->get_popup()->get_item_text(p_mode)); - snap_mode_button->get_popup()->set_item_checked(snap_mode,true); + snap_mode_button->get_popup()->set_item_checked(snap_mode, true); if (snap_mode == SNAP_GRID) hb_grid->show(); @@ -520,91 +514,80 @@ void TextureRegionEditor::_set_snap_mode(int p_mode) edit_draw->update(); } -void TextureRegionEditor::_set_snap_off_x(float p_val) -{ - snap_offset.x=p_val; +void TextureRegionEditor::_set_snap_off_x(float p_val) { + snap_offset.x = p_val; edit_draw->update(); } -void TextureRegionEditor::_set_snap_off_y(float p_val) -{ - snap_offset.y=p_val; +void TextureRegionEditor::_set_snap_off_y(float p_val) { + snap_offset.y = p_val; edit_draw->update(); } -void TextureRegionEditor::_set_snap_step_x(float p_val) -{ - snap_step.x=p_val; +void TextureRegionEditor::_set_snap_step_x(float p_val) { + snap_step.x = p_val; edit_draw->update(); } -void TextureRegionEditor::_set_snap_step_y(float p_val) -{ - snap_step.y=p_val; +void TextureRegionEditor::_set_snap_step_y(float p_val) { + snap_step.y = p_val; edit_draw->update(); } -void TextureRegionEditor::_set_snap_sep_x(float p_val) -{ +void TextureRegionEditor::_set_snap_sep_x(float p_val) { snap_separation.x = p_val; edit_draw->update(); } -void TextureRegionEditor::_set_snap_sep_y(float p_val) -{ +void TextureRegionEditor::_set_snap_sep_y(float p_val) { snap_separation.y = p_val; edit_draw->update(); } -void TextureRegionEditor::_zoom_in() -{ +void TextureRegionEditor::_zoom_in() { if (draw_zoom < 8) { draw_zoom *= 2; edit_draw->update(); } } -void TextureRegionEditor::_zoom_reset() -{ +void TextureRegionEditor::_zoom_reset() { if (draw_zoom == 1) return; draw_zoom = 1; edit_draw->update(); } -void TextureRegionEditor::_zoom_out() -{ +void TextureRegionEditor::_zoom_out() { if (draw_zoom > 0.25) { draw_zoom /= 2; edit_draw->update(); } } -void TextureRegionEditor::apply_rect(const Rect2& rect){ - if(node_sprite) +void TextureRegionEditor::apply_rect(const Rect2 &rect) { + if (node_sprite) node_sprite->set_region_rect(rect); - else if(node_patch9) + else if (node_patch9) node_patch9->set_region_rect(rect); - else if(obj_styleBox.is_valid()) + else if (obj_styleBox.is_valid()) obj_styleBox->set_region_rect(rect); - else if(atlas_tex.is_valid()) + else if (atlas_tex.is_valid()) atlas_tex->set_region(rect); } -void TextureRegionEditor::_notification(int p_what) -{ - switch(p_what) { - case NOTIFICATION_READY: { +void TextureRegionEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_READY: { zoom_out->set_icon(get_icon("ZoomLess", "EditorIcons")); zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons")); zoom_in->set_icon(get_icon("ZoomMore", "EditorIcons")); - icon_zoom->set_texture( get_icon("Zoom", "EditorIcons")); + icon_zoom->set_texture(get_icon("Zoom", "EditorIcons")); } break; } } -void TextureRegionEditor::_node_removed(Object *p_obj) -{ - if(p_obj == node_sprite || p_obj == node_patch9 || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr()) { +void TextureRegionEditor::_node_removed(Object *p_obj) { + if (p_obj == node_sprite || p_obj == node_patch9 || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr()) { node_patch9 = NULL; node_sprite = NULL; obj_styleBox = Ref<StyleBox>(NULL); @@ -613,35 +596,33 @@ void TextureRegionEditor::_node_removed(Object *p_obj) } } -void TextureRegionEditor::_bind_methods() -{ - ClassDB::bind_method(D_METHOD("_edit_region"),&TextureRegionEditor::_edit_region); - ClassDB::bind_method(D_METHOD("_region_draw"),&TextureRegionEditor::_region_draw); - ClassDB::bind_method(D_METHOD("_region_input"),&TextureRegionEditor::_region_input); - ClassDB::bind_method(D_METHOD("_scroll_changed"),&TextureRegionEditor::_scroll_changed); - ClassDB::bind_method(D_METHOD("_node_removed"),&TextureRegionEditor::_node_removed); - ClassDB::bind_method(D_METHOD("_set_snap_mode"),&TextureRegionEditor::_set_snap_mode); - ClassDB::bind_method(D_METHOD("_set_snap_off_x"),&TextureRegionEditor::_set_snap_off_x); - ClassDB::bind_method(D_METHOD("_set_snap_off_y"),&TextureRegionEditor::_set_snap_off_y); - ClassDB::bind_method(D_METHOD("_set_snap_step_x"),&TextureRegionEditor::_set_snap_step_x); - ClassDB::bind_method(D_METHOD("_set_snap_step_y"),&TextureRegionEditor::_set_snap_step_y); - ClassDB::bind_method(D_METHOD("_set_snap_sep_x"),&TextureRegionEditor::_set_snap_sep_x); - ClassDB::bind_method(D_METHOD("_set_snap_sep_y"),&TextureRegionEditor::_set_snap_sep_y); - ClassDB::bind_method(D_METHOD("_zoom_in"),&TextureRegionEditor::_zoom_in); - ClassDB::bind_method(D_METHOD("_zoom_reset"),&TextureRegionEditor::_zoom_reset); - ClassDB::bind_method(D_METHOD("_zoom_out"),&TextureRegionEditor::_zoom_out); +void TextureRegionEditor::_bind_methods() { + ClassDB::bind_method(D_METHOD("_edit_region"), &TextureRegionEditor::_edit_region); + ClassDB::bind_method(D_METHOD("_region_draw"), &TextureRegionEditor::_region_draw); + ClassDB::bind_method(D_METHOD("_region_input"), &TextureRegionEditor::_region_input); + ClassDB::bind_method(D_METHOD("_scroll_changed"), &TextureRegionEditor::_scroll_changed); + ClassDB::bind_method(D_METHOD("_node_removed"), &TextureRegionEditor::_node_removed); + ClassDB::bind_method(D_METHOD("_set_snap_mode"), &TextureRegionEditor::_set_snap_mode); + ClassDB::bind_method(D_METHOD("_set_snap_off_x"), &TextureRegionEditor::_set_snap_off_x); + ClassDB::bind_method(D_METHOD("_set_snap_off_y"), &TextureRegionEditor::_set_snap_off_y); + ClassDB::bind_method(D_METHOD("_set_snap_step_x"), &TextureRegionEditor::_set_snap_step_x); + ClassDB::bind_method(D_METHOD("_set_snap_step_y"), &TextureRegionEditor::_set_snap_step_y); + ClassDB::bind_method(D_METHOD("_set_snap_sep_x"), &TextureRegionEditor::_set_snap_sep_x); + ClassDB::bind_method(D_METHOD("_set_snap_sep_y"), &TextureRegionEditor::_set_snap_sep_y); + ClassDB::bind_method(D_METHOD("_zoom_in"), &TextureRegionEditor::_zoom_in); + ClassDB::bind_method(D_METHOD("_zoom_reset"), &TextureRegionEditor::_zoom_reset); + ClassDB::bind_method(D_METHOD("_zoom_out"), &TextureRegionEditor::_zoom_out); } -void TextureRegionEditor::edit(Object *p_obj) -{ - if (node_sprite && node_sprite->is_connected("texture_changed",this,"_edit_region")) - node_sprite->disconnect("texture_changed",this,"_edit_region"); - if (node_patch9 && node_patch9->is_connected("texture_changed",this,"_edit_region")) - node_patch9->disconnect("texture_changed",this,"_edit_region"); - if (obj_styleBox.is_valid() && obj_styleBox->is_connected("texture_changed",this,"_edit_region")) - obj_styleBox->disconnect("texture_changed",this,"_edit_region"); - if (atlas_tex.is_valid() && atlas_tex->is_connected("atlas_changed",this,"_edit_region")) - atlas_tex->disconnect("atlas_changed",this,"_edit_region"); +void TextureRegionEditor::edit(Object *p_obj) { + if (node_sprite && node_sprite->is_connected("texture_changed", this, "_edit_region")) + node_sprite->disconnect("texture_changed", this, "_edit_region"); + if (node_patch9 && node_patch9->is_connected("texture_changed", this, "_edit_region")) + node_patch9->disconnect("texture_changed", this, "_edit_region"); + if (obj_styleBox.is_valid() && obj_styleBox->is_connected("texture_changed", this, "_edit_region")) + obj_styleBox->disconnect("texture_changed", this, "_edit_region"); + if (atlas_tex.is_valid() && atlas_tex->is_connected("atlas_changed", this, "_edit_region")) + atlas_tex->disconnect("atlas_changed", this, "_edit_region"); if (p_obj) { node_sprite = p_obj->cast_to<Sprite>(); node_patch9 = p_obj->cast_to<NinePatchRect>(); @@ -649,22 +630,22 @@ void TextureRegionEditor::edit(Object *p_obj) obj_styleBox = Ref<StyleBoxTexture>(p_obj->cast_to<StyleBoxTexture>()); if (p_obj->cast_to<AtlasTexture>()) { atlas_tex = Ref<AtlasTexture>(p_obj->cast_to<AtlasTexture>()); - atlas_tex->connect("atlas_changed",this,"_edit_region"); + atlas_tex->connect("atlas_changed", this, "_edit_region"); } else { - p_obj->connect("texture_changed",this,"_edit_region"); + p_obj->connect("texture_changed", this, "_edit_region"); } p_obj->add_change_receptor(this); - p_obj->connect("tree_exited",this,"_node_removed",varray(p_obj),CONNECT_ONESHOT); + p_obj->connect("tree_exited", this, "_node_removed", varray(p_obj), CONNECT_ONESHOT); _edit_region(); } else { - if(node_sprite) - node_sprite->disconnect("tree_exited",this,"_node_removed"); - else if(node_patch9) - node_patch9->disconnect("tree_exited",this,"_node_removed"); - else if(obj_styleBox.is_valid()) - obj_styleBox->disconnect("tree_exited",this,"_node_removed"); - else if(atlas_tex.is_valid()) - atlas_tex->disconnect("tree_exited",this,"_node_removed"); + if (node_sprite) + node_sprite->disconnect("tree_exited", this, "_node_removed"); + else if (node_patch9) + node_patch9->disconnect("tree_exited", this, "_node_removed"); + else if (obj_styleBox.is_valid()) + obj_styleBox->disconnect("tree_exited", this, "_node_removed"); + else if (atlas_tex.is_valid()) + atlas_tex->disconnect("tree_exited", this, "_node_removed"); node_sprite = NULL; node_patch9 = NULL; @@ -680,16 +661,15 @@ void TextureRegionEditor::_changed_callback(Object *p_changed, const char *p_pro } } -void TextureRegionEditor::_edit_region() -{ +void TextureRegionEditor::_edit_region() { Ref<Texture> texture = NULL; - if(node_sprite ) + if (node_sprite) texture = node_sprite->get_texture(); - else if(node_patch9 ) + else if (node_patch9) texture = node_patch9->get_texture(); - else if(obj_styleBox.is_valid()) + else if (obj_styleBox.is_valid()) texture = obj_styleBox->get_texture(); - else if(atlas_tex.is_valid()) + else if (atlas_tex.is_valid()) texture = atlas_tex->get_atlas(); if (texture.is_null()) { @@ -703,30 +683,30 @@ void TextureRegionEditor::_edit_region() bm.create_from_image_alpha(i); for (int y = 0; y < i.get_height(); y++) { for (int x = 0; x < i.get_width(); x++) { - if (bm.get_bit(Point2(x,y))) { + if (bm.get_bit(Point2(x, y))) { bool found = false; - for (List<Rect2>::Element *E = autoslice_cache.front(); E; E=E->next()) { + for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { Rect2 grown = E->get().grow(1.5); - if (grown.has_point(Point2(x,y))) { - E->get().expand_to(Point2(x,y)); - E->get().expand_to(Point2(x+1,y+1)); - x = E->get().pos.x+E->get().size.x-1; + if (grown.has_point(Point2(x, y))) { + E->get().expand_to(Point2(x, y)); + E->get().expand_to(Point2(x + 1, y + 1)); + x = E->get().pos.x + E->get().size.x - 1; bool merged = true; while (merged) { merged = false; bool queue_erase = false; - for (List<Rect2>::Element *F = autoslice_cache.front(); F; F=F->next()) { - if (queue_erase){ + for (List<Rect2>::Element *F = autoslice_cache.front(); F; F = F->next()) { + if (queue_erase) { autoslice_cache.erase(F->prev()); queue_erase = false; } - if (F==E) + if (F == E) continue; if (E->get().grow(1).intersects(F->get())) { E->get().expand_to(F->get().pos); - E->get().expand_to(F->get().pos+F->get().size); + E->get().expand_to(F->get().pos + F->get().size); if (F->prev()) { - F=F->prev(); + F = F->prev(); autoslice_cache.erase(F->next()); } else { queue_erase = true; @@ -741,7 +721,7 @@ void TextureRegionEditor::_edit_region() } } if (!found) { - Rect2 new_rect(x,y,1,1); + Rect2 new_rect(x, y, 1, 1); autoslice_cache.push_back(new_rect); } } @@ -749,12 +729,11 @@ void TextureRegionEditor::_edit_region() } } - - if(node_sprite ) + if (node_sprite) rect = node_sprite->get_region_rect(); - else if(node_patch9 ) + else if (node_patch9) rect = node_patch9->get_region_rect(); - else if(obj_styleBox.is_valid()) + else if (obj_styleBox.is_valid()) rect = obj_styleBox->get_region_rect(); else if (atlas_tex.is_valid()) rect = atlas_tex->get_region(); @@ -764,13 +743,13 @@ void TextureRegionEditor::_edit_region() inline float _snap_scalar(float p_offset, float p_step, float separation, float p_target) { if (p_step != 0) { - float a = Math::stepify(p_target - p_offset, p_step+separation) + p_offset; + float a = Math::stepify(p_target - p_offset, p_step + separation) + p_offset; float b = a; if (p_target >= 0) b -= separation; else b += p_step; - return (Math::abs(p_target-a) < Math::abs(p_target-b)) ? a : b; + return (Math::abs(p_target - a) < Math::abs(p_target - b)) ? a : b; } return p_target; } @@ -784,48 +763,47 @@ Vector2 TextureRegionEditor::snap_point(Vector2 p_target) const { return p_target; } -TextureRegionEditor::TextureRegionEditor(EditorNode* p_editor) -{ +TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) { node_sprite = NULL; node_patch9 = NULL; obj_styleBox = Ref<StyleBoxTexture>(NULL); atlas_tex = Ref<AtlasTexture>(NULL); - editor=p_editor; + editor = p_editor; undo_redo = editor->get_undo_redo(); - snap_step=Vector2(10,10); - snap_separation = Vector2(0,0); + snap_step = Vector2(10, 10); + snap_separation = Vector2(0, 0); edited_margin = -1; drag_index = -1; - drag=false; + drag = false; - VBoxContainer *main_vb = memnew( VBoxContainer ); + VBoxContainer *main_vb = memnew(VBoxContainer); add_child(main_vb); main_vb->set_area_as_parent_rect(0); - HBoxContainer *hb_tools = memnew( HBoxContainer ); + HBoxContainer *hb_tools = memnew(HBoxContainer); main_vb->add_child(hb_tools); - hb_tools->add_child(memnew( Label(TTR("Snap Mode:")) )); + hb_tools->add_child(memnew(Label(TTR("Snap Mode:")))); - snap_mode_button = memnew( MenuButton ); + snap_mode_button = memnew(MenuButton); hb_tools->add_child(snap_mode_button); snap_mode_button->set_text(TTR("<None>")); PopupMenu *p = snap_mode_button->get_popup(); - p->add_item(TTR("<None>"),0); - p->add_item(TTR("Pixel Snap"),1); - p->add_item(TTR("Grid Snap"),2); - p->add_item(TTR("Auto Slice"),3); + p->add_item(TTR("<None>"), 0); + p->add_item(TTR("Pixel Snap"), 1); + p->add_item(TTR("Grid Snap"), 2); + p->add_item(TTR("Auto Slice"), 3); for (int i = 0; i < 4; i++) - p->set_item_as_checkable(i,true); - p->set_item_checked(0,true); + p->set_item_as_checkable(i, true); + p->set_item_checked(0, true); p->connect("id_pressed", this, "_set_snap_mode"); - hb_grid = memnew( HBoxContainer ); + hb_grid = memnew(HBoxContainer); hb_tools->add_child(hb_grid); - hb_grid->add_child( memnew( VSeparator )); + hb_grid->add_child(memnew(VSeparator)); - hb_grid->add_child( memnew( Label(TTR("Offset:")) ) ); + hb_grid->add_child(memnew(Label(TTR("Offset:")))); - sb_off_x = memnew( SpinBox ); + sb_off_x = memnew(SpinBox); sb_off_x->set_min(-256); sb_off_x->set_max(256); sb_off_x->set_step(1); @@ -834,7 +812,7 @@ TextureRegionEditor::TextureRegionEditor(EditorNode* p_editor) sb_off_x->connect("value_changed", this, "_set_snap_off_x"); hb_grid->add_child(sb_off_x); - sb_off_y = memnew( SpinBox ); + sb_off_y = memnew(SpinBox); sb_off_y->set_min(-256); sb_off_y->set_max(256); sb_off_y->set_step(1); @@ -843,10 +821,10 @@ TextureRegionEditor::TextureRegionEditor(EditorNode* p_editor) sb_off_y->connect("value_changed", this, "_set_snap_off_y"); hb_grid->add_child(sb_off_y); - hb_grid->add_child( memnew( VSeparator )); - hb_grid->add_child( memnew( Label(TTR("Step:")) ) ); + hb_grid->add_child(memnew(VSeparator)); + hb_grid->add_child(memnew(Label(TTR("Step:")))); - sb_step_x = memnew( SpinBox ); + sb_step_x = memnew(SpinBox); sb_step_x->set_min(-256); sb_step_x->set_max(256); sb_step_x->set_step(1); @@ -855,7 +833,7 @@ TextureRegionEditor::TextureRegionEditor(EditorNode* p_editor) sb_step_x->connect("value_changed", this, "_set_snap_step_x"); hb_grid->add_child(sb_step_x); - sb_step_y = memnew( SpinBox ); + sb_step_y = memnew(SpinBox); sb_step_y->set_min(-256); sb_step_y->set_max(256); sb_step_y->set_step(1); @@ -864,10 +842,10 @@ TextureRegionEditor::TextureRegionEditor(EditorNode* p_editor) sb_step_y->connect("value_changed", this, "_set_snap_step_y"); hb_grid->add_child(sb_step_y); - hb_grid->add_child( memnew( VSeparator )); - hb_grid->add_child( memnew( Label(TTR("Separation:")) ) ); + hb_grid->add_child(memnew(VSeparator)); + hb_grid->add_child(memnew(Label(TTR("Separation:")))); - sb_sep_x = memnew( SpinBox ); + sb_sep_x = memnew(SpinBox); sb_sep_x->set_min(0); sb_sep_x->set_max(256); sb_sep_x->set_step(1); @@ -876,7 +854,7 @@ TextureRegionEditor::TextureRegionEditor(EditorNode* p_editor) sb_sep_x->connect("value_changed", this, "_set_snap_sep_x"); hb_grid->add_child(sb_sep_x); - sb_sep_y = memnew( SpinBox ); + sb_sep_y = memnew(SpinBox); sb_sep_y->set_min(0); sb_sep_y->set_max(256); sb_sep_y->set_step(1); @@ -887,60 +865,56 @@ TextureRegionEditor::TextureRegionEditor(EditorNode* p_editor) hb_grid->hide(); - HBoxContainer *main_hb = memnew( HBoxContainer ); + HBoxContainer *main_hb = memnew(HBoxContainer); main_vb->add_child(main_hb); - edit_draw = memnew( Control ); + edit_draw = memnew(Control); main_hb->add_child(edit_draw); main_hb->set_v_size_flags(SIZE_EXPAND_FILL); edit_draw->set_h_size_flags(SIZE_EXPAND_FILL); - Control * separator = memnew( Control ); + Control *separator = memnew(Control); separator->set_h_size_flags(Control::SIZE_EXPAND_FILL); hb_tools->add_child(separator); - icon_zoom = memnew( TextureRect ); + icon_zoom = memnew(TextureRect); hb_tools->add_child(icon_zoom); - zoom_out = memnew( ToolButton ); + zoom_out = memnew(ToolButton); zoom_out->connect("pressed", this, "_zoom_out"); hb_tools->add_child(zoom_out); - zoom_reset = memnew( ToolButton ); + zoom_reset = memnew(ToolButton); zoom_reset->connect("pressed", this, "_zoom_reset"); hb_tools->add_child(zoom_reset); - zoom_in = memnew( ToolButton ); + zoom_in = memnew(ToolButton); zoom_in->connect("pressed", this, "_zoom_in"); hb_tools->add_child(zoom_in); - vscroll = memnew( VScrollBar); + vscroll = memnew(VScrollBar); main_hb->add_child(vscroll); - vscroll->connect("value_changed",this,"_scroll_changed"); - hscroll = memnew( HScrollBar ); + vscroll->connect("value_changed", this, "_scroll_changed"); + hscroll = memnew(HScrollBar); main_vb->add_child(hscroll); - hscroll->connect("value_changed",this,"_scroll_changed"); + hscroll->connect("value_changed", this, "_scroll_changed"); - edit_draw->connect("draw",this,"_region_draw"); - edit_draw->connect("gui_input",this,"_region_input"); - draw_zoom=1.0; - updating_scroll=false; + edit_draw->connect("draw", this, "_region_draw"); + edit_draw->connect("gui_input", this, "_region_input"); + draw_zoom = 1.0; + updating_scroll = false; edit_draw->set_clip_contents(true); - } -void TextureRegionEditorPlugin::edit(Object *p_node) -{ +void TextureRegionEditorPlugin::edit(Object *p_node) { region_editor->edit(p_node); } -bool TextureRegionEditorPlugin::handles(Object *p_obj) const -{ +bool TextureRegionEditorPlugin::handles(Object *p_obj) const { return p_obj->is_class("Sprite") || p_obj->is_class("Patch9Rect") || p_obj->is_class("StyleBoxTexture") || p_obj->is_class("AtlasTexture"); } -void TextureRegionEditorPlugin::make_visible(bool p_visible) -{ +void TextureRegionEditorPlugin::make_visible(bool p_visible) { if (p_visible) { region_button->show(); if (region_button->is_pressed()) @@ -952,21 +926,20 @@ void TextureRegionEditorPlugin::make_visible(bool p_visible) } } - Dictionary TextureRegionEditorPlugin::get_state() const { Dictionary state; - state["zoom"]=region_editor->draw_zoom; - state["snap_offset"]=region_editor->snap_offset; - state["snap_step"]=region_editor->snap_step; - state["snap_separation"]=region_editor->snap_separation; - state["snap_mode"]=region_editor->snap_mode; + state["zoom"] = region_editor->draw_zoom; + state["snap_offset"] = region_editor->snap_offset; + state["snap_step"] = region_editor->snap_step; + state["snap_separation"] = region_editor->snap_separation; + state["snap_mode"] = region_editor->snap_mode; return state; } -void TextureRegionEditorPlugin::set_state(const Dictionary& p_state){ +void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) { - Dictionary state=p_state; + Dictionary state = p_state; if (state.has("zoom")) { region_editor->draw_zoom = p_state["zoom"]; } @@ -995,18 +968,16 @@ void TextureRegionEditorPlugin::set_state(const Dictionary& p_state){ if (state.has("snap_mode")) { region_editor->_set_snap_mode(state["snap_mode"]); } - } -TextureRegionEditorPlugin::TextureRegionEditorPlugin(EditorNode *p_node) -{ +TextureRegionEditorPlugin::TextureRegionEditorPlugin(EditorNode *p_node) { editor = p_node; - region_editor = memnew ( TextureRegionEditor(p_node) ); + region_editor = memnew(TextureRegionEditor(p_node)); region_button = p_node->add_bottom_panel_item(TTR("Texture Region"), region_editor); region_button->set_tooltip(TTR("Texture Region Editor")); - region_editor->set_custom_minimum_size(Size2(0,200)); + region_editor->set_custom_minimum_size(Size2(0, 200)); region_editor->hide(); region_button->hide(); } diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h index 8e88f0b707..b3763acc22 100644 --- a/editor/plugins/texture_region_editor_plugin.h +++ b/editor/plugins/texture_region_editor_plugin.h @@ -33,8 +33,8 @@ #define TEXTURE_REGION_EDITOR_PLUGIN_H #include "canvas_item_editor_plugin.h" -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/sprite.h" #include "scene/gui/patch_9_rect.h" #include "scene/resources/style_box.h" @@ -42,7 +42,7 @@ class TextureRegionEditor : public Control { - GDCLASS(TextureRegionEditor, Control ); + GDCLASS(TextureRegionEditor, Control); enum SnapMode { SNAP_NONE, @@ -57,7 +57,7 @@ class TextureRegionEditor : public Control { ToolButton *zoom_in; ToolButton *zoom_reset; ToolButton *zoom_out; - HBoxContainer * hb_grid; //For showing/hiding the grid controls when changing the SnapMode + HBoxContainer *hb_grid; //For showing/hiding the grid controls when changing the SnapMode SpinBox *sb_step_y; SpinBox *sb_step_x; SpinBox *sb_off_y; @@ -70,7 +70,7 @@ class TextureRegionEditor : public Control { HScrollBar *hscroll; EditorNode *editor; - UndoRedo* undo_redo; + UndoRedo *undo_redo; Vector2 draw_ofs; float draw_zoom; @@ -107,9 +107,9 @@ class TextureRegionEditor : public Control { void _zoom_in(); void _zoom_reset(); void _zoom_out(); - void apply_rect(const Rect2& rect); -protected: + void apply_rect(const Rect2 &rect); +protected: void _notification(int p_what); void _node_removed(Object *p_obj); static void _bind_methods(); @@ -119,26 +119,23 @@ protected: virtual void _changed_callback(Object *p_changed, const char *p_prop); public: - void _edit_region(); void _region_draw(); void _region_input(const InputEvent &p_input); void _scroll_changed(float); void edit(Object *p_obj); - TextureRegionEditor(EditorNode* p_editor); - + TextureRegionEditor(EditorNode *p_editor); }; -class TextureRegionEditorPlugin : public EditorPlugin -{ - GDCLASS( TextureRegionEditorPlugin, EditorPlugin ); +class TextureRegionEditorPlugin : public EditorPlugin { + GDCLASS(TextureRegionEditorPlugin, EditorPlugin); Button *region_button; TextureRegionEditor *region_editor; EditorNode *editor; -public: +public: virtual String get_name() const { return "TextureRegion"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 4b8fea5a45..03316cc7d9 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -28,70 +28,64 @@ /*************************************************************************/ #include "theme_editor_plugin.h" -#include "version.h" #include "os/file_access.h" +#include "version.h" -void ThemeEditor::edit(const Ref<Theme>& p_theme) { +void ThemeEditor::edit(const Ref<Theme> &p_theme) { - theme=p_theme; + theme = p_theme; main_vb->set_theme(p_theme); - } - void ThemeEditor::_propagate_redraw(Control *p_at) { p_at->notification(NOTIFICATION_THEME_CHANGED); p_at->minimum_size_changed(); p_at->update(); - for(int i=0;i<p_at->get_child_count();i++) { + for (int i = 0; i < p_at->get_child_count(); i++) { Control *a = p_at->get_child(i)->cast_to<Control>(); if (a) _propagate_redraw(a); - } } void ThemeEditor::_refresh_interval() { _propagate_redraw(main_vb); - } void ThemeEditor::_type_menu_cbk(int p_option) { - - type_edit->set_text( type_menu->get_popup()->get_item_text(p_option) ); + type_edit->set_text(type_menu->get_popup()->get_item_text(p_option)); } void ThemeEditor::_name_menu_about_to_show() { - String fromtype=type_edit->get_text(); + String fromtype = type_edit->get_text(); List<StringName> names; - if (popup_mode==POPUP_ADD) { + if (popup_mode == POPUP_ADD) { - switch(type_select->get_selected()) { + switch (type_select->get_selected()) { - case 0: Theme::get_default()->get_icon_list(fromtype,&names); break; - case 1: Theme::get_default()->get_stylebox_list(fromtype,&names); break; - case 2: Theme::get_default()->get_font_list(fromtype,&names); break; - case 3: Theme::get_default()->get_color_list(fromtype,&names); break; - case 4: Theme::get_default()->get_constant_list(fromtype,&names); break; + case 0: Theme::get_default()->get_icon_list(fromtype, &names); break; + case 1: Theme::get_default()->get_stylebox_list(fromtype, &names); break; + case 2: Theme::get_default()->get_font_list(fromtype, &names); break; + case 3: Theme::get_default()->get_color_list(fromtype, &names); break; + case 4: Theme::get_default()->get_constant_list(fromtype, &names); break; } - } else if (popup_mode==POPUP_REMOVE) { + } else if (popup_mode == POPUP_REMOVE) { - theme->get_icon_list(fromtype,&names); - theme->get_stylebox_list(fromtype,&names); - theme->get_font_list(fromtype,&names); - theme->get_color_list(fromtype,&names); - theme->get_constant_list(fromtype,&names); + theme->get_icon_list(fromtype, &names); + theme->get_stylebox_list(fromtype, &names); + theme->get_font_list(fromtype, &names); + theme->get_color_list(fromtype, &names); + theme->get_constant_list(fromtype, &names); } - name_menu->get_popup()->clear(); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { name_menu->get_popup()->add_item(E->get()); } @@ -99,108 +93,103 @@ void ThemeEditor::_name_menu_about_to_show() { void ThemeEditor::_name_menu_cbk(int p_option) { - name_edit->set_text( name_menu->get_popup()->get_item_text(p_option) ); + name_edit->set_text(name_menu->get_popup()->get_item_text(p_option)); } struct _TECategory { - template<class T> + template <class T> struct RefItem { Ref<T> item; StringName name; - bool operator<(const RefItem<T>& p) const { return item->get_instance_ID() < p.item->get_instance_ID(); } + bool operator<(const RefItem<T> &p) const { return item->get_instance_ID() < p.item->get_instance_ID(); } }; - template<class T> + template <class T> struct Item { T item; String name; - bool operator<(const Item<T>& p) const { return name < p.name; } + bool operator<(const Item<T> &p) const { return name < p.name; } }; - Set<RefItem<StyleBox> > stylebox_items; Set<RefItem<Font> > font_items; Set<RefItem<Texture> > icon_items; Set<Item<Color> > color_items; Set<Item<int> > constant_items; - }; - void ThemeEditor::_save_template_cbk(String fname) { String filename = file_dialog->get_current_path(); - Map<String,_TECategory> categories; + Map<String, _TECategory> categories; //fill types List<StringName> type_list; Theme::get_default()->get_type_list(&type_list); - for (List<StringName>::Element *E=type_list.front();E;E=E->next()) { - categories.insert(E->get(),_TECategory()); + for (List<StringName>::Element *E = type_list.front(); E; E = E->next()) { + categories.insert(E->get(), _TECategory()); } //fill default theme - for(Map<String,_TECategory>::Element *E=categories.front();E;E=E->next() ) { + for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { _TECategory &tc = E->get(); List<StringName> stylebox_list; - Theme::get_default()->get_stylebox_list(E->key(),&stylebox_list); - for (List<StringName>::Element *F=stylebox_list.front();F;F=F->next()) { + Theme::get_default()->get_stylebox_list(E->key(), &stylebox_list); + for (List<StringName>::Element *F = stylebox_list.front(); F; F = F->next()) { _TECategory::RefItem<StyleBox> it; - it.name=F->get(); - it.item=Theme::get_default()->get_stylebox(F->get(),E->key()); + it.name = F->get(); + it.item = Theme::get_default()->get_stylebox(F->get(), E->key()); tc.stylebox_items.insert(it); } List<StringName> font_list; - Theme::get_default()->get_font_list(E->key(),&font_list); - for (List<StringName>::Element *F=font_list.front();F;F=F->next()) { + Theme::get_default()->get_font_list(E->key(), &font_list); + for (List<StringName>::Element *F = font_list.front(); F; F = F->next()) { _TECategory::RefItem<Font> it; - it.name=F->get(); - it.item=Theme::get_default()->get_font(F->get(),E->key()); + it.name = F->get(); + it.item = Theme::get_default()->get_font(F->get(), E->key()); tc.font_items.insert(it); } List<StringName> icon_list; - Theme::get_default()->get_icon_list(E->key(),&icon_list); - for (List<StringName>::Element *F=icon_list.front();F;F=F->next()) { + Theme::get_default()->get_icon_list(E->key(), &icon_list); + for (List<StringName>::Element *F = icon_list.front(); F; F = F->next()) { _TECategory::RefItem<Texture> it; - it.name=F->get(); - it.item=Theme::get_default()->get_icon(F->get(),E->key()); + it.name = F->get(); + it.item = Theme::get_default()->get_icon(F->get(), E->key()); tc.icon_items.insert(it); } List<StringName> color_list; - Theme::get_default()->get_color_list(E->key(),&color_list); - for (List<StringName>::Element *F=color_list.front();F;F=F->next()) { + Theme::get_default()->get_color_list(E->key(), &color_list); + for (List<StringName>::Element *F = color_list.front(); F; F = F->next()) { _TECategory::Item<Color> it; - it.name=F->get(); - it.item=Theme::get_default()->get_color(F->get(),E->key()); + it.name = F->get(); + it.item = Theme::get_default()->get_color(F->get(), E->key()); tc.color_items.insert(it); } List<StringName> constant_list; - Theme::get_default()->get_constant_list(E->key(),&constant_list); - for (List<StringName>::Element *F=constant_list.front();F;F=F->next()) { + Theme::get_default()->get_constant_list(E->key(), &constant_list); + for (List<StringName>::Element *F = constant_list.front(); F; F = F->next()) { _TECategory::Item<int> it; - it.name=F->get(); - it.item=Theme::get_default()->get_constant(F->get(),E->key()); + it.name = F->get(); + it.item = Theme::get_default()->get_constant(F->get(), E->key()); tc.constant_items.insert(it); } - } - FileAccess *file = FileAccess::open(filename,FileAccess::WRITE); + FileAccess *file = FileAccess::open(filename, FileAccess::WRITE); if (!file) { - - ERR_EXPLAIN(TTR("Can't save theme to file:")+" "+filename); + ERR_EXPLAIN(TTR("Can't save theme to file:") + " " + filename); return; } file->store_line("; ******************* "); @@ -253,7 +242,7 @@ void ThemeEditor::_save_template_cbk(String fname) { file->store_line("; "); file->store_line("; ******************* "); file->store_line("; "); - file->store_line("; Template Generated Using: "+String(VERSION_MKSTRING)); + file->store_line("; Template Generated Using: " + String(VERSION_MKSTRING)); file->store_line("; "); file->store_line("; "); file->store_line(""); @@ -266,59 +255,58 @@ void ThemeEditor::_save_template_cbk(String fname) { file->store_line(""); //write default theme - for(Map<String,_TECategory>::Element *E=categories.front();E;E=E->next() ) { + for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { _TECategory &tc = E->get(); - String underline="; "; - for(int i=0;i<E->key().length();i++) - underline+="*"; + String underline = "; "; + for (int i = 0; i < E->key().length(); i++) + underline += "*"; file->store_line(""); file->store_line(underline); - file->store_line("; "+E->key()); + file->store_line("; " + E->key()); file->store_line(underline); if (tc.stylebox_items.size()) file->store_line("\n; StyleBox Items:\n"); - for (Set<_TECategory::RefItem<StyleBox> >::Element *F=tc.stylebox_items.front();F;F=F->next()) { + for (Set<_TECategory::RefItem<StyleBox> >::Element *F = tc.stylebox_items.front(); F; F = F->next()) { - file->store_line(E->key()+"."+F->get().name+" = default"); + file->store_line(E->key() + "." + F->get().name + " = default"); } if (tc.font_items.size()) file->store_line("\n; Font Items:\n"); - for (Set<_TECategory::RefItem<Font> >::Element *F=tc.font_items.front();F;F=F->next()) { + for (Set<_TECategory::RefItem<Font> >::Element *F = tc.font_items.front(); F; F = F->next()) { - file->store_line(E->key()+"."+F->get().name+" = default"); + file->store_line(E->key() + "." + F->get().name + " = default"); } if (tc.icon_items.size()) file->store_line("\n; Icon Items:\n"); - for (Set<_TECategory::RefItem<Texture> >::Element *F=tc.icon_items.front();F;F=F->next()) { + for (Set<_TECategory::RefItem<Texture> >::Element *F = tc.icon_items.front(); F; F = F->next()) { - file->store_line(E->key()+"."+F->get().name+" = default"); + file->store_line(E->key() + "." + F->get().name + " = default"); } if (tc.color_items.size()) file->store_line("\n; Color Items:\n"); - for (Set<_TECategory::Item<Color> >::Element *F=tc.color_items.front();F;F=F->next()) { + for (Set<_TECategory::Item<Color> >::Element *F = tc.color_items.front(); F; F = F->next()) { - file->store_line(E->key()+"."+F->get().name+" = default"); + file->store_line(E->key() + "." + F->get().name + " = default"); } if (tc.constant_items.size()) file->store_line("\n; Constant Items:\n"); - for (Set<_TECategory::Item<int> >::Element *F=tc.constant_items.front();F;F=F->next()) { + for (Set<_TECategory::Item<int> >::Element *F = tc.constant_items.front(); F; F = F->next()) { - file->store_line(E->key()+"."+F->get().name+" = default"); + file->store_line(E->key() + "." + F->get().name + " = default"); } - } file->close(); @@ -327,16 +315,16 @@ void ThemeEditor::_save_template_cbk(String fname) { void ThemeEditor::_dialog_cbk() { - switch(popup_mode) { + switch (popup_mode) { case POPUP_ADD: { - switch(type_select->get_selected()) { + switch (type_select->get_selected()) { - case 0: theme->set_icon(name_edit->get_text(),type_edit->get_text(),Ref<Texture>()); break; - case 1: theme->set_stylebox(name_edit->get_text(),type_edit->get_text(),Ref<StyleBox>()); break; - case 2: theme->set_font(name_edit->get_text(),type_edit->get_text(),Ref<Font>()); break; - case 3: theme->set_color(name_edit->get_text(),type_edit->get_text(),Color()); break; - case 4: theme->set_constant(name_edit->get_text(),type_edit->get_text(),0); break; + case 0: theme->set_icon(name_edit->get_text(), type_edit->get_text(), Ref<Texture>()); break; + case 1: theme->set_stylebox(name_edit->get_text(), type_edit->get_text(), Ref<StyleBox>()); break; + case 2: theme->set_font(name_edit->get_text(), type_edit->get_text(), Ref<Font>()); break; + case 3: theme->set_color(name_edit->get_text(), type_edit->get_text(), Color()); break; + case 4: theme->set_constant(name_edit->get_text(), type_edit->get_text(), 0); break; } } break; @@ -347,58 +335,50 @@ void ThemeEditor::_dialog_cbk() { { names.clear(); - Theme::get_default()->get_icon_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->set_icon(E->get(),fromtype,Ref<Texture>()); - + Theme::get_default()->get_icon_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->set_icon(E->get(), fromtype, Ref<Texture>()); } - } { names.clear(); - Theme::get_default()->get_stylebox_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->set_stylebox(E->get(),fromtype,Ref<StyleBox>()); - + Theme::get_default()->get_stylebox_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->set_stylebox(E->get(), fromtype, Ref<StyleBox>()); } - } { names.clear(); - Theme::get_default()->get_font_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->set_font(E->get(),fromtype,Ref<Font>()); - + Theme::get_default()->get_font_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->set_font(E->get(), fromtype, Ref<Font>()); } } { names.clear(); - Theme::get_default()->get_color_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->set_color(E->get(),fromtype,Theme::get_default()->get_color(E->get(),fromtype)); - + Theme::get_default()->get_color_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->set_color(E->get(), fromtype, Theme::get_default()->get_color(E->get(), fromtype)); } } { names.clear(); - Theme::get_default()->get_constant_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->set_constant(E->get(),fromtype,Theme::get_default()->get_constant(E->get(),fromtype)); - + Theme::get_default()->get_constant_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->set_constant(E->get(), fromtype, Theme::get_default()->get_constant(E->get(), fromtype)); } } } break; case POPUP_REMOVE: { - switch(type_select->get_selected()) { + switch (type_select->get_selected()) { - case 0: theme->clear_icon(name_edit->get_text(),type_edit->get_text()); break; - case 1: theme->clear_stylebox(name_edit->get_text(),type_edit->get_text()); break; - case 2: theme->clear_font(name_edit->get_text(),type_edit->get_text()); break; - case 3: theme->clear_color(name_edit->get_text(),type_edit->get_text()); break; - case 4: theme->clear_constant(name_edit->get_text(),type_edit->get_text()); break; + case 0: theme->clear_icon(name_edit->get_text(), type_edit->get_text()); break; + case 1: theme->clear_stylebox(name_edit->get_text(), type_edit->get_text()); break; + case 2: theme->clear_font(name_edit->get_text(), type_edit->get_text()); break; + case 3: theme->clear_color(name_edit->get_text(), type_edit->get_text()); break; + case 4: theme->clear_constant(name_edit->get_text(), type_edit->get_text()); break; } - } break; case POPUP_CLASS_REMOVE: { StringName fromtype = type_edit->get_text(); @@ -406,121 +386,106 @@ void ThemeEditor::_dialog_cbk() { { names.clear(); - Theme::get_default()->get_icon_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->clear_icon(E->get(),fromtype); - + Theme::get_default()->get_icon_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->clear_icon(E->get(), fromtype); } - } { names.clear(); - Theme::get_default()->get_stylebox_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->clear_stylebox(E->get(),fromtype); - + Theme::get_default()->get_stylebox_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->clear_stylebox(E->get(), fromtype); } - } { names.clear(); - Theme::get_default()->get_font_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->clear_font(E->get(),fromtype); - + Theme::get_default()->get_font_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->clear_font(E->get(), fromtype); } } { names.clear(); - Theme::get_default()->get_color_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->clear_color(E->get(),fromtype); - + Theme::get_default()->get_color_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->clear_color(E->get(), fromtype); } } { names.clear(); - Theme::get_default()->get_constant_list(fromtype,&names); - for(List<StringName>::Element *E=names.front();E;E=E->next()) { - theme->clear_constant(E->get(),fromtype); - + Theme::get_default()->get_constant_list(fromtype, &names); + for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + theme->clear_constant(E->get(), fromtype); } } - }break; + } break; } - } void ThemeEditor::_theme_menu_cbk(int p_option) { - - if (p_option==POPUP_CREATE_EMPTY || p_option==POPUP_CREATE_EDITOR_EMPTY) { - + if (p_option == POPUP_CREATE_EMPTY || p_option == POPUP_CREATE_EDITOR_EMPTY) { Ref<Theme> base_theme; - if (p_option==POPUP_CREATE_EMPTY) { + if (p_option == POPUP_CREATE_EMPTY) { base_theme = Theme::get_default(); } else { base_theme = EditorNode::get_singleton()->get_theme_base()->get_theme(); } - { List<StringName> types; base_theme->get_type_list(&types); - - for (List<StringName>::Element *T=types.front();T;T=T->next()) { + for (List<StringName>::Element *T = types.front(); T; T = T->next()) { StringName type = T->get(); List<StringName> icons; - base_theme->get_icon_list(type,&icons); + base_theme->get_icon_list(type, &icons); - for (List<StringName>::Element *E=icons.front();E;E=E->next()) { - theme->set_icon(E->get(),type,Ref<Texture>()); + for (List<StringName>::Element *E = icons.front(); E; E = E->next()) { + theme->set_icon(E->get(), type, Ref<Texture>()); } List<StringName> shaders; - base_theme->get_shader_list(type,&shaders); + base_theme->get_shader_list(type, &shaders); - for (List<StringName>::Element *E=shaders.front();E;E=E->next()) { - theme->set_shader(E->get(),type,Ref<Shader>()); + for (List<StringName>::Element *E = shaders.front(); E; E = E->next()) { + theme->set_shader(E->get(), type, Ref<Shader>()); } List<StringName> styleboxs; - base_theme->get_stylebox_list(type,&styleboxs); + base_theme->get_stylebox_list(type, &styleboxs); - for (List<StringName>::Element *E=styleboxs.front();E;E=E->next()) { - theme->set_stylebox(E->get(),type,Ref<StyleBox>()); + for (List<StringName>::Element *E = styleboxs.front(); E; E = E->next()) { + theme->set_stylebox(E->get(), type, Ref<StyleBox>()); } List<StringName> fonts; - base_theme->get_font_list(type,&fonts); + base_theme->get_font_list(type, &fonts); - for (List<StringName>::Element *E=fonts.front();E;E=E->next()) { - theme->set_font(E->get(),type,Ref<Font>()); + for (List<StringName>::Element *E = fonts.front(); E; E = E->next()) { + theme->set_font(E->get(), type, Ref<Font>()); } List<StringName> colors; - base_theme->get_color_list(type,&colors); + base_theme->get_color_list(type, &colors); - for (List<StringName>::Element *E=colors.front();E;E=E->next()) { - theme->set_color(E->get(),type,Color()); + for (List<StringName>::Element *E = colors.front(); E; E = E->next()) { + theme->set_color(E->get(), type, Color()); } - List<StringName> constants; - base_theme->get_constant_list(type,&constants); + base_theme->get_constant_list(type, &constants); - for (List<StringName>::Element *E=constants.front();E;E=E->next()) { - theme->set_constant(E->get(),type,base_theme->get_constant(type,E->get())); + for (List<StringName>::Element *E = constants.front(); E; E = E->next()) { + theme->set_constant(E->get(), type, base_theme->get_constant(type, E->get())); } - } - } return; } @@ -533,22 +498,21 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { name_edit->show(); name_menu->show(); - - if (p_option==POPUP_ADD) {//add + if (p_option == POPUP_ADD) { //add add_del_dialog->set_title(TTR("Add Item")); add_del_dialog->get_ok()->set_text(TTR("Add")); - add_del_dialog->popup_centered(Size2(490,85)*EDSCALE); + add_del_dialog->popup_centered(Size2(490, 85) * EDSCALE); - base_theme=Theme::get_default(); + base_theme = Theme::get_default(); - } else if (p_option==POPUP_CLASS_ADD) {//add + } else if (p_option == POPUP_CLASS_ADD) { //add add_del_dialog->set_title(TTR("Add All Items")); add_del_dialog->get_ok()->set_text(TTR("Add All")); - add_del_dialog->popup_centered(Size2(240,85)*EDSCALE); + add_del_dialog->popup_centered(Size2(240, 85) * EDSCALE); - base_theme=Theme::get_default(); + base_theme = Theme::get_default(); type_select->hide(); name_select_label->hide(); @@ -556,21 +520,21 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { name_edit->hide(); name_menu->hide(); - } else if (p_option==POPUP_REMOVE) { + } else if (p_option == POPUP_REMOVE) { add_del_dialog->set_title(TTR("Remove Item")); add_del_dialog->get_ok()->set_text(TTR("Remove")); - add_del_dialog->popup_centered(Size2(490,85)*EDSCALE); + add_del_dialog->popup_centered(Size2(490, 85) * EDSCALE); - base_theme=theme; + base_theme = theme; - } else if (p_option==POPUP_CLASS_REMOVE) { + } else if (p_option == POPUP_CLASS_REMOVE) { add_del_dialog->set_title("Remove All Items"); add_del_dialog->get_ok()->set_text("Remove All"); - add_del_dialog->popup_centered(Size2(240,85)*EDSCALE); + add_del_dialog->popup_centered(Size2(240, 85) * EDSCALE); - base_theme=Theme::get_default(); + base_theme = Theme::get_default(); type_select->hide(); name_select_label->hide(); @@ -578,28 +542,28 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { name_edit->hide(); name_menu->hide(); } - popup_mode=p_option; + popup_mode = p_option; - ERR_FAIL_COND( theme.is_null() ); + ERR_FAIL_COND(theme.is_null()); List<StringName> types; base_theme->get_type_list(&types); type_menu->get_popup()->clear(); - if (p_option==0 || p_option==1) {//add + if (p_option == 0 || p_option == 1) { //add List<StringName> new_types; theme->get_type_list(&new_types); //uh kind of sucks - for(List<StringName>::Element *F=new_types.front();F;F=F->next()) { + for (List<StringName>::Element *F = new_types.front(); F; F = F->next()) { - bool found=false; - for(List<StringName>::Element *E=types.front();E;E=E->next()) { + bool found = false; + for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - if (E->get()==F->get()) { - found=true; + if (E->get() == F->get()) { + found = true; break; } } @@ -611,20 +575,19 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { //types.sort(); types.sort_custom<StringName::AlphCompare>(); - for(List<StringName>::Element *E=types.front();E;E=E->next()) { + for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - type_menu->get_popup()->add_item( E->get() ); + type_menu->get_popup()->add_item(E->get()); } - } void ThemeEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_PROCESS) { + if (p_what == NOTIFICATION_PROCESS) { - time_left-=get_process_delta_time(); - if (time_left<0) { - time_left=1.5; + time_left -= get_process_delta_time(); + if (time_left < 0) { + time_left = 1.5; _refresh_interval(); } } @@ -632,110 +595,101 @@ void ThemeEditor::_notification(int p_what) { void ThemeEditor::_bind_methods() { - ClassDB::bind_method("_type_menu_cbk",&ThemeEditor::_type_menu_cbk); - ClassDB::bind_method("_name_menu_about_to_show",&ThemeEditor::_name_menu_about_to_show); - ClassDB::bind_method("_name_menu_cbk",&ThemeEditor::_name_menu_cbk); - ClassDB::bind_method("_theme_menu_cbk",&ThemeEditor::_theme_menu_cbk); - ClassDB::bind_method("_dialog_cbk",&ThemeEditor::_dialog_cbk); - ClassDB::bind_method("_save_template_cbk",&ThemeEditor::_save_template_cbk); + ClassDB::bind_method("_type_menu_cbk", &ThemeEditor::_type_menu_cbk); + ClassDB::bind_method("_name_menu_about_to_show", &ThemeEditor::_name_menu_about_to_show); + ClassDB::bind_method("_name_menu_cbk", &ThemeEditor::_name_menu_cbk); + ClassDB::bind_method("_theme_menu_cbk", &ThemeEditor::_theme_menu_cbk); + ClassDB::bind_method("_dialog_cbk", &ThemeEditor::_dialog_cbk); + ClassDB::bind_method("_save_template_cbk", &ThemeEditor::_save_template_cbk); } ThemeEditor::ThemeEditor() { - time_left=0; + time_left = 0; - scroll = memnew( ScrollContainer ); + scroll = memnew(ScrollContainer); add_child(scroll); scroll->set_area_as_parent_rect(3); - scroll->set_margin(MARGIN_TOP,30*EDSCALE); + scroll->set_margin(MARGIN_TOP, 30 * EDSCALE); //scroll->set_enable_h_scroll(true); scroll->set_enable_v_scroll(true); scroll->set_enable_h_scroll(false); - Panel * panel = memnew( Panel ); + Panel *panel = memnew(Panel); scroll->add_child(panel); - panel->set_custom_minimum_size(Size2(500,800)*EDSCALE); + panel->set_custom_minimum_size(Size2(500, 800) * EDSCALE); panel->set_theme(Theme::get_default()); panel->set_h_size_flags(SIZE_EXPAND_FILL); - main_vb= memnew( VBoxContainer ); + main_vb = memnew(VBoxContainer); panel->add_child(main_vb); - main_vb->set_area_as_parent_rect(4*EDSCALE); - + main_vb->set_area_as_parent_rect(4 * EDSCALE); HBoxContainer *hb_menu = memnew(HBoxContainer); main_vb->add_child(hb_menu); - - - theme_menu = memnew( MenuButton ); + theme_menu = memnew(MenuButton); theme_menu->set_text(TTR("Theme")); - theme_menu->get_popup()->add_item(TTR("Add Item"),POPUP_ADD); - theme_menu->get_popup()->add_item(TTR("Add Class Items"),POPUP_CLASS_ADD); - theme_menu->get_popup()->add_item(TTR("Remove Item"),POPUP_REMOVE); - theme_menu->get_popup()->add_item(TTR("Remove Class Items"),POPUP_CLASS_REMOVE); + theme_menu->get_popup()->add_item(TTR("Add Item"), POPUP_ADD); + theme_menu->get_popup()->add_item(TTR("Add Class Items"), POPUP_CLASS_ADD); + theme_menu->get_popup()->add_item(TTR("Remove Item"), POPUP_REMOVE); + theme_menu->get_popup()->add_item(TTR("Remove Class Items"), POPUP_CLASS_REMOVE); theme_menu->get_popup()->add_separator(); - theme_menu->get_popup()->add_item(TTR("Create Empty Template"),POPUP_CREATE_EMPTY); - theme_menu->get_popup()->add_item(TTR("Create Empty Editor Template"),POPUP_CREATE_EDITOR_EMPTY); + theme_menu->get_popup()->add_item(TTR("Create Empty Template"), POPUP_CREATE_EMPTY); + theme_menu->get_popup()->add_item(TTR("Create Empty Editor Template"), POPUP_CREATE_EDITOR_EMPTY); add_child(theme_menu); - theme_menu->set_pos(Vector2(3,3)*EDSCALE); - theme_menu->get_popup()->connect("id_pressed", this,"_theme_menu_cbk"); + theme_menu->set_pos(Vector2(3, 3) * EDSCALE); + theme_menu->get_popup()->connect("id_pressed", this, "_theme_menu_cbk"); - - HBoxContainer *main_hb = memnew( HBoxContainer ); + HBoxContainer *main_hb = memnew(HBoxContainer); main_vb->add_child(main_hb); - - - VBoxContainer *first_vb = memnew( VBoxContainer); + VBoxContainer *first_vb = memnew(VBoxContainer); first_vb->set_h_size_flags(SIZE_EXPAND_FILL); main_hb->add_child(first_vb); - - //main_panel->add_child(panel); //panel->set_area_as_parent_rect(); //panel->set_margin( MARGIN_TOP,20 ); - first_vb->add_child(memnew( Label("Label") )); + first_vb->add_child(memnew(Label("Label"))); - first_vb->add_child(memnew( Button("Button")) ); - ToolButton *tb = memnew( ToolButton ); + first_vb->add_child(memnew(Button("Button"))); + ToolButton *tb = memnew(ToolButton); tb->set_text("ToolButton"); - first_vb->add_child(tb ); - CheckButton *cb = memnew( CheckButton ); + first_vb->add_child(tb); + CheckButton *cb = memnew(CheckButton); cb->set_text("CheckButton"); - first_vb->add_child(cb ); - CheckBox *cbx = memnew( CheckBox ); + first_vb->add_child(cb); + CheckBox *cbx = memnew(CheckBox); cbx->set_text("CheckBox"); - first_vb->add_child(cbx ); + first_vb->add_child(cbx); - - VBoxContainer *bg = memnew( VBoxContainer ); + VBoxContainer *bg = memnew(VBoxContainer); bg->set_v_size_flags(SIZE_EXPAND_FILL); - VBoxContainer *gbvb = memnew( VBoxContainer ); + VBoxContainer *gbvb = memnew(VBoxContainer); gbvb->set_v_size_flags(SIZE_EXPAND_FILL); - CheckBox *rbx1 = memnew( CheckBox ); + CheckBox *rbx1 = memnew(CheckBox); rbx1->set_text(TTR("CheckBox Radio1")); rbx1->set_pressed(true); gbvb->add_child(rbx1); - CheckBox *rbx2 = memnew( CheckBox ); + CheckBox *rbx2 = memnew(CheckBox); rbx2->set_text(TTR("CheckBox Radio2")); gbvb->add_child(rbx2); bg->add_child(gbvb); first_vb->add_child(bg); - MenuButton* test_menu_button = memnew( MenuButton ); + MenuButton *test_menu_button = memnew(MenuButton); test_menu_button->set_text("MenuButton"); test_menu_button->get_popup()->add_item(TTR("Item")); test_menu_button->get_popup()->add_separator(); test_menu_button->get_popup()->add_check_item(TTR("Check Item")); test_menu_button->get_popup()->add_check_item(TTR("Checked Item")); - test_menu_button->get_popup()->set_item_checked(2,true); + test_menu_button->get_popup()->set_item_checked(2, true); first_vb->add_child(test_menu_button); - OptionButton *test_option_button = memnew( OptionButton ); + OptionButton *test_option_button = memnew(OptionButton); test_option_button->add_item("OptionButton"); test_option_button->add_separator(); test_option_button->add_item(TTR("Has")); @@ -743,89 +697,85 @@ ThemeEditor::ThemeEditor() { test_option_button->add_item(TTR("Options")); first_vb->add_child(test_option_button); - ColorPickerButton *cpb = memnew( ColorPickerButton ); - first_vb->add_child(cpb ); + ColorPickerButton *cpb = memnew(ColorPickerButton); + first_vb->add_child(cpb); - first_vb->add_child( memnew( HSeparator )); - first_vb->add_child( memnew( HSlider )); - first_vb->add_child( memnew( HScrollBar )); - first_vb->add_child( memnew( SpinBox )); - ProgressBar *pb=memnew( ProgressBar ); + first_vb->add_child(memnew(HSeparator)); + first_vb->add_child(memnew(HSlider)); + first_vb->add_child(memnew(HScrollBar)); + first_vb->add_child(memnew(SpinBox)); + ProgressBar *pb = memnew(ProgressBar); pb->set_value(50); - first_vb->add_child( pb); - Panel *pn=memnew( Panel ); - pn->set_custom_minimum_size(Size2(40,40)*EDSCALE); - first_vb->add_child( pn); - first_vb->add_constant_override("separation",10*EDSCALE); + first_vb->add_child(pb); + Panel *pn = memnew(Panel); + pn->set_custom_minimum_size(Size2(40, 40) * EDSCALE); + first_vb->add_child(pn); + first_vb->add_constant_override("separation", 10 * EDSCALE); - VBoxContainer *second_vb = memnew( VBoxContainer ); + VBoxContainer *second_vb = memnew(VBoxContainer); second_vb->set_h_size_flags(SIZE_EXPAND_FILL); main_hb->add_child(second_vb); - second_vb->add_constant_override("separation",10*EDSCALE); - LineEdit *le = memnew( LineEdit ); + second_vb->add_constant_override("separation", 10 * EDSCALE); + LineEdit *le = memnew(LineEdit); le->set_text("LineEdit"); second_vb->add_child(le); - TextEdit *te = memnew( TextEdit ); + TextEdit *te = memnew(TextEdit); te->set_text("TextEdit"); //te->set_v_size_flags(SIZE_EXPAND_FILL); - te->set_custom_minimum_size(Size2(0,160)*EDSCALE); + te->set_custom_minimum_size(Size2(0, 160) * EDSCALE); second_vb->add_child(te); Tree *test_tree = memnew(Tree); second_vb->add_child(test_tree); - test_tree->set_custom_minimum_size(Size2(0,160)*EDSCALE); - + test_tree->set_custom_minimum_size(Size2(0, 160) * EDSCALE); TreeItem *item = test_tree->create_item(); - item->set_editable(0,true); - item->set_text(0,"Tree"); - item = test_tree->create_item( test_tree->get_root() ); + item->set_editable(0, true); + item->set_text(0, "Tree"); + item = test_tree->create_item(test_tree->get_root()); item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); - item->set_editable(0,true); - item->set_text(0,"check"); - item = test_tree->create_item( test_tree->get_root() ); + item->set_editable(0, true); + item->set_text(0, "check"); + item = test_tree->create_item(test_tree->get_root()); item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE); - item->set_editable(0,true); - item->set_range_config(0,0,20,0.1); - item->set_range(0,2); - item = test_tree->create_item( test_tree->get_root() ); + item->set_editable(0, true); + item->set_range_config(0, 0, 20, 0.1); + item->set_range(0, 2); + item = test_tree->create_item(test_tree->get_root()); item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE); - item->set_editable(0,true); - item->set_text(0,TTR("Have,Many,Several,Options!")); - item->set_range(0,2); + item->set_editable(0, true); + item->set_text(0, TTR("Have,Many,Several,Options!")); + item->set_range(0, 2); - VBoxContainer *third_vb = memnew( VBoxContainer ); + VBoxContainer *third_vb = memnew(VBoxContainer); third_vb->set_h_size_flags(SIZE_EXPAND_FILL); - third_vb->add_constant_override("separation",10); + third_vb->add_constant_override("separation", 10); main_hb->add_child(third_vb); - HBoxContainer *vhb = memnew( HBoxContainer ); - vhb->set_custom_minimum_size(Size2(0,160)*EDSCALE); + HBoxContainer *vhb = memnew(HBoxContainer); + vhb->set_custom_minimum_size(Size2(0, 160) * EDSCALE); vhb->add_child(memnew(VSeparator)); vhb->add_child(memnew(VSlider)); vhb->add_child(memnew(VScrollBar)); third_vb->add_child(vhb); - TabContainer *tc = memnew( TabContainer ); + TabContainer *tc = memnew(TabContainer); third_vb->add_child(tc); - tc->set_custom_minimum_size(Size2(0,160)*EDSCALE); - Control *tcc = memnew( Control ); + tc->set_custom_minimum_size(Size2(0, 160) * EDSCALE); + Control *tcc = memnew(Control); tcc->set_name(TTR("Tab 1")); tc->add_child(tcc); - tcc = memnew( Control ); + tcc = memnew(Control); tcc->set_name(TTR("Tab 2")); tc->add_child(tcc); - tcc = memnew( Control ); + tcc = memnew(Control); tcc->set_name(TTR("Tab 3")); tc->add_child(tcc); - main_hb->add_constant_override("separation",20*EDSCALE); - - + main_hb->add_constant_override("separation", 20 * EDSCALE); - -/* + /* test_h_scroll = memnew( HScrollBar ); test_h_scroll->set_pos( Point2( 25, 225 ) ); test_h_scroll->set_size( Point2( 150, 5 ) ); @@ -881,93 +831,88 @@ ThemeEditor::ThemeEditor() { add_del_dialog->hide(); add_child(add_del_dialog); - - Label *l = memnew( Label ); - l->set_pos( Point2(5,5)*EDSCALE ); + Label *l = memnew(Label); + l->set_pos(Point2(5, 5) * EDSCALE); l->set_text(TTR("Type:")); add_del_dialog->add_child(l); - dtype_select_label=l; - + dtype_select_label = l; - type_edit = memnew( LineEdit ); - type_edit->set_pos(Point2(5,25)*EDSCALE); - type_edit->set_size(Point2(150,5)*EDSCALE); + type_edit = memnew(LineEdit); + type_edit->set_pos(Point2(5, 25) * EDSCALE); + type_edit->set_size(Point2(150, 5) * EDSCALE); add_del_dialog->add_child(type_edit); - type_menu = memnew( MenuButton ); - type_menu->set_pos(Point2(160,25)*EDSCALE); - type_menu->set_size(Point2(30,5)*EDSCALE); + type_menu = memnew(MenuButton); + type_menu->set_pos(Point2(160, 25) * EDSCALE); + type_menu->set_size(Point2(30, 5) * EDSCALE); type_menu->set_text(".."); add_del_dialog->add_child(type_menu); - type_menu->get_popup()->connect("id_pressed", this,"_type_menu_cbk"); + type_menu->get_popup()->connect("id_pressed", this, "_type_menu_cbk"); - l = memnew( Label ); - l->set_pos( Point2(200,5)*EDSCALE ); + l = memnew(Label); + l->set_pos(Point2(200, 5) * EDSCALE); l->set_text(TTR("Name:")); add_del_dialog->add_child(l); - name_select_label=l; + name_select_label = l; - name_edit = memnew( LineEdit ); - name_edit->set_pos(Point2(200,25)*EDSCALE); - name_edit->set_size(Point2(150,5)*EDSCALE); + name_edit = memnew(LineEdit); + name_edit->set_pos(Point2(200, 25) * EDSCALE); + name_edit->set_size(Point2(150, 5) * EDSCALE); add_del_dialog->add_child(name_edit); - name_menu = memnew( MenuButton ); - name_menu->set_pos(Point2(360,25)*EDSCALE); - name_menu->set_size(Point2(30,5)*EDSCALE); + name_menu = memnew(MenuButton); + name_menu->set_pos(Point2(360, 25) * EDSCALE); + name_menu->set_size(Point2(30, 5) * EDSCALE); name_menu->set_text(".."); add_del_dialog->add_child(name_menu); - name_menu->get_popup()->connect("about_to_show", this,"_name_menu_about_to_show"); - name_menu->get_popup()->connect("id_pressed", this,"_name_menu_cbk"); + name_menu->get_popup()->connect("about_to_show", this, "_name_menu_about_to_show"); + name_menu->get_popup()->connect("id_pressed", this, "_name_menu_cbk"); - type_select_label= memnew( Label ); - type_select_label->set_pos( Point2(400,5)*EDSCALE ); + type_select_label = memnew(Label); + type_select_label->set_pos(Point2(400, 5) * EDSCALE); type_select_label->set_text(TTR("Data Type:")); add_del_dialog->add_child(type_select_label); - type_select = memnew( OptionButton ); + type_select = memnew(OptionButton); type_select->add_item(TTR("Icon")); type_select->add_item(TTR("Style")); type_select->add_item(TTR("Font")); type_select->add_item(TTR("Color")); type_select->add_item(TTR("Constant")); - type_select->set_pos( Point2( 400,25 )*EDSCALE ); - type_select->set_size( Point2( 80,5 )*EDSCALE ); - + type_select->set_pos(Point2(400, 25) * EDSCALE); + type_select->set_size(Point2(80, 5) * EDSCALE); add_del_dialog->add_child(type_select); - add_del_dialog->get_ok()->connect("pressed", this,"_dialog_cbk"); - + add_del_dialog->get_ok()->connect("pressed", this, "_dialog_cbk"); - file_dialog = memnew( EditorFileDialog ); + file_dialog = memnew(EditorFileDialog); file_dialog->add_filter("*.theme ; Theme File"); add_child(file_dialog); - file_dialog->connect("file_selected",this,"_save_template_cbk"); + file_dialog->connect("file_selected", this, "_save_template_cbk"); //MenuButton *name_menu; //LineEdit *name_edit; - } void ThemeEditorPlugin::edit(Object *p_node) { if (p_node && p_node->cast_to<Theme>()) { theme_editor->show(); - theme_editor->edit( p_node->cast_to<Theme>() ); + theme_editor->edit(p_node->cast_to<Theme>()); } else { - theme_editor->edit( Ref<Theme>() ); + theme_editor->edit(Ref<Theme>()); theme_editor->hide(); } } -bool ThemeEditorPlugin::handles(Object *p_node) const{ +bool ThemeEditorPlugin::handles(Object *p_node) const { return p_node->is_class("Theme"); } -void ThemeEditorPlugin::make_visible(bool p_visible){ +void ThemeEditorPlugin::make_visible(bool p_visible) { if (p_visible) { theme_editor->set_process(true); @@ -984,14 +929,11 @@ void ThemeEditorPlugin::make_visible(bool p_visible){ ThemeEditorPlugin::ThemeEditorPlugin(EditorNode *p_node) { - editor=p_node; - theme_editor = memnew( ThemeEditor ); - theme_editor->set_custom_minimum_size(Size2(0,200)); + editor = p_node; + theme_editor = memnew(ThemeEditor); + theme_editor->set_custom_minimum_size(Size2(0, 200)); //p_node->get_viewport()->add_child(theme_editor); - button=editor->add_bottom_panel_item("Theme",theme_editor); + button = editor->add_bottom_panel_item("Theme", theme_editor); button->hide(); - - } - diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index f661da4cd5..3881cf1a41 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -29,23 +29,19 @@ #ifndef THEME_EDITOR_PLUGIN_H #define THEME_EDITOR_PLUGIN_H -#include "scene/resources/theme.h" -#include "scene/gui/texture_rect.h" -#include "scene/gui/option_button.h" -#include "scene/gui/file_dialog.h" -#include "scene/gui/check_box.h" #include "scene/gui/button_group.h" +#include "scene/gui/check_box.h" +#include "scene/gui/file_dialog.h" +#include "scene/gui/option_button.h" #include "scene/gui/scroll_container.h" +#include "scene/gui/texture_rect.h" +#include "scene/resources/theme.h" #include "editor/editor_node.h" - - - class ThemeEditor : public Control { - GDCLASS( ThemeEditor, Control ); - + GDCLASS(ThemeEditor, Control); ScrollContainer *scroll; VBoxContainer *main_vb; @@ -62,9 +58,9 @@ class ThemeEditor : public Control { MenuButton *name_menu; LineEdit *name_edit; OptionButton *type_select; - Label * type_select_label; - Label * name_select_label; - Label * dtype_select_label; + Label *type_select_label; + Label *name_select_label; + Label *dtype_select_label; enum PopupMode { POPUP_ADD, @@ -88,29 +84,25 @@ class ThemeEditor : public Control { void _propagate_redraw(Control *p_at); void _refresh_interval(); - protected: void _notification(int p_what); static void _bind_methods(); -public: - void edit(const Ref<Theme>& p_theme); +public: + void edit(const Ref<Theme> &p_theme); ThemeEditor(); }; - - class ThemeEditorPlugin : public EditorPlugin { - GDCLASS( ThemeEditorPlugin, EditorPlugin ); + GDCLASS(ThemeEditorPlugin, EditorPlugin); ThemeEditor *theme_editor; EditorNode *editor; Button *button; public: - virtual String get_name() const { return "Theme"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -118,8 +110,6 @@ public: virtual void make_visible(bool p_visible); ThemeEditorPlugin(EditorNode *p_node); - }; - #endif // THEME_EDITOR_PLUGIN_H diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index fb6d5a786a..8cda9848bd 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -28,25 +28,25 @@ /*************************************************************************/ #include "tile_map_editor_plugin.h" -#include "os/keyboard.h" -#include "os/input.h" #include "canvas_item_editor_plugin.h" -#include "editor/editor_settings.h" #include "editor/editor_scale.h" +#include "editor/editor_settings.h" +#include "os/input.h" +#include "os/keyboard.h" void TileMapEditor::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_ENTER_TREE: { - transp->set_icon(get_icon("Transpose","EditorIcons")); - mirror_x->set_icon(get_icon("MirrorX","EditorIcons")); - mirror_y->set_icon(get_icon("MirrorY","EditorIcons")); - rotate_0->set_icon(get_icon("Rotate0","EditorIcons")); - rotate_90->set_icon(get_icon("Rotate90","EditorIcons")); - rotate_180->set_icon(get_icon("Rotate180","EditorIcons")); - rotate_270->set_icon(get_icon("Rotate270","EditorIcons")); + transp->set_icon(get_icon("Transpose", "EditorIcons")); + mirror_x->set_icon(get_icon("MirrorX", "EditorIcons")); + mirror_y->set_icon(get_icon("MirrorY", "EditorIcons")); + rotate_0->set_icon(get_icon("Rotate0", "EditorIcons")); + rotate_90->set_icon(get_icon("Rotate90", "EditorIcons")); + rotate_180->set_icon(get_icon("Rotate180", "EditorIcons")); + rotate_270->set_icon(get_icon("Rotate270", "EditorIcons")); } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { @@ -60,24 +60,24 @@ void TileMapEditor::_notification(int p_what) { void TileMapEditor::_menu_option(int p_option) { - switch(p_option) { + switch (p_option) { case OPTION_BUCKET: { - tool=TOOL_BUCKET; + tool = TOOL_BUCKET; canvas_item_editor->update(); } break; case OPTION_PICK_TILE: { - tool=TOOL_PICKING; + tool = TOOL_PICKING; canvas_item_editor->update(); } break; case OPTION_SELECT: { - tool=TOOL_SELECTING; - selection_active=false; + tool = TOOL_SELECTING; + selection_active = false; canvas_item_editor->update(); } break; @@ -86,7 +86,7 @@ void TileMapEditor::_menu_option(int p_option) { _update_copydata(); if (selection_active) { - tool=TOOL_DUPLICATING; + tool = TOOL_DUPLICATING; canvas_item_editor->update(); } @@ -97,15 +97,15 @@ void TileMapEditor::_menu_option(int p_option) { return; undo_redo->create_action("Erase Selection"); - for (int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) { - for (int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) { + for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { + for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { _set_cell(Point2i(j, i), TileMap::INVALID_CELL, false, false, false, true); } } undo_redo->commit_action(); - selection_active=false; + selection_active = false; copydata.clear(); canvas_item_editor->update(); @@ -113,15 +113,15 @@ void TileMapEditor::_menu_option(int p_option) { } } -void TileMapEditor::_canvas_mouse_enter() { +void TileMapEditor::_canvas_mouse_enter() { - mouse_over=true; + mouse_over = true; canvas_item_editor->update(); } -void TileMapEditor::_canvas_mouse_exit() { +void TileMapEditor::_canvas_mouse_exit() { - mouse_over=false; + mouse_over = false; canvas_item_editor->update(); } @@ -129,7 +129,7 @@ int TileMapEditor::get_selected_tile() const { int item = palette->get_current(); - if (item==-1) + if (item == -1) return TileMap::INVALID_CELL; return palette->get_item_metadata(item); @@ -145,47 +145,45 @@ void TileMapEditor::set_selected_tile(int p_tile) { } } -void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bool p_flip_v, bool p_transpose,bool p_with_undo) { +void TileMapEditor::_set_cell(const Point2i &p_pos, int p_value, bool p_flip_h, bool p_flip_v, bool p_transpose, bool p_with_undo) { ERR_FAIL_COND(!node); - int prev_val=node->get_cell(p_pos.x,p_pos.y); + int prev_val = node->get_cell(p_pos.x, p_pos.y); - bool prev_flip_h=node->is_cell_x_flipped(p_pos.x,p_pos.y); - bool prev_flip_v=node->is_cell_y_flipped(p_pos.x,p_pos.y); - bool prev_transpose=node->is_cell_transposed(p_pos.x,p_pos.y); + bool prev_flip_h = node->is_cell_x_flipped(p_pos.x, p_pos.y); + bool prev_flip_v = node->is_cell_y_flipped(p_pos.x, p_pos.y); + bool prev_transpose = node->is_cell_transposed(p_pos.x, p_pos.y); - if (p_value==prev_val && p_flip_h==prev_flip_h && p_flip_v==prev_flip_v && p_transpose==prev_transpose) + if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose) return; //check that it's actually different if (p_with_undo) { - undo_redo->add_do_method(node,"set_cellv",Point2(p_pos),p_value,p_flip_h,p_flip_v,p_transpose); - undo_redo->add_undo_method(node,"set_cellv",Point2(p_pos),prev_val,prev_flip_h,prev_flip_v,prev_transpose); + undo_redo->add_do_method(node, "set_cellv", Point2(p_pos), p_value, p_flip_h, p_flip_v, p_transpose); + undo_redo->add_undo_method(node, "set_cellv", Point2(p_pos), prev_val, prev_flip_h, prev_flip_v, prev_transpose); } else { - node->set_cell(p_pos.x,p_pos.y,p_value,p_flip_h,p_flip_v,p_transpose); + node->set_cell(p_pos.x, p_pos.y, p_value, p_flip_h, p_flip_v, p_transpose); } - } -void TileMapEditor::_text_entered(const String& p_text) { +void TileMapEditor::_text_entered(const String &p_text) { canvas_item_editor->grab_focus(); } -void TileMapEditor::_text_changed(const String& p_text) { +void TileMapEditor::_text_changed(const String &p_text) { _update_palette(); } -void TileMapEditor::_sbox_input(const InputEvent& p_ie) { +void TileMapEditor::_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)) { palette->call("_gui_input", p_ie); search_box->accept_event(); @@ -200,7 +198,7 @@ void TileMapEditor::_update_palette() { int selected = get_selected_tile(); palette->clear(); - Ref<TileSet> tileset=node->get_tileset(); + Ref<TileSet> tileset = node->get_tileset(); if (tileset.is_null()) return; @@ -212,25 +210,25 @@ void TileMapEditor::_update_palette() { float min_size = EDITOR_DEF("editors/tile_map/preview_size", 64); min_size *= EDSCALE; - int hseparation = EDITOR_DEF("editors/tile_map/palette_item_hseparation",8); + int hseparation = EDITOR_DEF("editors/tile_map/palette_item_hseparation", 8); bool show_tile_names = bool(EDITOR_DEF("editors/tile_map/show_tile_names", true)); - palette->add_constant_override("hseparation", hseparation*EDSCALE); - palette->add_constant_override("vseparation", 8*EDSCALE); + palette->add_constant_override("hseparation", hseparation * EDSCALE); + palette->add_constant_override("vseparation", 8 * EDSCALE); palette->set_fixed_icon_size(Size2(min_size, min_size)); palette->set_fixed_column_width(min_size * MAX(size_slider->get_value(), 1)); String filter = search_box->get_text().strip_edges(); - for (List<int>::Element *E=tiles.front();E;E=E->next()) { + for (List<int>::Element *E = tiles.front(); E; E = E->next()) { String name; - if (tileset->tile_get_name(E->get())!="") { - name = itos(E->get())+" - "+tileset->tile_get_name(E->get()); + if (tileset->tile_get_name(E->get()) != "") { + name = itos(E->get()) + " - " + tileset->tile_get_name(E->get()); } else { - name = "#"+itos(E->get()); + name = "#" + itos(E->get()); } if (filter != "" && !filter.is_subsequence_ofi(name)) @@ -248,14 +246,14 @@ void TileMapEditor::_update_palette() { Rect2 region = tileset->tile_get_region(E->get()); if (!region.has_no_area()) - palette->set_item_icon_region(palette->get_item_count()-1, region); + palette->set_item_icon_region(palette->get_item_count() - 1, region); - palette->set_item_icon(palette->get_item_count()-1, tex); + palette->set_item_icon(palette->get_item_count() - 1, tex); } - palette->set_item_metadata(palette->get_item_count()-1, E->get()); + palette->set_item_metadata(palette->get_item_count() - 1, E->get()); } - + palette->set_same_column_width(true); if (selected != -1) @@ -264,11 +262,11 @@ void TileMapEditor::_update_palette() { palette->select(0); } -void TileMapEditor::_pick_tile(const Point2& p_pos) { +void TileMapEditor::_pick_tile(const Point2 &p_pos) { int id = node->get_cell(p_pos.x, p_pos.y); - if (id==TileMap::INVALID_CELL) + if (id == TileMap::INVALID_CELL) return; if (search_box->get_text().strip_edges() != "") { @@ -287,7 +285,7 @@ void TileMapEditor::_pick_tile(const Point2& p_pos) { canvas_item_editor->update(); } -PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i& p_start, bool erase, bool preview) { +PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bool preview) { int prev_id = node->get_cell(p_start.x, p_start.y); int id = TileMap::INVALID_CELL; @@ -299,34 +297,33 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i& p_start, bool era } Rect2i r = node->get_item_rect(); - r.pos = r.pos/node->get_cell_size(); - r.size = r.size/node->get_cell_size(); + r.pos = r.pos / node->get_cell_size(); + r.size = r.size / node->get_cell_size(); int area = r.get_area(); - if(preview) { + if (preview) { // Test if we can re-use the result from preview bucket fill bool invalidate_cache = false; // Area changed - if(r != bucket_cache_rect) + if (r != bucket_cache_rect) _clear_bucket_cache(); // Cache grid is not initialized - if(bucket_cache_visited == 0) { + if (bucket_cache_visited == 0) { bucket_cache_visited = new bool[area]; invalidate_cache = true; } // Tile ID changed or position wasn't visited by the previous fill int loc = (p_start.x - r.get_pos().x) + (p_start.y - r.get_pos().y) * r.get_size().x; - if(prev_id != bucket_cache_tile || !bucket_cache_visited[loc]) { + if (prev_id != bucket_cache_tile || !bucket_cache_visited[loc]) { invalidate_cache = true; } - if(invalidate_cache) { - for(int i = 0; i < area; ++i) + if (invalidate_cache) { + for (int i = 0; i < area; ++i) bucket_cache_visited[i] = false; bucket_cache = PoolVector<Vector2>(); bucket_cache_tile = prev_id; bucket_cache_rect = r; - } - else { + } else { return bucket_cache; } } @@ -346,14 +343,13 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i& p_start, bool era if (node->get_cell(n.x, n.y) == prev_id) { - if(preview) { + if (preview) { int loc = (n.x - r.get_pos().x) + (n.y - r.get_pos().y) * r.get_size().x; - if(bucket_cache_visited[loc]) + if (bucket_cache_visited[loc]) continue; bucket_cache_visited[loc] = true; bucket_cache.push_back(n); - } - else { + } else { node->set_cellv(n, id, flip_h, flip_v, transpose); points.push_back(n); } @@ -368,7 +364,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i& p_start, bool era return preview ? bucket_cache : points; } -void TileMapEditor::_fill_points(const PoolVector<Vector2> p_points, const Dictionary& p_op) { +void TileMapEditor::_fill_points(const PoolVector<Vector2> p_points, const Dictionary &p_op) { int len = p_points.size(); PoolVector<Vector2>::Read pr = p_points.read(); @@ -378,7 +374,7 @@ void TileMapEditor::_fill_points(const PoolVector<Vector2> p_points, const Dicti bool yf = p_op["flip_v"]; bool tr = p_op["transpose"]; - for (int i=0;i<len;i++) { + for (int i = 0; i < len; i++) { _set_cell(pr[i], id, xf, yf, tr); } @@ -389,33 +385,33 @@ void TileMapEditor::_erase_points(const PoolVector<Vector2> p_points) { int len = p_points.size(); PoolVector<Vector2>::Read pr = p_points.read(); - for (int i=0;i<len;i++) { + for (int i = 0; i < len; i++) { _set_cell(pr[i], TileMap::INVALID_CELL); } } -void TileMapEditor::_select(const Point2i& p_from, const Point2i& p_to) { +void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { - Point2i begin=p_from; - Point2i end=p_to; + Point2i begin = p_from; + Point2i end = p_to; if (begin.x > end.x) { - SWAP( begin.x, end.x); + SWAP(begin.x, end.x); } if (begin.y > end.y) { - SWAP( begin.y, end.y); + SWAP(begin.y, end.y); } - rectangle.pos=begin; - rectangle.size=end-begin; + rectangle.pos = begin; + rectangle.size = end - begin; canvas_item_editor->update(); } -void TileMapEditor::_draw_cell(int p_cell, const Point2i& p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D& p_xform) { +void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform) { Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell); @@ -448,75 +444,74 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i& p_point, bool p_flip_h SWAP(tile_ofs.x, tile_ofs.y); } if (p_flip_h) { - sc.x*=-1.0; - tile_ofs.x*=-1.0; + sc.x *= -1.0; + tile_ofs.x *= -1.0; } if (p_flip_v) { - sc.y*=-1.0; - tile_ofs.y*=-1.0; + sc.y *= -1.0; + tile_ofs.y *= -1.0; } - if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) { + if (node->get_tile_origin() == TileMap::TILE_ORIGIN_TOP_LEFT) { - rect.pos+=tile_ofs; - } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_BOTTOM_LEFT) { + rect.pos += tile_ofs; + } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_BOTTOM_LEFT) { Size2 cell_size = node->get_cell_size(); - - rect.pos+=tile_ofs; - - if(p_transpose) - { - if(p_flip_h) - rect.pos.x-=cell_size.x; + + rect.pos += tile_ofs; + + if (p_transpose) { + if (p_flip_h) + rect.pos.x -= cell_size.x; else - rect.pos.x+=cell_size.x; + rect.pos.x += cell_size.x; } else { - if(p_flip_v) - rect.pos.y-=cell_size.y; + if (p_flip_v) + rect.pos.y -= cell_size.y; else - rect.pos.y+=cell_size.y; + rect.pos.y += cell_size.y; } - } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_CENTER) { - rect.pos+=node->get_cell_size()/2; + } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) { + rect.pos += node->get_cell_size() / 2; Vector2 s = r.size; - Vector2 center = (s/2) - tile_ofs; + Vector2 center = (s / 2) - tile_ofs; if (p_flip_h) - rect.pos.x-=s.x-center.x; + rect.pos.x -= s.x - center.x; else - rect.pos.x-=center.x; + rect.pos.x -= center.x; if (p_flip_v) - rect.pos.y-=s.y-center.y; + rect.pos.y -= s.y - center.y; else - rect.pos.y-=center.y; + rect.pos.y -= center.y; } - rect.pos=p_xform.xform(rect.pos); - rect.size*=sc; + rect.pos = p_xform.xform(rect.pos); + rect.size *= sc; if (r.has_no_area()) - canvas_item_editor->draw_texture_rect(t, rect, false, Color(1,1,1,0.5), p_transpose); + canvas_item_editor->draw_texture_rect(t, rect, false, Color(1, 1, 1, 0.5), p_transpose); else - canvas_item_editor->draw_texture_rect_region(t, rect, r, Color(1,1,1,0.5), p_transpose); + canvas_item_editor->draw_texture_rect_region(t, rect, r, Color(1, 1, 1, 0.5), p_transpose); } -void TileMapEditor::_draw_fill_preview(int p_cell, const Point2i& p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D& p_xform) { +void TileMapEditor::_draw_fill_preview(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform) { PoolVector<Vector2> points = _bucket_fill(p_point, false, true); PoolVector<Vector2>::Read pr = points.read(); int len = points.size(); int time_after = OS::get_singleton()->get_ticks_msec(); - for(int i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { _draw_cell(p_cell, pr[i], p_flip_h, p_flip_v, p_transpose, p_xform); } } void TileMapEditor::_clear_bucket_cache() { - if(bucket_cache_visited) { + if (bucket_cache_visited) { delete[] bucket_cache_visited; bucket_cache_visited = 0; } @@ -529,19 +524,19 @@ void TileMapEditor::_update_copydata() { if (!selection_active) return; - for (int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) { + for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) { + for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { TileData tcd; - tcd.cell=node->get_cell(j, i); + tcd.cell = node->get_cell(j, i); - if (tcd.cell!=TileMap::INVALID_CELL) { - tcd.pos=Point2i(j, i); - tcd.flip_h=node->is_cell_x_flipped(j,i); - tcd.flip_v=node->is_cell_y_flipped(j,i); - tcd.transpose=node->is_cell_transposed(j,i); + if (tcd.cell != TileMap::INVALID_CELL) { + tcd.pos = Point2i(j, i); + tcd.flip_h = node->is_cell_x_flipped(j, i); + tcd.flip_v = node->is_cell_y_flipped(j, i); + tcd.transpose = node->is_cell_transposed(j, i); } copydata.push_back(tcd); @@ -563,7 +558,7 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { int sy = y0 > y1 ? -1 : 1; if (dx > dy) { - float err = dx/2; + float err = dx / 2; for (; x != x1; x += sx) { points.push_back(Vector2(x, y)); @@ -575,7 +570,7 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { } } } else { - float err = dy/2; + float err = dy / 2; for (; y != y1; y += sy) { points.push_back(Vector2(x, y)); @@ -593,7 +588,7 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { return points; } -bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { +bool TileMapEditor::forward_gui_input(const InputEvent &p_event) { if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree()) return false; @@ -601,98 +596,98 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); Transform2D xform_inv = xform.affine_inverse(); - 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; - if (mb.button_index==BUTTON_LEFT) { + if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) return false; //drag - if (tool==TOOL_NONE) { + if (tool == TOOL_NONE) { if (mb.mod.shift) { if (mb.mod.control) - tool=TOOL_RECTANGLE_PAINT; + tool = TOOL_RECTANGLE_PAINT; else - tool=TOOL_LINE_PAINT; + tool = TOOL_LINE_PAINT; - selection_active=false; - rectangle_begin=over_tile; + selection_active = false; + rectangle_begin = over_tile; return true; } if (mb.mod.control) { - tool=TOOL_PICKING; + tool = TOOL_PICKING; _pick_tile(over_tile); return true; } - tool=TOOL_PAINTING; + tool = TOOL_PAINTING; } - if (tool==TOOL_PAINTING) { + if (tool == TOOL_PAINTING) { int id = get_selected_tile(); - if (id!=TileMap::INVALID_CELL) { + if (id != TileMap::INVALID_CELL) { - tool=TOOL_PAINTING; + tool = TOOL_PAINTING; paint_undo.clear(); - paint_undo[over_tile]=_get_op_from_cell(over_tile); + paint_undo[over_tile] = _get_op_from_cell(over_tile); _set_cell(over_tile, id, flip_h, flip_v, transpose); } - } else if (tool==TOOL_PICKING) { + } else if (tool == TOOL_PICKING) { _pick_tile(over_tile); - } else if (tool==TOOL_SELECTING) { + } else if (tool == TOOL_SELECTING) { - selection_active=true; - rectangle_begin=over_tile; + selection_active = true; + rectangle_begin = over_tile; } return true; } else { - if (tool!=TOOL_NONE) { + if (tool != TOOL_NONE) { - if (tool==TOOL_PAINTING) { + if (tool == TOOL_PAINTING) { - int id=get_selected_tile(); + int id = get_selected_tile(); - if (id!=TileMap::INVALID_CELL && paint_undo.size()) { + if (id != TileMap::INVALID_CELL && paint_undo.size()) { undo_redo->create_action(TTR("Paint TileMap")); - for (Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) { + for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { - Point2 p=E->key(); - undo_redo->add_do_method(node,"set_cellv",p,id,flip_h,flip_v,transpose); - undo_redo->add_undo_method(node,"set_cellv",p,E->get().idx,E->get().xf,E->get().yf,E->get().tr); + Point2 p = E->key(); + undo_redo->add_do_method(node, "set_cellv", p, id, flip_h, flip_v, transpose); + undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr); } undo_redo->commit_action(); paint_undo.clear(); } - } else if (tool==TOOL_LINE_PAINT) { + } else if (tool == TOOL_LINE_PAINT) { - int id=get_selected_tile(); + int id = get_selected_tile(); - if (id!=TileMap::INVALID_CELL) { + if (id != TileMap::INVALID_CELL) { undo_redo->create_action("Line Draw"); - for (Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) { + for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { _set_cell(E->key(), id, flip_h, flip_v, transpose, true); } @@ -702,15 +697,15 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { canvas_item_editor->update(); } - } else if (tool==TOOL_RECTANGLE_PAINT) { + } else if (tool == TOOL_RECTANGLE_PAINT) { - int id=get_selected_tile(); + int id = get_selected_tile(); - if (id!=TileMap::INVALID_CELL) { + if (id != TileMap::INVALID_CELL) { undo_redo->create_action("Rectangle Paint"); - for (int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) { - for (int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) { + for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { + for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { _set_cell(Point2i(j, i), id, flip_h, flip_v, transpose, true); } @@ -719,14 +714,14 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { canvas_item_editor->update(); } - } else if (tool==TOOL_DUPLICATING) { + } else if (tool == TOOL_DUPLICATING) { - Point2 ofs = over_tile-rectangle.pos; + Point2 ofs = over_tile - rectangle.pos; undo_redo->create_action(TTR("Duplicate")); - for (List<TileData>::Element *E=copydata.front();E;E=E->next()) { + for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { - _set_cell(E->get().pos+ofs,E->get().cell,E->get().flip_h,E->get().flip_v,E->get().transpose,true); + _set_cell(E->get().pos + ofs, E->get().cell, E->get().flip_h, E->get().flip_v, E->get().transpose, true); } undo_redo->commit_action(); @@ -734,11 +729,11 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { canvas_item_editor->update(); - } else if (tool==TOOL_SELECTING) { + } else if (tool == TOOL_SELECTING) { canvas_item_editor->update(); - } else if (tool==TOOL_BUCKET) { + } else if (tool == TOOL_BUCKET) { Dictionary pop; pop["id"] = node->get_cell(over_tile.x, over_tile.y); @@ -765,28 +760,28 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { undo_redo->commit_action(); } - tool=TOOL_NONE; + tool = TOOL_NONE; return true; } } - } else if (mb.button_index==BUTTON_RIGHT) { + } else if (mb.button_index == BUTTON_RIGHT) { if (mb.pressed) { - if (tool==TOOL_SELECTING || selection_active) { + if (tool == TOOL_SELECTING || selection_active) { - tool=TOOL_NONE; - selection_active=false; + tool = TOOL_NONE; + selection_active = false; canvas_item_editor->update(); return true; } - if (tool==TOOL_DUPLICATING) { + if (tool == TOOL_DUPLICATING) { - tool=TOOL_NONE; + tool = TOOL_NONE; copydata.clear(); canvas_item_editor->update(); @@ -794,7 +789,7 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { return true; } - if (tool==TOOL_NONE) { + if (tool == TOOL_NONE) { paint_undo.clear(); @@ -803,17 +798,17 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { if (mb.mod.shift) { if (mb.mod.control) - tool=TOOL_RECTANGLE_ERASE; + tool = TOOL_RECTANGLE_ERASE; else - tool=TOOL_LINE_ERASE; + tool = TOOL_LINE_ERASE; - selection_active=false; - rectangle_begin=local; + selection_active = false; + rectangle_begin = local; } else { - tool=TOOL_ERASING; + tool = TOOL_ERASING; - paint_undo[local]=_get_op_from_cell(local); + paint_undo[local] = _get_op_from_cell(local); _set_cell(local, TileMap::INVALID_CELL); } @@ -821,30 +816,30 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { } } else { - if (tool==TOOL_ERASING || tool==TOOL_RECTANGLE_ERASE || tool==TOOL_LINE_ERASE) { + if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { if (paint_undo.size()) { undo_redo->create_action(TTR("Erase TileMap")); - for (Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) { + for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { - Point2 p=E->key(); - undo_redo->add_do_method(node,"set_cellv",p,TileMap::INVALID_CELL,false,false,false); - undo_redo->add_undo_method(node,"set_cellv",p,E->get().idx,E->get().xf,E->get().yf,E->get().tr); + Point2 p = E->key(); + undo_redo->add_do_method(node, "set_cellv", p, TileMap::INVALID_CELL, false, false, false); + undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr); } undo_redo->commit_action(); paint_undo.clear(); } - if (tool==TOOL_RECTANGLE_ERASE || tool==TOOL_LINE_ERASE) { + if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { canvas_item_editor->update(); } - tool=TOOL_NONE; + tool = TOOL_NONE; return true; - } else if (tool==TOOL_BUCKET) { + } else if (tool == TOOL_BUCKET) { Dictionary pop; pop["id"] = node->get_cell(over_tile.x, over_tile.y); @@ -869,13 +864,13 @@ bool TileMapEditor::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; - Point2i new_over_tile = node->world_to_map(xform_inv.xform(Point2(mm.x,mm.y))); + Point2i new_over_tile = node->world_to_map(xform_inv.xform(Point2(mm.x, mm.y))); - if (new_over_tile!=over_tile) { + if (new_over_tile != over_tile) { - over_tile=new_over_tile; + over_tile = new_over_tile; canvas_item_editor->update(); } @@ -884,15 +879,15 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { if (node->get_tileset()->has_tile(tile_under)) tile_name = node->get_tileset()->tile_get_name(tile_under); - tile_info->set_text(String::num(over_tile.x)+", "+String::num(over_tile.y)+" ["+tile_name+"]"); + tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]"); - if (tool==TOOL_PAINTING) { + if (tool == TOOL_PAINTING) { int id = get_selected_tile(); - if (id!=TileMap::INVALID_CELL) { + if (id != TileMap::INVALID_CELL) { if (!paint_undo.has(over_tile)) { - paint_undo[over_tile]=_get_op_from_cell(over_tile); + paint_undo[over_tile] = _get_op_from_cell(over_tile); } _set_cell(over_tile, id, flip_h, flip_v, transpose); @@ -901,21 +896,21 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { } } - if (tool==TOOL_SELECTING) { + if (tool == TOOL_SELECTING) { _select(rectangle_begin, over_tile); return true; } - if (tool==TOOL_LINE_PAINT || tool==TOOL_LINE_ERASE) { + if (tool == TOOL_LINE_PAINT || tool == TOOL_LINE_ERASE) { int id = get_selected_tile(); - bool erasing = (tool==TOOL_LINE_ERASE); + bool erasing = (tool == TOOL_LINE_ERASE); if (erasing && paint_undo.size()) { - for (Map<Point2i, CellOp>::Element *E=paint_undo.front();E;E=E->next()) { + for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { _set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr); } @@ -923,13 +918,13 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { paint_undo.clear(); - if (id!=TileMap::INVALID_CELL) { + if (id != TileMap::INVALID_CELL) { Vector<Point2i> points = line(rectangle_begin.x, over_tile.x, rectangle_begin.y, over_tile.y); - for (int i=0;i<points.size();i++) { + for (int i = 0; i < points.size(); i++) { - paint_undo[points[i]]=_get_op_from_cell(points[i]); + paint_undo[points[i]] = _get_op_from_cell(points[i]); if (erasing) _set_cell(points[i], TileMap::INVALID_CELL); @@ -940,15 +935,15 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { return true; } - if (tool==TOOL_RECTANGLE_PAINT || tool==TOOL_RECTANGLE_ERASE) { + if (tool == TOOL_RECTANGLE_PAINT || tool == TOOL_RECTANGLE_ERASE) { _select(rectangle_begin, over_tile); - if (tool==TOOL_RECTANGLE_ERASE) { + if (tool == TOOL_RECTANGLE_ERASE) { if (paint_undo.size()) { - for (Map<Point2i, CellOp>::Element *E=paint_undo.front();E;E=E->next()) { + for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { _set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr); } @@ -956,11 +951,11 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { paint_undo.clear(); - for (int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) { - for (int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) { + for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { + for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { Point2i tile = Point2i(j, i); - paint_undo[tile]=_get_op_from_cell(tile); + paint_undo[tile] = _get_op_from_cell(tile); _set_cell(tile, TileMap::INVALID_CELL); } @@ -969,17 +964,17 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { return true; } - if (tool==TOOL_ERASING) { + if (tool == TOOL_ERASING) { if (!paint_undo.has(over_tile)) { - paint_undo[over_tile]=_get_op_from_cell(over_tile); + paint_undo[over_tile] = _get_op_from_cell(over_tile); } _set_cell(over_tile, TileMap::INVALID_CELL); return true; } - if (tool==TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { _pick_tile(over_tile); @@ -993,21 +988,21 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { if (!k.pressed) break; - if (k.scancode==KEY_ESCAPE) { + if (k.scancode == KEY_ESCAPE) { - if (tool==TOOL_DUPLICATING) + if (tool == TOOL_DUPLICATING) copydata.clear(); - else if (tool==TOOL_SELECTING || selection_active) - selection_active=false; + else if (tool == TOOL_SELECTING || selection_active) + selection_active = false; - tool=TOOL_NONE; + tool = TOOL_NONE; canvas_item_editor->update(); return true; } - if (tool!=TOOL_NONE || !mouse_over) + if (tool != TOOL_NONE || !mouse_over) return false; if (ED_IS_SHORTCUT("tile_map_editor/erase_selection", p_event)) { @@ -1016,8 +1011,8 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { return true; } if (ED_IS_SHORTCUT("tile_map_editor/select", p_event)) { - tool=TOOL_SELECTING; - selection_active=false; + tool = TOOL_SELECTING; + selection_active = false; canvas_item_editor->update(); @@ -1027,7 +1022,7 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { _update_copydata(); if (selection_active) { - tool=TOOL_DUPLICATING; + tool = TOOL_DUPLICATING; canvas_item_editor->update(); @@ -1041,13 +1036,13 @@ bool TileMapEditor::forward_gui_input(const InputEvent& p_event) { return true; } if (ED_IS_SHORTCUT("tile_map_editor/mirror_x", p_event)) { - flip_h=!flip_h; + flip_h = !flip_h; mirror_x->set_pressed(flip_h); canvas_item_editor->update(); return true; } if (ED_IS_SHORTCUT("tile_map_editor/mirror_y", p_event)) { - flip_v=!flip_v; + flip_v = !flip_v; mirror_y->set_pressed(flip_v); canvas_item_editor->update(); return true; @@ -1074,92 +1069,86 @@ void TileMapEditor::_canvas_draw() { Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); Transform2D xform_inv = xform.affine_inverse(); - - Size2 screen_size=canvas_item_editor->get_size(); + Size2 screen_size = canvas_item_editor->get_size(); { Rect2 aabb; - aabb.pos=node->world_to_map(xform_inv.xform(Vector2())); - aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(0,screen_size.height)))); - aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(screen_size.width,0)))); + aabb.pos = node->world_to_map(xform_inv.xform(Vector2())); + aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(0, screen_size.height)))); + aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(screen_size.width, 0)))); aabb.expand_to(node->world_to_map(xform_inv.xform(screen_size))); - Rect2i si=aabb.grow(1.0); + Rect2i si = aabb.grow(1.0); - if (node->get_half_offset()!=TileMap::HALF_OFFSET_X) { + if (node->get_half_offset() != TileMap::HALF_OFFSET_X) { - int max_lines=2000; //avoid crash if size too smal + int max_lines = 2000; //avoid crash if size too smal - for (int i=(si.pos.x)-1;i<=(si.pos.x+si.size.x);i++) { + for (int i = (si.pos.x) - 1; i <= (si.pos.x + si.size.x); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(i,si.pos.y))); - Vector2 to = xform.xform(node->map_to_world(Vector2(i,si.pos.y+si.size.y+1))); + Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.pos.y))); + Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.pos.y + si.size.y + 1))); - Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2); - canvas_item_editor->draw_line(from,to,col,1); - if (max_lines--==0) + Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); + canvas_item_editor->draw_line(from, to, col, 1); + if (max_lines-- == 0) break; } } else { - int max_lines=10000; //avoid crash if size too smal + int max_lines = 10000; //avoid crash if size too smal - for (int i=(si.pos.x)-1;i<=(si.pos.x+si.size.x);i++) { + for (int i = (si.pos.x) - 1; i <= (si.pos.x + si.size.x); i++) { - for (int j=(si.pos.y)-1;j<=(si.pos.y+si.size.y);j++) { + for (int j = (si.pos.y) - 1; j <= (si.pos.y + si.size.y); j++) { Vector2 ofs; - if (ABS(j)&1) { - ofs=cell_xf[0]*0.5; + if (ABS(j) & 1) { + ofs = cell_xf[0] * 0.5; } - Vector2 from = xform.xform(node->map_to_world(Vector2(i,j),true)+ofs); - Vector2 to = xform.xform(node->map_to_world(Vector2(i,j+1),true)+ofs); - Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2); - canvas_item_editor->draw_line(from,to,col,1); + Vector2 from = xform.xform(node->map_to_world(Vector2(i, j), true) + ofs); + Vector2 to = xform.xform(node->map_to_world(Vector2(i, j + 1), true) + ofs); + Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); + canvas_item_editor->draw_line(from, to, col, 1); - if (max_lines--==0) + if (max_lines-- == 0) break; - } - } } - int max_lines=10000; //avoid crash if size too smal + int max_lines = 10000; //avoid crash if size too smal - if (node->get_half_offset()!=TileMap::HALF_OFFSET_Y) { + if (node->get_half_offset() != TileMap::HALF_OFFSET_Y) { - for (int i=(si.pos.y)-1;i<=(si.pos.y+si.size.y);i++) { + for (int i = (si.pos.y) - 1; i <= (si.pos.y + si.size.y); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(si.pos.x,i))); - Vector2 to = xform.xform(node->map_to_world(Vector2(si.pos.x+si.size.x+1,i))); + Vector2 from = xform.xform(node->map_to_world(Vector2(si.pos.x, i))); + Vector2 to = xform.xform(node->map_to_world(Vector2(si.pos.x + si.size.x + 1, i))); - Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2); - canvas_item_editor->draw_line(from,to,col,1); + Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); + canvas_item_editor->draw_line(from, to, col, 1); - if (max_lines--==0) + if (max_lines-- == 0) break; - } } else { + for (int i = (si.pos.y) - 1; i <= (si.pos.y + si.size.y); i++) { - for (int i=(si.pos.y)-1;i<=(si.pos.y+si.size.y);i++) { - - for (int j=(si.pos.x)-1;j<=(si.pos.x+si.size.x);j++) { + for (int j = (si.pos.x) - 1; j <= (si.pos.x + si.size.x); j++) { Vector2 ofs; - if (ABS(j)&1) { - ofs=cell_xf[1]*0.5; + if (ABS(j) & 1) { + ofs = cell_xf[1] * 0.5; } - Vector2 from = xform.xform(node->map_to_world(Vector2(j,i),true)+ofs); - Vector2 to = xform.xform(node->map_to_world(Vector2(j+1,i),true)+ofs); - Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2); - canvas_item_editor->draw_line(from,to,col,1); + Vector2 from = xform.xform(node->map_to_world(Vector2(j, i), true) + ofs); + Vector2 to = xform.xform(node->map_to_world(Vector2(j + 1, i), true) + ofs); + Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); + canvas_item_editor->draw_line(from, to, col, 1); - if (max_lines--==0) + if (max_lines-- == 0) break; - } } } @@ -1168,74 +1157,73 @@ void TileMapEditor::_canvas_draw() { if (selection_active) { Vector<Vector2> points; - points.push_back( xform.xform( node->map_to_world(( rectangle.pos ) ))); - points.push_back( xform.xform( node->map_to_world((rectangle.pos+Point2(rectangle.size.x+1,0)) ) )); - points.push_back( xform.xform( node->map_to_world((rectangle.pos+Point2(rectangle.size.x+1,rectangle.size.y+1)) ) )); - points.push_back( xform.xform( node->map_to_world((rectangle.pos+Point2(0,rectangle.size.y+1)) ) )); + points.push_back(xform.xform(node->map_to_world((rectangle.pos)))); + points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(rectangle.size.x + 1, 0))))); + points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(rectangle.size.x + 1, rectangle.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(0, rectangle.size.y + 1))))); - canvas_item_editor->draw_colored_polygon(points, Color(0.2,0.8,1,0.4)); + canvas_item_editor->draw_colored_polygon(points, Color(0.2, 0.8, 1, 0.4)); } - if (mouse_over){ + if (mouse_over) { - Vector2 endpoints[4]={ + Vector2 endpoints[4] = { node->map_to_world(over_tile, true), - node->map_to_world((over_tile+Point2(1,0)), true), - node->map_to_world((over_tile+Point2(1,1)), true), - node->map_to_world((over_tile+Point2(0,1)), true) + node->map_to_world((over_tile + Point2(1, 0)), true), + node->map_to_world((over_tile + Point2(1, 1)), true), + node->map_to_world((over_tile + Point2(0, 1)), true) }; - for (int i=0;i<4;i++) { - if (node->get_half_offset()==TileMap::HALF_OFFSET_X && ABS(over_tile.y)&1) - endpoints[i]+=cell_xf[0]*0.5; - if (node->get_half_offset()==TileMap::HALF_OFFSET_Y && ABS(over_tile.x)&1) - endpoints[i]+=cell_xf[1]*0.5; - endpoints[i]=xform.xform(endpoints[i]); + for (int i = 0; i < 4; i++) { + if (node->get_half_offset() == TileMap::HALF_OFFSET_X && ABS(over_tile.y) & 1) + endpoints[i] += cell_xf[0] * 0.5; + if (node->get_half_offset() == TileMap::HALF_OFFSET_Y && ABS(over_tile.x) & 1) + endpoints[i] += cell_xf[1] * 0.5; + endpoints[i] = xform.xform(endpoints[i]); } Color col; - if (node->get_cell(over_tile.x,over_tile.y)!=TileMap::INVALID_CELL) - col=Color(0.2,0.8,1.0,0.8); + if (node->get_cell(over_tile.x, over_tile.y) != TileMap::INVALID_CELL) + col = Color(0.2, 0.8, 1.0, 0.8); else - col=Color(1.0,0.4,0.2,0.8); - - for (int i=0;i<4;i++) - canvas_item_editor->draw_line(endpoints[i],endpoints[(i+1)%4],col,2); + col = Color(1.0, 0.4, 0.2, 0.8); + for (int i = 0; i < 4; i++) + canvas_item_editor->draw_line(endpoints[i], endpoints[(i + 1) % 4], col, 2); bool bucket_preview = EditorSettings::get_singleton()->get("editors/tile_map/bucket_fill_preview"); - if (tool==TOOL_SELECTING || tool==TOOL_PICKING || !bucket_preview) { + if (tool == TOOL_SELECTING || tool == TOOL_PICKING || !bucket_preview) { return; } - if (tool==TOOL_LINE_PAINT) { + if (tool == TOOL_LINE_PAINT) { if (paint_undo.empty()) return; int id = get_selected_tile(); - if (id==TileMap::INVALID_CELL) + if (id == TileMap::INVALID_CELL) return; - for (Map<Point2i, CellOp>::Element *E=paint_undo.front();E;E=E->next()) { + for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { _draw_cell(id, E->key(), flip_h, flip_v, transpose, xform); } - } else if (tool==TOOL_RECTANGLE_PAINT) { + } else if (tool == TOOL_RECTANGLE_PAINT) { int id = get_selected_tile(); - if (id==TileMap::INVALID_CELL) + if (id == TileMap::INVALID_CELL) return; - for (int i=rectangle.pos.y;i<=rectangle.pos.y+rectangle.size.y;i++) { - for (int j=rectangle.pos.x;j<=rectangle.pos.x+rectangle.size.x;j++) { + for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { + for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { _draw_cell(id, Point2i(j, i), flip_h, flip_v, transpose, xform); } } - } else if (tool==TOOL_DUPLICATING) { + } else if (tool == TOOL_DUPLICATING) { if (copydata.empty()) return; @@ -1245,30 +1233,30 @@ void TileMapEditor::_canvas_draw() { if (ts.is_null()) return; - Point2 ofs = over_tile-rectangle.pos; + Point2 ofs = over_tile - rectangle.pos; - for (List<TileData>::Element *E=copydata.front();E;E=E->next()) { + for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { if (!ts->has_tile(E->get().cell)) continue; TileData tcd = E->get(); - _draw_cell(tcd.cell, tcd.pos+ofs, tcd.flip_h, tcd.flip_v, tcd.transpose, xform); + _draw_cell(tcd.cell, tcd.pos + ofs, tcd.flip_h, tcd.flip_v, tcd.transpose, xform); } - Rect2i duplicate=rectangle; - duplicate.pos=over_tile; + Rect2i duplicate = rectangle; + duplicate.pos = over_tile; Vector<Vector2> points; - points.push_back( xform.xform( node->map_to_world(duplicate.pos ) )); - points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(duplicate.size.x+1,0)) ) )); - points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(duplicate.size.x+1,duplicate.size.y+1))) )); - points.push_back( xform.xform( node->map_to_world((duplicate.pos+Point2(0,duplicate.size.y+1))) )); + points.push_back(xform.xform(node->map_to_world(duplicate.pos))); + points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(duplicate.size.x + 1, 0))))); + points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(duplicate.size.x + 1, duplicate.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(0, duplicate.size.y + 1))))); - canvas_item_editor->draw_colored_polygon(points, Color(0.2,1.0,0.8,0.2)); + canvas_item_editor->draw_colored_polygon(points, Color(0.2, 1.0, 0.8, 0.2)); - } else if(tool == TOOL_BUCKET) { + } else if (tool == TOOL_BUCKET) { int tile = get_selected_tile(); _draw_fill_preview(tile, over_tile, flip_h, flip_v, transpose, xform); @@ -1277,7 +1265,7 @@ void TileMapEditor::_canvas_draw() { int st = get_selected_tile(); - if (st==TileMap::INVALID_CELL) + if (st == TileMap::INVALID_CELL) return; _draw_cell(st, over_tile, flip_h, flip_v, transpose, xform); @@ -1290,41 +1278,40 @@ void TileMapEditor::edit(Node *p_tile_map) { search_box->set_text(""); if (!canvas_item_editor) { - canvas_item_editor=CanvasItemEditor::get_singleton()->get_viewport_control(); + canvas_item_editor = CanvasItemEditor::get_singleton()->get_viewport_control(); } if (node) - node->disconnect("settings_changed",this,"_tileset_settings_changed"); + node->disconnect("settings_changed", this, "_tileset_settings_changed"); if (p_tile_map) { - node=p_tile_map->cast_to<TileMap>(); - if (!canvas_item_editor->is_connected("draw",this,"_canvas_draw")) - canvas_item_editor->connect("draw",this,"_canvas_draw"); - if (!canvas_item_editor->is_connected("mouse_entered",this,"_canvas_mouse_enter")) - canvas_item_editor->connect("mouse_entered",this,"_canvas_mouse_enter"); - if (!canvas_item_editor->is_connected("mouse_exited",this,"_canvas_mouse_exit")) - canvas_item_editor->connect("mouse_exited",this,"_canvas_mouse_exit"); + node = p_tile_map->cast_to<TileMap>(); + if (!canvas_item_editor->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->connect("draw", this, "_canvas_draw"); + if (!canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter")) + canvas_item_editor->connect("mouse_entered", this, "_canvas_mouse_enter"); + if (!canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit")) + canvas_item_editor->connect("mouse_exited", this, "_canvas_mouse_exit"); _update_palette(); } else { - node=NULL; + node = NULL; - if (canvas_item_editor->is_connected("draw",this,"_canvas_draw")) - canvas_item_editor->disconnect("draw",this,"_canvas_draw"); - if (canvas_item_editor->is_connected("mouse_entered",this,"_canvas_mouse_enter")) - canvas_item_editor->disconnect("mouse_entered",this,"_canvas_mouse_enter"); - if (canvas_item_editor->is_connected("mouse_exited",this,"_canvas_mouse_exit")) - canvas_item_editor->disconnect("mouse_exited",this,"_canvas_mouse_exit"); + if (canvas_item_editor->is_connected("draw", this, "_canvas_draw")) + canvas_item_editor->disconnect("draw", this, "_canvas_draw"); + if (canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter")) + canvas_item_editor->disconnect("mouse_entered", this, "_canvas_mouse_enter"); + if (canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit")) + canvas_item_editor->disconnect("mouse_exited", this, "_canvas_mouse_exit"); _update_palette(); } if (node) - node->connect("settings_changed",this,"_tileset_settings_changed"); + node->connect("settings_changed", this, "_tileset_settings_changed"); _clear_bucket_cache(); - } void TileMapEditor::_tileset_settings_changed() { @@ -1344,66 +1331,62 @@ void TileMapEditor::_icon_size_changed(float p_value) { void TileMapEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_text_entered"),&TileMapEditor::_text_entered); - ClassDB::bind_method(D_METHOD("_text_changed"),&TileMapEditor::_text_changed); - ClassDB::bind_method(D_METHOD("_sbox_input"),&TileMapEditor::_sbox_input); - ClassDB::bind_method(D_METHOD("_menu_option"),&TileMapEditor::_menu_option); - ClassDB::bind_method(D_METHOD("_canvas_draw"),&TileMapEditor::_canvas_draw); - ClassDB::bind_method(D_METHOD("_canvas_mouse_enter"),&TileMapEditor::_canvas_mouse_enter); - ClassDB::bind_method(D_METHOD("_canvas_mouse_exit"),&TileMapEditor::_canvas_mouse_exit); - ClassDB::bind_method(D_METHOD("_tileset_settings_changed"),&TileMapEditor::_tileset_settings_changed); - ClassDB::bind_method(D_METHOD("_update_transform_buttons"),&TileMapEditor::_update_transform_buttons); + ClassDB::bind_method(D_METHOD("_text_entered"), &TileMapEditor::_text_entered); + ClassDB::bind_method(D_METHOD("_text_changed"), &TileMapEditor::_text_changed); + ClassDB::bind_method(D_METHOD("_sbox_input"), &TileMapEditor::_sbox_input); + ClassDB::bind_method(D_METHOD("_menu_option"), &TileMapEditor::_menu_option); + ClassDB::bind_method(D_METHOD("_canvas_draw"), &TileMapEditor::_canvas_draw); + ClassDB::bind_method(D_METHOD("_canvas_mouse_enter"), &TileMapEditor::_canvas_mouse_enter); + ClassDB::bind_method(D_METHOD("_canvas_mouse_exit"), &TileMapEditor::_canvas_mouse_exit); + ClassDB::bind_method(D_METHOD("_tileset_settings_changed"), &TileMapEditor::_tileset_settings_changed); + ClassDB::bind_method(D_METHOD("_update_transform_buttons"), &TileMapEditor::_update_transform_buttons); - ClassDB::bind_method(D_METHOD("_fill_points"),&TileMapEditor::_fill_points); - ClassDB::bind_method(D_METHOD("_erase_points"),&TileMapEditor::_erase_points); + ClassDB::bind_method(D_METHOD("_fill_points"), &TileMapEditor::_fill_points); + ClassDB::bind_method(D_METHOD("_erase_points"), &TileMapEditor::_erase_points); ClassDB::bind_method(D_METHOD("_icon_size_changed"), &TileMapEditor::_icon_size_changed); } -TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i& p_pos) -{ +TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i &p_pos) { CellOp op; - op.idx = node->get_cell(p_pos.x,p_pos.y); - if (op.idx!=TileMap::INVALID_CELL) { - if (node->is_cell_x_flipped(p_pos.x,p_pos.y)) - op.xf=true; - if (node->is_cell_y_flipped(p_pos.x,p_pos.y)) - op.yf=true; - if (node->is_cell_transposed(p_pos.x,p_pos.y)) - op.tr=true; + op.idx = node->get_cell(p_pos.x, p_pos.y); + if (op.idx != TileMap::INVALID_CELL) { + if (node->is_cell_x_flipped(p_pos.x, p_pos.y)) + op.xf = true; + if (node->is_cell_y_flipped(p_pos.x, p_pos.y)) + op.yf = true; + if (node->is_cell_transposed(p_pos.x, p_pos.y)) + op.tr = true; } return op; } void TileMapEditor::_update_transform_buttons(Object *p_button) { //ERR_FAIL_NULL(p_button); - ToolButton *b=p_button->cast_to<ToolButton>(); + ToolButton *b = p_button->cast_to<ToolButton>(); //ERR_FAIL_COND(!b); if (b == rotate_0) { mirror_x->set_pressed(false); mirror_y->set_pressed(false); transp->set_pressed(false); - } - else if (b == rotate_90) { + } else if (b == rotate_90) { mirror_x->set_pressed(true); mirror_y->set_pressed(false); transp->set_pressed(true); - } - else if (b == rotate_180) { + } else if (b == rotate_180) { mirror_x->set_pressed(true); mirror_y->set_pressed(true); transp->set_pressed(false); - } - else if (b == rotate_270) { + } else if (b == rotate_270) { mirror_x->set_pressed(false); mirror_y->set_pressed(true); transp->set_pressed(true); } - flip_h=mirror_x->is_pressed(); - flip_v=mirror_y->is_pressed(); - transpose=transp->is_pressed(); + flip_h = mirror_x->is_pressed(); + flip_v = mirror_y->is_pressed(); + transpose = transp->is_pressed(); rotate_0->set_pressed(!flip_h && !flip_v && !transpose); rotate_90->set_pressed(flip_h && !flip_v && transpose); @@ -1413,36 +1396,36 @@ void TileMapEditor::_update_transform_buttons(Object *p_button) { TileMapEditor::TileMapEditor(EditorNode *p_editor) { - node=NULL; - canvas_item_editor=NULL; - editor=p_editor; - undo_redo=editor->get_undo_redo(); + node = NULL; + canvas_item_editor = NULL; + editor = p_editor; + undo_redo = editor->get_undo_redo(); - tool=TOOL_NONE; - selection_active=false; - mouse_over=false; + tool = TOOL_NONE; + selection_active = false; + mouse_over = false; - flip_h=false; - flip_v=false; - transpose=false; + flip_h = false; + flip_v = false; + transpose = false; bucket_cache_tile = -1; bucket_cache_visited = 0; ED_SHORTCUT("tile_map_editor/erase_selection", TTR("Erase selection"), KEY_DELETE); - ED_SHORTCUT("tile_map_editor/find_tile", TTR("Find tile"), KEY_MASK_CMD+KEY_F); + ED_SHORTCUT("tile_map_editor/find_tile", TTR("Find tile"), KEY_MASK_CMD + KEY_F); ED_SHORTCUT("tile_map_editor/transpose", TTR("Transpose")); ED_SHORTCUT("tile_map_editor/mirror_x", TTR("Mirror X"), KEY_A); ED_SHORTCUT("tile_map_editor/mirror_y", TTR("Mirror Y"), KEY_S); - search_box = memnew( LineEdit ); + search_box = memnew(LineEdit); search_box->set_h_size_flags(SIZE_EXPAND_FILL); search_box->connect("text_entered", this, "_text_entered"); search_box->connect("text_changed", this, "_text_changed"); search_box->connect("gui_input", this, "_sbox_input"); add_child(search_box); - size_slider = memnew( HSlider ); + size_slider = memnew(HSlider); size_slider->set_h_size_flags(SIZE_EXPAND_FILL); size_slider->set_min(0.1f); size_slider->set_max(4.0f); @@ -1454,25 +1437,25 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { int mw = EDITOR_DEF("editors/tile_map/palette_min_width", 80); // Add tile palette - palette = memnew( ItemList ); + palette = memnew(ItemList); palette->set_v_size_flags(SIZE_EXPAND_FILL); - palette->set_custom_minimum_size(Size2(mw,0)); + palette->set_custom_minimum_size(Size2(mw, 0)); palette->set_max_columns(0); palette->set_icon_mode(ItemList::ICON_MODE_TOP); palette->set_max_text_lines(2); add_child(palette); // Add menu items - toolbar = memnew( HBoxContainer ); + toolbar = memnew(HBoxContainer); toolbar->set_h_size_flags(SIZE_EXPAND_FILL); toolbar->set_alignment(BoxContainer::ALIGN_END); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(toolbar); // Tile position - tile_info = memnew( Label ); + tile_info = memnew(Label); toolbar->add_child(tile_info); - options = memnew( MenuButton ); + options = memnew(MenuButton); options->set_text("Tile Map"); options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("TileMap", "EditorIcons")); options->set_process_unhandled_key_input(false); @@ -1483,56 +1466,56 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { p->add_separator(); p->add_item(TTR("Pick Tile"), OPTION_PICK_TILE, KEY_CONTROL); p->add_separator(); - p->add_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_MASK_CMD+KEY_B), OPTION_SELECT); - p->add_shortcut(ED_SHORTCUT("tile_map_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_CMD+KEY_D), OPTION_DUPLICATE); + p->add_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_MASK_CMD + KEY_B), OPTION_SELECT); + p->add_shortcut(ED_SHORTCUT("tile_map_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_CMD + KEY_D), OPTION_DUPLICATE); p->add_shortcut(ED_GET_SHORTCUT("tile_map_editor/erase_selection"), OPTION_ERASE_SELECTION); p->connect("id_pressed", this, "_menu_option"); toolbar->add_child(options); - toolbar->add_child( memnew( VSeparator ) ); + toolbar->add_child(memnew(VSeparator)); - transp = memnew( ToolButton ); + transp = memnew(ToolButton); transp->set_toggle_mode(true); - transp->set_tooltip(TTR("Transpose") + " ("+ED_GET_SHORTCUT("tile_map_editor/transpose")->get_as_text()+")"); + transp->set_tooltip(TTR("Transpose") + " (" + ED_GET_SHORTCUT("tile_map_editor/transpose")->get_as_text() + ")"); transp->set_focus_mode(FOCUS_NONE); transp->connect("pressed", this, "_update_transform_buttons", make_binds(transp)); toolbar->add_child(transp); - mirror_x = memnew( ToolButton ); + mirror_x = memnew(ToolButton); mirror_x->set_toggle_mode(true); - mirror_x->set_tooltip(TTR("Mirror X") + " ("+ED_GET_SHORTCUT("tile_map_editor/mirror_x")->get_as_text()+")"); + mirror_x->set_tooltip(TTR("Mirror X") + " (" + ED_GET_SHORTCUT("tile_map_editor/mirror_x")->get_as_text() + ")"); mirror_x->set_focus_mode(FOCUS_NONE); mirror_x->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_x)); toolbar->add_child(mirror_x); - mirror_y = memnew( ToolButton ); + mirror_y = memnew(ToolButton); mirror_y->set_toggle_mode(true); - mirror_y->set_tooltip(TTR("Mirror Y") + " ("+ED_GET_SHORTCUT("tile_map_editor/mirror_y")->get_as_text()+")"); + mirror_y->set_tooltip(TTR("Mirror Y") + " (" + ED_GET_SHORTCUT("tile_map_editor/mirror_y")->get_as_text() + ")"); mirror_y->set_focus_mode(FOCUS_NONE); mirror_y->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_y)); toolbar->add_child(mirror_y); - toolbar->add_child( memnew( VSeparator ) ); + toolbar->add_child(memnew(VSeparator)); - rotate_0 = memnew( ToolButton ); + rotate_0 = memnew(ToolButton); rotate_0->set_toggle_mode(true); rotate_0->set_tooltip(TTR("Rotate 0 degrees")); rotate_0->set_focus_mode(FOCUS_NONE); rotate_0->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_0)); toolbar->add_child(rotate_0); - rotate_90 = memnew( ToolButton ); + rotate_90 = memnew(ToolButton); rotate_90->set_toggle_mode(true); rotate_90->set_tooltip(TTR("Rotate 90 degrees")); rotate_90->set_focus_mode(FOCUS_NONE); rotate_90->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_90)); toolbar->add_child(rotate_90); - rotate_180 = memnew( ToolButton ); + rotate_180 = memnew(ToolButton); rotate_180->set_toggle_mode(true); rotate_180->set_tooltip(TTR("Rotate 180 degrees")); rotate_180->set_focus_mode(FOCUS_NONE); rotate_180->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_180)); toolbar->add_child(rotate_180); - rotate_270 = memnew( ToolButton ); + rotate_270 = memnew(ToolButton); rotate_270->set_toggle_mode(true); rotate_270->set_tooltip(TTR("Rotate 270 degrees")); rotate_270->set_focus_mode(FOCUS_NONE); @@ -1577,17 +1560,15 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) { - EDITOR_DEF("editors/tile_map/preview_size",64); - EDITOR_DEF("editors/tile_map/palette_item_hseparation",8); + EDITOR_DEF("editors/tile_map/preview_size", 64); + EDITOR_DEF("editors/tile_map/palette_item_hseparation", 8); EDITOR_DEF("editors/tile_map/show_tile_names", true); EDITOR_DEF("editors/tile_map/bucket_fill_preview", true); - tile_map_editor = memnew( TileMapEditor(p_node) ); + tile_map_editor = memnew(TileMapEditor(p_node)); add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, tile_map_editor); tile_map_editor->hide(); } -TileMapEditorPlugin::~TileMapEditorPlugin() -{ +TileMapEditorPlugin::~TileMapEditorPlugin() { } - diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index 82e2a396d1..a4774a23b9 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -29,14 +29,14 @@ #ifndef TILE_MAP_EDITOR_PLUGIN_H #define TILE_MAP_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" +#include "editor/editor_plugin.h" #include "scene/2d/tile_map.h" +#include "scene/gui/label.h" #include "scene/gui/line_edit.h" -#include "scene/gui/tool_button.h" #include "scene/gui/menu_button.h" -#include "scene/gui/label.h" +#include "scene/gui/tool_button.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -44,7 +44,7 @@ class TileMapEditor : public VBoxContainer { - GDCLASS(TileMapEditor, VBoxContainer ); + GDCLASS(TileMapEditor, VBoxContainer); enum Tool { @@ -77,7 +77,7 @@ class TileMapEditor : public VBoxContainer { Control *canvas_item_editor; LineEdit *search_box; - HSlider *size_slider; + HSlider *size_slider; ItemList *palette; HBoxContainer *toolbar; @@ -106,7 +106,7 @@ class TileMapEditor : public VBoxContainer { Point2i over_tile; - bool * bucket_cache_visited; + bool *bucket_cache_visited; Rect2i bucket_cache_rect; int bucket_cache_tile; PoolVector<Vector2> bucket_cache; @@ -117,7 +117,12 @@ class TileMapEditor : public VBoxContainer { bool yf; bool tr; - CellOp() { idx=-1; xf=false; yf=false; tr=false; } + CellOp() { + idx = -1; + xf = false; + yf = false; + tr = false; + } }; Map<Point2i, CellOp> paint_undo; @@ -132,17 +137,17 @@ class TileMapEditor : public VBoxContainer { List<TileData> copydata; - void _pick_tile(const Point2& p_pos); + void _pick_tile(const Point2 &p_pos); - PoolVector<Vector2> _bucket_fill(const Point2i& p_start, bool erase=false, bool preview=false); + PoolVector<Vector2> _bucket_fill(const Point2i &p_start, bool erase = false, bool preview = false); - void _fill_points(const PoolVector<Vector2> p_points, const Dictionary& p_op); + void _fill_points(const PoolVector<Vector2> p_points, const Dictionary &p_op); void _erase_points(const PoolVector<Vector2> p_points); - void _select(const Point2i& p_from, const Point2i& p_to); + void _select(const Point2i &p_from, const Point2i &p_to); - void _draw_cell(int p_cell, const Point2i& p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D& p_xform); - void _draw_fill_preview(int p_cell, const Point2i& p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D& p_xform); + void _draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform); + void _draw_fill_preview(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform); void _clear_bucket_cache(); void _update_copydata(); @@ -150,14 +155,14 @@ class TileMapEditor : public VBoxContainer { int get_selected_tile() const; void set_selected_tile(int p_tile); - void _text_entered(const String& p_text); - void _text_changed(const String& p_text); - void _sbox_input(const InputEvent& p_ie); + void _text_entered(const String &p_text); + void _text_changed(const String &p_text); + void _sbox_input(const InputEvent &p_ie); void _update_palette(); void _canvas_draw(); void _menu_option(int p_option); - void _set_cell(const Point2i& p_pos, int p_value, bool p_flip_h=false, bool p_flip_v=false, bool p_transpose=false, bool p_with_undo=false); + void _set_cell(const Point2i &p_pos, int p_value, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false, bool p_with_undo = false); void _canvas_mouse_enter(); void _canvas_mouse_exit(); @@ -165,17 +170,15 @@ class TileMapEditor : public VBoxContainer { void _icon_size_changed(float p_value); protected: - void _notification(int p_what); static void _bind_methods(); - CellOp _get_op_from_cell(const Point2i& p_pos); - void _update_transform_buttons(Object *p_button=NULL); + CellOp _get_op_from_cell(const Point2i &p_pos); + void _update_transform_buttons(Object *p_button = NULL); public: - HBoxContainer *get_toolbar() const { return toolbar; } - bool forward_gui_input(const InputEvent& p_event); + bool forward_gui_input(const InputEvent &p_event); void edit(Node *p_tile_map); TileMapEditor(EditorNode *p_editor); @@ -184,13 +187,12 @@ public: class TileMapEditorPlugin : public EditorPlugin { - GDCLASS( TileMapEditorPlugin, EditorPlugin ); + GDCLASS(TileMapEditorPlugin, EditorPlugin); TileMapEditor *tile_map_editor; public: - - virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform,const InputEvent& p_event) { return tile_map_editor->forward_gui_input(p_event); } + virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return tile_map_editor->forward_gui_input(p_event); } virtual String get_name() const { return "TileMap"; } bool has_main_screen() const { return false; } @@ -200,8 +202,6 @@ public: TileMapEditorPlugin(EditorNode *p_node); ~TileMapEditorPlugin(); - }; - #endif // TILE_MAP_EDITOR_PLUGIN_H diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 3db6c94917..6dee151d99 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -28,12 +28,12 @@ /*************************************************************************/ #include "tile_set_editor_plugin.h" -#include "scene/2d/sprite.h" #include "scene/2d/physics_body_2d.h" +#include "scene/2d/sprite.h" -void TileSetEditor::edit(const Ref<TileSet>& p_tileset) { +void TileSetEditor::edit(const Ref<TileSet> &p_tileset) { - tileset=p_tileset; + tileset = p_tileset; } void TileSetEditor::_import_scene(Node *scene, Ref<TileSet> p_library, bool p_merge) { @@ -41,85 +41,80 @@ void TileSetEditor::_import_scene(Node *scene, Ref<TileSet> p_library, bool p_me if (!p_merge) p_library->clear(); - for(int i=0;i<scene->get_child_count();i++) { - + for (int i = 0; i < scene->get_child_count(); i++) { Node *child = scene->get_child(i); - if (!child->cast_to<Sprite>()) { - if (child->get_child_count()>0) { - child=child->get_child(0); + if (child->get_child_count() > 0) { + child = child->get_child(0); if (!child->cast_to<Sprite>()) { continue; } } else continue; - - } Sprite *mi = child->cast_to<Sprite>(); - Ref<Texture> texture=mi->get_texture(); - Ref<CanvasItemMaterial> material=mi->get_material(); + Ref<Texture> texture = mi->get_texture(); + Ref<CanvasItemMaterial> material = mi->get_material(); if (texture.is_null()) continue; int id = p_library->find_tile_by_name(mi->get_name()); - if (id<0) { + if (id < 0) { - id=p_library->get_last_unused_tile_id(); + id = p_library->get_last_unused_tile_id(); p_library->create_tile(id); - p_library->tile_set_name(id,mi->get_name()); + p_library->tile_set_name(id, mi->get_name()); } - p_library->tile_set_texture(id,texture); - p_library->tile_set_material(id,material); + p_library->tile_set_texture(id, texture); + p_library->tile_set_material(id, material); - p_library->tile_set_modulate(id,mi->get_modulate()); + p_library->tile_set_modulate(id, mi->get_modulate()); Vector2 phys_offset; Size2 s; if (mi->is_region()) { - s=mi->get_region_rect().size; - p_library->tile_set_region(id,mi->get_region_rect()); + s = mi->get_region_rect().size; + p_library->tile_set_region(id, mi->get_region_rect()); } else { const int frame = mi->get_frame(); const int hframes = mi->get_hframes(); - s=texture->get_size()/Size2(hframes,mi->get_vframes()); - p_library->tile_set_region(id,Rect2(Vector2(frame%hframes,frame/hframes)*s,s)); + s = texture->get_size() / Size2(hframes, mi->get_vframes()); + p_library->tile_set_region(id, Rect2(Vector2(frame % hframes, frame / hframes) * s, s)); } - + if (mi->is_centered()) { - phys_offset+=-s/2; + phys_offset += -s / 2; } - Vector<Ref<Shape2D> >collisions; + Vector<Ref<Shape2D> > collisions; Ref<NavigationPolygon> nav_poly; Ref<OccluderPolygon2D> occluder; - for(int j=0;j<mi->get_child_count();j++) { + for (int j = 0; j < mi->get_child_count(); j++) { Node *child2 = mi->get_child(j); if (child2->cast_to<NavigationPolygonInstance>()) - nav_poly=child2->cast_to<NavigationPolygonInstance>()->get_navigation_polygon(); + nav_poly = child2->cast_to<NavigationPolygonInstance>()->get_navigation_polygon(); if (child2->cast_to<LightOccluder2D>()) - occluder=child2->cast_to<LightOccluder2D>()->get_occluder_polygon(); + occluder = child2->cast_to<LightOccluder2D>()->get_occluder_polygon(); if (!child2->cast_to<StaticBody2D>()) continue; StaticBody2D *sb = child2->cast_to<StaticBody2D>(); int shape_count = sb->get_shape_count(); - if (shape_count==0) + if (shape_count == 0) continue; - for (int shape_index=0; shape_index<shape_count; ++shape_index) - { - Ref<Shape2D> collision=sb->get_shape(shape_index); + for (int shape_index = 0; shape_index < shape_count; ++shape_index) { + Ref<Shape2D> collision = sb->get_shape(shape_index); if (collision.is_valid()) { collisions.push_back(collision); } @@ -128,58 +123,53 @@ void TileSetEditor::_import_scene(Node *scene, Ref<TileSet> p_library, bool p_me if (collisions.size()) { - p_library->tile_set_shapes(id,collisions); - p_library->tile_set_shape_offset(id,-phys_offset); + p_library->tile_set_shapes(id, collisions); + p_library->tile_set_shape_offset(id, -phys_offset); } else { - p_library->tile_set_shape_offset(id,Vector2()); - + p_library->tile_set_shape_offset(id, Vector2()); } - p_library->tile_set_texture_offset(id,mi->get_offset()); - p_library->tile_set_navigation_polygon(id,nav_poly); - p_library->tile_set_light_occluder(id,occluder); - p_library->tile_set_occluder_offset(id,-phys_offset); - p_library->tile_set_navigation_polygon_offset(id,-phys_offset); - - + p_library->tile_set_texture_offset(id, mi->get_offset()); + p_library->tile_set_navigation_polygon(id, nav_poly); + p_library->tile_set_light_occluder(id, occluder); + p_library->tile_set_occluder_offset(id, -phys_offset); + p_library->tile_set_navigation_polygon_offset(id, -phys_offset); } } void TileSetEditor::_menu_confirm() { - switch(option) { + switch (option) { case MENU_OPTION_MERGE_FROM_SCENE: case MENU_OPTION_CREATE_FROM_SCENE: { - EditorNode *en = editor; - Node * scene = en->get_edited_scene(); + Node *scene = en->get_edited_scene(); if (!scene) break; - _import_scene(scene,tileset,option==MENU_OPTION_MERGE_FROM_SCENE); - + _import_scene(scene, tileset, option == MENU_OPTION_MERGE_FROM_SCENE); } break; } } -void TileSetEditor::_name_dialog_confirm(const String& name) { +void TileSetEditor::_name_dialog_confirm(const String &name) { switch (option) { case MENU_OPTION_REMOVE_ITEM: { - int id=tileset->find_tile_by_name(name); + int id = tileset->find_tile_by_name(name); - if (id<0 && name.is_valid_integer()) - id=name.to_int(); + if (id < 0 && name.is_valid_integer()) + id = name.to_int(); if (tileset->has_tile(id)) { tileset->remove_tile(id); } else { - err_dialog->set_text(TTR("Could not find tile:")+" " + name); + err_dialog->set_text(TTR("Could not find tile:") + " " + name); err_dialog->popup_centered(Size2(300, 60)); } } break; @@ -188,8 +178,8 @@ void TileSetEditor::_name_dialog_confirm(const String& name) { void TileSetEditor::_menu_cbk(int p_option) { - option=p_option; - switch(p_option) { + option = p_option; + switch (p_option) { case MENU_OPTION_ADD_ITEM: { @@ -204,57 +194,54 @@ void TileSetEditor::_menu_cbk(int p_option) { case MENU_OPTION_CREATE_FROM_SCENE: { cd->set_text(TTR("Create from scene?")); - cd->popup_centered(Size2(300,60)); + cd->popup_centered(Size2(300, 60)); } break; case MENU_OPTION_MERGE_FROM_SCENE: { cd->set_text(TTR("Merge from scene?")); - cd->popup_centered(Size2(300,60)); + cd->popup_centered(Size2(300, 60)); } break; } } +Error TileSetEditor::update_library_file(Node *p_base_scene, Ref<TileSet> ml, bool p_merge) { - -Error TileSetEditor::update_library_file(Node *p_base_scene, Ref<TileSet> ml,bool p_merge) { - - _import_scene(p_base_scene,ml,p_merge); + _import_scene(p_base_scene, ml, p_merge); return OK; - } void TileSetEditor::_bind_methods() { - ClassDB::bind_method("_menu_cbk",&TileSetEditor::_menu_cbk); - ClassDB::bind_method("_menu_confirm",&TileSetEditor::_menu_confirm); - ClassDB::bind_method("_name_dialog_confirm",&TileSetEditor::_name_dialog_confirm); + ClassDB::bind_method("_menu_cbk", &TileSetEditor::_menu_cbk); + ClassDB::bind_method("_menu_confirm", &TileSetEditor::_menu_confirm); + ClassDB::bind_method("_name_dialog_confirm", &TileSetEditor::_name_dialog_confirm); } TileSetEditor::TileSetEditor(EditorNode *p_editor) { - Panel *panel = memnew( Panel ); + Panel *panel = memnew(Panel); panel->set_area_as_parent_rect(); add_child(panel); - MenuButton * options = memnew( MenuButton ); + MenuButton *options = memnew(MenuButton); panel->add_child(options); - options->set_pos(Point2(1,1)); + options->set_pos(Point2(1, 1)); options->set_text("Theme"); - options->get_popup()->add_item(TTR("Add Item"),MENU_OPTION_ADD_ITEM); - options->get_popup()->add_item(TTR("Remove Item"),MENU_OPTION_REMOVE_ITEM); + options->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM); + options->get_popup()->add_item(TTR("Remove Item"), MENU_OPTION_REMOVE_ITEM); options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Create from Scene"),MENU_OPTION_CREATE_FROM_SCENE); - options->get_popup()->add_item(TTR("Merge from Scene"),MENU_OPTION_MERGE_FROM_SCENE); - options->get_popup()->connect("id_pressed", this,"_menu_cbk"); - editor=p_editor; + options->get_popup()->add_item(TTR("Create from Scene"), MENU_OPTION_CREATE_FROM_SCENE); + options->get_popup()->add_item(TTR("Merge from Scene"), MENU_OPTION_MERGE_FROM_SCENE); + options->get_popup()->connect("id_pressed", this, "_menu_cbk"); + editor = p_editor; cd = memnew(ConfirmationDialog); add_child(cd); - cd->get_ok()->connect("pressed", this,"_menu_confirm"); + cd->get_ok()->connect("pressed", this, "_menu_confirm"); nd = memnew(EditorNameDialog); add_child(nd); nd->set_hide_on_ok(true); - nd->get_line_edit()->set_margin(MARGIN_TOP,28); - nd->connect("name_confirmed", this,"_name_dialog_confirm"); + nd->get_line_edit()->set_margin(MARGIN_TOP, 28); + nd->connect("name_confirmed", this, "_name_dialog_confirm"); err_dialog = memnew(AcceptDialog); add_child(err_dialog); @@ -264,18 +251,18 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { void TileSetEditorPlugin::edit(Object *p_node) { if (p_node && p_node->cast_to<TileSet>()) { - tileset_editor->edit( p_node->cast_to<TileSet>() ); + tileset_editor->edit(p_node->cast_to<TileSet>()); tileset_editor->show(); } else tileset_editor->hide(); } -bool TileSetEditorPlugin::handles(Object *p_node) const{ +bool TileSetEditorPlugin::handles(Object *p_node) const { return p_node->is_class("TileSet"); } -void TileSetEditorPlugin::make_visible(bool p_visible){ +void TileSetEditorPlugin::make_visible(bool p_visible) { if (p_visible) tileset_editor->show(); @@ -285,13 +272,12 @@ void TileSetEditorPlugin::make_visible(bool p_visible){ TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) { - tileset_editor = memnew( TileSetEditor(p_node) ); + tileset_editor = memnew(TileSetEditor(p_node)); p_node->get_viewport()->add_child(tileset_editor); tileset_editor->set_area_as_parent_rect(); - tileset_editor->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END ); - tileset_editor->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_BEGIN ); - tileset_editor->set_end( Point2(0,22) ); + tileset_editor->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); + tileset_editor->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_BEGIN); + tileset_editor->set_end(Point2(0, 22)); tileset_editor->hide(); - } diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index 02a82ebd6b..0dabf58f7c 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -29,16 +29,13 @@ #ifndef TILE_SET_EDITOR_PLUGIN_H #define TILE_SET_EDITOR_PLUGIN_H - - -#include "scene/resources/tile_set.h" -#include "editor/editor_node.h" #include "editor/editor_name_dialog.h" - +#include "editor/editor_node.h" +#include "scene/resources/tile_set.h" class TileSetEditor : public Control { - GDCLASS( TileSetEditor, Control ); + GDCLASS(TileSetEditor, Control); Ref<TileSet> tileset; @@ -59,43 +56,35 @@ class TileSetEditor : public Control { int option; void _menu_cbk(int p_option); void _menu_confirm(); - void _name_dialog_confirm(const String& name); + void _name_dialog_confirm(const String &name); static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge); - protected: static void _bind_methods(); -public: - void edit(const Ref<TileSet>& p_tileset); - static Error update_library_file(Node *p_base_scene, Ref<TileSet> ml,bool p_merge=true); +public: + void edit(const Ref<TileSet> &p_tileset); + static Error update_library_file(Node *p_base_scene, Ref<TileSet> ml, bool p_merge = true); TileSetEditor(EditorNode *p_editor); }; - - class TileSetEditorPlugin : public EditorPlugin { - GDCLASS( TileSetEditorPlugin, EditorPlugin ); + GDCLASS(TileSetEditorPlugin, EditorPlugin); TileSetEditor *tileset_editor; EditorNode *editor; public: - virtual String get_name() const { return "TileSet"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); virtual bool handles(Object *p_node) const; virtual void make_visible(bool p_visible); - - TileSetEditorPlugin(EditorNode *p_node); - }; - #endif // TILE_SET_EDITOR_PLUGIN_H |