summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-02-18 06:57:16 +0000
committerJared Adams <jaxad0127@gmail.com>2009-02-18 06:57:16 +0000
commit9568a305878d0c035e027c1ed6c9a24147a0adea (patch)
treeca6f2d1d61114f11057938c654ec004042412f1f /src
parenta0edd2e04b263faa13f6fbfbb81dd7c64520e584 (diff)
downloadmana-9568a305878d0c035e027c1ed6c9a24147a0adea.tar.gz
mana-9568a305878d0c035e027c1ed6c9a24147a0adea.tar.bz2
mana-9568a305878d0c035e027c1ed6c9a24147a0adea.tar.xz
mana-9568a305878d0c035e027c1ed6c9a24147a0adea.zip
Centralize current_npc cleanup
Diffstat (limited to 'src')
-rw-r--r--src/gui/buy.cpp2
-rw-r--r--src/gui/buysell.cpp2
-rw-r--r--src/gui/npc_text.cpp22
-rw-r--r--src/gui/sell.cpp2
-rw-r--r--src/net/beinghandler.cpp2
-rw-r--r--src/net/buysellhandler.cpp2
-rw-r--r--src/net/playerhandler.cpp4
-rw-r--r--src/npc.cpp18
-rw-r--r--src/npc.h5
9 files changed, 38 insertions, 21 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 27f738c7..b31d48e1 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -132,7 +132,7 @@ void BuyDialog::action(const gcn::ActionEvent &event)
if (event.getId() == "quit")
{
setVisible(false);
- current_npc = 0;
+ if (current_npc) current_npc->handleDeath();
return;
}
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index d060db85..2d39eac7 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -58,7 +58,7 @@ void BuySellDialog::action(const gcn::ActionEvent &event)
} else if (event.getId() == "Sell") {
current_npc->sell();
} else if (event.getId() == "Cancel") {
- current_npc = 0;
+ if (current_npc) current_npc->handleDeath();
}
setVisible(false);
}
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 0a8a4e4d..e6f039a0 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -91,19 +91,15 @@ void NpcTextDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok")
{
- switch (mState) {
- case NPC_TEXT_STATE_NEXT:
- current_npc->nextDialog();
- addText("\n> Next\n");
- break;
- case NPC_TEXT_STATE_CLOSE:
- setText("");
- setVisible(false);
- current_npc = NULL;
- break;
- default:
- return;
- }
+ if (mState == NPC_TEXT_STATE_NEXT && current_npc) {
+ current_npc->nextDialog();
+ addText("\n> Next\n");
+ } else if (mState == NPC_TEXT_STATE_CLOSE ||
+ mState == NPC_TEXT_STATE_NEXT && !current_npc) {
+ setText("");
+ setVisible(false);
+ if (current_npc) current_npc->handleDeath();
+ } else return;
}
else return;
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 1d7cb52f..dad6af21 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -131,7 +131,7 @@ void SellDialog::action(const gcn::ActionEvent &event)
if (event.getId() == "quit")
{
setVisible(false);
- current_npc = 0;
+ if (current_npc) current_npc->handleDeath();
return;
}
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index f757308c..3e746eb5 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -214,7 +214,7 @@ void BeingHandler::handleMessage(MessageIn *msg)
player_node->stopAttack();
if (dstBeing == current_npc)
- current_npc = NULL;
+ current_npc->handleDeath();
if (msg->readInt8() == 1)
dstBeing->setAction(Being::DEAD);
diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp
index 67c79ec4..a2442d70 100644
--- a/src/net/buysellhandler.cpp
+++ b/src/net/buysellhandler.cpp
@@ -107,7 +107,7 @@ void BuySellHandler::handleMessage(MessageIn *msg)
}
else {
chatWindow->chatLog(_("Nothing to sell"), BY_SERVER);
- current_npc = 0;
+ if (current_npc) current_npc->handleDeath();
}
break;
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index e142dd91..74e959da 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -86,7 +86,7 @@ namespace {
buyDialog->setVisible(false);
sellDialog->setVisible(false);
buySellDialog->setVisible(false);
- current_npc = 0;
+ if (current_npc) current_npc->handleDeath();
}
} deathListener;
}
@@ -140,7 +140,7 @@ void PlayerHandler::handleMessage(MessageIn *msg)
// Switch the actual map, deleting the previous one if necessary
engine->changeMap(mapPath);
- current_npc = 0;
+ if (current_npc) current_npc->handleDeath();
float scrollOffsetX = 0.0f;
float scrollOffsetY = 0.0f;
diff --git a/src/npc.cpp b/src/npc.cpp
index b3dd7b11..92db9373 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -24,12 +24,16 @@
#include "particle.h"
#include "text.h"
+#include "gui/npc_text.h"
+
#include "net/messageout.h"
#include "net/protocol.h"
#include "resources/npcdb.h"
-NPC *current_npc = 0;
+extern NpcTextDialog *npcTextDialog;
+
+NPC *current_npc = NULL;
static const int NAME_X_OFFSET = 15;
static const int NAME_Y_OFFSET = 30;
@@ -72,6 +76,8 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
NPC::~NPC()
{
delete mName;
+
+ if (current_npc == this) handleDeath();
}
void NPC::setName(const std::string &name)
@@ -169,3 +175,13 @@ void NPC::updateCoords()
mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET);
}
}
+
+void NPC::handleDeath()
+{
+ printf("NPC::handleDeath\n");
+ if (this != current_npc) return;
+
+ if (npcTextDialog->isVisible())
+ npcTextDialog->showCloseButton();
+ else current_npc = NULL;
+}
diff --git a/src/npc.h b/src/npc.h
index dd8d7f5d..81b6d51e 100644
--- a/src/npc.h
+++ b/src/npc.h
@@ -50,6 +50,11 @@ class NPC : public Player
void buy();
void sell();
+ /**
+ * Call this to ease clean up of the current NPC, without causing
+ * interface problems
+ */
+ void handleDeath();
protected:
Network *mNetwork;
void updateCoords();