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 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.
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.
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.
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;
33 void drawItemStack(video::IVideoDriver *driver,
35 const ItemStack &item,
36 const core::rect<s32> &rect,
37 const core::rect<s32> *clip,
40 class GUIInventoryMenu : public GUIModalMenu
48 ItemSpec(const InventoryLocation &a_inventoryloc,
49 const std::string &a_listname,
52 inventoryloc = a_inventoryloc;
53 listname = a_listname;
61 InventoryLocation inventoryloc;
71 ListDrawSpec(const InventoryLocation &a_inventoryloc,
72 const std::string &a_listname,
73 v2s32 a_pos, v2s32 a_geom)
75 inventoryloc = a_inventoryloc;
76 listname = a_listname;
81 InventoryLocation inventoryloc;
87 GUIInventoryMenu(gui::IGUIEnvironment* env,
88 gui::IGUIElement* parent, s32 id,
89 IMenuManager *menumgr,
90 InventoryManager *invmgr,
95 void setFormSpec(const std::string &formspec_string,
96 InventoryLocation current_inventory_location)
98 m_formspec_string = formspec_string;
99 m_current_inventory_location = current_inventory_location;
100 regenerateGui(m_screensize_old);
103 void removeChildren();
105 Remove and re-add (or reposition) stuff
107 void regenerateGui(v2u32 screensize);
109 ItemSpec getItemAtPos(v2s32 p) const;
110 void drawList(const ListDrawSpec &s, int phase);
111 void drawSelectedItem();
113 void updateSelectedItem();
115 bool OnEvent(const SEvent& event);
118 v2s32 getBasePos() const
120 return padding + AbsoluteRect.UpperLeftCorner;
127 InventoryManager *m_invmgr;
130 std::string m_formspec_string;
131 InventoryLocation m_current_inventory_location;
132 core::array<ListDrawSpec> m_draw_spec;
134 ItemSpec *m_selected_item;
135 u32 m_selected_amount;
136 bool m_selected_dragging;
139 gui::IGUIStaticText *m_tooltip_element;