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

#include <shopwindow.h>

Inheritance diagram for ShopWindow:
Window VendingModeListener VendingSlotsListener BuyingStoreModeListener BuyingStoreSlotsListener ActionListener SelectionListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Types

enum  ShopMode { BUY = 0, SELL = 1 }
 

Public Member Functions

 ShopWindow ()
 
 ~ShopWindow ()
 
void postInit ()
 
void action (const ActionEvent &event)
 
void valueChanged (const SelectionEvent &event)
 
void updateButtonsAndLabels ()
 
void setVisible (Visible visible)
 
void setItemSelected (const int id)
 
void addBuyItem (const Item *const item, const int amount, const int price)
 
void addSellItem (const Item *const item, const int amount, const int price)
 
void loadList ()
 
void saveList () const
 
void setAcceptPlayer (const std::string &name)
 
const std::string & getAcceptPlayer () const
 
void announce (ShopItems *const list, const int mode)
 
void giveList (const std::string &nick, const int mode)
 
void sendMessage (const std::string &nick, std::string data, const bool random)
 
void processRequest (const std::string &nick, std::string data, const int mode)
 
void updateTimes ()
 
bool findShopItem (const ShopItem *const shopItem, const int mode) const
 
bool isShopEmpty () const
 
void vendingEnabled (const bool b)
 
void vendingSlotsChanged (const int slots)
 
void buyingStoreEnabled (const bool b)
 
void buyingStoreSlotsChanged (const int slots)
 
void setShopName (const std::string &name)
 
- 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)
 
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 VendingModeListener
 VendingModeListener ()
 
virtual ~ VendingModeListener ()
 
- Public Member Functions inherited from VendingSlotsListener
 VendingSlotsListener ()
 
virtual ~ VendingSlotsListener ()
 
- Public Member Functions inherited from BuyingStoreModeListener
 BuyingStoreModeListener ()
 
virtual ~ BuyingStoreModeListener ()
 
- Public Member Functions inherited from BuyingStoreSlotsListener
 BuyingStoreSlotsListener ()
 
virtual ~ BuyingStoreSlotsListener ()
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 

Static Public Member Functions

static bool isActive ()
 
static void showList (const std::string &nick, std::string data)
 
static bool checkFloodCounter (time_t &counterTime)
 
static int sumAmount (const Item *const shopItem)
 
- 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)
 
- Static Public Member Functions inherited from VendingModeListener
static void distributeEvent (const bool b)
 
static void addListener (VendingModeListener *const listener)
 
static void removeListener (const VendingModeListener *const listener)
 
- Static Public Member Functions inherited from VendingSlotsListener
static void distributeEvent (const int slots)
 
static void addListener (VendingSlotsListener *const listener)
 
static void removeListener (const VendingSlotsListener *const listener)
 
- Static Public Member Functions inherited from BuyingStoreModeListener
static void distributeEvent (const bool b)
 
static void addListener (BuyingStoreModeListener *const listener)
 
static void removeListener (const BuyingStoreModeListener *const listener)
 
- Static Public Member Functions inherited from BuyingStoreSlotsListener
static void distributeEvent (const int slots)
 
static void addListener (BuyingStoreSlotsListener *const listener)
 
static void removeListener (const BuyingStoreSlotsListener *const listener)
 

Private Types

typedef std::list< ShopWindow * > DialogList
 

Private Member Functions

void startTrade ()
 
void updateSelection ()
 
void updateShopName ()
 

Private Attributes

ButtonmCloseButton
 
ShopItemsmBuyShopItems
 
ShopItemsmSellShopItems
 
ShopItemmTradeItem
 
ShopListBoxmBuyShopItemList
 
ShopListBoxmSellShopItemList
 
ShopListBoxmCurrentShopItemList
 
ScrollAreamScrollArea
 
ButtonmAddButton
 
ButtonmDeleteButton
 
ButtonmAnnounceButton
 
ButtonmPublishButton
 
ButtonmRenameButton
 
CheckBoxmAnnounceLinks
 
TabStripmTabs
 
std::string mAcceptPlayer
 
std::string mTradeNick
 
std::string mSellShopName
 
int mSelectedItem
 
time_t mAnnonceTime
 
time_t mLastRequestTimeList
 
time_t mLastRequestTimeItem
 
int mRandCounter
 
int mTradeMoney
 
int mSellShopSize
 
int mBuyShopSize
 
bool isBuySelected
 
bool mHaveVending
 
bool mEnableBuyingStore
 
bool mEnableVending
 

Static Private Attributes

static DialogList instances
 

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from SelectionListener
 SelectionListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

The buy dialog.

Definition at line 49 of file shopwindow.h.

Member Typedef Documentation

◆ DialogList

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

Definition at line 169 of file shopwindow.h.

Member Enumeration Documentation

◆ ShopMode

Enumerator
BUY 
SELL 

Definition at line 58 of file shopwindow.h.

59  {
60  BUY = 0,
61  SELL = 1
62  };

Constructor & Destructor Documentation

◆ ShopWindow()

ShopWindow::ShopWindow ( )

Constructor.

See also
Window::Window

Definition at line 104 of file shopwindow.cpp.

References _, Widget::addActionListener(), WidgetGroup::addButton(), ListBox::addSelectionListener(), BUTTON_SKIN, ImagePosition::CENTER, Window::center(), config, Configuration::getIntValue(), Window::getLayout(), Window::getOption(), Window::getPlacer(), instances, loadList(), Window::loadWindowState(), mAddButton, mainGraphics, mAnnounceButton, mAnnounceLinks, mBuyShopItemList, mCloseButton, mDeleteButton, mHaveVending, mPublishButton, mRenameButton, mScrollArea, mSellShopItemList, mTabs, Graphics::mWidth, SetupWindow::registerWindowForReset(), LayoutType::SET, Widget::setActionEventId(), Window::setCloseButton(), Window::setDefaultSize(), ScrollArea::setHorizontalScrollPolicy(), Window::setMinHeight(), Window::setMinWidth(), ShopListBox::setPriceCheck(), Window::setResizable(), LayoutCell::setRowHeight(), Widget::setSelectable(), Window::setStickyButtonLock(), setupWindow, Window::setWindowName(), ScrollArea::SHOW_NEVER, ServerCommandType::size, and updateShopName().

