ManaPlus
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes

#include <inventorywindow.h>

Inheritance diagram for InventoryWindow:
Window ActionListener KeyListener SelectionListener InventoryListener AttributeListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 InventoryWindow (Inventory *const inventory)
 
 ~InventoryWindow ()
 
void postInit ()
 
void storeSortOrder () const
 
void action (const ActionEvent &event)
 
ItemgetSelectedItem () const
 
void unselectItem ()
 
void widgetHidden (const Event &event)
 
void mouseClicked (MouseEvent &event)
 
void keyPressed (KeyEvent &event)
 
void keyReleased (KeyEvent &event)
 
void valueChanged (const SelectionEvent &event)
 
void close ()
 
void slotsChanged (const Inventory *const inventory)
 
bool isMainInventory () const
 
void updateDropButton ()
 
void updateButtons (const Item *item)
 
bool isInputFocused () const
 
void widgetResized (const Event &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void setVisible (Visible visible)
 
void unsetInventory ()
 
void attributeChanged (const AttributesT id, const int64_t oldVal, const int64_t newVal)
 
void combineItems (const int index1, const int index2)
 
void moveItemToCraft (const int craftSlot)
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetMoved (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
- Public Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 
- Public Member Functions inherited from InventoryListener
virtual ~InventoryListener ()
 
- Public Member Functions inherited from AttributeListener
 AttributeListener ()
 
virtual ~ AttributeListener ()
 

Static Public Member Functions

static bool isStorageActive ()
 
static bool isAnyInputFocused ()
 
static InventoryWindowgetFirstVisible ()
 
static void nextTab ()
 
static void prevTab ()
 
- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Static Public Member Functions inherited from AttributeListener
static void distributeEvent (const AttributesT id, const int64_t oldVal, const int64_t newVal)
 
static void addListener (AttributeListener *const listener)
 
static void removeListener (const AttributeListener *const listener)
 

Private Types

typedef std::list< InventoryWindow * > WindowList
 

Private Member Functions

void updateWeight ()
 

Private Attributes

InventorymInventory
 
ItemContainermItems
 
ButtonmUseButton
 
ButtonmDropButton
 
ButtonmOutfitButton
 
ButtonmShopButton
 
ButtonmCartButton
 
ButtonmEquipmentButton
 
ButtonmStoreButton
 
ButtonmRetrieveButton
 
ButtonmInvCloseButton
 
ProgressBarmWeightBar
 
ProgressBarmSlotsBar
 
TabStripmFilter
 
SortListModelInvmSortModel
 
DropDownmSortDropDown
 
TextFieldmNameFilter
 
LayoutCellmSortDropDownCell
 
LayoutCellmNameFilterCell
 
LayoutCellmFilterCell
 
LayoutCellmSlotsBarCell
 
bool mSplit
 
bool mCompactMode
 

Static Private Attributes

static WindowList invInstances
 

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Member Functions inherited from SelectionListener
 SelectionListener ()
 
- Protected Member Functions inherited from InventoryListener
 InventoryListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Inventory dialog.

Definition at line 57 of file inventorywindow.h.

Member Typedef Documentation

◆ WindowList

typedef std::list<InventoryWindow*> InventoryWindow::WindowList
private

Definition at line 180 of file inventorywindow.h.

Constructor & Destructor Documentation

◆ InventoryWindow()

InventoryWindow::InventoryWindow ( Inventory *const  inventory)
explicit

Constructor.

Definition at line 85 of file inventorywindow.cpp.

85  :
86  Window("Inventory", Modal_false, nullptr, "inventory.xml"),
88  KeyListener(),
92  mInventory(inventory),
93  mItems(new ItemContainer(this, mInventory, 100000,
95  mUseButton(nullptr),
96  mDropButton(nullptr),
97  mOutfitButton(nullptr),
98  mShopButton(nullptr),
99  mCartButton(nullptr),
100  mEquipmentButton(nullptr),
101  mStoreButton(nullptr),
102  mRetrieveButton(nullptr),
103  mInvCloseButton(nullptr),
104  mWeightBar(nullptr),
105  mSlotsBar(new ProgressBar(this, 0.0F, 100, 0,
107  "slotsprogressbar.xml", "slotsprogressbar_fill.xml")),
108  mFilter(nullptr),
110  mSortDropDown(new DropDown(this, mSortModel, false,
111  Modal_false, this, "sort")),
113  this, "namefilter", true)),
114  mSortDropDownCell(nullptr),
115  mNameFilterCell(nullptr),
116  mFilterCell(nullptr),
117  mSlotsBarCell(nullptr),
118  mSplit(false),
119  mCompactMode(false)
120 {
121  mSlotsBar->setColor(getThemeColor(ThemeColorId::SLOTS_BAR, 255U),
122  getThemeColor(ThemeColorId::SLOTS_BAR_OUTLINE, 255U));
123 
124  if (inventory != nullptr)
125  {
126  setCaption(gettext(inventory->getName().c_str()));
127  setWindowName(inventory->getName());
128  switch (inventory->getType())
129  {
132  case InventoryType::Npc:
138  default:
140  "inventorySortOrder"));
141  break;
144  "storageSortOrder"));
145  break;
146  case InventoryType::Cart:
148  "cartSortOrder"));
149  break;
150  }
151  }
152  else
153  {
154  // TRANSLATORS: inventory window name
155  setCaption(_("Inventory"));
156  setWindowName("Inventory");
158  }
159 
160  if ((setupWindow != nullptr) &&
161  (inventory != nullptr) &&
162  inventory->getType() != InventoryType::Storage)
163  {
165  }
166 
167  setResizable(true);
168  setCloseButton(true);
169  setSaveVisible(true);
170  setStickyButtonLock(true);
171 
172  if (mainGraphics->mWidth > 600)
173  setDefaultSize(450, 310, ImagePosition::CENTER, 0, 0);
174  else
175  setDefaultSize(387, 307, ImagePosition::CENTER, 0, 0);
176  setMinWidth(310);
177  setMinHeight(179);
178  addKeyListener(this);
179 
181 
182  const int size = config.getIntValue("fontSize");
183  mFilter = new TabStrip(this, "filter_" + getWindowName(), size + 16, 0);
184  mFilter->addActionListener(this);
185  mFilter->setActionEventId("tag_");
186  mFilter->setSelectable(false);
187 
188  StringVect tags = ItemDB::getTags();
189  const size_t sz = tags.size();
190  for (size_t f = 0; f < sz; f ++)
191  mFilter->addButton(tags[f], tags[f], false);
192 
193  if (mInventory == nullptr)
194  {
195  invInstances.push_back(this);
196  return;
197  }
198 
199  ScrollArea *const invenScroll = new ScrollArea(this, mItems,
200  fromBool(getOptionBool("showbackground", false), Opaque),
201  "inventory_background.xml");
203 
204  switch (mInventory->getType())
205  {
207  {
208  // TRANSLATORS: inventory button
209  const std::string equip = _("Equip");
210  // TRANSLATORS: inventory button
211  const std::string use = _("Use");
212  // TRANSLATORS: inventory button
213  const std::string unequip = _("Unequip");
214 
215  std::string longestUseString = getFont()->getWidth(equip) >
216  getFont()->getWidth(use) ? equip : use;
217 
218  if (getFont()->getWidth(longestUseString) <
219  getFont()->getWidth(unequip))
220  {
221  longestUseString = unequip;
222  }
223 
224  mUseButton = new Button(this,
225  longestUseString,
226  "use",
227  BUTTON_SKIN,
228  this);
229  mDropButton = new Button(this,
230  // TRANSLATORS: inventory button
231  _("Drop..."),
232  "drop",
233  BUTTON_SKIN,
234  this);
235  mOutfitButton = new Button(this,
236  // TRANSLATORS: inventory outfits button
237  _("O"),
238  "outfit",
239  BUTTON_SKIN,
240  this);
241  mCartButton = new Button(this,
242  // TRANSLATORS: inventory cart button
243  _("C"),
244  "cart",
245  BUTTON_SKIN,
246  this);
247  mShopButton = new Button(this,
248  // TRANSLATORS: inventory shop button
249  _("S"),
250  "shop",
251  BUTTON_SKIN,
252  this);
253  mEquipmentButton = new Button(this,
254  // TRANSLATORS: inventory equipment button
255  _("E"),
256  "equipment",
257  BUTTON_SKIN,
258  this);
259  mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
261  "weightprogressbar.xml", "weightprogressbar_fill.xml");
262  mWeightBar->setColor(getThemeColor(ThemeColorId::WEIGHT_BAR, 255U),
263  getThemeColor(ThemeColorId::WEIGHT_BAR_OUTLINE, 255U));
264 
265  // TRANSLATORS: outfits button tooltip
266  mOutfitButton->setDescription(_("Outfits"));
267  // TRANSLATORS: cart button tooltip
268  mCartButton->setDescription(_("Cart"));
269  // TRANSLATORS: shop button tooltip
270  mShopButton->setDescription(_("Shop"));
271  // TRANSLATORS: equipment button tooltip
272  mEquipmentButton->setDescription(_("Equipment"));
273 
274  place(0, 0, mWeightBar, 4, 1);
275  mSlotsBarCell = &place(4, 0, mSlotsBar, 4, 1);
276  mSortDropDownCell = &place(8, 0, mSortDropDown, 3, 1);
277 
278  mFilterCell = &place(0, 1, mFilter, 10, 1).setPadding(3);
279  mNameFilterCell = &place(8, 1, mNameFilter, 3, 1);
280 
281  place(0, 2, invenScroll, 11, 1).setPadding(3);
282  place(0, 3, mUseButton, 1, 1);
283  place(1, 3, mDropButton, 1, 1);
284  ContainerPlacer placer = getPlacer(10, 3);
285  placer(0, 0, mShopButton, 1, 1);
286  placer(1, 0, mOutfitButton, 1, 1);
287  placer(2, 0, mCartButton, 1, 1);
288  placer(3, 0, mEquipmentButton, 1, 1);
289 
290  updateWeight();
291  break;
292  }
293 
295  {
296  mStoreButton = new Button(this,
297  // TRANSLATORS: storage button
298  _("Store"),
299  "store",
300  BUTTON_SKIN,
301  this);
302  mRetrieveButton = new Button(this,
303  // TRANSLATORS: storage button
304  _("Retrieve"),
305  "retrieve",
306  BUTTON_SKIN,
307  this);
308  mInvCloseButton = new Button(this,
309  // TRANSLATORS: storage button
310  _("Close"),
311  "close",
312  BUTTON_SKIN,
313  this);
314 
315  mSlotsBarCell = &place(0, 0, mSlotsBar, 6, 1);
316  mSortDropDownCell = &place(6, 0, mSortDropDown, 1, 1);
317 
318  mFilterCell = &place(0, 1, mFilter, 7, 1).setPadding(3);
319  mNameFilterCell = &place(6, 1, mNameFilter, 1, 1);
320 
321  place(0, 2, invenScroll, 7, 4);
322  place(0, 6, mStoreButton, 1, 1);
323  place(1, 6, mRetrieveButton, 1, 1);
324  place(6, 6, mInvCloseButton, 1, 1);
325  break;
326  }
327 
328  case InventoryType::Cart:
329  {
330  mStoreButton = new Button(this,
331  // TRANSLATORS: storage button
332  _("Store"),
333  "store",
334  BUTTON_SKIN,
335  this);
336  mRetrieveButton = new Button(this,
337  // TRANSLATORS: storage button
338  _("Retrieve"),
339  "retrieve",
340  BUTTON_SKIN,
341  this);
342  mInvCloseButton = new Button(this,
343  // TRANSLATORS: storage button
344  _("Close"),
345  "close",
346  BUTTON_SKIN,
347  this);
348 
349  mWeightBar = new ProgressBar(this, 0.0F, 100, 0,
351  "weightprogressbar.xml", "weightprogressbar_fill.xml");
352  mWeightBar->setColor(getThemeColor(ThemeColorId::WEIGHT_BAR, 255U),
353  getThemeColor(ThemeColorId::WEIGHT_BAR_OUTLINE, 255U));
354 
355  mSlotsBarCell = &place(3, 0, mSlotsBar, 3, 1);
356  mSortDropDownCell = &place(6, 0, mSortDropDown, 1, 1);
357 
358  mFilterCell = &place(0, 1, mFilter, 7, 1).setPadding(3);
359  mNameFilterCell = &place(6, 1, mNameFilter, 1, 1);
360 
361  place(0, 0, mWeightBar, 3, 1);
362  place(0, 2, invenScroll, 7, 4);
363  place(0, 6, mStoreButton, 1, 1);
364  place(1, 6, mRetrieveButton, 1, 1);
365  place(6, 6, mInvCloseButton, 1, 1);
366  break;
367  }
368 
369  default:
371  case InventoryType::Npc:
377  break;
378  }
379 
380  Layout &layout = getLayout();
381  layout.setRowHeight(2, LayoutType::SET);
382 
384 
385  invInstances.push_back(this);
386 
387  if (inventory->isMainInventory())
388  {
390  }
391  else
392  {
393  if (!invInstances.empty())
394  invInstances.front()->updateDropButton();
395  }
396 
397  loadWindowState();
398  enableVisibleSound(true);
399 }
#define fromBool(val, name)
Definition: booldefines.h:49
const std::string BUTTON_SKIN
Definition: button.h:89
Definition: button.h:102
void setDescription(const std::string &text)
Definition: button.h:165
int getIntValue(const std::string &key) const
void setSelected(int selected)
Definition: dropdown.cpp:514
int getWidth(const std::string &text) const
Definition: font.cpp:334
int mWidth
Definition: graphics.h:484
Button * mRetrieveButton
TabStrip * mFilter
TextField * mNameFilter
static WindowList invInstances
ProgressBar * mSlotsBar
Button * mInvCloseButton
ItemContainer * mItems
Button * mOutfitButton
LayoutCell * mFilterCell
LayoutCell * mSortDropDownCell
Inventory * mInventory
DropDown * mSortDropDown
LayoutCell * mNameFilterCell
LayoutCell * mSlotsBarCell
Button * mEquipmentButton
SortListModelInv * mSortModel
ProgressBar * mWeightBar
bool isMainInventory() const
Definition: inventory.h:179
std::string getName() const
Definition: inventory.cpp:351
InventoryTypeT getType() const
Definition: inventory.h:176
void addInventoyListener(InventoryListener *const listener)
Definition: inventory.cpp:302
void addSelectionListener(SelectionListener *listener)
LayoutCell & setPadding(int p)
Definition: layoutcell.h:60
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:128
Definition: layout.h:45
void setColor(const Color &color1, const Color &color2)
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
void registerWindowForReset(Window *const window)
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
virtual void addButton(const std::string &text, const std::string &tag, const bool pressed)
Definition: widgetgroup.cpp:42
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
Font * getFont() const
Definition: widget.cpp:331
void setSelectable(const bool selectable)
Definition: widget.h:948
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
int getWidth() const
Definition: widget.h:221
void setSaveVisible(const bool save)
Definition: window.h:300
void setResizable(const bool resize)
Definition: window.cpp:627
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1391
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1466
Layout & getLayout()
Definition: window.cpp:1365
void setWindowName(const std::string &name)
Definition: window.h:355
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:109
void setCaption(const std::string &caption)
Definition: window.h:531
void setMinHeight(const int height)
Definition: window.cpp:604
void setMinWidth(const int width)
Definition: window.cpp:591
void enableVisibleSound(bool b)
Definition: window.h:481
const std::string & getWindowName() const
Definition: window.h:361
void setCloseButton(const bool flag)
Definition: window.cpp:749
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:772
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1384
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
Configuration config
const bool ForceQuantity_false
Definition: forcequantity.h:30
#define _(s)
Definition: gettext.h:35
Graphics * mainGraphics
Definition: graphics.cpp:109
const bool LoseFocusOnTab_true
const bool Modal_false
Definition: modal.h:30
int size()
Definition: emotedb.cpp:306
const StringVect & getTags()
Definition: itemdb.cpp:749
bool Opaque
Definition: opaque.h:30
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
const bool ShowEmptyRows_false
Definition: showemptyrows.h:30
std::vector< std::string > StringVect
Definition: stringvector.h:29

References _, Widget::addActionListener(), WidgetGroup::addButton(), Inventory::addInventoyListener(), Widget::addKeyListener(), ItemContainer::addSelectionListener(), BUTTON_SKIN, InventoryType::Cart, ImagePosition::CENTER, config, InventoryType::Craft, Window::enableVisibleSound(), fromBool, Widget::getFont(), Configuration::getIntValue(), Window::getLayout(), Inventory::getName(), Window::getOptionBool(), Window::getPlacer(), ItemDB::getTags(), Widget2::getThemeColor(), Inventory::getType(), Widget::getWidth(), Font::getWidth(), Window::getWindowName(), InventoryType::Inventory, invInstances, Inventory::isMainInventory(), Window::loadWindowState(), InventoryType::MailEdit, InventoryType::MailView, mainGraphics, mCartButton, mDropButton, mEquipmentButton, mFilter, mFilterCell, mInvCloseButton, mInventory, mItems, mNameFilter, mNameFilterCell, mOutfitButton, mRetrieveButton, mShopButton, mSlotsBar, mSlotsBarCell, mSortDropDown, mSortDropDownCell, mStoreButton, mUseButton, mWeightBar, Graphics::mWidth, InventoryType::Npc, Window::place(), ProgressColorId::PROG_WEIGHT, SetupWindow::registerWindowForReset(), LayoutType::SET, Widget::setActionEventId(), Window::setCaption(), Window::setCloseButton(), ProgressBar::setColor(), Window::setDefaultSize(), Button::setDescription(), ScrollArea::setHorizontalScrollPolicy(), Window::setMinHeight(), Window::setMinWidth(), LayoutCell::setPadding(), Window::setResizable(), LayoutCell::setRowHeight(), Window::setSaveVisible(), Widget::setSelectable(), DropDown::setSelected(), Window::setStickyButtonLock(), setupWindow, Window::setWindowName(), ScrollArea::SHOW_NEVER, EmoteDB::size(), InventoryType::Storage, InventoryType::Trade, InventoryType::TypeEnd, updateDropButton(), updateWeight(), and InventoryType::Vending.

◆ ~InventoryWindow()

InventoryWindow::~InventoryWindow ( )

Destructor.

Definition at line 415 of file inventorywindow.cpp.

416 {
417  invInstances.remove(this);
418  if (mInventory != nullptr)
420  if (!invInstances.empty())
421  invInstances.front()->updateDropButton();
422 
423  mSortDropDown->hideDrop(false);
425 }
void hideDrop(bool event)
Definition: dropdown.cpp:378
void removeInventoyListener(InventoryListener *const listener)
Definition: inventory.cpp:307
#define delete2(var)
Definition: delete2.h:25

References delete2, DropDown::hideDrop(), invInstances, mInventory, mSortDropDown, mSortModel, and Inventory::removeInventoyListener().

Member Function Documentation

◆ action()

void InventoryWindow::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 457 of file inventorywindow.cpp.

458 {
459  const std::string &eventId = event.getId();
460  if (eventId == "outfit")
461  {
463  }
464  else if (eventId == "shop")
465  {
467  }
468  else if (eventId == "equipment")
469  {
471  }
472  else if (eventId == "cart")
473  {
475  }
476  else if (eventId == "close")
477  {
478  close();
479  }
480  else if (eventId == "store")
481  {
482  if (inventoryWindow == nullptr || !inventoryWindow->isWindowVisible())
483  return;
484 
485  Item *const item = inventoryWindow->getSelectedItem();
486 
487  if (item == nullptr)
488  return;
489 
490  if (storageWindow != nullptr)
491  {
493  this,
494  item,
495  0,
496  0);
497  }
498  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
499  {
501  this,
502  item,
503  0,
504  0);
505  }
506  }
507  else if (eventId == "sort")
508  {
510  storeSortOrder();
511  return;
512  }
513  else if (eventId == "namefilter")
514  {
516  mItems->updateMatrix();
517  }
518  else if (eventId.find("tag_") == 0U)
519  {
520  std::string tagName = event.getId().substr(4);
521  mItems->setFilter(ItemDB::getTagId(tagName));
522  return;
523  }
524 
525  Item *const item = mItems->getSelectedItem();
526 
527  if (item == nullptr)
528  return;
529 
530  if (eventId == "use")
531  {
533  }
534  if (eventId == "equip")
535  {
537  }
538  else if (eventId == "drop")
539  {
540  if (isStorageActive())
541  {
543  item->getInvIndex(),
544  item->getQuantity(),
546  }
547  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
548  {
550  item->getInvIndex(),
551  item->getQuantity(),
553  }
554  else
555  {
556  if (PlayerInfo::isItemProtected(item->getId()))
557  return;
558 
560  {
561  PlayerInfo::dropItem(item, item->getQuantity(), Sfx_true);
562  }
563  else
564  {
566  this,
567  item,
568  0,
569  0);
570  }
571  }
572  }
573  else if (eventId == "split")
574  {
576  this,
577  item,
578  item->getQuantity() - 1,
579  9);
580  }
581  else if (eventId == "retrieve")
582  {
583  if (storageWindow != nullptr)
584  {
586  this,
587  item,
588  0,
589  0);
590  }
591  else if ((cartWindow != nullptr) && cartWindow->isWindowVisible())
592  {
594  this,
595  item,
596  0,
597  0);
598  }
599  }
600 }
int getSelected() const
Definition: dropdown.cpp:509
void executeAction(const InputActionT keyNum)
bool isActionActive(const InputActionT index) const
void storeSortOrder() const
static bool isStorageActive()
Item * getSelectedItem() const
static void showWindow(const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, int maxRange, const int tag)
void setFilter(const int tag)
void setName(const std::string &str)
Item * getSelectedItem() const
void setSortType(const int sortType)
Definition: item.h:50
int getQuantity() const
Definition: item.h:105
int getInvIndex() const
Definition: item.h:165
int getId() const
Definition: item.h:81
virtual void moveItem2(const InventoryTypeT source, const int slot, const int amount, const InventoryTypeT destination) const =0
const std::string & getText() const
Definition: textfield.h:224
bool isWindowVisible() const
Definition: window.h:484
InputManager inputManager
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
InventoryWindow * inventoryWindow
InventoryWindow * cartWindow
InventoryWindow * storageWindow
@ WINDOW_EQUIPMENT
Definition: inputaction.h:95
int getTagId(const std::string &tagName)
Definition: itemdb.cpp:754
void useEquipItem(const Item *const item, const int16_t useType, const Sfx sfx)
Definition: playerinfo.cpp:262
void dropItem(const Item *const item, const int amount, const Sfx sfx)
Definition: playerinfo.cpp:354
void useEquipItem2(const Item *const item, const int16_t useType, const Sfx sfx)
Definition: playerinfo.cpp:313
bool isItemProtected(const int id)
Definition: playerinfo.cpp:515
const bool Sfx_true
Definition: sfx.h:30

References InventoryType::Cart, ItemAmountWindowUsage::CartAdd, ItemAmountWindowUsage::CartRemove, cartWindow, close(), PlayerInfo::dropItem(), InputManager::executeAction(), Item::getId(), Item::getInvIndex(), Item::getQuantity(), DropDown::getSelected(), ItemContainer::getSelectedItem(), getSelectedItem(), ItemDB::getTagId(), TextField::getText(), inputManager, InventoryType::Inventory, inventoryHandler, inventoryWindow, InputManager::isActionActive(), PlayerInfo::isItemProtected(), isStorageActive(), Window::isWindowVisible(), ItemAmountWindowUsage::ItemDrop, ItemAmountWindowUsage::ItemSplit, mItems, mNameFilter, Net::InventoryHandler::moveItem2(), mSortDropDown, ItemContainer::setFilter(), ItemContainer::setName(), ItemContainer::setSortType(), Sfx_true, ItemAmountWindow::showWindow(), InputAction::STOP_ATTACK, InventoryType::Storage, storageWindow, ItemAmountWindowUsage::StoreAdd, ItemAmountWindowUsage::StoreRemove, storeSortOrder(), ItemContainer::updateMatrix(), PlayerInfo::useEquipItem(), PlayerInfo::useEquipItem2(), InputAction::WINDOW_CART, InputAction::WINDOW_EQUIPMENT, InputAction::WINDOW_OUTFIT, and InputAction::WINDOW_SHOP.

◆ attributeChanged()

void InventoryWindow::attributeChanged ( const AttributesT  id,
const int64_t  oldVal,
const int64_t  newVal 
)
virtual

Implements AttributeListener.

Definition at line 1095 of file inventorywindow.cpp.

1098 {
1099  if (id == Attributes::TOTAL_WEIGHT
1100  || id == Attributes::MAX_WEIGHT
1102  || id == Attributes::CART_MAX_WEIGHT)
1103  {
1104  updateWeight();
1105  }
1106 }
@ CART_TOTAL_WEIGHT
Definition: attributes.h:64
@ CART_MAX_WEIGHT
Definition: attributes.h:65
@ TOTAL_WEIGHT
Definition: attributes.h:39

References Attributes::CART_MAX_WEIGHT, Attributes::CART_TOTAL_WEIGHT, Attributes::MAX_WEIGHT, Attributes::TOTAL_WEIGHT, and updateWeight().

◆ close()

void InventoryWindow::close ( )
virtual

Closes the Storage Window, as well as telling the server that the window has been closed.

Reimplemented from Window.

Definition at line 895 of file inventorywindow.cpp.

896 {
897  if (mInventory == nullptr)
898  {
899  Window::close();
900  return;
901  }
902 
903  switch (mInventory->getType())
904  {
906  case InventoryType::Cart:
908  break;
909 
911  if (inventoryHandler != nullptr)
912  {
915  }
916  scheduleDelete();
917  break;
918 
919  default:
921  case InventoryType::Npc:
927  break;
928  }
929 }
void setVisible(Visible visible)
virtual void forgotStorage() const =0
virtual void closeStorage() const =0
virtual void close()
Definition: window.cpp:902
virtual void scheduleDelete()
Definition: window.cpp:831
const bool Visible_false
Definition: visible.h:30

References InventoryType::Cart, Window::close(), Net::InventoryHandler::closeStorage(), InventoryType::Craft, Net::InventoryHandler::forgotStorage(), Inventory::getType(), InventoryType::Inventory, inventoryHandler, InventoryType::MailEdit, InventoryType::MailView, mInventory, InventoryType::Npc, Window::scheduleDelete(), setVisible(), InventoryType::Storage, InventoryType::Trade, InventoryType::TypeEnd, InventoryType::Vending, and Visible_false.

Referenced by action(), Ea::InventoryHandler::destroyStorage(), Ea::InventoryRecv::processPlayerStorageClose(), and Ea::InventoryHandler::~InventoryHandler().

◆ combineItems()

void InventoryWindow::combineItems ( const int  index1,
const int  index2 
)

Definition at line 1108 of file inventorywindow.cpp.

1110 {
1111  if (mInventory == nullptr)
1112  return;
1113  const Item *item1 = mInventory->getItem(index1);
1114  if (item1 == nullptr)
1115  return;
1116  const Item *item2 = mInventory->getItem(index2);
1117  if (item2 == nullptr)
1118  return;
1119 
1120  if (item1->getType() != ItemType::Card)
1121  {
1122  const Item *tmpItem = item1;
1123  item1 = item2;
1124  item2 = tmpItem;
1125  }
1126 
1128  // TRANSLATORS: question dialog title
1129  _("Insert card request"),
1130  // TRANSLATORS: question dialog message
1131  strprintf(_("Insert %s into %s?"),
1132  item1->getName().c_str(),
1133  item2->getName().c_str()),
1134  SOUND_REQUEST,
1135  false,
1136  Modal_true,
1137  nullptr);
1141 }
Item * getItem(const int index) const
Definition: inventory.cpp:83
std::string getName() const
Definition: item.cpp:140
ItemTypeT getType() const
Definition: item.h:225
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
InsertCardListener insertCardListener
const bool Modal_true
Definition: modal.h:30
@ Card
Definition: itemtype.h:35
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:49
static const std::string SOUND_REQUEST
Definition: sound.h:29
std::string strprintf(const char *const format,...)

References _, Widget::addActionListener(), ItemType::Card, InsertCardListener::cardIndex, confirmDlg, CREATEWIDGETR, Item::getInvIndex(), Inventory::getItem(), Item::getName(), Item::getType(), insertCardListener, InsertCardListener::itemIndex, mInventory, Modal_true, SOUND_REQUEST, and strprintf().

Referenced by ItemContainer::mouseReleased().

◆ getFirstVisible()

InventoryWindow * InventoryWindow::getFirstVisible ( )
static

Definition at line 1019 of file inventorywindow.cpp.

1020 {
1021  std::set<Widget*> list;
1022  FOR_EACH (WindowList::const_iterator, it, invInstances)
1023  {
1024  if (((*it) != nullptr) && (*it)->isWindowVisible())
1025  list.insert(*it);
1026  }
1027  return dynamic_cast<InventoryWindow*>(
1029 }
Widget * findFirstWidget(const std::set< Widget * > &list)
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
WindowContainer * windowContainer

References BasicContainer::findFirstWidget(), FOR_EACH, invInstances, and windowContainer.

Referenced by nextTab(), and prevTab().

◆ getSelectedItem()

Item * InventoryWindow::getSelectedItem ( ) const

Returns the selected item.

Definition at line 602 of file inventorywindow.cpp.

603 {
604  return mItems->getSelectedItem();
605 }

References ItemContainer::getSelectedItem(), and mItems.

Referenced by action(), MailEditWindow::action(), NpcDialog::action(), and TradeWindow::action().

◆ isAnyInputFocused()

bool InventoryWindow::isAnyInputFocused ( )
static

Definition at line 1009 of file inventorywindow.cpp.

1010 {
1011  FOR_EACH (WindowList::const_iterator, it, invInstances)
1012  {
1013  if (((*it) != nullptr) && (*it)->isInputFocused())
1014  return true;
1015  }
1016  return false;
1017 }

References FOR_EACH, and invInstances.

Referenced by Game::handleMove(), and InputManager::updateConditionMask().

◆ isInputFocused()

bool InventoryWindow::isInputFocused ( ) const

Definition at line 1004 of file inventorywindow.cpp.

1005 {
1006  return (mNameFilter != nullptr) && mNameFilter->isFocused();
1007 }
virtual bool isFocused() const
Definition: widget.cpp:184

References Widget::isFocused(), and mNameFilter.

◆ isMainInventory()

bool InventoryWindow::isMainInventory ( ) const
inline

Definition at line 129 of file inventorywindow.h.

130  {
131  return mInventory != nullptr ?
132  mInventory->isMainInventory() : false;
133  }

References Inventory::isMainInventory(), and mInventory.

◆ isStorageActive()

static bool InventoryWindow::isStorageActive ( )
inlinestatic

Returns true if any instances exist.

Definition at line 138 of file inventorywindow.h.

139  { return storageWindow != nullptr; }
InventoryWindow * storageWindow

References storageWindow.

Referenced by action(), PlayerInfo::isTalking(), mouseClicked(), PopupMenu::showDropPopup(), PopupMenu::showItemPopup(), PopupMenu::showPopup(), InputManager::updateConditionMask(), and updateDropButton().

◆ keyPressed()

void InventoryWindow::keyPressed ( KeyEvent event)
virtual

Handles the key presses.

Reimplemented from KeyListener.

Definition at line 818 of file inventorywindow.cpp.

819 {
820  if (event.getActionId() == InputAction::GUI_MOD)
821  mSplit = true;
822 }
InputActionT getActionId() const
Definition: keyevent.h:127

References KeyEvent::getActionId(), InputAction::GUI_MOD, and mSplit.

◆ keyReleased()

void InventoryWindow::keyReleased ( KeyEvent event)
virtual

Handles the key releases.

Reimplemented from KeyListener.

Definition at line 824 of file inventorywindow.cpp.

825 {
826  if (event.getActionId() == InputAction::GUI_MOD)
827  mSplit = false;
828 }

References KeyEvent::getActionId(), InputAction::GUI_MOD, and mSplit.

◆ mouseClicked()

void InventoryWindow::mouseClicked ( MouseEvent event)
virtual

Handles the mouse clicks.

Reimplemented from MouseListener.

Definition at line 619 of file inventorywindow.cpp.

620 {
621  Window::mouseClicked(event);
622 
623  const int clicks = event.getClickCount();
624 
625  if (clicks == 2 && (gui != nullptr))
626  gui->resetClickCount();
627 
628  const bool mod = (isStorageActive() &&
630 
631  const bool mod2 = (tradeWindow != nullptr &&
634 
635  if (mInventory != nullptr)
636  {
637  if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT)
638  {
639  Item *const item = mItems->getSelectedItem();
640 
641  if (item == nullptr)
642  return;
643 
644  /* Convert relative to the window coordinates to absolute screen
645  * coordinates.
646  */
647  if (popupMenu != nullptr)
648  {
649  const int mx = event.getX() + getX();
650  const int my = event.getY() + getY();
651 
652  popupMenu->showPopup(this,
653  mx, my,
654  item,
655  mInventory->getType());
656  }
657  }
658  }
659  else
660  {
661  return;
662  }
663 
664  if (event.getButton() == MouseButton::LEFT ||
665  event.getButton() == MouseButton::RIGHT)
666  {
667  Item *const item = mItems->getSelectedItem();
668 
669  if (item == nullptr)
670  return;
671 
672  if (mod)
673  {
675  {
676  if (event.getButton() == MouseButton::RIGHT)
677  {
681  item,
682  0,
683  0);
684  }
685  else
686  {
688  item->getInvIndex(),
689  item->getQuantity(),
691  }
692  }
693  else
694  {
695  if (event.getButton() == MouseButton::RIGHT)
696  {
700  item,
701  0,
702  0);
703  }
704  else
705  {
707  item->getInvIndex(),
708  item->getQuantity(),
710  }
711  }
712  }
713  else if (mod2 && mInventory->isMainInventory())
714  {
715  if (PlayerInfo::isItemProtected(item->getId()))
716  return;
717  if (event.getButton() == MouseButton::RIGHT)
718  {
720  tradeWindow,
721  item,
722  0,
723  0);
724  }
725  else
726  {
727  if (tradeWindow != nullptr)
728  tradeWindow->tradeItem(item, item->getQuantity(), true);
729  }
730  }
731  else if (clicks == 2)
732  {
734  {
735  if (isStorageActive())
736  {
740  item,
741  0,
742  0);
743  }
744  else if (tradeWindow != nullptr &&
746  {
747  if (PlayerInfo::isItemProtected(item->getId()))
748  return;
751  tradeWindow,
752  item,
753  0,
754  0);
755  }
756  else
757  {
759  }
760  }
761  else
762  {
763  if (isStorageActive())
764  {
768  item,
769  0,
770  0);
771  }
772  }
773  }
774  }
775 }
void resetClickCount()
Definition: gui.cpp:980
MouseButtonT getButton() const
Definition: mouseevent.h:116
virtual void mouseClicked(MouseEvent &event)
void showPopup(const int x, const int y, const Being *const being)
Definition: popupmenu.cpp:203
void tradeItem(const Item *const item, const int quantity, const bool check) const
int getY() const
Definition: widget.h:288
int getX() const
Definition: widget.h:269
Gui * gui
Definition: gui.cpp:111
PopupMenu * popupMenu
Definition: popupmenu.cpp:103
TradeWindow * tradeWindow
Definition: tradewindow.cpp:65

