GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/shopwindow.h Lines: 0 2 0.0 %
Date: 2017-11-29 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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef GUI_WINDOWS_SHOPWINDOW_H
24
#define GUI_WINDOWS_SHOPWINDOW_H
25
26
#include "gui/widgets/window.h"
27
28
#include "listeners/actionlistener.h"
29
#include "listeners/buyingstoremodelistener.h"
30
#include "listeners/buyingstoreslotslistener.h"
31
#include "listeners/selectionlistener.h"
32
#include "listeners/vendingmodelistener.h"
33
#include "listeners/vendingslotslistener.h"
34
35
class Button;
36
class CheckBox;
37
class Item;
38
class ScrollArea;
39
class ShopItem;
40
class ShopItems;
41
class ShopListBox;
42
class TabStrip;
43
44
/**
45
 * The buy dialog.
46
 *
47
 * \ingroup Interface
48
 */
49
class ShopWindow final : public Window,
50
                         public VendingModeListener,
51
                         public VendingSlotsListener,
52
                         public BuyingStoreModeListener,
53
                         public BuyingStoreSlotsListener,
54
                         public ActionListener,
55
                         public SelectionListener
56
{
57
    public:
58
        enum ShopMode
59
        {
60
            BUY = 0,
61
            SELL = 1
62
        };
63
64
        /**
65
         * Constructor.
66
         *
67
         * @see Window::Window
68
         */
69
        ShopWindow();
70
71
        A_DELETE_COPY(ShopWindow)
72
73
        /**
74
         * Destructor
75
         */
76
        ~ShopWindow();
77
78
        void postInit() override final;
79
80
        /**
81
         * Called when receiving actions from the widgets.
82
         */
83
        void action(const ActionEvent &event) override final;
84
85
        /**
86
         * Updates the labels according to the selected item.
87
         */
88
        void valueChanged(const SelectionEvent &event) override final;
89
90
        /**
91
         * Updates the state of buttons and labels.
92
         */
93
        void updateButtonsAndLabels();
94
95
        /**
96
         * Sets the visibility of this window.
97
         */
98
        void setVisible(Visible visible) override final;
99
100
        /**
101
         * Returns true if any instances exist.
102
         */
103
        static bool isActive() A_WARN_UNUSED
104
        { return !instances.empty(); }
105
106
        void setItemSelected(const int id)
107
        { mSelectedItem = id; updateButtonsAndLabels(); }
108
109
        void addBuyItem(const Item *const item, const int amount,
110
                        const int price);
111
112
        void addSellItem(const Item *const item, const int amount,
113
                         const int price);
114
115
        void loadList();
116
117
        void saveList() const;
118
119
#ifdef TMWA_SUPPORT
120
        void setAcceptPlayer(const std::string &name)
121
        { mAcceptPlayer = name; }
122
123
        const std::string &getAcceptPlayer() const noexcept2 A_WARN_UNUSED
124
        { return mAcceptPlayer; }
125
126
        void announce(ShopItems *const list, const int mode);
127
128
        void giveList(const std::string &nick, const int mode);
129
130
        void sendMessage(const std::string &nick, std::string data,
131
                         const bool random = false);
132
133
        static void showList(const std::string &nick, std::string data);
134
135
        void processRequest(const std::string &nick, std::string data,
136
                            const int mode);
137
        void updateTimes();
138
139
        static bool checkFloodCounter(time_t &counterTime) A_WARN_UNUSED;
140
141
        bool findShopItem(const ShopItem *const shopItem,
142
                          const int mode) const A_WARN_UNUSED;
143
#endif  // TMWA_SUPPORT
144
145
        static int sumAmount(const Item *const shopItem) A_WARN_UNUSED;
146
147
        bool isShopEmpty() const A_WARN_UNUSED;
148
149
        void vendingEnabled(const bool b) override final;
150
151
        void vendingSlotsChanged(const int slots) override final;
152
153
        void buyingStoreEnabled(const bool b) override final;
154
155
        void buyingStoreSlotsChanged(const int slots) override final;
156
157
        void setShopName(const std::string &name);
158
159
    private:
160
#ifdef TMWA_SUPPORT
161
        void startTrade();
162
#endif  // TMWA_SUPPORT
163
164
        void updateSelection();
165
166
        void updateShopName();
167
168
        typedef std::list<ShopWindow*> DialogList;
169
        static DialogList instances;
170
171
        Button *mCloseButton A_NONNULLPOINTER;
172
173
        ShopItems *mBuyShopItems A_NONNULLPOINTER;
174
        ShopItems *mSellShopItems A_NONNULLPOINTER;
175
        ShopItem *mTradeItem;
176
177
        ShopListBox *mBuyShopItemList A_NONNULLPOINTER;
178
        ShopListBox *mSellShopItemList A_NONNULLPOINTER;
179
        ShopListBox *mCurrentShopItemList;
180
        ScrollArea *mScrollArea A_NONNULLPOINTER;
181
        Button *mAddButton A_NONNULLPOINTER;
182
        Button *mDeleteButton A_NONNULLPOINTER;
183
        Button *mAnnounceButton;
184
        Button *mPublishButton;
185
        Button *mRenameButton;
186
        CheckBox *mAnnounceLinks;
187
        TabStrip *mTabs;
188
        std::string mAcceptPlayer;
189
        std::string mTradeNick;
190
        std::string mSellShopName;
191
        int mSelectedItem;
192
        time_t mAnnonceTime;
193
        time_t mLastRequestTimeList;
194
        time_t mLastRequestTimeItem;
195
        int mRandCounter;
196
        int mTradeMoney;
197
        int mSellShopSize;
198
        int mBuyShopSize;
199
        bool isBuySelected;
200
        bool mHaveVending;
201
        bool mEnableBuyingStore;
202
        bool mEnableVending;
203
};
204
205
extern ShopWindow *shopWindow;
206
207
#endif  // GUI_WINDOWS_SHOPWINDOW_H