revamped LauncherDialog

added option to disable bottom buttons
This commit is contained in:
Thomas Jentzsch 2021-12-05 18:08:38 +01:00
parent 0a6560b47f
commit 13235e298b
10 changed files with 977 additions and 490 deletions

View File

@ -155,6 +155,7 @@ Settings::Settings()
setPermanent("launcherroms", "true"); setPermanent("launcherroms", "true");
setPermanent("launchersubdirs", "false"); setPermanent("launchersubdirs", "false");
setPermanent("launcherextensions", "false"); setPermanent("launcherextensions", "false");
setPermanent("launcherbuttons", "false");
setPermanent("romviewer", "1"); setPermanent("romviewer", "1");
setPermanent("lastrom", ""); setPermanent("lastrom", "");
setPermanent("favorites", "true"); setPermanent("favorites", "true");
@ -601,6 +602,7 @@ void Settings::usage() const
<< " -launcherroms <1|0> Show only ROMs in the launcher (vs. all files)\n" << " -launcherroms <1|0> Show only ROMs in the launcher (vs. all files)\n"
<< " -launchersubdirs <0|1> Show files from subdirectories too\n" << " -launchersubdirs <0|1> Show files from subdirectories too\n"
<< " -launcherextensions <0|1> Display file extensions in launcher\n" << " -launcherextensions <0|1> Display file extensions in launcher\n"
<< " -launcherbuttons <0|1> Display bottom buttons in launcher\n"
<< " -favorites <0|1> Enable virtual favorite directories in launcher\n" << " -favorites <0|1> Enable virtual favorite directories in launcher\n"
<< " -altsorting <0|1> Alternative sorting in virtual folders\n" << " -altsorting <0|1> Alternative sorting in virtual folders\n"
<< " -maxrecentroms <number> Number of ROMs tracked in 'Recently played'\n" << " -maxrecentroms <number> Number of ROMs tracked in 'Recently played'\n"

View File