104  :
105  // TRANSLATORS: shop window name
106  Window(_("Personal Shop"), Modal_false, nullptr, "shop.xml"),
111  ActionListener(),
113  // TRANSLATORS: shop window button
114  mCloseButton(new Button(this, _("Close"), "close", BUTTON_SKIN, this)),
117  mTradeItem(nullptr),
122  mCurrentShopItemList(nullptr),
124  fromBool(getOptionBool("showbuybackground", false), Opaque),
125  "shop_buy_background.xml")),
126  // TRANSLATORS: shop window label
127  mAddButton(new Button(this, _("Add"), "add", BUTTON_SKIN, this)),
128  // TRANSLATORS: shop window label
129  mDeleteButton(new Button(this, _("Delete"), "delete", BUTTON_SKIN, this)),
130  mAnnounceButton(nullptr),
131  mPublishButton(nullptr),
132  mRenameButton(nullptr),
133  mAnnounceLinks(nullptr),
134  mTabs(nullptr),
135  mAcceptPlayer(),
136  mTradeNick(),
137  mSellShopName(serverConfig.getStringValue("sellShopName")),
138  mSelectedItem(-1),
139  mAnnonceTime(0),
142  mRandCounter(0),
143  mTradeMoney(0),
144  mSellShopSize(0),
145  mBuyShopSize(0),
146  isBuySelected(true),
148  mEnableBuyingStore(false),
149  mEnableVending(false)
150 {
151  setWindowName("Personal Shop");
152  setResizable(true);
153  setCloseButton(true);
154  setStickyButtonLock(true);
155  setMinWidth(300);
156  setMinHeight(220);
157  if (mainGraphics->mWidth > 600)
158  setDefaultSize(500, 300, ImagePosition::CENTER, 0, 0);
159  else
160  setDefaultSize(380, 300, ImagePosition::CENTER, 0, 0);
161 
162  if (setupWindow != nullptr)
164 
165  const int size = config.getIntValue("fontSize")
166  + getOption("tabHeightAdjust", 16);
167  mTabs = new TabStrip(this, "shop", size, 0);
168  mTabs->addActionListener(this);
169  mTabs->setActionEventId("tab_");
170  // TRANSLATORS: shop window tab name
171  mTabs->addButton(_("Buy"), "buy", true);
172  // TRANSLATORS: shop window tab name
173  mTabs->addButton(_("Sell"), "sell", false);
174  mTabs->setSelectable(false);
175  mScrollArea->setSelectable(false);
176 
177  loadList();
178 
181 
183 
186 
187  ContainerPlacer placer(nullptr, nullptr);
188  placer = getPlacer(0, 0);
189 
190  placer(0, 0, mTabs, 8, 1).setPadding(3);
191 
192  if (mHaveVending)
193  {
194  mPublishButton = new Button(this,
195  // TRANSLATORS: shop window button
196  _("Publish"),
197  "publish",
198  BUTTON_SKIN,
199  this);
200  mRenameButton = new Button(this,
201  // TRANSLATORS: shop window button
202  _("Rename"),
203  "rename",
204  BUTTON_SKIN,
205  this);
206  placer(2, 6, mPublishButton, 1, 1);
207  placer(3, 6, mRenameButton, 1, 1);
208  }
209  else
210  {
211  mAnnounceButton = new Button(this,
212  // TRANSLATORS: shop window button
213  _("Announce"),
214  "announce",
215  BUTTON_SKIN,
216  this);
217  // TRANSLATORS: shop window checkbox
218  mAnnounceLinks = new CheckBox(this, _("Show links in announce"), false,
219  this, "link announce");
220 
221  placer(2, 6, mAnnounceButton, 1, 1);
222  placer(0, 7, mAnnounceLinks, 7, 1);
223  }
224 
225  placer(0, 1, mScrollArea, 8, 5).setPadding(3);
226  placer(0, 6, mAddButton, 1, 1);
227  placer(1, 6, mDeleteButton, 1, 1);
228  placer(7, 6, mCloseButton, 1, 1);
229 
230  Layout &layout = getLayout();
231  layout.setRowHeight(0, LayoutType::SET);
232 
233  center();
234  loadWindowState();
235  updateShopName();
236  instances.push_back(this);
237 }
Button * mDeleteButton
Definition: shopwindow.h:183
ShopListBox * mSellShopItemList
Definition: shopwindow.h:179
void setDefaultSize()
Definition: window.cpp:1197
int mBuyShopSize
Definition: shopwindow.h:199
bool mHaveVending
Definition: shopwindow.h:201
Button * mRenameButton
Definition: shopwindow.h:186
std::string getStringValue(const std::string &key) const
#define _(s)
Definition: gettext.h:34
bool isBuySelected
Definition: shopwindow.h:200
void loadList()
Definition: shopwindow.cpp:545
Button * mPublishButton
Definition: shopwindow.h:185
std::string mSellShopName
Definition: shopwindow.h:191
bool mEnableVending
Definition: shopwindow.h:203
Button * mAddButton
Definition: shopwindow.h:182
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1465
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
ShopItem * mTradeItem
Definition: shopwindow.h:176
void loadWindowState()
Definition: window.cpp:1086
void setPriceCheck(const bool check)
virtual void addButton(const std::string &text, const std::string &tag, const bool pressed)
Definition: widgetgroup.cpp:41
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:590
int mWidth
Definition: graphics.h:483
Definition: button.h:96
Configuration config
int getOption(const std::string &name, const int def) const
Definition: window.cpp:1453
int getIntValue(const std::string &key) const
int mTradeMoney
Definition: shopwindow.h:197
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
ShopListBox * mCurrentShopItemList
Definition: shopwindow.h:180
Configuration serverConfig
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:178
void registerWindowForReset(Window *const window)
void setSelectable(const bool selectable)
Definition: widget.h:947
bool mEnableBuyingStore
Definition: shopwindow.h:202
const std::string DEFAULT_CURRENCY
Definition: currency.h:26
const std::string BUTTON_SKIN
Definition: button.h:88
time_t mLastRequestTimeItem
Definition: shopwindow.h:195
int mSellShopSize
Definition: shopwindow.h:198
#define fromBool(val, name)
Definition: booldefines.h:48
time_t mAnnonceTime
Definition: shopwindow.h:193
std::string mTradeNick
Definition: shopwindow.h:190
Graphics * mainGraphics
Definition: graphics.cpp:108
int mSelectedItem
Definition: shopwindow.h:192
void setCloseButton(const bool flag)
Definition: window.cpp:748
std::string mAcceptPlayer
Definition: shopwindow.h:189
void setMinHeight(const int height)
Definition: window.cpp:603
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1390
Layout & getLayout()
Definition: window.cpp:1364
Button * mAnnounceButton
Definition: shopwindow.h:184
ServerTypeT getNetworkType()
Definition: net.cpp:184
TabStrip * mTabs
Definition: shopwindow.h:188
void updateShopName()
void center()
Definition: window.cpp:1416
ScrollArea * mScrollArea
Definition: shopwindow.h:181
time_t mLastRequestTimeList
Definition: shopwindow.h:194
Button * mCloseButton
Definition: shopwindow.h:172
static DialogList instances
Definition: shopwindow.h:170
void setResizable(const bool resize)
Definition: window.cpp:626
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:771
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
Definition: layout.h:43
CheckBox * mAnnounceLinks
Definition: shopwindow.h:187
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
ShopItems * mSellShopItems
Definition: shopwindow.h:175
void setWindowName(const std::string &name)
Definition: window.h:354
int mRandCounter
Definition: shopwindow.h:196
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)

◆ ~ShopWindow()

ShopWindow::~ShopWindow ( )

Destructor

Definition at line 247 of file shopwindow.cpp.

References delete2, instances, mBuyShopItemList, mBuyShopItems, mSellShopItemList, mSellShopItems, mTradeItem, and saveList().

248 {
249  saveList();
250 
256 
257  instances.remove(this);
258 }
ShopListBox * mSellShopItemList
Definition: shopwindow.h:179
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
ShopItem * mTradeItem
Definition: shopwindow.h:176
void saveList() const
Definition: shopwindow.cpp:608
#define delete2(var)
Definition: delete2.h:24
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:178
static DialogList instances
Definition: shopwindow.h:170
ShopItems * mSellShopItems
Definition: shopwindow.h:175

Member Function Documentation

◆ action()

void ShopWindow::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 260 of file shopwindow.cpp.

References _, Widget::addActionListener(), announce(), BUY, buyingStoreHandler, Net::VendingHandler::close(), Net::BuyingStoreHandler::close(), Window::close(), Net::BuyingStoreHandler::create(), Net::VendingHandler::createShop(), CREATEWIDGETR, ShopItems::del(), VendingModeListener::distributeEvent(), BuyingStoreModeListener::distributeEvent(), Inventory::findItem(), FOR_EACH, PlayerInfo::getAttribute(), PlayerInfo::getCartInventory(), Item::getColor(), Item::getId(), PlayerInfo::getInventory(), Item::getInvIndex(), ShopItems::getNumberOfElements(), Item::getQuantity(), ListBox::getSelected(), PlayerRelationsManager::ignoreTrade(), isBuySelected, isShopEmpty(), ServerCommandType::item, ItemColor_zero, ShopItems::items(), localPlayer, mBuyShopItemList, mBuyShopItems, mEnableBuyingStore, mEnableVending, mHaveVending, Modal_true, Attributes::MONEY, mSelectedItem, mSellShopItemList, mSellShopItems, mSellShopName, mSellShopSize, mTradeNick, playerRelations, SELL, ShopRenameListener::setDialog(), Item::setInvIndex(), Item::setQuantity(), ItemAmountWindowUsage::ShopBuyAdd, shopRenameListener, ItemAmountWindowUsage::ShopSellAdd, ItemAmountWindow::showWindow(), startTrade(), sumAmount(), updateSelection(), LocalPlayer::updateStatus(), and vendingHandler.

