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 46 of file itemamountwindow.h.

Constructor & Destructor Documentation

◆ ~ItemAmountWindow()

ItemAmountWindow::~ItemAmountWindow ( )

Definition at line 352 of file itemamountwindow.cpp.

References delete2, and mItemsModal.

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

◆ ItemAmountWindow()

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

Item amount caption.

Definition at line 131 of file itemamountwindow.cpp.

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.

134  :
135  Window("", Modal_false, parent, "amount.xml"),
136  ActionListener(),
137  KeyListener(),
138  mItemAmountTextField(new IntTextField(this, 1, 0, 0, Enable_true, 0)),
139  mItemPriceTextField(nullptr),
140  mGPLabel(nullptr),
141  mItem(item),
142  mItemIcon(new Icon(this,
143  item != nullptr ? item->getImage() : nullptr, AutoRelease_false)),
144  mItemAmountSlide(new Slider(this, 1.0, maxRange, 1.0)),
145  mItemPriceSlide(nullptr),
146  mItemDropDown(nullptr),
147  mItemsModal(nullptr),
148  mPrice(0),
149  mMax(maxRange),
150  mUsage(usage),
152 {
153  if (mItem == nullptr)
154  return;
155 
157  mMax = 10000;
158  else if (mMax == 0)
159  mMax = mItem->getQuantity();
160 
161  keyboard.setEnabled(false);
162 
166 
170 
173  {
174  mItemPriceTextField = new IntTextField(this, 1, 0, 0, Enable_true, 0);
175  mItemPriceTextField->setRange(1, 10000000);
178 
179  mItemPriceSlide = new Slider(this, 1.0, 10000000, 1.0);
181  mItemPriceSlide->setActionEventId("slidePrice");
183 
184  mGPLabel = new Label(this, " GP");
185  }
186 
188  {
189  mItemsModal = new ItemsModal;
190  mItemDropDown = new DropDown(this,
191  mItemsModal,
192  false,
193  Modal_false,
194  nullptr,
195  std::string());
196  mItemDropDown->setActionEventId("itemType");
198  }
199 
200  // Buttons
201  Button *const minusAmountButton = new Button(this,
202  // TRANSLATORS: item amount window button
203  _("-"),
204  "dec",
205  BUTTON_SKIN,
206  this);
207  Button *const plusAmountButton = new Button(this,
208  // TRANSLATORS: item amount window button
209  _("+"),
210  "inc",
211  BUTTON_SKIN,
212  this);
213  Button *const okButton = new Button(this,
214  // TRANSLATORS: item amount window button
215  _("OK"),
216  "ok",
217  BUTTON_SKIN,
218  this);
219  Button *const cancelButton = new Button(this,
220  // TRANSLATORS: item amount window button
221  _("Cancel"),
222  "cancel",
223  BUTTON_SKIN,
224  this);
225  Button *const addAllButton = new Button(this,
226  // TRANSLATORS: item amount window button
227  _("All"),
228  "all",
229  BUTTON_SKIN,
230  this);
231 
232  minusAmountButton->adjustSize();
233  minusAmountButton->setWidth(plusAmountButton->getWidth());
234 
235  // Set positions
236  ContainerPlacer placer(nullptr, nullptr);
237  placer = getPlacer(0, 0);
238  int n = 0;
240  {
241  placer(0, n, mItemDropDown, 8, 1);
242  n++;
243  }
244  placer(1, n, minusAmountButton, 1, 1);
245  placer(2, n, mItemAmountTextField, 3, 1);
246  placer(5, n, plusAmountButton, 1, 1);
247  placer(6, n, addAllButton, 1, 1);
248 
249  placer(0, n, mItemIcon, 1, 3);
250  placer(1, n + 1, mItemAmountSlide, 7, 1);
251 
254  {
255  Button *const minusPriceButton = new Button(this,
256  // TRANSLATORS: item amount window button
257  _("-"),
258  "decPrice",
259  BUTTON_SKIN,
260  this);
261  Button *const plusPriceButton = new Button(this,
262  // TRANSLATORS: item amount window button
263  _("+"),
264  "incPrice",
265  BUTTON_SKIN,
266  this);
267  minusPriceButton->adjustSize();
268  minusPriceButton->setWidth(plusPriceButton->getWidth());
269 
270  placer(1, n + 2, minusPriceButton, 1, 1);
271  placer(2, n + 2, mItemPriceTextField, 3, 1);
272  placer(5, n + 2, plusPriceButton, 1, 1);
273  placer(6, n + 2, mGPLabel, 1, 1);
274 
275  placer(1, n + 3, mItemPriceSlide, 7, 1);
276  placer(4, n + 5, cancelButton, 1, 1);
277  placer(5, n + 5, okButton, 1, 1);
278  }
279  else
280  {
281  placer(4, n + 2, cancelButton, 1, 1);
282  placer(5, n + 2, okButton, 1, 1);
283  }
284 
285  reflowLayout(225, 0);
286 
287  resetAmount();
288 
289  switch (usage)
290  {
292  // TRANSLATORS: amount window message
293  setCaption(_("Select amount of items to trade."));
294  break;
296  // TRANSLATORS: amount window message
297  setCaption(_("Select amount of items to drop."));
298  break;
300  // TRANSLATORS: amount window message
301  setCaption(_("Select amount of items to store."));
302  break;
304  // TRANSLATORS: amount window message
305  setCaption(_("Select amount of items to send."));
306  break;
308  // TRANSLATORS: amount window message
309  setCaption(_("Select amount of items to craft."));
310  break;
312  // TRANSLATORS: amount window message
313  setCaption(_("Select amount of items to store to cart."));
314  break;
316  // TRANSLATORS: amount window message
317  setCaption(_("Select amount of items to retrieve."));
318  break;
320  // TRANSLATORS: amount window message
321  setCaption(_("Select amount of items to retrieve from cart."));
322  break;
324  // TRANSLATORS: amount window message
325  setCaption(_("Select amount of items to split."));
326  break;
328  // TRANSLATORS: amount window message
329  setCaption(_("Add to buy shop."));
330  break;
332  // TRANSLATORS: amount window message
333  setCaption(_("Add to sell shop."));
334  break;
335  default:
336  // TRANSLATORS: amount window message
337  setCaption(_("Unknown."));
338  break;
339  }
340 
342 
344 }
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:96
Window * getParentWindow() const
Definition: window.h:309
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
ItemsModal * mItemsModal
const bool Enable_true
Definition: enable.h:29
bool isEnabled() const
void adjustSize()
Definition: button.cpp:798
Definition: icon.h:39
const std::string BUTTON_SKIN
Definition: button.h:88
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:1386
void setHeight(const int height)
Definition: widget.cpp:139
Image * getImage() const
Definition: item.h:86
const bool AutoRelease_false
Definition: autorelease.h:29
IntTextField * mItemPriceTextField
KeyboardConfig keyboard
DropDown * mItemDropDown
Definition: slider.h:85
void setCaption(const std::string &caption)
Definition: window.h:530
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
void setLocationRelativeTo(const Widget *const widget)
Definition: window.cpp:508
void setEnabled(const bool flag)
void reflowLayout(int w, int h)
Definition: window.cpp:1391

