Skip to content

Add ability to sort save files by name or date #9793

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

Merged
merged 41 commits into from
Jun 15, 2025

Conversation

usidedown
Copy link
Contributor

@usidedown usidedown commented May 7, 2025

Solves #1211

Introduces a new configuration save file sorting that changes the way sorting works in the load dialog

✅ Allows sorting by timestamp rather than filename
✅ Doesn't change the default behavior
❌No UI improvements
✅ Awesome UI thanks to @zenseii

@usidedown usidedown force-pushed the feature/sort-saves-by-date branch from 0639f48 to 4df04ce Compare May 8, 2025 14:49
@usidedown usidedown marked this pull request as ready for review May 8, 2025 14:50
@Districh-ru Districh-ru added the improvement New feature, request or improvement label May 9, 2025
@Districh-ru Districh-ru added this to the 1.1.9 milestone May 9, 2025
@ihhub
Copy link
Owner

ihhub commented May 9, 2025

Hi @usidedown , without UI changes most of players would never even know about this feature. We have to provide a user-friendly solution and do not rely on the configuration file which is served only for developers.

This is a UX design of how we can implement sorting mechanism (provided by @OogaBoogaCode in Discord - https://discord.com/channels/733093692860137523/963076826673070130/1338909387158454445):
image

The initial PR was here: #9560 but I don't know why the author removed everything.

To change UI you can start looking at dialog_selectfile.cpp file, selectFileListSimple() function. You will need to add a button with "SORT" title. Please let me know if you have any questions.

@ihhub ihhub marked this pull request as draft May 10, 2025 10:46
@usidedown usidedown force-pushed the feature/sort-saves-by-date branch from 798830f to db9c2d7 Compare May 10, 2025 19:52
@usidedown
Copy link
Contributor Author

@ihhub UI part is done, let me know how it looks.

I'm slightly worried about the performance of clicking the sort button. Not sure if it's worth improving though.

There are 2 "heavy" operations:

  • the sorting itself should be NLOGN comparisons, but each comparison is not very cheap when comparing filenames. Fixing this is probably a bigger change and probably deserves its own PR.
  • I also need to find the last selected item and re-selected in the new list. This is again N comparisons of file names. Maybe it's possible to compare pointers instead of strings to speed things up. Not sure it's worth doing.

What do you think?

@usidedown usidedown marked this pull request as ready for review May 13, 2025 12:04
@usidedown usidedown marked this pull request as draft May 18, 2025 18:30
@ihhub
Copy link
Owner

ihhub commented May 20, 2025

Hi @usidedown , don't worry about sorting or search as we are handling at max < 1000 items so this operation is heavy in theory, in reality rendering would be much longer. If we avoid any I/O operations while changing sorting then it doesn't impact the performance too much.

And as usual we can always improve performance later.

@ihhub
Copy link
Owner

ihhub commented May 20, 2025

@usidedown , could you please also resolve merge conflicts to proceed with the review?

@usidedown
Copy link
Contributor Author

@usidedown , could you please also resolve merge conflicts to proceed with the review?

@ihhub Is the proposed UI design acceptable? I got the impression from discord that we want something different.

@usidedown usidedown force-pushed the feature/sort-saves-by-date branch 2 times, most recently from b953f23 to ee2edb0 Compare May 21, 2025 06:46
@usidedown usidedown marked this pull request as ready for review May 21, 2025 06:50
Copy link
Owner

@ihhub ihhub left a comment

Choose a reason for hiding this comment

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

Hi @usidedown , I put several comments in this pull request. Could you please take a look at them in your free time?

@usidedown usidedown force-pushed the feature/sort-saves-by-date branch from 5a5acb4 to d352958 Compare May 22, 2025 08:24
Copy link
Owner

@ihhub ihhub left a comment

Choose a reason for hiding this comment

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

Hi @usidedown , I added few more comments here. Would you mind to take a look at them?

@usidedown usidedown force-pushed the feature/sort-saves-by-date branch from 0f73122 to 3932fe1 Compare May 24, 2025 07:32
@ihhub ihhub requested a review from zenseii May 24, 2025 10:01
@ihhub ihhub changed the title feature(load): sort savegames by timestamp Add ability to sort save files by name or date May 25, 2025
@usidedown usidedown force-pushed the feature/sort-saves-by-date branch 2 times, most recently from fd07389 to 36f350c Compare May 26, 2025 02:59
@usidedown usidedown requested a review from ihhub May 26, 2025 03:00
Copy link
Owner

@ihhub ihhub left a comment

Choose a reason for hiding this comment

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

Hi @usidedown , I added 2 more comments here. Would you mind to take a look at them?

@usidedown
Copy link
Contributor Author

@ihhub thanks for the review
I'll take a look after the weekend.
Might revert the last commit if I can't simplify.

@usidedown
Copy link
Contributor Author

@zenseii your design definitely looks better!
Is it a big change (code-wise) w.r.t the current PR?
I barely managed to put a button, not sure if I can handle this design 😅

@zenseii
Copy link
Collaborator

zenseii commented Jun 7, 2025

@zenseii your design definitely looks better! Is it a big change (code-wise) w.r.t the current PR? I barely managed to put a button, not sure if I can handle this design 😅

Thanks! I can push the needed changes as I did some of them already for the screenshot (it was less work than photoshopping it). I'll expand the height of the header cells too.

Copy link
Collaborator

@oleg-derevenetz oleg-derevenetz left a comment

Choose a reason for hiding this comment

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

Hi @usidedown I just made a few changes:

  • Renamed the Settings::changeSaveFileSortingMethod() to the Settings::toggleSaveFileSortingMethod() - it seems to me that this variant reflects its essence better.

  • Moved the CaseInsensitiveCompare() to the tools.h (as fheroes2::compareStringsCaseInsensitively()) since this function is "relatively generic" and can be used in multiple places... But for now it is used just in maps_fileinfo.cpp.

  • Moved all comparators to the single place so that there will be no confusion if there is a need to change something.

  • Fixed the issue like this:

    fheroes2.engine.version_.1.1.8.2025-06-07.22-48-18.mp4

    std::lower_bound() doesn't mean "equality" per se.

  • Fixed the similar issue on the case-sensitive filesystems. Given that the current sorting is case-insensitive, there can be multiple "identical" file names with different case.

  • Added a few assertions (for the debug builds only) to check that lists are properly sorted/partitioned before calling std::lower_bound() or std::equal_range() on them. Attempting to call these functions on an incorrectly sorted list causes undefined behavior.

Could you please take a look at these changes to make sure I didn't miss anything?

Copy link
Contributor Author

@usidedown usidedown left a comment

Choose a reason for hiding this comment

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

@oleg-derevenetz thank you so much for these fixes!

Code looks correct overall, but I have minor suggestions.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

@zenseii zenseii added the ui UI/GUI related stuff label Jun 8, 2025
@zenseii
Copy link
Collaborator

zenseii commented Jun 8, 2025

Hi, @usidedown. I've added the header cells and radio buttons. Things are a bit more crammed in the dialog now. Ideally the way the size of the dialog is setup according to resolution and number of save files should be reworked, but for now I think this is good enough.

Copy link
Collaborator

@Districh-ru Districh-ru left a comment

Choose a reason for hiding this comment

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

Hi @usidedown, I left several comments. Could you please take a look when you have time?

@usidedown usidedown requested a review from Districh-ru June 14, 2025 15:27
Copy link
Collaborator

@Districh-ru Districh-ru left a comment

Choose a reason for hiding this comment

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

Well done, @usidedown.

You can also mark in the PR topic that there are UI improvements. :)

@ihhub ihhub merged commit 32c8a39 into ihhub:master Jun 15, 2025
23 checks passed
@ihhub
Copy link
Owner

ihhub commented Jun 15, 2025

@usidedown , many thanks for this feature!

@usidedown usidedown deleted the feature/sort-saves-by-date branch June 15, 2025 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement New feature, request or improvement ui UI/GUI related stuff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants