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