From 9568a305878d0c035e027c1ed6c9a24147a0adea Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Feb 2009 06:57:16 +0000 Subject: Centralize current_npc cleanup --- src/gui/buy.cpp | 2 +- src/gui/buysell.cpp | 2 +- src/gui/npc_text.cpp | 22 +++++++++------------- src/gui/sell.cpp | 2 +- 4 files changed, 12 insertions(+), 16 deletions(-) (limited to 'src/gui') 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; } -- cgit v1.2.3-70-g09d2