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

#include <buydialog.h>

Inheritance diagram for BuyDialog:
Window ActionListener SelectionListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Types

enum  {
  Nick = -1, Items = -2, Market = -3, Cash = -4,
  Vending = -5
}
 

Public Member Functions

 BuyDialog ()
 
 BuyDialog (const BeingId npcId, const std::string &currency)
 
 BuyDialog (const std::string &nick, const std::string &currency)
 
 BuyDialog (const Being *const being, const std::string &currency)
 
 ~BuyDialog ()
 
void init ()
 
void reset ()
 
void setMoney (const int amount)
 
ShopItemaddItem (const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
 
void action (const ActionEvent &event)
 
int getNumberOfElements ()
 
void valueChanged (const SelectionEvent &event)
 
void updateButtonsAndLabels ()
 
void setVisible (Visible visible)
 
void sort ()
 
void close ()
 
- 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
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
void postInit ()
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (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 SelectionListener
virtual ~SelectionListener ()
 

Static Public Member Functions

static bool isActive ()
 
static void closeAll ()
 
- 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 Types

typedef std::list< BuyDialog * > DialogList
 

Private Member Functions

void updateSlider (const int selectedItem)
 
void applyNameFilter (const std::string &filter)
 

Private Attributes

ButtonmBuyButton
 
ButtonmConfirmButton
 
ButtonmQuitButton
 
ButtonmAddMaxButton
 
ButtonmIncreaseButton
 
ButtonmDecreaseButton
 
ShopListBoxmShopItemList
 
ScrollAreamScrollArea
 
LabelmMoneyLabel
 
LabelmQuantityLabel
 
SlidermSlider
 
LabelmAmountLabel
 
IntTextFieldmAmountField
 
ShopItemsmShopItems
 
SortListModelBuymSortModel
 
DropDownmSortDropDown
 
TextFieldmFilterTextField
 
LabelmFilterLabel
 
std::string mNick
 
std::string mCurrency
 
BeingId mNpcId
 
int mMoney
 
int mAmountItems
 
int mMaxItems
 
bool mAdvanced
 

Static Private Attributes

static DialogList instances
 

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 SelectionListener
 SelectionListener ()
 
- 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

The buy dialog.

Definition at line 54 of file buydialog.h.

Member Typedef Documentation

◆ DialogList

typedef std::list<BuyDialog*> BuyDialog::DialogList
private

Definition at line 176 of file buydialog.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Nick 
Items 
Market 
Cash 
Vending 

Definition at line 99 of file buydialog.h.

100  {
101 #ifdef TMWA_SUPPORT
102  Nick = -1,
103 #endif // TMWA_SUPPORT
104  Items = -2,
105  Market = -3,
106  Cash = -4,
107  Vending = -5
108  };

Constructor & Destructor Documentation

◆ BuyDialog() [1/4]

BuyDialog::BuyDialog ( )

Constructor.

See also
Window::Window

Definition at line 189 of file buydialog.cpp.

References init().

189  :
190  // TRANSLATORS: buy dialog name
191  Window(_("Create items"), Modal_false, nullptr, "buy.xml"),
192  ActionListener(),
194  mSortModel(nullptr),
195  mSortDropDown(nullptr),
197  this, "namefilter", true)),
198  mFilterLabel(nullptr),
199  mNick(),
200  mCurrency(),
202  mMoney(0),
203  mAmountItems(0),
204  mMaxItems(0),
205  mAdvanced(false)
206 {
207  init();
208 }
#define _(s)
Definition: gettext.h:34
const bool LoseFocusOnTab_true
#define fromInt(val, name)
Definition: intdefines.h:45
int BeingId
Definition: beingid.h:29
Label * mFilterLabel
Definition: buydialog.h:196
void init()
Definition: buydialog.cpp:280
int mMoney
Definition: buydialog.h:201
int mAmountItems
Definition: buydialog.h:202
std::string mCurrency
Definition: buydialog.h:199
BeingId mNpcId
Definition: buydialog.h:200
TextField * mFilterTextField
Definition: buydialog.h:195
DropDown * mSortDropDown
Definition: buydialog.h:194
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
std::string mNick
Definition: buydialog.h:198
SortListModelBuy * mSortModel
Definition: buydialog.h:193
bool mAdvanced
Definition: buydialog.h:204
int mMaxItems
Definition: buydialog.h:203

◆ BuyDialog() [2/4]

BuyDialog::BuyDialog ( const BeingId  npcId,
const std::string &  currency 
)

Constructor.

See also
Window::Window

Definition at line 210 of file buydialog.cpp.

References init().

211  :
212  // TRANSLATORS: buy dialog name
213  Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
214  ActionListener(),
216  mSortModel(nullptr),
217  mSortDropDown(nullptr),
219  this, "namefilter", true)),
220  mFilterLabel(nullptr),
221  mNick(),
222  mCurrency(currency),
223  mNpcId(npcId),
224  mMoney(0),
225  mAmountItems(0),
226  mMaxItems(0),
228 {
229  init();
230 }
#define _(s)
Definition: gettext.h:34
const bool LoseFocusOnTab_true
Label * mFilterLabel
Definition: buydialog.h:196
void init()
Definition: buydialog.cpp:280
int mMoney
Definition: buydialog.h:201
int mAmountItems
Definition: buydialog.h:202
std::string mCurrency
Definition: buydialog.h:199
ServerTypeT getNetworkType()
Definition: net.cpp:178
BeingId mNpcId
Definition: buydialog.h:200
TextField * mFilterTextField
Definition: buydialog.h:195
DropDown * mSortDropDown
Definition: buydialog.h:194
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
std::string mNick
Definition: buydialog.h:198
SortListModelBuy * mSortModel
Definition: buydialog.h:193
bool mAdvanced
Definition: buydialog.h:204
int mMaxItems
Definition: buydialog.h:203

◆ BuyDialog() [3/4]

BuyDialog::BuyDialog ( const std::string &  nick,
const std::string &  currency 
)

Constructor.

See also
Window::Window

Definition at line 233 of file buydialog.cpp.

References init().

234  :
235  // TRANSLATORS: buy dialog name
236  Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
237  ActionListener(),
240  mSortDropDown(new DropDown(this, mSortModel, false,
241  Modal_false, this, "sort")),
243  this, "namefilter", true)),
244  mFilterLabel(nullptr),
245  mNick(nick),
246  mCurrency(currency),
248  mMoney(0),
249  mAmountItems(0),
250  mMaxItems(0),
251  mAdvanced(false)
252 {
253  init();
254 }
#define _(s)
Definition: gettext.h:34
const bool LoseFocusOnTab_true
#define fromInt(val, name)
Definition: intdefines.h:45
int BeingId
Definition: beingid.h:29
Label * mFilterLabel
Definition: buydialog.h:196
void init()
Definition: buydialog.cpp:280
int mMoney
Definition: buydialog.h:201
int mAmountItems
Definition: buydialog.h:202
std::string mCurrency
Definition: buydialog.h:199
BeingId mNpcId
Definition: buydialog.h:200
TextField * mFilterTextField
Definition: buydialog.h:195
DropDown * mSortDropDown
Definition: buydialog.h:194
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
std::string mNick
Definition: buydialog.h:198
SortListModelBuy * mSortModel
Definition: buydialog.h:193
bool mAdvanced
Definition: buydialog.h:204
int mMaxItems
Definition: buydialog.h:203

◆ BuyDialog() [4/4]

BuyDialog::BuyDialog ( const Being *const  being,
const std::string &  currency 
)

Constructor.

See also
Window::Window

Definition at line 257 of file buydialog.cpp.

References init().

258  :
259  // TRANSLATORS: buy dialog name
260  Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
261  ActionListener(),
264  mSortDropDown(new DropDown(this, mSortModel, false,
265  Modal_false, this, "sort")),
267  this, "namefilter", true)),
268  mFilterLabel(nullptr),
269  mNick(being != nullptr ? being->getName() : std::string()),
270  mCurrency(currency),
272  mMoney(0),
273  mAmountItems(0),
274  mMaxItems(0),
275  mAdvanced(true)
276 {
277  init();
278 }
#define _(s)
Definition: gettext.h:34
const bool LoseFocusOnTab_true
#define fromInt(val, name)
Definition: intdefines.h:45
int BeingId
Definition: beingid.h:29
Label * mFilterLabel
Definition: buydialog.h:196
void init()
Definition: buydialog.cpp:280
int mMoney
Definition: buydialog.h:201
int mAmountItems
Definition: buydialog.h:202
std::string mCurrency
Definition: buydialog.h:199
const std::string & getName() const
Definition: being.h:233
BeingId mNpcId
Definition: buydialog.h:200
TextField * mFilterTextField
Definition: buydialog.h:195
DropDown * mSortDropDown
Definition: buydialog.h:194
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
std::string mNick
Definition: buydialog.h:198
SortListModelBuy * mSortModel
Definition: buydialog.h:193
bool mAdvanced
Definition: buydialog.h:204
int mMaxItems
Definition: buydialog.h:203

◆ ~BuyDialog()

BuyDialog::~BuyDialog ( )

Destructor

Definition at line 419 of file buydialog.cpp.

References buySellHandler, Net::BuySellHandler::cleanDialogReference(), delete2, instances, mShopItems, and mSortModel.

420 {
423  instances.remove(this);
424  if (buySellHandler != nullptr)
426 }
virtual void cleanDialogReference(const BuyDialog *const dialog) const =0
static DialogList instances
Definition: buydialog.h:177
#define delete2(var)
Definition: delete2.h:24
ShopItems * mShopItems
Definition: buydialog.h:192
Net::BuySellHandler * buySellHandler
Definition: net.cpp:93
SortListModelBuy * mSortModel
Definition: buydialog.h:193

Member Function Documentation

◆ action()

void BuyDialog::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 520 of file buydialog.cpp.

References actorManager, TradeWindow::addAutoMoney(), adminHandler, ShopItems::allItems(), applyNameFilter(), ShopItems::at(), Net::CashShopHandler::buyItem(), Net::MarketHandler::buyItem(), Net::NpcHandler::buyItem(), Net::CashShopHandler::buyItems(), Net::MarketHandler::buyItems(), Net::VendingHandler::buyItems(), Net::NpcHandler::buyItems(), buySellHandler, Cash, cashShopHandler, CAST_S32, close(), config, Net::AdminHandler::createItems(), ActorManager::findBeingByName(), fromInt, Item::getColor(), Item::getId(), ShopItems::getNumberOfElements(), ShopItem::getPrice(), DropDown::getSelected(), ListBox::getSelected(), TextField::getText(), Item::getType(), IntTextField::getValue(), Slider::getValue(), Item::increaseQuantity(), ShopItem::increaseUsedQuantity(), ServerCommandType::item, Items, mAdvanced, mAmountField, mAmountItems, Market, marketHandler, mConfirmButton, mFilterTextField, mMaxItems, mNick, mNpcId, mShopItemList, mShopItems, mSlider, mSortDropDown, Nick, npcHandler, ActorType::Player, Net::BuySellHandler::sendBuyRequest(), Widget::setEnabled(), IntTextField::setValue(), Slider::setValue(), Configuration::setValue(), sort(), tradeWindow, ShopItem::update(), updateButtonsAndLabels(), updateSlider(), Vending, and vendingHandler.

