summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-08-01 22:05:46 -0600
committerJared Adams <jaxad0127@gmail.com>2010-08-01 22:45:31 -0600
commitcec8045dcdad05d76141d4e27c8c9e72696ce7dc (patch)
tree0c7cded281b0ff01b2f0f0d74f44fc88e2622533 /src
parenta3e61c0e830c46b51c0d135962ad361c02b93243 (diff)
downloadMana-cec8045dcdad05d76141d4e27c8c9e72696ce7dc.tar.gz
Mana-cec8045dcdad05d76141d4e27c8c9e72696ce7dc.tar.bz2
Mana-cec8045dcdad05d76141d4e27c8c9e72696ce7dc.tar.xz
Mana-cec8045dcdad05d76141d4e27c8c9e72696ce7dc.zip
Remove isActive methods from NPC dialogs and InventoryWindow
Uses counts in PlayerInfo instead. Reviewed-by: Chuck Miller
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/inventorywindow.cpp8
-rw-r--r--src/gui/inventorywindow.h5
-rw-r--r--src/gui/npcdialog.cpp5
-rw-r--r--src/gui/npcdialog.h5
-rw-r--r--src/gui/npcpostdialog.cpp4
-rw-r--r--src/gui/npcpostdialog.h5
-rw-r--r--src/gui/popupmenu.cpp3
-rw-r--r--src/playerinfo.cpp68
-rw-r--r--src/playerinfo.h42
10 files changed, 122 insertions, 25 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 0c765f9e..4e76061e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -401,7 +401,7 @@ void Game::handleInput()
// send straight to gui for certain windows
if (quitDialog || TextDialog::isActive() ||
- NpcPostDialog::isActive())
+ PlayerInfo::getNPCPostCount() > 0)
{
try
{
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index fb7d1c8c..3bb84ab8 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -140,13 +140,19 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
slotsChanged(mInventory);
if (!isMainInventory())
+ {
setVisible(true);
+ PlayerInfo::setStorageCount(PlayerInfo::getStorageCount() + 1);
+ }
}
InventoryWindow::~InventoryWindow()
{
instances.remove(this);
mInventory->removeInventoyListener(this);
+
+ if (!isMainInventory())
+ PlayerInfo::setStorageCount(PlayerInfo::getStorageCount() - 1);
}
void InventoryWindow::action(const gcn::ActionEvent &event)
@@ -236,7 +242,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if (event.getButton() == gcn::MouseEvent::LEFT)
{
- if (isStorageActive() && keyboard.isKeyActive(keyboard.KEY_EMOTE))
+ if (instances.size() > 1 && keyboard.isKeyActive(keyboard.KEY_EMOTE))
{
Item *item = mItems->getSelectedItem();
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 3adbc1cc..af72106b 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -107,11 +107,6 @@ class InventoryWindow : public Window,
bool isMainInventory() { return mInventory->isMainInventory(); }
- /**
- * Returns true if any instances exist.
- */
- static bool isStorageActive() { return instances.size() > 1; }
-
void event(const std::string &channel, const Mana::Event &event);
private:
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index 828ed776..c9eaff10 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -22,6 +22,7 @@
#include "gui/npcdialog.h"
#include "configuration.h"
+#include "playerinfo.h"
#include "gui/setup.h"
@@ -123,6 +124,8 @@ NpcDialog::NpcDialog(int npcId)
requestFocus();
config.addListener("logNpcInGui", this);
+ PlayerInfo::setNPCInteractionCount(PlayerInfo::getNPCInteractionCount()
+ + 1);
}
NpcDialog::~NpcDialog()
@@ -139,6 +142,8 @@ NpcDialog::~NpcDialog()
instances.remove(this);
config.removeListener("logNpcInGui", this);
+ PlayerInfo::setNPCInteractionCount(PlayerInfo::getNPCInteractionCount()
+ - 1);
}
void NpcDialog::setText(const std::string &text)
diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h
index 26ff9c1a..561cceb9 100644
--- a/src/gui/npcdialog.h
+++ b/src/gui/npcdialog.h
@@ -154,11 +154,6 @@ class NpcDialog : public Window, public gcn::ActionListener,
void optionChanged(const std::string &name);
/**
- * Returns true if any instances exist.
- */
- static bool isActive() { return instances.size() > 0; }
-
- /**
* Returns the first active instance. Useful for pushing user
* interaction.
*/
diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp
index 74173ae9..6bc79017 100644
--- a/src/gui/npcpostdialog.cpp
+++ b/src/gui/npcpostdialog.cpp
@@ -22,6 +22,7 @@
#include "gui/npcpostdialog.h"
#include "eventmanager.h"
+#include "playerinfo.h"
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
@@ -79,11 +80,14 @@ NpcPostDialog::NpcPostDialog(int npcId):
instances.push_back(this);
setVisible(true);
+
+ PlayerInfo::setNPCPostCount(PlayerInfo::getNPCPostCount() + 1);
}
NpcPostDialog::~NpcPostDialog()
{
instances.remove(this);
+ PlayerInfo::setNPCPostCount(PlayerInfo::getNPCPostCount() - 1);
}
void NpcPostDialog::action(const gcn::ActionEvent &event)
diff --git a/src/gui/npcpostdialog.h b/src/gui/npcpostdialog.h
index ad0053a3..248e4515 100644
--- a/src/gui/npcpostdialog.h
+++ b/src/gui/npcpostdialog.h
@@ -47,11 +47,6 @@ public:
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/popupmenu.cpp b/src/gui/popupmenu.cpp
index 76569d38..7bf1d4fb 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -28,6 +28,7 @@
#include "item.h"
#include "localplayer.h"
#include "log.h"
+#include "playerinfo.h"
#include "playerrelations.h"
#include "gui/chat.h"
@@ -381,7 +382,7 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item,
mBrowserBox->addRow(strprintf("@@split|%s@@", _("Split")));
}
- if (InventoryWindow::isStorageActive())
+ if (PlayerInfo::getStorageCount() > 0)
{
mBrowserBox->addRow(strprintf("@@store|%s@@", _("Store")));
}
diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp
index 7b2a9b19..a6438187 100644
--- a/src/playerinfo.cpp
+++ b/src/playerinfo.cpp
@@ -44,6 +44,11 @@ PlayerInfoBackend mData;
Inventory *mInventory = 0;
Equipment *mEquipment = 0;
+bool mStorageCount = 0;
+
+bool mNPCCount = 0;
+bool mNPCPostCount = 0;
+
BuySellState mBuySellState = BUYSELL_NONE;
bool mTrading = false;
@@ -206,6 +211,65 @@ void setEquipmentBackend(Equipment::Backend *backend)
mEquipment->setBackend(backend);
}
+int getStorageCount()
+{
+ return mStorageCount;
+}
+
+void setStorageCount(int count)
+{
+ int old = mStorageCount;
+ mStorageCount = count;
+
+ if (count != old)
+ {
+ Mana::Event event("StorageCount");
+ event.setBool("oldCount", old);
+ event.setBool("newCount", count);
+ Mana::EventManager::trigger("Storage", event);
+ }
+}
+
+// -- NPC ---------------------------------------------------------------------
+
+int getNPCInteractionCount()
+{
+ return mNPCCount;
+}
+
+void setNPCInteractionCount(int count)
+{
+ int old = mNPCCount;
+ mNPCCount = count;
+
+ if (count != old)
+ {
+ Mana::Event event("NPCCount");
+ event.setBool("oldCount", old);
+ event.setBool("newCount", count);
+ Mana::EventManager::trigger("NPC", event);
+ }
+}
+
+int getNPCPostCount()
+{
+ return mNPCPostCount;
+}
+
+void setNPCPostCount(int count)
+{
+ int old = mNPCPostCount;
+ mNPCPostCount = count;
+
+ if (count != old)
+ {
+ Mana::Event event("PostCount");
+ event.setBool("oldCount", old);
+ event.setBool("newCount", count);
+ Mana::EventManager::trigger("NPC", event);
+ }
+}
+
// -- Buy/Sell/Trade ----------------------------------------------------------
BuySellState getBuySellState()
@@ -270,8 +334,8 @@ void setBackend(const PlayerInfoBackend &backend)
bool isTalking()
{
- return NpcDialog::isActive() || NpcPostDialog::isActive() ||
- PlayerInfo::getBuySellState() != BUYSELL_NONE;
+ return getNPCInteractionCount() || getNPCPostCount()
+ || getBuySellState() != BUYSELL_NONE;
}
void logic()
diff --git a/src/playerinfo.h b/src/playerinfo.h
index fabce6ea..43e7da6e 100644
--- a/src/playerinfo.h
+++ b/src/playerinfo.h
@@ -149,7 +149,7 @@ namespace PlayerInfo
*/
void setStatExperience(int id, int have, int need, bool notify = true);
-// --- Inventory / Equipment --------------------------------------------------
+// --- Inventory / Equipment / Storage ----------------------------------------
/**
* Returns the player's inventory.
@@ -176,17 +176,49 @@ namespace PlayerInfo
*/
Item *getEquipment(unsigned int slot);
+ /**
+ * Returns the number of currently open storage windows.
+ */
+ int getStorageCount();
+
+ /**
+ * Sets the number of currently open storage windows.
+ */
+ void setStorageCount(int count);
+
+// -- NPC ---------------------------------------------------------------------
+
+ /**
+ * Returns the number of currently open NPC interaction windows.
+ */
+ int getNPCInteractionCount();
+
+ /**
+ * Sets the number of currently open NPC interaction windows.
+ */
+ void setNPCInteractionCount(int count);
+
+ /**
+ * Returns the number of currently open NPC post windows.
+ */
+ int getNPCPostCount();
+
+ /**
+ * Sets the number of currently open NPC post windows.
+ */
+ void setNPCPostCount(int count);
+
// -- Buy/Sell/Trade ----------------------------------------------------------
/**
- * Returns true if the player is involved in a buy, sell, or related
- * interaction, false otherwise.
+ * Returns the current buy, sell, or related interaction the player is
+ * involved in.
*/
BuySellState getBuySellState();
/**
- * Sets whether the player is currently involved in a buy, sell, or related
- * interaction.
+ * Sets which buy, sell, or related interaction the player is currently
+ * involved in.
*/
void setBuySellState(BuySellState buySellState);