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 52 of file selldialog.h.

Member Typedef Documentation

◆ DialogList

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

Definition at line 123 of file selldialog.h.

Constructor & Destructor Documentation

◆ SellDialog()

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

Constructor.

Definition at line 56 of file selldialog.cpp.

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

◆ ~SellDialog()

SellDialog::~SellDialog ( )

Destructor

Definition at line 223 of file selldialog.cpp.

224 {
226  instances.remove(this);
227 }
static DialogList instances
Definition: selldialog.h:124
#define delete2(var)
Definition: delete2.h:25

References delete2, instances, and mShopItems.

Member Function Documentation

◆ action()

void SellDialog::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 269 of file selldialog.cpp.

270 {
271  const std::string &eventId = event.getId();
272 
273  if (eventId == "quit")
274  {
275  close();
276  return;
277  }
278 
279  const int selectedItem = mShopItemList->getSelected();
280 
281  // The following actions require a valid item selection
282  if (selectedItem == -1
283  || selectedItem >= mShopItems->getNumberOfElements())
284  {
285  return;
286  }
287 
288  if (eventId == "slider")
289  {
290  if (mSlider != nullptr)
291  {
294  }
295  }
296  else if (eventId == "inc" &&
297  mSlider != nullptr &&
299  {
300  mAmountItems++;
303  }
304  else if (eventId == "dec" &&
305  mSlider != nullptr &&
306  mAmountItems > 1)
307  {
308  mAmountItems--;
311  }
312  else if (eventId == "max" &&
313  mSlider != nullptr)
314  {
318  }
319  else if (eventId == "presell" ||
320  eventId == "sell" ||
321  eventId == "yes" ||
322  eventId == "confirm")
323  {
324  sellAction(event);
325  }
326 }
#define CAST_S32
Definition: cast.h:30
int getSelected() const
Definition: listbox.h:168
virtual void sellAction(const ActionEvent &event)=0
void updateButtonsAndLabels()
Definition: selldialog.cpp:346
int getNumberOfElements()
Definition: shopitems.h:99
double getValue() const
Definition: slider.h:204
void setValue(const double value)
Definition: slider.cpp:474
virtual void close()
Definition: window.cpp:902

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

◆ addItem() [1/2]

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

Definition at line 253 of file selldialog.cpp.

258 {
259  ShopItem *const item = mShopItems->addItem(id,
260  type,
261  color,
262  amount,
263  price);
265  return item;
266 }
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:59
void adjustSize()

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

◆ addItem() [2/2]

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

Adds an item to the inventory.

Definition at line 238 of file selldialog.cpp.

239 {
240  if (item == nullptr)
241  return;
242 
244  item->getId(),
245  item->getType(),
246  item->getColor(),
247  item->getQuantity(),
248  price);
249 
251 }
int getQuantity() const
Definition: item.h:105
int getInvIndex() const
Definition: item.h:165
int getId() const
Definition: item.h:81
ItemColor getColor() const
Definition: item.h:181
ItemTypeT getType() const
Definition: item.h:225
ShopItem * addItem2(const int inventoryIndex, const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:99

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

◆ closeAll()

void SellDialog::closeAll ( )
static

Closes all instances.

Definition at line 415 of file selldialog.cpp.

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

References FOR_EACH, and instances.

Referenced by DialogsManager::closeDialogs().

◆ initButtons()

virtual void SellDialog::initButtons ( )
inlineprotectedvirtual

Reimplemented in InsertCardDialog, and EggSelectionDialog.

Definition at line 133 of file selldialog.h.

134  { }

Referenced by postInit().

◆ isActive()

static bool SellDialog::isActive ( )
inlinestatic

Returns true if any instances exist.

Definition at line 112 of file selldialog.h.

113  { return !instances.empty(); }

References instances.

Referenced by InputManager::updateConditionMask().

◆ postInit()

void SellDialog::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 82 of file selldialog.cpp.

83 {
85  setWindowName("Sell");
86  setResizable(true);
87  setCloseButton(true);
88  setStickyButtonLock(true);
89  setMinWidth(260);
90  setMinHeight(220);
91  setDefaultSize(260, 230, ImagePosition::CENTER, 0, 0);
92 
93  if (setupWindow != nullptr)
95 
96  // Create a ShopItems instance, that is aware of duplicate entries.
97  mShopItems = new ShopItems(true,
99 
100  if (mAdvanced == Advanced_true)
102 
104  this,
105  mShopItems,
106  mShopItems,
110  fromBool(getOptionBool("showbackground", false), Opaque),
111  "sell_background.xml");
113 
114  mSellButton = new Button(this,
115  // TRANSLATORS: sell dialog button
116  mAdvanced == Advanced_true ? _("Add") : _("Sell"),
117  "presell",
118  BUTTON_SKIN,
119  this);
120  mQuitButton = new Button(this,
121  // TRANSLATORS: sell dialog button
122  _("Quit"),
123  "quit",
124  BUTTON_SKIN,
125  this);
126 
127  initButtons();
128 
129  mSellButton->setEnabled(false);
130 
136 
137  ContainerPlacer placer(nullptr, nullptr);
138  placer = getPlacer(0, 0);
139 
140  if (mIsSell == IsSell_true)
141  {
142  mIncreaseButton = new Button(this,
143  // TRANSLATORS: sell dialog button
144  _("+"),
145  "inc",
146  BUTTON_SKIN,
147  this);
148  mDecreaseButton = new Button(this,
149  // TRANSLATORS: sell dialog button
150  _("-"),
151  "dec",
152  BUTTON_SKIN,
153  this);
154  mAddMaxButton = new Button(this,
155  // TRANSLATORS: sell dialog button
156  _("Max"),
157  "max",
158  BUTTON_SKIN,
159  this);
160  mSlider = new Slider(this, 1.0, 1.0);
161 
162  mQuantityLabel = new Label(this, strprintf(
163  "%d / %d", mAmountItems, mMaxItems));
165  // TRANSLATORS: sell dialog label
166  mMoneyLabel = new Label(this, strprintf(_("Price: %s / Total: %s"),
167  "", ""));
168  if (mAdvanced == Advanced_true)
169  {
170  mConfirmButton = new Button(this,
171  // TRANSLATORS: sell dialog button
172  _("Sell"),
173  "confirm",
174  BUTTON_SKIN,
175  this);
176  mConfirmButton->setEnabled(false);
177  }
178 
181  mIncreaseButton->setEnabled(false);
182  mDecreaseButton->setEnabled(false);
183  mSlider->setEnabled(false);
184  mSlider->setActionEventId("slider");
185  mSlider->addActionListener(this);
186 
187  placer(0, 0, mScrollArea, 8, 5).setPadding(3);
188  placer(0, 5, mDecreaseButton, 1, 1);
189  placer(1, 5, mSlider, 3, 1);
190  placer(4, 5, mIncreaseButton, 1, 1);
191  placer(5, 5, mQuantityLabel, 2, 1);
192  placer(7, 5, mAddMaxButton, 1, 1);
193  placer(0, 6, mMoneyLabel, 8, 1);
194  if (mAdvanced == Advanced_true)
195  {
196  placer(5, 7, mSellButton, 1, 1);
197  placer(6, 7, mConfirmButton, 1, 1);
198  }
199  else
200  {
201  placer(6, 7, mSellButton, 1, 1);
202  }
203  placer(7, 7, mQuitButton, 1, 1);
204  }
205  else
206  {
207  placer(0, 0, mScrollArea, 8, 5).setPadding(3);
208  placer(6, 5, mSellButton, 1, 1);
209  placer(7, 5, mQuitButton, 1, 1);
210  }
211 
212  Layout &layout = getLayout();
213  layout.setRowHeight(0, LayoutType::SET);
214 
215  center();
216  loadWindowState();
217 
218  instances.push_back(this);
220  enableVisibleSound(true);
221 }
const bool Advanced_true
Definition: advanced.h:30
#define fromBool(val, name)
Definition: booldefines.h:49
const std::string BUTTON_SKIN
Definition: button.h:89
Definition: button.h:102
void adjustSize()
Definition: button.cpp:799
@ CENTER
Definition: graphics.h:132
Definition: label.h:91
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:153
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:128
Definition: layout.h:45
void setDistributeMousePressed(const bool b)
Definition: listbox.h:141
void addSelectionListener(SelectionListener *const selectionListener)
Definition: listbox.cpp:435
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
virtual void initButtons()
Definition: selldialog.h:133
void setVisible(Visible visible)
Definition: selldialog.cpp:400
void registerWindowForReset(Window *const window)
void setMergeDuplicates(const bool b)
Definition: shopitems.h:142
void setPriceCheck(const bool check)
void setProtectItems(bool p)
Definition: shoplistbox.h:89
Definition: slider.h:89
void setWidth(const int width)
Definition: widget.cpp:133
void setEnabled(const bool enabled)
Definition: widget.h:352
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
int getWidth() const
Definition: widget.h:221
void center()
Definition: window.cpp:1417
void setResizable(const bool resize)
Definition: window.cpp:627
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1391
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1466
Layout & getLayout()
Definition: window.cpp:1365
void setWindowName(const std::string &name)
Definition: window.h:355
void setMinHeight(const int height)
Definition: window.cpp:604
void postInit()
Definition: window.cpp:249
void setMinWidth(const int width)
Definition: window.cpp:591
void enableVisibleSound(bool b)
Definition: window.h:481
void setCloseButton(const bool flag)
Definition: window.cpp:749
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:772
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
const std::string DEFAULT_CURRENCY
Definition: currency.h:27
const bool IsSell_true
Definition: issell.h:30
bool Opaque
Definition: opaque.h:30
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
std::string strprintf(const char *const format,...)
const bool Visible_true
Definition: visible.h:30

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

◆ reset()

void SellDialog::reset ( )

Resets the dialog, clearing inventory.

Definition at line 229 of file selldialog.cpp.

230 {
231  mShopItems->clear();
232  if (mSlider != nullptr)
233  mSlider->setValue(0);
236 }
void setSelected(const int selected)
Definition: listbox.cpp:399
void clear()
Definition: shopitems.cpp:174

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

◆ 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 340 of file selldialog.cpp.

341 {
342  mPlayerMoney = amount;
344 }
void setPlayersMoney(const int money)
Definition: shoplistbox.cpp:87

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

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

◆ setVisible()

void SellDialog::setVisible ( Visible  visible)
virtual

Sets the visibility of this window.

Reimplemented from Window.

Definition at line 400 of file selldialog.cpp.

401 {
402  Window::setVisible(visible);
403 
404  if (visible == Visible_true)
405  {
406  if (mShopItemList != nullptr)
408  }
409  else
410  {
411  scheduleDelete();
412  }
413 }
virtual void requestFocus()
Definition: widget.cpp:204
virtual void setVisible(Visible visible)
Definition: window.cpp:778
virtual void scheduleDelete()
Definition: window.cpp:831

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

Referenced by postInit().

◆ updateButtonsAndLabels()

void SellDialog::updateButtonsAndLabels ( )
protected

Updates the state of buttons and labels.

Definition at line 346 of file selldialog.cpp.

347 {
348  const int selectedItem = mShopItemList->getSelected();
349  int income = 0;
350  ShopItem *item = nullptr;
351 
352  if (selectedItem > -1 && (mShopItems->at(selectedItem) != nullptr))
353  {
354  item = mShopItems->at(selectedItem);
355  if (item != nullptr)
356  {
357  mMaxItems = item->getQuantity();
358  if (mAmountItems > mMaxItems)
360  income = mAmountItems * mShopItems->at(selectedItem)->getPrice();
361  }
362  else
363  {
364  mMaxItems = 0;
365  mAmountItems = 0;
366  }
367  }
368  else
369  {
370  mMaxItems = 0;
371  mAmountItems = 0;
372  }
373 
374  // Update Buttons and slider
376  if (mDecreaseButton != nullptr)
378  if (mIncreaseButton != nullptr)
380  if (mSlider != nullptr)
382 
383  if (mQuantityLabel != nullptr)
384  {
385  // Update the quantity and money labels
388  }
389  if (mMoneyLabel != nullptr)
390  {
391  // TRANSLATORS: sell dialog label
392  mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
393  UnitsDb::formatCurrency(income).c_str(),
394  UnitsDb::formatCurrency(mPlayerMoney + income).c_str()));
395  }
396  if (item != nullptr)
397  item->update();
398 }
void setCaption(const std::string &caption)
Definition: label.cpp:264
void update()
Definition: shopitem.cpp:119
int getPrice() const
Definition: shopitem.h:132
ShopItem * at(const size_t i) const
Definition: shopitems.cpp:129
std::string formatCurrency(const int value)
Definition: unitsdb.cpp:324

