ManaPlus
shopwindow.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WINDOWS_SHOPWINDOW_H
25 #define GUI_WINDOWS_SHOPWINDOW_H
26 
27 #include "gui/widgets/window.h"
28 
35 
36 class Button;
37 class CheckBox;
38 class Item;
39 class ScrollArea;
40 class ShopItem;
41 class ShopItems;
42 class ShopListBox;
43 class TabStrip;
44 
50 class ShopWindow final : public Window,
51  public VendingModeListener,
52  public VendingSlotsListener,
55  public ActionListener,
56  public SelectionListener
57 {
58  public:
59  enum ShopMode
60  {
61  BUY = 0,
62  SELL = 1
63  };
64 
70  ShopWindow();
71 
73 
74 
78 
79  void postInit() override final;
80 
84  void action(const ActionEvent &event) override final;
85 
89  void valueChanged(const SelectionEvent &event) override final;
90 
95 
99  void setVisible(Visible visible) override final;
100 
104  static bool isActive() A_WARN_UNUSED
105  { return !instances.empty(); }
106 
107  void setItemSelected(const int id)
109 
110  void addBuyItem(const Item *const item, const int amount,
111  const int price);
112 
113  void addSellItem(const Item *const item, const int amount,
114  const int price);
115 
116  void loadList();
117 
118  void saveList() const;
119 
120 #ifdef TMWA_SUPPORT
121  void setAcceptPlayer(const std::string &name)
122  { mAcceptPlayer = name; }
123 
124  const std::string &getAcceptPlayer() const noexcept2 A_WARN_UNUSED
125  { return mAcceptPlayer; }
126 
127  void announce(ShopItems *const list, const int mode);
128 
129  void giveList(const std::string &nick, const int mode);
130 
131  void sendMessage(const std::string &nick,
132  std::string data,
133  const bool random);
134 
135  static void showList(const std::string &nick, std::string data);
136 
137  void processRequest(const std::string &nick, std::string data,
138  const int mode);
139  void updateTimes();
140 
141  static bool checkFloodCounter(time_t &counterTime) A_WARN_UNUSED;
142 
143  bool findShopItem(const ShopItem *const shopItem,
144  const int mode) const A_WARN_UNUSED;
145 #endif // TMWA_SUPPORT
146 
147  static int sumAmount(const Item *const shopItem) A_WARN_UNUSED;
148 
149  bool isShopEmpty() const A_WARN_UNUSED;
150 
151  void vendingEnabled(const bool b) override final;
152 
153  void vendingSlotsChanged(const int slots) override final;
154 
155  void buyingStoreEnabled(const bool b) override final;
156 
157  void buyingStoreSlotsChanged(const int slots) override final;
158 
159  void setShopName(const std::string &name);
160 
161  private:
162 #ifdef TMWA_SUPPORT
163  void startTrade();
164 #endif // TMWA_SUPPORT
165 
166  void updateSelection();
167 
168  void updateShopName();
169 
170  typedef std::list<ShopWindow*> DialogList;
172 
174 
178 
190  std::string mAcceptPlayer;
191  std::string mTradeNick;
192  std::string mSellShopName;
194  time_t mAnnonceTime;
205 };
206 
207 extern ShopWindow *shopWindow;
208 
209 #endif // GUI_WINDOWS_SHOPWINDOW_H
Definition: button.h:102
Definition: item.h:50
Button * mAddButton
Definition: shopwindow.h:183
void vendingEnabled(const bool b)
void sendMessage(const std::string &nick, std::string data, const bool random)
Definition: shopwindow.cpp:833
void giveList(const std::string &nick, const int mode)
Definition: shopwindow.cpp:759
int mRandCounter
Definition: shopwindow.h:197
bool mEnableBuyingStore
Definition: shopwindow.h:203
ShopItems * mBuyShopItems
Definition: shopwindow.h:175
Button * mCloseButton
Definition: shopwindow.h:173
static bool isActive()
Definition: shopwindow.h:104
bool findShopItem(const ShopItem *const shopItem, const int mode) const
void updateButtonsAndLabels()
Definition: shopwindow.cpp:439
time_t mLastRequestTimeItem
Definition: shopwindow.h:196
ShopListBox * mCurrentShopItemList
Definition: shopwindow.h:181
void postInit()
Definition: shopwindow.cpp:240
void addSellItem(const Item *const item, const int amount, const int price)
Definition: shopwindow.cpp:529
ShopItems * mSellShopItems
Definition: shopwindow.h:176
time_t mLastRequestTimeList
Definition: shopwindow.h:195
void startTrade()
Definition: shopwindow.cpp:734
void buyingStoreEnabled(const bool b)
ShopItem * mTradeItem
Definition: shopwindow.h:177
void buyingStoreSlotsChanged(const int slots)
int mBuyShopSize
Definition: shopwindow.h:200
ShopListBox * mSellShopItemList
Definition: shopwindow.h:180
static bool checkFloodCounter(time_t &counterTime)
std::string mAcceptPlayer
Definition: shopwindow.h:190
void setItemSelected(const int id)
Definition: shopwindow.h:107
void updateTimes()
void action(const ActionEvent &event)
Definition: shopwindow.cpp:261
TabStrip * mTabs
Definition: shopwindow.h:189
static void showList(const std::string &nick, std::string data)
Definition: shopwindow.cpp:854
static DialogList instances
Definition: shopwindow.h:171
void valueChanged(const SelectionEvent &event)
Definition: shopwindow.cpp:434
Button * mPublishButton
Definition: shopwindow.h:186
bool isShopEmpty() const
std::string mSellShopName
Definition: shopwindow.h:192
bool mEnableVending
Definition: shopwindow.h:204
void announce(ShopItems *const list, const int mode)
Definition: shopwindow.cpp:675
ShopListBox * mBuyShopItemList
Definition: shopwindow.h:179
void processRequest(const std::string &nick, std::string data, const int mode)
Definition: shopwindow.cpp:924
Button * mAnnounceButton
Definition: shopwindow.h:185
bool isBuySelected
Definition: shopwindow.h:201
CheckBox * mAnnounceLinks
Definition: shopwindow.h:188
void loadList()
Definition: shopwindow.cpp:546
time_t mAnnonceTime
Definition: shopwindow.h:194
void updateSelection()
ScrollArea * mScrollArea
Definition: shopwindow.h:182
static int sumAmount(const Item *const shopItem)
Button * mRenameButton
Definition: shopwindow.h:187
void saveList() const
Definition: shopwindow.cpp:609
std::string mTradeNick
Definition: shopwindow.h:191
void vendingSlotsChanged(const int slots)
int mSelectedItem
Definition: shopwindow.h:193
int mTradeMoney
Definition: shopwindow.h:198
bool mHaveVending
Definition: shopwindow.h:202
std::list< ShopWindow * > DialogList
Definition: shopwindow.h:170
const std::string & getAcceptPlayer() const
Definition: shopwindow.h:124
void setVisible(Visible visible)
Definition: shopwindow.cpp:507
Button * mDeleteButton
Definition: shopwindow.h:184
void updateShopName()
int mSellShopSize
Definition: shopwindow.h:199
void addBuyItem(const Item *const item, const int amount, const int price)
Definition: shopwindow.cpp:512
void setAcceptPlayer(const std::string &name)
Definition: shopwindow.h:121
void setShopName(const std::string &name)
Definition: window.h:102
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
uint32_t data
ShopWindow * shopWindow
Definition: shopwindow.cpp:101
bool Visible
Definition: visible.h:30