summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/animation_editor.cpp2
-rw-r--r--editor/code_editor.cpp35
-rw-r--r--editor/code_editor.h2
-rw-r--r--editor/editor_autoload_settings.cpp110
-rw-r--r--editor/editor_autoload_settings.h2
-rw-r--r--editor/editor_node.cpp6
-rw-r--r--editor/editor_node.h5
-rw-r--r--editor/editor_plugin.cpp11
-rw-r--r--editor/editor_plugin.h3
-rw-r--r--editor/editor_resource_preview.cpp1
-rw-r--r--editor/export_template_manager.cpp19
-rw-r--r--editor/filesystem_dock.cpp5
-rw-r--r--editor/icons/SCsub8
-rw-r--r--editor/import/editor_import_plugin.cpp4
-rw-r--r--editor/import/resource_importer_obj.cpp14
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp2
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp3276
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h125
-rw-r--r--editor/plugins/script_editor_plugin.cpp13
-rw-r--r--editor/plugins/script_editor_plugin.h3
-rw-r--r--editor/plugins/script_text_editor.cpp26
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp123
-rw-r--r--editor/plugins/spatial_editor_plugin.h2
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp2
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp39
-rw-r--r--editor/plugins/texture_region_editor_plugin.h7
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp4
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp1002
-rw-r--r--editor/plugins/tile_set_editor_plugin.h122
-rw-r--r--editor/project_manager.cpp45
-rw-r--r--editor/project_manager.h1
-rw-r--r--editor/project_settings_editor.h2
-rw-r--r--editor/scene_tree_dock.cpp2
-rw-r--r--editor/scene_tree_editor.cpp52
-rw-r--r--editor/scene_tree_editor.h3
-rw-r--r--editor/script_create_dialog.cpp14
-rw-r--r--editor/script_editor_debugger.cpp9
37 files changed, 2601 insertions, 2500 deletions
diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp
index cd8233e460..c064f9cbdf 100644
--- a/editor/animation_editor.cpp
+++ b/editor/animation_editor.cpp
@@ -3362,7 +3362,7 @@ int AnimationKeyEditor::_confirm_insert(InsertData p_id, int p_last_track) {
//wants a new tack
{
- //shitty hack
+ //hack
NodePath np;
animation->add_track(p_id.type);
animation->track_set_path(animation->get_track_count() - 1, p_id.path);
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 70334c2343..9ae9ab1501 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -666,6 +666,7 @@ void CodeTextEditor::_reset_zoom() {
if (font.is_valid()) {
EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14);
font->set_size(14);
+ zoom_nb->set_text("100%");
}
}
@@ -727,6 +728,9 @@ bool CodeTextEditor::_add_font_size(int p_delta) {
if (font.is_valid()) {
int new_size = CLAMP(font->get_size() + p_delta, 8 * EDSCALE, 96 * EDSCALE);
+
+ zoom_nb->set_text(itos(100 * new_size / 14) + "%");
+
if (new_size != font->get_size()) {
EditorSettings::get_singleton()->set("interface/editor/code_font_size", new_size / EDSCALE);
font->set_size(new_size);
@@ -771,6 +775,14 @@ void CodeTextEditor::set_error(const String &p_error) {
void CodeTextEditor::_update_font() {
text_editor->add_font_override("font", get_font("source", "EditorFonts"));
+
+ Ref<Font> status_bar_font = get_font("status_source", "EditorFonts");
+ int count = status_bar->get_child_count();
+ for (int i = 0; i < count; i++) {
+ Control *n = Object::cast_to<Control>(status_bar->get_child(i));
+ if (n)
+ n->add_font_override("font", status_bar_font);
+ }
}
void CodeTextEditor::_on_settings_change() {
@@ -851,7 +863,7 @@ CodeTextEditor::CodeTextEditor() {
text_editor->set_brace_matching(true);
text_editor->set_auto_indent(true);
- HBoxContainer *status_bar = memnew(HBoxContainer);
+ status_bar = memnew(HBoxContainer);
add_child(status_bar);
status_bar->set_h_size_flags(SIZE_EXPAND_FILL);
@@ -878,6 +890,24 @@ CodeTextEditor::CodeTextEditor() {
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);
@@ -931,7 +961,8 @@ CodeTextEditor::CodeTextEditor() {
code_complete_timer->connect("timeout", this, "_code_complete_timer_timeout");
font_resize_val = 0;
- font_size = -1;
+ 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);
diff --git a/editor/code_editor.h b/editor/code_editor.h
index db2e25b922..a860ad24e2 100644
--- a/editor/code_editor.h
+++ b/editor/code_editor.h
@@ -141,9 +141,11 @@ class CodeTextEditor : public VBoxContainer {
TextEdit *text_editor;
FindReplaceBar *find_replace_bar;
+ HBoxContainer *status_bar;
Label *line_nb;
Label *col_nb;
+ Label *zoom_nb;
Label *info;
Timer *idle;
Timer *code_complete_timer;
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index d3e697ac35..0e9b7b74fd 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -92,45 +92,7 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
void EditorAutoloadSettings::_autoload_add() {
- String name = autoload_add_name->get_text();
-
- String error;
- if (!_autoload_name_is_valid(name, &error)) {
- EditorNode::get_singleton()->show_warning(error);
- return;
- }
-
- String path = autoload_add_path->get_line_edit()->get_text();
- if (!FileAccess::exists(path)) {
- EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist."));
- return;
- }
-
- if (!path.begins_with("res://")) {
- EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("Not in resource path."));
- return;
- }
-
- name = "autoload/" + name;
-
- UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
-
- undo_redo->create_action(TTR("Add AutoLoad"));
- undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path);
-
- if (ProjectSettings::get_singleton()->has_setting(name)) {
- undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
- } else {
- undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
- }
-
- undo_redo->add_do_method(this, "update_autoload");
- undo_redo->add_undo_method(this, "update_autoload");
-
- undo_redo->add_do_method(this, "emit_signal", autoload_changed);
- undo_redo->add_undo_method(this, "emit_signal", autoload_changed);
-
- undo_redo->commit_action();
+ autoload_add(autoload_add_name->get_text(), autoload_add_path->get_line_edit()->get_text());
autoload_add_path->get_line_edit()->set_text("");
autoload_add_name->set_text("");
@@ -539,6 +501,74 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
undo_redo->commit_action();
}
+void EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_path) {
+
+ String name = p_name;
+
+ String error;
+ if (!_autoload_name_is_valid(name, &error)) {
+ EditorNode::get_singleton()->show_warning(error);
+ return;
+ }
+
+ String path = p_path;
+ if (!FileAccess::exists(path)) {
+ EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("File does not exist."));
+ return;
+ }
+
+ if (!path.begins_with("res://")) {
+ EditorNode::get_singleton()->show_warning(TTR("Invalid Path.") + "\n" + TTR("Not in resource path."));
+ return;
+ }
+
+ name = "autoload/" + name;
+
+ UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
+
+ undo_redo->create_action(TTR("Add AutoLoad"));
+ undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path);
+
+ if (ProjectSettings::get_singleton()->has_setting(name)) {
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
+ } else {
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
+ }
+
+ undo_redo->add_do_method(this, "update_autoload");
+ undo_redo->add_undo_method(this, "update_autoload");
+
+ undo_redo->add_do_method(this, "emit_signal", autoload_changed);
+ undo_redo->add_undo_method(this, "emit_signal", autoload_changed);
+
+ undo_redo->commit_action();
+}
+
+void EditorAutoloadSettings::autoload_remove(const String &p_name) {
+
+ String name = "autoload/" + p_name;
+
+ UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
+
+ int order = ProjectSettings::get_singleton()->get_order(name);
+
+ undo_redo->create_action(TTR("Remove Autoload"));
+
+ undo_redo->add_do_property(ProjectSettings::get_singleton(), name, Variant());
+
+ undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
+ undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_persisting", name, true);
+ undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", order);
+
+ undo_redo->add_do_method(this, "update_autoload");
+ undo_redo->add_undo_method(this, "update_autoload");
+
+ undo_redo->add_do_method(this, "emit_signal", autoload_changed);
+ undo_redo->add_undo_method(this, "emit_signal", autoload_changed);
+
+ undo_redo->commit_action();
+}
+
void EditorAutoloadSettings::_bind_methods() {
ClassDB::bind_method("_autoload_add", &EditorAutoloadSettings::_autoload_add);
@@ -554,6 +584,8 @@ void EditorAutoloadSettings::_bind_methods() {
ClassDB::bind_method("drop_data_fw", &EditorAutoloadSettings::drop_data_fw);
ClassDB::bind_method("update_autoload", &EditorAutoloadSettings::update_autoload);
+ ClassDB::bind_method("autoload_add", &EditorAutoloadSettings::autoload_add);
+ ClassDB::bind_method("autoload_remove", &EditorAutoloadSettings::autoload_remove);
ADD_SIGNAL(MethodInfo("autoload_changed"));
}
diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h
index 2e34a8b17f..6f622de6d5 100644
--- a/editor/editor_autoload_settings.h
+++ b/editor/editor_autoload_settings.h
@@ -87,6 +87,8 @@ protected:
public:
void update_autoload();
+ void autoload_add(const String &p_name, const String &p_path);
+ void autoload_remove(const String &p_name);
EditorAutoloadSettings();
};
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 29912feb1f..6d94aedfa9 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1784,7 +1784,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
editor_data.save_editor_external_data();
}
- if (!_call_build())
+ if (!call_build())
return;
if (bool(EDITOR_DEF("run/output/always_clear_output_on_play", true))) {
@@ -2321,7 +2321,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
if (run_native->is_deploy_debug_remote_enabled()) {
_menu_option_confirm(RUN_STOP, true);
- if (!_call_build())
+ if (!call_build())
break; // build failed
emit_signal("play_pressed");
@@ -4525,7 +4525,7 @@ void EditorNode::add_build_callback(EditorBuildCallback p_callback) {
EditorBuildCallback EditorNode::build_callbacks[EditorNode::MAX_BUILD_CALLBACKS];
-bool EditorNode::_call_build() {
+bool EditorNode::call_build() {
for (int i = 0; i < build_callback_count; i++) {
if (!build_callbacks[i]())
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 03102cdc81..6d96c2dea7 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -596,7 +596,6 @@ private:
static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
void _save_default_environment();
- bool _call_build();
static int build_callback_count;
static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
@@ -634,6 +633,8 @@ protected:
static void _bind_methods();
public:
+ bool call_build();
+
static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
enum EditorTable {
@@ -653,6 +654,8 @@ public:
PropertyEditor *get_property_editor() { return property_editor; }
VBoxContainer *get_property_editor_vb() { return prop_editor_vb; }
+ ProjectSettingsEditor *get_project_settings() { return project_settings; }
+
static void add_editor_plugin(EditorPlugin *p_editor);
static void remove_editor_plugin(EditorPlugin *p_editor);
diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp
index 733680645f..31d0bfa8a9 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -301,6 +301,14 @@ void EditorPlugin::remove_custom_type(const String &p_type) {
EditorNode::get_editor_data().remove_custom_type(p_type);
}
+void EditorPlugin::add_autoload_singleton(const String &p_name, const String &p_path) {
+ EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_add(p_name, p_path);
+}
+
+void EditorPlugin::remove_autoload_singleton(const String &p_name) {
+ EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name);
+}
+
ToolButton *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) {
return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control);
@@ -705,6 +713,9 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type);
ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type);
+ ClassDB::bind_method(D_METHOD("add_autoload_singleton", "name", "path"), &EditorPlugin::add_autoload_singleton);
+ ClassDB::bind_method(D_METHOD("remove_autoload_singleton", "name"), &EditorPlugin::remove_autoload_singleton);
+
ClassDB::bind_method(D_METHOD("update_overlays"), &EditorPlugin::update_overlays);
ClassDB::bind_method(D_METHOD("make_bottom_panel_item_visible", "item"), &EditorPlugin::make_bottom_panel_item_visible);
diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h
index e3e405479c..05cc6e07e3 100644
--- a/editor/editor_plugin.h
+++ b/editor/editor_plugin.h
@@ -212,6 +212,9 @@ public:
void add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
void remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
+ void add_autoload_singleton(const String &p_name, const String &p_path);
+ void remove_autoload_singleton(const String &p_name);
+
EditorPlugin();
virtual ~EditorPlugin();
};
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp
index 93787a7a4c..aa67ea03d7 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -253,7 +253,6 @@ void EditorResourcePreview::_thread() {
img.instance();
if (img->load(cache_base + ".png") != OK) {
- //well fuck
cache_valid = false;
} else {
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp
index c4ecf3c098..41b016bdca 100644
--- a/editor/export_template_manager.cpp
+++ b/editor/export_template_manager.cpp
@@ -402,19 +402,10 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int
if (p_code != 200) {
template_list_state->set_text(TTR("Failed:") + " " + itos(p_code));
} else {
- String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_templates.tpz");
- FileAccess *f = FileAccess::open(path, FileAccess::WRITE);
- if (!f) {
- template_list_state->set_text(TTR("Can't write file."));
- } else {
- int size = p_data.size();
- PoolVector<uint8_t>::Read r = p_data.read();
- f->store_buffer(r.ptr(), size);
- memdelete(f);
- template_list_state->set_text(TTR("Download Complete."));
- template_downloader->hide();
- _install_from_file(path, false);
- }
+ String path = download_templates->get_download_file();
+ template_list_state->set_text(TTR("Download Complete."));
+ template_downloader->hide();
+ _install_from_file(path, false);
}
} break;
}
@@ -437,6 +428,8 @@ void ExportTemplateManager::_begin_template_download(const String &p_url) {
}
download_data.clear();
+ download_templates->set_download_file(EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_templates.tpz"));
+ download_templates->set_use_threads(true);
Error err = download_templates->request(p_url);
if (err != OK) {
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index e26f4ba449..0be3bb86c7 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -958,7 +958,12 @@ void FileSystemDock::_rename_operation_confirm() {
//Present a more user friendly warning for name conflict
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+#if defined(WINDOWS_ENABLED) || defined(UWP_ENABLED)
+ // Workaround case insensitivity on Windows
+ if ((da->file_exists(new_path) || da->dir_exists(new_path)) && new_path.to_lower() != old_path.to_lower()) {
+#else
if (da->file_exists(new_path) || da->dir_exists(new_path)) {
+#endif
EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
memdelete(da);
return;
diff --git a/editor/icons/SCsub b/editor/icons/SCsub
index 9bd036dfa9..64992a9f90 100644
--- a/editor/icons/SCsub
+++ b/editor/icons/SCsub
@@ -34,7 +34,7 @@ def make_editor_icons_action(target, source, env):
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
s.write("#ifndef _EDITOR_ICONS_H\n")
s.write("#define _EDITOR_ICONS_H\n")
- s.write("static const int editor_icons_count = %s;\n" % len(svg_icons))
+ s.write("static const int editor_icons_count = {};\n".format(len(svg_icons)))
s.write("static const char *editor_icons_sources[] = {\n")
s.write(icons_string.getvalue())
s.write('};\n\n')
@@ -57,7 +57,7 @@ def make_editor_icons_action(target, source, env):
if icon_name.endswith("BigThumb"): # don't know a better way to handle this
thumb_big_indices.append(str(index))
- s.write('\t"%s"' % icon_name)
+ s.write('\t"{0}"'.format(icon_name))
if fname != svg_icons[-1]:
s.write(",")
@@ -69,13 +69,13 @@ def make_editor_icons_action(target, source, env):
if thumb_medium_indices:
s.write("\n\n")
- s.write("static const int editor_md_thumbs_count = %s;\n" % len(thumb_medium_indices))
+ s.write("static const int editor_md_thumbs_count = {};\n".format(len(thumb_medium_indices)))
s.write("static const int editor_md_thumbs_indices[] = {")
s.write(", ".join(thumb_medium_indices))
s.write("};\n")
if thumb_big_indices:
s.write("\n\n")
- s.write("static const int editor_bg_thumbs_count = %s;\n" % len(thumb_big_indices))
+ s.write("static const int editor_bg_thumbs_count = {};\n".format(len(thumb_big_indices)))
s.write("static const int editor_bg_thumbs_indices[] = {")
s.write(", ".join(thumb_big_indices))
s.write("};\n")
diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp
index 3f5dc7c9f4..c1c1183692 100644
--- a/editor/import/editor_import_plugin.cpp
+++ b/editor/import/editor_import_plugin.cpp
@@ -74,14 +74,14 @@ String EditorImportPlugin::get_resource_type() const {
float EditorImportPlugin::get_priority() const {
if (!(get_script_instance() && get_script_instance()->has_method("get_priority"))) {
- return EditorImportPlugin::get_priority();
+ return ResourceImporter::get_priority();
}
return get_script_instance()->call("get_priority");
}
int EditorImportPlugin::get_import_order() const {
if (!(get_script_instance() && get_script_instance()->has_method("get_import_order"))) {
- return EditorImportPlugin::get_import_order();
+ return ResourceImporter::get_import_order();
}
return get_script_instance()->call("get_import_order");
}
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index 78fc9ec9bd..21803a2184 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -188,7 +188,7 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati
return OK;
}
-static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p_single_mesh, bool p_generate_tangents, List<String> *r_missing_deps) {
+static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p_single_mesh, bool p_generate_tangents, Vector3 p_scale_mesh, List<String> *r_missing_deps) {
FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);
@@ -198,6 +198,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p
mesh.instance();
bool generate_tangents = p_generate_tangents;
+ Vector3 scale_mesh = p_scale_mesh;
bool flip_faces = false;
//bool flip_faces = p_options["force/flip_faces"];
//bool force_smooth = p_options["force/smooth_shading"];
@@ -227,9 +228,9 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p
Vector<String> v = l.split(" ", false);
ERR_FAIL_COND_V(v.size() < 4, ERR_FILE_CORRUPT);
Vector3 vtx;
- vtx.x = v[1].to_float();
- vtx.y = v[2].to_float();
- vtx.z = v[3].to_float();
+ vtx.x = v[1].to_float() * scale_mesh.x;
+ vtx.y = v[2].to_float() * scale_mesh.y;
+ vtx.z = v[3].to_float() * scale_mesh.z;
vertices.push_back(vtx);
} else if (l.begins_with("vt ")) {
//uv
@@ -401,7 +402,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in
List<Ref<Mesh> > meshes;
- Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, r_missing_deps);
+ Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, Vector3(1, 1, 1), r_missing_deps);
if (err != OK) {
if (r_err) {
@@ -468,6 +469,7 @@ String ResourceImporterOBJ::get_preset_name(int p_idx) const {
void ResourceImporterOBJ::get_import_options(List<ImportOption> *r_options, int p_preset) const {
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate_tangents"), true));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "scale_mesh"), Vector3(1, 1, 1)));
}
bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
@@ -478,7 +480,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s
List<Ref<Mesh> > meshes;
- Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], NULL);
+ Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["scale_mesh"], NULL);
ERR_FAIL_COND_V(err != OK, err);
ERR_FAIL_COND_V(meshes.size() != 1, ERR_BUG);
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index b8bf2b97f6..26afc78825 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -308,7 +308,7 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() {
preview_hb->set_v_size_flags(SIZE_EXPAND_FILL);
previews->add_child(preview_hb);
- get_ok()->set_text(TTR("Install"));
+ get_ok()->set_text(TTR("Download"));
get_cancel()->set_text(TTR("Close"));
}
///////////////////////////////////////////////////////////////////////////////////
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 4a05d401cb..9680ad07e7 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -169,64 +169,10 @@ public:
}
};
-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()) {
-
- Node2D *n2d = Object::cast_to<Node2D>(E->get());
- if (n2d && n2d->_edit_use_pivot()) {
-
- Vector2 offset = n2d->_edit_get_pivot();
- Vector2 gpos = n2d->get_global_position();
-
- Vector2 local_mouse_pos = n2d->get_canvas_transform().affine_inverse().xform(mouse_pos);
-
- Vector2 motion_ofs = gpos - local_mouse_pos;
-
- undo_redo->add_do_method(n2d, "set_global_position", 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_position", gpos);
- undo_redo->add_undo_method(n2d, "_edit_set_pivot", offset);
- for (int i = 0; i < n2d->get_child_count(); i++) {
- Node2D *n2dc = Object::cast_to<Node2D>(n2d->get_child(i));
- if (!n2dc)
- continue;
-
- undo_redo->add_do_method(n2dc, "set_global_position", n2dc->get_global_position());
- undo_redo->add_undo_method(n2dc, "set_global_position", n2dc->get_global_position());
- }
- }
-
- Control *cnt = Object::cast_to<Control>(E->get());
- if (cnt) {
-
- Vector2 old_pivot = cnt->get_pivot_offset();
- Vector2 new_pivot = cnt->get_global_transform_with_canvas().affine_inverse().xform(mouse_pos);
- Vector2 old_pos = cnt->get_position();
-
- Vector2 top_pos = cnt->get_transform().get_origin(); //remember where top pos was
- cnt->set_pivot_offset(new_pivot);
- Vector2 new_top_pos = cnt->get_transform().get_origin(); //check where it is now
-
- Vector2 new_pos = old_pos - (new_top_pos - top_pos); //offset it back
-
- undo_redo->add_do_method(cnt, "set_pivot_offset", new_pivot);
- undo_redo->add_do_method(cnt, "set_position", new_pos);
- undo_redo->add_undo_method(cnt, "set_pivot_offset", old_pivot);
- undo_redo->add_undo_method(cnt, "set_position", old_pos);
- }
- }
-
- undo_redo->commit_action();
-}
-
void CanvasItemEditor::_snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius) {
float radius = p_radius / zoom;
float dist = Math::abs(p_value - p_target_snap);
- if (p_radius < 0 || dist < radius && (!r_snapped || dist < Math::abs(r_current_snap - p_value))) {
+ if ((p_radius < 0 || dist < radius) && (!r_snapped || dist < Math::abs(r_current_snap - p_value))) {
r_current_snap = p_target_snap;
r_snapped = true;
}
@@ -263,7 +209,6 @@ void CanvasItemEditor::_snap_other_nodes(Point2 p_value, Point2 &r_current_snap,
}
Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const CanvasItem *p_canvas_item, unsigned int p_forced_modes) {
- Point2 dist[2];
bool snapped[2] = { false, false };
// Smart snap using the canvas position
@@ -271,12 +216,12 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const
real_t rotation = 0.0;
if (p_canvas_item) {
- Point2 begin;
- Point2 end;
rotation = p_canvas_item->get_global_transform_with_canvas().get_rotation();
+ // Parent sides and center
if ((snap_active && snap_node_parent && (p_modes & SNAP_NODE_PARENT)) || (p_forced_modes & SNAP_NODE_PARENT)) {
- // Parent sides and center
+ Point2 begin;
+ Point2 end;
bool can_snap = false;
if (const Control *c = Object::cast_to<Control>(p_canvas_item)) {
begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(0, 0)));
@@ -295,23 +240,29 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const
}
}
- // Self anchors (for sides)
+ // Self anchors
if ((snap_active && snap_node_anchors && (p_modes & SNAP_NODE_ANCHORS)) || (p_forced_modes & SNAP_NODE_ANCHORS)) {
if (const Control *c = Object::cast_to<Control>(p_canvas_item)) {
- begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP))));
- end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM))));
+ Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP))));
+ Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM))));
_snap_if_closer_point(p_target, begin, output, snapped, rotation);
_snap_if_closer_point(p_target, end, output, snapped, rotation);
}
}
- // Self sides (for anchors)
+ // Self sides
if ((snap_active && snap_node_sides && (p_modes & SNAP_NODE_SIDES)) || (p_forced_modes & SNAP_NODE_SIDES)) {
- begin = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position());
- end = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size());
+ Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position());
+ Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size());
_snap_if_closer_point(p_target, begin, output, snapped, rotation);
_snap_if_closer_point(p_target, end, output, snapped, rotation);
}
+
+ // Self center
+ if ((snap_active && snap_node_center && (p_modes & SNAP_NODE_CENTER)) || (p_forced_modes & SNAP_NODE_CENTER)) {
+ Point2 center = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size() / 2.0);
+ _snap_if_closer_point(p_target, center, output, snapped, rotation);
+ }
}
// Other nodes sides
@@ -340,11 +291,11 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const
// Grid
Point2 offset = grid_offset;
if (snap_relative) {
- List<Node *> selection = editor_selection->get_selected_node_list();
+ List<CanvasItem *> selection = _get_edited_canvas_items();
if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0])) {
offset = Object::cast_to<Node2D>(selection[0])->get_global_position();
- } else {
- offset = _find_topleftmost_point();
+ } else if (selection.size() > 0) {
+ offset = _get_encompassing_rect_from_list(selection).position;
}
}
Point2 grid_output;
@@ -362,7 +313,6 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const
}
float CanvasItemEditor::snap_angle(float p_target, float p_start) const {
- float offset = snap_relative ? p_start : p_target;
return (snap_rotation && snap_rotation_step != 0) ? Math::stepify(p_target - snap_rotation_offset, snap_rotation_step) + snap_rotation_offset : p_target;
}
@@ -377,48 +327,20 @@ void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
return;
if (k->is_pressed() && !k->is_echo()) {
- if (drag_pivot_shortcut.is_valid() && drag_pivot_shortcut->is_shortcut(p_ev) && drag == DRAG_NONE && can_move_pivot) {
- //move drag pivot
- drag = DRAG_PIVOT;
- } else if (set_pivot_shortcut.is_valid() && set_pivot_shortcut->is_shortcut(p_ev) && drag == DRAG_NONE && can_move_pivot) {
- if (!Input::get_singleton()->is_mouse_button_pressed(0)) {
- List<Node *> selection = editor_selection->get_selected_node_list();
- Vector2 mouse_pos = viewport->get_local_mouse_position();
- 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, SNAP_DEFAULT, _get_single_item());
-
- _edit_set_pivot(mouse_pos);
- }
- }
- } else if ((snap_grid || show_grid) && multiply_grid_step_shortcut.is_valid() && multiply_grid_step_shortcut->is_shortcut(p_ev)) {
+ if ((snap_grid || show_grid) && multiply_grid_step_shortcut.is_valid() && multiply_grid_step_shortcut->is_shortcut(p_ev)) {
// Multiply the grid size
grid_step_multiplier = MIN(grid_step_multiplier + 1, 12);
- viewport_base->update();
viewport->update();
} else if ((snap_grid || show_grid) && divide_grid_step_shortcut.is_valid() && divide_grid_step_shortcut->is_shortcut(p_ev)) {
// Divide the grid size
Point2 new_grid_step = grid_step * Math::pow(2.0, grid_step_multiplier - 1);
if (new_grid_step.x >= 1.0 && new_grid_step.y >= 1.0)
grid_step_multiplier--;
- viewport_base->update();
viewport->update();
}
}
}
-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++) {
- tb[i]->set_pressed(i == p_index);
- }
-
- viewport->update();
- tool = (Tool)p_index;
-}
-
Object *CanvasItemEditor::_get_editor_data(Object *p_what) {
CanvasItem *ci = Object::cast_to<CanvasItem>(p_what);
@@ -428,220 +350,109 @@ Object *CanvasItemEditor::_get_editor_data(Object *p_what) {
return memnew(CanvasItemEditorSelectedItem);
}
-Dictionary CanvasItemEditor::get_state() const {
+void CanvasItemEditor::_keying_changed() {
- Dictionary state;
- state["zoom"] = zoom;
- state["ofs"] = Point2(h_scroll->get_value(), v_scroll->get_value());
- //state["ofs"]=-transform.get_origin();
- state["grid_offset"] = grid_offset;
- state["grid_step"] = grid_step;
- state["snap_rotation_offset"] = snap_rotation_offset;
- state["snap_rotation_step"] = snap_rotation_step;
- state["snap_active"] = snap_active;
- state["snap_node_parent"] = snap_node_parent;
- state["snap_node_anchors"] = snap_node_anchors;
- state["snap_node_sides"] = snap_node_sides;
- state["snap_other_nodes"] = snap_other_nodes;
- state["snap_grid"] = snap_grid;
- state["snap_guides"] = snap_guides;
- state["show_grid"] = show_grid;
- state["show_rulers"] = show_rulers;
- state["show_guides"] = show_guides;
- state["show_helpers"] = show_helpers;
- state["snap_rotation"] = snap_rotation;
- state["snap_relative"] = snap_relative;
- state["snap_pixel"] = snap_pixel;
- state["skeleton_show_bones"] = skeleton_show_bones;
- return state;
+ if (AnimationPlayerEditor::singleton->get_key_editor()->is_visible_in_tree())
+ animation_hb->show();
+ else
+ animation_hb->hide();
}
-void CanvasItemEditor::set_state(const Dictionary &p_state) {
- Dictionary state = p_state;
- if (state.has("zoom")) {
- zoom = p_state["zoom"];
- }
+Rect2 CanvasItemEditor::_get_encompassing_rect_from_list(List<CanvasItem *> p_list) {
+ ERR_FAIL_COND_V(p_list.empty(), Rect2());
- if (state.has("ofs")) {
- _update_scrollbars(); // i wonder how safe is calling this here..
- Point2 ofs = p_state["ofs"];
- h_scroll->set_value(ofs.x);
- v_scroll->set_value(ofs.y);
- }
-
- if (state.has("grid_offset")) {
- grid_offset = state["grid_offset"];
- }
-
- if (state.has("grid_step")) {
- grid_step = state["grid_step"];
- }
-
- if (state.has("snap_rotation_step")) {
- snap_rotation_step = state["snap_rotation_step"];
- }
-
- if (state.has("snap_rotation_offset")) {
- snap_rotation_offset = state["snap_rotation_offset"];
- }
+ // Handles the first element
+ CanvasItem *canvas_item = p_list.front()->get();
+ Rect2 rect = Rect2(canvas_item->get_global_transform_with_canvas().xform(canvas_item->_edit_get_rect().position + canvas_item->_edit_get_rect().size / 2), Size2());
- if (state.has("snap_active")) {
- snap_active = state["snap_active"];
- snap_button->set_pressed(snap_active);
- }
-
- if (state.has("snap_node_parent")) {
- snap_node_parent = state["snap_node_parent"];
- int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_PARENT);
- smartsnap_config_popup->set_item_checked(idx, snap_node_parent);
- }
-
- if (state.has("snap_node_anchors")) {
- snap_node_anchors = state["snap_node_anchors"];
- int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_ANCHORS);
- smartsnap_config_popup->set_item_checked(idx, snap_node_anchors);
- }
-
- if (state.has("snap_node_sides")) {
- snap_node_sides = state["snap_node_sides"];
- int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_SIDES);
- smartsnap_config_popup->set_item_checked(idx, snap_node_sides);
- }
-
- if (state.has("snap_other_nodes")) {
- snap_other_nodes = state["snap_other_nodes"];
- int idx = smartsnap_config_popup->get_item_index(SNAP_USE_OTHER_NODES);
- smartsnap_config_popup->set_item_checked(idx, snap_other_nodes);
- }
-
- if (state.has("snap_guides")) {
- snap_guides = state["snap_guides"];
- int idx = smartsnap_config_popup->get_item_index(SNAP_USE_GUIDES);
- smartsnap_config_popup->set_item_checked(idx, snap_guides);
- }
-
- if (state.has("snap_grid")) {
- snap_grid = state["snap_grid"];
- int idx = snap_config_menu->get_popup()->get_item_index(SNAP_USE_GRID);
- snap_config_menu->get_popup()->set_item_checked(idx, snap_grid);
- }
-
- if (state.has("show_grid")) {
- show_grid = state["show_grid"];
- int idx = view_menu->get_popup()->get_item_index(SHOW_GRID);
- view_menu->get_popup()->set_item_checked(idx, show_grid);
- }
-
- if (state.has("show_rulers")) {
- show_rulers = state["show_rulers"];
- int idx = view_menu->get_popup()->get_item_index(SHOW_RULERS);
- view_menu->get_popup()->set_item_checked(idx, show_rulers);
+ // Handles the other ones
+ for (List<CanvasItem *>::Element *E = p_list.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ Rect2 current_rect = canvas_item->_edit_get_rect();
+ Transform2D xform = canvas_item->get_global_transform_with_canvas();
+ rect.expand_to(xform.xform(current_rect.position));
+ rect.expand_to(xform.xform(current_rect.position + Vector2(current_rect.size.x, 0)));
+ rect.expand_to(xform.xform(current_rect.position + current_rect.size));
+ rect.expand_to(xform.xform(current_rect.position + Vector2(0, current_rect.size.y)));
}
- if (state.has("show_guides")) {
- show_guides = state["show_guides"];
- int idx = view_menu->get_popup()->get_item_index(SHOW_GUIDES);
- view_menu->get_popup()->set_item_checked(idx, show_guides);
- }
+ return rect;
+}
- if (state.has("show_helpers")) {
- show_helpers = state["show_helpers"];
- int idx = view_menu->get_popup()->get_item_index(SHOW_HELPERS);
- view_menu->get_popup()->set_item_checked(idx, show_helpers);
- }
+void CanvasItemEditor::_expand_encompassing_rect_using_children(Rect2 &r_rect, Node *p_node, bool &r_first, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) {
+ if (!p_node)
+ return;
+ if (Object::cast_to<Viewport>(p_node))
+ return;
- if (state.has("snap_rotation")) {
- snap_rotation = state["snap_rotation"];
- int idx = snap_config_menu->get_popup()->get_item_index(SNAP_USE_ROTATION);
- snap_config_menu->get_popup()->set_item_checked(idx, snap_rotation);
- }
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
- if (state.has("snap_relative")) {
- snap_relative = state["snap_relative"];
- int idx = snap_config_menu->get_popup()->get_item_index(SNAP_RELATIVE);
- snap_config_menu->get_popup()->set_item_checked(idx, snap_relative);
- }
+ bool inherited = p_node != get_tree()->get_edited_scene_root() && p_node->get_filename() != "";
+ bool editable = inherited && 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_");
- if (state.has("snap_pixel")) {
- snap_pixel = state["snap_pixel"];
- int idx = snap_config_menu->get_popup()->get_item_index(SNAP_USE_PIXEL);
- snap_config_menu->get_popup()->set_item_checked(idx, snap_pixel);
+ if (!lock_children && (!inherited || editable)) {
+ for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
+ if (canvas_item && !canvas_item->is_set_as_toplevel()) {
+ _expand_encompassing_rect_using_children(r_rect, p_node->get_child(i), r_first, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
+ } else {
+ CanvasLayer *canvas_layer = Object::cast_to<CanvasLayer>(p_node);
+ _expand_encompassing_rect_using_children(r_rect, p_node->get_child(i), r_first, Transform2D(), canvas_layer ? canvas_layer->get_transform() : p_canvas_xform);
+ }
+ }
}
- if (state.has("skeleton_show_bones")) {
- skeleton_show_bones = state["skeleton_show_bones"];
- int idx = skeleton_menu->get_popup()->get_item_index(SKELETON_SHOW_BONES);
- skeleton_menu->get_popup()->set_item_checked(idx, skeleton_show_bones);
+ if (canvas_item && canvas_item->is_visible_in_tree() && !canvas_item->has_meta("_edit_lock_")) {
+ Rect2 rect = canvas_item->_edit_get_rect();
+ Transform2D xform = p_parent_xform * p_canvas_xform * canvas_item->get_transform();
+ if (r_first) {
+ r_rect = Rect2(xform.xform(rect.position + rect.size / 2), Size2());
+ r_first = false;
+ }
+ r_rect.expand_to(xform.xform(rect.position));
+ r_rect.expand_to(xform.xform(rect.position + Point2(rect.size.x, 0)));
+ r_rect.expand_to(xform.xform(rect.position + Point2(0, rect.size.y)));
+ r_rect.expand_to(xform.xform(rect.position + rect.size));
}
-
- viewport->update();
-}
-
-void CanvasItemEditor::_add_canvas_item(CanvasItem *p_canvas_item) {
-
- editor_selection->add_node(p_canvas_item);
-}
-
-void CanvasItemEditor::_remove_canvas_item(CanvasItem *p_canvas_item) {
-
- editor_selection->remove_node(p_canvas_item);
-}
-void CanvasItemEditor::_clear_canvas_items() {
-
- editor_selection->clear();
}
-void CanvasItemEditor::_keying_changed() {
-
- if (AnimationPlayerEditor::singleton->get_key_editor()->is_visible_in_tree())
- animation_hb->show();
- else
- animation_hb->hide();
-}
-
-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();
-
- return item_owner && item_owner != scene_node && p_item != scene_node && item_owner->get_filename() != "";
+Rect2 CanvasItemEditor::_get_scene_encompassing_rect() {
+ Rect2 rect;
+ bool first = true;
+ _expand_encompassing_rect_using_children(rect, editor->get_edited_scene(), first);
+ return rect;
}
-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, int limit) {
+void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, int limit, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) {
if (!p_node)
return;
if (Object::cast_to<Viewport>(p_node))
return;
const real_t grab_distance = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
- CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
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);
+ if (canvas_item && !canvas_item->is_set_as_toplevel())
+ _find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, 0, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
else {
CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
- _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), r_items, 0, Transform2D(), cl ? cl->get_transform() : p_canvas_xform); //use base transform
}
-
if (limit != 0 && r_items.size() >= limit)
return;
}
- if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
+ if (canvas_item && canvas_item->is_visible_in_tree() && !canvas_item->has_meta("_edit_lock_")) {
- Rect2 rect = c->_edit_get_rect();
- Transform2D to_local = (p_parent_xform * p_canvas_xform * c->get_transform()).affine_inverse();
- Point2 local_pos = to_local.xform(p_pos);
- const real_t local_grab_distance = (to_local.xform(p_pos + Vector2(grab_distance, 0)) - local_pos).length();
- Rect2 local_pos_rect = Rect2(local_pos, Vector2(0, 0)).grow(local_grab_distance);
+ Transform2D xform = (p_parent_xform * p_canvas_xform * canvas_item->get_transform()).affine_inverse();
+ const real_t local_grab_distance = xform.basis_xform(Vector2(grab_distance, 0)).length();
- if (rect.intersects(local_pos_rect) && c->_edit_is_selected_on_click(local_pos, local_grab_distance)) {
- Node2D *node = Object::cast_to<Node2D>(c);
+ if (canvas_item->_edit_is_selected_on_click(xform.xform(p_pos), local_grab_distance)) {
+ Node2D *node = Object::cast_to<Node2D>(canvas_item);
_SelectResult res;
- res.item = c;
+ res.item = canvas_item;
res.z_index = node ? node->get_z_index() : 0;
res.has_z = node;
r_items.push_back(res);
@@ -651,64 +462,45 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no
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, List<CanvasItem *> *r_items, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) {
if (!p_node)
return;
if (Object::cast_to<Viewport>(p_node))
return;
- CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(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 editable = inherited && 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_");
+
if (!lock_children && (!inherited || editable)) {
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);
- else {
- CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
- _find_canvas_items_at_rect(p_rect, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform, r_items);
+ if (canvas_item && !canvas_item->is_set_as_toplevel()) {
+ _find_canvas_items_at_rect(p_rect, p_node->get_child(i), r_items, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
+ } else {
+ CanvasLayer *canvas_layer = Object::cast_to<CanvasLayer>(p_node);
+ _find_canvas_items_at_rect(p_rect, p_node->get_child(i), r_items, Transform2D(), canvas_layer ? canvas_layer->get_transform() : p_canvas_xform);
}
}
}
- if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
+ if (canvas_item && canvas_item->is_visible_in_tree() && !canvas_item->has_meta("_edit_lock_")) {
- Rect2 rect = c->_edit_get_rect();
- Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform();
+ Rect2 rect = canvas_item->_edit_get_rect();
+ Transform2D xform = p_parent_xform * p_canvas_xform * canvas_item->get_transform();
if (p_rect.has_point(xform.xform(rect.position)) &&
p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, 0))) &&
p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, rect.size.y))) &&
p_rect.has_point(xform.xform(rect.position + Vector2(0, rect.size.y)))) {
- r_items->push_back(c);
+ r_items->push_back(canvas_item);
}
}
}
-void CanvasItemEditor::_select_click_on_empty_area(Point2 p_click_pos, bool p_append, bool p_box_selection) {
- if (!p_append) {
- editor_selection->clear();
- viewport->update();
- viewport_base->update();
- };
-
- if (p_box_selection) {
- // Start a box selection
- drag_from = transform.affine_inverse().xform(p_click_pos);
- box_selecting = true;
- box_selecting_to = drag_from;
- }
-}
-
-bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag) {
+bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append) {
bool still_selected = true;
if (p_append) {
if (editor_selection->is_selected(item)) {
@@ -717,7 +509,7 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po
still_selected = false;
} else {
// Add the item to the selection
- _append_canvas_item(item);
+ editor_selection->add_node(item);
}
} else {
if (!editor_selection->is_selected(item)) {
@@ -730,216 +522,33 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po
}
}
}
-
- if (still_selected && p_drag) {
- // Drag the node(s) if requested
- _prepare_drag(p_click_pos);
- }
-
viewport->update();
- viewport_base->update();
return still_selected;
}
-void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode) {
-
- if (drag != DRAG_NONE)
- return;
-
- if (editor_selection->get_selected_node_list().empty())
- return;
-
- undo_redo->create_action(TTR("Move Action"), UndoRedo::MERGE_ENDS);
-
- List<Node *> selection = editor_selection->get_selected_node_list();
-
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- 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 *= grid_step * Math::pow(2.0, grid_step_multiplier);
-
- undo_redo->add_undo_method(canvas_item, "_edit_set_state", canvas_item->_edit_get_state());
-
- 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->_edit_get_rect();
- local_rect.position += 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
-
- Node2D *node_2d = Object::cast_to<Node2D>(canvas_item);
- if (node_2d) {
-
- if (p_move_mode == MOVE_LOCAL_WITH_ROT) {
- Transform2D m;
- m.rotate(node_2d->get_rotation());
- drag = m.xform(drag);
- }
- node_2d->set_position(node_2d->get_position() + drag);
-
- } else {
- Control *control = Object::cast_to<Control>(canvas_item);
- if (control)
- control->set_position(control->get_position() + drag);
+List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool retreive_locked, bool remove_canvas_item_if_parent_in_selection) {
+ List<CanvasItem *> selection;
+ for (Map<Node *, Object *>::Element *E = editor_selection->get_selection().front(); E; E = E->next()) {
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
+ if (canvas_item && canvas_item->is_visible_in_tree() && canvas_item->get_viewport() == EditorNode::get_singleton()->get_scene_root() && (!retreive_locked || !canvas_item->has_meta("_edit_lock_"))) {
+ CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
+ if (se) {
+ selection.push_back(canvas_item);
}
}
}
- undo_redo->commit_action();
-}
-
-Point2 CanvasItemEditor::_find_topleftmost_point() {
-
- Vector2 tl = Point2(1e10, 1e10);
- Rect2 r2;
- r2.position = tl;
-
- List<Node *> selection = editor_selection->get_selected_node_list();
-
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- Rect2 rect = canvas_item->_edit_get_rect();
- Transform2D xform = canvas_item->get_global_transform_with_canvas();
-
- r2.expand_to(xform.xform(rect.position));
- r2.expand_to(xform.xform(rect.position + Vector2(rect.size.x, 0)));
- r2.expand_to(xform.xform(rect.position + rect.size));
- r2.expand_to(xform.xform(rect.position + Vector2(0, rect.size.y)));
- }
-
- return r2.position;
-}
-
-int CanvasItemEditor::get_item_count() {
-
- List<Node *> selection = editor_selection->get_selected_node_list();
-
- int ic = 0;
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
-
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- ic++;
- };
-
- return ic;
-}
-
-CanvasItem *CanvasItemEditor::_get_single_item() {
-
- Map<Node *, Object *> &selection = editor_selection->get_selection();
-
- CanvasItem *single_item = NULL;
-
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- if (single_item)
- return NULL; //morethan one
-
- single_item = canvas_item;
- };
-
- return single_item;
-}
-
-CanvasItemEditor::DragType CanvasItemEditor::_get_resize_handle_drag_type(const Point2 &p_click, Vector2 &r_point) {
- // Returns a drag type if a resize handle is clicked
- CanvasItem *canvas_item = _get_single_item();
-
- ERR_FAIL_COND_V(!canvas_item, DRAG_NONE);
-
- Rect2 rect = canvas_item->_edit_get_rect();
- Transform2D xforml = canvas_item->get_global_transform_with_canvas();
- Transform2D xform = transform * xforml;
-
- Vector2 endpoints[4] = {
-
- xform.xform(rect.position),
- xform.xform(rect.position + Vector2(rect.size.x, 0)),
- xform.xform(rect.position + rect.size),
- xform.xform(rect.position + Vector2(0, rect.size.y))
- };
-
- Vector2 endpointsl[4] = {
-
- xforml.xform(rect.position),
- xforml.xform(rect.position + Vector2(rect.size.x, 0)),
- xforml.xform(rect.position + rect.size),
- xforml.xform(rect.position + Vector2(0, rect.size.y))
- };
-
- DragType dragger[] = {
- DRAG_TOP_LEFT,
- DRAG_TOP,
- DRAG_TOP_RIGHT,
- DRAG_RIGHT,
- DRAG_BOTTOM_RIGHT,
- DRAG_BOTTOM,
- DRAG_BOTTOM_LEFT,
- DRAG_LEFT
- };
-
- float radius = (select_handle->get_size().width / 2) * 1.5;
-
- for (int i = 0; i < 4; i++) {
-
- int prev = (i + 3) % 4;
- int next = (i + 1) % 4;
-
- 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 += endpoints[i];
-
- 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);
-
- r_point = (endpointsl[i] + endpointsl[next]) / 2;
-
- if (ofs.distance_to(p_click) < radius)
- return dragger[i * 2 + 1];
+ if (remove_canvas_item_if_parent_in_selection) {
+ List<CanvasItem *> filtered_selection;
+ for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) {
+ if (!selection.find(E->get()->get_parent())) {
+ filtered_selection.push_back(E->get());
+ }
+ }
+ return filtered_selection;
+ } else {
+ return selection;
}
-
- return DRAG_NONE;
}
Vector2 CanvasItemEditor::_anchor_to_position(const Control *p_control, Vector2 anchor) {
@@ -958,148 +567,90 @@ Vector2 CanvasItemEditor::_position_to_anchor(const Control *p_control, Vector2
return p_control->get_transform().xform(position) / parent_size;
}
-CanvasItemEditor::DragType CanvasItemEditor::_get_anchor_handle_drag_type(const Point2 &p_click, Vector2 &r_point) {
- // Returns a drag type if an anchor handle is clicked
- CanvasItem *canvas_item = _get_single_item();
- ERR_FAIL_COND_V(!canvas_item, DRAG_NONE);
-
- Control *control = Object::cast_to<Control>(canvas_item);
- ERR_FAIL_COND_V(!control, DRAG_NONE);
-
- Vector2 anchor_pos[4];
- anchor_pos[0] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_TOP));
- anchor_pos[1] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_TOP));
- anchor_pos[2] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_BOTTOM));
- anchor_pos[3] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_BOTTOM));
-
- Rect2 anchor_rects[4];
- for (int i = 0; i < 4; i++) {
- anchor_pos[i] = (transform * control->get_global_transform_with_canvas()).xform(_anchor_to_position(control, anchor_pos[i]));
- anchor_rects[i] = Rect2(anchor_pos[i], anchor_handle->get_size());
- anchor_rects[i].position -= anchor_handle->get_size() * Vector2(i == 0 || i == 3, i <= 1);
- }
-
- DragType dragger[] = {
- DRAG_ANCHOR_TOP_LEFT,
- DRAG_ANCHOR_TOP_RIGHT,
- DRAG_ANCHOR_BOTTOM_RIGHT,
- DRAG_ANCHOR_BOTTOM_LEFT,
- };
+void CanvasItemEditor::_save_canvas_item_state(List<CanvasItem *> p_canvas_items, bool save_bones) {
+ for (List<CanvasItem *>::Element *E = p_canvas_items.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
+ if (se) {
+ se->undo_state = canvas_item->_edit_get_state();
+ se->pre_drag_xform = canvas_item->get_global_transform_with_canvas();
+ se->pre_drag_rect = canvas_item->_edit_get_rect();
+
+ se->pre_drag_bones_length = List<float>();
+ se->pre_drag_bones_undo_state = List<Dictionary>();
+
+ // If we have a bone, save the state of all nodes in the IK chain
+ Node2D *bone = Object::cast_to<Node2D>(canvas_item);
+ if (bone && bone->has_meta("_edit_bone_")) {
+ // Check if we have an IK chain
+ List<Node2D *> bone_ik_list;
+ bool ik_found;
+ bone = Object::cast_to<Node2D>(bone->get_parent());
+ while (bone) {
+ bone_ik_list.push_back(bone);
+ if (bone->has_meta("_edit_ik_")) {
+ ik_found = true;
+ break;
+ } else if (!bone->has_meta("_edit_bone_")) {
+ break;
+ }
+ bone = Object::cast_to<Node2D>(bone->get_parent());
+ }
- for (int i = 0; i < 4; i++) {
- if (anchor_rects[i].has_point(p_click)) {
- r_point = transform.affine_inverse().xform(anchor_pos[i]);
- if ((anchor_pos[0] == anchor_pos[2]) && (anchor_pos[0].distance_to(p_click) < anchor_handle->get_size().length() / 3.0)) {
- return DRAG_ANCHOR_ALL;
- } else {
- return dragger[i];
+ //Save the bone state and lenght if we have an IK chain
+ if (ik_found) {
+ bone = Object::cast_to<Node2D>(canvas_item);
+ Transform2D bone_xform = bone->get_global_transform();
+ for (List<Node2D *>::Element *bone_E = bone_ik_list.front(); bone_E; bone_E = bone_E->next()) {
+ bone_xform = bone_xform * bone->get_transform().affine_inverse();
+ Node2D *parent_bone = bone_E->get();
+ se->pre_drag_bones_length.push_back(parent_bone->get_global_transform().get_origin().distance_to(bone->get_global_position()));
+ se->pre_drag_bones_undo_state.push_back(parent_bone->_edit_get_state());
+ bone = parent_bone;
+ }
+ }
}
}
}
-
- return DRAG_NONE;
}
-void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) {
-
- List<Node *> selection = editor_selection->get_selected_node_list();
-
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
+void CanvasItemEditor::_restore_canvas_item_state(List<CanvasItem *> p_canvas_items, bool restore_bones) {
+ for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
- if (!se)
- continue;
-
- se->undo_state = canvas_item->_edit_get_state();
- if (Object::cast_to<Node2D>(canvas_item))
- se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->_edit_get_pivot();
- if (Object::cast_to<Control>(canvas_item))
- se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
-
- se->pre_drag_xform = canvas_item->get_global_transform_with_canvas();
- se->pre_drag_rect = canvas_item->_edit_get_rect();
- }
-
- if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0]) && bone_ik_list.size() == 0) {
- drag = DRAG_NODE_2D;
- drag_point_from = Object::cast_to<Node2D>(selection[0])->get_global_position();
- } else {
- drag = DRAG_ALL;
- drag_point_from = _find_topleftmost_point();
- }
- drag_from = transform.affine_inverse().xform(p_click_pos);
-}
-
-void CanvasItemEditor::incbeg(float &beg, float &end, float inc, float minsize, bool p_symmetric) {
-
- if (minsize < 0) {
-
- beg += inc;
- if (p_symmetric)
- 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;
+ canvas_item->_edit_set_state(se->undo_state);
+ if (restore_bones) {
+ for (List<Dictionary>::Element *E = se->pre_drag_bones_undo_state.front(); E; E = E->next()) {
+ canvas_item = Object::cast_to<CanvasItem>(canvas_item->get_parent());
+ canvas_item->_edit_set_state(E->get());
}
-
- } else {
- if (end - (beg + inc) < minsize)
- beg = end - minsize;
- else
- beg += inc;
}
}
}
-void CanvasItemEditor::incend(float &beg, float &end, float inc, float minsize, bool p_symmetric) {
-
- if (minsize < 0) {
-
- end += inc;
- if (p_symmetric)
- 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;
+void CanvasItemEditor::_commit_canvas_item_state(List<CanvasItem *> p_canvas_items, String action_name, bool commit_bones) {
+ undo_redo->create_action(action_name);
+ for (List<CanvasItem *>::Element *E = p_canvas_items.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
+ undo_redo->add_do_method(canvas_item, "_edit_set_state", canvas_item->_edit_get_state());
+ undo_redo->add_undo_method(canvas_item, "_edit_set_state", se->undo_state);
+ if (commit_bones) {
+ for (List<Dictionary>::Element *E = se->pre_drag_bones_undo_state.front(); E; E = E->next()) {
+ canvas_item = Object::cast_to<CanvasItem>(canvas_item->get_parent());
+ undo_redo->add_do_method(canvas_item, "_edit_set_state", canvas_item->_edit_get_state());
+ undo_redo->add_undo_method(canvas_item, "_edit_set_state", E->get());
}
-
- } else {
- if ((end + inc) - beg < minsize)
- end = beg + minsize;
- else
- end += inc;
}
}
-}
-
-void CanvasItemEditor::_append_canvas_item(CanvasItem *p_item) {
-
- editor_selection->add_node(p_item);
+ undo_redo->add_do_method(viewport, "update");
+ undo_redo->add_undo_method(viewport, "update");
+ undo_redo->commit_action();
}
void CanvasItemEditor::_snap_changed() {
((SnapDialog *)snap_dialog)->get_fields(grid_offset, grid_step, snap_rotation_offset, snap_rotation_step);
grid_step_multiplier = 0;
- viewport_base->update();
viewport->update();
}
@@ -1111,7 +662,7 @@ void CanvasItemEditor::_selection_result_pressed(int p_result) {
CanvasItem *item = selection_results[p_result].item;
if (item)
- _select_click_on_item(item, Point2(), additive_selection, false);
+ _select_click_on_item(item, Point2(), selection_menu_additive_selection);
}
void CanvasItemEditor::_selection_menu_hide() {
@@ -1121,124 +672,16 @@ void CanvasItemEditor::_selection_menu_hide() {
selection_menu->set_size(Vector2(0, 0));
}
-void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) {
-
- Point2 click = viewport_scrollable->get_transform().affine_inverse().xform(b->get_position());
-
- Node *scene = editor->get_edited_scene();
- if (!scene)
- return;
-
- _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())) {
- //invalid result
- selection_results.remove(i);
- i--;
- }
- }
-
- if (selection_results.size() == 1) {
-
- CanvasItem *item = selection_results[0].item;
- selection_results.clear();
-
- additive_selection = b->get_shift();
-
- if (!_select_click_on_item(item, click, additive_selection, false))
- return;
-
- } else if (!selection_results.empty()) {
-
- 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);
-
- for (int i = 0; i < selection_results.size(); i++) {
-
- CanvasItem *item = selection_results[i].item;
-
- Ref<Texture> icon;
- if (item->has_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");
-
- 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_metadata(i, node_path);
- selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path);
- }
-
- additive_selection = b->get_shift();
-
- selection_menu->set_global_position(b->get_global_position());
- selection_menu->popup();
- selection_menu->call_deferred("grab_click_focus");
- selection_menu->set_invalidate_click_until_motion();
-
- return;
- }
-}
-
-void CanvasItemEditor::_update_cursor() {
-
- CursorShape c = CURSOR_ARROW;
- switch (drag) {
- case DRAG_NONE:
- if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
- c = CURSOR_DRAG;
- } else {
- switch (tool) {
- case TOOL_MOVE:
- c = CURSOR_MOVE;
- break;
- case TOOL_EDIT_PIVOT:
- c = CURSOR_CROSS;
- break;
- case TOOL_PAN:
- c = CURSOR_DRAG;
- break;
- }
- }
- break;
- case DRAG_LEFT:
- case DRAG_RIGHT:
- c = CURSOR_HSIZE;
- break;
- case DRAG_TOP:
- case DRAG_BOTTOM:
- c = CURSOR_VSIZE;
- break;
- case DRAG_TOP_LEFT:
- case DRAG_BOTTOM_RIGHT:
- c = CURSOR_FDIAGSIZE;
- break;
- case DRAG_TOP_RIGHT:
- case DRAG_BOTTOM_LEFT:
- c = CURSOR_BDIAGSIZE;
- break;
- case DRAG_ALL:
- case DRAG_NODE_2D:
- c = CURSOR_MOVE;
- break;
- }
- viewport->set_default_cursor_shape(c);
-}
-
-void CanvasItemEditor::_gui_input_viewport_base(const Ref<InputEvent> &p_event) {
-
+bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
- if (b.is_valid()) {
- if (b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
+ Ref<InputEventMouseMotion> m = p_event;
+
+ // Start draging a guide
+ if (drag_type == DRAG_NONE) {
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
if (show_guides && show_rulers && EditorNode::get_singleton()->get_edited_scene()) {
Transform2D xform = viewport_scrollable->get_transform() * transform;
- // Retrieve the guide lists
+ // Retreive the guide lists
Array vguides;
if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
@@ -1251,48 +694,64 @@ void CanvasItemEditor::_gui_input_viewport_base(const Ref<InputEvent> &p_event)
// Press button
if (b->get_position().x < RULER_WIDTH && b->get_position().y < RULER_WIDTH) {
// Drag a new double guide
- drag = DRAG_DOUBLE_GUIDE;
- edited_guide_index = -1;
+ drag_type = DRAG_DOUBLE_GUIDE;
+ dragged_guide_index = -1;
+ return true;
} else if (b->get_position().x < RULER_WIDTH) {
// Check if we drag an existing horizontal guide
float minimum = 1e20;
- edited_guide_index = -1;
+ dragged_guide_index = -1;
for (int i = 0; i < hguides.size(); i++) {
if (ABS(xform.xform(Point2(0, hguides[i])).y - b->get_position().y) < MIN(minimum, 8)) {
- edited_guide_index = i;
+ dragged_guide_index = i;
}
}
- if (edited_guide_index >= 0) {
+ if (dragged_guide_index >= 0) {
// Drag an existing horizontal guide
- drag = DRAG_H_GUIDE;
+ drag_type = DRAG_H_GUIDE;
} else {
// Drag a new vertical guide
- drag = DRAG_V_GUIDE;
+ drag_type = DRAG_V_GUIDE;
}
+ return true;
} else if (b->get_position().y < RULER_WIDTH) {
// Check if we drag an existing vertical guide
float minimum = 1e20;
- edited_guide_index = -1;
+ dragged_guide_index = -1;
for (int i = 0; i < vguides.size(); i++) {
if (ABS(xform.xform(Point2(vguides[i], 0)).x - b->get_position().x) < MIN(minimum, 8)) {
- edited_guide_index = i;
+ dragged_guide_index = i;
}
}
- if (edited_guide_index >= 0) {
+ if (dragged_guide_index >= 0) {
// Drag an existing vertical guide
- drag = DRAG_V_GUIDE;
+ drag_type = DRAG_V_GUIDE;
} else {
// Drag a new vertical guide
- drag = DRAG_H_GUIDE;
+ drag_type = DRAG_H_GUIDE;
}
+ drag_from = xform.affine_inverse().xform(b->get_position());
+ return true;
}
}
}
+ }
- if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
- // Release button
+ if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_V_GUIDE || drag_type == DRAG_H_GUIDE) {
+ // Move the guide
+ if (m.is_valid()) {
+ Transform2D xform = viewport_scrollable->get_transform() * transform;
+ drag_to = xform.affine_inverse().xform(m->get_position());
+
+ dragged_guide_pos = xform.xform(snap_point(drag_to, SNAP_GRID | SNAP_PIXEL | SNAP_OTHER_NODES));
+ viewport->update();
+ return true;
+ }
+
+ // Release confirms the guide move
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
if (show_guides && EditorNode::get_singleton()->get_edited_scene()) {
Transform2D xform = viewport_scrollable->get_transform() * transform;
@@ -1307,65 +766,65 @@ void CanvasItemEditor::_gui_input_viewport_base(const Ref<InputEvent> &p_event)
}
Point2 edited = snap_point(xform.affine_inverse().xform(b->get_position()), SNAP_GRID | SNAP_PIXEL | SNAP_OTHER_NODES);
- if (drag == DRAG_V_GUIDE) {
+ if (drag_type == DRAG_V_GUIDE) {
Array prev_vguides = vguides.duplicate();
if (b->get_position().x > RULER_WIDTH) {
// Adds a new vertical guide
- if (edited_guide_index >= 0) {
- vguides[edited_guide_index] = edited.x;
+ if (dragged_guide_index >= 0) {
+ vguides[dragged_guide_index] = edited.x;
undo_redo->create_action(TTR("Move vertical guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
- undo_redo->add_undo_method(viewport_base, "update");
+ undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
} else {
vguides.push_back(edited.x);
undo_redo->create_action(TTR("Create new vertical guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
- undo_redo->add_undo_method(viewport_base, "update");
+ undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
}
} else {
- if (edited_guide_index >= 0) {
- vguides.remove(edited_guide_index);
+ if (dragged_guide_index >= 0) {
+ vguides.remove(dragged_guide_index);
undo_redo->create_action(TTR("Remove vertical guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
- undo_redo->add_undo_method(viewport_base, "update");
+ undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
}
}
- } else if (drag == DRAG_H_GUIDE) {
+ } else if (drag_type == DRAG_H_GUIDE) {
Array prev_hguides = hguides.duplicate();
if (b->get_position().y > RULER_WIDTH) {
// Adds a new horizontal guide
- if (edited_guide_index >= 0) {
- hguides[edited_guide_index] = edited.y;
+ if (dragged_guide_index >= 0) {
+ hguides[dragged_guide_index] = edited.y;
undo_redo->create_action(TTR("Move horizontal guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
- undo_redo->add_undo_method(viewport_base, "update");
+ undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
} else {
hguides.push_back(edited.y);
undo_redo->create_action(TTR("Create new horizontal guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
- undo_redo->add_undo_method(viewport_base, "update");
+ undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
}
} else {
- if (edited_guide_index >= 0) {
- hguides.remove(edited_guide_index);
+ if (dragged_guide_index >= 0) {
+ hguides.remove(dragged_guide_index);
undo_redo->create_action(TTR("Remove horizontal guide"));
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
- undo_redo->add_undo_method(viewport_base, "update");
+ undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
}
}
- } else if (drag == DRAG_DOUBLE_GUIDE) {
+ } else if (drag_type == DRAG_DOUBLE_GUIDE) {
Array prev_hguides = hguides.duplicate();
Array prev_vguides = vguides.duplicate();
if (b->get_position().x > RULER_WIDTH && b->get_position().y > RULER_WIDTH) {
@@ -1377,96 +836,22 @@ void CanvasItemEditor::_gui_input_viewport_base(const Ref<InputEvent> &p_event)
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
- undo_redo->add_undo_method(viewport_base, "update");
+ undo_redo->add_undo_method(viewport, "update");
undo_redo->commit_action();
}
}
}
- if (drag == DRAG_DOUBLE_GUIDE || drag == DRAG_V_GUIDE || drag == DRAG_H_GUIDE) {
- drag = DRAG_NONE;
- viewport_base->update();
- }
- }
- }
-
- Ref<InputEventMouseMotion> m = p_event;
- if (m.is_valid()) {
- if (!viewport_base->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) {
- viewport_base->call_deferred("grab_focus");
- }
- if (drag == DRAG_DOUBLE_GUIDE || drag == DRAG_H_GUIDE || drag == DRAG_V_GUIDE) {
- Transform2D xform = viewport_scrollable->get_transform() * transform;
- Point2 mouse_pos = m->get_position();
- mouse_pos = xform.affine_inverse().xform(mouse_pos);
- mouse_pos = xform.xform(snap_point(mouse_pos, SNAP_GRID | SNAP_PIXEL | SNAP_OTHER_NODES));
-
- edited_guide_pos = mouse_pos;
- viewport_base->update();
- }
- }
-
- Ref<InputEventKey> k = p_event;
- if (k.is_valid()) {
- if (k->is_pressed() && drag == DRAG_NONE) {
- // Move the object with the arrow keys
- KeyMoveMODE move_mode = MOVE_VIEW_BASE;
- if (k->get_alt()) move_mode = MOVE_LOCAL_BASE;
- if (k->get_control() || k->get_metakey()) move_mode = MOVE_LOCAL_WITH_ROT;
-
- if (k->get_scancode() == KEY_UP)
- _key_move(Vector2(0, -1), k->get_shift(), move_mode);
- else if (k->get_scancode() == KEY_DOWN)
- _key_move(Vector2(0, 1), k->get_shift(), move_mode);
- else if (k->get_scancode() == KEY_LEFT)
- _key_move(Vector2(-1, 0), k->get_shift(), move_mode);
- else if (k->get_scancode() == KEY_RIGHT)
- _key_move(Vector2(1, 0), k->get_shift(), move_mode);
- else if (k->get_scancode() == KEY_ESCAPE) {
- editor_selection->clear();
- viewport->update();
- } else
- return;
-
- accept_event();
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
}
}
+ return false;
}
-void CanvasItemEditor::_gui_input_viewport(const Ref<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(p_event);
- if (discard) {
- accept_event();
- return;
- }
- }
- }
-
- Ref<InputEventMagnifyGesture> magnify_gesture = p_event;
- if (magnify_gesture.is_valid()) {
-
- _zoom_on_position(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position());
- return;
- }
-
- Ref<InputEventPanGesture> pan_gesture = p_event;
- if (pan_gesture.is_valid()) {
-
- const Vector2 delta = (int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom) * pan_gesture->get_delta();
- h_scroll->set_value(h_scroll->get_value() + delta.x);
- v_scroll->set_value(v_scroll->get_value() + delta.y);
- return;
- }
-
+bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- // Button event
-
if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
// Scroll or pan down
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
@@ -1476,8 +861,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
} else {
_zoom_on_position(zoom * (1 - (0.05 * b->get_factor())), b->get_position());
}
-
- return;
+ return true;
}
if (b->get_button_index() == BUTTON_WHEEL_UP) {
@@ -1489,768 +873,988 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
} else {
_zoom_on_position(zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95), b->get_position());
}
-
- return;
+ return true;
}
if (b->get_button_index() == BUTTON_WHEEL_LEFT) {
// Pan left
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
-
h_scroll->set_value(h_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor());
+ return true;
}
}
if (b->get_button_index() == BUTTON_WHEEL_RIGHT) {
// Pan right
if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) {
-
h_scroll->set_value(h_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor());
+ return true;
}
}
+ }
- if (b->get_button_index() == BUTTON_RIGHT) {
+ Ref<InputEventMouseMotion> m = p_event;
+ if (m.is_valid()) {
+ if (drag_type == DRAG_NONE) {
+ if (((m->get_button_mask() & BUTTON_MASK_LEFT) && tool == TOOL_PAN) ||
+ (m->get_button_mask() & BUTTON_MASK_MIDDLE) ||
+ ((m->get_button_mask() & BUTTON_MASK_LEFT) && Input::get_singleton()->is_key_pressed(KEY_SPACE)) ||
+ (EditorSettings::get_singleton()->get("editors/2d/simple_spacebar_panning") && Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
+ // Pan the viewport
+ Point2i relative;
+ if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) {
+ relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect());
+ } else {
+ relative = m->get_relative();
+ }
- if (b->is_pressed() && (tool == TOOL_SELECT && b->get_alt())) {
- // Open the selection list
- _list_select(b);
- return;
+ h_scroll->set_value(h_scroll->get_value() - relative.x / zoom);
+ v_scroll->set_value(v_scroll->get_value() - relative.y / zoom);
+ return true;
}
+ }
+ }
- if (get_item_count() > 0 && drag != DRAG_NONE) {
- // Cancel a drag
- if (bone_ik_list.size()) {
- for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) {
- E->get().node->_edit_set_state(E->get().orig_state);
- }
+ Ref<InputEventMagnifyGesture> magnify_gesture = p_event;
+ if (magnify_gesture.is_valid()) {
+ // Zoom gesture
+ _zoom_on_position(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position());
+ return true;
+ }
- bone_ik_list.clear();
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+ // Pan gesture
+ const Vector2 delta = (int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom) * pan_gesture->get_delta();
+ h_scroll->set_value(h_scroll->get_value() + delta.x);
+ v_scroll->set_value(v_scroll->get_value() + delta.y);
+ return true;
+ }
- } else {
- List<Node *> selection = editor_selection->get_selected_node_list();
-
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
- if (!se)
- continue;
-
- canvas_item->_edit_set_state(se->undo_state);
- if (Object::cast_to<Node2D>(canvas_item))
- Object::cast_to<Node2D>(canvas_item)->_edit_set_pivot(se->undo_pivot);
- if (Object::cast_to<Control>(canvas_item))
- Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot);
- }
- }
+ return false;
+}
- drag = DRAG_NONE;
- viewport->update();
- can_move_pivot = false;
+bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseMotion> m = p_event;
+ Ref<InputEventMouseButton> b = p_event;
+ Ref<InputEventKey> k = p_event;
- } else if (box_selecting) {
- // Cancel box selection
- box_selecting = false;
- viewport->update();
+ // Drag the pivot (in pivot mode / with V key)
+ if (drag_type == DRAG_NONE) {
+ if ((b.is_valid() && b->is_pressed() && b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) ||
+ (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_scancode() == KEY_V)) {
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+
+ // Filters the selection with nodes that allow setting the pivot
+ drag_selection = List<CanvasItem *>();
+ for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ if (canvas_item->_edit_use_pivot()) {
+ drag_selection.push_back(canvas_item);
+ }
}
- return;
- }
- if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_LIST_SELECT) {
- if (b->is_pressed())
- // Open the selection list
- _list_select(b);
- return;
- }
+ // Start dragging if we still have nodes
+ if (drag_selection.size() > 0) {
+ drag_from = transform.affine_inverse().xform((b.is_valid()) ? b->get_position() : viewport->get_local_mouse_position());
+ Vector2 new_pos;
+ if (drag_selection.size() == 1)
+ new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]);
+ else
+ new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL);
+ for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos));
+ }
- if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) {
- if (b->is_pressed()) {
- // Set the pivot point
- Point2 mouse_pos = b->get_position();
- mouse_pos = transform.affine_inverse().xform(mouse_pos);
- mouse_pos = snap_point(mouse_pos, SNAP_DEFAULT, _get_single_item());
- _edit_set_pivot(mouse_pos);
+ drag_type = DRAG_PIVOT;
+ _save_canvas_item_state(drag_selection);
}
- return;
+ return true;
}
+ }
- if (tool == TOOL_PAN || b->get_button_index() != BUTTON_LEFT || Input::get_singleton()->is_key_pressed(KEY_SPACE))
- // Pan the view
- return;
-
- // -- From now we consider that the button is BUTTON_LEFT --
+ if (drag_type == DRAG_PIVOT) {
+ // Move the pivot
+ if (m.is_valid()) {
+ drag_to = transform.affine_inverse().xform(m->get_position());
+ _restore_canvas_item_state(drag_selection);
+ Vector2 new_pos;
+ if (drag_selection.size() == 1)
+ new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]);
+ else
+ new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL);
+ for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos));
+ }
+ return true;
+ }
- if (!b->is_pressed()) {
+ // Confirm the pivot move
+ if ((b.is_valid() && !b->is_pressed() && b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) ||
+ (k.is_valid() && !k->is_pressed() && k->get_scancode() == KEY_V)) {
+ _commit_canvas_item_state(drag_selection, TTR("Move pivot"));
+ drag_type = DRAG_NONE;
+ return true;
+ }
- if (drag != DRAG_NONE) {
- // Stop dragging
- if (undo_redo) {
+ // Cancel a drag
+ if (b.is_valid() && b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
+ _restore_canvas_item_state(drag_selection);
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
+ }
+ }
+ return false;
+}
- if (bone_ik_list.size()) {
- undo_redo->create_action(TTR("Edit IK Chain"));
+void CanvasItemEditor::_solve_IK(Node2D *leaf_node, Point2 target_position) {
+ CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(leaf_node);
+ if (se && !se->pre_drag_bones_undo_state.empty()) {
+
+ // Build the node list
+ Point2 leaf_pos = target_position;
+
+ List<Node2D *> joints_list;
+ List<Point2> joints_pos;
+ Node2D *joint = leaf_node;
+ Transform2D joint_transform = leaf_node->get_global_transform_with_canvas();
+ for (int i = 0; i < se->pre_drag_bones_undo_state.size() + 1; i++) {
+ joints_list.push_back(joint);
+ joints_pos.push_back(joint_transform.get_origin());
+ joint_transform = joint_transform * joint->get_transform().affine_inverse();
+ joint = Object::cast_to<Node2D>(joint->get_parent());
+ }
+ Point2 root_pos = joints_list.back()->get()->get_global_transform_with_canvas().get_origin();
- for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) {
+ // Restraints the node to a maximum distance is necessary
+ float total_len = 0;
+ for (List<float>::Element *E = se->pre_drag_bones_length.front(); E; E = E->next()) {
+ total_len += E->get();
+ }
+ if ((root_pos.distance_to(leaf_pos)) > total_len) {
+ Vector2 rel = leaf_pos - root_pos;
+ rel = rel.normalized() * total_len;
+ leaf_pos = root_pos + rel;
+ }
+ joints_pos[0] = leaf_pos;
+
+ // Run the solver
+ int solver_iterations = 64;
+ float solver_k = 0.3;
+
+ // Build the position list
+ for (int i = 0; i < solver_iterations; i++) {
+ // Handle the leaf joint
+ int node_id = 0;
+ for (List<float>::Element *E = se->pre_drag_bones_length.front(); E; E = E->next()) {
+ Vector2 direction = (joints_pos[node_id + 1] - joints_pos[node_id]).normalized();
+ int len = E->get();
+ if (E == se->pre_drag_bones_length.front()) {
+ joints_pos[1] = joints_pos[1].linear_interpolate(joints_pos[0] + len * direction, solver_k);
+ } else if (E == se->pre_drag_bones_length.back()) {
+ joints_pos[node_id] = joints_pos[node_id].linear_interpolate(joints_pos[node_id + 1] - len * direction, solver_k);
+ } else {
+ Vector2 center = (joints_pos[node_id + 1] + joints_pos[node_id]) / 2.0;
+ joints_pos[node_id] = joints_pos[node_id].linear_interpolate(center - (direction * len) / 2.0, solver_k);
+ joints_pos[node_id + 1] = joints_pos[node_id + 1].linear_interpolate(center + (direction * len) / 2.0, solver_k);
+ }
+ node_id++;
+ }
+ }
- 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);
- }
+ // Set the position
+ float total_rot = 0.0f;
+ for (int node_id = joints_list.size() - 1; node_id > 0; node_id--) {
+ Point2 current = (joints_list[node_id - 1]->get_global_position() - joints_list[node_id]->get_global_position()).normalized();
+ Point2 target = (joints_pos[node_id - 1] - joints_list[node_id]->get_global_position()).normalized();
+ float rot = current.angle_to(target);
+ if (joints_list[node_id]->get_global_transform().basis_determinant() < 0) {
+ rot = -rot;
+ }
+ joints_list[node_id]->rotate(rot);
+ total_rot += rot;
+ }
- undo_redo->add_do_method(viewport, "update");
- undo_redo->add_undo_method(viewport, "update");
+ joints_list[0]->rotate(-total_rot);
+ }
+}
- bone_ik_list.clear();
+bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> b = p_event;
+ Ref<InputEventMouseMotion> m = p_event;
- undo_redo->commit_action();
- } else {
- undo_redo->create_action(TTR("Edit CanvasItem"));
-
- List<Node *> selection = editor_selection->get_selected_node_list();
-
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- 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);
- {
- Node2D *pvt = Object::cast_to<Node2D>(canvas_item);
- if (pvt && pvt->_edit_use_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);
- }
-
- Control *cnt = Object::cast_to<Control>(canvas_item);
- if (cnt) {
- undo_redo->add_do_method(canvas_item, "set_pivot_offset", cnt->get_pivot_offset());
- undo_redo->add_undo_method(canvas_item, "set_pivot_offset", se->undo_pivot);
- }
- }
- }
- undo_redo->commit_action();
- }
+ // Start rotation
+ if (drag_type == DRAG_NONE) {
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
+ drag_selection = _get_edited_canvas_items();
+ if (drag_selection.size() > 0 && ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE)) {
+ drag_type = DRAG_ROTATE;
+ drag_from = transform.affine_inverse().xform(b->get_position());
+ CanvasItem *canvas_item = drag_selection[0];
+ if (canvas_item->_edit_use_pivot()) {
+ drag_rotation_center = canvas_item->get_global_transform_with_canvas().xform(canvas_item->_edit_get_pivot());
+ } else {
+ drag_rotation_center = canvas_item->get_global_transform_with_canvas().get_origin();
}
+ _save_canvas_item_state(drag_selection);
+ return true;
+ }
+ }
+ }
- drag = DRAG_NONE;
+ if (drag_type == DRAG_ROTATE) {
+ // Rotate the node
+ if (m.is_valid()) {
+ _restore_canvas_item_state(drag_selection);
+ for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ drag_to = transform.affine_inverse().xform(m->get_position());
+ canvas_item->_edit_set_rotation(snap_angle(canvas_item->_edit_get_rotation() + (drag_from - drag_rotation_center).angle_to(drag_to - drag_rotation_center), canvas_item->_edit_get_rotation()));
viewport->update();
- can_move_pivot = false;
}
+ return true;
+ }
- if (box_selecting) {
- // Stop box selection
- Node *scene = editor->get_edited_scene();
- if (scene) {
-
- 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);
-
- _find_canvas_items_at_rect(Rect2(bsfrom, bsto - bsfrom), scene, transform, Transform2D(), &selitems);
+ // Confirms the node rotation
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
+ _commit_canvas_item_state(drag_selection, TTR("Rotate CanvasItem"));
+ drag_type = DRAG_NONE;
+ return true;
+ }
- for (List<CanvasItem *>::Element *E = selitems.front(); E; E = E->next()) {
+ // Cancel a drag
+ if (b.is_valid() && b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
+ _restore_canvas_item_state(drag_selection);
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
+ }
+ }
+ return false;
+}
- _append_canvas_item(E->get());
- }
- }
+bool CanvasItemEditor::_gui_input_open_scene_on_double_click(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> b = p_event;
- box_selecting = false;
- viewport->update();
+ // Open a sub-scene on double-click
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed() && b->is_doubleclick() && tool == TOOL_SELECT) {
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+ if (selection.size() == 1) {
+ CanvasItem *canvas_item = selection[0];
+ if (canvas_item->get_filename() != "" && canvas_item != editor->get_edited_scene()) {
+ editor->open_request(canvas_item->get_filename());
+ return true;
}
- return;
}
+ }
+ return false;
+}
- // -- From now we consider that the button is BUTTON_LEFT and that it is pressed --
+bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> b = p_event;
+ Ref<InputEventMouseMotion> m = p_event;
- Map<ObjectID, BoneList>::Element *Cbone = NULL; //closest
+ // Starts anchor dragging if needed
+ if (drag_type == DRAG_NONE) {
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed() && tool == TOOL_SELECT && show_helpers) {
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+ if (selection.size() == 1) {
+ Control *control = Object::cast_to<Control>(selection[0]);
+ if (control && !Object::cast_to<Container>(control->get_parent())) {
+ Vector2 anchor_pos[4];
+ anchor_pos[0] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_TOP));
+ anchor_pos[1] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_TOP));
+ anchor_pos[2] = Vector2(control->get_anchor(MARGIN_RIGHT), control->get_anchor(MARGIN_BOTTOM));
+ anchor_pos[3] = Vector2(control->get_anchor(MARGIN_LEFT), control->get_anchor(MARGIN_BOTTOM));
- {
- bone_ik_list.clear();
- 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()) {
+ Rect2 anchor_rects[4];
+ for (int i = 0; i < 4; i++) {
+ anchor_pos[i] = (transform * control->get_global_transform_with_canvas()).xform(_anchor_to_position(control, anchor_pos[i]));
+ anchor_rects[i] = Rect2(anchor_pos[i], anchor_handle->get_size());
+ anchor_rects[i].position -= anchor_handle->get_size() * Vector2(i == 0 || i == 3, i <= 1);
+ }
- if (E->get().from == E->get().to)
- continue;
- Vector2 s[2] = {
- E->get().from,
- E->get().to
- };
+ DragType dragger[] = {
+ DRAG_ANCHOR_TOP_LEFT,
+ DRAG_ANCHOR_TOP_RIGHT,
+ DRAG_ANCHOR_BOTTOM_RIGHT,
+ DRAG_ANCHOR_BOTTOM_LEFT,
+ };
- Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_position(), s);
- float d = p.distance_to(b->get_position());
- if (d < bone_width && d < closest_dist) {
- Cbone = E;
- closest_dist = d;
+ for (int i = 0; i < 4; i++) {
+ if (anchor_rects[i].has_point(b->get_position())) {
+ if ((anchor_pos[0] == anchor_pos[2]) && (anchor_pos[0].distance_to(b->get_position()) < anchor_handle->get_size().length() / 3.0)) {
+ drag_type = DRAG_ANCHOR_ALL;
+ } else {
+ drag_type = dragger[i];
+ }
+ drag_from = transform.affine_inverse().xform(b->get_position());
+ drag_selection = List<CanvasItem *>();
+ drag_selection.push_back(control);
+ _save_canvas_item_state(drag_selection);
+ return true;
+ }
+ }
}
}
+ }
+ }
- if (Cbone) {
- Node2D *b = Object::cast_to<Node2D>(ObjectDB::get_instance(Cbone->get().bone));
+ if (drag_type == DRAG_ANCHOR_TOP_LEFT || drag_type == DRAG_ANCHOR_TOP_RIGHT || drag_type == DRAG_ANCHOR_BOTTOM_RIGHT || drag_type == DRAG_ANCHOR_BOTTOM_LEFT || drag_type == DRAG_ANCHOR_ALL) {
+ // Drag the anchor
+ if (m.is_valid()) {
+ _restore_canvas_item_state(drag_selection);
+ Control *control = Object::cast_to<Control>(drag_selection[0]);
- if (b) {
+ drag_to = transform.affine_inverse().xform(m->get_position());
- bool ik_found = false;
+ Transform2D xform = control->get_global_transform_with_canvas().affine_inverse();
- bool first = true;
+ Point2 previous_anchor;
+ previous_anchor.x = (drag_type == DRAG_ANCHOR_TOP_LEFT || drag_type == DRAG_ANCHOR_BOTTOM_LEFT) ? control->get_anchor(MARGIN_LEFT) : control->get_anchor(MARGIN_RIGHT);
+ previous_anchor.y = (drag_type == DRAG_ANCHOR_TOP_LEFT || drag_type == DRAG_ANCHOR_TOP_RIGHT) ? control->get_anchor(MARGIN_TOP) : control->get_anchor(MARGIN_BOTTOM);
+ previous_anchor = xform.affine_inverse().xform(_anchor_to_position(control, previous_anchor));
- while (b) {
+ Vector2 new_anchor = xform.xform(snap_point(previous_anchor + (drag_to - drag_from), SNAP_GRID | SNAP_OTHER_NODES, control, SNAP_NODE_PARENT | SNAP_NODE_SIDES | SNAP_NODE_CENTER));
+ new_anchor = _position_to_anchor(control, new_anchor).snapped(Vector2(0.001, 0.001));
- CanvasItem *pi = b->get_parent_item();
- if (!pi)
- break;
+ bool use_single_axis = m->get_shift();
+ Vector2 drag_vector = xform.xform(drag_to) - xform.xform(drag_from);
+ bool use_y = Math::abs(drag_vector.y) > Math::abs(drag_vector.x);
- float len = pi->get_global_transform().get_origin().distance_to(b->get_global_position());
- b = Object::cast_to<Node2D>(pi);
- if (!b)
- break;
+ switch (drag_type) {
+ case DRAG_ANCHOR_TOP_LEFT:
+ if (!use_single_axis || (use_single_axis && !use_y)) control->set_anchor(MARGIN_LEFT, new_anchor.x, false, false);
+ if (!use_single_axis || (use_single_axis && use_y)) control->set_anchor(MARGIN_TOP, new_anchor.y, false, false);
+ break;
+ case DRAG_ANCHOR_TOP_RIGHT:
+ if (!use_single_axis || (use_single_axis && !use_y)) control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, false);
+ if (!use_single_axis || (use_single_axis && use_y)) control->set_anchor(MARGIN_TOP, new_anchor.y, false, false);
+ break;
+ case DRAG_ANCHOR_BOTTOM_RIGHT:
+ if (!use_single_axis || (use_single_axis && !use_y)) control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, false);
+ if (!use_single_axis || (use_single_axis && use_y)) control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, false);
+ break;
+ case DRAG_ANCHOR_BOTTOM_LEFT:
+ if (!use_single_axis || (use_single_axis && !use_y)) control->set_anchor(MARGIN_LEFT, new_anchor.x, false, false);
+ if (!use_single_axis || (use_single_axis && use_y)) control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, false);
+ break;
+ case DRAG_ANCHOR_ALL:
+ if (!use_single_axis || (use_single_axis && !use_y)) control->set_anchor(MARGIN_LEFT, new_anchor.x, false, true);
+ if (!use_single_axis || (use_single_axis && !use_y)) control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, true);
+ if (!use_single_axis || (use_single_axis && use_y)) control->set_anchor(MARGIN_TOP, new_anchor.y, false, true);
+ if (!use_single_axis || (use_single_axis && use_y)) control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, true);
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
- if (first) {
+ // Confirms new anchor position
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
+ _commit_canvas_item_state(drag_selection, TTR("Move anchor"));
+ drag_type = DRAG_NONE;
+ return true;
+ }
- bone_orig_xform = b->get_global_transform();
- first = false;
- }
+ // Cancel a drag
+ if (b.is_valid() && b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
+ _restore_canvas_item_state(drag_selection);
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
+ }
+ }
+ return false;
+}
- BoneIK bik;
- bik.node = b;
- bik.len = len;
- bik.orig_state = b->_edit_get_state();
+bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> b = p_event;
+ Ref<InputEventMouseMotion> m = p_event;
- bone_ik_list.push_back(bik);
+ // Drag resize handles
+ if (drag_type == DRAG_NONE) {
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed() && tool == TOOL_SELECT) {
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+ if (selection.size() == 1) {
+ CanvasItem *canvas_item = selection[0];
+
+ Rect2 rect = canvas_item->_edit_get_rect();
+ Transform2D xform = transform * canvas_item->get_global_transform_with_canvas();
+
+ Vector2 endpoints[4] = {
+ xform.xform(rect.position),
+ xform.xform(rect.position + Vector2(rect.size.x, 0)),
+ xform.xform(rect.position + rect.size),
+ xform.xform(rect.position + Vector2(0, rect.size.y))
+ };
- if (b->has_meta("_edit_ik_")) {
+ DragType dragger[] = {
+ DRAG_TOP_LEFT,
+ DRAG_TOP,
+ DRAG_TOP_RIGHT,
+ DRAG_RIGHT,
+ DRAG_BOTTOM_RIGHT,
+ DRAG_BOTTOM,
+ DRAG_BOTTOM_LEFT,
+ DRAG_LEFT
+ };
- ik_found = bone_ik_list.size() > 1;
- break;
- }
+ DragType resize_drag = DRAG_NONE;
+ float radius = (select_handle->get_size().width / 2) * 1.5;
- if (!pi->has_meta("_edit_bone_"))
- break;
- }
+ for (int i = 0; i < 4; i++) {
+ int prev = (i + 3) % 4;
+ int next = (i + 1) % 4;
- if (!ik_found)
- bone_ik_list.clear();
+ Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
+ ofs *= (select_handle->get_size().width / 2);
+ ofs += endpoints[i];
+ if (ofs.distance_to(b->get_position()) < radius)
+ resize_drag = dragger[i * 2];
+
+ ofs = (endpoints[i] + endpoints[next]) / 2;
+ ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2);
+ if (ofs.distance_to(b->get_position()) < radius)
+ resize_drag = dragger[i * 2 + 1];
+ }
+
+ if (resize_drag != DRAG_NONE) {
+ drag_type = resize_drag;
+ drag_from = transform.affine_inverse().xform(b->get_position());
+ drag_selection = List<CanvasItem *>();
+ drag_selection.push_back(canvas_item);
+ _save_canvas_item_state(drag_selection);
+ return true;
}
}
}
+ }
- // Single selected item
- CanvasItem *canvas_item = _get_single_item();
- if (canvas_item) {
+ if (drag_type == DRAG_LEFT || drag_type == DRAG_RIGHT || drag_type == DRAG_TOP || drag_type == DRAG_BOTTOM ||
+ drag_type == DRAG_TOP_LEFT || drag_type == DRAG_TOP_RIGHT || drag_type == DRAG_BOTTOM_LEFT || drag_type == DRAG_BOTTOM_RIGHT) {
+ // Resize the node
+ if (m.is_valid()) {
+ CanvasItem *canvas_item = drag_selection[0];
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
- ERR_FAIL_COND(!se);
-
- Point2 click = b->get_position();
-
- // Rotation
- if ((b->get_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();
- if (Object::cast_to<Node2D>(canvas_item))
- se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->_edit_get_pivot();
- if (Object::cast_to<Control>(canvas_item))
- se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
- se->pre_drag_xform = canvas_item->get_global_transform_with_canvas();
- se->pre_drag_rect = canvas_item->_edit_get_rect();
- return;
+ //Reset state
+ canvas_item->_edit_set_state(se->undo_state);
+
+ bool uniform = m->get_shift();
+ bool symmetric = m->get_alt();
+
+ Rect2 local_rect = canvas_item->_edit_get_rect();
+ float aspect = local_rect.get_size().y / local_rect.get_size().x;
+ Point2 current_begin = local_rect.get_position();
+ Point2 current_end = local_rect.get_position() + local_rect.get_size();
+ Point2 max_begin = (symmetric) ? (current_begin + current_end - canvas_item->_edit_get_minimum_size()) / 2.0 : current_end - canvas_item->_edit_get_minimum_size();
+ Point2 min_end = (symmetric) ? (current_begin + current_end + canvas_item->_edit_get_minimum_size()) / 2.0 : current_begin + canvas_item->_edit_get_minimum_size();
+ Point2 center = (current_begin + current_end) / 2.0;
+
+ drag_to = transform.affine_inverse().xform(m->get_position());
+
+ Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse();
+
+ Point2 drag_to_snapped_begin = snap_point(xform.affine_inverse().xform(current_begin) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item);
+ Point2 drag_to_snapped_end = snap_point(xform.affine_inverse().xform(current_end) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item);
+ Point2 drag_begin = xform.xform(drag_to_snapped_begin);
+ Point2 drag_end = xform.xform(drag_to_snapped_end);
+
+ // Horizontal resize
+ if (drag_type == DRAG_LEFT || drag_type == DRAG_TOP_LEFT || drag_type == DRAG_BOTTOM_LEFT) {
+ current_begin.x = MIN(drag_begin.x, max_begin.x);
+ } else if (drag_type == DRAG_RIGHT || drag_type == DRAG_TOP_RIGHT || drag_type == DRAG_BOTTOM_RIGHT) {
+ current_end.x = MAX(drag_end.x, min_end.x);
}
- if (tool == TOOL_SELECT) {
- // Open a sub-scene on double-click
- if (b->is_doubleclick()) {
- if (canvas_item->get_filename() != "" && canvas_item != editor->get_edited_scene()) {
- editor->open_request(canvas_item->get_filename());
- return;
+ // Vertical resize
+ if (drag_type == DRAG_TOP || drag_type == DRAG_TOP_LEFT || drag_type == DRAG_TOP_RIGHT) {
+ current_begin.y = MIN(drag_begin.y, max_begin.y);
+ } else if (drag_type == DRAG_BOTTOM || drag_type == DRAG_BOTTOM_LEFT || drag_type == DRAG_BOTTOM_RIGHT) {
+ current_end.y = MAX(drag_end.y, min_end.y);
+ }
+
+ // Uniform resize
+ if (uniform) {
+ if (drag_type == DRAG_LEFT || drag_type == DRAG_RIGHT) {
+ current_end.y = current_begin.y + aspect * (current_end.x - current_begin.x);
+ } else if (drag_type == DRAG_TOP || drag_type == DRAG_BOTTOM) {
+ current_end.x = current_begin.x + (current_end.y - current_begin.y) / aspect;
+ } else {
+ if (aspect >= 1.0) {
+ if (drag_type == DRAG_TOP_LEFT || drag_type == DRAG_TOP_RIGHT) {
+ current_begin.y = current_end.y - aspect * (current_end.x - current_begin.x);
+ } else {
+ current_end.y = current_begin.y + aspect * (current_end.x - current_begin.x);
+ }
+ } else {
+ if (drag_type == DRAG_TOP_LEFT || drag_type == DRAG_BOTTOM_LEFT) {
+ current_begin.x = current_end.x - (current_end.y - current_begin.y) / aspect;
+ } else {
+ current_end.x = current_begin.x + (current_end.y - current_begin.y) / aspect;
+ }
}
}
+ }
- // Drag resize handles
- drag = _get_resize_handle_drag_type(click, drag_point_from);
- if (drag != DRAG_NONE) {
- drag_from = transform.affine_inverse().xform(click);
- se->undo_state = canvas_item->_edit_get_state();
- if (Object::cast_to<Node2D>(canvas_item))
- se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->_edit_get_pivot();
- if (Object::cast_to<Control>(canvas_item))
- se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
- se->pre_drag_xform = canvas_item->get_global_transform_with_canvas();
- se->pre_drag_rect = canvas_item->_edit_get_rect();
- return;
+ // Symmetric resize
+ if (symmetric) {
+ if (drag_type == DRAG_LEFT || drag_type == DRAG_TOP_LEFT || drag_type == DRAG_BOTTOM_LEFT) {
+ current_end.x = 2.0 * center.x - current_begin.x;
+ } else if (drag_type == DRAG_RIGHT || drag_type == DRAG_TOP_RIGHT || drag_type == DRAG_BOTTOM_RIGHT) {
+ current_begin.x = 2.0 * center.x - current_end.x;
}
-
- // Drag anchor handles
- Control *control = Object::cast_to<Control>(canvas_item);
- if (control && show_helpers && !Object::cast_to<Container>(control->get_parent())) {
- drag = _get_anchor_handle_drag_type(click, drag_point_from);
- if (drag != DRAG_NONE) {
- drag_from = transform.affine_inverse().xform(click);
- se->undo_state = canvas_item->_edit_get_state();
- se->pre_drag_xform = canvas_item->get_global_transform_with_canvas();
- se->pre_drag_rect = canvas_item->_edit_get_rect();
- return;
- }
+ if (drag_type == DRAG_TOP || drag_type == DRAG_TOP_LEFT || drag_type == DRAG_TOP_RIGHT) {
+ current_end.y = 2.0 * center.y - current_begin.y;
+ } else if (drag_type == DRAG_BOTTOM || drag_type == DRAG_BOTTOM_LEFT || drag_type == DRAG_BOTTOM_RIGHT) {
+ current_begin.y = 2.0 * center.y - current_end.y;
}
}
+ canvas_item->_edit_set_rect(Rect2(current_begin, current_end - current_begin));
+ return true;
}
- // Multiple selected items
- Point2 click = b->get_position();
-
- if ((b->get_alt() || tool == TOOL_MOVE) && get_item_count()) {
- // Drag the nodes
- _prepare_drag(click);
+ // Confirm resize
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
+ _commit_canvas_item_state(drag_selection, TTR("Resize CanvasItem"));
+ drag_type = DRAG_NONE;
viewport->update();
- return;
+ return true;
}
- CanvasItem *c = NULL;
- if (Cbone) {
- c = Object::cast_to<CanvasItem>(ObjectDB::get_instance(Cbone->get().bone));
- if (c)
- c = c->get_parent_item();
+ // Cancel a drag
+ if (b.is_valid() && b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
+ _restore_canvas_item_state(drag_selection);
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
}
+ }
+ return false;
+}
- Node *scene = editor->get_edited_scene();
- if (!scene)
- return;
- // Find the item to select
- if (!c) {
- Vector<_SelectResult> selection;
- _find_canvas_items_at_pos(click, scene, transform, Transform2D(), selection, 1);
- if (!selection.empty())
- c = selection[0].item;
+bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> b = p_event;
+ Ref<InputEventMouseMotion> m = p_event;
+ Ref<InputEventKey> k = p_event;
- CanvasItem *cn = c;
- while (cn) {
- if (cn->has_meta("_edit_group_")) {
- c = cn;
- }
- cn = cn->get_parent_item();
+ if (drag_type == DRAG_NONE) {
+ //Start moving the nodes
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+ if ((b->get_alt() || tool == TOOL_MOVE) && selection.size() > 0) {
+ drag_type = DRAG_ALL;
+ drag_from = transform.affine_inverse().xform(b->get_position());
+ drag_selection = selection;
+ _save_canvas_item_state(drag_selection);
+ return true;
}
}
+ }
- Node *n = c;
- while ((n && n != scene && n->get_owner() != scene) || (n && !n->is_class("CanvasItem"))) {
- n = n->get_parent();
- };
+ if (drag_type == DRAG_ALL) {
+ // Move the nodes
+ if (m.is_valid()) {
+ _restore_canvas_item_state(drag_selection, true);
- if (n) {
- c = Object::cast_to<CanvasItem>(n);
- } else {
- c = NULL;
- }
+ drag_to = transform.affine_inverse().xform(m->get_position());
+ Point2 previous_pos;
+ if (drag_selection.size() == 1) {
+ Transform2D xform = drag_selection[0]->get_global_transform_with_canvas() * drag_selection[0]->get_transform().affine_inverse();
+ previous_pos = xform.xform(drag_selection[0]->_edit_get_position());
+ } else {
+ previous_pos = _get_encompassing_rect_from_list(drag_selection).position;
+ }
+ Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES);
+ bool single_axis = m->get_shift();
+ if (single_axis) {
+ if (ABS(new_pos.x - previous_pos.x) > ABS(new_pos.y - previous_pos.y)) {
+ new_pos.y = previous_pos.y;
+ } else {
+ new_pos.x = previous_pos.x;
+ }
+ }
- // Select the item
- additive_selection = b->get_shift();
- if (!c) {
- _select_click_on_empty_area(click, additive_selection, true);
- } else if (!_select_click_on_item(c, click, additive_selection, true)) {
- return;
+ bool force_no_IK = m->get_alt();
+ for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
+ CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
+ Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse() * canvas_item->get_transform();
+
+ Node2D *node2d = Object::cast_to<Node2D>(canvas_item);
+ if (node2d && se->pre_drag_bones_undo_state.size() > 0 && !force_no_IK) {
+ _solve_IK(node2d, new_pos);
+ } else {
+ canvas_item->_edit_set_position(canvas_item->_edit_get_position() + xform.xform(new_pos) - xform.xform(previous_pos));
+ }
+ }
+ return true;
}
- }
- Ref<InputEventMouseMotion> m = p_event;
- if (m.is_valid()) {
- // Mouse motion event
- _update_cursor();
+ // Confirm the move (only if it was moved)
+ if (b.is_valid() && !b->is_pressed() && b->get_button_index() == BUTTON_LEFT && (drag_type == DRAG_ALL)) {
+ if (transform.affine_inverse().xform(b->get_position()) != drag_from) {
+ _commit_canvas_item_state(drag_selection, TTR("Move CanvasItem"), true);
+ }
- if (box_selecting) {
- // Update box selection
- box_selecting_to = transform.affine_inverse().xform(m->get_position());
+ drag_type = DRAG_NONE;
viewport->update();
- return;
+ return true;
}
- if (drag == DRAG_NONE) {
- bool space_pressed = Input::get_singleton()->is_key_pressed(KEY_SPACE);
- bool simple_panning = EditorSettings::get_singleton()->get("editors/2d/simple_spacebar_panning");
- int button = m->get_button_mask();
+ // Cancel a drag
+ if (b.is_valid() && b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
+ _restore_canvas_item_state(drag_selection, true);
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
+ }
+ }
- // Check if any of the panning triggers are activated
- bool panning_tool = (button & BUTTON_MASK_LEFT) && tool == TOOL_PAN;
- bool panning_middle_button = button & BUTTON_MASK_MIDDLE;
- bool panning_spacebar = (button & BUTTON_MASK_LEFT) && space_pressed;
- bool panning_spacebar_simple = space_pressed && simple_panning;
+ // Move the canvas items with the arrow keys
+ if (k.is_valid() && k->is_pressed() && tool == TOOL_SELECT &&
+ (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_LEFT || k->get_scancode() == KEY_RIGHT)) {
+ if (!k->is_echo()) {
+ // Start moving the canvas items with the keyboard
+ drag_selection = _get_edited_canvas_items();
+ drag_type = DRAG_KEY_MOVE;
+ drag_from = Vector2();
+ drag_to = Vector2();
+ _save_canvas_item_state(drag_selection, true);
+ }
- if (panning_tool || panning_middle_button || panning_spacebar || panning_spacebar_simple) {
- // Pan the viewport
- Point2i relative;
- if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) {
- relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect());
- } else {
- relative = m->get_relative();
- }
+ _restore_canvas_item_state(drag_selection, true);
+
+ bool move_local_base = k->get_alt();
+ bool move_local_base_rotated = k->get_control() || k->get_metakey();
+
+ Vector2 dir;
+ if (k->get_scancode() == KEY_UP)
+ dir += Vector2(0, -1);
+ else if (k->get_scancode() == KEY_DOWN)
+ dir += Vector2(0, 1);
+ else if (k->get_scancode() == KEY_LEFT)
+ dir += Vector2(-1, 0);
+ else if (k->get_scancode() == KEY_RIGHT)
+ dir += Vector2(1, 0);
+ if (k->get_shift())
+ dir *= grid_step * Math::pow(2.0, grid_step_multiplier);
+
+ drag_to += dir;
+ if (k->get_shift())
+ drag_to = drag_to.snapped(grid_step * Math::pow(2.0, grid_step_multiplier));
+
+ Point2 previous_pos;
+ if (drag_selection.size() == 1) {
+ Transform2D xform = drag_selection[0]->get_global_transform_with_canvas() * drag_selection[0]->get_transform().affine_inverse();
+ previous_pos = xform.xform(drag_selection[0]->_edit_get_position());
+ } else {
+ previous_pos = _get_encompassing_rect_from_list(drag_selection).position;
+ }
- h_scroll->set_value(h_scroll->get_value() - relative.x / zoom);
- v_scroll->set_value(v_scroll->get_value() - relative.y / zoom);
+ Point2 new_pos;
+ if (drag_selection.size() == 1) {
+ Node2D *node_2d = Object::cast_to<Node2D>(drag_selection[0]);
+ if (node_2d && move_local_base_rotated) {
+ Transform2D m;
+ m.rotate(node_2d->get_rotation());
+ new_pos += m.xform(drag_to);
+ } else if (move_local_base) {
+ new_pos += drag_to;
+ } else {
+ new_pos = previous_pos + (drag_to - drag_from);
}
-
- return;
+ } else {
+ new_pos = previous_pos + (drag_to - drag_from);
}
- List<Node *> selection = editor_selection->get_selected_node_list();
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
+ for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
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();
+ Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse() * canvas_item->get_transform();
- if (!dragging_bone) {
- canvas_item->_edit_set_state(se->undo_state); //reset state and reapply
- if (Object::cast_to<Node2D>(canvas_item))
- Object::cast_to<Node2D>(canvas_item)->_edit_set_pivot(se->undo_pivot);
- if (Object::cast_to<Control>(canvas_item))
- Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot);
+ Node2D *node2d = Object::cast_to<Node2D>(canvas_item);
+ if (node2d && se->pre_drag_bones_undo_state.size() > 0) {
+ _solve_IK(node2d, new_pos);
+ } else {
+ canvas_item->_edit_set_position(canvas_item->_edit_get_position() + xform.xform(new_pos) - xform.xform(previous_pos));
}
+ }
+ return true;
+ }
- Vector2 dfrom = drag_from;
- Vector2 dto = transform.affine_inverse().xform(m->get_position());
- if (canvas_item->has_meta("_edit_lock_"))
- continue;
+ if (k.is_valid() && !k->is_pressed() && drag_type == DRAG_KEY_MOVE && tool == TOOL_SELECT &&
+ (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_LEFT || k->get_scancode() == KEY_RIGHT)) {
+ // Confirm canvas items move by arrow keys
+ if ((!Input::get_singleton()->is_key_pressed(KEY_UP)) &&
+ (!Input::get_singleton()->is_key_pressed(KEY_DOWN)) &&
+ (!Input::get_singleton()->is_key_pressed(KEY_LEFT)) &&
+ (!Input::get_singleton()->is_key_pressed(KEY_RIGHT))) {
+ _commit_canvas_item_state(drag_selection, TTR("Move CanvasItem"), true);
+ drag_type = DRAG_NONE;
+ }
+ viewport->update();
+ return true;
+ }
- if (drag == DRAG_ROTATE) {
- // Rotate the node
- Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin();
- {
- Node2D *node = Object::cast_to<Node2D>(canvas_item);
-
- if (node) {
- real_t angle = node->get_rotation();
- node->set_rotation(snap_angle(angle + (dfrom - center).angle_to(dto - center), angle));
- display_rotate_to = dto;
- display_rotate_from = center;
- viewport->update();
- }
- }
+ if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_LEFT || k->get_scancode() == KEY_RIGHT)) {
+ // Accept the key event in any case
+ return true;
+ }
+ return false;
+}
- {
- Control *node = Object::cast_to<Control>(canvas_item);
+bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> b = p_event;
+ Ref<InputEventMouseMotion> m = p_event;
+ Ref<InputEventKey> k = p_event;
- if (node) {
- real_t angle = node->get_rotation();
- display_rotate_to = dto;
- display_rotate_from = center + node->get_pivot_offset().rotated(angle);
- node->set_rotation(snap_angle(angle + (dfrom - display_rotate_from).angle_to(display_rotate_to - display_rotate_from), angle));
- viewport->update();
- }
+ if (drag_type == DRAG_NONE) {
+ if (b.is_valid() &&
+ ((b->get_button_index() == BUTTON_LEFT && b->get_alt() && tool == TOOL_SELECT) ||
+ (b->get_button_index() == BUTTON_LEFT && tool == TOOL_LIST_SELECT))) {
+ // Popup the selection menu list
+ Point2 click = transform.xform(b->get_position());
+
+ Node *scene = editor->get_edited_scene();
+
+ _find_canvas_items_at_pos(click, scene, 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())) {
+ //invalid result
+ selection_results.remove(i);
+ i--;
}
-
- continue;
}
- bool uniform = m->get_shift();
- bool symmetric = m->get_alt();
+ if (selection_results.size() == 1) {
+ CanvasItem *item = selection_results[0].item;
+ selection_results.clear();
- Vector2 drag_vector =
- canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto) -
- canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dfrom);
-
- switch (drag) {
- case DRAG_ALL:
- case DRAG_NODE_2D:
- dto -= drag_from - drag_point_from;
- if (uniform) {
- 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;
- }
- }
- break;
- }
+ _select_click_on_item(item, click, b->get_shift());
- Control *control = Object::cast_to<Control>(canvas_item);
- if (control) {
- // Drag and snap the anchor
- Transform2D c_trans_rev = canvas_item->get_global_transform_with_canvas().affine_inverse();
+ return true;
+ } else if (!selection_results.empty()) {
+ selection_results.sort();
- Vector2 anchor = c_trans_rev.xform(dto - drag_from + drag_point_from);
- anchor = _position_to_anchor(control, anchor);
+ NodePath root_path = get_tree()->get_edited_scene_root()->get_path();
+ StringName root_name = root_path.get_name(root_path.get_name_count() - 1);
- Vector2 anchor_snapped = c_trans_rev.xform(snap_point(dto - drag_from + drag_point_from, SNAP_GRID | SNAP_GUIDES | SNAP_OTHER_NODES, _get_single_item(), SNAP_NODE_PARENT | SNAP_NODE_SIDES));
- anchor_snapped = _position_to_anchor(control, anchor_snapped).snapped(Vector2(0.00001, 0.00001));
+ for (int i = 0; i < selection_results.size(); i++) {
+ CanvasItem *item = selection_results[i].item;
- bool use_y = Math::abs(drag_vector.y) > Math::abs(drag_vector.x);
+ Ref<Texture> icon;
+ if (item->has_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");
+ String node_path = "/" + root_name + "/" + root_path.rel_path_to(item->get_path());
- switch (drag) {
- case DRAG_ANCHOR_TOP_LEFT:
- if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x, false);
- if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y, false);
- continue;
- break;
- case DRAG_ANCHOR_TOP_RIGHT:
- if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x, false);
- if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y, false);
- continue;
- break;
- case DRAG_ANCHOR_BOTTOM_RIGHT:
- if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x, false);
- if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y, false);
- break;
- case DRAG_ANCHOR_BOTTOM_LEFT:
- if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x, false);
- if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y, false);
- continue;
- break;
- case DRAG_ANCHOR_ALL:
- if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_LEFT, anchor_snapped.x, false);
- if (!uniform || (uniform && !use_y)) control->set_anchor(MARGIN_RIGHT, anchor_snapped.x, false);
- if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_TOP, anchor_snapped.y, false);
- if (!uniform || (uniform && use_y)) control->set_anchor(MARGIN_BOTTOM, anchor_snapped.y, false);
- continue;
- break;
+ selection_menu->add_item(item->get_name());
+ 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);
}
- }
-
- dfrom = drag_point_from;
- dto = snap_point(dto, SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL, _get_single_item());
- drag_vector =
- canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto) -
- canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dfrom);
-
- Rect2 local_rect = canvas_item->_edit_get_rect();
- Vector2 begin = local_rect.position;
- Vector2 end = local_rect.position + local_rect.size;
- Vector2 minsize = canvas_item->_edit_get_minimum_size();
-
- if (uniform) {
- // Keep the height/width ratio of the item
- float aspect = local_rect.size.aspect();
- switch (drag) {
- case DRAG_LEFT:
- drag_vector.y = -drag_vector.x / aspect;
- break;
- case DRAG_RIGHT:
- drag_vector.y = drag_vector.x / aspect;
- break;
- case DRAG_TOP:
- drag_vector.x = -drag_vector.y * aspect;
- break;
- case DRAG_BOTTOM:
- drag_vector.x = drag_vector.y * aspect;
- break;
- 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;
- } else { // height > width, take y as reference
- 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;
- } else { // height > width, take y as reference
- drag_vector.x = drag_vector.y * aspect;
- }
- break;
- }
- } else {
- switch (drag) {
- case DRAG_RIGHT:
- case DRAG_LEFT:
- drag_vector.y = 0;
- break;
- case DRAG_TOP:
- case DRAG_BOTTOM:
- drag_vector.x = 0;
- break;
- }
+ selection_menu_additive_selection = b->get_shift();
+ selection_menu->set_global_position(b->get_global_position());
+ selection_menu->popup();
+ selection_menu->call_deferred("grab_click_focus");
+ selection_menu->set_invalidate_click_until_motion();
+ return true;
}
+ }
- switch (drag) {
- case DRAG_ALL:
- begin += drag_vector;
- end += drag_vector;
- break;
- case DRAG_RIGHT:
- case DRAG_BOTTOM:
- 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);
- 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);
- break;
- case DRAG_TOP:
- 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);
- break;
- case DRAG_LEFT:
- 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);
- break;
+ if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed() && tool == TOOL_SELECT) {
+ // Single item selection
+ Point2 click = transform.affine_inverse().xform(b->get_position());
- case DRAG_PIVOT:
+ Node *scene = editor->get_edited_scene();
+ if (!scene)
+ return true;
- if (Object::cast_to<Node2D>(canvas_item)) {
- Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
- n2d->_edit_set_pivot(se->undo_pivot + drag_vector);
- }
- if (Object::cast_to<Control>(canvas_item)) {
- Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot + drag_vector);
- }
- continue;
- break;
- case DRAG_NODE_2D:
+ // Find the item to select
+ CanvasItem *canvas_item = NULL;
+ Vector<_SelectResult> selection;
+ _find_canvas_items_at_pos(click, scene, selection, 1);
+ if (!selection.empty())
+ canvas_item = selection[0].item;
- ERR_FAIL_COND(!Object::cast_to<Node2D>(canvas_item));
- Object::cast_to<Node2D>(canvas_item)->set_global_position(dto);
- continue;
- break;
+ // Check if the canvas item is in a group, and select the group instead if it is the case
+ CanvasItem *canvas_item_tmp = canvas_item;
+ while (canvas_item_tmp) {
+ if (canvas_item->has_meta("_edit_group_")) {
+ canvas_item = canvas_item_tmp;
+ }
+ canvas_item_tmp = canvas_item_tmp->get_parent_item();
}
- if (!dragging_bone) {
+ // Make sure the selected node is in the current scene
+ Node *node = canvas_item;
+ while (node && ((node != scene && node->get_owner() != scene) || !node->is_class("CanvasItem"))) {
+ node = node->get_parent();
+ };
+ canvas_item = Object::cast_to<CanvasItem>(node);
- local_rect.position = begin;
- local_rect.size = end - begin;
- canvas_item->_edit_set_rect(local_rect);
+ if (!canvas_item) {
+ // Start a box selection
+ if (!b->get_shift()) {
+ // Clear the selection if not additive
+ editor_selection->clear();
+ viewport->update();
+ };
+ drag_from = click;
+ drag_type = DRAG_BOX_SELECTION;
+ box_selecting_to = drag_from;
+ return true;
} else {
- //ok, all that had to be done was done, now solve IK
-
- Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
- 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()) {
- if (E->prev())
- 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);
- //n2d->set_global_transform(final_xform);
- }
-
- CanvasItem *last = bone_ik_list.back()->get().node;
- if (!last)
- break;
-
- Vector2 root_pos = last->get_global_transform().get_origin();
- Vector2 leaf_pos = final_xform.get_origin();
-
- if ((leaf_pos.distance_to(root_pos)) > total_len) {
- //oops dude you went too far
- //print_line("TOO FAR!");
- Vector2 rel = leaf_pos - root_pos;
- rel = rel.normalized() * total_len;
- leaf_pos = root_pos + rel;
- }
-
- 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;
-
- 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()) {
-
- break;
- }
-
- float len = E->next()->get().len;
-
- if (E->next() == bone_ik_list.back()) {
-
- //print_line("back");
+ bool still_selected = _select_click_on_item(canvas_item, click, b->get_shift());
+ // Start dragging
+ if (still_selected) {
+ // Drag the node(s) if requested
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+
+ drag_type = DRAG_ALL;
+ drag_selection = selection;
+ drag_from = click;
+ _save_canvas_item_state(drag_selection);
+ }
+ // Select the item
+ return true;
+ }
+ }
+ }
- Vector2 rel = E->get().pos - E->next()->get().pos;
- //print_line("PREV "+E->get().pos);
- Vector2 desired = E->next()->get().pos + rel.normalized() * len;
- //print_line("DESIRED "+desired);
- E->get().pos = E->get().pos.linear_interpolate(desired, solver_k);
- //print_line("POST "+E->get().pos);
+ if (drag_type == DRAG_BOX_SELECTION) {
+ if (b.is_valid() && !b->is_pressed() && b->get_button_index() == BUTTON_LEFT) {
+ // Confirms box selection
+ Node *scene = editor->get_edited_scene();
+ if (scene) {
+ List<CanvasItem *> selitems;
- } 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;
- //print_line("DESIRED "+desired);
- E->next()->get().pos = E->next()->get().pos.linear_interpolate(desired, solver_k);
- //print_line("POST "+E->next()->get().pos);
- } else {
+ Point2 bsfrom = drag_from;
+ Point2 bsto = box_selecting_to;
+ if (bsfrom.x > bsto.x)
+ SWAP(bsfrom.x, bsto.x);
+ if (bsfrom.y > bsto.y)
+ SWAP(bsfrom.y, bsto.y);
- 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;
- //print_line("mid");
- }
- }
- }
- }
+ _find_canvas_items_at_rect(Rect2(bsfrom, bsto - bsfrom), scene, &selitems);
+ for (List<CanvasItem *>::Element *E = selitems.front(); E; E = E->next()) {
+ editor_selection->add_node(E->get());
}
+ }
- for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) {
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
+ }
- Node2D *n = E->get().node;
+ if (b.is_valid() && b->is_pressed() && b->get_button_index() == BUTTON_RIGHT) {
+ // Cancel box selection
+ drag_type = DRAG_NONE;
+ viewport->update();
+ return true;
+ }
- if (!E->prev()) {
- //last goes to what it was
- final_xform.set_origin(n->get_global_position());
- n->set_global_transform(final_xform);
+ if (m.is_valid()) {
+ // Update box selection
+ box_selecting_to = transform.affine_inverse().xform(m->get_position());
+ viewport->update();
+ return true;
+ }
+ }
- } else {
- 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) {
- //mirrored, rotate the other way
- rot = -rot;
- }
+ if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_ESCAPE && drag_type == DRAG_NONE && tool == TOOL_SELECT) {
+ // Unselect everything
+ editor_selection->clear();
+ viewport->update();
+ }
+ return false;
+}
- n->rotate(rot);
- }
+void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
+ bool accepted = false;
+ if ((accepted = _gui_input_rulers_and_guides(p_event))) {
+ //printf("Rulers and guides\n");
+ } else if ((accepted = editor->get_editor_plugins_over()->forward_gui_input(p_event))) {
+ //printf("Plugin\n");
+ } else if ((accepted = _gui_input_open_scene_on_double_click(p_event))) {
+ //printf("Open scene on double click\n");
+ } else if ((accepted = _gui_input_anchors(p_event))) {
+ //printf("Anchors\n");
+ } else if ((accepted = _gui_input_pivot(p_event))) {
+ //printf("Set pivot\n");
+ } else if ((accepted = _gui_input_resize(p_event))) {
+ //printf("Resize\n");
+ } else if ((accepted = _gui_input_rotate(p_event))) {
+ //printf("Rotate\n");
+ } else if ((accepted = _gui_input_move(p_event))) {
+ //printf("Move\n");
+ } else if ((accepted = _gui_input_select(p_event))) {
+ //printf("Selection\n");
+ } else if ((accepted = _gui_input_zoom_or_pan(p_event))) {
+ //printf("Zoom or pan\n");
+ }
+
+ if (accepted)
+ accept_event();
+
+ // Change the cursor
+ CursorShape c = CURSOR_ARROW;
+ switch (drag_type) {
+ case DRAG_NONE:
+ if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
+ c = CURSOR_DRAG;
+ } else {
+ switch (tool) {
+ case TOOL_MOVE:
+ c = CURSOR_MOVE;
+ break;
+ case TOOL_EDIT_PIVOT:
+ c = CURSOR_CROSS;
+ break;
+ case TOOL_PAN:
+ c = CURSOR_DRAG;
+ break;
+ default:
+ break;
}
-
- break;
}
- }
+ break;
+ case DRAG_LEFT:
+ case DRAG_RIGHT:
+ c = CURSOR_HSIZE;
+ break;
+ case DRAG_TOP:
+ case DRAG_BOTTOM:
+ c = CURSOR_VSIZE;
+ break;
+ case DRAG_TOP_LEFT:
+ case DRAG_BOTTOM_RIGHT:
+ c = CURSOR_FDIAGSIZE;
+ break;
+ case DRAG_TOP_RIGHT:
+ case DRAG_BOTTOM_LEFT:
+ c = CURSOR_BDIAGSIZE;
+ break;
+ case DRAG_ALL:
+ c = CURSOR_MOVE;
+ break;
+ default:
+ break;
+ }
+ viewport->set_default_cursor_shape(c);
+
+ // Grab focus
+ if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) {
+ viewport->call_deferred("grab_focus");
}
}
@@ -2292,8 +1896,8 @@ void CanvasItemEditor::_draw_percentage_at_position(float p_value, Point2 p_posi
void CanvasItemEditor::_draw_focus() {
// Draw the focus around the base viewport
- if (viewport_base->has_focus()) {
- get_stylebox("Focus", "EditorStyles")->draw(viewport_base->get_canvas_item(), Rect2(Point2(), viewport_base->get_size()));
+ if (viewport->has_focus()) {
+ get_stylebox("Focus", "EditorStyles")->draw(viewport->get_canvas_item(), Rect2(Point2(), viewport->get_size()));
}
}
@@ -2306,63 +1910,61 @@ void CanvasItemEditor::_draw_guides() {
if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
for (int i = 0; i < vguides.size(); i++) {
- if (drag == DRAG_V_GUIDE && i == edited_guide_index)
+ if (drag_type == DRAG_V_GUIDE && i == dragged_guide_index)
continue;
float x = xform.xform(Point2(vguides[i], 0)).x;
- viewport_base->draw_line(Point2(x, 0), Point2(x, viewport_base->get_size().y), guide_color);
+ viewport->draw_line(Point2(x, 0), Point2(x, viewport->get_size().y), guide_color);
}
}
if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) {
Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_");
for (int i = 0; i < hguides.size(); i++) {
- if (drag == DRAG_H_GUIDE && i == edited_guide_index)
+ if (drag_type == DRAG_H_GUIDE && i == dragged_guide_index)
continue;
float y = xform.xform(Point2(0, hguides[i])).y;
- viewport_base->draw_line(Point2(0, y), Point2(viewport_base->get_size().x, y), guide_color);
+ viewport->draw_line(Point2(0, y), Point2(viewport->get_size().x, y), guide_color);
}
}
// Dragged guide
Color text_color = get_color("font_color", "Editor");
text_color.a = 0.5;
- if (drag == DRAG_DOUBLE_GUIDE || drag == DRAG_V_GUIDE) {
- String str = vformat("%d px", xform.affine_inverse().xform(edited_guide_pos).x);
+ if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_V_GUIDE) {
+ String str = vformat("%d px", xform.affine_inverse().xform(dragged_guide_pos).x);
Ref<Font> font = get_font("font", "Label");
Size2 text_size = font->get_string_size(str);
- viewport_base->draw_string(font, Point2(edited_guide_pos.x + 10, RULER_WIDTH + text_size.y / 2 + 10), str, text_color);
- viewport_base->draw_line(Point2(edited_guide_pos.x, 0), Point2(edited_guide_pos.x, viewport_base->get_size().y), guide_color);
+ viewport->draw_string(font, Point2(dragged_guide_pos.x + 10, RULER_WIDTH + text_size.y / 2 + 10), str, text_color);
+ viewport->draw_line(Point2(dragged_guide_pos.x, 0), Point2(dragged_guide_pos.x, viewport->get_size().y), guide_color);
}
- if (drag == DRAG_DOUBLE_GUIDE || drag == DRAG_H_GUIDE) {
- String str = vformat("%d px", xform.affine_inverse().xform(edited_guide_pos).y);
+ if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_H_GUIDE) {
+ String str = vformat("%d px", xform.affine_inverse().xform(dragged_guide_pos).y);
Ref<Font> font = get_font("font", "Label");
Size2 text_size = font->get_string_size(str);
- viewport_base->draw_string(font, Point2(RULER_WIDTH + 10, edited_guide_pos.y + text_size.y / 2 + 10), str, text_color);
- viewport_base->draw_line(Point2(0, edited_guide_pos.y), Point2(viewport_base->get_size().x, edited_guide_pos.y), guide_color);
+ viewport->draw_string(font, Point2(RULER_WIDTH + 10, dragged_guide_pos.y + text_size.y / 2 + 10), str, text_color);
+ viewport->draw_line(Point2(0, dragged_guide_pos.y), Point2(viewport->get_size().x, dragged_guide_pos.y), guide_color);
}
}
void CanvasItemEditor::_draw_rulers() {
- Color graduation_color = get_color("font_color", "Editor");
- graduation_color.a = 0.5;
Color bg_color = get_color("dark_color_2", "Editor");
+ Color graduation_color = get_color("font_color", "Editor").linear_interpolate(bg_color, 0.5);
Color font_color = get_color("font_color", "Editor");
font_color.a = 0.8;
Ref<Font> font = get_font("rulers", "EditorFonts");
// The rule transform
- Transform2D ruler_transform;
- if (show_grid || snap_grid) {
- ruler_transform = Transform2D();
- if (snap_relative && get_item_count() > 0) {
- ruler_transform.translate(_find_topleftmost_point());
+ Transform2D ruler_transform = Transform2D();
+ if (show_grid || (snap_active && snap_grid)) {
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+ if (snap_relative && selection.size() > 0) {
+ ruler_transform.translate(_get_encompassing_rect_from_list(selection).position);
ruler_transform.scale_basis(grid_step * Math::pow(2.0, grid_step_multiplier));
} else {
ruler_transform.translate(grid_offset);
ruler_transform.scale_basis(grid_step * Math::pow(2.0, grid_step_multiplier));
}
while ((transform * ruler_transform).get_scale().x < 50 || (transform * ruler_transform).get_scale().y < 50) {
-
ruler_transform.scale_basis(Point2(2, 2));
}
} else {
@@ -2373,7 +1975,6 @@ void CanvasItemEditor::_draw_rulers() {
for (int i = 0; basic_rule * zoom < 100; i++) {
basic_rule *= (i % 2) ? 2.0 : 5.0;
}
- ruler_transform = Transform2D();
ruler_transform.scale(Size2(basic_rule, basic_rule));
}
@@ -2387,43 +1988,43 @@ void CanvasItemEditor::_draw_rulers() {
minor_subdivide.scale(Size2(1.0 / minor_subdivision, 1.0 / minor_subdivision));
// First and last graduations to draw (in the ruler space)
- Point2 first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Point2());
+ Point2 first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Point2(RULER_WIDTH, RULER_WIDTH));
Point2 last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(viewport->get_size());
// Draw top ruler
- viewport_base->draw_rect(Rect2(Point2(RULER_WIDTH, 0), Size2(viewport->get_size().x, RULER_WIDTH)), bg_color);
+ viewport->draw_rect(Rect2(Point2(RULER_WIDTH, 0), Size2(viewport->get_size().x, RULER_WIDTH)), bg_color);
for (int i = Math::ceil(first.x); i < last.x; i++) {
Point2 position = (transform * ruler_transform * major_subdivide * minor_subdivide).xform(Point2(i, 0));
if (i % (major_subdivision * minor_subdivision) == 0) {
- viewport_base->draw_line(Point2(position.x + RULER_WIDTH, 0), Point2(position.x + RULER_WIDTH, RULER_WIDTH), graduation_color);
+ viewport->draw_line(Point2(position.x, 0), Point2(position.x, RULER_WIDTH), graduation_color);
float val = (ruler_transform * major_subdivide * minor_subdivide).xform(Point2(i, 0)).x;
- viewport_base->draw_string(font, Point2(position.x + RULER_WIDTH + 2, font->get_height()), vformat(((int)val == val) ? "%d" : "%.1f", val), font_color);
+ viewport->draw_string(font, Point2(position.x + 2, font->get_height()), vformat(((int)val == val) ? "%d" : "%.1f", val), font_color);
} else {
if (i % minor_subdivision == 0) {
- viewport_base->draw_line(Point2(position.x + RULER_WIDTH, RULER_WIDTH * 0.33), Point2(position.x + RULER_WIDTH, RULER_WIDTH), graduation_color);
+ viewport->draw_line(Point2(position.x, RULER_WIDTH * 0.33), Point2(position.x, RULER_WIDTH), graduation_color);
} else {
- viewport_base->draw_line(Point2(position.x + RULER_WIDTH, RULER_WIDTH * 0.66), Point2(position.x + RULER_WIDTH, RULER_WIDTH), graduation_color);
+ viewport->draw_line(Point2(position.x, RULER_WIDTH * 0.66), Point2(position.x, RULER_WIDTH), graduation_color);
}
}
}
// Draw left ruler
- viewport_base->draw_rect(Rect2(Point2(0, RULER_WIDTH), Size2(RULER_WIDTH, viewport->get_size().y)), bg_color);
+ viewport->draw_rect(Rect2(Point2(0, RULER_WIDTH), Size2(RULER_WIDTH, viewport->get_size().y)), bg_color);
for (int i = Math::ceil(first.y); i < last.y; i++) {
Point2 position = (transform * ruler_transform * major_subdivide * minor_subdivide).xform(Point2(0, i));
if (i % (major_subdivision * minor_subdivision) == 0) {
- viewport_base->draw_line(Point2(0, position.y + RULER_WIDTH), Point2(RULER_WIDTH, position.y + RULER_WIDTH), graduation_color);
+ viewport->draw_line(Point2(0, position.y), Point2(RULER_WIDTH, position.y), graduation_color);
float val = (ruler_transform * major_subdivide * minor_subdivide).xform(Point2(0, i)).y;
- viewport_base->draw_string(font, Point2(2, position.y + RULER_WIDTH + 2 + font->get_height()), vformat(((int)val == val) ? "%d" : "%.1f", val), font_color);
+ viewport->draw_string(font, Point2(2, position.y + 2 + font->get_height()), vformat(((int)val == val) ? "%d" : "%.1f", val), font_color);
} else {
if (i % minor_subdivision == 0) {
- viewport_base->draw_line(Point2(RULER_WIDTH * 0.33, position.y + RULER_WIDTH), Point2(RULER_WIDTH, position.y + RULER_WIDTH), graduation_color);
+ viewport->draw_line(Point2(RULER_WIDTH * 0.33, position.y), Point2(RULER_WIDTH, position.y), graduation_color);
} else {
- viewport_base->draw_line(Point2(RULER_WIDTH * 0.66, position.y + RULER_WIDTH), Point2(RULER_WIDTH, position.y + RULER_WIDTH), graduation_color);
+ viewport->draw_line(Point2(RULER_WIDTH * 0.66, position.y), Point2(RULER_WIDTH, position.y), graduation_color);
}
}
}
- viewport_base->draw_rect(Rect2(Point2(), Size2(RULER_WIDTH, RULER_WIDTH)), graduation_color);
+ viewport->draw_rect(Rect2(Point2(), Size2(RULER_WIDTH, RULER_WIDTH)), graduation_color);
}
void CanvasItemEditor::_draw_grid() {
@@ -2434,8 +2035,9 @@ void CanvasItemEditor::_draw_grid() {
Transform2D xform = transform.affine_inverse();
Vector2 real_grid_offset;
- if (snap_relative && get_item_count() > 0) {
- Vector2 topleft = _find_topleftmost_point();
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+ if (snap_relative && selection.size() > 0) {
+ Vector2 topleft = _get_encompassing_rect_from_list(selection).position;
real_grid_offset.x = fmod(topleft.x, grid_step.x * (real_t)Math::pow(2.0, grid_step_multiplier));
real_grid_offset.y = fmod(topleft.y, grid_step.y * (real_t)Math::pow(2.0, grid_step_multiplier));
} else {
@@ -2468,26 +2070,23 @@ void CanvasItemEditor::_draw_grid() {
}
void CanvasItemEditor::_draw_selection() {
- bool pivot_found = false;
Ref<Texture> pivot_icon = get_icon("EditorPivot", "EditorIcons");
- bool single = _get_single_item() != NULL;
RID ci = viewport->get_canvas_item();
- Map<Node *, Object *> &selection = editor_selection->get_selection();
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
+ List<CanvasItem *> selection = _get_edited_canvas_items(false, false);
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
+ bool single = selection.size() == 1;
+ for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
- if (!se)
- continue;
Rect2 rect = canvas_item->_edit_get_rect();
- if (show_helpers && drag != DRAG_NONE && drag != DRAG_PIVOT) {
+ // Draw the previous position if we are dragging the node
+ if (show_helpers &&
+ (drag_type == DRAG_ALL || drag_type == DRAG_ROTATE ||
+ drag_type == DRAG_LEFT || drag_type == DRAG_RIGHT || drag_type == DRAG_TOP || drag_type == DRAG_BOTTOM ||
+ drag_type == DRAG_TOP_LEFT || drag_type == DRAG_TOP_RIGHT || drag_type == DRAG_BOTTOM_LEFT || drag_type == DRAG_BOTTOM_RIGHT)) {
const Transform2D pre_drag_xform = transform * se->pre_drag_xform;
const Color pre_drag_color = Color(0.4, 0.6, 1, 0.7);
@@ -2507,8 +2106,8 @@ void CanvasItemEditor::_draw_selection() {
Transform2D xform = transform * canvas_item->get_global_transform_with_canvas();
VisualServer::get_singleton()->canvas_item_add_set_transform(ci, xform);
+ // Draw the selected items surrounding boxes
Vector2 endpoints[4] = {
-
xform.xform(rect.position),
xform.xform(rect.position + Vector2(rect.size.x, 0)),
xform.xform(rect.position + rect.size),
@@ -2524,25 +2123,13 @@ void CanvasItemEditor::_draw_selection() {
}
if (single && (tool == TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_ROTATE || tool == TOOL_EDIT_PIVOT)) { //kind of sucks
-
- Node2D *node2d = Object::cast_to<Node2D>(canvas_item);
- if (node2d) {
- if (node2d->_edit_use_pivot()) {
- viewport->draw_texture(pivot_icon, xform.get_origin() + (-pivot_icon->get_size() / 2).floor());
- can_move_pivot = true;
- pivot_found = true;
- }
+ // Draw the pivot
+ if (canvas_item->_edit_get_pivot() != Vector2() || drag_type == DRAG_PIVOT || tool == TOOL_EDIT_PIVOT) { // This is not really clean :/
+ viewport->draw_texture(pivot_icon, xform.xform(canvas_item->_edit_get_pivot()) + (-pivot_icon->get_size() / 2).floor());
}
Control *control = Object::cast_to<Control>(canvas_item);
if (control) {
- Vector2 pivot_ofs = control->get_pivot_offset();
- if (pivot_ofs != Vector2()) {
- viewport->draw_texture(pivot_icon, xform.xform(pivot_ofs) + (-pivot_icon->get_size() / 2).floor());
- }
- can_move_pivot = true;
- pivot_found = true;
-
if (tool == TOOL_SELECT && show_helpers && !Object::cast_to<Container>(control->get_parent())) {
// Draw the helpers
Color color_base = Color(0.8, 0.8, 0.8, 0.5);
@@ -2561,10 +2148,9 @@ void CanvasItemEditor::_draw_selection() {
anchors_pos[i] = xform.xform(_anchor_to_position(control, anchors[i]));
}
- Map<Node *, Object *> &selection = editor_selection->get_selection();
// Get which anchor is dragged
int dragged_anchor = -1;
- switch (drag) {
+ switch (drag_type) {
case DRAG_ANCHOR_ALL:
case DRAG_ANCHOR_TOP_LEFT:
dragged_anchor = 0;
@@ -2578,6 +2164,8 @@ void CanvasItemEditor::_draw_selection() {
case DRAG_ANCHOR_BOTTOM_LEFT:
dragged_anchor = 3;
break;
+ default:
+ break;
}
if (dragged_anchor >= 0) {
@@ -2639,56 +2227,65 @@ void CanvasItemEditor::_draw_selection() {
node_pos_in_parent[2] = control->get_anchor(MARGIN_RIGHT) * control->get_parent_area_size().width + control->get_margin(MARGIN_RIGHT);
node_pos_in_parent[3] = control->get_anchor(MARGIN_BOTTOM) * control->get_parent_area_size().height + control->get_margin(MARGIN_BOTTOM);
- switch (drag) {
+ Point2 start, end;
+ switch (drag_type) {
case DRAG_LEFT:
case DRAG_TOP_LEFT:
case DRAG_BOTTOM_LEFT:
_draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM);
case DRAG_ALL:
- Point2 start = Vector2(node_pos_in_parent[0], Math::lerp(node_pos_in_parent[1], node_pos_in_parent[3], ratio));
- Point2 end = start - Vector2(control->get_margin(MARGIN_LEFT), 0);
+ start = Vector2(node_pos_in_parent[0], Math::lerp(node_pos_in_parent[1], node_pos_in_parent[3], ratio));
+ end = start - Vector2(control->get_margin(MARGIN_LEFT), 0);
_draw_margin_at_position(control->get_margin(MARGIN_LEFT), parent_transform.xform((start + end) / 2), MARGIN_TOP);
viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1);
break;
+ default:
+ break;
}
- switch (drag) {
+ switch (drag_type) {
case DRAG_RIGHT:
case DRAG_TOP_RIGHT:
case DRAG_BOTTOM_RIGHT:
_draw_margin_at_position(control->get_size().width, parent_transform.xform(Vector2((node_pos_in_parent[0] + node_pos_in_parent[2]) / 2, node_pos_in_parent[3])) + Vector2(0, 5), MARGIN_BOTTOM);
case DRAG_ALL:
- Point2 start = Vector2(node_pos_in_parent[2], Math::lerp(node_pos_in_parent[3], node_pos_in_parent[1], ratio));
- Point2 end = start - Vector2(control->get_margin(MARGIN_RIGHT), 0);
+ start = Vector2(node_pos_in_parent[2], Math::lerp(node_pos_in_parent[3], node_pos_in_parent[1], ratio));
+ end = start - Vector2(control->get_margin(MARGIN_RIGHT), 0);
_draw_margin_at_position(control->get_margin(MARGIN_RIGHT), parent_transform.xform((start + end) / 2), MARGIN_BOTTOM);
viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1);
break;
+ default:
+ break;
}
- switch (drag) {
+ switch (drag_type) {
case DRAG_TOP:
case DRAG_TOP_LEFT:
case DRAG_TOP_RIGHT:
_draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2)) + Vector2(5, 0), MARGIN_RIGHT);
case DRAG_ALL:
- Point2 start = Vector2(Math::lerp(node_pos_in_parent[0], node_pos_in_parent[2], ratio), node_pos_in_parent[1]);
- Point2 end = start - Vector2(0, control->get_margin(MARGIN_TOP));
+ start = Vector2(Math::lerp(node_pos_in_parent[0], node_pos_in_parent[2], ratio), node_pos_in_parent[1]);
+ end = start - Vector2(0, control->get_margin(MARGIN_TOP));
_draw_margin_at_position(control->get_margin(MARGIN_TOP), parent_transform.xform((start + end) / 2), MARGIN_LEFT);
viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1);
break;
+ default:
+ break;
}
- switch (drag) {
+ switch (drag_type) {
case DRAG_BOTTOM:
case DRAG_BOTTOM_LEFT:
case DRAG_BOTTOM_RIGHT:
_draw_margin_at_position(control->get_size().height, parent_transform.xform(Vector2(node_pos_in_parent[2], (node_pos_in_parent[1] + node_pos_in_parent[3]) / 2) + Vector2(5, 0)), MARGIN_RIGHT);
case DRAG_ALL:
- Point2 start = Vector2(Math::lerp(node_pos_in_parent[2], node_pos_in_parent[0], ratio), node_pos_in_parent[3]);
- Point2 end = start - Vector2(0, control->get_margin(MARGIN_BOTTOM));
+ start = Vector2(Math::lerp(node_pos_in_parent[2], node_pos_in_parent[0], ratio), node_pos_in_parent[3]);
+ end = start - Vector2(0, control->get_margin(MARGIN_BOTTOM));
_draw_margin_at_position(control->get_margin(MARGIN_BOTTOM), parent_transform.xform((start + end) / 2), MARGIN_RIGHT);
viewport->draw_line(parent_transform.xform(start), parent_transform.xform(end), color_base, 1);
break;
+ default:
+ break;
}
- switch (drag) {
+ switch (drag_type) {
//Draw the ghost rect if the node if rotated/scaled
case DRAG_LEFT:
case DRAG_TOP_LEFT:
@@ -2704,14 +2301,15 @@ void CanvasItemEditor::_draw_selection() {
viewport->draw_rect(parent_transform.xform(rect), color_base, false);
}
break;
+ default:
+ break;
}
}
}
if (tool == TOOL_SELECT) {
-
for (int i = 0; i < 4; i++) {
-
+ // Draw the resize handles
int prev = (i + 3) % 4;
int next = (i + 1) % 4;
@@ -2728,9 +2326,9 @@ void CanvasItemEditor::_draw_selection() {
}
}
}
- pivot_button->set_disabled(!pivot_found);
- if (box_selecting) {
+ if (drag_type == DRAG_BOX_SELECTION) {
+ // Draw the dragging box
Point2 bsfrom = transform.xform(drag_from);
Point2 bsto = transform.xform(box_selecting_to);
@@ -2738,8 +2336,50 @@ void CanvasItemEditor::_draw_selection() {
}
Color rotate_color(0.4, 0.7, 1.0, 0.8);
- 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_type == DRAG_ROTATE) {
+ // Draw the line when rotating a node
+ viewport->draw_line(transform.xform(drag_rotation_center), transform.xform(drag_to), rotate_color);
+ }
+}
+
+void CanvasItemEditor::_draw_straight_line(Point2 p_from, Point2 p_to, Color p_color) {
+ // Draw a line going through the whole screen from a vector
+ RID ci = viewport->get_canvas_item();
+ Vector<Point2> points;
+ Point2 from = transform.xform(p_from);
+ Point2 to = transform.xform(p_to);
+ Size2 viewport_size = viewport->get_size();
+
+ if (to.x == from.x) {
+ // Vertical line
+ points.push_back(Point2(to.x, 0));
+ points.push_back(Point2(to.x, viewport_size.y));
+ } else if (to.y == from.y) {
+ // Horizontal line
+ points.push_back(Point2(0, to.y));
+ points.push_back(Point2(viewport_size.x, to.y));
+ } else {
+ float y_for_zero_x = (to.y * from.x - from.y * to.x) / (from.x - to.x);
+ float x_for_zero_y = (to.x * from.y - from.x * to.y) / (from.y - to.y);
+ float y_for_viewport_x = ((to.y - from.y) * (viewport_size.x - from.x)) / (to.x - from.x) + from.y;
+ float x_for_viewport_y = ((to.x - from.x) * (viewport_size.y - from.y)) / (to.y - from.y) + from.x; // faux
+
+ //bool start_set = false;
+ if (y_for_zero_x >= 0 && y_for_zero_x <= viewport_size.y) {
+ points.push_back(Point2(0, y_for_zero_x));
+ }
+ if (x_for_zero_y >= 0 && x_for_zero_y <= viewport_size.x) {
+ points.push_back(Point2(x_for_zero_y, 0));
+ }
+ if (y_for_viewport_x >= 0 && y_for_viewport_x <= viewport_size.y) {
+ points.push_back(Point2(viewport_size.x, y_for_viewport_x));
+ }
+ if (x_for_viewport_y >= 0 && x_for_viewport_y <= viewport_size.x) {
+ points.push_back(Point2(x_for_viewport_y, viewport_size.y));
+ }
+ }
+ if (points.size() >= 2) {
+ VisualServer::get_singleton()->canvas_item_add_line(ci, points[0], points[1], p_color);
}
}
@@ -2750,9 +2390,8 @@ void CanvasItemEditor::_draw_axis() {
Color y_axis_color(0.4, 1.0, 0.4, 0.6);
Color area_axis_color(0.4, 0.4, 1.0, 0.4);
- Point2 origin = transform.get_origin();
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(0, origin.y), Point2(viewport->get_size().x, origin.y), x_axis_color);
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(origin.x, 0), Point2(origin.x, viewport->get_size().y), y_axis_color);
+ _draw_straight_line(Point2(), Point2(1, 0), x_axis_color);
+ _draw_straight_line(Point2(), Point2(0, 1), y_axis_color);
Size2 screen_size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
@@ -2783,7 +2422,7 @@ void CanvasItemEditor::_draw_bones() {
E->get().from = Vector2();
E->get().to = Vector2();
- Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().bone));
+ Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->key()));
if (!n2d)
continue;
@@ -2881,7 +2520,6 @@ void CanvasItemEditor::_build_bones_list(Node *p_node) {
ObjectID id = c->get_instance_id();
if (!bone_list.has(id)) {
BoneList bone;
- bone.bone = id;
bone_list[id] = bone;
}
@@ -2890,32 +2528,6 @@ void CanvasItemEditor::_build_bones_list(Node *p_node) {
}
}
-void CanvasItemEditor::_get_encompassing_rect(Node *p_node, Rect2 &r_rect, const Transform2D &p_xform) {
- ERR_FAIL_COND(!p_node);
-
- for (int i = 0; i < p_node->get_child_count(); i++) {
- _get_encompassing_rect(p_node->get_child(i), r_rect, p_xform);
- }
-
- CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
- if (c && c->is_visible_in_tree()) {
- Rect2 rect = c->_edit_get_rect();
- Transform2D xform = p_xform * c->get_transform();
- r_rect.expand_to(xform.xform(rect.position));
- r_rect.expand_to(xform.xform(rect.position + Point2(rect.size.x, 0)));
- r_rect.expand_to(xform.xform(rect.position + Point2(0, rect.size.y)));
- r_rect.expand_to(xform.xform(rect.position + rect.size));
- }
-}
-
-void CanvasItemEditor::_draw_viewport_base() {
- if (show_rulers)
- _draw_rulers();
- if (show_guides)
- _draw_guides();
- _draw_focus();
-}
-
void CanvasItemEditor::_draw_viewport() {
// hide/show buttons depending on the selection
@@ -2968,36 +2580,25 @@ void CanvasItemEditor::_draw_viewport() {
}
_draw_bones();
+ if (show_rulers)
+ _draw_rulers();
+ if (show_guides)
+ _draw_guides();
+ _draw_focus();
}
void CanvasItemEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_PHYSICS_PROCESS) {
-
EditorNode::get_singleton()->get_scene_root()->set_snap_controls_to_pixels(GLOBAL_GET("gui/common/snap_controls_to_pixels"));
- List<Node *> selection = editor_selection->get_selected_node_list();
-
- bool all_control = true;
- bool has_control = false;
-
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
- continue;
-
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
- continue;
-
- if (Object::cast_to<Control>(canvas_item))
- has_control = true;
- else
- all_control = false;
+ int nb_control = 0;
+ int nb_having_pivot = 0;
+ List<CanvasItem *> selection = _get_edited_canvas_items();
+ for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) {
+ CanvasItem *canvas_item = E->get();
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
- if (!se)
- continue;
Rect2 r = canvas_item->_edit_get_rect();
Transform2D xform = canvas_item->get_transform();
@@ -3008,36 +2609,41 @@ void CanvasItemEditor::_notification(int p_what) {
se->prev_xform = xform;
}
- if (Object::cast_to<Control>(canvas_item)) {
+ Control *control = Object::cast_to<Control>(canvas_item);
+ if (control) {
float anchors[4];
Vector2 pivot;
- pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
- anchors[MARGIN_LEFT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_LEFT);
- anchors[MARGIN_RIGHT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_RIGHT);
- anchors[MARGIN_TOP] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_TOP);
- anchors[MARGIN_BOTTOM] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_BOTTOM);
+ pivot = control->get_pivot_offset();
+ anchors[MARGIN_LEFT] = control->get_anchor(MARGIN_LEFT);
+ anchors[MARGIN_RIGHT] = control->get_anchor(MARGIN_RIGHT);
+ anchors[MARGIN_TOP] = control->get_anchor(MARGIN_TOP);
+ anchors[MARGIN_BOTTOM] = control->get_anchor(MARGIN_BOTTOM);
if (pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) {
- viewport->update();
- viewport_base->update();
se->prev_pivot = pivot;
se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT];
se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT];
se->prev_anchors[MARGIN_TOP] = anchors[MARGIN_TOP];
se->prev_anchors[MARGIN_BOTTOM] = anchors[MARGIN_BOTTOM];
+ viewport->update();
}
+ nb_control++;
+ }
+
+ if (canvas_item->_edit_use_pivot()) {
+ nb_having_pivot++;
}
}
+ // Activate / Deactivate the pivot tool
+ pivot_button->set_disabled(nb_having_pivot == 0);
- if (all_control && has_control)
- presets_menu->show();
- else
- presets_menu->hide();
+ // Show / Hide the layout button
+ presets_menu->set_visible(nb_control > 0 && nb_control == selection.size());
for (Map<ObjectID, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
- Object *b = ObjectDB::get_instance(E->get().bone);
+ Object *b = ObjectDB::get_instance(E->key());
if (!b) {
viewport->update();
@@ -3150,63 +2756,60 @@ void CanvasItemEditor::_notification(int p_what) {
void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
- drag = DRAG_NONE;
+ drag_type = DRAG_NONE;
// Clear the selection
editor_selection->clear(); //_clear_canvas_items();
editor_selection->add_node(p_canvas_item);
- //_add_canvas_item(p_canvas_item);
viewport->update();
- viewport_base->update();
}
void CanvasItemEditor::_update_scrollbars() {
updating_scroll = true;
- if (show_rulers)
- viewport_scrollable->set_begin(Point2(RULER_WIDTH, RULER_WIDTH));
- else
- viewport_scrollable->set_begin(Point2());
+ Point2 zoom_hb_begin = Point2(5, 5);
+ zoom_hb_begin += (show_rulers) ? Point2(RULER_WIDTH, RULER_WIDTH) : Point2();
+ zoom_hb->set_begin(zoom_hb_begin);
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_begin(Point2(size.width - vmin.width, (show_rulers) ? RULER_WIDTH : 0));
v_scroll->set_end(Point2(size.width, size.height));
- h_scroll->set_begin(Point2(0, size.height - hmin.height));
+ h_scroll->set_begin(Point2((show_rulers) ? RULER_WIDTH : 0, size.height - hmin.height));
h_scroll->set_end(Point2(size.width - vmin.width, size.height));
Size2 screen_rect = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
Rect2 local_rect = Rect2(Point2(), viewport->get_size() - Size2(vmin.width, hmin.height));
- Rect2 canvas_item_rect = Rect2(Point2(), screen_rect);
-
bone_last_frame++;
if (editor->get_edited_scene()) {
_build_bones_list(editor->get_edited_scene());
- _get_encompassing_rect(editor->get_edited_scene(), canvas_item_rect, Transform2D());
}
List<Map<ObjectID, BoneList>::Element *> bone_to_erase;
-
for (Map<ObjectID, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
-
if (E->get().last_pass != bone_last_frame) {
bone_to_erase.push_back(E);
}
}
-
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
+ // Calculate scrollable area
+ Rect2 canvas_item_rect = Rect2(Point2(), screen_rect);
+ if (editor->get_edited_scene()) {
+ Rect2 content_rect = _get_scene_encompassing_rect();
+ canvas_item_rect.expand_to(content_rect.position);
+ canvas_item_rect.expand_to(content_rect.position + content_rect.size);
+ }
canvas_item_rect.size += screen_rect * 2;
canvas_item_rect.position -= screen_rect;
@@ -3273,48 +2876,42 @@ void CanvasItemEditor::_update_scroll(float) {
editor->get_scene_root()->set_global_canvas_transform(transform);
viewport->update();
- viewport_base->update();
}
void CanvasItemEditor::_set_anchors_and_margins_preset(Control::LayoutPreset p_preset) {
List<Node *> selection = editor_selection->get_selected_node_list();
undo_redo->create_action(TTR("Change Anchors and Margins"));
+
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Control *c = Object::cast_to<Control>(E->get());
-
- undo_redo->add_do_method(c, "set_anchors_preset", p_preset);
- switch (p_preset) {
- case PRESET_TOP_LEFT:
- case PRESET_TOP_RIGHT:
- case PRESET_BOTTOM_LEFT:
- case PRESET_BOTTOM_RIGHT:
- case PRESET_CENTER_LEFT:
- case PRESET_CENTER_TOP:
- case PRESET_CENTER_RIGHT:
- case PRESET_CENTER_BOTTOM:
- case PRESET_CENTER:
- undo_redo->add_do_method(c, "set_margins_preset", p_preset, Control::PRESET_MODE_KEEP_SIZE);
- break;
- case PRESET_LEFT_WIDE:
- case PRESET_TOP_WIDE:
- case PRESET_RIGHT_WIDE:
- case PRESET_BOTTOM_WIDE:
- case PRESET_VCENTER_WIDE:
- case PRESET_HCENTER_WIDE:
- case PRESET_WIDE:
- undo_redo->add_do_method(c, "set_margins_preset", p_preset, Control::PRESET_MODE_MINSIZE);
- break;
+ Control *control = Object::cast_to<Control>(E->get());
+ if (control) {
+ undo_redo->add_do_method(control, "set_anchors_preset", p_preset);
+ switch (p_preset) {
+ case PRESET_TOP_LEFT:
+ case PRESET_TOP_RIGHT:
+ case PRESET_BOTTOM_LEFT:
+ case PRESET_BOTTOM_RIGHT:
+ case PRESET_CENTER_LEFT:
+ case PRESET_CENTER_TOP:
+ case PRESET_CENTER_RIGHT:
+ case PRESET_CENTER_BOTTOM:
+ case PRESET_CENTER:
+ undo_redo->add_do_method(control, "set_margins_preset", p_preset, Control::PRESET_MODE_KEEP_SIZE);
+ break;
+ case PRESET_LEFT_WIDE:
+ case PRESET_TOP_WIDE:
+ case PRESET_RIGHT_WIDE:
+ case PRESET_BOTTOM_WIDE:
+ case PRESET_VCENTER_WIDE:
+ case PRESET_HCENTER_WIDE:
+ case PRESET_WIDE:
+ undo_redo->add_do_method(control, "set_margins_preset", p_preset, Control::PRESET_MODE_MINSIZE);
+ break;
+ }
+ undo_redo->add_undo_method(control, "_edit_set_state", control->_edit_get_state());
}
- 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_undo_method(c, "set_margin", MARGIN_LEFT, c->get_margin(MARGIN_LEFT));
- undo_redo->add_undo_method(c, "set_margin", MARGIN_TOP, c->get_margin(MARGIN_TOP));
- undo_redo->add_undo_method(c, "set_margin", MARGIN_RIGHT, c->get_margin(MARGIN_RIGHT));
- undo_redo->add_undo_method(c, "set_margin", MARGIN_BOTTOM, c->get_margin(MARGIN_BOTTOM));
}
undo_redo->commit_action();
@@ -3326,13 +2923,11 @@ void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) {
undo_redo->create_action(TTR("Change Anchors"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Control *c = Object::cast_to<Control>(E->get());
-
- undo_redo->add_do_method(c, "set_anchors_preset", p_preset);
- 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));
+ Control *control = Object::cast_to<Control>(E->get());
+ if (control) {
+ undo_redo->add_do_method(control, "set_anchors_preset", p_preset);
+ undo_redo->add_undo_method(control, "_edit_set_state", control->_edit_get_state());
+ }
}
undo_redo->commit_action();
@@ -3351,25 +2946,34 @@ void CanvasItemEditor::_zoom_on_position(float p_zoom, Point2 p_position) {
_update_scroll(0);
viewport->update();
- viewport_base->update();
}
-void CanvasItemEditor::_zoom_minus() {
+void CanvasItemEditor::_button_zoom_minus() {
_zoom_on_position(zoom / 2.0, viewport_scrollable->get_size() / 2.0);
}
-void CanvasItemEditor::_zoom_reset() {
+void CanvasItemEditor::_button_zoom_reset() {
_zoom_on_position(1.0, viewport_scrollable->get_size() / 2.0);
}
-void CanvasItemEditor::_zoom_plus() {
+void CanvasItemEditor::_button_zoom_plus() {
_zoom_on_position(zoom * 2.0, viewport_scrollable->get_size() / 2.0);
}
-void CanvasItemEditor::_toggle_snap(bool p_status) {
+void CanvasItemEditor::_button_toggle_snap(bool p_status) {
snap_active = p_status;
viewport->update();
- viewport_base->update();
+}
+
+void CanvasItemEditor::_button_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++) {
+ tb[i]->set_pressed(i == p_index);
+ }
+
+ viewport->update();
+ tool = (Tool)p_index;
}
void CanvasItemEditor::_popup_callback(int p_op) {
@@ -3382,7 +2986,6 @@ void CanvasItemEditor::_popup_callback(int p_op) {
int idx = view_menu->get_popup()->get_item_index(SHOW_GRID);
view_menu->get_popup()->set_item_checked(idx, show_grid);
viewport->update();
- viewport_base->update();
} break;
case SNAP_USE_NODE_PARENT: {
snap_node_parent = !snap_node_parent;
@@ -3399,6 +3002,11 @@ void CanvasItemEditor::_popup_callback(int p_op) {
int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_SIDES);
smartsnap_config_popup->set_item_checked(idx, snap_node_sides);
} break;
+ case SNAP_USE_NODE_CENTER: {
+ snap_node_center = !snap_node_center;
+ int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_CENTER);
+ smartsnap_config_popup->set_item_checked(idx, snap_node_center);
+ } break;
case SNAP_USE_OTHER_NODES: {
snap_other_nodes = !snap_other_nodes;
int idx = smartsnap_config_popup->get_item_index(SNAP_USE_OTHER_NODES);
@@ -3424,7 +3032,6 @@ void CanvasItemEditor::_popup_callback(int p_op) {
int idx = snap_config_menu->get_popup()->get_item_index(SNAP_RELATIVE);
snap_config_menu->get_popup()->set_item_checked(idx, snap_relative);
viewport->update();
- viewport_base->update();
} break;
case SNAP_USE_PIXEL: {
snap_pixel = !snap_pixel;
@@ -3452,26 +3059,19 @@ void CanvasItemEditor::_popup_callback(int p_op) {
int idx = view_menu->get_popup()->get_item_index(SHOW_RULERS);
view_menu->get_popup()->set_item_checked(idx, show_rulers);
viewport->update();
- viewport_base->update();
} break;
case SHOW_GUIDES: {
show_guides = !show_guides;
int idx = view_menu->get_popup()->get_item_index(SHOW_GUIDES);
view_menu->get_popup()->set_item_checked(idx, show_guides);
viewport->update();
- viewport_base->update();
} break;
-
case LOCK_SELECTED: {
-
List<Node *> selection = editor_selection->get_selected_node_list();
-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_inside_tree())
continue;
-
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
@@ -3481,35 +3081,25 @@ void CanvasItemEditor::_popup_callback(int p_op) {
viewport->update();
} break;
case UNLOCK_SELECTED: {
-
List<Node *> selection = editor_selection->get_selected_node_list();
-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_inside_tree())
continue;
-
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
canvas_item->set_meta("_edit_lock_", Variant());
emit_signal("item_lock_status_changed");
}
-
viewport->update();
-
} break;
case GROUP_SELECTED: {
-
List<Node *> selection = editor_selection->get_selected_node_list();
-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_inside_tree())
continue;
-
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
@@ -3519,26 +3109,19 @@ void CanvasItemEditor::_popup_callback(int p_op) {
viewport->update();
} break;
case UNGROUP_SELECTED: {
-
List<Node *> selection = editor_selection->get_selected_node_list();
-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
-
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_inside_tree())
continue;
-
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
canvas_item->set_meta("_edit_group_", Variant());
emit_signal("item_group_status_changed");
}
-
viewport->update();
-
} break;
-
case ANCHORS_AND_MARGINS_PRESET_TOP_LEFT: {
_set_anchors_and_margins_preset(PRESET_TOP_LEFT);
} break;
@@ -3723,28 +3306,6 @@ 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:
- case ANIM_INSERT_POS_ROT_SCALE: {
- static const bool key_toggles[7][3]={
- {true,false,false},
- {false,true,false},
- {false,false,true},
- {true,true,false},
- {true,false,true},
- {false,true,true},
- {true,true,true}
- };
- key_pos=key_toggles[p_op-ANIM_INSERT_POS][0];
- key_rot=key_toggles[p_op-ANIM_INSERT_POS][1];
- key_scale=key_toggles[p_op-ANIM_INSERT_POS][2];
- for(int i=ANIM_INSERT_POS;i<=ANIM_INSERT_POS_ROT_SCALE;i++) {
- int idx = animation_menu->get_popup()->get_item_index(i);
- animation_menu->get_popup()->set_item_checked(idx,i==p_op);
- }
- } break;*/
case ANIM_COPY_POSE: {
pose_clipboard.clear();
@@ -3823,9 +3384,9 @@ void CanvasItemEditor::_popup_callback(int p_op) {
if (key_pos)
ctrl->set_position(Point2());
/*
- if (key_scale)
- AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size());
- */
+ if (key_scale)
+ AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size());
+ */
}
}
@@ -3974,20 +3535,18 @@ void CanvasItemEditor::_focus_selection(int p_op) {
void CanvasItemEditor::_bind_methods() {
- ClassDB::bind_method("_zoom_minus", &CanvasItemEditor::_zoom_minus);
- ClassDB::bind_method("_zoom_reset", &CanvasItemEditor::_zoom_reset);
- ClassDB::bind_method("_zoom_plus", &CanvasItemEditor::_zoom_plus);
- ClassDB::bind_method("_toggle_snap", &CanvasItemEditor::_toggle_snap);
+ ClassDB::bind_method("_button_zoom_minus", &CanvasItemEditor::_button_zoom_minus);
+ ClassDB::bind_method("_button_zoom_reset", &CanvasItemEditor::_button_zoom_reset);
+ ClassDB::bind_method("_button_zoom_plus", &CanvasItemEditor::_button_zoom_plus);
+ ClassDB::bind_method("_button_toggle_snap", &CanvasItemEditor::_button_toggle_snap);
ClassDB::bind_method("_update_scroll", &CanvasItemEditor::_update_scroll);
ClassDB::bind_method("_popup_callback", &CanvasItemEditor::_popup_callback);
ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data);
- ClassDB::bind_method("_tool_select", &CanvasItemEditor::_tool_select);
+ ClassDB::bind_method("_button_tool_select", &CanvasItemEditor::_button_tool_select);
ClassDB::bind_method("_keying_changed", &CanvasItemEditor::_keying_changed);
ClassDB::bind_method("_unhandled_key_input", &CanvasItemEditor::_unhandled_key_input);
ClassDB::bind_method("_draw_viewport", &CanvasItemEditor::_draw_viewport);
- ClassDB::bind_method("_draw_viewport_base", &CanvasItemEditor::_draw_viewport_base);
ClassDB::bind_method("_gui_input_viewport", &CanvasItemEditor::_gui_input_viewport);
- ClassDB::bind_method("_gui_input_viewport_base", &CanvasItemEditor::_gui_input_viewport_base);
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);
@@ -3997,6 +3556,162 @@ void CanvasItemEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_group_status_changed"));
}
+Dictionary CanvasItemEditor::get_state() const {
+
+ Dictionary state;
+ state["zoom"] = zoom;
+ state["ofs"] = Point2(h_scroll->get_value(), v_scroll->get_value());
+ state["grid_offset"] = grid_offset;
+ state["grid_step"] = grid_step;
+ state["snap_rotation_offset"] = snap_rotation_offset;
+ state["snap_rotation_step"] = snap_rotation_step;
+ state["snap_active"] = snap_active;
+ state["snap_node_parent"] = snap_node_parent;
+ state["snap_node_anchors"] = snap_node_anchors;
+ state["snap_node_sides"] = snap_node_sides;
+ state["snap_node_center"] = snap_node_center;
+ state["snap_other_nodes"] = snap_other_nodes;
+ state["snap_grid"] = snap_grid;
+ state["snap_guides"] = snap_guides;
+ state["show_grid"] = show_grid;
+ state["show_rulers"] = show_rulers;
+ state["show_guides"] = show_guides;
+ state["show_helpers"] = show_helpers;
+ 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) {
+
+ Dictionary state = p_state;
+ if (state.has("zoom")) {
+ zoom = p_state["zoom"];
+ }
+
+ if (state.has("ofs")) {
+ _update_scrollbars(); // i wonder how safe is calling this here..
+ Point2 ofs = p_state["ofs"];
+ h_scroll->set_value(ofs.x);
+ v_scroll->set_value(ofs.y);
+ }
+
+ if (state.has("grid_offset")) {
+ grid_offset = state["grid_offset"];
+ }
+
+ if (state.has("grid_step")) {
+ grid_step = state["grid_step"];
+ }
+
+ if (state.has("snap_rotation_step")) {
+ snap_rotation_step = state["snap_rotation_step"];
+ }
+
+ if (state.has("snap_rotation_offset")) {
+ snap_rotation_offset = state["snap_rotation_offset"];
+ }
+
+ if (state.has("snap_active")) {
+ snap_active = state["snap_active"];
+ snap_button->set_pressed(snap_active);
+ }
+
+ if (state.has("snap_node_parent")) {
+ snap_node_parent = state["snap_node_parent"];
+ int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_PARENT);
+ smartsnap_config_popup->set_item_checked(idx, snap_node_parent);
+ }
+
+ if (state.has("snap_node_anchors")) {
+ snap_node_anchors = state["snap_node_anchors"];
+ int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_ANCHORS);
+ smartsnap_config_popup->set_item_checked(idx, snap_node_anchors);
+ }
+
+ if (state.has("snap_node_sides")) {
+ snap_node_sides = state["snap_node_sides"];
+ int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_SIDES);
+ smartsnap_config_popup->set_item_checked(idx, snap_node_sides);
+ }
+
+ if (state.has("snap_node_center")) {
+ snap_node_center = state["snap_node_center"];
+ int idx = smartsnap_config_popup->get_item_index(SNAP_USE_NODE_CENTER);
+ smartsnap_config_popup->set_item_checked(idx, snap_node_center);
+ }
+
+ if (state.has("snap_other_nodes")) {
+ snap_other_nodes = state["snap_other_nodes"];
+ int idx = smartsnap_config_popup->get_item_index(SNAP_USE_OTHER_NODES);
+ smartsnap_config_popup->set_item_checked(idx, snap_other_nodes);
+ }
+
+ if (state.has("snap_guides")) {
+ snap_guides = state["snap_guides"];
+ int idx = smartsnap_config_popup->get_item_index(SNAP_USE_GUIDES);
+ smartsnap_config_popup->set_item_checked(idx, snap_guides);
+ }
+
+ if (state.has("snap_grid")) {
+ snap_grid = state["snap_grid"];
+ int idx = snap_config_menu->get_popup()->get_item_index(SNAP_USE_GRID);
+ snap_config_menu->get_popup()->set_item_checked(idx, snap_grid);
+ }
+
+ if (state.has("show_grid")) {
+ show_grid = state["show_grid"];
+ int idx = view_menu->get_popup()->get_item_index(SHOW_GRID);
+ view_menu->get_popup()->set_item_checked(idx, show_grid);
+ }
+
+ if (state.has("show_rulers")) {
+ show_rulers = state["show_rulers"];
+ int idx = view_menu->get_popup()->get_item_index(SHOW_RULERS);
+ view_menu->get_popup()->set_item_checked(idx, show_rulers);
+ }
+
+ if (state.has("show_guides")) {
+ show_guides = state["show_guides"];
+ int idx = view_menu->get_popup()->get_item_index(SHOW_GUIDES);
+ view_menu->get_popup()->set_item_checked(idx, show_guides);
+ }
+
+ if (state.has("show_helpers")) {
+ show_helpers = state["show_helpers"];
+ int idx = view_menu->get_popup()->get_item_index(SHOW_HELPERS);
+ view_menu->get_popup()->set_item_checked(idx, show_helpers);
+ }
+
+ if (state.has("snap_rotation")) {
+ snap_rotation = state["snap_rotation"];
+ int idx = snap_config_menu->get_popup()->get_item_index(SNAP_USE_ROTATION);
+ snap_config_menu->get_popup()->set_item_checked(idx, snap_rotation);
+ }
+
+ if (state.has("snap_relative")) {
+ snap_relative = state["snap_relative"];
+ int idx = snap_config_menu->get_popup()->get_item_index(SNAP_RELATIVE);
+ snap_config_menu->get_popup()->set_item_checked(idx, snap_relative);
+ }
+
+ if (state.has("snap_pixel")) {
+ snap_pixel = state["snap_pixel"];
+ int idx = snap_config_menu->get_popup()->get_item_index(SNAP_USE_PIXEL);
+ snap_config_menu->get_popup()->set_item_checked(idx, snap_pixel);
+ }
+
+ if (state.has("skeleton_show_bones")) {
+ skeleton_show_bones = state["skeleton_show_bones"];
+ int idx = skeleton_menu->get_popup()->get_item_index(SKELETON_SHOW_BONES);
+ skeleton_menu->get_popup()->set_item_checked(idx, skeleton_show_bones);
+ }
+
+ viewport->update();
+}
+
void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
hb->add_child(p_control);
@@ -4042,21 +3757,12 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
bottom_split->add_child(palette_split);
palette_split->set_v_size_flags(SIZE_EXPAND_FILL);
- viewport_base = memnew(Control);
- palette_split->add_child(viewport_base);
- viewport_base->set_clip_contents(true);
- viewport_base->connect("draw", this, "_draw_viewport_base");
- viewport_base->connect("gui_input", this, "_gui_input_viewport_base");
- viewport_base->set_focus_mode(FOCUS_ALL);
- viewport_base->set_v_size_flags(SIZE_EXPAND_FILL);
- viewport_base->set_h_size_flags(SIZE_EXPAND_FILL);
-
viewport_scrollable = memnew(Control);
- viewport_base->add_child(viewport_scrollable);
+ palette_split->add_child(viewport_scrollable);
viewport_scrollable->set_mouse_filter(MOUSE_FILTER_PASS);
- viewport_scrollable->set_draw_behind_parent(true);
- viewport_scrollable->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- viewport_scrollable->set_begin(Point2(RULER_WIDTH, RULER_WIDTH));
+ viewport_scrollable->set_clip_contents(true);
+ viewport_scrollable->set_v_size_flags(SIZE_EXPAND_FILL);
+ viewport_scrollable->set_h_size_flags(SIZE_EXPAND_FILL);
ViewportContainer *scene_tree = memnew(ViewportContainer);
viewport_scrollable->add_child(scene_tree);
@@ -4069,6 +3775,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
viewport->set_mouse_filter(MOUSE_FILTER_PASS);
viewport->set_anchors_and_margins_preset(Control::PRESET_WIDE);
viewport->set_clip_contents(true);
+ viewport->set_focus_mode(FOCUS_ALL);
viewport->connect("draw", this, "_draw_viewport");
viewport->connect("gui_input", this, "_gui_input_viewport");
@@ -4082,33 +3789,32 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
v_scroll->connect("value_changed", this, "_update_scroll", Vector<Variant>(), Object::CONNECT_DEFERRED);
v_scroll->hide();
- HBoxContainer *zoom_hb = memnew(HBoxContainer);
+ zoom_hb = memnew(HBoxContainer);
viewport->add_child(zoom_hb);
zoom_hb->set_begin(Point2(5, 5));
zoom_minus = memnew(ToolButton);
zoom_hb->add_child(zoom_minus);
- zoom_minus->connect("pressed", this, "_zoom_minus");
+ zoom_minus->connect("pressed", this, "_button_zoom_minus");
zoom_minus->set_focus_mode(FOCUS_NONE);
zoom_reset = memnew(ToolButton);
zoom_hb->add_child(zoom_reset);
- zoom_reset->connect("pressed", this, "_zoom_reset");
+ zoom_reset->connect("pressed", this, "_button_zoom_reset");
zoom_reset->set_focus_mode(FOCUS_NONE);
zoom_plus = memnew(ToolButton);
zoom_hb->add_child(zoom_plus);
- zoom_plus->connect("pressed", this, "_zoom_plus");
+ zoom_plus->connect("pressed", this, "_button_zoom_plus");
zoom_plus->set_focus_mode(FOCUS_NONE);
updating_scroll = false;
- handle_len = 10;
first_update = true;
select_button = memnew(ToolButton);
hb->add_child(select_button);
select_button->set_toggle_mode(true);
- select_button->connect("pressed", this, "_tool_select", make_binds(TOOL_SELECT));
+ select_button->connect("pressed", this, "_button_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(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"));
@@ -4116,14 +3822,14 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
move_button = memnew(ToolButton);
hb->add_child(move_button);
move_button->set_toggle_mode(true);
- move_button->connect("pressed", this, "_tool_select", make_binds(TOOL_MOVE));
+ move_button->connect("pressed", this, "_button_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);
hb->add_child(rotate_button);
rotate_button->set_toggle_mode(true);
- rotate_button->connect("pressed", this, "_tool_select", make_binds(TOOL_ROTATE));
+ rotate_button->connect("pressed", this, "_button_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"));
@@ -4132,19 +3838,19 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
list_select_button = memnew(ToolButton);
hb->add_child(list_select_button);
list_select_button->set_toggle_mode(true);
- list_select_button->connect("pressed", this, "_tool_select", make_binds(TOOL_LIST_SELECT));
+ list_select_button->connect("pressed", this, "_button_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);
hb->add_child(pivot_button);
pivot_button->set_toggle_mode(true);
- pivot_button->connect("pressed", this, "_tool_select", make_binds(TOOL_EDIT_PIVOT));
+ pivot_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_EDIT_PIVOT));
pivot_button->set_tooltip(TTR("Click to change object's rotation pivot."));
pan_button = memnew(ToolButton);
hb->add_child(pan_button);
pan_button->set_toggle_mode(true);
- pan_button->connect("pressed", this, "_tool_select", make_binds(TOOL_PAN));
+ pan_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_PAN));
pan_button->set_tooltip(TTR("Pan Mode"));
hb->add_child(memnew(VSeparator));
@@ -4152,7 +3858,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
snap_button = memnew(ToolButton);
hb->add_child(snap_button);
snap_button->set_toggle_mode(true);
- snap_button->connect("toggled", this, "_toggle_snap");
+ snap_button->connect("toggled", this, "_button_toggle_snap");
snap_button->set_tooltip(TTR("Toggles snapping"));
snap_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/use_snap", TTR("Use Snap"), KEY_S));
@@ -4179,6 +3885,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
smartsnap_config_popup->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_node_parent", TTR("Snap to parent")), SNAP_USE_NODE_PARENT);
smartsnap_config_popup->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_node_anchors", TTR("Snap to node anchor")), SNAP_USE_NODE_ANCHORS);
smartsnap_config_popup->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_node_sides", TTR("Snap to node sides")), SNAP_USE_NODE_SIDES);
+ smartsnap_config_popup->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_node_center", TTR("Snap to node center")), SNAP_USE_NODE_CENTER);
smartsnap_config_popup->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_other_nodes", TTR("Snap to other nodes")), SNAP_USE_OTHER_NODES);
smartsnap_config_popup->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_guides", TTR("Snap to guides")), SNAP_USE_GUIDES);
@@ -4310,9 +4017,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
selection_menu->connect("id_pressed", this, "_selection_result_pressed");
selection_menu->connect("popup_hide", this, "_selection_menu_hide");
- drag_pivot_shortcut = ED_SHORTCUT("canvas_item_editor/drag_pivot", TTR("Drag pivot from mouse position"), KEY_MASK_SHIFT | KEY_V);
- set_pivot_shortcut = ED_SHORTCUT("canvas_item_editor/set_pivot", TTR("Set pivot at mouse position"), KEY_V);
-
multiply_grid_step_shortcut = ED_SHORTCUT("canvas_item_editor/multiply_grid_step", TTR("Multiply grid step by 2"), KEY_KP_MULTIPLY);
divide_grid_step_shortcut = ED_SHORTCUT("canvas_item_editor/divide_grid_step", TTR("Divide grid step by 2"), KEY_KP_DIVIDE);
@@ -4320,9 +4024,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
key_rot = true;
key_scale = false;
- edited_guide_pos = Point2();
- edited_guide_index = -1;
-
show_grid = false;
show_helpers = false;
show_rulers = true;
@@ -4337,6 +4038,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
snap_node_parent = true;
snap_node_anchors = true;
snap_node_sides = true;
+ snap_node_center = true;
snap_other_nodes = true;
snap_grid = true;
snap_guides = true;
@@ -4344,17 +4046,19 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
snap_pixel = false;
skeleton_show_bones = true;
skeleton_menu->get_popup()->set_item_checked(skeleton_menu->get_popup()->get_item_index(SKELETON_SHOW_BONES), true);
- box_selecting = false;
- //zoom=0.5;
singleton = this;
set_process_unhandled_key_input(true);
- can_move_pivot = false;
- drag = DRAG_NONE;
+
+ drag_type = DRAG_NONE;
+ drag_from = Vector2();
+ drag_to = Vector2();
+ dragged_guide_pos = Point2();
+ dragged_guide_index = -1;
+
bone_last_frame = 0;
- additive_selection = false;
- // Update the menus checkboxes
+ // Update the menus' checkboxes
call_deferred("set_state", get_state());
}
@@ -4377,7 +4081,7 @@ void CanvasItemEditorPlugin::make_visible(bool p_visible) {
canvas_item_editor->show();
canvas_item_editor->set_physics_process(true);
VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport_rid(), false);
- canvas_item_editor->viewport_base->grab_focus();
+ canvas_item_editor->viewport->grab_focus();
} else {
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index ee9be86cce..adf203cf3d 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -50,9 +50,6 @@ class CanvasItemEditorSelectedItem : public Object {
GDCLASS(CanvasItemEditorSelectedItem, Object);
public:
- Variant undo_state;
- Vector2 undo_pivot;
-
Transform2D prev_xform;
float prev_rot;
Rect2 prev_rect;
@@ -62,6 +59,11 @@ public:
Transform2D pre_drag_xform;
Rect2 pre_drag_rect;
+ List<float> pre_drag_bones_length;
+ List<Dictionary> pre_drag_bones_undo_state;
+
+ Dictionary undo_state;
+
CanvasItemEditorSelectedItem() { prev_rot = 0; }
};
@@ -86,6 +88,7 @@ class CanvasItemEditor : public VBoxContainer {
SNAP_USE_NODE_PARENT,
SNAP_USE_NODE_ANCHORS,
SNAP_USE_NODE_SIDES,
+ SNAP_USE_NODE_CENTER,
SNAP_USE_OTHER_NODES,
SNAP_USE_GRID,
SNAP_USE_GUIDES,
@@ -169,6 +172,7 @@ class CanvasItemEditor : public VBoxContainer {
enum DragType {
DRAG_NONE,
+ DRAG_BOX_SELECTION,
DRAG_LEFT,
DRAG_TOP_LEFT,
DRAG_TOP,
@@ -185,29 +189,20 @@ class CanvasItemEditor : public VBoxContainer {
DRAG_ALL,
DRAG_ROTATE,
DRAG_PIVOT,
- DRAG_NODE_2D,
DRAG_V_GUIDE,
DRAG_H_GUIDE,
DRAG_DOUBLE_GUIDE,
- };
-
- enum KeyMoveMODE {
- MOVE_VIEW_BASE,
- MOVE_LOCAL_BASE,
- MOVE_LOCAL_WITH_ROT
+ DRAG_KEY_MOVE
};
EditorSelection *editor_selection;
- bool additive_selection;
+ bool selection_menu_additive_selection;
Tool tool;
bool first_update;
Control *viewport;
- Control *viewport_base;
Control *viewport_scrollable;
- bool can_move_pivot;
-
HScrollBar *h_scroll;
VScrollBar *v_scroll;
HBoxContainer *hb;
@@ -233,6 +228,7 @@ class CanvasItemEditor : public VBoxContainer {
bool snap_node_parent;
bool snap_node_anchors;
bool snap_node_sides;
+ bool snap_node_center;
bool snap_other_nodes;
bool snap_grid;
bool snap_guides;
@@ -240,14 +236,10 @@ class CanvasItemEditor : public VBoxContainer {
bool snap_relative;
bool snap_pixel;
bool skeleton_show_bones;
- bool box_selecting;
- Point2 box_selecting_to;
bool key_pos;
bool key_rot;
bool key_scale;
- void _tool_select(int p_index);
-
MenuOption last_option;
struct _SelectResult {
@@ -267,33 +259,17 @@ class CanvasItemEditor : public VBoxContainer {
Transform2D xform;
Vector2 from;
Vector2 to;
- ObjectID bone;
uint64_t last_pass;
};
-
uint64_t bone_last_frame;
Map<ObjectID, BoneList> bone_list;
- Transform2D bone_orig_xform;
-
- struct BoneIK {
-
- Variant orig_state;
- Vector2 pos;
- float len;
- Node2D *node;
- };
-
- List<BoneIK> bone_ik_list;
-
struct PoseClipboard {
-
Vector2 pos;
Vector2 scale;
float rot;
ObjectID id;
};
-
List<PoseClipboard> pose_clipboard;
ToolButton *select_button;
@@ -333,16 +309,17 @@ class CanvasItemEditor : public VBoxContainer {
Control *top_ruler;
Control *left_ruler;
- //PopupMenu *popup;
- DragType drag;
+ DragType drag_type;
Point2 drag_from;
- Point2 drag_point_from;
+ Point2 drag_to;
+ Point2 drag_rotation_center;
+ List<CanvasItem *> drag_selection;
+ int dragged_guide_index;
+ Point2 dragged_guide_pos;
+
bool updating_value_dialog;
- Point2 display_rotate_from;
- Point2 display_rotate_to;
- int edited_guide_index;
- Point2 edited_guide_pos;
+ Point2 box_selecting_to;
Ref<StyleBoxTexture> select_sb;
Ref<Texture> select_handle;
@@ -353,28 +330,19 @@ class CanvasItemEditor : public VBoxContainer {
Ref<ShortCut> multiply_grid_step_shortcut;
Ref<ShortCut> divide_grid_step_shortcut;
- int handle_len;
- bool _is_part_of_subscene(CanvasItem *p_item);
- 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, int limit = 0);
- 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);
-
- void _select_click_on_empty_area(Point2 p_click_pos, bool p_append, bool p_box_selection);
- bool _select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag);
+ void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, int limit = 0, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
+ void _find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_node, List<CanvasItem *> *r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
+ bool _select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append);
ConfirmationDialog *snap_dialog;
CanvasItem *ref_item;
- 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 _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode);
- void _list_select(const Ref<InputEventMouseButton> &b);
- DragType _get_resize_handle_drag_type(const Point2 &p_click, Vector2 &r_point);
- void _prepare_drag(const Point2 &p_click_pos);
- DragType _get_anchor_handle_drag_type(const Point2 &p_click, Vector2 &r_point);
+ void _save_canvas_item_state(List<CanvasItem *> p_canvas_items, bool save_bones = false);
+ void _restore_canvas_item_state(List<CanvasItem *> p_canvas_items, bool restore_bones = false);
+ void _commit_canvas_item_state(List<CanvasItem *> p_canvas_items, String action_name, bool commit_bones = false);
Vector2 _anchor_to_position(const Control *p_control, Vector2 anchor);
Vector2 _position_to_anchor(const Control *p_control, Vector2 position);
@@ -383,27 +351,21 @@ class CanvasItemEditor : public VBoxContainer {
bool updating_scroll;
void _update_scroll(float);
void _update_scrollbars();
- void _update_cursor();
- 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 _snap_changed();
void _selection_result_pressed(int);
void _selection_menu_hide();
UndoRedo *undo_redo;
-
- Point2 _find_topleftmost_point();
-
void _build_bones_list(Node *p_node);
- void _get_encompassing_rect(Node *p_node, Rect2 &r_rect, const Transform2D &p_xform);
+ List<CanvasItem *> _get_edited_canvas_items(bool retreive_locked = false, bool remove_canvas_item_if_parent_in_selection = true);
+ Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list);
+ void _expand_encompassing_rect_using_children(Rect2 &p_rect, Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
+ Rect2 _get_scene_encompassing_rect();
Object *_get_editor_data(Object *p_what);
- CanvasItem *_get_single_item();
- int get_item_count();
void _keying_changed();
void _unhandled_key_input(const Ref<InputEvent> &p_ev);
@@ -411,6 +373,7 @@ class CanvasItemEditor : public VBoxContainer {
void _draw_text_at_position(Point2 p_position, String p_string, Margin p_side);
void _draw_margin_at_position(int p_value, Point2 p_position, Margin p_side);
void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side);
+ void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color);
void _draw_rulers();
void _draw_guides();
@@ -422,13 +385,23 @@ class CanvasItemEditor : public VBoxContainer {
void _draw_locks_and_groups(Node *p_node, const Transform2D &p_xform);
void _draw_viewport();
- void _draw_viewport_base();
+
+ bool _gui_input_anchors(const Ref<InputEvent> &p_event);
+ bool _gui_input_move(const Ref<InputEvent> &p_event);
+ bool _gui_input_open_scene_on_double_click(const Ref<InputEvent> &p_event);
+ bool _gui_input_pivot(const Ref<InputEvent> &p_event);
+ bool _gui_input_resize(const Ref<InputEvent> &p_event);
+ bool _gui_input_rotate(const Ref<InputEvent> &p_event);
+ bool _gui_input_select(const Ref<InputEvent> &p_event);
+ bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event);
+ bool _gui_input_rulers_and_guides(const Ref<InputEvent> &p_event);
void _gui_input_viewport(const Ref<InputEvent> &p_event);
- void _gui_input_viewport_base(const Ref<InputEvent> &p_event);
void _focus_selection(int p_op);
+ void _solve_IK(Node2D *leaf_node, Point2 target_position);
+
void _snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius = 10.0);
void _snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation = 0.0, float p_radius = 10.0);
void _snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap = NULL);
@@ -437,12 +410,13 @@ class CanvasItemEditor : public VBoxContainer {
void _set_margins_preset(Control::LayoutPreset p_preset);
void _set_anchors_and_margins_preset(Control::LayoutPreset p_preset);
+ HBoxContainer *zoom_hb;
void _zoom_on_position(float p_zoom, Point2 p_position = Point2());
- void _zoom_minus();
- void _zoom_reset();
- void _zoom_plus();
-
- void _toggle_snap(bool p_status);
+ void _button_zoom_minus();
+ void _button_zoom_reset();
+ void _button_zoom_plus();
+ void _button_toggle_snap(bool p_status);
+ void _button_tool_select(int p_index);
HSplitContainer *palette_split;
VSplitContainer *bottom_split;
@@ -494,9 +468,10 @@ public:
SNAP_NODE_PARENT = 1 << 3,
SNAP_NODE_ANCHORS = 1 << 4,
SNAP_NODE_SIDES = 1 << 5,
- SNAP_OTHER_NODES = 1 << 6,
+ SNAP_NODE_CENTER = 1 << 6,
+ SNAP_OTHER_NODES = 1 << 7,
- SNAP_DEFAULT = 0x07,
+ SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL,
};
Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, const CanvasItem *p_canvas_item = NULL, unsigned int p_forced_modes = 0);
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index bd8c502a80..c06531d975 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -505,7 +505,7 @@ void ScriptEditor::_show_error_dialog(String p_path) {
error_dialog->popup_centered_minsize();
}
-void ScriptEditor::_close_tab(int p_idx, bool p_save) {
+void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
int selected = p_idx;
if (selected < 0 || selected >= tab_container->get_child_count())
@@ -521,7 +521,9 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) {
}
// roll back to previous tab
- _history_back();
+ if (p_history_back) {
+ _history_back();
+ }
//remove from history
history.resize(history_pos + 1);
@@ -579,7 +581,7 @@ void ScriptEditor::_close_docs_tab() {
EditorHelp *se = Object::cast_to<EditorHelp>(tab_container->get_child(i));
if (se) {
- _close_tab(i);
+ _close_tab(i, true, false);
}
}
}
@@ -1576,6 +1578,9 @@ void ScriptEditor::_update_script_names() {
case SORT_BY_PATH: {
sd.sort_key = path;
} break;
+ case SORT_BY_NONE: {
+ sd.sort_key = "";
+ } break;
}
switch (display_as) {
@@ -2926,7 +2931,7 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) {
EDITOR_DEF("text_editor/open_scripts/script_temperature_history_size", 15);
EDITOR_DEF("text_editor/open_scripts/current_script_background_color", Color(1, 1, 1, 0.3));
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"));
+ EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/sort_scripts_by", PROPERTY_HINT_ENUM, "Name,Path,None"));
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);
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index e98a4c97a6..bcc604d990 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -165,6 +165,7 @@ class ScriptEditor : public PanelContainer {
enum ScriptSortBy {
SORT_BY_NAME,
SORT_BY_PATH,
+ SORT_BY_NONE
};
enum ScriptListName {
@@ -251,7 +252,7 @@ class ScriptEditor : public PanelContainer {
void _show_error_dialog(String p_path);
- void _close_tab(int p_idx, bool p_save = true);
+ void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true);
void _close_current_tab();
void _close_discard_current_tab(const String &p_str);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 87e92f0807..aeba0ff930 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -935,13 +935,27 @@ void ScriptTextEditor::_edit_option(int p_op) {
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
-
tx->begin_complex_operation();
- int line = tx->cursor_get_line();
- tx->set_line(tx->cursor_get_line(), "");
- tx->backspace_at_cursor();
- tx->unfold_line(line);
- tx->cursor_set_line(line);
+ if (tx->is_selection_active()) {
+ int to_line = tx->get_selection_to_line();
+ int from_line = tx->get_selection_from_line();
+ int count = Math::abs(to_line - from_line) + 1;
+ while (count) {
+ tx->set_line(tx->cursor_get_line(), "");
+ tx->backspace_at_cursor();
+ count--;
+ if (count)
+ tx->unfold_line(from_line);
+ }
+ tx->cursor_set_line(from_line - 1);
+ tx->deselect();
+ } else {
+ int line = tx->cursor_get_line();
+ tx->set_line(tx->cursor_get_line(), "");
+ tx->backspace_at_cursor();
+ tx->unfold_line(line);
+ tx->cursor_set_line(line);
+ }
tx->end_complex_operation();
} break;
case EDIT_CLONE_DOWN: {
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 63762651d7..6fd93c2f28 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -4282,67 +4282,26 @@ void SpatialEditor::_init_indicators() {
indicator_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
indicator_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
- PoolVector<Color> grid_colors[3];
- PoolVector<Vector3> grid_points[3];
Vector<Color> origin_colors;
Vector<Vector3> origin_points;
- Color grid_color = EditorSettings::get_singleton()->get("editors/3d/grid_color");
-
for (int i = 0; i < 3; i++) {
Vector3 axis;
axis[i] = 1;
- Vector3 axis_n1;
- axis_n1[(i + 1) % 3] = 1;
- Vector3 axis_n2;
- axis_n2[(i + 2) % 3] = 1;
+
+ grid_enable[i] = false;
+ grid_visible[i] = false;
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 50
-
- for (int j = -ORIGIN_GRID_SIZE; j <= ORIGIN_GRID_SIZE; j++) {
-
- Vector3 p1 = axis_n1 * j + axis_n2 * -ORIGIN_GRID_SIZE;
- Vector3 p1_dest = p1 * (-axis_n2 + axis_n1);
- Vector3 p2 = axis_n2 * j + axis_n1 * -ORIGIN_GRID_SIZE;
- Vector3 p2_dest = p2 * (-axis_n1 + axis_n2);
-
- Color line_color = grid_color;
- if (j == 0) {
- continue;
- } else if (j % 10 == 0) {
- line_color *= 1.5;
- }
-
- grid_points[i].push_back(p1);
- grid_points[i].push_back(p1_dest);
- grid_colors[i].push_back(line_color);
- grid_colors[i].push_back(line_color);
-
- grid_points[i].push_back(p2);
- grid_points[i].push_back(p2_dest);
- grid_colors[i].push_back(line_color);
- grid_colors[i].push_back(line_color);
- }
+ }
- 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_enable[1] = true;
+ grid_visible[1] = true;
- 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);
- }
+ _init_grid();
origin = VisualServer::get_singleton()->mesh_create();
Array d;
@@ -4358,9 +4317,6 @@ void SpatialEditor::_init_indicators() {
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;
}
@@ -4629,10 +4585,71 @@ void SpatialEditor::_init_indicators() {
_generate_selection_box();
}
+void SpatialEditor::_init_grid() {
+
+ PoolVector<Color> grid_colors[3];
+ PoolVector<Vector3> grid_points[3];
+
+ Color grid_color = EditorSettings::get_singleton()->get("editors/3d/grid_color");
+
+ for (int i = 0; i < 3; i++) {
+ Vector3 axis;
+ axis[i] = 1;
+ Vector3 axis_n1;
+ axis_n1[(i + 1) % 3] = 1;
+ Vector3 axis_n2;
+ axis_n2[(i + 2) % 3] = 1;
+
+#define ORIGIN_GRID_SIZE 50
+
+ for (int j = -ORIGIN_GRID_SIZE; j <= ORIGIN_GRID_SIZE; j++) {
+ Vector3 p1 = axis_n1 * j + axis_n2 * -ORIGIN_GRID_SIZE;
+ Vector3 p1_dest = p1 * (-axis_n2 + axis_n1);
+ Vector3 p2 = axis_n2 * j + axis_n1 * -ORIGIN_GRID_SIZE;
+ Vector3 p2_dest = p2 * (-axis_n1 + axis_n2);
+
+ Color line_color = grid_color;
+ if (j == 0) {
+ continue;
+ } else if (j % 10 == 0) {
+ line_color *= 1.5;
+ }
+
+ grid_points[i].push_back(p1);
+ grid_points[i].push_back(p1_dest);
+ grid_colors[i].push_back(line_color);
+ grid_colors[i].push_back(line_color);
+
+ grid_points[i].push_back(p2);
+ grid_points[i].push_back(p2_dest);
+ grid_colors[i].push_back(line_color);
+ grid_colors[i].push_back(line_color);
+ }
+
+ 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());
+
+ VisualServer::get_singleton()->instance_set_visible(grid_instance[i], grid_visible[i]);
+ 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);
+ }
+}
+
void SpatialEditor::_finish_indicators() {
VisualServer::get_singleton()->free(origin_instance);
VisualServer::get_singleton()->free(origin);
+
+ _finish_grid();
+}
+
+void SpatialEditor::_finish_grid() {
for (int i = 0; i < 3; i++) {
VisualServer::get_singleton()->free(grid_instance[i]);
VisualServer::get_singleton()->free(grid[i]);
@@ -4770,6 +4787,10 @@ void SpatialEditor::_notification(int p_what) {
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"));
+
+ // Update grid color by rebuilding grid.
+ _finish_grid();
+ _init_grid();
}
}
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 55866cac99..d1fcdf8d54 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -531,7 +531,9 @@ private:
void _instance_scene();
void _init_indicators();
+ void _init_grid();
void _finish_indicators();
+ void _finish_grid();
void _toggle_maximize_view(Object *p_viewport);
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index 7a4eee0344..d8d0a6f013 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -398,8 +398,6 @@ void SpriteFramesEditor::_animation_add() {
animations->grab_focus();
}
void SpriteFramesEditor::_animation_remove() {
-
- //fuck everything
if (updating)
return;
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index e04798d6d6..215d2ca551 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -57,6 +57,8 @@ void TextureRegionEditor::_region_draw() {
base_tex = obj_styleBox->get_texture();
else if (atlas_tex.is_valid())
base_tex = atlas_tex->get_atlas();
+ else if (tile_set.is_valid() && selected_tile != -1)
+ base_tex = tile_set->tile_get_texture(selected_tile);
if (base_tex.is_null())
return;
@@ -281,6 +283,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
r = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid())
r = atlas_tex->get_region();
+ else if (tile_set.is_valid() && selected_tile != -1)
+ r = tile_set->tile_get_region(selected_tile);
rect.expand_to(r.position);
rect.expand_to(r.position + r.size);
}
@@ -297,6 +301,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
} 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());
+ } else if (tile_set.is_valid() && selected_tile != -1) {
+ undo_redo->add_do_method(tile_set.ptr(), "tile_set_region", selected_tile, rect);
+ undo_redo->add_undo_method(tile_set.ptr(), "tile_set_region", selected_tile, tile_set->tile_get_region(selected_tile));
}
undo_redo->add_do_method(edit_draw, "update");
undo_redo->add_undo_method(edit_draw, "update");
@@ -319,6 +326,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
rect_prev = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid())
rect_prev = atlas_tex->get_region();
+ else if (tile_set.is_valid() && selected_tile != -1)
+ rect_prev = tile_set->tile_get_region(selected_tile);
for (int i = 0; i < 8; i++) {
Vector2 tuv = endpoints[i];
@@ -362,6 +371,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
} 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);
+ } else if (tile_set.is_valid()) {
+ undo_redo->add_do_method(tile_set.ptr(), "tile_set_region", selected_tile, tile_set->tile_get_region(selected_tile));
+ undo_redo->add_undo_method(tile_set.ptr(), "tile_set_region", selected_tile, rect_prev);
}
drag_index = -1;
}
@@ -582,6 +594,8 @@ void TextureRegionEditor::apply_rect(const Rect2 &rect) {
obj_styleBox->set_region_rect(rect);
else if (atlas_tex.is_valid())
atlas_tex->set_region(rect);
+ else if (tile_set.is_valid() && selected_tile != -1)
+ tile_set->tile_set_region(selected_tile, rect);
}
void TextureRegionEditor::_notification(int p_what) {
@@ -596,11 +610,12 @@ void TextureRegionEditor::_notification(int p_what) {
}
void TextureRegionEditor::_node_removed(Object *p_obj) {
- if (p_obj == node_sprite || p_obj == node_ninepatch || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr()) {
+ if (p_obj == node_sprite || p_obj == node_ninepatch || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr() || p_obj == tile_set.ptr()) {
node_ninepatch = NULL;
node_sprite = NULL;
obj_styleBox = Ref<StyleBox>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL);
+ tile_set = Ref<TileSet>(NULL);
hide();
}
}
@@ -632,6 +647,8 @@ void TextureRegionEditor::edit(Object *p_obj) {
obj_styleBox->remove_change_receptor(this);
if (atlas_tex.is_valid())
atlas_tex->remove_change_receptor(this);
+ if (tile_set.is_valid())
+ tile_set->remove_change_receptor(this);
if (p_obj) {
node_sprite = Object::cast_to<Sprite>(p_obj);
node_ninepatch = Object::cast_to<NinePatchRect>(p_obj);
@@ -639,6 +656,8 @@ void TextureRegionEditor::edit(Object *p_obj) {
obj_styleBox = Ref<StyleBoxTexture>(Object::cast_to<StyleBoxTexture>(p_obj));
if (Object::cast_to<AtlasTexture>(p_obj))
atlas_tex = Ref<AtlasTexture>(Object::cast_to<AtlasTexture>(p_obj));
+ if (Object::cast_to<TileSet>(p_obj))
+ tile_set = Ref<TileSet>(Object::cast_to<TileSet>(p_obj));
p_obj->add_change_receptor(this);
_edit_region();
} else {
@@ -646,6 +665,7 @@ void TextureRegionEditor::edit(Object *p_obj) {
node_ninepatch = NULL;
obj_styleBox = Ref<StyleBoxTexture>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL);
+ tile_set = Ref<TileSet>(NULL);
}
edit_draw->update();
}
@@ -668,6 +688,8 @@ void TextureRegionEditor::_edit_region() {
texture = obj_styleBox->get_texture();
else if (atlas_tex.is_valid())
texture = atlas_tex->get_atlas();
+ else if (tile_set.is_valid() && selected_tile != -1)
+ texture = tile_set->tile_get_texture(selected_tile);
if (texture.is_null()) {
return;
@@ -735,6 +757,8 @@ void TextureRegionEditor::_edit_region() {
rect = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid())
rect = atlas_tex->get_region();
+ else if (tile_set.is_valid() && selected_tile != -1)
+ rect = tile_set->tile_get_region(selected_tile);
edit_draw->update();
}
@@ -753,6 +777,7 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
node_ninepatch = NULL;
obj_styleBox = Ref<StyleBoxTexture>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL);
+ tile_set = Ref<TileSet>(NULL);
editor = p_editor;
undo_redo = editor->get_undo_redo();
@@ -903,11 +928,11 @@ bool TextureRegionEditorPlugin::handles(Object *p_object) const {
void TextureRegionEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- region_button->show();
- if (region_button->is_pressed())
+ texture_region_button->show();
+ if (texture_region_button->is_pressed())
region_editor->show();
} else {
- region_button->hide();
+ texture_region_button->hide();
region_editor->edit(NULL);
region_editor->hide();
}
@@ -961,10 +986,10 @@ TextureRegionEditorPlugin::TextureRegionEditorPlugin(EditorNode *p_node) {
editor = 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"));
+ texture_region_button = p_node->add_bottom_panel_item(TTR("Texture Region"), region_editor);
+ texture_region_button->set_tooltip(TTR("Texture Region Editor"));
region_editor->set_custom_minimum_size(Size2(0, 200));
region_editor->hide();
- region_button->hide();
+ texture_region_button->hide();
}
diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h
index cf9396bd5b..1244953a3f 100644
--- a/editor/plugins/texture_region_editor_plugin.h
+++ b/editor/plugins/texture_region_editor_plugin.h
@@ -38,6 +38,7 @@
#include "scene/gui/nine_patch_rect.h"
#include "scene/resources/style_box.h"
#include "scene/resources/texture.h"
+#include "scene/resources/tile_set.h"
/**
@author Mariano Suligoy
@@ -55,6 +56,8 @@ class TextureRegionEditor : public Control {
};
friend class TextureRegionEditorPlugin;
+ friend class TileSetEditor;
+ friend class TileSetEditorPlugin;
MenuButton *snap_mode_button;
TextureRect *icon_zoom;
ToolButton *zoom_in;
@@ -88,12 +91,14 @@ class TextureRegionEditor : public Control {
Sprite *node_sprite;
Ref<StyleBoxTexture> obj_styleBox;
Ref<AtlasTexture> atlas_tex;
+ Ref<TileSet> tile_set;
Rect2 rect;
Rect2 rect_prev;
float prev_margin;
int edited_margin;
List<Rect2> autoslice_cache;
+ int selected_tile;
bool drag;
bool creating;
@@ -134,7 +139,7 @@ public:
class TextureRegionEditorPlugin : public EditorPlugin {
GDCLASS(TextureRegionEditorPlugin, EditorPlugin);
- Button *region_button;
+ Button *texture_region_button;
TextureRegionEditor *region_editor;
EditorNode *editor;
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index a102d99d1c..c97e949403 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -303,7 +303,7 @@ void TileMapEditor::_update_palette() {
if (tex.is_valid()) {
Rect2 region = tileset->tile_get_region(entries[i].id);
- if (tileset->tile_get_is_autotile(entries[i].id)) {
+ if (tileset->tile_get_tile_mode(entries[i].id) == TileSet::AUTO_TILE) {
int spacing = tileset->autotile_get_spacing(entries[i].id);
region.size = tileset->autotile_get_size(entries[i].id);
region.position += (region.size + Vector2(spacing, spacing)) * tileset->autotile_get_icon_coordinate(entries[i].id);
@@ -506,7 +506,7 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h
Vector2 tile_ofs = node->get_tileset()->tile_get_texture_offset(p_cell);
Rect2 r = node->get_tileset()->tile_get_region(p_cell);
- if (node->get_tileset()->tile_get_is_autotile(p_cell)) {
+ if (node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::AUTO_TILE) {
int spacing = node->get_tileset()->autotile_get_spacing(p_cell);
r.size = node->get_tileset()->autotile_get_size(p_cell);
r.position += (r.size + Vector2(spacing, spacing)) * node->get_tileset()->autotile_get_icon_coordinate(p_cell);
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 2ff8536b4c..71c0d8a782 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -37,6 +37,9 @@
void TileSetEditor::edit(const Ref<TileSet> &p_tileset) {
tileset = p_tileset;
+ tileset->add_change_receptor(this);
+
+ update_tile_list();
}
void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
@@ -188,6 +191,7 @@ void TileSetEditor::_name_dialog_confirm(const String &name) {
if (tileset->has_tile(id)) {
tileset->remove_tile(id);
+ update_tile_list();
} else {
err_dialog->set_text(TTR("Could not find tile:") + " " + name);
err_dialog->popup_centered(Size2(300, 60));
@@ -202,8 +206,9 @@ void TileSetEditor::_menu_cbk(int p_option) {
switch (p_option) {
case MENU_OPTION_ADD_ITEM: {
-
tileset->create_tile(tileset->get_last_unused_tile_id());
+ tileset->tile_set_name(tileset->get_last_unused_tile_id() - 1, itos(tileset->get_last_unused_tile_id() - 1));
+ update_tile_list();
} break;
case MENU_OPTION_REMOVE_ITEM: {
@@ -235,106 +240,75 @@ 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("_on_tile_list_selected", &TileSetEditor::_on_tile_list_selected);
+ ClassDB::bind_method("_on_edit_mode_changed", &TileSetEditor::_on_edit_mode_changed);
+ ClassDB::bind_method("_on_workspace_draw", &TileSetEditor::_on_workspace_draw);
+ ClassDB::bind_method("_on_workspace_input", &TileSetEditor::_on_workspace_input);
+ ClassDB::bind_method("_on_tool_clicked", &TileSetEditor::_on_tool_clicked);
+ ClassDB::bind_method("_on_priority_changed", &TileSetEditor::_on_priority_changed);
+ ClassDB::bind_method("_on_grid_snap_toggled", &TileSetEditor::_on_grid_snap_toggled);
+ ClassDB::bind_method("_set_snap_step_x", &TileSetEditor::_set_snap_step_x);
+ ClassDB::bind_method("_set_snap_step_y", &TileSetEditor::_set_snap_step_y);
+ ClassDB::bind_method("_set_snap_off_x", &TileSetEditor::_set_snap_off_x);
+ ClassDB::bind_method("_set_snap_off_y", &TileSetEditor::_set_snap_off_y);
+ ClassDB::bind_method("_set_snap_sep_x", &TileSetEditor::_set_snap_sep_x);
+ ClassDB::bind_method("_set_snap_sep_y", &TileSetEditor::_set_snap_sep_y);
}
-TileSetEditor::TileSetEditor(EditorNode *p_editor) {
-
- menu = memnew(MenuButton);
- CanvasItemEditor::get_singleton()->add_control_to_menu_panel(menu);
- menu->hide();
- menu->set_text(TTR("Tile Set"));
- menu->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM);
- menu->get_popup()->add_item(TTR("Remove Item"), MENU_OPTION_REMOVE_ITEM);
- menu->get_popup()->add_separator();
- menu->get_popup()->add_item(TTR("Create from Scene"), MENU_OPTION_CREATE_FROM_SCENE);
- menu->get_popup()->add_item(TTR("Merge from Scene"), MENU_OPTION_MERGE_FROM_SCENE);
- menu->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");
-
- 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");
-
- err_dialog = memnew(AcceptDialog);
- add_child(err_dialog);
- err_dialog->set_title(TTR("Error"));
-}
-
-void TileSetEditorPlugin::edit(Object *p_node) {
-
- if (Object::cast_to<TileSet>(p_node)) {
- tileset_editor->edit(Object::cast_to<TileSet>(p_node));
- tileset_editor->show();
- autotile_editor->edit(p_node);
- } else
- tileset_editor->hide();
-}
-
-bool TileSetEditorPlugin::handles(Object *p_node) const {
-
- return p_node->is_class("TileSet");
-}
-
-void TileSetEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
- tileset_editor->show();
- tileset_editor->menu->show();
- autotile_button->show();
- autotile_editor->side_panel->show();
- if (autotile_button->is_pressed()) {
- autotile_editor->show();
- }
- } else {
- tileset_editor->hide();
- tileset_editor->menu->hide();
- autotile_editor->side_panel->hide();
- autotile_editor->hide();
- autotile_button->hide();
+void TileSetEditor::_notification(int p_what) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
+ tools[TOOL_SELECT]->set_icon(get_icon("ToolSelect", "EditorIcons"));
+ tools[BITMASK_COPY]->set_icon(get_icon("Duplicate", "EditorIcons"));
+ tools[BITMASK_PASTE]->set_icon(get_icon("Override", "EditorIcons"));
+ tools[BITMASK_CLEAR]->set_icon(get_icon("Clear", "EditorIcons"));
+ tools[SHAPE_NEW_POLYGON]->set_icon(get_icon("CollisionPolygon2D", "EditorIcons"));
+ tools[SHAPE_DELETE]->set_icon(get_icon("Remove", "EditorIcons"));
+ tools[SHAPE_KEEP_INSIDE_TILE]->set_icon(get_icon("Snap", "EditorIcons"));
+ tools[SHAPE_GRID_SNAP]->set_icon(get_icon("SnapGrid", "EditorIcons"));
+ tools[ZOOM_OUT]->set_icon(get_icon("ZoomLess", "EditorIcons"));
+ tools[ZOOM_1]->set_icon(get_icon("ZoomReset", "EditorIcons"));
+ tools[ZOOM_IN]->set_icon(get_icon("ZoomMore", "EditorIcons"));
}
}
-TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) {
-
- tileset_editor = memnew(TileSetEditor(p_node));
-
- add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, tileset_editor);
- tileset_editor->set_anchors_and_margins_preset(Control::PRESET_TOP_WIDE);
- tileset_editor->set_end(Point2(0, 22));
- tileset_editor->hide();
-
- autotile_editor = memnew(AutotileEditor(p_node));
- add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, autotile_editor->side_panel);
- autotile_editor->side_panel->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- autotile_editor->side_panel->set_custom_minimum_size(Size2(200, 0));
- autotile_editor->side_panel->hide();
- autotile_button = p_node->add_bottom_panel_item(TTR("Autotiles"), autotile_editor);
- autotile_button->hide();
+void TileSetEditor::_changed_callback(Object *p_changed, const char *p_prop) {
+ if (p_prop == StringName("region")) {
+ update_tile_list_icon();
+ preview->set_region_rect(tileset->tile_get_region(get_current_tile()));
+ } else if (p_prop == StringName("name")) {
+ update_tile_list_icon();
+ } else if (p_prop == StringName("texture") || p_prop == StringName("tile_mode")) {
+ _on_tile_list_selected(get_current_tile());
+ workspace->update();
+ preview->set_texture(tileset->tile_get_texture(get_current_tile()));
+ preview->set_region_rect(tileset->tile_get_region(get_current_tile()));
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE)
+ property_editor->show();
+ else
+ property_editor->hide();
+ texture_region_editor->_edit_region();
+ update_tile_list_icon();
+ } else if (p_prop == StringName("autotile")) {
+ workspace->update();
+ }
}
-AutotileEditor::AutotileEditor(EditorNode *p_editor) {
-
- editor = p_editor;
+void TileSetEditor::initialize_bottom_editor() {
//Side Panel
side_panel = memnew(Control);
- side_panel->set_name("Autotiles");
+ side_panel->set_name("Tile Set");
VSplitContainer *split = memnew(VSplitContainer);
side_panel->add_child(split);
split->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- autotile_list = memnew(ItemList);
- autotile_list->set_v_size_flags(SIZE_EXPAND_FILL);
- autotile_list->set_h_size_flags(SIZE_EXPAND_FILL);
- autotile_list->set_custom_minimum_size(Size2(10, 200));
- autotile_list->connect("item_selected", this, "_on_autotile_selected");
- split->add_child(autotile_list);
+ tile_list = memnew(ItemList);
+ tile_list->set_v_size_flags(SIZE_EXPAND_FILL);
+ tile_list->set_h_size_flags(SIZE_EXPAND_FILL);
+ tile_list->set_custom_minimum_size(Size2(10, 200));
+ tile_list->connect("item_selected", this, "_on_tile_list_selected");
+ split->add_child(tile_list);
property_editor = memnew(PropertyEditor);
property_editor->set_v_size_flags(SIZE_EXPAND_FILL);
@@ -342,25 +316,29 @@ AutotileEditor::AutotileEditor(EditorNode *p_editor) {
property_editor->set_custom_minimum_size(Size2(10, 70));
split->add_child(property_editor);
- helper = memnew(AutotileEditorHelper(this));
+ helper = memnew(TileSetEditorHelper(this));
property_editor->call_deferred("edit", helper);
+ helper->add_change_receptor(this);
//Editor
+ //Bottom Panel
+ bottom_panel = memnew(Control);
+ bottom_panel->set_name("Tile Set Bottom Editor");
dragging_point = -1;
creating_shape = false;
snap_step = Vector2(32, 32);
- set_custom_minimum_size(Size2(0, 150));
+ bottom_panel->set_custom_minimum_size(Size2(0, 150));
VBoxContainer *main_vb = memnew(VBoxContainer);
- add_child(main_vb);
+ bottom_panel->add_child(main_vb);
main_vb->set_anchors_and_margins_preset(Control::PRESET_WIDE);
HBoxContainer *tool_hb = memnew(HBoxContainer);
Ref<ButtonGroup> g(memnew(ButtonGroup));
- String label[EDITMODE_MAX] = { "Icon", "Bitmask", "Collision", "Occlusion", "Navigation", "Priority" };
+ String label[EDITMODE_MAX] = { "Collision", "Occlusion", "Navigation", "Bitmask", "Priority", "Icon" };
for (int i = 0; i < (int)EDITMODE_MAX; i++) {
tool_editmode[i] = memnew(Button);
@@ -372,7 +350,8 @@ AutotileEditor::AutotileEditor(EditorNode *p_editor) {
tool_editmode[i]->connect("pressed", this, "_on_edit_mode_changed", args);
tool_hb->add_child(tool_editmode[i]);
}
- tool_editmode[EDITMODE_ICON]->set_pressed(true);
+ tool_editmode[EDITMODE_COLLISION]->set_pressed(true);
+ edit_mode = EDITMODE_COLLISION;
main_vb->add_child(tool_hb);
main_vb->add_child(memnew(HSeparator));
@@ -386,15 +365,17 @@ AutotileEditor::AutotileEditor(EditorNode *p_editor) {
Ref<ButtonGroup> tg(memnew(ButtonGroup));
+ Vector<Variant> p;
tools[TOOL_SELECT] = memnew(ToolButton);
tool_containers[TOOLBAR_DUMMY]->add_child(tools[TOOL_SELECT]);
tools[TOOL_SELECT]->set_tooltip(TTR("Select sub-tile to use as icon, this will be also used on invalid autotile bindings."));
tools[TOOL_SELECT]->set_toggle_mode(true);
tools[TOOL_SELECT]->set_button_group(tg);
tools[TOOL_SELECT]->set_pressed(true);
+ p.push_back((int)TOOL_SELECT);
+ tools[TOOL_SELECT]->connect("pressed", this, "_on_tool_clicked", p);
tool_containers[TOOLBAR_DUMMY]->show();
- Vector<Variant> p;
tools[BITMASK_COPY] = memnew(ToolButton);
p.push_back((int)BITMASK_COPY);
tools[BITMASK_COPY]->connect("pressed", this, "_on_tool_clicked", p);
@@ -420,7 +401,7 @@ AutotileEditor::AutotileEditor(EditorNode *p_editor) {
p.push_back((int)SHAPE_DELETE);
tools[SHAPE_DELETE]->connect("pressed", this, "_on_tool_clicked", p);
tool_containers[TOOLBAR_SHAPE]->add_child(tools[SHAPE_DELETE]);
- tool_containers[TOOLBAR_SHAPE]->add_child(memnew(VSeparator));
+ tool_containers[TOOLBAR_SHAPE]->add_change_receptor(memnew(VSeparator));
tools[SHAPE_KEEP_INSIDE_TILE] = memnew(ToolButton);
tools[SHAPE_KEEP_INSIDE_TILE]->set_toggle_mode(true);
tools[SHAPE_KEEP_INSIDE_TILE]->set_pressed(true);
@@ -507,6 +488,8 @@ AutotileEditor::AutotileEditor(EditorNode *p_editor) {
spin_priority->hide();
toolbar->add_child(spin_priority);
+ tool_containers[TOOLBAR_SHAPE]->show();
+
Control *separator = memnew(Control);
separator->set_h_size_flags(SIZE_EXPAND_FILL);
toolbar->add_child(separator);
@@ -548,70 +531,56 @@ AutotileEditor::AutotileEditor(EditorNode *p_editor) {
preview->set_region(true);
}
-AutotileEditor::~AutotileEditor() {
- memdelete(helper);
-}
+TileSetEditor::TileSetEditor(EditorNode *p_editor) {
-void AutotileEditor::_bind_methods() {
-
- ClassDB::bind_method("_on_autotile_selected", &AutotileEditor::_on_autotile_selected);
- ClassDB::bind_method("_on_edit_mode_changed", &AutotileEditor::_on_edit_mode_changed);
- ClassDB::bind_method("_on_workspace_draw", &AutotileEditor::_on_workspace_draw);
- ClassDB::bind_method("_on_workspace_input", &AutotileEditor::_on_workspace_input);
- ClassDB::bind_method("_on_tool_clicked", &AutotileEditor::_on_tool_clicked);
- ClassDB::bind_method("_on_priority_changed", &AutotileEditor::_on_priority_changed);
- ClassDB::bind_method("_on_grid_snap_toggled", &AutotileEditor::_on_grid_snap_toggled);
- ClassDB::bind_method("_set_snap_step_x", &AutotileEditor::_set_snap_step_x);
- ClassDB::bind_method("_set_snap_step_y", &AutotileEditor::_set_snap_step_y);
- ClassDB::bind_method("_set_snap_off_x", &AutotileEditor::_set_snap_off_x);
- ClassDB::bind_method("_set_snap_off_y", &AutotileEditor::_set_snap_off_y);
- ClassDB::bind_method("_set_snap_sep_x", &AutotileEditor::_set_snap_sep_x);
- ClassDB::bind_method("_set_snap_sep_y", &AutotileEditor::_set_snap_sep_y);
-}
+ menu = memnew(MenuButton);
+ CanvasItemEditor::get_singleton()->add_control_to_menu_panel(menu);
+ menu->hide();
+ menu->set_text(TTR("Tile Set"));
+ menu->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM);
+ menu->get_popup()->add_item(TTR("Remove Item"), MENU_OPTION_REMOVE_ITEM);
+ menu->get_popup()->add_separator();
+ menu->get_popup()->add_item(TTR("Create from Scene"), MENU_OPTION_CREATE_FROM_SCENE);
+ menu->get_popup()->add_item(TTR("Merge from Scene"), MENU_OPTION_MERGE_FROM_SCENE);
+ menu->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");
-void AutotileEditor::_notification(int p_what) {
+ 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");
- if (p_what == NOTIFICATION_ENTER_TREE) {
- tools[TOOL_SELECT]->set_icon(get_icon("ToolSelect", "EditorIcons"));
- tools[BITMASK_COPY]->set_icon(get_icon("Duplicate", "EditorIcons"));
- tools[BITMASK_PASTE]->set_icon(get_icon("Override", "EditorIcons"));
- tools[BITMASK_CLEAR]->set_icon(get_icon("Clear", "EditorIcons"));
- tools[SHAPE_NEW_POLYGON]->set_icon(get_icon("CollisionPolygon2D", "EditorIcons"));
- tools[SHAPE_DELETE]->set_icon(get_icon("Remove", "EditorIcons"));
- tools[SHAPE_KEEP_INSIDE_TILE]->set_icon(get_icon("Snap", "EditorIcons"));
- tools[SHAPE_GRID_SNAP]->set_icon(get_icon("SnapGrid", "EditorIcons"));
- tools[ZOOM_OUT]->set_icon(get_icon("ZoomLess", "EditorIcons"));
- tools[ZOOM_1]->set_icon(get_icon("ZoomReset", "EditorIcons"));
- tools[ZOOM_IN]->set_icon(get_icon("ZoomMore", "EditorIcons"));
- }
-}
+ err_dialog = memnew(AcceptDialog);
+ add_child(err_dialog);
+ err_dialog->set_title(TTR("Error"));
-void AutotileEditor::_changed_callback(Object *p_changed, const char *p_prop) {
- if (p_prop == StringName("texture") || p_prop == StringName("is_autotile")) {
- edit(tile_set.ptr());
- autotile_list->update();
- workspace->update();
- }
+ initialize_bottom_editor();
}
-void AutotileEditor::_on_autotile_selected(int p_index) {
-
+void TileSetEditor::_on_tile_list_selected(int p_index) {
if (get_current_tile() >= 0) {
current_item_index = p_index;
- preview->set_texture(tile_set->tile_get_texture(get_current_tile()));
- preview->set_region_rect(tile_set->tile_get_region(get_current_tile()));
- workspace->set_custom_minimum_size(tile_set->tile_get_region(get_current_tile()).size);
+ preview->set_texture(tileset->tile_get_texture(get_current_tile()));
+ preview->set_region_rect(tileset->tile_get_region(get_current_tile()));
+ workspace->set_custom_minimum_size(tileset->tile_get_region(get_current_tile()).size);
+ update_workspace_tile_mode();
} else {
current_item_index = -1;
preview->set_texture(NULL);
workspace->set_custom_minimum_size(Size2i());
}
+ texture_region_editor->selected_tile = get_current_tile();
+ texture_region_editor->_edit_region();
+ helper->selected_tile = get_current_tile();
helper->_change_notify("");
workspace->update();
}
-void AutotileEditor::_on_edit_mode_changed(int p_edit_mode) {
-
+void TileSetEditor::_on_edit_mode_changed(int p_edit_mode) {
edit_mode = (EditMode)p_edit_mode;
switch (edit_mode) {
case EDITMODE_BITMASK: {
@@ -631,7 +600,6 @@ void AutotileEditor::_on_edit_mode_changed(int p_edit_mode) {
tools[TOOL_SELECT]->set_tooltip(TTR("Select current edited sub-tile."));
spin_priority->hide();
- current_shape = PoolVector2Array();
select_coord(edited_shape_coord);
} break;
default: {
@@ -650,17 +618,17 @@ void AutotileEditor::_on_edit_mode_changed(int p_edit_mode) {
workspace->update();
}
-void AutotileEditor::_on_workspace_draw() {
+void TileSetEditor::_on_workspace_draw() {
- if (get_current_tile() >= 0 && !tile_set.is_null()) {
- int spacing = tile_set->autotile_get_spacing(get_current_tile());
- Vector2 size = tile_set->autotile_get_size(get_current_tile());
- Rect2i region = tile_set->tile_get_region(get_current_tile());
+ if (get_current_tile() >= 0 && !tileset.is_null()) {
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->autotile_get_size(get_current_tile());
+ Rect2i region = tileset->tile_get_region(get_current_tile());
Color c(0.347214, 0.722656, 0.617063);
switch (edit_mode) {
case EDITMODE_ICON: {
- Vector2 coord = tile_set->autotile_get_icon_coordinate(get_current_tile());
+ Vector2 coord = tileset->autotile_get_icon_coordinate(get_current_tile());
draw_highlight_tile(coord);
} break;
case EDITMODE_BITMASK: {
@@ -669,8 +637,8 @@ void AutotileEditor::_on_workspace_draw() {
for (float y = 0; y < region.size.y / (spacing + size.y); y++) {
Vector2 coord(x, y);
Point2 anchor(coord.x * (spacing + size.x), coord.y * (spacing + size.y));
- uint16_t mask = tile_set->autotile_get_bitmask(get_current_tile(), coord);
- if (tile_set->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_2X2) {
+ uint16_t mask = tileset->autotile_get_bitmask(get_current_tile(), coord);
+ if (tileset->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_2X2) {
if (mask & TileSet::BIND_TOPLEFT) {
workspace->draw_rect(Rect2(anchor, size / 2), c);
}
@@ -683,7 +651,7 @@ void AutotileEditor::_on_workspace_draw() {
if (mask & TileSet::BIND_BOTTOMRIGHT) {
workspace->draw_rect(Rect2(anchor + size / 2, size / 2), c);
}
- } else if (tile_set->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_3X3) {
+ } else if (tileset->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_3X3) {
if (mask & TileSet::BIND_TOPLEFT) {
workspace->draw_rect(Rect2(anchor, size / 3), c);
}
@@ -718,19 +686,21 @@ void AutotileEditor::_on_workspace_draw() {
case EDITMODE_COLLISION:
case EDITMODE_OCCLUSION:
case EDITMODE_NAVIGATION: {
- Vector2 coord = edited_shape_coord;
- draw_highlight_tile(coord);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
+ Vector2 coord = edited_shape_coord;
+ draw_highlight_tile(coord);
+ }
draw_polygon_shapes();
draw_grid_snap();
} break;
case EDITMODE_PRIORITY: {
- spin_priority->set_value(tile_set->autotile_get_subtile_priority(get_current_tile(), edited_shape_coord));
- uint16_t mask = tile_set->autotile_get_bitmask(get_current_tile(), edited_shape_coord);
+ spin_priority->set_value(tileset->autotile_get_subtile_priority(get_current_tile(), edited_shape_coord));
+ uint16_t mask = tileset->autotile_get_bitmask(get_current_tile(), edited_shape_coord);
Vector<Vector2> queue_others;
int total = 0;
- for (Map<Vector2, uint16_t>::Element *E = tile_set->autotile_get_bitmask_map(get_current_tile()).front(); E; E = E->next()) {
+ for (Map<Vector2, uint16_t>::Element *E = tileset->autotile_get_bitmask_map(get_current_tile()).front(); E; E = E->next()) {
if (E->value() == mask) {
- total += tile_set->autotile_get_subtile_priority(get_current_tile(), E->key());
+ total += tileset->autotile_get_subtile_priority(get_current_tile(), E->key());
if (E->key() != edited_shape_coord) {
queue_others.push_back(E->key());
}
@@ -741,53 +711,55 @@ void AutotileEditor::_on_workspace_draw() {
} break;
}
- float j = -size.x; //make sure to draw at 0
- while (j < region.size.x) {
- j += size.x;
- if (spacing <= 0) {
- workspace->draw_line(Point2(j, 0), Point2(j, region.size.y), c);
- } else {
- workspace->draw_rect(Rect2(Point2(j, 0), Size2(spacing, region.size.y)), c);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
+ float j = -size.x; //make sure to draw at 0
+ while (j < region.size.x) {
+ j += size.x;
+ if (spacing <= 0) {
+ workspace->draw_line(Point2(j, 0), Point2(j, region.size.y), c);
+ } else {
+ workspace->draw_rect(Rect2(Point2(j, 0), Size2(spacing, region.size.y)), c);
+ }
+ j += spacing;
}
- j += spacing;
- }
- j = -size.y; //make sure to draw at 0
- while (j < region.size.y) {
- j += size.y;
- if (spacing <= 0) {
- workspace->draw_line(Point2(0, j), Point2(region.size.x, j), c);
- } else {
- workspace->draw_rect(Rect2(Point2(0, j), Size2(region.size.x, spacing)), c);
+ j = -size.y; //make sure to draw at 0
+ while (j < region.size.y) {
+ j += size.y;
+ if (spacing <= 0) {
+ workspace->draw_line(Point2(0, j), Point2(region.size.x, j), c);
+ } else {
+ workspace->draw_rect(Rect2(Point2(0, j), Size2(region.size.x, spacing)), c);
+ }
+ j += spacing;
}
- j += spacing;
}
}
}
#define MIN_DISTANCE_SQUARED 10
-void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
+void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
- if (get_current_tile() >= 0 && !tile_set.is_null()) {
+ if (get_current_tile() >= 0 && !tileset.is_null()) {
Ref<InputEventMouseButton> mb = p_ie;
Ref<InputEventMouseMotion> mm = p_ie;
static bool dragging;
static bool erasing;
- int spacing = tile_set->autotile_get_spacing(get_current_tile());
- Vector2 size = tile_set->autotile_get_size(get_current_tile());
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->autotile_get_size(get_current_tile());
switch (edit_mode) {
case EDITMODE_ICON: {
if (mb.is_valid()) {
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
Vector2 coord((int)(mb->get_position().x / (spacing + size.x)), (int)(mb->get_position().y / (spacing + size.y)));
- tile_set->autotile_set_icon_coordinate(get_current_tile(), coord);
- Rect2 region = tile_set->tile_get_region(get_current_tile());
+ tileset->autotile_set_icon_coordinate(get_current_tile(), coord);
+ Rect2 region = tileset->tile_get_region(get_current_tile());
region.size = size;
coord.x *= (spacing + size.x);
coord.y *= (spacing + size.y);
region.position += coord;
- autotile_list->set_item_icon_region(current_item_index, region);
+ tile_list->set_item_icon_region(current_item_index, region);
workspace->update();
}
}
@@ -805,7 +777,7 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
Vector2 pos(coord.x * (spacing + size.x), coord.y * (spacing + size.y));
pos = mb->get_position() - pos;
uint16_t bit;
- if (tile_set->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_2X2) {
+ if (tileset->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_2X2) {
if (pos.x < size.x / 2) {
if (pos.y < size.y / 2) {
bit = TileSet::BIND_TOPLEFT;
@@ -819,7 +791,7 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
bit = TileSet::BIND_BOTTOMRIGHT;
}
}
- } else if (tile_set->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_3X3) {
+ } else if (tileset->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_3X3) {
if (pos.x < size.x / 3) {
if (pos.y < size.y / 3) {
bit = TileSet::BIND_TOPLEFT;
@@ -846,13 +818,13 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
}
}
- uint16_t mask = tile_set->autotile_get_bitmask(get_current_tile(), coord);
+ uint16_t mask = tileset->autotile_get_bitmask(get_current_tile(), coord);
if (erasing) {
mask &= ~bit;
} else {
mask |= bit;
}
- tile_set->autotile_set_bitmask(get_current_tile(), coord, mask);
+ tileset->autotile_set_bitmask(get_current_tile(), coord, mask);
workspace->update();
}
} else {
@@ -868,7 +840,7 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
Vector2 pos(coord.x * (spacing + size.x), coord.y * (spacing + size.y));
pos = mm->get_position() - pos;
uint16_t bit;
- if (tile_set->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_2X2) {
+ if (tileset->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_2X2) {
if (pos.x < size.x / 2) {
if (pos.y < size.y / 2) {
bit = TileSet::BIND_TOPLEFT;
@@ -882,7 +854,7 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
bit = TileSet::BIND_BOTTOMRIGHT;
}
}
- } else if (tile_set->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_3X3) {
+ } else if (tileset->autotile_get_bitmask_mode(get_current_tile()) == TileSet::BITMASK_3X3) {
if (pos.x < size.x / 3) {
if (pos.y < size.y / 3) {
bit = TileSet::BIND_TOPLEFT;
@@ -909,13 +881,13 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
}
}
- uint16_t mask = tile_set->autotile_get_bitmask(get_current_tile(), coord);
+ uint16_t mask = tileset->autotile_get_bitmask(get_current_tile(), coord);
if (erasing) {
mask &= ~bit;
} else {
mask |= bit;
}
- tile_set->autotile_set_bitmask(get_current_tile(), coord, mask);
+ tileset->autotile_set_bitmask(get_current_tile(), coord, mask);
workspace->update();
}
}
@@ -924,9 +896,12 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
case EDITMODE_OCCLUSION:
case EDITMODE_NAVIGATION:
case EDITMODE_PRIORITY: {
- Vector2 shape_anchor = edited_shape_coord;
- shape_anchor.x *= (size.x + spacing);
- shape_anchor.y *= (size.y + spacing);
+ Vector2 shape_anchor = Vector2(0, 0);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
+ shape_anchor = edited_shape_coord;
+ shape_anchor.x *= (size.x + spacing);
+ shape_anchor.y *= (size.y + spacing);
+ }
if (tools[TOOL_SELECT]->is_pressed()) {
if (mb.is_valid()) {
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
@@ -939,23 +914,25 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
}
}
- Vector2 coord((int)(mb->get_position().x / (spacing + size.x)), (int)(mb->get_position().y / (spacing + size.y)));
- if (edited_shape_coord != coord) {
- edited_shape_coord = coord;
- edited_occlusion_shape = tile_set->autotile_get_light_occluder(get_current_tile(), edited_shape_coord);
- edited_navigation_shape = tile_set->autotile_get_navigation_polygon(get_current_tile(), edited_shape_coord);
- Vector<TileSet::ShapeData> sd = tile_set->tile_get_shapes(get_current_tile());
- bool found_collision_shape = false;
- for (int i = 0; i < sd.size(); i++) {
- if (sd[i].autotile_coord == coord) {
- edited_collision_shape = sd[i].shape;
- found_collision_shape = true;
- break;
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
+ Vector2 coord((int)(mb->get_position().x / (spacing + size.x)), (int)(mb->get_position().y / (spacing + size.y)));
+ if (edited_shape_coord != coord) {
+ edited_shape_coord = coord;
+ edited_occlusion_shape = tileset->autotile_get_light_occluder(get_current_tile(), edited_shape_coord);
+ edited_navigation_shape = tileset->autotile_get_navigation_polygon(get_current_tile(), edited_shape_coord);
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(get_current_tile());
+ bool found_collision_shape = false;
+ for (int i = 0; i < sd.size(); i++) {
+ if (sd[i].autotile_coord == coord) {
+ edited_collision_shape = sd[i].shape;
+ found_collision_shape = true;
+ break;
+ }
}
+ if (!found_collision_shape)
+ edited_collision_shape = Ref<ConvexPolygonShape2D>(NULL);
+ select_coord(edited_shape_coord);
}
- if (!found_collision_shape)
- edited_collision_shape = Ref<ConvexPolygonShape2D>(NULL);
- select_coord(edited_shape_coord);
}
workspace->update();
} else if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
@@ -1023,8 +1000,6 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
}
} else if (tools[SHAPE_NEW_POLYGON]->is_pressed()) {
- if (!tools[TOOL_SELECT]->is_disabled())
- tools[TOOL_SELECT]->set_disabled(true);
if (mb.is_valid()) {
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
@@ -1046,14 +1021,14 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
int t_id = get_current_tile();
if (t_id >= 0) {
if (edit_mode == EDITMODE_COLLISION) {
- Vector<TileSet::ShapeData> sd = tile_set->tile_get_shapes(t_id);
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(t_id);
for (int i = 0; i < sd.size(); i++) {
- if (sd[i].autotile_coord == edited_shape_coord) {
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE || sd[i].autotile_coord == edited_shape_coord) {
Ref<ConvexPolygonShape2D> shape = sd[i].shape;
if (!shape.is_null()) {
sd.remove(i);
- tile_set->tile_set_shapes(get_current_tile(), sd);
+ tileset->tile_set_shapes(get_current_tile(), sd);
edited_collision_shape = Ref<Shape2D>();
workspace->update();
}
@@ -1061,25 +1036,30 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
}
} else if (edit_mode == EDITMODE_OCCLUSION) {
- Map<Vector2, Ref<OccluderPolygon2D> > map = tile_set->autotile_get_light_oclusion_map(t_id);
- for (Map<Vector2, Ref<OccluderPolygon2D> >::Element *E = map.front(); E; E = E->next()) {
- if (E->key() == edited_shape_coord) {
- tile_set->autotile_set_light_occluder(get_current_tile(), Ref<OccluderPolygon2D>(), edited_shape_coord);
- break;
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
+ Map<Vector2, Ref<OccluderPolygon2D> > map = tileset->autotile_get_light_oclusion_map(t_id);
+ for (Map<Vector2, Ref<OccluderPolygon2D> >::Element *E = map.front(); E; E = E->next()) {
+ if (E->key() == edited_shape_coord) {
+ tileset->autotile_set_light_occluder(get_current_tile(), Ref<OccluderPolygon2D>(), edited_shape_coord);
+ break;
+ }
}
- }
+ } else
+ tileset->tile_set_light_occluder(t_id, Ref<OccluderPolygon2D>());
edited_occlusion_shape = Ref<OccluderPolygon2D>();
workspace->update();
} else if (edit_mode == EDITMODE_NAVIGATION) {
- Map<Vector2, Ref<NavigationPolygon> > map = tile_set->autotile_get_navigation_map(t_id);
- for (Map<Vector2, Ref<NavigationPolygon> >::Element *E = map.front(); E; E = E->next()) {
- if (E->key() == edited_shape_coord) {
- tile_set->autotile_set_navigation_polygon(t_id, Ref<NavigationPolygon>(), edited_shape_coord);
- break;
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
+ Map<Vector2, Ref<NavigationPolygon> > map = tileset->autotile_get_navigation_map(t_id);
+ for (Map<Vector2, Ref<NavigationPolygon> >::Element *E = map.front(); E; E = E->next()) {
+ if (E->key() == edited_shape_coord) {
+ tileset->autotile_set_navigation_polygon(t_id, Ref<NavigationPolygon>(), edited_shape_coord);
+ break;
+ }
}
- }
-
+ } else
+ tileset->tile_set_navigation_polygon(t_id, Ref<NavigationPolygon>());
edited_navigation_shape = Ref<NavigationPolygon>();
workspace->update();
}
@@ -1092,8 +1072,6 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
} else if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT && current_shape.size() > 2) {
if (creating_shape) {
close_shape(shape_anchor);
- if (tools[TOOL_SELECT]->is_disabled())
- tools[TOOL_SELECT]->set_disabled(false);
}
}
} else if (mm.is_valid()) {
@@ -1117,17 +1095,17 @@ void AutotileEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
}
}
-void AutotileEditor::_on_tool_clicked(int p_tool) {
+void TileSetEditor::_on_tool_clicked(int p_tool) {
if (p_tool == BITMASK_COPY) {
- bitmask_map_copy = tile_set->autotile_get_bitmask_map(get_current_tile());
+ bitmask_map_copy = tileset->autotile_get_bitmask_map(get_current_tile());
} else if (p_tool == BITMASK_PASTE) {
- tile_set->autotile_clear_bitmask_map(get_current_tile());
+ tileset->autotile_clear_bitmask_map(get_current_tile());
for (Map<Vector2, uint16_t>::Element *E = bitmask_map_copy.front(); E; E = E->next()) {
- tile_set->autotile_set_bitmask(get_current_tile(), E->key(), E->value());
+ tileset->autotile_set_bitmask(get_current_tile(), E->key(), E->value());
}
workspace->update();
} else if (p_tool == BITMASK_CLEAR) {
- tile_set->autotile_clear_bitmask_map(get_current_tile());
+ tileset->autotile_clear_bitmask_map(get_current_tile());
workspace->update();
} else if (p_tool == SHAPE_DELETE) {
if (creating_shape) {
@@ -1138,7 +1116,7 @@ void AutotileEditor::_on_tool_clicked(int p_tool) {
switch (edit_mode) {
case EDITMODE_COLLISION: {
if (!edited_collision_shape.is_null()) {
- Vector<TileSet::ShapeData> sd = tile_set->tile_get_shapes(get_current_tile());
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(get_current_tile());
int index;
for (int i = 0; i < sd.size(); i++) {
if (sd[i].shape == edited_collision_shape) {
@@ -1148,7 +1126,7 @@ void AutotileEditor::_on_tool_clicked(int p_tool) {
}
if (index >= 0) {
sd.remove(index);
- tile_set->tile_set_shapes(get_current_tile(), sd);
+ tileset->tile_set_shapes(get_current_tile(), sd);
edited_collision_shape = Ref<Shape2D>();
current_shape.resize(0);
workspace->update();
@@ -1157,7 +1135,7 @@ void AutotileEditor::_on_tool_clicked(int p_tool) {
} break;
case EDITMODE_NAVIGATION: {
if (!edited_navigation_shape.is_null()) {
- tile_set->autotile_set_navigation_polygon(get_current_tile(), Ref<NavigationPolygon>(), edited_shape_coord);
+ tileset->autotile_set_navigation_polygon(get_current_tile(), Ref<NavigationPolygon>(), edited_shape_coord);
edited_navigation_shape = Ref<NavigationPolygon>();
current_shape.resize(0);
workspace->update();
@@ -1165,7 +1143,7 @@ void AutotileEditor::_on_tool_clicked(int p_tool) {
} break;
case EDITMODE_OCCLUSION: {
if (!edited_occlusion_shape.is_null()) {
- tile_set->autotile_set_light_occluder(get_current_tile(), Ref<OccluderPolygon2D>(), edited_shape_coord);
+ tileset->autotile_set_light_occluder(get_current_tile(), Ref<OccluderPolygon2D>(), edited_shape_coord);
edited_occlusion_shape = Ref<OccluderPolygon2D>();
current_shape.resize(0);
workspace->update();
@@ -1188,15 +1166,22 @@ void AutotileEditor::_on_tool_clicked(int p_tool) {
scale *= 2;
workspace->set_scale(Vector2(scale, scale));
workspace_container->set_custom_minimum_size(preview->get_region_rect().size * scale);
+ } else if (p_tool == TOOL_SELECT) {
+ if (creating_shape) {
+ //Cancel Creation
+ creating_shape = false;
+ current_shape.resize(0);
+ workspace->update();
+ }
}
}
-void AutotileEditor::_on_priority_changed(float val) {
- tile_set->autotile_set_subtile_priority(get_current_tile(), edited_shape_coord, (int)val);
+void TileSetEditor::_on_priority_changed(float val) {
+ tileset->autotile_set_subtile_priority(get_current_tile(), edited_shape_coord, (int)val);
workspace->update();
}
-void AutotileEditor::_on_grid_snap_toggled(bool p_val) {
+void TileSetEditor::_on_grid_snap_toggled(bool p_val) {
if (p_val)
hb_grid->show();
else
@@ -1204,40 +1189,40 @@ void AutotileEditor::_on_grid_snap_toggled(bool p_val) {
workspace->update();
}
-void AutotileEditor::_set_snap_step_x(float p_val) {
+void TileSetEditor::_set_snap_step_x(float p_val) {
snap_step.x = p_val;
workspace->update();
}
-void AutotileEditor::_set_snap_step_y(float p_val) {
+void TileSetEditor::_set_snap_step_y(float p_val) {
snap_step.y = p_val;
workspace->update();
}
-void AutotileEditor::_set_snap_off_x(float p_val) {
+void TileSetEditor::_set_snap_off_x(float p_val) {
snap_offset.x = p_val;
workspace->update();
}
-void AutotileEditor::_set_snap_off_y(float p_val) {
+void TileSetEditor::_set_snap_off_y(float p_val) {
snap_offset.y = p_val;
workspace->update();
}
-void AutotileEditor::_set_snap_sep_x(float p_val) {
+void TileSetEditor::_set_snap_sep_x(float p_val) {
snap_separation.x = p_val;
workspace->update();
}
-void AutotileEditor::_set_snap_sep_y(float p_val) {
+void TileSetEditor::_set_snap_sep_y(float p_val) {
snap_separation.y = p_val;
workspace->update();
}
-void AutotileEditor::draw_highlight_tile(Vector2 coord, const Vector<Vector2> &other_highlighted) {
+void TileSetEditor::draw_highlight_tile(Vector2 coord, const Vector<Vector2> &other_highlighted) {
- Vector2 size = tile_set->autotile_get_size(get_current_tile());
- int spacing = tile_set->autotile_get_spacing(get_current_tile());
- Rect2 region = tile_set->tile_get_region(get_current_tile());
+ Vector2 size = tileset->autotile_get_size(get_current_tile());
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Rect2 region = tileset->tile_get_region(get_current_tile());
coord.x *= (size.x + spacing);
coord.y *= (size.y + spacing);
workspace->draw_rect(Rect2(0, 0, region.size.x, coord.y), Color(0.5, 0.5, 0.5, 0.5));
@@ -1255,7 +1240,7 @@ void AutotileEditor::draw_highlight_tile(Vector2 coord, const Vector<Vector2> &o
}
}
-void AutotileEditor::draw_grid_snap() {
+void TileSetEditor::draw_grid_snap() {
if (tools[SHAPE_GRID_SNAP]->is_pressed()) {
Color grid_color = Color(0.39, 0, 1, 0.2f);
Size2 s = workspace->get_size();
@@ -1296,7 +1281,7 @@ void AutotileEditor::draw_grid_snap() {
}
}
-void AutotileEditor::draw_polygon_shapes() {
+void TileSetEditor::draw_polygon_shapes() {
int t_id = get_current_tile();
if (t_id < 0)
@@ -1304,19 +1289,23 @@ void AutotileEditor::draw_polygon_shapes() {
switch (edit_mode) {
case EDITMODE_COLLISION: {
- Vector<TileSet::ShapeData> sd = tile_set->tile_get_shapes(t_id);
+ Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(t_id);
for (int i = 0; i < sd.size(); i++) {
- Vector2 coord = sd[i].autotile_coord;
- Vector2 anchor = tile_set->autotile_get_size(t_id);
- anchor.x += tile_set->autotile_get_spacing(t_id);
- anchor.y += tile_set->autotile_get_spacing(t_id);
- anchor.x *= coord.x;
- anchor.y *= coord.y;
+ Vector2 coord = Vector2(0, 0);
+ Vector2 anchor = Vector2(0, 0);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
+ coord = sd[i].autotile_coord;
+ anchor = tileset->autotile_get_size(t_id);
+ anchor.x += tileset->autotile_get_spacing(t_id);
+ anchor.y += tileset->autotile_get_spacing(t_id);
+ anchor.x *= coord.x;
+ anchor.y *= coord.y;
+ }
Ref<ConvexPolygonShape2D> shape = sd[i].shape;
if (shape.is_valid()) {
Color c_bg;
Color c_border;
- if (coord == edited_shape_coord && sd[i].shape == edited_collision_shape) {
+ if ((tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE || coord == edited_shape_coord) && sd[i].shape == edited_collision_shape) {
c_bg = Color(0, 1, 1, 0.5);
c_border = Color(0, 1, 1);
} else {
@@ -1339,7 +1328,7 @@ void AutotileEditor::draw_polygon_shapes() {
if (polygon.size() > 2) {
workspace->draw_polygon(polygon, colors);
}
- if (coord == edited_shape_coord) {
+ if (coord == edited_shape_coord || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
for (int j = 0; j < shape->get_points().size() - 1; j++) {
workspace->draw_line(shape->get_points()[j] + anchor, shape->get_points()[j + 1] + anchor, c_border, 1, true);
}
@@ -1354,47 +1343,73 @@ void AutotileEditor::draw_polygon_shapes() {
}
} break;
case EDITMODE_OCCLUSION: {
- Map<Vector2, Ref<OccluderPolygon2D> > map = tile_set->autotile_get_light_oclusion_map(t_id);
- for (Map<Vector2, Ref<OccluderPolygon2D> >::Element *E = map.front(); E; E = E->next()) {
- Vector2 coord = E->key();
- Vector2 anchor = tile_set->autotile_get_size(t_id);
- anchor.x += tile_set->autotile_get_spacing(t_id);
- anchor.y += tile_set->autotile_get_spacing(t_id);
- anchor.x *= coord.x;
- anchor.y *= coord.y;
- Ref<OccluderPolygon2D> shape = E->value();
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ Ref<OccluderPolygon2D> shape = edited_occlusion_shape;
if (shape.is_valid()) {
- Color c_bg;
- Color c_border;
- if (coord == edited_shape_coord && shape == edited_occlusion_shape) {
- c_bg = Color(0, 1, 1, 0.5);
- c_border = Color(0, 1, 1);
- } else {
- c_bg = Color(0.9, 0.7, 0.07, 0.5);
- c_border = Color(0.9, 0.7, 0.07, 1);
- }
+ Color c_bg = Color(0, 1, 1, 0.5);
+ Color c_border = Color(0, 1, 1);
+
Vector<Vector2> polygon;
Vector<Color> colors;
- if (shape == edited_occlusion_shape && current_shape.size() > 2) {
+ for (int j = 0; j < shape->get_polygon().size(); j++) {
+ polygon.push_back(shape->get_polygon()[j]);
+ colors.push_back(c_bg);
+ }
+ workspace->draw_polygon(polygon, colors);
+
+ for (int j = 0; j < shape->get_polygon().size() - 1; j++) {
+ workspace->draw_line(shape->get_polygon()[j], shape->get_polygon()[j + 1], c_border, 1, true);
+ }
+ workspace->draw_line(shape->get_polygon()[shape->get_polygon().size() - 1], shape->get_polygon()[0], c_border, 1, true);
+ if (shape == edited_occlusion_shape) {
for (int j = 0; j < current_shape.size(); j++) {
- polygon.push_back(current_shape[j]);
- colors.push_back(c_bg);
- }
- } else {
- for (int j = 0; j < shape->get_polygon().size(); j++) {
- polygon.push_back(shape->get_polygon()[j] + anchor);
- colors.push_back(c_bg);
+ workspace->draw_circle(current_shape[j], 8 / workspace->get_scale().x, Color(1, 0, 0));
}
}
- workspace->draw_polygon(polygon, colors);
- if (coord == edited_shape_coord) {
- for (int j = 0; j < shape->get_polygon().size() - 1; j++) {
- workspace->draw_line(shape->get_polygon()[j] + anchor, shape->get_polygon()[j + 1] + anchor, c_border, 1, true);
+ }
+ } else {
+ Map<Vector2, Ref<OccluderPolygon2D> > map = tileset->autotile_get_light_oclusion_map(t_id);
+ for (Map<Vector2, Ref<OccluderPolygon2D> >::Element *E = map.front(); E; E = E->next()) {
+ Vector2 coord = E->key();
+ Vector2 anchor = tileset->autotile_get_size(t_id);
+ anchor.x += tileset->autotile_get_spacing(t_id);
+ anchor.y += tileset->autotile_get_spacing(t_id);
+ anchor.x *= coord.x;
+ anchor.y *= coord.y;
+ Ref<OccluderPolygon2D> shape = E->value();
+ if (shape.is_valid()) {
+ Color c_bg;
+ Color c_border;
+ if (coord == edited_shape_coord && shape == edited_occlusion_shape) {
+ c_bg = Color(0, 1, 1, 0.5);
+ c_border = Color(0, 1, 1);
+ } else {
+ c_bg = Color(0.9, 0.7, 0.07, 0.5);
+ c_border = Color(0.9, 0.7, 0.07, 1);
}
- workspace->draw_line(shape->get_polygon()[shape->get_polygon().size() - 1] + anchor, shape->get_polygon()[0] + anchor, c_border, 1, true);
- if (shape == edited_occlusion_shape) {
+ Vector<Vector2> polygon;
+ Vector<Color> colors;
+ if (shape == edited_occlusion_shape && current_shape.size() > 2) {
for (int j = 0; j < current_shape.size(); j++) {
- workspace->draw_circle(current_shape[j], 8 / workspace->get_scale().x, Color(1, 0, 0));
+ polygon.push_back(current_shape[j]);
+ colors.push_back(c_bg);
+ }
+ } else {
+ for (int j = 0; j < shape->get_polygon().size(); j++) {
+ polygon.push_back(shape->get_polygon()[j] + anchor);
+ colors.push_back(c_bg);
+ }
+ }
+ workspace->draw_polygon(polygon, colors);
+ if (coord == edited_shape_coord) {
+ for (int j = 0; j < shape->get_polygon().size() - 1; j++) {
+ workspace->draw_line(shape->get_polygon()[j] + anchor, shape->get_polygon()[j + 1] + anchor, c_border, 1, true);
+ }
+ workspace->draw_line(shape->get_polygon()[shape->get_polygon().size() - 1] + anchor, shape->get_polygon()[0] + anchor, c_border, 1, true);
+ if (shape == edited_occlusion_shape) {
+ for (int j = 0; j < current_shape.size(); j++) {
+ workspace->draw_circle(current_shape[j], 8 / workspace->get_scale().x, Color(1, 0, 0));
+ }
}
}
}
@@ -1402,49 +1417,81 @@ void AutotileEditor::draw_polygon_shapes() {
}
} break;
case EDITMODE_NAVIGATION: {
- Map<Vector2, Ref<NavigationPolygon> > map = tile_set->autotile_get_navigation_map(t_id);
- for (Map<Vector2, Ref<NavigationPolygon> >::Element *E = map.front(); E; E = E->next()) {
- Vector2 coord = E->key();
- Vector2 anchor = tile_set->autotile_get_size(t_id);
- anchor.x += tile_set->autotile_get_spacing(t_id);
- anchor.y += tile_set->autotile_get_spacing(t_id);
- anchor.x *= coord.x;
- anchor.y *= coord.y;
- Ref<NavigationPolygon> shape = E->value();
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ Ref<NavigationPolygon> shape = edited_navigation_shape;
+
if (shape.is_valid()) {
- Color c_bg;
- Color c_border;
- if (coord == edited_shape_coord && shape == edited_navigation_shape) {
- c_bg = Color(0, 1, 1, 0.5);
- c_border = Color(0, 1, 1);
- } else {
- c_bg = Color(0.9, 0.7, 0.07, 0.5);
- c_border = Color(0.9, 0.7, 0.07, 1);
- }
+ Color c_bg = Color(0, 1, 1, 0.5);
+ Color c_border = Color(0, 1, 1);
+
Vector<Vector2> polygon;
Vector<Color> colors;
- if (shape == edited_navigation_shape && current_shape.size() > 2) {
- for (int j = 0; j < current_shape.size(); j++) {
- polygon.push_back(current_shape[j]);
- colors.push_back(c_bg);
- }
- } else if (shape->get_polygon_count() > 0) {
+
+ PoolVector<Vector2> vertices = shape->get_vertices();
+ for (int j = 0; j < shape->get_polygon(0).size(); j++) {
+ polygon.push_back(vertices[shape->get_polygon(0)[j]]);
+ colors.push_back(c_bg);
+ }
+ workspace->draw_polygon(polygon, colors);
+
+ if (shape->get_polygon_count() > 0) {
PoolVector<Vector2> vertices = shape->get_vertices();
- for (int j = 0; j < shape->get_polygon(0).size(); j++) {
- polygon.push_back(vertices[shape->get_polygon(0)[j]] + anchor);
- colors.push_back(c_bg);
+ for (int j = 0; j < shape->get_polygon(0).size() - 1; j++) {
+ workspace->draw_line(vertices[shape->get_polygon(0)[j]], vertices[shape->get_polygon(0)[j + 1]], c_border, 1, true);
+ }
+ if (shape == edited_navigation_shape) {
+ for (int j = 0; j < current_shape.size(); j++) {
+ workspace->draw_circle(current_shape[j], 8 / workspace->get_scale().x, Color(1, 0, 0));
+ }
}
}
- workspace->draw_polygon(polygon, colors);
- if (coord == edited_shape_coord) {
- if (shape->get_polygon_count() > 0) {
+ }
+
+ } else {
+ Map<Vector2, Ref<NavigationPolygon> > map = tileset->autotile_get_navigation_map(t_id);
+ for (Map<Vector2, Ref<NavigationPolygon> >::Element *E = map.front(); E; E = E->next()) {
+ Vector2 coord = E->key();
+ Vector2 anchor = tileset->autotile_get_size(t_id);
+ anchor.x += tileset->autotile_get_spacing(t_id);
+ anchor.y += tileset->autotile_get_spacing(t_id);
+ anchor.x *= coord.x;
+ anchor.y *= coord.y;
+ Ref<NavigationPolygon> shape = E->value();
+ if (shape.is_valid()) {
+ Color c_bg;
+ Color c_border;
+ if (coord == edited_shape_coord && shape == edited_navigation_shape) {
+ c_bg = Color(0, 1, 1, 0.5);
+ c_border = Color(0, 1, 1);
+ } else {
+ c_bg = Color(0.9, 0.7, 0.07, 0.5);
+ c_border = Color(0.9, 0.7, 0.07, 1);
+ }
+ Vector<Vector2> polygon;
+ Vector<Color> colors;
+ if (shape == edited_navigation_shape && current_shape.size() > 2) {
+ for (int j = 0; j < current_shape.size(); j++) {
+ polygon.push_back(current_shape[j]);
+ colors.push_back(c_bg);
+ }
+ } else if (shape->get_polygon_count() > 0) {
PoolVector<Vector2> vertices = shape->get_vertices();
- for (int j = 0; j < shape->get_polygon(0).size() - 1; j++) {
- workspace->draw_line(vertices[shape->get_polygon(0)[j]] + anchor, vertices[shape->get_polygon(0)[j + 1]] + anchor, c_border, 1, true);
+ for (int j = 0; j < shape->get_polygon(0).size(); j++) {
+ polygon.push_back(vertices[shape->get_polygon(0)[j]] + anchor);
+ colors.push_back(c_bg);
}
- if (shape == edited_navigation_shape) {
- for (int j = 0; j < current_shape.size(); j++) {
- workspace->draw_circle(current_shape[j], 8 / workspace->get_scale().x, Color(1, 0, 0));
+ }
+ workspace->draw_polygon(polygon, colors);
+ if (coord == edited_shape_coord) {
+ if (shape->get_polygon_count() > 0) {
+ PoolVector<Vector2> vertices = shape->get_vertices();
+ for (int j = 0; j < shape->get_polygon(0).size() - 1; j++) {
+ workspace->draw_line(vertices[shape->get_polygon(0)[j]] + anchor, vertices[shape->get_polygon(0)[j + 1]] + anchor, c_border, 1, true);
+ }
+ if (shape == edited_navigation_shape) {
+ for (int j = 0; j < current_shape.size(); j++) {
+ workspace->draw_circle(current_shape[j], 8 / workspace->get_scale().x, Color(1, 0, 0));
+ }
}
}
}
@@ -1461,7 +1508,7 @@ void AutotileEditor::draw_polygon_shapes() {
}
}
-void AutotileEditor::close_shape(const Vector2 &shape_anchor) {
+void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
creating_shape = false;
@@ -1486,7 +1533,11 @@ void AutotileEditor::close_shape(const Vector2 &shape_anchor) {
shape->set_points(segments);
- tile_set->tile_add_shape(get_current_tile(), shape, Transform2D(), false, edited_shape_coord);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE)
+ tileset->tile_add_shape(get_current_tile(), shape, Transform2D(), false, edited_shape_coord);
+ else
+ tileset->tile_set_shape(get_current_tile(), 0, shape);
+
edited_collision_shape = shape;
}
@@ -1506,7 +1557,10 @@ void AutotileEditor::close_shape(const Vector2 &shape_anchor) {
w = PoolVector<Vector2>::Write();
shape->set_polygon(polygon);
- tile_set->autotile_set_light_occluder(get_current_tile(), shape, edited_shape_coord);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE)
+ tileset->autotile_set_light_occluder(get_current_tile(), shape, edited_shape_coord);
+ else
+ tileset->tile_set_light_occluder(get_current_tile(), shape);
edited_occlusion_shape = shape;
tools[TOOL_SELECT]->set_pressed(true);
workspace->update();
@@ -1526,55 +1580,99 @@ void AutotileEditor::close_shape(const Vector2 &shape_anchor) {
w = PoolVector<Vector2>::Write();
shape->set_vertices(polygon);
shape->add_polygon(indices);
- tile_set->autotile_set_navigation_polygon(get_current_tile(), shape, edited_shape_coord);
+
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE)
+ tileset->autotile_set_navigation_polygon(get_current_tile(), shape, edited_shape_coord);
+ else
+ tileset->tile_set_navigation_polygon(get_current_tile(), shape);
edited_navigation_shape = shape;
tools[TOOL_SELECT]->set_pressed(true);
workspace->update();
}
+ tileset->_change_notify("");
}
-void AutotileEditor::select_coord(const Vector2 &coord) {
- int spacing = tile_set->autotile_get_spacing(get_current_tile());
- Vector2 size = tile_set->autotile_get_size(get_current_tile());
- Vector2 shape_anchor = coord;
- shape_anchor.x *= (size.x + spacing);
- shape_anchor.y *= (size.y + spacing);
- if (edit_mode == EDITMODE_COLLISION) {
- current_shape.resize(0);
- if (edited_collision_shape.is_valid()) {
- for (int j = 0; j < edited_collision_shape->get_points().size(); j++) {
- current_shape.push_back(edited_collision_shape->get_points()[j] + shape_anchor);
+void TileSetEditor::select_coord(const Vector2 &coord) {
+ current_shape = PoolVector2Array();
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ if (edited_collision_shape != tileset->tile_get_shape(get_current_tile(), 0))
+ edited_collision_shape = tileset->tile_get_shape(get_current_tile(), 0);
+ if (edited_occlusion_shape != tileset->tile_get_light_occluder(get_current_tile()))
+ edited_occlusion_shape = tileset->tile_get_light_occluder(get_current_tile());
+ if (edited_navigation_shape != tileset->tile_get_navigation_polygon(get_current_tile()))
+ edited_navigation_shape = tileset->tile_get_navigation_polygon(get_current_tile());
+
+ if (edit_mode == EDITMODE_COLLISION) {
+ current_shape.resize(0);
+ if (edited_collision_shape.is_valid()) {
+ for (int i = 0; i < edited_collision_shape->get_points().size(); i++) {
+ current_shape.push_back(edited_collision_shape->get_points()[i]);
+ }
}
- }
- } else if (edit_mode == EDITMODE_OCCLUSION) {
- current_shape.resize(0);
- if (edited_occlusion_shape.is_valid()) {
- for (int i = 0; i < edited_occlusion_shape->get_polygon().size(); i++) {
- current_shape.push_back(edited_occlusion_shape->get_polygon()[i] + shape_anchor);
+ } else if (edit_mode == EDITMODE_OCCLUSION) {
+ current_shape.resize(0);
+ if (edited_occlusion_shape.is_valid()) {
+ for (int i = 0; i < edited_occlusion_shape->get_polygon().size(); i++) {
+ current_shape.push_back(edited_occlusion_shape->get_polygon()[i]);
+ }
+ }
+ } else if (edit_mode == EDITMODE_NAVIGATION) {
+ current_shape.resize(0);
+ if (edited_navigation_shape.is_valid()) {
+ if (edited_navigation_shape->get_polygon_count() > 0) {
+ PoolVector<Vector2> vertices = edited_navigation_shape->get_vertices();
+ for (int i = 0; i < edited_navigation_shape->get_polygon(0).size(); i++) {
+ current_shape.push_back(vertices[edited_navigation_shape->get_polygon(0)[i]]);
+ }
+ }
}
}
- } else if (edit_mode == EDITMODE_NAVIGATION) {
- current_shape.resize(0);
- if (edited_navigation_shape.is_valid()) {
- if (edited_navigation_shape->get_polygon_count() > 0) {
- PoolVector<Vector2> vertices = edited_navigation_shape->get_vertices();
- for (int i = 0; i < edited_navigation_shape->get_polygon(0).size(); i++) {
- current_shape.push_back(vertices[edited_navigation_shape->get_polygon(0)[i]] + shape_anchor);
+ } else {
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
+ Vector2 size = tileset->autotile_get_size(get_current_tile());
+ Vector2 shape_anchor = coord;
+ shape_anchor.x *= (size.x + spacing);
+ shape_anchor.y *= (size.y + spacing);
+ if (edit_mode == EDITMODE_COLLISION) {
+ current_shape.resize(0);
+ if (edited_collision_shape.is_valid()) {
+ for (int j = 0; j < edited_collision_shape->get_points().size(); j++) {
+ current_shape.push_back(edited_collision_shape->get_points()[j] + shape_anchor);
+ }
+ }
+ } else if (edit_mode == EDITMODE_OCCLUSION) {
+ current_shape.resize(0);
+ if (edited_occlusion_shape.is_valid()) {
+ for (int i = 0; i < edited_occlusion_shape->get_polygon().size(); i++) {
+ current_shape.push_back(edited_occlusion_shape->get_polygon()[i] + shape_anchor);
+ }
+ }
+ } else if (edit_mode == EDITMODE_NAVIGATION) {
+ current_shape.resize(0);
+ if (edited_navigation_shape.is_valid()) {
+ if (edited_navigation_shape->get_polygon_count() > 0) {
+ PoolVector<Vector2> vertices = edited_navigation_shape->get_vertices();
+ for (int i = 0; i < edited_navigation_shape->get_polygon(0).size(); i++) {
+ current_shape.push_back(vertices[edited_navigation_shape->get_polygon(0)[i]] + shape_anchor);
+ }
}
}
}
}
}
-Vector2 AutotileEditor::snap_point(const Vector2 &point) {
+Vector2 TileSetEditor::snap_point(const Vector2 &point) {
Vector2 p = point;
Vector2 coord = edited_shape_coord;
- Vector2 tile_size = tile_set->autotile_get_size(get_current_tile());
- int spacing = tile_set->autotile_get_spacing(get_current_tile());
+ Vector2 tile_size = tileset->autotile_get_size(get_current_tile());
+ int spacing = tileset->autotile_get_spacing(get_current_tile());
Vector2 anchor = coord;
anchor.x *= (tile_size.x + spacing);
anchor.y *= (tile_size.y + spacing);
Rect2 region(anchor, tile_size);
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE)
+ region.position = Point2(0, 0);
+
if (tools[SHAPE_GRID_SNAP]->is_pressed()) {
p.x = Math::snap_scalar_seperation(snap_offset.x, snap_step.x, p.x, snap_separation.x);
p.y = Math::snap_scalar_seperation(snap_offset.y, snap_step.y, p.y, snap_separation.y);
@@ -1592,86 +1690,134 @@ Vector2 AutotileEditor::snap_point(const Vector2 &point) {
return p;
}
-void AutotileEditor::edit(Object *p_node) {
+void TileSetEditor::update_tile_list() {
+ int selected_tile = get_current_tile();
- tile_set = Ref<TileSet>(Object::cast_to<TileSet>(p_node));
- tile_set->add_change_receptor(this);
- helper->set_tileset(tile_set);
+ if (selected_tile < 0)
+ selected_tile = 0;
- autotile_list->clear();
+ helper->set_tileset(tileset);
+
+ tile_list->clear();
List<int> ids;
- tile_set->get_tile_list(&ids);
+ tileset->get_tile_list(&ids);
for (List<int>::Element *E = ids.front(); E; E = E->next()) {
- if (tile_set->tile_get_is_autotile(E->get())) {
- autotile_list->add_item(tile_set->tile_get_name(E->get()));
- autotile_list->set_item_metadata(autotile_list->get_item_count() - 1, E->get());
- autotile_list->set_item_icon(autotile_list->get_item_count() - 1, tile_set->tile_get_texture(E->get()));
- Rect2 region = tile_set->tile_get_region(E->get());
- region.size = tile_set->autotile_get_size(E->get());
- Vector2 pos = tile_set->autotile_get_icon_coordinate(E->get());
- pos.x *= (tile_set->autotile_get_spacing(E->get()) + region.size.x);
- pos.y *= (tile_set->autotile_get_spacing(E->get()) + region.size.y);
+ tile_list->add_item(tileset->tile_get_name(E->get()));
+ tile_list->set_item_metadata(tile_list->get_item_count() - 1, E->get());
+ tile_list->set_item_icon(tile_list->get_item_count() - 1, tileset->tile_get_texture(E->get()));
+ Rect2 region = tileset->tile_get_region(E->get());
+ if (tileset->tile_get_tile_mode(E->get()) == TileSet::AUTO_TILE) {
+ region.size = tileset->autotile_get_size(E->get());
+ Vector2 pos = tileset->autotile_get_icon_coordinate(E->get());
+ pos.x *= (tileset->autotile_get_spacing(E->get()) + region.size.x);
+ pos.y *= (tileset->autotile_get_spacing(E->get()) + region.size.y);
region.position += pos;
- autotile_list->set_item_icon_region(autotile_list->get_item_count() - 1, region);
}
+ tile_list->set_item_icon_region(tile_list->get_item_count() - 1, region);
}
- if (autotile_list->get_item_count() > 0) {
- autotile_list->select(0);
- _on_autotile_selected(0);
+ if (tile_list->get_item_count() > 0 && selected_tile < tile_list->get_item_count()) {
+ tile_list->select(selected_tile);
+ _on_tile_list_selected(selected_tile);
}
helper->_change_notify("");
}
-int AutotileEditor::get_current_tile() {
+void TileSetEditor::update_tile_list_icon() {
+ List<int> ids;
+ tileset->get_tile_list(&ids);
+ int current_idx = 0;
+ for (List<int>::Element *E = ids.front(); E; E = E->next()) {
+ if (current_idx >= tile_list->get_item_count())
+ break;
+
+ Rect2 region = tileset->tile_get_region(E->get());
+ if (tileset->tile_get_tile_mode(E->get()) == TileSet::AUTO_TILE) {
+ region.size = tileset->autotile_get_size(E->get());
+ Vector2 pos = tileset->autotile_get_icon_coordinate(E->get());
+ pos.x *= (tileset->autotile_get_spacing(E->get()) + region.size.x);
+ pos.y *= (tileset->autotile_get_spacing(E->get()) + region.size.y);
+ region.position += pos;
+ }
+ tile_list->set_item_metadata(current_idx, E->get());
+ tile_list->set_item_icon(current_idx, tileset->tile_get_texture(E->get()));
+ tile_list->set_item_icon_region(current_idx, region);
+ tile_list->set_item_text(current_idx, tileset->tile_get_name(E->get()));
+ current_idx += 1;
+ }
+ tile_list->update();
+}
+
+void TileSetEditor::update_workspace_tile_mode() {
+ if (get_current_tile() < 0)
+ return;
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
+ if (tool_editmode[EDITMODE_ICON]->is_pressed() || tool_editmode[EDITMODE_PRIORITY]->is_pressed() || tool_editmode[EDITMODE_BITMASK]->is_pressed()) {
+ tool_editmode[EDITMODE_COLLISION]->set_pressed(true);
+ _on_edit_mode_changed(EDITMODE_COLLISION);
+ } else {
+ select_coord(Vector2(0, 0));
+ }
+
+ tool_editmode[EDITMODE_ICON]->hide();
+ tool_editmode[EDITMODE_BITMASK]->hide();
+ tool_editmode[EDITMODE_PRIORITY]->hide();
+ property_editor->hide();
+ } else {
+ tool_editmode[EDITMODE_ICON]->show();
+ tool_editmode[EDITMODE_BITMASK]->show();
+ tool_editmode[EDITMODE_PRIORITY]->show();
+ property_editor->show();
+ }
+}
- if (autotile_list->get_selected_items().size() == 0)
+int TileSetEditor::get_current_tile() {
+ if (tile_list->get_selected_items().size() == 0)
return -1;
else
- return autotile_list->get_item_metadata(autotile_list->get_selected_items()[0]);
+ return tile_list->get_item_metadata(tile_list->get_selected_items()[0]);
}
-void AutotileEditorHelper::set_tileset(const Ref<TileSet> &p_tileset) {
+void TileSetEditorHelper::set_tileset(const Ref<TileSet> &p_tileset) {
- tile_set = p_tileset;
+ tileset = p_tileset;
}
-bool AutotileEditorHelper::_set(const StringName &p_name, const Variant &p_value) {
+bool TileSetEditorHelper::_set(const StringName &p_name, const Variant &p_value) {
- if (autotile_editor->get_current_tile() < 0 || tile_set.is_null())
+ if (selected_tile < 0 || tileset.is_null())
return false;
String name = p_name.operator String();
bool v = false;
if (name == "bitmask_mode") {
- tile_set->set(String::num(autotile_editor->get_current_tile(), 0) + "/autotile/bitmask_mode", p_value, &v);
+ tileset->set(String::num(selected_tile, 0) + "/autotile/bitmask_mode", p_value, &v);
} else if (name.left(7) == "layout/") {
- tile_set->set(String::num(autotile_editor->get_current_tile(), 0) + "/autotile" + name.right(6), p_value, &v);
+ tileset->set(String::num(selected_tile, 0) + "/autotile" + name.right(6), p_value, &v);
}
if (v) {
- tile_set->_change_notify("");
- autotile_editor->workspace->update();
+ tileset->_change_notify("autotile");
}
return v;
}
-bool AutotileEditorHelper::_get(const StringName &p_name, Variant &r_ret) const {
+bool TileSetEditorHelper::_get(const StringName &p_name, Variant &r_ret) const {
- if (autotile_editor->get_current_tile() < 0 || tile_set.is_null())
+ if (selected_tile < 0 || tileset.is_null())
return false;
String name = p_name.operator String();
bool v = false;
if (name == "bitmask_mode") {
- r_ret = tile_set->get(String::num(autotile_editor->get_current_tile(), 0) + "/autotile/bitmask_mode", &v);
+ r_ret = tileset->get(String::num(selected_tile, 0) + "/autotile/bitmask_mode", &v);
} else if (name.left(7) == "layout/") {
- r_ret = tile_set->get(String::num(autotile_editor->get_current_tile(), 0) + "/autotile" + name.right(6), &v);
+ r_ret = tileset->get(String::num(selected_tile, 0) + "/autotile" + name.right(6), &v);
}
return v;
}
-void AutotileEditorHelper::_get_property_list(List<PropertyInfo> *p_list) const {
+void TileSetEditorHelper::_get_property_list(List<PropertyInfo> *p_list) const {
- if (autotile_editor->get_current_tile() < 0 || tile_set.is_null())
+ if (selected_tile < 0 || tileset.is_null())
return;
p_list->push_back(PropertyInfo(Variant::INT, "bitmask_mode", PROPERTY_HINT_ENUM, "2x2,3x3"));
@@ -1679,7 +1825,71 @@ void AutotileEditorHelper::_get_property_list(List<PropertyInfo> *p_list) const
p_list->push_back(PropertyInfo(Variant::INT, "layout/spacing", PROPERTY_HINT_RANGE, "0,256,1"));
}
-AutotileEditorHelper::AutotileEditorHelper(AutotileEditor *p_autotile_editor) {
+TileSetEditorHelper::TileSetEditorHelper(TileSetEditor *p_tileset_editor) {
+
+ tileset_editor = p_tileset_editor;
+}
+
+void TileSetEditorPlugin::edit(Object *p_node) {
+
+ if (Object::cast_to<TileSet>(p_node)) {
+ tileset_editor->edit(Object::cast_to<TileSet>(p_node));
+ tileset_editor->show();
+ tileset_editor->texture_region_editor->edit(p_node);
+ } else
+ tileset_editor->hide();
+}
+
+bool TileSetEditorPlugin::handles(Object *p_node) const {
+
+ return p_node->is_class("TileSet");
+}
+
+void TileSetEditorPlugin::make_visible(bool p_visible) {
+
+ if (p_visible) {
+ tileset_editor->show();
+ tileset_editor->menu->show();
+ tileset_editor_button->show();
+ tileset_editor->side_panel->show();
+ if (tileset_editor_button->is_pressed()) {
+ tileset_editor->bottom_panel->show();
+ }
+ texture_region_button->show();
+ if (texture_region_button->is_pressed())
+ tileset_editor->texture_region_editor->show();
+ } else {
+ tileset_editor->hide();
+ tileset_editor->menu->hide();
+ tileset_editor->side_panel->hide();
+ tileset_editor->bottom_panel->hide();
+ tileset_editor_button->hide();
+ texture_region_button->hide();
+ tileset_editor->texture_region_editor->hide();
+ }
+}
+
+TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) {
+
+ tileset_editor = memnew(TileSetEditor(p_node));
+
+ add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, tileset_editor);
+ tileset_editor->set_anchors_and_margins_preset(Control::PRESET_TOP_WIDE);
+ tileset_editor->set_end(Point2(0, 22));
+ tileset_editor->hide();
+
+ tileset_editor->texture_region_editor = memnew(TextureRegionEditor(p_node));
+ texture_region_button = p_node->add_bottom_panel_item(TTR("Texture Region"), tileset_editor->texture_region_editor);
+ texture_region_button->set_tooltip(TTR("Texture Region Editor"));
+
+ tileset_editor->texture_region_editor->set_custom_minimum_size(Size2(0, 200));
+ tileset_editor->texture_region_editor->hide();
+ texture_region_button->hide();
- autotile_editor = p_autotile_editor;
+ add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, tileset_editor->side_panel);
+ tileset_editor->side_panel->set_anchors_and_margins_preset(Control::PRESET_WIDE);
+ tileset_editor->side_panel->set_custom_minimum_size(Size2(200, 0));
+ tileset_editor->side_panel->hide();
+ tileset_editor_button = p_node->add_bottom_panel_item(TTR("Tile Set"), tileset_editor->bottom_panel);
+ tileset_editor_button->hide();
}
diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h
index 30f6e2b925..0404c5236a 100644
--- a/editor/plugins/tile_set_editor_plugin.h
+++ b/editor/plugins/tile_set_editor_plugin.h
@@ -33,35 +33,38 @@
#include "editor/editor_name_dialog.h"
#include "editor/editor_node.h"
+#include "editor/plugins/texture_region_editor_plugin.h"
#include "scene/2d/sprite.h"
#include "scene/resources/convex_polygon_shape_2d.h"
#include "scene/resources/tile_set.h"
-class AutotileEditorHelper;
-class AutotileEditor : public Control {
+class TileSetEditorHelper;
+
+class TileSetEditor : public Control {
friend class TileSetEditorPlugin;
- friend class AutotileEditorHelper;
- GDCLASS(AutotileEditor, Control);
+ friend class TextureRegionEditor;
+
+ GDCLASS(TileSetEditor, Control);
enum EditMode {
- EDITMODE_ICON,
- EDITMODE_BITMASK,
EDITMODE_COLLISION,
EDITMODE_OCCLUSION,
EDITMODE_NAVIGATION,
+ EDITMODE_BITMASK,
EDITMODE_PRIORITY,
+ EDITMODE_ICON,
EDITMODE_MAX
};
- enum AutotileToolbars {
+ enum TileSetToolbar {
TOOLBAR_DUMMY,
TOOLBAR_BITMASK,
TOOLBAR_SHAPE,
TOOLBAR_MAX
};
- enum AutotileTools {
+ enum TileSetTools {
TOOL_SELECT,
BITMASK_COPY,
BITMASK_PASTE,
@@ -78,13 +81,12 @@ class AutotileEditor : public Control {
TOOL_MAX
};
- Ref<TileSet> tile_set;
+ Ref<TileSet> tileset;
+
Ref<ConvexPolygonShape2D> edited_collision_shape;
Ref<OccluderPolygon2D> edited_occlusion_shape;
Ref<NavigationPolygon> edited_navigation_shape;
- EditorNode *editor;
-
int current_item_index;
Sprite *preview;
ScrollContainer *scroll;
@@ -114,21 +116,48 @@ class AutotileEditor : public Control {
PoolVector2Array current_shape;
Map<Vector2, uint16_t> bitmask_map_copy;
+ EditorNode *editor;
+ TextureRegionEditor *texture_region_editor;
+ Control *bottom_panel;
Control *side_panel;
- ItemList *autotile_list;
+ ItemList *tile_list;
PropertyEditor *property_editor;
- AutotileEditorHelper *helper;
+ TileSetEditorHelper *helper;
+
+ MenuButton *menu;
+ ConfirmationDialog *cd;
+ EditorNameDialog *nd;
+ AcceptDialog *err_dialog;
+
+ enum {
- AutotileEditor(EditorNode *p_editor);
- ~AutotileEditor();
+ MENU_OPTION_ADD_ITEM,
+ MENU_OPTION_REMOVE_ITEM,
+ MENU_OPTION_CREATE_FROM_SCENE,
+ MENU_OPTION_MERGE_FROM_SCENE
+ };
+
+ int option;
+ void _menu_cbk(int p_option);
+ void _menu_confirm();
+ void _name_dialog_confirm(const String &name);
+
+ static void _import_node(Node *p_node, Ref<TileSet> p_library);
+ static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge);
protected:
static void _bind_methods();
void _notification(int p_what);
virtual void _changed_callback(Object *p_changed, const char *p_prop);
+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);
+
private:
- void _on_autotile_selected(int p_index);
+ void _on_tile_list_selected(int p_index);
void _on_edit_mode_changed(int p_edit_mode);
void _on_workspace_draw();
void _on_workspace_input(const Ref<InputEvent> &p_ie);
@@ -142,24 +171,28 @@ private:
void _set_snap_sep_x(float p_val);
void _set_snap_sep_y(float p_val);
+ void initialize_bottom_editor();
void draw_highlight_tile(Vector2 coord, const Vector<Vector2> &other_highlighted = Vector<Vector2>());
void draw_grid_snap();
void draw_polygon_shapes();
void close_shape(const Vector2 &shape_anchor);
void select_coord(const Vector2 &coord);
Vector2 snap_point(const Vector2 &point);
+ void update_tile_list();
+ void update_tile_list_icon();
+ void update_workspace_tile_mode();
- void edit(Object *p_node);
int get_current_tile();
};
-class AutotileEditorHelper : public Object {
+class TileSetEditorHelper : public Object {
- friend class AutotileEditor;
- GDCLASS(AutotileEditorHelper, Object);
+ friend class TileSetEditor;
+ GDCLASS(TileSetEditorHelper, Object);
- Ref<TileSet> tile_set;
- AutotileEditor *autotile_editor;
+ Ref<TileSet> tileset;
+ TileSetEditor *tileset_editor;
+ int selected_tile;
public:
void set_tileset(const Ref<TileSet> &p_tileset);
@@ -169,46 +202,7 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
- AutotileEditorHelper(AutotileEditor *p_autotile_editor);
-};
-
-class TileSetEditor : public Control {
-
- friend class TileSetEditorPlugin;
- GDCLASS(TileSetEditor, Control);
-
- Ref<TileSet> tileset;
-
- EditorNode *editor;
- MenuButton *menu;
- ConfirmationDialog *cd;
- EditorNameDialog *nd;
- AcceptDialog *err_dialog;
-
- enum {
-
- MENU_OPTION_ADD_ITEM,
- MENU_OPTION_REMOVE_ITEM,
- MENU_OPTION_CREATE_FROM_SCENE,
- MENU_OPTION_MERGE_FROM_SCENE
- };
-
- int option;
- void _menu_cbk(int p_option);
- void _menu_confirm();
- void _name_dialog_confirm(const String &name);
-
- static void _import_node(Node *p_node, Ref<TileSet> p_library);
- 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);
-
- TileSetEditor(EditorNode *p_editor);
+ TileSetEditorHelper(TileSetEditor *p_tileset_editor);
};
class TileSetEditorPlugin : public EditorPlugin {
@@ -216,10 +210,10 @@ class TileSetEditorPlugin : public EditorPlugin {
GDCLASS(TileSetEditorPlugin, EditorPlugin);
TileSetEditor *tileset_editor;
- AutotileEditor *autotile_editor;
EditorNode *editor;
- ToolButton *autotile_button;
+ ToolButton *tileset_editor_button;
+ ToolButton *texture_region_button;
public:
virtual String get_name() const { return "TileSet"; }
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index da283b16dc..bd700342f6 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -304,8 +304,9 @@ private:
ProjectSettings *current = memnew(ProjectSettings);
- if (current->setup(dir, "")) {
- set_message(TTR("Couldn't get project.godot in project path."), MESSAGE_ERROR);
+ int err = current->setup(dir, "");
+ if (err != OK) {
+ set_message(vformat(TTR("Couldn't load project.godot in project path (error %d). It may be missing or corrupted."), err), MESSAGE_ERROR);
} else {
ProjectSettings::CustomMap edited_settings;
edited_settings["application/config/name"] = project_name->get_text();
@@ -530,8 +531,9 @@ public:
ProjectSettings *current = memnew(ProjectSettings);
- if (current->setup(project_path->get_text(), "")) {
- set_message(TTR("Couldn't get project.godot in the project path."), MESSAGE_ERROR);
+ int err = current->setup(project_path->get_text(), "");
+ if (err != OK) {
+ set_message(vformat(TTR("Couldn't load project.godot in project path (error %d). It may be missing or corrupted."), err), MESSAGE_ERROR);
status_rect->show();
msg->show();
get_ok()->set_disabled(true);
@@ -713,6 +715,12 @@ void ProjectManager::_update_project_buttons() {
CanvasItem *item = Object::cast_to<CanvasItem>(scroll_children->get_child(i));
item->update();
+
+ Button *show = Object::cast_to<Button>(item->get_node(NodePath("project/path_box/show")));
+ if (show) {
+ String current = item->get_meta("name");
+ show->set_visible(selected_list.has(current));
+ }
}
erase_btn->set_disabled(selected_list.size() < 1);
@@ -1092,9 +1100,26 @@ void ProjectManager::_load_recent_projects() {
title->add_color_override("font_color", font_color);
title->set_clip_text(true);
vb->add_child(title);
+
+ HBoxContainer *path_hb = memnew(HBoxContainer);
+ path_hb->set_name("path_box");
+ path_hb->set_h_size_flags(SIZE_EXPAND_FILL);
+ vb->add_child(path_hb);
+
+ Button *show = memnew(Button);
+ show->set_name("show");
+ show->set_icon(get_icon("Filesystem", "EditorIcons"));
+ show->set_flat(true);
+ show->set_modulate(Color(1, 1, 1, 0.5));
+ path_hb->add_child(show);
+ show->connect("pressed", this, "_show_project", varray(path));
+ show->set_tooltip(TTR("Show In File Manager"));
+ show->set_visible(false);
+
Label *fpath = memnew(Label(path));
fpath->set_name("path");
- vb->add_child(fpath);
+ path_hb->add_child(fpath);
+ fpath->set_h_size_flags(SIZE_EXPAND_FILL);
fpath->set_modulate(Color(1, 1, 1, 0.5));
fpath->add_color_override("font_color", font_color);
fpath->set_clip_text(true);
@@ -1124,7 +1149,7 @@ void ProjectManager::_on_project_created(const String &dir) {
bool has_already = false;
for (int i = 0; i < scroll_children->get_child_count(); i++) {
HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
- Label *fpath = Object::cast_to<Label>(hb->get_node(NodePath("project/path")));
+ Label *fpath = Object::cast_to<Label>(hb->get_node(NodePath("project/path_box/path")));
if (fpath->get_text() == dir) {
has_already = true;
break;
@@ -1142,7 +1167,7 @@ void ProjectManager::_on_project_created(const String &dir) {
void ProjectManager::_update_scroll_position(const String &dir) {
for (int i = 0; i < scroll_children->get_child_count(); i++) {
HBoxContainer *hb = Object::cast_to<HBoxContainer>(scroll_children->get_child(i));
- Label *fpath = Object::cast_to<Label>(hb->get_node(NodePath("project/path")));
+ Label *fpath = Object::cast_to<Label>(hb->get_node(NodePath("project/path_box/path")));
if (fpath->get_text() == dir) {
last_clicked = hb->get_meta("name");
selected_list.clear();
@@ -1260,6 +1285,11 @@ void ProjectManager::_run_project() {
}
}
+void ProjectManager::_show_project(const String &p_path) {
+
+ OS::get_singleton()->shell_open(String("file://") + p_path);
+}
+
void ProjectManager::_scan_dir(DirAccess *da, float pos, float total, List<String> *r_projects) {
List<String> subdirs;
@@ -1448,6 +1478,7 @@ void ProjectManager::_bind_methods() {
ClassDB::bind_method("_open_project_confirm", &ProjectManager::_open_project_confirm);
ClassDB::bind_method("_run_project", &ProjectManager::_run_project);
ClassDB::bind_method("_run_project_confirm", &ProjectManager::_run_project_confirm);
+ ClassDB::bind_method("_show_project", &ProjectManager::_show_project);
ClassDB::bind_method("_scan_projects", &ProjectManager::_scan_projects);
ClassDB::bind_method("_scan_begin", &ProjectManager::_scan_begin);
ClassDB::bind_method("_import_project", &ProjectManager::_import_project);
diff --git a/editor/project_manager.h b/editor/project_manager.h
index 23ffa2f857..a9d23b1f71 100644
--- a/editor/project_manager.h
+++ b/editor/project_manager.h
@@ -85,6 +85,7 @@ class ProjectManager : public Control {
void _run_project_confirm();
void _open_project();
void _open_project_confirm();
+ void _show_project(const String &p_path);
void _import_project();
void _new_project();
void _rename_project();
diff --git a/editor/project_settings_editor.h b/editor/project_settings_editor.h
index 452cf5b060..9364b0ff2c 100644
--- a/editor/project_settings_editor.h
+++ b/editor/project_settings_editor.h
@@ -176,6 +176,8 @@ public:
void popup_project_settings();
void set_plugins_page();
+ EditorAutoloadSettings *get_autoload_settings() { return autoload_settings; }
+
TabContainer *get_tabs();
void queue_save();
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 8506c75a68..45622d43e8 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -1885,8 +1885,6 @@ void SceneTreeDock::_local_tree_selected() {
remote_tree->hide();
edit_remote->set_pressed(false);
edit_local->set_pressed(true);
-
- _node_selected();
}
void SceneTreeDock::_bind_methods() {
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index fd21b83605..8f3113c816 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -69,24 +69,10 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
emit_signal("open_script", script);
} else if (p_id == BUTTON_VISIBILITY) {
-
- if (n->is_class("Spatial")) {
-
- bool v = bool(n->call("is_visible"));
- undo_redo->create_action(TTR("Toggle Spatial Visible"));
- undo_redo->add_do_method(n, "set_visible", !v);
- undo_redo->add_undo_method(n, "set_visible", v);
- undo_redo->commit_action();
-
- } else if (n->is_class("CanvasItem")) {
-
- bool v = bool(n->call("is_visible"));
- undo_redo->create_action(TTR("Toggle CanvasItem Visible"));
- undo_redo->add_do_method(n, v ? "hide" : "show");
- undo_redo->add_undo_method(n, v ? "show" : "hide");
- undo_redo->commit_action();
- }
-
+ undo_redo->create_action(TTR("Toggle Visible"));
+ undo_redo->add_do_method(this, "toggle_visible", n);
+ undo_redo->add_undo_method(this, "toggle_visible", n);
+ undo_redo->commit_action();
} else if (p_id == BUTTON_LOCK) {
if (n->is_class("CanvasItem") || n->is_class("Spatial")) {
@@ -131,7 +117,34 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
NodeDock::singleton->show_groups();
}
}
+void SceneTreeEditor::_toggle_visible(Node *p_node) {
+ if (p_node->is_class("Spatial")) {
+ bool v = bool(p_node->call("is_visible"));
+ p_node->call("set_visible", !v);
+ } else if (p_node->is_class("CanvasItem")) {
+ bool v = bool(p_node->call("is_visible"));
+ if (v) {
+ p_node->call("hide");
+ } else {
+ p_node->call("show");
+ }
+ }
+}
+void SceneTreeEditor::toggle_visible(Node *p_node) {
+ _toggle_visible(p_node);
+ List<Node *> selection = editor_selection->get_selected_node_list();
+ if (selection.size() > 1) {
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ Node *nv = E->get();
+ ERR_FAIL_COND(!nv);
+ if (nv == p_node) {
+ continue;
+ }
+ _toggle_visible(nv);
+ }
+ }
+}
bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (!p_node)
@@ -523,6 +536,7 @@ void SceneTreeEditor::_notification(int p_what) {
tree->connect("item_collapsed", this, "_cell_collapsed");
EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
+ _editor_settings_changed();
//get_scene()->connect("tree_changed",this,"_tree_changed",Vector<Variant>(),CONNECT_DEFERRED);
//get_scene()->connect("node_removed",this,"_node_removed",Vector<Variant>(),CONNECT_DEFERRED);
@@ -949,6 +963,8 @@ void SceneTreeEditor::_bind_methods() {
ClassDB::bind_method("_cell_collapsed", &SceneTreeEditor::_cell_collapsed);
ClassDB::bind_method("_rmb_select", &SceneTreeEditor::_rmb_select);
ClassDB::bind_method("_warning_changed", &SceneTreeEditor::_warning_changed);
+ ClassDB::bind_method("_toggle_visible", &SceneTreeEditor::_toggle_visible);
+ ClassDB::bind_method("toggle_visible", &SceneTreeEditor::toggle_visible);
ClassDB::bind_method("_node_script_changed", &SceneTreeEditor::_node_script_changed);
ClassDB::bind_method("_node_visibility_changed", &SceneTreeEditor::_node_visibility_changed);
diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h
index 45194bb81d..b63eb2a1f0 100644
--- a/editor/scene_tree_editor.h
+++ b/editor/scene_tree_editor.h
@@ -70,6 +70,8 @@ class SceneTreeEditor : public Control {
void _compute_hash(Node *p_node, uint64_t &hash);
+ void toggle_visible(Node *p_node);
+
bool _add_nodes(Node *p_node, TreeItem *p_parent);
void _test_update_tree();
void _update_tree();
@@ -103,6 +105,7 @@ class SceneTreeEditor : public Control {
static void _bind_methods();
void _cell_button_pressed(Object *p_item, int p_column, int p_id);
+ void _toggle_visible(Node *p_node);
void _cell_multi_selected(Object *p_object, int p_cell, bool p_selected);
void _update_selection(TreeItem *item);
void _node_script_changed(Node *p_node);
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index e56a7f2a55..b893b098ac 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -535,15 +535,19 @@ void ScriptCreateDialog::_update_dialog() {
/* Is Script created or loaded from existing file */
- if (is_new_script_created) {
+ if (is_built_in) {
+ get_ok()->set_text(TTR("Create"));
+ parent_name->set_editable(true);
+ parent_browse_button->set_disabled(false);
+ internal->set_disabled(!supports_built_in);
+ _msg_path_valid(true, TTR("Built-in script (into scene file)"));
+ } else if (is_new_script_created) {
// New Script Created
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_browse_button->set_disabled(false);
internal->set_disabled(!supports_built_in);
- if (is_built_in) {
- _msg_path_valid(true, TTR("Built-in script (into scene file)"));
- } else if (is_path_valid) {
+ if (is_path_valid) {
_msg_path_valid(true, TTR("Create new script file"));
}
} else {
@@ -551,7 +555,7 @@ void ScriptCreateDialog::_update_dialog() {
get_ok()->set_text(TTR("Load"));
parent_name->set_editable(false);
parent_browse_button->set_disabled(true);
- internal->set_disabled(true);
+ internal->set_disabled(!supports_built_in);
if (is_path_valid) {
_msg_path_valid(true, TTR("Load existing script file"));
}
diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp
index 86ab84909e..4fc73b2a8e 100644
--- a/editor/script_editor_debugger.cpp
+++ b/editor/script_editor_debugger.cpp
@@ -965,6 +965,14 @@ void ScriptEditorDebugger::_notification(int p_what) {
reason->add_color_override("font_color", get_color("error_color", "Editor"));
+ bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines");
+ Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color");
+
+ if (enable_rl) {
+ inspect_scene_tree->add_constant_override("draw_relationship_lines", 1);
+ inspect_scene_tree->add_color_override("relationship_line_color", rl_color);
+ } else
+ inspect_scene_tree->add_constant_override("draw_relationship_lines", 0);
} break;
case NOTIFICATION_PROCESS: {
@@ -1873,6 +1881,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
sc->set_v_size_flags(SIZE_EXPAND_FILL);
stack_dump = memnew(Tree);
+ stack_dump->set_allow_reselect(true);
stack_dump->set_columns(1);
stack_dump->set_column_titles_visible(true);
stack_dump->set_column_title(0, TTR("Stack Frames"));