diff --git a/src/gui/GuiIconGrid.cpp b/src/gui/GuiIconGrid.cpp index 7aa1336..c5bcbdc 100644 --- a/src/gui/GuiIconGrid.cpp +++ b/src/gui/GuiIconGrid.cpp @@ -14,6 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include +#include #include #include #include @@ -23,8 +25,9 @@ #include "utils/logger.h" #include "gui/GameIcon.h" -GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex) +GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex,bool sortByName) : GuiTitleBrowser(w, h, GameIndex), + sortByName(sortByName), particleBgImage(w, h, 50, 60.0f, 90.0f, 0.6f, 1.0f) , touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH) , wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A) @@ -57,7 +60,7 @@ void GuiIconGrid::setSelectedGame(uint64_t idx) { container = x.second; if(x.first == idx) { container->image->setSelected(true); - }else{ + } else { container->image->setSelected(false); } } @@ -197,9 +200,28 @@ void GuiIconGrid::updateButtonPositions() { int32_t col = 0, row = 0, listOff = 0; int i = 0; - containerMutex.lock(); - for (auto const& x : gameInfoContainers) { + // create an empty vector of pairs + std::vector> vec; + containerMutex.lock(); + + // copy key-value pairs from the map to the vector + std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter>>(vec)); + + containerMutex.unlock(); + + if(sortByName) { + std::sort(vec.begin(), vec.end(), + [](const std::pair& l, const std::pair& r) { + if (l.second != r.second) + return l.second->info->name.compare(r.second->info->name) <0; + + return l.first < r.first; + }); + } + + + for (auto const& x : vec) { listOff = i / (MAX_COLS * MAX_ROWS); float posX = currentLeftPosition + listOff * width + ( col * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) - (MAX_COLS * 0.5f - 0.5f) * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) ); @@ -219,7 +241,7 @@ void GuiIconGrid::updateButtonPositions() { i++; } - containerMutex.unlock(); + } void GuiIconGrid::draw(CVideo *pVideo) { diff --git a/src/gui/GuiIconGrid.h b/src/gui/GuiIconGrid.h index 73631ec..0ebdf08 100644 --- a/src/gui/GuiIconGrid.h +++ b/src/gui/GuiIconGrid.h @@ -25,7 +25,7 @@ class GuiIconGrid : public GuiTitleBrowser, public sigslot::has_slots<> { public: - GuiIconGrid(int32_t w, int32_t h, uint64_t selectedTitleId); + GuiIconGrid(int32_t w, int32_t h, uint64_t selectedTitleId, bool sortByName); virtual ~GuiIconGrid(); void setSelectedGame(uint64_t idx); @@ -62,6 +62,7 @@ private: int32_t targetLeftPosition; uint32_t gameLaunchTimer; bool bUpdatePositions = false; + bool sortByName = false; class GameInfoContainer { public: diff --git a/src/menu/MainWindow.cpp b/src/menu/MainWindow.cpp index 7234e92..5cdc269 100644 --- a/src/menu/MainWindow.cpp +++ b/src/menu/MainWindow.cpp @@ -202,7 +202,7 @@ void MainWindow::drawTv(CVideo *video) { } void MainWindow::SetupMainView() { - currentTvFrame = new GuiIconGrid(width, height,0); + currentTvFrame = new GuiIconGrid(width, height,0, true); currentTvFrame->setEffect(EFFECT_FADE, 10, 255); currentTvFrame->setState(GuiElement::STATE_DISABLED); @@ -210,7 +210,7 @@ void MainWindow::SetupMainView() { appendTv(currentTvFrame); - currentDrcFrame = new GuiIconGrid(width, height,0); + currentDrcFrame = new GuiIconGrid(width, height,0, false); currentDrcFrame->setEffect(EFFECT_FADE, 10, 255); currentDrcFrame->setState(GuiElement::STATE_DISABLED); currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); @@ -239,6 +239,7 @@ void MainWindow::SetupMainView() { mainSwitchButtonFrame = new MainDrcButtonsFrame(width, height); mainSwitchButtonFrame->settingsButtonClicked.connect(this, &MainWindow::OnSettingsButtonClicked); mainSwitchButtonFrame->layoutSwitchClicked.connect(this, &MainWindow::OnLayoutSwitchClicked); + mainSwitchButtonFrame->gameListFilterClicked.connect(this, &MainWindow::OnGameListFilterButtonClicked); mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED); mainSwitchButtonFrame->setEffect(EFFECT_FADE, 10, 255); mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED);