ManaPlus
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes
SellDialog Class Referenceabstract

#include <selldialog.h>

Inheritance diagram for SellDialog:
Window ActionListener SelectionListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2 BuyingStoreSellDialog EggSelectionDialog InsertCardDialog NpcSellDialog ShopSellDialog

Public Member Functions

 SellDialog (const IsSell isSell, const Advanced advanced)
 
 ~SellDialog ()
 
void reset ()
 
void addItem (const Item *const item, const int price)
 
void action (const ActionEvent &event)
 
void valueChanged (const SelectionEvent &event)
 
void setMoney (const int amount)
 
void setVisible (Visible visible)
 
ShopItemaddItem (const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
 
void postInit ()
 
- 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 ()
 
virtual void close ()
 
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 ()
 

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)
 

Protected Types

typedef std::list< SellDialog * > DialogList
 
- 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

void updateButtonsAndLabels ()
 
virtual void sellAction (const ActionEvent &event)=0
 
virtual void initButtons ()
 
- 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 Attributes

ButtonmSellButton
 
ButtonmQuitButton
 
ButtonmConfirmButton
 
ButtonmAddMaxButton
 
ButtonmIncreaseButton
 
ButtonmDecreaseButton
 
ShopListBoxmShopItemList
 
ScrollAreamScrollArea
 
LabelmMoneyLabel
 
LabelmQuantityLabel
 
SlidermSlider
 
ShopItemsmShopItems
 
int mPlayerMoney
 
int mMaxItems
 
int mAmountItems
 
IsSell mIsSell
 
Advanced mAdvanced
 
- 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

static DialogList instances
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
 
- Private Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 
 SelectionListener ()
 

Detailed Description

The sell dialog.

Definition at line 51 of file selldialog.h.

Member Typedef Documentation

◆ DialogList

typedef std::list<SellDialog*> SellDialog::DialogList
protected

Definition at line 122 of file selldialog.h.

Constructor & Destructor Documentation

◆ SellDialog()

SellDialog::SellDialog ( const IsSell  isSell,
const Advanced  advanced 
)

Constructor.

Definition at line 55 of file selldialog.cpp.

56  :
57  // TRANSLATORS: sell dialog name
58  Window(_("Sell"), Modal_false, nullptr, "sell.xml"),
61  mSellButton(nullptr),
62  mQuitButton(nullptr),
63  mConfirmButton(nullptr),
64  mAddMaxButton(nullptr),
65  mIncreaseButton(nullptr),
66  mDecreaseButton(nullptr),
67  mShopItemList(nullptr),
68  mScrollArea(nullptr),
69  mMoneyLabel(nullptr),
70  mQuantityLabel(nullptr),
71  mSlider(nullptr),
72  mShopItems(nullptr),
73  mPlayerMoney(0),
74  mMaxItems(0),
75  mAmountItems(0),
76  mIsSell(isSell),
77  mAdvanced(advanced)
78 {
79 }
#define _(s)
Definition: gettext.h:34
int mAmountItems
Definition: selldialog.h:150
IsSell mIsSell
Definition: selldialog.h:152
Button * mIncreaseButton
Definition: selldialog.h:139
Label * mQuantityLabel
Definition: selldialog.h:144
Slider * mSlider
Definition: selldialog.h:145
Advanced mAdvanced
Definition: selldialog.h:153
Label * mMoneyLabel
Definition: selldialog.h:143
int mMaxItems
Definition: selldialog.h:149
Button * mConfirmButton
Definition: selldialog.h:137
Button * mSellButton
Definition: selldialog.h:135
Button * mQuitButton
Definition: selldialog.h:136
ShopItems * mShopItems
Definition: selldialog.h:146
Button * mAddMaxButton
Definition: selldialog.h:138
ShopListBox * mShopItemList
Definition: selldialog.h:141
ScrollArea * mScrollArea
Definition: selldialog.h:142
int mPlayerMoney
Definition: selldialog.h:148
Button * mDecreaseButton
Definition: selldialog.h:140
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108

◆ ~SellDialog()

SellDialog::~SellDialog ( )

Destructor

Definition at line 222 of file selldialog.cpp.

References delete2, instances, and mShopItems.

223 {
225  instances.remove(this);
226 }
#define delete2(var)
Definition: delete2.h:24
static DialogList instances
Definition: selldialog.h:123
ShopItems * mShopItems
Definition: selldialog.h:146

