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;
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,
213 GUIFormSpecMenu** ext_ptr,
219 void setFormSpec(const std::string &formspec_string,
220 InventoryLocation current_inventory_location)
222 m_formspec_string = formspec_string;
223 m_current_inventory_location = current_inventory_location;
224 regenerateGui(m_screensize_old);
227 // form_src is deleted by this GUIFormSpecMenu
228 void setFormSource(IFormSource *form_src)
230 if (m_form_src != NULL) {
233 m_form_src = form_src;
236 // text_dst is deleted by this GUIFormSpecMenu
237 void setTextDest(TextDest *text_dst)
239 if (m_text_dst != NULL) {
242 m_text_dst = text_dst;
245 void allowClose(bool value)
247 m_allowclose = value;
250 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
252 m_lockscreensize = basescreensize;
255 void removeChildren();
256 void setInitialFocus();
258 Remove and re-add (or reposition) stuff
260 void regenerateGui(v2u32 screensize);
262 ItemSpec getItemAtPos(v2s32 p) const;
263 void drawList(const ListDrawSpec &s, int phase);
264 void drawSelectedItem();
266 void updateSelectedItem();
267 ItemStack verifySelectedItem();
269 void acceptInput(FormspecQuitMode quitmode);
270 bool preprocessEvent(const SEvent& event);
271 bool OnEvent(const SEvent& event);
273 bool pausesGame() { return doPause; }
275 GUITable* getTable(std::wstring tablename);
277 static bool parseColor(const std::string &value,
278 video::SColor &color, bool quiet);
281 bool getAndroidUIInput();
285 v2s32 getBasePos() const
287 return padding + offset + AbsoluteRect.UpperLeftCorner;
295 irr::IrrlichtDevice* m_device;
296 InventoryManager *m_invmgr;
298 ISimpleTextureSource *m_tsrc;
301 std::string m_formspec_string;
302 InventoryLocation m_current_inventory_location;
304 std::vector<ListDrawSpec> m_inventorylists;
305 std::vector<ImageDrawSpec> m_backgrounds;
306 std::vector<ImageDrawSpec> m_images;
307 std::vector<ImageDrawSpec> m_itemimages;
308 std::vector<BoxDrawSpec> m_boxes;
309 std::vector<FieldSpec> m_fields;
310 std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
311 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
312 std::map<std::wstring, TooltipSpec> m_tooltips;
313 std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
315 ItemSpec *m_selected_item;
316 u32 m_selected_amount;
317 bool m_selected_dragging;
319 // WARNING: BLACK MAGIC
320 // Used to guess and keep up with some special things the server can do.
321 // If name is "", no guess exists.
322 ItemStack m_selected_content_guess;
323 InventoryLocation m_selected_content_guess_inventory;
326 gui::IGUIStaticText *m_tooltip_element;
328 u32 m_tooltip_show_delay;
330 s32 m_old_tooltip_id;
331 std::string m_old_tooltip;
335 v2u32 m_lockscreensize;
339 bool m_clipbackground;
340 video::SColor m_bgcolor;
341 video::SColor m_slotbg_n;
342 video::SColor m_slotbg_h;
343 video::SColor m_slotbordercolor;
344 video::SColor m_default_tooltip_bgcolor;
345 video::SColor m_default_tooltip_color;
348 IFormSource *m_form_src;
349 TextDest *m_text_dst;
350 GUIFormSpecMenu **m_ext_ptr;
351 gui::IGUIFont *m_font;
352 unsigned int m_formspec_version;
356 core::rect<s32> rect;
360 std::wstring focused_fieldname;
361 GUITable::TableOptions table_options;
362 GUITable::TableColumns table_columns;
363 // used to restore table selection/scroll/treeview state
364 std::map<std::wstring,GUITable::DynamicData> table_dyndata;
374 fs_key_pendig current_keys_pending;
376 void parseElement(parserData* data,std::string element);
378 void parseSize(parserData* data,std::string element);
379 void parseList(parserData* data,std::string element);
380 void parseCheckbox(parserData* data,std::string element);
381 void parseImage(parserData* data,std::string element);
382 void parseItemImage(parserData* data,std::string element);
383 void parseButton(parserData* data,std::string element,std::string typ);
384 void parseBackground(parserData* data,std::string element);
385 void parseTableOptions(parserData* data,std::string element);
386 void parseTableColumns(parserData* data,std::string element);
387 void parseTable(parserData* data,std::string element);
388 void parseTextList(parserData* data,std::string element);
389 void parseDropDown(parserData* data,std::string element);
390 void parsePwdField(parserData* data,std::string element);
391 void parseField(parserData* data,std::string element,std::string type);
392 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
393 void parseTextArea(parserData* data,std::vector<std::string>& parts,
395 void parseLabel(parserData* data,std::string element);
396 void parseVertLabel(parserData* data,std::string element);
397 void parseImageButton(parserData* data,std::string element,std::string type);
398 void parseItemImageButton(parserData* data,std::string element);
399 void parseTabHeader(parserData* data,std::string element);
400 void parseBox(parserData* data,std::string element);
401 void parseBackgroundColor(parserData* data,std::string element);
402 void parseListColors(parserData* data,std::string element);
403 void parseTooltip(parserData* data,std::string element);
404 bool parseVersionDirect(std::string data);
405 void parseScrollBar(parserData* data, std::string element);
408 * check if event is part of a double click
409 * @param event event to evaluate
410 * @return true/false if a doubleclick was detected
412 bool DoubleClickDetection(const SEvent event);
419 clickpos m_doubleclickdetect[2];
423 std::wstring getLabelByID(s32 id);
424 std::wstring getNameByID(s32 id);
427 std::wstring m_JavaDialogFieldName;
432 class FormspecFormSource: public IFormSource
435 FormspecFormSource(std::string formspec)
437 m_formspec = formspec;
440 ~FormspecFormSource()
443 void setForm(std::string formspec) {
444 m_formspec = FORMSPEC_VERSION_STRING + formspec;
447 std::string getForm()
452 std::string m_formspec;