summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-08-15 21:28:10 -0600
committerJared Adams <jaxad0127@gmail.com>2010-08-16 13:19:09 -0600
commitd8d9232a67a03548b827bdb0515fe7a620a488f8 (patch)
treed6e0644f99e0ff89f9b320c0b479ba5a4e398125 /src/gui
parenta6c2b90c2dabac18ad8052d948bc540406b3a613 (diff)
downloadmana-d8d9232a67a03548b827bdb0515fe7a620a488f8.tar.gz
mana-d8d9232a67a03548b827bdb0515fe7a620a488f8.tar.bz2
mana-d8d9232a67a03548b827bdb0515fe7a620a488f8.tar.xz
mana-d8d9232a67a03548b827bdb0515fe7a620a488f8.zip
Move more to the event system
Most of Net::InventoryHandler is now done through events. The ActorSpriteManager was also replaced by events. A few odds and ends were taken care of too. Reviewed-by: Bertram
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/equipmentwindow.cpp2
-rw-r--r--src/gui/inventorywindow.cpp32
-rw-r--r--src/gui/itemamount.cpp26
-rw-r--r--src/gui/outfitwindow.cpp7
-rw-r--r--src/gui/popupmenu.cpp8
-rw-r--r--src/gui/viewport.cpp23
-rw-r--r--src/gui/viewport.h6
-rw-r--r--src/gui/widgets/itemcontainer.cpp38
8 files changed, 89 insertions, 53 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index dcc372cd..474a9cb6 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -158,7 +158,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event)
if (event.getId() == "unequip" && mSelected > -1)
{
Item *item = mEquipment->getEquipment(mSelected);
- Net::getInventoryHandler()->unequipItem(item);
+ item->doEvent("doUnequip");
setSelected(-1);
}
}
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 41ac96b4..5df1d4ba 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -188,12 +188,12 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
if (item->isEquipment())
{
if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
+ item->doEvent("doUnequip");
else
- Net::getInventoryHandler()->equipItem(item);
+ item->doEvent("doEquip");
}
else
- Net::getInventoryHandler()->useItem(item);
+ item->doEvent("doUse");
}
else if (event.getId() == "drop")
{
@@ -249,13 +249,23 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if(!item)
return;
if (mInventory->isMainInventory())
- Net::getInventoryHandler()->moveItem(Inventory::INVENTORY,
- item->getInvIndex(), item->getQuantity(),
- Inventory::STORAGE);
+ {
+ Mana::Event event("doMove");
+ event.setItem("item", item);
+ event.setInt("amount", item->getQuantity());
+ event.setInt("source", Inventory::INVENTORY);
+ event.setInt("destination", Inventory::STORAGE);
+ event.trigger("Item");
+ }
else
- Net::getInventoryHandler()->moveItem(Inventory::STORAGE,
- item->getInvIndex(), item->getQuantity(),
- Inventory::INVENTORY);
+ {
+ Mana::Event event("doMove");
+ event.setItem("item", item);
+ event.setInt("amount", item->getQuantity());
+ event.setInt("source", Inventory::STORAGE);
+ event.setInt("destination", Inventory::INVENTORY);
+ event.trigger("Item");
+ }
}
}
}
@@ -344,7 +354,9 @@ void InventoryWindow::close()
}
else
{
- Net::getInventoryHandler()->closeStorage(Inventory::STORAGE);
+ Mana::Event event("doCloseInventory");
+ event.setInt("type", mInventory->getType());
+ event.trigger("Item");
scheduleDelete();
}
}
diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp
index a98a67ab..aed8d11d 100644
--- a/src/gui/itemamount.cpp
+++ b/src/gui/itemamount.cpp
@@ -47,20 +47,30 @@ void ItemAmountWindow::finish(Item *item, int amount, Usage usage)
tradeWindow->tradeItem(item, amount);
break;
case ItemDrop:
- Net::getInventoryHandler()->dropItem(item, amount);
+ item->doEvent("doDrop", amount);
break;
case ItemSplit:
- Net::getInventoryHandler()->splitItem(item, amount);
+ item->doEvent("doSplit", amount);
break;
case StoreAdd:
- Net::getInventoryHandler()->moveItem(Inventory::INVENTORY,
- item->getInvIndex(), amount,
- Inventory::STORAGE);
+ {
+ Mana::Event event("doMove");
+ event.setItem("item", item);
+ event.setInt("amount", amount);
+ event.setInt("source", Inventory::INVENTORY);
+ event.setInt("destination", Inventory::STORAGE);
+ event.trigger("Item");
+ }
break;
case StoreRemove:
- Net::getInventoryHandler()->moveItem(Inventory::STORAGE,
- item->getInvIndex(), amount,
- Inventory::INVENTORY);
+ {
+ Mana::Event event("doMove");
+ event.setItem("item", item);
+ event.setInt("amount", amount);
+ event.setInt("source", Inventory::STORAGE);
+ event.setInt("destination", Inventory::INVENTORY);
+ event.trigger("Item");
+ }
break;
default:
break;
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index ad3342ee..f16ebd39 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -171,7 +171,7 @@ void OutfitWindow::wearOutfit(int outfit)
if (item && !item->isEquipped() && item->getQuantity())
{
if (item->isEquipment())
- Net::getInventoryHandler()->equipItem(item);
+ item->doEvent("doEquip");
}
}
}
@@ -337,7 +337,10 @@ void OutfitWindow::unequipNotInOutfit(int outfit)
}
if (!found)
{
- Net::getInventoryHandler()->unequipItem(inventory->getItem(i));
+ Item *item = inventory->getItem(i);
+
+ if (item)
+ item->doEvent("doUnequip");
}
}
}
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 7bf1d4fb..41ecafc9 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -277,14 +277,12 @@ void PopupMenu::handleLink(const std::string &link)
if (mItem->isEquipment())
{
if (mItem->isEquipped())
- Net::getInventoryHandler()->unequipItem(mItem);
+ mItem->doEvent("doUnequip");
else
- Net::getInventoryHandler()->equipItem(mItem);
+ mItem->doEvent("doEquip");
}
else
- {
- Net::getInventoryHandler()->useItem(mItem);
- }
+ mItem->doEvent("doUse");
}
else if (link == "chat")
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index f63fe5c6..972920a5 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -71,6 +71,8 @@ Viewport::Viewport():
mBeingPopup = new BeingPopup;
setFocusable(true);
+
+ listen("ActorSprite");
}
Viewport::~Viewport()
@@ -495,19 +497,14 @@ void Viewport::mouseMoved(gcn::MouseEvent &event)
const int x = (event.getX() + (int) mPixelViewX);
const int y = (event.getY() + (int) mPixelViewY);
- if (mHoverBeing)
- mHoverBeing->removeActorSpriteListener(this);
mHoverBeing = actorSpriteManager->findBeingByPixel(x, y);
mBeingPopup->show(getMouseX(), getMouseY(), mHoverBeing);
- if (mHoverItem)
- mHoverItem->removeActorSpriteListener(this);
mHoverItem = actorSpriteManager->findItem(x / mMap->getTileWidth(),
y / mMap->getTileHeight());
if (mHoverBeing)
{
- mHoverBeing->addActorSpriteListener(this);
switch (mHoverBeing->getType())
{
// NPCs
@@ -527,7 +524,6 @@ void Viewport::mouseMoved(gcn::MouseEvent &event)
}
else if (mHoverItem)
{
- mHoverItem->addActorSpriteListener(this);
gui->setCursorType(Gui::CURSOR_PICKUP);
}
else
@@ -552,11 +548,16 @@ void Viewport::hideBeingPopup()
mBeingPopup->setVisible(false);
}
-void Viewport::actorSpriteDestroyed(const ActorSprite &actorSprite)
+void Viewport::event(const std::string &channel, const Mana::Event &event)
{
- if (&actorSprite == mHoverBeing)
- mHoverBeing = 0;
+ if (channel == "ActorSprite" && event.getName() == "Destroyed")
+ {
+ ActorSprite *actor = event.getActor("source");
- if (&actorSprite == mHoverItem)
- mHoverItem = 0;
+ if (mHoverBeing == actor)
+ mHoverBeing = 0;
+
+ if (mHoverItem == actor)
+ mHoverItem = 0;
+ }
}
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index eaf23085..c54b9860 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -22,9 +22,9 @@
#ifndef VIEWPORT_H
#define VIEWPORT_H
-#include "actorspritelistener.h"
#include "actorspritemanager.h"
#include "configlistener.h"
+#include "listener.h"
#include "position.h"
#include "gui/widgets/windowcontainer.h"
@@ -54,7 +54,7 @@ const int walkingMouseDelay = 500;
* coordinates.
*/
class Viewport : public WindowContainer, public gcn::MouseListener,
- public ConfigListener, public ActorSpriteListener
+ public ConfigListener, public Mana::Listener
{
public:
/**
@@ -160,7 +160,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
*/
void hideBeingPopup();
- void actorSpriteDestroyed(const ActorSprite &actorSprite);
+ void event(const std::string &channel, const Mana::Event &event);
private:
/**
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index b98cac66..a9df95a6 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -260,12 +260,12 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (item->isEquipment())
{
if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
+ item->doEvent("doUnequip");
else
- Net::getInventoryHandler()->equipItem(item);
+ item->doEvent("doEquip");
}
else
- Net::getInventoryHandler()->useItem(item);
+ item->doEvent("doUse");
}
else
@@ -275,18 +275,17 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
}
else if (item && item->getId())
{
- if(event.getClickCount() == 2)
+ if(event.getClickCount() == 2)
{
if (item->isEquipment())
{
if (item->isEquipped())
- Net::getInventoryHandler()->unequipItem(item);
+ item->doEvent("doUnequip");
else
- Net::getInventoryHandler()->equipItem(item);
+ item->doEvent("doEquip");
}
else
- Net::getInventoryHandler()->useItem(item);
-
+ item->doEvent("doUse");
}
else
{
@@ -337,7 +336,14 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
return;
if (index == mSelectedIndex || mSelectedIndex == -1)
return;
- Net::getInventoryHandler()->moveItem(mSelectedIndex, index);
+
+ Item *item = getSelectedItem();
+ {
+ Mana::Event event("doMove");
+ event.setItem("item", item);
+ event.setInt("newIndex", index);
+ event.trigger("Item");
+ }
selectNone();
}
@@ -404,8 +410,11 @@ void ItemContainer::keyAction()
mSelectedIndex != -1 &&
mHighlightedIndex != -1)
{
- Net::getInventoryHandler()->moveItem(
- mSelectedIndex, mHighlightedIndex);
+ Item *item = getSelectedItem();
+ Mana::Event event("doMove");
+ event.setItem("item", item);
+ event.setInt("newIndex", mHighlightedIndex);
+ event.trigger("Item");
setSelectedIndex(mHighlightedIndex);
}
// If the highlight is on an item then select it.
@@ -417,8 +426,11 @@ void ItemContainer::keyAction()
// If the highlight is on a blank space then move it.
else if (mSelectedIndex != -1)
{
- Net::getInventoryHandler()->moveItem(
- mSelectedIndex, mHighlightedIndex);
+ Item *item = getSelectedItem();
+ Mana::Event event("doMove");
+ event.setItem("item", item);
+ event.setInt("newIndex", mHighlightedIndex);
+ event.trigger("Item");
selectNone();
}
}