diff options
author | Paul Gilbert | 2016-03-06 22:57:45 -0500 |
---|---|---|
committer | Paul Gilbert | 2016-03-06 22:57:45 -0500 |
commit | fbcd4de457cfa18d121158e6be45ade57a3428f1 (patch) | |
tree | 57164bead00648b82210a34409bfc85ff52c42ea /engines/titanic | |
parent | 2395e5601ca09c001ba5cff7c67a0dd70019f789 (diff) | |
download | scummvm-rg350-fbcd4de457cfa18d121158e6be45ade57a3428f1.tar.gz scummvm-rg350-fbcd4de457cfa18d121158e6be45ade57a3428f1.tar.bz2 scummvm-rg350-fbcd4de457cfa18d121158e6be45ade57a3428f1.zip |
TITANIC: Overall message handling method
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/core/saveable_object.cpp | 17 | ||||
-rw-r--r-- | engines/titanic/core/saveable_object.h | 2 | ||||
-rw-r--r-- | engines/titanic/core/tree_item.cpp | 17 | ||||
-rw-r--r-- | engines/titanic/core/tree_item.h | 2 | ||||
-rw-r--r-- | engines/titanic/messages/messages.cpp | 29 | ||||
-rw-r--r-- | engines/titanic/messages/messages.h | 8 |
6 files changed, 72 insertions, 3 deletions
diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index e831cca8b0..7ec4f949f2 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -406,6 +406,12 @@ namespace Titanic { +CSaveableObject *ClassDef::create() { + return new CSaveableObject(); +} + +/*------------------------------------------------------------------------*/ + Common::HashMap<Common::String, CSaveableObject::CreateFunction> * CSaveableObject::_classList = nullptr; Common::List<ClassDef *> *CSaveableObject::_classDefs; @@ -1573,10 +1579,15 @@ void CSaveableObject::saveFooter(SimpleFile *file, int indent) const { file->writeClassEnd(indent); } -/*------------------------------------------------------------------------*/ +bool CSaveableObject::isInstanceOf(const ClassDef &classDef) { + for (ClassDef *def = getType(); def != nullptr; def = def->_parent) { + if (def == &classDef) + return true; + } -CSaveableObject *ClassDef::create() { - return new CSaveableObject(); + return false; } + + } // End of namespace Titanic diff --git a/engines/titanic/core/saveable_object.h b/engines/titanic/core/saveable_object.h index 32b277f53b..b15dd13072 100644 --- a/engines/titanic/core/saveable_object.h +++ b/engines/titanic/core/saveable_object.h @@ -79,6 +79,8 @@ public: CLASSDEF virtual ~CSaveableObject() {} + bool isInstanceOf(const ClassDef &classDef); + /** * Save the data for the class to file */ diff --git a/engines/titanic/core/tree_item.cpp b/engines/titanic/core/tree_item.cpp index 8c9080fd84..ee89a0532e 100644 --- a/engines/titanic/core/tree_item.cpp +++ b/engines/titanic/core/tree_item.cpp @@ -70,6 +70,23 @@ CTreeItem *CTreeItem::getLastChild() { return _firstChild->getLastSibling(); } +CTreeItem *CTreeItem::scan(CTreeItem *item) { + if (_firstChild) + return _firstChild; + + CTreeItem *treeItem = this; + while (treeItem != item) { + if (treeItem->_nextSibling) + return treeItem->_nextSibling; + + treeItem = treeItem->_parent; + if (!treeItem) + break; + } + + return nullptr; +} + CDontSaveFileItem *CTreeItem::getDontSaveFileItem() { CTreeItem *item = getFirstChild(); while (item) { diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h index 78a58fa735..eed30a3ecb 100644 --- a/engines/titanic/core/tree_item.h +++ b/engines/titanic/core/tree_item.h @@ -96,6 +96,8 @@ public: */ CTreeItem *getLastChild(); + CTreeItem *scan(CTreeItem *item); + /** * Get any dont save file item in the immediate children */ diff --git a/engines/titanic/messages/messages.cpp b/engines/titanic/messages/messages.cpp index c2a6197d4a..f9648f9dfb 100644 --- a/engines/titanic/messages/messages.cpp +++ b/engines/titanic/messages/messages.cpp @@ -22,6 +22,7 @@ #include "titanic/messages/messages.h" #include "titanic/core/game_object.h" +#include "titanic/core/tree_item.h" namespace Titanic { @@ -37,4 +38,32 @@ void CMessage::load(SimpleFile *file) { CSaveableObject::load(file); } +bool CMessage::execute(CTreeItem *target, const ClassDef *classDef, int flags) { + // If no target was specified, then there's nothing to do + if (!target) + return false; + + bool result = false; + CTreeItem *item = target; + CTreeItem *nextItem = nullptr; + do { + if (flags & MSGFLAG_SCAN) + nextItem = item->scan(target); + + if (!(flags & MSGFLAG_CLASS_DEF) || item->isInstanceOf(*classDef)) { + bool handled = true; // item->handleEvent(this); + + if (handled) { + result = true; + if (flags & MSGFLAG_BREAK_IF_HANDLED) + return true; + } + } + + item = nextItem; + } while (nextItem); + + return result; +} + } // End of namespace Titanic diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h index 5e6e0d7939..e369157f1d 100644 --- a/engines/titanic/messages/messages.h +++ b/engines/titanic/messages/messages.h @@ -28,11 +28,19 @@ namespace Titanic { +enum MessageFlag { + MSGFLAG_SCAN = 1, + MSGFLAG_BREAK_IF_HANDLED = 2, + MSGFLAG_CLASS_DEF = 4 +}; + class CMessage : public CSaveableObject { public: CLASSDEF CMessage(); + bool execute(CTreeItem *target, const ClassDef *classDef, int flags); + /** * Save the data for the class to file */ |