Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve undo log messages in the 2D editor for additional context #42229

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 96 additions & 11 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,16 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) {
}

// Confirm the pivot move
if ((b.is_valid() && !b->is_pressed() && b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) ||
(k.is_valid() && !k->is_pressed() && k->get_keycode() == KEY_V)) {
_commit_canvas_item_state(drag_selection, TTR("Move pivot"));
if (drag_selection.size() >= 1 &&
((b.is_valid() && !b->is_pressed() && b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) ||
(k.is_valid() && !k->is_pressed() && k->get_keycode() == KEY_V))) {
_commit_canvas_item_state(
drag_selection,
vformat(
TTR("Set CanvasItem \"%s\" Pivot Offset to (%d, %d)"),
drag_selection[0]->get_name(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that drag_selection.size() > 0 in all this code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the drag_selection can be empty in that part of the code. Unless there's a way to trigger the rotation, pivot dragging, etc... without a selected node. It might happen in some weird buggy situation though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe there should be some ERR_FAIL_COND(drag_selection.size()); at the start of each helper method, just to be safe?

Note that some of those methods actually mutate drag_selection based on filtering selection too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump. If you think it's safe I don't mind merging as is, but we need some resolution to this comment.

drag_selection[0]->_edit_get_pivot().x,
drag_selection[0]->_edit_get_pivot().y));
drag_type = DRAG_NONE;
return true;
}
Expand Down Expand Up @@ -1549,7 +1556,20 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) {

// Confirms the node rotation
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(drag_selection, TTR("Rotate CanvasItem"));
if (drag_selection.size() != 1) {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Rotate %d CanvasItems"), drag_selection.size()),
true);
} else {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Rotate CanvasItem \"%s\" to %d degrees"),
drag_selection[0]->get_name(),
Math::rad2deg(drag_selection[0]->_edit_get_rotation())),
true);
}

if (key_auto_insert_button->is_pressed()) {
_insert_animation_keys(false, true, false, true);
}
Expand Down Expand Up @@ -1708,8 +1728,10 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) {
}

// Confirms new anchor position
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(drag_selection, TTR("Move anchor"));
if (drag_selection.size() >= 1 && b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Move CanvasItem \"%s\" Anchor"), drag_selection[0]->get_name()));
drag_type = DRAG_NONE;
return true;
}
Expand Down Expand Up @@ -1885,8 +1907,31 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) {
}

// Confirm resize
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(drag_selection, TTR("Resize CanvasItem"));
if (drag_selection.size() >= 1 && b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
const Node2D *node2d = Object::cast_to<Node2D>(drag_selection[0]);
if (node2d) {
// Extends from Node2D.
// Node2D doesn't have an actual stored rect size, unlike Controls.
_commit_canvas_item_state(
drag_selection,
vformat(
TTR("Scale Node2D \"%s\" to (%s, %s)"),
drag_selection[0]->get_name(),
Math::stepify(drag_selection[0]->_edit_get_scale().x, 0.01),
Math::stepify(drag_selection[0]->_edit_get_scale().y, 0.01)),
true);
} else {
// Extends from Control.
_commit_canvas_item_state(
drag_selection,
vformat(
TTR("Resize Control \"%s\" to (%d, %d)"),
drag_selection[0]->get_name(),
drag_selection[0]->_edit_get_rect().size.x,
drag_selection[0]->_edit_get_rect().size.y),
true);
}

if (key_auto_insert_button->is_pressed()) {
_insert_animation_keys(false, false, true, true);
}
Expand Down Expand Up @@ -2014,7 +2059,20 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {

// Confirm resize
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && !b->is_pressed()) {
_commit_canvas_item_state(drag_selection, TTR("Scale CanvasItem"));
if (drag_selection.size() != 1) {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Scale %d CanvasItems"), drag_selection.size()),
true);
} else {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Scale CanvasItem \"%s\" to (%s, %s)"),
drag_selection[0]->get_name(),
Math::stepify(drag_selection[0]->_edit_get_scale().x, 0.01),
Math::stepify(drag_selection[0]->_edit_get_scale().y, 0.01)),
true);
}
if (key_auto_insert_button->is_pressed()) {
_insert_animation_keys(false, false, true, true);
}
Expand Down Expand Up @@ -2145,7 +2203,21 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) {
// Confirm the move (only if it was moved)
if (b.is_valid() && !b->is_pressed() && b->get_button_index() == BUTTON_LEFT) {
if (transform.affine_inverse().xform(b->get_position()) != drag_from) {
_commit_canvas_item_state(drag_selection, TTR("Move CanvasItem"), true);
if (drag_selection.size() != 1) {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Move %d CanvasItems"), drag_selection.size()),
true);
} else {
_commit_canvas_item_state(
drag_selection,
vformat(
TTR("Move CanvasItem \"%s\" to (%d, %d)"),
drag_selection[0]->get_name(),
drag_selection[0]->_edit_get_position().x,
drag_selection[0]->_edit_get_position().y),
true);
}
}

if (key_auto_insert_button->is_pressed()) {
Expand Down Expand Up @@ -2270,7 +2342,20 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) {
(!Input::get_singleton()->is_key_pressed(KEY_DOWN)) &&
(!Input::get_singleton()->is_key_pressed(KEY_LEFT)) &&
(!Input::get_singleton()->is_key_pressed(KEY_RIGHT))) {
_commit_canvas_item_state(drag_selection, TTR("Move CanvasItem"), true);
if (drag_selection.size() != 1) {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Move %d CanvasItems"), drag_selection.size()),
true);
} else {
_commit_canvas_item_state(
drag_selection,
vformat(TTR("Move CanvasItem \"%s\" to (%d, %d)"),
drag_selection[0]->get_name(),
drag_selection[0]->_edit_get_position().x,
drag_selection[0]->_edit_get_position().y),
true);
}
drag_type = DRAG_NONE;
}
viewport->update();
Expand Down