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="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
 
virtual ~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=0, int offsetY=0)
 
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=0, const int offsetY=0)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w=0, int h=0)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w=1, const int h=1)
 
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)
 
virtual ~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)
 
virtual ~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)
 
virtual ~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=255U) 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=0, const int tag=0)
 
- 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=0)
 

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=0) const
 
bool getOptionBool (const std::string &name, const bool def=false) 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 46 of file itemamountwindow.h.

Constructor & Destructor Documentation

◆ ~ItemAmountWindow()

ItemAmountWindow::~ItemAmountWindow ( )

Definition at line 320 of file itemamountwindow.cpp.

References delete2, and mItemsModal.

321 {
323 }
#define delete2(var)
Definition: delete2.h:24
ItemsModal * mItemsModal

◆ ItemAmountWindow()

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

Item amount caption.

Definition at line 131 of file itemamountwindow.cpp.

References _, Widget::addActionListener(), Widget::addKeyListener(), Widget::addMouseListener(), Button::adjustSize(), ItemAmountWindowUsage::CartAdd, ItemAmountWindowUsage::CartRemove, ItemAmountWindowUsage::CraftAdd, 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, 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.

134  :
135  Window("", Modal_false, parent, "amount.xml"),
136  ActionListener(),
137  KeyListener(),
138  mItemAmountTextField(new IntTextField(this, 1)),
139  mItemPriceTextField(nullptr),
140  mGPLabel(nullptr),
141  mItem(item),
142  mItemIcon(new Icon(this, item != nullptr ? item->getImage() : nullptr)),
143  mItemAmountSlide(new Slider(this, 1.0, maxRange, 1.0)),
144  mItemPriceSlide(nullptr),
145  mItemDropDown(nullptr),
146  mItemsModal(nullptr),
147  mPrice(0),
148  mMax(maxRange),
149  mUsage(usage),
151 {
152  if (mItem == nullptr)
153  return;
154 
156  mMax = 10000;
157  else if (mMax == 0)
158  mMax = mItem->getQuantity();
159 
160  keyboard.setEnabled(false);
161 
165 
169 
172  {
173  mItemPriceTextField = new IntTextField(this, 1);
174  mItemPriceTextField->setRange(1, 10000000);
177 
178  mItemPriceSlide = new Slider(this, 1.0, 10000000, 1.0);
180  mItemPriceSlide->setActionEventId("slidePrice");
182 
183  mGPLabel = new Label(this, " GP");
184  }
185 
187  {
188  mItemsModal = new ItemsModal;
189  mItemDropDown = new DropDown(this, mItemsModal);
190  mItemDropDown->setActionEventId("itemType");
192  }
193 
194  // Buttons
195  // TRANSLATORS: item amount window button
196  Button *const minusAmountButton = new Button(this, _("-"), "dec", this);
197  // TRANSLATORS: item amount window button
198  Button *const plusAmountButton = new Button(this, _("+"), "inc", this);
199  // TRANSLATORS: item amount window button
200  Button *const okButton = new Button(this, _("OK"), "ok", this);
201  // TRANSLATORS: item amount window button
202  Button *const cancelButton = new Button(this, _("Cancel"), "cancel", this);
203  // TRANSLATORS: item amount window button
204  Button *const addAllButton = new Button(this, _("All"), "all", this);
205 
206  minusAmountButton->adjustSize();
207  minusAmountButton->setWidth(plusAmountButton->getWidth());
208 
209  // Set positions
210  ContainerPlacer placer;
211  placer = getPlacer(0, 0);
212  int n = 0;
214  {
215  placer(0, n, mItemDropDown, 8);
216  n++;
217  }
218  placer(1, n, minusAmountButton);
219  placer(2, n, mItemAmountTextField, 3);
220  placer(5, n, plusAmountButton);
221  placer(6, n, addAllButton);
222 
223  placer(0, n, mItemIcon, 1, 3);
224  placer(1, n + 1, mItemAmountSlide, 7);
225 
228  {
229  Button *const minusPriceButton = new Button(
230  // TRANSLATORS: item amount window button
231  this, _("-"), "decPrice", this);
232  Button *const plusPriceButton = new Button(
233  // TRANSLATORS: item amount window button
234  this, _("+"), "incPrice", this);
235  minusPriceButton->adjustSize();
236  minusPriceButton->setWidth(plusPriceButton->getWidth());
237 
238  placer(1, n + 2, minusPriceButton);
239  placer(2, n + 2, mItemPriceTextField, 3);
240  placer(5, n + 2, plusPriceButton);
241  placer(6, n + 2, mGPLabel);
242 
243  placer(1, n + 3, mItemPriceSlide, 7);
244  placer(4, n + 5, cancelButton);
245  placer(5, n + 5, okButton);
246  }
247  else
248  {
249  placer(4, n + 2, cancelButton);
250  placer(5, n + 2, okButton);
251  }
252 
253  reflowLayout(225, 0);
254 
255  resetAmount();
256 
257  switch (usage)
258  {
260  // TRANSLATORS: amount window message
261  setCaption(_("Select amount of items to trade."));
262  break;
264  // TRANSLATORS: amount window message
265  setCaption(_("Select amount of items to drop."));
266  break;
268  // TRANSLATORS: amount window message
269  setCaption(_("Select amount of items to store."));
270  break;
272  // TRANSLATORS: amount window message
273  setCaption(_("Select amount of items to send."));
274  break;
276  // TRANSLATORS: amount window message
277  setCaption(_("Select amount of items to craft."));
278  break;
280  // TRANSLATORS: amount window message
281  setCaption(_("Select amount of items to store to cart."));
282  break;
284  // TRANSLATORS: amount window message
285  setCaption(_("Select amount of items to retrieve."));
286  break;
288  // TRANSLATORS: amount window message
289  setCaption(_("Select amount of items to retrieve from cart."));
290  break;
292  // TRANSLATORS: amount window message
293  setCaption(_("Select amount of items to split."));
294  break;
296  // TRANSLATORS: amount window message
297  setCaption(_("Add to buy shop."));
298  break;
300  // TRANSLATORS: amount window message
301  setCaption(_("Add to sell shop."));
302  break;
303  default:
304  // TRANSLATORS: amount window message
305  setCaption(_("Unknown."));
306  break;
307  }
308 
310 
312 }
ItemAmountWindowUsageT mUsage
#define _(s)
Definition: gettext.h:34
int getWidth() const
Definition: widget.h:220
void setWidth(const int width)
Definition: widget.cpp:132
IntTextField * mItemAmountTextField
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
Definition: button.h:94
Window * getParentWindow() const
Definition: window.h:308
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
ItemsModal * mItemsModal
bool isEnabled() const
void adjustSize()
Definition: button.cpp:821
void reflowLayout(int w=0, int h=0)
Definition: window.cpp:1384
Definition: icon.h:39
Definition: label.h:87
int getQuantity() const
Definition: item.h:104
void setRange(const int minimum, const int maximum)
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1379
void setHeight(const int height)
Definition: widget.cpp:139
Image * getImage() const
Definition: item.h:86
IntTextField * mItemPriceTextField
KeyboardConfig keyboard
DropDown * mItemDropDown
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
Definition: slider.h:85
void setCaption(const std::string &caption)
Definition: window.h:523
void setLocationRelativeTo(const Widget *const widget)
Definition: window.cpp:501
void setEnabled(const bool flag)

Member Function Documentation

◆ action()

void ItemAmountWindow::action ( const ActionEvent event)
virtual

Called when receiving actions from widget.

Implements ActionListener.

Definition at line 352 of file itemamountwindow.cpp.

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(), IntTextField::setValue(), Slider::setValue(), ItemAmountWindowUsage::ShopBuyAdd, and ItemType::Unknown.

353 {
354  const std::string &eventId = event.getId();
355  if (eventId == "cancel")
356  {
357  close();
358  return;
359  }
360  else if (eventId == "ok")
361  {
362  if (mItemPriceTextField != nullptr)
363  {
364  finish(mItem,
367  mUsage);
368  }
369  else
370  {
372  {
373  finish(mItem,
375  mPrice,
376  mUsage);
377  }
378  else
379  {
380  finish(mItem,
382  0,
383  mUsage);
384  }
385  }
386  close();
387  return;
388  }
389  else if (eventId == "itemType")
390  {
391  if ((mItemDropDown == nullptr) || (mItemsModal == nullptr))
392  return;
393 
394  const int id = ItemDB::get(mItemsModal->getElementAt(
396 
397  mItem = new Item(id,
399  10000,
400  0,
403  Damaged_true,
405  Equipm_false,
407 
409  mMax = 10000;
410  else if (mMax == 0)
411  mMax = mItem->getQuantity();
412 
414  }
415 
416  int amount = mItemAmountTextField->getValue();
417 
418  if (eventId == "inc" && amount < mMax)
419  amount++;
420  else if (eventId == "dec" && amount > 1)
421  amount--;
422  else if (eventId == "all")
423  amount = mMax;
424  else if (eventId == "slide")
425  amount = CAST_S32(mItemAmountSlide->getValue());
427  mItemAmountSlide->setValue(amount);
428 
429  if ((mItemPriceTextField != nullptr) && (mItemPriceSlide != nullptr))
430  {
431  if (mPrice > 7)
432  mPrice = 7;
433  else if (mPrice < 0)
434  mPrice = 0;
435 
436  int price = 0;
437 
438  if (eventId == "incPrice")
439  {
440  mPrice++;
441  price = CAST_S32(pow(10.0, mPrice));
443  mItemPriceSlide->setValue(price);
444  }
445  else if (eventId == "decPrice")
446  {
447  mPrice--;
448  price = CAST_S32(pow(10.0, mPrice));
450  mItemPriceSlide->setValue(price);
451  }
452  else if (eventId == "slidePrice")
453  {
454  price = CAST_S32(mItemPriceSlide->getValue());
455  if (price != 0)
456  mPrice = CAST_S32(log(static_cast<float>(price)));
457  else
458  mPrice = 0;
460  mItemPriceSlide->setValue(price);
461  }
462  }
463 }
ItemAmountWindowUsageT mUsage
const ItemInfo & get(const int id)
Definition: itemdb.cpp:814
void setValue(const int value)
IntTextField * mItemAmountTextField
int getId() const
Definition: iteminfo.h:67
const bool Damaged_true
Definition: damaged.h:29
const ItemColor ItemColor_one
Definition: itemcolor.h:29
ItemsModal * mItemsModal
const bool Equipped_false
Definition: equipped.h:29
#define CAST_S32
Definition: cast.h:29
const bool Favorite_false
Definition: favorite.h:29
int getQuantity() const
Definition: item.h:104
double getValue() const
Definition: slider.h:203
int getValue() const
static void finish(Item *const item, const int amount, const int price, const ItemAmountWindowUsageT usage)
Image * getImage() const
Definition: item.h:86
void setImage(Image *const image)
Definition: icon.cpp:73
void setValue(const double value)
Definition: slider.cpp:473
IntTextField * mItemPriceTextField
DropDown * mItemDropDown
int getSelected() const
Definition: dropdown.cpp:505
const bool Equipm_false
Definition: equipm.h:29
std::string getElementAt(int i)
Definition: itemsmodel.h:77
const bool Identified_true
Definition: identified.h:29

◆ close()

void ItemAmountWindow::close ( )
virtual

Schedules the Item Amount window for deletion.

Reimplemented from Window.

Definition at line 465 of file itemamountwindow.cpp.

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

Referenced by action().

466 {
468  scheduleDelete();
469 }
virtual void scheduleDelete()
Definition: window.cpp:819
KeyboardConfig keyboard
void setEnabled(const bool flag)

◆ finish()

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

Definition at line 66 of file itemamountwindow.cpp.

References ShopWindow::addBuyItem(), NpcDialog::addCraftItem(), Net::Mail2Handler::addItem(), MailEditWindow::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().

70 {
71  if (item == nullptr)
72  return;
73  switch (usage)
74  {
76  if (tradeWindow != nullptr)
77  tradeWindow->tradeItem(item, amount);
78  break;
80  PlayerInfo::dropItem(item, amount, Sfx_true);
81  break;
83  inventoryHandler->splitItem(item, amount);
84  break;
87  item->getInvIndex(), amount, InventoryType::Storage);
88  break;
91  item->getInvIndex(), amount, InventoryType::Inventory);
92  break;
94  if (shopWindow != nullptr)
95  shopWindow->addBuyItem(item, amount, price);
96  break;
98  if (shopWindow != nullptr)
99  shopWindow->addSellItem(item, amount, price);
100  break;
103  item->getInvIndex(), amount, InventoryType::Cart);
104  break;
107  item->getInvIndex(), amount, InventoryType::Inventory);
108  break;
111  {
112  mail2Handler->addItem(item, amount);
113  }
114  else if (mailEditWindow != nullptr)
115  {
116  mailEditWindow->addItem(item, amount);
117  }
118  break;
120  {
121  NpcDialog *const dialog = npcHandler->getCurrentNpcDialog();
122  if (dialog != nullptr)
123  dialog->addCraftItem(item, amount, price); // price as slot
124  break;
125  }
126  default:
127  break;
128  }
129 }
int getInvIndex() const
Definition: item.h:164
virtual void moveItem2(const InventoryTypeT source, const int slot, const int amount, const InventoryTypeT destination) const =0
TradeWindow * tradeWindow
Definition: tradewindow.cpp:64
virtual void addItem(const Item *const item, const int amount) const =0
const bool Sfx_true
Definition: sfx.h:29
void addItem(const Item *const item, const int amount)
Net::Mail2Handler * mail2Handler
Definition: net.cpp:104
virtual void splitItem(const Item *const item, const int amount) const =0
virtual NpcDialog * getCurrentNpcDialog() const =0
Settings settings
Definition: settings.cpp:31
void addBuyItem(const Item *const item, const int amount, const int price)
Definition: shopwindow.cpp:491
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:82
ShopWindow * shopWindow
Definition: shopwindow.cpp:97
void tradeItem(const Item *const item, const int quantity, const bool check=false) const
Net::NpcHandler * npcHandler
Definition: net.cpp:86
MailEditWindow * mailEditWindow
void addCraftItem(Item *const item, const int amount, const int slot)
Definition: npcdialog.cpp:1376
bool enableNewMailSystem
Definition: settings.h:163
void addSellItem(const Item *const item, const int amount, const int price)
Definition: shopwindow.cpp:508
void dropItem(const Item *const item, const int amount, const Sfx sfx)
Definition: playerinfo.cpp:366

◆ 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 471 of file itemamountwindow.cpp.

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

472 {
474 }
IntTextField * mItemAmountTextField
int getValue() const
void setValue(const double value)
Definition: slider.cpp:473

◆ 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 341 of file itemamountwindow.cpp.

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

342 {
343  if (itemPopup != nullptr)
345 }
void setVisible(Visible visible)
Definition: widget.cpp:224
const bool Visible_false
Definition: visible.h:29
ItemPopup * itemPopup
Definition: itempopup.cpp:63

◆ mouseMoved()

void ItemAmountWindow::mouseMoved ( MouseEvent event)
virtual

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

Reimplemented from Window.

Definition at line 326 of file itemamountwindow.cpp.

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

327 {
328  Window::mouseMoved(event);
329 
330  if ((viewport == nullptr) || (itemPopup == nullptr))
331  return;
332 
333  if (event.getSource() == mItemIcon)
334  {
335  itemPopup->setItem(mItem, false);
337  }
338 }
void mouseMoved(MouseEvent &event)
Definition: window.cpp:955
int mMouseX
Definition: viewport.h:153
Widget * getSource() const
Definition: event.h:103
void position(const int x, const int y)
Definition: popup.cpp:229
void setItem(const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
Definition: itempopup.cpp:183
int mMouseY
Definition: viewport.h:154
ItemPopup * itemPopup
Definition: itempopup.cpp:63
Viewport * viewport
Definition: viewport.cpp:35

◆ postInit()

void ItemAmountWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 314 of file itemamountwindow.cpp.

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

315 {
318 }
#define fromBool(val, name)
Definition: booldefines.h:48
virtual void setVisible(Visible visible)
Definition: window.cpp:766
void postInit()
Definition: window.cpp:241

◆ resetAmount()

void ItemAmountWindow::resetAmount ( )

Sets default amount value.

Definition at line 347 of file itemamountwindow.cpp.

References mItemAmountTextField, and IntTextField::setValue().

Referenced by ItemAmountWindow().

348 {
350 }
void setValue(const int value)
IntTextField * mItemAmountTextField

◆ showWindow()

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

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

Definition at line 476 of file itemamountwindow.cpp.

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

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

481 {
482  if (item == nullptr)
483  return;
484 
485  if (maxRange == 0)
486  maxRange = item->getQuantity();
487 
488  if (usage != ItemAmountWindowUsage::ShopBuyAdd &&
490  maxRange <= 1)
491  {
492  if (usage == ItemAmountWindowUsage::CraftAdd)
493  finish(item, maxRange, tag, usage);
494  else
495  finish(item, maxRange, 0, usage);
496  }
497  else
498  {
500  usage, parent, item, maxRange);
501  if (usage == ItemAmountWindowUsage::CraftAdd)
502  window->mPrice = tag;
503  }
504 }
int getQuantity() const
Definition: item.h:104
static void finish(Item *const item, const int amount, const int price, const ItemAmountWindowUsageT usage)
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35

