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"
31 #include "network/networkprotocol.h"
34 class InventoryManager;
35 class ISimpleTextureSource;
56 virtual ~TextDest() {};
57 // This is deprecated I guess? -celeron55
58 virtual void gotText(std::wstring text){}
59 virtual void gotText(const StringMap &fields) = 0;
60 virtual void setFormName(std::string formname)
61 { m_formname = formname;};
63 std::string m_formname;
69 virtual ~IFormSource(){}
70 virtual std::string getForm() = 0;
71 // Fill in variables in field text
72 virtual std::string resolveText(std::string str){ return str; }
75 class GUIFormSpecMenu : public GUIModalMenu
83 ItemSpec(const InventoryLocation &a_inventoryloc,
84 const std::string &a_listname,
87 inventoryloc = a_inventoryloc;
88 listname = a_listname;
96 InventoryLocation inventoryloc;
106 ListDrawSpec(const InventoryLocation &a_inventoryloc,
107 const std::string &a_listname,
108 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
109 inventoryloc(a_inventoryloc),
110 listname(a_listname),
113 start_item_i(a_start_item_i)
117 InventoryLocation inventoryloc;
118 std::string listname;
129 ListRingSpec(const InventoryLocation &a_inventoryloc,
130 const std::string &a_listname):
131 inventoryloc(a_inventoryloc),
136 InventoryLocation inventoryloc;
137 std::string listname;
145 ImageDrawSpec(const std::string &a_name,
146 const std::string &a_item_name,
147 const v2s32 &a_pos, const v2s32 &a_geom):
149 item_name (a_item_name),
155 ImageDrawSpec(const std::string &a_name,
156 const v2s32 &a_pos, const v2s32 &a_geom):
163 ImageDrawSpec(const std::string &a_name,
171 std::string item_name;
182 FieldSpec(const std::string &name, const std::wstring &label,
183 const std::wstring &fdeflt, int id) :
195 std::wstring fdefault;
198 FormspecFieldType ftype;
200 core::rect<s32> rect;
204 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
212 irr::video::SColor color;
219 TooltipSpec(std::string a_tooltip, irr::video::SColor a_bgcolor,
220 irr::video::SColor a_color):
227 irr::video::SColor bgcolor;
228 irr::video::SColor color;
232 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
233 gui::IGUIElement* parent, s32 id,
234 IMenuManager *menumgr,
235 InventoryManager *invmgr,
237 ISimpleTextureSource *tsrc,
241 bool remap_dbl_click = true);
245 void setFormSpec(const std::string &formspec_string,
246 InventoryLocation current_inventory_location)
248 m_formspec_string = formspec_string;
249 m_current_inventory_location = current_inventory_location;
250 regenerateGui(m_screensize_old);
253 // form_src is deleted by this GUIFormSpecMenu
254 void setFormSource(IFormSource *form_src)
256 if (m_form_src != NULL) {
259 m_form_src = form_src;
262 // text_dst is deleted by this GUIFormSpecMenu
263 void setTextDest(TextDest *text_dst)
265 if (m_text_dst != NULL) {
268 m_text_dst = text_dst;
271 void allowClose(bool value)
273 m_allowclose = value;
276 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0))
279 m_lockscreensize = basescreensize;
282 void removeChildren();
283 void setInitialFocus();
285 void setFocus(std::string &elementname)
287 m_focused_element = elementname;
291 Remove and re-add (or reposition) stuff
293 void regenerateGui(v2u32 screensize);
295 ItemSpec getItemAtPos(v2s32 p) const;
296 void drawList(const ListDrawSpec &s, int phase, bool &item_hovered);
297 void drawSelectedItem();
299 void updateSelectedItem();
300 ItemStack verifySelectedItem();
302 void acceptInput(FormspecQuitMode quitmode);
303 bool preprocessEvent(const SEvent& event);
304 bool OnEvent(const SEvent& event);
306 bool pausesGame() { return doPause; }
308 GUITable* getTable(const std::string &tablename);
311 bool getAndroidUIInput();
315 v2s32 getBasePos() const
317 return padding + offset + AbsoluteRect.UpperLeftCorner;
325 irr::IrrlichtDevice* m_device;
326 InventoryManager *m_invmgr;
328 ISimpleTextureSource *m_tsrc;
331 std::string m_formspec_string;
332 InventoryLocation m_current_inventory_location;
335 std::vector<ListDrawSpec> m_inventorylists;
336 std::vector<ListRingSpec> m_inventory_rings;
337 std::vector<ImageDrawSpec> m_backgrounds;
338 std::vector<ImageDrawSpec> m_images;
339 std::vector<ImageDrawSpec> m_itemimages;
340 std::vector<BoxDrawSpec> m_boxes;
341 std::vector<FieldSpec> m_fields;
342 std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
343 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
344 std::map<std::string, TooltipSpec> m_tooltips;
345 std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
347 ItemSpec *m_selected_item;
350 u32 m_selected_amount;
351 bool m_selected_dragging;
353 // WARNING: BLACK MAGIC
354 // Used to guess and keep up with some special things the server can do.
355 // If name is "", no guess exists.
356 ItemStack m_selected_content_guess;
357 InventoryLocation m_selected_content_guess_inventory;
360 v2s32 m_old_pointer; // Mouse position after previous mouse event
361 gui::IGUIStaticText *m_tooltip_element;
363 u32 m_tooltip_show_delay;
365 s32 m_old_tooltip_id;
366 std::string m_old_tooltip;
368 bool m_rmouse_auto_place;
372 v2u32 m_lockscreensize;
376 bool m_clipbackground;
377 video::SColor m_bgcolor;
378 video::SColor m_slotbg_n;
379 video::SColor m_slotbg_h;
380 video::SColor m_slotbordercolor;
381 video::SColor m_default_tooltip_bgcolor;
382 video::SColor m_default_tooltip_color;
385 IFormSource *m_form_src;
386 TextDest *m_text_dst;
387 unsigned int m_formspec_version;
388 std::string m_focused_element;
389 bool m_selection_active;
395 core::rect<s32> rect;
398 std::string focused_fieldname;
399 GUITable::TableOptions table_options;
400 GUITable::TableColumns table_columns;
401 // used to restore table selection/scroll/treeview state
402 std::map<std::string, GUITable::DynamicData> table_dyndata;
412 fs_key_pendig current_keys_pending;
414 void parseElement(parserData* data,std::string element);
416 void parseSize(parserData* data,std::string element);
417 void parseList(parserData* data,std::string element);
418 void parseListRing(parserData* data,std::string element);
419 void parseCheckbox(parserData* data,std::string element);
420 void parseImage(parserData* data,std::string element);
421 void parseItemImage(parserData* data,std::string element);
422 void parseButton(parserData* data,std::string element,std::string typ);
423 void parseBackground(parserData* data,std::string element);
424 void parseTableOptions(parserData* data,std::string element);
425 void parseTableColumns(parserData* data,std::string element);
426 void parseTable(parserData* data,std::string element);
427 void parseTextList(parserData* data,std::string element);
428 void parseDropDown(parserData* data,std::string element);
429 void parsePwdField(parserData* data,std::string element);
430 void parseField(parserData* data,std::string element,std::string type);
431 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
432 void parseTextArea(parserData* data,std::vector<std::string>& parts,
434 void parseLabel(parserData* data,std::string element);
435 void parseVertLabel(parserData* data,std::string element);
436 void parseImageButton(parserData* data,std::string element,std::string type);
437 void parseItemImageButton(parserData* data,std::string element);
438 void parseTabHeader(parserData* data,std::string element);
439 void parseBox(parserData* data,std::string element);
440 void parseBackgroundColor(parserData* data,std::string element);
441 void parseListColors(parserData* data,std::string element);
442 void parseTooltip(parserData* data,std::string element);
443 bool parseVersionDirect(std::string data);
444 bool parseSizeDirect(parserData* data, std::string element);
445 void parseScrollBar(parserData* data, std::string element);
448 * check if event is part of a double click
449 * @param event event to evaluate
450 * @return true/false if a doubleclick was detected
452 bool DoubleClickDetection(const SEvent event);
459 clickpos m_doubleclickdetect[2];
462 gui::IGUIFont *m_font;
464 std::wstring getLabelByID(s32 id);
465 std::string getNameByID(s32 id);
468 std::string m_JavaDialogFieldName;
471 /* If true, remap a double-click (or double-tap) action to ESC. This is so
472 * that, for example, Android users can double-tap to close a formspec.
474 * This value can (currently) only be set by the class constructor
475 * and the default value for the setting is true.
477 bool m_remap_dbl_click;
481 class FormspecFormSource: public IFormSource
484 FormspecFormSource(std::string formspec)
486 m_formspec = formspec;
489 ~FormspecFormSource()
492 void setForm(std::string formspec) {
493 m_formspec = FORMSPEC_VERSION_STRING + formspec;
496 std::string getForm()
501 std::string m_formspec;