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