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, 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
 
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, 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 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) 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 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(),
195  mSortDropDown(new DropDown(this, mSortModel, false,
196  Modal_false, this, "sort")),
198  this, "namefilter", true)),
199  mFilterLabel(nullptr),
200  mNick(),
201  mCurrency(),
203  mMoney(0),
204  mAmountItems(0),
205  mMaxItems(0),
206  mAdvanced(false)
207 {
208  init();
209 }
#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:281
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
std::string mNick
Definition: buydialog.h:198
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
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 211 of file buydialog.cpp.

References init().

212  :
213  // TRANSLATORS: buy dialog name
214  Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
215  ActionListener(),
217  mSortModel(nullptr),
218  mSortDropDown(nullptr),
220  this, "namefilter", true)),
221  mFilterLabel(nullptr),
222  mNick(),
223  mCurrency(currency),
224  mNpcId(npcId),
225  mMoney(0),
226  mAmountItems(0),
227  mMaxItems(0),
229 {
230  init();
231 }
#define _(s)
Definition: gettext.h:34
const bool LoseFocusOnTab_true
Label * mFilterLabel
Definition: buydialog.h:196
void init()
Definition: buydialog.cpp:281
int mMoney
Definition: buydialog.h:201
int mAmountItems
Definition: buydialog.h:202
std::string mCurrency
Definition: buydialog.h:199
ServerTypeT getNetworkType()
Definition: net.cpp:182
BeingId mNpcId
Definition: buydialog.h:200
TextField * mFilterTextField
Definition: buydialog.h:195
DropDown * mSortDropDown
Definition: buydialog.h:194
std::string mNick
Definition: buydialog.h:198
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
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 234 of file buydialog.cpp.

References init().

235  :
236  // TRANSLATORS: buy dialog name
237  Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
238  ActionListener(),
241  mSortDropDown(new DropDown(this, mSortModel, false,
242  Modal_false, this, "sort")),
244  this, "namefilter", true)),
245  mFilterLabel(nullptr),
246  mNick(nick),
247  mCurrency(currency),
249  mMoney(0),
250  mAmountItems(0),
251  mMaxItems(0),
252  mAdvanced(false)
253 {
254  init();
255 }
#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:281
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
std::string mNick
Definition: buydialog.h:198
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
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 258 of file buydialog.cpp.

References init().

259  :
260  // TRANSLATORS: buy dialog name
261  Window(_("Buy"), Modal_false, nullptr, "buy.xml"),
262  ActionListener(),
265  mSortDropDown(new DropDown(this, mSortModel, false,
266  Modal_false, this, "sort")),
268  this, "namefilter", true)),
269  mFilterLabel(nullptr),
270  mNick(being != nullptr ? being->getName() : std::string()),
271  mCurrency(currency),
273  mMoney(0),
274  mAmountItems(0),
275  mMaxItems(0),
276  mAdvanced(true)
277 {
278  init();
279 }
#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:281
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:231
BeingId mNpcId
Definition: buydialog.h:200
TextField * mFilterTextField
Definition: buydialog.h:195
DropDown * mSortDropDown
Definition: buydialog.h:194
std::string mNick
Definition: buydialog.h:198
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
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 427 of file buydialog.cpp.

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

428 {
431  instances.remove(this);
432  if (buySellHandler != nullptr)
434 }
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:96
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 528 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.

