diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 12 | ||||
-rw-r--r-- | src/being.h | 2 | ||||
-rw-r--r-- | src/event.cpp | 20 | ||||
-rw-r--r-- | src/event.h | 4 | ||||
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | src/gui/buy.cpp | 6 | ||||
-rw-r--r-- | src/gui/buy.h | 5 | ||||
-rw-r--r-- | src/gui/buysell.cpp | 7 | ||||
-rw-r--r-- | src/gui/buysell.h | 5 | ||||
-rw-r--r-- | src/gui/sell.cpp | 6 | ||||
-rw-r--r-- | src/gui/sell.h | 5 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 3 | ||||
-rw-r--r-- | src/net/tmwa/buysellhandler.cpp | 2 | ||||
-rw-r--r-- | src/playerinfo.cpp | 80 | ||||
-rw-r--r-- | src/playerinfo.h | 46 |
15 files changed, 140 insertions, 65 deletions
diff --git a/src/being.cpp b/src/being.cpp index 22fb9610..280a5a1b 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -39,12 +39,7 @@ #include "text.h" #include "statuseffect.h" -#include "gui/buy.h" -#include "gui/buysell.h" #include "gui/gui.h" -#include "gui/npcdialog.h" -#include "gui/npcpostdialog.h" -#include "gui/sell.h" #include "gui/socialwindow.h" #include "gui/speechbubble.h" #include "gui/theme.h" @@ -1203,10 +1198,3 @@ void Being::talkTo() { Net::getNpcHandler()->talk(mId); } - -bool Being::isTalking() -{ - return NpcDialog::isActive() || BuyDialog::isActive() || - SellDialog::isActive() || BuySellDialog::isActive() || - NpcPostDialog::isActive(); -} diff --git a/src/being.h b/src/being.h index 07826a11..a379bdaa 100644 --- a/src/being.h +++ b/src/being.h @@ -493,8 +493,6 @@ class Being : public ActorSprite, public ConfigListener void talkTo(); - static bool isTalking(); - protected: /** * Sets the new path for this being. diff --git a/src/event.cpp b/src/event.cpp index 65fdee8a..d503ad58 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -96,4 +96,24 @@ double Event::getFloat(const std::string &key) const throw (BadEvent) return static_cast<FloatData *>(it->second)->getData(); } +void Event::setBool(const std::string &key, bool value) throw (BadEvent) +{ + if (mData.find(key) != mData.end()) + throw KEY_ALREADY_EXISTS; + + mData[key] = new BoolData(value); +} + +bool Event::getBool(const std::string &key) const throw (BadEvent) +{ + VariableMap::const_iterator it = mData.find(key); + if (it == mData.end()) + throw BAD_KEY; + + if (it->second->getType() != VariableData::DATA_BOOL) + throw BAD_VALUE; + + return static_cast<BoolData *>(it->second)->getData(); +} + } // namespace Mana diff --git a/src/event.h b/src/event.h index 03751739..1e057a05 100644 --- a/src/event.h +++ b/src/event.h @@ -63,6 +63,10 @@ public: void setFloat(const std::string &key, double value) throw (BadEvent); double getFloat(const std::string &key) const throw (BadEvent); + // Sets or gets a boolean with key to identify + void setBool(const std::string &key, bool value) throw (BadEvent); + bool getBool(const std::string &key) const throw (BadEvent); + private: std::string mEventName; diff --git a/src/game.cpp b/src/game.cpp index 148c3784..0c765f9e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -758,7 +758,7 @@ void Game::handleInput() return; // Moving player around - if (player_node->isAlive() && !Being::isTalking() && + if (player_node->isAlive() && !PlayerInfo::isTalking() && !chatWindow->isInputFocused() && !quitDialog) { // Get the state of the keyboard keys diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index a214c075..cc135e07 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -21,6 +21,7 @@ #include "gui/buy.h" +#include "playerinfo.h" #include "shopitem.h" #include "units.h" @@ -111,6 +112,8 @@ BuyDialog::BuyDialog(int npcId): instances.push_back(this); setVisible(true); + + PlayerInfo::setBuySellState(BUYSELL_BUYING); } BuyDialog::~BuyDialog() @@ -118,6 +121,9 @@ BuyDialog::~BuyDialog() delete mShopItems; instances.remove(this); + + if (PlayerInfo::getBuySellState() == BUYSELL_BUYING) + PlayerInfo::setBuySellState(BUYSELL_NONE); } void BuyDialog::setMoney(int amount) diff --git a/src/gui/buy.h b/src/gui/buy.h index 4b273bcc..c3cb3229 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -100,11 +100,6 @@ class BuyDialog : public Window, public gcn::ActionListener, void setVisible(bool visible); /** - * Returns true if any instances exist. - */ - static bool isActive() { return instances.size() > 0; } - - /** * Closes all instances. */ static void closeAll(); diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 3e810a4a..4419ffcc 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -21,6 +21,8 @@ #include "buysell.h" +#include "playerinfo.h" + #include "gui/setup.h" #include "gui/widgets/button.h" @@ -65,11 +67,16 @@ BuySellDialog::BuySellDialog(int npcId): instances.push_back(this); setVisible(true); + + PlayerInfo::setBuySellState(BUYSELL_CHOOSING); } BuySellDialog::~BuySellDialog() { instances.remove(this); + + if (PlayerInfo::getBuySellState() == BUYSELL_CHOOSING) + PlayerInfo::setBuySellState(BUYSELL_NONE); } void BuySellDialog::setVisible(bool visible) diff --git a/src/gui/buysell.h b/src/gui/buysell.h index cf7ec91e..3408821a 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -52,11 +52,6 @@ class BuySellDialog : public Window, public gcn::ActionListener void action(const gcn::ActionEvent &event); /** - * Returns true if any instances exist. - */ - static bool isActive() { return instances.size() > 0; } - - /** * Closes all instances. */ static void closeAll(); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b017983c..83f01d7f 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,6 +21,7 @@ #include "gui/sell.h" +#include "playerinfo.h" #include "shopitem.h" #include "units.h" @@ -110,6 +111,8 @@ SellDialog::SellDialog(int npcId): instances.push_back(this); setVisible(true); + + PlayerInfo::setBuySellState(BUYSELL_SELLING); } SellDialog::~SellDialog() @@ -117,6 +120,9 @@ SellDialog::~SellDialog() delete mShopItems; instances.remove(this); + + if (PlayerInfo::getBuySellState() == BUYSELL_SELLING) + PlayerInfo::setBuySellState(BUYSELL_NONE); } void SellDialog::reset() diff --git a/src/gui/sell.h b/src/gui/sell.h index 32a4dc55..c286dcc2 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -86,11 +86,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener void setVisible(bool visible); /** - * Returns true if any instances exist. - */ - static bool isActive() { return instances.size() > 0; } - - /** * Closes all instances. */ static void closeAll(); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index f1cd38e4..fc9adab1 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -28,6 +28,7 @@ #include "keyboardconfig.h" #include "localplayer.h" #include "map.h" +#include "playerinfo.h" #include "textmanager.h" #include "gui/gui.h" @@ -345,7 +346,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) return; // Check if we are busy - if (Being::isTalking()) + if (PlayerInfo::isTalking()) return; mPlayerFollowMouse = false; diff --git a/src/net/tmwa/buysellhandler.cpp b/src/net/tmwa/buysellhandler.cpp index a43784de..3e9156a1 100644 --- a/src/net/tmwa/buysellhandler.cpp +++ b/src/net/tmwa/buysellhandler.cpp @@ -61,7 +61,7 @@ void BuySellHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case SMSG_NPC_BUY_SELL_CHOICE: - if (!BuySellDialog::isActive()) + if (PlayerInfo::getBuySellState() != BUYSELL_CHOOSING) { mNpcId = msg.readInt32(); new BuySellDialog(mNpcId); diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 28d37c83..7b2a9b19 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -27,24 +27,29 @@ #include "listener.h" #include "log.h" +#include "gui/npcdialog.h" +#include "gui/npcpostdialog.h" + #include "resources/itemdb.h" #include "resources/iteminfo.h" namespace PlayerInfo { -class PlayerInfoListener; +class PlayerLogic; -PlayerInfoListener *mListener = 0; +PlayerLogic *mListener = 0; PlayerInfoBackend mData; Inventory *mInventory = 0; Equipment *mEquipment = 0; +BuySellState mBuySellState = BUYSELL_NONE; +bool mTrading = false; + std::map<int, Special> mSpecials; char mSpecialRechargeUpdateNeeded = 0; -bool mTrading = false; int mLevelProgress = 0; // --- Triggers --------------------------------------------------------------- @@ -201,6 +206,45 @@ void setEquipmentBackend(Equipment::Backend *backend) mEquipment->setBackend(backend); } +// -- Buy/Sell/Trade ---------------------------------------------------------- + +BuySellState getBuySellState() +{ + return mBuySellState; +} + +void setBuySellState(BuySellState buySellState) +{ + BuySellState old = mBuySellState; + mBuySellState = buySellState; + + if (buySellState != old) + { + Mana::Event event("StateChange"); + event.setInt("oldState", old); + event.setInt("newState", buySellState); + Mana::EventManager::trigger("BuySell", event); + } +} + +bool isTrading() +{ + return mTrading; +} + +void setTrading(bool trading) +{ + bool notify = mTrading != trading; + mTrading = trading; + + if (notify) + { + Mana::Event event("Trading"); + event.setBool("trading", trading); + Mana::EventManager::trigger("Status", event); + } +} + // --- Specials --------------------------------------------------------------- void setSpecialStatus(int id, int current, int max, int recharge) @@ -224,6 +268,12 @@ void setBackend(const PlayerInfoBackend &backend) mData = backend; } +bool isTalking() +{ + return NpcDialog::isActive() || NpcPostDialog::isActive() || + PlayerInfo::getBuySellState() != BUYSELL_NONE; +} + void logic() { if ((mSpecialRechargeUpdateNeeded%11) == 0) @@ -242,28 +292,10 @@ void logic() mSpecialRechargeUpdateNeeded++; } -bool isTrading() -{ - return mTrading; -} - -void setTrading(bool trading) -{ - bool notify = mTrading != trading; - mTrading = trading; - - if (notify) - { - Mana::Event event("Trading"); - event.setInt("trading", trading); - Mana::EventManager::trigger("Status", event); - } -} - -class PlayerInfoListener : Mana::Listener +class PlayerLogic : Mana::Listener { public: - PlayerInfoListener() + PlayerLogic() { listen("Client"); listen("Game"); @@ -306,7 +338,7 @@ void init() if (mListener) return; - mListener = new PlayerInfoListener(); + mListener = new PlayerLogic(); } } // namespace PlayerInfo diff --git a/src/playerinfo.h b/src/playerinfo.h index 3214e64e..fabce6ea 100644 --- a/src/playerinfo.h +++ b/src/playerinfo.h @@ -66,6 +66,14 @@ class Equipment; class Inventory; class Item; +enum BuySellState +{ + BUYSELL_NONE, + BUYSELL_CHOOSING, + BUYSELL_BUYING, + BUYSELL_SELLING +}; + /** * Special information storage structure. */ @@ -168,6 +176,31 @@ namespace PlayerInfo */ Item *getEquipment(unsigned int slot); +// -- Buy/Sell/Trade ---------------------------------------------------------- + + /** + * Returns true if the player is involved in a buy, sell, or related + * interaction, false otherwise. + */ + BuySellState getBuySellState(); + + /** + * Sets whether the player is currently involved in a buy, sell, or related + * interaction. + */ + void setBuySellState(BuySellState buySellState); + + /** + * Returns true if the player is involved in a trade at the moment, false + * otherwise. + */ + bool isTrading(); + + /** + * Sets whether the player is currently involved in trade or not. + */ + void setTrading(bool trading); + // --- Specials --------------------------------------------------------------- /** @@ -188,20 +221,15 @@ namespace PlayerInfo void setBackend(const PlayerInfoBackend &backend); /** - * Does necessary updates every tick. - */ - void logic(); - - /** - * Returns true if the player is involved in a trade at the moment, false + * Returns true if the player is involved in a NPC interaction, false * otherwise. */ - bool isTrading(); + bool isTalking(); /** - * Sets whether the player is currently involved in trade or not. + * Does necessary updates every tick. */ - void setTrading(bool trading); + void logic(); /** * Initializes some internals. |