ScummVM API documentation
ui.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 
13 #ifndef SCUMM_INSANE_REBEL2_PSX_UI_H
14 #define SCUMM_INSANE_REBEL2_PSX_UI_H
15 
16 #include "common/random.h"
17 #include "common/rect.h"
18 
19 #include "graphics/surface.h"
20 
21 #include "scumm/insane/rebel2/psx/psx.h"
22 
23 namespace Scumm {
24 
26 public:
27  enum BlendMode {
28  kBlendOpaque,
29  kBlendAdditive,
30  // The GPU's semi-transparency mode 0: half background, half source.
31  kBlendAverage
32  };
33 
34  void clear() { _textures.clear(); }
35  bool append(const Common::Array<byte> &data);
36  bool appendRaw24(const char *name, const Common::Array<byte> &data,
37  uint16 width, uint16 height);
38  bool has(const char *name) const { return find(name) != nullptr; }
39  // Sprites streamed into a texture's VRAM slot are drawn through its CLUT.
40  const Common::Array<uint32> *palette(const char *name) const;
41  void draw(Graphics::Surface &surface, const char *name, int x, int y,
42  const Common::Rect &source, int brightness = 0x80,
43  BlendMode blend = kBlendOpaque) const;
44  void drawText(Graphics::Surface &surface, const char *font, const char *text,
45  int x, int y, int brightness = 0x80) const;
46  int measureText(const char *text) const;
47  // The 16 pixel tall menu headline font, drawn over a black drop shadow.
48  void drawHeadline(Graphics::Surface &surface, const char *text, int x, int y) const;
49  int measureHeadline(const char *text) const;
50 
51 private:
52  const RA2PSXTexture *find(const char *name) const;
53  void drawShape(Graphics::Surface &surface, const char *name, int x, int y,
54  const Common::Rect &source, byte r, byte g, byte b) const;
56 };
57 
58 // One part of level 2: the backdrop halves and parallax walls scroll behind the rookie,
59 // who stands centred and ducks in and out of cover while scripted troopers trade fire.
61 public:
63 
64  bool load(const RA2PSXArchive &archive, int part, int difficulty,
65  Common::RandomSource &random);
66  // Toggles between cover and the open; ignored while a move is already running.
67  void toggleCover();
68  void update(int aimX, int aimY);
69  // One 60Hz tick of the trooper slots. Returns the shield damage it cost the player.
70  int updateEnemies(Common::RandomSource &random);
71  // Fires a bolt at the crosshair and kills whatever it covers; returns the score.
72  int shoot(int aimX, int aimY);
73  bool outOfCover() const { return _out && !_moving; }
74  // Anything but fully ducked; the original only shields a rookie who has finished.
75  bool exposed() const { return _out || _moving; }
76  bool busy() const { return _moving; }
77  bool cleared() const { return _clearTicks >= kRA2PSXLevel2ClearTicks; }
78  int kills() const { return _kills; }
79  int misses() const { return _misses; }
80  void draw(Graphics::Surface &surface, int aimX, int aimY) const;
81  const RA2PSXLevel2PartInfo &info() const;
82 
83 private:
84  void drawLayer(Graphics::Surface &surface, const RA2PSXLevel2Layer &layer,
85  int left, int top) const;
86  void drawFrame(Graphics::Surface &surface, const RA2PSXTexture &frame,
87  int x, int y) const;
88  void drawPlayFrame(Graphics::Surface &surface, const RA2PSXPlayFrame &frame,
89  const Common::Array<uint32> &palette, int left, int top) const;
90  void setScrollTarget(const int16 target[2][2]);
91  int aimFrame(int aimX, int aimY) const;
92  // How many poses the rookie walks leaning out; the aim grid starts right after.
93  int coverFrames() const;
94  // Restarts an actor on the given animation, the way the original's loader does.
95  void startActor(RA2PSXLevel2Actor &actor, int state, int animation);
96  const RA2PSXPlayFrame *actorFrame(const RA2PSXLevel2Actor &actor) const;
97  void advanceActor(RA2PSXLevel2Actor &actor);
98  int slotDelay(int base, int range, Common::RandomSource &random) const;
99  // Projects a bolt's 3D line onto the screen at the given point along it.
100  void projectShot(const RA2PSXLevel2Shot &shot, int step, int &x, int &y) const;
101 
102  RA2PSXTextureSet _textures;
103  RA2PSXTextureSet _hud;
106  int _part;
107  int _difficulty;
108  int _frame;
109  int _delay;
110  bool _out;
111  bool _moving;
112  // Background and parallax scroll, held in 16.16 with a target to ease toward.
113  int _scroll[2][2];
114  int _scrollTarget[2][2];
115  int _scrollStep[2][2];
116  int _scrollHold[2][2];
117  // The trooper slots, the bolt each one has in the air, and the wave they draw from.
118  RA2PSXLevel2Actor _troopers[kRA2PSXLevel2TrooperCount];
119  RA2PSXLevel2Actor _bolts[kRA2PSXLevel2TrooperCount];
120  RA2PSXLevel2Shot _shots[kRA2PSXLevel2ShotCount];
121  int _tick;
122  int _remaining;
123  int _active;
124  int _clearTicks;
125  int _kills;
126  int _misses;
127 };
128 
129 // The GPU's semi-transparency mode 2: background minus source.
130 void subtractRA2PSXRect(Graphics::Surface &surface, const Common::Rect &rect,
131  int r, int g, int b);
132 void drawRA2PSXGouraudLine(Graphics::Surface &surface, int x0, int y0, int x1, int y1,
133  const byte *from, const byte *to);
134 // The "back" and "select" button captions along the bottom of every menu page.
135 void drawRA2PSXMenuHints(Graphics::Surface &surface, const RA2PSXTextureSet &textures);
136 
138 public:
139  bool load(Common::SeekableReadStream &executable);
140  void draw(Graphics::Surface &surface, RA2PSXMovieTextSequence sequence,
141  int frame, int xOffset, int yOffset) const;
142 
143 private:
144  RA2PSXTextureSet _textures;
145 };
146 
148 public:
149  bool load(const RA2PSXArchive &archive);
150  // The spinning crest is drawn between these two passes.
151  void drawBackground(Graphics::Surface &surface) const;
152  void drawForeground(Graphics::Surface &surface, int selection) const;
153  static Common::Rect itemRect(int item);
154  const RA2PSXTextureSet &textures() const { return _textures; }
155 
156 private:
157  RA2PSXTextureSet _textures;
158 };
159 
160 // Options menu; passcode, memory card, high scores and controls are dimmed for now.
162 public:
163  enum Item {
164  kItemDifficulty,
165  kItemAdjustSound,
166  kItemPasscode,
167  kItemMemoryCard,
168  kItemHighScores,
169  kItemControls,
170  kItemResetSettings,
171  kItemExit,
172  kItemCount
173  };
174 
175  enum SoundItem {
176  kSoundItemMode,
177  kSoundItemEffects,
178  kSoundItemMusic,
179  kSoundItemMovies,
180  kSoundItemExit,
181  kSoundItemCount
182  };
183 
184  explicit RA2PSXOptionsUI(const RA2PSXTextureSet &textures) : _textures(textures) {}
185 
186  static bool isItemAvailable(int item);
187  static Common::Rect mainItemRect(int item);
188  static Common::Rect soundItemRect(int item);
189 
190  void drawMain(Graphics::Surface &surface, int selection,
191  const RA2PSXSettings &settings) const;
192  void drawSound(Graphics::Surface &surface, int selection,
193  const RA2PSXSettings &settings) const;
194  // A two or three line box; pass a negative selection for a plain message.
195  void drawDialog(Graphics::Surface &surface, const char *headline,
196  const char *question, const char *detail, int selection) const;
197 
198 private:
199  void drawItem(Graphics::Surface &surface, const char *text, int x, int y,
200  bool centered, int state) const;
201  void drawVolume(Graphics::Surface &surface, int y, int level) const;
202 
203  const RA2PSXTextureSet &_textures;
204 };
205 
206 // The scrolling chapter grid, whose tiles are frames of LEVELSEL.STR diced into
207 // a four by four atlas of 80x60 previews.
209 public:
210  enum {
211  kChapterCount = 16,
212  kTileWidth = 80,
213  kTileHeight = 60,
214  kRowPitch = 62
215  };
216 
217  explicit RA2PSXChapterSelectUI(const RA2PSXTextureSet &textures) : _textures(textures) {}
218 
219  void draw(Graphics::Surface &surface, const Graphics::Surface *previews,
220  int scroll, int selection, int unlocked) const;
221  static int rowY(int chapter, int scroll);
222  static Common::Rect tileRect(int chapter, int scroll);
223 
224 private:
225  void drawTile(Graphics::Surface &surface, int chapter, int y,
226  const Graphics::Surface *previews, bool selected, bool unlocked) const;
227  void drawLabel(Graphics::Surface &surface, int chapter, int y,
228  bool selected, bool unlocked) const;
229 
230  const RA2PSXTextureSet &_textures;
231 };
232 
233 // A hit washes the screen for five frames.
234 enum { kRA2PSXHitFlashFrames = 5 };
235 
236 void drawRA2PSXHitFlash(Graphics::Surface &surface, int frame);
237 
238 // The shield gauge runs 0 to 0x1000, and warns below 0x501.
239 enum {
240  kRA2PSXShieldFull = 0x1000,
241  kRA2PSXLowShield = 0x501
242 };
243 
245 public:
246  bool load(const RA2PSXArchive &archive);
247 
248  // The shell zooms away while the camera swaps views (0x1000 is its resting size)
249  // and drifts a few pixels with the crosshair.
250  void drawCockpit(Graphics::Surface &surface, int scale = 0x1000,
251  int driftX = 0, int driftY = 0) const;
252  void drawExplosion(Graphics::Surface &surface, int x, int y, int frame) const;
253  void drawHUD(Graphics::Surface &surface, int score, int lives, int shield, int frame) const;
254 
255 private:
256  void drawShield(Graphics::Surface &surface, int shield, int xOffset, int yOffset) const;
257 
258  RA2PSXTextureSet _textures;
259 };
260 
261 } // End of namespace Scumm
262 
263 #endif
Definition: ui.h:137
Definition: ui.h:60
Definition: surface.h:67
void clear()
Definition: array.h:321
Definition: ui.h:244
Definition: random.h:44
Definition: ui.h:208
Definition: rect.h:536
Definition: stream.h:745
Definition: ui.h:147
Definition: ui.h:161
Definition: ui.h:25
Definition: actor.h:30