summaryrefslogtreecommitdiff
path: root/src/gui/itemcontainer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itemcontainer.cpp')
-rw-r--r--src/gui/itemcontainer.cpp58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 4a90510c..bdae9ada 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -1,27 +1,29 @@
/*
* The Mana World
- * Copyright 2004 The Mana World Development Team
+ * Copyright (C) 2004 The Mana World Development Team
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
+ * 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.
*
- * The Mana World is distributed in the hope that it will be useful,
+ * 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 The Mana World; if not, write to the Free Software
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "itemcontainer.h"
#include "chat.h"
+#include "itempopup.h"
+
#include <guichan/mouseinput.hpp>
#include <guichan/selectionlistener.hpp>
@@ -32,12 +34,12 @@
#include "../item.h"
#include "../itemshortcut.h"
#include "../localplayer.h"
+#include "../log.h"
#include "../resources/image.h"
-#include "../resources/iteminfo.h"
#include "../resources/resourcemanager.h"
-#include "../utils/tostring.h"
+#include "../utils/stringutils.h"
// TODO: Add support for adding items to the item shortcut window (global
// itemShortcut).
@@ -55,10 +57,13 @@ enum
};
ItemContainer::ItemContainer(Inventory *inventory,
- int gridColumns = 1, int gridRows = 1):
+ int gridColumns,
+ int gridRows,
+ int offset):
mInventory(inventory),
mGridColumns(gridColumns),
mGridRows(gridRows),
+ mOffset(offset),
mSelectedItem(NULL),
mHighlightedItem(NULL),
mSelectionStatus(SEL_NONE),
@@ -71,17 +76,19 @@ ItemContainer::ItemContainer(Inventory *inventory,
ResourceManager *resman = ResourceManager::getInstance();
mSelImg = resman->getImage("graphics/gui/selection.png");
+ if (!mSelImg) logger->error("Unable to load selection.png");
addKeyListener(this);
addMouseListener(this);
setSize((BOX_WIDTH - 1) * mGridColumns + 1,
- (BOX_HEIGHT - 1) * mGridRows + 1);
+ (BOX_HEIGHT - 1) * mGridRows + 1);
}
ItemContainer::~ItemContainer()
{
mSelImg->decRef();
+ delete mItemPopup;
}
void ItemContainer::draw(gcn::Graphics *graphics)
@@ -174,8 +181,7 @@ void ItemContainer::distributeValueChangedEvent()
}
}
-void
-ItemContainer::keyPressed(gcn::KeyEvent &event)
+void ItemContainer::keyPressed(gcn::KeyEvent &event)
{
switch (event.getKey().getValue())
{
@@ -204,8 +210,7 @@ ItemContainer::keyPressed(gcn::KeyEvent &event)
}
}
-void
-ItemContainer::keyReleased(gcn::KeyEvent &event)
+void ItemContainer::keyReleased(gcn::KeyEvent &event)
{
switch (event.getKey().getValue())
{
@@ -219,8 +224,7 @@ ItemContainer::keyReleased(gcn::KeyEvent &event)
}
}
-void
-ItemContainer::mousePressed(gcn::MouseEvent &event)
+void ItemContainer::mousePressed(gcn::MouseEvent &event)
{
const int button = event.getButton();
if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
@@ -235,7 +239,7 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
// put item name into chat window
if (mDescItems)
{
- chatWindow->addItemText(item->getId(), item->getInfo().getName());
+ chatWindow->addItemText(item->getInfo().getName());
}
if (mSelectedItem && mSelectedItem == item)
@@ -246,6 +250,8 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
{
setSelectedItem(item);
mSelectionStatus = SEL_SELECTING;
+
+ itemShortcut->setItemSelected(item->getId());
}
else
{
@@ -255,8 +261,7 @@ ItemContainer::mousePressed(gcn::MouseEvent &event)
}
}
-void
-ItemContainer::mouseDragged(gcn::MouseEvent &event)
+void ItemContainer::mouseDragged(gcn::MouseEvent &event)
{
if (mSelectionStatus != SEL_NONE)
{
@@ -297,15 +302,16 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
// Show ItemTooltip
void ItemContainer::mouseMoved(gcn::MouseEvent &event)
{
- Item *item = mInventory->getItem( getSlotIndex(event.getX(), event.getY() ) );
+ Item *item = mInventory->getItem(getSlotIndex(event.getX(), event.getY()));
- if( item )
+ if (item)
{
- mItemPopup->setPosition(getParent()->getParent()->getX() + getParent()->getParent()->getWidth(), getParent()->getParent()->getY());
+ int mouseX, mouseY;
+ SDL_GetMouseState(&mouseX, &mouseY);
mItemPopup->setItem(item->getInfo());
-
- mItemPopup->setVisible(true);
+ mItemPopup->setOpaque(false);
+ mItemPopup->view(mouseX, mouseY);
}
else
{
@@ -313,14 +319,6 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event)
}
}
-
-// Show ItemTooltip
-void ItemContainer::mouseEntered(gcn::MouseEvent &event)
-{
-
-}
-
-
// Hide ItemTooltip
void ItemContainer::mouseExited(gcn::MouseEvent &event)
{