From 0d9c81b9c1b5fba27aa9baf748383cd87371c040 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Mon, 23 Dec 2024 16:02:47 +0100 Subject: [PATCH] GUI: Disable load button in Grid Launcher when no savegame can be loaded --- gui/launcher.cpp | 2 +- gui/widgets/grid.cpp | 10 +++++++--- gui/widgets/grid.h | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 4a2867cb2c7a..2b389e7ccb0a 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -1679,7 +1679,7 @@ void LauncherGrid::build() { _gridItemSizeLabel->setValue(ConfMan.getInt("grid_items_per_row")); // Add list with game titles - _grid = new GridWidget(this, "LauncherGrid.IconArea"); + _grid = new GridWidget(this, "LauncherGrid.IconArea", this); // Populate the list updateListing(); diff --git a/gui/widgets/grid.cpp b/gui/widgets/grid.cpp index 91ea47edabb5..124d2be78695 100644 --- a/gui/widgets/grid.cpp +++ b/gui/widgets/grid.cpp @@ -28,6 +28,7 @@ #include "gui/gui-manager.h" #include "gui/widgets/grid.h" +#include "gui/launcher.h" #include "gui/ThemeEval.h" @@ -264,7 +265,7 @@ void GridItemWidget::handleMouseDown(int x, int y, int button, int clickCount) { #pragma mark - -GridItemTray::GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid) +GridItemTray::GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid, LauncherDialog *launcher) : Dialog(x, y, w, h), CommandSender(boss) { _entryID = entryID; @@ -286,6 +287,8 @@ GridItemTray::GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entr _loadButton = new PicButtonWidget(this, trayPaddingX, trayPaddingY + buttonHeight + buttonSpacingY, buttonWidth, buttonHeight, _("Saves"), kLoadButtonCmd); + if (launcher) + _loadButton->setEnabled(launcher->canLoadSavegames(entryID)); _editButton = new PicButtonWidget(this, trayPaddingX + buttonWidth + buttonSpacingX, trayPaddingY + buttonHeight + buttonSpacingY, buttonWidth, buttonHeight, _("Edit"), kEditButtonCmd); @@ -400,9 +403,10 @@ Graphics::ManagedSurface *loadSurfaceFromFile(const Common::String &name, int re #pragma mark - -GridWidget::GridWidget(GuiObject *boss, const Common::String &name) +GridWidget::GridWidget(GuiObject *boss, const Common::String &name, LauncherDialog *launcher) : ContainerWidget(boss, name), CommandSender(boss) { + _launcher = launcher; _thumbnailHeight = 0; _thumbnailWidth = 0; _flagIconHeight = 0; @@ -1115,7 +1119,7 @@ void GridWidget::reflowLayout() { void GridWidget::openTrayAtSelected() { if (_selectedEntry) { GridItemTray *tray = new GridItemTray(this, _x + _selectedEntry->x - _gridXSpacing / 3, _y + _selectedEntry->y + _selectedEntry->h - _scrollPos, - _gridItemWidth + 2 * (_gridXSpacing / 3), _trayHeight, _selectedEntry->entryID, this); + _gridItemWidth + 2 * (_gridXSpacing / 3), _trayHeight, _selectedEntry->entryID, this, _launcher); tray->runModal(); delete tray; } diff --git a/gui/widgets/grid.h b/gui/widgets/grid.h index 97f4808d5933..f890c3fbc99a 100644 --- a/gui/widgets/grid.h +++ b/gui/widgets/grid.h @@ -35,6 +35,7 @@ namespace GUI { class ScrollBarWidget; class GridItemWidget; class GridWidget; +class LauncherDialog; enum { kPlayButtonCmd = 'PLAY', @@ -84,7 +85,7 @@ class GridItemTray: public Dialog, public CommandSender { PicButtonWidget *_loadButton; PicButtonWidget *_editButton; public: - GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid); + GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid, LauncherDialog *launcher); void reflowLayout() override; @@ -126,6 +127,7 @@ class GridWidget : public ContainerWidget, public CommandSender { Common::Array _gridItems; ScrollBarWidget *_scrollBar; + LauncherDialog *_launcher; int _scrollBarWidth; int _scrollWindowHeight; @@ -169,7 +171,7 @@ class GridWidget : public ContainerWidget, public CommandSender { Common::U32String _filter; - GridWidget(GuiObject *boss, const Common::String &name); + GridWidget(GuiObject *boss, const Common::String &name, LauncherDialog *launcher); ~GridWidget(); template