Member Function Documentation

◆ action()

void SellDialog::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 268 of file selldialog.cpp.

References CAST_S32, Window::close(), ShopItems::getNumberOfElements(), ListBox::getSelected(), Slider::getValue(), mAmountItems, mMaxItems, mShopItemList, mShopItems, mSlider, sellAction(), Slider::setValue(), and updateButtonsAndLabels().

269 {
270  const std::string &eventId = event.getId();
271 
272  if (eventId == "quit")
273  {
274  close();
275  return;
276  }
277 
278  const int selectedItem = mShopItemList->getSelected();
279 
280  // The following actions require a valid item selection
281  if (selectedItem == -1
282  || selectedItem >= mShopItems->getNumberOfElements())
283  {
284  return;
285  }
286 
287  if (eventId == "slider")
288  {
289  if (mSlider != nullptr)
290  {
293  }
294  }
295  else if (eventId == "inc" &&
296  mSlider != nullptr &&
298  {
299  mAmountItems++;
302  }
303  else if (eventId == "dec" &&
304  mSlider != nullptr &&
305  mAmountItems > 1)
306  {
307  mAmountItems--;
310  }
311  else if (eventId == "max" &&
312  mSlider != nullptr)
313  {
317  }
318  else if (eventId == "presell" ||
319  eventId == "sell" ||
320  eventId == "yes" ||
321  eventId == "confirm")
322  {
323  sellAction(event);
324  }
325 }
int mAmountItems
Definition: selldialog.h:150
void updateButtonsAndLabels()
Definition: selldialog.cpp:345
Slider * mSlider
Definition: selldialog.h:145
virtual void close()
Definition: window.cpp:897
#define CAST_S32
Definition: cast.h:29
int mMaxItems
Definition: selldialog.h:149
double getValue() const
Definition: slider.h:203
virtual void sellAction(const ActionEvent &event)=0
ShopItems * mShopItems
Definition: selldialog.h:146
int getSelected() const
Definition: listbox.h:167
ShopListBox * mShopItemList
Definition: selldialog.h:141
void setValue(const double value)
Definition: slider.cpp:473
int getNumberOfElements()
Definition: shopitems.h:98

◆ addItem() [1/2]

void SellDialog::addItem ( const Item *const  item,
const int  price 
)

Adds an item to the inventory.

Definition at line 237 of file selldialog.cpp.

References ShopItems::addItem2(), ShopListBox::adjustSize(), Item::getColor(), Item::getId(), Item::getInvIndex(), Item::getQuantity(), Item::getType(), mShopItemList, and mShopItems.

Referenced by EAthena::BuyingStoreRecv::processBuyingStoreItemsList(), EAthena::PetRecv::processEggsList(), Ea::BuySellRecv::processNpcSell(), EAthena::InventoryRecv::processPlayerUseCard(), and ShopWindow::showList().

238 {
239  if (item == nullptr)
240  return;
241 
243  item->getId(),
244  item->getType(),
245  item->getColor(),
246  item->getQuantity(),
247  price);
248 
250 }
int getInvIndex() const
Definition: item.h:164
ShopItem * addItem2(const int inventoryIndex, const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:98
void adjustSize()
int getQuantity() const
Definition: item.h:104
ShopItems * mShopItems
Definition: selldialog.h:146
ItemColor getColor() const
Definition: item.h:180
ShopListBox * mShopItemList
Definition: selldialog.h:141
int getId() const
Definition: item.h:80
ItemTypeT getType() const
Definition: item.h:224

◆ addItem() [2/2]

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

Definition at line 252 of file selldialog.cpp.

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

257 {
258  ShopItem *const item = mShopItems->addItem(id,
259  type,
260  color,
261  amount,
262  price);
264  return item;
265 }
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: selldialog.h:146
ShopListBox * mShopItemList
Definition: selldialog.h:141

◆ closeAll()

void SellDialog::closeAll ( )
static

Closes all instances.

Definition at line 414 of file selldialog.cpp.

References FOR_EACH, and instances.

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

415 {
416  FOR_EACH (DialogList::const_iterator, it, instances)
417  (*it)->close();
418 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
static DialogList instances
Definition: selldialog.h:123

◆ initButtons()

virtual void SellDialog::initButtons ( )
inlineprotectedvirtual

Reimplemented in InsertCardDialog, and EggSelectionDialog.

Definition at line 132 of file selldialog.h.

Referenced by postInit().

133  { }

◆ isActive()

static bool SellDialog::isActive ( )
inlinestatic

Returns true if any instances exist.

Definition at line 111 of file selldialog.h.

References closeAll(), instances, and postInit().

Referenced by InputManager::updateConditionMask().

112  { return !instances.empty(); }
static DialogList instances
Definition: selldialog.h:123

◆ postInit()

void SellDialog::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 81 of file selldialog.cpp.

References _, Widget::addActionListener(), ListBox::addSelectionListener(), Button::adjustSize(), Advanced_true, BUTTON_SKIN, ImagePosition::CENTER, Graphics::CENTER, Window::center(), CREATEWIDGETR, DEFAULT_CURRENCY, Window::enableVisibleSound(), fromBool, Window::getLayout(), Window::getOptionBool(), Window::getPlacer(), Widget::getWidth(), initButtons(), instances, IsSell_true, Window::loadWindowState(), mAddMaxButton, mAdvanced, mAmountItems, mConfirmButton, mDecreaseButton, mIncreaseButton, mIsSell, mMaxItems, mMoneyLabel, mQuantityLabel, mQuitButton, mScrollArea, mSellButton, mShopItemList, mShopItems, mSlider, Window::postInit(), SetupWindow::registerWindowForReset(), LayoutType::SET, Widget::setActionEventId(), Label::setAlignment(), Window::setCloseButton(), Window::setDefaultSize(), ListBox::setDistributeMousePressed(), Widget::setEnabled(), ScrollArea::setHorizontalScrollPolicy(), ShopItems::setMergeDuplicates(), Window::setMinHeight(), Window::setMinWidth(), ShopListBox::setPriceCheck(), ShopListBox::setProtectItems(), Window::setResizable(), LayoutCell::setRowHeight(), Window::setStickyButtonLock(), setupWindow, setVisible(), Widget::setWidth(), Window::setWindowName(), ScrollArea::SHOW_NEVER, strprintf(), ShopListBoxType::Unknown, and Visible_true.

Referenced by isActive().

82 {
84  setWindowName("Sell");
85  setResizable(true);
86  setCloseButton(true);
87  setStickyButtonLock(true);
88  setMinWidth(260);
89  setMinHeight(220);
90  setDefaultSize(260, 230, ImagePosition::CENTER, 0, 0);
91 
92  if (setupWindow != nullptr)
94 
95  // Create a ShopItems instance, that is aware of duplicate entries.
96  mShopItems = new ShopItems(true,
98 
99  if (mAdvanced == Advanced_true)
101 
103  this,
104  mShopItems,
105  mShopItems,
109  fromBool(getOptionBool("showbackground", false), Opaque),
110  "sell_background.xml");
112 
113  mSellButton = new Button(this,
114  // TRANSLATORS: sell dialog button
115  mAdvanced == Advanced_true ? _("Add") : _("Sell"),
116  "presell",
117  BUTTON_SKIN,
118  this);
119  mQuitButton = new Button(this,
120  // TRANSLATORS: sell dialog button
121  _("Quit"),
122  "quit",
123  BUTTON_SKIN,
124  this);
125 
126  initButtons();
127 
128  mSellButton->setEnabled(false);
129 
135 
136  ContainerPlacer placer(nullptr, nullptr);
137  placer = getPlacer(0, 0);
138 
139  if (mIsSell == IsSell_true)
140  {
141  mIncreaseButton = new Button(this,
142  // TRANSLATORS: sell dialog button
143  _("+"),
144  "inc",
145  BUTTON_SKIN,
146  this);
147  mDecreaseButton = new Button(this,
148  // TRANSLATORS: sell dialog button
149  _("-"),
150  "dec",
151  BUTTON_SKIN,
152  this);
153  mAddMaxButton = new Button(this,
154  // TRANSLATORS: sell dialog button
155  _("Max"),
156  "max",
157  BUTTON_SKIN,
158  this);
159  mSlider = new Slider(this, 1.0, 1.0);
160 
161  mQuantityLabel = new Label(this, strprintf(
162  "%d / %d", mAmountItems, mMaxItems));
164  // TRANSLATORS: sell dialog label
165  mMoneyLabel = new Label(this, strprintf(_("Price: %s / Total: %s"),
166  "", ""));
167  if (mAdvanced == Advanced_true)
168  {
169  mConfirmButton = new Button(this,
170  // TRANSLATORS: sell dialog button
171  _("Sell"),
172  "confirm",
173  BUTTON_SKIN,
174  this);
175  mConfirmButton->setEnabled(false);
176  }
177 
180  mIncreaseButton->setEnabled(false);
181  mDecreaseButton->setEnabled(false);
182  mSlider->setEnabled(false);
183  mSlider->setActionEventId("slider");
184  mSlider->addActionListener(this);
185 
186  placer(0, 0, mScrollArea, 8, 5).setPadding(3);
187  placer(0, 5, mDecreaseButton, 1, 1);
188  placer(1, 5, mSlider, 3, 1);
189  placer(4, 5, mIncreaseButton, 1, 1);
190  placer(5, 5, mQuantityLabel, 2, 1);
191  placer(7, 5, mAddMaxButton, 1, 1);
192  placer(0, 6, mMoneyLabel, 8, 1);
193  if (mAdvanced == Advanced_true)
194  {
195  placer(5, 7, mSellButton, 1, 1);
196  placer(6, 7, mConfirmButton, 1, 1);
197  }
198  else
199  {
200  placer(6, 7, mSellButton, 1, 1);
201  }
202  placer(7, 7, mQuitButton, 1, 1);
203  }
204  else
205  {
206  placer(0, 0, mScrollArea, 8, 5).setPadding(3);
207  placer(6, 5, mSellButton, 1, 1);
208  placer(7, 5, mQuitButton, 1, 1);
209  }
210 
211  Layout &layout = getLayout();
212  layout.setRowHeight(0, LayoutType::SET);
213 
214  center();
215  loadWindowState();
216 
217  instances.push_back(this);
219  enableVisibleSound(true);
220 }
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
int mAmountItems
Definition: selldialog.h:150
IsSell mIsSell
Definition: selldialog.h:152
const bool Visible_true
Definition: visible.h:29
Button * mIncreaseButton
Definition: selldialog.h:139
void loadWindowState()
Definition: window.cpp:1082
void setPriceCheck(const bool check)
Label * mQuantityLabel
Definition: selldialog.h:144
void setMergeDuplicates(const bool b)
Definition: shopitems.h:141
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
void addSelectionListener(SelectionListener *const selectionListener)
Definition: listbox.cpp:434
void setMinWidth(const int width)
Definition: window.cpp:586
Definition: button.h:96
void setDistributeMousePressed(const bool b)
Definition: listbox.h:140
Slider * mSlider
Definition: selldialog.h:145
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
Advanced mAdvanced
Definition: selldialog.h:153
void setVisible(Visible visible)
Definition: selldialog.cpp:399
void registerWindowForReset(Window *const window)
void adjustSize()
Definition: button.cpp:798
Label * mMoneyLabel
Definition: selldialog.h:143
static DialogList instances
Definition: selldialog.h:123
const std::string DEFAULT_CURRENCY
Definition: currency.h:26
const std::string BUTTON_SKIN
Definition: button.h:88
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
int mMaxItems
Definition: selldialog.h:149
Definition: label.h:87
#define fromBool(val, name)
Definition: booldefines.h:48
Button * mConfirmButton
Definition: selldialog.h:137
Button * mSellButton
Definition: selldialog.h:135
Button * mQuitButton
Definition: selldialog.h:136
ShopItems * mShopItems
Definition: selldialog.h:146
Button * mAddMaxButton
Definition: selldialog.h:138
void setCloseButton(const bool flag)
Definition: window.cpp:744
virtual void initButtons()
Definition: selldialog.h:132
void enableVisibleSound(bool b)
Definition: window.h:480
void setMinHeight(const int height)
Definition: window.cpp:599
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1386
void setEnabled(const bool enabled)
Definition: widget.h:351
Layout & getLayout()
Definition: window.cpp:1360
const bool IsSell_true
Definition: issell.h:29
ShopListBox * mShopItemList
Definition: selldialog.h:141
const bool Advanced_true
Definition: advanced.h:29
void center()
Definition: window.cpp:1412
ScrollArea * mScrollArea
Definition: selldialog.h:142
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:152
Button * mDecreaseButton
Definition: selldialog.h:140
void setResizable(const bool resize)
Definition: window.cpp:622
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:767
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
Definition: slider.h:85
Definition: layout.h:43
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
void setProtectItems(bool p)
Definition: shoplistbox.h:88
void postInit()
Definition: window.cpp:248
void setWindowName(const std::string &name)
Definition: window.h:354
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)

◆ reset()

void SellDialog::reset ( )

Resets the dialog, clearing inventory.

Definition at line 228 of file selldialog.cpp.

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

229 {
230  mShopItems->clear();
231  if (mSlider != nullptr)
232  mSlider->setValue(0);
235 }
void setSelected(const int selected)
Definition: listbox.cpp:398
void updateButtonsAndLabels()
Definition: selldialog.cpp:345
Slider * mSlider
Definition: selldialog.h:145
void clear()
Definition: shopitems.cpp:173
ShopItems * mShopItems
Definition: selldialog.h:146
ShopListBox * mShopItemList
Definition: selldialog.h:141
void setValue(const double value)
Definition: slider.cpp:473

◆ sellAction()

virtual void SellDialog::sellAction ( const ActionEvent event)
protectedpure virtual

◆ setMoney()

void SellDialog::setMoney ( const int  amount)

Gives Player's Money amount

Definition at line 339 of file selldialog.cpp.

References mPlayerMoney, mShopItemList, and ShopListBox::setPlayersMoney().

Referenced by EAthena::BuyingStoreRecv::processBuyingStoreItemsList(), Ea::BuySellRecv::processNpcSell(), and ShopWindow::showList().

340 {
341  mPlayerMoney = amount;
343 }
void setPlayersMoney(const int money)
Definition: shoplistbox.cpp:86
ShopListBox * mShopItemList
Definition: selldialog.h:141
int mPlayerMoney
Definition: selldialog.h:148

◆ setVisible()

void SellDialog::setVisible ( Visible  visible)
virtual

Sets the visibility of this window.

Reimplemented from Window.

Definition at line 399 of file selldialog.cpp.

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

Referenced by postInit().

400 {
401  Window::setVisible(visible);
402 
403  if (visible == Visible_true)
404  {
405  if (mShopItemList != nullptr)
407  }
408  else
409  {
410  scheduleDelete();
411  }
412 }
const bool Visible_true
Definition: visible.h:29
virtual void requestFocus()
Definition: widget.cpp:203
virtual void scheduleDelete()
Definition: window.cpp:826
ShopListBox * mShopItemList
Definition: selldialog.h:141
virtual void setVisible(Visible visible)
Definition: window.cpp:773

◆ updateButtonsAndLabels()

void SellDialog::updateButtonsAndLabels ( )
protected

Updates the state of buttons and labels.

Definition at line 345 of file selldialog.cpp.

References _, ShopItems::at(), UnitsDb::formatCurrency(), ShopItem::getPrice(), Item::getQuantity(), ListBox::getSelected(), ServerCommandType::item, mAmountItems, mDecreaseButton, mIncreaseButton, mMaxItems, mMoneyLabel, mPlayerMoney, mQuantityLabel, mSellButton, mShopItemList, mShopItems, mSlider, Label::setCaption(), Widget::setEnabled(), strprintf(), and ShopItem::update().

Referenced by action(), reset(), NpcSellDialog::sellOneItem(), and valueChanged().

346 {
347  const int selectedItem = mShopItemList->getSelected();
348  int income = 0;
349  ShopItem *item = nullptr;
350 
351  if (selectedItem > -1 && (mShopItems->at(selectedItem) != nullptr))
352  {
353  item = mShopItems->at(selectedItem);
354  if (item != nullptr)
355  {
356  mMaxItems = item->getQuantity();
357  if (mAmountItems > mMaxItems)
359  income = mAmountItems * mShopItems->at(selectedItem)->getPrice();
360  }
361  else
362  {
363  mMaxItems = 0;
364  mAmountItems = 0;
365  }
366  }
367  else
368  {
369  mMaxItems = 0;
370  mAmountItems = 0;
371  }
372 
373  // Update Buttons and slider
375  if (mDecreaseButton != nullptr)
377  if (mIncreaseButton != nullptr)
379  if (mSlider != nullptr)
381 
382  if (mQuantityLabel != nullptr)
383  {
384  // Update the quantity and money labels
387  }
388  if (mMoneyLabel != nullptr)
389  {
390  // TRANSLATORS: sell dialog label
391  mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
392  UnitsDb::formatCurrency(income).c_str(),
393  UnitsDb::formatCurrency(mPlayerMoney + income).c_str()));
394  }
395  if (item != nullptr)
396  item->update();
397 }
#define _(s)
Definition: gettext.h:34
int mAmountItems
Definition: selldialog.h:150
ShopItem * at(const size_t i) const
Definition: shopitems.cpp:128
Button * mIncreaseButton
Definition: selldialog.h:139
Label * mQuantityLabel
Definition: selldialog.h:144
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:323
Slider * mSlider
Definition: selldialog.h:145
void update()
Definition: shopitem.cpp:118
Label * mMoneyLabel
Definition: selldialog.h:143
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 mMaxItems
Definition: selldialog.h:149
int getQuantity() const
Definition: item.h:104
Button * mSellButton
Definition: selldialog.h:135
ShopItems * mShopItems
Definition: selldialog.h:146
int getSelected() const
Definition: listbox.h:167
void setEnabled(const bool enabled)
Definition: widget.h:351
ShopListBox * mShopItemList
Definition: selldialog.h:141
int mPlayerMoney
Definition: selldialog.h:148
Button * mDecreaseButton
Definition: selldialog.h:140