Member Function Documentation

◆ action()

void ItemAmountWindow::action ( const ActionEvent event)
virtual

Called when receiving actions from widget.

Implements ActionListener.

Definition at line 384 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.

385 {
386  const std::string &eventId = event.getId();
387  if (eventId == "cancel")
388  {
389  close();
390  return;
391  }
392  else if (eventId == "ok")
393  {
394  if (mItemPriceTextField != nullptr)
395  {
396  finish(mItem,
399  mUsage);
400  }
401  else
402  {
404  {
405  finish(mItem,
407  mPrice,
408  mUsage);
409  }
410  else
411  {
412  finish(mItem,
414  0,
415  mUsage);
416  }
417  }
418  close();
419  return;
420  }
421  else if (eventId == "itemType")
422  {
423  if ((mItemDropDown == nullptr) || (mItemsModal == nullptr))
424  return;
425 
426  const int id = ItemDB::get(mItemsModal->getElementAt(
428 
429  mItem = new Item(id,
431  10000,
432  0,
435  Damaged_true,
437  Equipm_false,
439 
441  mMax = 10000;
442  else if (mMax == 0)
443  mMax = mItem->getQuantity();
444 
446  }
447 
448  int amount = mItemAmountTextField->getValue();
449 
450  if (eventId == "inc" && amount < mMax)
451  amount++;
452  else if (eventId == "dec" && amount > 1)
453  amount--;
454  else if (eventId == "all")
455  amount = mMax;
456  else if (eventId == "slide")
457  amount = CAST_S32(mItemAmountSlide->getValue());
459  mItemAmountSlide->setValue(amount);
460 
461  if ((mItemPriceTextField != nullptr) && (mItemPriceSlide != nullptr))
462  {
463  if (mPrice > 7)
464  mPrice = 7;
465  else if (mPrice < 0)
466  mPrice = 0;
467 
468  int price = 0;
469 
470  if (eventId == "incPrice")
471  {
472  mPrice++;
473  price = CAST_S32(pow(10.0, mPrice));
475  mItemPriceSlide->setValue(price);
476  }
477  else if (eventId == "decPrice")
478  {
479  mPrice--;
480  price = CAST_S32(pow(10.0, mPrice));
482  mItemPriceSlide->setValue(price);
483  }
484  else if (eventId == "slidePrice")
485  {
486  price = CAST_S32(mItemPriceSlide->getValue());
487  if (price != 0)
488  mPrice = CAST_S32(log(static_cast<float>(price)));
489  else
490  mPrice = 0;
492  mItemPriceSlide->setValue(price);
493  }
494  }
495 }
ItemAmountWindowUsageT mUsage
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
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:509
const bool Equipm_false
Definition: equipm.h:29
std::string getElementAt(int i)
Definition: itemsmodel.h:74
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 497 of file itemamountwindow.cpp.

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

Referenced by action().

498 {
500  scheduleDelete();
501 }
virtual void scheduleDelete()
Definition: window.cpp:826
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, false);
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:108
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:511
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:85
void tradeItem(const Item *const item, const int quantity, const bool check) const
ShopWindow * shopWindow
Definition: shopwindow.cpp:100
Net::NpcHandler * npcHandler
Definition: net.cpp:89
MailEditWindow * mailEditWindow
void addCraftItem(Item *const item, const int amount, const int slot)
Definition: npcdialog.cpp:1381
bool enableNewMailSystem
Definition: settings.h:162
void addSellItem(const Item *const item, const int amount, const int price)
Definition: shopwindow.cpp:528
void dropItem(const Item *const item, const int amount, const Sfx sfx)
Definition: playerinfo.cpp:351

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

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

504 {
506 }
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 373 of file itemamountwindow.cpp.

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

374 {
375  if (itemPopup != nullptr)
377 }
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 358 of file itemamountwindow.cpp.

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

359 {
360  Window::mouseMoved(event);
361 
362  if ((viewport == nullptr) || (itemPopup == nullptr))
363  return;
364 
365  if (event.getSource() == mItemIcon)
366  {
367  itemPopup->setItem(mItem, false);
369  }
370 }
void mouseMoved(MouseEvent &event)
Definition: window.cpp:962
int mMouseX
Definition: viewport.h:153
Widget * getSource() const
Definition: event.h:103
void position(const int x, const int y)
Definition: popup.cpp:232
void setItem(const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
Definition: itempopup.cpp:188
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 346 of file itemamountwindow.cpp.

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

347 {
350 }
#define fromBool(val, name)
Definition: booldefines.h:48
virtual void setVisible(Visible visible)
Definition: window.cpp:773
void postInit()
Definition: window.cpp:248

◆ resetAmount()

void ItemAmountWindow::resetAmount ( )

Sets default amount value.

Definition at line 379 of file itemamountwindow.cpp.

References mItemAmountTextField, and IntTextField::setValue().

Referenced by ItemAmountWindow().

380 {
382 }
void setValue(const int value)
IntTextField * mItemAmountTextField

◆ 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 508 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().

513 {
514  if (item == nullptr)
515  return;
516 
517  if (maxRange == 0)
518  maxRange = item->getQuantity();
519 
520  if (usage != ItemAmountWindowUsage::ShopBuyAdd &&
522  maxRange <= 1)
523  {
524  if (usage == ItemAmountWindowUsage::CraftAdd)
525  finish(item, maxRange, tag, usage);
526  else
527  finish(item, maxRange, 0, usage);
528  }
529  else
530  {
532  usage, parent, item, maxRange);
533  if (usage == ItemAmountWindowUsage::CraftAdd)
534  window->mPrice = tag;
535  }
536 }
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: