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="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
 
virtual ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX=0, int offsetY=0)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
void postInit ()
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx=0, const int offsetY=0)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w=0, int h=0)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w=1, const int h=1)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
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)
 
virtual ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
virtual ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
virtual ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha=255U) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 

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=0) const
 
bool getOptionBool (const std::string &name, const bool def=false) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 

Protected 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="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108

◆ ~SellDialog()

SellDialog::~SellDialog ( )

Destructor

Definition at line 201 of file selldialog.cpp.

References delete2, instances, and mShopItems.

202 {
204  instances.remove(this);
205 }
#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 247 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().

248 {
249  const std::string &eventId = event.getId();
250 
251  if (eventId == "quit")
252  {
253  close();
254  return;
255  }
256 
257  const int selectedItem = mShopItemList->getSelected();
258 
259  // The following actions require a valid item selection
260  if (selectedItem == -1
261  || selectedItem >= mShopItems->getNumberOfElements())
262  {
263  return;
264  }
265 
266  if (eventId == "slider")
267  {
268  if (mSlider != nullptr)
269  {
272  }
273  }
274  else if (eventId == "inc" &&
275  mSlider != nullptr &&
277  {
278  mAmountItems++;
281  }
282  else if (eventId == "dec" &&
283  mSlider != nullptr &&
284  mAmountItems > 1)
285  {
286  mAmountItems--;
289  }
290  else if (eventId == "max" &&
291  mSlider != nullptr)
292  {
296  }
297  else if (eventId == "presell" ||
298  eventId == "sell" ||
299  eventId == "yes" ||
300  eventId == "confirm")
301  {
302  sellAction(event);
303  }
304 }
int mAmountItems
Definition: selldialog.h:150
void updateButtonsAndLabels()
Definition: selldialog.cpp:324
Slider * mSlider
Definition: selldialog.h:145
virtual void close()
Definition: window.cpp:890
#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 216 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().

217 {
218  if (item == nullptr)
219  return;
220 
222  item->getId(),
223  item->getType(),
224  item->getColor(),
225  item->getQuantity(),
226  price);
227 
229 }
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 231 of file selldialog.cpp.

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

236 {
237  ShopItem *const item = mShopItems->addItem(id,
238  type,
239  color,
240  amount,
241  price);
243  return item;
244 }
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 393 of file selldialog.cpp.

References FOR_EACH, and instances.

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

394 {
395  FOR_EACH (DialogList::const_iterator, it, instances)
396  (*it)->close();
397 }
#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, 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);
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"), 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  this);
118  // TRANSLATORS: sell dialog button
119  mQuitButton = new Button(this, _("Quit"), "quit", this);
120 
121  initButtons();
122 
123  mSellButton->setEnabled(false);
124 
130 
131  ContainerPlacer placer;
132  placer = getPlacer(0, 0);
133 
134  if (mIsSell == IsSell_true)
135  {
136  // TRANSLATORS: sell dialog button
137  mIncreaseButton = new Button(this, _("+"), "inc", this);
138  // TRANSLATORS: sell dialog button
139  mDecreaseButton = new Button(this, _("-"), "dec", this);
140  // TRANSLATORS: sell dialog button
141  mAddMaxButton = new Button(this, _("Max"), "max", this);
142  mSlider = new Slider(this, 1.0, 1.0);
143 
144  mQuantityLabel = new Label(this, strprintf(
145  "%d / %d", mAmountItems, mMaxItems));
147  // TRANSLATORS: sell dialog label
148  mMoneyLabel = new Label(this, strprintf(_("Price: %s / Total: %s"),
149  "", ""));
150  if (mAdvanced == Advanced_true)
151  {
152  // TRANSLATORS: sell dialog button
153  mConfirmButton = new Button(this, _("Sell"), "confirm", this);
154  mConfirmButton->setEnabled(false);
155  }
156 
159  mIncreaseButton->setEnabled(false);
160  mDecreaseButton->setEnabled(false);
161  mSlider->setEnabled(false);
162  mSlider->setActionEventId("slider");
163  mSlider->addActionListener(this);
164 
165  placer(0, 0, mScrollArea, 8, 5).setPadding(3);
166  placer(0, 5, mDecreaseButton);
167  placer(1, 5, mSlider, 3);
168  placer(4, 5, mIncreaseButton);
169  placer(5, 5, mQuantityLabel, 2);
170  placer(7, 5, mAddMaxButton);
171  placer(0, 6, mMoneyLabel, 8);
172  if (mAdvanced == Advanced_true)
173  {
174  placer(5, 7, mSellButton);
175  placer(6, 7, mConfirmButton);
176  }
177  else
178  {
179  placer(6, 7, mSellButton);
180  }
181  placer(7, 7, mQuitButton);
182  }
183  else
184  {
185  placer(0, 0, mScrollArea, 8, 5).setPadding(3);
186  placer(6, 5, mSellButton);
187  placer(7, 5, mQuitButton);
188  }
189 
190  Layout &layout = getLayout();
191  layout.setRowHeight(0, LayoutType::SET);
192 
193  center();
194  loadWindowState();
195 
196  instances.push_back(this);
198  enableVisibleSound(true);
199 }
void setDefaultSize()
Definition: window.cpp:1186
#define _(s)
Definition: gettext.h:34
int getWidth() const
Definition: widget.h:220
void setWidth(const int width)
Definition: widget.cpp:132
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:1075
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:428
void setMinWidth(const int width)
Definition: window.cpp:579
Definition: button.h:94
bool getOptionBool(const std::string &name, const bool def=false) const
Definition: window.cpp:1454
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:378
void registerWindowForReset(Window *const window)
void adjustSize()
Definition: button.cpp:821
Label * mMoneyLabel
Definition: selldialog.h:143
static DialogList instances
Definition: selldialog.h:123
const std::string DEFAULT_CURRENCY
Definition: currency.h:26
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:737
virtual void initButtons()
Definition: selldialog.h:132
void enableVisibleSound(bool b)
Definition: window.h:473
void setMinHeight(const int height)
Definition: window.cpp:592
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1379
void setEnabled(const bool enabled)
Definition: widget.h:351
Layout & getLayout()
Definition: window.cpp:1353
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:1405
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:615
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:760
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:241
void setWindowName(const std::string &name)
Definition: window.h:353
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)

◆ reset()

void SellDialog::reset ( )

Resets the dialog, clearing inventory.

Definition at line 207 of file selldialog.cpp.

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

208 {
209  mShopItems->clear();
210  if (mSlider != nullptr)
211  mSlider->setValue(0);
214 }
void setSelected(const int selected)
Definition: listbox.cpp:392
void updateButtonsAndLabels()
Definition: selldialog.cpp:324
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 318 of file selldialog.cpp.

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

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

319 {
320  mPlayerMoney = amount;
322 }
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 378 of file selldialog.cpp.

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

Referenced by postInit().

379 {
380  Window::setVisible(visible);
381 
382  if (visible == Visible_true)
383  {
384  if (mShopItemList != nullptr)
386  }
387  else
388  {
389  scheduleDelete();
390  }
391 }
const bool Visible_true
Definition: visible.h:29
virtual void requestFocus()
Definition: widget.cpp:203
virtual void scheduleDelete()
Definition: window.cpp:819
ShopListBox * mShopItemList
Definition: selldialog.h:141
virtual void setVisible(Visible visible)
Definition: window.cpp:766

◆ updateButtonsAndLabels()

void SellDialog::updateButtonsAndLabels ( )
protected

Updates the state of buttons and labels.

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

325 {
326  const int selectedItem = mShopItemList->getSelected();
327  int income = 0;
328  ShopItem *item = nullptr;
329 
330  if (selectedItem > -1 && (mShopItems->at(selectedItem) != nullptr))
331  {
332  item = mShopItems->at(selectedItem);
333  if (item != nullptr)
334  {
335  mMaxItems = item->getQuantity();
336  if (mAmountItems > mMaxItems)
338  income = mAmountItems * mShopItems->at(selectedItem)->getPrice();
339  }
340  else
341  {
342  mMaxItems = 0;
343  mAmountItems = 0;
344  }
345  }
346  else
347  {
348  mMaxItems = 0;
349  mAmountItems = 0;
350  }
351 
352  // Update Buttons and slider
354  if (mDecreaseButton != nullptr)
356  if (mIncreaseButton != nullptr)
358  if (mSlider != nullptr)
360 
361  if (mQuantityLabel != nullptr)
362  {
363  // Update the quantity and money labels
366  }
367  if (mMoneyLabel != nullptr)
368  {
369  // TRANSLATORS: sell dialog label
370  mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
371  UnitsDb::formatCurrency(income).c_str(),
372  UnitsDb::formatCurrency(mPlayerMoney + income).c_str()));
373  }
374  if (item != nullptr)
375  item->update();
376 }
#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:256
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 306 of file selldialog.cpp.

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

307 {
308  // Reset amount of items and update labels
309  mAmountItems = 1;
310  if (mSlider != nullptr)
311  {
312  mSlider->setValue(0);
314  }
316 }
int mAmountItems
Definition: selldialog.h:150
void updateButtonsAndLabels()
Definition: selldialog.cpp:324
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: