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

References _, Widget::addActionListener(), WidgetGroup::addButton(), ListBox::addSelectionListener(), 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().

101  :
102  // TRANSLATORS: shop window name
103  Window(_("Personal Shop"), Modal_false, nullptr, "shop.xml"),
108  ActionListener(),
110  // TRANSLATORS: shop window button
111  mCloseButton(new Button(this, _("Close"), "close", this)),
114  mTradeItem(nullptr),
119  mCurrentShopItemList(nullptr),
121  fromBool(getOptionBool("showbuybackground"), Opaque),
122  "shop_buy_background.xml")),
123  // TRANSLATORS: shop window label
124  mAddButton(new Button(this, _("Add"), "add", this)),
125  // TRANSLATORS: shop window label
126  mDeleteButton(new Button(this, _("Delete"), "delete", this)),
127  mAnnounceButton(nullptr),
128  mPublishButton(nullptr),
129  mRenameButton(nullptr),
130  mAnnounceLinks(nullptr),
131  mTabs(nullptr),
132  mAcceptPlayer(),
133  mTradeNick(),
134  mSellShopName(serverConfig.getStringValue("sellShopName")),
135  mSelectedItem(-1),
136  mAnnonceTime(0),
139  mRandCounter(0),
140  mTradeMoney(0),
141  mSellShopSize(0),
142  mBuyShopSize(0),
143  isBuySelected(true),
145  mEnableBuyingStore(false),
146  mEnableVending(false)
147 {
148  setWindowName("Personal Shop");
149  setResizable(true);
150  setCloseButton(true);
151  setStickyButtonLock(true);
152  setMinWidth(300);
153  setMinHeight(220);
154  if (mainGraphics->mWidth > 600)
156  else
158 
159  if (setupWindow != nullptr)
161 
162  const int size = config.getIntValue("fontSize")
163  + getOption("tabHeightAdjust", 16);
164  mTabs = new TabStrip(this, "shop", size);
165  mTabs->addActionListener(this);
166  mTabs->setActionEventId("tab_");
167  // TRANSLATORS: shop window tab name
168  mTabs->addButton(_("Buy"), "buy", true);
169  // TRANSLATORS: shop window tab name
170  mTabs->addButton(_("Sell"), "sell", false);
171  mTabs->setSelectable(false);
172  mScrollArea->setSelectable(false);
173 
174  loadList();
175 
178 
180 
183 
184  ContainerPlacer placer;
185  placer = getPlacer(0, 0);
186 
187  placer(0, 0, mTabs, 8).setPadding(3);
188 
189  if (mHaveVending)
190  {
191  // TRANSLATORS: shop window button
192  mPublishButton = new Button(this, _("Publish"), "publish", this);
193  // TRANSLATORS: shop window button
194  mRenameButton = new Button(this, _("Rename"), "rename", this);
195  placer(2, 6, mPublishButton);
196  placer(3, 6, mRenameButton);
197  }
198  else
199  {
200  // TRANSLATORS: shop window button
201  mAnnounceButton = new Button(this, _("Announce"), "announce", this);
202  // TRANSLATORS: shop window checkbox
203  mAnnounceLinks = new CheckBox(this, _("Show links in announce"), false,
204  this, "link announce");
205 
206  placer(2, 6, mAnnounceButton);
207  placer(0, 7, mAnnounceLinks, 7);
208  }
209 
210  placer(0, 1, mScrollArea, 8, 5).setPadding(3);
211  placer(0, 6, mAddButton);
212  placer(1, 6, mDeleteButton);
213  placer(7, 6, mCloseButton);
214 
215  Layout &layout = getLayout();
216  layout.setRowHeight(0, LayoutType::SET);
217 
218  center();
219  loadWindowState();
220  updateShopName();
221  instances.push_back(this);
222 }
Button * mDeleteButton
Definition: shopwindow.h:182
ShopListBox * mSellShopItemList
Definition: shopwindow.h:178
void setDefaultSize()
Definition: window.cpp:1186
int mBuyShopSize
Definition: shopwindow.h:198
bool mHaveVending
Definition: shopwindow.h:200
Button * mRenameButton
Definition: shopwindow.h:185
std::string getStringValue(const std::string &key) const
#define _(s)
Definition: gettext.h:34
bool isBuySelected
Definition: shopwindow.h:199
void loadList()
Definition: shopwindow.cpp:525
Button * mPublishButton
Definition: shopwindow.h:184
std::string mSellShopName
Definition: shopwindow.h:190
bool mEnableVending
Definition: shopwindow.h:202
Button * mAddButton
Definition: shopwindow.h:181
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
ShopItem * mTradeItem
Definition: shopwindow.h:175
void loadWindowState()
Definition: window.cpp:1075
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:428
void setMinWidth(const int width)
Definition: window.cpp:579
int mWidth
Definition: graphics.h:483
Definition: button.h:94
Configuration config
bool getOptionBool(const std::string &name, const bool def=false) const
Definition: window.cpp:1454
int getIntValue(const std::string &key) const
int mTradeMoney
Definition: shopwindow.h:196
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
ShopListBox * mCurrentShopItemList
Definition: shopwindow.h:179
Configuration serverConfig
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:177
void registerWindowForReset(Window *const window)
void setSelectable(const bool selectable)
Definition: widget.h:947
bool mEnableBuyingStore
Definition: shopwindow.h:201
const std::string DEFAULT_CURRENCY
Definition: currency.h:26
time_t mLastRequestTimeItem
Definition: shopwindow.h:194
int mSellShopSize
Definition: shopwindow.h:197
#define fromBool(val, name)
Definition: booldefines.h:48
time_t mAnnonceTime
Definition: shopwindow.h:192
std::string mTradeNick
Definition: shopwindow.h:189
Graphics * mainGraphics
Definition: graphics.cpp:108
int mSelectedItem
Definition: shopwindow.h:191
void setCloseButton(const bool flag)
Definition: window.cpp:737
std::string mAcceptPlayer
Definition: shopwindow.h:188
void setMinHeight(const int height)
Definition: window.cpp:592
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1379
Layout & getLayout()
Definition: window.cpp:1353
Button * mAnnounceButton
Definition: shopwindow.h:183
ServerTypeT getNetworkType()
Definition: net.cpp:178
TabStrip * mTabs
Definition: shopwindow.h:187
void updateShopName()
void center()
Definition: window.cpp:1405
ScrollArea * mScrollArea
Definition: shopwindow.h:180
time_t mLastRequestTimeList
Definition: shopwindow.h:193
Button * mCloseButton
Definition: shopwindow.h:171
static DialogList instances
Definition: shopwindow.h:169
void setResizable(const bool resize)
Definition: window.cpp:615
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:760
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
int getOption(const std::string &name, const int def=0) const
Definition: window.cpp:1442
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
Definition: layout.h:43
CheckBox * mAnnounceLinks
Definition: shopwindow.h:186
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
ShopItems * mSellShopItems
Definition: shopwindow.h:174
void setWindowName(const std::string &name)
Definition: window.h:353
int mRandCounter
Definition: shopwindow.h:195
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)

◆ ~ShopWindow()

ShopWindow::~ShopWindow ( )

Destructor

Definition at line 232 of file shopwindow.cpp.

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

233 {
234  saveList();
235 
241 
242  instances.remove(this);
243 }
ShopListBox * mSellShopItemList
Definition: shopwindow.h:178
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
ShopItem * mTradeItem
Definition: shopwindow.h:175
void saveList() const
Definition: shopwindow.cpp:588
#define delete2(var)
Definition: delete2.h:24
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:177
static DialogList instances
Definition: shopwindow.h:169
ShopItems * mSellShopItems
Definition: shopwindow.h:174

Member Function Documentation

◆ action()

void ShopWindow::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 245 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, 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.

246 {
247  const std::string &eventId = event.getId();
248  if (eventId == "close")
249  {
250  close();
251  return;
252  }
253 #ifdef TMWA_SUPPORT
254  else if (eventId == "yes")
255  {
256  startTrade();
257  }
258  else if (eventId == "no")
259  {
260  mTradeNick.clear();
261  }
262  else if (eventId == "ignore")
263  {
265  mTradeNick.clear();
266  }
267  else if (eventId == "announce")
268  {
269  if (isBuySelected)
270  {
273  }
274  else if (mSellShopItems->getNumberOfElements() > 0)
275  {
277  }
278  }
279 #endif // TMWA_SUPPORT
280  else if (eventId == "delete")
281  {
282  if (isBuySelected)
283  {
284  if (mBuyShopItemList != nullptr &&
286  {
288  if (isShopEmpty() && (localPlayer != nullptr))
290  }
291  }
292  else if ((mSellShopItemList != nullptr)
293  && mSellShopItemList->getSelected() >= 0)
294  {
296  if (isShopEmpty() && (localPlayer != nullptr))
298  }
299  }
300  else if (eventId == "tab_buy")
301  {
302  isBuySelected = true;
303  updateSelection();
304  }
305  else if (eventId == "tab_sell")
306  {
307  isBuySelected = false;
308  updateSelection();
309  }
310  else if (eventId == "publish")
311  {
312  if (isBuySelected)
313  {
314  if (mEnableBuyingStore)
315  {
318  }
319  else
320  {
321  STD_VECTOR<ShopItem*> &items = mBuyShopItems->items();
322  if (!items.empty())
323  {
326  true,
327  items);
328  }
329  }
330  }
331  else
332  {
333  if (mEnableVending)
334  {
337  }
338  else
339  {
340  STD_VECTOR<ShopItem*> &oldItems = mSellShopItems->items();
341  STD_VECTOR<ShopItem*> items;
342  const Inventory *const inv = PlayerInfo::getCartInventory();
343  if (inv == nullptr)
344  return;
345  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, oldItems)
346  {
347  ShopItem *const item = *it;
348  if (item == nullptr)
349  continue;
350  const Item *const cartItem = inv->findItem(item->getId(),
351  item->getColor());
352  if (cartItem == nullptr)
353  continue;
354  item->setInvIndex(cartItem->getInvIndex());
355  const int amount = cartItem->getQuantity();
356  if (amount == 0)
357  continue;
358  if (item->getQuantity() > amount)
359  item->setQuantity(amount);
360  items.push_back(item);
361  if (static_cast<signed int>(items.size()) >= mSellShopSize)
362  break;
363  }
364  if (!items.empty())
365  vendingHandler->createShop(mSellShopName, true, items);
366  }
367  }
368  }
369  else if (eventId == "rename")
370  {
371  EditDialog *const dialog = CREATEWIDGETR(EditDialog,
372  // TRANSLATORS: shop rename dialog title
373  _("Please enter new shop name"),
375  "OK");
378  }
379 
380  if (mSelectedItem < 1)
381  return;
382 
383  const Inventory *const inv = mHaveVending && !isBuySelected
385  if (inv == nullptr)
386  return;
387 
388  // +++ need support for colors
389  Item *const item = inv->findItem(mSelectedItem, ItemColor_zero);
390  if (item != nullptr)
391  {
392  if (eventId == "add")
393  {
394  if (isBuySelected)
395  {
397  this,
398  item,
399  sumAmount(item));
400  }
401  else
402  {
405  this,
406  item,
407  sumAmount(item));
408  }
409  }
410  }
411 }
int getInvIndex() const
Definition: item.h:164
ShopListBox * mSellShopItemList
Definition: shopwindow.h:178
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mHaveVending
Definition: shopwindow.h:200
#define _(s)
Definition: gettext.h:34
bool isBuySelected
Definition: shopwindow.h:199
std::string mSellShopName
Definition: shopwindow.h:190
bool mEnableVending
Definition: shopwindow.h:202
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
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:207
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:177
static int sumAmount(const Item *const shopItem)
static void distributeEvent(const bool b)
void startTrade()
Definition: shopwindow.cpp:713
virtual void close()
Definition: window.cpp:890
bool mEnableBuyingStore
Definition: shopwindow.h:201
std::vector< ShopItem * > & items()
Definition: shopitems.h:135
Inventory * getCartInventory()
Definition: playerinfo.cpp:219
int mSellShopSize
Definition: shopwindow.h:197
void announce(ShopItems *const list, const int mode)
Definition: shopwindow.cpp:654
int getQuantity() const
Definition: item.h:104
LocalPlayer * localPlayer
ItemColor getColor() const
Definition: item.h:180
std::string mTradeNick
Definition: shopwindow.h:189
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:191
ShopRenameListener shopRenameListener
Net::BuyingStoreHandler * buyingStoreHandler
Definition: net.cpp:98
static void showWindow(const ItemAmountWindowUsageT usage, Window *const parent, Item *const item, int maxRange=0, const int tag=0)
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:111
#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:174
int getNumberOfElements()
Definition: shopitems.h:98

◆ addBuyItem()

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

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

493 {
494  if (item == nullptr)
495  return;
496  const bool emp = isShopEmpty();
498  item->getType(),
499  item->getColor(),
500  amount,
501  price);
502  if (emp && (localPlayer != nullptr))
504 
506 }
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
void updateStatus() const
LocalPlayer * localPlayer
ItemColor getColor() const
Definition: item.h:180
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418
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 508 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().

510 {
511  if (item == nullptr)
512  return;
513  const bool emp = isShopEmpty();
515  item->getType(),
516  item->getColor(),
517  amount,
518  price);
519  if (emp && (localPlayer != nullptr))
521 
523 }
void updateStatus() const
LocalPlayer * localPlayer
ItemColor getColor() const
Definition: item.h:180
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418
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:174

◆ announce()

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

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

655 {
656  if (list == nullptr)
657  return;
658 
659  std::string data;
660  if (mode == BUY)
661  data.append("Buy ");
662  else
663  data.append("Sell ");
664 
665  if (mAnnonceTime != 0 &&
666  (mAnnonceTime + (2 * 60) > cur_time || mAnnonceTime > cur_time))
667  {
668  return;
669  }
670 
672  if (mAnnounceButton != nullptr)
673  mAnnounceButton->setEnabled(false);
674 
675  STD_VECTOR<ShopItem*> items = list->items();
676 
677  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
678  {
679  const ShopItem *const item = *(it);
680  if (item->getQuantity() > 1)
681  {
682  if (mAnnounceLinks->isSelected())
683  {
684  data.append(strprintf("[@@%d|%[email protected]@] (%dGP) %d, ", item->getId(),
685  item->getInfo().getName().c_str(),
686  item->getPrice(), item->getQuantity()));
687  }
688  else
689  {
690  data.append(strprintf("%s (%dGP) %d, ",
691  item->getInfo().getName().c_str(),
692  item->getPrice(), item->getQuantity()));
693  }
694  }
695  else
696  {
697  if (mAnnounceLinks->isSelected())
698  {
699  data.append(strprintf("[@@%d|%[email protected]@] (%dGP), ", item->getId(),
700  item->getInfo().getName().c_str(), item->getPrice()));
701  }
702  else
703  {
704  data.append(strprintf("%s (%dGP), ",
705  item->getInfo().getName().c_str(), item->getPrice()));
706  }
707  }
708  }
709 
711 }
#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:192
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:183
int getId() const
Definition: item.h:80
Net::ChatHandler * chatHandler
Definition: net.cpp:80
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:186
bool isSelected() const
Definition: checkbox.h:146

◆ buyingStoreEnabled()

void ShopWindow::buyingStoreEnabled ( const bool  b)
virtual

Implements BuyingStoreModeListener.

Definition at line 1168 of file shopwindow.cpp.

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

Referenced by getAcceptPlayer().

1169 {
1170  mEnableBuyingStore = b;
1171  localPlayer->enableShop(b);
1172  if (!b)
1173  mBuyShopSize = 0;
1175 }
int mBuyShopSize
Definition: shopwindow.h:198
bool mEnableBuyingStore
Definition: shopwindow.h:201
LocalPlayer * localPlayer
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418
void enableShop(const bool b)
Definition: being.cpp:5264

◆ buyingStoreSlotsChanged()

void ShopWindow::buyingStoreSlotsChanged ( const int  slots)
virtual

Implements BuyingStoreSlotsListener.

Definition at line 1162 of file shopwindow.cpp.

References mBuyShopSize, and updateButtonsAndLabels().

Referenced by getAcceptPlayer().

1163 {
1164  mBuyShopSize = slots;
1166 }
int mBuyShopSize
Definition: shopwindow.h:198
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418

