-
-
Notifications
You must be signed in to change notification settings - Fork 418
Added category filtering for hotkeys in settings window #9957
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
base: master
Are you sure you want to change the base?
Changes from all commits
c24cebb
505ce52
93cf960
9a06ceb
512ce83
2ab9905
5eb18f1
6eb3c21
5f018e3
48ee49d
58aa00c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| #include <cassert> | ||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <set> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
@@ -254,20 +255,55 @@ namespace fheroes2 | |
| fheroes2::Display & display = fheroes2::Display::instance(); | ||
|
|
||
| // Dialog height is capped with the current screen height minus 100 pixels. | ||
| fheroes2::StandardWindow background( keyDescriptionLength + hotKeyLength + 8 + 75, std::min( display.height() - 100, 520 ), true, display ); | ||
| const int32_t categoryWidth = 115; | ||
| fheroes2::StandardWindow background( categoryWidth + keyDescriptionLength + hotKeyLength + 8 + 95, std::min( display.height() - 100, 520 ), true, display ); | ||
|
|
||
| const fheroes2::Rect roi( background.activeArea() ); | ||
| const fheroes2::Rect listRoi( roi.x + 24, roi.y + 37, keyDescriptionLength + hotKeyLength + 8, roi.height - 75 ); | ||
| const fheroes2::Rect listRoi( roi.x + categoryWidth + 50, roi.y + 50, keyDescriptionLength + hotKeyLength + 8, roi.height - 92 ); | ||
|
|
||
| const fheroes2::Text title( _( "Hot Keys:" ), fheroes2::FontType::normalYellow() ); | ||
| title.draw( roi.x + ( roi.width - title.width() ) / 2, roi.y + 16, display ); | ||
|
|
||
| std::vector<std::pair<Game::HotKeyEvent, Game::HotKeyCategory>> hotKeyEvents = Game::getAllHotKeyEvents(); | ||
| std::vector<Game::HotKeyCategory> uniqueCategories = { Game::HotKeyCategory::ALL }; | ||
|
|
||
| std::set<Game::HotKeyCategory> seen; | ||
| for ( const auto & pair : hotKeyEvents ) { | ||
| if ( seen.find( pair.second ) == seen.end() ) { | ||
| seen.insert( pair.second ); | ||
| uniqueCategories.push_back( pair.second ); | ||
| } | ||
| } | ||
|
Comment on lines
+270
to
+276
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code isn't needed. We can directly take all entries from the enumeration. |
||
|
|
||
| // We divide the list: action description and binded hot-key. | ||
| const fheroes2::Rect categoryRoi( roi.x + 15, listRoi.y, categoryWidth + 25, listRoi.height ); | ||
| background.applyTextBackgroundShading( categoryRoi ); | ||
| background.applyTextBackgroundShading( { listRoi.x, listRoi.y, keyDescriptionLength + 8, listRoi.height } ); | ||
| background.applyTextBackgroundShading( { listRoi.x + keyDescriptionLength + 8, listRoi.y, hotKeyLength, listRoi.height } ); | ||
|
|
||
| const bool isEvilInterface = Settings::Get().isEvilInterfaceEnabled(); | ||
|
|
||
| std::vector<std::pair<Game::HotKeyCategory, fheroes2::Rect>> categoryRects; | ||
|
|
||
| int categoryOffsetY = categoryRoi.y + 4; | ||
|
|
||
| Game::HotKeyCategory selectedCategory = Game::HotKeyCategory::ALL; | ||
|
|
||
| const fheroes2::Text categoryHeader( _( "Category:" ), fheroes2::FontType::normalWhite() ); | ||
| categoryHeader.draw( roi.x + 45, roi.y + 32, display ); | ||
|
|
||
| for ( const Game::HotKeyCategory category : uniqueCategories ) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need |
||
| const bool isSelected = ( category == selectedCategory ); | ||
| const fheroes2::FontType fontType = isSelected ? fheroes2::FontType::normalYellow() : fheroes2::FontType::normalWhite(); | ||
| const fheroes2::Text categoryText( _( Game::getHotKeyCategoryName( category ) ), fontType ); | ||
| categoryText.draw( categoryRoi.x + 4, categoryOffsetY, display ); | ||
|
|
||
| const fheroes2::Rect textRect( categoryRoi.x, categoryOffsetY, categoryRoi.width, categoryText.height() + 4 ); | ||
| categoryRects.emplace_back( category, textRect ); | ||
|
|
||
| categoryOffsetY += categoryText.height() + 4; | ||
| } | ||
|
Comment on lines
+296
to
+305
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this code into a separate function in anonymous namespace and call it here and in the code below to avoid code duplication. |
||
|
|
||
| // Prepare OKAY button and render its shadow. | ||
| fheroes2::Button buttonOk; | ||
| const int buttonOkIcn = isEvilInterface ? ICN::BUTTON_SMALL_OKAY_EVIL : ICN::BUTTON_SMALL_OKAY_GOOD; | ||
|
|
@@ -290,20 +326,51 @@ namespace fheroes2 | |
| listbox.setScrollBarImage( fheroes2::AGG::GetICN( listIcnId, 4 ) ); | ||
| listbox.SetAreaMaxItems( ( listRoi.height - 7 ) / fheroes2::getFontHeight( fheroes2::FontSize::NORMAL ) ); | ||
|
|
||
| std::vector<std::pair<Game::HotKeyEvent, Game::HotKeyCategory>> hotKeyEvents = Game::getAllHotKeyEvents(); | ||
|
|
||
|
Comment on lines
-293
to
-294
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the above comment we can revert this change since |
||
| listbox.SetListContent( hotKeyEvents ); | ||
| listbox.updateScrollBarImage(); | ||
| listbox.Redraw(); | ||
|
|
||
| display.render( background.totalArea() ); | ||
|
|
||
| std::vector<std::pair<Game::HotKeyEvent, Game::HotKeyCategory>> filtered = hotKeyEvents; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is not needed especially outside the loop. Its lifetime is within the newly created below if-condition body. |
||
|
|
||
| LocalEvent & le = LocalEvent::Get(); | ||
| while ( le.HandleEvents() ) { | ||
| buttonOk.drawOnState( le.isMouseLeftButtonPressedAndHeldInArea( buttonOk.area() ) ); | ||
|
|
||
| listbox.QueueEventProcessing(); | ||
|
|
||
| for ( const auto & pair : categoryRects ) { | ||
| if ( le.MouseClickLeft( pair.second ) ) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should update the list only when clicking is done on a different item. Now we rebuild everything without this conditon. |
||
| selectedCategory = pair.first; | ||
|
|
||
| // ? DO NOT re-declare 'filtered' here | ||
| filtered.clear(); | ||
| for ( const auto & item : hotKeyEvents ) { | ||
| if ( selectedCategory == Game::HotKeyCategory::ALL || item.second == selectedCategory ) | ||
| filtered.push_back( item ); | ||
| } | ||
|
|
||
| categoryOffsetY = categoryRoi.y + 4; | ||
| for ( auto & categoryPair : categoryRects ) { | ||
| const bool isSelected = ( categoryPair.first == selectedCategory ); | ||
| const fheroes2::FontType fontType = isSelected ? fheroes2::FontType::normalYellow() : fheroes2::FontType::normalWhite(); | ||
| const fheroes2::Text categoryText( _( Game::getHotKeyCategoryName( categoryPair.first ) ), fontType ); | ||
| categoryText.draw( categoryRoi.x + 4, categoryOffsetY, display ); | ||
|
|
||
| categoryPair.second = { categoryRoi.x, categoryOffsetY, categoryRoi.width, categoryText.height() + 4 }; | ||
| categoryOffsetY += categoryText.height() + 4; | ||
| } | ||
|
Comment on lines
+355
to
+363
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to see how this dialog looks in the original resolution: 640x480 and whether every element fits. Also, please attach screenshots in other languages to see how it looks and whether the dialog is not being crumped for some languages. |
||
|
|
||
| listbox.SetListContent( filtered ); | ||
| listbox.updateScrollBarImage(); | ||
| listbox.Redraw(); | ||
| display.render( roi ); | ||
|
|
||
| break; | ||
| } | ||
| } | ||
|
|
||
| if ( le.MouseClickLeft( buttonOk.area() ) || Game::HotKeyCloseWindow() ) { | ||
| return; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -565,6 +565,8 @@ void Game::globalKeyDownEvent( const fheroes2::Key key, const int32_t modifier ) | |
| const char * Game::getHotKeyCategoryName( const HotKeyCategory category ) | ||
| { | ||
| switch ( category ) { | ||
| case HotKeyCategory::ALL: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this change. This doesn't belong to the class but only for a single specific dialog. So, let's make changes where they needed - in that dialog. |
||
| return gettext_noop( "All" ); | ||
| case HotKeyCategory::DEFAULT: | ||
| return gettext_noop( "Default Actions" ); | ||
| case HotKeyCategory::GLOBAL: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,8 +175,9 @@ namespace Game | |
| NO_EVENT, | ||
| }; | ||
|
|
||
| enum class HotKeyCategory : uint8_t | ||
| enum class HotKeyCategory : int | ||
| { | ||
| ALL = -1, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this change. This seem like a hack rather than a solution. Usually, all items in enumeration start from 0 (default value). We call simply call |
||
| DEFAULT, | ||
| GLOBAL, | ||
| MAIN_MENU, | ||
|
|
||
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 header won't be needed with the changes proposed below.