GUI: Skip games during Mass Add

Use [x] for selected games, as well as enabled list items.

Co-Authored-By: Filippos Karapetis <bluegr@gmail.com>
This commit is contained in:
HectorRecloud 2024-03-03 17:09:07 +01:00 committed by Eugene Sandulenko
parent e6c06c6aaf
commit e9f2468df9
5 changed files with 49 additions and 4 deletions

View File

@ -170,6 +170,11 @@ struct DetectedGame {
*/
bool hasUnknownFiles;
/**
* A game was detected and is selected in the Mass Add list.
*/
bool isSelected;
/**
* An optional list of the files that were used to match the game with the engine's detection tables
*/

View File

@ -136,10 +136,13 @@ void MassAddDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
Common::sort(_games.begin(), _games.end(), GameTargetLess());
// Add all the detected games to the config
for (DetectedGames::iterator iter = _games.begin(); iter != _games.end(); ++iter) {
debug(1, " Added gameid '%s', desc '%s'\n",
iter->gameId.c_str(),
iter->description.c_str());
iter->gameId = EngineMan.createTargetForGame(*iter);
// Make sure the game is selected
if (iter->isSelected) {
debug(1, " Added gameid '%s', desc '%s'",
iter->gameId.c_str(),
iter->description.c_str());
iter->gameId = EngineMan.createTargetForGame(*iter);
}
}
// Write everything to disk
@ -156,11 +159,30 @@ void MassAddDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
// User cancelled, so we don't do anything and just leave.
_games.clear();
close();
} else if (cmd == kListSelectionChangedCmd) {
// Select / unselect game from list
int curretScrollPos = _list->getCurrentScrollPos();
_games[_list->getSelected()].isSelected = !_games[_list->getSelected()].isSelected;
updateGameList();
_list->scrollTo(curretScrollPos);
} else {
Dialog::handleCommand(sender, cmd, data);
}
}
void MassAddDialog::updateGameList() {
// Update list to correctly display selected / unselected games
Common::U32StringArray l;
_list->setList(l);
_list->clearSelectedList();
for (const auto &game : _games) {
Common::U32String displayString = game.isSelected ? Common::String("[x] ") + game.description : Common::String("[\u2000] ") + game.description;
_list->append(displayString);
_list->appendToSelectedList(game.isSelected);
}
}
void MassAddDialog::handleTickle() {
if (_scanStack.empty())
return; // We have finished scanning
@ -227,6 +249,11 @@ void MassAddDialog::handleTickle() {
_list->append(result.description);
}
for (DetectedGame &game : _games) {
game.isSelected = true;
}
updateGameList();
// Recurse into all subdirs
for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file) {

View File

@ -51,6 +51,8 @@ private:
Common::Stack<Common::FSNode> _scanStack;
DetectedGames _games;
void updateGameList();
/**
* Map each path occuring in the config file to the target(s) using that path.
* Used to detect whether a potential new target is already present in the

View File

@ -559,6 +559,12 @@ void ListWidget::drawWidget() {
if (_selectedItem == pos)
inverted = _inversion;
// Display selected/unselected games in mass detection as enabled/disabled items.
if (pos < (signed int)_listSelected.size() && _listSelected[pos])
_state = ThemeEngine::kStateEnabled;
else
_state = ThemeEngine::kStateDisabled;
Common::Rect r(getEditRect());
int pad = _leftPadding;
int rtlPad = (_x + r.left + _leftPadding) - (_x + _hlLeftPadding);

View File

@ -97,6 +97,8 @@ protected:
FilterMatcher _filterMatcher;
void *_filterMatcherArg;
Common::Array<bool> _listSelected;
public:
ListWidget(Dialog *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
ListWidget(Dialog *boss, int x, int y, int w, int h, bool scale, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
@ -131,6 +133,9 @@ public:
void setEditColor(ThemeEngine::FontColor color) { _editColor = color; }
void setFilterMatcher(FilterMatcher matcher, void *arg) { _filterMatcher = matcher; _filterMatcherArg = arg; }
void appendToSelectedList(bool selected) { _listSelected.push_back(selected); }
void clearSelectedList() { _listSelected.clear(); }
// Made startEditMode/endEditMode for SaveLoadChooser
void startEditMode() override;
void endEditMode() override;