summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/game.cpp4
-rw-r--r--src/gui/buysell.cpp2
-rw-r--r--src/gui/char_select.cpp4
-rw-r--r--src/gui/confirm_dialog.cpp13
-rw-r--r--src/gui/confirm_dialog.h4
-rw-r--r--src/gui/login.cpp12
-rw-r--r--src/gui/login.h5
-rw-r--r--src/gui/menuwindow.cpp10
-rw-r--r--src/gui/ok_dialog.cpp12
-rw-r--r--src/gui/ok_dialog.h4
-rw-r--r--src/gui/register.cpp4
-rw-r--r--src/gui/requesttrade.cpp39
-rw-r--r--src/gui/requesttrade.h45
-rw-r--r--src/gui/setup.cpp6
-rw-r--r--src/net/playerhandler.cpp8
-rw-r--r--src/net/tradehandler.cpp18
17 files changed, 66 insertions, 126 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 947c76b9..a5d8b6bf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,8 +79,6 @@ tmw_SOURCES = graphic/spriteset.cpp \
gui/radiobutton.h \
gui/register.cpp \
gui/register.h \
- gui/requesttrade.cpp \
- gui/requesttrade.h \
gui/scrollarea.cpp \
gui/scrollarea.h \
gui/sell.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 2387a041..99a83ba0 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -562,8 +562,8 @@ void do_input(Network *network)
case SDLK_ESCAPE:
if (!exitConfirm) {
exitConfirm = new ConfirmDialog(
- "Quit", "Are you sure you want to quit?",
- (gcn::ActionListener*)&exitListener);
+ "Quit", "Are you sure you want to quit?");
+ exitConfirm->addActionListener(&exitListener);
}
exitConfirm->requestMoveToTop();
break;
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index f443e237..ccd82db5 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -34,7 +34,7 @@ BuySellDialog::BuySellDialog():
char *buttonNames[] = {
"Buy", "Sell", "Cancel", 0
};
- int x = 10, y = 10, h;
+ int x = 10, y = 10;
for (char **curBtn = buttonNames; *curBtn; curBtn++)
{
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index e3f4766e..c54481f4 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -54,7 +54,7 @@ class CharDeleteConfirm : public ConfirmDialog
CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m):
ConfirmDialog("Confirm", "Are you sure you want to delete this character?",
- NULL, m),
+ m),
master(m)
{
}
@@ -319,7 +319,7 @@ void CharCreateDialog::action(const std::string& eventId)
}
else {
new OkDialog("Error",
- "Your name needs to be at least 4 characters.", NULL, this);
+ "Your name needs to be at least 4 characters.", this);
}
}
else if (eventId == "cancel") {
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index 2babbf23..becb8859 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -29,7 +29,7 @@
ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
- gcn::ActionListener *listener, Window *parent):
+ Window *parent):
Window(title, true, parent)
{
gcn::Label *textLabel = new gcn::Label(msg);
@@ -57,10 +57,6 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
noButton->setEventId("no");
yesButton->addActionListener(this);
noButton->addActionListener(this);
- if (listener) {
- yesButton->addActionListener(listener);
- noButton->addActionListener(listener);
- }
add(textLabel);
add(yesButton);
@@ -75,6 +71,13 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
void ConfirmDialog::action(const std::string &eventId)
{
+ // Proxy button events to our listeners
+ ActionListenerIterator i;
+ for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
+ {
+ (*i)->action(eventId);
+ }
+
// Can we receive anything else anyway?
if (eventId == "yes" || eventId == "no") {
scheduleDelete();
diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h
index e3638439..3a05494f 100644
--- a/src/gui/confirm_dialog.h
+++ b/src/gui/confirm_dialog.h
@@ -28,8 +28,6 @@
#include "window.h"
-#include "../guichanfwd.h"
-
/**
* An option dialog.
@@ -44,7 +42,7 @@ class ConfirmDialog : public Window, public gcn::ActionListener {
* @see Window::Window
*/
ConfirmDialog(const std::string &title, const std::string &msg,
- gcn::ActionListener *listener = NULL, Window *parent = NULL);
+ Window *parent = NULL);
/**
* Called when receiving actions from the widgets.
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 836c1c14..e3828af7 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -133,7 +133,12 @@ LoginDialog::LoginDialog(LoginData *loginData):
serverField->setText(config.getValue("host", ""));
- wrongDataNoticeListener = NULL;
+ wrongDataNoticeListener = new WrongDataNoticeListener();
+}
+
+LoginDialog::~LoginDialog()
+{
+ delete wrongDataNoticeListener;
}
void
@@ -160,10 +165,9 @@ LoginDialog::action(const std::string& eventId)
// Check login
if (user.length() == 0)
{
- wrongDataNoticeListener = new WrongDataNoticeListener();
wrongDataNoticeListener->setTarget(this->passField);
- new OkDialog("Error", "Enter your username first",
- wrongDataNoticeListener);
+ OkDialog *dlg = new OkDialog("Error", "Enter your username first");
+ dlg->addActionListener(wrongDataNoticeListener);
}
else
{
diff --git a/src/gui/login.h b/src/gui/login.h
index 669752c5..b096d05f 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -58,6 +58,11 @@ class LoginDialog : public Window, public gcn::ActionListener {
LoginDialog(LoginData *loginData);
/**
+ * Destructor
+ */
+ ~LoginDialog();
+
+ /**
* Called when receiving actions from the widgets.
*/
void action(const std::string& eventId);
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index b243cd57..cb5fc654 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -35,12 +35,12 @@ extern Graphics *graphics;
extern Window *setupWindow, *inventoryWindow, *equipmentWindow,
*skillDialog, *statusWindow;
-class MenuWindowListener : public gcn::ActionListener
+struct MenuWindowListener : public gcn::ActionListener
{
- /**
- * Called when receiving actions from widget.
- */
- void action(const std::string& eventId);
+ /**
+ * Called when receiving actions from widget.
+ */
+ void action(const std::string& eventId);
} menuWindowListener;
MenuWindow::MenuWindow():
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index 2e2594d1..8d2ebc23 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -29,7 +29,7 @@
OkDialog::OkDialog(const std::string &title, const std::string &msg,
- gcn::ActionListener *listener, Window *parent):
+ Window *parent):
Window(title, true, parent)
{
gcn::Label *textLabel = new gcn::Label(msg);
@@ -49,9 +49,6 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
okButton->setEventId("ok");
okButton->addActionListener(this);
- if (listener) {
- okButton->addActionListener(listener);
- }
add(textLabel);
add(okButton);
@@ -62,6 +59,13 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
void OkDialog::action(const std::string &eventId)
{
+ // Proxy button events to our listeners
+ ActionListenerIterator i;
+ for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
+ {
+ (*i)->action(eventId);
+ }
+
// Can we receive anything else anyway?
if (eventId == "ok") {
scheduleDelete();
diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h
index 4eac77de..eb0da2c0 100644
--- a/src/gui/ok_dialog.h
+++ b/src/gui/ok_dialog.h
@@ -28,8 +28,6 @@
#include "window.h"
-#include "../guichanfwd.h"
-
/**
* An 'Ok' button dialog.
*
@@ -43,7 +41,7 @@ class OkDialog : public Window, public gcn::ActionListener {
* @see Window::Window
*/
OkDialog(const std::string &title, const std::string &msg,
- gcn::ActionListener *listener = NULL, Window *parent = NULL);
+ Window *parent = NULL);
/**
* Called when receiving actions from the widgets.
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index 9b4cf79d..a22d1f73 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -208,8 +208,8 @@ RegisterDialog::action(const std::string& eventId)
delete wrongRegisterNotice;
wrongRegisterNotice = NULL;
}
- wrongRegisterNotice = new OkDialog("Error", errorMsg.str(),
- wrongDataNoticeListener);
+ wrongRegisterNotice = new OkDialog("Error", errorMsg.str());
+ wrongRegisterNotice->addActionListener(wrongDataNoticeListener);
}
else
{
diff --git a/src/gui/requesttrade.cpp b/src/gui/requesttrade.cpp
deleted file mode 100644
index 9d61e860..00000000
--- a/src/gui/requesttrade.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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
- *
- * $Id$
- */
-
-#include "requesttrade.h"
-
-#include "../localplayer.h"
-
-struct RequestTradeListener : public gcn::ActionListener
-{
- void action(const std::string& eventId)
- {
- player_node->tradeReply(eventId == "yes");
- };
-} requestTradeListener;
-
-RequestTradeDialog::RequestTradeDialog(const std::string &name):
- ConfirmDialog("Request for Trade", name + " wants to trade with you, do you accept?", &requestTradeListener)
-{
-}
diff --git a/src/gui/requesttrade.h b/src/gui/requesttrade.h
deleted file mode 100644
index 5aa41ddb..00000000
--- a/src/gui/requesttrade.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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
- *
- * $Id$
- */
-
-#ifndef _TMW_REQUESTTRADE_
-#define _TMW_REQUESTTRADE_
-
-#include "confirm_dialog.h"
-
-/**
- * The request trade dialog.
- *
- * \ingroup Interface
- */
-class RequestTradeDialog : public ConfirmDialog
-{
- public:
- /**
- * Constructor.
- *
- * @see Window::Window
- */
- RequestTradeDialog(const std::string &name);
-};
-
-#endif
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 15ef9092..c47d12da 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -316,7 +316,7 @@ void Setup::action(const std::string &eventId)
}
} else {
new OkDialog("Switching to FullScreen",
- "Restart needed for changes to take effect.", NULL, this);
+ "Restart needed for changes to take effect.", this);
}
config.setValue("screen", fullscreen ? 1 : 0);
}
@@ -330,7 +330,7 @@ void Setup::action(const std::string &eventId)
}
catch (const char *err)
{
- new OkDialog("Sound Engine", err, NULL, this);
+ new OkDialog("Sound Engine", err, this);
logger->log("Warning: %s", err);
}
}
@@ -347,7 +347,7 @@ void Setup::action(const std::string &eventId)
// OpenGL can currently only be changed by restarting, notify user.
new OkDialog("Changing OpenGL",
- "Applying change to OpenGL requires restart.", NULL, this);
+ "Applying change to OpenGL requires restart.", this);
}
// We sync old and new values at apply time
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 1a255e0b..7bf97b5f 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -141,8 +141,8 @@ void PlayerHandler::handleMessage(MessageIn *msg)
weightNotice = new OkDialog("Message",
"You are carrying more then half your "
"weight. You are unable to regain "
- "health.",
- &weightNoticeListener);
+ "health.");
+ weightNotice->addActionListener(&weightNoticeListener);
}
player_node->totalWeight = value;
break;
@@ -163,8 +163,8 @@ void PlayerHandler::handleMessage(MessageIn *msg)
if (player_node->hp == 0 && deathNotice == NULL)
{
deathNotice = new OkDialog("Message",
- "You're now dead, press ok to restart",
- &deathNoticeListener);
+ "You're now dead, press ok to restart");
+ deathNotice->addActionListener(&deathNoticeListener);
player_node->action = Being::DEAD;
}
}
diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp
index 6ed3bab2..5675fab8 100644
--- a/src/net/tradehandler.cpp
+++ b/src/net/tradehandler.cpp
@@ -30,11 +30,22 @@
#include "../localplayer.h"
#include "../gui/chat.h"
-#include "../gui/requesttrade.h"
+#include "../gui/confirm_dialog.h"
#include "../gui/trade.h"
std::string tradePartnerName;
+/**
+ * Listener for request trade dialogs
+ */
+struct RequestTradeListener : public gcn::ActionListener
+{
+ void action(const std::string& eventId)
+ {
+ player_node->tradeReply(eventId == "yes");
+ };
+} requestTradeListener;
+
TradeHandler::TradeHandler()
{
static const Uint16 _messages[] = {
@@ -69,7 +80,10 @@ void TradeHandler::handleMessage(MessageIn *msg)
player_node->setTrading(true);
tradePartnerName = msg->readString(24);
- new RequestTradeDialog(tradePartnerName);
+ ConfirmDialog *dlg = new ConfirmDialog("Request for trade",
+ tradePartnerName +
+ " wants to trade with you, do you accept?");
+ dlg->addActionListener(&requestTradeListener);
break;
case SMSG_TRADE_RESPONSE: