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 SHERLOCK_TATTOO_UI_H
24 #define SHERLOCK_TATTOO_UI_H
25 
26 #include "common/scummsys.h"
27 #include "common/list.h"
28 #include "sherlock/saveload.h"
29 #include "sherlock/screen.h"
30 #include "sherlock/user_interface.h"
31 #include "sherlock/tattoo/widget_credits.h"
32 #include "sherlock/tattoo/widget_files.h"
33 #include "sherlock/tattoo/widget_inventory.h"
34 #include "sherlock/tattoo/widget_options.h"
35 #include "sherlock/tattoo/widget_quit.h"
36 #include "sherlock/tattoo/widget_text.h"
37 #include "sherlock/tattoo/widget_tooltip.h"
38 #include "sherlock/tattoo/widget_verbs.h"
39 
40 namespace Sherlock {
41 
42 namespace Tattoo {
43 
44 // Button width/height
45 #define BUTTON_SIZE 15
46 // How long to play the intro before it can be skipped
47 #define STARTUP_KEYS_DISABLED_DELAY 200
48 
49 class WidgetBase;
50 
51 enum ScrollHighlight { SH_NONE = 0, SH_SCROLL_UP = 1, SH_PAGE_UP = 2, SH_THUMBNAIL = 3, SH_PAGE_DOWN = 4, SH_SCROLL_DOWN = 5 };
52 
53 class WidgetList : public Common::List <WidgetBase *> {
54 public:
55 	bool contains(const WidgetBase *item) const;
56 };
57 
58 class TattooUserInterface : public UserInterface {
59 	friend class WidgetBase;
60 private:
61 	int _scriptZone;
62 	int _cAnimFramePause;
63 	WidgetInventory _inventoryWidget;
64 	WidgetMessage _messageWidget;
65 	WidgetQuit _quitWidget;
66 	WidgetList _fixedWidgets;
67 	WidgetList _widgets;
68 	byte _lookupTable[PALETTE_COUNT];
69 	byte _lookupTable1[PALETTE_COUNT];
70 private:
71 	/**
72 	 * Handle any input when we're in standard mode (with no windows open)
73 	 */
74 	void doStandardControl();
75 
76 	/**
77 	 * Handle input when in look mode
78 	 */
79 	void doLookControl();
80 
81 	/**
82 	 * Handle input when the File window is open
83 	 */
84 	void doFileControl();
85 
86 	/**
87 	 * Handle input while the verb menu is open
88 	 */
89 	void doVerbControl();
90 
91 	/**
92 	 * Free any active menu
93 	 */
94 	void freeMenu();
95 public:
96 	Common::Point _targetScroll;
97 	int _scrollSize, _scrollSpeed;
98 	bool _drawMenu;
99 	int _arrowZone, _oldArrowZone;
100 	Object *_bgShape;
101 	bool _personFound;
102 	int _activeObj;
103 	Common::KeyState _keyState;
104 	Common::Point _lookPos;
105 	ScrollHighlight _scrollHighlight;
106 	Common::SeekableReadStream *_mask, *_mask1;
107 	Common::Point _maskOffset;
108 	int _maskCounter;
109 	int _lockoutTimer;
110 	ImageFile *_interfaceImages;
111 	WidgetCredits _creditsWidget;
112 	WidgetOptions _optionsWidget;
113 	WidgetText _textWidget;
114 	WidgetSceneTooltip _tooltipWidget;
115 	WidgetVerbs _verbsWidget;
116 	WidgetList _postRenderWidgets;
117 public:
118 	TattooUserInterface(SherlockEngine *vm);
119 	~TattooUserInterface() override;
120 
121 	/**
122 	 * Handles restoring any areas of the back buffer that were/are covered by UI elements
123 	 */
124 	void doBgAnimRestoreUI();
125 
126 	/**
127 	 * Checks to see if the screen needs to be scrolled. If so, scrolls it towards the target position
128 	 */
129 	void doScroll();
130 
131 	/**
132 	 * Initializes scroll variables
133 	 */
134 	void initScrollVars();
135 
136 	/**
137 	 * Display the long description for an object in a window
138 	 */
139 	void lookAtObject();
140 
141 	/**
142 	 * Display the passed long description for an object. If the flag firstTime is set,
143 	 * the window will be opened to accomodate the text. Otherwise, the remaining text
144 	 * will be printed in an already open window
145 	 */
146 	void printObjectDesc(const Common::String &str, bool firstTime);
147 
148 	/**
149 	 * Handles displaying the journal
150 	 */
151 	void doJournal();
152 
153 	/**
154 	 * Put the game in inventory mode by opening the inventory dialog
155 	 */
156 	void doInventory(int mode);
157 
158 	/**
159 	 * Handle the display of the options/setup menu
160 	 */
161 	void doControls();
162 
163 	/**
164 	 * Handle the display of the quit menu
165 	 */
166 	void doQuitMenu();
167 
168 	/**
169 	 * Pick up the selected object
170 	 */
171 	void pickUpObject(int objNum);
172 
173 	/**
174 	 * This will display a text message in a dialog at the bottom of the screen
175 	 */
176 	void putMessage(const char *formatStr, ...) GCC_PRINTF(2, 3);
177 
178 	/**
179 	 * Makes a greyscale translation table for each palette entry in the table
180 	 */
181 	void setupBGArea(const byte cMap[PALETTE_SIZE]);
182 
183 	/**
184 	 * Erase any background as needed before drawing frame
185 	 */
186 	void doBgAnimEraseBackground();
187 
188 	/**
189 	 * Draws overlays onto the scene. Basically, the smoke effects some scenes have
190 	 */
191 	void drawMaskArea(bool mode);
192 
193 	/**
194 	 * Takes the data passed in the image and apply it to the surface at the given position.
195 	 * The src mask data is encoded with a different color for each item. To highlight one,
196 	 the runs that do not match the highlight number will be darkened
197 	 */
198 	void maskArea(Common::SeekableReadStream &mask, const Common::Point &pt);
199 
200 	/**
201 	 * Translate a given area of the back buffer to greyscale shading
202 	 */
203 	void makeBGArea(const Common::Rect &r);
204 
205 	/**
206 	 * Draws all the dialog rectangles for any items that need them
207 	 */
208 	void drawDialogRect(Surface &s, const Common::Rect &r, bool raised);
209 
210 	/**
211 	 * If the mouse cursor is point at the cursor, then display the name of the object on the screen.
212 	 * If there is no object being pointed it, clear any previously displayed name
213 	 */
214 	void displayObjectNames();
215 
216 	/**
217 	 * Show the load game dialog, and allow the user to load a game
218 	 */
219 	void loadGame();
220 
221 	/**
222 	 * Show the save game dialog, and allow the user to save the game
223 	 */
224 	void saveGame();
225 
226 	/**
227 	 * Add a widget to the current scene to be executed if there are no active widgets in the
228 	 * main _widgets list
229 	 */
230 	void addFixedWidget(WidgetBase *widget);
231 public:
232 	/**
233 	 * Resets the user interface
234 	 */
235 	void reset() override;
236 
237 	/**
238 	 * Main input handler for the user interface
239 	 */
240 	void handleInput() override;
241 
242 	/**
243 	 * Draw the user interface onto the screen's back buffers
244 	 */
245 	void drawInterface(int bufferNum = 3) override;
246 
247 	/**
248 	 * Clear any active text window
249 	 */
250 	void clearWindow() override;
251 
252 	/**
253 	 * Banish any active window
254 	 * @remarks		Tattoo doesn't use sliding windows, but the parameter is in the base
255 	 * UserInterface class as a convenience for Scalpel UI code
256 	 */
257 	void banishWindow(bool slideUp = true) override;
258 };
259 
260 } // End of namespace Tattoo
261 
262 } // End of namespace Sherlock
263 
264 #endif
265