Field Documentation

◆ mEnabledKeyboard

bool ItemAmountWindow::mEnabledKeyboard
private

Definition at line 120 of file itemamountwindow.h.

Referenced by close().

◆ mGPLabel

Label* ItemAmountWindow::mGPLabel
private

Definition at line 105 of file itemamountwindow.h.

Referenced by ItemAmountWindow().

◆ mItem

Item* ItemAmountWindow::mItem
private

Definition at line 106 of file itemamountwindow.h.

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

◆ mItemAmountSlide

Slider* ItemAmountWindow::mItemAmountSlide
private

Item Amount buttons.

Definition at line 112 of file itemamountwindow.h.

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

◆ mItemAmountTextField

IntTextField* ItemAmountWindow::mItemAmountTextField
private

Item price caption.

Definition at line 102 of file itemamountwindow.h.

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

◆ mItemDropDown

DropDown* ItemAmountWindow::mItemDropDown
private

Definition at line 114 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mItemIcon

Icon* ItemAmountWindow::mItemIcon
private

Definition at line 107 of file itemamountwindow.h.

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

◆ mItemPriceSlide

Slider* ItemAmountWindow::mItemPriceSlide
private

Definition at line 113 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mItemPriceTextField

IntTextField* ItemAmountWindow::mItemPriceTextField
private

Definition at line 104 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mItemsModal

ItemsModal* ItemAmountWindow::mItemsModal
private

Definition at line 115 of file itemamountwindow.h.

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

◆ mMax

int ItemAmountWindow::mMax
private

Definition at line 118 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().

◆ mPrice

int ItemAmountWindow::mPrice
private

Definition at line 117 of file itemamountwindow.h.

Referenced by action(), and showWindow().

◆ mUsage

ItemAmountWindowUsageT ItemAmountWindow::mUsage
private

Definition at line 119 of file itemamountwindow.h.

Referenced by action(), and ItemAmountWindow().


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