GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/shopwindow.h Lines: 0 2 0.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
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
29
#include "listeners/actionlistener.h"
30
#include "listeners/buyingstoremodelistener.h"
31
#include "listeners/buyingstoreslotslistener.h"
32
#include "listeners/selectionlistener.h"
33
#include "listeners/vendingmodelistener.h"
34
#include "listeners/vendingslotslistener.h"
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
45
/**
46
 * The buy dialog.
47
 *
48
 * \ingroup Interface
49
 */
50
class ShopWindow final : public Window,
51
                         public VendingModeListener,
52
                         public VendingSlotsListener,
53
                         public BuyingStoreModeListener,
54
                         public BuyingStoreSlotsListener,
55
                         public ActionListener,
56
                         public SelectionListener
57
{
58
    public:
59
        enum ShopMode
60
        {
61
            BUY = 0,
62
            SELL = 1
63
        };
64
65
        /**
66
         * Constructor.
67
         *
68
         * @see Window::Window
69
         */
70
        ShopWindow();
71
72
        A_DELETE_COPY(ShopWindow)
73
74
        /**
75
         * Destructor
76
         */
77
        ~ShopWindow() override final;
78
79
        void postInit() override final;
80
81
        /**
82
         * Called when receiving actions from the widgets.
83
         */
84
        void action(const ActionEvent &event) override final;
85
86
        /**
87
         * Updates the labels according to the selected item.
88
         */
89
        void valueChanged(const SelectionEvent &event) override final;
90
91
        /**
92
         * Updates the state of buttons and labels.
93
         */
94
        void updateButtonsAndLabels();
95
96
        /**
97
         * Sets the visibility of this window.
98
         */
99
        void setVisible(Visible visible) override final;
100
101
        /**
102
         * Returns true if any instances exist.
103
         */
104
        static bool isActive() A_WARN_UNUSED
105
        { return !instances.empty(); }
106
107
        void setItemSelected(const int id)
108
        { mSelectedItem = id; updateButtonsAndLabels(); }
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;
171
        static DialogList instances;
172
173
        Button *mCloseButton A_NONNULLPOINTER;
174
175
        ShopItems *mBuyShopItems A_NONNULLPOINTER;
176
        ShopItems *mSellShopItems A_NONNULLPOINTER;
177
        ShopItem *mTradeItem;
178
179
        ShopListBox *mBuyShopItemList A_NONNULLPOINTER;
180
        ShopListBox *mSellShopItemList A_NONNULLPOINTER;
181
        ShopListBox *mCurrentShopItemList;
182
        ScrollArea *mScrollArea A_NONNULLPOINTER;
183
        Button *mAddButton A_NONNULLPOINTER;
184
        Button *mDeleteButton A_NONNULLPOINTER;
185
        Button *mAnnounceButton;
186
        Button *mPublishButton;
187
        Button *mRenameButton;
188
        CheckBox *mAnnounceLinks;
189
        TabStrip *mTabs;
190
        std::string mAcceptPlayer;
191
        std::string mTradeNick;
192
        std::string mSellShopName;
193
        int mSelectedItem;
194
        time_t mAnnonceTime;
195
        time_t mLastRequestTimeList;
196
        time_t mLastRequestTimeItem;
197
        int mRandCounter;
198
        int mTradeMoney;
199
        int mSellShopSize;
200
        int mBuyShopSize;
201
        bool isBuySelected;
202
        bool mHaveVending;
203
        bool mEnableBuyingStore;
204
        bool mEnableVending;
205
};
206
207
extern ShopWindow *shopWindow;
208
209
#endif  // GUI_WINDOWS_SHOPWINDOW_H