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 NEVERHOOD_MENUMODULE_H 24 #define NEVERHOOD_MENUMODULE_H 25 26 #include "common/str.h" 27 #include "common/str-array.h" 28 #include "neverhood/neverhood.h" 29 #include "neverhood/module.h" 30 #include "neverhood/scene.h" 31 32 namespace Neverhood { 33 34 struct SavegameItem { 35 int slotNum; 36 Common::String description; 37 }; 38 39 typedef Common::Array<SavegameItem> SavegameList; 40 41 class MenuModule : public Module { 42 public: 43 MenuModule(NeverhoodEngine *vm, Module *parentModule, int which); 44 ~MenuModule() override; 45 void setLoadgameInfo(uint index); 46 void setLoadgameSlot(int slot); 47 void setSavegameInfo(const Common::String &description, uint index, bool newSavegame); 48 void setDeletegameInfo(uint index); 49 void refreshSaveGameList(); 50 protected: 51 int _sceneNum; 52 byte *_savedPaletteData; 53 SavegameList *_savegameList; 54 Common::String _savegameDescription; 55 int _savegameSlot; 56 void createScene(int sceneNum, int which); 57 void updateScene(); 58 uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); 59 void createLoadGameMenu(); 60 void createSaveGameMenu(); 61 void createDeleteGameMenu(); 62 void handleLoadGameMenuAction(bool doLoad); 63 void handleSaveGameMenuAction(bool doSave, bool doQuery); 64 void handleDeleteGameMenuAction(bool doDelete); 65 void loadSavegameList(); 66 }; 67 68 class MenuButton : public StaticSprite { 69 public: 70 MenuButton(NeverhoodEngine *vm, Scene *parentScene, uint buttonIndex, uint32 fileHash, const NRect &collisionBounds); 71 protected: 72 Scene *_parentScene; 73 int _countdown; 74 uint _buttonIndex; 75 void update(); 76 uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); 77 }; 78 79 class MainMenu : public Scene { 80 public: 81 MainMenu(NeverhoodEngine *vm, Module *parentModule); 82 protected: 83 uint32 handleMessage(int messageNum, const MessageParam ¶m, 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 ¶m, 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 ¶m, 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, BaseSurface *drawSurface, int16 tx, int16 ty, 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); getFontSurface()135 FontSurface *getFontSurface() const { return _fontSurface; } 136 protected: 137 BaseSurface *_drawSurface; 138 int16 _tx, _ty; 139 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, 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(); setReadOnly(bool value)161 void setReadOnly(bool value) { _readOnly = value; } isReadOnly()162 bool isReadOnly() const { return _readOnly; } isModified()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 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 ¶m, Entity *sender); 181 }; 182 183 class SavegameListBox : public Widget { 184 public: 185 SavegameListBox(NeverhoodEngine *vm, int16 x, int16 y, GameStateMenu *parentScene, 186 SavegameList *savegameList, 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(); getCurrIndex()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 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 ~GameStateMenu() override; 220 NPoint getMousePos(); 221 virtual void setCurrWidget(Widget *newWidget); getCurrWidget()222 virtual Widget *getCurrWidget() { return _currWidget; } 223 virtual void refreshDescriptionEdit(); 224 protected: 225 Widget *_currWidget; 226 SavegameList *_savegameList; 227 FontSurface *_fontSurface; 228 SavegameListBox *_listBox; 229 TextEditWidget *_textEditWidget; 230 Common::String _savegameDescription; 231 uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); 232 virtual void performAction(); 233 int scummVMSaveLoadDialog(bool isSave, Common::String &saveDesc); 234 }; 235 236 class SaveGameMenu : public GameStateMenu { 237 public: 238 SaveGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList); 239 protected: 240 void performAction() override; 241 }; 242 243 class LoadGameMenu : public GameStateMenu { 244 public: 245 LoadGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList); 246 protected: 247 void performAction() override; 248 }; 249 250 class DeleteGameMenu : public GameStateMenu { 251 public: 252 DeleteGameMenu(NeverhoodEngine *vm, Module *parentModule, SavegameList *savegameList); 253 protected: 254 void performAction() override; 255 }; 256 257 class QueryOverwriteMenu : public Scene { 258 public: 259 QueryOverwriteMenu(NeverhoodEngine *vm, Module *parentModule, const Common::String &description); 260 protected: 261 void update(); 262 uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); 263 }; 264 265 } // End of namespace Neverhood 266 267 #endif /* NEVERHOOD_MENUMODULE_H */ 268