Skip to content

Commit

Permalink
added random ROM loading option (resolves #995)
Browse files Browse the repository at this point in the history
  • Loading branch information
thrust26 committed Jan 11, 2024
1 parent 39caf7d commit 14df3bc
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 97 deletions.
2 changes: 2 additions & 0 deletions Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

* Added searching by filename for ROM launcher images.

* Added option to start random ROM.

* Enhanced Game Properties dialog for multigame ROMs.

* Added 2nd UI theme and hotkey for toggling UI theme.
Expand Down
Binary file modified docs/graphics/launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/graphics/rominfo_1x_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/graphics/rominfo_1x_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/graphics/rominfo_2x_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/graphics/select_random_rom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,12 @@ <h2><b><a name="Hotkeys">Hotkeys</a></b></h2>
<td>Control + R</td>
<td>-</td>
</tr>
<tr>
<td>Load random ROM</td>
<td>Control-Alt + R</td>
<td>Control-Alt + R</td>
<td>-</td>
</tr>
<tr>
<td>Open Options dialog</td>
<td>Control + O</td>
Expand Down Expand Up @@ -4232,6 +4238,9 @@ <h3><b><a name="ROMInfoViewer">ROM Info Viewer</a></b></h3>
</li><li>
<img src="graphics/open_help.png" style="vertical-align: middle; margin-top: 4px; margin-bottom: 4px; margin-right: 4px">
Open this help for the launcher.
</li><li>
<img src="graphics/reload_list.png" style="vertical-align: middle; margin-top: 4px; margin-bottom: 4px; margin-right: 4px">
Reload the file list.
</li><li>
The 'Filter' text box can be used to narrow down the results in the
ROM listing. When this box is empty, all files are shown. Typing
Expand All @@ -4246,7 +4255,10 @@ <h3><b><a name="ROMInfoViewer">ROM Info Viewer</a></b></h3>
</li><li>
<img src="graphics/show_current_dir.png" style="vertical-align: middle; margin-top: 4px; margin-bottom: 4px">
<img src="graphics/show_sub_dirs.png" style="vertical-align: middle; margin-top: 4px; margin-bottom: 4px; margin-right: 4px">
Display either files from current directory only or all subdirectories too.
Display either files from current directory only, or all subdirectories too.
</li><li>
<img src="graphics/select_random_rom.png" style="vertical-align: middle; margin-top: 4px; margin-bottom: 4px; margin-right: 4px">
Load a random ROM from the current file list.
</li>
</ul>
</br>
Expand Down
135 changes: 48 additions & 87 deletions src/gui/Icons.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace GUI {

/* Exported structure definition. */
static constexpr IconDesc iconSmallDesc(14, 14);
static constexpr IconDesc iconSmallWDesc(24, 14);
static constexpr IconDesc iconLargeDesc(19, 20);
static constexpr IconDesc iconLargeWDesc(32, 20);

// Settings icon
static const Icon icon_settings_small(
Expand Down Expand Up @@ -149,44 +151,6 @@ static const Icon icon_reload_small(
0b00000111110000
});

// Allfiles icons
static const Icon icon_onlyroms_small_on (
iconSmallDesc,
{
0b00000000000000,
0b00000111100000,
0b00000111100000,
0b00000111100000,
0b00000111100000,
0b00000111100000,
0b00000111100000,
0b00001111110000,
0b00001111110000,
0b00011111111000,
0b00011011011000,
0b00110011001100,
0b11110011001111,
0b11100011000111
});
static const Icon icon_onlyroms_small_off (
iconSmallDesc,
{
0b01111111111000,
0b01000000001100,
0b01000000000110,
0b01000000000010,
0b01001000010010,
0b01001100110010,
0b01000111100010,
0b01011111111010,
0b01000111100010,
0b01001100110010,
0b01001000010010,
0b01000000000010,
0b01000000000010,
0b01111111111110
});

// Subdirs icons
static const Icon icon_subdirs_small_off(
iconSmallDesc,
Expand Down Expand Up @@ -224,6 +188,27 @@ static const Icon icon_subdirs_small_on(
0b00001000000001,
0b00001111111111
});

// random ROM icon
static const Icon icon_random_small(
iconSmallWDesc,
{
0b100000000000000000000100,
0b110000000000000000000110,
0b111000000011100000011111,
0b111100000011110000111111,
0b111110000000011001100110,
0b111111000000001100000100,
0b111111100000000110000000,
0b111111100000000110000000,
0b111111000000000011000100,
0b111110000000011001100110,
0b111100000011110000111111,
0b111000000011100000011111,
0b110000000000000000000110,
0b100000000000000000000100
});

// Help icon
static const Icon icon_help_small(
iconSmallDesc,
Expand Down Expand Up @@ -401,55 +386,6 @@ static const Icon icon_reload_large(
0b0000001111111000000
});

// Allfiles icons
static const Icon icon_onlyroms_large_on(
iconLargeDesc,
{
0b00000000000000000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000001011010000000,
0b00000011011011000000,
0b00000011011011000000,
0b00000111011011100000,
0b00000110011001100000,
0b00001110011001110000,
0b00011100011000111000,
0b01111100011000011110,
0b11111000011000001111,
0b11100000011000000111
});
static const Icon icon_onlyroms_large_off(
iconLargeDesc,
{
0b0111111111111100000,
0b0100000000000110000,
0b0100000000000011000,
0b0100000000000001100,
0b0100011000011000100,
0b0100011100111000100,
0b0100001100110000100,
0b0100001111110000100,
0b0100000111100000100,
0b0101111111111110100,
0b0101111111111110100,
0b0100000111100000100,
0b0100001111110000100,
0b0100001100110000100,
0b0100011100111000100,
0b0100011000011000100,
0b0100000000000000100,
0b0100000000000000100,
0b0100000000000000100,
0b0111111111111111100
});

// Subdirs icons
static const Icon icon_subdirs_large_off(
Expand Down Expand Up @@ -501,6 +437,31 @@ static const Icon icon_subdirs_large_on(
0b0000111111111111111
});

static const Icon icon_random_large(
iconLargeWDesc,
{
0b00000000000000000000000000001100,
0b10000000000000000000000000001110,
0b11000000000001111000000001111111,
0b11100000000001111100000011111111,
0b11110000000001111110000111001110,
0b11111000000000000111000110001100,
0b11111100000000000011100000001000,
0b11111110000000000001110000000000,
0b11111111000000000001110000000000,
0b11111111100000000000111000000000,
0b11111111100000000000011100000000,
0b11111111000000000000011100001000,
0b11111110000000000110001110001100,
0b11111100000001111110000111001110,
0b11111000000001111100000011111111,
0b11110000000001111000000001111111,
0b11100000000000000000000000001110,
0b11000000000000000000000000001100,
0b10000000000000000000000000001000,
0b00000000000000000000000000001000,
});

static const Icon icon_help_large(
iconLargeDesc,
{
Expand Down
40 changes: 35 additions & 5 deletions src/gui/LauncherDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "Version.hxx"
#include "MediaFactory.hxx"
#include "LauncherDialog.hxx"
#include "Random.hxx"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent,
Expand Down Expand Up @@ -129,10 +130,12 @@ void LauncherDialog::addFilteringWidgets(int& ypos)

// Figure out general icon button size
const GUI::Icon& reloadIcon = smallIcon ? GUI::icon_reload_small : GUI::icon_reload_large;
const GUI::Icon& randomIcon = smallIcon ? GUI::icon_random_small : GUI::icon_random_large;
const GUI::Icon& dummyIcon = reloadIcon; //-- used for sizing all the other icons
const int iconWidth = dummyIcon.width();
const int iconGap = ((fontWidth + 1) & ~0b1) + 1; // round up to next even
const int iconButtonWidth = iconWidth + iconGap;
const int randomButtonWidth = randomIcon.width() + iconGap;

int xpos = HBORDER;

Expand All @@ -151,8 +154,8 @@ void LauncherDialog::addFilteringWidgets(int& ypos)
int fwFilter = EditTextWidget::calcWidth(_font, "123456"); // at least 6 chars

// Calculate how much space everything will take
int wTotal = xpos + (iconButtonWidth * 3) + lwFilter + fwFilter + lwFound + bwSettings
+ LBL_GAP * 6 + btnGap * 2 + HBORDER;
int wTotal = xpos + (iconButtonWidth * 2) + randomButtonWidth + lwFilter + fwFilter + lwFound + bwSettings
+ LBL_GAP * 5 + btnGap * 3 + HBORDER;

// make sure there is space for at least 6 characters in the filter field
if(_w < wTotal)
Expand All @@ -175,7 +178,7 @@ void LauncherDialog::addFilteringWidgets(int& ypos)
// Show the reload button
myReloadButton = new ButtonWidget(this, _font, xpos, ypos - btnYOfs,
iconButtonWidth, buttonHeight, reloadIcon, kReloadCmd);
myReloadButton->setToolTip("Reload listing. (Ctrl+R)");
myReloadButton->setToolTip("Reload listing (Ctrl+R)");
wid.push_back(myReloadButton);
xpos = myReloadButton->getRight() + LBL_GAP * 2;

Expand Down Expand Up @@ -203,13 +206,20 @@ void LauncherDialog::addFilteringWidgets(int& ypos)
// Show the files counter
myRomCount = new StaticTextWidget(this, _font, xpos, ypos,
lwFound, fontHeight, "", TextAlign::Right);
xpos = myRomCount->getRight() + LBL_GAP;

// Show the random ROM button
myRandomRomButton = new ButtonWidget(this, _font, xpos, ypos - btnYOfs,
randomButtonWidth, buttonHeight, randomIcon, kLoadRndRomCmd);
myRandomRomButton->setToolTip("Load random ROM (Ctrl-Alt+R)");
wid.push_back(myRandomRomButton);

// Show the Settings / Options button (positioned from the right)
xpos = _w - HBORDER - bwSettings;
mySettingsButton = new ButtonWidget(this, _font, xpos, ypos - btnYOfs,
iconWidth, buttonHeight, settingsIcon,
iconGap, lblSettings, kOptionsCmd);
mySettingsButton-> setToolTip("(Ctrl+O)");
mySettingsButton-> setToolTip("Open Options dialog (Ctrl+O)");
wid.push_back(mySettingsButton);

ypos = mySettingsButton->getBottom() + Dialog::vGap();
Expand Down Expand Up @@ -821,7 +831,10 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
break;

case KBDK_R:
reload();
if(StellaModTest::isAlt(mod))
loadRandomRom();
else
reload();
break;

case KBDK_S:
Expand Down Expand Up @@ -993,6 +1006,10 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
loadRom();
break;

case kLoadRndRomCmd:
loadRandomRom();
break;

case kOptionsCmd:
openSettings();
break;
Expand Down Expand Up @@ -1227,6 +1244,19 @@ void LauncherDialog::openContextMenu(int x, int y)
contextMenu().show(x + getAbsX(), y + getAbsY(), surface().dstRect(), 0);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::loadRandomRom()
{
const Random rand;
int tries = 100; // limit to 100 tries, in case the directory contains no ROMs

do {
myList->setSelected(rand.next() % myList->getList().size());
} while(myList->isDirectory(myList->selected()) && --tries);
if(tries)
loadRom();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::openSettings()
{
Expand Down
3 changes: 3 additions & 0 deletions src/gui/LauncherDialog.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class LauncherDialog : public Dialog, CommandSender
void loadRom();
void loadRomInfo();
void loadPendingRomInfo();
void loadRandomRom();
void openSettings();
void openGameProperties();
void openContextMenu(int x = -1, int y = -1);
Expand Down Expand Up @@ -178,6 +179,7 @@ class LauncherDialog : public Dialog, CommandSender
ButtonWidget* mySettingsButton{nullptr};
EditTextWidget* myPattern{nullptr};
ButtonWidget* mySubDirsButton{nullptr};
ButtonWidget* myRandomRomButton{nullptr};
StaticTextWidget* myRomCount{nullptr};
ButtonWidget* myHelpButton{nullptr};

Expand Down Expand Up @@ -211,6 +213,7 @@ class LauncherDialog : public Dialog, CommandSender

enum {
kSubDirsCmd = 'lred',
kLoadRndRomCmd = 'lrnd', // load random ROM
kOptionsCmd = 'OPTI',
kQuitCmd = 'QUIT',
kReloadCmd = 'relc',
Expand Down
10 changes: 6 additions & 4 deletions src/gui/RomInfoWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ void RomInfoWidget::parseProperties(const FSNode& node, bool full)
+ (isPlusCart ? " - PlusROM" : "")
+ buf.str());
}
#ifdef DEBUG_BUILD
// Debug bezel properties:
//if(myProperties.get(PropType::Bezel_Name).empty())
// myRomInfo.push_back("*Bezel: " + Bezel::getName(instance().bezelDir().getPath(), myProperties));
//else
// myRomInfo.push_back(" Bezel: " + myProperties.get(PropType::Bezel_Name));
if(myProperties.get(PropType::Bezel_Name).empty())
myRomInfo.push_back("*Bezel: " + Bezel::getName(instance().bezelDir().getPath(), myProperties));
else
myRomInfo.push_back(" Bezel: " + myProperties.get(PropType::Bezel_Name));
#endif
}

setDirty();
Expand Down

0 comments on commit 14df3bc

Please sign in to comment.