File: saveloadmenu.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (182 lines) | stat: -rw-r--r-- 4,518 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef STARK_UI_MENU_SAVELOAD_MENU_H
#define STARK_UI_MENU_SAVELOAD_MENU_H

#include "engines/stark/ui/menu/locationscreen.h"
#include "engines/stark/visual/text.h"

#include "common/error.h"

namespace Stark {

namespace Gfx {
class Bitmap;
class SurfaceRenderer;
}

class SaveDataWidget;

/**
 * The base class of the save and load menu of the game
 */
class SaveLoadMenuScreen : public StaticLocationScreen {
public:
	static const int _slotPerRow = 3;
	static const int _slotPerColumn = 3;
	static const int _slotPerPage = 9;

	SaveLoadMenuScreen(Gfx::Driver *gfx, Cursor *cursor, Screen::Name screenName);
	virtual ~SaveLoadMenuScreen();

	// StaticLocationScreen API
	void open() override;
	void close() override;

	/** Called when a SaveDataWidget is selected */
	virtual void onWidgetSelected(SaveDataWidget *widget) = 0;

	/** Check whether the menu is used for saving */
	virtual bool isSaveMenu() = 0;

protected:
	static void checkError(Common::Error error);

	enum WidgetIndex {
		kWidgetSaveText = 3,
		kWidgetLoadText = 4,
		kWidgetBack = 5,
		kWidgetNext = 6
	};

private:
	// Start from zero
	int _page;
	int _maxPage;

	void backHandler();

	void prevPageHandler() { changePage(_page - 1); }
	void nextPageHandler() { changePage(_page + 1); }

	void removeSaveDataWidgets();
	void loadSaveData(int page);
	void changePage(int page);
	int computeMaxPage();
};

/**
 * The save menu of the game
 */
class SaveMenuScreen : public SaveLoadMenuScreen {
public:
	SaveMenuScreen(Gfx::Driver *gfx, Cursor *cursor) :
			SaveLoadMenuScreen(gfx, cursor, Screen::kScreenSaveMenu),
			_slotToSaveAfterConfirm(nullptr) {}
	virtual ~SaveMenuScreen() {}

	// SaveLoadMenuScreen API
	void open() override;

	void onWidgetSelected(SaveDataWidget *widget) override;

	bool isSaveMenu() override { return true; }

private:
	void saveGameToSlot(SaveDataWidget *widget);
	void saveConfirmSlot();

	SaveDataWidget *_slotToSaveAfterConfirm;
};

/**
 * The load menu of the game
 */
class LoadMenuScreen : public SaveLoadMenuScreen {
public:
	LoadMenuScreen(Gfx::Driver *gfx, Cursor *cursor) :
			SaveLoadMenuScreen(gfx, cursor, Screen::kScreenLoadMenu),
			_slotToLoadAfterConfirm(-1) {}
	~LoadMenuScreen() override {}

	// SaveLoadMenuScreen API
	void open() override;

	void onWidgetSelected(SaveDataWidget *widget) override;

	bool isSaveMenu() override { return false; }

private:
	void loadConfirmSlot();

	int _slotToLoadAfterConfirm;
};

/**
 * The widget of save data
 */
class SaveDataWidget : public StaticLocationWidget {
public:
	SaveDataWidget(int slot, Gfx::Driver *gfx, SaveLoadMenuScreen *screen);
	~SaveDataWidget();

	// StaticLocationWidget API
	void render() override;
	bool isMouseInside(const Common::Point &mousePos) const override;
	void onClick() override;
	void onMouseMove(const Common::Point &mousePos) override;
	void onScreenChanged() override;

	int getSlot() { return _slot; }
	Common::String getName() { return _name; }

	/** Load the thumbnail and info from the save data */
	void loadSaveDataElements();

	/** Check whether the save slot has data */
	bool hasSave() { return _hasSave; }

private:
	const Gfx::Color _outlineColor = Gfx::Color(0x1E, 0x1E, 0x96);
	const Gfx::Color _textColor = Gfx::Color(0x5C, 0x48, 0x3D);

	int _slot;
	SaveLoadMenuScreen *_screen;

	Common::Point _thumbPos, _textDescPos, _textTimePos;
	int _thumbWidth, _thumbHeight;

	Gfx::Bitmap *_bitmap;
	Gfx::Bitmap *_outline;
	Gfx::SurfaceRenderer *_surfaceRenderer;

	VisualText _textDesc, _textTime;

	bool _isMouseHovered;
	bool _hasSave;

	Common::String _name;
};

} // End of namespace Stark

#endif // STARK_UI_MENU_SETTING_MENU_H