]> git.lizzy.rs Git - dragonfireclient.git/blob - src/guiInventoryMenu.h
Update Lua API documentation to include minetest.get_modnames()
[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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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 "irrlichttypes_extrabloated.h"
25 #include "inventory.h"
26 #include "inventorymanager.h"
27 #include "modalMenu.h"
28
29 class IGameDef;
30 class InventoryManager;
31
32 class IFormSource
33 {
34 public:
35         virtual ~IFormSource(){}
36         virtual std::string getForm() = 0;
37 };
38
39 void drawItemStack(video::IVideoDriver *driver,
40                 gui::IGUIFont *font,
41                 const ItemStack &item,
42                 const core::rect<s32> &rect,
43                 const core::rect<s32> *clip,
44                 IGameDef *gamedef);
45
46 class GUIInventoryMenu : public GUIModalMenu
47 {
48         struct ItemSpec
49         {
50                 ItemSpec()
51                 {
52                         i = -1;
53                 }
54                 ItemSpec(const InventoryLocation &a_inventoryloc,
55                                 const std::string &a_listname,
56                                 s32 a_i)
57                 {
58                         inventoryloc = a_inventoryloc;
59                         listname = a_listname;
60                         i = a_i;
61                 }
62                 bool isValid() const
63                 {
64                         return i != -1;
65                 }
66
67                 InventoryLocation inventoryloc;
68                 std::string listname;
69                 s32 i;
70         };
71
72         struct ListDrawSpec
73         {
74                 ListDrawSpec()
75                 {
76                 }
77                 ListDrawSpec(const InventoryLocation &a_inventoryloc,
78                                 const std::string &a_listname,
79                                 v2s32 a_pos, v2s32 a_geom):
80                         inventoryloc(a_inventoryloc),
81                         listname(a_listname),
82                         pos(a_pos),
83                         geom(a_geom)
84                 {
85                 }
86
87                 InventoryLocation inventoryloc;
88                 std::string listname;
89                 v2s32 pos;
90                 v2s32 geom;
91         };
92
93         struct ImageDrawSpec
94         {
95                 ImageDrawSpec()
96                 {
97                 }
98                 ImageDrawSpec(const std::string &a_name,
99                                 v2s32 a_pos, v2s32 a_geom):
100                         name(a_name),
101                         pos(a_pos),
102                         geom(a_geom)
103                 {
104                 }
105                 std::string name;
106                 v2s32 pos;
107                 v2s32 geom;
108         };
109
110 public:
111         GUIInventoryMenu(gui::IGUIEnvironment* env,
112                         gui::IGUIElement* parent, s32 id,
113                         IMenuManager *menumgr,
114                         InventoryManager *invmgr,
115                         IGameDef *gamedef
116                         );
117         ~GUIInventoryMenu();
118
119         void setFormSpec(const std::string &formspec_string,
120                         InventoryLocation current_inventory_location)
121         {
122                 m_formspec_string = formspec_string;
123                 m_current_inventory_location = current_inventory_location;
124                 regenerateGui(m_screensize_old);
125         }
126         
127         // form_src is deleted by this GUIInventoryMenu
128         void setFormSource(IFormSource *form_src)
129         {
130                 m_form_src = form_src;
131         }
132
133         void removeChildren();
134         /*
135                 Remove and re-add (or reposition) stuff
136         */
137         void regenerateGui(v2u32 screensize);
138         
139         ItemSpec getItemAtPos(v2s32 p) const;
140         void drawList(const ListDrawSpec &s, int phase);
141         void drawSelectedItem();
142         void drawMenu();
143         void updateSelectedItem();
144
145         bool OnEvent(const SEvent& event);
146         
147 protected:
148         v2s32 getBasePos() const
149         {
150                 return padding + AbsoluteRect.UpperLeftCorner;
151         }
152
153         v2s32 padding;
154         v2s32 spacing;
155         v2s32 imgsize;
156         
157         InventoryManager *m_invmgr;
158         IGameDef *m_gamedef;
159
160         std::string m_formspec_string;
161         InventoryLocation m_current_inventory_location;
162         IFormSource *m_form_src;
163
164         core::array<ListDrawSpec> m_inventorylists;
165         core::array<ImageDrawSpec> m_images;
166
167         ItemSpec *m_selected_item;
168         u32 m_selected_amount;
169         bool m_selected_dragging;
170
171         v2s32 m_pointer;
172         gui::IGUIStaticText *m_tooltip_element;
173 };
174
175 #endif
176