@ -39,13 +39,20 @@ void FavoritesManager::load()
const string& serializedUser = mySettings.getString("_favoriteroms"); const string& serializedUser = mySettings.getString("_favoriteroms");
if(!serializedUser.empty()) if(!serializedUser.empty())
{ {
const json& jUser = json::parse(serializedUser); try
for(const auto& u : jUser)
{ {
const string& path = u.get<string>(); const json& jUser = json::parse(serializedUser);
FilesystemNode node(path); for (const auto& u : jUser)
if(node.exists()) {
addUser(path); const string& path = u.get<string>();
FilesystemNode node(path);
if (node.exists())
addUser(path);
}
}
catch (...)
{
cerr << "ERROR: FavoritesManager::load() '_favoriteroms' exception\n";
} }
} }
@ -56,13 +63,20 @@ void FavoritesManager::load()
const string& serializedRecent = mySettings.getString("_recentroms"); const string& serializedRecent = mySettings.getString("_recentroms");
if(!serializedRecent.empty()) if(!serializedRecent.empty())
{ {
const json& jRecent = json::parse(serializedRecent); try
for(const auto& r : jRecent)
{ {
const string& path = r.get<string>(); const json& jRecent = json::parse(serializedRecent);
FilesystemNode node(path); for (const auto& r : jRecent)
if(node.exists()) {
addRecent(path); const string& path = r.get<string>();
FilesystemNode node(path);
if (node.exists())
addRecent(path);
}
}
catch (...)
{
cerr << "ERROR: FavoritesManager::load() '_recentroms' exception\n";
} }
} }
} }
@ -70,16 +84,23 @@ void FavoritesManager::load()
// Most Popular // Most Popular
myPopularMap.clear(); myPopularMap.clear();
const string& serializedPopular = mySettings.getString("_popularroms"); const string& serializedPopular = mySettings.getString("_popularroms");
if(!serializedPopular.empty()) if (!serializedPopular.empty())
{ {
const json& jPopular = json::parse(serializedPopular); try
for(const auto& p : jPopular)
{ {
const string& path = p[0].get<string>(); const json& jPopular = json::parse(serializedPopular);
const uInt32 count = p[1].get<uInt32>(); for (const auto& p : jPopular)
FilesystemNode node(path); {
if(node.exists()) const string& path = p[0].get<string>();
myPopularMap.emplace(path, count); const uInt32 count = p[1].get<uInt32>();
FilesystemNode node(path);
if (node.exists())
myPopularMap.emplace(path, count);
}
}
catch (...)
{
cerr << "ERROR: FavoritesManager::load() '_popularroms' exception\n";
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -121,6 +121,10 @@ class LauncherDialog : public Dialog
void loadConfig() override; void loadConfig() override;
void saveConfig() override; void saveConfig() override;
void updateUI(); void updateUI();
void addOptionWidgets(int& ypos, WidgetArray& wid);
void addPathWidgets(int& ypos, WidgetArray& wid);
void addRomWidgets(int& ypos, WidgetArray& wid);
void addButtonWidgets(int& ypos, WidgetArray& wid);
string getRomDir(); string getRomDir();
/** /**
@ -162,21 +166,23 @@ class LauncherDialog : public Dialog
void loadRom(); void loadRom();
void loadRomInfo(); void loadRomInfo();
void handleFavoritesChanged(); void openSettings();
void handleContextMenu(); void openContextMenu(int x = -1, int y = -1);
void openGlobalProps();
void openHighScores();
void openWhatsNew();
void showOnlyROMs(bool state); void showOnlyROMs(bool state);
void toggleShowAll(); void toggleShowAll(bool toggle = true);
void toggleSubDirs(); void toggleSubDirs(bool toggle = true);
void gotoHomeDir();
void handleContextMenu();
void handleQuit();
void toggleExtensions(); void toggleExtensions();
void toggleSorting(); void toggleSorting();
void handleFavoritesChanged();
void removeAllFavorites(); void removeAllFavorites();
void removeAllPopular(); void removeAllPopular();
void removeAllRecent(); void removeAllRecent();
void openContextMenu(int x = -1, int y = -1);
void openGlobalProps();
void openSettings();
void openHighScores();
void openWhatsNew();
ContextMenu& contextMenu(); ContextMenu& contextMenu();
@ -187,17 +193,19 @@ class LauncherDialog : public Dialog
// automatically sized font for ROM info viewer // automatically sized font for ROM info viewer
unique_ptr<GUI::Font> myROMInfoFont; unique_ptr<GUI::Font> myROMInfoFont;
CheckboxWidget* myAllFiles{nullptr}; ButtonWidget* mySettingsButton{nullptr};
EditTextWidget* myPattern{nullptr}; EditTextWidget* myPattern{nullptr};
CheckboxWidget* mySubDirs{nullptr}; ButtonWidget* myOnlyRomsButton{nullptr};
ButtonWidget* mySubDirsButton{nullptr};
StaticTextWidget* myRomCount{nullptr}; StaticTextWidget* myRomCount{nullptr};
ButtonWidget* myHomeButton{nullptr};
ButtonWidget* myUpButton{nullptr};
EditTextWidget* myDir{nullptr};
ButtonWidget* myReloadButton{nullptr};
LauncherFileListWidget* myList{nullptr}; LauncherFileListWidget* myList{nullptr};
StaticTextWidget* myDirLabel{nullptr};
EditTextWidget* myDir{nullptr};
ButtonWidget* myHomeButton{nullptr};
ButtonWidget* myStartButton{nullptr}; ButtonWidget* myStartButton{nullptr};
ButtonWidget* myPrevDirButton{nullptr}; ButtonWidget* myPrevDirButton{nullptr};
ButtonWidget* myOptionsButton{nullptr}; ButtonWidget* myOptionsButton{nullptr};
@ -213,6 +221,7 @@ class LauncherDialog : public Dialog
int mySelectedItem{0}; int mySelectedItem{0};
bool myShowOnlyROMs{false}; bool myShowOnlyROMs{false};
bool myIncludeSubDirs{false};
bool myUseMinimalUI{false}; bool myUseMinimalUI{false};
bool myEventHandled{false}; bool myEventHandled{false};
bool myShortCount{false}; bool myShortCount{false};
@ -226,6 +235,7 @@ class LauncherDialog : public Dialog
kOptionsCmd = 'OPTI', kOptionsCmd = 'OPTI',
kQuitCmd = 'QUIT', kQuitCmd = 'QUIT',
kHomeDirCmd = 'homc', // goto Home directory kHomeDirCmd = 'homc', // goto Home directory
kReloadCmd = 'relc',
kRmAllFav = 'rmaf', kRmAllFav = 'rmaf',
kRmAllPop = 'rmap', kRmAllPop = 'rmap',
kRmAllRec = 'rmar' kRmAllRec = 'rmar'

View File

@ -58,6 +58,9 @@ class LauncherFileListWidget : public FileListWidget
bool inUserDir() const { return myVirtualDir == user_name; } bool inUserDir() const { return myVirtualDir == user_name; }
bool inRecentDir() const { return myVirtualDir == recent_name; } bool inRecentDir() const { return myVirtualDir == recent_name; }
bool inPopularDir() const { return myVirtualDir == popular_name; } bool inPopularDir() const { return myVirtualDir == popular_name; }
bool isUserDir(const string& name) const { return name == user_name; }
bool isRecentDir(const string& name) const { return name == recent_name; }
bool isPopularDir(const string& name) const { return name == popular_name; }
private: private:
static const string user_name; static const string user_name;

View File

@ -213,7 +213,7 @@ bool RomInfoWidget::loadPng(const string& filename)
// Scale surface to available image area // Scale surface to available image area
const Common::Rect& src = mySurface->srcRect(); const Common::Rect& src = mySurface->srcRect();
float scale = std::min(float(myAvail.w) / src.w(), float(myAvail.h) / src.h()) * const float scale = std::min(float(myAvail.w) / src.w(), float(myAvail.h) / src.h()) *
instance().frameBuffer().hidpiScaleFactor(); instance().frameBuffer().hidpiScaleFactor();
mySurface->setDstSize(uInt32(src.w() * scale), uInt32(src.h() * scale)); mySurface->setDstSize(uInt32(src.w() * scale), uInt32(src.h() * scale));
@ -241,10 +241,9 @@ void RomInfoWidget::handleMouseUp(int x, int y, MouseButton b, int clickCount)
void RomInfoWidget::drawWidget(bool hilite) void RomInfoWidget::drawWidget(bool hilite)
{ {
FBSurface& s = dialog().surface(); FBSurface& s = dialog().surface();
const int yoff = myAvail.h + 10; const int yoff = myAvail.h + _font.getFontHeight() / 2;
s.fillRect(_x+2, _y+2, _w-4, _h-4, _bgcolor); s.fillRect(_x+2, _y+2, _w-4, _h-4, _bgcolor);
s.frameRect(_x, _y, _w, _h, kColor);
s.frameRect(_x, _y+yoff, _w, _h-yoff, kColor); s.frameRect(_x, _y+yoff, _w, _h-yoff, kColor);
if(!myHaveProperties) if(!myHaveProperties)
@ -257,8 +256,8 @@ void RomInfoWidget::drawWidget(bool hilite)
{ {
const Common::Rect& dst = mySurface->dstRect(); const Common::Rect& dst = mySurface->dstRect();
const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); const uInt32 scale = instance().frameBuffer().hidpiScaleFactor();
uInt32 x = _x*scale + ((_w*scale - dst.w()) >> 1); const uInt32 x = _x * scale + ((_w * scale - dst.w()) >> 1);
uInt32 y = _y*scale + ((yoff*scale - dst.h()) >> 1); const uInt32 y = _y * scale + ((myAvail.h * scale - dst.h()) >> 1);
// Make sure when positioning the snapshot surface that we take // Make sure when positioning the snapshot surface that we take
// the dialog surface position into account // the dialog surface position into account
@ -267,12 +266,13 @@ void RomInfoWidget::drawWidget(bool hilite)
} }
else if(mySurfaceErrorMsg != "") else if(mySurfaceErrorMsg != "")
{ {
uInt32 x = _x + ((_w - _font.getStringWidth(mySurfaceErrorMsg)) >> 1); const uInt32 x = _x + ((_w - _font.getStringWidth(mySurfaceErrorMsg)) >> 1);
uInt32 y = _y + ((yoff - _font.getLineHeight()) >> 1); const uInt32 y = _y + ((yoff - _font.getLineHeight()) >> 1);
s.drawString(_font, mySurfaceErrorMsg, x, y, _w - 10, _textcolor); s.drawString(_font, mySurfaceErrorMsg, x, y, _w - 10, _textcolor);
} }
int xpos = _x + 8, ypos = _y + yoff + 5; const int xpos = _x + 8;
int ypos = _y + yoff + 5;
for(const auto& info : myRomInfo) for(const auto& info : myRomInfo)
{ {
if(info.length() * _font.getMaxCharWidth() <= uInt64(_w - 16)) if(info.length() * _font.getMaxCharWidth() <= uInt64(_w - 16))

View File

@ -224,7 +224,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
wid.push_back(myFollowLauncherWidget); wid.push_back(myFollowLauncherWidget);
xpos = HBORDER; xpos = HBORDER;
ypos += VGAP * 4; ypos += lineHeight + VGAP;
// Launcher font // Launcher font
pwidth = font.getStringWidth("2x (1000x760)"); pwidth = font.getStringWidth("2x (1000x760)");
@ -255,20 +255,27 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
myLauncherHeightSlider->setMaxValue(ds.h); myLauncherHeightSlider->setMaxValue(ds.h);
myLauncherHeightSlider->setStepValue(10); myLauncherHeightSlider->setStepValue(10);
wid.push_back(myLauncherHeightSlider); wid.push_back(myLauncherHeightSlider);
ypos += lineHeight + VGAP;
ypos = myLauncherFontPopup->getTop();
// Track favorites // Track favorites
ypos = myLauncherWidthSlider->getTop(); myFavoritesWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 1,
myFavoritesWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 2,
"Track favorites"); "Track favorites");
myFavoritesWidget->setToolTip("Check to enable favorites tracking and display."); myFavoritesWidget->setToolTip("Check to enable favorites tracking and display.");
wid.push_back(myFavoritesWidget); wid.push_back(myFavoritesWidget);
ypos += lineHeight + VGAP; ypos += lineHeight + VGAP;
// Display launcher extensions // Display launcher extensions
myLauncherExtensionsWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 2, myLauncherExtensionsWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 1,
"Display file extensions"); "Display file extensions");
wid.push_back(myLauncherExtensionsWidget); wid.push_back(myLauncherExtensionsWidget);
ypos += lineHeight + VGAP;
// Display bottom buttons
myLauncherButtonsWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 1,
"Display bottom buttons");
myLauncherButtonsWidget->setToolTip("Check to enable bottom command buttons.");
wid.push_back(myLauncherButtonsWidget);
// ROM launcher info/snapshot viewer // ROM launcher info/snapshot viewer
ypos = myLauncherHeightSlider->getTop() + lineHeight + VGAP * 4; ypos = myLauncherHeightSlider->getTop() + lineHeight + VGAP * 4;
@ -369,6 +376,7 @@ void UIDialog::loadConfig()
myFavoritesWidget->setState(settings.getBool("favorites")); myFavoritesWidget->setState(settings.getBool("favorites"));
myLauncherExtensionsWidget->setState(settings.getBool("launcherextensions")); myLauncherExtensionsWidget->setState(settings.getBool("launcherextensions"));
myLauncherButtonsWidget->setState(settings.getBool("launcherbuttons"));
// ROM launcher info viewer // ROM launcher info viewer
float zoom = instance().settings().getFloat("romviewer"); float zoom = instance().settings().getFloat("romviewer");
@ -457,6 +465,8 @@ void UIDialog::saveConfig()
settings.setValue("favorites", myFavoritesWidget->getState()); settings.setValue("favorites", myFavoritesWidget->getState());
// Display launcher extensions // Display launcher extensions
settings.setValue("launcherextensions", myLauncherExtensionsWidget->getState()); settings.setValue("launcherextensions", myLauncherExtensionsWidget->getState());
// Display bottom buttons
settings.setValue("launcherbuttons", myLauncherButtonsWidget->getState());
// ROM launcher info viewer // ROM launcher info viewer
int w = myLauncherWidthSlider->getValue(); int w = myLauncherWidthSlider->getValue();
@ -543,6 +553,7 @@ void UIDialog::setDefaults()
myLauncherFontPopup->setSelected("medium", ""); myLauncherFontPopup->setSelected("medium", "");
myFavoritesWidget->setState(true); myFavoritesWidget->setState(true);
myLauncherExtensionsWidget->setState(false); myLauncherExtensionsWidget->setState(false);
myLauncherButtonsWidget->setState(false);
myRomViewerSize->setValue(35); myRomViewerSize->setValue(35);
mySnapLoadPath->setText(instance().userDir().getShortPath()); mySnapLoadPath->setText(instance().userDir().getShortPath());
myLauncherExitWidget->setState(false); myLauncherExitWidget->setState(false);

View File

@ -57,8 +57,9 @@ class UIDialog : public Dialog, public CommandSender
SliderWidget* myLauncherWidthSlider{nullptr}; SliderWidget* myLauncherWidthSlider{nullptr};
SliderWidget* myLauncherHeightSlider{nullptr}; SliderWidget* myLauncherHeightSlider{nullptr};
PopUpWidget* myLauncherFontPopup{nullptr}; PopUpWidget* myLauncherFontPopup{nullptr};
CheckboxWidget* myLauncherExtensionsWidget{nullptr};
CheckboxWidget* myFavoritesWidget{nullptr}; CheckboxWidget* myFavoritesWidget{nullptr};
CheckboxWidget* myLauncherExtensionsWidget{nullptr};
CheckboxWidget* myLauncherButtonsWidget{nullptr};
SliderWidget* myRomViewerSize{nullptr}; SliderWidget* myRomViewerSize{nullptr};
ButtonWidget* myOpenBrowserButton{nullptr}; ButtonWidget* myOpenBrowserButton{nullptr};
EditTextWidget* mySnapLoadPath{nullptr}; EditTextWidget* mySnapLoadPath{nullptr};

View File

@ -662,11 +662,29 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font,
: ButtonWidget(boss, font, x, y, w, h, "", cmd, repeat) : ButtonWidget(boss, font, x, y, w, h, "", cmd, repeat)
{ {
_useBitmap = true; _useBitmap = true;
_useText = false;
_bitmap = bitmap; _bitmap = bitmap;
_bmw = bmw; _bmw = bmw;
_bmh = bmh; _bmh = bmh;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h,
const uInt32* bitmap, int bmw, int bmh, int bmx,
const string& label,
int cmd, bool repeat)
: ButtonWidget(boss, font, x, y, w + bmx * 1.5 + font.getStringWidth(label), h,
label, cmd, repeat)
{
_useBitmap = true;
_bitmap = bitmap;
_bmw = bmw;
_bmh = bmh;
_bmx = bmx;
_align = TextAlign::Left;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ButtonWidget::handleMouseEntered() void ButtonWidget::handleMouseEntered()
{ {
@ -736,15 +754,20 @@ void ButtonWidget::drawWidget(bool hilite)
s.frameRect(_x, _y, _w, _h, hilite && isEnabled() ? kBtnBorderColorHi : kBtnBorderColor); s.frameRect(_x, _y, _w, _h, hilite && isEnabled() ? kBtnBorderColorHi : kBtnBorderColor);
if (!_useBitmap) int x = _x;
s.drawString(_font, _label, _x, _y + (_h - _lineHeight)/2 + 1, _w, if(_useBitmap)
!isEnabled() ? _textcolorlo : {
hilite ? _textcolorhi : _textcolor, _align); int xb = _useText ? _x + _bmx / 2 : _x + (_w - _bmw) / 2;
else s.drawBitmap(_bitmap, xb, _y + (_h - _bmh) / 2,
s.drawBitmap(_bitmap, _x + (_w - _bmw) / 2, _y + (_h - _bmh) / 2,
!isEnabled() ? _textcolorlo : !isEnabled() ? _textcolorlo :
hilite ? _textcolorhi : _textcolor, hilite ? _textcolorhi : _textcolor,
_bmw, _bmh); _bmw, _bmh);
x = _x + _bmw + _bmx;
}
if(_useText)
s.drawString(_font, _label, x, _y + (_h - _lineHeight)/2 + 1, _w,
!isEnabled() ? _textcolorlo :
hilite ? _textcolorhi : _textcolor, _align);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -266,12 +266,15 @@ class ButtonWidget : public StaticTextWidget
int x, int y, int dw, int dh, int x, int y, int dw, int dh,
const uInt32* bitmap, int bmw, int bmh, const uInt32* bitmap, int bmw, int bmh,
int cmd = 0, bool repeat = false); int cmd = 0, bool repeat = false);
ButtonWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h,
const uInt32* bitmap, int bmw, int bmh, int bmx,
const string& label,
int cmd = 0, bool repeat= false);
~ButtonWidget() override = default; ~ButtonWidget() override = default;
bool handleEvent(Event::Type event) override; bool handleEvent(Event::Type event) override;
void setCmd(int cmd) { _cmd = cmd; }
int getCmd() const { return _cmd; }
/* Sets/changes the button's bitmap **/ /* Sets/changes the button's bitmap **/
void setBitmap(const uInt32* bitmap, int bmw, int bmh); void setBitmap(const uInt32* bitmap, int bmw, int bmh);
@ -286,9 +289,10 @@ class ButtonWidget : public StaticTextWidget
protected: protected:
bool _repeat{false}; // button repeats bool _repeat{false}; // button repeats
bool _useText{true};
bool _useBitmap{false}; bool _useBitmap{false};
const uInt32* _bitmap{nullptr}; const uInt32* _bitmap{nullptr};
int _bmw{0}, _bmh{0}; int _bmw{0}, _bmh{0}, _bmx{0};
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported