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,
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)) {
251 m_lockscreensize = basescreensize;
254 void removeChildren();
255 void setInitialFocus();
257 Remove and re-add (or reposition) stuff
259 void regenerateGui(v2u32 screensize);
261 ItemSpec getItemAtPos(v2s32 p) const;
262 void drawList(const ListDrawSpec &s, int phase);
263 void drawSelectedItem();
265 void updateSelectedItem();
266 ItemStack verifySelectedItem();
268 void acceptInput(FormspecQuitMode quitmode);
269 bool preprocessEvent(const SEvent& event);
270 bool OnEvent(const SEvent& event);
272 bool pausesGame() { return doPause; }
274 GUITable* getTable(std::wstring tablename);
277 bool getAndroidUIInput();
281 v2s32 getBasePos() const
283 return padding + offset + AbsoluteRect.UpperLeftCorner;
291 irr::IrrlichtDevice* m_device;
292 InventoryManager *m_invmgr;
294 ISimpleTextureSource *m_tsrc;
297 std::string m_formspec_string;
298 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 v2s32 m_old_pointer; // Mouse position after previous mouse event
324 gui::IGUIStaticText *m_tooltip_element;
326 u32 m_tooltip_show_delay;
328 s32 m_old_tooltip_id;
329 std::string m_old_tooltip;
331 bool m_rmouse_auto_place;
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 unsigned int m_formspec_version;
356 core::rect<s32> rect;
359 std::wstring focused_fieldname;
360 GUITable::TableOptions table_options;
361 GUITable::TableColumns table_columns;
362 // used to restore table selection/scroll/treeview state
363 std::map<std::wstring,GUITable::DynamicData> table_dyndata;
373 fs_key_pendig current_keys_pending;
375 void parseElement(parserData* data,std::string element);
377 void parseSize(parserData* data,std::string element);
378 void parseList(parserData* data,std::string element);
379 void parseCheckbox(parserData* data,std::string element);
380 void parseImage(parserData* data,std::string element);
381 void parseItemImage(parserData* data,std::string element);
382 void parseButton(parserData* data,std::string element,std::string typ);
383 void parseBackground(parserData* data,std::string element);
384 void parseTableOptions(parserData* data,std::string element);
385 void parseTableColumns(parserData* data,std::string element);
386 void parseTable(parserData* data,std::string element);
387 void parseTextList(parserData* data,std::string element);
388 void parseDropDown(parserData* data,std::string element);
389 void parsePwdField(parserData* data,std::string element);
390 void parseField(parserData* data,std::string element,std::string type);
391 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
392 void parseTextArea(parserData* data,std::vector<std::string>& parts,
394 void parseLabel(parserData* data,std::string element);
395 void parseVertLabel(parserData* data,std::string element);
396 void parseImageButton(parserData* data,std::string element,std::string type);
397 void parseItemImageButton(parserData* data,std::string element);
398 void parseTabHeader(parserData* data,std::string element);
399 void parseBox(parserData* data,std::string element);
400 void parseBackgroundColor(parserData* data,std::string element);
401 void parseListColors(parserData* data,std::string element);
402 void parseTooltip(parserData* data,std::string element);
403 bool parseVersionDirect(std::string data);
404 bool parseSizeDirect(parserData* data, std::string element);
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];
422 gui::IGUIFont *m_font;
424 std::wstring getLabelByID(s32 id);
425 std::wstring getNameByID(s32 id);
428 std::wstring m_JavaDialogFieldName;
433 class FormspecFormSource: public IFormSource
436 FormspecFormSource(std::string formspec)
438 m_formspec = formspec;
441 ~FormspecFormSource()
444 void setForm(std::string formspec) {
445 m_formspec = FORMSPEC_VERSION_STRING + formspec;
448 std::string getForm()
453 std::string m_formspec;