521 {
522  const std::string &eventId = event.getId();
523  if (eventId == "quit")
524  {
525  close();
526  return;
527  }
528  else if (eventId == "sort")
529  {
530  sort();
531  if (mSortDropDown != nullptr)
532  config.setValue("buySortOrder", mSortDropDown->getSelected());
533  return;
534  }
535  else if (eventId == "namefilter")
536  {
538  }
539 
540  const int selectedItem = mShopItemList->getSelected();
541 
542  // The following actions require a valid selection
543  if (selectedItem < 0 || selectedItem >= mShopItems->getNumberOfElements())
544  return;
545 
546  if (eventId == "slider")
547  {
551  }
552  else if (eventId == "inc" && mAmountItems < mMaxItems)
553  {
554  mAmountItems++;
558  }
559  else if (eventId == "dec" && mAmountItems > 1)
560  {
561  mAmountItems--;
565  }
566  else if (eventId == "max")
567  {
572  }
573  else if (eventId == "amount")
574  {
578  }
579  else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems)
580  {
581  ShopItem *const item = mShopItems->at(selectedItem);
582  if (item == nullptr)
583  return;
584  if (mNpcId == fromInt(Items, BeingId))
585  {
586  adminHandler->createItems(item->getId(),
587  item->getColor(),
588  mAmountItems);
589  }
590 #ifdef TMWA_SUPPORT
591  else if (mNpcId == fromInt(Nick, BeingId))
592  {
593  if (tradeWindow != nullptr)
594  {
596  item, mAmountItems);
598  item->getPrice() * mAmountItems);
599  }
600  }
601 #endif // TMWA_SUPPORT
602  else if (mNpcId == fromInt(Vending, BeingId))
603  {
605  item->update();
606  if (mConfirmButton != nullptr)
607  mConfirmButton->setEnabled(true);
608  }
609 #ifdef TMWA_SUPPORT
610  else if (mNpcId != fromInt(Nick, BeingId))
611 #else
612  else
613 #endif // TMWA_SUPPORT
614  {
615  if (mAdvanced)
616  {
618  item->update();
619  if (mConfirmButton != nullptr)
620  mConfirmButton->setEnabled(true);
621  }
622  else if (mNpcId == fromInt(Market, BeingId))
623  {
624  marketHandler->buyItem(item->getId(),
625  item->getType(),
626  item->getColor(),
627  mAmountItems);
629  item->update();
630  }
631  else if (mNpcId == fromInt(Cash, BeingId))
632  {
634  item->getId(),
635  item->getColor(),
636  mAmountItems);
637  }
638  else
639  {
641  item->getId(),
642  item->getColor(),
643  mAmountItems);
644  }
645 
646  updateSlider(selectedItem);
647  }
648  }
649  else if (eventId == "confirm")
650  {
651  STD_VECTOR<ShopItem*> &items = mShopItems->allItems();
652 
653  if (mNpcId == fromInt(Market, BeingId))
654  {
655  marketHandler->buyItems(items);
656  }
657  else if (mNpcId == fromInt(Vending, BeingId))
658  {
659  const Being *const being = actorManager->findBeingByName(
660  mNick,
662  if (being != nullptr)
663  {
664  vendingHandler->buyItems(being,
665  items);
666  }
667  }
668  else if (mNpcId == fromInt(Cash, BeingId))
669  {
670  cashShopHandler->buyItems(0, items);
671  }
672  else
673  {
674  npcHandler->buyItems(items);
675  }
676  close();
677  }
678 }
virtual void buyItem(const int itemId, const ItemTypeT type, const ItemColor color, const int amount) const =0
void setValue(const int value)
void addAutoMoney(const std::string &nick, const int money)
TradeWindow * tradeWindow
Definition: tradewindow.cpp:64
Being * findBeingByName(const std::string &name, const ActorTypeT type=ActorType::Unknown) const
ShopItem * at(const size_t i) const
Definition: shopitems.cpp:128
#define fromInt(val, name)
Definition: intdefines.h:45
Configuration config
int BeingId
Definition: beingid.h:29
virtual void buyItem(const BeingId beingId, const int itemId, const ItemColor color, const int amount) const =0
Slider * mSlider
Definition: buydialog.h:189
void update()
Definition: shopitem.cpp:118
virtual void buyItems(const int points, const std::vector< ShopItem *> &items) const =0
Button * mConfirmButton
Definition: buydialog.h:180
virtual void buyItems(const std::vector< ShopItem *> &items) const =0
int mAmountItems
Definition: buydialog.h:202
#define CAST_S32
Definition: cast.h:29
void sort()
Definition: buydialog.cpp:463
int getPrice() const
Definition: shopitem.h:131
double getValue() const
Definition: slider.h:203
IntTextField * mAmountField
Definition: buydialog.h:191
ItemColor getColor() const
Definition: item.h:180
void applyNameFilter(const std::string &filter)
Definition: buydialog.cpp:776
int getSelected() const
Definition: listbox.h:167
void increaseUsedQuantity(const int amount)
Definition: shopitem.cpp:158
int getValue() const
Net::MarketHandler * marketHandler
Definition: net.cpp:107
virtual void createItems(const int id, const ItemColor color, const int amount) const =0
ShopItems * mShopItems
Definition: buydialog.h:192
void setEnabled(const bool enabled)
Definition: widget.h:351
Net::CashShopHandler * cashShopHandler
Definition: net.cpp:99
virtual void sendBuyRequest(const std::string &nick, const ShopItem *const item, const int amount) const =0
Net::AdminHandler * adminHandler
Definition: net.cpp:78
virtual void buyItems(std::vector< ShopItem *> &items) const =0
BeingId mNpcId
Definition: buydialog.h:200
int getId() const
Definition: item.h:80
std::vector< ShopItem * > & allItems()
Definition: shopitems.h:138
TextField * mFilterTextField
Definition: buydialog.h:195
void setValue(const double value)
Definition: slider.cpp:473
Net::BuySellHandler * buySellHandler
Definition: net.cpp:93
ItemTypeT getType() const
Definition: item.h:224
DropDown * mSortDropDown
Definition: buydialog.h:194
virtual void buyItems(const Being *const being, const std::vector< ShopItem *> &items) const =0
Net::VendingHandler * vendingHandler
Definition: net.cpp:111
Net::NpcHandler * npcHandler
Definition: net.cpp:86
void close()
Definition: buydialog.cpp:495
void updateSlider(const int selectedItem)
Definition: buydialog.cpp:680
std::string mNick
Definition: buydialog.h:198
ShopListBox * mShopItemList
Definition: buydialog.h:185
virtual void buyItem(const int points, const int itemId, const ItemColor color, const int amount) const =0
void updateButtonsAndLabels()
Definition: buydialog.cpp:709
Definition: being.h:93
void setValue(const std::string &key, const std::string &value)
const std::string & getText() const
Definition: textfield.h:225
int getSelected() const
Definition: dropdown.cpp:505
ActorManager * actorManager
bool mAdvanced
Definition: buydialog.h:204
int mMaxItems
Definition: buydialog.h:203
int getNumberOfElements()
Definition: shopitems.h:98
void increaseQuantity(const int amount)
Definition: item.h:98

◆ addItem()

ShopItem * BuyDialog::addItem ( const int  id,
const ItemTypeT  type,
const ItemColor  color,
const int  amount,
const int  price 
)

Adds an item to the shop inventory.

Definition at line 448 of file buydialog.cpp.

References ShopItems::addItem(), ShopListBox::adjustSize(), ServerCommandType::item, mShopItemList, and mShopItems.

Referenced by Actions::doSit(), EAthena::CashShopRecv::processCashShopOpen(), EAthena::VendingRecv::processItemsList(), EAthena::MarketRecv::processMarketOpen(), EAthena::BuySellRecv::processNpcBuy(), TmwAthena::BuySellRecv::processNpcBuy(), and ShopWindow::showList().

453 {
454  ShopItem *const item = mShopItems->addItem(id,
455  type,
456  color,
457  amount,
458  price);
460  return item;
461 }
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:58
void adjustSize()
ShopItems * mShopItems
Definition: buydialog.h:192
ShopListBox * mShopItemList
Definition: buydialog.h:185

◆ applyNameFilter()

void BuyDialog::applyNameFilter ( const std::string &  filter)
private

Definition at line 776 of file buydialog.cpp.

References ShopItems::allItems(), FOR_EACH, Item::getName(), ServerCommandType::item, mShopItems, ShopItem::setVisible(), Catch::toLower(), and ShopItems::updateList().

Referenced by action(), and isActive().

777 {
778  STD_VECTOR<ShopItem*> &items = mShopItems->allItems();
779  std::string filterStr = filter;
780  toLower(filterStr);
781  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, items)
782  {
783  ShopItem *const item = *it;
784  if (item == nullptr)
785  continue;
786  std::string name = item->getName();
787  toLower(name);
788  if (name.find(filterStr) != std::string::npos)
789  item->setVisible(true);
790  else
791  item->setVisible(false);
792  }
794 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void setVisible(const bool b)
Definition: shopitem.h:142
std::string toLower(std::string const &s)
ShopItems * mShopItems
Definition: buydialog.h:192
std::string getName() const
Definition: item.cpp:139
std::vector< ShopItem * > & allItems()
Definition: shopitems.h:138
void updateList()
Definition: shopitems.cpp:197

◆ close()

void BuyDialog::close ( )
virtual

Overrideable functionality for when the window is to close. This allows for class implementations to clean up or do certain actions on window close they couldn't do otherwise.

Reimplemented from Window.

Definition at line 495 of file buydialog.cpp.

References buySellHandler, Cash, cashShopHandler, Net::VendingHandler::close(), Net::MarketHandler::close(), Net::CashShopHandler::close(), Net::BuySellHandler::close(), Window::close(), Items, Market, marketHandler, mNpcId, Nick, toInt, Vending, and vendingHandler.

Referenced by action().

496 {
497  switch (toInt(mNpcId, int))
498  {
499 #ifdef TMWA_SUPPORT
500  case Nick:
501 #endif // TMWA_SUPPORT
502  case Items:
503  break;
504  case Market:
505  marketHandler->close();
506  break;
507  case Cash:
509  break;
510  case Vending:
512  break;
513  default:
515  break;
516  }
517  Window::close();
518 }
virtual void close() const =0
virtual void close()
Definition: window.cpp:890
#define toInt(val, name)
Definition: intdefines.h:46
virtual void close() const =0
Net::MarketHandler * marketHandler
Definition: net.cpp:107
Net::CashShopHandler * cashShopHandler
Definition: net.cpp:99
BeingId mNpcId
Definition: buydialog.h:200
Net::BuySellHandler * buySellHandler
Definition: net.cpp:93
virtual void close() const =0
Net::VendingHandler * vendingHandler
Definition: net.cpp:111
virtual void close() const =0

◆ closeAll()

void BuyDialog::closeAll ( )
static

Closes all instances.

Definition at line 767 of file buydialog.cpp.

References FOR_EACH, and instances.

Referenced by DialogsManager::closeDialogs(), and isActive().

768 {
769  FOR_EACH (DialogList::const_iterator, it, instances)
770  {
771  if (*it != nullptr)
772  (*it)->close();
773  }
774 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
static DialogList instances
Definition: buydialog.h:177

◆ getNumberOfElements()

int BuyDialog::getNumberOfElements ( )

Returns the number of items in the shop inventory.

◆ init()

void BuyDialog::init ( )

Definition at line 280 of file buydialog.cpp.

References _, Widget::addActionListener(), ListBox::addSelectionListener(), Label::adjustSize(), Button::adjustSize(), ImagePosition::CENTER, Graphics::CENTER, Window::center(), config, CREATEWIDGETV, Window::enableVisibleSound(), fromBool, fromInt, Configuration::getIntValue(), Window::getLayout(), Window::getOptionBool(), Window::getPlacer(), Widget::getWidth(), instances, Items, Window::loadWindowState(), mAddMaxButton, mAdvanced, mAmountField, mAmountItems, mAmountLabel, mBuyButton, mConfirmButton, mCurrency, mDecreaseButton, mFilterLabel, mFilterTextField, mIncreaseButton, mMaxItems, mMoneyLabel, mNpcId, mQuantityLabel, mQuitButton, mScrollArea, mShopItemList, mShopItems, mSlider, mSortDropDown, Nick, SetupWindow::registerWindowForReset(), LayoutType::SET, Widget::setActionEventId(), Label::setAlignment(), Window::setCloseButton(), Window::setDefaultSize(), ListBox::setDistributeMousePressed(), Widget::setEnabled(), ScrollArea::setHorizontalScrollPolicy(), Window::setMinHeight(), Window::setMinWidth(), Window::setResizable(), LayoutCell::setRowHeight(), DropDown::setSelected(), TextField::setSendAlwaysEvents(), Window::setStickyButtonLock(), setupWindow, setVisible(), Widget::setWidth(), Window::setWindowName(), ScrollArea::SHOW_NEVER, strprintf(), ShopListBoxType::Unknown, and Visible_true.

Referenced by BuyDialog().

281 {
282  setWindowName("Buy");
283  setResizable(true);
284  setCloseButton(true);
285  setStickyButtonLock(true);
286  setMinWidth(260);
287  setMinHeight(220);
289 
290 #ifdef TMWA_SUPPORT
291  // reset advance flag for personal shops
292  if (mAdvanced &&
293  mNpcId == fromInt(Nick, BeingId))
294  {
295  mAdvanced = false;
296  }
297 #endif // TMWA_SUPPORT
298 
299  if (setupWindow != nullptr)
301 
302  mShopItems = new ShopItems(false,
303  mCurrency);
304 
308  fromBool(getOptionBool("showbackground"), Opaque),
309  "buy_background.xml");
311 
312  mSlider = new Slider(this, 1.0, 1.0);
313  mQuantityLabel = new Label(this, strprintf(
314  "%d / %d", mAmountItems, mMaxItems));
316  mMoneyLabel = new Label(this, strprintf(
317  // TRANSLATORS: buy dialog label
318  _("Price: %s / Total: %s"), "", ""));
319 
320  mAmountField = new IntTextField(this, 1, 1, 123);
321  mAmountField->setActionEventId("amount");
324  mAmountField->setEnabled(false);
325 
326  // TRANSLATORS: buy dialog label
327  mAmountLabel = new Label(this, _("Amount:"));
329 
330  // TRANSLATORS: This is a narrow symbol used to denote 'increasing'.
331  // You may change this symbol if your language uses another.
332  mIncreaseButton = new Button(this, _("+"), "inc", this);
333  // TRANSLATORS: This is a narrow symbol used to denote 'decreasing'.
334  // You may change this symbol if your language uses another.
335  mDecreaseButton = new Button(this, _("-"), "dec", this);
336  mBuyButton = new Button(this, mNpcId == fromInt(Items, BeingId)
337  // TRANSLATORS: buy dialog button
338  ? _("Create") : (mAdvanced ? _("Add") : _("Buy")), "buy", this);
339  if (mAdvanced)
340  {
341  // TRANSLATORS: buy dialog button
342  mConfirmButton = new Button(this, _("Buy"), "confirm", this);
343  mConfirmButton->setEnabled(false);
344  }
345  else
346  {
347  mConfirmButton = nullptr;
348  }
349  // TRANSLATORS: buy dialog button
350  mQuitButton = new Button(this, _("Quit"), "quit", this);
351  // TRANSLATORS: buy dialog button
352  mAddMaxButton = new Button(this, _("Max"), "max", this);
353 
356 
357  mIncreaseButton->setEnabled(false);
358  mDecreaseButton->setEnabled(false);
359  mBuyButton->setEnabled(false);
360  mSlider->setEnabled(false);
361 
362  mSlider->setActionEventId("slider");
363  mSlider->addActionListener(this);
364 
369 
371 
372  ContainerPlacer placer = getPlacer(0, 0);
373  placer(0, 0, mScrollArea, 9, 5).setPadding(3);
374  placer(0, 5, mDecreaseButton);
375  placer(1, 5, mSlider, 4);
376  placer(5, 5, mIncreaseButton);
377  placer(6, 5, mQuantityLabel, 2);
378  placer(8, 5, mAddMaxButton);
379  placer(0, 6, mAmountLabel, 2);
380  placer(2, 6, mAmountField, 2);
381  placer(0, 7, mMoneyLabel, 8);
382  if (mSortDropDown != nullptr)
383  {
384  placer(0, 8, mSortDropDown, 2);
385  }
386  else
387  {
388  // TRANSLATORS: buy dialog label
389  mFilterLabel = new Label(this, _("Filter:"));
391  placer(0, 8, mFilterLabel, 2);
392  }
393  placer(2, 8, mFilterTextField, 2);
394  if (mAdvanced)
395  {
396  placer(6, 8, mBuyButton);
397  placer(7, 8, mConfirmButton);
398  }
399  else
400  {
401  placer(7, 8, mBuyButton);
402  }
403  placer(8, 8, mQuitButton);
404 
405  Layout &layout = getLayout();
406  layout.setRowHeight(0, LayoutType::SET);
407 
408  center();
409  loadWindowState();
410  enableVisibleSound(true);
411 
412  instances.push_back(this);
414 
415  if (mSortDropDown != nullptr)
416  mSortDropDown->setSelected(config.getIntValue("buySortOrder"));
417 }
void setDefaultSize()
Definition: window.cpp:1186
#define _(s)
Definition: gettext.h:34
int getWidth() const
Definition: widget.h:220
void setWidth(const int width)
Definition: widget.cpp:132
Button * mAddMaxButton
Definition: buydialog.h:182
const bool Visible_true
Definition: visible.h:29
void loadWindowState()
Definition: window.cpp:1075
#define fromInt(val, name)
Definition: intdefines.h:45
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
Button * mIncreaseButton
Definition: buydialog.h:183
void addSelectionListener(SelectionListener *const selectionListener)
Definition: listbox.cpp:428
void setMinWidth(const int width)
Definition: window.cpp:579
static DialogList instances
Definition: buydialog.h:177
Definition: button.h:94
Configuration config
Button * mDecreaseButton
Definition: buydialog.h:184
int BeingId
Definition: beingid.h:29
Label * mFilterLabel
Definition: buydialog.h:196
bool getOptionBool(const std::string &name, const bool def=false) const
Definition: window.cpp:1454
void setDistributeMousePressed(const bool b)
Definition: listbox.h:140
int getIntValue(const std::string &key) const
Slider * mSlider
Definition: buydialog.h:189
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
Button * mConfirmButton
Definition: buydialog.h:180
void registerWindowForReset(Window *const window)
void adjustSize()
Definition: button.cpp:821
int mAmountItems
Definition: buydialog.h:202
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Definition: label.h:87
#define fromBool(val, name)
Definition: booldefines.h:48
Button * mQuitButton
Definition: buydialog.h:181
std::string mCurrency
Definition: buydialog.h:199
Button * mBuyButton
Definition: buydialog.h:179
IntTextField * mAmountField
Definition: buydialog.h:191
void setCloseButton(const bool flag)
Definition: window.cpp:737
Label * mAmountLabel
Definition: buydialog.h:190
void enableVisibleSound(bool b)
Definition: window.h:473
void setMinHeight(const int height)
Definition: window.cpp:592
ScrollArea * mScrollArea
Definition: buydialog.h:186
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1379
ShopItems * mShopItems
Definition: buydialog.h:192
void setEnabled(const bool enabled)
Definition: widget.h:351
Layout & getLayout()
Definition: window.cpp:1353
BeingId mNpcId
Definition: buydialog.h:200
void center()
Definition: window.cpp:1405
TextField * mFilterTextField
Definition: buydialog.h:195
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:152
void setSendAlwaysEvents(const bool b)
Definition: textfield.h:167
DropDown * mSortDropDown
Definition: buydialog.h:194
Label * mQuantityLabel
Definition: buydialog.h:188
void setResizable(const bool resize)
Definition: window.cpp:615
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:760
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
Definition: slider.h:85
Definition: layout.h:43
void setVisible(Visible visible)
Definition: buydialog.cpp:757
ShopListBox * mShopItemList
Definition: buydialog.h:185
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
void setSelected(int selected)
Definition: dropdown.cpp:510
void adjustSize()
Definition: label.cpp:192
Label * mMoneyLabel
Definition: buydialog.h:187
bool mAdvanced
Definition: buydialog.h:204
int mMaxItems
Definition: buydialog.h:203
void setWindowName(const std::string &name)
Definition: window.h:353
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)

