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 "common_irrlicht.h"
25 #include "inventory.h"
26 #include "inventorymanager.h"
28 #include "modalMenu.h"
31 class InventoryManager;
36 virtual ~IFormSource(){}
37 virtual std::string getForm() = 0;
40 void drawItemStack(video::IVideoDriver *driver,
42 const ItemStack &item,
43 const core::rect<s32> &rect,
44 const core::rect<s32> *clip,
47 class GUIInventoryMenu : public GUIModalMenu
55 ItemSpec(const InventoryLocation &a_inventoryloc,
56 const std::string &a_listname,
59 inventoryloc = a_inventoryloc;
60 listname = a_listname;
68 InventoryLocation inventoryloc;
78 ListDrawSpec(const InventoryLocation &a_inventoryloc,
79 const std::string &a_listname,
80 v2s32 a_pos, v2s32 a_geom):
81 inventoryloc(a_inventoryloc),
88 InventoryLocation inventoryloc;
99 ImageDrawSpec(const std::string &a_name,
100 v2s32 a_pos, v2s32 a_geom):
112 GUIInventoryMenu(gui::IGUIEnvironment* env,
113 gui::IGUIElement* parent, s32 id,
114 IMenuManager *menumgr,
115 InventoryManager *invmgr,
120 void setFormSpec(const std::string &formspec_string,
121 InventoryLocation current_inventory_location)
123 m_formspec_string = formspec_string;
124 m_current_inventory_location = current_inventory_location;
125 regenerateGui(m_screensize_old);
128 // form_src is deleted by this GUIInventoryMenu
129 void setFormSource(IFormSource *form_src)
131 m_form_src = form_src;
134 void removeChildren();
136 Remove and re-add (or reposition) stuff
138 void regenerateGui(v2u32 screensize);
140 ItemSpec getItemAtPos(v2s32 p) const;
141 void drawList(const ListDrawSpec &s, int phase);
142 void drawSelectedItem();
144 void updateSelectedItem();
146 bool OnEvent(const SEvent& event);
149 v2s32 getBasePos() const
151 return padding + AbsoluteRect.UpperLeftCorner;
158 InventoryManager *m_invmgr;
161 std::string m_formspec_string;
162 InventoryLocation m_current_inventory_location;
163 IFormSource *m_form_src;
165 core::array<ListDrawSpec> m_inventorylists;
166 core::array<ImageDrawSpec> m_images;
168 ItemSpec *m_selected_item;
169 u32 m_selected_amount;
170 bool m_selected_dragging;
173 gui::IGUIStaticText *m_tooltip_element;