From c4ed42e6d5974e635b4241aa110d8ffe2a8c99c7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 15 Mar 2014 20:19:01 -0400 Subject: MADS: Implementing UserInterface loading --- engines/mads/scene_data.h | 7 +-- engines/mads/user_interface.cpp | 102 +++++++++++++++++++++++++++++++++++++++- engines/mads/user_interface.h | 21 +++++++++ 3 files changed, 123 insertions(+), 7 deletions(-) diff --git a/engines/mads/scene_data.h b/engines/mads/scene_data.h index 7a41bab1f8..1cd262755f 100644 --- a/engines/mads/scene_data.h +++ b/engines/mads/scene_data.h @@ -33,6 +33,7 @@ #include "mads/events.h" #include "mads/game_data.h" #include "mads/messages.h" +#include "mads/user_interface.h" namespace MADS { @@ -50,12 +51,6 @@ class SpriteSlot; #define TEXT_DISPLAY_MAX_SIZE 40 #define DIRTY_AREAS_SIZE (SPRITE_SLOTS_MAX_SIZE + TEXT_DISPLAY_MAX_SIZE) -enum ScrCategory { - CAT_NONE = 0, CAT_ACTION = 1, CAT_INV_LIST = 2, CAT_INV_VOCAB = 3, - CAT_HOTSPOT = 4, CAT_INV_ANIM = 5, CAT_6 = 6, CAT_INV_SCROLLER = 7, - CAT_12 = 12 -}; - enum Layer { LAYER_GUI = 19 }; diff --git a/engines/mads/user_interface.cpp b/engines/mads/user_interface.cpp index 63a0ec0a80..e6840ac01a 100644 --- a/engines/mads/user_interface.cpp +++ b/engines/mads/user_interface.cpp @@ -39,6 +39,8 @@ void SceneNode::load(Common::SeekableReadStream *f) { UserInterface::UserInterface(MADSEngine *vm) : _vm(vm) { _category = CAT_NONE; _screenObjectsCount = 0; + _inventoryTopIndex = 0; + _objectY = 0; byte *pData = _vm->_screen.getBasePtr(0, MADS_SCREEN_HEIGHT - MADS_INTERFACE_HEIGHT); setPixels(pData, MADS_SCREEN_WIDTH, MADS_INTERFACE_HEIGHT); @@ -123,7 +125,105 @@ void UserInterface::setBounds(const Common::Rect &r) { } void UserInterface::loadElements() { - warning("TODO: UserInterface::loadElements"); + Scene &scene = _vm->_game->_scene; + Common::Rect bounds; + scene._screenObjects.clear(); + + if (!scene._screenObjects._v832EC) { + for (int idx = 1; idx <= 3; ++idx) { + getBounds(CAT_INV_SCROLLER, idx, bounds); + // TODO + } + } +} + +bool UserInterface::getBounds(ScrCategory category, int v, Common::Rect &bounds) { + Common::Rect result; + int heightMultiplier, widthMultiplier; + int leftStart, yOffset, widthAmt; + + switch (category) { + case CAT_ACTION: + heightMultiplier = v / 5; + widthMultiplier = v / 5; + leftStart = 2; + yOffset = 3; + widthAmt = 32; + break; + + case CAT_INV_LIST: + if (v < _inventoryTopIndex || v > (_inventoryTopIndex + 5)) + return false; + + heightMultiplier = v - _inventoryTopIndex; + widthMultiplier = 0; + leftStart = 90; + yOffset = 3; + widthAmt = 69; + break; + + case CAT_6: + heightMultiplier = v; + widthMultiplier = 0; + leftStart = 2; + yOffset = 3; + widthAmt = 310; + break; + + case CAT_INV_SCROLLER: + heightMultiplier = 0; + widthMultiplier = 73; + yOffset = 0; + widthAmt = 9; + leftStart = (v != 73) ? 73 : 75; + break; + + default: + heightMultiplier = v; + widthMultiplier = 0; + leftStart = 240; + yOffset = 3; + widthAmt = 80; + break; + } + + result.left = (widthMultiplier > 0) ? widthMultiplier * widthAmt + leftStart : leftStart; + result.setWidth(widthAmt); + result.top = heightMultiplier * 3 + yOffset; + result.setHeight(8); + + if (category == CAT_INV_SCROLLER) { + switch (v) { + case 1: + // Arrow up + result.top = 4; + result.setHeight(7); + break; + case 2: + // Arrow down + result.top = 35; + result.setHeight(7); + break; + case 3: + // Scroller + result.top = 12; + result.setHeight(22); + break; + case 4: + // Thumb + result.top = _objectY + 14; + result.setHeight(1); + break; + default: + break; + } + } + + return true; +} + +void UserInterface::extendRect(Common::Rect &bounds) { + } } // End of namespace MADS diff --git a/engines/mads/user_interface.h b/engines/mads/user_interface.h index 8bd02ff6fc..b8e86bfefb 100644 --- a/engines/mads/user_interface.h +++ b/engines/mads/user_interface.h @@ -30,17 +30,38 @@ namespace MADS { +enum ScrCategory { + CAT_NONE = 0, CAT_ACTION = 1, CAT_INV_LIST = 2, CAT_INV_VOCAB = 3, + CAT_HOTSPOT = 4, CAT_INV_ANIM = 5, CAT_6 = 6, CAT_INV_SCROLLER = 7, + CAT_12 = 12 +}; + class UserInterface : public MSurface { private: MADSEngine *_vm; + /** + * Loads the elements of the user interface + */ void loadElements(); + + /** + * Returns the area within the user interface a given element falls + */ + bool getBounds(ScrCategory category, int invIndex, Common::Rect &bounds); + + /** + * Reposition a bounding rectangle to physical co-ordinates + */ + void extendRect(Common::Rect &bounds); public: ScrCategory _category; int _screenObjectsCount; Common::Rect _bounds; Common::Rect *_rectP; MSurface _surface; + int _inventoryTopIndex; + int _objectY; public: /** * Constructor -- cgit v1.2.3