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 class GUIFormSpecMenu : public GUIModalMenu
68 ItemSpec(const InventoryLocation &a_inventoryloc,
69 const std::string &a_listname,
72 inventoryloc = a_inventoryloc;
73 listname = a_listname;
81 InventoryLocation inventoryloc;
91 ListDrawSpec(const InventoryLocation &a_inventoryloc,
92 const std::string &a_listname,
93 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
94 inventoryloc(a_inventoryloc),
98 start_item_i(a_start_item_i)
102 InventoryLocation inventoryloc;
103 std::string listname;
114 ImageDrawSpec(const std::string &a_name,
115 v2s32 a_pos, v2s32 a_geom):
122 ImageDrawSpec(const std::string &a_name,
140 FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id):
153 std::wstring fdefault;
156 FormspecFieldType ftype;
158 core::rect<s32> rect;
163 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
171 irr::video::SColor color;
175 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
176 gui::IGUIElement* parent, s32 id,
177 IMenuManager *menumgr,
178 InventoryManager *invmgr,
184 void setFormSpec(const std::string &formspec_string,
185 InventoryLocation current_inventory_location)
187 m_formspec_string = formspec_string;
188 m_current_inventory_location = current_inventory_location;
189 regenerateGui(m_screensize_old);
192 // form_src is deleted by this GUIFormSpecMenu
193 void setFormSource(IFormSource *form_src)
195 m_form_src = form_src;
198 // text_dst is deleted by this GUIFormSpecMenu
199 void setTextDest(TextDest *text_dst)
201 m_text_dst = text_dst;
204 void allowClose(bool value)
206 m_allowclose = value;
209 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
211 m_lockscreensize = basescreensize;
214 void removeChildren();
215 void setInitialFocus();
217 Remove and re-add (or reposition) stuff
219 void regenerateGui(v2u32 screensize);
221 ItemSpec getItemAtPos(v2s32 p) const;
222 void drawList(const ListDrawSpec &s, int phase);
223 void drawSelectedItem();
225 void updateSelectedItem();
226 ItemStack verifySelectedItem();
229 bool preprocessEvent(const SEvent& event);
230 bool OnEvent(const SEvent& event);
232 int getListboxIndex(std::string listboxname);
235 v2s32 getBasePos() const
237 return padding + offset + AbsoluteRect.UpperLeftCorner;
245 irr::IrrlichtDevice* m_device;
246 InventoryManager *m_invmgr;
249 std::string m_formspec_string;
250 InventoryLocation m_current_inventory_location;
251 IFormSource *m_form_src;
252 TextDest *m_text_dst;
254 std::vector<ListDrawSpec> m_inventorylists;
255 std::vector<ImageDrawSpec> m_backgrounds;
256 std::vector<ImageDrawSpec> m_images;
257 std::vector<ImageDrawSpec> m_itemimages;
258 std::vector<BoxDrawSpec> m_boxes;
259 std::vector<FieldSpec> m_fields;
260 std::vector<std::pair<FieldSpec,gui::IGUIListBox*> > m_listboxes;
261 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
263 ItemSpec *m_selected_item;
264 u32 m_selected_amount;
265 bool m_selected_dragging;
267 // WARNING: BLACK MAGIC
268 // Used to guess and keep up with some special things the server can do.
269 // If name is "", no guess exists.
270 ItemStack m_selected_content_guess;
271 InventoryLocation m_selected_content_guess_inventory;
273 // WARNING: BLACK IRRLICHT MAGIC, see checkListboxClick()
274 std::wstring m_listbox_click_fname;
275 int m_listbox_click_index;
276 u32 m_listbox_click_time;
277 bool m_listbox_doubleclick;
280 gui::IGUIStaticText *m_tooltip_element;
284 v2u32 m_lockscreensize;
289 core::rect<s32> rect;
293 std::wstring focused_fieldname;
294 std::map<std::wstring,int> listbox_selections;
295 std::map<std::wstring,int> listbox_scroll;
305 std::vector<video::ITexture *> m_Textures;
307 fs_key_pendig current_keys_pending;
309 // Determine whether listbox click was double click
310 // (Using some black Irrlicht magic)
311 bool checkListboxClick(std::wstring wlistboxname, int eventtype);
313 gui::IGUIScrollBar* getListboxScrollbar(gui::IGUIListBox *listbox);
315 void parseElement(parserData* data,std::string element);
317 void parseSize(parserData* data,std::string element);
318 void parseList(parserData* data,std::string element);
319 void parseCheckbox(parserData* data,std::string element);
320 void parseImage(parserData* data,std::string element);
321 void parseItemImage(parserData* data,std::string element);
322 void parseButton(parserData* data,std::string element,std::string typ);
323 void parseBackground(parserData* data,std::string element);
324 void parseTextList(parserData* data,std::string element);
325 void parseDropDown(parserData* data,std::string element);
326 void parsePwdField(parserData* data,std::string element);
327 void parseField(parserData* data,std::string element,std::string type);
328 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
329 void parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type);
330 void parseLabel(parserData* data,std::string element);
331 void parseVertLabel(parserData* data,std::string element);
332 void parseImageButton(parserData* data,std::string element,std::string type);
333 void parseItemImageButton(parserData* data,std::string element);
334 void parseTabHeader(parserData* data,std::string element);
335 void parseBox(parserData* data,std::string element);
337 bool parseColor(std::string color, irr::video::SColor& outcolor);
340 class FormspecFormSource: public IFormSource
343 FormspecFormSource(std::string formspec,FormspecFormSource** game_formspec)
345 m_formspec = formspec;
346 m_game_formspec = game_formspec;
349 ~FormspecFormSource()
351 *m_game_formspec = 0;
354 void setForm(std::string formspec) {
355 m_formspec = formspec;
358 std::string getForm()
363 std::string m_formspec;
364 FormspecFormSource** m_game_formspec;