References _, ShopItems::at(), UnitsDb::formatCurrency(), ShopItem::getPrice(), Item::getQuantity(), ListBox::getSelected(), 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().

◆ valueChanged()

void SellDialog::valueChanged ( const SelectionEvent event)
virtual

Updates labels according to selected item.

See also
SelectionListener::selectionChanged

Reimplemented from SelectionListener.

Definition at line 328 of file selldialog.cpp.

329 {
330  // Reset amount of items and update labels
331  mAmountItems = 1;
332  if (mSlider != nullptr)
333  {
334  mSlider->setValue(0);
336  }
338 }
void setScale(const double scaleStart, const double scaleEnd)
Definition: slider.cpp:468

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

Field Documentation

◆ instances

SellDialog::DialogList SellDialog::instances
staticprotected

Definition at line 124 of file selldialog.h.

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

◆ mAddMaxButton

Button* SellDialog::mAddMaxButton
protected

Definition at line 139 of file selldialog.h.

Referenced by postInit().

◆ mAdvanced

Advanced SellDialog::mAdvanced
protected

Definition at line 154 of file selldialog.h.

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

◆ mAmountItems

int SellDialog::mAmountItems
protected

◆ mConfirmButton

Button* SellDialog::mConfirmButton
protected

Definition at line 138 of file selldialog.h.

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

◆ mDecreaseButton

Button* SellDialog::mDecreaseButton
protected

Definition at line 141 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mIncreaseButton

Button* SellDialog::mIncreaseButton
protected

Definition at line 140 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mIsSell

IsSell SellDialog::mIsSell
protected

Definition at line 153 of file selldialog.h.

Referenced by postInit().

◆ mMaxItems

int SellDialog::mMaxItems
protected

◆ mMoneyLabel

Label* SellDialog::mMoneyLabel
protected

Definition at line 144 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mPlayerMoney

int SellDialog::mPlayerMoney
protected

◆ mQuantityLabel

Label* SellDialog::mQuantityLabel
protected

Definition at line 145 of file selldialog.h.

Referenced by postInit(), and updateButtonsAndLabels().

◆ mQuitButton

Button* SellDialog::mQuitButton
protected

Definition at line 137 of file selldialog.h.

Referenced by postInit().

◆ mScrollArea

ScrollArea* SellDialog::mScrollArea
protected

Definition at line 143 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: