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"
33 class InventoryManager;
34 class ISimpleTextureSource;
53 virtual ~TextDest() {};
54 // This is deprecated I guess? -celeron55
55 virtual void gotText(std::wstring text){}
56 virtual void gotText(std::map<std::string, std::string> fields) = 0;
57 virtual void setFormName(std::string formname)
58 { m_formname = formname;};
60 std::string m_formname;
66 virtual ~IFormSource(){}
67 virtual std::string getForm() = 0;
68 // Fill in variables in field text
69 virtual std::string resolveText(std::string str){ return str; }
72 class GUIFormSpecMenu : public GUIModalMenu
80 ItemSpec(const InventoryLocation &a_inventoryloc,
81 const std::string &a_listname,
84 inventoryloc = a_inventoryloc;
85 listname = a_listname;
93 InventoryLocation inventoryloc;
103 ListDrawSpec(const InventoryLocation &a_inventoryloc,
104 const std::string &a_listname,
105 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
106 inventoryloc(a_inventoryloc),
107 listname(a_listname),
110 start_item_i(a_start_item_i)
114 InventoryLocation inventoryloc;
115 std::string listname;
126 ImageDrawSpec(const std::string &a_name,
127 v2s32 a_pos, v2s32 a_geom):
134 ImageDrawSpec(const std::string &a_name,
152 FieldSpec(const std::wstring &name, const std::wstring &label,
153 const std::wstring &fdeflt, int id) :
166 std::wstring fdefault;
169 FormspecFieldType ftype;
171 core::rect<s32> rect;
176 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
184 irr::video::SColor color;
188 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
189 gui::IGUIElement* parent, s32 id,
190 IMenuManager *menumgr,
191 InventoryManager *invmgr,
193 ISimpleTextureSource *tsrc,
196 GUIFormSpecMenu** ext_ptr
201 void setFormSpec(const std::string &formspec_string,
202 InventoryLocation current_inventory_location)
204 m_formspec_string = formspec_string;
205 m_current_inventory_location = current_inventory_location;
206 regenerateGui(m_screensize_old);
209 // form_src is deleted by this GUIFormSpecMenu
210 void setFormSource(IFormSource *form_src)
212 if (m_form_src != NULL) {
215 m_form_src = form_src;
218 // text_dst is deleted by this GUIFormSpecMenu
219 void setTextDest(TextDest *text_dst)
221 if (m_text_dst != NULL) {
224 m_text_dst = text_dst;
227 void allowClose(bool value)
229 m_allowclose = value;
232 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
234 m_lockscreensize = basescreensize;
237 void removeChildren();
238 void setInitialFocus();
240 Remove and re-add (or reposition) stuff
242 void regenerateGui(v2u32 screensize);
244 ItemSpec getItemAtPos(v2s32 p) const;
245 void drawList(const ListDrawSpec &s, int phase);
246 void drawSelectedItem();
248 void updateSelectedItem();
249 ItemStack verifySelectedItem();
251 void acceptInput(FormspecQuitMode quitmode);
252 bool preprocessEvent(const SEvent& event);
253 bool OnEvent(const SEvent& event);
255 bool pausesGame() { return doPause; }
257 GUITable* getTable(std::wstring tablename);
259 static bool parseColor(const std::string &value,
260 video::SColor &color, bool quiet);
263 v2s32 getBasePos() const
265 return padding + offset + AbsoluteRect.UpperLeftCorner;
273 irr::IrrlichtDevice* m_device;
274 InventoryManager *m_invmgr;
276 ISimpleTextureSource *m_tsrc;
278 std::string m_formspec_string;
279 InventoryLocation m_current_inventory_location;
281 std::vector<ListDrawSpec> m_inventorylists;
282 std::vector<ImageDrawSpec> m_backgrounds;
283 std::vector<ImageDrawSpec> m_images;
284 std::vector<ImageDrawSpec> m_itemimages;
285 std::vector<BoxDrawSpec> m_boxes;
286 std::vector<FieldSpec> m_fields;
287 std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
288 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
290 ItemSpec *m_selected_item;
291 u32 m_selected_amount;
292 bool m_selected_dragging;
294 // WARNING: BLACK MAGIC
295 // Used to guess and keep up with some special things the server can do.
296 // If name is "", no guess exists.
297 ItemStack m_selected_content_guess;
298 InventoryLocation m_selected_content_guess_inventory;
301 gui::IGUIStaticText *m_tooltip_element;
305 v2u32 m_lockscreensize;
309 bool m_clipbackground;
310 video::SColor m_bgcolor;
311 video::SColor m_slotbg_n;
312 video::SColor m_slotbg_h;
313 video::SColor m_slotbordercolor;
315 IFormSource *m_form_src;
316 TextDest *m_text_dst;
317 GUIFormSpecMenu **m_ext_ptr;
318 gui::IGUIFont *m_font;
323 core::rect<s32> rect;
327 std::wstring focused_fieldname;
328 GUITable::TableOptions table_options;
329 GUITable::TableColumns table_columns;
330 // used to restore table selection/scroll/treeview state
331 std::map<std::wstring,GUITable::DynamicData> table_dyndata;
341 fs_key_pendig current_keys_pending;
343 void parseElement(parserData* data,std::string element);
345 void parseSize(parserData* data,std::string element);
346 void parseList(parserData* data,std::string element);
347 void parseCheckbox(parserData* data,std::string element);
348 void parseImage(parserData* data,std::string element);
349 void parseItemImage(parserData* data,std::string element);
350 void parseButton(parserData* data,std::string element,std::string typ);
351 void parseBackground(parserData* data,std::string element);
352 void parseTableOptions(parserData* data,std::string element);
353 void parseTableColumns(parserData* data,std::string element);
354 void parseTable(parserData* data,std::string element);
355 void parseTextList(parserData* data,std::string element);
356 void parseDropDown(parserData* data,std::string element);
357 void parsePwdField(parserData* data,std::string element);
358 void parseField(parserData* data,std::string element,std::string type);
359 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
360 void parseTextArea(parserData* data,std::vector<std::string>& parts,
362 void parseLabel(parserData* data,std::string element);
363 void parseVertLabel(parserData* data,std::string element);
364 void parseImageButton(parserData* data,std::string element,std::string type);
365 void parseItemImageButton(parserData* data,std::string element);
366 void parseTabHeader(parserData* data,std::string element);
367 void parseBox(parserData* data,std::string element);
368 void parseBackgroundColor(parserData* data,std::string element);
369 void parseListColors(parserData* data,std::string element);
372 * check if event is part of a double click
373 * @param event event to evaluate
374 * @return true/false if a doubleclick was detected
376 bool DoubleClickDetection(const SEvent event);
383 clickpos m_doubleclickdetect[2];
386 class FormspecFormSource: public IFormSource
389 FormspecFormSource(std::string formspec)
391 m_formspec = formspec;
394 ~FormspecFormSource()
397 void setForm(std::string formspec) {
398 m_formspec = formspec;
401 std::string getForm()
406 std::string m_formspec;