GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/tradewindow.h Lines: 0 1 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_TRADEWINDOW_H
24
#define GUI_WINDOWS_TRADEWINDOW_H
25
26
#include "gui/widgets/window.h"
27
28
#include "enums/resources/item/itemtype.h"
29
30
#include "enums/simpletypes/damaged.h"
31
#include "enums/simpletypes/equipm.h"
32
#include "enums/simpletypes/favorite.h"
33
#include "enums/simpletypes/identified.h"
34
#include "enums/simpletypes/itemcolor.h"
35
36
#include "listeners/actionlistener.h"
37
#include "listeners/selectionlistener.h"
38
39
class Button;
40
class Inventory;
41
class Item;
42
class ItemContainer;
43
class Label;
44
class TextField;
45
46
struct ItemOptionsList;
47
48
/**
49
 * Trade dialog.
50
 *
51
 * \ingroup Interface
52
 */
53
class TradeWindow final : public Window,
54
                          private ActionListener,
55
                          private SelectionListener
56
{
57
    public:
58
        /**
59
         * Constructor.
60
         */
61
        TradeWindow();
62
63
        A_DELETE_COPY(TradeWindow)
64
65
        /**
66
         * Destructor.
67
         */
68
        ~TradeWindow();
69
70
        /**
71
         * Displays expected money in the trade window.
72
         */
73
        void setMoney(const int quantity);
74
75
        /**
76
         * Add an item to the trade window.
77
         */
78
        void addItem(const int id,
79
                     const ItemTypeT type,
80
                     const bool own,
81
                     const int quantity,
82
                     const uint8_t refine,
83
                     const ItemColor color,
84
                     const Identified identified,
85
                     const Damaged damaged,
86
                     const Favorite favorite) const;
87
88
        /**
89
         * Reset both item containers
90
         */
91
        void reset();
92
93
        /**
94
         * Add an item to the trade window.
95
         */
96
        void addItem2(const int id,
97
                      const ItemTypeT type,
98
                      const int *const cards,
99
                      const ItemOptionsList *const options,
100
                      const int sz,
101
                      const bool own,
102
                      const int quantity,
103
                      const uint8_t refine,
104
                      const ItemColor color,
105
                      const Identified identified,
106
                      const Damaged damaged,
107
                      const Favorite favorite,
108
                      const Equipm equipment) const;
109
110
        /**
111
         * Change quantity of an item.
112
         */
113
        void changeQuantity(const int index, const bool own,
114
                            const int quantity) const;
115
116
        /**
117
         * Increase quantity of an item.
118
         */
119
        void increaseQuantity(const int index, const bool own,
120
                              const int quantity) const;
121
122
        /**
123
         * Player received ok message from server
124
         */
125
        void receivedOk(const bool own);
126
127
        /**
128
         * Send trade packet.
129
         */
130
        void tradeItem(const Item *const item,
131
                       const int quantity,
132
                       const bool check = false) const;
133
134
        /**
135
         * Updates the labels and makes sure only one item is selected in
136
         * either my inventory or partner inventory.
137
         */
138
        void valueChanged(const SelectionEvent &event) override final;
139
140
        /**
141
         * Called when receiving actions from the widgets.
142
         */
143
        void action(const ActionEvent &event) override final;
144
145
        /**
146
         * Closes the Trade Window, as well as telling the server that the
147
         * window has been closed.
148
         */
149
        void close() override final;
150
151
        /**
152
         * Clear auto trade items.
153
         */
154
        void clear() override final;
155
156
        /**
157
         * Add item what will be added to trade.
158
         */
159
        void addAutoItem(const std::string &nick, Item *const item,
160
                         const int amount);
161
162
        void addAutoMoney(const std::string &nick, const int money);
163
164
        void initTrade(const std::string &nick);
165
166
        std::string getAutoTradeNick() const noexcept2 A_WARN_UNUSED
167
        { return mAutoAddToNick; }
168
169
        bool checkItem(const Item *const item) const A_WARN_UNUSED;
170
171
        bool isInpupFocused() const A_WARN_UNUSED;
172
173
        void completeTrade();
174
175
    private:
176
        enum Status
177
        {
178
            PREPARING = 0, /**< Players are adding items. (1) */
179
            PROPOSING, /**< Local player has confirmed the trade. (1) */
180
            ACCEPTING, /**< Accepting the trade. (2) */
181
            ACCEPTED  /**< Local player has accepted the trade. */
182
        };
183
184
        /**
185
         * Sets the current status of the trade.
186
         */
187
        void setStatus(const Status s);
188
189
        Inventory *mMyInventory A_NONNULLPOINTER;
190
        Inventory *mPartnerInventory A_NONNULLPOINTER;
191
192
        ItemContainer *mMyItemContainer A_NONNULLPOINTER;
193
        ItemContainer *mPartnerItemContainer A_NONNULLPOINTER;
194
195
        Label *mMoneyLabel A_NONNULLPOINTER;
196
        Button *mAddButton A_NONNULLPOINTER;
197
        Button *mOkButton A_NONNULLPOINTER;
198
        Button  *mMoneyChangeButton A_NONNULLPOINTER;
199
        TextField *mMoneyField A_NONNULLPOINTER;
200
201
        Item* mAutoAddItem;
202
        std::string mAutoAddToNick;
203
        int mGotMoney;
204
        int mGotMaxMoney;
205
        int mAutoMoney;
206
        int mAutoAddAmount;
207
        Status mStatus;
208
        bool mOkOther;
209
        bool mOkMe;
210
};
211
212
extern TradeWindow *tradeWindow;
213
214
#endif  // GUI_WINDOWS_TRADEWINDOW_H