◆ checkFloodCounter()

bool ShopWindow::checkFloodCounter ( time_t &  counterTime)
static

Definition at line 1050 of file shopwindow.cpp.

References cur_time.

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

1051 {
1052  if (counterTime == 0 || counterTime > cur_time)
1053  counterTime = cur_time;
1054  else if (counterTime + 10 > cur_time)
1055  return false;
1056  else
1057  counterTime = cur_time;
1058  return true;
1059 }
volatile time_t cur_time
Definition: timer.cpp:57

◆ findShopItem()

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

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

1063 {
1064  if (shopItem == nullptr)
1065  return false;
1066 
1067  STD_VECTOR<ShopItem*> items;
1068  if (mode == SELL)
1069  items = mSellShopItems->items();
1070  else
1071  items = mBuyShopItems->items();
1072 
1073  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
1074  {
1075  const ShopItem *const item = *(it);
1076  if (item == nullptr)
1077  continue;
1078 
1079  if (item->getId() == shopItem->getId()
1080  && item->getPrice() == shopItem->getPrice()
1081  && item->getQuantity() >= shopItem->getQuantity())
1082  {
1083  return true;
1084  }
1085  }
1086  return false;
1087 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
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:174

◆ getAcceptPlayer()

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

◆ giveList()

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

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

739 {
741  return;
742 
743  std::string data("\302\202");
744 
745  ShopItems *list;
746  if (mode == BUY)
747  {
748  list = mBuyShopItems;
749  data.append("S1");
750  }
751  else
752  {
753  list = mSellShopItems;
754  data.append("B1");
755  }
756  if (list == nullptr)
757  return;
758 
759  const Inventory *const inv = PlayerInfo::getInventory();
760  if (inv == nullptr)
761  return;
762 
763  STD_VECTOR<ShopItem*> items = list->items();
764 
765  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
766  {
767  const ShopItem *const item = *(it);
768  if (item == nullptr)
769  continue;
770 
771  if (mode == SELL)
772  {
773  const Item *const item2 = inv->findItem(item->getId(),
775  if (item2 != nullptr)
776  {
777  int amount = item->getQuantity();
778  if (item2->getQuantity() < amount)
779  amount = item2->getQuantity();
780 
781  if (amount != 0)
782  {
783  data.append(strprintf("%s%s%s",
784  encodeStr(item->getId(), 2).c_str(),
785  encodeStr(item->getPrice(), 4).c_str(),
786  encodeStr(amount, 3).c_str()));
787  }
788  }
789  }
790  else
791  {
792  int amount = item->getQuantity();
793  if (item->getPrice() * amount > PlayerInfo::getAttribute(
795  {
797  / item->getPrice();
798  }
799 
800  if (amount > 0)
801  {
802  data.append(strprintf("%s%s%s",
803  encodeStr(item->getId(), 2).c_str(),
804  encodeStr(item->getPrice(), 4).c_str(),
805  encodeStr(amount, 3).c_str()));
806  }
807  }
808  }
809  sendMessage(nick, data, true);
810 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
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:207
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
int getId() const
Definition: item.h:80
time_t mLastRequestTimeList
Definition: shopwindow.h:193
void sendMessage(const std::string &nick, std::string data, const bool random=false)
Definition: shopwindow.cpp:812
static bool checkFloodCounter(time_t &counterTime)
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
ShopItems * mSellShopItems
Definition: shopwindow.h:174

◆ 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:169

◆ isShopEmpty()

bool ShopWindow::isShopEmpty ( ) const

Definition at line 1109 of file shopwindow.cpp.

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

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

1110 {
1111  if (mBuyShopItems->empty() && mSellShopItems->empty())
1112  return true;
1113  return false;
1114 }
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
bool empty() const
Definition: shopitems.h:101
ShopItems * mSellShopItems
Definition: shopwindow.h:174

◆ loadList()

void ShopWindow::loadList ( )

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

526 {
527  std::ifstream shopFile;
528  struct stat statbuf;
529 
530  mBuyShopItems->clear();
532 
533  const std::string shopListName = settings.serverConfigDir
534  + "/shoplist.txt";
535 
536  if (stat(shopListName.c_str(), &statbuf) == 0 &&
537  S_ISREG(statbuf.st_mode))
538  {
539  shopFile.open(shopListName.c_str(), std::ios::in);
540  if (!shopFile.is_open())
541  {
542  reportAlways("Error opening file for reading: %s",
543  shopListName.c_str());
544  shopFile.close();
545  return;
546  }
547  char line[101];
548  while (shopFile.getline(line, 100))
549  {
550  std::string buf;
551  const std::string str = line;
552  if (!str.empty())
553  {
554  STD_VECTOR<int> tokens;
555  std::stringstream ss(str);
556 
557  while (ss >> buf)
558  tokens.push_back(atoi(buf.c_str()));
559 
560  if (tokens.size() == 5 && (tokens[0] != 0))
561  {
562  // +++ need impliment colors?
563  if ((tokens[1] != 0) && (tokens[2] != 0))
564  {
566  tokens[0],
569  tokens[1],
570  tokens[2]);
571  }
572  if ((tokens[3] != 0) && (tokens[4] != 0))
573  {
575  tokens[0],
578  tokens[3],
579  tokens[4]);
580  }
581  }
582  }
583  }
584  shopFile.close();
585  }
586 }
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:173
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:174

◆ postInit()

void ShopWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 224 of file shopwindow.cpp.

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

225 {
228  enableVisibleSound(true);
229  updateSelection();
230 }
const bool Visible_false
Definition: visible.h:29
void enableVisibleSound(bool b)
Definition: window.h:473
void updateSelection()
void postInit()
Definition: window.cpp:241
void setVisible(Visible visible)
Definition: shopwindow.cpp:486

◆ processRequest()

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

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

906 {
907  if (localPlayer == nullptr ||
908  !mTradeNick.empty() ||
910  actorManager == nullptr ||
912  {
913  return;
914  }
915 
916  const Inventory *const inv = PlayerInfo::getInventory();
917  if (inv == nullptr)
918  return;
919 
920  const size_t idx = data.find(' ');
921  if (idx == std::string::npos)
922  return;
923 
925  return;
926 
927  if (!mTradeNick.empty())
928  {
929  sendMessage(nick,
930  // TRANSLATORS: error buy/sell shop request
931  _("error: player busy") + std::string(" "),
932  true);
933  return;
934  }
935 
936  data = data.substr(idx + 1);
937 
938  std::string part1;
939  std::string part2;
940  std::string part3;
941  std::stringstream ss(data);
942  int id;
943  int price;
944  int amount;
945 
946  if (!(ss >> part1))
947  return;
948 
949  if (!(ss >> part2))
950  return;
951 
952  if (!(ss >> part3))
953  return;
954 
955  id = atoi(part1.c_str());
956  price = atoi(part2.c_str());
957  amount = atoi(part3.c_str());
958 
959  delete mTradeItem;
960  // +++ need impliment colors?
961  mTradeItem = new ShopItem(-1,
962  id,
965  amount,
966  price,
968 
969  if (mode == BUY)
970  {
971  // +++ need support for colors
972  const Item *const item2 = inv->findItem(mTradeItem->getId(),
974  if (item2 == nullptr ||
975  item2->getQuantity() < amount ||
976  !findShopItem(mTradeItem, SELL))
977  {
978  sendMessage(nick,
979  // TRANSLATORS: error buy/sell shop request
980  _("error: Can't sell this item") + std::string(" "),
981  true);
982  return;
983  }
984  mTradeMoney = 0;
985  }
986  else
987  {
988  if (!findShopItem(mTradeItem, BUY))
989  {
990  sendMessage(nick,
991  // TRANSLATORS: error buy/sell shop request
992  _("error: Can't buy this item") + std::string(" "),
993  true);
994  return;
995  }
996  mTradeMoney = mTradeItem->getPrice() * mTradeItem->getQuantity();
997  }
998 
999  mTradeNick = nick;
1000 
1001  if (config.getBoolValue("autoShop"))
1002  {
1004  startTrade();
1005  }
1006  else
1007  {
1008  std::string msg;
1009  if (mode == BUY)
1010  {
1011  // TRANSLATORS: buy shop request (nick, item)
1012  msg = strprintf(_("%s wants to buy %s do you accept?"),
1013  nick.c_str(),
1014  mTradeItem->getInfo().getName().c_str());
1015  }
1016  else
1017  {
1018  // TRANSLATORS: sell shop request (nick, item)
1019  msg = strprintf(_("%s wants to sell %s do you accept?"),
1020  nick.c_str(),
1021  mTradeItem->getInfo().getName().c_str());
1022  }
1023 
1025  // TRANSLATORS: shop window dialog
1026  _("Request for Trade"),
1027  msg,
1028  SOUND_REQUEST,
1029  true);
1030  confirmDlg->addActionListener(this);
1031  }
1032 }
#define _(s)
Definition: gettext.h:34
Being * findBeingByName(const std::string &name, const ActorTypeT type=ActorType::Unknown) const
ShopItem * mTradeItem
Definition: shopwindow.h:175
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Inventory * getInventory()
Definition: playerinfo.cpp:207
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:196
const ItemColor ItemColor_one
Definition: itemcolor.h:29
void startTrade()
Definition: shopwindow.cpp:713
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:194
int getQuantity() const
Definition: item.h:104
uint32_t data
LocalPlayer * localPlayer
std::string mTradeNick
Definition: shopwindow.h:189
Definition: item.h:48
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:46
static const std::string SOUND_TRADE
Definition: sound.h:29
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
bool findShopItem(const ShopItem *const shopItem, const int mode) const
void sendMessage(const std::string &nick, std::string data, const bool random=false)
Definition: shopwindow.cpp:812
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:403

◆ saveList()

void ShopWindow::saveList ( ) const

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

589 {
590  std::ofstream shopFile;
591  const std::string shopListName = settings.serverConfigDir
592  + "/shoplist.txt";
593  std::map<int, ShopItem*> mapItems;
594 
595  shopFile.open(shopListName.c_str(), std::ios::binary);
596  if (!shopFile.is_open())
597  {
598  reportAlways("Error opening file writing: %s",
599  shopListName.c_str());
600  return;
601  }
602 
603  STD_VECTOR<ShopItem*> items = mBuyShopItems->items();
604  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
605  {
606  ShopItem *const item = *(it);
607  if (item != nullptr)
608  mapItems[item->getId()] = item;
609  }
610 
611  items = mSellShopItems->items();
612  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
613  {
614  if ((*it) == nullptr)
615  continue;
616  const ShopItem *const sellItem = *(it);
617  const ShopItem *const buyItem = mapItems[sellItem->getId()];
618 
619  shopFile << sellItem->getId();
620  if (buyItem != nullptr)
621  {
622  shopFile << strprintf(" %d %d ", buyItem->getQuantity(),
623  buyItem->getPrice());
624  mapItems.erase(sellItem->getId());
625  }
626  else
627  {
628  shopFile << " 0 0 ";
629  }
630 
631  shopFile << strprintf("%d %d", sellItem->getQuantity(),
632  sellItem->getPrice()) << std::endl;
633  }
634 
635  for (std::map<int, ShopItem*>::const_iterator mapIt = mapItems.begin(),
636  mapIt_fend = mapItems.end();
637  mapIt != mapIt_fend;
638  ++mapIt)
639  {
640  const ShopItem *const buyItem = (*mapIt).second;
641  if (buyItem != nullptr)
642  {
643  shopFile << buyItem->getId();
644  shopFile << strprintf(" %d %d ", buyItem->getQuantity(),
645  buyItem->getPrice());
646  shopFile << "0 0" << std::endl;
647  }
648  }
649 
650  shopFile.close();
651 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
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:174

◆ sendMessage()

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

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

815 {
816  if (chatWindow == nullptr)
817  return;
818 
819  if (random)
820  {
821  mRandCounter ++;
822  if (mRandCounter > 200)
823  mRandCounter = 0;
824  data.append(encodeStr(mRandCounter, 2));
825  }
826 
827  if (config.getBoolValue("hideShopMessages"))
829  else
831 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
const std::string encodeStr(unsigned int value, const unsigned int size)
Configuration config
void addWhisper(const std::string &nick, const std::string &mes, const ChatMsgTypeT own=ChatMsgType::BY_OTHER)
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:80
int mRandCounter
Definition: shopwindow.h:195

◆ 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:188

◆ setItemSelected()

void ShopWindow::setItemSelected ( const int  id)
inline

◆ setShopName()

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

Definition at line 1140 of file shopwindow.cpp.

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

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

1141 {
1142  mSellShopName = name;
1143  serverConfig.setValue("sellShopName", mSellShopName);
1144  updateShopName();
1145 }
std::string mSellShopName
Definition: shopwindow.h:190
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 486 of file shopwindow.cpp.

References Window::setVisible().

Referenced by postInit().

487 {
488  Window::setVisible(visible);
489 }
virtual void setVisible(Visible visible)
Definition: window.cpp:766

◆ showList()

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

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

834 {
835  const Inventory *const inv = PlayerInfo::getInventory();
836  if (inv == nullptr)
837  return;
838 
839  BuyDialog *buyDialog = nullptr;
840  SellDialog *sellDialog = nullptr;
841  if (data.find("B1") == 0)
842  {
843  data = data.substr(2);
844  CREATEWIDGETV(buyDialog, BuyDialog, nick, DEFAULT_CURRENCY);
845  }
846  else if (data.find("S1") == 0)
847  {
848  data = data.substr(2);
849  CREATEWIDGETV(sellDialog, ShopSellDialog, nick);
850  }
851  else
852  {
853  return;
854  }
855 
856  if (buyDialog != nullptr)
858  if (sellDialog != nullptr)
860 
861  for (unsigned f = 0; f < data.length(); f += 9)
862  {
863  if (f + 9 > data.length())
864  break;
865 
866  const int id = decodeStr(data.substr(f, 2));
867  const int price = decodeStr(data.substr(f + 2, 4));
868  int amount = decodeStr(data.substr(f + 6, 3));
869  if (buyDialog != nullptr && amount > 0)
870  {
871  buyDialog->addItem(id,
874  amount,
875  price);
876  }
877  if (sellDialog != nullptr)
878  {
879  const Item *const item = inv->findItem(id, ItemColor_zero);
880  if (item != nullptr)
881  {
882  if (item->getQuantity() < amount)
883  amount = item->getQuantity();
884  }
885  else
886  {
887  amount = 0;
888  }
889  ShopItem *const shopItem = sellDialog->addItem(id,
892  amount,
893  price);
894 
895  if (shopItem != nullptr && amount <= 0)
896  shopItem->setDisabled(true);
897  }
898  }
899  if (buyDialog != nullptr)
900  buyDialog->sort();
901 }
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
Inventory * getInventory()
Definition: playerinfo.cpp:207
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:448
const std::string DEFAULT_CURRENCY
Definition: currency.h:26
void sort()
Definition: buydialog.cpp:463
int getQuantity() const
Definition: item.h:104
uint32_t data
void setMoney(const int amount)
Definition: selldialog.cpp:318
Definition: item.h:48
void addItem(const Item *const item, const int price)
Definition: selldialog.cpp:216
unsigned int decodeStr(const std::string &str)
void setDisabled(const bool b)
Definition: shopitem.h:153
void setMoney(const int amount)
Definition: buydialog.cpp:428
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100

◆ startTrade()

void ShopWindow::startTrade ( )
private

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

714 {
715  if (actorManager == nullptr ||
716  tradeWindow == nullptr)
717  {
718  return;
719  }
720 
721  const Being *const being = actorManager->findBeingByName(
723  tradeWindow->clear();
724  if (mTradeMoney != 0)
725  {
727  }
728  else
729  {
732  }
733  tradeHandler->request(being);
735  mTradeNick.clear();
736 }
void addAutoMoney(const std::string &nick, const int money)
TradeWindow * tradeWindow
Definition: tradewindow.cpp:64
Being * findBeingByName(const std::string &name, const ActorTypeT type=ActorType::Unknown) const
ShopItem * mTradeItem
Definition: shopwindow.h:175
int mTradeMoney
Definition: shopwindow.h:196
std::string tradePartnerName
Definition: popupmenu.cpp:100
int getQuantity() const
Definition: item.h:104
std::string mTradeNick
Definition: shopwindow.h:189
void addAutoItem(const std::string &nick, Item *const item, const int amount)
Net::TradeHandler * tradeHandler
Definition: net.cpp:91
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 1090 of file shopwindow.cpp.

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

Referenced by action(), and getAcceptPlayer().

1091 {
1092  if ((localPlayer == nullptr) || (shopItem == nullptr))
1093  return 0;
1094 
1095  const Inventory *const inv = PlayerInfo::getInventory();
1096  if (inv == nullptr)
1097  return 0;
1098  int sum = 0;
1099 
1100  for (unsigned f = 0; f < inv->getSize(); f ++)
1101  {
1102  const Item *const item = inv->getItem(f);
1103  if ((item != nullptr) && item->getId() == shopItem->getId())
1104  sum += item->getQuantity();
1105  }
1106  return sum;
1107 }
Inventory * getInventory()
Definition: playerinfo.cpp:207
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 418 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().

419 {
420  bool allowDel(false);
421  bool allowAdd(false);
422  const bool sellNotEmpty = mSellShopItems->getNumberOfElements() > 0;
423  if (isBuySelected)
424  {
425  allowAdd = !mEnableBuyingStore;
426  allowDel = !mEnableBuyingStore
427  && mBuyShopItemList->getSelected() != -1
429  if (mPublishButton != nullptr)
430  {
431  if (mEnableBuyingStore)
432  {
433  // TRANSLATORS: unpublish shop button
434  mPublishButton->setCaption(_("Unpublish"));
435  }
436  else
437  {
438  // TRANSLATORS: publish shop button
439  mPublishButton->setCaption(_("Publish"));
440  }
442  if (mBuyShopSize > 0)
443  mPublishButton->setEnabled(true);
444  else
445  mPublishButton->setEnabled(false);
446  }
447  }
448  else
449  {
450  allowAdd = !mEnableVending && mSelectedItem != -1;
451  allowDel = !mEnableVending
452  && mSellShopItemList->getSelected() != -1
453  && sellNotEmpty;
454  if (mPublishButton != nullptr)
455  {
456  if (mEnableVending)
457  {
458  // TRANSLATORS: unpublish shop button
459  mPublishButton->setCaption(_("Unpublish"));
460  }
461  else
462  {
463  // TRANSLATORS: publish shop button
464  mPublishButton->setCaption(_("Publish"));
465  }
467  if (sellNotEmpty
468  && mSellShopSize > 0
469  && (localPlayer != nullptr)
470  && localPlayer->getHaveCart())
471  {
472  mPublishButton->setEnabled(true);
473  }
474  else
475  {
476  mPublishButton->setEnabled(false);
477  }
478  }
479  }
480  mAddButton->setEnabled(allowAdd);
481  mDeleteButton->setEnabled(allowDel);
482  if (mRenameButton != nullptr)
484 }
Button * mDeleteButton
Definition: shopwindow.h:182
ShopListBox * mSellShopItemList
Definition: shopwindow.h:178
int mBuyShopSize
Definition: shopwindow.h:198
Button * mRenameButton
Definition: shopwindow.h:185
#define _(s)
Definition: gettext.h:34
bool isBuySelected
Definition: shopwindow.h:199
Button * mPublishButton
Definition: shopwindow.h:184
bool mEnableVending
Definition: shopwindow.h:202
Button * mAddButton
Definition: shopwindow.h:181
ShopItems * mBuyShopItems
Definition: shopwindow.h:173
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:177
void adjustSize()
Definition: button.cpp:821
bool mEnableBuyingStore
Definition: shopwindow.h:201
void setCaption(const std::string &caption)
Definition: button.h:214
int mSellShopSize
Definition: shopwindow.h:197
LocalPlayer * localPlayer
int getSelected() const
Definition: listbox.h:167
int mSelectedItem
Definition: shopwindow.h:191
void setEnabled(const bool enabled)
Definition: widget.h:351
bool getHaveCart() const
Definition: actorsprite.h:174
ShopItems * mSellShopItems
Definition: shopwindow.h:174
int getNumberOfElements()
Definition: shopitems.h:98

◆ updateSelection()

void ShopWindow::updateSelection ( )
private

Definition at line 1116 of file shopwindow.cpp.

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

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

1117 {
1118  if (isBuySelected)
1120  else
1124 }
ShopListBox * mSellShopItemList
Definition: shopwindow.h:178
bool isBuySelected
Definition: shopwindow.h:199
ShopListBox * mCurrentShopItemList
Definition: shopwindow.h:179
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:177
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418
void setContent(Widget *widget)
ScrollArea * mScrollArea
Definition: shopwindow.h:180

◆ updateShopName()

void ShopWindow::updateShopName ( )
private

Definition at line 1126 of file shopwindow.cpp.

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

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

1127 {
1128  if (mSellShopName.empty())
1129  {
1130  // TRANSLATORS: shop window name
1131  setCaption(_("Personal Shop"));
1132  }
1133  else
1134  {
1135  // TRANSLATORS: shop window name
1136  setCaption(strprintf(_("Personal Shop - %s"), mSellShopName.c_str()));
1137  }
1138 }
#define _(s)
Definition: gettext.h:34
std::string mSellShopName
Definition: shopwindow.h:190
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: window.h:523

◆ updateTimes()

void ShopWindow::updateTimes ( )

Definition at line 1034 of file shopwindow.cpp.

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

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

1035 {
1036  BLOCK_START("ShopWindow::updateTimes")
1037  if (mAnnounceButton == nullptr)
1038  {
1039  BLOCK_END("ShopWindow::updateTimes")
1040  return;
1041  }
1042  if (mAnnonceTime + (2 * 60) < cur_time ||
1044  {
1045  mAnnounceButton->setEnabled(true);
1046  }
1047  BLOCK_END("ShopWindow::updateTimes")
1048 }
#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:192
volatile time_t cur_time
Definition: timer.cpp:57
void setEnabled(const bool enabled)
Definition: widget.h:351
Button * mAnnounceButton
Definition: shopwindow.h:183

◆ valueChanged()

void ShopWindow::valueChanged ( const SelectionEvent event)
virtual

Updates the labels according to the selected item.

Reimplemented from SelectionListener.

Definition at line 413 of file shopwindow.cpp.

References updateButtonsAndLabels().

414 {
416 }
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418

◆ vendingEnabled()

void ShopWindow::vendingEnabled ( const bool  b)
virtual

Implements VendingModeListener.

Definition at line 1153 of file shopwindow.cpp.

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

Referenced by getAcceptPlayer().

1154 {
1155  mEnableVending = b;
1156  localPlayer->enableShop(b);
1157  if (!b)
1158  mSellShopSize = 0;
1160 }
bool mEnableVending
Definition: shopwindow.h:202
int mSellShopSize
Definition: shopwindow.h:197
LocalPlayer * localPlayer
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418
void enableShop(const bool b)
Definition: being.cpp:5264

◆ vendingSlotsChanged()

void ShopWindow::vendingSlotsChanged ( const int  slots)
virtual

Implements VendingSlotsListener.

Definition at line 1147 of file shopwindow.cpp.

References mSellShopSize, and updateButtonsAndLabels().

Referenced by getAcceptPlayer().

1148 {
1149  mSellShopSize = slots;
1151 }
int mSellShopSize
Definition: shopwindow.h:197
void updateButtonsAndLabels()
Definition: shopwindow.cpp:418

Field Documentation

◆ instances

ShopWindow::DialogList ShopWindow::instances
staticprivate

Definition at line 169 of file shopwindow.h.

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

◆ isBuySelected

bool ShopWindow::isBuySelected
private

Definition at line 199 of file shopwindow.h.

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

◆ mAcceptPlayer

std::string ShopWindow::mAcceptPlayer
private

Definition at line 188 of file shopwindow.h.

Referenced by getAcceptPlayer(), and setAcceptPlayer().

◆ mAddButton

Button* ShopWindow::mAddButton
private

Definition at line 181 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mAnnonceTime

time_t ShopWindow::mAnnonceTime
private

Definition at line 192 of file shopwindow.h.

Referenced by announce(), and updateTimes().

◆ mAnnounceButton

Button* ShopWindow::mAnnounceButton
private

Definition at line 183 of file shopwindow.h.

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

◆ mAnnounceLinks

CheckBox* ShopWindow::mAnnounceLinks
private

Definition at line 186 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 171 of file shopwindow.h.

Referenced by ShopWindow().

◆ mCurrentShopItemList

ShopListBox* ShopWindow::mCurrentShopItemList
private

Definition at line 179 of file shopwindow.h.

Referenced by updateSelection().

◆ mDeleteButton

Button* ShopWindow::mDeleteButton
private

Definition at line 182 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mEnableBuyingStore

bool ShopWindow::mEnableBuyingStore
private

Definition at line 201 of file shopwindow.h.

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

◆ mEnableVending

bool ShopWindow::mEnableVending
private

Definition at line 202 of file shopwindow.h.

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

◆ mHaveVending

bool ShopWindow::mHaveVending
private

Definition at line 200 of file shopwindow.h.

Referenced by action(), and ShopWindow().

◆ mLastRequestTimeItem

time_t ShopWindow::mLastRequestTimeItem
private

Definition at line 194 of file shopwindow.h.

Referenced by processRequest().

◆ mLastRequestTimeList

time_t ShopWindow::mLastRequestTimeList
private

Definition at line 193 of file shopwindow.h.

Referenced by giveList().

◆ mPublishButton

Button* ShopWindow::mPublishButton
private

Definition at line 184 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mRandCounter

int ShopWindow::mRandCounter
private

Definition at line 195 of file shopwindow.h.

Referenced by sendMessage().

◆ mRenameButton

Button* ShopWindow::mRenameButton
private

Definition at line 185 of file shopwindow.h.

Referenced by ShopWindow(), and updateButtonsAndLabels().

◆ mScrollArea

ScrollArea* ShopWindow::mScrollArea
private

Definition at line 180 of file shopwindow.h.

Referenced by ShopWindow(), and updateSelection().

◆ mSelectedItem

int ShopWindow::mSelectedItem
private

Definition at line 191 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 190 of file shopwindow.h.

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

◆ mSellShopSize

int ShopWindow::mSellShopSize
private

Definition at line 197 of file shopwindow.h.

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

◆ mTabs

TabStrip* ShopWindow::mTabs
private

Definition at line 187 of file shopwindow.h.

Referenced by ShopWindow().

◆ mTradeItem

ShopItem* ShopWindow::mTradeItem
private

Definition at line 175 of file shopwindow.h.

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

◆ mTradeMoney

int ShopWindow::mTradeMoney
private

Definition at line 196 of file shopwindow.h.

Referenced by processRequest(), and startTrade().

◆ mTradeNick

std::string ShopWindow::mTradeNick
private

Definition at line 189 of file shopwindow.h.

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


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