-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Add sort button and logic #9560
Conversation
There was a problem hiding this 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)
There was a problem hiding this 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.
There was a problem hiding this 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?
src/fheroes2/system/settings.h
Outdated
@@ -56,6 +56,12 @@ enum MusicSource | |||
MUSIC_EXTERNAL | |||
}; | |||
|
|||
enum SaveSortMode |
There was a problem hiding this comment.
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
};
src/fheroes2/system/settings.h
Outdated
@@ -373,6 +385,7 @@ class Settings | |||
|
|||
int sound_volume; | |||
int music_volume; | |||
int save_sort_mode; |
There was a problem hiding this comment.
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 };
src/fheroes2/system/settings.h
Outdated
@@ -94,6 +100,11 @@ class Settings | |||
return _currentMapInfo; | |||
} | |||
|
|||
int SaveSortMode() const |
There was a problem hiding this comment.
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;
}
src/fheroes2/system/settings.h
Outdated
@@ -257,6 +268,7 @@ class Settings | |||
|
|||
void SetSoundVolume( int v ); | |||
void SetMusicVolume( int v ); | |||
void SetSaveSortMode( int mode ); |
There was a problem hiding this comment.
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.
src/fheroes2/system/settings.cpp
Outdated
@@ -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; |
There was a problem hiding this comment.
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;
}
src/fheroes2/gui/ui_window.h
Outdated
@@ -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 ); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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 ) ) { |
There was a problem hiding this comment.
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.
3f156f8
to
98b74a7
Compare
This is the reworked PR.