ScummVM API documentation
launcher.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GUI_LAUNCHER_DIALOG_H
23 #define GUI_LAUNCHER_DIALOG_H
24 
25 // Disable the grid for platforms that disable fancy themes
26 #ifdef DISABLE_FANCY_THEMES
27 #define DISABLE_LAUNCHERDISPLAY_GRID
28 #endif
29 #define kSwitchLauncherDialog -2
30 
31 #include "common/hashmap.h"
32 
33 #include "gui/dialog.h"
34 #include "gui/widgets/popup.h"
35 #include "gui/MetadataParser.h"
36 
37 #include "engines/game.h"
38 
39 namespace GUI {
40 
41 enum LauncherDisplayType {
42  kLauncherDisplayList = 1,
43  kLauncherDisplayGrid = 2
44 };
45 
46 enum GroupingMethod {
47  kGroupByNone,
48  kGroupByFirstLetter,
49  kGroupByEngine,
50  kGroupBySeries,
51  kGroupByCompany,
52  kGroupByLanguage,
53  kGroupByPlatform,
54  kGroupByYear,
55 };
56 
57 struct GroupingMode {
61  const char *name;
62 
66  const char *description;
67 
71  const char *lowresDescription;
72 
76  GroupingMethod id;
77 };
78 
79 class BrowserDialog;
80 class CommandSender;
81 class GroupedListWidget;
82 class ContainerWidget;
83 class EntryContainerWidget;
84 class GridWidget;
85 class ButtonWidget;
86 class PicButtonWidget;
87 class GraphicsWidget;
88 class StaticTextWidget;
89 class EditTextWidget;
90 class SaveLoadChooser;
91 class PopUpWidget;
93 
94 struct LauncherEntry {
95  Common::String key;
96  Common::String engineid;
97  Common::String gameid;
99  Common::String title;
100  const Common::ConfigManager::Domain *domain;
101 
102  LauncherEntry(const Common::String &k, const Common::String &e, const Common::String &g,
103  const Common::String &d, const Common::String &t, const Common::ConfigManager::Domain *v) :
104  key(k), engineid(e), gameid(g), description(d), title(t), domain(v) {
105  }
106 };
107 
108 class LauncherDialog : public Dialog {
109 public:
110  LauncherDialog(const Common::String &dialogName);
111  ~LauncherDialog() override;
112 
113  void rebuild();
114 
115  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
116 
117  virtual LauncherDisplayType getType() const = 0;
118 
119  int run();
120 
121  void handleKeyDown(Common::KeyState state) override;
122  void handleKeyUp(Common::KeyState state) override;
123  void handleOtherEvent(const Common::Event &evt) override;
124  bool doGameDetection(const Common::Path &path);
125  Common::String getGameConfig(int item, Common::String key);
126 protected:
127  EditTextWidget *_searchWidget;
128 #ifndef DISABLE_FANCY_THEMES
129  GraphicsWidget *_logo;
130  GraphicsWidget *_searchPic;
131  GraphicsWidget *_groupPic;
132 #endif
133  StaticTextWidget *_searchDesc;
134  ButtonWidget *_searchClearButton;
135  ButtonWidget *_addButton;
136  Widget *_removeButton;
137  Widget *_startButton;
138  ButtonWidget *_loadButton;
139  Widget *_editButton;
140  Widget *_mainHelpButton;
141  Common::StringArray _domains;
142  BrowserDialog *_browser;
143  SaveLoadChooser *_loadDialog;
144  PopUpWidget *_grpChooserPopup;
145  StaticTextWidget *_grpChooserDesc;
146  GroupingMethod _groupBy;
147  Common::String _title;
148  Common::String _search;
149  MetadataParser _metadataParser;
150  Common::StringArray _domainTitles; // Store game titles for each domain
151 
152 #ifndef DISABLE_LAUNCHERDISPLAY_GRID
153  ButtonWidget *_listButton;
154  ButtonWidget *_gridButton;
155 
160  void addLayoutChooserButtons();
161  ButtonWidget *createSwitchButton(const Common::String &name, const Common::U32String &desc, const Common::U32String &tooltip, const char *image, uint32 cmd = 0);
162 #endif // !DISABLE_LAUNCHERDISPLAY_GRID
163 
164  void reflowLayout() override;
165 
170  virtual void updateListing(int selPos = -1) = 0;
171 
172  virtual int getItemPos(int item) = 0;
173 
174  virtual void updateButtons() = 0;
175 
176  virtual void build();
177  void clean();
178 
179  void open() override;
180  void close() override;
181 
185  virtual void addGame();
186  void massAddGame();
187 
191  void removeGame(int item);
192 
196  void removeGamesWithAddons(const Common::StringArray &domainsToRemove);
197 
202  void removeGames(const Common::Array<bool> &selectedItems, bool isGrid);
203 
209  void confirmRemoveGames(const Common::Array<bool> &selectedItems);
210 
215  virtual void updateSelectionAfterRemoval() = 0;
216 
220  bool hasAnySelection(const Common::Array<bool> &selectedItems) const;
221 
222  // Get the selected items from the current view (list or grid).
223  virtual const Common::Array<bool>& getSelectedItems() const = 0;
224 
228  void editGame(int item);
229 
233  void recordGame(int item);
234 
238  void loadGame(int item);
239 
240  Common::Array<LauncherEntry> generateEntries(const Common::ConfigManager::DomainMap &domains, bool skipAddOns);
241 
248  virtual void selectTarget(const Common::String &target) = 0;
249  virtual int getSelected() = 0;
250 private:
252 
253  bool checkModifier(int modifier);
254 };
255 
261 public:
262  RemovalConfirmationDialog(const Common::U32String &message, const Common::StringArray &gameTitles);
263  ~RemovalConfirmationDialog() override;
264 
265  void reflowLayout() override;
266  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
267 
268  static const uint32 kRemovalYes = 1;
269  static const uint32 kRemovalNo = 2;
270 
271 private:
272  static const int kHorizontalMargin = 10;
273  static const int kButtonSpacing = 10;
274  static const int kGamePadding = 10;
275 
276  // Pre-calculated values
277  const int _buttonWidth;
278  const int _buttonHeight;
279  const int _scrollbarWidth;
280 
281  Common::U32String _message;
282  Common::StringArray _gameTitles;
283  ScrollContainerWidget *_scrollContainer;
284  Common::Array<StaticTextWidget *> _messageWidgets;
285  Common::Array<StaticTextWidget *> _gameNameWidgets;
287  Common::Array<Common::U32String> _messageLines;
288  int _maxlineWidth;
289 };
290 
292 protected:
293  LauncherDialog *_impl;
294 
295 public:
296  LauncherChooser();
297  ~LauncherChooser();
298 
299  int runModal();
300  void selectLauncher();
301 };
302 
304 public:
305  LauncherSimple(const Common::String &title);
306  ~LauncherSimple() override;
307 
308  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
309  void handleKeyDown(Common::KeyState state) override;
310 
311  LauncherDisplayType getType() const override { return kLauncherDisplayList; }
312 
313 protected:
314  void updateSelectionAfterRemoval() override;
315  const Common::Array<bool>& getSelectedItems() const override;
316  void updateListing(int selPos = -1) override;
317  int getItemPos(int item) override;
318  void groupEntries(const Common::Array<LauncherEntry> &metadata);
319  void updateButtons() override;
320  void selectTarget(const Common::String &target) override;
321  int getSelected() override;
322  void build() override;
323 
324 private:
325  GroupedListWidget *_list;
326 };
327 
328 } // End of namespace GUI
329 
330 #endif
const char * name
Definition: launcher.h:61
Definition: str.h:59
Definition: launcher.h:108
Definition: widget.h:445
Definition: edittext.h:32
Definition: grid.h:100
Definition: scrollcontainer.h:31
Definition: widget.h:307
Definition: path.h:52
Definition: widget.h:206
Definition: groupedlist.h:32
Definition: launcher.h:303
Definition: printman.h:30
Definition: MetadataParser.h:75
Definition: launcher.h:94
Definition: saveload.h:32
Definition: ustr.h:57
GroupingMethod id
Definition: launcher.h:76
Definition: events.h:210
Definition: config-manager.h:59
Definition: browser.h:36
Definition: launcher.h:57
Definition: launcher.h:291
const char * description
Definition: launcher.h:66
Definition: dialog.h:49
const char * lowresDescription
Definition: launcher.h:71
Definition: widget.h:101
Definition: keyboard.h:294
Definition: widget.h:515
Definition: widget.h:234
Definition: launcher.h:260
Definition: popup.h:39
Definition: object.h:40