diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-02-02 22:15:55 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-02-02 22:15:55 +0200 |
commit | 4ead5c9f65ffbf1de9b0cb60cae06b116badbced (patch) | |
tree | bc94093b90e7b4d3168259b7404ae2f6236f3925 | |
parent | 4b0caea6389ab789ff3ae3a267b9002f8a21e8c3 (diff) | |
download | manaplus-4ead5c9f65ffbf1de9b0cb60cae06b116badbced.tar.gz manaplus-4ead5c9f65ffbf1de9b0cb60cae06b116badbced.tar.bz2 manaplus-4ead5c9f65ffbf1de9b0cb60cae06b116badbced.tar.xz manaplus-4ead5c9f65ffbf1de9b0cb60cae06b116badbced.zip |
Close npc and other dialogs if reconnecting.
Also save extra layers if network error.
-rw-r--r-- | src/client.cpp | 14 | ||||
-rw-r--r-- | src/client.h | 5 | ||||
-rw-r--r-- | src/game.cpp | 15 | ||||
-rw-r--r-- | src/gui/npcdialog.cpp | 6 | ||||
-rw-r--r-- | src/gui/npcdialog.h | 5 | ||||
-rw-r--r-- | src/gui/quitdialog.cpp | 5 | ||||
-rw-r--r-- | src/net/npchandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 2 | ||||
-rw-r--r-- | src/net/tmwa/playerhandler.cpp | 9 |
9 files changed, 52 insertions, 11 deletions
diff --git a/src/client.cpp b/src/client.cpp index 251144654..3c1c2054d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -39,6 +39,8 @@ #include "statuseffect.h" #include "units.h" +#include "gui/buy.h" +#include "gui/buysell.h" #include "gui/changeemaildialog.h" #include "gui/changepassworddialog.h" #include "gui/charselectdialog.h" @@ -48,6 +50,8 @@ #include "gui/okdialog.h" #include "gui/quitdialog.h" #include "gui/register.h" +#include "gui/npcdialog.h" +#include "gui/sell.h" #include "gui/sdlinput.h" #include "gui/serverdialog.h" #include "gui/setup.h" @@ -67,6 +71,7 @@ #include "net/logindata.h" #include "net/loginhandler.h" #include "net/net.h" +#include "net/npchandler.h" #include "net/packetcounters.h" #include "net/worldinfo.h" @@ -1999,3 +2004,12 @@ void Client::setFramerate(int fpsLimit) SDL_setFramerate(&instance()->mFpsManager, fpsLimit); } + +void Client::closeDialogs() +{ + Net::getNpcHandler()->clearDialogs(); + BuyDialog::closeAll(); + BuySellDialog::closeAll(); + NpcDialog::closeAll(); + SellDialog::closeAll(); +}
\ No newline at end of file diff --git a/src/client.h b/src/client.h index c853411d3..19270d6bb 100644 --- a/src/client.h +++ b/src/client.h @@ -246,9 +246,14 @@ public: static float getGuiAlpha(); + static void closeDialogs(); + static void setFramerate(int fpsLimit); + void optionChanged(const std::string &name); + void action(const gcn::ActionEvent &event); + void initTradeFilter(); void initPacketLimiter(); diff --git a/src/game.cpp b/src/game.cpp index f5565b71e..efa5085f5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -484,12 +484,27 @@ void Game::logic() if (!disconnectedDialog) { + if (viewport) + { + Map *map = viewport->getCurrentMap(); + if (map) + map->saveExtraLayer(); + } + Client::closeDialogs(); disconnectedDialog = new OkDialog(_("Network Error"), errorMessage, false); disconnectedDialog->addActionListener(&errorListener); disconnectedDialog->requestMoveToTop(); } } + else + { + if (disconnectedDialog) + { + disconnectedDialog->scheduleDelete(); + disconnectedDialog = 0; + } + } } /** diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 3af0594f6..4fe5bf8ab 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -149,7 +149,6 @@ NpcDialog::~NpcDialog() mMinusButton = 0; instances.remove(this); - } void NpcDialog::setText(const std::string &text) @@ -418,7 +417,10 @@ void NpcDialog::closeAll() DialogList::iterator it_end = instances.end(); for (; it != it_end; ++it) - (*it)->close(); + { + if (*it) + (*it)->close(); + } } void NpcDialog::buildLayout() diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index eee4b32e2..c4a567c06 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -171,6 +171,11 @@ class NpcDialog : public Window, public gcn::ActionListener, */ static void closeAll(); + /** + * Closes all instances and destroy also net handler dialogs. + */ + static void destroyAll(); + private: typedef std::list<NpcDialog*> DialogList; static DialogList instances; diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index 221a94747..24dc953be 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -24,6 +24,7 @@ #include "client.h" #include "gui/chat.h" +#include "gui/npcdialog.h" #include "gui/sdlinput.h" #include "gui/viewport.h" @@ -34,6 +35,7 @@ #include "net/charhandler.h" #include "net/gamehandler.h" +#include "net/npchandler.h" #include "net/net.h" #include "utils/gettext.h" @@ -137,11 +139,13 @@ void QuitDialog::action(const gcn::ActionEvent &event) } else if (mLogoutQuit->isSelected()) { + Client::closeDialogs(); Client::setState(STATE_EXIT); } else if (Net::getGameHandler()->isConnected() && mSwitchAccountServer->isSelected()) { + Client::closeDialogs(); Client::setState(STATE_SWITCH_SERVER); } else if (mSwitchCharacter->isSelected()) @@ -149,6 +153,7 @@ void QuitDialog::action(const gcn::ActionEvent &event) assert(Client::getState() == STATE_GAME); Net::getCharHandler()->switchCharacter(); + Client::closeDialogs(); } } scheduleDelete(); diff --git a/src/net/npchandler.h b/src/net/npchandler.h index 1b08a83ec..e12cd9422 100644 --- a/src/net/npchandler.h +++ b/src/net/npchandler.h @@ -59,6 +59,8 @@ class NpcHandler virtual void sellItem(int beingId, int itemId, int amount) = 0; virtual void endShopping(int beingId) = 0; + + virtual void clearDialogs() = 0; }; } // namespace Net diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 84fe1789c..22f4c7687 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -112,7 +112,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) msg.readString(msg.getLength() - 8); break; - case SMSG_NPC_CLOSE: + case SMSG_NPC_CLOSE: // Show the close button if (dialog) dialog->showCloseButton(); diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 8ef19c373..528e727a3 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -29,12 +29,8 @@ #include "playerinfo.h" #include "units.h" -#include "gui/buy.h" -#include "gui/buysell.h" #include "gui/gui.h" -#include "gui/npcdialog.h" #include "gui/okdialog.h" -#include "gui/sell.h" #include "gui/skilldialog.h" #include "gui/statuswindow.h" #include "gui/viewport.h" @@ -79,10 +75,7 @@ namespace Net::getPlayerHandler()->respawn(); deathNotice = NULL; - BuyDialog::closeAll(); - BuySellDialog::closeAll(); - NpcDialog::closeAll(); - SellDialog::closeAll(); + Client::closeDialogs(); if (viewport) viewport->closePopupMenu(); |