summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-02-25 13:38:55 -0700
committerJared Adams <jaxad0127@gmail.com>2009-02-25 13:38:55 -0700
commitf04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 (patch)
tree1822aa7cecfbe4ef38b55216ab82b686e3b636c7 /src/gui
parent9673149ea3c28f42f38fc9989faf76d68e72bd20 (diff)
downloadMana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.tar.gz
Mana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.tar.bz2
Mana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.tar.xz
Mana-f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1.zip
Fix NPC handling to not need a handle on the NPC
The Being ID is used instead, as that is all that was ever really needed.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/buy.cpp2
-rw-r--r--src/gui/buysell.cpp22
-rw-r--r--src/gui/buysell.h7
-rw-r--r--src/gui/npc_text.cpp21
-rw-r--r--src/gui/npc_text.h8
-rw-r--r--src/gui/npcintegerdialog.cpp14
-rw-r--r--src/gui/npcintegerdialog.h4
-rw-r--r--src/gui/npclistdialog.cpp12
-rw-r--r--src/gui/npclistdialog.h5
-rw-r--r--src/gui/npcstringdialog.cpp16
-rw-r--r--src/gui/npcstringdialog.h5
-rw-r--r--src/gui/sell.cpp2
12 files changed, 90 insertions, 28 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index c084c7c2..cad21ab5 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);
- if (current_npc) current_npc->handleDeath();
+ current_npc = 0;
return;
}
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index 8bf5f1f4..c1c934d1 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -24,10 +24,13 @@
#include "../npc.h"
+#include "../net/messageout.h"
+#include "../net/protocol.h"
+
#include "../utils/gettext.h"
-BuySellDialog::BuySellDialog():
- Window(_("Shop"))
+BuySellDialog::BuySellDialog(Network *network):
+ Window(_("Shop")), mNetwork(network)
{
Button *buyButton = 0;
static const char *buttonNames[] = {
@@ -60,12 +63,19 @@ void BuySellDialog::logic()
void BuySellDialog::action(const gcn::ActionEvent &event)
{
+ setVisible(false);
+ int action;
if (event.getId() == "Buy") {
- current_npc->buy();
+ action = 0;
} else if (event.getId() == "Sell") {
- current_npc->sell();
+ action = 1;
} else if (event.getId() == "Cancel") {
- if (current_npc) current_npc->handleDeath();
+ current_npc = 0;
+ return;
}
- setVisible(false);
+
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST);
+ outMsg.writeInt32(current_npc);
+ outMsg.writeInt8(action);
}
diff --git a/src/gui/buysell.h b/src/gui/buysell.h
index 754bb551..197c1a2b 100644
--- a/src/gui/buysell.h
+++ b/src/gui/buysell.h
@@ -26,6 +26,8 @@
#include "window.h"
+class Network;
+
/**
* A dialog to choose between buying or selling at a shop.
*
@@ -40,7 +42,7 @@ class BuySellDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- BuySellDialog();
+ BuySellDialog(Network *network);
/**
* Check for current NPC
@@ -51,6 +53,9 @@ class BuySellDialog : public Window, public gcn::ActionListener
* Called when receiving actions from the widgets.
*/
void action(const gcn::ActionEvent &event);
+
+ private:
+ Network *mNetwork;
};
#endif
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 1750cbd4..db0015e9 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -28,10 +28,13 @@
#include "../npc.h"
+#include "../net/messageout.h"
+#include "../net/protocol.h"
+
#include "../utils/gettext.h"
-NpcTextDialog::NpcTextDialog():
- Window(_("NPC")),
+NpcTextDialog::NpcTextDialog(Network *network):
+ Window(_("NPC")), mNetwork(network),
mState(NPC_TEXT_STATE_WAITING)
{
setResizable(true);
@@ -97,14 +100,14 @@ void NpcTextDialog::action(const gcn::ActionEvent &event)
if (event.getId() == "ok")
{
if (mState == NPC_TEXT_STATE_NEXT && current_npc) {
- current_npc->nextDialog();
+ nextDialog();
addText("\n> Next\n");
} else if (mState == NPC_TEXT_STATE_CLOSE ||
(mState == NPC_TEXT_STATE_NEXT && !current_npc)) {
setText("");
- if (current_npc) current_npc->nextDialog();
+ if (current_npc) nextDialog();
setVisible(false);
- if (current_npc) current_npc->handleDeath();
+ current_npc = 0;
} else return;
}
else return;
@@ -114,10 +117,16 @@ void NpcTextDialog::action(const gcn::ActionEvent &event)
mState = NPC_TEXT_STATE_WAITING;
}
+void NpcTextDialog::nextDialog(int npcID)
+{
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST);
+ outMsg.writeInt32(npcID);
+}
+
void NpcTextDialog::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
setText(mText);
}
-
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index 00b11b3c..62486fff 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -28,6 +28,9 @@
#include "window.h"
+#include "../npc.h"
+
+class Network;
class TextBox;
/**
@@ -43,7 +46,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- NpcTextDialog();
+ NpcTextDialog(Network *network);
/**
* Called when receiving actions from the widgets.
@@ -74,6 +77,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener
void showCloseButton();
+ void nextDialog(int npcID = current_npc);
+
/**
* Called when resizing the window.
*
@@ -82,6 +87,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener
void widgetResized(const gcn::Event &event);
private:
+ Network *mNetwork;
gcn::ScrollArea *mScrollArea;
TextBox *mTextBox;
gcn::Button *mButton;
diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp
index f91b42da..f6d788df 100644
--- a/src/gui/npcintegerdialog.cpp
+++ b/src/gui/npcintegerdialog.cpp
@@ -28,13 +28,16 @@
#include "../npc.h"
+#include "../net/messageout.h"
+#include "../net/protocol.h"
+
#include "../utils/gettext.h"
#include "../utils/strprintf.h"
extern NpcTextDialog *npcTextDialog;
-NpcIntegerDialog::NpcIntegerDialog():
- Window(_("NPC Number Request"))
+NpcIntegerDialog::NpcIntegerDialog(Network *network):
+ Window(_("NPC Number Request")), mNetwork(network)
{
mValueField = new IntTextField;
@@ -104,7 +107,12 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event)
if (finish)
{
setVisible(false);
- current_npc->integerInput(mValueField->getValue());
+
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_NPC_INT_RESPONSE);
+ outMsg.writeInt32(current_npc);
+ outMsg.writeInt32(mValueField->getValue());
+
mValueField->reset();
}
}
diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h
index 6083338c..80a21848 100644
--- a/src/gui/npcintegerdialog.h
+++ b/src/gui/npcintegerdialog.h
@@ -26,6 +26,7 @@
#include "window.h"
+class Network;
class IntTextField;
/**
@@ -41,7 +42,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- NpcIntegerDialog();
+ NpcIntegerDialog(Network *network);
/**
* Called when receiving actions from the widgets.
@@ -81,6 +82,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener
void setVisible(bool visible);
private:
+ Network *mNetwork;
gcn::Button *mDecButton;
gcn::Button *mIncButton;
IntTextField *mValueField;
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp
index 8349cb4a..fc7d2979 100644
--- a/src/gui/npclistdialog.cpp
+++ b/src/gui/npclistdialog.cpp
@@ -31,13 +31,16 @@
#include "../npc.h"
+#include "../net/messageout.h"
+#include "../net/protocol.h"
+
#include "../utils/gettext.h"
#include "../utils/strprintf.h"
extern NpcTextDialog *npcTextDialog;
-NpcListDialog::NpcListDialog():
- Window(_("NPC"))
+NpcListDialog::NpcListDialog(Network *network):
+ Window(_("NPC")), mNetwork(network)
{
setResizable(true);
@@ -115,7 +118,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event)
{
setVisible(false);
reset();
- current_npc->dialogChoice(choice);
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_NPC_LIST_CHOICE);
+ outMsg.writeInt32(current_npc);
+ outMsg.writeInt8(choice);
}
}
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index e7e2f9a9..a7b49506 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -29,6 +29,8 @@
#include <vector>
+class Network;
+
/**
* The npc list dialog.
*
@@ -43,7 +45,7 @@ class NpcListDialog : public Window, public gcn::ActionListener,
*
* @see Window::Window
*/
- NpcListDialog();
+ NpcListDialog(Network *network);
/**
* Called when receiving actions from the widgets.
@@ -75,6 +77,7 @@ class NpcListDialog : public Window, public gcn::ActionListener,
void setVisible(bool visible);
private:
+ Network *mNetwork;
gcn::ListBox *mItemList;
std::vector<std::string> mItems;
diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp
index 679c93e5..7ed05288 100644
--- a/src/gui/npcstringdialog.cpp
+++ b/src/gui/npcstringdialog.cpp
@@ -28,13 +28,16 @@
#include "../npc.h"
+#include "../net/messageout.h"
+#include "../net/protocol.h"
+
#include "../utils/gettext.h"
#include "../utils/strprintf.h"
extern NpcTextDialog *npcTextDialog;
-NpcStringDialog::NpcStringDialog():
- Window(_("NPC Text Request"))
+NpcStringDialog::NpcStringDialog(Network *network):
+ Window(_("NPC Text Request")), mNetwork(network)
{
mValueField = new TextField("");
@@ -74,8 +77,15 @@ void NpcStringDialog::action(const gcn::ActionEvent &event)
}
setVisible(false);
- current_npc->stringInput(mValueField->getText());
+ std::string text = mValueField->getText();
mValueField->setText("");
+
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_NPC_STR_RESPONSE);
+ outMsg.writeInt16(text.length() + 9);
+ outMsg.writeInt32(current_npc);
+ outMsg.writeString(text, text.length());
+ outMsg.writeInt8(0);
}
bool NpcStringDialog::isInputFocused()
diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h
index 31f9c9a0..43283219 100644
--- a/src/gui/npcstringdialog.h
+++ b/src/gui/npcstringdialog.h
@@ -26,6 +26,8 @@
#include <guichan/actionlistener.hpp>
+class Network;
+
/**
* The npc integer input dialog.
*
@@ -39,7 +41,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- NpcStringDialog();
+ NpcStringDialog(Network *network);
/**
* Called when receiving actions from the widgets.
@@ -71,6 +73,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener
void setVisible(bool visible);
private:
+ Network *mNetwork;
gcn::TextField *mValueField;
std::string mDefault;
};
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 14620aa6..51fc8f9f 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -133,7 +133,7 @@ void SellDialog::action(const gcn::ActionEvent &event)
if (event.getId() == "quit")
{
setVisible(false);
- if (current_npc) current_npc->handleDeath();
+ current_npc = 0;
return;
}