b6766484ebf69f835e50c5de3fcd48e8720c904e
[oweals/minetest.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(gui::IGUIEnvironment* env,
30                 InventoryItem *item, core::rect<s32> rect,
31                 const core::rect<s32> *clip=0);
32
33 class GUIInventoryMenu : public GUIModalMenu
34 {
35         struct ItemSpec
36         {
37                 ItemSpec()
38                 {
39                         i = -1;
40                 }
41                 ItemSpec(const std::string &a_name, s32 a_i)
42                 {
43                         listname = a_name;
44                         i = a_i;
45                 }
46                 bool isValid() const
47                 {
48                         return i != -1;
49                 }
50
51                 std::string listname;
52                 s32 i;
53         };
54
55         struct ListDrawSpec
56         {
57                 ListDrawSpec()
58                 {
59                 }
60                 ListDrawSpec(const std::string &a_name, v2s32 a_pos, v2s32 a_geom)
61                 {
62                         listname = a_name;
63                         pos = a_pos;
64                         geom = a_geom;
65                 }
66
67                 std::string listname;
68                 v2s32 pos;
69                 v2s32 geom;
70         };
71
72 public:
73         GUIInventoryMenu(gui::IGUIEnvironment* env,
74                         gui::IGUIElement* parent, s32 id,
75                         Inventory *inventory,
76                         Queue<InventoryAction*> *actions,
77                         int *active_menu_count);
78         ~GUIInventoryMenu();
79
80         /*
81                 Remove and re-add (or reposition) stuff
82         */
83         void regenerateGui(v2u32 screensize);
84         
85         ItemSpec getItemAtPos(v2s32 p) const;
86         void drawList(const ListDrawSpec &s);
87         void drawMenu();
88
89         bool OnEvent(const SEvent& event);
90         
91 private:
92         v2s32 getBasePos() const
93         {
94                 return padding + AbsoluteRect.UpperLeftCorner;
95         }
96
97         v2s32 padding;
98         v2s32 spacing;
99         v2s32 imgsize;
100
101         core::array<ListDrawSpec> m_draw_positions;
102
103         Inventory *m_inventory;
104
105         ItemSpec *m_selected_item;
106         Queue<InventoryAction*> *m_actions;
107 };
108
109 #endif
110