]> git.lizzy.rs Git - dragonfireclient.git/blob - src/guiInventoryMenu.h
forgot some files
[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_name, s32 a_i)
43                 {
44                         listname = a_name;
45                         i = a_i;
46                 }
47                 bool isValid() const
48                 {
49                         return i != -1;
50                 }
51
52                 std::string listname;
53                 s32 i;
54         };
55
56         struct ListDrawSpec
57         {
58                 ListDrawSpec()
59                 {
60                 }
61                 ListDrawSpec(const std::string &a_name, v2s32 a_pos, v2s32 a_geom)
62                 {
63                         listname = a_name;
64                         pos = a_pos;
65                         geom = a_geom;
66                 }
67
68                 std::string listname;
69                 v2s32 pos;
70                 v2s32 geom;
71         };
72
73 public:
74         GUIInventoryMenu(gui::IGUIEnvironment* env,
75                         gui::IGUIElement* parent, s32 id,
76                         Inventory *inventory,
77                         Queue<InventoryAction*> *actions,
78                         IMenuManager *menumgr);
79         ~GUIInventoryMenu();
80
81         void removeChildren();
82         /*
83                 Remove and re-add (or reposition) stuff
84         */
85         void regenerateGui(v2u32 screensize);
86         
87         ItemSpec getItemAtPos(v2s32 p) const;
88         void drawList(const ListDrawSpec &s);
89         void drawMenu();
90
91         bool OnEvent(const SEvent& event);
92         
93 private:
94         v2s32 getBasePos() const
95         {
96                 return padding + AbsoluteRect.UpperLeftCorner;
97         }
98
99         v2s32 padding;
100         v2s32 spacing;
101         v2s32 imgsize;
102
103         core::array<ListDrawSpec> m_draw_positions;
104
105         Inventory *m_inventory;
106
107         ItemSpec *m_selected_item;
108         Queue<InventoryAction*> *m_actions;
109 };
110
111 #endif
112