◆ isActive()

static bool BuyDialog::isActive ( )
inlinestatic

Returns true if any instances exist.

Definition at line 163 of file buydialog.h.

References applyNameFilter(), closeAll(), instances, and updateSlider().

Referenced by InputManager::updateConditionMask().

164  { return !instances.empty(); }
static DialogList instances
Definition: buydialog.h:177

◆ reset()

void BuyDialog::reset ( )

Resets the dialog, clearing shop inventory.

Definition at line 436 of file buydialog.cpp.

References ShopListBox::adjustSize(), ShopItems::clear(), mShopItemList, mShopItems, mSlider, setMoney(), ListBox::setSelected(), and Slider::setValue().

437 {
438  mShopItems->clear();
440 
441  // Reset previous selected items to prevent failing asserts
443  mSlider->setValue(0);
444 
445  setMoney(0);
446 }
void setSelected(const int selected)
Definition: listbox.cpp:392
Slider * mSlider
Definition: buydialog.h:189
void adjustSize()
void clear()
Definition: shopitems.cpp:173
ShopItems * mShopItems
Definition: buydialog.h:192
void setValue(const double value)
Definition: slider.cpp:473
void setMoney(const int amount)
Definition: buydialog.cpp:428
ShopListBox * mShopItemList
Definition: buydialog.h:185

◆ setMoney()

void BuyDialog::setMoney ( const int  amount)

◆ setVisible()

void BuyDialog::setVisible ( Visible  visible)
virtual

Sets the visibility of this window.

Reimplemented from Window.

Definition at line 757 of file buydialog.cpp.

References mShopItemList, Widget::requestFocus(), Window::scheduleDelete(), Window::setVisible(), and Visible_true.

Referenced by init().

758 {
759  Window::setVisible(visible);
760 
761  if (visible == Visible_true && (mShopItemList != nullptr))
763  else
764  scheduleDelete();
765 }
const bool Visible_true
Definition: visible.h:29
virtual void requestFocus()
Definition: widget.cpp:203
virtual void scheduleDelete()
Definition: window.cpp:819
virtual void setVisible(Visible visible)
Definition: window.cpp:766
ShopListBox * mShopItemList
Definition: buydialog.h:185

◆ sort()

void BuyDialog::sort ( )

Definition at line 463 of file buydialog.cpp.

References DropDown::getSelected(), anonymous_namespace{buydialog.cpp}::itemAmountBuySorter, anonymous_namespace{buydialog.cpp}::itemIdBuySorter, anonymous_namespace{buydialog.cpp}::itemNameBuySorter, anonymous_namespace{buydialog.cpp}::itemPriceBuySorter, ShopItems::items(), anonymous_namespace{buydialog.cpp}::itemTypeBuySorter, anonymous_namespace{buydialog.cpp}::itemWeightBuySorter, mShopItems, and mSortDropDown.

Referenced by action(), Actions::doSit(), EAthena::CashShopRecv::processCashShopOpen(), EAthena::VendingRecv::processItemsList(), EAthena::MarketRecv::processMarketOpen(), TmwAthena::BuySellRecv::processNpcBuy(), EAthena::BuySellRecv::processNpcBuy(), and ShopWindow::showList().

464 {
465  if ((mSortDropDown != nullptr) && (mShopItems != nullptr))
466  {
467  STD_VECTOR<ShopItem*> &items = mShopItems->items();
468  switch (mSortDropDown->getSelected())
469  {
470  case 1:
471  std::sort(items.begin(), items.end(), itemPriceBuySorter);
472  break;
473  case 2:
474  std::sort(items.begin(), items.end(), itemNameBuySorter);
475  break;
476  case 3:
477  std::sort(items.begin(), items.end(), itemIdBuySorter);
478  break;
479  case 4:
480  std::sort(items.begin(), items.end(), itemWeightBuySorter);
481  break;
482  case 5:
483  std::sort(items.begin(), items.end(), itemAmountBuySorter);
484  break;
485  case 6:
486  std::sort(items.begin(), items.end(), itemTypeBuySorter);
487  break;
488  case 0:
489  default:
490  break;
491  }
492  }
493 }
class anonymous_namespace{buydialog.cpp}::SortItemNameFunctor itemNameBuySorter
std::vector< ShopItem * > & items()
Definition: shopitems.h:135
class anonymous_namespace{buydialog.cpp}::SortItemTypeFunctor itemTypeBuySorter
class anonymous_namespace{buydialog.cpp}::SortItemAmountFunctor itemAmountBuySorter
ShopItems * mShopItems
Definition: buydialog.h:192
class anonymous_namespace{buydialog.cpp}::SortItemIdFunctor itemIdBuySorter
DropDown * mSortDropDown
Definition: buydialog.h:194
int getSelected() const
Definition: dropdown.cpp:505
class anonymous_namespace{buydialog.cpp}::SortItemWeightFunctor itemWeightBuySorter
class anonymous_namespace{buydialog.cpp}::SortItemPriceFunctor itemPriceBuySorter

◆ updateButtonsAndLabels()

void BuyDialog::updateButtonsAndLabels ( )

Updates the state of buttons and labels.

Definition at line 709 of file buydialog.cpp.

References _, ShopItems::at(), UnitsDb::formatCurrency(), fromInt, ShopItem::getPrice(), Item::getQuantity(), ListBox::getSelected(), ServerCommandType::item, Items, mAmountField, mAmountItems, mBuyButton, mCurrency, mDecreaseButton, mIncreaseButton, mMaxItems, mMoney, mMoneyLabel, mNpcId, mQuantityLabel, mShopItemList, mShopItems, mSlider, Label::setCaption(), Widget::setEnabled(), and strprintf().

Referenced by action(), setMoney(), and valueChanged().

710 {
711  const int selectedItem = mShopItemList->getSelected();
712  int price = 0;
713 
714  if (selectedItem > -1)
715  {
716  const ShopItem *const item = mShopItems->at(selectedItem);
717  if (item != nullptr)
718  {
719  const int itemPrice = item->getPrice();
720 
721  // Calculate how many the player can afford
722  if (mNpcId == fromInt(Items, BeingId))
723  mMaxItems = 100;
724  else if (itemPrice != 0)
725  mMaxItems = mMoney / itemPrice;
726  else
727  mMaxItems = 1;
728 
729  if (item->getQuantity() > 0 && mMaxItems > item->getQuantity())
730  mMaxItems = item->getQuantity();
731 
732  if (mAmountItems > mMaxItems)
734 
735  price = mAmountItems * itemPrice;
736  }
737  }
738  else
739  {
740  mMaxItems = 0;
741  mAmountItems = 0;
742  }
743 
749 
751  // TRANSLATORS: buy dialog label
752  mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
753  UnitsDb::formatCurrency(mCurrency, price).c_str(),
754  UnitsDb::formatCurrency(mCurrency, mMoney - price).c_str()));
755 }
#define _(s)
Definition: gettext.h:34
ShopItem * at(const size_t i) const
Definition: shopitems.cpp:128
#define fromInt(val, name)
Definition: intdefines.h:45
Button * mIncreaseButton
Definition: buydialog.h:183
Button * mDecreaseButton
Definition: buydialog.h:184
int BeingId
Definition: beingid.h:29
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:323
Slider * mSlider
Definition: buydialog.h:189
int mMoney
Definition: buydialog.h:201
int mAmountItems
Definition: buydialog.h:202
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:256
int getPrice() const
Definition: shopitem.h:131
int getQuantity() const
Definition: item.h:104
std::string mCurrency
Definition: buydialog.h:199
Button * mBuyButton
Definition: buydialog.h:179
IntTextField * mAmountField
Definition: buydialog.h:191
int getSelected() const
Definition: listbox.h:167
ShopItems * mShopItems
Definition: buydialog.h:192
void setEnabled(const bool enabled)
Definition: widget.h:351
BeingId mNpcId
Definition: buydialog.h:200
Label * mQuantityLabel
Definition: buydialog.h:188
ShopListBox * mShopItemList
Definition: buydialog.h:185
Label * mMoneyLabel
Definition: buydialog.h:187
int mMaxItems
Definition: buydialog.h:203

◆ updateSlider()

void BuyDialog::updateSlider ( const int  selectedItem)
private

Definition at line 680 of file buydialog.cpp.

References ShopItems::at(), ShopItem::getPrice(), ServerCommandType::item, mAmountItems, mMaxItems, mMoney, mShopItems, mSlider, setMoney(), Slider::setScale(), and Slider::setValue().

Referenced by action(), and isActive().

