ManaPlus
equipmentwindow.h
Go to the documentation of this file.
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_EQUIPMENTWINDOW_H
25 #define GUI_WINDOWS_EQUIPMENTWINDOW_H
26 
27 #include "equipment.h"
28 #include "localconsts.h"
29 
30 #include "gui/widgets/window.h"
31 
32 #include "utils/stringmap.h"
33 #include "utils/xml.h"
34 
36 
37 class Being;
38 class Button;
39 class Image;
40 class ImageSet;
41 class Item;
42 class PlayerBox;
43 class TabStrip;
44 
45 struct EquipmentPage;
46 
52 class EquipmentWindow final : public Window,
53  public ActionListener
54 {
55  public:
59  EquipmentWindow(Equipment *const equipment,
60  Being *const being,
61  const bool foring);
62 
64 
65 
68  ~EquipmentWindow() override final;
69 
70  void postInit() override final;
71 
75  void draw(Graphics *const graphics) override final A_NONNULL(2);
76 
77  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
78 
79  void action(const ActionEvent &event) override final;
80 
81  void mousePressed(MouseEvent& event) override final;
82 
83  const Item* getEquipment(const int i) const A_WARN_UNUSED
84  {
85  return mEquipment != nullptr ?
86  mEquipment->getEquipment(i) : nullptr;
87  }
88 
89  void setBeing(Being *const being);
90 
91  void updateBeing(Being *const being);
92 
93  void resetBeing(const Being *const being);
94 
95  void mouseExited(MouseEvent &event) override final;
96 
97  void mouseMoved(MouseEvent &event) override final;
98 
99  void mouseReleased(MouseEvent &event) override final;
100 
101  void recalcSize();
102 
103  static void prepareSlotNames();
104 
105  private:
106  const Item *getItem(const int x, const int y) const A_WARN_UNUSED;
107 
108  void setSelected(const int index);
109 
110  void fillBoxes();
111 
112  void fillDefault();
113 
114  void updatePage();
115 
116  int addPage(const std::string &name);
117 
118  void addDefaultPage();
119 
120  void addBox(const int idx, int x, int y, const int imageIndex);
121 
122  void loadWindow(XmlNodeConstPtrConst windowNode);
123 
124  void loadPage(XmlNodeConstPtr node);
125 
126  void loadPlayerBox(XmlNodeConstPtr playerBoxNode, const int page);
127 
128  void loadSlot(XmlNodeConstPtr slotNode,
129  const ImageSet *const imageset,
130  const int page);
131 
132  static int parseSlotName(const std::string &name) A_WARN_UNUSED;
133 
135 
137 
140 
146  STD_VECTOR<EquipmentPage*> mPages;
152  int mSelected;
154  int mBoxSize;
156  int mMinX;
157  int mMinY;
158  int mMaxX;
159  int mMaxY;
162  bool mForing;
164 };
165 
168 
169 #endif // GUI_WINDOWS_EQUIPMENTWINDOW_H
Definition: being.h:96
Definition: button.h:102
Definition: color.h:76
void setBeing(Being *const being)
ImageSet * mImageSet
ImageCollection * mVertexes
void setSelected(const int index)
std::vector< EquipmentPage * > mPages
const Item * getEquipment(const int i) const
PlayerBox * mPlayerBox
void loadPlayerBox(const xmlNodePtr playerBoxNode, const int page)
void draw(Graphics *const graphics)
static void prepareSlotNames()
static StringIntMap mSlotNames
void mousePressed(MouseEvent &event)
static int parseSlotName(const std::string &name)
Equipment * mEquipment
void loadSlot(const xmlNodePtr slotNode, const ImageSet *const imageset, const int page)
void action(const ActionEvent &event)
Image * mSlotHighlightedBackground
void mouseExited(MouseEvent &event)
EquipmentWindow(Equipment *const equipment, Being *const being, const bool foring)
void safeDraw(Graphics *const graphics)
void resetBeing(const Being *const being)
int addPage(const std::string &name)
void mouseReleased(MouseEvent &event)
const Item * getItem(const int x, const int y) const
void mouseMoved(MouseEvent &event)
void addBox(const int idx, int x, int y, const int imageIndex)
void loadWindow(const xmlNode *const windowNode)
void updateBeing(Being *const being)
void loadPage(const xmlNodePtr node)
const Item * getEquipment(const int index) const
Definition: equipment.h:69
Definition: item.h:50
Definition: window.h:102
EquipmentWindow * equipmentWindow
EquipmentWindow * beingEquipmentWindow
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
std::map< std::string, int > StringIntMap
Definition: stringmap.h:28