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 usability of the SpriteFramesEditor #80448

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nonunknown
Copy link
Contributor

@nonunknown nonunknown commented Aug 9, 2023

Currently when the user is adding a lot of animations in the SpriteFramesEditor he has to open the sprite everytime and set values all again:

PR-usability-1.mp4

with the changes of this PR, I tried to make it as more reliable as possible, the editor will "save" the settings and know the settings and last texture used in the process:

PR-usability-2.mp4

Some info:

  • If you close the editor, and open again, it will still know your last configurations
  • If you (HOLD SHIFT + Click) on Add frames from spritesheet it will open the Open a file to select a new texture

Bugsquad edit:

@YuriSizov YuriSizov changed the title SpriteFramesEditor usability improvement Improve usability of the SpriteFramesEditor Aug 9, 2023
@YuriSizov YuriSizov added this to the 4.x milestone Aug 9, 2023
editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Make sure to check that you actually applied the suggestions, pay attention to detail :)

editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
editor/plugins/sprite_frames_editor_plugin.cpp Outdated Show resolved Hide resolved
@akien-mga akien-mga requested review from kleonc and KoBeWi August 9, 2023 13:46
@nonunknown nonunknown force-pushed the frame-usability branch 2 times, most recently from 038b3bb to 19a46ee Compare August 9, 2023 14:00
@nonunknown nonunknown force-pushed the frame-usability branch 3 times, most recently from 0ee6b62 to d78b48b Compare August 10, 2023 15:04
@nonunknown
Copy link
Contributor Author

@AThousandShips ok, did the requested changes, saving only dominant parameter related to the spin box that was mofied!

  • Also I've removed the _save_data function, because now its saving everytime you change a value.

Also thank you very much for explaining me how the dominant_param works I've understood it well! Hope theres no bug left xD what a PR damn :D

