Mana
Loading...
Searching...
No Matches
itemcontainer.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <guichan/keylistener.hpp>
25#include <guichan/mouselistener.hpp>
26#include <guichan/widget.hpp>
27#include <guichan/widgetlistener.hpp>
28
29#include <map>
30#include <list>
31
32class Image;
33class Inventory;
34class Item;
35class ItemPopup;
36
37namespace gcn {
38 class SelectionListener;
39}
40
46class ItemContainer : public gcn::Widget,
47 public gcn::KeyListener,
48 public gcn::MouseListener,
49 public gcn::WidgetListener
50{
51 public:
57 ItemContainer(Inventory *inventory);
58
59 ~ItemContainer() override;
60
61 void hidePopup();
62
66 void logic() override;
67
71 void draw(gcn::Graphics *graphics) override;
72
73 // Overridden to disable drawing of the frame
74 void drawFrame(gcn::Graphics *graphics) override {}
75
76 // KeyListener
77 void keyPressed(gcn::KeyEvent &event) override;
78 void keyReleased(gcn::KeyEvent &event) override;
79
80 // MouseListener
81 void mousePressed(gcn::MouseEvent &event) override;
82 void mouseDragged(gcn::MouseEvent &event) override;
83 void mouseReleased(gcn::MouseEvent &event) override;
84 void mouseMoved(gcn::MouseEvent &event) override;
85 void mouseExited(gcn::MouseEvent &event) override;
86
87 // WidgetListener
88 void widgetResized(const gcn::Event &event) override;
89
93 Item *getSelectedItem() const;
94
98 void selectNone();
99
100
104 void setFilter(const std::string &filter);
105
110 void addSelectionListener(gcn::SelectionListener *listener)
111 {
112 mSelectionListeners.push_back(listener);
113 }
114
119 void removeSelectionListener(gcn::SelectionListener *listener)
120 {
121 mSelectionListeners.remove(listener);
122 }
123
124 private:
132
141
145 void keyAction();
146
152 void moveHighlight(Direction direction);
153
157 void setSelectedIndex(int index);
158
162 void adjustHeight();
163
168
176 int getSlotIndex(int x, int y) const;
177
178 Item *getItemAt(int) const;
179
182 int mGridRows = 1;
187 bool mSwapItems = false;
188 bool mDescItems = false;
189 int mDragPosX = 0;
190 int mDragPosY = 0;
191
192 std::map<int, Item*> mFilteredMap;
193
194 std::string mFilter;
195
197
198 std::list<gcn::SelectionListener *> mSelectionListeners;
199};
Defines a class for loading and storing images.
Definition image.h:45
An item container.
int getSlotIndex(int x, int y) const
Gets the slot index based on the cursor position.
void widgetResized(const gcn::Event &event) override
void setSelectedIndex(int index)
Sets the currently selected item.
SelectionState mSelectionStatus
void mouseExited(gcn::MouseEvent &event) override
void setFilter(const std::string &filter)
Sets item filter.
void drawFrame(gcn::Graphics *graphics) override
void removeSelectionListener(gcn::SelectionListener *listener)
Removes a listener from the list that's notified each time a change to the selection occurs.
void mouseMoved(gcn::MouseEvent &event) override
Item * getItemAt(int) const
void keyReleased(gcn::KeyEvent &event) override
void keyPressed(gcn::KeyEvent &event) override
~ItemContainer() override
void logic() override
Necessary for checking how full the inventory is.
std::list< gcn::SelectionListener * > mSelectionListeners
void mousePressed(gcn::MouseEvent &event) override
void addSelectionListener(gcn::SelectionListener *listener)
Adds a listener to the list that's notified each time a change to the selection occurs.
void mouseReleased(gcn::MouseEvent &event) override
ItemPopup * mItemPopup
Item * getSelectedItem() const
Returns the selected item.
void selectNone()
Sets selected item to NULL.
void moveHighlight(Direction direction)
Moves the highlight in the direction specified.
void distributeValueChangedEvent()
Sends out selection events to the list of selection listeners.
Inventory * mInventory
void draw(gcn::Graphics *graphics) override
Draws the items.
std::string mFilter
void adjustHeight()
Determine and set the height of the container.
void keyAction()
Execute all the functionality associated with the action key.
std::map< int, Item * > mFilteredMap
void mouseDragged(gcn::MouseEvent &event) override
A popup that displays information about an item.
Definition itempopup.h:39
Represents one or more instances of a certain item type.
Definition item.h:35
Graphics * graphics
Definition client.cpp:104