aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk
diff options
context:
space:
mode:
Diffstat (limited to 'engines/mohawk')
-rw-r--r--engines/mohawk/myst_areas.cpp74
-rw-r--r--engines/mohawk/myst_areas.h4
2 files changed, 18 insertions, 60 deletions
diff --git a/engines/mohawk/myst_areas.cpp b/engines/mohawk/myst_areas.cpp
index 824aa4247b..cfaacccb11 100644
--- a/engines/mohawk/myst_areas.cpp
+++ b/engines/mohawk/myst_areas.cpp
@@ -284,86 +284,40 @@ MystAreaActionSwitch::~MystAreaActionSwitch() {
_subResources.clear();
}
-// TODO: All these functions to switch subresource are very similar.
-// Find way to share code (function pointer pass?)
-void MystAreaActionSwitch::drawDataToScreen() {
+void MystAreaActionSwitch::doSwitch(AreaHandler handler) {
if (_actionSwitchVar == 0xFFFF) {
if (_numSubResources == 1)
- _subResources[0]->drawDataToScreen();
+ (_subResources[0]->*handler)();
else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
+ warning("Action switch resource with _numSubResources of %d, but no control variable", _numSubResources);
} else {
uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->drawDataToScreen();
+ (_subResources[0]->*handler)();
else if (_numSubResources != 0) {
if (varValue < _numSubResources)
- _subResources[varValue]->drawDataToScreen();
+ (_subResources[varValue]->*handler)();
else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
+ warning("Action switch resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
}
}
}
-void MystAreaActionSwitch::handleCardChange() {
- if (_actionSwitchVar == 0xFFFF) {
- if (_numSubResources == 1)
- _subResources[0]->handleCardChange();
- else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
- } else {
- uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
+void MystAreaActionSwitch::drawDataToScreen() {
+ doSwitch(&MystArea::drawDataToScreen);
+}
- if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->handleCardChange();
- else if (_numSubResources != 0) {
- if (varValue < _numSubResources)
- _subResources[varValue]->handleCardChange();
- else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
- }
- }
+void MystAreaActionSwitch::handleCardChange() {
+ doSwitch(&MystArea::handleCardChange);
}
void MystAreaActionSwitch::handleMouseUp() {
- if (_actionSwitchVar == 0xFFFF) {
- if (_numSubResources == 1)
- _subResources[0]->handleMouseUp();
- else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
- } else {
- uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
-
- if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->handleMouseUp();
- else if (_numSubResources != 0) {
- if (varValue < _numSubResources)
- _subResources[varValue]->handleMouseUp();
- else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
- }
- }
+ doSwitch(&MystArea::handleMouseUp);
}
void MystAreaActionSwitch::handleMouseDown() {
- if (_actionSwitchVar == 0xFFFF) {
- if (_numSubResources == 1)
- _subResources[0]->handleMouseDown();
- else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
- } else {
- uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
-
- if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->handleMouseDown();
- else if (_numSubResources != 0) {
- if (varValue < _numSubResources)
- _subResources[varValue]->handleMouseDown();
- else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
- }
- }
+ doSwitch(&MystArea::handleMouseDown);
}
MystAreaImageSwitch::MystAreaImageSwitch(MohawkEngine_Myst *vm, Common::SeekableReadStream *rlstStream, MystArea *parent) :
@@ -407,7 +361,7 @@ MystAreaImageSwitch::~MystAreaImageSwitch() {
}
void MystAreaImageSwitch::drawDataToScreen() {
- // Need to call overidden Type 7 function to ensure
+ // Need to call overridden function to ensure
// switch section is processed correctly.
MystAreaActionSwitch::drawDataToScreen();
diff --git a/engines/mohawk/myst_areas.h b/engines/mohawk/myst_areas.h
index dfaa90e8a3..b4b6fabcb7 100644
--- a/engines/mohawk/myst_areas.h
+++ b/engines/mohawk/myst_areas.h
@@ -140,6 +140,10 @@ public:
MystArea *getSubResource(uint16 index) { return _subResources[index]; }
protected:
+ typedef void (MystArea::*AreaHandler)();
+
+ void doSwitch(AreaHandler handler);
+
uint16 _actionSwitchVar;
uint16 _numSubResources;
Common::Array<MystArea *> _subResources;