]> git.lizzy.rs Git - dragonfireclient.git/blob - src/guiInventoryMenu.h
Add InvRef and InvStack (currently untested and unusable)
[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 class ITextureSource;
30 class InventoryContext;
31 class InventoryManager;
32
33 void drawInventoryItem(video::IVideoDriver *driver,
34                 gui::IGUIFont *font,
35                 InventoryItem *item, core::rect<s32> rect,
36                 const core::rect<s32> *clip,
37                 ITextureSource *tsrc);
38
39 class GUIInventoryMenu : public GUIModalMenu
40 {
41         struct ItemSpec
42         {
43                 ItemSpec()
44                 {
45                         i = -1;
46                 }
47                 ItemSpec(const std::string &a_inventoryname,
48                                 const std::string &a_listname,
49                                 s32 a_i)
50                 {
51                         inventoryname = a_inventoryname;
52                         listname = a_listname;
53                         i = a_i;
54                 }
55                 bool isValid() const
56                 {
57                         return i != -1;
58                 }
59
60                 std::string inventoryname;
61                 std::string listname;
62                 s32 i;
63         };
64
65         struct ListDrawSpec
66         {
67                 ListDrawSpec()
68                 {
69                 }
70                 ListDrawSpec(const std::string &a_inventoryname,
71                                 const std::string &a_listname,
72                                 v2s32 a_pos, v2s32 a_geom)
73                 {
74                         inventoryname = a_inventoryname;
75                         listname = a_listname;
76                         pos = a_pos;
77                         geom = a_geom;
78                 }
79
80                 std::string inventoryname;
81                 std::string listname;
82                 v2s32 pos;
83                 v2s32 geom;
84         };
85 public:
86         struct DrawSpec
87         {
88                 DrawSpec()
89                 {
90                 }
91                 DrawSpec(const std::string &a_type,
92                                 const std::string &a_name,
93                                 const std::string &a_subname,
94                                 v2s32 a_pos,
95                                 v2s32 a_geom)
96                 {
97                         type = a_type;
98                         name = a_name;
99                         subname = a_subname;
100                         pos = a_pos;
101                         geom = a_geom;
102                 }
103
104                 std::string type;
105                 std::string name;
106                 std::string subname;
107                 v2s32 pos;
108                 v2s32 geom;
109         };
110         
111         // See .cpp for format
112         static v2s16 makeDrawSpecArrayFromString(
113                         core::array<GUIInventoryMenu::DrawSpec> &draw_spec,
114                         const std::string &data,
115                         const std::string &current_name);
116
117         GUIInventoryMenu(gui::IGUIEnvironment* env,
118                         gui::IGUIElement* parent, s32 id,
119                         IMenuManager *menumgr,
120                         v2s16 menu_size,
121                         InventoryContext *c,
122                         InventoryManager *invmgr,
123                         ITextureSource *tsrc
124                         );
125         ~GUIInventoryMenu();
126
127         void setDrawSpec(core::array<DrawSpec> &init_draw_spec)
128         {
129                 m_init_draw_spec = init_draw_spec;
130         }
131
132         void removeChildren();
133         /*
134                 Remove and re-add (or reposition) stuff
135         */
136         void regenerateGui(v2u32 screensize);
137         
138         ItemSpec getItemAtPos(v2s32 p) const;
139         void drawList(const ListDrawSpec &s, ITextureSource *tsrc);
140         void drawMenu();
141
142         bool OnEvent(const SEvent& event);
143         
144 protected:
145         v2s32 getBasePos() const
146         {
147                 return padding + AbsoluteRect.UpperLeftCorner;
148         }
149
150         v2s16 m_menu_size;
151
152         v2s32 padding;
153         v2s32 spacing;
154         v2s32 imgsize;
155         
156         InventoryContext *m_c;
157         InventoryManager *m_invmgr;
158         ITextureSource *m_tsrc;
159
160         core::array<DrawSpec> m_init_draw_spec;
161         core::array<ListDrawSpec> m_draw_spec;
162
163         ItemSpec *m_selected_item;
164         v2s32 m_pointer;
165 };
166
167 #endif
168