3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
21 #ifndef GUIINVENTORYMENU_HEADER
22 #define GUIINVENTORYMENU_HEADER
24 #include "irrlichttypes_extrabloated.h"
25 #include "inventory.h"
26 #include "inventorymanager.h"
27 #include "modalMenu.h"
30 class InventoryManager;
35 virtual ~IFormSource(){}
36 virtual std::string getForm() = 0;
39 void drawItemStack(video::IVideoDriver *driver,
41 const ItemStack &item,
42 const core::rect<s32> &rect,
43 const core::rect<s32> *clip,
46 class GUIInventoryMenu : public GUIModalMenu
54 ItemSpec(const InventoryLocation &a_inventoryloc,
55 const std::string &a_listname,
58 inventoryloc = a_inventoryloc;
59 listname = a_listname;
67 InventoryLocation inventoryloc;
77 ListDrawSpec(const InventoryLocation &a_inventoryloc,
78 const std::string &a_listname,
79 v2s32 a_pos, v2s32 a_geom):
80 inventoryloc(a_inventoryloc),
87 InventoryLocation inventoryloc;
98 ImageDrawSpec(const std::string &a_name,
99 v2s32 a_pos, v2s32 a_geom):
111 GUIInventoryMenu(gui::IGUIEnvironment* env,
112 gui::IGUIElement* parent, s32 id,
113 IMenuManager *menumgr,
114 InventoryManager *invmgr,
119 void setFormSpec(const std::string &formspec_string,
120 InventoryLocation current_inventory_location)
122 m_formspec_string = formspec_string;
123 m_current_inventory_location = current_inventory_location;
124 regenerateGui(m_screensize_old);
127 // form_src is deleted by this GUIInventoryMenu
128 void setFormSource(IFormSource *form_src)
130 m_form_src = form_src;
133 void removeChildren();
135 Remove and re-add (or reposition) stuff
137 void regenerateGui(v2u32 screensize);
139 ItemSpec getItemAtPos(v2s32 p) const;
140 void drawList(const ListDrawSpec &s, int phase);
141 void drawSelectedItem();
143 void updateSelectedItem();
145 bool OnEvent(const SEvent& event);
148 v2s32 getBasePos() const
150 return padding + AbsoluteRect.UpperLeftCorner;
157 InventoryManager *m_invmgr;
160 std::string m_formspec_string;
161 InventoryLocation m_current_inventory_location;
162 IFormSource *m_form_src;
164 core::array<ListDrawSpec> m_inventorylists;
165 core::array<ImageDrawSpec> m_images;
167 ItemSpec *m_selected_item;
168 u32 m_selected_amount;
169 bool m_selected_dragging;
172 gui::IGUIStaticText *m_tooltip_element;