diff options
Diffstat (limited to 'engines/titanic/messages/messages.cpp')
-rw-r--r-- | engines/titanic/messages/messages.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/engines/titanic/messages/messages.cpp b/engines/titanic/messages/messages.cpp index 1c3d406b1b..9f46fef6ca 100644 --- a/engines/titanic/messages/messages.cpp +++ b/engines/titanic/messages/messages.cpp @@ -23,6 +23,7 @@ #include "titanic/messages/messages.h" #include "titanic/messages/mouse_messages.h" #include "titanic/core/game_object.h" +#include "titanic/core/message_target.h" #include "titanic/core/tree_item.h" #include "titanic/titanic.h" @@ -79,6 +80,33 @@ bool CMessage::execute(const CString &target, const ClassDef *classDef, int flag return false; } +const MSGMAP_ENTRY *CMessage::findMapEntry(const CTreeItem *treeItem, const ClassDef *classDef) { + // Iterate through the class and any parent classes + for (const MSGMAP *msgMap = treeItem->getMessageMap(); msgMap->pFnGetBaseMap; + msgMap = msgMap->pFnGetBaseMap()) { + // Iterate through the map entries for this class + for (const MSGMAP_ENTRY *entry = msgMap->lpEntries; + entry->_class != nullptr; ++entry) { + // Check if the class or any of it's ancesotrs is handled by this entry + for (const ClassDef *entryDef = entry->_class; entryDef; entryDef = entryDef->_parent) { + if (entryDef == classDef) + return entry; + } + } + } + + return nullptr; +} + +bool CMessage::perform(CTreeItem *treeItem) { + const MSGMAP_ENTRY *entry = findMapEntry(treeItem, getType()); + return entry && (*treeItem.*(entry->_fn))(this); +} + +bool CMessage::supports(const CTreeItem *treeItem, ClassDef *classDef) { + return findMapEntry(treeItem, classDef) != nullptr; +} + bool CMessage::isMouseMsg() const { return dynamic_cast<const CMouseMsg *>(this) != nullptr; } |