aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/mohawk/livingbooks.cpp14
-rw-r--r--engines/mohawk/livingbooks.h3
2 files changed, 14 insertions, 3 deletions
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp
index f9d18ff7ff..dd7bc9a839 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);
}
}
diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h
index ad2fe56a52..c86a3cc055 100644
--- a/engines/mohawk/livingbooks.h
+++ b/engines/mohawk/livingbooks.h
@@ -405,6 +405,8 @@ public:
uint16 getSoundPriority() { return _soundMode; }
bool isAmbient() { return _isAmbient; }
+ Common::List<LBItem *>::iterator _iterator;
+
protected:
MohawkEngine_LivingBooks *_vm;
LBPage *_page;
@@ -714,6 +716,7 @@ private:
uint16 _phase;
LBPage *_page;
Common::Array<LBItem *> _items;
+ Common::List<LBItem *> _orderedItems;
Common::Queue<DelayedEvent> _eventQueue;
LBItem *_focus;
void destroyPage();