From 5781d238e97689be482c5ac691143ce35e3e278e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 14 May 2014 15:36:21 +0300 Subject: Move playerlistener into separate file. --- src/listeners/playerlistener.cpp | 51 ++++++++++++++++++++++++++++++++++++ src/listeners/playerlistener.h | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/listeners/playerlistener.cpp create mode 100644 src/listeners/playerlistener.h (limited to 'src/listeners') diff --git a/src/listeners/playerlistener.cpp b/src/listeners/playerlistener.cpp new file mode 100644 index 000000000..d50aa20d9 --- /dev/null +++ b/src/listeners/playerlistener.cpp @@ -0,0 +1,51 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#include "listeners/playerlistener.h" + +#include "actormanager.h" + +#include "being/being.h" + +#include "gui/windows/textdialog.h" + +#include "debug.h" + +PlayerListener::PlayerListener() : + ActionListener(), + mNick(), + mDialog(nullptr), + mType(static_cast(ActorType::UNKNOWN)) +{ +} + +void PlayerListener::action(const ActionEvent &event) +{ + if (event.getId() == "ok" && !mNick.empty() && mDialog) + { + std::string comment = mDialog->getText(); + Being *const being = actorManager->findBeingByName( + mNick, static_cast(mType)); + if (being) + being->setComment(comment); + Being::saveComment(mNick, comment, mType); + } + mDialog = nullptr; +} diff --git a/src/listeners/playerlistener.h b/src/listeners/playerlistener.h new file mode 100644 index 000000000..85623fbd5 --- /dev/null +++ b/src/listeners/playerlistener.h @@ -0,0 +1,56 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef LISTENERS_PLAYERLISTENER_H +#define LISTENERS_PLAYERLISTENER_H + +#include "listeners/actionlistener.h" + +#include + +#include "localconsts.h" + +class TextDialog; + +class PlayerListener : public ActionListener +{ + public: + PlayerListener(); + + A_DELETE_COPY(PlayerListener) + + void action(const ActionEvent &event) override final; + + void setNick(const std::string &name) + { mNick = name; } + + void setDialog(TextDialog *const dialog) + { mDialog = dialog; } + + void setType(const int type) + { mType = type; } + + private: + std::string mNick; + TextDialog *mDialog; + int mType; +}; + +#endif // LISTENERS_PLAYERLISTENER_H -- cgit v1.2.3-60-g2f50