◆ valueChanged()

void SellDialog::valueChanged ( const SelectionEvent event)
virtual

Updates labels according to selected item.

See also
SelectionListener::selectionChanged

Reimplemented from SelectionListener.

Definition at line 327 of file selldialog.cpp.

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

328 {
329  // Reset amount of items and update labels
330  mAmountItems = 1;
331  if (mSlider != nullptr)
332  {
333  mSlider->setValue(0);
335  }
337 }
int mAmountItems
Definition: selldialog.h:150
void updateButtonsAndLabels()
Definition: selldialog.cpp:345
Slider * mSlider
Definition: selldialog.h:145
void setScale(const double scaleStart, const double scaleEnd)
Definition: slider.cpp:467
int mMaxItems
Definition: selldialog.h:149
void setValue(const double value)
Definition: slider.cpp:473

Field Documentation

◆ instances

SellDialog::DialogList SellDialog::instances
staticprotected

Definition at line 123 of file selldialog.h.

Referenced by closeAll(), isActive(), postInit(), and ~SellDialog().

◆ mAddMaxButton

Button* SellDialog::mAddMaxButton
protected

Definition at line 138 of file selldialog.h.

Referenced by postInit().

◆ mAdvanced

Advanced SellDialog::mAdvanced
protected

Definition at line 153 of file selldialog.h.

Referenced by postInit(), and NpcSellDialog::sellAction().

◆ mAmountItems

int SellDialog::mAmountItems
protected

◆ mConfirmButton

Button* SellDialog::mConfirmButton
protected

Definition at line 137 of file selldialog.h.

Referenced by postInit(), and NpcSellDialog::sellManyItems().

◆ mDecreaseButton

Button* SellDialog::mDecreaseButton
protected

Definition at line 140 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mIncreaseButton

Button* SellDialog::mIncreaseButton
protected

Definition at line 139 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mIsSell

IsSell SellDialog::mIsSell
protected

Definition at line 152 of file selldialog.h.

Referenced by postInit().

◆ mMaxItems

int SellDialog::mMaxItems
protected

◆ mMoneyLabel

Label* SellDialog::mMoneyLabel
protected

Definition at line 143 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mPlayerMoney

int SellDialog::mPlayerMoney
protected

◆ mQuantityLabel

Label* SellDialog::mQuantityLabel
protected

Definition at line 144 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mQuitButton

Button* SellDialog::mQuitButton
protected

Definition at line 136 of file selldialog.h.

Referenced by postInit().

◆ mScrollArea

ScrollArea* SellDialog::mScrollArea
protected

Definition at line 142 of file selldialog.h.

Referenced by postInit().

◆ mSellButton

Button* SellDialog::mSellButton
protected

◆ mShopItemList

ShopListBox* SellDialog::mShopItemList
protected

◆ mShopItems

ShopItems* SellDialog::mShopItems
protected

◆ mSlider

Slider* SellDialog::mSlider
protected

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