diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/event.cpp | 8 | ||||
-rw-r--r-- | src/event.h | 7 | ||||
-rw-r--r-- | src/gui/npcdialog.cpp | 33 | ||||
-rw-r--r-- | src/gui/npcdialog.h | 8 | ||||
-rw-r--r-- | src/net/manaserv/npchandler.cpp | 33 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 27 |
6 files changed, 13 insertions, 103 deletions
diff --git a/src/event.cpp b/src/event.cpp index 7c9b6f45..55782300 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -179,12 +179,8 @@ void Event::trigger(Channel channel, const Event &event) return; // Loop though all listeners - auto lit = it->second.begin(); - while (lit != it->second.end()) - { - (*lit)->event(channel, event); - lit++; - } + for (auto *listener : it->second) + listener->event(channel, event); } void Event::bind(EventListener *listener, Channel channel) diff --git a/src/event.h b/src/event.h index 5f053724..065fb7f6 100644 --- a/src/event.h +++ b/src/event.h @@ -64,7 +64,6 @@ public: Close, CloseAll, CloseDialog, - CloseSent, ConfigOptionChanged, Constructed, LoadingDatabases, @@ -86,25 +85,19 @@ public: GuiWindowsUnloaded, GuiWindowsUnloading, IntegerInput, - IntegerInputSent, MapLoaded, Menu, - MenuSent, Message, Next, - NextSent, NpcCount, Player, Post, PostCount, - SendLetterSent, ServerNotice, StateChange, StorageCount, StringInput, - StringInputSent, Stun, - TalkSent, UpdateAttribute, UpdateStat, UpdateStatusEffect, diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 376813f7..be076fc5 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -330,16 +330,9 @@ bool NpcDialog::isInputFocused() const bool NpcDialog::isAnyInputFocused() { - auto it = instances.begin(); - auto it_end = instances.end(); - - for (; it != it_end; it++) - { - if ((*it)->isInputFocused()) - { + for (auto dialog : instances) + if (dialog->isInputFocused()) return true; - } - } return false; } @@ -415,29 +408,17 @@ NpcDialog *NpcDialog::getActive() if (instances.size() == 1) return instances.front(); - auto it = instances.begin(); - auto it_end = instances.end(); - - for (; it != it_end; it++) - { - if ((*it)->isFocused()) - { - return (*it); - } - } + for (auto dialog : instances) + if (dialog->isFocused()) + return dialog; return nullptr; } void NpcDialog::closeAll() { - auto it = instances.begin(); - auto it_end = instances.end(); - - for (; it != it_end; it++) - { - (*it)->close(); - } + for (auto dialog : instances) + dialog->close(); } void NpcDialog::setup() diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index b902f044..42485766 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -46,10 +46,10 @@ class Button; * * \ingroup Interface */ -class NpcDialog : public Window, - public gcn::ActionListener, - public gcn::ListModel, - public EventListener +class NpcDialog final : public Window, + public gcn::ActionListener, + public gcn::ListModel, + public EventListener { public: NpcDialog(int npcId); diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index bd131d55..f19bf134 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -168,10 +168,6 @@ void NpcHandler::talk(int npcId) MessageOut msg(PGMSG_NPC_TALK); msg.writeInt16(npcId); gameServerConnection->send(msg); - - Event event(Event::TalkSent); - event.setInt("npcId", npcId); - event.trigger(Event::NpcChannel); } void NpcHandler::nextDialog(int npcId) @@ -179,10 +175,6 @@ void NpcHandler::nextDialog(int npcId) MessageOut msg(PGMSG_NPC_TALK_NEXT); msg.writeInt16(npcId); gameServerConnection->send(msg); - - Event event(Event::NextSent); - event.setInt("npcId", npcId); - event.trigger(Event::NpcChannel); } void NpcHandler::closeDialog(int npcId) @@ -190,10 +182,6 @@ void NpcHandler::closeDialog(int npcId) MessageOut msg(PGMSG_NPC_TALK_NEXT); msg.writeInt16(npcId); gameServerConnection->send(msg); - - Event event(Event::CloseSent); - event.setInt("npcId", npcId); - event.trigger(Event::NpcChannel); } void NpcHandler::menuSelect(int npcId, int choice) @@ -202,11 +190,6 @@ void NpcHandler::menuSelect(int npcId, int choice) msg.writeInt16(npcId); msg.writeInt8(choice); gameServerConnection->send(msg); - - Event event(Event::MenuSent); - event.setInt("npcId", npcId); - event.setInt("choice", choice); - event.trigger(Event::NpcChannel); } void NpcHandler::integerInput(int npcId, int value) @@ -215,11 +198,6 @@ void NpcHandler::integerInput(int npcId, int value) msg.writeInt16(npcId); msg.writeInt32(value); gameServerConnection->send(msg); - - Event event(Event::IntegerInputSent); - event.setInt("npcId", npcId); - event.setInt("value", value); - event.trigger(Event::NpcChannel); } void NpcHandler::stringInput(int npcId, const std::string &value) @@ -228,11 +206,6 @@ void NpcHandler::stringInput(int npcId, const std::string &value) msg.writeInt16(npcId); msg.writeString(value); gameServerConnection->send(msg); - - Event event(Event::StringInputSent); - event.setInt("npcId", npcId); - event.setString("value", value); - event.trigger(Event::NpcChannel); } void NpcHandler::sendLetter(int npcId, const std::string &recipient, @@ -242,12 +215,6 @@ void NpcHandler::sendLetter(int npcId, const std::string &recipient, msg.writeString(recipient); msg.writeString(text); gameServerConnection->send(msg); - - Event event(Event::SendLetterSent); - event.setInt("npcId", npcId); - event.setString("recipient", recipient); - event.setString("text", text); - event.trigger(Event::NpcChannel); } } // namespace ManaServ diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index aeb8cf95..54a3abe0 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -213,30 +213,18 @@ void NpcHandler::talk(int npcId) MessageOut outMsg(CMSG_NPC_TALK); outMsg.writeInt32(npcId); outMsg.writeInt8(0); // Unused - - Event event(Event::TalkSent); - event.setInt("npcId", npcId); - event.trigger(Event::NpcChannel); } void NpcHandler::nextDialog(int npcId) { MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(npcId); - - Event event(Event::NextSent); - event.setInt("npcId", npcId); - event.trigger(Event::NpcChannel); } void NpcHandler::closeDialog(int npcId) { MessageOut outMsg(CMSG_NPC_CLOSE); outMsg.writeInt32(npcId); - - Event event(Event::CloseSent); - event.setInt("npcId", npcId); - event.trigger(Event::NpcChannel); } void NpcHandler::menuSelect(int npcId, int choice) @@ -244,11 +232,6 @@ void NpcHandler::menuSelect(int npcId, int choice) MessageOut outMsg(CMSG_NPC_LIST_CHOICE); outMsg.writeInt32(npcId); outMsg.writeInt8(choice); - - Event event(Event::MenuSent); - event.setInt("npcId", npcId); - event.setInt("choice", choice); - event.trigger(Event::NpcChannel); } void NpcHandler::integerInput(int npcId, int value) @@ -256,11 +239,6 @@ void NpcHandler::integerInput(int npcId, int value) MessageOut outMsg(CMSG_NPC_INT_RESPONSE); outMsg.writeInt32(npcId); outMsg.writeInt32(value); - - Event event(Event::IntegerInputSent); - event.setInt("npcId", npcId); - event.setInt("value", value); - event.trigger(Event::NpcChannel); } void NpcHandler::stringInput(int npcId, const std::string &value) @@ -270,11 +248,6 @@ void NpcHandler::stringInput(int npcId, const std::string &value) outMsg.writeInt32(npcId); outMsg.writeString(value, value.length()); outMsg.writeInt8(0); // Prevent problems with string reading - - Event event(Event::StringInputSent); - event.setInt("npcId", npcId); - event.setString("value", value); - event.trigger(Event::NpcChannel); } void NpcHandler::sendLetter(int npcId, const std::string &recipient, |