summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/abstract_polygon_2d_editor.cpp8
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp51
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp125
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h3
-rw-r--r--editor/plugins/collision_polygon_editor_plugin.cpp2
-rw-r--r--editor/plugins/editor_preview_plugins.cpp6
-rw-r--r--editor/plugins/material_editor_plugin.cpp38
-rw-r--r--editor/plugins/material_editor_plugin.h8
-rw-r--r--editor/plugins/mesh_editor_plugin.cpp2
-rw-r--r--editor/plugins/particles_editor_plugin.cpp8
-rw-r--r--editor/plugins/script_editor_plugin.cpp363
-rw-r--r--editor/plugins/script_editor_plugin.h16
-rw-r--r--editor/plugins/script_text_editor.cpp197
-rw-r--r--editor/plugins/script_text_editor.h6
-rw-r--r--editor/plugins/shader_editor_plugin.cpp399
-rw-r--r--editor/plugins/shader_editor_plugin.h18
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp206
-rw-r--r--editor/plugins/spatial_editor_plugin.h19
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp2
19 files changed, 1197 insertions, 280 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp
index f2f913d2b3..736e176ab8 100644
--- a/editor/plugins/abstract_polygon_2d_editor.cpp
+++ b/editor/plugins/abstract_polygon_2d_editor.cpp
@@ -563,6 +563,14 @@ void AbstractPolygon2DEditor::forward_draw_over_canvas(Control *p_canvas) {
const Vector2 next_point = xform.xform(p2);
vpc->draw_line(point, next_point, col, 2);
}
+ }
+
+ for (int i = 0; i < n_points; i++) {
+
+ const Vertex vertex(j, i);
+
+ const Vector2 p = (vertex == edited_point) ? edited_point.pos : (points[i] + offset);
+ const Vector2 point = xform.xform(p);
Ref<Texture> handle = vertex == active_point ? selected_handle : default_handle;
vpc->draw_texture(handle, point - handle->get_size() * 0.5);
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index d2e7feb6e1..b63352389e 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -47,9 +47,9 @@ void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, co
for (int i = 0; i < 5; i++) {
if (i < p_rating)
- stars[i]->set_texture(get_icon("RatingStar", "EditorIcons"));
+ stars[i]->set_texture(get_icon("Favorites", "EditorIcons"));
else
- stars[i]->set_texture(get_icon("RatingNoStar", "EditorIcons"));
+ stars[i]->set_texture(get_icon("NonFavorite", "EditorIcons"));
}
}
@@ -273,15 +273,15 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() {
HBoxContainer *hbox = memnew(HBoxContainer);
vbox->add_child(hbox);
- vbox->add_constant_override("separation", 15);
+ vbox->add_constant_override("separation", 15 * EDSCALE);
VBoxContainer *desc_vbox = memnew(VBoxContainer);
hbox->add_child(desc_vbox);
- hbox->add_constant_override("separation", 15);
+ hbox->add_constant_override("separation", 15 * EDSCALE);
item = memnew(EditorAssetLibraryItem);
desc_vbox->add_child(item);
- desc_vbox->set_custom_minimum_size(Size2(300, 0));
+ desc_vbox->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
desc_bg = memnew(PanelContainer);
desc_vbox->add_child(desc_bg);
@@ -292,12 +292,12 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() {
desc_bg->add_child(description);
preview = memnew(TextureRect);
- preview->set_custom_minimum_size(Size2(640, 345));
+ preview->set_custom_minimum_size(Size2(640 * EDSCALE, 345 * EDSCALE));
hbox->add_child(preview);
previews_bg = memnew(PanelContainer);
vbox->add_child(previews_bg);
- previews_bg->set_custom_minimum_size(Size2(0, 85));
+ previews_bg->set_custom_minimum_size(Size2(0, 101 * EDSCALE));
previews = memnew(ScrollContainer);
previews_bg->add_child(previews);
@@ -445,7 +445,7 @@ void EditorAssetLibraryItemDownload::_install() {
void EditorAssetLibraryItemDownload::_make_request() {
download->cancel_request();
- download->set_download_file(EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("tmp_asset_" + itos(asset_id)) + ".zip");
+ download->set_download_file(EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_asset_" + itos(asset_id)) + ".zip");
Error err = download->request(host);
if (err != OK) {
@@ -680,7 +680,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt
PoolByteArray image_data = p_data;
if (use_cache) {
- String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
+ String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
FileAccess *file = FileAccess::open(cache_filename_base + ".data", FileAccess::READ);
@@ -702,15 +702,28 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt
Ref<Image> image = Ref<Image>(memnew(Image(r.ptr(), len)));
if (!image->empty()) {
- float max_height = 10000;
switch (image_queue[p_queue_id].image_type) {
- case IMAGE_QUEUE_ICON: max_height = 80; break;
- case IMAGE_QUEUE_THUMBNAIL: max_height = 80; break;
- case IMAGE_QUEUE_SCREENSHOT: max_height = 345; break;
- }
- float scale_ratio = max_height / image->get_height();
- if (scale_ratio < 1) {
- image->resize(image->get_width() * scale_ratio, image->get_height() * scale_ratio, Image::INTERPOLATE_CUBIC);
+ case IMAGE_QUEUE_ICON:
+
+ image->resize(80 * EDSCALE, 80 * EDSCALE, Image::INTERPOLATE_CUBIC);
+
+ break;
+ case IMAGE_QUEUE_THUMBNAIL: {
+ float max_height = 85 * EDSCALE;
+
+ float scale_ratio = max_height / (image->get_height() * EDSCALE);
+ if (scale_ratio < 1) {
+ image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_CUBIC);
+ }
+ } break;
+ case IMAGE_QUEUE_SCREENSHOT: {
+ float max_height = 397 * EDSCALE;
+
+ float scale_ratio = max_height / (image->get_height() * EDSCALE);
+ if (scale_ratio < 1) {
+ image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_CUBIC);
+ }
+ } break;
}
Ref<ImageTexture> tex;
@@ -738,7 +751,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons
if (p_code != HTTPClient::RESPONSE_NOT_MODIFIED) {
for (int i = 0; i < headers.size(); i++) {
if (headers[i].findn("ETag:") == 0) { // Save etag
- String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
+ String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
String new_etag = headers[i].substr(headers[i].find(":") + 1, headers[i].length()).strip_edges();
FileAccess *file;
@@ -786,7 +799,7 @@ void EditorAssetLibrary::_update_image_queue() {
for (Map<int, ImageQueue>::Element *E = image_queue.front(); E; E = E->next()) {
if (!E->get().active && current_images < max_images) {
- String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + E->get().image_url.md5_text());
+ String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + E->get().image_url.md5_text());
Vector<String> headers;
if (FileAccess::exists(cache_filename_base + ".etag") && FileAccess::exists(cache_filename_base + ".data")) {
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 16564ce45f..b6ba09fb58 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -176,9 +176,9 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node2D *n2d = Object::cast_to<Node2D>(E->get());
- if (n2d && n2d->edit_has_pivot()) {
+ if (n2d && n2d->_edit_use_pivot()) {
- Vector2 offset = n2d->edit_get_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);
@@ -186,9 +186,9 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &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_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);
+ 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)
@@ -249,8 +249,8 @@ void CanvasItemEditor::_snap_other_nodes(Point2 p_value, Point2 &r_current_snap,
Transform2D ci_transform = canvas_item->get_global_transform_with_canvas();
Transform2D to_snap_transform = p_to_snap ? p_to_snap->get_global_transform_with_canvas() : Transform2D();
if (fmod(ci_transform.get_rotation() - to_snap_transform.get_rotation(), (real_t)360.0) == 0.0) {
- Point2 begin = ci_transform.xform(canvas_item->get_item_rect().get_position());
- Point2 end = ci_transform.xform(canvas_item->get_item_rect().get_position() + canvas_item->get_item_rect().get_size());
+ Point2 begin = ci_transform.xform(canvas_item->_edit_get_rect().get_position());
+ Point2 end = ci_transform.xform(canvas_item->_edit_get_rect().get_position() + canvas_item->_edit_get_rect().get_size());
_snap_if_closer_point(p_value, begin, r_current_snap, r_snapped, ci_transform.get_rotation());
_snap_if_closer_point(p_value, end, r_current_snap, r_snapped, ci_transform.get_rotation());
@@ -282,8 +282,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const
end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1)));
can_snap = true;
} else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_canvas_item->get_parent())) {
- begin = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->get_item_rect().get_position());
- end = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->get_item_rect().get_position() + parent_ci->get_item_rect().get_size());
+ begin = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position());
+ end = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size());
can_snap = true;
}
@@ -306,8 +306,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const
// Self sides (for anchors)
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->get_item_rect().get_position());
- end = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->get_item_rect().get_position() + p_canvas_item->get_item_rect().get_size());
+ 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());
_snap_if_closer_point(p_target, begin, output, snapped, rotation);
_snap_if_closer_point(p_target, end, output, snapped, rotation);
}
@@ -629,7 +629,7 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no
if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
- Rect2 rect = c->get_item_rect();
+ Rect2 rect = c->_edit_get_rect();
Point2 local_pos = (p_parent_xform * p_canvas_xform * c->get_transform()).affine_inverse().xform(p_pos);
if (rect.has_point(local_pos)) {
@@ -675,7 +675,7 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_n
if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
- Rect2 rect = c->get_item_rect();
+ Rect2 rect = c->_edit_get_rect();
Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform();
if (p_rect.has_point(xform.xform(rect.position)) &&
@@ -767,15 +767,15 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE
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());
+ 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->get_item_rect();
+ Rect2 local_rect = canvas_item->_edit_get_rect();
local_rect.position += drag;
- undo_redo->add_do_method(canvas_item, "edit_set_rect", local_rect);
+ 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
@@ -816,7 +816,7 @@ Point2 CanvasItemEditor::_find_topleftmost_point() {
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
- Rect2 rect = canvas_item->get_item_rect();
+ Rect2 rect = canvas_item->_edit_get_rect();
Transform2D xform = canvas_item->get_global_transform_with_canvas();
r2.expand_to(xform.xform(rect.position));
@@ -877,7 +877,7 @@ CanvasItemEditor::DragType CanvasItemEditor::_get_resize_handle_drag_type(const
ERR_FAIL_COND_V(!canvas_item, DRAG_NONE);
- Rect2 rect = canvas_item->get_item_rect();
+ Rect2 rect = canvas_item->_edit_get_rect();
Transform2D xforml = canvas_item->get_global_transform_with_canvas();
Transform2D xform = transform * xforml;
@@ -1011,14 +1011,14 @@ void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) {
if (!se)
continue;
- se->undo_state = canvas_item->edit_get_state();
+ 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();
+ 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->get_item_rect();
+ se->pre_drag_rect = canvas_item->_edit_get_rect();
}
if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0]) && bone_ik_list.size() == 0) {
@@ -1500,7 +1500,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
// 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);
+ E->get().node->_edit_set_state(E->get().orig_state);
}
bone_ik_list.clear();
@@ -1519,9 +1519,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
if (!se)
continue;
- canvas_item->edit_set_state(se->undo_state);
+ 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);
+ 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);
}
@@ -1574,8 +1574,8 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) {
- undo_redo->add_do_method(E->get().node, "edit_set_state", E->get().node->edit_get_state());
- undo_redo->add_undo_method(E->get().node, "edit_set_state", E->get().orig_state);
+ undo_redo->add_do_method(E->get().node, "_edit_set_state", E->get().node->_edit_get_state());
+ undo_redo->add_undo_method(E->get().node, "_edit_set_state", E->get().orig_state);
}
undo_redo->add_do_method(viewport, "update");
@@ -1601,14 +1601,14 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
if (!se)
continue;
- Variant state = canvas_item->edit_get_state();
- undo_redo->add_do_method(canvas_item, "edit_set_state", state);
- undo_redo->add_undo_method(canvas_item, "edit_set_state", se->undo_state);
+ Variant state = canvas_item->_edit_get_state();
+ undo_redo->add_do_method(canvas_item, "_edit_set_state", state);
+ undo_redo->add_undo_method(canvas_item, "_edit_set_state", se->undo_state);
{
Node2D *pvt = Object::cast_to<Node2D>(canvas_item);
- if (pvt && pvt->edit_has_pivot()) {
- undo_redo->add_do_method(canvas_item, "edit_set_pivot", pvt->edit_get_pivot());
- undo_redo->add_undo_method(canvas_item, "edit_set_pivot", se->undo_pivot);
+ 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);
@@ -1709,7 +1709,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
BoneIK bik;
bik.node = b;
bik.len = len;
- bik.orig_state = b->edit_get_state();
+ bik.orig_state = b->_edit_get_state();
bone_ik_list.push_back(bik);
@@ -1741,13 +1741,13 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
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();
+ 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();
+ 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->get_item_rect();
+ se->pre_drag_rect = canvas_item->_edit_get_rect();
return;
}
@@ -1764,13 +1764,13 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
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();
+ 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();
+ 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->get_item_rect();
+ se->pre_drag_rect = canvas_item->_edit_get_rect();
return;
}
@@ -1780,9 +1780,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
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->undo_state = canvas_item->_edit_get_state();
se->pre_drag_xform = canvas_item->get_global_transform_with_canvas();
- se->pre_drag_rect = canvas_item->get_item_rect();
+ se->pre_drag_rect = canvas_item->_edit_get_rect();
return;
}
}
@@ -1890,9 +1890,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
bool dragging_bone = drag == DRAG_ALL && selection.size() == 1 && bone_ik_list.size();
if (!dragging_bone) {
- canvas_item->edit_set_state(se->undo_state); //reset state and reapply
+ 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);
+ 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);
}
@@ -2003,10 +2003,10 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
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->get_item_rect();
+ 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();
+ Vector2 minsize = canvas_item->_edit_get_minimum_size();
if (uniform) {
// Keep the height/width ratio of the item
@@ -2084,7 +2084,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
if (Object::cast_to<Node2D>(canvas_item)) {
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
- n2d->edit_set_pivot(se->undo_pivot + drag_vector);
+ 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);
@@ -2103,7 +2103,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
local_rect.position = begin;
local_rect.size = end - begin;
- canvas_item->edit_set_rect(local_rect);
+ canvas_item->_edit_set_rect(local_rect);
} else {
//ok, all that had to be done was done, now solve IK
@@ -2454,7 +2454,7 @@ void CanvasItemEditor::_draw_selection() {
if (!se)
continue;
- Rect2 rect = canvas_item->get_item_rect();
+ Rect2 rect = canvas_item->_edit_get_rect();
if (show_helpers && drag != DRAG_NONE && drag != DRAG_PIVOT) {
const Transform2D pre_drag_xform = transform * se->pre_drag_xform;
@@ -2496,7 +2496,7 @@ void CanvasItemEditor::_draw_selection() {
Node2D *node2d = Object::cast_to<Node2D>(canvas_item);
if (node2d) {
- if (node2d->edit_has_pivot()) {
+ 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;
@@ -2868,7 +2868,7 @@ void CanvasItemEditor::_get_encompassing_rect(Node *p_node, Rect2 &r_rect, const
CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
if (c && c->is_visible_in_tree()) {
- Rect2 rect = c->get_item_rect();
+ 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)));
@@ -2963,7 +2963,7 @@ void CanvasItemEditor::_notification(int p_what) {
if (!se)
continue;
- Rect2 r = canvas_item->get_item_rect();
+ Rect2 r = canvas_item->_edit_get_rect();
Transform2D xform = canvas_item->get_transform();
if (r != se->prev_rect || xform != se->prev_xform) {
@@ -3899,7 +3899,7 @@ void CanvasItemEditor::_focus_selection(int p_op) {
//if (!canvas_item->is_visible_in_tree()) continue;
++count;
- Rect2 item_rect = canvas_item->get_item_rect();
+ Rect2 item_rect = canvas_item->_edit_get_rect();
Vector2 pos = canvas_item->get_global_transform().get_origin();
Vector2 scale = canvas_item->get_global_transform().get_scale();
@@ -4373,11 +4373,11 @@ void CanvasItemEditorViewport::_on_mouse_exit() {
void CanvasItemEditorViewport::_on_select_type(Object *selected) {
CheckBox *check = Object::cast_to<CheckBox>(selected);
String type = check->get_text();
- selector_label->set_text(vformat(TTR("Add %s"), type));
+ selector->set_title(vformat(TTR("Add %s"), type));
label->set_text(vformat(TTR("Adding %s..."), type));
}
-void CanvasItemEditorViewport::_on_change_type() {
+void CanvasItemEditorViewport::_on_change_type_confirmed() {
if (!button_group->get_pressed_button())
return;
@@ -4387,6 +4387,11 @@ void CanvasItemEditorViewport::_on_change_type() {
selector->hide();
}
+void CanvasItemEditorViewport::_on_change_type_closed() {
+
+ _remove_preview();
+}
+
void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) const {
label->set_position(get_global_position() + Point2(14, 14) * EDSCALE);
label_desc->set_position(label->get_position() + Point2(0, label->get_size().height));
@@ -4698,7 +4703,7 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]);
check->set_pressed(check->get_text() == default_type);
}
- selector_label->set_text(vformat(TTR("Add %s"), default_type));
+ selector->set_title(vformat(TTR("Add %s"), default_type));
selector->popup_centered_minsize();
} else {
_perform_drop_data();
@@ -4721,7 +4726,8 @@ void CanvasItemEditorViewport::_notification(int p_what) {
void CanvasItemEditorViewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_select_type"), &CanvasItemEditorViewport::_on_select_type);
- ClassDB::bind_method(D_METHOD("_on_change_type"), &CanvasItemEditorViewport::_on_change_type);
+ ClassDB::bind_method(D_METHOD("_on_change_type_confirmed"), &CanvasItemEditorViewport::_on_change_type_confirmed);
+ ClassDB::bind_method(D_METHOD("_on_change_type_closed"), &CanvasItemEditorViewport::_on_change_type_closed);
ClassDB::bind_method(D_METHOD("_on_mouse_exit"), &CanvasItemEditorViewport::_on_mouse_exit);
}
@@ -4749,7 +4755,8 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
selector = memnew(AcceptDialog);
editor->get_gui_base()->add_child(selector);
selector->set_title(TTR("Change default type"));
- selector->connect("confirmed", this, "_on_change_type");
+ selector->connect("confirmed", this, "_on_change_type_confirmed");
+ selector->connect("popup_hide", this, "_on_change_type_closed");
VBoxContainer *vbc = memnew(VBoxContainer);
selector->add_child(vbc);
@@ -4757,12 +4764,6 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
vbc->set_v_size_flags(SIZE_EXPAND_FILL);
vbc->set_custom_minimum_size(Size2(200, 260) * EDSCALE);
- selector_label = memnew(Label);
- vbc->add_child(selector_label);
- selector_label->set_align(Label::ALIGN_CENTER);
- selector_label->set_valign(Label::VALIGN_BOTTOM);
- selector_label->set_custom_minimum_size(Size2(0, 30) * EDSCALE);
-
btn_group = memnew(VBoxContainer);
vbc->add_child(btn_group);
btn_group->set_h_size_flags(0);
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 97e3b03569..457833e1a7 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -568,7 +568,8 @@ class CanvasItemEditorViewport : public Control {
void _on_mouse_exit();
void _on_select_type(Object *selected);
- void _on_change_type();
+ void _on_change_type_confirmed();
+ void _on_change_type_closed();
void _create_preview(const Vector<String> &files) const;
void _remove_preview();
diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp
index 24c4813771..0818c8975e 100644
--- a/editor/plugins/collision_polygon_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_editor_plugin.cpp
@@ -389,7 +389,7 @@ void CollisionPolygonEditor::_polygon_draw() {
rect = rect.grow(1);
- Rect3 r;
+ AABB r;
r.position.x = rect.position.x;
r.position.y = rect.position.y;
r.position.z = depth;
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index 5f73d0b465..ed04c90cc5 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -184,7 +184,7 @@ Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from) {
Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) {
- String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp");
+ String temp_path = EditorSettings::get_singleton()->get_cache_dir();
String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text();
cache_base = temp_path.plus_file("resthumb-" + cache_base);
@@ -790,13 +790,13 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) {
VS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid());
- Rect3 aabb = mesh->get_aabb();
+ AABB aabb = mesh->get_aabb();
Vector3 ofs = aabb.position + aabb.size * 0.5;
aabb.position -= ofs;
Transform xform;
xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.125);
xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.125) * xform.basis;
- Rect3 rot_aabb = xform.xform(aabb);
+ AABB rot_aabb = xform.xform(aabb);
float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5;
if (m == 0)
return Ref<Texture>();
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index bd4891ccb7..1fc112896d 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/editor/plugins/material_editor_plugin.cpp
@@ -503,3 +503,41 @@ Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_
smat->set_render_priority(mat->get_render_priority());
return smat;
}
+
+String CanvasItemMaterialConversionPlugin::converts_to() const {
+
+ return "ShaderMaterial";
+}
+bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const {
+
+ Ref<CanvasItemMaterial> mat = p_resource;
+ return mat.is_valid();
+}
+Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) {
+
+ Ref<CanvasItemMaterial> mat = p_resource;
+ ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>());
+
+ Ref<ShaderMaterial> smat;
+ smat.instance();
+
+ Ref<Shader> shader;
+ shader.instance();
+
+ String code = VS::get_singleton()->shader_get_code(mat->get_shader_rid());
+
+ shader->set_code(code);
+
+ smat->set_shader(shader);
+
+ List<PropertyInfo> params;
+ VS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), &params);
+
+ for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) {
+ Variant value = VS::get_singleton()->material_get_param(mat->get_rid(), E->get().name);
+ smat->set_shader_param(E->get().name, value);
+ }
+
+ smat->set_render_priority(mat->get_render_priority());
+ return smat;
+}
diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h
index 52c73cb7d8..2cc24be33a 100644
--- a/editor/plugins/material_editor_plugin.h
+++ b/editor/plugins/material_editor_plugin.h
@@ -119,4 +119,12 @@ public:
virtual Ref<Resource> convert(const Ref<Resource> &p_resource);
};
+class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin {
+ GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin)
+public:
+ virtual String converts_to() const;
+ virtual bool handles(const Ref<Resource> &p_resource) const;
+ virtual Ref<Resource> convert(const Ref<Resource> &p_resource);
+};
+
#endif // MATERIAL_EDITOR_PLUGIN_H
diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp
index 74618aecc2..60e8858b2d 100644
--- a/editor/plugins/mesh_editor_plugin.cpp
+++ b/editor/plugins/mesh_editor_plugin.cpp
@@ -95,7 +95,7 @@ void MeshEditor::edit(Ref<Mesh> p_mesh) {
rot_y = 0;
_update_rotation();
- Rect3 aabb = mesh->get_aabb();
+ AABB aabb = mesh->get_aabb();
print_line("aabb: " + aabb);
Vector3 ofs = aabb.position + aabb.size * 0.5;
float m = aabb.get_longest_axis_size();
diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp
index 10834b74ff..f4a9960087 100644
--- a/editor/plugins/particles_editor_plugin.cpp
+++ b/editor/plugins/particles_editor_plugin.cpp
@@ -153,15 +153,15 @@ void ParticlesEditor::_generate_aabb() {
EditorProgress ep("gen_aabb", TTR("Generating AABB"), int(time));
- Rect3 rect;
+ AABB rect;
while (running < time) {
uint64_t ticks = OS::get_singleton()->get_ticks_usec();
ep.step("Generating..", int(running), true);
OS::get_singleton()->delay_usec(1000);
- Rect3 capture = node->capture_aabb();
- if (rect == Rect3())
+ AABB capture = node->capture_aabb();
+ if (rect == AABB())
rect = capture;
else
rect.merge_with(capture);
@@ -247,7 +247,7 @@ void ParticlesEditor::_generate_emission_points() {
PoolVector<Face3>::Read r = geometry.read();
- Rect3 aabb;
+ AABB aabb;
for (int i = 0; i < gcount; i++) {
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index a1183307fb..32ec9b2ba9 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -586,6 +586,32 @@ void ScriptEditor::_close_docs_tab() {
}
}
+void ScriptEditor::_close_other_tabs() {
+
+ int child_count = tab_container->get_child_count();
+ int current_idx = tab_container->get_current_tab();
+ for (int i = child_count - 1; i >= 0; i--) {
+
+ if (i == current_idx) {
+ continue;
+ }
+
+ tab_container->set_current_tab(i);
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
+
+ if (se) {
+
+ // Maybe there are unsaved changes
+ if (se->is_unsaved()) {
+ _ask_close_current_unsaved_tab(se);
+ continue;
+ }
+ }
+
+ _close_current_tab();
+ }
+}
+
void ScriptEditor::_close_all_tabs() {
int child_count = tab_container->get_child_count();
@@ -855,7 +881,7 @@ void ScriptEditor::_menu_option(int p_option) {
file_dialog_option = FILE_SAVE_THEME_AS;
file_dialog->clear_filters();
file_dialog->add_filter("*.tet");
- file_dialog->set_current_path(EditorSettings::get_singleton()->get_settings_path() + "/text_editor_themes/" + EditorSettings::get_singleton()->get("text_editor/theme/color_theme"));
+ file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme")));
file_dialog->popup_centered_ratio();
file_dialog->set_title(TTR("Save Theme As.."));
} break;
@@ -865,20 +891,7 @@ void ScriptEditor::_menu_option(int p_option) {
} break;
case SEARCH_CLASSES: {
- String current;
-
- if (tab_container->get_tab_count() > 0) {
- EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(tab_container->get_current_tab()));
- if (eh) {
- current = eh->get_class();
- }
- }
-
help_index->popup();
-
- if (current != "") {
- help_index->call_deferred("select_class", current);
- }
} break;
case SEARCH_WEBSITE: {
@@ -890,8 +903,13 @@ void ScriptEditor::_menu_option(int p_option) {
_history_forward();
} break;
case WINDOW_PREV: {
+
_history_back();
} break;
+ case WINDOW_SORT: {
+ _sort_list_on_update = true;
+ _update_script_names();
+ } break;
case DEBUG_SHOW: {
if (debugger) {
bool visible = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW));
@@ -926,10 +944,6 @@ void ScriptEditor::_menu_option(int p_option) {
if (current) {
switch (p_option) {
- case FILE_NEW: {
- script_create_dialog->config("Node", ".gd");
- script_create_dialog->popup_centered(Size2(300, 300) * EDSCALE);
- } break;
case FILE_SAVE: {
if (_test_script_times_on_disk())
@@ -1015,6 +1029,9 @@ void ScriptEditor::_menu_option(int p_option) {
case CLOSE_DOCS: {
_close_docs_tab();
} break;
+ case CLOSE_OTHER_TABS: {
+ _close_other_tabs();
+ } break;
case CLOSE_ALL: {
_close_all_tabs();
} break;
@@ -1041,26 +1058,22 @@ void ScriptEditor::_menu_option(int p_option) {
debugger->debug_continue();
} break;
- case WINDOW_MOVE_LEFT: {
+ case WINDOW_MOVE_UP: {
if (tab_container->get_current_tab() > 0) {
- tab_container->call_deferred("set_current_tab", tab_container->get_current_tab() - 1);
- script_list->call_deferred("select", tab_container->get_current_tab() - 1);
tab_container->move_child(current, tab_container->get_current_tab() - 1);
+ tab_container->set_current_tab(tab_container->get_current_tab() - 1);
_update_script_names();
}
} break;
- case WINDOW_MOVE_RIGHT: {
+ case WINDOW_MOVE_DOWN: {
if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) {
- tab_container->call_deferred("set_current_tab", tab_container->get_current_tab() + 1);
- script_list->call_deferred("select", tab_container->get_current_tab() + 1);
tab_container->move_child(current, tab_container->get_current_tab() + 1);
+ tab_container->set_current_tab(tab_container->get_current_tab() + 1);
_update_script_names();
}
-
} break;
-
default: {
if (p_option >= WINDOW_SELECT_BASE) {
@@ -1077,6 +1090,11 @@ void ScriptEditor::_menu_option(int p_option) {
switch (p_option) {
+ case SEARCH_CLASSES: {
+
+ help_index->popup();
+ help_index->call_deferred("select_class", help->get_class());
+ } break;
case HELP_SEARCH_FIND: {
help->popup_search();
} break;
@@ -1089,9 +1107,28 @@ void ScriptEditor::_menu_option(int p_option) {
case CLOSE_DOCS: {
_close_docs_tab();
} break;
+ case CLOSE_OTHER_TABS: {
+ _close_other_tabs();
+ } break;
case CLOSE_ALL: {
_close_all_tabs();
} break;
+ case WINDOW_MOVE_UP: {
+
+ if (tab_container->get_current_tab() > 0) {
+ tab_container->move_child(help, tab_container->get_current_tab() - 1);
+ tab_container->set_current_tab(tab_container->get_current_tab() - 1);
+ _update_script_names();
+ }
+ } break;
+ case WINDOW_MOVE_DOWN: {
+
+ if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) {
+ tab_container->move_child(help, tab_container->get_current_tab() + 1);
+ tab_container->set_current_tab(tab_container->get_current_tab() + 1);
+ _update_script_names();
+ }
+ } break;
}
}
}
@@ -1114,6 +1151,7 @@ void ScriptEditor::_notification(int p_what) {
editor->connect("script_add_function_request", this, "_add_callback");
editor->connect("resource_saved", this, "_res_saved_callback");
script_list->connect("item_selected", this, "_script_selected");
+
members_overview->connect("item_selected", this, "_members_overview_selected");
help_overview->connect("item_selected", this, "_help_overview_selected");
script_split->connect("dragged", this, "_script_split_dragged");
@@ -1361,6 +1399,7 @@ struct _ScriptEditorItemData {
String tooltip;
bool used;
int category;
+ Node *ref;
bool operator<(const _ScriptEditorItemData &id) const {
@@ -1526,6 +1565,7 @@ void ScriptEditor::_update_script_names() {
sd.index = i;
sd.used = used.has(se->get_edited_script());
sd.category = 0;
+ sd.ref = se;
switch (sort_by) {
case SORT_BY_NAME: {
@@ -1565,16 +1605,38 @@ void ScriptEditor::_update_script_names() {
_ScriptEditorItemData sd;
sd.icon = icon;
sd.name = name;
- sd.sort_key = name;
+ sd.sort_key = name.to_lower();
sd.tooltip = tooltip;
sd.index = i;
sd.used = false;
sd.category = split_script_help ? 1 : 0;
+ sd.ref = eh;
+
sedata.push_back(sd);
}
}
- sedata.sort();
+ if (_sort_list_on_update && !sedata.empty()) {
+ sedata.sort();
+
+ // change actual order of tab_container so that the order can be rearranged by user
+ int cur_tab = tab_container->get_current_tab();
+ int prev_tab = tab_container->get_previous_tab();
+ int new_cur_tab = -1;
+ int new_prev_tab = -1;
+ for (int i = 0; i < sedata.size(); i++) {
+ tab_container->move_child(sedata[i].ref, i);
+ if (new_prev_tab == -1 && sedata[i].index == prev_tab) {
+ new_prev_tab = i;
+ }
+ if (new_cur_tab == -1 && sedata[i].index == cur_tab) {
+ new_cur_tab = i;
+ }
+ }
+ tab_container->call_deferred("set_current_tab", new_prev_tab);
+ tab_container->call_deferred("set_current_tab", new_cur_tab);
+ _sort_list_on_update = false;
+ }
for (int i = 0; i < sedata.size(); i++) {
@@ -1903,8 +1965,171 @@ void ScriptEditor::_script_split_dragged(float) {
_save_layout();
}
+Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
+
+ // return Variant(); // return this if drag disabled
+
+ Node *cur_node = tab_container->get_child(tab_container->get_current_tab());
+
+ HBoxContainer *drag_preview = memnew(HBoxContainer);
+ String preview_name = "";
+ Ref<Texture> preview_icon;
+
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(cur_node);
+ if (se) {
+ preview_name = se->get_name();
+ preview_icon = se->get_icon();
+ }
+ EditorHelp *eh = Object::cast_to<EditorHelp>(cur_node);
+ if (eh) {
+ preview_name = eh->get_class();
+ preview_icon = get_icon("Help", "EditorIcons");
+ }
+
+ if (!preview_icon.is_null()) {
+ TextureRect *tf = memnew(TextureRect);
+ tf->set_texture(preview_icon);
+ drag_preview->add_child(tf);
+ }
+ Label *label = memnew(Label(preview_name));
+ drag_preview->add_child(label);
+ set_drag_preview(drag_preview);
+
+ Dictionary drag_data;
+ drag_data["type"] = "script_list_element"; // using a custom type because node caused problems when dragging to scene tree
+ drag_data["script_list_element"] = cur_node;
+
+ return drag_data;
+}
+
+bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
+
+ Dictionary d = p_data;
+ if (!d.has("type"))
+ return false;
+
+ if (String(d["type"]) == "script_list_element") {
+
+ Node *node = d["script_list_element"];
+
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
+ if (se) {
+ return true;
+ }
+ EditorHelp *eh = Object::cast_to<EditorHelp>(node);
+ if (eh) {
+ return true;
+ }
+ }
+
+ if (String(d["type"]) == "nodes") {
+
+ Array nodes = d["nodes"];
+ if (nodes.size() == 0)
+ return false;
+ Node *node = get_node((nodes[0]));
+
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
+ if (se) {
+ return true;
+ }
+ EditorHelp *eh = Object::cast_to<EditorHelp>(node);
+ if (eh) {
+ return true;
+ }
+ }
+
+ if (String(d["type"]) == "files") {
+
+ Vector<String> files = d["files"];
+
+ if (files.size() == 0)
+ return false; //weird
+
+ for (int i = 0; i < files.size(); i++) {
+ String file = files[i];
+ if (file == "" || !FileAccess::exists(file))
+ continue;
+ Ref<Script> scr = ResourceLoader::load(file);
+ if (scr.is_valid()) {
+ return true;
+ }
+ }
+ return true;
+ }
+
+ return false;
+}
+
+void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
+
+ if (!can_drop_data_fw(p_point, p_data, p_from))
+ return;
+
+ Dictionary d = p_data;
+ if (!d.has("type"))
+ return;
+
+ if (String(d["type"]) == "script_list_element") {
+
+ Node *node = d["script_list_element"];
+
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
+ EditorHelp *eh = Object::cast_to<EditorHelp>(node);
+ if (se || eh) {
+ int new_index = script_list->get_item_at_position(p_point);
+ tab_container->move_child(node, new_index);
+ tab_container->set_current_tab(new_index);
+ _update_script_names();
+ }
+ }
+
+ if (String(d["type"]) == "nodes") {
+
+ Array nodes = d["nodes"];
+ if (nodes.size() == 0)
+ return;
+ Node *node = get_node(nodes[0]);
+
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
+ EditorHelp *eh = Object::cast_to<EditorHelp>(node);
+ if (se || eh) {
+ int new_index = script_list->get_item_at_position(p_point);
+ tab_container->move_child(node, new_index);
+ tab_container->set_current_tab(new_index);
+ _update_script_names();
+ }
+ }
+
+ if (String(d["type"]) == "files") {
+
+ Vector<String> files = d["files"];
+
+ int new_index = script_list->get_item_at_position(p_point);
+ int num_tabs_before = tab_container->get_child_count();
+ for (int i = 0; i < files.size(); i++) {
+ String file = files[i];
+ if (file == "" || !FileAccess::exists(file))
+ continue;
+ Ref<Script> scr = ResourceLoader::load(file);
+ if (scr.is_valid()) {
+ edit(scr);
+ if (tab_container->get_child_count() > num_tabs_before) {
+ tab_container->move_child(tab_container->get_child(tab_container->get_child_count() - 1), new_index);
+ num_tabs_before = tab_container->get_child_count();
+ } else {
+ tab_container->move_child(tab_container->get_child(tab_container->get_current_tab()), new_index);
+ }
+ }
+ }
+ tab_container->set_current_tab(new_index);
+ _update_script_names();
+ }
+}
+
void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
- if (p_event->is_pressed() || !is_visible_in_tree()) return;
+ if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo())
+ return;
if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) {
int next_tab = script_list->get_current() + 1;
next_tab %= script_list->get_item_count();
@@ -1917,6 +2142,64 @@ void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
_go_to_tab(script_list->get_item_metadata(next_tab));
_update_script_names();
}
+ if (ED_IS_SHORTCUT("script_editor/window_move_up", p_event)) {
+ _menu_option(WINDOW_MOVE_UP);
+ }
+ if (ED_IS_SHORTCUT("script_editor/window_move_down", p_event)) {
+ _menu_option(WINDOW_MOVE_DOWN);
+ }
+}
+
+void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) {
+
+ Ref<InputEventMouseButton> mb = ev;
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
+
+ _make_script_list_context_menu();
+ }
+}
+
+void ScriptEditor::_make_script_list_context_menu() {
+
+ context_menu->clear();
+
+ int selected = tab_container->get_current_tab();
+ if (selected < 0 || selected >= tab_container->get_child_count())
+ return;
+
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
+ if (se) {
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/save"), FILE_SAVE);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/save_as"), FILE_SAVE_AS);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_file"), FILE_CLOSE);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_all"), CLOSE_ALL);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_other_tabs"), CLOSE_OTHER_TABS);
+ context_menu->add_separator();
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT);
+
+ Ref<Script> scr = se->get_edited_script();
+ if (!scr.is_null() && scr->is_tool()) {
+ context_menu->add_separator();
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/run_file"), FILE_RUN);
+ }
+ } else {
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_file"), FILE_CLOSE);
+ }
+
+ EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(selected));
+ if (eh) {
+ // nothing
+ }
+
+ context_menu->add_separator();
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_up"), WINDOW_MOVE_UP);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_down"), WINDOW_MOVE_DOWN);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_sort"), WINDOW_SORT);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/toggle_scripts_panel"), TOGGLE_SCRIPTS_PANEL);
+
+ context_menu->set_position(get_global_transform().xform(get_local_mouse_position()));
+ context_menu->set_size(Vector2(1, 1));
+ context_menu->popup();
}
void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
@@ -2210,6 +2493,7 @@ void ScriptEditor::_bind_methods() {
ClassDB::bind_method("_close_discard_current_tab", &ScriptEditor::_close_discard_current_tab);
ClassDB::bind_method("_close_docs_tab", &ScriptEditor::_close_docs_tab);
ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs);
+ ClassDB::bind_method("_close_other_tabs", &ScriptEditor::_close_other_tabs);
ClassDB::bind_method("_open_recent_script", &ScriptEditor::_open_recent_script);
ClassDB::bind_method("_editor_play", &ScriptEditor::_editor_play);
ClassDB::bind_method("_editor_pause", &ScriptEditor::_editor_pause);
@@ -2243,9 +2527,14 @@ void ScriptEditor::_bind_methods() {
ClassDB::bind_method("_history_back", &ScriptEditor::_history_back);
ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts);
ClassDB::bind_method("_unhandled_input", &ScriptEditor::_unhandled_input);
+ ClassDB::bind_method("_script_list_gui_input", &ScriptEditor::_script_list_gui_input);
ClassDB::bind_method("_script_changed", &ScriptEditor::_script_changed);
ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts);
+ ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ScriptEditor::get_drag_data_fw);
+ ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ScriptEditor::can_drop_data_fw);
+ ClassDB::bind_method(D_METHOD("drop_data_fw"), &ScriptEditor::drop_data_fw);
+
ClassDB::bind_method(D_METHOD("get_current_script"), &ScriptEditor::_get_current_script);
ClassDB::bind_method(D_METHOD("get_open_scripts"), &ScriptEditor::_get_open_scripts);
@@ -2286,6 +2575,14 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
script_list->set_v_size_flags(SIZE_EXPAND_FILL);
script_split->set_split_offset(140);
//list_split->set_split_offset(500);
+ _sort_list_on_update = true;
+ script_list->connect("gui_input", this, "_script_list_gui_input");
+ script_list->set_allow_rmb_select(true);
+ script_list->set_drag_forwarding(this);
+
+ context_menu = memnew(PopupMenu);
+ add_child(context_menu);
+ context_menu->connect("id_pressed", this, "_menu_option");
members_overview = memnew(ItemList);
list_split->add_child(members_overview);
@@ -2303,8 +2600,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
tab_container->set_h_size_flags(SIZE_EXPAND_FILL);
- ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_GREATER);
- ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_LESS);
+ ED_SHORTCUT("script_editor/window_sort", TTR("Sort"));
+ ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP);
+ ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN);
+ ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work
+ ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COLON);
set_process_unhandled_input(true);
file_menu = memnew(MenuButton);
@@ -2339,6 +2639,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL);
+ file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_other_tabs", TTR("Close Other Tabs")), CLOSE_OTHER_TABS);
file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/run_file", TTR("Run"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_X), FILE_RUN);
file_menu->get_popup()->add_separator();
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 03fc4da7ce..77ca4bc9d9 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -135,6 +135,7 @@ class ScriptEditor : public PanelContainer {
FILE_CLOSE,
CLOSE_DOCS,
CLOSE_ALL,
+ CLOSE_OTHER_TABS,
TOGGLE_SCRIPTS_PANEL,
FILE_TOOL_RELOAD,
FILE_TOOL_RELOAD_SOFT,
@@ -150,10 +151,11 @@ class ScriptEditor : public PanelContainer {
SEARCH_WEBSITE,
HELP_SEARCH_FIND,
HELP_SEARCH_FIND_NEXT,
- WINDOW_MOVE_LEFT,
- WINDOW_MOVE_RIGHT,
+ WINDOW_MOVE_UP,
+ WINDOW_MOVE_DOWN,
WINDOW_NEXT,
WINDOW_PREV,
+ WINDOW_SORT,
WINDOW_SELECT_BASE = 100
};
@@ -173,6 +175,7 @@ class ScriptEditor : public PanelContainer {
MenuButton *edit_menu;
MenuButton *script_search_menu;
MenuButton *debug_menu;
+ PopupMenu *context_menu;
Timer *autosave_timer;
uint64_t idle;
@@ -249,6 +252,7 @@ class ScriptEditor : public PanelContainer {
void _close_current_tab();
void _close_discard_current_tab(const String &p_str);
void _close_docs_tab();
+ void _close_other_tabs();
void _close_all_tabs();
void _ask_close_current_unsaved_tab(ScriptEditorBase *current);
@@ -292,6 +296,7 @@ class ScriptEditor : public PanelContainer {
void _update_members_overview_visibility();
void _update_members_overview();
void _update_script_names();
+ bool _sort_list_on_update;
void _members_overview_selected(int p_idx);
void _script_selected(int p_idx);
@@ -306,8 +311,15 @@ class ScriptEditor : public PanelContainer {
void _script_split_dragged(float);
+ Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
+ bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
+ void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
+
void _unhandled_input(const Ref<InputEvent> &p_event);
+ void _script_list_gui_input(const Ref<InputEvent> &ev);
+ void _make_script_list_context_menu();
+
void _help_search(String p_text);
void _help_index(String p_text);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index adf65c11e1..214f24b386 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -201,7 +201,7 @@ void ScriptTextEditor::_set_theme_for_script() {
text_edit->add_keyword_color("Rect2", basetype_color);
text_edit->add_keyword_color("Transform2D", basetype_color);
text_edit->add_keyword_color("Vector3", basetype_color);
- text_edit->add_keyword_color("Rect3", basetype_color);
+ text_edit->add_keyword_color("AABB", basetype_color);
text_edit->add_keyword_color("Basis", basetype_color);
text_edit->add_keyword_color("Plane", basetype_color);
text_edit->add_keyword_color("Transform", basetype_color);
@@ -518,7 +518,9 @@ void ScriptTextEditor::tag_saved_version() {
}
void ScriptTextEditor::goto_line(int p_line, bool p_with_error) {
- code_editor->get_text_edit()->call_deferred("cursor_set_line", p_line);
+ TextEdit *tx = code_editor->get_text_edit();
+ tx->unfold_line(p_line);
+ tx->call_deferred("cursor_set_line", p_line);
}
void ScriptTextEditor::ensure_focus() {
@@ -712,15 +714,6 @@ void ScriptTextEditor::_breakpoint_toggled(int p_row) {
ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(script->get_path(), p_row + 1, code_editor->get_text_edit()->is_line_set_as_breakpoint(p_row));
}
-static void swap_lines(TextEdit *tx, int line1, int line2) {
- String tmp = tx->get_line(line1);
- String tmp2 = tx->get_line(line2);
- tx->set_line(line2, tmp);
- tx->set_line(line1, tmp2);
-
- tx->cursor_set_line(line2);
-}
-
void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) {
Node *base = get_tree()->get_edited_scene_root();
@@ -799,39 +792,41 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c
void ScriptTextEditor::_edit_option(int p_op) {
+ TextEdit *tx = code_editor->get_text_edit();
+
switch (p_op) {
case EDIT_UNDO: {
- code_editor->get_text_edit()->undo();
- code_editor->get_text_edit()->call_deferred("grab_focus");
+
+ tx->undo();
+ tx->call_deferred("grab_focus");
} break;
case EDIT_REDO: {
- code_editor->get_text_edit()->redo();
- code_editor->get_text_edit()->call_deferred("grab_focus");
+
+ tx->redo();
+ tx->call_deferred("grab_focus");
} break;
case EDIT_CUT: {
- code_editor->get_text_edit()->cut();
- code_editor->get_text_edit()->call_deferred("grab_focus");
+ tx->cut();
+ tx->call_deferred("grab_focus");
} break;
case EDIT_COPY: {
- code_editor->get_text_edit()->copy();
- code_editor->get_text_edit()->call_deferred("grab_focus");
+ tx->copy();
+ tx->call_deferred("grab_focus");
} break;
case EDIT_PASTE: {
- code_editor->get_text_edit()->paste();
- code_editor->get_text_edit()->call_deferred("grab_focus");
+ tx->paste();
+ tx->call_deferred("grab_focus");
} break;
case EDIT_SELECT_ALL: {
- code_editor->get_text_edit()->select_all();
- code_editor->get_text_edit()->call_deferred("grab_focus");
-
+ tx->select_all();
+ tx->call_deferred("grab_focus");
} break;
case EDIT_MOVE_LINE_UP: {
- TextEdit *tx = code_editor->get_text_edit();
Ref<Script> scr = script;
if (scr.is_null())
return;
@@ -850,7 +845,11 @@ void ScriptTextEditor::_edit_option(int p_op) {
if (line_id == 0 || next_id < 0)
return;
- swap_lines(tx, line_id, next_id);
+ tx->unfold_line(line_id);
+ tx->unfold_line(next_id);
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
}
int from_line_up = from_line > 0 ? from_line - 1 : from_line;
int to_line_up = to_line > 0 ? to_line - 1 : to_line;
@@ -862,15 +861,17 @@ void ScriptTextEditor::_edit_option(int p_op) {
if (line_id == 0 || next_id < 0)
return;
- swap_lines(tx, line_id, next_id);
+ tx->unfold_line(line_id);
+ tx->unfold_line(next_id);
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
}
tx->end_complex_operation();
tx->update();
-
} break;
case EDIT_MOVE_LINE_DOWN: {
- TextEdit *tx = code_editor->get_text_edit();
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
@@ -889,7 +890,11 @@ void ScriptTextEditor::_edit_option(int p_op) {
if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count())
return;
- swap_lines(tx, line_id, next_id);
+ tx->unfold_line(line_id);
+ tx->unfold_line(next_id);
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
}
int from_line_down = from_line < tx->get_line_count() ? from_line + 1 : from_line;
int to_line_down = to_line < tx->get_line_count() ? to_line + 1 : to_line;
@@ -901,7 +906,11 @@ void ScriptTextEditor::_edit_option(int p_op) {
if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count())
return;
- swap_lines(tx, line_id, next_id);
+ tx->unfold_line(line_id);
+ tx->unfold_line(next_id);
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
}
tx->end_complex_operation();
tx->update();
@@ -909,7 +918,6 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break;
case EDIT_INDENT_LEFT: {
- TextEdit *tx = code_editor->get_text_edit();
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
@@ -934,11 +942,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
tx->end_complex_operation();
tx->update();
//tx->deselect();
-
} break;
case EDIT_INDENT_RIGHT: {
- TextEdit *tx = code_editor->get_text_edit();
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
@@ -955,11 +961,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
tx->end_complex_operation();
tx->update();
//tx->deselect();
-
} break;
case EDIT_DELETE_LINE: {
- TextEdit *tx = code_editor->get_text_edit();
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
@@ -968,13 +972,12 @@ void ScriptTextEditor::_edit_option(int p_op) {
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: {
- TextEdit *tx = code_editor->get_text_edit();
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
@@ -993,6 +996,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
tx->begin_complex_operation();
for (int i = from_line; i <= to_line; i++) {
+ tx->unfold_line(i);
if (i >= tx->get_line_count() - 1) {
tx->set_line(i, tx->get_line(i) + "\n");
}
@@ -1008,11 +1012,29 @@ void ScriptTextEditor::_edit_option(int p_op) {
tx->end_complex_operation();
tx->update();
+ } break;
+ case EDIT_FOLD_LINE: {
+
+ tx->fold_line(tx->cursor_get_line());
+ tx->update();
+ } break;
+ case EDIT_UNFOLD_LINE: {
+
+ tx->unfold_line(tx->cursor_get_line());
+ tx->update();
+ } break;
+ case EDIT_FOLD_ALL_LINES: {
+
+ tx->fold_all_lines();
+ tx->update();
+ } break;
+ case EDIT_UNFOLD_ALL_LINES: {
+ tx->unhide_all_lines();
+ tx->update();
} break;
case EDIT_TOGGLE_COMMENT: {
- TextEdit *tx = code_editor->get_text_edit();
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
@@ -1061,62 +1083,65 @@ void ScriptTextEditor::_edit_option(int p_op) {
tx->end_complex_operation();
tx->update();
//tx->deselect();
-
} break;
case EDIT_COMPLETE: {
- code_editor->get_text_edit()->query_code_comple();
-
+ tx->query_code_comple();
} break;
case EDIT_AUTO_INDENT: {
- TextEdit *te = code_editor->get_text_edit();
- String text = te->get_text();
+ String text = tx->get_text();
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
- te->begin_complex_operation();
+ tx->begin_complex_operation();
int begin, end;
- if (te->is_selection_active()) {
- begin = te->get_selection_from_line();
- end = te->get_selection_to_line();
+ if (tx->is_selection_active()) {
+ begin = tx->get_selection_from_line();
+ end = tx->get_selection_to_line();
// ignore if the cursor is not past the first column
- if (te->get_selection_to_column() == 0) {
+ if (tx->get_selection_to_column() == 0) {
end--;
}
} else {
begin = 0;
- end = te->get_line_count() - 1;
+ end = tx->get_line_count() - 1;
}
scr->get_language()->auto_indent_code(text, begin, end);
Vector<String> lines = text.split("\n");
for (int i = begin; i <= end; ++i) {
- te->set_line(i, lines[i]);
+ tx->set_line(i, lines[i]);
}
- te->end_complex_operation();
-
+ tx->end_complex_operation();
} break;
case EDIT_TRIM_TRAILING_WHITESAPCE: {
+
trim_trailing_whitespace();
} break;
case EDIT_CONVERT_INDENT_TO_SPACES: {
+
convert_indent_to_spaces();
} break;
case EDIT_CONVERT_INDENT_TO_TABS: {
+
convert_indent_to_tabs();
} break;
case EDIT_PICK_COLOR: {
+
color_panel->popup();
} break;
case EDIT_TO_UPPERCASE: {
+
_convert_case(UPPER);
} break;
case EDIT_TO_LOWERCASE: {
+
_convert_case(LOWER);
} break;
case EDIT_CAPITALIZE: {
+
_convert_case(CAPITALIZE);
} break;
case SEARCH_FIND: {
@@ -1141,41 +1166,47 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break;
case SEARCH_GOTO_LINE: {
- goto_line_dialog->popup_find_line(code_editor->get_text_edit());
+ goto_line_dialog->popup_find_line(tx);
} break;
case DEBUG_TOGGLE_BREAKPOINT: {
- int line = code_editor->get_text_edit()->cursor_get_line();
- bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line);
- code_editor->get_text_edit()->set_line_as_breakpoint(line, dobreak);
+
+ int line = tx->cursor_get_line();
+ bool dobreak = !tx->is_line_set_as_breakpoint(line);
+ tx->set_line_as_breakpoint(line, dobreak);
ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(), line + 1, dobreak);
} break;
case DEBUG_REMOVE_ALL_BREAKPOINTS: {
+
List<int> bpoints;
- code_editor->get_text_edit()->get_breakpoints(&bpoints);
+ tx->get_breakpoints(&bpoints);
for (List<int>::Element *E = bpoints.front(); E; E = E->next()) {
int line = E->get();
- bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line);
- code_editor->get_text_edit()->set_line_as_breakpoint(line, dobreak);
+ bool dobreak = !tx->is_line_set_as_breakpoint(line);
+ tx->set_line_as_breakpoint(line, dobreak);
ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(), line + 1, dobreak);
}
}
case DEBUG_GOTO_NEXT_BREAKPOINT: {
+
List<int> bpoints;
- code_editor->get_text_edit()->get_breakpoints(&bpoints);
+ tx->get_breakpoints(&bpoints);
if (bpoints.size() <= 0) {
return;
}
- int line = code_editor->get_text_edit()->cursor_get_line();
+ int line = tx->cursor_get_line();
+
// wrap around
if (line >= bpoints[bpoints.size() - 1]) {
- code_editor->get_text_edit()->cursor_set_line(bpoints[0]);
+ tx->unfold_line(bpoints[0]);
+ tx->cursor_set_line(bpoints[0]);
} else {
for (List<int>::Element *E = bpoints.front(); E; E = E->next()) {
int bline = E->get();
if (bline > line) {
- code_editor->get_text_edit()->cursor_set_line(bline);
+ tx->unfold_line(bline);
+ tx->cursor_set_line(bline);
return;
}
}
@@ -1183,21 +1214,24 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break;
case DEBUG_GOTO_PREV_BREAKPOINT: {
+
List<int> bpoints;
- code_editor->get_text_edit()->get_breakpoints(&bpoints);
+ tx->get_breakpoints(&bpoints);
if (bpoints.size() <= 0) {
return;
}
- int line = code_editor->get_text_edit()->cursor_get_line();
+ int line = tx->cursor_get_line();
// wrap around
if (line <= bpoints[0]) {
- code_editor->get_text_edit()->cursor_set_line(bpoints[bpoints.size() - 1]);
+ tx->unfold_line(bpoints[bpoints.size() - 1]);
+ tx->cursor_set_line(bpoints[bpoints.size() - 1]);
} else {
for (List<int>::Element *E = bpoints.back(); E; E = E->prev()) {
int bline = E->get();
if (bline < line) {
- code_editor->get_text_edit()->cursor_set_line(bline);
+ tx->unfold_line(bline);
+ tx->cursor_set_line(bline);
return;
}
}
@@ -1206,9 +1240,10 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break;
case HELP_CONTEXTUAL: {
- String text = code_editor->get_text_edit()->get_selection_text();
+
+ String text = tx->get_selection_text();
if (text == "")
- text = code_editor->get_text_edit()->get_word_under_cursor();
+ text = tx->get_word_under_cursor();
if (text != "") {
emit_signal("request_help_search", text);
}
@@ -1394,6 +1429,9 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
Vector2 mpos = mb->get_global_position() - tx->get_global_position();
bool have_selection = (tx->get_selection_text().length() > 0);
bool have_color = (tx->get_word_at_pos(mpos) == "Color");
+ int fold_state = 0;
+ bool can_fold = tx->can_fold(row);
+ bool is_folded = tx->is_folded(row);
if (have_color) {
String line = tx->get_line(row);
@@ -1424,7 +1462,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
have_color = false;
}
}
- _make_context_menu(have_selection, have_color);
+ _make_context_menu(have_selection, have_color, can_fold, is_folded);
}
}
}
@@ -1443,7 +1481,7 @@ void ScriptTextEditor::_color_changed(const Color &p_color) {
code_editor->get_text_edit()->set_line(color_line, new_line);
}
-void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) {
+void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_can_fold, bool p_is_folded) {
context_menu->clear();
if (p_selection) {
@@ -1463,6 +1501,13 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
}
+ if (p_can_fold) {
+ // can fold
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_line"), EDIT_FOLD_LINE);
+ } else if (p_is_folded) {
+ // can unfold
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_line"), EDIT_UNFOLD_LINE);
+ }
if (p_color) {
context_menu->add_separator();
context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR);
@@ -1526,6 +1571,10 @@ ScriptTextEditor::ScriptTextEditor() {
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_line"), EDIT_FOLD_LINE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_line"), EDIT_UNFOLD_LINE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
edit_menu->get_popup()->add_separator();
#ifdef OSX_ENABLED
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
@@ -1603,6 +1652,10 @@ void ScriptTextEditor::register_editor() {
ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0);
ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K);
ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_B);
+ ED_SHORTCUT("script_text_editor/fold_line", TTR("Fold Line"), KEY_MASK_ALT | KEY_LEFT);
+ ED_SHORTCUT("script_text_editor/unfold_line", TTR("Unfold Line"), KEY_MASK_ALT | KEY_RIGHT);
+ ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0);
+ ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0);
#ifdef OSX_ENABLED
ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL | KEY_SPACE);
#else
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index 83f3ea57c0..722015ef3e 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -91,6 +91,10 @@ class ScriptTextEditor : public ScriptEditorBase {
EDIT_TO_UPPERCASE,
EDIT_TO_LOWERCASE,
EDIT_CAPITALIZE,
+ EDIT_FOLD_LINE,
+ EDIT_UNFOLD_LINE,
+ EDIT_FOLD_ALL_LINES,
+ EDIT_UNFOLD_ALL_LINES,
SEARCH_FIND,
SEARCH_FIND_NEXT,
SEARCH_FIND_PREV,
@@ -118,7 +122,7 @@ protected:
static void _bind_methods();
void _edit_option(int p_op);
- void _make_context_menu(bool p_selection, bool p_color);
+ void _make_context_menu(bool p_selection, bool p_color, bool p_can_fold, bool p_is_folded);
void _text_edit_gui_input(const Ref<InputEvent> &ev);
void _color_changed(const Color &p_color);
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index f7dcc4b52d..49e4642049 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -248,6 +248,8 @@ void ShaderTextEditor::_validate_script() {
if (err != OK) {
String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
set_error(error_text);
+ for (int i = 0; i < get_text_edit()->get_line_count(); i++)
+ get_text_edit()->set_line_as_marked(i, false);
get_text_edit()->set_line_as_marked(sl.get_error_line() - 1, true);
} else {
@@ -269,55 +271,284 @@ ShaderTextEditor::ShaderTextEditor() {
void ShaderEditor::_menu_option(int p_option) {
- ShaderTextEditor *current = shader_editor;
-
switch (p_option) {
case EDIT_UNDO: {
-
- current->get_text_edit()->undo();
+ shader_editor->get_text_edit()->undo();
} break;
case EDIT_REDO: {
- current->get_text_edit()->redo();
-
+ shader_editor->get_text_edit()->redo();
} break;
case EDIT_CUT: {
-
- current->get_text_edit()->cut();
+ shader_editor->get_text_edit()->cut();
} break;
case EDIT_COPY: {
- current->get_text_edit()->copy();
-
+ shader_editor->get_text_edit()->copy();
} break;
case EDIT_PASTE: {
- current->get_text_edit()->paste();
-
+ shader_editor->get_text_edit()->paste();
} break;
case EDIT_SELECT_ALL: {
+ shader_editor->get_text_edit()->select_all();
+ } break;
+ case EDIT_MOVE_LINE_UP: {
+
+ TextEdit *tx = shader_editor->get_text_edit();
+ if (shader.is_null())
+ return;
+
+ tx->begin_complex_operation();
+ if (tx->is_selection_active()) {
+ int from_line = tx->get_selection_from_line();
+ int from_col = tx->get_selection_from_column();
+ int to_line = tx->get_selection_to_line();
+ int to_column = tx->get_selection_to_column();
+
+ for (int i = from_line; i <= to_line; i++) {
+ int line_id = i;
+ int next_id = i - 1;
+
+ if (line_id == 0 || next_id < 0)
+ return;
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
+ }
+ int from_line_up = from_line > 0 ? from_line - 1 : from_line;
+ int to_line_up = to_line > 0 ? to_line - 1 : to_line;
+ tx->select(from_line_up, from_col, to_line_up, to_column);
+ } else {
+ int line_id = tx->cursor_get_line();
+ int next_id = line_id - 1;
+
+ if (line_id == 0 || next_id < 0)
+ return;
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
+ }
+ tx->end_complex_operation();
+ tx->update();
+
+ } break;
+ case EDIT_MOVE_LINE_DOWN: {
+
+ TextEdit *tx = shader_editor->get_text_edit();
+ if (shader.is_null())
+ return;
+
+ tx->begin_complex_operation();
+ if (tx->is_selection_active()) {
+ int from_line = tx->get_selection_from_line();
+ int from_col = tx->get_selection_from_column();
+ int to_line = tx->get_selection_to_line();
+ int to_column = tx->get_selection_to_column();
+
+ for (int i = to_line; i >= from_line; i--) {
+ int line_id = i;
+ int next_id = i + 1;
+
+ if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count())
+ return;
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
+ }
+ int from_line_down = from_line < tx->get_line_count() ? from_line + 1 : from_line;
+ int to_line_down = to_line < tx->get_line_count() ? to_line + 1 : to_line;
+ tx->select(from_line_down, from_col, to_line_down, to_column);
+ } else {
+ int line_id = tx->cursor_get_line();
+ int next_id = line_id + 1;
+
+ if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count())
+ return;
+
+ tx->swap_lines(line_id, next_id);
+ tx->cursor_set_line(next_id);
+ }
+ tx->end_complex_operation();
+ tx->update();
+
+ } break;
+ case EDIT_INDENT_LEFT: {
+
+ TextEdit *tx = shader_editor->get_text_edit();
+ if (shader.is_null())
+ return;
+
+ tx->begin_complex_operation();
+ if (tx->is_selection_active()) {
+ tx->indent_selection_left();
+ } else {
+ int begin = tx->cursor_get_line();
+ String line_text = tx->get_line(begin);
+ // begins with tab
+ if (line_text.begins_with("\t")) {
+ line_text = line_text.substr(1, line_text.length());
+ tx->set_line(begin, line_text);
+ }
+ // begins with 4 spaces
+ else if (line_text.begins_with(" ")) {
+ line_text = line_text.substr(4, line_text.length());
+ tx->set_line(begin, line_text);
+ }
+ }
+ tx->end_complex_operation();
+ tx->update();
+ //tx->deselect();
+
+ } break;
+ case EDIT_INDENT_RIGHT: {
+
+ TextEdit *tx = shader_editor->get_text_edit();
+ if (shader.is_null())
+ return;
+
+ tx->begin_complex_operation();
+ if (tx->is_selection_active()) {
+ tx->indent_selection_right();
+ } else {
+ int begin = tx->cursor_get_line();
+ String line_text = tx->get_line(begin);
+ line_text = '\t' + line_text;
+ tx->set_line(begin, line_text);
+ }
+ tx->end_complex_operation();
+ tx->update();
+ //tx->deselect();
+
+ } break;
+ case EDIT_DELETE_LINE: {
- current->get_text_edit()->select_all();
+ TextEdit *tx = shader_editor->get_text_edit();
+ if (shader.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->cursor_set_line(line);
+ tx->end_complex_operation();
} break;
+ case EDIT_CLONE_DOWN: {
+
+ TextEdit *tx = shader_editor->get_text_edit();
+ if (shader.is_null())
+ return;
+
+ int from_line = tx->cursor_get_line();
+ int to_line = tx->cursor_get_line();
+ int column = tx->cursor_get_column();
+
+ if (tx->is_selection_active()) {
+ from_line = tx->get_selection_from_line();
+ to_line = tx->get_selection_to_line();
+ column = tx->cursor_get_column();
+ }
+ int next_line = to_line + 1;
+
+ tx->begin_complex_operation();
+ for (int i = from_line; i <= to_line; i++) {
+
+ if (i >= tx->get_line_count() - 1) {
+ tx->set_line(i, tx->get_line(i) + "\n");
+ }
+ String line_clone = tx->get_line(i);
+ tx->insert_at(line_clone, next_line);
+ next_line++;
+ }
+
+ tx->cursor_set_column(column);
+ if (tx->is_selection_active()) {
+ tx->select(to_line + 1, tx->get_selection_from_column(), next_line - 1, tx->get_selection_to_column());
+ }
+
+ tx->end_complex_operation();
+ tx->update();
+
+ } break;
+ case EDIT_TOGGLE_COMMENT: {
+
+ TextEdit *tx = shader_editor->get_text_edit();
+ if (shader.is_null())
+ return;
+
+ tx->begin_complex_operation();
+ if (tx->is_selection_active()) {
+ int begin = tx->get_selection_from_line();
+ int end = tx->get_selection_to_line();
+
+ // End of selection ends on the first column of the last line, ignore it.
+ if (tx->get_selection_to_column() == 0)
+ end -= 1;
+
+ // Check if all lines in the selected block are commented
+ bool is_commented = true;
+ for (int i = begin; i <= end; i++) {
+ if (!tx->get_line(i).begins_with("//")) {
+ is_commented = false;
+ break;
+ }
+ }
+ for (int i = begin; i <= end; i++) {
+ String line_text = tx->get_line(i);
+
+ if (line_text.strip_edges().empty()) {
+ line_text = "//";
+ } else {
+ if (is_commented) {
+ line_text = line_text.substr(2, line_text.length());
+ } else {
+ line_text = "//" + line_text;
+ }
+ }
+ tx->set_line(i, line_text);
+ }
+ } else {
+ int begin = tx->cursor_get_line();
+ String line_text = tx->get_line(begin);
+
+ if (line_text.begins_with("//"))
+ line_text = line_text.substr(2, line_text.length());
+ else
+ line_text = "//" + line_text;
+ tx->set_line(begin, line_text);
+ }
+ tx->end_complex_operation();
+ tx->update();
+ //tx->deselect();
+
+ } break;
+ case EDIT_COMPLETE: {
+
+ shader_editor->get_text_edit()->query_code_comple();
+ } break;
case SEARCH_FIND: {
- current->get_find_replace_bar()->popup_search();
+ shader_editor->get_find_replace_bar()->popup_search();
} break;
case SEARCH_FIND_NEXT: {
- current->get_find_replace_bar()->search_next();
+ shader_editor->get_find_replace_bar()->search_next();
} break;
case SEARCH_FIND_PREV: {
- current->get_find_replace_bar()->search_prev();
+ shader_editor->get_find_replace_bar()->search_prev();
} break;
case SEARCH_REPLACE: {
- current->get_find_replace_bar()->popup_replace();
+ shader_editor->get_find_replace_bar()->popup_replace();
} break;
case SEARCH_GOTO_LINE: {
- goto_line_dialog->popup_find_line(current->get_text_edit());
+ goto_line_dialog->popup_find_line(shader_editor->get_text_edit());
} break;
}
+ if (p_option != SEARCH_FIND && p_option != SEARCH_REPLACE && p_option != SEARCH_GOTO_LINE) {
+ shader_editor->get_text_edit()->call_deferred("grab_focus");
+ }
}
void ShaderEditor::_notification(int p_what) {
@@ -325,10 +556,6 @@ void ShaderEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
}
if (p_what == NOTIFICATION_DRAW) {
-
- RID ci = get_canvas_item();
- Ref<StyleBox> style = get_stylebox("panel", "Panel");
- style->draw(ci, Rect2(Point2(), get_size()));
}
}
@@ -360,6 +587,7 @@ void ShaderEditor::_editor_settings_changed() {
void ShaderEditor::_bind_methods() {
ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed);
+ ClassDB::bind_method("_text_edit_gui_input", &ShaderEditor::_text_edit_gui_input);
ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option);
ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed);
@@ -413,49 +641,122 @@ void ShaderEditor::apply_shaders() {
}
}
-ShaderEditor::ShaderEditor() {
+void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
- HBoxContainer *hbc = memnew(HBoxContainer);
+ Ref<InputEventMouseButton> mb = ev;
- add_child(hbc);
+ if (mb.is_valid()) {
+
+ if (mb->get_button_index() == BUTTON_RIGHT && !mb->is_pressed()) {
+
+ int col, row;
+ TextEdit *tx = shader_editor->get_text_edit();
+ tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col);
+ Vector2 mpos = mb->get_global_position() - tx->get_global_position();
+ bool have_selection = (tx->get_selection_text().length() > 0);
+ _make_context_menu(have_selection);
+ }
+ }
+}
+
+void ShaderEditor::_make_context_menu(bool p_selection) {
+
+ context_menu->clear();
+ if (p_selection) {
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
+ }
+
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ context_menu->add_separator();
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+
+ context_menu->add_separator();
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
+ context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
+
+ context_menu->set_position(get_global_transform().xform(get_local_mouse_position()));
+ context_menu->set_size(Vector2(1, 1));
+ context_menu->popup();
+}
+
+ShaderEditor::ShaderEditor(EditorNode *p_node) {
+
+ shader_editor = memnew(ShaderTextEditor);
+ shader_editor->set_v_size_flags(SIZE_EXPAND_FILL);
+ shader_editor->add_constant_override("separation", 0);
+ shader_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE);
+
+ shader_editor->connect("script_changed", this, "apply_shaders");
+ EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
+
+ shader_editor->get_text_edit()->set_callhint_settings(
+ EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"),
+ EditorSettings::get_singleton()->get("text_editor/completion/callhint_tooltip_offset"));
+
+ shader_editor->get_text_edit()->set_select_identifiers_on_hover(true);
+ shader_editor->get_text_edit()->set_context_menu_enabled(false);
+ shader_editor->get_text_edit()->connect("gui_input", this, "_text_edit_gui_input");
+
+ shader_editor->update_editor_settings();
+
+ context_menu = memnew(PopupMenu);
+ add_child(context_menu);
+ context_menu->connect("id_pressed", this, "_menu_option");
+
+ VBoxContainer *main_container = memnew(VBoxContainer);
+ HBoxContainer *hbc = memnew(HBoxContainer);
edit_menu = memnew(MenuButton);
- hbc->add_child(edit_menu);
- edit_menu->set_position(Point2(5, -1));
+ //edit_menu->set_position(Point2(5, -1));
edit_menu->set_text(TTR("Edit"));
- edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z), EDIT_UNDO);
- edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y), EDIT_REDO);
+
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
+ edit_menu->get_popup()->add_separator();
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
+ edit_menu->get_popup()->add_separator();
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X), EDIT_CUT);
- edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C), EDIT_COPY);
- edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V), EDIT_PASTE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A), EDIT_SELECT_ALL);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
+
edit_menu->get_popup()->connect("id_pressed", this, "_menu_option");
search_menu = memnew(MenuButton);
- hbc->add_child(search_menu);
- search_menu->set_position(Point2(38, -1));
+ //search_menu->set_position(Point2(38, -1));
search_menu->set_text(TTR("Search"));
- search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F), SEARCH_FIND);
- search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), SEARCH_FIND_NEXT);
- search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3), SEARCH_FIND_PREV);
- search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD | KEY_R), SEARCH_REPLACE);
+
+ search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
+ search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
+ search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
+ search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
search_menu->get_popup()->add_separator();
- //search_menu->get_popup()->add_item("Locate Symbol..",SEARCH_LOCATE_SYMBOL,KEY_MASK_CMD|KEY_K);
- search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD | KEY_L), SEARCH_GOTO_LINE);
+ search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
search_menu->get_popup()->connect("id_pressed", this, "_menu_option");
+ add_child(main_container);
+ main_container->add_child(hbc);
+ hbc->add_child(search_menu);
+ hbc->add_child(edit_menu);
+ hbc->add_style_override("panel", p_node->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles"));
+ main_container->add_child(shader_editor);
+
goto_line_dialog = memnew(GotoLineDialog);
add_child(goto_line_dialog);
- shader_editor = memnew(ShaderTextEditor);
- add_child(shader_editor);
- shader_editor->set_v_size_flags(SIZE_EXPAND_FILL);
-
- shader_editor->connect("script_changed", this, "apply_shaders");
- EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
-
_editor_settings_changed();
}
@@ -504,7 +805,7 @@ void ShaderEditorPlugin::apply_changes() {
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
editor = p_node;
- shader_editor = memnew(ShaderEditor);
+ shader_editor = memnew(ShaderEditor(p_node));
shader_editor->set_custom_minimum_size(Size2(0, 300));
button = editor->add_bottom_panel_item(TTR("Shader"), shader_editor);
diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h
index ab18784d9f..b191f5700f 100644
--- a/editor/plugins/shader_editor_plugin.h
+++ b/editor/plugins/shader_editor_plugin.h
@@ -33,6 +33,7 @@
#include "editor/code_editor.h"
#include "editor/editor_plugin.h"
#include "scene/gui/menu_button.h"
+#include "scene/gui/panel_container.h"
#include "scene/gui/tab_container.h"
#include "scene/gui/text_edit.h"
#include "scene/main/timer.h"
@@ -61,9 +62,9 @@ public:
ShaderTextEditor();
};
-class ShaderEditor : public VBoxContainer {
+class ShaderEditor : public PanelContainer {
- GDCLASS(ShaderEditor, VBoxContainer);
+ GDCLASS(ShaderEditor, PanelContainer);
enum {
@@ -73,6 +74,14 @@ class ShaderEditor : public VBoxContainer {
EDIT_COPY,
EDIT_PASTE,
EDIT_SELECT_ALL,
+ EDIT_MOVE_LINE_UP,
+ EDIT_MOVE_LINE_DOWN,
+ EDIT_INDENT_LEFT,
+ EDIT_INDENT_RIGHT,
+ EDIT_DELETE_LINE,
+ EDIT_CLONE_DOWN,
+ EDIT_TOGGLE_COMMENT,
+ EDIT_COMPLETE,
SEARCH_FIND,
SEARCH_FIND_NEXT,
SEARCH_FIND_PREV,
@@ -84,6 +93,7 @@ class ShaderEditor : public VBoxContainer {
MenuButton *edit_menu;
MenuButton *search_menu;
MenuButton *settings_menu;
+ PopupMenu *context_menu;
uint64_t idle;
GotoLineDialog *goto_line_dialog;
@@ -100,6 +110,8 @@ class ShaderEditor : public VBoxContainer {
protected:
void _notification(int p_what);
static void _bind_methods();
+ void _make_context_menu(bool p_selection);
+ void _text_edit_gui_input(const Ref<InputEvent> &ev);
public:
void apply_shaders();
@@ -110,7 +122,7 @@ public:
virtual Size2 get_minimum_size() const { return Size2(0, 200); }
void save_external_data();
- ShaderEditor();
+ ShaderEditor(EditorNode *p_node);
};
class ShaderEditorPlugin : public EditorPlugin {
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 7d9958989e..448daab226 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -758,17 +758,49 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig
}
}
+ bool is_plane_scale = false;
+ // plane select
+ if (col_axis == -1) {
+ col_d = 1e20;
+
+ for (int i = 0; i < 3; i++) {
+
+ Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized();
+ Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized();
+
+ Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST);
+
+ Vector3 r;
+ Plane plane(gt.origin, gt.basis.get_axis(i).normalized());
+
+ if (plane.intersects_ray(ray_pos, ray, &r)) {
+
+ float dist = r.distance_to(grabber_pos);
+ if (dist < (gs * GIZMO_PLANE_SIZE)) {
+
+ float d = ray_pos.distance_to(r);
+ if (d < col_d) {
+ col_d = d;
+ col_axis = i;
+
+ is_plane_scale = true;
+ }
+ }
+ }
+ }
+ }
+
if (col_axis != -1) {
if (p_highlight_only) {
- spatial_editor->select_gizmo_highlight_axis(col_axis + 9);
+ spatial_editor->select_gizmo_highlight_axis(col_axis + (is_plane_scale ? 12 : 9));
} else {
//handle scale
_edit.mode = TRANSFORM_SCALE;
_compute_edit(Point2(p_screenpos.x, p_screenpos.y));
- _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis);
+ _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis + (is_plane_scale ? 3 : 0));
}
return true;
}
@@ -1255,7 +1287,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Vector3 motion_mask;
Plane plane;
- bool plane_mv;
+ bool plane_mv = false;
switch (_edit.plane) {
case TRANSFORM_VIEW:
@@ -1274,6 +1306,21 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2);
plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
break;
+ case TRANSFORM_YZ:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(1);
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0));
+ plane_mv = true;
+ break;
+ case TRANSFORM_XZ:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(0);
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1));
+ plane_mv = true;
+ break;
+ case TRANSFORM_XY:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(0) + spatial_editor->get_gizmo_transform().basis.get_axis(1);
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2));
+ plane_mv = true;
+ break;
}
Vector3 intersection;
@@ -1285,8 +1332,19 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
break;
Vector3 motion = intersection - click;
- if (motion_mask != Vector3()) {
- motion = motion_mask.dot(motion) * motion_mask;
+ if (_edit.plane != TRANSFORM_VIEW) {
+
+ if (!plane_mv) {
+
+ motion = motion_mask.dot(motion) * motion_mask;
+
+ } else {
+
+ // Alternative planar scaling mode
+ if (_get_key_modifier(m) != KEY_SHIFT) {
+ motion = motion_mask.dot(motion) * motion_mask;
+ }
+ }
} else {
float center_click_dist = click.distance_to(_edit.center);
@@ -1300,7 +1358,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
List<Node *> &selection = editor_selection->get_selected_node_list();
- bool local_coords = (spatial_editor->are_local_coords_enabled() && motion_mask != Vector3()); // Disable local transformation for TRANSFORM_VIEW
+ bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW
float snap = 0;
if (_edit.snap || spatial_editor->is_snap_enabled()) {
@@ -1309,10 +1367,10 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Vector3 motion_snapped = motion;
motion_snapped.snap(Vector3(snap, snap, snap));
- set_message(TTR("Scaling XYZ: ") + motion_snapped);
+ set_message(TTR("Scaling: ") + motion_snapped);
} else {
- set_message(TTR("Scaling XYZ: ") + motion);
+ set_message(TTR("Scaling: ") + motion);
}
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
@@ -1380,11 +1438,10 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Vector3 motion_mask;
Plane plane;
- bool plane_mv;
+ bool plane_mv = false;
switch (_edit.plane) {
case TRANSFORM_VIEW:
- motion_mask = Vector3(0, 0, 0);
plane = Plane(_edit.center, _get_camera_normal());
break;
case TRANSFORM_X_AXIS:
@@ -1422,7 +1479,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
break;
Vector3 motion = intersection - click;
- if (motion_mask != Vector3()) {
+ if (_edit.plane != TRANSFORM_VIEW) {
if (!plane_mv) {
motion = motion_mask.dot(motion) * motion_mask;
}
@@ -1430,7 +1487,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
List<Node *> &selection = editor_selection->get_selected_node_list();
- bool local_coords = (spatial_editor->are_local_coords_enabled() && motion_mask != Vector3()); // Disable local transformation for TRANSFORM_VIEW
+ bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW
float snap = 0;
if (_edit.snap || spatial_editor->is_snap_enabled()) {
@@ -1544,7 +1601,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
List<Node *> &selection = editor_selection->get_selected_node_list();
- bool local_coords = spatial_editor->are_local_coords_enabled();
+ bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
@@ -1821,6 +1878,11 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (!k->is_pressed()) emit_signal("toggle_maximize_view", this);
}
}
+
+ // freelook uses most of the useful shortcuts, like save, so its ok
+ // to consider freelook active as end of the line for future events.
+ if (freelook_active)
+ accept_event();
}
void SpatialEditorViewport::set_freelook_active(bool active_now) {
@@ -2019,7 +2081,7 @@ void SpatialEditorViewport::_notification(int p_what) {
if (se->aabb.has_no_surface()) {
- se->aabb = vi ? vi->get_aabb() : Rect3(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4));
+ se->aabb = vi ? vi->get_aabb() : AABB(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4));
}
Transform t = sp->get_global_transform();
@@ -2107,6 +2169,29 @@ void SpatialEditorViewport::_notification(int p_what) {
}
}
+ // FPS Counter.
+ bool show_fps = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FPS));
+ if (show_fps != fps->is_visible()) {
+ if (show_fps)
+ fps->show();
+ else
+ fps->hide();
+ }
+
+ if (show_fps) {
+ String text;
+ const float temp_fps = Engine::get_singleton()->get_frames_per_second();
+ text += TTR("FPS") + ": " + itos(temp_fps) + " (" + String::num(1000.0f / temp_fps, 2) + " ms)";
+
+ if (fps_label->get_text() != text || surface->get_size() != prev_size) {
+ fps_label->set_text(text);
+ Size2 ms = fps->get_size();
+ Size2 size = surface->get_size();
+ size.y = ms.y + 20;
+ fps->set_position(size - ms - Vector2(20, 0) * EDSCALE);
+ }
+ }
+
prev_size = surface->get_size();
}
@@ -2117,6 +2202,7 @@ void SpatialEditorViewport::_notification(int p_what) {
surface->connect("mouse_entered", this, "_smouseenter");
surface->connect("mouse_exited", this, "_smouseexit");
info->add_style_override("panel", get_stylebox("panel", "Panel"));
+ fps->add_style_override("panel", get_stylebox("panel", "Panel"));
preview_camera->set_icon(get_icon("Camera", "EditorIcons"));
_init_gizmo_instance(index);
}
@@ -2439,6 +2525,13 @@ void SpatialEditorViewport::_menu_option(int p_option) {
view_menu->get_popup()->set_item_checked(idx, !current);
} break;
+ case VIEW_FPS: {
+
+ int idx = view_menu->get_popup()->get_item_index(VIEW_FPS);
+ bool current = view_menu->get_popup()->is_item_checked(idx);
+ view_menu->get_popup()->set_item_checked(idx, !current);
+
+ } break;
case VIEW_DISPLAY_NORMAL: {
viewport->set_debug_draw(Viewport::DEBUG_DRAW_DISABLED);
@@ -2524,6 +2617,14 @@ void SpatialEditorViewport::_init_gizmo_instance(int p_idx) {
//VS::get_singleton()->instance_geometry_set_flag(scale_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true);
VS::get_singleton()->instance_geometry_set_cast_shadows_setting(scale_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF);
VS::get_singleton()->instance_set_layer_mask(scale_gizmo_instance[i], layer);
+
+ scale_plane_gizmo_instance[i] = VS::get_singleton()->instance_create();
+ VS::get_singleton()->instance_set_base(scale_plane_gizmo_instance[i], spatial_editor->get_scale_plane_gizmo(i)->get_rid());
+ VS::get_singleton()->instance_set_scenario(scale_plane_gizmo_instance[i], get_tree()->get_root()->get_world()->get_scenario());
+ VS::get_singleton()->instance_set_visible(scale_plane_gizmo_instance[i], false);
+ //VS::get_singleton()->instance_geometry_set_flag(scale_plane_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true);
+ VS::get_singleton()->instance_geometry_set_cast_shadows_setting(scale_plane_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF);
+ VS::get_singleton()->instance_set_layer_mask(scale_plane_gizmo_instance[i], layer);
}
}
@@ -2534,6 +2635,7 @@ void SpatialEditorViewport::_finish_gizmo_instances() {
VS::get_singleton()->free(move_plane_gizmo_instance[i]);
VS::get_singleton()->free(rotate_gizmo_instance[i]);
VS::get_singleton()->free(scale_gizmo_instance[i]);
+ VS::get_singleton()->free(scale_plane_gizmo_instance[i]);
}
}
void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) {
@@ -2630,6 +2732,8 @@ void SpatialEditorViewport::update_transform_gizmo_view() {
VisualServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE));
VisualServer::get_singleton()->instance_set_transform(scale_gizmo_instance[i], xform);
VisualServer::get_singleton()->instance_set_visible(scale_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SCALE));
+ VisualServer::get_singleton()->instance_set_transform(scale_plane_gizmo_instance[i], xform);
+ VisualServer::get_singleton()->instance_set_visible(scale_plane_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SCALE));
}
}
@@ -2764,7 +2868,7 @@ void SpatialEditorViewport::focus_selection() {
cursor.pos = center;
}
-void SpatialEditorViewport::assign_pending_data_pointers(Spatial *p_preview_node, Rect3 *p_preview_bounds, AcceptDialog *p_accept) {
+void SpatialEditorViewport::assign_pending_data_pointers(Spatial *p_preview_node, AABB *p_preview_bounds, AcceptDialog *p_accept) {
preview_node = p_preview_node;
preview_bounds = p_preview_bounds;
accept = p_accept;
@@ -2827,14 +2931,14 @@ Vector3 SpatialEditorViewport::_get_instance_position(const Point2 &p_pos) const
return point + offset;
}
-Rect3 SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, const Rect3 p_bounds) {
- Rect3 bounds = p_bounds;
+AABB SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, const AABB p_bounds) {
+ AABB bounds = p_bounds;
for (int i = 0; i < p_parent->get_child_count(); i++) {
Spatial *child = Object::cast_to<Spatial>(p_parent->get_child(i));
if (child) {
MeshInstance *mesh_instance = Object::cast_to<MeshInstance>(child);
if (mesh_instance) {
- Rect3 mesh_instance_bounds = mesh_instance->get_aabb();
+ AABB mesh_instance_bounds = mesh_instance->get_aabb();
mesh_instance_bounds.position += mesh_instance->get_global_transform().origin - p_parent->get_global_transform().origin;
bounds.merge_with(mesh_instance_bounds);
}
@@ -2866,7 +2970,7 @@ void SpatialEditorViewport::_create_preview(const Vector<String> &files) const {
editor->get_scene_root()->add_child(preview_node);
}
}
- *preview_bounds = _calculate_spatial_bounds(preview_node, Rect3());
+ *preview_bounds = _calculate_spatial_bounds(preview_node, AABB());
}
void SpatialEditorViewport::_remove_preview() {
@@ -2929,7 +3033,9 @@ bool SpatialEditorViewport::_create_instance(Node *parent, String &path, const P
}
}
- instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path));
+ if (scene != NULL) {
+ instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path));
+ }
editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene);
editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", editor->get_edited_scene());
@@ -3155,6 +3261,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION);
+ view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_fps", TTR("View FPS")), VIEW_FPS);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT), true);
view_menu->get_popup()->add_separator();
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_half_resolution", TTR("Half Resolution")), VIEW_HALF_RESOLUTION);
@@ -3197,6 +3304,14 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
info->add_child(info_label);
info->hide();
+ // FPS Counter.
+ fps = memnew(PanelContainer);
+ fps->set_self_modulate(Color(1, 1, 1, 0.4));
+ surface->add_child(fps);
+ fps_label = memnew(Label);
+ fps->add_child(fps_label);
+ fps->hide();
+
accept = NULL;
freelook_active = false;
@@ -3534,13 +3649,14 @@ void SpatialEditor::select_gizmo_highlight_axis(int p_axis) {
move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? gizmo_hl : plane_gizmo_color[i]);
rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_hl : gizmo_color[i]);
scale_gizmo[i]->surface_set_material(0, (i + 9) == p_axis ? gizmo_hl : gizmo_color[i]);
+ scale_plane_gizmo[i]->surface_set_material(0, (i + 12) == p_axis ? gizmo_hl : plane_gizmo_color[i]);
}
}
void SpatialEditor::update_transform_gizmo() {
List<Node *> &selection = editor_selection->get_selected_node_list();
- Rect3 center;
+ AABB center;
bool first = true;
Basis gizmo_basis;
@@ -3601,7 +3717,7 @@ Object *SpatialEditor::_get_editor_data(Object *p_what) {
void SpatialEditor::_generate_selection_box() {
- Rect3 aabb(Vector3(), Vector3(1, 1, 1));
+ AABB aabb(Vector3(), Vector3(1, 1, 1));
aabb.grow_by(aabb.get_longest_axis_size() / 20.0);
Ref<SurfaceTool> st = memnew(SurfaceTool);
@@ -4145,6 +4261,7 @@ void SpatialEditor::_init_indicators() {
move_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
scale_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
+ scale_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
Ref<SpatialMaterial> mat = memnew(SpatialMaterial);
mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
@@ -4340,6 +4457,49 @@ void SpatialEditor::_init_indicators() {
surftool->set_material(mat);
surftool->commit(scale_gizmo[i]);
}
+
+ // Plane Scale
+ {
+ Ref<SurfaceTool> surftool = memnew(SurfaceTool);
+ surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
+
+ Vector3 vec = ivec2 - ivec3;
+ Vector3 plane[4] = {
+ vec * GIZMO_PLANE_DST,
+ vec * GIZMO_PLANE_DST + ivec2 * GIZMO_PLANE_SIZE,
+ vec * (GIZMO_PLANE_DST + GIZMO_PLANE_SIZE),
+ vec * GIZMO_PLANE_DST - ivec3 * GIZMO_PLANE_SIZE
+ };
+
+ Basis ma(ivec, Math_PI / 2);
+
+ Vector3 points[4] = {
+ ma.xform(plane[0]),
+ ma.xform(plane[1]),
+ ma.xform(plane[2]),
+ ma.xform(plane[3]),
+ };
+ surftool->add_vertex(points[0]);
+ surftool->add_vertex(points[1]);
+ surftool->add_vertex(points[2]);
+
+ surftool->add_vertex(points[0]);
+ surftool->add_vertex(points[2]);
+ surftool->add_vertex(points[3]);
+
+ Ref<SpatialMaterial> plane_mat = memnew(SpatialMaterial);
+ plane_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ plane_mat->set_on_top_of_alpha();
+ plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED);
+ Color col;
+ col[i] = 1.0;
+ col.a = gizmo_alph;
+ plane_mat->set_albedo(col);
+ plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides
+ surftool->set_material(plane_mat);
+ surftool->commit(scale_plane_gizmo[i]);
+ }
}
}
@@ -4708,7 +4868,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
// Drag and drop support;
preview_node = memnew(Spatial);
- preview_bounds = Rect3();
+ preview_bounds = AABB();
ED_SHORTCUT("spatial_editor/bottom_view", TTR("Bottom View"), KEY_MASK_ALT + KEY_KP_7);
ED_SHORTCUT("spatial_editor/top_view", TTR("Top View"), KEY_KP_7);
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 64acced01f..ad11ec33df 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -88,6 +88,7 @@ class SpatialEditorViewport : public Control {
VIEW_AUDIO_DOPPLER,
VIEW_GIZMOS,
VIEW_INFORMATION,
+ VIEW_FPS,
VIEW_DISPLAY_NORMAL,
VIEW_DISPLAY_WIREFRAME,
VIEW_DISPLAY_OVERDRAW,
@@ -108,7 +109,7 @@ private:
Size2 prev_size;
Spatial *preview_node;
- Rect3 *preview_bounds;
+ AABB *preview_bounds;
Vector<String> selected_files;
AcceptDialog *accept;
@@ -138,6 +139,9 @@ private:
PanelContainer *info;
Label *info_label;
+ PanelContainer *fps;
+ Label *fps_label;
+
struct _RayResult {
Spatial *item;
@@ -255,7 +259,7 @@ private:
real_t zoom_indicator_delay;
- RID move_gizmo_instance[3], move_plane_gizmo_instance[3], rotate_gizmo_instance[3], scale_gizmo_instance[3];
+ RID move_gizmo_instance[3], move_plane_gizmo_instance[3], rotate_gizmo_instance[3], scale_gizmo_instance[3], scale_plane_gizmo_instance[3];
String last_message;
String message;
@@ -287,7 +291,7 @@ private:
Point2i _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const;
Vector3 _get_instance_position(const Point2 &p_pos) const;
- static Rect3 _calculate_spatial_bounds(const Spatial *p_parent, const Rect3 p_bounds);
+ static AABB _calculate_spatial_bounds(const Spatial *p_parent, const AABB p_bounds);
void _create_preview(const Vector<String> &files) const;
void _remove_preview();
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
@@ -314,7 +318,7 @@ public:
void assign_pending_data_pointers(
Spatial *p_preview_node,
- Rect3 *p_preview_bounds,
+ AABB *p_preview_bounds,
AcceptDialog *p_accept);
Viewport *get_viewport_node() { return viewport; }
@@ -327,7 +331,7 @@ class SpatialEditorSelectedItem : public Object {
GDCLASS(SpatialEditorSelectedItem, Object);
public:
- Rect3 aabb;
+ AABB aabb;
Transform original; // original location when moving
Transform original_local;
Transform last_xform; // last transform
@@ -420,7 +424,7 @@ private:
bool grid_enable[3]; //should be always visible if true
bool grid_enabled;
- Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3], scale_gizmo[3];
+ Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3], scale_gizmo[3], scale_plane_gizmo[3];
Ref<SpatialMaterial> gizmo_color[3];
Ref<SpatialMaterial> plane_gizmo_color[3];
Ref<SpatialMaterial> gizmo_hl;
@@ -437,7 +441,7 @@ private:
// Scene drag and drop support
Spatial *preview_node;
- Rect3 preview_bounds;
+ AABB preview_bounds;
/*
struct Selected {
@@ -579,6 +583,7 @@ public:
Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; }
Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; }
Ref<ArrayMesh> get_scale_gizmo(int idx) const { return scale_gizmo[idx]; }
+ Ref<ArrayMesh> get_scale_plane_gizmo(int idx) const { return scale_plane_gizmo[idx]; }
void update_transform_gizmo();
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 0ee0eed3a2..ffddd8a3a9 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -363,7 +363,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era
return PoolVector<Vector2>();
}
- Rect2i r = node->get_item_rect();
+ Rect2i r = node->_edit_get_rect();
r.position = r.position / node->get_cell_size();
r.size = r.size / node->get_cell_size();