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(std::map<std::string, std::string> 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 ImageDrawSpec(const std::string &a_name,
130 v2s32 a_pos, v2s32 a_geom):
137 ImageDrawSpec(const std::string &a_name,
155 FieldSpec(const std::wstring &name, const std::wstring &label,
156 const std::wstring &fdeflt, int id) :
168 std::wstring fdefault;
171 FormspecFieldType ftype;
173 core::rect<s32> rect;
177 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
185 irr::video::SColor color;
192 TooltipSpec(std::string a_tooltip, irr::video::SColor a_bgcolor,
193 irr::video::SColor a_color):
200 irr::video::SColor bgcolor;
201 irr::video::SColor color;
205 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
206 gui::IGUIElement* parent, s32 id,
207 IMenuManager *menumgr,
208 InventoryManager *invmgr,
210 ISimpleTextureSource *tsrc,
218 void setFormSpec(const std::string &formspec_string,
219 InventoryLocation current_inventory_location)
221 m_formspec_string = formspec_string;
222 m_current_inventory_location = current_inventory_location;
223 regenerateGui(m_screensize_old);
226 // form_src is deleted by this GUIFormSpecMenu
227 void setFormSource(IFormSource *form_src)
229 if (m_form_src != NULL) {
232 m_form_src = form_src;
235 // text_dst is deleted by this GUIFormSpecMenu
236 void setTextDest(TextDest *text_dst)
238 if (m_text_dst != NULL) {
241 m_text_dst = text_dst;
244 void allowClose(bool value)
246 m_allowclose = value;
249 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0))
252 m_lockscreensize = basescreensize;
255 void removeChildren();
256 void setInitialFocus();
258 void setFocus(std::wstring elementname)
260 m_focused_element = elementname;
264 Remove and re-add (or reposition) stuff
266 void regenerateGui(v2u32 screensize);
268 ItemSpec getItemAtPos(v2s32 p) const;
269 void drawList(const ListDrawSpec &s, int phase);
270 void drawSelectedItem();
272 void updateSelectedItem();
273 ItemStack verifySelectedItem();
275 void acceptInput(FormspecQuitMode quitmode);
276 bool preprocessEvent(const SEvent& event);
277 bool OnEvent(const SEvent& event);
279 bool pausesGame() { return doPause; }
281 GUITable* getTable(std::wstring tablename);
284 bool getAndroidUIInput();
288 v2s32 getBasePos() const
290 return padding + offset + AbsoluteRect.UpperLeftCorner;
298 irr::IrrlichtDevice* m_device;
299 InventoryManager *m_invmgr;
301 ISimpleTextureSource *m_tsrc;
304 std::string m_formspec_string;
305 InventoryLocation m_current_inventory_location;
308 std::vector<ListDrawSpec> m_inventorylists;
309 std::vector<ImageDrawSpec> m_backgrounds;
310 std::vector<ImageDrawSpec> m_images;
311 std::vector<ImageDrawSpec> m_itemimages;
312 std::vector<BoxDrawSpec> m_boxes;
313 std::vector<FieldSpec> m_fields;
314 std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
315 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
316 std::map<std::wstring, TooltipSpec> m_tooltips;
317 std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
319 ItemSpec *m_selected_item;
320 u32 m_selected_amount;
321 bool m_selected_dragging;
323 // WARNING: BLACK MAGIC
324 // Used to guess and keep up with some special things the server can do.
325 // If name is "", no guess exists.
326 ItemStack m_selected_content_guess;
327 InventoryLocation m_selected_content_guess_inventory;
330 v2s32 m_old_pointer; // Mouse position after previous mouse event
331 gui::IGUIStaticText *m_tooltip_element;
333 u32 m_tooltip_show_delay;
335 s32 m_old_tooltip_id;
336 std::string m_old_tooltip;
338 bool m_rmouse_auto_place;
342 v2u32 m_lockscreensize;
346 bool m_clipbackground;
347 video::SColor m_bgcolor;
348 video::SColor m_slotbg_n;
349 video::SColor m_slotbg_h;
350 video::SColor m_slotbordercolor;
351 video::SColor m_default_tooltip_bgcolor;
352 video::SColor m_default_tooltip_color;
355 IFormSource *m_form_src;
356 TextDest *m_text_dst;
357 unsigned int m_formspec_version;
358 std::wstring m_focused_element;
364 core::rect<s32> rect;
367 std::wstring focused_fieldname;
368 GUITable::TableOptions table_options;
369 GUITable::TableColumns table_columns;
370 // used to restore table selection/scroll/treeview state
371 std::map<std::wstring,GUITable::DynamicData> table_dyndata;
381 fs_key_pendig current_keys_pending;
383 void parseElement(parserData* data,std::string element);
385 void parseSize(parserData* data,std::string element);
386 void parseList(parserData* data,std::string element);
387 void parseCheckbox(parserData* data,std::string element);
388 void parseImage(parserData* data,std::string element);
389 void parseItemImage(parserData* data,std::string element);
390 void parseButton(parserData* data,std::string element,std::string typ);
391 void parseBackground(parserData* data,std::string element);
392 void parseTableOptions(parserData* data,std::string element);
393 void parseTableColumns(parserData* data,std::string element);
394 void parseTable(parserData* data,std::string element);
395 void parseTextList(parserData* data,std::string element);
396 void parseDropDown(parserData* data,std::string element);
397 void parsePwdField(parserData* data,std::string element);
398 void parseField(parserData* data,std::string element,std::string type);
399 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
400 void parseTextArea(parserData* data,std::vector<std::string>& parts,
402 void parseLabel(parserData* data,std::string element);
403 void parseVertLabel(parserData* data,std::string element);
404 void parseImageButton(parserData* data,std::string element,std::string type);
405 void parseItemImageButton(parserData* data,std::string element);
406 void parseTabHeader(parserData* data,std::string element);
407 void parseBox(parserData* data,std::string element);
408 void parseBackgroundColor(parserData* data,std::string element);
409 void parseListColors(parserData* data,std::string element);
410 void parseTooltip(parserData* data,std::string element);
411 bool parseVersionDirect(std::string data);
412 bool parseSizeDirect(parserData* data, std::string element);
413 void parseScrollBar(parserData* data, std::string element);
416 * check if event is part of a double click
417 * @param event event to evaluate
418 * @return true/false if a doubleclick was detected
420 bool DoubleClickDetection(const SEvent event);
427 clickpos m_doubleclickdetect[2];
430 gui::IGUIFont *m_font;
432 std::wstring getLabelByID(s32 id);
433 std::wstring getNameByID(s32 id);
436 std::wstring m_JavaDialogFieldName;
441 class FormspecFormSource: public IFormSource
444 FormspecFormSource(std::string formspec)
446 m_formspec = formspec;
449 ~FormspecFormSource()
452 void setForm(std::string formspec) {
453 m_formspec = FORMSPEC_VERSION_STRING + formspec;
456 std::string getForm()
461 std::string m_formspec;