529 {
530  const std::string &eventId = event.getId();
531  if (eventId == "quit")
532  {
533  close();
534  return;
535  }
536  else if (eventId == "sort")
537  {
538  sort();
539  if (mSortDropDown != nullptr)
540  config.setValue("buySortOrder", mSortDropDown->getSelected());
541  return;
542  }
543  else if (eventId == "namefilter")
544  {
546  }
547 
548  const int selectedItem = mShopItemList->getSelected();
549 
550  // The following actions require a valid selection
551  if (selectedItem < 0 || selectedItem >= mShopItems->getNumberOfElements())
552  return;
553 
554  if (eventId == "slider")
555  {
559  }
560  else if (eventId == "inc" && mAmountItems < mMaxItems)
561  {
562  mAmountItems++;
566  }
567  else if (eventId == "dec" && mAmountItems > 1)
568  {
569  mAmountItems--;
573  }
574  else if (eventId == "max")
575  {
580  }
581  else if (eventId == "amount")
582  {
586  }
587  else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems)
588  {
589  ShopItem *const item = mShopItems->at(selectedItem);
590  if (item == nullptr)
591  return;
592  if (mNpcId == fromInt(Items, BeingId))
593  {
594  adminHandler->createItems(item->getId(),
595  item->getColor(),
596  mAmountItems);
597  }
598 #ifdef TMWA_SUPPORT
599  else if (mNpcId == fromInt(Nick, BeingId))
600  {
601  if (tradeWindow != nullptr)
602  {
604  item, mAmountItems);
606  item->getPrice() * mAmountItems);
607  }
608  }
609 #endif // TMWA_SUPPORT
610  else if (mNpcId == fromInt(Vending, BeingId))
611  {
613  item->update();
614  if (mConfirmButton != nullptr)
615  mConfirmButton->setEnabled(true);
616  }
617 #ifdef TMWA_SUPPORT
618  else if (mNpcId != fromInt(Nick, BeingId))
619 #else
620  else
621 #endif // TMWA_SUPPORT
622  {
623  if (mAdvanced)
624  {
626  item->update();
627  if (mConfirmButton != nullptr)
628  mConfirmButton->setEnabled(true);
629  }
630  else if (mNpcId == fromInt(Market, BeingId))
631  {
632  marketHandler->buyItem(item->getId(),
633  item->getType(),
634  item->getColor(),
635  mAmountItems);
637  item->update();
638  }
639  else if (mNpcId == fromInt(Cash, BeingId))
640  {
642  item->getId(),
643  item->getColor(),
644  mAmountItems);
645  }
646  else
647  {
649  item->getId(),
650  item->getColor(),
651  mAmountItems);
652  }
653 
654  updateSlider(selectedItem);
655  }
656  }
657  else if (eventId == "confirm")
658  {
659  STD_VECTOR<ShopItem*> &items = mShopItems->allItems();
660 
661  if (mNpcId == fromInt(Market, BeingId))
662  {
663  marketHandler->buyItems(items);
664  }
665  else if (mNpcId == fromInt(Vending, BeingId))
666  {
667  const Being *const being = actorManager->findBeingByName(
668  mNick,
670  if (being != nullptr)
671  {
672  vendingHandler->buyItems(being,
673  items);
674  }
675  }
676  else if (mNpcId == fromInt(Cash, BeingId))
677  {
678  cashShopHandler->buyItems(0, items);
679  }
680  else
681  {
682  npcHandler->buyItems(items);
683  }
684  close();
685  }
686 }
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
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:471
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:792
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:111
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:103
virtual void sendBuyRequest(const std::string &nick, const ShopItem *const item, const int amount) const =0
Net::AdminHandler * adminHandler
Definition: net.cpp:80
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:96
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
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
Net::VendingHandler * vendingHandler
Definition: net.cpp:115
Net::NpcHandler * npcHandler
Definition: net.cpp:89
void close()
Definition: buydialog.cpp:503
void updateSlider(const int selectedItem)
Definition: buydialog.cpp:688
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:717
Definition: being.h:93
void setValue(const std::string &key, const std::string &value)
const std::string & getText() const
Definition: textfield.h:223
int getSelected() const
Definition: dropdown.cpp:509
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 456 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().

461 {
462  ShopItem *const item = mShopItems->addItem(id,
463  type,
464  color,
465  amount,
466  price);
468  return item;
469 }
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 792 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().

793 {
794  STD_VECTOR<ShopItem*> &items = mShopItems->allItems();
795  std::string filterStr = filter;
796  toLower(filterStr);
797  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, items)
798  {
799  ShopItem *const item = *it;
800  if (item == nullptr)
801  continue;
802  std::string name = item->getName();
803  toLower(name);
804  if (name.find(filterStr) != std::string::npos)
805  item->setVisible(true);
806  else
807  item->setVisible(false);
808  }
810 }
#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 503 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().

504 {
505  switch (toInt(mNpcId, int))
506  {
507 #ifdef TMWA_SUPPORT
508  case Nick:
509 #endif // TMWA_SUPPORT
510  case Items:
511  break;
512  case Market:
513  marketHandler->close();
514  break;
515  case Cash:
517  break;
518  case Vending:
520  break;
521  default:
523  break;
524  }
525  Window::close();
526 }
virtual void close() const =0
virtual void close()
Definition: window.cpp:897
#define toInt(val, name)
Definition: intdefines.h:46
virtual void close() const =0
Net::MarketHandler * marketHandler
Definition: net.cpp:111
Net::CashShopHandler * cashShopHandler
Definition: net.cpp:103
BeingId mNpcId
Definition: buydialog.h:200
Net::BuySellHandler * buySellHandler
Definition: net.cpp:96
virtual void close() const =0
Net::VendingHandler * vendingHandler
Definition: net.cpp:115
virtual void close() const =0

◆ closeAll()

void BuyDialog::closeAll ( )
static

Closes all instances.

Definition at line 783 of file buydialog.cpp.

References FOR_EACH, and instances.

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

784 {
785  FOR_EACH (DialogList::const_iterator, it, instances)
786  {
787  if (*it != nullptr)
788  (*it)->close();
789  }
790 }
#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 281 of file buydialog.cpp.

References _, Widget::addActionListener(), ListBox::addSelectionListener(), Label::adjustSize(), Button::adjustSize(), BUTTON_SKIN, ImagePosition::CENTER, Graphics::CENTER, Window::center(), config, CREATEWIDGETV, Enable_true, 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().

282 {
283  setWindowName("Buy");
284  setResizable(true);
285  setCloseButton(true);
286  setStickyButtonLock(true);
287  setMinWidth(260);
288  setMinHeight(220);
289  setDefaultSize(260, 230, ImagePosition::CENTER, 0, 0);
290 
291 #ifdef TMWA_SUPPORT
292  // reset advance flag for personal shops
293  if (mAdvanced &&
294  mNpcId == fromInt(Nick, BeingId))
295  {
296  mAdvanced = false;
297  }
298 #endif // TMWA_SUPPORT
299 
300  if (setupWindow != nullptr)
302 
303  mShopItems = new ShopItems(false,
304  mCurrency);
305 
309  fromBool(getOptionBool("showbackground", false), Opaque),
310  "buy_background.xml");
312 
313  mSlider = new Slider(this, 1.0, 1.0);
314  mQuantityLabel = new Label(this, strprintf(
315  "%d / %d", mAmountItems, mMaxItems));
317  mMoneyLabel = new Label(this, strprintf(
318  // TRANSLATORS: buy dialog label
319  _("Price: %s / Total: %s"), "", ""));
320 
321  mAmountField = new IntTextField(this, 1, 1, 123, Enable_true, 0);
322  mAmountField->setActionEventId("amount");
325  mAmountField->setEnabled(false);
326 
327  // TRANSLATORS: buy dialog label
328  mAmountLabel = new Label(this, _("Amount:"));
330 
331  // TRANSLATORS: This is a narrow symbol used to denote 'increasing'.
332  // You may change this symbol if your language uses another.
333  mIncreaseButton = new Button(this, _("+"), "inc", BUTTON_SKIN, this);
334  // TRANSLATORS: This is a narrow symbol used to denote 'decreasing'.
335  // You may change this symbol if your language uses another.
336  mDecreaseButton = new Button(this, _("-"), "dec", BUTTON_SKIN, this);
337  mBuyButton = new Button(this, mNpcId == fromInt(Items, BeingId)
338  // TRANSLATORS: buy dialog button
339  ? _("Create") : (mAdvanced ? _("Add") : _("Buy")),
340  "buy",
341  BUTTON_SKIN,
342  this);
343  if (mAdvanced)
344  {
345  mConfirmButton = new Button(this,
346  // TRANSLATORS: buy dialog button
347  _("Buy"),
348  "confirm",
349  BUTTON_SKIN,
350  this);
351  mConfirmButton->setEnabled(false);
352  }
353  else
354  {
355  mConfirmButton = nullptr;
356  }
357  // TRANSLATORS: buy dialog button
358  mQuitButton = new Button(this, _("Quit"), "quit", BUTTON_SKIN, this);
359  // TRANSLATORS: buy dialog button
360  mAddMaxButton = new Button(this, _("Max"), "max", BUTTON_SKIN, this);
361 
364 
365  mIncreaseButton->setEnabled(false);
366  mDecreaseButton->setEnabled(false);
367  mBuyButton->setEnabled(false);
368  mSlider->setEnabled(false);
369 
370  mSlider->setActionEventId("slider");
371  mSlider->addActionListener(this);
372 
377 
379 
380  ContainerPlacer placer = getPlacer(0, 0);
381  placer(0, 0, mScrollArea, 9, 5).setPadding(3);
382  placer(0, 5, mDecreaseButton, 1, 1);
383  placer(1, 5, mSlider, 4, 1);
384  placer(5, 5, mIncreaseButton, 1, 1);
385  placer(6, 5, mQuantityLabel, 2, 1);
386  placer(8, 5, mAddMaxButton, 1, 1);
387  placer(0, 6, mAmountLabel, 2, 1);
388  placer(2, 6, mAmountField, 2, 1);
389  placer(0, 7, mMoneyLabel, 8, 1);
390  if (mSortDropDown != nullptr)
391  {
392  placer(0, 8, mSortDropDown, 2, 1);
393  }
394  else
395  {
396  // TRANSLATORS: buy dialog label
397  mFilterLabel = new Label(this, _("Filter:"));
399  placer(0, 8, mFilterLabel, 2, 1);
400  }
401  placer(2, 8, mFilterTextField, 2, 1);
402  if (mAdvanced)
403  {
404  placer(6, 8, mBuyButton, 1, 1);
405  placer(7, 8, mConfirmButton, 1, 1);
406  }
407  else
408  {
409  placer(7, 8, mBuyButton, 1, 1);
410  }
411  placer(8, 8, mQuitButton, 1, 1);
412 
413  Layout &layout = getLayout();
414  layout.setRowHeight(0, LayoutType::SET);
415 
416  center();
417  loadWindowState();
418  enableVisibleSound(true);
419 
420  instances.push_back(this);
422 
423  if (mSortDropDown != nullptr)
424  mSortDropDown->setSelected(config.getIntValue("buySortOrder"));
425 }
void setDefaultSize()
Definition: window.cpp:1193
#define _(s)
Definition: gettext.h:34
int getWidth() const
Definition: widget.h:220
void setWidth(const int width)
Definition: widget.cpp:132
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1461
Button * mAddMaxButton
Definition: buydialog.h:182
const bool Visible_true
Definition: visible.h:29
void loadWindowState()
Definition: window.cpp:1082
#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:434
void setMinWidth(const int width)
Definition: window.cpp:586
static DialogList instances
Definition: buydialog.h:177
Definition: button.h:96
Configuration config
Button * mDecreaseButton
Definition: buydialog.h:184
int BeingId
Definition: beingid.h:29
Label * mFilterLabel
Definition: buydialog.h:196
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
const bool Enable_true
Definition: enable.h:29
Button * mConfirmButton
Definition: buydialog.h:180
void registerWindowForReset(Window *const window)
void adjustSize()
Definition: button.cpp:798
int mAmountItems
Definition: buydialog.h:202
const std::string BUTTON_SKIN
Definition: button.h:88
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:744
Label * mAmountLabel
Definition: buydialog.h:190
void enableVisibleSound(bool b)
Definition: window.h:480
void setMinHeight(const int height)
Definition: window.cpp:599
ScrollArea * mScrollArea
Definition: buydialog.h:186
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1386
ShopItems * mShopItems
Definition: buydialog.h:192
void setEnabled(const bool enabled)
Definition: widget.h:351
Layout & getLayout()
Definition: window.cpp:1360
BeingId mNpcId
Definition: buydialog.h:200
void center()
Definition: window.cpp:1412
TextField * mFilterTextField
Definition: buydialog.h:195
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:152
void setSendAlwaysEvents(const bool b)
Definition: textfield.h:165
DropDown * mSortDropDown
Definition: buydialog.h:194
Label * mQuantityLabel
Definition: buydialog.h:188
void setResizable(const bool resize)
Definition: window.cpp:622
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:767
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
Definition: slider.h:85
Definition: layout.h:43
void setVisible(Visible visible)
Definition: buydialog.cpp:773
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:514
void adjustSize()
Definition: label.cpp:197
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:354
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 444 of file buydialog.cpp.

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

