Skip to content

Add sort button and logic #9560

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

Closed

Conversation

OogaBoogaCode
Copy link

This is the reworked PR.

@zenseii zenseii added improvement New feature, request or improvement ui UI/GUI related stuff labels Feb 11, 2025
@zenseii zenseii added this to the 1.1.7 milestone Feb 11, 2025
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 self-requested a review February 11, 2025 22:33
Copy link
Collaborator

@zenseii zenseii left a comment

Choose a reason for hiding this comment

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

Hi, @OogaBoogaCode. Thank you for this contribution.
I left some comments. The main change regards the button code, which I've outlined. Please have a look when it is convenient for you.

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 @OogaBoogaCode , I left multiple comments here. Would you mind to take a look at them?

@@ -56,6 +56,12 @@ enum MusicSource
MUSIC_EXTERNAL
};

enum SaveSortMode
Copy link
Owner

Choose a reason for hiding this comment

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

This should be class enumeration with no values:

enum class SaveFileSortMethod : uint8_t
{
    SORT_BY_NAME,
    SORT_BY_DATE
};

@@ -373,6 +385,7 @@ class Settings

int sound_volume;
int music_volume;
int save_sort_mode;
Copy link
Owner

Choose a reason for hiding this comment

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

Please use the correct camelCase variable naming convention:

SaveFileSortMethod _saveFileSortMethod;

and since this is going to be uint8_t move it after ZoomLevel _viewWorldZoomLevel{ ZoomLevel::ZoomLevel1 };

Moreover, this member must have a default value:

SaveFileSortMethod _saveFileSortMethod{ SaveFileSortMethod::SORT_BY_NAME };

@@ -94,6 +100,11 @@ class Settings
return _currentMapInfo;
}

int SaveSortMode() const
Copy link
Owner

Choose a reason for hiding this comment

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

Please use the correct method naming:

SaveFileSortMethod getSaveFileSortMethod() const
{
    return _saveFileSortMethod;
}

@@ -257,6 +268,7 @@ class Settings

void SetSoundVolume( int v );
void SetMusicVolume( int v );
void SetSaveSortMode( int mode );
Copy link
Owner

Choose a reason for hiding this comment

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

This method should have the following signature:

void setSaveFileSortMethod( const SaveFileSortMethod method )
{
    _saveFileSortMethod = method;
}

The method can be inlined since it is literally one line of code.

@@ -390,6 +396,9 @@ std::string Settings::String() const
os << std::endl << "# music volume: 0 - 10" << std::endl;
os << "music volume = " << music_volume << std::endl;

os << std::endl << "# save sort mode: 1 - by name, 2 - by timestamp" << std::endl;
Copy link
Owner

Choose a reason for hiding this comment

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

We must not use any cryptic integer values and offer users more friend string approach:

os << std::endl << "# file save sort method: name or date" << std::endl;
if ( _saveFileSortMethod == SaveFileSortMethod::SORT_BY_NAME ) {
    os << "file save sort method = name" << std::endl;
}
else {
    os << "file save sort method = date" << std::endl;
}

@@ -89,6 +89,7 @@ namespace fheroes2
const Padding padding );
void renderButton( Button & button, const int icnId, const uint32_t releasedIndex, const uint32_t pressedIndex, const Point & offset, const Padding padding );
void renderOkayCancelButtons( Button & buttonOk, Button & buttonCancel, const bool isEvilInterface );
void renderOkaySortCancelButtons( Button & buttonOk, Button & buttonSort, Point sortButtonOffset, Button & buttonCancel, const bool isEvilInterface );
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove this method. Adding a new method which does exactly the same but for a very specific case is not a good design idea. Instead, you can use renderButton() method call for 3 buttons from your code.

@@ -291,14 +297,13 @@ namespace

const bool isEvilInterface = Settings::Get().isEvilInterfaceEnabled();
Copy link
Owner

Choose a reason for hiding this comment

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

Please cache Settings::Get() call and use it here and later in the newly added code.

@@ -247,8 +247,14 @@ namespace
}
}

std::sort( mapInfos.begin(), mapInfos.end(), Maps::FileInfo::sortByFileName );
Copy link
Owner

Choose a reason for hiding this comment

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

getSortedMapsFileInfoList() function is literally used only in one place. We should just pass sorting method as an input parameter for this function.

int const sortMode = Settings::Get().SaveSortMode();
Settings::Get().SetSaveSortMode( sortMode == 0 ? 1 : 0 );
lists = getSortedMapsFileInfoList();
listbox.SetListContent( lists );
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need to call this function? What happens with a file selection? Does it preserved while switching between methods?

listbox.updateScrollBarImage();
listbox.Redraw();
}

if ( le.MouseClickLeft( buttonCancel.area() ) || Game::HotKeyPressEvent( Game::HotKeyEvent::DEFAULT_CANCEL ) ) {
Copy link
Owner

Choose a reason for hiding this comment

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

Since we added the condition of mouse click above then we need to add else keyword here as we don't expect to execute the code.

@ihhub ihhub marked this pull request as draft February 23, 2025 04:21
@OogaBoogaCode OogaBoogaCode force-pushed the Add-sort-button-and-logic branch from 3f156f8 to 98b74a7 Compare February 25, 2025 03:43
@zenseii zenseii mentioned this pull request Apr 4, 2025
1 task
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.

3 participants