3 Copyright (C) 2013 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;
34 virtual ~TextDest() {};
35 // This is deprecated I guess? -celeron55
36 virtual void gotText(std::wstring text){}
37 virtual void gotText(std::map<std::string, std::string> fields) = 0;
43 virtual ~IFormSource(){}
44 virtual std::string getForm() = 0;
45 // Fill in variables in field text
46 virtual std::string resolveText(std::string str){ return str; }
49 void drawItemStack(video::IVideoDriver *driver,
51 const ItemStack &item,
52 const core::rect<s32> &rect,
53 const core::rect<s32> *clip,
56 class GUIFormSpecMenu : public GUIModalMenu
64 ItemSpec(const InventoryLocation &a_inventoryloc,
65 const std::string &a_listname,
68 inventoryloc = a_inventoryloc;
69 listname = a_listname;
77 InventoryLocation inventoryloc;
87 ListDrawSpec(const InventoryLocation &a_inventoryloc,
88 const std::string &a_listname,
89 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
90 inventoryloc(a_inventoryloc),
94 start_item_i(a_start_item_i)
98 InventoryLocation inventoryloc;
110 ImageDrawSpec(const std::string &a_name,
111 v2s32 a_pos, v2s32 a_geom):
127 FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id):
140 std::wstring fdefault;
145 core::rect<s32> rect;
150 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
151 gui::IGUIElement* parent, s32 id,
152 IMenuManager *menumgr,
153 InventoryManager *invmgr,
158 void setFormSpec(const std::string &formspec_string,
159 InventoryLocation current_inventory_location)
161 m_formspec_string = formspec_string;
162 m_current_inventory_location = current_inventory_location;
163 regenerateGui(m_screensize_old);
166 // form_src is deleted by this GUIFormSpecMenu
167 void setFormSource(IFormSource *form_src)
169 m_form_src = form_src;
172 // text_dst is deleted by this GUIFormSpecMenu
173 void setTextDest(TextDest *text_dst)
175 m_text_dst = text_dst;
178 void removeChildren();
180 Remove and re-add (or reposition) stuff
182 void regenerateGui(v2u32 screensize);
184 ItemSpec getItemAtPos(v2s32 p) const;
185 void drawList(const ListDrawSpec &s, int phase);
186 void drawSelectedItem();
188 void updateSelectedItem();
191 bool OnEvent(const SEvent& event);
194 v2s32 getBasePos() const
196 return padding + AbsoluteRect.UpperLeftCorner;
203 irr::IrrlichtDevice* m_device;
204 InventoryManager *m_invmgr;
207 std::string m_formspec_string;
208 InventoryLocation m_current_inventory_location;
209 IFormSource *m_form_src;
210 TextDest *m_text_dst;
212 std::vector<ListDrawSpec> m_inventorylists;
213 std::vector<ImageDrawSpec> m_backgrounds;
214 std::vector<ImageDrawSpec> m_images;
215 std::vector<ImageDrawSpec> m_itemimages;
216 std::vector<FieldSpec> m_fields;
218 ItemSpec *m_selected_item;
219 u32 m_selected_amount;
220 bool m_selected_dragging;
222 // WARNING: BLACK MAGIC
223 // Used to guess and keep up with some special things the server can do.
224 // If name is "", no guess exists.
225 ItemStack m_selected_content_guess;
226 InventoryLocation m_selected_content_guess_inventory;
229 gui::IGUIStaticText *m_tooltip_element;