GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/selldialog.h Lines: 2 3 66.7 %
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_WIDGETS_SELLDIALOG_H
24
#define GUI_WIDGETS_SELLDIALOG_H
25
26
#include "enums/resources/item/itemtype.h"
27
28
#include "enums/simpletypes/advanced.h"
29
#include "enums/simpletypes/issell.h"
30
#include "enums/simpletypes/itemcolor.h"
31
32
#include "gui/widgets/window.h"
33
34
#include "listeners/actionlistener.h"
35
#include "listeners/selectionlistener.h"
36
37
class Button;
38
class Item;
39
class Label;
40
class ScrollArea;
41
class ShopItem;
42
class ShopItems;
43
class ShopListBox;
44
class Slider;
45
46
/**
47
 * The sell dialog.
48
 *
49
 * \ingroup Interface
50
 */
51
class SellDialog notfinal : public Window,
52
                            public ActionListener,
53
                            private SelectionListener
54
{
55
    public:
56
        /**
57
         * Constructor.
58
         */
59
        SellDialog(const IsSell isSell,
60
                   const Advanced advanced);
61
62
        A_DELETE_COPY(SellDialog)
63
64
        /**
65
         * Destructor
66
         */
67
        ~SellDialog();
68
69
        /**
70
         * Resets the dialog, clearing inventory.
71
         */
72
        void reset();
73
74
        /**
75
         * Adds an item to the inventory.
76
         */
77
        void addItem(const Item *const item,
78
                     const int price);
79
80
        /**
81
         * Called when receiving actions from the widgets.
82
         */
83
        void action(const ActionEvent &event) override final;
84
85
        /**
86
         * Updates labels according to selected item.
87
         *
88
         * @see SelectionListener::selectionChanged
89
         */
90
        void valueChanged(const SelectionEvent &event) override final;
91
92
        /**
93
         * Gives Player's Money amount
94
         */
95
        void setMoney(const int amount);
96
97
        /**
98
         * Sets the visibility of this window.
99
         */
100
        void setVisible(Visible visible) override final;
101
102
        ShopItem *addItem(const int id,
103
                          const ItemTypeT type,
104
                          const ItemColor color,
105
                          const int amount,
106
                          const int price);
107
108
        /**
109
         * Returns true if any instances exist.
110
         */
111
        static bool isActive() A_WARN_UNUSED
112
        { return !instances.empty(); }
113
114
        /**
115
         * Closes all instances.
116
         */
117
        static void closeAll();
118
119
        void postInit() override;
120
121
    protected:
122
        typedef std::list<SellDialog*> DialogList;
123
        static DialogList instances;
124
125
        /**
126
         * Updates the state of buttons and labels.
127
         */
128
        void updateButtonsAndLabels();
129
130
        virtual void sellAction(const ActionEvent &event) = 0;
131
132
4
        virtual void initButtons()
133
4
        { }
134
135
        Button *mSellButton A_NONNULLPOINTER;
136
        Button *mQuitButton A_NONNULLPOINTER;
137
        Button *mConfirmButton A_NONNULLPOINTER;
138
        Button *mAddMaxButton;
139
        Button *mIncreaseButton;
140
        Button *mDecreaseButton;
141
        ShopListBox *mShopItemList A_NONNULLPOINTER;
142
        ScrollArea *mScrollArea A_NONNULLPOINTER;
143
        Label *mMoneyLabel;
144
        Label *mQuantityLabel;
145
        Slider *mSlider;
146
        ShopItems *mShopItems A_NONNULLPOINTER;
147
148
        int mPlayerMoney;
149
        int mMaxItems;
150
        int mAmountItems;
151
152
        IsSell mIsSell;
153
        Advanced mAdvanced;
154
};
155
156
#endif  // GUI_WIDGETS_SELLDIALOG_H