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

#include <itemamountwindow.h>

Inheritance diagram for ItemAmountWindow:
Window ActionListener KeyListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

void postInit ()
 
void action (const ActionEvent &event)
 
void resetAmount ()
 
void mouseMoved (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void close ()
 
void keyReleased (KeyEvent &event)
 
 ~ItemAmountWindow ()
 
- 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 widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (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
 
virtual void setVisible (Visible visible)
 
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 mouseClicked (MouseEvent &event)
 
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 ()
 
virtual void keyPressed (KeyEvent &event)
 

Static Public Member Functions

static void showWindow (const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, int maxRange, const int tag)
 
- 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)
 

Private Member Functions

 ItemAmountWindow (const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, const int maxRange)
 

Static Private Member Functions

static void finish (Item *const item, const int amount, const int price, const ItemAmountWindowUsageT usage)
 

Private Attributes

IntTextFieldmItemAmountTextField
 
IntTextFieldmItemPriceTextField
 
LabelmGPLabel
 
ItemmItem
 
IconmItemIcon
 
SlidermItemAmountSlide
 
SlidermItemPriceSlide
 
DropDownmItemDropDown
 
ItemsModalmItemsModal
 
int mPrice
 
int mMax
 
ItemAmountWindowUsageT mUsage
 
bool mEnabledKeyboard
 

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 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

Window used for selecting the amount of items to drop, trade or split.

Definition at line 47 of file itemamountwindow.h.

Constructor & Destructor Documentation

◆ ~ItemAmountWindow()

ItemAmountWindow::~ItemAmountWindow ( )

Definition at line 353 of file itemamountwindow.cpp.

354 {
356 }
ItemsModal * mItemsModal
#define delete2(var)
Definition: delete2.h:25

References delete2, and mItemsModal.

◆ ItemAmountWindow()

ItemAmountWindow::ItemAmountWindow ( const ItemAmountWindowUsageT  usage,
Window *const  parent,
Item *const  item,
const int  maxRange 
)
private

Item amount caption.

Definition at line 132 of file itemamountwindow.cpp.

135  :
136  Window("", Modal_false, parent, "amount.xml"),
137  ActionListener(),
138  KeyListener(),
139  mItemAmountTextField(new IntTextField(this, 1, 0, 0, Enable_true, 0)),
140  mItemPriceTextField(nullptr),
141  mGPLabel(nullptr),
142  mItem(item),
143  mItemIcon(new Icon(this,
144  item != nullptr ? item->getImage() : nullptr, AutoRelease_false)),
145  mItemAmountSlide(new Slider(this, 1.0, maxRange, 1.0)),
146  mItemPriceSlide(nullptr),
147  mItemDropDown(nullptr),
148  mItemsModal(nullptr),
149  mPrice(0),
150  mMax(maxRange),
151  mUsage(usage),
153 {
154  if (mItem == nullptr)
155  return;
156 
158  mMax = 10000;
159  else if (mMax == 0)
160  mMax = mItem->getQuantity();
161 
162  keyboard.setEnabled(false);
163 
167 
171 
174  {
175  mItemPriceTextField = new IntTextField(this, 1, 0, 0, Enable_true, 0);
176  mItemPriceTextField->setRange(1, 10000000);
179 
180  mItemPriceSlide = new Slider(this, 1.0, 10000000, 1.0);
182  mItemPriceSlide->setActionEventId("slidePrice");
184 
185  mGPLabel = new Label(this, " GP");
186  }
187 
189  {
190  mItemsModal = new ItemsModal;
191  mItemDropDown = new DropDown(this,
192  mItemsModal,
193  false,
194  Modal_false,
195  nullptr,
196  std::string());
197  mItemDropDown->setActionEventId("itemType");
199  }
200 
201  // Buttons
202  Button *const minusAmountButton = new Button(this,
203  // TRANSLATORS: item amount window button
204  _("-"),
205  "dec",
206  BUTTON_SKIN,
207  this);
208  Button *const plusAmountButton = new Button(this,
209  // TRANSLATORS: item amount window button
210  _("+"),
211  "inc",
212  BUTTON_SKIN,
213  this);
214  Button *const okButton = new Button(this,
215  // TRANSLATORS: item amount window button
216  _("OK"),
217  "ok",
218  BUTTON_SKIN,
219  this);
220  Button *const cancelButton = new Button(this,
221  // TRANSLATORS: item amount window button
222  _("Cancel"),
223  "cancel",
224  BUTTON_SKIN,
225  this);
226  Button *const addAllButton = new Button(this,
227  // TRANSLATORS: item amount window button
228  _("All"),
229  "all",
230  BUTTON_SKIN,
231  this);
232 
233  minusAmountButton->adjustSize();
234  minusAmountButton->setWidth(plusAmountButton->getWidth());
235 
236  // Set positions
237  ContainerPlacer placer(nullptr, nullptr);
238  placer = getPlacer(0, 0);
239  int n = 0;
241  {
242  placer(0, n, mItemDropDown, 8, 1);
243  n++;
244  }
245  placer(1, n, minusAmountButton, 1, 1);
246  placer(2, n, mItemAmountTextField, 3, 1);
247  placer(5, n, plusAmountButton, 1, 1);
248  placer(6, n, addAllButton, 1, 1);
249 
250  placer(0, n, mItemIcon, 1, 3);
251  placer(1, n + 1, mItemAmountSlide, 7, 1);
252 
255  {
256  Button *const minusPriceButton = new Button(this,
257  // TRANSLATORS: item amount window button
258  _("-"),
259  "decPrice",
260  BUTTON_SKIN,
261  this);
262  Button *const plusPriceButton = new Button(this,
263  // TRANSLATORS: item amount window button
264  _("+"),
265  "incPrice",
266  BUTTON_SKIN,
267  this);
268  minusPriceButton->adjustSize();
269  minusPriceButton->setWidth(plusPriceButton->getWidth());
270 
271  placer(1, n + 2, minusPriceButton, 1, 1);
272  placer(2, n + 2, mItemPriceTextField, 3, 1);
273  placer(5, n + 2, plusPriceButton, 1, 1);
274  placer(6, n + 2, mGPLabel, 1, 1);
275 
276  placer(1, n + 3, mItemPriceSlide, 7, 1);
277  placer(4, n + 5, cancelButton, 1, 1);
278  placer(5, n + 5, okButton, 1, 1);
279  }
280  else
281  {
282  placer(4, n + 2, cancelButton, 1, 1);
283  placer(5, n + 2, okButton, 1, 1);
284  }
285 
286  reflowLayout(225, 0);
287 
288  resetAmount();
289 
290  switch (usage)
291  {
293  // TRANSLATORS: amount window message
294  setCaption(_("Select amount of items to trade."));
295  break;
297  // TRANSLATORS: amount window message
298  setCaption(_("Select amount of items to drop."));
299  break;
301  // TRANSLATORS: amount window message
302  setCaption(_("Select amount of items to store."));
303  break;
305  // TRANSLATORS: amount window message
306  setCaption(_("Select amount of items to send."));
307  break;
309  // TRANSLATORS: amount window message
310  setCaption(_("Select amount of items to craft."));
311  break;
313  // TRANSLATORS: amount window message
314  setCaption(_("Select amount of items to store to cart."));
315  break;
317  // TRANSLATORS: amount window message
318  setCaption(_("Select amount of items to retrieve."));
319  break;
321  // TRANSLATORS: amount window message
322  setCaption(_("Select amount of items to retrieve from cart."));
323  break;
325  // TRANSLATORS: amount window message
326  setCaption(_("Select amount of items to split."));
327  break;
329  // TRANSLATORS: amount window message
330  setCaption(_("Add to buy shop."));
331  break;
333  // TRANSLATORS: amount window message
334  setCaption(_("Add to sell shop."));
335  break;
336  default:
337  // TRANSLATORS: amount window message
338  setCaption(_("Unknown."));
339  break;
340  }
341 
343 
345 }
const bool AutoRelease_false
Definition: autorelease.h:30
const std::string BUTTON_SKIN
Definition: button.h:89
Definition: button.h:102
void adjustSize()
Definition: button.cpp:799
Definition: icon.h:41
void setRange(const int minimum, const int maximum)
IntTextField * mItemPriceTextField
DropDown * mItemDropDown
IntTextField * mItemAmountTextField
ItemAmountWindowUsageT mUsage
int getQuantity() const
Definition: item.h:105
Image * getImage() const
Definition: item.h:87
void setEnabled(const bool flag)
bool isEnabled() const
Definition: label.h:91
Definition: slider.h:89
void setWidth(const int width)
Definition: widget.cpp:133
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void setHeight(const int height)
Definition: widget.cpp:140
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
int getWidth() const
Definition: widget.h:221
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1391
Window * getParentWindow() const
Definition: window.h:310
void reflowLayout(int w, int h)
Definition: window.cpp:1396
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 setLocationRelativeTo(const Widget *const widget)
Definition: window.cpp:509
const bool Enable_true
Definition: enable.h:30
#define _(s)
Definition: gettext.h:35
KeyboardConfig keyboard
const bool Modal_false
Definition: modal.h:30

References _, Widget::addActionListener(), Widget::addKeyListener(), Widget::addMouseListener(), Button::adjustSize(), BUTTON_SKIN, ItemAmountWindowUsage::CartAdd, ItemAmountWindowUsage::CartRemove, ItemAmountWindowUsage::CraftAdd, Enable_true, Window::getParentWindow(), Window::getPlacer(), Item::getQuantity(), Widget::getWidth(), ItemAmountWindowUsage::ItemDrop, ItemAmountWindowUsage::ItemSplit, keyboard, ItemAmountWindowUsage::MailAdd, mGPLabel, mItem, mItemAmountSlide, mItemAmountTextField, mItemDropDown, mItemIcon, mItemPriceSlide, mItemPriceTextField, mItemsModal, mMax, Modal_false, mUsage, Window::reflowLayout(), resetAmount(), Widget::setActionEventId(), Window::setCaption(), KeyboardConfig::setEnabled(), Widget::setHeight(), Window::setLocationRelativeTo(), IntTextField::setRange(), Widget::setWidth(), ItemAmountWindowUsage::ShopBuyAdd, ItemAmountWindowUsage::ShopSellAdd, ItemAmountWindowUsage::StoreAdd, ItemAmountWindowUsage::StoreRemove, and ItemAmountWindowUsage::TradeAdd.

Member Function Documentation

◆ action()

void ItemAmountWindow::action ( const ActionEvent event)
virtual

Called when receiving actions from widget.

Implements ActionListener.

Definition at line 385 of file itemamountwindow.cpp.

386 {
387  const std::string &eventId = event.getId();
388  if (eventId == "cancel")
389  {
390  close();
391  return;
392  }
393  else if (eventId == "ok")
394  {
395  if (mItemPriceTextField != nullptr)
396  {
397  finish(mItem,
400  mUsage);
401  }
402  else
403  {
405  {
406  finish(mItem,
408  mPrice,
409  mUsage);
410  }
411  else
412  {
413  finish(mItem,
415  0,
416  mUsage);
417  }
418  }
419  close();
420  return;
421  }
422  else if (eventId == "itemType")
423  {
424  if ((mItemDropDown == nullptr) || (mItemsModal == nullptr))
425  return;
426 
427  const int id = ItemDB::get(mItemsModal->getElementAt(
429 
430  mItem = new Item(id,
432  10000,
433  0,
436  Damaged_true,
438  Equipm_false,
440 
442  mMax = 10000;
443  else if (mMax == 0)
444  mMax = mItem->getQuantity();
445 
447  }
448 
449  int amount = mItemAmountTextField->getValue();
450 
451  if (eventId == "inc" && amount < mMax)
452  amount++;
453  else if (eventId == "dec" && amount > 1)
454  amount--;
455  else if (eventId == "all")
456  amount = mMax;
457  else if (eventId == "slide")
458  amount = CAST_S32(mItemAmountSlide->getValue());
460  mItemAmountSlide->setValue(amount);
461 
462  if ((mItemPriceTextField != nullptr) && (mItemPriceSlide != nullptr))
463  {
464  if (mPrice > 7)
465  mPrice = 7;
466  else if (mPrice < 0)
467  mPrice = 0;
468 
469  int price = 0;
470 
471  if (eventId == "incPrice")
472  {
473  mPrice++;
474  price = CAST_S32(pow(10.0, mPrice));
476  mItemPriceSlide->setValue(price);
477  }
478  else if (eventId == "decPrice")
479  {
480  mPrice--;
481  price = CAST_S32(pow(10.0, mPrice));
483  mItemPriceSlide->setValue(price);
484  }
485  else if (eventId == "slidePrice")
486  {
487  price = CAST_S32(mItemPriceSlide->getValue());
488  if (price != 0)
489  mPrice = CAST_S32(log(static_cast<float>(price)));
490  else
491  mPrice = 0;
493  mItemPriceSlide->setValue(price);
494  }
495  }
496 }
#define CAST_S32
Definition: cast.h:30
int getSelected() const
Definition: dropdown.cpp:509
void setImage(Image *const image)
Definition: icon.cpp:74
void setValue(const int value)
int getValue() const
static void finish(Item *const item, const int amount, const int price, const ItemAmountWindowUsageT usage)
int getId() const
Definition: iteminfo.h:68
std::string getElementAt(int i)
Definition: itemsmodel.h:75
double getValue() const
Definition: slider.h:204
void setValue(const double value)
Definition: slider.cpp:474
const bool Damaged_true
Definition: damaged.h:30
const bool Equipm_false
Definition: equipm.h:30
const bool Equipped_false
Definition: equipped.h:30
const bool Favorite_false
Definition: favorite.h:30
const bool Identified_true
Definition: identified.h:30
const ItemColor ItemColor_one
Definition: itemcolor.h:30
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
@ Unknown
Definition: itemtype.h:30

References CAST_S32, close(), ItemAmountWindowUsage::CraftAdd, Damaged_true, Equipm_false, Equipped_false, Favorite_false, finish(), ItemDB::get(), ItemsModal::getElementAt(), ItemInfo::getId(), Item::getImage(), Item::getQuantity(), DropDown::getSelected(), IntTextField::getValue(), Slider::getValue(), Identified_true, MailMessageType::Item, ItemColor_one, mItem, mItemAmountSlide, mItemAmountTextField, mItemDropDown, mItemIcon, mItemPriceSlide, mItemPriceTextField, mItemsModal, mMax, mPrice, mUsage, Icon::setImage(), Slider::setValue(), IntTextField::setValue(), ItemAmountWindowUsage::ShopBuyAdd, and ItemType::Unknown.

◆ close()

void ItemAmountWindow::close ( )
virtual

Schedules the Item Amount window for deletion.

Reimplemented from Window.

Definition at line 498 of file itemamountwindow.cpp.

499 {
501  scheduleDelete();
502 }
virtual void scheduleDelete()
Definition: window.cpp:831

References keyboard, mEnabledKeyboard, Window::scheduleDelete(), and KeyboardConfig::setEnabled().

Referenced by action().

◆ finish()

void ItemAmountWindow::finish ( Item *const  item,
const int  amount,
const int  price,
const ItemAmountWindowUsageT  usage 
)
staticprivate

Definition at line 67 of file itemamountwindow.cpp.

71 {
72  if (item == nullptr)
73  return;
74  switch (usage)
75  {
77  if (tradeWindow != nullptr)
78  tradeWindow->tradeItem(item, amount, false);
79  break;
81  PlayerInfo::dropItem(item, amount, Sfx_true);
82  break;
84  inventoryHandler->splitItem(item, amount);
85  break;
88  item->getInvIndex(), amount, InventoryType::Storage);
89  break;
92  item->getInvIndex(), amount, InventoryType::Inventory);
93  break;
95  if (shopWindow != nullptr)
96  shopWindow->addBuyItem(item, amount, price);
97  break;
99  if (shopWindow != nullptr)
100  shopWindow->addSellItem(item, amount, price);
101  break;
104  item->getInvIndex(), amount, InventoryType::Cart);
105  break;
108  item->getInvIndex(), amount, InventoryType::Inventory);
109  break;
112  {
113  mail2Handler->addItem(item, amount);
114  }
115  else if (mailEditWindow != nullptr)
116  {
117  mailEditWindow->addItem(item, amount);
118  }
119  break;
121  {
122  NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
123  if (dialog != nullptr)
124  dialog->addCraftItem(item, amount, price); // price as slot
125  break;
126  }
127  default:
128  break;
129  }
130 }
int getInvIndex() const
Definition: item.h:165
void addItem(const Item *const item, const int amount)
virtual void moveItem2(const InventoryTypeT source, const int slot, const int amount, const InventoryTypeT destination) const =0
virtual void splitItem(const Item *const item, const int amount) const =0
virtual void addItem(const Item *const item, const int amount) const =0
virtual NpcDialog * getCurrentNpcDialog() const =0
void addCraftItem(Item *const item, const int amount, const int slot)
Definition: npcdialog.cpp:1382
bool enableNewMailSystem
Definition: settings.h:165
void addSellItem(const Item *const item, const int amount, const int price)
Definition: shopwindow.cpp:529
void addBuyItem(const Item *const item, const int amount, const int price)
Definition: shopwindow.cpp:512
void tradeItem(const Item *const item, const int quantity, const bool check) const
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
Net::Mail2Handler * mail2Handler
Definition: net.cpp:113
MailEditWindow * mailEditWindow
void dropItem(const Item *const item, const int amount, const Sfx sfx)
Definition: playerinfo.cpp:354
Net::NpcHandler * npcHandler
Definition: net.cpp:93
Settings settings
Definition: settings.cpp:32
const bool Sfx_true
Definition: sfx.h:30
ShopWindow * shopWindow
Definition: shopwindow.cpp:101
TradeWindow * tradeWindow
Definition: tradewindow.cpp:65

References ShopWindow::addBuyItem(), NpcDialog::addCraftItem(), MailEditWindow::addItem(), Net::Mail2Handler::addItem(), ShopWindow::addSellItem(), InventoryType::Cart, ItemAmountWindowUsage::CartAdd, ItemAmountWindowUsage::CartRemove, ItemAmountWindowUsage::CraftAdd, PlayerInfo::dropItem(), Settings::enableNewMailSystem, Net::NpcHandler::getCurrentNpcDialog(), Item::getInvIndex(), InventoryType::Inventory, inventoryHandler, ItemAmountWindowUsage::ItemDrop, ItemAmountWindowUsage::ItemSplit, mail2Handler, ItemAmountWindowUsage::MailAdd, mailEditWindow, Net::InventoryHandler::moveItem2(), npcHandler, settings, Sfx_true, ItemAmountWindowUsage::ShopBuyAdd, ItemAmountWindowUsage::ShopSellAdd, shopWindow, Net::InventoryHandler::splitItem(), InventoryType::Storage, ItemAmountWindowUsage::StoreAdd, ItemAmountWindowUsage::StoreRemove, ItemAmountWindowUsage::TradeAdd, TradeWindow::tradeItem(), and tradeWindow.

Referenced by action(), and showWindow().

◆ keyReleased()

void ItemAmountWindow::keyReleased ( KeyEvent event)
virtual

Called if a key is released when the widget has keyboard focus.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 504 of file itemamountwindow.cpp.

References IntTextField::getValue(), mItemAmountSlide, mItemAmountTextField, and Slider::setValue().

◆ mouseExited()

void ItemAmountWindow::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 374 of file itemamountwindow.cpp.

375 {
376  if (itemPopup != nullptr)
378 }
void setVisible(Visible visible)
Definition: widget.cpp:225
ItemPopup * itemPopup
Definition: itempopup.cpp:64
const bool Visible_false
Definition: visible.h:30

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

◆ mouseMoved()

void ItemAmountWindow::mouseMoved ( MouseEvent event)
virtual

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

Reimplemented from Window.

Definition at line 359 of file itemamountwindow.cpp.

360 {
361  Window::mouseMoved(event);
362 
363  if ((viewport == nullptr) || (itemPopup == nullptr))
364  return;
365 
366  if (event.getSource() == mItemIcon)
367  {
368  itemPopup->setItem(mItem, false);
370  }
371 }
Widget * getSource() const
Definition: event.h:104
void setItem(const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
Definition: itempopup.cpp:189
void position(const int x, const int y)
Definition: popup.cpp:235
int mMouseX
Definition: viewport.h:154
int mMouseY
Definition: viewport.h:155
void mouseMoved(MouseEvent &event)
Definition: window.cpp:967
Viewport * viewport
Definition: viewport.cpp:36

References Event::getSource(), itemPopup, mItem, mItemIcon, Viewport::mMouseX, Viewport::mMouseY, Window::mouseMoved(), Popup::position(), ItemPopup::setItem(), and viewport.

◆ postInit()

void ItemAmountWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 347 of file itemamountwindow.cpp.

348 {
351 }
#define fromBool(val, name)
Definition: booldefines.h:49
virtual void setVisible(Visible visible)
Definition: window.cpp:778
void postInit()
Definition: window.cpp:249
bool Visible
Definition: visible.h:30

References fromBool, mItem, Window::postInit(), and Window::setVisible().

◆ resetAmount()

void ItemAmountWindow::resetAmount ( )

Sets default amount value.

Definition at line 380 of file itemamountwindow.cpp.

381 {
383 }

References mItemAmountTextField, and IntTextField::setValue().

Referenced by ItemAmountWindow().

◆ showWindow()

void ItemAmountWindow::showWindow ( const ItemAmountWindowUsageT  usage,
Window *const  parent,
Item *const  item,
int  maxRange,
const int  tag 
)
static

Creates the dialog, or bypass it if there aren't enough items.

Definition at line 509 of file itemamountwindow.cpp.

514 {
515  if (item == nullptr)
516  return;
517 
518  if (maxRange == 0)
519  maxRange = item->getQuantity();
520 
521  if (usage != ItemAmountWindowUsage::ShopBuyAdd &&
523  maxRange <= 1)
524  {
525  if (usage == ItemAmountWindowUsage::CraftAdd)
526  finish(item, maxRange, tag, usage);
527  else
528  finish(item, maxRange, 0, usage);
529  }
530  else
531  {
533  usage, parent, item, maxRange);
534  if (usage == ItemAmountWindowUsage::CraftAdd)
535  window->mPrice = tag;
536  }
537 }
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36

References ItemAmountWindowUsage::CraftAdd, CREATEWIDGETR, finish(), Item::getQuantity(), mPrice, ItemAmountWindowUsage::ShopBuyAdd, and ItemAmountWindowUsage::ShopSellAdd.

Referenced by InventoryWindow::action(), MailEditWindow::action(), ShopWindow::action(), TradeWindow::action(), InventoryWindow::mouseClicked(), ItemContainer::mouseReleased(), ShopListBox::mouseReleased(), InventoryWindow::moveItemToCraft(), and InventoryWindow::valueChanged().

Field Documentation

◆ mEnabledKeyboard

bool ItemAmountWindow::mEnabledKeyboard
private

Definition at line 121 of file itemamountwindow.h.

Referenced by close().

◆ mGPLabel

Label* ItemAmountWindow::mGPLabel
private

Definition at line 106 of file itemamountwindow.h.

Referenced by ItemAmountWindow().

◆ mItem

Item* ItemAmountWindow::mItem
private

Definition at line 107 of file itemamountwindow.h.

Referenced by action(), ItemAmountWindow(), mouseMoved(), and postInit().

◆ mItemAmountSlide

Slider* ItemAmountWindow::mItemAmountSlide
private

Item Amount buttons.

Definition at line 113 of file itemamountwindow.h.

Referenced by action(), ItemAmountWindow(), and keyReleased().

◆ mItemAmountTextField

IntTextField* ItemAmountWindow::mItemAmountTextField
private

Item price caption.

Definition at line 103 of file itemamountwindow.h.

Referenced by action(), ItemAmountWindow(), keyReleased(), and resetAmount().

◆ mItemDropDown

DropDown* ItemAmountWindow::mItemDropDown
private

Definition at line 115 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mItemIcon

Icon* ItemAmountWindow::mItemIcon
private

Definition at line 108 of file itemamountwindow.h.

Referenced by action(), ItemAmountWindow(), and mouseMoved().

◆ mItemPriceSlide

Slider* ItemAmountWindow::mItemPriceSlide
private

Definition at line 114 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mItemPriceTextField

IntTextField* ItemAmountWindow::mItemPriceTextField
private

Definition at line 105 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mItemsModal

ItemsModal* ItemAmountWindow::mItemsModal
private

Definition at line 116 of file itemamountwindow.h.

Referenced by action(), ItemAmountWindow(), and ~ItemAmountWindow().

◆ mMax

int ItemAmountWindow::mMax
private

Definition at line 119 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mPrice

int ItemAmountWindow::mPrice
private

Definition at line 118 of file itemamountwindow.h.

Referenced by action(), and showWindow().

◆ mUsage

ItemAmountWindowUsageT ItemAmountWindow::mUsage
private

Definition at line 120 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().


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