dominant_param = int(EditorSettings::get_singleton()->get_project_metadata("sprite_frames", "dominant_param", -1));
if (dominant_param == PARAM_SIZE) {
split_sheet_size_x->set_value(split_data["dom_x"]);
split_sheet_size_y->set_value(split_data["dom_y"]);
Copy link
Member

@AThousandShips AThousandShips Aug 10, 2023

Choose a reason for hiding this comment

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

Need to compute the other values here (i.e. count for x/y and vice versa), including the ranges for sep/offset I believe, otherwise it looks good, will take a deeper look when I have time!

To ensure correctness I'd also suggest using wildly different sized textures to see what happens when you swap over and catch nasty cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry didnt understood, the sep/offset is below outside the if statement, you mean compute them before? the dominants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also I have found a problem, if you close the project and open again, the dominant values are set, but the others, lets suppose dominant is hor/vert then size x/y is saved, and when open the project the size x/y is set_value but hor/vert is not calculated, didnt understood why!

Copy link
Member

@AThousandShips AThousandShips Aug 10, 2023

Choose a reason for hiding this comment

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

See here:

case PARAM_SIZE: {
const Size2i frame_size = _get_frame_size();
const Size2i offset_max = texture_size - frame_size;
split_sheet_offset_x->set_max(offset_max.x);
split_sheet_offset_y->set_max(offset_max.y);
const Size2i sep_max = size - frame_size * 2;
split_sheet_sep_x->set_max(sep_max.x);
split_sheet_sep_y->set_max(sep_max.y);
const Size2i separation = _get_separation();
const Size2i count = (size + separation) / (frame_size + separation);
split_sheet_h->set_value(count.x);
split_sheet_v->set_value(count.y);

case PARAM_FRAME_COUNT: {
const Size2i count = _get_frame_count();
const Size2i offset_max = texture_size - count;
split_sheet_offset_x->set_max(offset_max.x);
split_sheet_offset_y->set_max(offset_max.y);
const Size2i gap_count = count - Size2i(1, 1);
split_sheet_sep_x->set_max(gap_count.x == 0 ? size.x : (size.x - count.x) / gap_count.x);
split_sheet_sep_y->set_max(gap_count.y == 0 ? size.y : (size.y - count.y) / gap_count.y);
const Size2i separation = _get_separation();
const Size2i frame_size = (size - separation * gap_count) / count;
split_sheet_size_x->set_value(frame_size.x);
split_sheet_size_y->set_value(frame_size.y);

and when open the project the size x/y is set_value but hor/vert is not calculated, didnt understood why!

The min/max of the sep/offset values are updated here and should be done so here as well IMO

and when open the project the size x/y is set_value but hor/vert is not calculated, didnt understood why!

This is exactly what I'm talking about, they need to be calculated, see the code I referenced for how it is done

@@ -458,6 +471,9 @@ void SpriteFramesEditor::_sheet_spin_changed(double p_value, int p_dominant_para
const Size2i count = (size + separation) / (frame_size + separation);
split_sheet_h->set_value(count.x);
split_sheet_v->set_value(count.y);

split_data["dom_x"] = int(split_sheet_h->get_value());
split_data["dom_y"] = int(split_sheet_v->get_value());
Copy link
Member

@AThousandShips AThousandShips Aug 10, 2023

Choose a reason for hiding this comment

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

This is now reversed, when PARAM_SIZE you store the size, and calculate the other value, and vice versa

The split_sheet_x/y should be calculated from the texture size, and vice versa, when loading

@KoBeWi
Copy link
Member

KoBeWi commented Sep 6, 2023

Is this intended that changing spritesheet will reset the values to default?

file_split_sheet->popup_file_dialog();
} else {
// If there's a path to a texture goto the editor directly!
String path = EditorSettings::get_singleton()->get_project_metadata("sprite_frames", "last_texture", "");
Copy link
Member

Choose a reason for hiding this comment

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

Why is last texture remembered globally? Is it so common to use a single texture between editor sessions?

if (updating_split_settings) {
return;
}
updating_split_settings = true;

if (p_dominant_param != PARAM_USE_CURRENT) {
dominant_param = p_dominant_param;
EditorSettings::get_singleton()->set_project_metadata("sprite_frames", "dominant_param", dominant_param);
Copy link
Member

@KoBeWi KoBeWi Sep 6, 2023

Choose a reason for hiding this comment

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

Suggested change
EditorSettings::get_singleton()->set_project_metadata("sprite_frames", "dominant_param", dominant_param);
EditorSettings::get_singleton()->set_project_metadata("sprite_frames_editor", "dominant_param", dominant_param);

Makes its purpose more clear.
(remember to replace other references too)

} break;
}

// Save relevant data
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Save relevant data
// Save relevant data.

bool new_texture = texture != split_sheet_preview->get_texture();
split_data = EditorSettings::get_singleton()->get_project_metadata("sprite_frames", "split_data", Dictionary());
String last_texture = EditorSettings::get_singleton()->get_project_metadata("sprite_frames", "last_texture", "");
bool has_valid_data = (split_data != Dictionary() && last_texture != "");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool has_valid_data = (split_data != Dictionary() && last_texture != "");
bool has_valid_data = (!split_data.is_empty() && !last_texture.is_empty());

split_sheet_offset_x->set_max(size.x);
split_sheet_offset_y->set_max(size.y);

updating_split_settings = true;
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this flag if you use set_value_no_signal().

}

updating_split_settings = false;

// Reset zoom.
Copy link
Member

Choose a reason for hiding this comment

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

If it's done for a specific purpose, this comment would need to be clarified. Otherwise you can remove it, as it's obvious from the method name.

@@ -1896,7 +1942,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
load->set_shortcut_context(frame_list);
load->set_shortcut(ED_SHORTCUT("sprite_frames/load_from_file", TTR("Add frame from file"), KeyModifierMask::CMD_OR_CTRL | Key::O));
load_sheet->set_shortcut_context(frame_list);
load_sheet->set_shortcut(ED_SHORTCUT("sprite_frames/load_from_sheet", TTR("Add frames from sprite sheet"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::O));
load_sheet->set_shortcut(ED_SHORTCUT("sprite_frames/load_from_sheet", TTR("Add frames from sprite sheet | (Shift + Click) to load new texture"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::O));
Copy link
Member

Choose a reason for hiding this comment

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

This can't be added like that, because it becomes a part of shortcut's name:
image
Instead you should use set_tooltip_text() for the note.

Suggested change
load_sheet->set_shortcut(ED_SHORTCUT("sprite_frames/load_from_sheet", TTR("Add frames from sprite sheet | (Shift + Click) to load new texture"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::O));
load_sheet->set_shortcut(ED_SHORTCUT("sprite_frames/load_from_sheet", TTR("Add frames from sprite sheet"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::O));
load_sheet->set_tooltip_text("Shift + Click: Load new texture.")

btw the way it is implemented, if a shortcut includes Shift (like the default one), the file dialog will be opened when you press it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Select Frames" window should remember previous settings
5 participants