diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-01-25 02:35:39 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-25 02:35:39 +0300 |
commit | e15445f0f8f95f1547798b886b002146d282c006 (patch) | |
tree | d29b49d8d7d0c8d997cbd58ce3733dba5c2c5a9a | |
parent | 992f105f78fb0e4c42fcc7941e289a2348a3ccaf (diff) | |
download | mv-e15445f0f8f95f1547798b886b002146d282c006.tar.gz mv-e15445f0f8f95f1547798b886b002146d282c006.tar.bz2 mv-e15445f0f8f95f1547798b886b002146d282c006.tar.xz mv-e15445f0f8f95f1547798b886b002146d282c006.zip |
Save camera mode before speaking with npc and restore after.
-rw-r--r-- | src/gui/npcdialog.cpp | 39 | ||||
-rw-r--r-- | src/gui/npcdialog.h | 7 | ||||
-rw-r--r-- | src/gui/viewport.h | 6 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 7 |
4 files changed, 57 insertions, 2 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 265748b6f..eadd99c21 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -26,6 +26,7 @@ #include "client.h" #include "gui/setup.h" +#include "gui/viewport.h" #include "gui/widgets/browserbox.h" #include "gui/widgets/button.h" @@ -62,7 +63,10 @@ NpcDialog::NpcDialog(int npcId) : mDefaultInt(0), mInputState(NPC_INPUT_NONE), mActionState(NPC_ACTION_WAIT), - mLastNextTime(0) + mLastNextTime(0), + mCameraMode(-1), + mCameraX(0), + mCameraY(0) { // Basic Window Setup setWindowName("NpcText"); @@ -301,6 +305,7 @@ void NpcDialog::nextDialog() void NpcDialog::closeDialog() { + restoreCamera(); Net::getNpcHandler()->closeDialog(mNpcId); } @@ -504,4 +509,34 @@ void NpcDialog::buildLayout() redraw(); mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); -}
\ No newline at end of file +} + +void NpcDialog::saveCamera() +{ + if (!viewport || mCameraMode >= 0) + return; + + mCameraMode = viewport->getCameraMode(); + mCameraX = viewport->getCameraRelativeX(); + mCameraY = viewport->getCameraRelativeY(); +} + +void NpcDialog::restoreCamera() +{ + if (!viewport || mCameraMode == -1) + return; + + if (!mCameraMode) + { + if (viewport->getCameraMode() != mCameraMode) + viewport->toggleCameraMode(); + } + else + { + if (viewport->getCameraMode() != mCameraMode) + viewport->toggleCameraMode(); + viewport->setCameraRelativeX(mCameraX); + viewport->setCameraRelativeY(mCameraY); + } + mCameraMode = -1; +} diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index e76897499..4d919a3f2 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -172,6 +172,10 @@ class NpcDialog : public Window, public gcn::ActionListener, */ static void destroyAll(); + void saveCamera(); + + void restoreCamera(); + private: typedef std::list<NpcDialog*> DialogList; static DialogList instances; @@ -230,6 +234,9 @@ class NpcDialog : public Window, public gcn::ActionListener, NpcInputState mInputState; NpcActionState mActionState; int mLastNextTime; + int mCameraMode; + int mCameraX; + int mCameraY; }; #endif // NPCDIALOG_H diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 0f56e9426..4ed80ed32 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -248,6 +248,12 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int getCameraRelativeY() { return mCameraRelativeY; } + void setCameraRelativeX(int n) + { mCameraRelativeX = n; } + + void setCameraRelativeY(int n) + { mCameraRelativeY = n; } + bool isPopupMenuVisible(); void moveCameraToActor(int actorId, int x = 0, int y = 0); diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index c395eb1b8..eed10ab7c 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -131,6 +131,8 @@ void NpcHandler::closeDialog(int npcId) { if ((*it).second.dialog) (*it).second.dialog->close(); + if ((*it).second.dialog == mDialog) + mDialog = nullptr; mNpcDialogs.erase(it); } } @@ -226,6 +228,7 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength) else { mDialog = new NpcDialog(npcId); + mDialog->saveCamera(); if (player_node) player_node->stopWalking(false); Wrapper wrap; @@ -235,7 +238,11 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength) } else { + if (mDialog && mDialog != diag->second.dialog) + mDialog->restoreCamera(); mDialog = diag->second.dialog; + if (mDialog) + mDialog->saveCamera(); } return npcId; } |