]> git.lizzy.rs Git - dragonfireclient.git/blob - src/guiInventoryMenu.h
Modified windows build parameters a bit to make it build
[dragonfireclient.git] / src / guiInventoryMenu.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20
21 #ifndef GUIINVENTORYMENU_HEADER
22 #define GUIINVENTORYMENU_HEADER
23
24 #include "common_irrlicht.h"
25 #include "inventory.h"
26 #include "utility.h"
27 #include "modalMenu.h"
28
29 void drawInventoryItem(video::IVideoDriver *driver,
30                 gui::IGUIFont *font,
31                 InventoryItem *item, core::rect<s32> rect,
32                 const core::rect<s32> *clip);
33
34 class GUIInventoryMenu : public GUIModalMenu
35 {
36         struct ItemSpec
37         {
38                 ItemSpec()
39                 {
40                         i = -1;
41                 }
42                 ItemSpec(const std::string &a_inventoryname,
43                                 const std::string &a_listname,
44                                 s32 a_i)
45                 {
46                         inventoryname = a_inventoryname;
47                         listname = a_listname;
48                         i = a_i;
49                 }
50                 bool isValid() const
51                 {
52                         return i != -1;
53                 }
54
55                 std::string inventoryname;
56                 std::string listname;
57                 s32 i;
58         };
59
60         struct ListDrawSpec
61         {
62                 ListDrawSpec()
63                 {
64                 }
65                 ListDrawSpec(const std::string &a_inventoryname,
66                                 const std::string &a_listname,
67                                 v2s32 a_pos, v2s32 a_geom)
68                 {
69                         inventoryname = a_inventoryname;
70                         listname = a_listname;
71                         pos = a_pos;
72                         geom = a_geom;
73                 }
74
75                 std::string inventoryname;
76                 std::string listname;
77                 v2s32 pos;
78                 v2s32 geom;
79         };
80 public:
81         struct DrawSpec
82         {
83                 DrawSpec()
84                 {
85                 }
86                 DrawSpec(const std::string &a_type,
87                                 const std::string &a_name,
88                                 const std::string &a_subname,
89                                 v2s32 a_pos,
90                                 v2s32 a_geom)
91                 {
92                         type = a_type;
93                         name = a_name;
94                         subname = a_subname;
95                         pos = a_pos;
96                         geom = a_geom;
97                 }
98
99                 std::string type;
100                 std::string name;
101                 std::string subname;
102                 v2s32 pos;
103                 v2s32 geom;
104         };
105
106         GUIInventoryMenu(gui::IGUIEnvironment* env,
107                         gui::IGUIElement* parent, s32 id,
108                         IMenuManager *menumgr,
109                         v2s16 menu_size,
110                         core::array<DrawSpec> &init_draw_spec,
111                         InventoryContext *c,
112                         InventoryManager *invmgr
113                         );
114         ~GUIInventoryMenu();
115
116         void removeChildren();
117         /*
118                 Remove and re-add (or reposition) stuff
119         */
120         void regenerateGui(v2u32 screensize);
121         
122         ItemSpec getItemAtPos(v2s32 p) const;
123         void drawList(const ListDrawSpec &s);
124         void drawMenu();
125
126         bool OnEvent(const SEvent& event);
127         
128 private:
129         v2s32 getBasePos() const
130         {
131                 return padding + AbsoluteRect.UpperLeftCorner;
132         }
133
134         v2s16 m_menu_size;
135
136         v2s32 padding;
137         v2s32 spacing;
138         v2s32 imgsize;
139         
140         InventoryContext *m_c;
141         InventoryManager *m_invmgr;
142
143         core::array<DrawSpec> m_init_draw_spec;
144         core::array<ListDrawSpec> m_draw_spec;
145
146         ItemSpec *m_selected_item;
147 };
148
149 #endif
150