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 MADS_USER_INTERFACE_H 24 #define MADS_USER_INTERFACE_H 25 26 #include "common/scummsys.h" 27 #include "common/rect.h" 28 #include "common/str.h" 29 #include "mads/msurface.h" 30 #include "mads/screen.h" 31 32 namespace MADS { 33 34 enum { IMG_SPINNING_OBJECT = 200, IMG_TEXT_UPDATE = 201 }; 35 36 enum ScrollbarActive { 37 SCROLLBAR_NONE = 0, // No state 38 SCROLLBAR_UP = 1, // Up butotn 39 SCROLLBAR_DOWN = 2, // Down button 40 SCROLLBAR_ELEVATOR = 3, // Elevator bar 41 SCROLLBAR_THUMB = 4 // Scrollbar thumb 42 }; 43 44 class AnimFrameEntry; 45 class MADSEngine; 46 47 class UISlot { 48 public: 49 int _flags; 50 int _segmentId; 51 int _spritesIndex; 52 int _frameNumber; 53 Common::Point _position; 54 55 // Only used for IMG_OVERPRINT 56 int _width; 57 int _height; 58 59 UISlot(); 60 }; 61 62 /** 63 * Sprite list for the user interface 64 */ 65 class UISlots : public Common::Array<UISlot> { 66 private: 67 MADSEngine *_vm; 68 public: 69 /** 70 * Constructor 71 */ UISlots(MADSEngine * vm)72 UISlots(MADSEngine *vm) : _vm(vm) {} 73 74 /** 75 * Add an overprint (text) entry to the list 76 */ 77 void add(const Common::Rect &bounds); 78 79 /** 80 * Loads the data from an aimation frame entry 81 */ 82 void add(const AnimFrameEntry &frameEntry); 83 84 /** 85 * Adds a special entry for full refresh of the user interface 86 */ 87 void fullRefresh(); 88 89 /** 90 * Draw all the sprites in the list on the user interface. 91 * @param updateFlag Flag drawn areas to be updated on physical screen 92 * @param delFlag Controls how used slots are deleted after drawing 93 */ 94 void draw(bool updateFlag, bool delFlag); 95 }; 96 97 class Conversation { 98 private: 99 static MADSEngine *_vm; 100 public: 101 static void init(MADSEngine *vm); 102 public: 103 int _globalId; 104 Common::Array<int> _quotes; 105 106 /** 107 * Set up a conversation sequence 108 */ 109 void setup(int globalId, ...); 110 111 /** 112 * Activates the passed set of quotes in the given conversation node 113 */ 114 void set(int quoteId, ...); 115 116 /** 117 * Returns the bit for a given quote to indicate whether it's active or not or, 118 * if 0 is passed, returns the number of currently active quotes 119 */ 120 int read(int quoteId); 121 122 /** 123 * Activates or deactivates the specified quote in the given conversation node 124 */ 125 void write(int quoteId, bool flag); 126 127 /** 128 * Starts the conversation 129 */ 130 void start(); 131 }; 132 133 class UserInterface : public MSurface { 134 friend class UISlots; 135 private: 136 MADSEngine *_vm; 137 int _invSpritesIndex; 138 int _invFrameNumber; 139 uint32 _scrollMilli; 140 bool _scrollFlag; 141 int _noSegmentsActive; 142 int _someSegmentsActive; 143 144 /** 145 * Loads the elements of the user interface 146 */ 147 void loadElements(); 148 149 /** 150 * Returns the area within the user interface a given element falls 151 */ 152 bool getBounds(ScrCategory category, int invIndex, Common::Rect &bounds); 153 154 /** 155 * Reposition a bounding rectangle to physical co-ordinates 156 */ 157 void moveRect(Common::Rect &bounds); 158 159 /** 160 * Draw options during a conversation. 161 */ 162 void drawConversationList(); 163 164 /** 165 * Draw the action list 166 */ 167 void drawActions(); 168 169 /** 170 * Draw the inventory list 171 */ 172 void drawInventoryList(); 173 174 /** 175 * Draw the inventory item vocab list 176 */ 177 void drawItemVocabList(); 178 179 /** 180 * Draw the inventory scroller 181 */ 182 void drawScroller(); 183 184 /** 185 * Called when the inventory scrollbar has changed 186 */ 187 void scrollbarChanged(); 188 189 /** 190 * Draw a UI textual element 191 */ 192 void writeVocab(ScrCategory category, int id); 193 public: 194 MSurface _surface; 195 UISlots _uiSlots; 196 DirtyAreas _dirtyAreas; 197 ScrCategory _category; 198 Common::Rect *_rectP; 199 int _inventoryTopIndex; 200 int _selectedInvIndex; 201 int _selectedActionIndex; 202 int _selectedItemVocabIdx; 203 ScrollbarActive _scrollbarActive, _scrollbarOldActive; 204 int _highlightedCommandIndex; 205 int _highlightedInvIndex; 206 int _highlightedItemVocabIndex; 207 bool _inventoryChanged; 208 int _categoryIndexes[8]; 209 Common::StringArray _talkStrings; 210 Common::Array<int> _talkIds; 211 bool _scrollbarQuickly; 212 uint32 _scrollbarMilliTime; 213 int _scrollbarElevator, _scrollbarOldElevator; 214 ScrollbarActive _scrollbarStrokeType; 215 public: 216 /** 217 * Constructor 218 */ 219 UserInterface(MADSEngine *vm); 220 221 /** 222 * Loads an interface from a specified resource 223 */ 224 void load(const Common::String &resName) override; 225 226 /** 227 * Set up the interface 228 */ 229 void setup(InputMode inputMode); 230 231 void drawTextElements(); 232 233 /** 234 * Merges a sub-section of another surface into the user interface without 235 * destroying any on-screen text 236 * @param src Source surface 237 * @param srcBounds Area to copy/merge from 238 * @param destPos Destination position to draw in current surface 239 * @param transparencyIndex Transparency color 240 */ 241 void mergeFrom(BaseSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos, 242 int transparencyIndex = -1); 243 244 /** 245 * Loads the animation sprite data for a given inventory object 246 */ 247 void loadInventoryAnim(int objectId); 248 249 /** 250 * Resets the inventory animation when no inventory item is selected 251 */ 252 void noInventoryAnim(); 253 254 /** 255 * Handles any animation that occurs in the background of the user interface 256 */ 257 void doBackgroundAnimation(); 258 259 /** 260 * Handles queuing a new frame of an inventory animation for drawing 261 */ 262 void inventoryAnim(); 263 264 void categoryChanged(); 265 266 /** 267 * Select an item from the inventory list 268 * @param invIndex Index in the inventory list of the item to select 269 */ 270 void selectObject(int invIndex); 271 272 void updateSelection(ScrCategory category, int newIndex, int *idx); 273 274 /** 275 * Updates the current top visible item of the scrollbar 276 */ 277 void changeScrollBar(); 278 279 void scrollerChanged(); 280 281 void scrollInventory(); 282 283 /** 284 * Checks for the mouse being on the user interface inventory scroller, 285 * and update the scroller highlight and selected inventory object as necessary 286 */ 287 void updateInventoryScroller(); 288 289 /** 290 * Empties the current conversation talk list 291 */ 292 void emptyConversationList(); 293 294 /** 295 * Add a msesage to the list of conversation items to select from 296 */ 297 void addConversationMessage(int vocabId, const Common::String &msg); 298 299 /** 300 * Synchronize the data 301 */ 302 void synchronize(Common::Serializer &s); 303 304 void refresh(); 305 }; 306 307 } // End of namespace MADS 308 309 #endif /* MADS_USER_INTERFACE_H */ 310