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 SWORD1_CONTROL_H 24 #define SWORD1_CONTROL_H 25 26 #include "common/scummsys.h" 27 #include "common/events.h" 28 #include "common/str-array.h" 29 #include "sword1/sworddefs.h" 30 31 class OSystem; 32 namespace Common { 33 class SaveFileManager; 34 class MemoryWriteStreamDynamic; 35 } 36 37 namespace Sword1 { 38 39 class ObjectMan; 40 class ResMan; 41 class Mouse; 42 class Music; 43 class Sound; 44 45 #define SAVEGAME_HEADER MKTAG('B','S','_','1') 46 #define SAVEGAME_VERSION 2 47 48 #define MAX_BUTTONS 16 49 50 #define CONTROL_NOTHING_DONE 0 51 #define CONTROL_GAME_RESTORED 1 52 #define CONTROL_RESTART_GAME 2 53 54 class ControlButton { 55 public: 56 ControlButton(uint16 x, uint16 y, uint32 resId, uint8 id, uint8 flag, ResMan *pResMan, uint8 *screenBuf, OSystem *system); 57 ~ControlButton(); 58 void draw(); 59 bool wasClicked(uint16 mouseX, uint16 mouseY); 60 void setSelected(uint8 selected); 61 bool isSaveslot(); 62 uint8 _id; 63 uint8 _flag; 64 private: 65 int _frameIdx; 66 uint16 _x, _y; 67 uint16 _width, _height; 68 uint32 _resId; 69 ResMan *_resMan; 70 uint8 *_dstBuf; 71 OSystem *_system; 72 }; 73 74 enum { 75 kButtonOk = 1, 76 kButtonCancel = 2 77 }; 78 79 struct ButtonInfo { 80 uint16 x, y; 81 uint32 resId, id; 82 uint8 flag; 83 }; 84 85 class Control { 86 public: 87 Control(Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic); 88 uint8 runPanel(); 89 void doRestore(); 90 void askForCd(); 91 bool savegamesExist(); 92 void readSavegameDescriptions(); 93 void saveGameToFile(uint8 slot); 94 bool restoreGameFromFile(uint8 slot); 95 void checkForOldSaveGames(); 96 bool isPanelShown(); 97 setSaveDescription(int slot,const char * desc)98 void setSaveDescription(int slot, const char *desc) { 99 _saveNames[slot] = desc; 100 } 101 102 private: 103 int displayMessage(const char *altButton, const char *message, ...) GCC_PRINTF(3, 4); 104 105 bool convertSaveGame(uint8 slot, char *desc); 106 void showSavegameNames(); 107 void deselectSaveslots(); 108 uint8 *_restoreBuf; 109 uint8 _saveFiles; 110 uint8 _numSaves; 111 uint8 _saveScrollPos; 112 uint8 _selectedSavegame; 113 Common::StringArray _saveNames; 114 Common::String _oldName; 115 uint8 _cursorTick; 116 bool _cursorVisible; 117 bool _panelShown; 118 Common::MemoryWriteStreamDynamic *_tempThumbnail; 119 120 uint8 getClicks(uint8 mode, uint8 *retVal); 121 uint8 handleButtonClick(uint8 id, uint8 mode, uint8 *retVal); 122 void handleVolumeClicks(); 123 void changeVolume(uint8 id, uint8 action); 124 125 void setupMainPanel(); 126 void setupSaveRestorePanel(bool saving); 127 void setupVolumePanel(); 128 bool getConfirm(const uint8 *title); 129 130 void saveNameScroll(uint8 scroll, bool saving); 131 void saveNameSelect(uint8 id, bool saving); 132 bool saveToFile(); 133 bool restoreFromFile(); 134 bool keyAccepted(uint16 ascii); 135 void handleSaveKey(Common::KeyState kbd); 136 137 void renderVolumeBar(uint8 id, uint8 volL, uint8 volR); 138 uint16 getTextWidth(const uint8 *str); 139 void renderText(const uint8 *str, uint16 x, uint16 y, uint8 mode); 140 uint8 _numButtons; 141 uint8 _selectedButton; 142 void createButtons(const ButtonInfo *buttons, uint8 num); 143 void destroyButtons(); 144 ControlButton *_buttons[MAX_BUTTONS]; 145 static const ButtonInfo _deathButtons[3], _panelButtons[7], _saveButtons[16], _volumeButtons[4]; 146 static const uint8 _languageStrings[8 * 20][43]; 147 const uint8(*_lStrings)[43]; 148 Common::SaveFileManager *_saveFileMan; 149 ObjectMan *_objMan; 150 ResMan *_resMan; 151 OSystem *_system; 152 Mouse *_mouse; 153 Music *_music; 154 Sound *_sound; 155 uint8 *_font, *_redFont; 156 uint8 *_screenBuf; 157 Common::KeyState _keyPressed; 158 void delay(uint32 msecs); 159 Common::Point _mouseCoord; 160 uint16 _mouseState; 161 bool _mouseDown; 162 }; 163 164 } // End of namespace Sword1 165 166 #endif //BSCONTROL_H 167