From 45a2aa94b9e79bfe1e384d1240018abdc8df8f84 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 22:21:26 +0200 Subject: MACVENTURE: Fix rect collission --- engines/macventure/gui.cpp | 104 ++++++++++++++++++++++++-------------- engines/macventure/image.cpp | 4 +- engines/macventure/macventure.cpp | 12 ++++- engines/macventure/macventure.h | 2 + 4 files changed, 80 insertions(+), 42 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 529d0444de..e1fb0beca3 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -38,6 +38,11 @@ enum { kCursorHeight = 4 }; +enum { + kExitButtonWidth = 10, // HACK Arbitrary width to test + kExitButtonHeight = 10 +}; + enum { kMenuHighLevel = -1, kMenuAbout = 0, @@ -212,7 +217,8 @@ void Gui::removeChild(WindowReference target, ObjID child) { if (data.children[index].obj == child) break; } - data.children.remove_at(index); + if (index < data.children.size()) + data.children.remove_at(index); } void Gui::initGUI() { @@ -249,15 +255,15 @@ void Gui::initWindows() { _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); _controlsWindow->setActive(false); _controlsWindow->setCallback(commandsWindowCallback, this); - //loadBorder(_controlsWindow, "border_command.bmp", false); - //loadBorder(_controlsWindow, "border_command.bmp", true); + loadBorder(_controlsWindow, "border_command.bmp", false); + loadBorder(_controlsWindow, "border_command.bmp", true); // Main Game Window _mainGameWindow = _wm.addWindow(false, false, false); _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); - //loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); // In-game Output Console @@ -265,24 +271,24 @@ void Gui::initWindows() { _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - //loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); - //loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); // Self Window _selfWindow = _wm.addWindow(false, true, true); _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - //loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); + loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); // Exits Window _exitsWindow = _wm.addWindow(false, true, true); _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); - //loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); + loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); } @@ -318,8 +324,8 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); - //loadBorder(newWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(newWindow, "border_no_scroll_act.bmp", true); + loadBorder(newWindow, "border_no_scroll_inac.bmp", false); + loadBorder(newWindow, "border_no_scroll_act.bmp", true); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); @@ -340,21 +346,12 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool Graphics::TransparentSurface *surface = new Graphics::TransparentSurface(); if (stream) { - debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename); - bmpDecoder.loadStream(*stream); - source = *(bmpDecoder.getSurface()); - - source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette()); - surface->create(source.w, source.h, source.format); - surface->copyFrom(source); - surface->applyColorKey(255, 0, 255, false); - - target->setBorder(*surface, active); - - borderfile.close(); + debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename.c_str()); + target->loadBorder(*stream, active); delete stream; } + borderfile.close(); } void Gui::loadGraphics() { @@ -567,21 +564,13 @@ void Gui::drawMainGameWindow() { drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); - // To be deleted - /* - g_system->copyRectToScreen( - _mainGameWindow->getSurface()->getPixels(), - _mainGameWindow->getSurface()->pitch, - 0, 0, - _mainGameWindow->getSurface()->w, - _mainGameWindow->getSurface()->h); - */ - g_system->updateScreen(); + findWindow(kMainGameWindow)->setDirty(true); } void Gui::drawSelfWindow() { drawObjectsInWindow(kSelfWindow, _selfWindow->getSurface()); if (_engine->isObjSelected(1)) invertWindowColors(kSelfWindow); + findWindow(kSelfWindow)->setDirty(true); } void Gui::drawInventories() { @@ -600,7 +589,10 @@ void Gui::drawInventories() { srf->h + border.bottomOffset), kColorWhite); drawObjectsInWindow((*it).refcon, _inventoryWindows[(*it).refcon]->getSurface()); it++; + + findWindow((*it).refcon)->setDirty(true); } + } void Gui::drawExitsWindow() { @@ -613,7 +605,32 @@ void Gui::drawExitsWindow() { srf->w + border.rightOffset, srf->h + border.bottomOffset), kColorWhite); - drawObjectsInWindow(kMainGameWindow, _exitsWindow->getSurface()); + // For each obj in the main window, if it is an exit, we draw it + WindowData &objData = findWindowData(kMainGameWindow); + Common::Point pos; + ObjID child; + BlitMode mode; + Common::Rect exit; + for (uint i = 0; i < objData.children.size(); i++) { + child = objData.children[i].obj; + mode = (BlitMode)objData.children[i].mode; + pos = _engine->getObjExitPosition(child); + pos.x += border.leftOffset; + pos.y += border.topOffset; + exit = Common::Rect(pos.x, pos.y, pos.x + kExitButtonWidth, pos.y + kExitButtonHeight); + if (_engine->isObjExit(child)) { + if (_engine->isObjSelected(child)) + srf->fillRect(exit, kColorGreen); + + srf->fillRect(exit, kColorGreen); + } + } + + findWindow(kExitsWindow)->setDirty(true); + + // To be deleted + //g_system->copyRectToScreen(srf->getPixels(), srf->pitch, 0, 0, srf->w, srf->h); + //g_system->updateScreen(); } void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { @@ -652,7 +669,6 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * } - findWindow(data.refcon)->setDirty(true); } void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { @@ -939,9 +955,19 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; - Common::Rect intersection = clickRect.findIntersectingRect(_engine->getObjBounds(child)); - intersection = Common::Rect(0, 0, intersection.width(), intersection.height()); - if (_assets.contains(child) && _engine->isObjClickable(child)) { + if (_assets.contains(child) && + _engine->isObjClickable(child) && + _engine->isObjVisible(child)) { + Common::Rect bounds = _engine->getObjBounds(child); + Common::Rect intersection = bounds.findIntersectingRect(clickRect); + // We translate it to the image's coord system + intersection = Common::Rect( + intersection.left - bounds.left, + intersection.top - bounds.top, + intersection.left - bounds.left + intersection.width(), + intersection.top - bounds.top + intersection.height()); + + if (_assets[child]->isRectInside(intersection)) { // select the first object clicked _engine->handleObjectSelect(child, kMainGameWindow, event); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 1a50a4ffbc..e70a82154f 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -80,7 +80,7 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { if (size == 2 || size == 0) { realID = _container->getItem(id)->readUint16BE(); } - Common::BitStream32BEMSB stream(_container->getItem(realID)); + Common::BitStream32BEMSB stream(_container->getItem(realID), true); uint8 mode = stream.getBits(3); int w, h; @@ -367,7 +367,7 @@ uint ImageAsset::getWidth() { } uint ImageAsset::getHeight() { - return _bitWidth; + return _bitHeight; } void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 3187b39709..012c9a7341 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -96,7 +96,7 @@ Common::Error MacVentureEngine::run() { _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); _decodingDirectArticles = new StringTable(this, _resourceManager, kCommonArticlesStringTableID); _decodingNamingArticles = new StringTable(this, _resourceManager, kNamingArticlesStringTableID); - _decodingDirectArticles = new StringTable(this, _resourceManager, kIndirectArticlesStringTableID); + _decodingIndirectArticles = new StringTable(this, _resourceManager, kIndirectArticlesStringTableID); // Big class instantiation _gui = new Gui(this, _resourceManager); @@ -783,6 +783,16 @@ bool MacVentureEngine::isObjSelected(ObjID objID) { return idx != -1; } +bool MacVentureEngine::isObjExit(ObjID objID) { + return _world->getObjAttr(objID, kAttrIsExit); +} + +Common::Point MacVentureEngine::getObjExitPosition(ObjID objID) { + uint x = _world->getObjAttr(objID, kAttrExitX); + uint y = _world->getObjAttr(objID, kAttrExitY); + return Common::Point(x, y); +} + Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { Common::Point pos = getObjPosition(objID); uint w = _gui->getObjWidth(objID); // This shouldn't go here diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 891fdb5ad6..c63864de20 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -204,6 +204,8 @@ public: bool isObjVisible(ObjID objID); bool isObjClickable(ObjID objID); bool isObjSelected(ObjID objID); + bool isObjExit(ObjID objID); + Common::Point getObjExitPosition(ObjID objID); // Encapsulation HACK Common::Rect getObjBounds(ObjID objID); -- cgit v1.2.3