References MouseEvent::getButton(), Item::getId(), Item::getInvIndex(), Item::getQuantity(), ItemContainer::getSelectedItem(), Inventory::getType(), Widget::getX(), Widget::getY(), gui, inputManager, InventoryType::Inventory, inventoryHandler, inventoryWindow, InputManager::isActionActive(), PlayerInfo::isItemProtected(), Inventory::isMainInventory(), isStorageActive(), Window::isWindowVisible(), MouseButton::LEFT, mInventory, mItems, MouseListener::mouseClicked(), Net::InventoryHandler::moveItem2(), popupMenu, Gui::resetClickCount(), MouseButton::RIGHT, Sfx_true, PopupMenu::showPopup(), ItemAmountWindow::showWindow(), InputAction::STOP_ATTACK, InventoryType::Storage, ItemAmountWindowUsage::StoreAdd, ItemAmountWindowUsage::StoreRemove, ItemAmountWindowUsage::TradeAdd, TradeWindow::tradeItem(), tradeWindow, and PlayerInfo::useEquipItem().

◆ mouseExited()

void InventoryWindow::mouseExited ( MouseEvent event)
virtual

When the mouse leaves the window this ensures that the custom cursor is restored back to it's standard image.

Reimplemented from Window.

Definition at line 813 of file inventorywindow.cpp.

814 {
815  textPopup->hide();
816 }
void hide()
Definition: popup.cpp:265
TextPopup * textPopup
Definition: textpopup.cpp:33

References Popup::hide(), and textPopup.

◆ mouseMoved()

void InventoryWindow::mouseMoved ( MouseEvent event)
virtual

Implements custom cursor image changing context, based on mouse relative position.

Reimplemented from Window.

Definition at line 777 of file inventorywindow.cpp.

778 {
779  Window::mouseMoved(event);
780  if (textPopup == nullptr)
781  return;
782 
783  const Widget *const src = event.getSource();
784  if (src == nullptr)
785  {
786  textPopup->hide();
787  return;
788  }
789  const int x = event.getX();
790  const int y = event.getY();
791  const Rect &rect = mDimension;
792  if (src == mSlotsBar || src == mWeightBar)
793  {
794  // TRANSLATORS: money label
795  textPopup->show(rect.x + x, rect.y + y, strprintf(_("Money: %s"),
797  Attributes::MONEY)).c_str()));
798  }
799  else
800  {
801  const Button *const btn = dynamic_cast<const Button *>(src);
802  if (btn == nullptr)
803  {
804  textPopup->hide();
805  return;
806  }
807  const std::string text = btn->getDescription();
808  if (!text.empty())
809  textPopup->show(x + rect.x, y + rect.y, text);
810  }
811 }
std::string getDescription() const
Definition: button.h:168
Definition: rect.h:74
int y
Definition: rect.h:214
int x
Definition: rect.h:209
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:57
Definition: widget.h:99
Rect mDimension
Definition: widget.h:1101
void mouseMoved(MouseEvent &event)
Definition: window.cpp:967
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:324

References _, UnitsDb::formatCurrency(), PlayerInfo::getAttribute(), Button::getDescription(), Popup::hide(), Widget::mDimension, Attributes::MONEY, Window::mouseMoved(), mSlotsBar, mWeightBar, TextPopup::show(), strprintf(), textPopup, Rect::x, x, Rect::y, and y.

◆ moveItemToCraft()

void InventoryWindow::moveItemToCraft ( const int  craftSlot)

Definition at line 1143 of file inventorywindow.cpp.