261 {
262  const std::string &eventId = event.getId();
263  if (eventId == "close")
264  {
265  close();
266  return;
267  }
268 #ifdef TMWA_SUPPORT
269  else if (eventId == "yes")
270  {
271  startTrade();
272  }
273  else if (eventId == "no")
274  {
275  mTradeNick.clear();
276  }
277  else if (eventId == "ignore")
278  {
280  mTradeNick.clear();
281  }
282  else if (eventId == "announce")
283  {
284  if (isBuySelected)
285  {
288  }
289  else if (mSellShopItems->getNumberOfElements() > 0)
290  {
292  }
293  }
294 #endif // TMWA_SUPPORT
295  else if (eventId == "delete")
296  {
297  if (isBuySelected)
298  {
299  if (mBuyShopItemList != nullptr &&
301  {
303  if (isShopEmpty() && (localPlayer != nullptr))
305  }
306  }
307  else if ((mSellShopItemList != nullptr)
308  && mSellShopItemList->getSelected() >= 0)
309  {
311  if (isShopEmpty() && (localPlayer != nullptr))
313  }
314  }
315  else if (eventId == "tab_buy")
316  {
317  isBuySelected = true;
318  updateSelection();
319  }
320  else if (eventId == "tab_sell")
321  {
322  isBuySelected = false;
323  updateSelection();
324  }
325  else if (eventId == "publish")
326  {
327  if (isBuySelected)
328  {
329  if (mEnableBuyingStore)
330  {
333  }
334  else
335  {
336  STD_VECTOR<ShopItem*> &items = mBuyShopItems->items();
337  if (!items.empty())
338  {
341  true,
342  items);
343  }
344  }
345  }
346  else
347  {
348  if (mEnableVending)
349  {
352  }
353  else
354  {
355  STD_VECTOR<ShopItem*> &oldItems = mSellShopItems->items();
356  STD_VECTOR<ShopItem*> items;
357  const Inventory *const inv = PlayerInfo::getCartInventory();
358  if (inv == nullptr)
359  return;
360  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, oldItems)
361  {
362  ShopItem *const item = *it;
363  if (item == nullptr)
364  continue;
365  const Item *const cartItem = inv->findItem(item->getId(),
366  item->getColor());
367  if (cartItem == nullptr)
368  continue;
369  item->setInvIndex(cartItem->getInvIndex());
370  const int amount = cartItem->getQuantity();
371  if (amount == 0)
372  continue;
373  if (item->getQuantity() > amount)
374  item->setQuantity(amount);
375  items.push_back(item);
376  if (static_cast<signed int>(items.size()) >= mSellShopSize)
377  break;
378  }
379  if (!items.empty())
380  vendingHandler->createShop(mSellShopName, true, items);
381  }
382  }
383  }
384  else if (eventId == "rename")
385  {
386  EditDialog *const dialog = CREATEWIDGETR(EditDialog,
387  // TRANSLATORS: shop rename dialog title
388  _("Please enter new shop name"),
390  "OK",
391  300,
392  nullptr,
393  Modal_true);
396  }
397 
398  if (mSelectedItem < 1)
399  return;
400 
401  const Inventory *const inv = mHaveVending && !isBuySelected
403  if (inv == nullptr)
404  return;
405 
406  // +++ need support for colors
407  Item *const item = inv->findItem(mSelectedItem, ItemColor_zero);
408  if (item != nullptr)
409  {
410  if (eventId == "add")
411  {
412  if (isBuySelected)
413  {
415  this,
416  item,
417  sumAmount(item),
418  0);
419  }
420  else
421  {
424  this,
425  item,
426  sumAmount(item),
427  0);
428  }
429  }
430  }
431 }
int getInvIndex() const
Definition: item.h:164
ShopListBox * mSellShopItemList
Definition: shopwindow.h:179
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mHaveVending
Definition: shopwindow.h:201
#define _(s)
Definition: gettext.h:34
bool isBuySelected
Definition: shopwindow.h:200
std::string mSellShopName
Definition: shopwindow.h:191
bool mEnableVending
Definition: shopwindow.h:203
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
virtual void create(const std::string &name, const int maxMoney, const bool flag, const std::vector< ShopItem *> &items) const =0
void ignoreTrade(const std::string &name) const
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
virtual void close() const =0
void updateStatus() const
Inventory * getInventory()
Definition: playerinfo.cpp:193
static void showWindow(const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, int maxRange, const int tag)
virtual void createShop(const std::string &name, const bool flag, const std::vector< ShopItem *> &items) const =0
const ItemColor ItemColor_zero
Definition: itemcolor.h:29
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:178
static int sumAmount(const Item *const shopItem)
static void distributeEvent(const bool b)
void startTrade()
Definition: shopwindow.cpp:733
virtual void close()
Definition: window.cpp:901
bool mEnableBuyingStore
Definition: shopwindow.h:202
std::vector< ShopItem * > & items()
Definition: shopitems.h:135
Inventory * getCartInventory()
Definition: playerinfo.cpp:205
int mSellShopSize
Definition: shopwindow.h:198
void announce(ShopItems *const list, const int mode)
Definition: shopwindow.cpp:674
int getQuantity() const
Definition: item.h:104
LocalPlayer * localPlayer
ItemColor getColor() const
Definition: item.h:180
std::string mTradeNick
Definition: shopwindow.h:190
int getSelected() const
Definition: listbox.h:167
Definition: item.h:48
static void distributeEvent(const bool b)
void setInvIndex(const int index)
Definition: item.h:158
int mSelectedItem
Definition: shopwindow.h:192
ShopRenameListener shopRenameListener
Net::BuyingStoreHandler * buyingStoreHandler
Definition: net.cpp:104
int getId() const
Definition: item.h:80
void updateSelection()
bool isShopEmpty() const
void setQuantity(const int quantity)
Definition: item.h:92
void del(const unsigned int i)
Definition: shopitems.cpp:160
Net::VendingHandler * vendingHandler
Definition: net.cpp:117
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
PlayerRelationsManager playerRelations
void setDialog(EditDialog *const dialog)
virtual void close() const =0
ShopItems * mSellShopItems
Definition: shopwindow.h:175
int getNumberOfElements()
Definition: shopitems.h:98

◆ addBuyItem()

void ShopWindow::addBuyItem ( const Item *const  item,
const int  amount,
const int  price 
)

Definition at line 511 of file shopwindow.cpp.

References ShopItems::addItemNoDup(), Item::getColor(), Item::getId(), Item::getType(), isShopEmpty(), localPlayer, mBuyShopItems, updateButtonsAndLabels(), and LocalPlayer::updateStatus().

Referenced by ItemAmountWindow::finish(), and setItemSelected().

513 {
514  if (item == nullptr)
515  return;
516  const bool emp = isShopEmpty();
518  item->getType(),
519  item->getColor(),
520  amount,
521  price);
522  if (emp && (localPlayer != nullptr))
524 
526 }
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
void updateStatus() const
LocalPlayer * localPlayer
ItemColor getColor() const
Definition: item.h:180
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438
int getId() const
Definition: item.h:80
ShopItem * addItemNoDup(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:76
bool isShopEmpty() const
ItemTypeT getType() const
Definition: item.h:224

◆ addSellItem()

void ShopWindow::addSellItem ( const Item *const  item,
const int  amount,
const int  price 
)

Definition at line 528 of file shopwindow.cpp.

References ShopItems::addItemNoDup(), Item::getColor(), Item::getId(), Item::getType(), isShopEmpty(), localPlayer, mSellShopItems, updateButtonsAndLabels(), and LocalPlayer::updateStatus().

Referenced by ItemAmountWindow::finish(), and setItemSelected().

530 {
531  if (item == nullptr)
532  return;
533  const bool emp = isShopEmpty();
535  item->getType(),
536  item->getColor(),
537  amount,
538  price);
539  if (emp && (localPlayer != nullptr))
541 
543 }
void updateStatus() const
LocalPlayer * localPlayer
ItemColor getColor() const
Definition: item.h:180
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438
int getId() const
Definition: item.h:80
ShopItem * addItemNoDup(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:76
bool isShopEmpty() const
ItemTypeT getType() const
Definition: item.h:224
ShopItems * mSellShopItems
Definition: shopwindow.h:175

◆ announce()

void ShopWindow::announce ( ShopItems *const  list,
const int  mode 
)

Definition at line 674 of file shopwindow.cpp.

References BUY, Net::ChatHandler::channelMessage(), chatHandler, cur_time, data, FOR_EACH, Item::getId(), Item::getInfo(), ItemInfo::getName(), ShopItem::getPrice(), Item::getQuantity(), CheckBox::isSelected(), ServerCommandType::item, ShopItems::items(), mAnnonceTime, mAnnounceButton, mAnnounceLinks, Widget::setEnabled(), strprintf(), and TRADE_CHANNEL.

Referenced by action(), and getAcceptPlayer().

675 {
676  if (list == nullptr)
677  return;
678 
679  std::string data;
680  if (mode == BUY)
681  data.append("Buy ");
682  else
683  data.append("Sell ");
684 
685  if (mAnnonceTime != 0 &&
686  (mAnnonceTime + (2 * 60) > cur_time || mAnnonceTime > cur_time))
687  {
688  return;
689  }
690 
692  if (mAnnounceButton != nullptr)
693  mAnnounceButton->setEnabled(false);
694 
695  STD_VECTOR<ShopItem*> items = list->items();
696 
697  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
698  {
699  const ShopItem *const item = *(it);
700  if (item->getQuantity() > 1)
701  {
702  if (mAnnounceLinks->isSelected())
703  {
704  data.append(strprintf("[@@%d|%[email protected]@] (%dGP) %d, ", item->getId(),
705  item->getInfo().getName().c_str(),
706  item->getPrice(), item->getQuantity()));
707  }
708  else
709  {
710  data.append(strprintf("%s (%dGP) %d, ",
711  item->getInfo().getName().c_str(),
712  item->getPrice(), item->getQuantity()));
713  }
714  }
715  else
716  {
717  if (mAnnounceLinks->isSelected())
718  {
719  data.append(strprintf("[@@%d|%[email protected]@] (%dGP), ", item->getId(),
720  item->getInfo().getName().c_str(), item->getPrice()));
721  }
722  else
723  {
724  data.append(strprintf("%s (%dGP), ",
725  item->getInfo().getName().c_str(), item->getPrice()));
726  }
727  }
728  }
729 
731 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
const std::string & getName() const
Definition: iteminfo.h:73
std::vector< ShopItem * > & items()
Definition: shopitems.h:135
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
int getPrice() const
Definition: shopitem.h:131
int getQuantity() const
Definition: item.h:104
uint32_t data
time_t mAnnonceTime
Definition: shopwindow.h:193
const ItemInfo & getInfo() const
Definition: item.h:170
volatile time_t cur_time
Definition: timer.cpp:57
void setEnabled(const bool enabled)
Definition: widget.h:351
Button * mAnnounceButton
Definition: shopwindow.h:184
int getId() const
Definition: item.h:80
Net::ChatHandler * chatHandler
Definition: net.cpp:83
virtual void channelMessage(const std::string &channel, const std::string &text) const =0
const std::string TRADE_CHANNEL
Definition: chat.h:30
CheckBox * mAnnounceLinks
Definition: shopwindow.h:187
bool isSelected() const
Definition: checkbox.h:146

◆ buyingStoreEnabled()

void ShopWindow::buyingStoreEnabled ( const bool  b)
virtual

Implements BuyingStoreModeListener.

Definition at line 1190 of file shopwindow.cpp.

References Being::enableShop(), localPlayer, mBuyShopSize, mEnableBuyingStore, and updateButtonsAndLabels().

Referenced by getAcceptPlayer().

1191 {
1192  mEnableBuyingStore = b;
1193  localPlayer->enableShop(b);
1194  if (!b)
1195  mBuyShopSize = 0;
1197 }
int mBuyShopSize
Definition: shopwindow.h:199
bool mEnableBuyingStore
Definition: shopwindow.h:202
LocalPlayer * localPlayer
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438
void enableShop(const bool b)
Definition: being.cpp:5344

◆ buyingStoreSlotsChanged()

void ShopWindow::buyingStoreSlotsChanged ( const int  slots)
virtual

Implements BuyingStoreSlotsListener.

Definition at line 1184 of file shopwindow.cpp.

References mBuyShopSize, and updateButtonsAndLabels().

Referenced by getAcceptPlayer().

1185 {
1186  mBuyShopSize = slots;
1188 }
int mBuyShopSize
Definition: shopwindow.h:199
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438

◆ checkFloodCounter()

bool ShopWindow::checkFloodCounter ( time_t &  counterTime)
static

Definition at line 1072 of file shopwindow.cpp.

References cur_time.

Referenced by getAcceptPlayer(), giveList(), and processRequest().

1073 {
1074  if (counterTime == 0 || counterTime > cur_time)
1075  counterTime = cur_time;
1076  else if (counterTime + 10 > cur_time)
1077  return false;
1078  else
1079  counterTime = cur_time;
1080  return true;
1081 }
volatile time_t cur_time
Definition: timer.cpp:57

◆ findShopItem()

bool ShopWindow::findShopItem ( const ShopItem *const  shopItem,
const int  mode 
) const

Definition at line 1083 of file shopwindow.cpp.

References FOR_EACH, Item::getId(), ShopItem::getPrice(), Item::getQuantity(), ServerCommandType::item, ShopItems::items(), mBuyShopItems, mSellShopItems, and SELL.

Referenced by getAcceptPlayer(), and processRequest().

1085 {
1086  if (shopItem == nullptr)
1087  return false;
1088 
1089  STD_VECTOR<ShopItem*> items;
1090  if (mode == SELL)
1091  items = mSellShopItems->items();
1092  else
1093  items = mBuyShopItems->items();
1094 
1095  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
1096  {
1097  const ShopItem *const item = *(it);
1098  if (item == nullptr)
1099  continue;
1100 
1101  if (item->getId() == shopItem->getId()
1102  && item->getPrice() == shopItem->getPrice()
1103  && item->getQuantity() >= shopItem->getQuantity())
1104  {
1105  return true;
1106  }
1107  }
1108  return false;
1109 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
std::vector< ShopItem * > & items()
Definition: shopitems.h:135
int getPrice() const
Definition: shopitem.h:131
int getQuantity() const
Definition: item.h:104
int getId() const
Definition: item.h:80
ShopItems * mSellShopItems
Definition: shopwindow.h:175

◆ getAcceptPlayer()

const std::string& ShopWindow::getAcceptPlayer ( ) const
inline

◆ giveList()

void ShopWindow::giveList ( const std::string &  nick,
const int  mode 
)

Definition at line 758 of file shopwindow.cpp.

References BUY, checkFloodCounter(), data, encodeStr(), Inventory::findItem(), FOR_EACH, PlayerInfo::getAttribute(), Item::getId(), PlayerInfo::getInventory(), ShopItem::getPrice(), Item::getQuantity(), ServerCommandType::item, ServerCommandType::item2, ItemColor_zero, ShopItems::items(), mBuyShopItems, mLastRequestTimeList, Attributes::MONEY, mSellShopItems, SELL, sendMessage(), and strprintf().

Referenced by getAcceptPlayer(), and TmwAthena::ChatRecv::processWhisperContinue().

759 {
761  return;
762 
763  std::string data("\302\202");
764 
765  ShopItems *list;
766  if (mode == BUY)
767  {
768  list = mBuyShopItems;
769  data.append("S1");
770  }
771  else
772  {
773  list = mSellShopItems;
774  data.append("B1");
775  }
776  if (list == nullptr)
777  return;
778 
779  const Inventory *const inv = PlayerInfo::getInventory();
780  if (inv == nullptr)
781  return;
782 
783  STD_VECTOR<ShopItem*> items = list->items();
784 
785  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
786  {
787  const ShopItem *const item = *(it);
788  if (item == nullptr)
789  continue;
790 
791  if (mode == SELL)
792  {
793  const Item *const item2 = inv->findItem(item->getId(),
795  if (item2 != nullptr)
796  {
797  int amount = item->getQuantity();
798  if (item2->getQuantity() < amount)
799  amount = item2->getQuantity();
800 
801  if (amount != 0)
802  {
803  data.append(strprintf("%s%s%s",
804  encodeStr(item->getId(), 2).c_str(),
805  encodeStr(item->getPrice(), 4).c_str(),
806  encodeStr(amount, 3).c_str()));
807  }
808  }
809  }
810  else
811  {
812  int amount = item->getQuantity();
813  if (item->getPrice() * amount > PlayerInfo::getAttribute(
815  {
817  / item->getPrice();
818  }
819 
820  if (amount > 0)
821  {
822  data.append(strprintf("%s%s%s",
823  encodeStr(item->getId(), 2).c_str(),
824  encodeStr(item->getPrice(), 4).c_str(),
825  encodeStr(amount, 3).c_str()));
826  }
827  }
828  }
829  sendMessage(nick, data, true);
830 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
const std::string encodeStr(unsigned int value, const unsigned int size)
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Inventory * getInventory()
Definition: playerinfo.cpp:193
const ItemColor ItemColor_zero
Definition: itemcolor.h:29
std::vector< ShopItem * > & items()
Definition: shopitems.h:135
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
int getPrice() const
Definition: shopitem.h:131
int getQuantity() const
Definition: item.h:104
uint32_t data
Definition: item.h:48
void sendMessage(const std::string &nick, std::string data, const bool random)
Definition: shopwindow.cpp:832
int getId() const
Definition: item.h:80
time_t mLastRequestTimeList
Definition: shopwindow.h:194
static bool checkFloodCounter(time_t &counterTime)
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
ShopItems * mSellShopItems
Definition: shopwindow.h:175

◆ isActive()

static bool ShopWindow::isActive ( )
inlinestatic

Returns true if any instances exist.

Definition at line 103 of file shopwindow.h.

References instances.

104  { return !instances.empty(); }
static DialogList instances
Definition: shopwindow.h:170

◆ isShopEmpty()

bool ShopWindow::isShopEmpty ( ) const

Definition at line 1131 of file shopwindow.cpp.

References ShopItems::empty(), mBuyShopItems, and mSellShopItems.

Referenced by action(), addBuyItem(), addSellItem(), getAcceptPlayer(), LocalPlayer::slowLogic(), and LocalPlayer::updateStatus().

1132 {
1133  if (mBuyShopItems->empty() && mSellShopItems->empty())
1134  return true;
1135  return false;
1136 }
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
bool empty() const
Definition: shopitems.h:101
ShopItems * mSellShopItems
Definition: shopwindow.h:175

◆ loadList()

void ShopWindow::loadList ( )

Definition at line 545 of file shopwindow.cpp.

References ShopItems::addItem(), ShopItems::clear(), ItemColor_one, mBuyShopItems, mSellShopItems, reportAlways, Settings::serverConfigDir, settings, ServerCommandType::str, and ItemType::Unknown.

Referenced by Actions::doSit(), setItemSelected(), and ShopWindow().

546 {
547  std::ifstream shopFile;
548  struct stat statbuf;
549 
550  mBuyShopItems->clear();
552 
553  const std::string shopListName = settings.serverConfigDir
554  + "/shoplist.txt";
555 
556  if (stat(shopListName.c_str(), &statbuf) == 0 &&
557  S_ISREG(statbuf.st_mode))
558  {
559  shopFile.open(shopListName.c_str(), std::ios::in);
560  if (!shopFile.is_open())
561  {
562  reportAlways("Error opening file for reading: %s",
563  shopListName.c_str())
564  shopFile.close();
565  return;
566  }
567  char line[101];
568  while (shopFile.getline(line, 100))
569  {
570  std::string buf;
571  const std::string str = line;
572  if (!str.empty())
573  {
574  STD_VECTOR<int> tokens;
575  std::stringstream ss(str);
576 
577  while (ss >> buf)
578  tokens.push_back(atoi(buf.c_str()));
579 
580  if (tokens.size() == 5 && (tokens[0] != 0))
581  {
582  // +++ need impliment colors?
583  if ((tokens[1] != 0) && (tokens[2] != 0))
584  {
586  tokens[0],
589  tokens[1],
590  tokens[2]);
591  }
592  if ((tokens[3] != 0) && (tokens[4] != 0))
593  {
595  tokens[0],
598  tokens[3],
599  tokens[4]);
600  }
601  }
602  }
603  }
604  shopFile.close();
605  }
606 }
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: shopitems.cpp:58
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
const ItemColor ItemColor_one
Definition: itemcolor.h:29
void clear()
Definition: shopitems.cpp:173
Settings settings
Definition: settings.cpp:31
std::string serverConfigDir
Definition: settings.h:115
#define reportAlways(...)
Definition: checkutils.h:252
ShopItems * mSellShopItems
Definition: shopwindow.h:175

◆ postInit()

void ShopWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 239 of file shopwindow.cpp.

References Window::enableVisibleSound(), Window::postInit(), setVisible(), updateSelection(), and Visible_false.

240 {
243  enableVisibleSound(true);
244  updateSelection();
245 }
const bool Visible_false
Definition: visible.h:29
void enableVisibleSound(bool b)
Definition: window.h:480
void updateSelection()
void postInit()
Definition: window.cpp:248
void setVisible(Visible visible)
Definition: shopwindow.cpp:506

◆ processRequest()

void ShopWindow::processRequest ( const std::string &  nick,
std::string  data,
const int  mode 
)

Definition at line 923 of file shopwindow.cpp.

References _, actorManager, BUY, checkFloodCounter(), config, confirmDlg, CREATEWIDGETR, DEFAULT_CURRENCY, ActorManager::findBeingByName(), Inventory::findItem(), findShopItem(), Configuration::getBoolValue(), PlayerInfo::getInventory(), Item::getQuantity(), PlayerInfo::isTrading(), ServerCommandType::item2, ItemColor_one, ItemColor_zero, localPlayer, mLastRequestTimeItem, Modal_false, Actions::msg(), mTradeItem, mTradeMoney, mTradeNick, ActorType::Player, SoundManager::playGuiSound(), SELL, sendMessage(), SOUND_REQUEST, SOUND_TRADE, soundManager, startTrade(), strprintf(), Trading_true, and ItemType::Unknown.

Referenced by getAcceptPlayer(), and TmwAthena::ChatRecv::processWhisperContinue().

926 {
927  if (localPlayer == nullptr ||
928  !mTradeNick.empty() ||
930  actorManager == nullptr ||
932  {
933  return;
934  }
935 
936  const Inventory *const inv = PlayerInfo::getInventory();
937  if (inv == nullptr)
938  return;
939 
940  const size_t idx = data.find(' ');
941  if (idx == std::string::npos)
942  return;
943 
945  return;
946 
947  if (!mTradeNick.empty())
948  {
949  sendMessage(nick,
950  // TRANSLATORS: error buy/sell shop request
951  _("error: player busy") + std::string(" "),
952  true);
953  return;
954  }
955 
956  data = data.substr(idx + 1);
957 
958  std::string part1;
959  std::string part2;
960  std::string part3;
961  std::stringstream ss(data);
962  int id;
963  int price;
964  int amount;
965 
966  if (!(ss >> part1))
967  return;
968 
969  if (!(ss >> part2))
970  return;
971 
972  if (!(ss >> part3))
973  return;
974 
975  id = atoi(part1.c_str());
976  price = atoi(part2.c_str());
977  amount = atoi(part3.c_str());
978 
979  delete mTradeItem;
980  // +++ need impliment colors?
981  mTradeItem = new ShopItem(-1,
982  id,
985  amount,
986  price,
988 
989  if (mode == BUY)
990  {
991  // +++ need support for colors
992  const Item *const item2 = inv->findItem(mTradeItem->getId(),
994  if (item2 == nullptr ||
995  item2->getQuantity() < amount ||
996  !findShopItem(mTradeItem, SELL))
997  {
998  sendMessage(nick,
999  // TRANSLATORS: error buy/sell shop request
1000  _("error: Can't sell this item") + std::string(" "),
1001  true);
1002  return;
1003  }
1004  mTradeMoney = 0;
1005  }
1006  else
1007  {
1008  if (!findShopItem(mTradeItem, BUY))
1009  {
1010  sendMessage(nick,
1011  // TRANSLATORS: error buy/sell shop request
1012  _("error: Can't buy this item") + std::string(" "),
1013  true);
1014  return;
1015  }
1016  mTradeMoney = mTradeItem->getPrice() * mTradeItem->getQuantity();
1017  }
1018 
1019  mTradeNick = nick;
1020 
1021  if (config.getBoolValue("autoShop"))
1022  {
1024  startTrade();
1025  }
1026  else
1027  {
1028  std::string msg;
1029  if (mode == BUY)
1030  {
1031  // TRANSLATORS: buy shop request (nick, item)
1032  msg = strprintf(_("%s wants to buy %s do you accept?"),
1033  nick.c_str(),
1034  mTradeItem->getInfo().getName().c_str());
1035  }
1036  else
1037  {
1038  // TRANSLATORS: sell shop request (nick, item)
1039  msg = strprintf(_("%s wants to sell %s do you accept?"),
1040  nick.c_str(),
1041  mTradeItem->getInfo().getName().c_str());
1042  }
1043 
1045  // TRANSLATORS: shop window dialog
1046  _("Request for Trade"),
1047  msg,
1048  SOUND_REQUEST,
1049  true,
1050  Modal_false,
1051  nullptr);
1052  confirmDlg->addActionListener(this);
1053  }
1054 }
#define _(s)
Definition: gettext.h:34
ShopItem * mTradeItem
Definition: shopwindow.h:176
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Inventory * getInventory()
Definition: playerinfo.cpp:193
SoundManager soundManager
Configuration config
static const std::string SOUND_REQUEST
Definition: sound.h:28
bool msg(InputEvent &event)
Definition: chat.cpp:38
const ItemColor ItemColor_zero
Definition: itemcolor.h:29
int mTradeMoney
Definition: shopwindow.h:197
const ItemColor ItemColor_one
Definition: itemcolor.h:29
void startTrade()
Definition: shopwindow.cpp:733
bool getBoolValue(const std::string &key) const
const std::string DEFAULT_CURRENCY
Definition: currency.h:26
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
time_t mLastRequestTimeItem
Definition: shopwindow.h:195
int getQuantity() const
Definition: item.h:104
uint32_t data
LocalPlayer * localPlayer
std::string mTradeNick
Definition: shopwindow.h:190
Definition: item.h:48
void sendMessage(const std::string &nick, std::string data, const bool random)
Definition: shopwindow.cpp:832
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:48
static const std::string SOUND_TRADE
Definition: sound.h:29
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
bool findShopItem(const ShopItem *const shopItem, const int mode) const
const bool Trading_true
Definition: trading.h:29
static bool checkFloodCounter(time_t &counterTime)
ActorManager * actorManager
void playGuiSound(const std::string &name)
Trading isTrading()
Definition: playerinfo.cpp:389

◆ saveList()

void ShopWindow::saveList ( ) const

Definition at line 608 of file shopwindow.cpp.

References FOR_EACH, Item::getId(), ShopItem::getPrice(), Item::getQuantity(), ServerCommandType::item, ShopItems::items(), mBuyShopItems, mSellShopItems, reportAlways, Settings::serverConfigDir, settings, and strprintf().

Referenced by Actions::doSit(), setItemSelected(), and ~ShopWindow().

609 {
610  std::ofstream shopFile;
611  const std::string shopListName = settings.serverConfigDir
612  + "/shoplist.txt";
613  std::map<int, ShopItem*> mapItems;
614 
615  shopFile.open(shopListName.c_str(), std::ios::binary);
616  if (!shopFile.is_open())
617  {
618  reportAlways("Error opening file writing: %s",
619  shopListName.c_str())
620  return;
621  }
622 
623  STD_VECTOR<ShopItem*> items = mBuyShopItems->items();
624  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
625  {
626  ShopItem *const item = *(it);
627  if (item != nullptr)
628  mapItems[item->getId()] = item;
629  }
630 
631  items = mSellShopItems->items();
632  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
633  {
634  if ((*it) == nullptr)
635  continue;
636  const ShopItem *const sellItem = *(it);
637  const ShopItem *const buyItem = mapItems[sellItem->getId()];
638 
639  shopFile << sellItem->getId();
640  if (buyItem != nullptr)
641  {
642  shopFile << strprintf(" %d %d ", buyItem->getQuantity(),
643  buyItem->getPrice());
644  mapItems.erase(sellItem->getId());
645  }
646  else
647  {
648  shopFile << " 0 0 ";
649  }
650 
651  shopFile << strprintf("%d %d", sellItem->getQuantity(),
652  sellItem->getPrice()) << std::endl;
653  }
654 
655  for (std::map<int, ShopItem*>::const_iterator mapIt = mapItems.begin(),
656  mapIt_fend = mapItems.end();
657  mapIt != mapIt_fend;
658  ++mapIt)
659  {
660  const ShopItem *const buyItem = (*mapIt).second;
661  if (buyItem != nullptr)
662  {
663  shopFile << buyItem->getId();
664  shopFile << strprintf(" %d %d ", buyItem->getQuantity(),
665  buyItem->getPrice());
666  shopFile << "0 0" << std::endl;
667  }
668  }
669 
670  shopFile.close();
671 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
Settings settings
Definition: settings.cpp:31
std::vector< ShopItem * > & items()
Definition: shopitems.h:135
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
int getPrice() const
Definition: shopitem.h:131
int getQuantity() const
Definition: item.h:104
std::string serverConfigDir
Definition: settings.h:115
int getId() const
Definition: item.h:80
#define reportAlways(...)
Definition: checkutils.h:252
ShopItems * mSellShopItems
Definition: shopwindow.h:175

◆ sendMessage()

void ShopWindow::sendMessage ( const std::string &  nick,
std::string  data,
const bool  random 
)

Definition at line 832 of file shopwindow.cpp.

References ChatWindow::addWhisper(), ChatMsgType::BY_PLAYER, chatHandler, chatWindow, config, encodeStr(), Configuration::getBoolValue(), mRandCounter, and Net::ChatHandler::privateMessage().

Referenced by getAcceptPlayer(), giveList(), and processRequest().

835 {
836  if (chatWindow == nullptr)
837  return;
838 
839  if (random)
840  {
841  mRandCounter ++;
842  if (mRandCounter > 200)
843  mRandCounter = 0;
844  data.append(encodeStr(mRandCounter, 2));
845  }
846 
847  if (config.getBoolValue("hideShopMessages"))
849  else
851 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:89
const std::string encodeStr(unsigned int value, const unsigned int size)
Configuration config
bool getBoolValue(const std::string &key) const
virtual void privateMessage(const std::string &recipient, const std::string &text) const =0
uint32_t data
Net::ChatHandler * chatHandler
Definition: net.cpp:83
void addWhisper(const std::string &nick, const std::string &mes, const ChatMsgTypeT own)
int mRandCounter
Definition: shopwindow.h:196

◆ setAcceptPlayer()

void ShopWindow::setAcceptPlayer ( const std::string &  name)
inline

Definition at line 120 of file shopwindow.h.

References mAcceptPlayer.

Referenced by TmwAthena::BuySellHandler::requestBuyList(), and TmwAthena::BuySellHandler::requestSellList().

121  { mAcceptPlayer = name; }
std::string mAcceptPlayer
Definition: shopwindow.h:189

◆ setItemSelected()

void ShopWindow::setItemSelected ( const int  id)
inline

◆ setShopName()

void ShopWindow::setShopName ( const std::string &  name)

Definition at line 1162 of file shopwindow.cpp.

References mSellShopName, serverConfig, Configuration::setValue(), and updateShopName().

Referenced by ShopRenameListener::action(), and getAcceptPlayer().

1163 {
1164  mSellShopName = name;
1165  serverConfig.setValue("sellShopName", mSellShopName);
1166  updateShopName();
1167 }
std::string mSellShopName
Definition: shopwindow.h:191
Configuration serverConfig
void updateShopName()
void setValue(const std::string &key, const std::string &value)

◆ setVisible()

void ShopWindow::setVisible ( Visible  visible)
virtual

Sets the visibility of this window.

Reimplemented from Window.

Definition at line 506 of file shopwindow.cpp.

References Window::setVisible().

Referenced by postInit().

507 {
508  Window::setVisible(visible);
509 }
virtual void setVisible(Visible visible)
Definition: window.cpp:777

◆ showList()

void ShopWindow::showList ( const std::string &  nick,
std::string  data 
)
static

Definition at line 853 of file shopwindow.cpp.

References SellDialog::addItem(), BuyDialog::addItem(), CREATEWIDGETV, decodeStr(), DEFAULT_CURRENCY, Inventory::findItem(), PlayerInfo::getAttribute(), PlayerInfo::getInventory(), Item::getQuantity(), ServerCommandType::item, ItemColor_one, ItemColor_zero, Attributes::MONEY, ShopItem::setDisabled(), SellDialog::setMoney(), BuyDialog::setMoney(), BuyDialog::sort(), and ItemType::Unknown.

Referenced by getAcceptPlayer(), and TmwAthena::ChatRecv::processWhisperContinue().

854 {
855  const Inventory *const inv = PlayerInfo::getInventory();
856  if (inv == nullptr)
857  return;
858 
859  BuyDialog *buyDialog = nullptr;
860  SellDialog *sellDialog = nullptr;
861  if (data.find("B1") == 0)
862  {
863  data = data.substr(2);
864  CREATEWIDGETV(buyDialog, BuyDialog, nick, DEFAULT_CURRENCY);
865  }
866  else if (data.find("S1") == 0)
867  {
868  data = data.substr(2);
869  CREATEWIDGETV(sellDialog, ShopSellDialog, nick);
870  }
871  else
872  {
873  return;
874  }
875 
876  if (buyDialog != nullptr)
878  if (sellDialog != nullptr)
880 
881  for (unsigned f = 0; f < data.length(); f += 9)
882  {
883  if (f + 9 > data.length())
884  break;
885 
886  const int id = decodeStr(data.substr(f, 2));
887  const int price = decodeStr(data.substr(f + 2, 4));
888  int amount = decodeStr(data.substr(f + 6, 3));
889  if (buyDialog != nullptr && amount > 0)
890  {
891  buyDialog->addItem(id,
894  amount,
895  price);
896  }
897  if (sellDialog != nullptr)
898  {
899  const Item *const item = inv->findItem(id, ItemColor_zero);
900  if (item != nullptr)
901  {
902  if (item->getQuantity() < amount)
903  amount = item->getQuantity();
904  }
905  else
906  {
907  amount = 0;
908  }
909  ShopItem *const shopItem = sellDialog->addItem(id,
912  amount,
913  price);
914 
915  if (shopItem != nullptr && amount <= 0)
916  shopItem->setDisabled(true);
917  }
918  }
919  if (buyDialog != nullptr)
920  buyDialog->sort();
921 }
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Inventory * getInventory()
Definition: playerinfo.cpp:193
const ItemColor ItemColor_zero
Definition: itemcolor.h:29
const ItemColor ItemColor_one
Definition: itemcolor.h:29
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: buydialog.cpp:456
const std::string DEFAULT_CURRENCY
Definition: currency.h:26
void sort()
Definition: buydialog.cpp:471
int getQuantity() const
Definition: item.h:104
uint32_t data
void setMoney(const int amount)
Definition: selldialog.cpp:339
Definition: item.h:48
void addItem(const Item *const item, const int price)
Definition: selldialog.cpp:237
unsigned int decodeStr(const std::string &str)
void setDisabled(const bool b)
Definition: shopitem.h:153
void setMoney(const int amount)
Definition: buydialog.cpp:436
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100

◆ startTrade()

void ShopWindow::startTrade ( )
private

Definition at line 733 of file shopwindow.cpp.

References actorManager, TradeWindow::addAutoItem(), TradeWindow::addAutoMoney(), TradeWindow::clear(), ActorManager::findBeingByName(), Item::getQuantity(), mTradeItem, mTradeMoney, mTradeNick, ActorType::Player, Net::TradeHandler::request(), tradeHandler, tradePartnerName, and tradeWindow.

Referenced by action(), getAcceptPlayer(), and processRequest().

734 {
735  if (actorManager == nullptr ||
736  tradeWindow == nullptr)
737  {
738  return;
739  }
740 
741  const Being *const being = actorManager->findBeingByName(
743  tradeWindow->clear();
744  if (mTradeMoney != 0)
745  {
747  }
748  else
749  {
752  }
753  tradeHandler->request(being);
755  mTradeNick.clear();
756 }
void addAutoMoney(const std::string &nick, const int money)
TradeWindow * tradeWindow
Definition: tradewindow.cpp:64
ShopItem * mTradeItem
Definition: shopwindow.h:176
int mTradeMoney
Definition: shopwindow.h:197
std::string tradePartnerName
Definition: popupmenu.cpp:100
int getQuantity() const
Definition: item.h:104
std::string mTradeNick
Definition: shopwindow.h:190
void addAutoItem(const std::string &nick, Item *const item, const int amount)
Net::TradeHandler * tradeHandler
Definition: net.cpp:95
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
virtual void request(const Being *const being) const
Definition: tradehandler.h:45
Definition: being.h:93
ActorManager * actorManager

◆ sumAmount()

int ShopWindow::sumAmount ( const Item *const  shopItem)
static

Definition at line 1112 of file shopwindow.cpp.

References Item::getId(), PlayerInfo::getInventory(), Inventory::getItem(), Item::getQuantity(), Inventory::getSize(), ServerCommandType::item, and localPlayer.

Referenced by action(), and getAcceptPlayer().

1113 {
1114  if ((localPlayer == nullptr) || (shopItem == nullptr))
1115  return 0;
1116 
1117  const Inventory *const inv = PlayerInfo::getInventory();
1118  if (inv == nullptr)
1119  return 0;
1120  int sum = 0;
1121 
1122  for (unsigned f = 0; f < inv->getSize(); f ++)
1123  {
1124  const Item *const item = inv->getItem(f);
1125  if ((item != nullptr) && item->getId() == shopItem->getId())
1126  sum += item->getQuantity();
1127  }
1128  return sum;
1129 }
Inventory * getInventory()
Definition: playerinfo.cpp:193
int getQuantity() const
Definition: item.h:104
LocalPlayer * localPlayer
Definition: item.h:48
int getId() const
Definition: item.h:80
Item * getItem(const int index) const
Definition: inventory.cpp:82
unsigned getSize() const
Definition: inventory.h:75

◆ updateButtonsAndLabels()

void ShopWindow::updateButtonsAndLabels ( )

Updates the state of buttons and labels.

Definition at line 438 of file shopwindow.cpp.

References _, Button::adjustSize(), ActorSprite::getHaveCart(), ShopItems::getNumberOfElements(), ListBox::getSelected(), isBuySelected, localPlayer, mAddButton, mBuyShopItemList, mBuyShopItems, mBuyShopSize, mDeleteButton, mEnableBuyingStore, mEnableVending, mPublishButton, mRenameButton, mSelectedItem, mSellShopItemList, mSellShopItems, mSellShopSize, Button::setCaption(), and Widget::setEnabled().

Referenced by addBuyItem(), addSellItem(), buyingStoreEnabled(), buyingStoreSlotsChanged(), setItemSelected(), updateSelection(), valueChanged(), vendingEnabled(), and vendingSlotsChanged().

439 {
440  bool allowDel(false);
441  bool allowAdd(false);
442  const bool sellNotEmpty = mSellShopItems->getNumberOfElements() > 0;
443  if (isBuySelected)
444  {
445  allowAdd = !mEnableBuyingStore;
446  allowDel = !mEnableBuyingStore
447  && mBuyShopItemList->getSelected() != -1
449  if (mPublishButton != nullptr)
450  {
451  if (mEnableBuyingStore)
452  {
453  // TRANSLATORS: unpublish shop button
454  mPublishButton->setCaption(_("Unpublish"));
455  }
456  else
457  {
458  // TRANSLATORS: publish shop button
459  mPublishButton->setCaption(_("Publish"));
460  }
462  if (mBuyShopSize > 0)
463  mPublishButton->setEnabled(true);
464  else
465  mPublishButton->setEnabled(false);
466  }
467  }
468  else
469  {
470  allowAdd = !mEnableVending && mSelectedItem != -1;
471  allowDel = !mEnableVending
472  && mSellShopItemList->getSelected() != -1
473  && sellNotEmpty;
474  if (mPublishButton != nullptr)
475  {
476  if (mEnableVending)
477  {
478  // TRANSLATORS: unpublish shop button
479  mPublishButton->setCaption(_("Unpublish"));
480  }
481  else
482  {
483  // TRANSLATORS: publish shop button
484  mPublishButton->setCaption(_("Publish"));
485  }
487  if (sellNotEmpty
488  && mSellShopSize > 0
489  && (localPlayer != nullptr)
490  && localPlayer->getHaveCart())
491  {
492  mPublishButton->setEnabled(true);
493  }
494  else
495  {
496  mPublishButton->setEnabled(false);
497  }
498  }
499  }
500  mAddButton->setEnabled(allowAdd);
501  mDeleteButton->setEnabled(allowDel);
502  if (mRenameButton != nullptr)
504 }
Button * mDeleteButton
Definition: shopwindow.h:183
ShopListBox * mSellShopItemList
Definition: shopwindow.h:179
int mBuyShopSize
Definition: shopwindow.h:199
Button * mRenameButton
Definition: shopwindow.h:186
#define _(s)
Definition: gettext.h:34
bool isBuySelected
Definition: shopwindow.h:200
Button * mPublishButton
Definition: shopwindow.h:185
bool mEnableVending
Definition: shopwindow.h:203
Button * mAddButton
Definition: shopwindow.h:182
ShopItems * mBuyShopItems
Definition: shopwindow.h:174
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:178
void adjustSize()
Definition: button.cpp:798
bool mEnableBuyingStore
Definition: shopwindow.h:202
void setCaption(const std::string &caption)
Definition: button.h:213
int mSellShopSize
Definition: shopwindow.h:198
LocalPlayer * localPlayer
int getSelected() const
Definition: listbox.h:167
int mSelectedItem
Definition: shopwindow.h:192
void setEnabled(const bool enabled)
Definition: widget.h:351
bool getHaveCart() const
Definition: actorsprite.h:174
ShopItems * mSellShopItems
Definition: shopwindow.h:175
int getNumberOfElements()
Definition: shopitems.h:98

◆ updateSelection()

void ShopWindow::updateSelection ( )
private

Definition at line 1138 of file shopwindow.cpp.

References isBuySelected, mBuyShopItemList, mCurrentShopItemList, mScrollArea, mSellShopItemList, ScrollArea::setContent(), and updateButtonsAndLabels().

Referenced by action(), getAcceptPlayer(), and postInit().

1139 {
1140  if (isBuySelected)
1142  else
1146 }
ShopListBox * mSellShopItemList
Definition: shopwindow.h:179
bool isBuySelected
Definition: shopwindow.h:200
ShopListBox * mCurrentShopItemList
Definition: shopwindow.h:180
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:178
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438
void setContent(Widget *widget)
ScrollArea * mScrollArea
Definition: shopwindow.h:181

◆ updateShopName()

void ShopWindow::updateShopName ( )
private

Definition at line 1148 of file shopwindow.cpp.

References _, mSellShopName, Window::setCaption(), and strprintf().

Referenced by getAcceptPlayer(), setShopName(), and ShopWindow().

1149 {
1150  if (mSellShopName.empty())
1151  {
1152  // TRANSLATORS: shop window name
1153  setCaption(_("Personal Shop"));
1154  }
1155  else
1156  {
1157  // TRANSLATORS: shop window name
1158  setCaption(strprintf(_("Personal Shop - %s"), mSellShopName.c_str()));
1159  }
1160 }
#define _(s)
Definition: gettext.h:34
std::string mSellShopName
Definition: shopwindow.h:191
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: window.h:530

◆ updateTimes()

void ShopWindow::updateTimes ( )

Definition at line 1056 of file shopwindow.cpp.

References BLOCK_END, BLOCK_START, cur_time, mAnnonceTime, mAnnounceButton, and Widget::setEnabled().

Referenced by getAcceptPlayer(), and Game::slowLogic().

1057 {
1058  BLOCK_START("ShopWindow::updateTimes")
1059  if (mAnnounceButton == nullptr)
1060  {
1061  BLOCK_END("ShopWindow::updateTimes")
1062  return;
1063  }
1064  if (mAnnonceTime + (2 * 60) < cur_time ||
1066  {
1067  mAnnounceButton->setEnabled(true);
1068  }
1069  BLOCK_END("ShopWindow::updateTimes")
1070 }
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
time_t mAnnonceTime
Definition: shopwindow.h:193
volatile time_t cur_time
Definition: timer.cpp:57
void setEnabled(const bool enabled)
Definition: widget.h:351
Button * mAnnounceButton
Definition: shopwindow.h:184

◆ valueChanged()

void ShopWindow::valueChanged ( const SelectionEvent event)
virtual

Updates the labels according to the selected item.

Reimplemented from SelectionListener.

Definition at line 433 of file shopwindow.cpp.

References updateButtonsAndLabels().

434 {
436 }
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438

◆ vendingEnabled()

void ShopWindow::vendingEnabled ( const bool  b)
virtual

Implements VendingModeListener.

Definition at line 1175 of file shopwindow.cpp.

References Being::enableShop(), localPlayer, mEnableVending, mSellShopSize, and updateButtonsAndLabels().

Referenced by getAcceptPlayer().

1176 {
1177  mEnableVending = b;
1178  localPlayer->enableShop(b);
1179  if (!b)
1180  mSellShopSize = 0;
1182 }
bool mEnableVending
Definition: shopwindow.h:203
int mSellShopSize
Definition: shopwindow.h:198
LocalPlayer * localPlayer
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438
void enableShop(const bool b)
Definition: being.cpp:5344

◆ vendingSlotsChanged()

void ShopWindow::vendingSlotsChanged ( const int  slots)
virtual

Implements VendingSlotsListener.

Definition at line 1169 of file shopwindow.cpp.

References mSellShopSize, and updateButtonsAndLabels().

Referenced by getAcceptPlayer().

1170 {
1171  mSellShopSize = slots;
1173 }
int mSellShopSize
Definition: shopwindow.h:198
void updateButtonsAndLabels()
Definition: shopwindow.cpp:438

Field Documentation

◆ instances

ShopWindow::DialogList ShopWindow::instances
staticprivate

Definition at line 170 of file shopwindow.h.

Referenced by isActive(), ShopWindow(), and ~ShopWindow().

◆ isBuySelected

bool ShopWindow::isBuySelected
private

Definition at line 200 of file shopwindow.h.

Referenced by action(), updateButtonsAndLabels(), and updateSelection().

◆ mAcceptPlayer

std::string ShopWindow::mAcceptPlayer
private

Definition at line 189 of file shopwindow.h.

Referenced by getAcceptPlayer(), and setAcceptPlayer().

◆ mAddButton

Button* ShopWindow::mAddButton
private

Definition at line 182 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mAnnonceTime

time_t ShopWindow::mAnnonceTime
private

Definition at line 193 of file shopwindow.h.

Referenced by announce(), and updateTimes().

◆ mAnnounceButton

Button* ShopWindow::mAnnounceButton
private

Definition at line 184 of file shopwindow.h.

Referenced by announce(), ShopWindow(), and updateTimes().

◆ mAnnounceLinks

CheckBox* ShopWindow::mAnnounceLinks
private

Definition at line 187 of file shopwindow.h.

Referenced by announce(), and ShopWindow().

◆ mBuyShopItemList

ShopListBox* ShopWindow::mBuyShopItemList
private

◆ mBuyShopItems

ShopItems* ShopWindow::mBuyShopItems
private

◆ mBuyShopSize

int ShopWindow::mBuyShopSize
private

◆ mCloseButton

Button* ShopWindow::mCloseButton
private

Definition at line 172 of file shopwindow.h.

Referenced by ShopWindow().

◆ mCurrentShopItemList

ShopListBox* ShopWindow::mCurrentShopItemList
private

Definition at line 180 of file shopwindow.h.

Referenced by updateSelection().

◆ mDeleteButton

Button* ShopWindow::mDeleteButton
private

Definition at line 183 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mEnableBuyingStore

bool ShopWindow::mEnableBuyingStore
private

Definition at line 202 of file shopwindow.h.

Referenced by action(), buyingStoreEnabled(), and updateButtonsAndLabels().

◆ mEnableVending

bool ShopWindow::mEnableVending
private

Definition at line 203 of file shopwindow.h.

Referenced by action(), updateButtonsAndLabels(), and vendingEnabled().

◆ mHaveVending

bool ShopWindow::mHaveVending
private

Definition at line 201 of file shopwindow.h.

Referenced by action(), and ShopWindow().

◆ mLastRequestTimeItem

time_t ShopWindow::mLastRequestTimeItem
private

Definition at line 195 of file shopwindow.h.

Referenced by processRequest().

◆ mLastRequestTimeList

time_t ShopWindow::mLastRequestTimeList
private

Definition at line 194 of file shopwindow.h.

Referenced by giveList().

◆ mPublishButton

Button* ShopWindow::mPublishButton
private

Definition at line 185 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mRandCounter

int ShopWindow::mRandCounter
private

Definition at line 196 of file shopwindow.h.

Referenced by sendMessage().

◆ mRenameButton

Button* ShopWindow::mRenameButton
private

Definition at line 186 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mScrollArea

ScrollArea* ShopWindow::mScrollArea
private

Definition at line 181 of file shopwindow.h.

Referenced by ShopWindow(), and updateSelection().

◆ mSelectedItem

int ShopWindow::mSelectedItem
private

Definition at line 192 of file shopwindow.h.

Referenced by action(), setItemSelected(), and updateButtonsAndLabels().

◆ mSellShopItemList

ShopListBox* ShopWindow::mSellShopItemList
private

◆ mSellShopItems

ShopItems* ShopWindow::mSellShopItems
private

◆ mSellShopName

std::string ShopWindow::mSellShopName
private

Definition at line 191 of file shopwindow.h.

Referenced by action(), setShopName(), and updateShopName().

◆ mSellShopSize

int ShopWindow::mSellShopSize
private

Definition at line 198 of file shopwindow.h.

Referenced by action(), updateButtonsAndLabels(), vendingEnabled(), and vendingSlotsChanged().

◆ mTabs

TabStrip* ShopWindow::mTabs
private

Definition at line 188 of file shopwindow.h.

Referenced by ShopWindow().

◆ mTradeItem

ShopItem* ShopWindow::mTradeItem
private

Definition at line 176 of file shopwindow.h.

Referenced by processRequest(), startTrade(), and ~ShopWindow().

◆ mTradeMoney

int ShopWindow::mTradeMoney
private

Definition at line 197 of file shopwindow.h.

Referenced by processRequest(), and startTrade().

◆ mTradeNick

std::string ShopWindow::mTradeNick
private

Definition at line 190 of file shopwindow.h.

Referenced by action(), processRequest(), and startTrade().


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