681 {
682  // Update money and adjust the max number of items
683  // that can be bought
685  const ShopItem *const item = mShopItems->at(selectedItem);
686  if (item != nullptr)
687  setMoney(mMoney - mAmountItems * item->getPrice());
688  else
689  setMoney(mMoney);
690 
691  // Reset selection
692  mAmountItems = 1;
694  mSlider->setValue(1);
695 }
ShopItem * at(const size_t i) const
Definition: shopitems.cpp:128
Slider * mSlider
Definition: buydialog.h:189
void setScale(const double scaleStart, const double scaleEnd)
Definition: slider.cpp:467
int mMoney
Definition: buydialog.h:201
int mAmountItems
Definition: buydialog.h:202
int getPrice() const
Definition: shopitem.h:131
ShopItems * mShopItems
Definition: buydialog.h:192
void setValue(const double value)
Definition: slider.cpp:473
void setMoney(const int amount)
Definition: buydialog.cpp:428
int mMaxItems
Definition: buydialog.h:203

◆ valueChanged()

void BuyDialog::valueChanged ( const SelectionEvent event)
virtual

Updates the labels according to the selected item.

Reimplemented from SelectionListener.

Definition at line 697 of file buydialog.cpp.

References mAmountField, mAmountItems, mMaxItems, mSlider, IntTextField::setRange(), Slider::setScale(), IntTextField::setValue(), Slider::setValue(), and updateButtonsAndLabels().

698 {
699  // Reset amount of items and update labels
700  mAmountItems = 1;
701  mSlider->setValue(1);
702 
707 }
void setValue(const int value)
Slider * mSlider
Definition: buydialog.h:189
void setScale(const double scaleStart, const double scaleEnd)
Definition: slider.cpp:467
int mAmountItems
Definition: buydialog.h:202
IntTextField * mAmountField
Definition: buydialog.h:191
void setRange(const int minimum, const int maximum)
void setValue(const double value)
Definition: slider.cpp:473
void updateButtonsAndLabels()
Definition: buydialog.cpp:709
int mMaxItems
Definition: buydialog.h:203

Field Documentation

◆ instances

BuyDialog::DialogList BuyDialog::instances
staticprivate

◆ mAddMaxButton

Button* BuyDialog::mAddMaxButton
private

Definition at line 182 of file buydialog.h.

Referenced by init().

◆ mAdvanced

bool BuyDialog::mAdvanced
private

Definition at line 204 of file buydialog.h.

Referenced by action(), and init().

◆ mAmountField

IntTextField* BuyDialog::mAmountField
private

Definition at line 191 of file buydialog.h.

Referenced by action(), init(), updateButtonsAndLabels(), and valueChanged().

◆ mAmountItems

int BuyDialog::mAmountItems
private

Definition at line 202 of file buydialog.h.

Referenced by action(), init(), updateButtonsAndLabels(), updateSlider(), and valueChanged().

◆ mAmountLabel

Label* BuyDialog::mAmountLabel
private

Definition at line 190 of file buydialog.h.

Referenced by init().

◆ mBuyButton

Button* BuyDialog::mBuyButton
private

Definition at line 179 of file buydialog.h.

Referenced by init(), and updateButtonsAndLabels().

◆ mConfirmButton

Button* BuyDialog::mConfirmButton
private

Definition at line 180 of file buydialog.h.

Referenced by action(), and init().

◆ mCurrency

std::string BuyDialog::mCurrency
private

Definition at line 199 of file buydialog.h.

Referenced by init(), and updateButtonsAndLabels().

◆ mDecreaseButton

Button* BuyDialog::mDecreaseButton
private

Definition at line 184 of file buydialog.h.

Referenced by init(), and updateButtonsAndLabels().

◆ mFilterLabel

Label* BuyDialog::mFilterLabel
private

Definition at line 196 of file buydialog.h.

Referenced by init().

◆ mFilterTextField

TextField* BuyDialog::mFilterTextField
private

Definition at line 195 of file buydialog.h.

Referenced by action(), and init().

◆ mIncreaseButton

Button* BuyDialog::mIncreaseButton
private

Definition at line 183 of file buydialog.h.

Referenced by init(), and updateButtonsAndLabels().

◆ mMaxItems

int BuyDialog::mMaxItems
private

Definition at line 203 of file buydialog.h.

Referenced by action(), init(), updateButtonsAndLabels(), updateSlider(), and valueChanged().

◆ mMoney

int BuyDialog::mMoney
private

Definition at line 201 of file buydialog.h.

Referenced by setMoney(), updateButtonsAndLabels(), and updateSlider().

◆ mMoneyLabel

Label* BuyDialog::mMoneyLabel
private

Definition at line 187 of file buydialog.h.

Referenced by init(), and updateButtonsAndLabels().

◆ mNick

std::string BuyDialog::mNick
private

Definition at line 198 of file buydialog.h.

Referenced by action().

◆ mNpcId

BeingId BuyDialog::mNpcId
private

Definition at line 200 of file buydialog.h.

Referenced by action(), close(), init(), and updateButtonsAndLabels().

◆ mQuantityLabel

Label* BuyDialog::mQuantityLabel
private

Definition at line 188 of file buydialog.h.

Referenced by init(), and updateButtonsAndLabels().

◆ mQuitButton

Button* BuyDialog::mQuitButton
private

Definition at line 181 of file buydialog.h.

Referenced by init().

◆ mScrollArea

ScrollArea* BuyDialog::mScrollArea
private

Definition at line 186 of file buydialog.h.

Referenced by init().

◆ mShopItemList

ShopListBox* BuyDialog::mShopItemList
private

Definition at line 185 of file buydialog.h.

Referenced by action(), addItem(), init(), reset(), setMoney(), setVisible(), and updateButtonsAndLabels().

◆ mShopItems

ShopItems* BuyDialog::mShopItems
private

◆ mSlider

Slider* BuyDialog::mSlider
private

Definition at line 189 of file buydialog.h.

Referenced by action(), init(), reset(), updateButtonsAndLabels(), updateSlider(), and valueChanged().

◆ mSortDropDown

DropDown* BuyDialog::mSortDropDown
private

Definition at line 194 of file buydialog.h.

Referenced by action(), init(), and sort().

◆ mSortModel

SortListModelBuy* BuyDialog::mSortModel
private

Definition at line 193 of file buydialog.h.

Referenced by ~BuyDialog().


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