aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBorja Lorente2016-07-07 15:06:40 +0200
committerBorja Lorente2016-08-14 18:48:04 +0200
commit9905cd24d3335c6dab612b5a8c0e3682856020d9 (patch)
treed29956decb9991d93e380380492080ee54bd13fc
parentb4609642840917fe08d675960ce9f0e4567bd6c9 (diff)
downloadscummvm-rg350-9905cd24d3335c6dab612b5a8c0e3682856020d9.tar.gz
scummvm-rg350-9905cd24d3335c6dab612b5a8c0e3682856020d9.tar.bz2
scummvm-rg350-9905cd24d3335c6dab612b5a8c0e3682856020d9.zip
MACVENTURE: Tidy up Inventory window system
-rw-r--r--engines/macventure/gui.cpp78
-rw-r--r--engines/macventure/gui.h7
-rw-r--r--engines/macventure/macventure.cpp33
-rw-r--r--engines/macventure/macventure.h2
-rw-r--r--engines/macventure/script.cpp12
5 files changed, 87 insertions, 45 deletions
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp
index fb6f46ba03..0012335584 100644
--- a/engines/macventure/gui.cpp
+++ b/engines/macventure/gui.cpp
@@ -56,7 +56,7 @@ enum {
};
enum {
- kDragThreshold = 5
+ kDragThreshold = 1
};
static const Graphics::MenuData menuSubItems[] = {
@@ -320,21 +320,17 @@ void Gui::initWindows() {
_exitsWindow->setCallback(exitsWindowCallback, this);
loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false);
loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true);
-
-
}
void Gui::assignObjReferences() {
-
findWindowData(kSelfWindow).objRef = 0;
-
}
WindowReference Gui::createInventoryWindow(ObjID objRef) {
Graphics::MacWindow *newWindow = _wm.addWindow(true, true, true);
WindowData newData;
GlobalSettings settings = _engine->getGlobalSettings();
- newData.refcon = (WindowReference)ABS(_inventoryWindows.size()); // This is a HACK
+ newData.refcon = (WindowReference)ABS(_inventoryWindows.size() + kInventoryStart); // This is a HACK
if (_windowData->back().refcon < 0x80) { // There is already another inventory window
newData.bounds = _windowData->back().bounds; // Inventory windows are always last
@@ -606,23 +602,21 @@ void Gui::drawSelfWindow() {
}
void Gui::drawInventories() {
- Common::List<WindowData>::const_iterator it = _windowData->begin();
- while (it != _windowData->end() && (*it).refcon >= 0x80) {
- it++;
- }
+
+
Graphics::ManagedSurface *srf;
- while (it != _windowData->end()) {
- srf = _inventoryWindows[(*it).refcon]->getSurface();
- BorderBounds border = borderBounds((*it).type);
+ for (uint i = 0; i < _inventoryWindows.size(); i++) {
+ const WindowData &data = getWindowData((WindowReference)(kInventoryStart + i));
+ srf = findWindow(data.refcon)->getSurface(); // HACK
+ BorderBounds border = borderBounds(data.type);
srf->fillRect(Common::Rect(
border.leftOffset,
border.topOffset,
srf->w + border.rightOffset,
srf->h + border.bottomOffset), kColorWhite);
- drawObjectsInWindow((*it).refcon, _inventoryWindows[(*it).refcon]->getSurface());
- it++;
+ drawObjectsInWindow(data.refcon, srf);
- findWindow((*it).refcon)->setDirty(true);
+ findWindow(data.refcon)->setDirty(true);
}
}
@@ -864,8 +858,8 @@ WindowData & Gui::findWindowData(WindowReference reference) {
}
Graphics::MacWindow * Gui::findWindow(WindowReference reference) {
- if (reference < 0x80) { // It's an inventory window
- return _inventoryWindows[reference];
+ if (reference < 0x80 && reference >= kInventoryStart) { // It's an inventory window
+ return _inventoryWindows[reference - kInventoryStart];
}
switch (reference) {
case MacVenture::kNoWindow:
@@ -921,6 +915,8 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point sta
if (_engine->isObjClickable(child) && _draggedObj.id == 0) {
_draggedObj.hasMoved = false;
_draggedObj.id = child;
+ _draggedObj.startPos = startPos;
+ _draggedObj.startWin = origin;
_draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - startPos;
_draggedObj.pos = startPos + _draggedObj.mouseOffset;
}
@@ -928,14 +924,19 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point sta
void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) {
WindowReference destinationWindow = findWindowAtPoint(pos);
- if (_draggedObj.id != 0 && _draggedObj.hasMoved) {
- ObjID destObject = getWindowData(destinationWindow).objRef;
- debug("drop the object at obj %d", destObject);
- _engine->handleObjectDrop(_draggedObj.id, pos, destObject);
- }
- _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick);
+ if (_draggedObj.id != 0) {
+ if (_draggedObj.hasMoved) {
+ ObjID destObject = getWindowData(destinationWindow).objRef;
+ pos -= _draggedObj.startPos;
+ pos = localize(pos, _draggedObj.startWin, destinationWindow);
+ debug("drop the object at obj %d, pos (%d, %d)", destObject, pos.x, pos.y);
- _draggedObj.id = 0;
+ _engine->handleObjectDrop(_draggedObj.id, pos, destObject);
+ }
+ _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick);
+ _draggedObj.id = 0;
+ _draggedObj.hasMoved = false;
+ }
}
Common::Rect Gui::calculateClickRect(Common::Point clickPos, Common::Rect windowBounds) {
@@ -944,6 +945,22 @@ Common::Rect Gui::calculateClickRect(Common::Point clickPos, Common::Rect window
return Common::Rect(left - kCursorWidth, top - kCursorHeight, left + kCursorWidth, top + kCursorHeight);
}
+Common::Point Gui::localize(Common::Point point, WindowReference origin, WindowReference target) {
+ Graphics::MacWindow *oriWin = findWindow(origin);
+ Graphics::MacWindow *destWin = findWindow(target);
+ if (origin != target) {
+ // ori.local to global
+ point.x += oriWin->getDimensions().left;
+ point.y += oriWin->getDimensions().top;
+ if (destWin) {
+ // dest.globalToLocal
+ point.x -= destWin->getDimensions().left;
+ point.y -= destWin->getDimensions().top;
+ }
+ }
+ return point;
+}
+
/* HANDLERS */
void Gui::handleMenuAction(MenuAction action) {
@@ -1177,7 +1194,7 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even
event.mouse.x - _exitsWindow->getDimensions().left,
event.mouse.y - _exitsWindow->getDimensions().top);
- CommandButton data;
+ CommandButton button;
if (!_exitsData)
return false;
@@ -1185,14 +1202,15 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even
for (; it != _exitsData->end(); ++it) {
if (it->isInsideBounds(position)) {
it->select();
- data = *it;
+ button = *it;
+ _engine->handleObjectSelect(button.getData().refcon, kExitsWindow, false, false);
+ return true;
}
else {
it->unselect();
}
}
- _engine->handleObjectSelect(data.getData().refcon, kExitsWindow, false, false);
}
return getWindowData(kExitsWindow).visible;
}
@@ -1238,7 +1256,7 @@ void Gui::processCursorTick() {
void Gui::handleSingleClick(Common::Point pos) {
debug("Single Click");
- handleDragRelease(_draggedObj.pos, false, false);
+ handleDragRelease(pos, false, false);
// HACK For test, please delete me
//WindowReference destinationWindow = findWindowAtPoint(pos);
@@ -1248,7 +1266,7 @@ void Gui::handleSingleClick(Common::Point pos) {
void Gui::handleDoubleClick(Common::Point pos) {
debug("Double Click");
- handleDragRelease(_draggedObj.pos, false, true);
+ handleDragRelease(pos, false, true);
// HACK For test, please delete me
//WindowReference destinationWindow = findWindowAtPoint(pos);
diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h
index 4e4eda7092..54e7b66945 100644
--- a/engines/macventure/gui.h
+++ b/engines/macventure/gui.h
@@ -65,6 +65,7 @@ enum MenuAction {
enum WindowReference {
kNoWindow = 0,
+ kInventoryStart = 1,
kCommandsWindow = 0x80,
kMainGameWindow = 0x81,
kOutConsoleWindow = 0x82,
@@ -171,6 +172,8 @@ struct DraggedObj {
ObjID id;
Common::Point pos;
Common::Point mouseOffset;
+ Common::Point startPos;
+ WindowReference startWin;
bool hasMoved;
};
@@ -312,6 +315,7 @@ private: // Methods
void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos);
void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick);
Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds);
+ Common::Point localize(Common::Point point, WindowReference origin, WindowReference target);
};
@@ -352,12 +356,11 @@ public:
~Cursor() {}
void tick() {
- executeState();
+ executeState();
changeState(kTickCol);
}
bool processEvent(const Common::Event &event) {
- executeState();
if (event.type == Common::EVENT_MOUSEMOVE) {
_pos = event.mouse;
diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp
index 42829d97cd..b9c46da8e4 100644
--- a/engines/macventure/macventure.cpp
+++ b/engines/macventure/macventure.cpp
@@ -231,6 +231,10 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID targ
QueuedObject obj;
obj.id = type;
+ if (type == kUpdateObject && isObjEnqueued(objID)) {
+ return;
+ }
+
if (type == kUpdateWindow) { obj.target = target; }
if (type != kHightlightExits) {
@@ -247,6 +251,14 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID targ
_objQueue.push_back(obj);
}
+bool MacVentureEngine::isObjEnqueued(ObjID objID) {
+ Common::Array<QueuedObject>::const_iterator it;
+ for (it = _objQueue.begin(); it != _objQueue.end(); it++) {
+ if ((*it).object == objID) return true;
+ }
+ return false;
+}
+
void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text) {
QueuedText newText;
newText.id = type;
@@ -337,18 +349,17 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool
void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent) {
_destObject = newParent;
updateDelta(delta);
- selectControl(kOperate);
- activateCommand(kOperate);
+ selectControl(kMoveObject);
+ activateCommand(kMoveObject);
refreshReady();
preparedToRun();
}
void MacVentureEngine::updateDelta(Common::Point newPos) {
- Common::Point newDelta = newPos - _deltaPoint;
debug("Update delta: Old(%d, %d), New(%d, %d)",
_deltaPoint.x, _deltaPoint.y,
- newDelta.x, newDelta.y);
- _deltaPoint = newDelta;
+ newPos.x, newPos.y);
+ _deltaPoint = newPos;
}
void MacVentureEngine::focusObjWin(ObjID objID) {
@@ -620,7 +631,12 @@ void MacVentureEngine::focusObjectWindow(ObjID objID) {
void MacVentureEngine::openObject(ObjID objID) {
- debug("openObject: %d", objID);
+ debug("Open Object[%d] parent[%d] x[%d] y[%d]",
+ objID,
+ _world->getObjAttr(objID, kAttrParentObject),
+ _world->getObjAttr(objID, kAttrPosX),
+ _world->getObjAttr(objID, kAttrPosY));
+
if (getObjWindow(objID)) return;
if (objID == _world->getObjAttr(1, kAttrParentObject)) {
_gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true));
@@ -712,10 +728,13 @@ void MacVentureEngine::checkObject(QueuedObject old) {
}
void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) {
- warning("reflectSwap: untested");
+ //warning("reflectSwap: untested");
WindowReference from = getObjWindow(fromID);
WindowReference to = getObjWindow(toID);
WindowReference tmp = to;
+ debug("Swap Object[%d] to Object[%d], from win[%d] to win[%d] ",
+ fromID, toID, from, to);
+
if (!to) {
tmp = from;
}
diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h
index 6dab558a0d..043218c8a0 100644
--- a/engines/macventure/macventure.h
+++ b/engines/macventure/macventure.h
@@ -270,6 +270,8 @@ private:
void toggleExits();
void zoomObject(ObjID objID);
+ bool isObjEnqueued(ObjID obj);
+
// Data loading
bool loadGlobalSettings();
bool loadTextHuffman();
diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp
index a86347ba4c..5e8bcd69a2 100644
--- a/engines/macventure/script.cpp
+++ b/engines/macventure/script.cpp
@@ -51,14 +51,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat
frame.haltedInFirst = false;
frame.haltedInFamily = false;
_frames.push_back(frame);
- debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)",
+ debug(2, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)",
_frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y);
return resume(true);
}
bool ScriptEngine::resume(bool execAll) {
- debug(3, "SCRIPT: Resume");
+ debug(2, "SCRIPT: Resume");
while (_frames.size()) {
bool fail = execFrame(execAll);
if (fail) return true;
@@ -146,7 +146,7 @@ bool ScriptEngine::execFrame(bool execAll) {
bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) {
if (_scripts->getItemByteSize(scriptID) > 0) {
- debug(3, "SCRIPT: Loading function %d", scriptID);
+ debug(2, "SCRIPT: Loading function %d", scriptID);
// Insert the new script at the front
frame->scripts.push_front(ScriptAsset(scriptID, _scripts));
return runFunc(frame);
@@ -165,7 +165,7 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) {
bool ScriptEngine::runFunc(EngineFrame *frame) {
ScriptAsset &script = frame->scripts.front();
- debug(3, "SCRIPT: Executing function %d", script.getId());
+ debug(2, "SCRIPT: Executing function %d", script.getId());
EngineState *state = &frame->state;
byte op;
while (script.hasNext()) {
@@ -927,7 +927,7 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse
return true;
frame->scripts.pop_front();
script = frame->scripts.front();
- debug(3, "SCRIPT: Return from fuction %d", id);
+ debug(2, "SCRIPT: Return from fuction %d", id);
}
void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) {
@@ -1203,7 +1203,7 @@ void ScriptAsset::loadInstructions() {
for (uint i = 0; i < amount; i++) {
_instructions.push_back(res->readByte());
}
- debug(3, "SCRIPT: Load %d instructions for script %d", amount, _id);
+ debug(2, "SCRIPT: Load %d instructions for script %d", amount, _id);
}
} // End of namespace MacVenture \ No newline at end of file