summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Makefile.am4
-rw-r--r--src/game.cpp11
-rw-r--r--src/gui/npcintegerdialog.cpp125
-rw-r--r--src/gui/npcintegerdialog.h82
-rw-r--r--src/gui/npcstringdialog.cpp77
-rw-r--r--src/gui/npcstringdialog.h78
-rw-r--r--src/gui/playerbox.cpp6
-rw-r--r--src/gui/register.cpp99
-rw-r--r--src/gui/register.h17
-rw-r--r--src/gui/setup_video.cpp4
-rw-r--r--src/gui/truetypefont.h4
-rw-r--r--src/net/npchandler.cpp22
-rw-r--r--src/net/protocol.h4
-rw-r--r--src/npc.cpp36
-rw-r--r--src/npc.h2
16 files changed, 482 insertions, 93 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 467ceb71..f87b6c8c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -116,8 +116,12 @@ SET(SRCS
gui/minimap.h
gui/ministatus.cpp
gui/ministatus.h
+ gui/npcintegerdialog.cpp
+ gui/npcintegerdialog.h
gui/npclistdialog.cpp
gui/npclistdialog.h
+ gui/npcstringdialog.cpp
+ gui/npcstringdialog.h
gui/npc_text.cpp
gui/npc_text.h
gui/ok_dialog.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 95379a3c..2936849a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,8 +68,12 @@ tmw_SOURCES = gui/widgets/layout.cpp \
gui/minimap.h \
gui/ministatus.cpp \
gui/ministatus.h \
+ gui/npcintegerdialog.cpp \
+ gui/npcintegerdialog.h \
gui/npclistdialog.cpp \
gui/npclistdialog.h \
+ gui/npcstringdialog.cpp \
+ gui/npcstringdialog.h \
gui/npc_text.cpp \
gui/npc_text.h \
gui/ok_dialog.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index a788c51a..1b6f2d5c 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -55,7 +55,9 @@
#include "gui/menuwindow.h"
#include "gui/minimap.h"
#include "gui/ministatus.h"
+#include "gui/npcintegerdialog.h"
#include "gui/npclistdialog.h"
+#include "gui/npcstringdialog.h"
#include "gui/npc_text.h"
#include "gui/ok_dialog.h"
#include "gui/sdlinput.h"
@@ -107,8 +109,10 @@ BuyDialog *buyDialog;
SellDialog *sellDialog;
BuySellDialog *buySellDialog;
InventoryWindow *inventoryWindow;
+NpcIntegerDialog *npcIntegerDialog;
NpcListDialog *npcListDialog;
NpcTextDialog *npcTextDialog;
+NpcStringDialog *npcStringDialog;
SkillDialog *skillDialog;
Setup* setupWindow;
Minimap *minimap;
@@ -187,7 +191,9 @@ void createGuiWindows(Network *network)
buySellDialog = new BuySellDialog();
inventoryWindow = new InventoryWindow();
npcTextDialog = new NpcTextDialog();
+ npcIntegerDialog = new NpcIntegerDialog();
npcListDialog = new NpcListDialog();
+ npcStringDialog = new NpcStringDialog();
skillDialog = new SkillDialog();
setupWindow = new Setup();
minimap = new Minimap();
@@ -237,8 +243,10 @@ void destroyGuiWindows()
delete sellDialog;
delete buySellDialog;
delete inventoryWindow;
+ delete npcIntegerDialog;
delete npcListDialog;
delete npcTextDialog;
+ delete npcStringDialog;
delete skillDialog;
delete setupWindow;
delete minimap;
@@ -643,7 +651,8 @@ void Game::handleInput()
default:
break;
}
- if (keyboard.isEnabled() && !chatWindow->isInputFocused())
+ if (keyboard.isEnabled() && !chatWindow->isInputFocused()
+ && !npcStringDialog->isInputFocused())
{
const int tKey = keyboard.getKeyIndex(event.key.keysym.sym);
// Do not activate shortcuts if tradewindow is visible
diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp
new file mode 100644
index 00000000..f5b6ac5b
--- /dev/null
+++ b/src/gui/npcintegerdialog.cpp
@@ -0,0 +1,125 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "npcintegerdialog.h"
+
+#include <limits>
+#include <sstream>
+
+#include "button.h"
+#include "textfield.h"
+
+#include "../npc.h"
+
+#include "../utils/gettext.h"
+#include "../utils/tostring.h"
+
+#include "widgets/layout.h"
+
+NpcIntegerDialog::NpcIntegerDialog():
+ Window(_("NPC Number Request"))
+{
+ mDecButton = new Button("-", "decvalue", this);
+ mIncButton = new Button("+", "incvalue", this);
+ mValueField = new TextField();
+ okButton = new Button(_("OK"), "ok", this);
+ cancelButton = new Button(_("Cancel"), "cancel", this);
+
+ mDecButton->setSize(20, 20);
+ mIncButton->setSize(20, 20);
+
+ place(0, 0, mDecButton);
+ place(1, 0, mValueField, 3);
+ place(4, 0, mIncButton);
+ place(2, 1, okButton);
+ place(3, 1, cancelButton, 2);
+ reflowLayout(175, 0);
+
+ setLocationRelativeTo(getParent());
+
+ mValueField->setActionEventId("valuefield");
+ mValueField->addKeyListener(this);
+}
+
+void NpcIntegerDialog::prepDialog(const int min, const int def, const int max)
+{
+ mMin = min;
+ mMax = max;
+ mDefault = def;
+ mValue = def;
+
+ mValueField->setText(toString(mValue));
+}
+
+int NpcIntegerDialog::getValue()
+{
+ return mValue;
+}
+
+void NpcIntegerDialog::action(const gcn::ActionEvent &event)
+{
+ int finish = 0;
+
+ if (event.getId() == "ok")
+ {
+ finish = 1;
+ }
+ else if (event.getId() == "cancel")
+ {
+ finish = 1;
+ mValue = mDefault;
+ }
+ else if (event.getId() == "decvalue" && mValue < mMin)
+ {
+ mValue--;
+ }
+ else if (event.getId() == "incvalue" && mValue > mMax)
+ {
+ mValue++;
+ }
+
+ mValueField->setText(toString(mValue));
+
+ if (finish)
+ {
+ setVisible(false);
+ current_npc->integerInput(mValue);
+ current_npc = 0;
+ }
+}
+
+void NpcIntegerDialog::keyPressed(gcn::KeyEvent &event)
+{
+ std::stringstream tempValue(mValueField->getText());
+ int value;
+ tempValue >> value;
+ if (value < mMin)
+ {
+ value = mMin;
+ }
+ if (value > mMax)
+ {
+ value = mMax;
+ }
+
+ mValue = value;
+ mValueField->setText(toString(value));
+}
diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h
new file mode 100644
index 00000000..a45d57c4
--- /dev/null
+++ b/src/gui/npcintegerdialog.h
@@ -0,0 +1,82 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _TMW_GUI_NPCINTEGERDIALOG_H
+#define _TMW_GUI_NPCINTEGERDIALOG_H
+
+#include <iosfwd>
+#include <vector>
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
+
+#include "window.h"
+
+#include "../guichanfwd.h"
+
+/**
+ * The npc integer input dialog.
+ *
+ * \ingroup Interface
+ */
+class NpcIntegerDialog : public Window, public gcn::ActionListener,
+ public gcn::KeyListener
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ NpcIntegerDialog();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ /** Called when key is pressed */
+ void keyPressed(gcn::KeyEvent &event);
+
+ /**
+ * Returns the current value.
+ */
+ int getValue();
+
+ /**
+ * Prepares the NPC dialog.
+ *
+ * @param min The minimum value to allow
+ * @param def The default value
+ * @param max The maximum value to allow
+ */
+ void prepDialog(const int min, const int def, const int max);
+
+ private:
+ int mMin, mMax, mDefault, mValue;
+ gcn::Button *mDecButton;
+ gcn::Button *mIncButton;
+ gcn::TextField *mValueField;
+ gcn::Button *okButton;
+ gcn::Button *cancelButton;
+};
+
+#endif // _TMW_GUI_NPCINTEGERDIALOG_H
diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp
new file mode 100644
index 00000000..6bca961c
--- /dev/null
+++ b/src/gui/npcstringdialog.cpp
@@ -0,0 +1,77 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "npcstringdialog.h"
+
+#include <limits>
+#include <sstream>
+
+#include "button.h"
+#include "textfield.h"
+
+#include "../npc.h"
+
+#include "../utils/gettext.h"
+#include "../utils/tostring.h"
+
+#include "widgets/layout.h"
+
+NpcStringDialog::NpcStringDialog():
+ Window(_("NPC Text Request"))
+{
+ mValueField = new TextField("The Mana World"); // Just a sizing value :)
+ okButton = new Button(_("OK"), "ok", this);
+ cancelButton = new Button(_("Cancel"), "cancel", this);
+
+ place(0, 0, mValueField, 3);
+ place(1, 1, okButton);
+ place(2, 1, cancelButton);
+ reflowLayout(175, 0);
+
+ setLocationRelativeTo(getParent());
+}
+
+std::string NpcStringDialog::getValue()
+{
+ return mValueField->getText();
+}
+
+void NpcStringDialog::setValue(const std::string &value)
+{
+ mValueField->setText(value);
+}
+
+void NpcStringDialog::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "cancel")
+ {
+ mValueField->setText("");
+ }
+
+ setVisible(false);
+ current_npc->stringInput(mValueField->getText());
+ current_npc = 0;
+}
+
+bool NpcStringDialog::isInputFocused()
+{
+ return mValueField->isFocused();
+}
diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h
new file mode 100644
index 00000000..22054994
--- /dev/null
+++ b/src/gui/npcstringdialog.h
@@ -0,0 +1,78 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _TMW_GUI_NPCSTRINGDIALOG_H
+#define _TMW_GUI_NPCSTRINGDIALOG_H
+
+#include <iosfwd>
+#include <vector>
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
+
+#include "window.h"
+
+#include "../guichanfwd.h"
+
+/**
+ * The npc integer input dialog.
+ *
+ * \ingroup Interface
+ */
+class NpcStringDialog : public Window, public gcn::ActionListener
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ NpcStringDialog();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ /**
+ * Returns the current value.
+ */
+ std::string getValue();
+
+ /**
+ * Chnages the current value.
+ *
+ * @param value The new value
+ */
+ void setValue(const std::string &value);
+
+ /**
+ * Checks whether NpcStringDialog is Focused or not.
+ */
+ bool isInputFocused();
+
+ private:
+ gcn::TextField *mValueField;
+ gcn::Button *okButton;
+ gcn::Button *cancelButton;
+};
+
+#endif // _TMW_GUI_NPCSTRINGDIALOG_H
diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp
index b6b7663a..b196753b 100644
--- a/src/gui/playerbox.cpp
+++ b/src/gui/playerbox.cpp
@@ -74,8 +74,7 @@ PlayerBox::~PlayerBox()
}
}
-void
-PlayerBox::draw(gcn::Graphics *graphics)
+void PlayerBox::draw(gcn::Graphics *graphics)
{
if (mPlayer)
{
@@ -88,8 +87,7 @@ PlayerBox::draw(gcn::Graphics *graphics)
}
}
-void
-PlayerBox::drawFrame(gcn::Graphics *graphics)
+void PlayerBox::drawFrame(gcn::Graphics *graphics)
{
int w, h, bs;
bs = getFrameSize();
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index ce36efa2..cb2f468d 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -39,17 +39,30 @@
#include "textfield.h"
#include "ok_dialog.h"
+#include "widgets/layout.h"
+
#include "../utils/gettext.h"
#include "../utils/strprintf.h"
-void
-WrongDataNoticeListener::setTarget(gcn::TextField *textField)
+/**
+ * Listener used while dealing with wrong data. It is used to direct the focus
+ * to the field which contained wrong data when the Ok button was pressed on
+ * the error notice.
+ */
+class WrongDataNoticeListener : public gcn::ActionListener {
+ public:
+ void setTarget(gcn::TextField *textField);
+ void action(const gcn::ActionEvent &event);
+ private:
+ gcn::TextField *mTarget;
+};
+
+void WrongDataNoticeListener::setTarget(gcn::TextField *textField)
{
mTarget = textField;
}
-void
-WrongDataNoticeListener::action(const gcn::ActionEvent &event)
+void WrongDataNoticeListener::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok")
{
@@ -57,9 +70,10 @@ WrongDataNoticeListener::action(const gcn::ActionEvent &event)
}
}
+
RegisterDialog::RegisterDialog(LoginData *loginData):
- Window("Register"),
- mWrongDataNoticeListener(new WrongDataNoticeListener()),
+ Window(_("Register")),
+ mWrongDataNoticeListener(new WrongDataNoticeListener),
mLoginData(loginData)
{
gcn::Label *userLabel = new gcn::Label(_("Name:"));
@@ -68,46 +82,29 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
gcn::Label *serverLabel = new gcn::Label(_("Server:"));
mUserField = new TextField(loginData->username);
mPasswordField = new PasswordField(loginData->password);
- mConfirmField = new PasswordField();
+ mConfirmField = new PasswordField;
mServerField = new TextField(loginData->hostname);
mMaleButton = new RadioButton(_("Male"), "sex", true);
mFemaleButton = new RadioButton(_("Female"), "sex", false);
mRegisterButton = new Button(_("Register"), "register", this);
mCancelButton = new Button(_("Cancel"), "cancel", this);
- const int width = 220;
- const int height = 150;
- setContentSize(width, height);
-
- mUserField->setPosition(65, 5);
- mUserField->setWidth(width - 70);
- mPasswordField->setPosition(
- 65, mUserField->getY() + mUserField->getHeight() + 7);
- mPasswordField->setWidth(mUserField->getWidth());
- mConfirmField->setPosition(
- 65, mPasswordField->getY() + mPasswordField->getHeight() + 7);
- mConfirmField->setWidth(mUserField->getWidth());
- mServerField->setPosition(
- 65, 23 + mConfirmField->getY() + mConfirmField->getHeight() + 7);
- mServerField->setWidth(mUserField->getWidth());
-
- userLabel->setPosition(5, mUserField->getY() + 1);
- passwordLabel->setPosition(5, mPasswordField->getY() + 1);
- confirmLabel->setPosition(5, mConfirmField->getY() + 1);
- serverLabel->setPosition(5, mServerField->getY() + 1);
-
- mMaleButton->setPosition(
- 70, mConfirmField->getY() + mConfirmField->getHeight() + 7);
- mFemaleButton->setPosition(
- 70 + 10 + mMaleButton->getWidth(),
- mMaleButton->getY());
-
- mCancelButton->setPosition(
- width - mCancelButton->getWidth() - 5,
- height - mCancelButton->getHeight() - 5);
- mRegisterButton->setPosition(
- mCancelButton->getX() - mRegisterButton->getWidth() - 5,
- height - mRegisterButton->getHeight() - 5);
+ ContainerPlacer place;
+ place = getPlacer(0, 0);
+ place(0, 0, userLabel);
+ place(0, 1, passwordLabel);
+ place(0, 2, confirmLabel);
+ place(1, 3, mMaleButton);
+ place(2, 3, mFemaleButton);
+ place(0, 4, serverLabel);
+ place(1, 0, mUserField, 3).setPadding(2);
+ place(1, 1, mPasswordField, 3).setPadding(2);
+ place(1, 2, mConfirmField, 3).setPadding(2);
+ place(1, 4, mServerField, 3).setPadding(2);
+ place = getPlacer(0, 2);
+ place(1, 0, mRegisterButton);
+ place(2, 0, mCancelButton);
+ reflowLayout(250, 0);
mUserField->addKeyListener(this);
mPasswordField->addKeyListener(this);
@@ -128,19 +125,6 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mConfirmField->addActionListener(this);
mServerField->addActionListener(this);
- add(userLabel);
- add(passwordLabel);
- add(serverLabel);
- add(confirmLabel);
- add(mUserField);
- add(mPasswordField);
- add(mConfirmField);
- add(mServerField);
- add(mMaleButton);
- add(mFemaleButton);
- add(mRegisterButton);
- add(mCancelButton);
-
setLocationRelativeTo(getParent());
setVisible(true);
mUserField->requestFocus();
@@ -154,8 +138,7 @@ RegisterDialog::~RegisterDialog()
delete mWrongDataNoticeListener;
}
-void
-RegisterDialog::action(const gcn::ActionEvent &event)
+void RegisterDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "cancel")
{
@@ -244,14 +227,12 @@ RegisterDialog::action(const gcn::ActionEvent &event)
}
}
-void
-RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
mRegisterButton->setEnabled(canSubmit());
}
-bool
-RegisterDialog::canSubmit()
+bool RegisterDialog::canSubmit() const
{
return !mUserField->getText().empty() &&
!mPasswordField->getText().empty() &&
diff --git a/src/gui/register.h b/src/gui/register.h
index 771962cc..d696c686 100644
--- a/src/gui/register.h
+++ b/src/gui/register.h
@@ -31,19 +31,7 @@
class LoginData;
class OkDialog;
-
-/**
- * Listener used while dealing with wrong data. It is used to direct the focus
- * to the field which contained wrong data when the Ok button was pressed on
- * the error notice.
- */
-class WrongDataNoticeListener : public gcn::ActionListener {
- public:
- void setTarget(gcn::TextField *textField);
- void action(const gcn::ActionEvent &event);
- private:
- gcn::TextField *mTarget;
-};
+class WrongDataNoticeListener;
/**
* The registration dialog.
@@ -82,8 +70,7 @@ class RegisterDialog : public Window, public gcn::ActionListener,
* Returns whether submit can be enabled. This is true in the register
* state, when all necessary fields have some text.
*/
- bool
- canSubmit();
+ bool canSubmit() const;
gcn::TextField *mUserField;
gcn::TextField *mPasswordField;
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 51a5fac5..9fb38f13 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -287,7 +287,7 @@ void Setup_Video::apply()
* See http://libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode
*/
-#ifdef WIN32
+#if defined(WIN32) || defined(__APPLE__)
// checks for opengl usage
if (!(config.getValue("opengl", 0) == 1))
{
@@ -305,7 +305,7 @@ void Setup_Video::apply()
logger->error(error.str());
}
}
-#ifdef WIN32
+#if defined(WIN32) || defined(__APPLE__)
} else {
new OkDialog(_("Switching to full screen"),
_("Restart needed for changes to take effect."));
diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h
index e8617c7d..14203277 100644
--- a/src/gui/truetypefont.h
+++ b/src/gui/truetypefont.h
@@ -26,7 +26,11 @@
#include <guichan/font.hpp>
#include <guichan/graphics.hpp>
+#ifndef __APPLE__
#include <SDL/SDL_ttf.h>
+#else
+#include <SDL_ttf.h>
+#endif
/**
* A wrapper around SDL_ttf for allowing the use of TrueType fonts.
diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp
index b633835c..d8763f43 100644
--- a/src/net/npchandler.cpp
+++ b/src/net/npchandler.cpp
@@ -27,11 +27,15 @@
#include "../beingmanager.h"
#include "../npc.h"
+#include "../gui/npcintegerdialog.h"
#include "../gui/npclistdialog.h"
+#include "../gui/npcstringdialog.h"
#include "../gui/npc_text.h"
+extern NpcIntegerDialog *npcIntegerDialog;
extern NpcListDialog *npcListDialog;
extern NpcTextDialog *npcTextDialog;
+extern NpcStringDialog *npcStringDialog;
NPCHandler::NPCHandler()
{
@@ -40,6 +44,8 @@ NPCHandler::NPCHandler()
SMSG_NPC_MESSAGE,
SMSG_NPC_NEXT,
SMSG_NPC_CLOSE,
+ SMSG_NPC_INT_INPUT,
+ SMSG_NPC_STR_INPUT,
0
};
handledMessages = _messages;
@@ -78,5 +84,21 @@ void NPCHandler::handleMessage(MessageIn *msg)
case SMSG_NPC_NEXT:
// Next button in NPC dialog, currently unused
break;
+
+ case SMSG_NPC_INT_INPUT:
+ // Request for an integer
+ id = msg->readInt32();
+ current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id));
+ npcIntegerDialog->prepDialog(0, 0, 2147483647);
+ npcIntegerDialog->setVisible(true);
+ break;
+
+ case SMSG_NPC_STR_INPUT:
+ // Request for a string
+ id = msg->readInt32();
+ current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id));
+ npcStringDialog->setValue("");
+ npcStringDialog->setVisible(true);
+ break;
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index d7bdd041..f52aa794 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -75,6 +75,8 @@
#define SMSG_NPC_SELL 0x00c7
#define SMSG_NPC_BUY_RESPONSE 0x00ca
#define SMSG_NPC_SELL_RESPONSE 0x00cb
+#define SMSG_NPC_INT_INPUT 0x0142 /**< Integer input */
+#define SMSG_NPC_STR_INPUT 0x01d4 /**< String input */
#define SMSG_PLAYER_CHAT 0x008e /**< Player talks */
#define SMSG_WHISPER 0x0097 /**< Whisper Recieved */
#define SMSG_WHISPER_RESPONSE 0x0098
@@ -100,6 +102,8 @@
#define CMSG_NPC_LIST_CHOICE 0x00b8
#define CMSG_NPC_NEXT_REQUEST 0x00b9
#define CMSG_NPC_SELL_REQUEST 0x00c9
+#define CMSG_NPC_INT_RESPONSE 0x0143
+#define CMSG_NPC_STR_RESPONSE 0x01d5
#define CMSG_SKILL_LEVELUP_REQUEST 0x0112
#define CMSG_STAT_UPDATE_REQUEST 0x00bb
#define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8
diff --git a/src/npc.cpp b/src/npc.cpp
index 66048005..b107445a 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -80,14 +80,12 @@ void NPC::setName(const std::string &name)
gcn::Color(200, 200, 255));
}
-Being::Type
-NPC::getType() const
+Being::Type NPC::getType() const
{
return Being::NPC;
}
-void
-NPC::talk()
+void NPC::talk()
{
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_TALK);
@@ -96,16 +94,14 @@ NPC::talk()
current_npc = this;
}
-void
-NPC::nextDialog()
+void NPC::nextDialog()
{
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST);
outMsg.writeInt32(mId);
}
-void
-NPC::dialogChoice(char choice)
+void NPC::dialogChoice(char choice)
{
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_LIST_CHOICE);
@@ -113,12 +109,29 @@ NPC::dialogChoice(char choice)
outMsg.writeInt8(choice);
}
+void NPC::integerInput(int value)
+{
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_NPC_INT_RESPONSE);
+ outMsg.writeInt32(mId);
+ outMsg.writeInt32(value);
+}
+
+void NPC::stringInput(const std::string &value)
+{
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_NPC_STR_RESPONSE);
+ outMsg.writeInt16(value.length() + 8);
+ outMsg.writeInt32(mId);
+ outMsg.writeString(value, value.length());
+ outMsg.writeInt8(0); // Just to be safe
+}
+
/*
* TODO Unify the buy() and sell() methods, without sacrificing readability of
* the code calling the method. buy(bool buySell) would be bad...
*/
-void
-NPC::buy()
+void NPC::buy()
{
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST);
@@ -126,8 +139,7 @@ NPC::buy()
outMsg.writeInt8(0);
}
-void
-NPC::sell()
+void NPC::sell()
{
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST);
diff --git a/src/npc.h b/src/npc.h
index 5eb9036d..b463d5b0 100644
--- a/src/npc.h
+++ b/src/npc.h
@@ -43,6 +43,8 @@ class NPC : public Being
void talk();
void nextDialog();
void dialogChoice(char choice);
+ void integerInput(int value);
+ void stringInput(const std::string &value);
void buy();
void sell();