diff options
author | Bastien Bouclet | 2019-11-13 21:09:21 +0100 |
---|---|---|
committer | Bastien Bouclet | 2019-11-24 14:06:25 +0100 |
commit | 2c812a6b7a0b24b9012379118867fb4f64f32c14 (patch) | |
tree | 6f4225127305dbdae8f3a0dc7dfe61e51af51b1a /gui/launcher.cpp | |
parent | 3db6aed4e474d5b16639ee4958d1cd13504d12fb (diff) | |
download | scummvm-rg350-2c812a6b7a0b24b9012379118867fb4f64f32c14.tar.gz scummvm-rg350-2c812a6b7a0b24b9012379118867fb4f64f32c14.tar.bz2 scummvm-rg350-2c812a6b7a0b24b9012379118867fb4f64f32c14.zip |
GUI: Add DropdownButtonWidget and use it in the launcher for mass add
DropdownButtonWidget is a button split in two parts vertically. Clicking
the left part triggers a default action. Clicking the right part shows a
list of other actions the user can choose from.
Using this widget on the launcher lets 'Mass add' be a secondary action
of the 'Add' button, removing the necessity of pressing the shift key to
access the feature.
Diffstat (limited to 'gui/launcher.cpp')
-rw-r--r-- | gui/launcher.cpp | 122 |
1 files changed, 49 insertions, 73 deletions
diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 84512ea018..15866c0bc8 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -66,9 +66,11 @@ enum { kAboutCmd = 'ABOU', kOptionsCmd = 'OPTN', kAddGameCmd = 'ADDG', + kMassAddGameCmd = 'MADD', kEditGameCmd = 'EDTG', kRemoveGameCmd = 'REMG', kLoadGameCmd = 'LOAD', + kRecordGameCmd = 'RECG', kQuitCmd = 'QUIT', kSearchCmd = 'SRCH', kListSearchCmd = 'LSSR', @@ -145,20 +147,30 @@ void LauncherDialog::build() { _startButton = new ButtonWidget(this, "Launcher.StartButton", _("~S~tart"), _("Start selected game"), kStartCmd); - _loadButton = - new ButtonWidget(this, "Launcher.LoadGameButton", _("~L~oad..."), _("Load saved game for selected game"), kLoadGameCmd); + DropdownButtonWidget *loadButton = + new DropdownButtonWidget(this, "Launcher.LoadGameButton", _("~L~oad..."), _("Load saved game for selected game"), kLoadGameCmd); +#ifdef ENABLE_EVENTRECORDER + loadButton->appendEntry(_s("Record..."), kRecordGameCmd); +#endif + _loadButton = loadButton; // Above the lowest button rows: two more buttons (directly below the list box) if (g_system->getOverlayWidth() > 320) { - _addButton = - new ButtonWidget(this, "Launcher.AddGameButton", _("~A~dd Game..."), _("Hold Shift for Mass Add"), kAddGameCmd); + DropdownButtonWidget *addButton = + new DropdownButtonWidget(this, "Launcher.AddGameButton", _("~A~dd Game..."), _("Add games to the list"), kAddGameCmd); + addButton->appendEntry(_s("Mass Add..."), kMassAddGameCmd); + _addButton = addButton; + _editButton = new ButtonWidget(this, "Launcher.EditGameButton", _("~E~dit Game..."), _("Change game options"), kEditGameCmd); _removeButton = new ButtonWidget(this, "Launcher.RemoveGameButton", _("~R~emove Game"), _("Remove game from the list. The game data files stay intact"), kRemoveGameCmd); } else { - _addButton = - new ButtonWidget(this, "Launcher.AddGameButton", _c("~A~dd Game...", "lowres"), _("Hold Shift for Mass Add"), kAddGameCmd); + DropdownButtonWidget *addButton = + new DropdownButtonWidget(this, "Launcher.AddGameButton", _c("~A~dd Game...", "lowres"), _("Add games to the list"), kAddGameCmd); + addButton->appendEntry(_c("Mass Add...", "lowres"), kMassAddGameCmd); + _addButton = addButton; + _editButton = new ButtonWidget(this, "Launcher.EditGameButton", _c("~E~dit Game...", "lowres"), _("Change game options"), kEditGameCmd); _removeButton = @@ -318,38 +330,6 @@ void LauncherDialog::updateListing() { } void LauncherDialog::addGame() { - -#ifndef DISABLE_MASS_ADD - const bool massAdd = checkModifier(Common::KBD_SHIFT); - - if (massAdd) { - MessageDialog alert(_("Do you really want to run the mass game detector? " - "This could potentially add a huge number of games."), _("Yes"), _("No")); - if (alert.runModal() == GUI::kMessageOK && _browser->runModal() > 0) { - MassAddDialog massAddDlg(_browser->getResult()); - - massAddDlg.runModal(); - - // Update the ListWidget and force a redraw - - // If new target(s) were added, update the ListWidget and move - // the selection to to first newly detected game. - Common::String newTarget = massAddDlg.getFirstAddedTarget(); - if (!newTarget.empty()) { - updateListing(); - selectTarget(newTarget); - } - - g_gui.scheduleTopDialogRedraw(); - } - - // We need to update the buttons here, so "Mass add" will revert to "Add game" - // without any additional event. - updateButtons(); - return; - } -#endif - // Allow user to add a new game to the list. // 1) show a dir selection dialog which lets the user pick the directory // the game data resides in. @@ -392,6 +372,28 @@ void LauncherDialog::addGame() { } while (looping); } +void LauncherDialog::massAddGame() { + MessageDialog alert(_("Do you really want to run the mass game detector? " + "This could potentially add a huge number of games."), _("Yes"), _("No")); + if (alert.runModal() == GUI::kMessageOK && _browser->runModal() > 0) { + MassAddDialog massAddDlg(_browser->getResult()); + + massAddDlg.runModal(); + + // Update the ListWidget and force a redraw + + // If new target(s) were added, update the ListWidget and move + // the selection to to first newly detected game. + Common::String newTarget = massAddDlg.getFirstAddedTarget(); + if (!newTarget.empty()) { + updateListing(); + selectTarget(newTarget); + } + + g_gui.scheduleTopDialogRedraw(); + } +} + void LauncherDialog::removeGame(int item) { MessageDialog alert(_("Do you really want to remove this game configuration?"), _("Yes"), _("No")); @@ -432,20 +434,6 @@ void LauncherDialog::editGame(int item) { } } -void LauncherDialog::loadGameButtonPressed(int item) { -#ifdef ENABLE_EVENTRECORDER - const bool shiftPressed = checkModifier(Common::KBD_SHIFT); - if (shiftPressed) { - recordGame(item); - } else { - loadGame(item); - } - updateButtons(); -#else - loadGame(item); -#endif -} - #ifdef ENABLE_EVENTRECORDER void LauncherDialog::recordGame(int item) { RecorderDialog recorderDialog; @@ -640,6 +628,9 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat case kAddGameCmd: addGame(); break; + case kMassAddGameCmd: + massAddGame(); + break; case kRemoveGameCmd: removeGame(item); break; @@ -647,8 +638,13 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat editGame(item); break; case kLoadGameCmd: - loadGameButtonPressed(item); + loadGame(item); break; +#ifdef ENABLE_EVENTRECORDER + case kRecordGameCmd: + recordGame(item); + break; +#endif case kOptionsCmd: { GlobalOptionsDialog options(this); options.runModal(); @@ -717,28 +713,8 @@ void LauncherDialog::updateButtons() { _loadButton->setEnabled(en); _loadButton->markAsDirty(); } - switchButtonsText(_addButton, "~A~dd Game...", _s("Mass Add...")); -#ifdef ENABLE_EVENTRECORDER - switchButtonsText(_loadButton, "~L~oad...", _s("Record...")); -#endif } -// Update the label of the button depending on whether shift is pressed or not -void LauncherDialog::switchButtonsText(ButtonWidget *button, const char *normalText, const char *shiftedText) { - const bool shiftPressed = checkModifier(Common::KBD_SHIFT); - const bool lowRes = g_system->getOverlayWidth() <= 320; - - const char *newAddButtonLabel = shiftPressed - ? (lowRes ? _c(shiftedText, "lowres") : _(shiftedText)) - : (lowRes ? _c(normalText, "lowres") : _(normalText)); - - if (button->getLabel() != newAddButtonLabel) - button->setLabel(newAddButtonLabel); -} - - - - void LauncherDialog::reflowLayout() { #ifndef DISABLE_FANCY_THEMES if (g_gui.xmlEval()->getVar("Globals.ShowLauncherLogo") == 1 && g_gui.theme()->supportsImages()) { |