ScummVM API documentation
saveload-dialog.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_SAVELOAD_DIALOG_H
23 #define GUI_SAVELOAD_DIALOG_H
24 
25 #include "gui/dialog.h"
26 #include "gui/widgets/list.h"
27 
28 #include "engines/metaengine.h"
29 
30 namespace GUI {
31 
32 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
33 class SaveLoadChooserDialog;
34 
35 class SaveLoadCloudSyncProgressDialog : public Dialog { //protected?
36  StaticTextWidget *_label, *_percentLabel;
37  SliderWidget *_progressBar;
38  SaveLoadChooserDialog *_parent;
39  bool _close;
40  int _pollFrame;
41 
42 public:
43  SaveLoadCloudSyncProgressDialog(bool canRunInBackground, SaveLoadChooserDialog *parent);
44  ~SaveLoadCloudSyncProgressDialog() override;
45 
46  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
47  void handleTickle() override;
48 
49 private:
50  void pollCloudMan();
51 };
52 #endif
53 
54 #define kSwitchSaveLoadDialog -2
55 
56 // TODO: We might want to disable the grid based save/load chooser for more
57 // platforms, than those which define DISABLE_FANCY_THEMES. But those are
58 // probably not able to handle the grid chooser anyway, so disabling it
59 // for them is a good start.
60 #ifdef DISABLE_FANCY_THEMES
61 #define DISABLE_SAVELOADCHOOSER_GRID
62 #endif // DISABLE_FANCY_THEMES
63 
64 #ifndef DISABLE_SAVELOADCHOOSER_GRID
65 enum SaveLoadChooserType {
66  kSaveLoadDialogList = 0,
67  kSaveLoadDialogGrid = 1
68 };
69 
70 SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngine *metaEngine);
71 #endif // !DISABLE_SAVELOADCHOOSER_GRID
72 
73 class SaveLoadChooserDialog : protected Dialog {
74 public:
75  SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode);
76  SaveLoadChooserDialog(int x, int y, int w, int h, const bool saveMode);
77  ~SaveLoadChooserDialog() override;
78 
79  void open() override;
80  void close() override;
81 
82  void reflowLayout() override;
83 
84  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
85 
86 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
87  virtual void runSaveSync(bool hasSavepathOverride);
88 #endif
89 
90  void handleTickle() override;
91 
92 #ifndef DISABLE_SAVELOADCHOOSER_GRID
93  virtual SaveLoadChooserType getType() const = 0;
94 #endif // !DISABLE_SAVELOADCHOOSER_GRID
95 
96  int run(const Common::String &target, const MetaEngine *metaEngine);
97  virtual const Common::U32String getResultString() const = 0;
98 
99 protected:
100  virtual int runIntern() = 0;
101 
103  virtual void updateSaveList();
104 
113  virtual void listSaves();
114 
115  void activate(int slot, const Common::U32String &description);
116 
117  const bool _saveMode;
118  const MetaEngine *_metaEngine;
119  bool _delSupport;
120  bool _metaInfoSupport;
121  bool _thumbnailSupport;
122  bool _saveDateSupport;
123  bool _playTimeSupport;
124  Common::String _target;
125  bool _dialogWasShown;
126  SaveStateList _saveList;
127  Common::U32String _resultString;
128 
129 #ifndef DISABLE_SAVELOADCHOOSER_GRID
130  ButtonWidget *_listButton;
131  ButtonWidget *_gridButton;
132 
133  void addChooserButtons();
134  ButtonWidget *createSwitchButton(const Common::String &name, const Common::U32String &desc, const Common::U32String &tooltip, const char *image, uint32 cmd = 0);
135 #endif // !DISABLE_SAVELOADCHOOSER_GRID
136 
137 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
138  int _pollFrame;
139  bool _didUpdateAfterSync;
140 
142  void pollCloudMan();
143 
144  friend class SaveLoadCloudSyncProgressDialog;
145 #endif
146 };
147 
149 public:
150  SaveLoadChooserSimple(const Common::U32String &title, const Common::U32String &buttonLabel, bool saveMode);
151 
152  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
153 
154  const Common::U32String getResultString() const override;
155 
156  void reflowLayout() override;
157 
158 #ifndef DISABLE_SAVELOADCHOOSER_GRID
159  SaveLoadChooserType getType() const override { return kSaveLoadDialogList; }
160 #endif // !DISABLE_SAVELOADCHOOSER_GRID
161 
162  void open() override;
163  void close() override;
164 protected:
165  void updateSaveList() override;
166 private:
167  int runIntern() override;
168 
169  ListWidget *_list;
170  ButtonWidget *_chooseButton;
171  ButtonWidget *_deleteButton;
172  GraphicsWidget *_gfxWidget;
173  ContainerWidget *_container;
174  StaticTextWidget *_date;
175  StaticTextWidget *_time;
176  StaticTextWidget *_playtime;
177  StaticTextWidget *_pageTitle;
178 
179  void addThumbnailContainer();
180  void updateSelection(bool redraw);
181 };
182 
183 #ifndef DISABLE_SAVELOADCHOOSER_GRID
184 
185 class EditTextWidget;
186 
187 class SavenameDialog : public Dialog {
188 public:
189  SavenameDialog();
190 
191  void setDescription(const Common::U32String &desc);
192  const Common::U32String &getDescription();
193 
194  void setTargetSlot(int slot) { _targetSlot = slot; }
195 
196  void open() override;
197 protected:
198  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
199 private:
200  int _targetSlot;
201  StaticTextWidget *_title;
202  EditTextWidget *_description;
203 };
204 
206 public:
207  SaveLoadChooserGrid(const Common::U32String &title, bool saveMode);
208  ~SaveLoadChooserGrid() override;
209 
210  const Common::U32String getResultString() const override;
211 
212  void open() override;
213 
214  void reflowLayout() override;
215 
216  SaveLoadChooserType getType() const override { return kSaveLoadDialogGrid; }
217 
218  void close() override;
219 protected:
220  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
221  void handleMouseWheel(int x, int y, int direction) override;
222  void updateSaveList() override;
223 private:
224  int runIntern() override;
225 
226  uint _columns, _lines;
227  uint _entriesPerPage;
228  uint _curPage;
229 
230  ButtonWidget *_nextButton;
231  ButtonWidget *_prevButton;
232 
233  StaticTextWidget *_pageTitle;
234  StaticTextWidget *_pageDisplay;
235 
236  ContainerWidget *_newSaveContainer;
237  int _nextFreeSaveSlot;
238 
239  SavenameDialog _savenameDialog;
240  bool selectDescription();
241 
242  struct SlotButton {
243  SlotButton() : container(nullptr), button(nullptr), description(nullptr) {}
244  SlotButton(ContainerWidget *c, PicButtonWidget *b, StaticTextWidget *d) : container(c), button(b), description(d) {}
245 
246  ContainerWidget *container;
247  PicButtonWidget *button;
248  StaticTextWidget *description;
249 
250  void setVisible(bool state) {
251  container->setVisible(state);
252  }
253  };
255  ButtonArray _buttons;
256  void destroyButtons();
257  void hideButtons();
258  void updateSaves();
259 };
260 
261 #endif // !DISABLE_SAVELOADCHOOSER_GRID
262 
263 } // End of namespace GUI
264 
265 #endif
Definition: metaengine.h:200
Definition: str.h:59
Definition: saveload-dialog.h:73
Definition: widget.h:441
Definition: saveload-dialog.h:205
Definition: edittext.h:32
Definition: widget.h:304
Definition: saveload-dialog.h:187
Definition: widget.h:204
Definition: system.h:45
Definition: saveload-dialog.h:148
Definition: ustr.h:57
Definition: list.h:49
Definition: dialog.h:49
Definition: widget.h:510
Definition: widget.h:231
Definition: object.h:40