summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-09 12:56:02 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2006-03-09 12:56:02 +0000
commit8a9e607d36b9b22cfb22002a3bbeb1bf86810337 (patch)
tree032f20fff6f1371548d279c7cfad8e550ca75128 /src
parent76185faa619fd06576f2e67e1f2d5f1fb659e340 (diff)
downloadmana-client-8a9e607d36b9b22cfb22002a3bbeb1bf86810337.tar.gz
mana-client-8a9e607d36b9b22cfb22002a3bbeb1bf86810337.tar.bz2
mana-client-8a9e607d36b9b22cfb22002a3bbeb1bf86810337.tar.xz
mana-client-8a9e607d36b9b22cfb22002a3bbeb1bf86810337.zip
Made all local action listeners structs and moved them into anonymous namespaces.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp16
-rw-r--r--src/gui/connection.cpp20
-rw-r--r--src/gui/menuwindow.cpp18
-rw-r--r--src/main.cpp14
-rw-r--r--src/net/playerhandler.cpp26
-rw-r--r--src/net/tradehandler.cpp18
6 files changed, 53 insertions, 59 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 497cc903..a780c2d7 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -120,14 +120,16 @@ const int MAX_TIME = 10000;
/**
* Listener used for exitting handling.
*/
-class ExitListener : public gcn::ActionListener {
- void action(const std::string &eventId) {
- if (eventId == "yes") {
- done = true;
+namespace {
+ struct ExitListener : public gcn::ActionListener {
+ void action(const std::string &eventId) {
+ if (eventId == "yes") {
+ done = true;
+ }
+ exitConfirm = NULL;
}
- exitConfirm = NULL;
- }
-} exitListener;
+ } exitListener;
+}
/**
* Advances game logic counter.
diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp
index 89f145c4..4bd619ea 100644
--- a/src/gui/connection.cpp
+++ b/src/gui/connection.cpp
@@ -32,25 +32,19 @@
#include "../main.h"
-class ConnectionActionListener : public gcn::ActionListener
-{
- public:
- void action(const std::string& eventId)
- {
- if (eventId == "cancel")
- {
- state = EXIT_STATE;
- }
- }
-} connectionActionListener;
+namespace {
+ struct ConnectionActionListener : public gcn::ActionListener
+ {
+ void action(const std::string& eventId) { state = EXIT_STATE; }
+ } listener;
+}
ConnectionDialog::ConnectionDialog():
Window("Info"), mProgress(0)
{
setContentSize(200, 100);
- Button *cancelButton = new Button("Cancel", "cancelButton",
- &connectionActionListener);
+ Button *cancelButton = new Button("Cancel", "cancelButton", &listener);
mProgressBar = new ProgressBar(0.0, 200 - 10, 20, 128, 128, 128);
gcn::Label *label = new gcn::Label("Connecting...");
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index c18132cf..871a50d3 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -35,13 +35,15 @@ extern Graphics *graphics;
extern Window *setupWindow, *inventoryWindow, *equipmentWindow,
*skillDialog, *statusWindow;
-struct MenuWindowListener : public gcn::ActionListener
-{
- /**
- * Called when receiving actions from widget.
- */
- void action(const std::string& eventId);
-} menuWindowListener;
+namespace {
+ struct MenuWindowListener : public gcn::ActionListener
+ {
+ /**
+ * Called when receiving actions from widget.
+ */
+ void action(const std::string& eventId);
+ } listener;
+}
MenuWindow::MenuWindow():
Window("")
@@ -59,7 +61,7 @@ MenuWindow::MenuWindow():
int x = 0, y = 3, h = 0;
for (const char **curBtn = buttonNames; *curBtn; curBtn++) {
- gcn::Button *btn = new Button(*curBtn, *curBtn, &menuWindowListener);
+ gcn::Button *btn = new Button(*curBtn, *curBtn, &listener);
btn->setPosition(x, y);
add(btn);
x += btn->getWidth() + 3;
diff --git a/src/main.cpp b/src/main.cpp
index eba01d0f..ee0dad1b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -113,16 +113,12 @@ Uint32 nextFrame(Uint32 interval, void *param)
return interval;
}
-struct ErrorListener : public gcn::ActionListener
-{
- void action(const std::string& eventId)
+namespace {
+ struct ErrorListener : public gcn::ActionListener
{
- if (eventId == "ok")
- {
- state = LOGIN_STATE;
- }
- }
-} errorListener;
+ void action(const std::string& eventId) { state = LOGIN_STATE; }
+ } errorListener;
+}
/**
* Do all initialization stuff
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 02afc9db..070fb112 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -43,27 +43,25 @@ OkDialog *deathNotice = NULL;
* Listener used for handling the overweigth message.
*/
// TODO Move somewhere else
-class WeightNoticeListener : public gcn::ActionListener
-{
- public:
- void action(const std::string &eventId)
- {
- weightNotice = NULL;
- }
-} weightNoticeListener;
-
+namespace {
+ struct WeightListener : public gcn::ActionListener
+ {
+ void action(const std::string &eventId) { weightNotice = NULL; }
+ } weightListener;
+}
/**
* Listener used for handling death message.
*/
// TODO Move somewhere else
-class DeathNoticeListener : public gcn::ActionListener {
- public:
+namespace {
+ struct DeathListener : public gcn::ActionListener {
void action(const std::string &eventId) {
player_node->revive();
deathNotice = NULL;
}
-} deathNoticeListener;
+ } deathListener;
+}
PlayerHandler::PlayerHandler()
{
@@ -142,7 +140,7 @@ void PlayerHandler::handleMessage(MessageIn *msg)
"You are carrying more then half your "
"weight. You are unable to regain "
"health.");
- weightNotice->addActionListener(&weightNoticeListener);
+ weightNotice->addActionListener(&weightListener);
}
player_node->mTotalWeight = value;
break;
@@ -164,7 +162,7 @@ void PlayerHandler::handleMessage(MessageIn *msg)
{
deathNotice = new OkDialog("Message",
"You're now dead, press ok to restart");
- deathNotice->addActionListener(&deathNoticeListener);
+ deathNotice->addActionListener(&deathListener);
player_node->mAction = Being::DEAD;
}
}
diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp
index c3fd6d4b..5bce0574 100644
--- a/src/net/tradehandler.cpp
+++ b/src/net/tradehandler.cpp
@@ -38,13 +38,15 @@ std::string tradePartnerName;
/**
* Listener for request trade dialogs
*/
-struct RequestTradeListener : public gcn::ActionListener
-{
- void action(const std::string& eventId)
+namespace {
+ struct RequestTradeListener : public gcn::ActionListener
{
- player_node->tradeReply(eventId == "yes");
- };
-} requestTradeListener;
+ void action(const std::string& eventId)
+ {
+ player_node->tradeReply(eventId == "yes");
+ };
+ } listener;
+}
TradeHandler::TradeHandler()
{
@@ -77,14 +79,14 @@ void TradeHandler::handleMessage(MessageIn *msg)
player_node->tradeReply(false);
break;
}
-
+
player_node->setTrading(true);
tradePartnerName = msg->readString(24);
ConfirmDialog *dlg;
dlg = new ConfirmDialog("Request for trade",
tradePartnerName +
" wants to trade with you, do you accept?");
- dlg->addActionListener(&requestTradeListener);
+ dlg->addActionListener(&listener);
break;
case SMSG_TRADE_RESPONSE: