00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ITEMCONTAINER_H
00023 #define ITEMCONTAINER_H
00024
00025 #include <guichan/keylistener.hpp>
00026 #include <guichan/mouselistener.hpp>
00027 #include <guichan/widget.hpp>
00028 #include <guichan/widgetlistener.hpp>
00029
00030 #include <list>
00031
00032 class Image;
00033 class Inventory;
00034 class Item;
00035 class ItemPopup;
00036
00037 namespace gcn {
00038 class SelectionListener;
00039 }
00040
00046 class ItemContainer : public gcn::Widget,
00047 public gcn::KeyListener,
00048 public gcn::MouseListener,
00049 public gcn::WidgetListener
00050 {
00051 public:
00060 ItemContainer(Inventory *inventory, bool forceQuantity = false);
00061
00065 virtual ~ItemContainer();
00066
00070 void draw(gcn::Graphics *graphics);
00071
00072
00073 void keyPressed(gcn::KeyEvent &event);
00074 void keyReleased(gcn::KeyEvent &event);
00075
00076
00077 void mousePressed(gcn::MouseEvent &event);
00078 void mouseDragged(gcn::MouseEvent &event);
00079 void mouseReleased(gcn::MouseEvent &event);
00080 void mouseMoved(gcn::MouseEvent &event);
00081 void mouseExited(gcn::MouseEvent &event);
00082
00083
00084 void widgetResized(const gcn::Event &event);
00085
00089 Item *getSelectedItem() const
00090 { return mSelectedItem; }
00091
00095 void selectNone();
00096
00101 void addSelectionListener(gcn::SelectionListener *listener)
00102 {
00103 mSelectionListeners.push_back(listener);
00104 }
00105
00110 void removeSelectionListener(gcn::SelectionListener *listener)
00111 {
00112 mSelectionListeners.remove(listener);
00113 }
00114
00115 private:
00116 enum Direction
00117 {
00118 Left,
00119 Right,
00120 Up,
00121 Down
00122 };
00123
00124 enum SelectionState
00125 {
00126 SEL_NONE = 0,
00127 SEL_SELECTED,
00128 SEL_SELECTING,
00129 SEL_DESELECTING,
00130 SEL_DRAGGING
00131 };
00132
00136 void keyAction();
00137
00143 void moveHighlight(Direction direction);
00144
00148 void setSelectedItem(Item *item);
00149
00153 void refindSelectedItem();
00154
00158 void recalculateHeight();
00159
00163 void distributeValueChangedEvent();
00164
00172 int getSlotIndex(int x, int y) const;
00173
00174 Inventory *mInventory;
00175 int mGridColumns, mGridRows;
00176 Image *mSelImg;
00177 Item *mSelectedItem, *mHighlightedItem;
00178 SelectionState mSelectionStatus;
00179 bool mForceQuantity;
00180 bool mSwapItems;
00181 bool mDescItems;
00182 int mDragPosX, mDragPosY;
00183
00184 ItemPopup *mItemPopup;
00185
00186 typedef std::list<gcn::SelectionListener*> SelectionListenerList;
00187 typedef SelectionListenerList::iterator SelectionListenerIterator;
00188
00189 SelectionListenerList mSelectionListeners;
00190 };
00191
00192 #endif