445 {
446  mShopItems->clear();
448 
449  // Reset previous selected items to prevent failing asserts
451  mSlider->setValue(0);
452 
453  setMoney(0);
454 }
void setSelected(const int selected)
Definition: listbox.cpp:398
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:436
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 773 of file buydialog.cpp.

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

Referenced by init().

774 {
775  Window::setVisible(visible);
776 
777  if (visible == Visible_true && (mShopItemList != nullptr))
779  else
780  scheduleDelete();
781 }
const bool Visible_true
Definition: visible.h:29
virtual void requestFocus()
Definition: widget.cpp:203
virtual void scheduleDelete()
Definition: window.cpp:826
virtual void setVisible(Visible visible)
Definition: window.cpp:773
ShopListBox * mShopItemList
Definition: buydialog.h:185

◆ sort()

void BuyDialog::sort ( )

Definition at line 471 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().

472 {
473  if ((mSortDropDown != nullptr) && (mShopItems != nullptr))
474  {
475  STD_VECTOR<ShopItem*> &items = mShopItems->items();
476  switch (mSortDropDown->getSelected())
477  {
478  case 1:
479  std::sort(items.begin(), items.end(), itemPriceBuySorter);
480  break;
481  case 2:
482  std::sort(items.begin(), items.end(), itemNameBuySorter);
483  break;
484  case 3:
485  std::sort(items.begin(), items.end(), itemIdBuySorter);
486  break;
487  case 4:
488  std::sort(items.begin(), items.end(), itemWeightBuySorter);
489  break;
490  case 5:
491  std::sort(items.begin(), items.end(), itemAmountBuySorter);
492  break;
493  case 6:
494  std::sort(items.begin(), items.end(), itemTypeBuySorter);
495  break;
496  case 0:
497  default:
498  break;
499  }
500  }
501 }
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:509
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 717 of file buydialog.cpp.

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

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

718 {
719  const int selectedItem = mShopItemList->getSelected();
720  int price = 0;
721 
722  if (selectedItem > -1)
723  {
724  const ShopItem *const item = mShopItems->at(selectedItem);
725  if (item != nullptr)
726  {
727  const int itemPrice = item->getPrice();
728 
729  // Calculate how many the player can afford
730  if (mNpcId == fromInt(Items, BeingId))
731  mMaxItems = 100;
732  else if (itemPrice != 0)
733  mMaxItems = mMoney / itemPrice;
734  else
735  mMaxItems = 1;
736 
737  if (mNpcId == fromInt(Market, BeingId))
738  {
739  if (mMaxItems > item->getQuantity())
740  mMaxItems = item->getQuantity();
741  }
742  else if (item->getQuantity() > 0 &&
743  mMaxItems > item->getQuantity())
744  {
745  mMaxItems = item->getQuantity();
746  }
747 
748  if (mAmountItems > mMaxItems)
750 
751  price = mAmountItems * itemPrice;
752  }
753  }
754  else
755  {
756  mMaxItems = 0;
757  mAmountItems = 0;
758  }
759 
765 
767  // TRANSLATORS: buy dialog label
768  mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
769  UnitsDb::formatCurrency(mCurrency, price).c_str(),
770  UnitsDb::formatCurrency(mCurrency, mMoney - price).c_str()));
771 }
#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:261
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 688 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().

689 {
690  // Update money and adjust the max number of items
691  // that can be bought
693  const ShopItem *const item = mShopItems->at(selectedItem);
694  if (item != nullptr)
695  setMoney(mMoney - mAmountItems * item->getPrice());
696  else
697  setMoney(mMoney);
698 
699  // Reset selection
700  mAmountItems = 1;
702  mSlider->setValue(1);
703 }
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:436
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 705 of file buydialog.cpp.

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

706 {
707  // Reset amount of items and update labels
708  mAmountItems = 1;
709  mSlider->setValue(1);
710 
715 }
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:717
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: