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 "clientserver.h"
34 class InventoryManager;
35 class ISimpleTextureSource;
55 virtual ~TextDest() {};
56 // This is deprecated I guess? -celeron55
57 virtual void gotText(std::wstring text){}
58 virtual void gotText(std::map<std::string, std::string> fields) = 0;
59 virtual void setFormName(std::string formname)
60 { m_formname = formname;};
62 std::string m_formname;
68 virtual ~IFormSource(){}
69 virtual std::string getForm() = 0;
70 // Fill in variables in field text
71 virtual std::string resolveText(std::string str){ return str; }
74 class GUIFormSpecMenu : public GUIModalMenu
82 ItemSpec(const InventoryLocation &a_inventoryloc,
83 const std::string &a_listname,
86 inventoryloc = a_inventoryloc;
87 listname = a_listname;
95 InventoryLocation inventoryloc;
105 ListDrawSpec(const InventoryLocation &a_inventoryloc,
106 const std::string &a_listname,
107 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
108 inventoryloc(a_inventoryloc),
109 listname(a_listname),
112 start_item_i(a_start_item_i)
116 InventoryLocation inventoryloc;
117 std::string listname;
128 ImageDrawSpec(const std::string &a_name,
129 v2s32 a_pos, v2s32 a_geom):
136 ImageDrawSpec(const std::string &a_name,
154 FieldSpec(const std::wstring &name, const std::wstring &label,
155 const std::wstring &fdeflt, int id) :
167 std::wstring fdefault;
170 FormspecFieldType ftype;
172 core::rect<s32> rect;
176 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
184 irr::video::SColor color;
191 TooltipSpec(std::string a_tooltip, irr::video::SColor a_bgcolor,
192 irr::video::SColor a_color):
199 irr::video::SColor bgcolor;
200 irr::video::SColor color;
204 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
205 gui::IGUIElement* parent, s32 id,
206 IMenuManager *menumgr,
207 InventoryManager *invmgr,
209 ISimpleTextureSource *tsrc,
212 GUIFormSpecMenu** ext_ptr
217 void setFormSpec(const std::string &formspec_string,
218 InventoryLocation current_inventory_location)
220 m_formspec_string = formspec_string;
221 m_current_inventory_location = current_inventory_location;
222 regenerateGui(m_screensize_old);
225 // form_src is deleted by this GUIFormSpecMenu
226 void setFormSource(IFormSource *form_src)
228 if (m_form_src != NULL) {
231 m_form_src = form_src;
234 // text_dst is deleted by this GUIFormSpecMenu
235 void setTextDest(TextDest *text_dst)
237 if (m_text_dst != NULL) {
240 m_text_dst = text_dst;
243 void allowClose(bool value)
245 m_allowclose = value;
248 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
250 m_lockscreensize = basescreensize;
253 void removeChildren();
254 void setInitialFocus();
256 Remove and re-add (or reposition) stuff
258 void regenerateGui(v2u32 screensize);
260 ItemSpec getItemAtPos(v2s32 p) const;
261 void drawList(const ListDrawSpec &s, int phase);
262 void drawSelectedItem();
264 void updateSelectedItem();
265 ItemStack verifySelectedItem();
267 void acceptInput(FormspecQuitMode quitmode);
268 bool preprocessEvent(const SEvent& event);
269 bool OnEvent(const SEvent& event);
271 bool pausesGame() { return doPause; }
273 GUITable* getTable(std::wstring tablename);
275 static bool parseColor(const std::string &value,
276 video::SColor &color, bool quiet);
279 bool getAndroidUIInput();
283 v2s32 getBasePos() const
285 return padding + offset + AbsoluteRect.UpperLeftCorner;
293 irr::IrrlichtDevice* m_device;
294 InventoryManager *m_invmgr;
296 ISimpleTextureSource *m_tsrc;
298 std::string m_formspec_string;
299 InventoryLocation m_current_inventory_location;
301 std::vector<ListDrawSpec> m_inventorylists;
302 std::vector<ImageDrawSpec> m_backgrounds;
303 std::vector<ImageDrawSpec> m_images;
304 std::vector<ImageDrawSpec> m_itemimages;
305 std::vector<BoxDrawSpec> m_boxes;
306 std::vector<FieldSpec> m_fields;
307 std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
308 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
309 std::map<std::wstring, TooltipSpec> m_tooltips;
310 std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
312 ItemSpec *m_selected_item;
313 u32 m_selected_amount;
314 bool m_selected_dragging;
316 // WARNING: BLACK MAGIC
317 // Used to guess and keep up with some special things the server can do.
318 // If name is "", no guess exists.
319 ItemStack m_selected_content_guess;
320 InventoryLocation m_selected_content_guess_inventory;
323 gui::IGUIStaticText *m_tooltip_element;
325 u32 m_tooltip_show_delay;
327 s32 m_old_tooltip_id;
328 std::string m_old_tooltip;
332 v2u32 m_lockscreensize;
336 bool m_clipbackground;
337 video::SColor m_bgcolor;
338 video::SColor m_slotbg_n;
339 video::SColor m_slotbg_h;
340 video::SColor m_slotbordercolor;
341 video::SColor m_default_tooltip_bgcolor;
342 video::SColor m_default_tooltip_color;
345 IFormSource *m_form_src;
346 TextDest *m_text_dst;
347 GUIFormSpecMenu **m_ext_ptr;
348 gui::IGUIFont *m_font;
349 unsigned int m_formspec_version;
353 core::rect<s32> rect;
357 std::wstring focused_fieldname;
358 GUITable::TableOptions table_options;
359 GUITable::TableColumns table_columns;
360 // used to restore table selection/scroll/treeview state
361 std::map<std::wstring,GUITable::DynamicData> table_dyndata;
371 fs_key_pendig current_keys_pending;
373 void parseElement(parserData* data,std::string element);
375 void parseSize(parserData* data,std::string element);
376 void parseList(parserData* data,std::string element);
377 void parseCheckbox(parserData* data,std::string element);
378 void parseImage(parserData* data,std::string element);
379 void parseItemImage(parserData* data,std::string element);
380 void parseButton(parserData* data,std::string element,std::string typ);
381 void parseBackground(parserData* data,std::string element);
382 void parseTableOptions(parserData* data,std::string element);
383 void parseTableColumns(parserData* data,std::string element);
384 void parseTable(parserData* data,std::string element);
385 void parseTextList(parserData* data,std::string element);
386 void parseDropDown(parserData* data,std::string element);
387 void parsePwdField(parserData* data,std::string element);
388 void parseField(parserData* data,std::string element,std::string type);
389 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
390 void parseTextArea(parserData* data,std::vector<std::string>& parts,
392 void parseLabel(parserData* data,std::string element);
393 void parseVertLabel(parserData* data,std::string element);
394 void parseImageButton(parserData* data,std::string element,std::string type);
395 void parseItemImageButton(parserData* data,std::string element);
396 void parseTabHeader(parserData* data,std::string element);
397 void parseBox(parserData* data,std::string element);
398 void parseBackgroundColor(parserData* data,std::string element);
399 void parseListColors(parserData* data,std::string element);
400 void parseTooltip(parserData* data,std::string element);
401 bool parseVersionDirect(std::string data);
402 void parseScrollBar(parserData* data, std::string element);
405 * check if event is part of a double click
406 * @param event event to evaluate
407 * @return true/false if a doubleclick was detected
409 bool DoubleClickDetection(const SEvent event);
416 clickpos m_doubleclickdetect[2];
420 std::wstring getLabelByID(s32 id);
421 std::wstring getNameByID(s32 id);
424 std::wstring m_JavaDialogFieldName;
429 class FormspecFormSource: public IFormSource
432 FormspecFormSource(std::string formspec)
434 m_formspec = formspec;
437 ~FormspecFormSource()
440 void setForm(std::string formspec) {
441 m_formspec = FORMSPEC_VERSION_STRING + formspec;
444 std::string getForm()
449 std::string m_formspec;