From 98525c1145f8b62c1e12d463754ff3777bcc7db7 Mon Sep 17 00:00:00 2001 From: lukaslw Date: Mon, 9 Jun 2014 00:57:08 +0200 Subject: [PATCH] PRINCE: Inventory - left mouse button handling --- engines/prince/mob.h | 4 - engines/prince/prince.cpp | 152 ++++++++++++++++++++++++++------------ engines/prince/prince.h | 12 ++- engines/prince/script.cpp | 21 ++++++ engines/prince/script.h | 2 + 5 files changed, 138 insertions(+), 53 deletions(-) diff --git a/engines/prince/mob.h b/engines/prince/mob.h index 1c095c2fc43..36630eb6eb8 100644 --- a/engines/prince/mob.h +++ b/engines/prince/mob.h @@ -66,10 +66,6 @@ public: bool _visible; uint16 _type; - uint16 _x1; // initialize this? - uint16 _y1; - uint16 _x2; - uint16 _y2; uint16 _mask; Common::Rect _rect; diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 261ba70b269..ae7530997a3 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -82,7 +82,8 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) _invLineX(134), _invLineY(176), _invLine(5), _invLines(3), _invLineW(70), _invLineH(76), _maxInvW(72), _maxInvH(76), _invLineSkipX(2), _invLineSkipY(3), _showInventoryFlag(false), _inventoryBackgroundRemember(false), _mst_shadow(0), _mst_shadow2(0), _candleCounter(0), _invX1(53), _invY1(18), _invWidth(536), _invHeight(438), - _invCurInside(false) { + _invCurInside(false), _optionsFlag(false), _currentMob(0), _optionEnabled(0), _invOptionsNumber(5), + _invExamY(120) { // Debug/console setup DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel"); @@ -685,7 +686,7 @@ void PrinceEngine::keyHandler(Common::Event event) { } } -void PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array &mobList) { +int PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array &mobList) { Common::Point mousepos = _system->getEventManager()->getMousePos(); Common::Point mousePosCamera(mousepos.x + _picWindowX, mousepos.y); @@ -700,7 +701,7 @@ void PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array &mobLis textW += _font->getCharWidth(mob._name[i]); } - uint16 x = mousepos.x - textW/2; + uint16 x = mousepos.x - textW / 2; if (x > screen->w) { x = 0; } @@ -715,9 +716,10 @@ void PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array &mobLis } _font->drawString(screen, mob._name, x, y, screen->w, 216); - break; + return mob._mask; } } + return 0; } void PrinceEngine::printAt(uint32 slot, uint8 color, const char *s, uint16 x, uint16 y) { @@ -740,7 +742,7 @@ uint32 PrinceEngine::getTextWidth(const char *s) { return textW; } -void PrinceEngine::showTexts() { +void PrinceEngine::showTexts(Graphics::Surface *screen) { for (uint32 slot = 0; slot < MAXTEXTS; ++slot) { Text& text = _textSlots[slot]; if (!text._str && !text._time) @@ -751,11 +753,11 @@ void PrinceEngine::showTexts() { for (uint8 i = 0; i < lines.size(); ++i) { _font->drawString( - _graph->_frontScreen, + screen, lines[i], text._x - getTextWidth(lines[i].c_str())/2, text._y - (lines.size() - i) * (_font->getFontHeight()), - _graph->_frontScreen->w, + screen->w, text._color ); } @@ -1249,8 +1251,8 @@ void PrinceEngine::drawScreen() { playNextFrame(); if (!_inventoryBackgroundRemember) { - hotspot(_graph->_frontScreen, _mobList); - showTexts(); + _currentMob = hotspot(_graph->_frontScreen, _mobList); + showTexts(_graph->_frontScreen); } else { _inventoryBackgroundRemember = false; } @@ -1372,18 +1374,13 @@ void PrinceEngine::prepareInventoryToView() { for (int j = 0; j < _invLine; j++) { Mob tempMobItem; if (item < _mainHero->_inventory.size()) { - int itemNr = _mainHero->_inventory[item]; + int itemNr = _mainHero->_inventory[item]; tempMobItem._visible = 0; tempMobItem._mask = itemNr; // itemNr - 1?? - tempMobItem._x1 = currInvX + _picWindowX; //picWindowX2 ? - tempMobItem._x2 = currInvX + _picWindowX + _invLineW - 1; // picWindowX2 ? - tempMobItem._y1 = currInvY; - tempMobItem._y2 = currInvY + _invLineH - 1; - - tempMobItem._rect.left = tempMobItem._x1; - tempMobItem._rect.right = tempMobItem._x2; - tempMobItem._rect.top = tempMobItem._y1; - tempMobItem._rect.bottom = tempMobItem._y2; + tempMobItem._rect.left = currInvX + _picWindowX; //picWindowX2 ? + tempMobItem._rect.right = currInvX + _picWindowX + _invLineW - 1; // picWindowX2 ? + tempMobItem._rect.top = currInvY; + tempMobItem._rect.bottom = currInvY + _invLineH - 1; tempMobItem._name = ""; tempMobItem._examText = ""; @@ -1466,6 +1463,59 @@ void PrinceEngine::drawInvItems() { } } +void PrinceEngine::inventoryLeftButton() { + if (_optionsFlag == 1) { + //check_opt + if (_currentMob != 0) { + if (_optionEnabled < _invOptionsNumber) { + _optionsFlag = 0; + // ebp = _currentMob; + } else { + return; + } + } else { + // test bx, RMBMask 7996 ? + } + } else { + if (_currentMob != 0) { + //if (_currentPointerNumber != 2) { + if (_currentMob != 29) { + _optionEnabled = 0; + } else { + _optionEnabled = 1; + } + //do_option + //} else { + //use_item_on_item + //} + } + } + //do_option + int selectedMob = _currentMob; // no _currentMob just selectedMob as global for _currentMob.mask ? + if (_optionEnabled == 0) { + int invObjExamEvent = _script->scanInvObjExamEvents(selectedMob); // test this + if (invObjExamEvent == -1) { + // do_standard + printAt(0, 216, _invMobList[selectedMob]._examText.c_str(), kNormalWidth / 2, _invExamY); + showTexts(_graph->_screenForInventory); // here? + // setSpecVoice(); + } else { + //store_new_pc + // storeNewPC(); + _flags->setFlagValue(Flags::CURRMOB, selectedMob); + _currentMob = 0; + //_optionsMob = 0; + } + } else { + // not_examine + + } +} + +void PrinceEngine::inventoryRightButton() { + +} + void PrinceEngine::displayInventory() { // temp: _mainHero->_inventory.clear(); @@ -1475,37 +1525,15 @@ void PrinceEngine::displayInventory() { _mainHero->_inventory.push_back(4); _mainHero->_inventory.push_back(68); + _mainHero->_inventory.push_back(29); + _mainHero->_inventory.push_back(13); + _mainHero->_inventory.push_back(44); + _mainHero->_inventory.push_back(67); + prepareInventoryToView(); while (!shouldQuit()) { - Common::Event event; - Common::EventManager *eventMan = _system->getEventManager(); - while (eventMan->pollEvent(event)) { - switch (event.type) { - case Common::EVENT_KEYDOWN: - keyHandler(event); - break; - case Common::EVENT_KEYUP: - break; - case Common::EVENT_MOUSEMOVE: - break; - case Common::EVENT_LBUTTONDOWN: - case Common::EVENT_RBUTTONDOWN: - break; - case Common::EVENT_LBUTTONUP: - case Common::EVENT_RBUTTONUP: - break; - case Common::EVENT_QUIT: - break; - default: - break; - } - } - - if (shouldQuit()) - return; - rememberScreenInv(); Graphics::Surface *suitcase = _suitcaseBmp->getSurface(); @@ -1530,7 +1558,37 @@ void PrinceEngine::displayInventory() { break; } - hotspot(_graph->_screenForInventory, _invMobList); + _currentMob = hotspot(_graph->_screenForInventory, _invMobList); + + Common::Event event; + Common::EventManager *eventMan = _system->getEventManager(); + while (eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_KEYDOWN: + keyHandler(event); + break; + case Common::EVENT_KEYUP: + break; + case Common::EVENT_MOUSEMOVE: + break; + case Common::EVENT_LBUTTONDOWN: + inventoryLeftButton(); + break; + case Common::EVENT_RBUTTONDOWN: + break; + case Common::EVENT_LBUTTONUP: + case Common::EVENT_RBUTTONUP: + break; + case Common::EVENT_QUIT: + break; + default: + break; + } + } + + if (shouldQuit()) + return; + getDebugger()->onFrame(); _graph->update(_graph->_screenForInventory); pause(); diff --git a/engines/prince/prince.h b/engines/prince/prince.h index b85a1610c8e..46c573b0a6a 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -273,12 +273,18 @@ public: void showMask(int maskNr, Graphics::Surface *originalRoomSurface); void clsMasks(); + int _currentMob; // number of selected Mob / inventory item + static const int16 kMaxInv = 90; // max amount of inventory items in whole game uint32 _invTxtSize; byte *_invTxt; bool _showInventoryFlag; + bool _optionsFlag; + int _optionEnabled; + int _invOptionsNumber; + int _invExamY; bool _inventoryBackgroundRemember; int _invLineX; int _invLineY; @@ -307,6 +313,8 @@ public: void displayInventory(); void addInvObj(); void makeInvCursor(); + void inventoryLeftButton(); + void inventoryRightButton(); int testAnimNr; int testAnimFrame; @@ -314,9 +322,9 @@ public: private: bool playNextFrame(); void keyHandler(Common::Event event); - void hotspot(Graphics::Surface *screen, Common::Array &mobList); + int hotspot(Graphics::Surface *screen, Common::Array &mobList); void drawScreen(); - void showTexts(); + void showTexts(Graphics::Surface *screen); void init(); void showLogo(); void showBackAnims(); diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 331e425a42c..4eed60d7e5e 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -205,6 +205,27 @@ uint8 *Script::getRoomOffset(int locationNr) { return &_data[_scriptInfo.rooms + locationNr * 64]; } +struct RE { + int16 _mob; // number of Mob, -1 for end of list + int32 _code; // offset of code in script +}; + +int Script::scanInvObjExamEvents(int mobMask) { + RE tempRE; + int i = 0; + do { + tempRE._mob = (int)READ_UINT16(&_data[_scriptInfo.invObjExam + i * 6]); + debug("mob: %d", tempRE._mob); + tempRE._code = (int)READ_UINT32(&_data[_scriptInfo.invObjExam + i * 6 + 2]); + debug("code: %d", tempRE._code); + if (tempRE._mob == mobMask) { + return tempRE._code; + } + i++; + } while (tempRE._mob != -1); //?? || i <= 1 or without this (no items there) + return -1; // or sth else? +} + void Script::installSingleBackAnim(Common::Array &_backanimList, int offset) { BackgroundAnim newBackgroundAnim; diff --git a/engines/prince/script.h b/engines/prince/script.h index 4b9f85a61ec..06b09b94c4b 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -137,6 +137,8 @@ public: void installSingleBackAnim(Common::Array &_backanimList, int offset); bool loadAllMasks(Common::Array &maskList, int offset); + int scanInvObjExamEvents(int mobMask); + const char *getString(uint32 offset) { return (const char *)(&_data[offset]); }