From 4dd40b0f7b8fdf27b59fc7e330b624cd844348da Mon Sep 17 00:00:00 2001 From: whiterandrek Date: Sun, 3 Jun 2018 21:30:52 +0300 Subject: PINK: add saving/loading for PDA --- engines/pink/objects/actors/lead_actor.cpp | 17 +++++--- engines/pink/objects/pages/page.cpp | 1 - engines/pink/pda_mgr.cpp | 63 +++++++++++++++++++----------- engines/pink/pda_mgr.h | 9 ++++- 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/engines/pink/objects/actors/lead_actor.cpp b/engines/pink/objects/actors/lead_actor.cpp index cf59405f34..0032d7857e 100644 --- a/engines/pink/objects/actors/lead_actor.cpp +++ b/engines/pink/objects/actors/lead_actor.cpp @@ -57,6 +57,7 @@ void LeadActor::loadState(Archive &archive) { _state = (State) archive.readByte(); _nextState = (State) archive.readByte(); _stateCopy = (State) archive.readByte(); + _stateBeforePDA = (State) archive.readByte(); _isHaveItem = archive.readByte(); Common::String recepient = archive.readString(); if (!recepient.empty()) @@ -65,14 +66,15 @@ void LeadActor::loadState(Archive &archive) { _recipient = nullptr; _sequencer->loadState(archive); _walkMgr->loadState(archive); - - // load audioInfoMgr, PDAMgr + _page->getGame()->getPdaMgr().loadState(archive); + // load audioInfoMgr } void LeadActor::saveState(Archive &archive) { archive.writeByte(_state); archive.writeByte(_nextState); archive.writeByte(_stateCopy); + archive.writeByte(_stateBeforePDA); archive.writeByte(_isHaveItem); if (_recipient) archive.writeString(_recipient->getName()); @@ -80,6 +82,7 @@ void LeadActor::saveState(Archive &archive) { archive.writeString(Common::String()); _sequencer->saveState(archive); _walkMgr->saveState(archive); + _page->getGame()->getPdaMgr().saveState(archive); } void LeadActor::init(bool unk) { @@ -103,7 +106,12 @@ void LeadActor::start(bool isHandler) { _page->pause(true); break; case kPDA: - + if (_stateBeforePDA == kInventory) { + _page->getModule()->getInventoryMgr()->start(0); + _page->pause(true); + } + loadPDA(_page->getGame()->getPdaMgr().getSavedPageName()); + break; default: forceUpdateCursor(); } @@ -158,9 +166,8 @@ void LeadActor::loadPDA(const Common::String &pageName) { _stateBeforePDA = _state; _state = kPDA; - - _page->getGame()->getDirector()->saveStage(); } + _page->getGame()->getDirector()->saveStage(); _page->getGame()->getPdaMgr().setLead(this); _page->getGame()->getPdaMgr().goToPage(pageName); } diff --git a/engines/pink/objects/pages/page.cpp b/engines/pink/objects/pages/page.cpp index b7a210b82f..2266cd5a2a 100644 --- a/engines/pink/objects/pages/page.cpp +++ b/engines/pink/objects/pages/page.cpp @@ -56,7 +56,6 @@ CelDecoder *Page::loadCel(Common::String &fileName) { return _resMgr.loadCEL(fileName); } - void Page::toConsole() { for (uint i = 0; i < _actors.size(); ++i) { _actors[i]->toConsole(); diff --git a/engines/pink/pda_mgr.cpp b/engines/pink/pda_mgr.cpp index 9cce204ad8..a2cfb5d454 100644 --- a/engines/pink/pda_mgr.cpp +++ b/engines/pink/pda_mgr.cpp @@ -32,8 +32,15 @@ namespace Pink { PDAMgr::PDAMgr(Pink::PinkEngine *game) : _game(game), _page(nullptr), _cursorMgr(game, nullptr) {} -void PDAMgr::update() { - _cursorMgr.update(); +void PDAMgr::loadState(Archive &archive) { + _savedPage = archive.readString(); +} + +void PDAMgr::saveState(Archive &archive) { + if (_page) + archive.writeString(_page->getName()); + else + archive.writeString(""); } void PDAMgr::execute(const Command &command) { @@ -49,10 +56,6 @@ void PDAMgr::execute(const Command &command) { } } -PinkEngine *PDAMgr::getGame() const { - return _game; -} - void PDAMgr::goToPage(const Common::String &pageName) { if (_page && _page->getName() == pageName) return; @@ -71,6 +74,37 @@ void PDAMgr::goToPage(const Common::String &pageName) { _cursorMgr.setPage(_page); } +void PDAMgr::update() { + _cursorMgr.update(); +} + +void PDAMgr::onLeftButtonClick(Common::Point point) { + Actor *actor = _game->getDirector()->getActorByPoint(point); + if (actor) + actor->onClick(); +} + +void PDAMgr::onMouseMove(Common::Point point) { + Actor *actor = _game->getDirector()->getActorByPoint(point); + if (actor && dynamic_cast(actor)) + actor->onMouseOver(point, &_cursorMgr); + else _cursorMgr.setCursor(kPDADefaultCursor, point,Common::String()); +} + + +PinkEngine *PDAMgr::getGame() const { + return _game; +} + +const Common::String &PDAMgr::getSavedPageName() { + return _savedPage; +} + + +void PDAMgr::setLead(LeadActor *lead) { + _lead = lead; +} + void PDAMgr::close() { for (uint i = 0; i < _globalActors.size(); ++i) { delete _globalActors[i]; @@ -94,21 +128,4 @@ void PDAMgr::loadGlobal() { } } -void PDAMgr::setLead(LeadActor *lead) { - _lead = lead; -} - -void PDAMgr::onLeftButtonClick(Common::Point point) { - Actor *actor = _game->getDirector()->getActorByPoint(point); - if (actor) - actor->onClick(); -} - -void PDAMgr::onMouseMove(Common::Point point) { - Actor *actor = _game->getDirector()->getActorByPoint(point); - if (actor && dynamic_cast(actor)) - actor->onMouseOver(point, &_cursorMgr); - else _cursorMgr.setCursor(kPDADefaultCursor, point,Common::String()); -} - } // End of namespace Pink diff --git a/engines/pink/pda_mgr.h b/engines/pink/pda_mgr.h index 75f28a7c36..fd35674156 100644 --- a/engines/pink/pda_mgr.h +++ b/engines/pink/pda_mgr.h @@ -36,14 +36,20 @@ class PDAPage; class PDAMgr { public: PDAMgr(PinkEngine *game); - void update(); + + void loadState(Archive &archive); + void saveState(Archive &archive); + void execute(const Command &command); void goToPage(const Common::String &pageName); + void update(); + void onLeftButtonClick(Common::Point point); void onMouseMove(Common::Point point); PinkEngine *getGame() const; + const Common::String &getSavedPageName(); void setLead(LeadActor *lead); @@ -56,6 +62,7 @@ private: PDAPage *_page; CursorMgr _cursorMgr; Array _globalActors; + Common::String _savedPage; }; } // End of namespace Pink -- cgit v1.2.3