diff options
Diffstat (limited to 'engines/mohawk')
-rw-r--r-- | engines/mohawk/cursors.cpp | 11 | ||||
-rw-r--r-- | engines/mohawk/cursors.h | 2 | ||||
-rw-r--r-- | engines/mohawk/livingbooks.cpp | 65 | ||||
-rw-r--r-- | engines/mohawk/livingbooks.h | 9 | ||||
-rw-r--r-- | engines/mohawk/livingbooks_code.cpp | 33 | ||||
-rw-r--r-- | engines/mohawk/livingbooks_code.h | 2 |
6 files changed, 103 insertions, 19 deletions
diff --git a/engines/mohawk/cursors.cpp b/engines/mohawk/cursors.cpp index 3284a3228f..78e099ccfe 100644 --- a/engines/mohawk/cursors.cpp +++ b/engines/mohawk/cursors.cpp @@ -252,6 +252,17 @@ void LivingBooksCursorManager_v2::setCursor(uint16 id) { } } +void LivingBooksCursorManager_v2::setCursor(const Common::String &name) { + if (!_sysArchive) + return; + + uint16 id = _sysArchive->findResourceID(ID_TCUR, name); + if (id == 0xffff) + error("Could not find cursor '%s'", name.c_str()); + else + setCursor(id); +} + PECursorManager::PECursorManager(const Common::String &appName) { _exe = new Common::PEResources(); diff --git a/engines/mohawk/cursors.h b/engines/mohawk/cursors.h index d92b6b4285..7bfa491904 100644 --- a/engines/mohawk/cursors.h +++ b/engines/mohawk/cursors.h @@ -56,6 +56,7 @@ public: virtual void showCursor(); virtual void hideCursor(); virtual void setCursor(uint16 id); + virtual void setCursor(const Common::String &name) {} virtual void setDefaultCursor(); virtual bool hasSource() const { return false; } @@ -157,6 +158,7 @@ public: ~LivingBooksCursorManager_v2(); void setCursor(uint16 id); + void setCursor(const Common::String &name); bool hasSource() const { return _sysArchive != 0; } private: diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index f9d18ff7ff..65073bd970 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -204,9 +204,12 @@ Common::Error MohawkEngine_LivingBooks::run() { break; case Common::EVENT_LBUTTONDOWN: - for (uint16 i = 0; i < _items.size(); i++) - if (_items[i]->contains(event.mouse)) - found = _items[i]; + for (Common::List<LBItem *>::const_iterator i = _orderedItems.begin(); i != _orderedItems.end(); ++i) { + if ((*i)->contains(event.mouse)) { + found = *i; + break; + } + } if (found) found->handleMouseDown(event.mouse); @@ -341,6 +344,7 @@ void MohawkEngine_LivingBooks::destroyPage() { delete _page; assert(_items.empty()); + assert(_orderedItems.empty()); _page = NULL; _notifyEvents.clear(); @@ -567,6 +571,7 @@ void MohawkEngine_LivingBooks::updatePage() { case kLBDelayedEventDestroy: _items.remove_at(i); i--; + _orderedItems.remove(delayedEvent.item); delete delayedEvent.item; _page->itemDestroyed(delayedEvent.item); if (_focus == delayedEvent.item) @@ -613,6 +618,8 @@ void MohawkEngine_LivingBooks::removeArchive(Archive *archive) { void MohawkEngine_LivingBooks::addItem(LBItem *item) { _items.push_back(item); + _orderedItems.push_front(item); + item->_iterator = _orderedItems.begin(); } void MohawkEngine_LivingBooks::removeItems(const Common::Array<LBItem *> &items) { @@ -626,6 +633,7 @@ void MohawkEngine_LivingBooks::removeItems(const Common::Array<LBItem *> &items) break; } assert(found); + _orderedItems.erase(items[i]->_iterator); } } @@ -1319,8 +1327,13 @@ void MohawkEngine_LivingBooks::handleNotify(NotifyEvent &event) { if (getGameType() == GType_LIVINGBOOKSV1) { debug(2, "kLBNotifyChangeMode: %d", event.param); quitGame(); - } else { - debug(2, "kLBNotifyChangeMode: mode %d, page %d.%d", + break; + } + + debug(2, "kLBNotifyChangeMode: v2 type %d", event.param); + switch (event.param) { + case 1: + debug(2, "kLBNotifyChangeMode:, mode %d, page %d.%d", event.newMode, event.newPage, event.newSubpage); // TODO: what is entry.newUnknown? if (!event.newMode) @@ -1331,6 +1344,13 @@ void MohawkEngine_LivingBooks::handleNotify(NotifyEvent &event) { error("kLBNotifyChangeMode failed to move to mode %d, page %d.%d", event.newMode, event.newPage, event.newSubpage); } + break; + case 3: + debug(2, "kLBNotifyChangeMode: new cursor '%s'", event.newCursor.c_str()); + _cursor->setCursor(event.newCursor); + break; + default: + error("unknown v2 kLBNotifyChangeMode type %d", event.param); } break; @@ -2084,16 +2104,32 @@ LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::Memor } if (type == kLBNotifyScript && entry->opcode == kLBNotifyChangeMode && _vm->getGameType() != GType_LIVINGBOOKSV1) { - if (size < 8) { - error("%d unknown bytes in notify entry kLBNotifyChangeMode", size); + switch (entry->param) { + case 1: + if (size < 8) + error("%d unknown bytes in notify entry kLBNotifyChangeMode", size); + entry->newUnknown = stream->readUint16(); + entry->newMode = stream->readUint16(); + entry->newPage = stream->readUint16(); + entry->newSubpage = stream->readUint16(); + debug(4, "kLBNotifyChangeMode: unknown %04x, mode %d, page %d.%d", + entry->newUnknown, entry->newMode, entry->newPage, entry->newSubpage); + size -= 8; + break; + case 3: + { + Common::String newCursor = _vm->readString(stream); + entry->newCursor = newCursor; + if (size < newCursor.size() + 1) + error("failed to read newCursor in notify entry"); + size -= newCursor.size() + 1; + debug(4, "kLBNotifyChangeMode: new cursor '%s'", newCursor.c_str()); + } + break; + default: + // the original engine also does something when param==2 (but not a notify) + error("unknown v2 kLBNotifyChangeMode type %d", entry->param); } - entry->newUnknown = stream->readUint16(); - entry->newMode = stream->readUint16(); - entry->newPage = stream->readUint16(); - entry->newSubpage = stream->readUint16(); - debug(4, "kLBNotifyChangeMode: unknown %04x, mode %d, page %d.%d", - entry->newUnknown, entry->newMode, entry->newPage, entry->newSubpage); - size -= 8; } if (entry->opcode == kLBOpSendExpression) { if (size < 4) @@ -2577,6 +2613,7 @@ void LBItem::runScript(uint event, uint16 data, uint16 from) { notifyEvent.newMode = entry->newMode; notifyEvent.newPage = entry->newPage; notifyEvent.newSubpage = entry->newSubpage; + notifyEvent.newCursor = entry->newCursor; _vm->addNotifyEvent(notifyEvent); } else _vm->addNotifyEvent(NotifyEvent(entry->opcode, entry->param)); diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index ad2fe56a52..27e703a578 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -133,7 +133,9 @@ enum { kLBEventMouseUp = 5, kLBEventPhaseMain = 6, kLBEventNotified = 7, + kLBEventDragStart = 8, kLBEventDragMove = 9, + kLBEventDragEnd = 0xa, kLBEventRolloverBegin = 0xb, kLBEventRolloverMove = 0xc, kLBEventRolloverEnd = 0xd, @@ -271,6 +273,7 @@ struct LBScriptEntry { uint16 newMode; uint16 newPage; uint16 newSubpage; + Common::String newCursor; // kLBEventNotified uint16 matchFrom; @@ -405,6 +408,8 @@ public: uint16 getSoundPriority() { return _soundMode; } bool isAmbient() { return _isAmbient; } + Common::List<LBItem *>::iterator _iterator; + protected: MohawkEngine_LivingBooks *_vm; LBPage *_page; @@ -608,6 +613,7 @@ struct NotifyEvent { uint16 newMode; uint16 newPage; uint16 newSubpage; + Common::String newCursor; }; enum DelayedEventType { @@ -667,7 +673,7 @@ public: GUI::Debugger *getDebugger() { return _console; } void addArchive(Archive *archive); - void removeArchive(Archive *Archive); + void removeArchive(Archive *archive); void addItem(LBItem *item); void removeItems(const Common::Array<LBItem *> &items); @@ -714,6 +720,7 @@ private: uint16 _phase; LBPage *_page; Common::Array<LBItem *> _items; + Common::List<LBItem *> _orderedItems; Common::Queue<DelayedEvent> _eventQueue; LBItem *_focus; void destroyPage(); diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index e9ef2516e2..80b5fe9660 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -686,8 +686,8 @@ struct CodeCommandInfo { CodeCommandInfo generalCommandInfo[NUM_GENERAL_COMMANDS] = { { "eval", &LBCode::cmdEval }, { "random", &LBCode::cmdRandom }, - { "stringLen", 0 }, - { "substring", 0 }, + { "stringLen", &LBCode::cmdStringLen }, + { "substring", &LBCode::cmdSubstring }, { "max", 0 }, { "min", 0 }, { "abs", 0 }, @@ -861,6 +861,31 @@ void LBCode::cmdRandom(const Common::Array<LBValue> ¶ms) { _stack.push(_vm->_rnd->getRandomNumberRng(min, max)); } +void LBCode::cmdStringLen(const Common::Array<LBValue> ¶ms) { + if (params.size() != 1) + error("incorrect number of parameters (%d) to stringLen", params.size()); + + const Common::String &string = params[0].toString(); + _stack.push(string.size()); +} + +void LBCode::cmdSubstring(const Common::Array<LBValue> ¶ms) { + if (params.size() != 3) + error("incorrect number of parameters (%d) to substring", params.size()); + + const Common::String &string = params[0].toString(); + uint begin = params[1].toInt(); + uint end = params[2].toInt(); + if (begin == 0) + error("invalid substring call (%d to %d)", begin, end); + if (begin > end || end > string.size()) { + _stack.push(Common::String()); + return; + } + Common::String substring(string.c_str() + (begin - 1), end - begin + 1); + _stack.push(substring); +} + void LBCode::cmdGetRect(const Common::Array<LBValue> ¶ms) { if (params.size() < 2) { _stack.push(getRectFromParams(params)); @@ -1156,8 +1181,8 @@ bool LBCode::parseCodeSymbol(const Common::String &name, uint &pos, Common::Arra // first, check whether the name matches a known function for (uint i = 0; i < 2; i++) { byte cmdToken; - CodeCommandInfo *cmdInfo; - uint cmdCount; + CodeCommandInfo *cmdInfo = NULL; + uint cmdCount = 0; switch (i) { case 0: diff --git a/engines/mohawk/livingbooks_code.h b/engines/mohawk/livingbooks_code.h index 9c58ed7a46..79c9af94f7 100644 --- a/engines/mohawk/livingbooks_code.h +++ b/engines/mohawk/livingbooks_code.h @@ -222,6 +222,8 @@ public: void cmdUnimplemented(const Common::Array<LBValue> ¶ms); void cmdEval(const Common::Array<LBValue> ¶ms); void cmdRandom(const Common::Array<LBValue> ¶ms); + void cmdStringLen(const Common::Array<LBValue> ¶ms); + void cmdSubstring(const Common::Array<LBValue> ¶ms); void cmdGetRect(const Common::Array<LBValue> ¶ms); void cmdTopLeft(const Common::Array<LBValue> ¶ms); void cmdBottomRight(const Common::Array<LBValue> ¶ms); |