ScummVM API documentation
menu.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 TWINE_MENU_H
23 #define TWINE_MENU_H
24 
25 #include "twine/twine.h"
26 #include "twine/text.h"
27 
28 namespace TwinE {
29 
30 #define MAX_BUTTONS 10
31 #define PLASMA_WIDTH 320
32 #define PLASMA_HEIGHT 50
33 #define kQuitEngine 9998
34 
35 class BodyData;
36 class SpriteData;
37 
38 class MenuSettings {
39 private:
40  enum MenuSettingsType {
41  // button number
42  MenuSettings_CurrentLoadedButton = 0,
43  // is used to calc the height where the first button will appear
44  MenuSettings_NumberOfButtons = 1,
45  MenuSettings_ButtonsBoxHeight = 2,
46  MenuSettings_HeaderEnd = 3, // TODO: unknown
47  MenuSettings_FirstButtonState = 4,
48  MenuSettings_FirstButton = 5
49  };
50 
51  int16 _settings[4 + MAX_BUTTONS * 2] {0};
52  Common::String _buttonTexts[MAX_BUTTONS];
53  int8 _activeButtonIdx = 0;
54 
55 public:
56  TextId getButtonTextId(int buttonIndex) const {
57  return (TextId)_settings[MenuSettings_FirstButton + buttonIndex * 2];
58  }
59 
60  void reset() {
61  for (int32 i = 0; i < MAX_BUTTONS; ++i) {
62  _buttonTexts[i] = "";
63  }
64  _settings[MenuSettings_NumberOfButtons] = 0;
65  setButtonsBoxHeight(0);
66  setActiveButton(0);
67  }
68 
69  // used to calc the height where the first button will appear
70  void setButtonsBoxHeight(int16 height) {
71  _settings[MenuSettings_ButtonsBoxHeight] = height;
72  }
73 
74  void setActiveButton(int16 buttonIdx) {
75  _activeButtonIdx = buttonIdx;
76  _settings[MenuSettings_CurrentLoadedButton] = buttonIdx;
77  }
78 
79  void setActiveButtonTextId(TextId textIndex) {
80  setButtonTextId(getActiveButton(), textIndex);
81  }
82 
83  void setButtonTextId(int16 buttonIdx, TextId textIndex) {
84  _settings[MenuSettings_FirstButton + buttonIdx * 2] = (int16)textIndex;
85  _buttonTexts[buttonIdx].clear();
86  }
87 
88  TextId getActiveButtonTextId() const {
89  return getButtonTextId(getActiveButton());
90  }
91 
92  int16 getActiveButtonState() const {
93  return getButtonState(getActiveButton());
94  }
95 
96  int16 getButtonState(int buttonIndex) const {
97  return _settings[MenuSettings_FirstButtonState + buttonIndex * 2];
98  }
99 
100  const char *getButtonText(Text *text, int buttonIndex);
101 
102  int16 getActiveButton() const {
103  return _activeButtonIdx;
104  }
105 
106  int16 getButtonBoxHeight() const {
107  return _settings[MenuSettings_ButtonsBoxHeight];
108  }
109 
110  int16 getButtonCount() const {
111  return _settings[MenuSettings_NumberOfButtons];
112  }
113 
114  void setTextBankId(TextBankId textBankIndex) {
115  _settings[MenuSettings_HeaderEnd] = (int16)textBankIndex;
116  }
117 
118  void addButton(TextId textId, int16 state = 0) {
119  const int16 i = _settings[MenuSettings_NumberOfButtons];
120  _settings[i * 2 + MenuSettings_FirstButtonState] = state;
121  _settings[i * 2 + MenuSettings_FirstButton] = (int16)textId;
122  ++_settings[MenuSettings_NumberOfButtons];
123  }
124 
125  void addButton(const char *text, int16 state = 0) {
126  const int16 i = _settings[MenuSettings_NumberOfButtons];
127  _settings[i * 2 + MenuSettings_FirstButtonState] = state;
128  // will return the button index
129  _settings[i * 2 + MenuSettings_FirstButton] = i;
130  _buttonTexts[i] = text;
131  ++_settings[MenuSettings_NumberOfButtons];
132  }
133 };
134 
135 class Menu {
136 private:
137  TwinEEngine *_engine;
139  BodyData *_behaviourEntity = nullptr;
141  uint _behaviourAnimState[4]; // winTab
143  AnimTimerDataStruct _behaviourAnimData[4];
144 
145  int32 _inventorySelectedColor = COLOR_BLACK;
146  int32 _inventorySelectedItem = 0; // currentSelectedObjectInInventory
147 
149  uint8 *_plasmaEffectPtr = nullptr;
150 
151  MenuSettings _giveUpMenuWithSaveState;
152  MenuSettings _volumeMenuState;
153  MenuSettings _saveManageMenuState;
154  MenuSettings _giveUpMenuState;
155  MenuSettings _mainMenuState;
156  MenuSettings _newGameMenuState;
157  MenuSettings _advOptionsMenuState;
158  MenuSettings _optionsMenuState;
159  MenuSettings _languageMenuState;
160 
161  // objectRotation
162  int16 _itemAngle[NUM_INVENTORY_ITEMS];
164  ActorMoveStruct _moveMenu;
165 
172  void drawButtonGfx(const MenuSettings *menuSettings, const Common::Rect &rect, int32 buttonId, const char *dialText, bool hover);
173  void plasmaEffectRenderFrame();
179  int16 drawButtons(MenuSettings *menuSettings, bool hover);
181  int32 advoptionsMenu();
183  int32 volumeMenu();
184  int32 languageMenu();
186  int32 savemanageMenu();
187  void drawInfoMenu(int16 left, int16 top, int16 width);
188  Common::Rect calcBehaviourRect(int32 left, int32 top, HeroBehaviourType behaviour) const;
189  bool isBehaviourHovered(int32 left, int32 top, HeroBehaviourType behaviour) const;
190  void drawBehaviour(int32 left, int32 top, HeroBehaviourType behaviour, int32 angle, bool cantDrawBox);
191  void drawInventoryItems(int32 left, int32 top);
192  void prepareAndDrawBehaviour(int32 left, int32 top, int32 angle, HeroBehaviourType behaviour); // DrawComportement
193  void drawBehaviourMenu(int32 left, int32 top, int32 angle); // DrawMenuComportement
194  void drawItem(int32 left, int32 top, int32 item);
195 
196  void drawSpriteAndString(int32 left, int32 top, const SpriteData &spriteData, const Common::String &str, int32 color = COLOR_GOLD);
197 
198 public:
199  Menu(TwinEEngine *engine);
200  ~Menu();
201 
206  void processPlasmaEffect(const Common::Rect &rect, int32 color);
207 
208  void drawHealthBar(int32 left, int32 right, int32 top, int32 barLeftPadding, int32 barHeight);
209  void drawCloverLeafs(int32 newBoxLeft, int32 boxRight, int32 top);
210  void drawMagicPointsBar(int32 left, int32 right, int32 top, int32 barLeftPadding, int32 barHeight);
211  void drawCoins(int32 left, int32 top);
212  void drawKeys(int32 left, int32 top);
213 
221  void drawRectBorders(int32 left, int32 top, int32 right, int32 bottom, int32 colorLeftTop = COLOR_79, int32 colorRightBottom = COLOR_73);
222  void drawRectBorders(const Common::Rect &rect, int32 colorLeftTop = COLOR_79, int32 colorRightBottom = COLOR_73);
228  int32 processMenu(MenuSettings *menuSettings);
229 
230  bool init();
231 
233  EngineState run();
234 
236  int32 giveupMenu();
237 
238  void inGameOptionsMenu();
239 
241  int32 optionsMenu();
242 
244  void processBehaviourMenu(bool behaviourMenu); // MenuComportement
245 
246  int32 newGameClassicMenu();
247 
249  void processInventoryMenu();
250 };
251 
252 } // namespace TwinE
253 
254 #endif
Definition: str.h:59
Definition: actor.h:55
Definition: rect.h:144
Definition: sprite.h:67
Definition: menu.h:38
Definition: menu.h:135
Definition: twine.h:200
Definition: achievements_tables.h:27
Definition: text.h:44
Definition: actor.h:40
Definition: body.h:35