]> git.lizzy.rs Git - dragonfireclient.git/blob - src/guiInventoryMenu.h
+ paper, book, bookshelf
[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                         InventoryContext *c,
111                         InventoryManager *invmgr
112                         );
113         ~GUIInventoryMenu();
114
115         void setDrawSpec(core::array<DrawSpec> &init_draw_spec)
116         {
117                 m_init_draw_spec = init_draw_spec;
118         }
119
120         void removeChildren();
121         /*
122                 Remove and re-add (or reposition) stuff
123         */
124         void regenerateGui(v2u32 screensize);
125         
126         ItemSpec getItemAtPos(v2s32 p) const;
127         void drawList(const ListDrawSpec &s);
128         void drawMenu();
129
130         bool OnEvent(const SEvent& event);
131         
132 protected:
133         v2s32 getBasePos() const
134         {
135                 return padding + AbsoluteRect.UpperLeftCorner;
136         }
137
138         v2s16 m_menu_size;
139
140         v2s32 padding;
141         v2s32 spacing;
142         v2s32 imgsize;
143         
144         InventoryContext *m_c;
145         InventoryManager *m_invmgr;
146
147         core::array<DrawSpec> m_init_draw_spec;
148         core::array<ListDrawSpec> m_draw_spec;
149
150         ItemSpec *m_selected_item;
151 };
152
153 #endif
154