1144 {
1145  if (npcHandler == nullptr)
1146  return;
1147 
1148  Item *const item = mItems->getSelectedItem();
1149  if (item == nullptr)
1150  return;
1151 
1152  NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
1153  if ((dialog != nullptr) &&
1155  {
1156  if (item->getQuantity() > 1
1158  {
1161  item,
1162  0,
1163  craftSlot);
1164  }
1165  else
1166  {
1167  dialog->addCraftItem(item, 1, craftSlot);
1168  }
1169  }
1170 }
virtual NpcDialog * getCurrentNpcDialog() const =0
NpcInputStateT getInputState()
Definition: npcdialog.h:237
void addCraftItem(Item *const item, const int amount, const int slot)
Definition: npcdialog.cpp:1382
Net::NpcHandler * npcHandler
Definition: net.cpp:93

References NpcDialog::addCraftItem(), ItemAmountWindowUsage::CraftAdd, Net::NpcHandler::getCurrentNpcDialog(), NpcDialog::getInputState(), Item::getQuantity(), ItemContainer::getSelectedItem(), inputManager, InputManager::isActionActive(), NpcInputState::ITEM_CRAFT, mItems, npcHandler, ItemAmountWindow::showWindow(), and InputAction::STOP_ATTACK.

◆ nextTab()

void InventoryWindow::nextTab ( )
static

Definition at line 1031 of file inventorywindow.cpp.

1032 {
1033  const InventoryWindow *const window = getFirstVisible();
1034  if (window != nullptr)
1035  window->mFilter->nextTab();
1036 }
static InventoryWindow * getFirstVisible()
void nextTab()
Definition: tabstrip.cpp:90

References getFirstVisible(), mFilter, and TabStrip::nextTab().

◆ postInit()

void InventoryWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 401 of file inventorywindow.cpp.

402 {
405 
407  widgetResized(Event(nullptr));
408  if (mInventory != nullptr &&
410  {
412  }
413 }
Definition: event.h:79
void widgetResized(const Event &event)
void slotsChanged(const Inventory *const inventory)
void postInit()
Definition: window.cpp:249
const bool Visible_true
Definition: visible.h:30

References DropDown::getSelected(), Inventory::getType(), mInventory, mItems, mSortDropDown, Window::postInit(), ItemContainer::setSortType(), setVisible(), slotsChanged(), InventoryType::Storage, Visible_true, and widgetResized().

◆ prevTab()

void InventoryWindow::prevTab ( )
static

Definition at line 1038 of file inventorywindow.cpp.

1039 {
1040  const InventoryWindow *const window = getFirstVisible();
1041  if (window != nullptr)
1042  window->mFilter->prevTab();
1043 }
void prevTab()
Definition: tabstrip.cpp:108

References getFirstVisible(), mFilter, and TabStrip::prevTab().

◆ setVisible()

void InventoryWindow::setVisible ( Visible  visible)
virtual

Overloads window setVisible by Guichan to allow sticky window handling.

Reimplemented from Window.

Definition at line 1077 of file inventorywindow.cpp.

1078 {
1079  if (visible == Visible_false)
1080  mSortDropDown->hideDrop(true);
1081  Window::setVisible(visible);
1082 }
virtual void setVisible(Visible visible)
Definition: window.cpp:778

References DropDown::hideDrop(), mSortDropDown, Window::setVisible(), and Visible_false.

Referenced by TradeWindow::action(), close(), and postInit().

◆ slotsChanged()

void InventoryWindow::slotsChanged ( const Inventory *const  inventory)
virtual

Implements InventoryListener.

Definition at line 959 of file inventorywindow.cpp.

960 {
961  if (inventory == mInventory)
962  {
963  const int usedSlots = mInventory->getNumberOfSlotsUsed();
964  const int maxSlots = mInventory->getSize();
965 
966  if (maxSlots != 0)
967  {
968  mSlotsBar->setProgress(static_cast<float>(usedSlots)
969  / static_cast<float>(maxSlots));
970  }
971 
972  mSlotsBar->setText(strprintf("%d/%d", usedSlots, maxSlots));
973  mItems->updateMatrix();
974  }
975 }
unsigned getSize() const
Definition: inventory.h:76
int getNumberOfSlotsUsed() const
Definition: inventory.h:164
void setProgress(const float progress)
void setText(const std::string &str)

References Inventory::getNumberOfSlotsUsed(), Inventory::getSize(), mInventory, mItems, mSlotsBar, ProgressBar::setProgress(), ProgressBar::setText(), strprintf(), and ItemContainer::updateMatrix().

Referenced by postInit().

◆ storeSortOrder()

void InventoryWindow::storeSortOrder ( ) const

Definition at line 427 of file inventorywindow.cpp.

428 {
429  if (mInventory != nullptr)
430  {
431  switch (mInventory->getType())
432  {
435  case InventoryType::Npc:
441  default:
442  config.setValue("inventorySortOrder",
444  break;
446  config.setValue("storageSortOrder",
448  break;
449  case InventoryType::Cart:
450  config.setValue("cartSortOrder",
452  break;
453  }
454  }
455 }
void setValue(const std::string &key, const std::string &value)

References InventoryType::Cart, config, InventoryType::Craft, DropDown::getSelected(), Inventory::getType(), InventoryType::Inventory, InventoryType::MailEdit, InventoryType::MailView, mInventory, mSortDropDown, InventoryType::Npc, Configuration::setValue(), InventoryType::Storage, InventoryType::Trade, InventoryType::TypeEnd, and InventoryType::Vending.

Referenced by action().

◆ unselectItem()

void InventoryWindow::unselectItem ( )

Unselect item

Definition at line 607 of file inventorywindow.cpp.

608 {
609  mItems->selectNone();
610 }

References mItems, and ItemContainer::selectNone().

Referenced by ItemShortcutContainer::mousePressed().

◆ unsetInventory()

void InventoryWindow::unsetInventory ( )

Definition at line 1084 of file inventorywindow.cpp.

1085 {
1086  if (mInventory != nullptr)
1087  {
1089  if (mItems != nullptr)
1091  }
1092  mInventory = nullptr;
1093 }
void unsetInventory()

References mInventory, mItems, Inventory::removeInventoyListener(), and ItemContainer::unsetInventory().

Referenced by Ea::InventoryHandler::destroyStorage(), and Ea::InventoryRecv::processPlayerStorageClose().

◆ updateButtons()

void InventoryWindow::updateButtons ( const Item item)

Definition at line 849 of file inventorywindow.cpp.

850 {
851  if ((mInventory == nullptr) || !mInventory->isMainInventory())
852  return;
853 
854  const Item *const selectedItem = mItems->getSelectedItem();
855  if ((item != nullptr) && selectedItem != item)
856  return;
857 
858  if (item == nullptr)
859  item = selectedItem;
860 
861  if ((item == nullptr) || item->getQuantity() == 0)
862  {
863  if (mUseButton != nullptr)
864  mUseButton->setEnabled(false);
865  if (mDropButton != nullptr)
866  mDropButton->setEnabled(false);
867  return;
868  }
869 
870  if (mDropButton != nullptr)
871  mDropButton->setEnabled(true);
872 
873  if (mUseButton != nullptr)
874  {
875  const ItemInfo &info = item->getInfo();
876  const std::string &str = (item->isEquipment() == Equipm_true
877  && item->isEquipped() == Equipped_true)
878  ? info.getUseButton2() : info.getUseButton();
879  if (str.empty())
880  {
881  mUseButton->setEnabled(false);
882  // TRANSLATORS: default use button name
883  mUseButton->setCaption(_("Use"));
884  }
885  else
886  {
887  mUseButton->setEnabled(true);
888  mUseButton->setCaption(str);
889  }
890  }
891 
893 }
void setCaption(const std::string &caption)
Definition: button.h:214
Equipm isEquipment() const
Definition: item.h:117
Equipped isEquipped() const
Definition: item.h:129
const ItemInfo & getInfo() const
Definition: item.h:171
void setEnabled(const bool enabled)
Definition: widget.h:352
const bool Equipm_true
Definition: equipm.h:30
const bool Equipped_true
Definition: equipped.h:30
bool info(InputEvent &event)
Definition: commands.cpp:57

References _, Equipm_true, Equipped_true, Item::getInfo(), Item::getQuantity(), ItemContainer::getSelectedItem(), Actions::info(), Item::isEquipment(), Item::isEquipped(), Inventory::isMainInventory(), mDropButton, mInventory, mItems, mUseButton, Button::setCaption(), Widget::setEnabled(), and updateDropButton().

Referenced by Ea::EquipBackend::setEquipment(), and valueChanged().

◆ updateDropButton()

void InventoryWindow::updateDropButton ( )

Definition at line 977 of file inventorywindow.cpp.

978 {
979  if (mDropButton == nullptr)
980  return;
981 
982  if (isStorageActive() ||
983  (cartWindow != nullptr && cartWindow->isWindowVisible()))
984  {
985  // TRANSLATORS: inventory button
986  mDropButton->setCaption(_("Store"));
987  }
988  else
989  {
990  const Item *const item = mItems->getSelectedItem();
991  if ((item != nullptr) && item->getQuantity() > 1)
992  {
993  // TRANSLATORS: inventory button
994  mDropButton->setCaption(_("Drop..."));
995  }
996  else
997  {
998  // TRANSLATORS: inventory button
999  mDropButton->setCaption(_("Drop"));
1000  }
1001  }
1002 }

References _, cartWindow, Item::getQuantity(), ItemContainer::getSelectedItem(), isStorageActive(), Window::isWindowVisible(), mDropButton, mItems, and Button::setCaption().

Referenced by InventoryWindow(), and updateButtons().

◆ updateWeight()

void InventoryWindow::updateWeight ( )
private

Updates the weight bar.

Definition at line 931 of file inventorywindow.cpp.

932 {
933  if ((mInventory == nullptr) || (mWeightBar == nullptr))
934  return;
935  const InventoryTypeT type = mInventory->getType();
936  if (type != InventoryType::Inventory &&
937  type != InventoryType::Cart)
938  {
939  return;
940  }
941 
942  const bool isInv = type == InventoryType::Inventory;
943  const int total = PlayerInfo::getAttribute(isInv
945  const int max = PlayerInfo::getAttribute(isInv
947 
948  if (max <= 0)
949  return;
950 
951  // Adjust progress bar
952  mWeightBar->setProgress(static_cast<float>(total)
953  / static_cast<float>(max));
954  mWeightBar->setText(strprintf("%s/%s",
955  UnitsDb::formatWeight(total).c_str(),
956  UnitsDb::formatWeight(max).c_str()));
957 }
InventoryType ::T InventoryTypeT
Definition: inventorytype.h:42
std::string formatWeight(const int value)
Definition: unitsdb.cpp:352

References InventoryType::Cart, Attributes::CART_MAX_WEIGHT, Attributes::CART_TOTAL_WEIGHT, UnitsDb::formatWeight(), PlayerInfo::getAttribute(), Inventory::getType(), InventoryType::Inventory, Attributes::MAX_WEIGHT, mInventory, mWeightBar, ProgressBar::setProgress(), ProgressBar::setText(), strprintf(), and Attributes::TOTAL_WEIGHT.

Referenced by attributeChanged(), and InventoryWindow().

◆ valueChanged()

void InventoryWindow::valueChanged ( const SelectionEvent event)
virtual

Updates labels to currently selected item.

Reimplemented from SelectionListener.

Definition at line 830 of file inventorywindow.cpp.

831 {
832  if ((mInventory == nullptr) || !mInventory->isMainInventory())
833  return;
834 
835  Item *const item = mItems->getSelectedItem();
836 
837  if (mSplit && (item != nullptr) && inventoryHandler->
838  canSplit(mItems->getSelectedItem()))
839  {
841  this,
842  item,
843  item->getQuantity() - 1,
844  0);
845  }
846  updateButtons(item);
847 }
void updateButtons(const Item *item)

References Item::getQuantity(), ItemContainer::getSelectedItem(), inventoryHandler, Inventory::isMainInventory(), ItemAmountWindowUsage::ItemSplit, mInventory, mItems, mSplit, ItemAmountWindow::showWindow(), and updateButtons().

◆ widgetHidden()

void InventoryWindow::widgetHidden ( const Event event)
virtual

Handles closing of the window

Reimplemented from Window.

Definition at line 612 of file inventorywindow.cpp.

613 {
614  Window::widgetHidden(event);
615  if (itemPopup != nullptr)
617 }
void setVisible(Visible visible)
Definition: widget.cpp:225
void widgetHidden(const Event &event)
Definition: window.cpp:725
ItemPopup * itemPopup
Definition: itempopup.cpp:64

References itemPopup, Widget::setVisible(), Visible_false, and Window::widgetHidden().

◆ widgetResized()

void InventoryWindow::widgetResized ( const Event event)
virtual

Called whenever the widget changes size.

Reimplemented from Window.

Definition at line 1045 of file inventorywindow.cpp.

1046 {
1047  Window::widgetResized(event);
1048 
1049  if (mInventory == nullptr)
1050  return;
1051  const InventoryTypeT type = mInventory->getType();
1052  if (type != InventoryType::Inventory &&
1053  type != InventoryType::Cart)
1054  {
1055  return;
1056  }
1057 
1058  if (getWidth() < 600)
1059  {
1060  if (!mCompactMode)
1061  {
1065  mCompactMode = true;
1066  }
1067  }
1068  else if (mCompactMode)
1069  {
1073  mCompactMode = false;
1074  }
1075 }
void setType(int t)
Definition: layoutcell.h:134
void setWidth(const int w)
Definition: layoutcell.h:143
int getWidth() const
Definition: layoutcell.h:137
void widgetResized(const Event &event)
Definition: window.cpp:655

References InventoryType::Cart, Inventory::getType(), LayoutCell::getWidth(), Widget::getWidth(), InventoryType::Inventory, mCompactMode, mFilterCell, mInventory, mNameFilter, mNameFilterCell, LayoutCell::NONE, LayoutCell::setType(), Widget::setVisible(), LayoutCell::setWidth(), Visible_false, Visible_true, LayoutCell::WIDGET, and Window::widgetResized().

Referenced by postInit().

Field Documentation

◆ invInstances

InventoryWindow::WindowList InventoryWindow::invInstances
staticprivate

◆ mCartButton

Button* InventoryWindow::mCartButton
private

Definition at line 190 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mCompactMode

bool InventoryWindow::mCompactMode
private

Definition at line 208 of file inventorywindow.h.

Referenced by widgetResized().

◆ mDropButton

Button* InventoryWindow::mDropButton
private

Definition at line 187 of file inventorywindow.h.

Referenced by InventoryWindow(), updateButtons(), and updateDropButton().

◆ mEquipmentButton

Button* InventoryWindow::mEquipmentButton
private

Definition at line 191 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mFilter

TabStrip* InventoryWindow::mFilter
private

Definition at line 198 of file inventorywindow.h.

Referenced by InventoryWindow(), nextTab(), and prevTab().

◆ mFilterCell

LayoutCell* InventoryWindow::mFilterCell
private

Definition at line 204 of file inventorywindow.h.

Referenced by InventoryWindow(), and widgetResized().

◆ mInvCloseButton

Button* InventoryWindow::mInvCloseButton
private

Definition at line 194 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mInventory

Inventory* InventoryWindow::mInventory
private

◆ mItems

ItemContainer* InventoryWindow::mItems
private

◆ mNameFilter

TextField* InventoryWindow::mNameFilter
private

Definition at line 201 of file inventorywindow.h.

Referenced by action(), InventoryWindow(), isInputFocused(), and widgetResized().

◆ mNameFilterCell

LayoutCell* InventoryWindow::mNameFilterCell
private

Definition at line 203 of file inventorywindow.h.

Referenced by InventoryWindow(), and widgetResized().

◆ mOutfitButton

Button* InventoryWindow::mOutfitButton
private

Definition at line 188 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mRetrieveButton

Button* InventoryWindow::mRetrieveButton
private

Definition at line 193 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mShopButton

Button* InventoryWindow::mShopButton
private

Definition at line 189 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mSlotsBar

ProgressBar* InventoryWindow::mSlotsBar
private

Definition at line 197 of file inventorywindow.h.

Referenced by InventoryWindow(), mouseMoved(), and slotsChanged().

◆ mSlotsBarCell

LayoutCell* InventoryWindow::mSlotsBarCell
private

Definition at line 205 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mSortDropDown

DropDown* InventoryWindow::mSortDropDown
private

◆ mSortDropDownCell

LayoutCell* InventoryWindow::mSortDropDownCell
private

Definition at line 202 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mSortModel

SortListModelInv* InventoryWindow::mSortModel
private

Definition at line 199 of file inventorywindow.h.

Referenced by ~InventoryWindow().

◆ mSplit

bool InventoryWindow::mSplit
private

Definition at line 207 of file inventorywindow.h.

Referenced by keyPressed(), keyReleased(), and valueChanged().

◆ mStoreButton

Button* InventoryWindow::mStoreButton
private

Definition at line 192 of file inventorywindow.h.

Referenced by InventoryWindow().

◆ mUseButton

Button* InventoryWindow::mUseButton
private

Definition at line 186 of file inventorywindow.h.

Referenced by InventoryWindow(), and updateButtons().

◆ mWeightBar

ProgressBar* InventoryWindow::mWeightBar
private

Definition at line 196 of file inventorywindow.h.

Referenced by InventoryWindow(), mouseMoved(), and updateWeight().


The documentation for this class was generated from the following files: