ScummVM API documentation
menumodule.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 NEVERHOOD_MENUMODULE_H
23 #define NEVERHOOD_MENUMODULE_H
24 
25 #include "common/str.h"
26 #include "common/str-array.h"
27 #include "neverhood/neverhood.h"
28 #include "neverhood/module.h"
29 #include "neverhood/scene.h"
30 
31 namespace Neverhood {
32 
33 struct SavegameItem {
34  int slotNum;
35  Common::String description;
36 };
37 
39 
40 class MenuModule : public Module {
41 public:
42  MenuModule(NeverhoodEngine *vm, Module *parentModule, int which);
43  ~MenuModule() override;
44  void setLoadgameInfo(uint index);
45  void setLoadgameSlot(int slot);
46  void setSavegameInfo(const Common::String &description, uint index, bool newSavegame);
47  void setDeletegameInfo(uint index);
48  void refreshSaveGameList();
49 protected:
50  int _sceneNum;
51  byte *_savedPaletteData;
52  SavegameList *_savegameList;
53  Common::String _savegameDescription;
54  int _savegameSlot;
55  void createScene(int sceneNum, int which);
56  void updateScene();
57  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
58  void createLoadGameMenu();
59  void createSaveGameMenu();
60  void createDeleteGameMenu();
61  void handleLoadGameMenuAction(bool doLoad);
62  void handleSaveGameMenuAction(bool doSave, bool doQuery);
63  void handleDeleteGameMenuAction(bool doDelete);
64  void loadSavegameList();
65 };
66 
67 class MenuButton : public StaticSprite {
68 public:
69  MenuButton(NeverhoodEngine *vm, Scene *parentScene, uint buttonIndex, uint32 fileHash, const NRect &collisionBounds);
70 protected:
71  Scene *_parentScene;
72  int _countdown;
73  uint _buttonIndex;
74  void update();
75  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
76 };
77 
78 class MainMenu : public Scene {
79 public:
80  MainMenu(NeverhoodEngine *vm, Module *parentModule);
81  bool hasMakingOf() const;
82 protected:
83  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
84 };
85 
86 class CreditsScene : public Scene {
87 public:
88  CreditsScene(NeverhoodEngine *vm, Module *parentModule, bool canAbort);
89  ~CreditsScene() override;
90 protected:
91  int _screenIndex;
92  int _countdown;
93  MusicResource *_musicResource;
94  uint32 _ticksTime;
95  uint32 _ticksDuration;
96  bool _canAbort;
97  void update();
98  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
99 };
100 
101 class Widget;
102 class GameStateMenu;
103 
104 class Widget : public StaticSprite {
105 public:
106  Widget(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
107  int baseObjectPriority, int baseSurfacePriority);
108  virtual void onClick();
109  virtual void setPosition(int16 x, int16 y);
110  virtual void refreshPosition();
111  virtual void initialize();
112  virtual int16 getWidth();
113  virtual int16 getHeight();
114  virtual void enterWidget();
115  virtual void exitWidget();
116 protected:
117  GameStateMenu *_parentScene;
118  int _baseObjectPriority;
119  int _baseSurfacePriority;
120  void update();
121  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
122 };
123 
124 class TextLabelWidget : public Widget {
125 public:
126  TextLabelWidget(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
127  int baseObjectPriority, int baseSurfacePriority,
128  const byte *string, int stringLen, const Common::SharedPtr<BaseSurface> &drawSurface, int16 tx, int16 ty, const Common::SharedPtr<FontSurface> &fontSurface);
129  void initialize() override;
130  int16 getWidth() override;
131  int16 getHeight() override;
132  void drawString(int maxStringLength);
133  void clear();
134  void setString(const byte *string, int stringLen);
135  Common::SharedPtr<FontSurface> getFontSurface() const { return _fontSurface; }
136 protected:
137  Common::SharedPtr<BaseSurface> _drawSurface;
138  int16 _tx, _ty;
139  Common::SharedPtr<FontSurface> _fontSurface;
140  const byte *_string;
141  int _stringLen;
142 };
143 
144 class TextEditWidget : public Widget {
145 public:
146  TextEditWidget(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
147  int maxStringLength, const Common::SharedPtr<FontSurface> &fontSurface, uint32 fileHash, const NRect &rect);
148  ~TextEditWidget() override;
149  void onClick() override;
150  void initialize() override;
151  void enterWidget() override;
152  void exitWidget() override;
153  void setCursor(uint32 cursorFileHash, int16 cursorWidth, int16 cursorHeight);
154  void drawCursor();
155  void updateString();
156  Common::String& getString();
157  void setString(const Common::String &string);
158  void handleAsciiKey(char ch);
159  void handleKeyDown(Common::KeyCode keyCode);
160  void refresh();
161  void setReadOnly(bool value) { _readOnly = value; }
162  bool isReadOnly() const { return _readOnly; }
163  bool isModified() const { return _modified; }
164 protected:
165  NRect _rect;
166  uint32 _fileHash;
167  int _maxVisibleChars;
168  int _maxStringLength;
169  int _cursorPos;
170  int _cursorTicks;
171  Common::String _entryString;
172  Common::SharedPtr<FontSurface> _fontSurface;
173  TextLabelWidget *_textLabelWidget;
174  BaseSurface *_cursorSurface;
175  uint32 _cursorFileHash;
176  int16 _cursorWidth, _cursorHeight;
177  bool _modified;
178  bool _readOnly;
179  void update();
180  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
181 };
182 
183 class SavegameListBox : public Widget {
184 public:
185  SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene,
186  SavegameList *savegameList, const Common::SharedPtr<FontSurface> &fontSurface, uint32 bgFileHash, const NRect &rect);
187  void onClick() override;
188  void initialize() override;
189  void buildItems();
190  void drawItems();
191  void refresh();
192  void scrollUp();
193  void scrollDown();
194  void pageUp();
195  void pageDown();
196  uint getCurrIndex() const { return _currIndex; }
197 protected:
198  const NRect _rect;
199  uint32 _bgFileHash;
200  int _maxStringLength;
201  Common::Array<TextLabelWidget*> _textLabelItems;
202  int _firstVisibleItem;
203  int _lastVisibleItem;
204  SavegameList *_savegameList;
205  Common::SharedPtr<FontSurface> _fontSurface;
206  uint _currIndex;
207  int _maxVisibleItemsCount;
208 };
209 
210 class GameStateMenu : public Scene {
211 public:
212  GameStateMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList,
213  const uint32 *buttonFileHashes, const NRect *buttonCollisionBounds,
214  uint32 backgroundFileHash, uint32 fontFileHash,
215  uint32 mouseFileHash, const NRect *mouseRect,
216  uint32 listBoxBackgroundFileHash, int16 listBoxX, int16 listBoxY, const NRect &listBoxRect,
217  uint32 textEditBackgroundFileHash, uint32 textEditCursorFileHash, int16 textEditX, int16 textEditY, const NRect &textEditRect,
218  uint32 textFileHash1, uint32 textFileHash2);
219  NPoint getMousePos();
220  virtual void setCurrWidget(Widget *newWidget);
221  virtual Widget *getCurrWidget() { return _currWidget; }
222  virtual void refreshDescriptionEdit();
223 protected:
224  Widget *_currWidget;
225  SavegameList *_savegameList;
226  Common::SharedPtr<FontSurface> _fontSurface;
227  SavegameListBox *_listBox;
228  TextEditWidget *_textEditWidget;
229  Common::String _savegameDescription;
230  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
231  virtual void performAction();
232  int scummVMSaveLoadDialog(bool isSave, Common::String &saveDesc);
233 };
234 
235 class SaveGameMenu : public GameStateMenu {
236 public:
237  SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList);
238 protected:
239  void performAction() override;
240 };
241 
242 class LoadGameMenu : public GameStateMenu {
243 public:
244  LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList);
245 protected:
246  void performAction() override;
247 };
248 
250 public:
251  DeleteGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList);
252 protected:
253  void performAction() override;
254 };
255 
256 class QueryOverwriteMenu : public Scene {
257 public:
258  QueryOverwriteMenu(NeverhoodEngine *vm, Module *parentModule, const Common::String &description);
259 protected:
260  void update();
261  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
262  void displayOverwriteStrings(const Common::String &description);
263 };
264 
265 } // End of namespace Neverhood
266 
267 #endif /* NEVERHOOD_MENUMODULE_H */
Definition: menumodule.h:124
Definition: background.h:30
Definition: menumodule.h:256
Definition: str.h:59
Definition: menumodule.h:40
Definition: menumodule.h:183
Definition: menumodule.h:67
Definition: menumodule.h:249
Definition: neverhood.h:60
Definition: array.h:52
Definition: menumodule.h:86
Definition: graphics.h:42
Definition: entity.h:42
Definition: entity.h:77
Definition: menumodule.h:78
Definition: menumodule.h:33
Definition: scene.h:41
Definition: menumodule.h:144
Definition: sound.h:62
Definition: menumodule.h:210
Definition: sprite.h:119
Definition: module.h:45
Definition: menumodule.h:242
Definition: ptr.h:159
Definition: graphics.h:85
Definition: menumodule.h:104
Definition: menumodule.h:235
Definition: graphics.h:32