diff options
-rw-r--r-- | src/being.cpp | 22 | ||||
-rw-r--r-- | src/being.h | 5 | ||||
-rw-r--r-- | src/client.cpp | 25 | ||||
-rw-r--r-- | src/client.h | 6 | ||||
-rw-r--r-- | src/configlistener.h | 48 | ||||
-rw-r--r-- | src/configuration.cpp | 24 | ||||
-rw-r--r-- | src/configuration.h | 18 | ||||
-rw-r--r-- | src/event.h | 2 | ||||
-rw-r--r-- | src/gui/gui.cpp | 19 | ||||
-rw-r--r-- | src/gui/npcdialog.cpp | 11 | ||||
-rw-r--r-- | src/gui/npcdialog.h | 6 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 20 | ||||
-rw-r--r-- | src/gui/viewport.h | 8 | ||||
-rw-r--r-- | src/localplayer.cpp | 20 | ||||
-rw-r--r-- | src/localplayer.h | 5 | ||||
-rw-r--r-- | src/resources/theme.cpp | 12 | ||||
-rw-r--r-- | src/resources/theme.h | 6 |
17 files changed, 92 insertions, 165 deletions
diff --git a/src/being.cpp b/src/being.cpp index 47410620..d0442610 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -110,19 +110,16 @@ Being::Being(int id, Type type, int subtype, Map *map): if (getType() == PLAYER) mShowName = config.getBoolValue("visiblenames"); - config.addListener("visiblenames", this); - if (getType() == PLAYER || getType() == NPC) setShowName(true); updateColors(); + listen(CHANNEL_CONFIG); listen(CHANNEL_CHAT); } Being::~Being() { - config.removeListener("visiblenames", this); - delete mSpeechBubble; delete mDispName; delete mText; @@ -991,14 +988,6 @@ void Being::updateCoords() mDispName->adviseXY(getPixelX(), getPixelY()); } -void Being::optionChanged(const std::string &value) -{ - if (getType() == PLAYER && value == "visiblenames") - { - setShowName(config.getBoolValue("visiblenames")); - } -} - void Being::flashName(int time) { if (mDispName) @@ -1228,4 +1217,13 @@ void Being::event(Channels channel, const Mana::Event &event) catch (Mana::BadEvent badEvent) {} } + else if (channel == CHANNEL_CONFIG && + event.getName() == EVENT_CONFIGOPTIONCHANGED) + { + if (getType() == PLAYER && event.getString("option") == "visiblenames") + { + setShowName(config.getBoolValue("visiblenames")); + } + } + } diff --git a/src/being.h b/src/being.h index 60dca323..49995641 100644 --- a/src/being.h +++ b/src/being.h @@ -23,7 +23,6 @@ #define BEING_H #include "actorsprite.h" -#include "configlistener.h" #include "listener.h" #include "map.h" #include "particlecontainer.h" @@ -63,7 +62,7 @@ enum Gender GENDER_UNSPECIFIED = 2 }; -class Being : public ActorSprite, public ConfigListener, public Mana::Listener +class Being : public ActorSprite, public Mana::Listener { public: /** @@ -441,8 +440,6 @@ class Being : public ActorSprite, public ConfigListener, public Mana::Listener static void load(); - virtual void optionChanged(const std::string &value); - void flashName(int time); int getDamageTaken() const diff --git a/src/client.cpp b/src/client.cpp index d584d168..20d85ede 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -450,8 +450,13 @@ Client::Client(const Options &options): // Initialize frame limiting SDL_initFramerate(&mFpsManager); - config.addListener("fpslimit", this); - optionChanged("fpslimit"); + + listen(CHANNEL_CONFIG); + + //TODO: fix having to fake a option changed event + Mana::Event fakeevent(EVENT_CONFIGOPTIONCHANGED); + fakeevent.setString("option", "fpslimit"); + event(CHANNEL_CONFIG, fakeevent); // Initialize PlayerInfo PlayerInfo::init(); @@ -1022,12 +1027,18 @@ int Client::exec() return 0; } -void Client::optionChanged(const std::string &name) +void Client::event(Channels channel, const Mana::Event &event) { - const int fpsLimit = config.getIntValue("fpslimit"); - mLimitFps = fpsLimit > 0; - if (mLimitFps) - SDL_setFramerate(&mFpsManager, fpsLimit); + if (channel == CHANNEL_CONFIG && + event.getName() == EVENT_CONFIGOPTIONCHANGED && + event.getString("option") == "fpslimit") + { + const int fpsLimit = config.getIntValue("fpslimit"); + mLimitFps = fpsLimit > 0; + if (mLimitFps) + SDL_setFramerate(&mFpsManager, fpsLimit); + } + } void Client::action(const gcn::ActionEvent &event) diff --git a/src/client.h b/src/client.h index 429deb34..8d2c23d5 100644 --- a/src/client.h +++ b/src/client.h @@ -22,7 +22,7 @@ #ifndef CLIENT_H #define CLIENT_H -#include "configlistener.h" +#include "listener.h" #include "net/serverinfo.h" @@ -119,7 +119,7 @@ enum State { * The core part of the client. This class initializes all subsystems, runs * the event loop, and shuts everything down again. */ -class Client : public ConfigListener, public gcn::ActionListener +class Client : public Mana::Listener, public gcn::ActionListener { public: /** @@ -185,7 +185,7 @@ public: static const std::string &getScreenshotDirectory() { return instance()->mScreenshotDir; } - void optionChanged(const std::string &name); + void event(Channels channel, const Mana::Event &event); void action(const gcn::ActionEvent &event); private: diff --git a/src/configlistener.h b/src/configlistener.h deleted file mode 100644 index 923b3115..00000000 --- a/src/configlistener.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * - * This file is part of The Mana 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 <http://www.gnu.org/licenses/>. - */ - -#ifndef CONFIGLISTENER_H -#define CONFIGLISTENER_H - -#include <string> - -/** - * The listener interface for receiving notifications about changes to - * configuration options. - * - * \ingroup CORE - */ -class ConfigListener -{ - public: - /** - * Destructor. - */ - virtual ~ConfigListener() {} - - /** - * Called when an option changed. The config listener will have to be - * registered to the option name first. - */ - virtual void optionChanged(const std::string &name) = 0; -}; - -#endif diff --git a/src/configuration.cpp b/src/configuration.cpp index 50d76bfb..44fb6e2e 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -21,7 +21,7 @@ #include "configuration.h" -#include "configlistener.h" +#include "event.h" #include "log.h" #include "utils/stringutils.h" @@ -38,13 +38,9 @@ void Configuration::setValue(const std::string &key, const std::string &value) ConfigurationObject::setValue(key, value); // Notify listeners - ListenerMapIterator list = mListenerMap.find(key); - if (list != mListenerMap.end()) - { - Listeners listeners = list->second; - for (ListenerIterator i = listeners.begin(); i != listeners.end(); i++) - (*i)->optionChanged(key); - } + Mana::Event event(EVENT_CONFIGOPTIONCHANGED); + event.setString("option", key); + event.trigger(CHANNEL_CONFIG); } std::string ConfigurationObject::getValue(const std::string &key, @@ -358,15 +354,3 @@ void Configuration::write() xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); } - -void Configuration::addListener(const std::string &key, - ConfigListener *listener) -{ - mListenerMap[key].push_front(listener); -} - -void Configuration::removeListener(const std::string &key, - ConfigListener *listener) -{ - mListenerMap[key].remove(listener); -} diff --git a/src/configuration.h b/src/configuration.h index 451b55a3..a46b0718 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -32,7 +32,6 @@ #include <map> #include <string> -class ConfigListener; class ConfigurationObject; /** @@ -215,17 +214,6 @@ class Configuration : public ConfigurationObject */ void write(); - /** - * Adds a listener to the listen list of the specified config option. - */ - void addListener(const std::string &key, ConfigListener *listener); - - /** - * Removes a listener from the listen list of the specified config - * option. - */ - void removeListener(const std::string &key, ConfigListener *listener); - void setValue(const std::string &key, const std::string &value); inline void setValue(const std::string &key, const char *value) @@ -267,12 +255,6 @@ class Configuration : public ConfigurationObject */ void cleanDefaults(); - typedef std::list<ConfigListener*> Listeners; - typedef Listeners::iterator ListenerIterator; - typedef std::map<std::string, Listeners> ListenerMap; - typedef ListenerMap::iterator ListenerMapIterator; - ListenerMap mListenerMap; - std::string mConfigPath; /**< Location of config file */ DefaultsData *mDefaultsData; /**< Defaults of value for a given key */ }; diff --git a/src/event.h b/src/event.h index 4264232f..758d6b34 100644 --- a/src/event.h +++ b/src/event.h @@ -35,6 +35,7 @@ enum Channels CHANNEL_BUYSELL, CHANNEL_CHAT, CHANNEL_CLIENT, + CHANNEL_CONFIG, CHANNEL_GAME, CHANNEL_ITEM, CHANNEL_NOTICES, @@ -50,6 +51,7 @@ enum Events EVENT_CLOSE, EVENT_CLOSEALL, EVENT_CLOSESENT, + EVENT_CONFIGOPTIONCHANGED, EVENT_CONSTRUCTED, EVENT_DBSLOADING, EVENT_DESTROYED, diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index c8568b0f..c0d1babf 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -29,8 +29,8 @@ #include "gui/widgets/window.h" #include "gui/widgets/windowcontainer.h" -#include "configlistener.h" #include "configuration.h" +#include "listener.h" #include "graphics.h" #include "log.h" @@ -50,19 +50,23 @@ SDLInput *guiInput = 0; // Bolded font gcn::Font *boldFont = 0; -class GuiConfigListener : public ConfigListener +class GuiConfigListener : public Mana::Listener { public: GuiConfigListener(Gui *g): mGui(g) {} - void optionChanged(const std::string &name) + void event(Channels channel, const Mana::Event &event) { - if (name == "customcursor") + if (channel == CHANNEL_CONFIG) { - bool bCustomCursor = config.getBoolValue("customcursor"); - mGui->setUseCustomCursor(bCustomCursor); + if (event.getName() == EVENT_CONFIGOPTIONCHANGED && + event.getString("option") == "customcursor") + { + bool bCustomCursor = config.getBoolValue("customcursor"); + mGui->setUseCustomCursor(bCustomCursor); + } } } private: @@ -137,12 +141,11 @@ Gui::Gui(Graphics *graphics): // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getBoolValue("customcursor")); mConfigListener = new GuiConfigListener(this); - config.addListener("customcursor", mConfigListener); + mConfigListener->listen(CHANNEL_CONFIG); } Gui::~Gui() { - config.removeListener("customcursor", mConfigListener); delete mConfigListener; if (mMouseCursors) diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 5b1939a6..1a5186ff 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -143,7 +143,7 @@ NpcDialog::NpcDialog(int npcId) setVisible(true); requestFocus(); - config.addListener("logNpcInGui", this); + listen(CHANNEL_CONFIG); PlayerInfo::setNPCInteractionCount(PlayerInfo::getNPCInteractionCount() + 1); } @@ -161,7 +161,6 @@ NpcDialog::~NpcDialog() instances.remove(this); - config.removeListener("logNpcInGui", this); PlayerInfo::setNPCInteractionCount(PlayerInfo::getNPCInteractionCount() - 1); @@ -383,9 +382,13 @@ void NpcDialog::setVisible(bool visible) } } -void NpcDialog::optionChanged(const std::string &name) +void NpcDialog::event(Channels channel, const Mana::Event &event) { - if (name == "logNpcInGui") + if (channel != CHANNEL_CONFIG) + return; + + if (event.getName() == EVENT_CONFIGOPTIONCHANGED && + event.getString("option") == "logNpcInGui") { mLogInteraction = config.getBoolValue("logNpcInGui"); } diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index 5850ecca..1906d725 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -22,7 +22,7 @@ #ifndef NPCDIALOG_H #define NPCDIALOG_H -#include "configlistener.h" +#include "listener.h" #include "gui/widgets/window.h" @@ -45,7 +45,7 @@ class Button; * \ingroup Interface */ class NpcDialog : public Window, public gcn::ActionListener, - public gcn::ListModel, public ConfigListener + public gcn::ListModel, public Mana::Listener { public: /** @@ -143,7 +143,7 @@ class NpcDialog : public Window, public gcn::ActionListener, void setVisible(bool visible); - void optionChanged(const std::string &name); + void event(Channels channel, const Mana::Event &event); /** * Returns the first active instance. Useful for pushing user diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 4152bd95..ac910d5f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -64,14 +64,12 @@ Viewport::Viewport(): mScrollCenterOffsetX = config.getIntValue("ScrollCenterOffsetX"); mScrollCenterOffsetY = config.getIntValue("ScrollCenterOffsetY"); - config.addListener("ScrollLaziness", this); - config.addListener("ScrollRadius", this); - mPopupMenu = new PopupMenu; mBeingPopup = new BeingPopup; setFocusable(true); + listen(CHANNEL_CONFIG); listen(CHANNEL_ACTORSPRITE); } @@ -485,12 +483,6 @@ void Viewport::closePopupMenu() mPopupMenu->handleLink("cancel"); } -void Viewport::optionChanged(const std::string &name) -{ - mScrollLaziness = config.getIntValue("ScrollLaziness"); - mScrollRadius = config.getIntValue("ScrollRadius"); -} - void Viewport::mouseMoved(gcn::MouseEvent &event) { // Check if we are on the map @@ -568,4 +560,14 @@ void Viewport::event(Channels channel, const Mana::Event &event) if (mHoverItem == actor) mHoverItem = 0; } + else if (channel == CHANNEL_CONFIG && + event.getName() == EVENT_CONFIGOPTIONCHANGED) + { + const std::string option = event.getString("option"); + if (option == "ScrollLaziness" || option == "ScrollRadius") + { + mScrollLaziness = config.getIntValue("ScrollLaziness"); + mScrollRadius = config.getIntValue("ScrollRadius"); + } + } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 9fbdf496..3b449371 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -23,7 +23,6 @@ #define VIEWPORT_H #include "actorspritemanager.h" -#include "configlistener.h" #include "listener.h" #include "position.h" @@ -54,7 +53,7 @@ const int walkingMouseDelay = 500; * coordinates. */ class Viewport : public WindowContainer, public gcn::MouseListener, - public ConfigListener, public Mana::Listener + public Mana::Listener { public: /** @@ -121,11 +120,6 @@ class Viewport : public WindowContainer, public gcn::MouseListener, void closePopupMenu(); /** - * A relevant config option changed. - */ - void optionChanged(const std::string &name); - - /** * Returns camera x offset in pixels. */ int getCameraX() const { return (int) mPixelViewX; } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 79f814a3..4aec2399 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -91,15 +91,14 @@ LocalPlayer::LocalPlayer(int id, int subtype): mUpdateName = true; - config.addListener("showownname", this); setShowName(config.getValue("showownname", 1)); + listen(CHANNEL_CONFIG); listen(CHANNEL_ACTORSPRITE); } LocalPlayer::~LocalPlayer() { - config.removeListener("showownname", this); } void LocalPlayer::logic() @@ -1076,14 +1075,6 @@ void LocalPlayer::addMessageToQueue(const std::string &message, int color) mMessages.push_back(MessagePair(message, color)); } -void LocalPlayer::optionChanged(const std::string &value) -{ - if (value == "showownname") - { - setShowName(config.getValue("showownname", 1)); - } -} - void LocalPlayer::event(Channels channel, const Mana::Event &event) { if (channel == CHANNEL_ACTORSPRITE) @@ -1112,6 +1103,15 @@ void LocalPlayer::event(Channels channel, const Mana::Event &event) } } } + else if (channel == CHANNEL_CONFIG) + { + if (event.getName() == EVENT_CONFIGOPTIONCHANGED && + event.getString("option") == "showownname") + { + setShowName(config.getValue("showownname", 1)); + } + + } Being::event(channel, event); } diff --git a/src/localplayer.h b/src/localplayer.h index 984e3c75..334a2598 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -181,11 +181,6 @@ class LocalPlayer : public Being void addMessageToQueue(const std::string &message, int color = UserPalette::EXP_INFO); - /** - * Called when a option (set with config.addListener()) is changed - */ - void optionChanged(const std::string &value); - void event(Channels channel, const Mana::Event &event); /** diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index aa28af36..8de275ae 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -111,7 +111,7 @@ Theme::Theme(): { initDefaultThemePath(); - config.addListener("guialpha", this); + listen(CHANNEL_CONFIG); loadColors(); mColors[HIGHLIGHT].ch = 'H'; @@ -130,7 +130,6 @@ Theme::Theme(): Theme::~Theme() { delete_all(mSkins); - config.removeListener("guialpha", this); delete_all(mProgressColors); } @@ -209,9 +208,14 @@ void Theme::updateAlpha() iter->second->updateAlpha(mMinimumOpacity); } -void Theme::optionChanged(const std::string &) +void Theme::event(Channels channel, const Mana::Event &event) { - updateAlpha(); + if (channel == CHANNEL_CONFIG && + event.getName() == EVENT_CONFIGOPTIONCHANGED && + event.getString("option") == "guialpha") + { + updateAlpha(); + } } Skin *Theme::readSkin(const std::string &filename) diff --git a/src/resources/theme.h b/src/resources/theme.h index 3a5aa41a..f830c94f 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -24,8 +24,8 @@ #ifndef SKIN_H #define SKIN_H -#include "configlistener.h" #include "graphics.h" +#include "listener.h" #include "gui/palette.h" @@ -100,7 +100,7 @@ class Skin Image *mStickyImageDown; /**< Sticky Button Image */ }; -class Theme : public Palette, public ConfigListener +class Theme : public Palette, public Mana::Listener { public: static Theme *instance(); @@ -218,7 +218,7 @@ class Theme : public Palette, public ConfigListener */ void setMinimumOpacity(float minimumOpacity); - void optionChanged(const std::string &); + void event(Channels channel, const Mana::Event &event); private: Theme(); |