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 kDemoMenu 9999
34 #define kQuitEngine 9998
35 
36 class BodyData;
37 class SpriteData;
38 
39 class MenuSettings {
40 private:
41  enum MenuSettingsType {
42  // button number
43  MenuSettings_CurrentLoadedButton = 0,
44  // is used to calc the height where the first button will appear
45  MenuSettings_NumberOfButtons = 1,
46  MenuSettings_ButtonsBoxHeight = 2,
47  MenuSettings_TextBankId = 3,
48 
49  MenuSettings_FirstButtonState,
50  MenuSettings_FirstButton
51  };
52 
53  int16 _settings[4 + MAX_BUTTONS * 2] {0};
54  Common::String _buttonTexts[MAX_BUTTONS];
55  int8 _activeButtonIdx = 0;
56 
57 public:
58  TextId getButtonTextId(int buttonIndex) const {
59  return (TextId)_settings[MenuSettings_FirstButton + buttonIndex * 2];
60  }
61 
62  void reset() {
63  for (int32 i = 0; i < MAX_BUTTONS; ++i) {
64  _buttonTexts[i] = "";
65  }
66  _settings[MenuSettings_NumberOfButtons] = 0;
67  setButtonsBoxHeight(0);
68  setActiveButton(0);
69  }
70 
71  // used to calc the height where the first button will appear
72  void setButtonsBoxHeight(int16 height) {
73  _settings[MenuSettings_ButtonsBoxHeight] = height;
74  }
75 
76  void setActiveButton(int16 buttonIdx) {
77  _activeButtonIdx = buttonIdx;
78  _settings[MenuSettings_CurrentLoadedButton] = buttonIdx;
79  }
80 
81  void setActiveButtonTextId(TextId textIndex) {
82  setButtonTextId(getActiveButton(), textIndex);
83  }
84 
85  void setButtonTextId(int16 buttonIdx, TextId textIndex) {
86  _settings[MenuSettings_FirstButton + buttonIdx * 2] = (int16)textIndex;
87  _buttonTexts[buttonIdx].clear();
88  }
89 
90  TextId getActiveButtonTextId() const {
91  return getButtonTextId(getActiveButton());
92  }
93 
94  int16 getActiveButtonState() const {
95  return getButtonState(getActiveButton());
96  }
97 
98  int16 getButtonState(int buttonIndex) const {
99  return _settings[MenuSettings_FirstButtonState + buttonIndex * 2];
100  }
101 
102  const char *getButtonText(Text *text, int buttonIndex);
103 
104  int16 getActiveButton() const {
105  return _activeButtonIdx;
106  }
107 
108  int16 getButtonBoxHeight() const {
109  return _settings[MenuSettings_ButtonsBoxHeight];
110  }
111 
112  int16 getButtonCount() const {
113  return _settings[MenuSettings_NumberOfButtons];
114  }
115 
116  void setTextBankId(TextBankId textBankIndex) {
117  _settings[MenuSettings_TextBankId] = (int16)textBankIndex;
118  }
119 
120  void addButton(TextId textId, int16 state = 0) {
121  const int16 i = _settings[MenuSettings_NumberOfButtons];
122  _settings[i * 2 + MenuSettings_FirstButtonState] = state;
123  _settings[i * 2 + MenuSettings_FirstButton] = (int16)textId;
124  ++_settings[MenuSettings_NumberOfButtons];
125  }
126 
127  void addButton(const char *text, int16 state = 0) {
128  const int16 i = _settings[MenuSettings_NumberOfButtons];
129  _settings[i * 2 + MenuSettings_FirstButtonState] = state;
130  // will return the button index
131  _settings[i * 2 + MenuSettings_FirstButton] = i;
132  _buttonTexts[i] = text;
133  ++_settings[MenuSettings_NumberOfButtons];
134  }
135 };
136 
137 class Menu {
138 private:
139  TwinEEngine *_engine;
141  BodyData *_behaviourEntity = nullptr;
143  uint _behaviourAnimState[4]; // winTab
145  AnimTimerDataStruct _behaviourAnimData[4];
146 
147  int32 _inventorySelectedColor = COLOR_BLACK;
148  int32 _inventorySelectedItem = 0; // currentSelectedObjectInInventory
149 
151  uint8 *_plasmaEffectPtr = nullptr;
152 
153  MenuSettings _giveUpMenuWithSaveState;
154  MenuSettings _volumeMenuState;
155  MenuSettings _saveManageMenuState;
156  MenuSettings _giveUpMenuState;
157  MenuSettings _mainMenuState;
158  MenuSettings _newGameMenuState;
159  MenuSettings _advOptionsMenuState;
160  MenuSettings _optionsMenuState;
161  MenuSettings _languageMenuState;
162 
163  // objectRotation
164  int16 _itemAngle[NUM_INVENTORY_ITEMS];
166  RealValue _moveMenu;
167 
174  void drawButtonGfx(const MenuSettings *menuSettings, const Common::Rect &rect, int32 buttonId, const char *dialText, bool hover);
175  void plasmaEffectRenderFrame();
181  int16 drawButtons(MenuSettings *menuSettings, bool hover);
183  int32 advoptionsMenu();
185  int32 volumeOptions();
186  int32 languageMenu();
188  int32 savemanageMenu();
189  void drawInfoMenu(int16 left, int16 top, int16 width);
190  Common::Rect calcBehaviourRect(int32 left, int32 top, HeroBehaviourType behaviour) const;
191  bool isBehaviourHovered(int32 left, int32 top, HeroBehaviourType behaviour) const;
192  void drawBehaviour(int32 left, int32 top, HeroBehaviourType behaviour, int32 angle, bool cantDrawBox);
193  void drawListInventory(int32 left, int32 top);
194  void prepareAndDrawBehaviour(int32 left, int32 top, int32 angle, HeroBehaviourType behaviour); // DrawComportement
195  void drawBehaviourMenu(int32 left, int32 top, int32 angle); // DrawMenuComportement
196  Common::Rect calcItemRect(int32 left, int32 top, int32 item, int32 *centerX = nullptr, int32 *centerY = nullptr) const;
197  // draw the 2d sprite of the item
198  void drawOneInventory(int32 left, int32 top, int32 item);
199 
200  void drawSpriteAndString(int32 left, int32 top, const SpriteData &spriteData, const Common::String &str, int32 color = COLOR_GOLD);
201 
202 public:
203  Menu(TwinEEngine *engine);
204  ~Menu();
205 
210  void processPlasmaEffect(const Common::Rect &rect, int32 color);
211 
212  void drawHealthBar(int32 left, int32 right, int32 top, int32 barLeftPadding, int32 barHeight);
213  void drawCloverLeafs(int32 newBoxLeft, int32 boxRight, int32 top);
214  void drawMagicPointsBar(int32 left, int32 right, int32 top, int32 barLeftPadding, int32 barHeight);
215  void drawCoins(int32 left, int32 top);
216  void drawKeys(int32 left, int32 top);
217 
225  void drawRectBorders(int32 left, int32 top, int32 right, int32 bottom, int32 colorLeftTop = COLOR_79, int32 colorRightBottom = COLOR_73);
226  void drawRectBorders(const Common::Rect &rect, int32 colorLeftTop = COLOR_79, int32 colorRightBottom = COLOR_73);
232  void menuDemo();
233  int32 doGameMenu(MenuSettings *menuSettings);
234 
235  bool init();
236 
238  EngineState run();
239 
241  int32 quitMenu();
242 
243  void inGameOptionsMenu();
244 
246  int32 optionsMenu();
247 
249  void processBehaviourMenu(bool behaviourMenu); // MenuComportement
250 
251  int32 newGameClassicMenu();
252 
254  void inventory();
255 };
256 
257 } // namespace TwinE
258 
259 #endif
Definition: str.h:59
Definition: actor.h:55
Definition: rect.h:144
Definition: sprite.h:68
Definition: menu.h:39
Definition: menu.h:137
Definition: actor.h:40
Definition: twine.h:207
Definition: achievements_tables.h:27
Definition: text.h:48
Definition: body.h:35