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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GUI_SAVELOAD_DIALOG_H
24 #define GUI_SAVELOAD_DIALOG_H
25 
26 #include "gui/dialog.h"
27 #include "gui/widgets/list.h"
28 
29 #include "engines/metaengine.h"
30 
31 namespace GUI {
32 
33 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
34 enum SaveLoadCloudSyncProgress {
35 	kSavesSyncProgressCmd = 'SSPR',
36 	kSavesSyncEndedCmd = 'SSEN'
37 };
38 
39 class SaveLoadCloudSyncProgressDialog : public Dialog { //protected?
40 	StaticTextWidget *_label, *_percentLabel;
41 	SliderWidget *_progressBar;
42 	bool _close;
43 public:
44 	SaveLoadCloudSyncProgressDialog(bool canRunInBackground);
45 	virtual ~SaveLoadCloudSyncProgressDialog();
46 
47 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
48 	virtual void handleTickle();
49 };
50 #endif
51 
52 #define kSwitchSaveLoadDialog -2
53 
54 // TODO: We might want to disable the grid based save/load chooser for more
55 // platforms, than those which define DISABLE_FANCY_THEMES. But those are
56 // probably not able to handle the grid chooser anyway, so disabling it
57 // for them is a good start.
58 #ifdef DISABLE_FANCY_THEMES
59 #define DISABLE_SAVELOADCHOOSER_GRID
60 #endif // DISABLE_FANCY_THEMES
61 
62 #ifndef DISABLE_SAVELOADCHOOSER_GRID
63 enum SaveLoadChooserType {
64 	kSaveLoadDialogList = 0,
65 	kSaveLoadDialogGrid = 1
66 };
67 
68 SaveLoadChooserType getRequestedSaveLoadDialog(const MetaEngine &metaEngine);
69 #endif // !DISABLE_SAVELOADCHOOSER_GRID
70 
71 class SaveLoadChooserDialog : protected Dialog {
72 public:
73 	SaveLoadChooserDialog(const Common::String &dialogName, const bool saveMode);
74 	SaveLoadChooserDialog(int x, int y, int w, int h, const bool saveMode);
75 	virtual ~SaveLoadChooserDialog();
76 
77 	virtual void open();
78 	virtual void close();
79 
80 	virtual void reflowLayout();
81 
82 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
83 
84 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
85 	virtual void runSaveSync(bool hasSavepathOverride);
86 #endif
87 
88 	virtual void handleTickle();
89 
90 #ifndef DISABLE_SAVELOADCHOOSER_GRID
91 	virtual SaveLoadChooserType getType() const = 0;
92 #endif // !DISABLE_SAVELOADCHOOSER_GRID
93 
94 	int run(const Common::String &target, const MetaEngine *metaEngine);
95 	virtual const Common::String &getResultString() const = 0;
96 
97 protected:
98 	virtual int runIntern() = 0;
99 
100 	/** Common function to refresh the list on the screen. */
101 	virtual void updateSaveList();
102 
103 	/**
104 	* Common function to get saves list from MetaEngine.
105 	*
106 	* It also checks whether there are some locked saves
107 	* because of saves sync and adds such saves as locked
108 	* slots. User sees these slots, but is unable to save
109 	* or load from these.
110 	*/
111 	virtual void listSaves();
112 
113 	const bool				_saveMode;
114 	const MetaEngine		*_metaEngine;
115 	bool					_delSupport;
116 	bool					_metaInfoSupport;
117 	bool					_thumbnailSupport;
118 	bool					_saveDateSupport;
119 	bool					_playTimeSupport;
120 	Common::String			_target;
121 	bool _dialogWasShown;
122 	SaveStateList			_saveList;
123 
124 #ifndef DISABLE_SAVELOADCHOOSER_GRID
125 	ButtonWidget *_listButton;
126 	ButtonWidget *_gridButton;
127 
128 	void addChooserButtons();
129 	ButtonWidget *createSwitchButton(const Common::String &name, const char *desc, const char *tooltip, const char *image, uint32 cmd = 0);
130 #endif // !DISABLE_SAVELOADCHOOSER_GRID
131 };
132 
133 class SaveLoadChooserSimple : public SaveLoadChooserDialog {
134 	typedef Common::String String;
135 	typedef Common::Array<Common::String> StringArray;
136 public:
137 	SaveLoadChooserSimple(const String &title, const String &buttonLabel, bool saveMode);
138 
139 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
140 
141 	virtual const Common::String &getResultString() const;
142 
143 	virtual void reflowLayout();
144 
145 #ifndef DISABLE_SAVELOADCHOOSER_GRID
getType()146 	virtual SaveLoadChooserType getType() const { return kSaveLoadDialogList; }
147 #endif // !DISABLE_SAVELOADCHOOSER_GRID
148 
149 	virtual void open();
150 	virtual void close();
151 protected:
152 	virtual void updateSaveList();
153 private:
154 	virtual int runIntern();
155 
156 	ListWidget		*_list;
157 	ButtonWidget	*_chooseButton;
158 	ButtonWidget	*_deleteButton;
159 	GraphicsWidget	*_gfxWidget;
160 	ContainerWidget	*_container;
161 	StaticTextWidget	*_date;
162 	StaticTextWidget	*_time;
163 	StaticTextWidget	*_playtime;
164 
165 	String					_resultString;
166 
167 	void updateSelection(bool redraw);
168 };
169 
170 #ifndef DISABLE_SAVELOADCHOOSER_GRID
171 
172 class EditTextWidget;
173 
174 class SavenameDialog : public Dialog {
175 public:
176 	SavenameDialog();
177 
178 	void setDescription(const Common::String &desc);
179 	const Common::String &getDescription();
180 
setTargetSlot(int slot)181 	void setTargetSlot(int slot) { _targetSlot = slot; }
182 
183 	virtual void open();
184 protected:
185 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
186 private:
187 	int _targetSlot;
188 	StaticTextWidget *_title;
189 	EditTextWidget *_description;
190 };
191 
192 class SaveLoadChooserGrid : public SaveLoadChooserDialog {
193 public:
194 	SaveLoadChooserGrid(const Common::String &title, bool saveMode);
195 	~SaveLoadChooserGrid();
196 
197 	virtual const Common::String &getResultString() const;
198 
199 	virtual void open();
200 
201 	virtual void reflowLayout();
202 
getType()203 	virtual SaveLoadChooserType getType() const { return kSaveLoadDialogGrid; }
204 
205 	virtual void close();
206 protected:
207 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
208 	virtual void handleMouseWheel(int x, int y, int direction);
209 	virtual void updateSaveList();
210 private:
211 	virtual int runIntern();
212 
213 	uint _columns, _lines;
214 	uint _entriesPerPage;
215 	uint _curPage;
216 
217 	ButtonWidget *_nextButton;
218 	ButtonWidget *_prevButton;
219 
220 	StaticTextWidget *_pageDisplay;
221 
222 	ContainerWidget *_newSaveContainer;
223 	int _nextFreeSaveSlot;
224 	Common::String _resultString;
225 
226 	SavenameDialog _savenameDialog;
227 	bool selectDescription();
228 
229 	struct SlotButton {
SlotButtonSlotButton230 		SlotButton() : container(0), button(0), description(0) {}
SlotButtonSlotButton231 		SlotButton(ContainerWidget *c, PicButtonWidget *b, StaticTextWidget *d) : container(c), button(b), description(d) {}
232 
233 		ContainerWidget  *container;
234 		PicButtonWidget  *button;
235 		StaticTextWidget *description;
236 
setVisibleSlotButton237 		void setVisible(bool state) {
238 			container->setVisible(state);
239 		}
240 	};
241 	typedef Common::Array<SlotButton> ButtonArray;
242 	ButtonArray _buttons;
243 	void destroyButtons();
244 	void hideButtons();
245 	void updateSaves();
246 };
247 
248 #endif // !DISABLE_SAVELOADCHOOSER_GRID
249 
250 } // End of namespace GUI
251 
252 #endif
253