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
26 #include "irrlichttypes_extrabloated.h"
27 #include "inventory.h"
28 #include "inventorymanager.h"
29 #include "modalMenu.h"
32 class InventoryManager;
45 virtual ~TextDest() {};
46 // This is deprecated I guess? -celeron55
47 virtual void gotText(std::wstring text){}
48 virtual void gotText(std::map<std::string, std::string> fields) = 0;
54 virtual ~IFormSource(){}
55 virtual std::string getForm() = 0;
56 // Fill in variables in field text
57 virtual std::string resolveText(std::string str){ return str; }
60 void drawItemStack(video::IVideoDriver *driver,
62 const ItemStack &item,
63 const core::rect<s32> &rect,
64 const core::rect<s32> *clip,
67 class GUIFormSpecMenu : public GUIModalMenu
75 ItemSpec(const InventoryLocation &a_inventoryloc,
76 const std::string &a_listname,
79 inventoryloc = a_inventoryloc;
80 listname = a_listname;
88 InventoryLocation inventoryloc;
98 ListDrawSpec(const InventoryLocation &a_inventoryloc,
99 const std::string &a_listname,
100 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
101 inventoryloc(a_inventoryloc),
102 listname(a_listname),
105 start_item_i(a_start_item_i)
109 InventoryLocation inventoryloc;
110 std::string listname;
121 ImageDrawSpec(const std::string &a_name,
122 v2s32 a_pos, v2s32 a_geom):
129 ImageDrawSpec(const std::string &a_name,
147 FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id):
160 std::wstring fdefault;
163 FormspecFieldType ftype;
165 core::rect<s32> rect;
170 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
178 irr::video::SColor color;
182 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
183 gui::IGUIElement* parent, s32 id,
184 IMenuManager *menumgr,
185 InventoryManager *invmgr,
191 void setFormSpec(const std::string &formspec_string,
192 InventoryLocation current_inventory_location)
194 m_formspec_string = formspec_string;
195 m_current_inventory_location = current_inventory_location;
196 regenerateGui(m_screensize_old);
199 // form_src is deleted by this GUIFormSpecMenu
200 void setFormSource(IFormSource *form_src)
202 m_form_src = form_src;
205 // text_dst is deleted by this GUIFormSpecMenu
206 void setTextDest(TextDest *text_dst)
208 m_text_dst = text_dst;
211 void allowClose(bool value)
213 m_allowclose = value;
216 void useGettext(bool value) {
217 m_use_gettext = true;
220 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
222 m_lockscreensize = basescreensize;
225 void removeChildren();
227 Remove and re-add (or reposition) stuff
229 void regenerateGui(v2u32 screensize);
231 ItemSpec getItemAtPos(v2s32 p) const;
232 void drawList(const ListDrawSpec &s, int phase);
233 void drawSelectedItem();
235 void updateSelectedItem();
236 ItemStack verifySelectedItem();
238 void acceptInput(int evttype=-1);
239 bool OnEvent(const SEvent& event);
241 int getListboxIndex(std::string listboxname);
244 v2s32 getBasePos() const
246 return padding + offset + AbsoluteRect.UpperLeftCorner;
254 irr::IrrlichtDevice* m_device;
255 InventoryManager *m_invmgr;
258 std::string m_formspec_string;
259 InventoryLocation m_current_inventory_location;
260 IFormSource *m_form_src;
261 TextDest *m_text_dst;
263 std::vector<ListDrawSpec> m_inventorylists;
264 std::vector<ImageDrawSpec> m_backgrounds;
265 std::vector<ImageDrawSpec> m_images;
266 std::vector<ImageDrawSpec> m_itemimages;
267 std::vector<BoxDrawSpec> m_boxes;
268 std::vector<FieldSpec> m_fields;
269 std::vector<std::pair<FieldSpec,gui::IGUIListBox*> > m_listboxes;
270 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
272 ItemSpec *m_selected_item;
273 u32 m_selected_amount;
274 bool m_selected_dragging;
276 // WARNING: BLACK MAGIC
277 // Used to guess and keep up with some special things the server can do.
278 // If name is "", no guess exists.
279 ItemStack m_selected_content_guess;
280 InventoryLocation m_selected_content_guess_inventory;
283 gui::IGUIStaticText *m_tooltip_element;
288 v2u32 m_lockscreensize;
293 core::rect<s32> rect;
297 std::map<std::wstring,int> listbox_selections;
307 std::vector<video::ITexture *> m_Textures;
309 fs_key_pendig current_keys_pending;
311 void parseElement(parserData* data,std::string element);
313 void parseSize(parserData* data,std::string element);
314 void parseList(parserData* data,std::string element);
315 void parseCheckbox(parserData* data,std::string element);
316 void parseImage(parserData* data,std::string element);
317 void parseItemImage(parserData* data,std::string element);
318 void parseButton(parserData* data,std::string element,std::string typ);
319 void parseBackground(parserData* data,std::string element);
320 void parseTextList(parserData* data,std::string element);
321 void parseDropDown(parserData* data,std::string element);
322 void parsePwdField(parserData* data,std::string element);
323 void parseField(parserData* data,std::string element,std::string type);
324 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
325 void parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type);
326 void parseLabel(parserData* data,std::string element);
327 void parseVertLabel(parserData* data,std::string element);
328 void parseImageButton(parserData* data,std::string element,std::string type);
329 void parseItemImageButton(parserData* data,std::string element);
330 void parseTabHeader(parserData* data,std::string element);
331 void parseBox(parserData* data,std::string element);
333 bool parseColor(std::string color, irr::video::SColor& outcolor);
336 class FormspecFormSource: public IFormSource
339 FormspecFormSource(std::string formspec,FormspecFormSource** game_formspec)
341 m_formspec = formspec;
342 m_game_formspec = game_formspec;
345 ~FormspecFormSource()
347 *m_game_formspec = 0;
350 void setForm(std::string formspec) {
351 m_formspec = formspec;
354 std::string getForm()
359 std::string m_formspec;
360 FormspecFormSource** m_game_formspec;