void EditorAssetInstaller::open(const String &p_path, int p_depth) { package_path = p_path; Set<String> files_sorted; FileAccess *src_f = NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); unzFile pkg = unzOpen2(p_path.utf8().get_data(), &io); if (!pkg) { error->set_text(TTR("Error opening package file, not in zip format.")); return; } int ret = unzGoToFirstFile(pkg); while (ret == UNZ_OK) { //get filename unz_file_info info; char fname[16384]; unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); String name = fname; files_sorted.insert(name); ret = unzGoToNextFile(pkg); } Map<String, Ref<Texture> > extension_guess; { extension_guess["png"] = get_icon("Texture", "EditorIcons"); extension_guess["jpg"] = get_icon("Texture", "EditorIcons"); extension_guess["tex"] = get_icon("Texture", "EditorIcons"); extension_guess["atlastex"] = get_icon("Texture", "EditorIcons"); extension_guess["dds"] = get_icon("Texture", "EditorIcons"); extension_guess["scn"] = get_icon("PackedScene", "EditorIcons"); extension_guess["tscn"] = get_icon("PackedScene", "EditorIcons"); extension_guess["xml"] = get_icon("PackedScene", "EditorIcons"); extension_guess["xscn"] = get_icon("PackedScene", "EditorIcons"); extension_guess["material"] = get_icon("Material", "EditorIcons"); extension_guess["shd"] = get_icon("Shader", "EditorIcons"); extension_guess["gd"] = get_icon("GDScript", "EditorIcons"); } Ref<Texture> generic_extension = get_icon("Object", "EditorIcons"); unzClose(pkg); updating = true; tree->clear(); TreeItem *root = tree->create_item(); root->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); root->set_checked(0, true); root->set_icon(0, get_icon("folder", "FileDialog")); root->set_text(0, "res://"); root->set_editable(0, true); Map<String, TreeItem *> dir_map; for (Set<String>::Element *E = files_sorted.front(); E; E = E->next()) { String path = E->get(); int depth = p_depth; bool skip = false; while (depth > 0) { int pp = path.find("/"); if (pp == -1) { skip = true; break; } path = path.substr(pp + 1, path.length()); depth--; } if (skip || path == String()) continue; bool isdir = false; if (path.ends_with("/")) { //a directory path = path.substr(0, path.length() - 1); isdir = true; } int pp = path.find_last("/"); TreeItem *parent; if (pp == -1) { parent = root; } else { String ppath = path.substr(0, pp); ERR_CONTINUE(!dir_map.has(ppath)); parent = dir_map[ppath]; } TreeItem *ti = tree->create_item(parent); ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); ti->set_checked(0, true); ti->set_editable(0, true); if (isdir) { dir_map[path] = ti; ti->set_text(0, path.get_file() + "/"); ti->set_icon(0, get_icon("folder", "FileDialog")); ti->set_metadata(0, String()); } else { String file = path.get_file(); String extension = file.get_extension().to_lower(); if (extension_guess.has(extension)) { ti->set_icon(0, extension_guess[extension]); } else { ti->set_icon(0, generic_extension); } ti->set_text(0, file); String res_path = "res://" + path; if (FileAccess::exists(res_path)) { ti->set_custom_color(0, get_color("error_color", "Editor")); ti->set_tooltip(0, res_path + " (Already Exists)"); ti->set_checked(0, false); } else { ti->set_tooltip(0, res_path); } ti->set_metadata(0, res_path); } status_map[E->get()] = ti; } popup_centered_ratio(); updating = false; }
ConnectDialog::ConnectDialog() { VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); HBoxContainer *main_hb = memnew(HBoxContainer); vbc->add_child(main_hb); main_hb->set_v_size_flags(SIZE_EXPAND_FILL); VBoxContainer *vbc_left = memnew(VBoxContainer); main_hb->add_child(vbc_left); vbc_left->set_h_size_flags(SIZE_EXPAND_FILL); tree = memnew(SceneTreeEditor(false)); tree->get_scene_tree()->connect("item_activated", this, "_ok"); vbc_left->add_margin_child(TTR("Connect To Node:"), tree, true); VBoxContainer *vbc_right = memnew(VBoxContainer); main_hb->add_child(vbc_right); vbc_right->set_h_size_flags(SIZE_EXPAND_FILL); HBoxContainer *add_bind_hb = memnew(HBoxContainer); type_list = memnew(OptionButton); type_list->set_h_size_flags(SIZE_EXPAND_FILL); add_bind_hb->add_child(type_list); type_list->add_item("bool", Variant::BOOL); type_list->add_item("int", Variant::INT); type_list->add_item("real", Variant::REAL); type_list->add_item("string", Variant::STRING); //type_list->add_separator(); type_list->add_item("Vector2", Variant::VECTOR2); type_list->add_item("Rect2", Variant::RECT2); type_list->add_item("Vector3", Variant::VECTOR3); type_list->add_item("Plane", Variant::PLANE); type_list->add_item("Quat", Variant::QUAT); type_list->add_item("AABB", Variant::AABB); type_list->add_item("Basis", Variant::BASIS); type_list->add_item("Transform", Variant::TRANSFORM); //type_list->add_separator(); type_list->add_item("Color", Variant::COLOR); type_list->select(0); Button *add_bind = memnew(Button); add_bind->set_text(TTR("Add")); add_bind_hb->add_child(add_bind); add_bind->connect("pressed", this, "_add_bind"); Button *del_bind = memnew(Button); del_bind->set_text(TTR("Remove")); add_bind_hb->add_child(del_bind); del_bind->connect("pressed", this, "_remove_bind"); vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb); bind_editor = memnew(PropertyEditor); bind_editor->hide_top_label(); vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true); dst_path = memnew(LineEdit); vbc->add_margin_child(TTR("Path to Node:"), dst_path); HBoxContainer *dstm_hb = memnew(HBoxContainer); vbc->add_margin_child("Method In Node:", dstm_hb); dst_method = memnew(LineEdit); dst_method->set_h_size_flags(SIZE_EXPAND_FILL); dstm_hb->add_child(dst_method); /*dst_method_list = memnew( MenuButton ); dst_method_list->set_text("List.."); dst_method_list->set_anchor( MARGIN_RIGHT, ANCHOR_END ); dst_method_list->set_anchor( MARGIN_LEFT, ANCHOR_END ); dst_method_list->set_anchor( MARGIN_TOP, ANCHOR_END ); dst_method_list->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); dst_method_list->set_begin( Point2( 70,59) ); dst_method_list->set_end( Point2( 15,39 ) ); */ //add_child(dst_method_list); make_callback = memnew(CheckButton); make_callback->set_toggle_mode(true); make_callback->set_pressed(EDITOR_DEF("text_editor/tools/create_signal_callbacks", true)); make_callback->set_text(TTR("Make Function")); dstm_hb->add_child(make_callback); deferred = memnew(CheckButton); deferred->set_text(TTR("Deferred")); dstm_hb->add_child(deferred); oneshot = memnew(CheckButton); oneshot->set_text(TTR("Oneshot")); dstm_hb->add_child(oneshot); tree->connect("node_selected", this, "_tree_node_selected"); set_as_toplevel(true); cdbinds = memnew(ConnectDialogBinds); error = memnew(ConfirmationDialog); add_child(error); error->get_ok()->set_text(TTR("Close")); get_ok()->set_text(TTR("Connect")); }
String EditorMeshImportPlugin::get_visible_name() const{ return TTR("Mesh"); }
EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { HBoxContainer *hb = memnew(HBoxContainer); add_child(hb); icon = memnew(TextureRect); hb->add_child(icon); VBoxContainer *vb = memnew(VBoxContainer); hb->add_child(vb); vb->set_h_size_flags(SIZE_EXPAND_FILL); HBoxContainer *title_hb = memnew(HBoxContainer); vb->add_child(title_hb); title = memnew(Label); title_hb->add_child(title); title->set_h_size_flags(SIZE_EXPAND_FILL); dismiss = memnew(TextureButton); dismiss->connect("pressed", this, "_close"); title_hb->add_child(dismiss); title->set_clip_text(true); vb->add_spacer(); status = memnew(Label(TTR("Idle"))); vb->add_child(status); status->add_color_override("font_color", Color(0.5, 0.5, 0.5)); progress = memnew(ProgressBar); vb->add_child(progress); HBoxContainer *hb2 = memnew(HBoxContainer); vb->add_child(hb2); hb2->add_spacer(); install = memnew(Button); install->set_text(TTR("Install")); install->set_disabled(true); install->connect("pressed", this, "_install"); retry = memnew(Button); retry->set_text(TTR("Retry")); retry->connect("pressed", this, "_make_request"); hb2->add_child(retry); hb2->add_child(install); set_custom_minimum_size(Size2(250, 0)); download = memnew(HTTPRequest); add_child(download); download->connect("request_completed", this, "_http_download_completed"); download_error = memnew(AcceptDialog); add_child(download_error); download_error->set_title(TTR("Download Error")); asset_installer = memnew(EditorAssetInstaller); add_child(asset_installer); prev_status = -1; external_install = false; }
void FindReplaceBar::_replace_all() { text_edit->disconnect("text_changed", this, "_editor_text_changed"); // line as x so it gets priority in comparison, column as y Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column()); Point2i prev_match = Point2(-1, -1); bool selection_enabled = text_edit->is_selection_active(); Point2i selection_begin, selection_end; if (selection_enabled) { selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); } int vsval = text_edit->get_v_scroll(); text_edit->cursor_set_line(0); text_edit->cursor_set_column(0); String replace_text = get_replace_text(); int search_text_len = get_search_text().length(); int rc = 0; replace_all_mode = true; text_edit->begin_complex_operation(); if (search_current()) { do { // replace area Point2i match_from(result_line, result_col); Point2i match_to(result_line, result_col + search_text_len); if (match_from < prev_match) { break; // done } prev_match = Point2i(result_line, result_col + replace_text.length()); text_edit->unfold_line(result_line); text_edit->select(result_line, result_col, result_line, match_to.y); if (selection_enabled && is_selection_only()) { if (match_from < selection_begin || match_to > selection_end) { continue; } // replace but adjust selection bounds text_edit->insert_text_at_cursor(replace_text); if (match_to.x == selection_end.x) { selection_end.y += replace_text.length() - search_text_len; } } else { // just replace text_edit->insert_text_at_cursor(replace_text); } rc++; } while (search_next()); } text_edit->end_complex_operation(); replace_all_mode = false; // restore editor state (selection, cursor, scroll) text_edit->cursor_set_line(orig_cursor.x); text_edit->cursor_set_column(orig_cursor.y); if (selection_enabled && is_selection_only()) { // reselect text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); } else { text_edit->deselect(); } text_edit->set_v_scroll(vsval); set_error(vformat(TTR("Replaced %d occurrence(s)."), rc)); text_edit->call_deferred("connect", "text_changed", this, "_editor_text_changed"); }
CodeTextEditor::CodeTextEditor() { code_complete_func = NULL; ED_SHORTCUT("script_editor/zoom_in", TTR("Zoom In"), KEY_MASK_CMD | KEY_EQUAL); ED_SHORTCUT("script_editor/zoom_out", TTR("Zoom Out"), KEY_MASK_CMD | KEY_MINUS); ED_SHORTCUT("script_editor/reset_zoom", TTR("Reset Zoom"), KEY_MASK_CMD | KEY_0); find_replace_bar = memnew(FindReplaceBar); add_child(find_replace_bar); find_replace_bar->set_h_size_flags(SIZE_EXPAND_FILL); find_replace_bar->hide(); text_editor = memnew(TextEdit); add_child(text_editor); text_editor->set_v_size_flags(SIZE_EXPAND_FILL); find_replace_bar->set_text_edit(text_editor); text_editor->set_show_line_numbers(true); text_editor->set_brace_matching(true); text_editor->set_auto_indent(true); status_bar = memnew(HBoxContainer); add_child(status_bar); status_bar->set_h_size_flags(SIZE_EXPAND_FILL); idle = memnew(Timer); add_child(idle); idle->set_one_shot(true); idle->set_wait_time(EDITOR_DEF("text_editor/completion/idle_parse_delay", 2)); code_complete_timer = memnew(Timer); add_child(code_complete_timer); code_complete_timer->set_one_shot(true); enable_complete_timer = EDITOR_DEF("text_editor/completion/enable_code_completion_delay", true); code_complete_timer->set_wait_time(EDITOR_DEF("text_editor/completion/code_complete_delay", .3f)); error = memnew(Label); status_bar->add_child(error); error->set_autowrap(true); error->set_valign(Label::VALIGN_CENTER); error->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); error->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); error->set_h_size_flags(SIZE_EXPAND_FILL); //required for it to display, given now it's clipping contents, do not touch find_replace_bar->connect("error", error, "set_text"); status_bar->add_child(memnew(Label)); //to keep the height if the other labels are not visible Label *zoom_txt = memnew(Label); status_bar->add_child(zoom_txt); zoom_txt->set_align(Label::ALIGN_RIGHT); zoom_txt->set_valign(Label::VALIGN_CENTER); zoom_txt->set_v_size_flags(SIZE_FILL); zoom_txt->set_text(TTR("Zoom:")); zoom_txt->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); zoom_nb = memnew(Label); status_bar->add_child(zoom_nb); zoom_nb->set_valign(Label::VALIGN_CENTER); zoom_nb->set_v_size_flags(SIZE_FILL); zoom_nb->set_autowrap(true); // workaround to prevent resizing the label on each change, do not touch zoom_nb->set_clip_text(true); // workaround to prevent resizing the label on each change, do not touch zoom_nb->set_custom_minimum_size(Size2(60, 1) * EDSCALE); zoom_nb->set_align(Label::ALIGN_RIGHT); zoom_nb->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); Label *line_txt = memnew(Label); status_bar->add_child(line_txt); line_txt->set_align(Label::ALIGN_RIGHT); line_txt->set_valign(Label::VALIGN_CENTER); line_txt->set_v_size_flags(SIZE_FILL); line_txt->set_text(TTR("Line:")); line_txt->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); line_nb = memnew(Label); status_bar->add_child(line_nb); line_nb->set_valign(Label::VALIGN_CENTER); line_nb->set_v_size_flags(SIZE_FILL); line_nb->set_autowrap(true); // workaround to prevent resizing the label on each change, do not touch line_nb->set_clip_text(true); // workaround to prevent resizing the label on each change, do not touch line_nb->set_custom_minimum_size(Size2(40, 1) * EDSCALE); line_nb->set_align(Label::ALIGN_RIGHT); line_nb->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); Label *col_txt = memnew(Label); status_bar->add_child(col_txt); col_txt->set_align(Label::ALIGN_RIGHT); col_txt->set_valign(Label::VALIGN_CENTER); col_txt->set_v_size_flags(SIZE_FILL); col_txt->set_text(TTR("Col:")); col_txt->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); col_nb = memnew(Label); status_bar->add_child(col_nb); col_nb->set_valign(Label::VALIGN_CENTER); col_nb->set_v_size_flags(SIZE_FILL); col_nb->set_autowrap(true); // workaround to prevent resizing the label on each change, do not touch col_nb->set_clip_text(true); // workaround to prevent resizing the label on each change, do not touch col_nb->set_custom_minimum_size(Size2(40, 1) * EDSCALE); col_nb->set_align(Label::ALIGN_RIGHT); col_nb->set("custom_constants/margin_right", 0); col_nb->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("status_source", "EditorFonts")); text_editor->connect("gui_input", this, "_text_editor_gui_input"); text_editor->connect("cursor_changed", this, "_line_col_changed"); text_editor->connect("text_changed", this, "_text_changed"); text_editor->connect("request_completion", this, "_complete_request"); Vector<String> cs; cs.push_back("."); cs.push_back(","); cs.push_back("("); cs.push_back("="); cs.push_back("$"); text_editor->set_completion(true, cs); idle->connect("timeout", this, "_text_changed_idle_timeout"); code_complete_timer->connect("timeout", this, "_code_complete_timer_timeout"); font_resize_val = 0; font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); zoom_nb->set_text(itos(100 * font_size / 14) + "%"); font_resize_timer = memnew(Timer); add_child(font_resize_timer); font_resize_timer->set_one_shot(true); font_resize_timer->set_wait_time(0.07); font_resize_timer->connect("timeout", this, "_font_resize_timeout"); EditorSettings::get_singleton()->connect("settings_changed", this, "_on_settings_change"); }
void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge) { if (!p_merge) p_library->clear(); for(int i=0;i<p_scene->get_child_count();i++) { Node *child = p_scene->get_child(i); if (!child->cast_to<MeshInstance>()) { if (child->get_child_count()>0) { child=child->get_child(0); if (!child->cast_to<MeshInstance>()) { continue; } } else continue; } MeshInstance *mi = child->cast_to<MeshInstance>(); Ref<Mesh> mesh=mi->get_mesh(); if (mesh.is_null()) continue; int id = p_library->find_item_name(mi->get_name()); if (id<0) { id=p_library->get_last_unused_item_id(); p_library->create_item(id); p_library->set_item_name(id,mi->get_name()); } p_library->set_item_mesh(id,mesh); Ref<Shape> collision; for(int j=0;j<mi->get_child_count();j++) { #if 1 Node *child2 = mi->get_child(j); if (!child2->cast_to<StaticBody>()) continue; StaticBody *sb = child2->cast_to<StaticBody>(); if (sb->get_shape_count()==0) continue; collision=sb->get_shape(0); if (!collision.is_null()) break; #endif } if (!collision.is_null()) { p_library->set_item_shape(id,collision); } Ref<NavigationMesh> navmesh; for(int j=0;j<mi->get_child_count();j++) { Node *child2 = mi->get_child(j); if (!child2->cast_to<NavigationMeshInstance>()) continue; NavigationMeshInstance *sb = child2->cast_to<NavigationMeshInstance>(); navmesh=sb->get_navigation_mesh(); if (!navmesh.is_null()) break; } if(!navmesh.is_null()){ p_library->set_item_navmesh(id, navmesh); } } //generate previews! if (1) { Vector<int> ids = p_library->get_item_list(); RID vp = VS::get_singleton()->viewport_create(); VS::ViewportRect vr; vr.x=0; vr.y=0; vr.width=EditorSettings::get_singleton()->get("editors/grid_map/preview_size"); vr.height=EditorSettings::get_singleton()->get("editors/grid_map/preview_size"); VS::get_singleton()->viewport_set_rect(vp,vr); VS::get_singleton()->viewport_set_as_render_target(vp,true); VS::get_singleton()->viewport_set_render_target_update_mode(vp,VS::RENDER_TARGET_UPDATE_ALWAYS); RID scen = VS::get_singleton()->scenario_create(); VS::get_singleton()->viewport_set_scenario(vp,scen); RID cam = VS::get_singleton()->camera_create(); VS::get_singleton()->camera_set_transform(cam, Transform() ); VS::get_singleton()->viewport_attach_camera(vp,cam); RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); RID lightinst = VS::get_singleton()->instance_create2(light,scen); VS::get_singleton()->camera_set_orthogonal(cam,1.0,0.01,1000.0); EditorProgress ep("mlib",TTR("Creating Mesh Library"),ids.size()); for(int i=0;i<ids.size();i++) { int id=ids[i]; Ref<Mesh> mesh = p_library->get_item_mesh(id); if (!mesh.is_valid()) continue; AABB aabb= mesh->get_aabb(); print_line("aabb: "+aabb); Vector3 ofs = aabb.pos + aabb.size*0.5; aabb.pos-=ofs; Transform xform; xform.basis=Matrix3().rotated(Vector3(0,1,0),-Math_PI*0.25); xform.basis = Matrix3().rotated(Vector3(1,0,0),Math_PI*0.25)*xform.basis; AABB rot_aabb = xform.xform(aabb); print_line("rot_aabb: "+rot_aabb); float m = MAX(rot_aabb.size.x,rot_aabb.size.y)*0.5; if (m==0) continue; m=1.0/m; m*=0.5; print_line("scale: "+rtos(m)); xform.basis.scale(Vector3(m,m,m)); xform.origin=-xform.basis.xform(ofs); //-ofs*m; xform.origin.z-=rot_aabb.size.z*2; RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(),scen); VS::get_singleton()->instance_set_transform(inst,xform); ep.step(TTR("Thumbnail.."),i); VS::get_singleton()->viewport_queue_screen_capture(vp); Main::iteration(); Image img = VS::get_singleton()->viewport_get_screen_capture(vp); ERR_CONTINUE(img.empty()); Ref<ImageTexture> it( memnew( ImageTexture )); it->create_from_image(img); p_library->set_item_preview(id,it); //print_line("loaded image, size: "+rtos(m)+" dist: "+rtos(dist)+" empty?"+itos(img.empty())+" w: "+itos(it->get_width())+" h: "+itos(it->get_height())); VS::get_singleton()->free(inst); } VS::get_singleton()->free(lightinst); VS::get_singleton()->free(light); VS::get_singleton()->free(vp); VS::get_singleton()->free(cam); VS::get_singleton()->free(scen); } }
PluginConfigDialog::PluginConfigDialog() { get_ok()->set_disabled(true); set_hide_on_ok(true); GridContainer *grid = memnew(GridContainer); grid->set_columns(2); add_child(grid); Label *name_lb = memnew(Label); name_lb->set_text(TTR("Plugin Name:")); grid->add_child(name_lb); name_edit = memnew(LineEdit); name_edit->connect("text_changed", this, "_on_required_text_changed"); name_edit->set_placeholder("MyPlugin"); grid->add_child(name_edit); Label *subfolder_lb = memnew(Label); subfolder_lb->set_text(TTR("Subfolder:")); grid->add_child(subfolder_lb); subfolder_edit = memnew(LineEdit); subfolder_edit->set_placeholder("\"my_plugin\" -> res://addons/my_plugin"); grid->add_child(subfolder_edit); Label *desc_lb = memnew(Label); desc_lb->set_text(TTR("Description:")); grid->add_child(desc_lb); desc_edit = memnew(TextEdit); desc_edit->set_custom_minimum_size(Size2(400, 80) * EDSCALE); grid->add_child(desc_edit); Label *author_lb = memnew(Label); author_lb->set_text(TTR("Author:")); grid->add_child(author_lb); author_edit = memnew(LineEdit); author_edit->set_placeholder("Godette"); grid->add_child(author_edit); Label *version_lb = memnew(Label); version_lb->set_text(TTR("Version:")); grid->add_child(version_lb); version_edit = memnew(LineEdit); version_edit->set_placeholder("1.0"); grid->add_child(version_edit); Label *script_option_lb = memnew(Label); script_option_lb->set_text(TTR("Language:")); grid->add_child(script_option_lb); script_option_edit = memnew(OptionButton); int default_lang = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptLanguage *lang = ScriptServer::get_language(i); script_option_edit->add_item(lang->get_name()); if (lang == GDScriptLanguage::get_singleton()) { default_lang = i; } } script_option_edit->select(default_lang); grid->add_child(script_option_edit); Label *script_lb = memnew(Label); script_lb->set_text(TTR("Script Name:")); grid->add_child(script_lb); script_edit = memnew(LineEdit); script_edit->connect("text_changed", this, "_on_required_text_changed"); script_edit->set_placeholder("\"plugin.gd\" -> res://addons/my_plugin/plugin.gd"); grid->add_child(script_edit); // TODO Make this option work better with languages like C#. Right now, it does not work because the C# project must be compiled first. Label *active_lb = memnew(Label); active_lb->set_text(TTR("Activate now?")); grid->add_child(active_lb); active_edit = memnew(CheckBox); active_edit->set_pressed(true); grid->add_child(active_edit); }
void CurveEditor::_draw() { if (_curve_ref.is_null()) return; Curve &curve = **_curve_ref; update_view_transform(); // Background Vector2 view_size = get_rect().size; draw_style_box(get_stylebox("bg", "Tree"), Rect2(Point2(), view_size)); // Grid draw_set_transform_matrix(_world_to_view); Vector2 min_edge = get_world_pos(Vector2(0, view_size.y)); Vector2 max_edge = get_world_pos(Vector2(view_size.x, 0)); const Color grid_color0 = Color(1.0, 1.0, 1.0, 0.15); const Color grid_color1 = Color(1.0, 1.0, 1.0, 0.07); draw_line(Vector2(min_edge.x, curve.get_min_value()), Vector2(max_edge.x, curve.get_min_value()), grid_color0); draw_line(Vector2(max_edge.x, curve.get_max_value()), Vector2(min_edge.x, curve.get_max_value()), grid_color0); draw_line(Vector2(0, min_edge.y), Vector2(0, max_edge.y), grid_color0); draw_line(Vector2(1, max_edge.y), Vector2(1, min_edge.y), grid_color0); float curve_height = (curve.get_max_value() - curve.get_min_value()); const Vector2 grid_step(0.25, 0.5 * curve_height); for (real_t x = 0; x < 1.0; x += grid_step.x) { draw_line(Vector2(x, min_edge.y), Vector2(x, max_edge.y), grid_color1); } for (real_t y = curve.get_min_value(); y < curve.get_max_value(); y += grid_step.y) { draw_line(Vector2(min_edge.x, y), Vector2(max_edge.x, y), grid_color1); } // Markings draw_set_transform_matrix(Transform2D()); Ref<Font> font = get_font("font", "Label"); float font_height = font->get_height(); Color text_color = get_color("font_color", "Editor"); { // X axis float y = curve.get_min_value(); Vector2 off(0, font_height - 1); draw_string(font, get_view_pos(Vector2(0, y)) + off, "0.0", text_color); draw_string(font, get_view_pos(Vector2(0.25, y)) + off, "0.25", text_color); draw_string(font, get_view_pos(Vector2(0.5, y)) + off, "0.5", text_color); draw_string(font, get_view_pos(Vector2(0.75, y)) + off, "0.75", text_color); draw_string(font, get_view_pos(Vector2(1, y)) + off, "1.0", text_color); } { // Y axis float m0 = curve.get_min_value(); float m1 = 0.5 * (curve.get_min_value() + curve.get_max_value()); float m2 = curve.get_max_value(); Vector2 off(1, -1); draw_string(font, get_view_pos(Vector2(0, m0)) + off, String::num(m0, 2), text_color); draw_string(font, get_view_pos(Vector2(0, m1)) + off, String::num(m1, 2), text_color); draw_string(font, get_view_pos(Vector2(0, m2)) + off, String::num(m2, 3), text_color); } // Draw tangents for current point if (_selected_point >= 0) { const Color tangent_color = get_color("accent_color", "Editor"); int i = _selected_point; Vector2 pos = curve.get_point_position(i); if (i != 0) { Vector2 control_pos = get_tangent_view_pos(i, TANGENT_LEFT); draw_line(get_view_pos(pos), control_pos, tangent_color); draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(2), tangent_color); } if (i != curve.get_point_count() - 1) { Vector2 control_pos = get_tangent_view_pos(i, TANGENT_RIGHT); draw_line(get_view_pos(pos), control_pos, tangent_color); draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(2), tangent_color); } } // Draw lines draw_set_transform_matrix(_world_to_view); const Color line_color = get_color("highlight_color", "Editor"); const Color edge_line_color = get_color("font_color", "Editor"); CanvasItemPlotCurve plot_func(*this, line_color, edge_line_color); plot_curve_accurate(curve, 4.f / view_size.x, plot_func); // Draw points draw_set_transform_matrix(Transform2D()); const Color point_color = get_color("font_color", "Editor"); const Color selected_point_color = get_color("accent_color", "Editor"); for (int i = 0; i < curve.get_point_count(); ++i) { Vector2 pos = curve.get_point_position(i); draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(3), i == _selected_point ? selected_point_color : point_color); // TODO Circles are prettier. Needs a fix! Or a texture //draw_circle(pos, 2, point_color); } // Hover if (_hover_point != -1) { const Color hover_color = line_color; Vector2 pos = curve.get_point_position(_hover_point); stroke_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(_hover_radius), hover_color); } // Help text if (_selected_point > 0 && _selected_point + 1 < curve.get_point_count()) { text_color.a *= 0.4; draw_string(font, Vector2(50, font_height), TTR("Hold Shift to edit tangents individually"), text_color); } }
bool CollisionPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (!node) return false; Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mb->get_position(); Vector2 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); Vector<Vector2> poly = node->get_polygon(); //first check if a point is to be added (segment split) real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8); switch (mode) { case MODE_CREATE: { if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { if (!wip_active) { wip.clear(); wip.push_back(cpoint); wip_active = true; edited_point_pos = cpoint; canvas_item_editor->get_viewport_control()->update(); edited_point = 1; return true; } else { if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_threshold) { //wip closed _wip_close(); return true; } else { wip.push_back(cpoint); edited_point = wip.size(); canvas_item_editor->get_viewport_control()->update(); return true; //add wip point } } } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) { _wip_close(); } } break; case MODE_EDIT: { if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { if (mb->get_control()) { if (poly.size() < 3) { undo_redo->create_action(TTR("Edit 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->commit_action(); return true; } //search edges int closest_idx = -1; Vector2 closest_pos; 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 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_threshold) { closest_dist = d; closest_pos = cp; closest_idx = i; } } 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); node->set_polygon(poly); canvas_item_editor->get_viewport_control()->update(); return true; } } else { //look for points to move int closest_idx = -1; Vector2 closest_pos; real_t closest_dist = 1e10; for (int i = 0; i < poly.size(); i++) { Vector2 cp = xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); if (d < closest_dist && d < grab_threshold) { closest_dist = d; closest_pos = cp; closest_idx = i; } } if (closest_idx >= 0) { 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) { //apply 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->commit_action(); edited_point = -1; return true; } } } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) { int closest_idx = -1; Vector2 closest_pos; real_t closest_dist = 1e10; for (int i = 0; i < poly.size(); i++) { Vector2 cp = xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); if (d < closest_dist && d < grab_threshold) { closest_dist = d; closest_pos = cp; closest_idx = i; } } if (closest_idx >= 0) { undo_redo->create_action(TTR("Edit Poly (Remove Point)")); 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->commit_action(); return true; } } } break; } } Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); 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(); } } return false; }
void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb_ref = p_event; if (mb_ref.is_valid()) { const InputEventMouseButton &mb = **mb_ref; if (mb.is_pressed() && !_dragging) { Vector2 mpos = mb.get_position(); _selected_tangent = get_tangent_at(mpos); if (_selected_tangent == TANGENT_NONE) set_selected_point(get_point_at(mpos)); switch (mb.get_button_index()) { case BUTTON_RIGHT: _context_click_pos = mpos; open_context_menu(get_global_transform().xform(mpos)); break; case BUTTON_MIDDLE: remove_point(_hover_point); break; case BUTTON_LEFT: _dragging = true; break; } } if (!mb.is_pressed() && _dragging && mb.get_button_index() == BUTTON_LEFT) { _dragging = false; if (_has_undo_data) { UndoRedo &ur = *EditorNode::get_singleton()->get_undo_redo(); ur.create_action(_selected_tangent == TANGENT_NONE ? TTR("Modify Curve Point") : TTR("Modify Curve Tangent")); ur.add_do_method(*_curve_ref, "_set_data", _curve_ref->get_data()); ur.add_undo_method(*_curve_ref, "_set_data", _undo_data); // Note: this will trigger one more "changed" signal even if nothing changes, // but it's ok since it would have fired every frame during the drag anyways ur.commit_action(); _has_undo_data = false; } } } Ref<InputEventMouseMotion> mm_ref = p_event; if (mm_ref.is_valid()) { const InputEventMouseMotion &mm = **mm_ref; Vector2 mpos = mm.get_position(); if (_dragging && _curve_ref.is_valid()) { Curve &curve = **_curve_ref; if (_selected_point != -1) { if (!_has_undo_data) { // Save full curve state before dragging points, // because this operation can modify their order _undo_data = curve.get_data(); _has_undo_data = true; } if (_selected_tangent == TANGENT_NONE) { // Drag point Vector2 point_pos = get_world_pos(mpos); int i = curve.set_point_offset(_selected_point, point_pos.x); // The index may change if the point is dragged across another one set_hover_point_index(i); set_selected_point(i); // This is to prevent the user from losing a point out of view. if (point_pos.y < curve.get_min_value()) point_pos.y = curve.get_min_value(); else if (point_pos.y > curve.get_max_value()) point_pos.y = curve.get_max_value(); curve.set_point_value(_selected_point, point_pos.y); } else { // Drag tangent Vector2 point_pos = curve.get_point_position(_selected_point); Vector2 control_pos = get_world_pos(mpos); Vector2 dir = (control_pos - point_pos).normalized(); real_t tangent; if (Math::abs(dir.x) > CMP_EPSILON) tangent = dir.y / dir.x; else tangent = 9999 * (dir.y >= 0 ? 1 : -1); bool link = !Input::get_singleton()->is_key_pressed(KEY_SHIFT); if (_selected_tangent == TANGENT_LEFT) { curve.set_point_left_tangent(_selected_point, tangent); // Note: if a tangent is set to linear, it shouldn't be linked to the other if (link && _selected_point != (curve.get_point_count() - 1) && curve.get_point_right_mode(_selected_point) != Curve::TANGENT_LINEAR) curve.set_point_right_tangent(_selected_point, tangent); } else { curve.set_point_right_tangent(_selected_point, tangent); if (link && _selected_point != 0 && curve.get_point_left_mode(_selected_point) != Curve::TANGENT_LINEAR) curve.set_point_left_tangent(_selected_point, tangent); } } } } else { set_hover_point_index(get_point_at(mpos)); } } Ref<InputEventKey> key_ref = p_event; if (key_ref.is_valid()) { const InputEventKey &key = **key_ref; if (key.is_pressed() && _selected_point != -1) { if (key.get_scancode() == KEY_DELETE) remove_point(_selected_point); } } }
AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { editor=p_editor; singleton=this; updating=false; set_focus_mode(FOCUS_ALL); player=NULL; add_style_override("panel", get_stylebox("panel","Panel")); Label * l; /*l= memnew( Label ); l->set_text("Animation Player:"); add_child(l);*/ HBoxContainer *hb = memnew( HBoxContainer ); add_child(hb); 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->set_tooltip(TTR("Play selected animation backwards from end. (Shift+A)")); hb->add_child(play_bw); stop = memnew( ToolButton ); stop->set_toggle_mode(true); hb->add_child(stop); stop->set_tooltip(TTR("Stop animation playback. (S)")); play = memnew( ToolButton ); play->set_tooltip(TTR("Play selected animation from start. (Shift+D)")); hb->add_child(play); 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 ); hb->add_child(frame); 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)); 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 ); 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 ); 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.")); hb->add_child(load_anim); save_anim = memnew(MenuButton); save_anim->set_tooltip(TTR("Save the current animation")); save_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/save", TTR("Save")), ANIM_SAVE); save_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/save_as", TTR("Save As")), ANIM_SAVE_AS); save_anim->set_focus_mode(Control::FOCUS_NONE); hb->add_child(save_anim); accept = memnew(AcceptDialog); add_child(accept); accept->connect("confirmed", this, "_menu_confirm_current"); 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 ); 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 ); 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 ); 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 ); hb->add_child(autoplay); autoplay->set_tooltip(TTR("Autoplay on Load")); blend_anim = memnew( ToolButton ); hb->add_child(blend_anim); blend_anim->set_tooltip(TTR("Edit Target Blend Times")); 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_separator(); //tool_anim->get_popup()->add_item("Edit Anim Resource",TOOL_PASTE_ANIM); hb->add_child(tool_anim); nodename = memnew( Button ); hb->add_child(nodename); pin = memnew( ToolButton ); pin->set_toggle_mode(true); hb->add_child(pin); 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->set_title(TTR("Create New Animation")); name_dialog->set_hide_on_ok(false); add_child(name_dialog); 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_dialog->register_text_enter(name); l = memnew( Label ); l->set_text(TTR("Animation Name:")); l->set_pos( Point2(10,10) ); name_dialog->add_child(l); name_title=l; 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"); 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); blend_editor.dialog->add_child(blend_vb); blend_editor.dialog->set_child_rect(blend_vb); 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_editor.dialog->set_title(TTR("Cross-Animation Blend Times")); updating_blends=false; blend_editor.tree->connect("item_edited",this,"_blend_edited"); 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"); //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"); //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); renaming=false; last_active=false; set_process_unhandled_key_input(true); key_editor = memnew( AnimationKeyEditor); add_child(key_editor); 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"); _update_player(); }
void AnimationPlayerEditor::_animation_tool_menu(int p_option) { switch(p_option) { case TOOL_COPY_ANIM: { if (!animation->get_item_count()) { error_dialog->set_text(TTR("ERROR: No animation to copy!")); error_dialog->popup_centered_minsize(); return; } String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); //editor->edit_resource(anim); EditorSettings::get_singleton()->set_resource_clipboard(anim); } break; case TOOL_PASTE_ANIM: { Ref<Animation> anim = EditorSettings::get_singleton()->get_resource_clipboard(); if (!anim.is_valid()) { error_dialog->set_text(TTR("ERROR: No animation resource on clipboard!")); error_dialog->popup_centered_minsize(); return; } String name = anim->get_name(); if (name=="") { name=TTR("Pasted Animation"); } int idx=1; String base = name; while (player->has_animation(name)) { 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->commit_action(); _select_anim_by_name(name); } break; case TOOL_EDIT_RESOURCE: { if (!animation->get_item_count()) { error_dialog->set_text(TTR("ERROR: No animation to edit!")); error_dialog->popup_centered_minsize(); return; } String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); editor->edit_resource(anim); } break; } }
void ConnectionsDock::update_tree() { tree->clear(); if (!node) return; TreeItem *root = tree->create_item(); List<MethodInfo> node_signals; node->get_signal_list(&node_signals); //node_signals.sort_custom<_ConnectionsDockMethodInfoSort>(); bool did_script = false; StringName base = node->get_class(); while (base) { List<MethodInfo> node_signals; Ref<Texture> icon; String name; if (!did_script) { Ref<Script> scr = node->get_script(); if (scr.is_valid()) { scr->get_script_signal_list(&node_signals); if (scr->get_path().is_resource_file()) name = scr->get_path().get_file(); else name = scr->get_class(); if (has_icon(scr->get_class(), "EditorIcons")) { icon = get_icon(scr->get_class(), "EditorIcons"); } } } else { ClassDB::get_signal_list(base, &node_signals, true); if (has_icon(base, "EditorIcons")) { icon = get_icon(base, "EditorIcons"); } name = base; } TreeItem *pitem = NULL; if (node_signals.size()) { pitem = tree->create_item(root); pitem->set_text(0, name); pitem->set_icon(0, icon); pitem->set_selectable(0, false); pitem->set_editable(0, false); pitem->set_custom_bg_color(0, get_color("prop_subsection", "Editor")); node_signals.sort(); } for (List<MethodInfo>::Element *E = node_signals.front(); E; E = E->next()) { MethodInfo &mi = E->get(); String signaldesc; signaldesc = mi.name + "("; PoolStringArray argnames; if (mi.arguments.size()) { signaldesc += " "; for (int i = 0; i < mi.arguments.size(); i++) { PropertyInfo &pi = mi.arguments[i]; if (i > 0) signaldesc += ", "; String tname = "var"; if (pi.type != Variant::NIL) { tname = Variant::get_type_name(pi.type); } signaldesc += tname + " " + (pi.name == "" ? String("arg " + itos(i)) : pi.name); argnames.push_back(pi.name + ":" + tname); } signaldesc += " "; } signaldesc += ")"; TreeItem *item = tree->create_item(pitem); item->set_text(0, signaldesc); Dictionary sinfo; sinfo["name"] = mi.name; sinfo["args"] = argnames; item->set_metadata(0, sinfo); item->set_icon(0, get_icon("Signal", "EditorIcons")); List<Object::Connection> connections; node->get_signal_connection_list(mi.name, &connections); for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) { Object::Connection &c = F->get(); if (!(c.flags & CONNECT_PERSIST)) continue; Node *target = Object::cast_to<Node>(c.target); if (!target) continue; String path = String(node->get_path_to(target)) + " :: " + c.method + "()"; if (c.flags & CONNECT_DEFERRED) path += " (deferred)"; if (c.flags & CONNECT_ONESHOT) path += " (oneshot)"; if (c.binds.size()) { path += " binds( "; for (int i = 0; i < c.binds.size(); i++) { if (i > 0) path += ", "; path += c.binds[i].operator String(); } path += " )"; } TreeItem *item2 = tree->create_item(item); item2->set_text(0, path); item2->set_metadata(0, c); item2->set_icon(0, get_icon("Slot", "EditorIcons")); } } if (!did_script) { did_script = true; } else { base = ClassDB::get_parent_class(base); } } connect_button->set_text(TTR("Connect")); connect_button->set_disabled(true); }
void ItemListOptionButtonPlugin::add_item() { ob->add_item(vformat(TTR("Item %d"), ob->get_item_count())); _change_notify(); }
void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node()); if (Object::cast_to<CSGSphere>(cs)) { CSGSphere *s = Object::cast_to<CSGSphere>(cs); if (p_cancel) { s->set_radius(p_restore); return; } UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); ur->create_action(TTR("Change Sphere Shape Radius")); ur->add_do_method(s, "set_radius", s->get_radius()); ur->add_undo_method(s, "set_radius", p_restore); ur->commit_action(); } if (Object::cast_to<CSGBox>(cs)) { CSGBox *s = Object::cast_to<CSGBox>(cs); if (p_cancel) { switch (p_idx) { case 0: s->set_width(p_restore); break; case 1: s->set_height(p_restore); break; case 2: s->set_depth(p_restore); break; } return; } UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); ur->create_action(TTR("Change Box Shape Extents")); static const char *method[3] = { "set_width", "set_height", "set_depth" }; float current; switch (p_idx) { case 0: current = s->get_width(); break; case 1: current = s->get_height(); break; case 2: current = s->get_depth(); break; } ur->add_do_method(s, method[p_idx], current); ur->add_undo_method(s, method[p_idx], p_restore); ur->commit_action(); } if (Object::cast_to<CSGCylinder>(cs)) { CSGCylinder *s = Object::cast_to<CSGCylinder>(cs); if (p_cancel) { if (p_idx == 0) s->set_radius(p_restore); else s->set_height(p_restore); return; } UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); if (p_idx == 0) { ur->create_action(TTR("Change Cylinder Radius")); ur->add_do_method(s, "set_radius", s->get_radius()); ur->add_undo_method(s, "set_radius", p_restore); } else { ur->create_action(TTR("Change Cylinder Height")); ur->add_do_method(s, "set_height", s->get_height()); ur->add_undo_method(s, "set_height", p_restore); } ur->commit_action(); } if (Object::cast_to<CSGTorus>(cs)) { CSGTorus *s = Object::cast_to<CSGTorus>(cs); if (p_cancel) { if (p_idx == 0) s->set_inner_radius(p_restore); else s->set_outer_radius(p_restore); return; } UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); if (p_idx == 0) { ur->create_action(TTR("Change Torus Inner Radius")); ur->add_do_method(s, "set_inner_radius", s->get_inner_radius()); ur->add_undo_method(s, "set_inner_radius", p_restore); } else { ur->create_action(TTR("Change Torus Outer Radius")); ur->add_do_method(s, "set_outer_radius", s->get_outer_radius()); ur->add_undo_method(s, "set_outer_radius", p_restore); } ur->commit_action(); } }
void ItemListItemListPlugin::add_item() { pp->add_item(vformat(TTR("Item %d"), pp->get_item_count())); _change_notify(); }
bool NavigationPolygonEditor::forward_input_event(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) { 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);; } switch(p_event.type) { case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton &mb=p_event.mouse_button; Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); 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 = 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("poly_editor/point_grab_radius",8); switch(mode) { case MODE_CREATE: { 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; canvas_item_editor->get_viewport_control()->update(); edited_point=1; return true; } else { 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(); canvas_item_editor->get_viewport_control()->update(); return true; //add wip point } } } 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.pressed) { if (mb.mod.control) { //search edges 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++) { DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j); int pc=points.size(); DVector<Vector2>::Read poly=points.read(); for(int i=0;i<pc;i++) { 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) 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 (closest_idx>=0) { pre_move_edit=node->get_navigation_polygon()->get_outline(closest_outline); DVector<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); canvas_item_editor->get_viewport_control()->update(); return true; } } else { //look for points to move 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++) { DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j); int pc=points.size(); DVector<Vector2>::Read poly=points.read(); for(int i=0;i<pc;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 (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); canvas_item_editor->get_viewport_control()->update(); return true; } } } else { if (edited_point!=-1) { //apply DVector<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); 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->commit_action(); edited_point=-1; return true; } } } if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-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++) { DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j); int pc=points.size(); DVector<Vector2>::Read poly=points.read(); for(int i=0;i<pc;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 (closest_idx>=0) { DVector<Vector2> poly = node->get_navigation_polygon()->get_outline(closest_outline); 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); 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->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); 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->commit_action(); } return true; } } } break; } } break; case InputEvent::MOUSE_MOTION: { const InputEventMouseMotion &mm=p_event.mouse_motion; if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { 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); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); } } break; } return false; }
void SpriteFramesEditor::_update_library(bool p_skip_selector) { updating = true; if (!p_skip_selector) { animations->clear(); TreeItem *anim_root = animations->create_item(); List<StringName> anim_names; anim_names.sort_custom<StringName::AlphCompare>(); frames->get_animation_list(&anim_names); anim_names.sort_custom<StringName::AlphCompare>(); 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_text(0, name); it->set_editable(0, true); if (E->get() == edited_anim) { it->select(0); } } } tree->clear(); if (!frames->has_animation(edited_anim)) { 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; 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()) { name = itos(i) + ": " + TTR("(empty)"); } else { 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); } anim_speed->set_value(frames->get_animation_speed(edited_anim)); anim_loop->set_pressed(frames->get_animation_loop(edited_anim)); updating = false; //player->add_resource("default",resource); }
FindReplaceBar::FindReplaceBar() { container = memnew(MarginContainer); container->add_constant_override("margin_bottom", 5 * EDSCALE); add_child(container); container->set_clip_contents(true); container->set_h_size_flags(SIZE_EXPAND_FILL); replace_all_mode = false; preserve_cursor = false; hbc = memnew(HBoxContainer); container->add_child(hbc); hbc->set_anchor_and_margin(MARGIN_RIGHT, 1, 0); vbc_lineedit = memnew(VBoxContainer); hbc->add_child(vbc_lineedit); vbc_lineedit->set_h_size_flags(SIZE_EXPAND_FILL); VBoxContainer *vbc_button = memnew(VBoxContainer); hbc->add_child(vbc_button); VBoxContainer *vbc_option = memnew(VBoxContainer); hbc->add_child(vbc_option); HBoxContainer *hbc_button_search = memnew(HBoxContainer); vbc_button->add_child(hbc_button_search); hbc_button_replace = memnew(HBoxContainer); vbc_button->add_child(hbc_button_replace); HBoxContainer *hbc_option_search = memnew(HBoxContainer); vbc_option->add_child(hbc_option_search); hbc_option_replace = memnew(HBoxContainer); vbc_option->add_child(hbc_option_replace); // search toolbar search_text = memnew(LineEdit); vbc_lineedit->add_child(search_text); search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); search_text->connect("text_changed", this, "_search_text_changed"); search_text->connect("text_entered", this, "_search_text_entered"); find_prev = memnew(ToolButton); hbc_button_search->add_child(find_prev); find_prev->set_focus_mode(FOCUS_NONE); find_prev->connect("pressed", this, "_search_prev"); find_next = memnew(ToolButton); hbc_button_search->add_child(find_next); find_next->set_focus_mode(FOCUS_NONE); find_next->connect("pressed", this, "_search_next"); case_sensitive = memnew(CheckBox); hbc_option_search->add_child(case_sensitive); case_sensitive->set_text(TTR("Match Case")); case_sensitive->set_focus_mode(FOCUS_NONE); case_sensitive->connect("toggled", this, "_search_options_changed"); whole_words = memnew(CheckBox); hbc_option_search->add_child(whole_words); whole_words->set_text(TTR("Whole Words")); whole_words->set_focus_mode(FOCUS_NONE); whole_words->connect("toggled", this, "_search_options_changed"); // replace toolbar replace_text = memnew(LineEdit); vbc_lineedit->add_child(replace_text); replace_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); replace_text->connect("text_entered", this, "_replace_text_entered"); replace = memnew(Button); hbc_button_replace->add_child(replace); replace->set_text(TTR("Replace")); replace->connect("pressed", this, "_replace_pressed"); replace_all = memnew(Button); hbc_button_replace->add_child(replace_all); replace_all->set_text(TTR("Replace All")); replace_all->connect("pressed", this, "_replace_all_pressed"); selection_only = memnew(CheckBox); hbc_option_replace->add_child(selection_only); selection_only->set_text(TTR("Selection Only")); selection_only->set_focus_mode(FOCUS_NONE); selection_only->connect("toggled", this, "_search_options_changed"); hide_button = memnew(TextureButton); add_child(hide_button); hide_button->set_focus_mode(FOCUS_NONE); hide_button->connect("pressed", this, "_hide_pressed"); hide_button->set_v_size_flags(SIZE_SHRINK_CENTER); }
SpriteFramesEditor::SpriteFramesEditor() { //add_style_override("panel", get_stylebox("panel","Panel")); split = memnew(HSplitContainer); add_child(split); VBoxContainer *vbc_animlist = memnew(VBoxContainer); split->add_child(vbc_animlist); 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); sub_vb->set_v_size_flags(SIZE_EXPAND_FILL); HBoxContainer *hbc_animlist = memnew(HBoxContainer); sub_vb->add_child(hbc_animlist); new_anim = memnew(Button); hbc_animlist->add_child(new_anim); new_anim->connect("pressed", this, "_animation_add"); hbc_animlist->add_spacer(); remove_anim = memnew(Button); hbc_animlist->add_child(remove_anim); remove_anim->connect("pressed", this, "_animation_remove"); 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->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->set_min(0); anim_speed->set_max(100); anim_speed->set_step(0.01); anim_speed->connect("value_changed", this, "_animation_fps_changed"); anim_loop = memnew(CheckButton); anim_loop->set_text(TTR("Loop")); vbc_animlist->add_child(anim_loop); anim_loop->connect("pressed", this, "_animation_loop_changed"); 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); HBoxContainer *hbc = memnew(HBoxContainer); sub_vb->add_child(hbc); //animations = memnew( ItemList ); load = memnew(Button); load->set_tooltip(TTR("Load Resource")); hbc->add_child(load); paste = memnew(Button); paste->set_text(TTR("Paste")); hbc->add_child(paste); empty = memnew(Button); empty->set_text(TTR("Insert Empty (Before)")); hbc->add_child(empty); empty2 = memnew(Button); empty2->set_text(TTR("Insert Empty (After)")); hbc->add_child(empty2); move_up = memnew(Button); move_up->set_text(TTR("Up")); hbc->add_child(move_up); move_down = memnew(Button); move_down->set_text(TTR("Down")); hbc->add_child(move_down); _delete = memnew(Button); hbc->add_child(_delete); file = memnew(EditorFileDialog); add_child(file); 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_max_text_lines(2); 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->connect("confirmed", this,"_delete_confirm_pressed"); //tree->connect("item_selected", this,"_item_edited"); loading_scene = false; sel = -1; updating = false; edited_anim = "default"; }
void CreateDialog::set_base_type(const String &p_base) { base_type = p_base; set_title(TTR("Create New") + " " + p_base); _update_search(); }
void EditorAssetInstaller::ok_pressed() { FileAccess *src_f = NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); unzFile pkg = unzOpen2(package_path.utf8().get_data(), &io); if (!pkg) { error->set_text(TTR("Error opening package file, not in zip format.")); return; } int ret = unzGoToFirstFile(pkg); Vector<String> failed_files; ProgressDialog::get_singleton()->add_task("uncompress", TTR("Uncompressing Assets"), status_map.size()); int idx = 0; while (ret == UNZ_OK) { //get filename unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); String name = fname; if (status_map.has(name) && status_map[name]->is_checked(0)) { String path = status_map[name]->get_metadata(0); if (path == String()) { // a dir String dirpath; TreeItem *t = status_map[name]; while (t) { dirpath = t->get_text(0) + dirpath; t = t->get_parent(); } if (dirpath.ends_with("/")) { dirpath = dirpath.substr(0, dirpath.length() - 1); } DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); da->make_dir(dirpath); memdelete(da); } else { Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); unzReadCurrentFile(pkg, data.ptrw(), data.size()); unzCloseCurrentFile(pkg); FileAccess *f = FileAccess::open(path, FileAccess::WRITE); if (f) { f->store_buffer(data.ptr(), data.size()); memdelete(f); } else { failed_files.push_back(path); } ProgressDialog::get_singleton()->task_step("uncompress", path, idx); } } idx++; ret = unzGoToNextFile(pkg); } ProgressDialog::get_singleton()->end_task("uncompress"); unzClose(pkg); if (failed_files.size()) { String msg = "The following files failed extraction from package:\n\n"; for (int i = 0; i < failed_files.size(); i++) { if (i > 15) { msg += "\nAnd " + itos(failed_files.size() - i) + " more files."; break; } msg += failed_files[i]; } if (EditorNode::get_singleton() != NULL) EditorNode::get_singleton()->show_warning(msg); } else { if (EditorNode::get_singleton() != NULL) EditorNode::get_singleton()->show_warning(TTR("Package Installed Successfully!"), TTR("Success!")); } EditorFileSystem::get_singleton()->scan_changes(); }
Error EditorMeshImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){ ERR_FAIL_COND_V(p_from->get_source_count()!=1,ERR_INVALID_PARAMETER); Ref<ResourceImportMetadata> from=p_from; String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0)); FileAccessRef f = FileAccess::open(src_path,FileAccess::READ); ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); Ref<Mesh> mesh; Map<String,Ref<Material> > name_map; if (FileAccess::exists(p_path)) { mesh=ResourceLoader::load(p_path,"Mesh"); if (mesh.is_valid()) { for(int i=0;i<mesh->get_surface_count();i++) { if (!mesh->surface_get_material(i).is_valid()) continue; String name; if (mesh->surface_get_name(i)!="") name=mesh->surface_get_name(i); else name=vformat(TTR("Surface %d"),i+1); name_map[name]=mesh->surface_get_material(i); } while(mesh->get_surface_count()) { mesh->surface_remove(0); } } } if (!mesh.is_valid()) mesh = Ref<Mesh>( memnew( Mesh ) ); bool generate_normals=from->get_option("generate/normals"); bool generate_tangents=from->get_option("generate/tangents"); bool flip_faces=from->get_option("force/flip_faces"); bool force_smooth=from->get_option("force/smooth_shading"); bool weld_vertices=from->get_option("force/weld_vertices"); float weld_tolerance=from->get_option("force/weld_tolerance"); Vector<Vector3> vertices; Vector<Vector3> normals; Vector<Vector2> uvs; String name; Ref<SurfaceTool> surf_tool = memnew( SurfaceTool) ; surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES); if (force_smooth) surf_tool->add_smooth_group(true); int has_index_data=false; while(true) { String l = f->get_line().strip_edges(); if (l.begins_with("v ")) { //vertex Vector<String> v = l.split(" ",false); ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA); Vector3 vtx; vtx.x=v[1].to_float(); vtx.y=v[2].to_float(); vtx.z=v[3].to_float(); vertices.push_back(vtx); } else if (l.begins_with("vt ")) { //uv Vector<String> v = l.split(" ",false); ERR_FAIL_COND_V(v.size()<3,ERR_INVALID_DATA); Vector2 uv; uv.x=v[1].to_float(); uv.y=1.0-v[2].to_float(); uvs.push_back(uv); } else if (l.begins_with("vn ")) { //normal Vector<String> v = l.split(" ",false); ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA); Vector3 nrm; nrm.x=v[1].to_float(); nrm.y=v[2].to_float(); nrm.z=v[3].to_float(); normals.push_back(nrm); } if (l.begins_with("f ")) { //vertex has_index_data=true; Vector<String> v = l.split(" ",false); ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA); //not very fast, could be sped up Vector<String> face[3]; face[0] = v[1].split("/"); face[1] = v[2].split("/"); ERR_FAIL_COND_V(face[0].size()==0,ERR_PARSE_ERROR); ERR_FAIL_COND_V(face[0].size()!=face[1].size(),ERR_PARSE_ERROR); for(int i=2;i<v.size()-1;i++) { face[2] = v[i+1].split("/"); ERR_FAIL_COND_V(face[0].size()!=face[2].size(),ERR_PARSE_ERROR); for(int j=0;j<3;j++) { int idx=j; if (!flip_faces && idx<2) { idx=1^idx; } if (face[idx].size()==3) { int norm = face[idx][2].to_int()-1; ERR_FAIL_INDEX_V(norm,normals.size(),ERR_PARSE_ERROR); surf_tool->add_normal(normals[norm]); } if (face[idx].size()>=2 && face[idx][1]!=String()) { int uv = face[idx][1].to_int()-1; ERR_FAIL_INDEX_V(uv,uvs.size(),ERR_PARSE_ERROR); surf_tool->add_uv(uvs[uv]); } int vtx = face[idx][0].to_int()-1; print_line("vtx: "+itos(vtx)+"/"+itos(vertices.size())); ERR_FAIL_INDEX_V(vtx,vertices.size(),ERR_PARSE_ERROR); Vector3 vertex = vertices[vtx]; if (weld_vertices) vertex=vertex.snapped(weld_tolerance); surf_tool->add_vertex(vertex); } face[1]=face[2]; } } else if (l.begins_with("s ") && !force_smooth) { //smoothing String what = l.substr(2,l.length()).strip_edges(); if (what=="off") surf_tool->add_smooth_group(false); else surf_tool->add_smooth_group(true); } else if (l.begins_with("o ") || f->eof_reached()) { //new surface or done if (has_index_data) { //new object/surface if (generate_normals || force_smooth) surf_tool->generate_normals(); if (uvs.size() && (normals.size() || generate_normals) && generate_tangents) surf_tool->generate_tangents(); surf_tool->index(); mesh = surf_tool->commit(mesh); if (name=="") name=vformat(TTR("Surface %d"),mesh->get_surface_count()-1); mesh->surface_set_name(mesh->get_surface_count()-1,name); name=""; surf_tool->clear(); surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES); if (force_smooth) surf_tool->add_smooth_group(true); has_index_data=false; if (f->eof_reached()) break; } if (l.begins_with("o ")) //name name=l.substr(2,l.length()).strip_edges(); } } from->set_source_md5(0,FileAccess::get_md5(src_path)); from->set_editor(get_name()); mesh->set_import_metadata(from); //re-apply materials if exist for(int i=0;i<mesh->get_surface_count();i++) { String n = mesh->surface_get_name(i); if (name_map.has(n)) mesh->surface_set_material(i,name_map[n]); } Error err = ResourceSaver::save(p_path,mesh); return err; }
void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { String error_text; print_line("COMPLETED: " + itos(p_status) + " code: " + itos(p_code) + " data size: " + itos(p_data.size())); switch (p_status) { case HTTPRequest::RESULT_CANT_RESOLVE: { error_text = TTR("Can't resolve hostname:") + " " + host; status->set_text(TTR("Can't resolve.")); } break; case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: case HTTPRequest::RESULT_CONNECTION_ERROR: case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: { error_text = TTR("Connection error, please try again."); status->set_text(TTR("Can't connect.")); } break; case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: case HTTPRequest::RESULT_CANT_CONNECT: { error_text = TTR("Can't connect to host:") + " " + host; status->set_text(TTR("Can't connect.")); } break; case HTTPRequest::RESULT_NO_RESPONSE: { error_text = TTR("No response from host:") + " " + host; status->set_text(TTR("No response.")); } break; case HTTPRequest::RESULT_REQUEST_FAILED: { error_text = TTR("Request failed, return code:") + " " + itos(p_code); status->set_text(TTR("Req. Failed.")); } break; case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { error_text = TTR("Request failed, too many redirects"); status->set_text(TTR("Redirect Loop.")); } break; default: { if (p_code != 200) { error_text = TTR("Request failed, return code:") + " " + itos(p_code); status->set_text(TTR("Failed:") + " " + itos(p_code)); } else if (sha256 != "") { String download_sha256 = FileAccess::get_sha256(download->get_download_file()); if (sha256 != download_sha256) { error_text = TTR("Bad download hash, assuming file has been tampered with.") + "\n"; error_text += TTR("Expected:") + " " + sha256 + "\n" + TTR("Got:") + " " + download_sha256; status->set_text(TTR("Failed sha256 hash check")); } } } break; } if (error_text != String()) { download_error->set_text(TTR("Asset Download Error:") + "\n" + error_text); download_error->popup_centered_minsize(); return; } progress->set_max(download->get_body_size()); progress->set_value(download->get_downloaded_bytes()); print_line("max: " + itos(download->get_body_size()) + " bytes: " + itos(download->get_downloaded_bytes())); install->set_disabled(false); progress->set_value(download->get_downloaded_bytes()); status->set_text(TTR("Success!") + " (" + String::humanize_size(download->get_downloaded_bytes()) + ")"); set_process(false); }