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;
47 virtual ~TextDest() {};
48 // This is deprecated I guess? -celeron55
49 virtual void gotText(std::wstring text){}
50 virtual void gotText(std::map<std::string, std::string> fields) = 0;
56 virtual ~IFormSource(){}
57 virtual std::string getForm() = 0;
58 // Fill in variables in field text
59 virtual std::string resolveText(std::string str){ return str; }
62 class GUIFormSpecMenu : public GUIModalMenu
70 ItemSpec(const InventoryLocation &a_inventoryloc,
71 const std::string &a_listname,
74 inventoryloc = a_inventoryloc;
75 listname = a_listname;
83 InventoryLocation inventoryloc;
93 ListDrawSpec(const InventoryLocation &a_inventoryloc,
94 const std::string &a_listname,
95 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
96 inventoryloc(a_inventoryloc),
100 start_item_i(a_start_item_i)
104 InventoryLocation inventoryloc;
105 std::string listname;
116 ImageDrawSpec(const std::string &a_name,
117 v2s32 a_pos, v2s32 a_geom):
124 ImageDrawSpec(const std::string &a_name,
142 FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id):
155 std::wstring fdefault;
158 FormspecFieldType ftype;
160 core::rect<s32> rect;
165 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
173 irr::video::SColor color;
177 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
178 gui::IGUIElement* parent, s32 id,
179 IMenuManager *menumgr,
180 InventoryManager *invmgr,
182 ISimpleTextureSource *tsrc
187 void setFormSpec(const std::string &formspec_string,
188 InventoryLocation current_inventory_location)
190 m_formspec_string = formspec_string;
191 m_current_inventory_location = current_inventory_location;
192 regenerateGui(m_screensize_old);
195 // form_src is deleted by this GUIFormSpecMenu
196 void setFormSource(IFormSource *form_src)
198 m_form_src = form_src;
201 // text_dst is deleted by this GUIFormSpecMenu
202 void setTextDest(TextDest *text_dst)
204 m_text_dst = text_dst;
207 void allowClose(bool value)
209 m_allowclose = value;
212 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
214 m_lockscreensize = basescreensize;
217 void removeChildren();
218 void setInitialFocus();
220 Remove and re-add (or reposition) stuff
222 void regenerateGui(v2u32 screensize);
224 ItemSpec getItemAtPos(v2s32 p) const;
225 void drawList(const ListDrawSpec &s, int phase);
226 void drawSelectedItem();
228 void updateSelectedItem();
229 ItemStack verifySelectedItem();
231 void acceptInput(bool quit);
232 bool preprocessEvent(const SEvent& event);
233 bool OnEvent(const SEvent& event);
235 GUITable* getTable(std::wstring tablename);
237 static bool parseColor(const std::string &value,
238 video::SColor &color, bool quiet);
241 v2s32 getBasePos() const
243 return padding + offset + AbsoluteRect.UpperLeftCorner;
251 irr::IrrlichtDevice* m_device;
252 InventoryManager *m_invmgr;
254 ISimpleTextureSource *m_tsrc;
256 std::string m_formspec_string;
257 InventoryLocation m_current_inventory_location;
258 IFormSource *m_form_src;
259 TextDest *m_text_dst;
261 std::vector<ListDrawSpec> m_inventorylists;
262 std::vector<ImageDrawSpec> m_backgrounds;
263 std::vector<ImageDrawSpec> m_images;
264 std::vector<ImageDrawSpec> m_itemimages;
265 std::vector<BoxDrawSpec> m_boxes;
266 std::vector<FieldSpec> m_fields;
267 std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
268 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
270 ItemSpec *m_selected_item;
271 u32 m_selected_amount;
272 bool m_selected_dragging;
274 // WARNING: BLACK MAGIC
275 // Used to guess and keep up with some special things the server can do.
276 // If name is "", no guess exists.
277 ItemStack m_selected_content_guess;
278 InventoryLocation m_selected_content_guess_inventory;
281 gui::IGUIStaticText *m_tooltip_element;
285 v2u32 m_lockscreensize;
289 bool m_clipbackground;
290 video::SColor m_bgcolor;
291 video::SColor m_slotbg_n;
292 video::SColor m_slotbg_h;
293 video::SColor m_slotbordercolor;
298 core::rect<s32> rect;
302 std::wstring focused_fieldname;
303 GUITable::TableOptions table_options;
304 GUITable::TableColumns table_columns;
305 // used to restore table selection/scroll/treeview state
306 std::map<std::wstring,GUITable::DynamicData> table_dyndata;
316 fs_key_pendig current_keys_pending;
318 void parseElement(parserData* data,std::string element);
320 void parseSize(parserData* data,std::string element);
321 void parseList(parserData* data,std::string element);
322 void parseCheckbox(parserData* data,std::string element);
323 void parseImage(parserData* data,std::string element);
324 void parseItemImage(parserData* data,std::string element);
325 void parseButton(parserData* data,std::string element,std::string typ);
326 void parseBackground(parserData* data,std::string element);
327 void parseTableOptions(parserData* data,std::string element);
328 void parseTableColumns(parserData* data,std::string element);
329 void parseTable(parserData* data,std::string element);
330 void parseTextList(parserData* data,std::string element);
331 void parseDropDown(parserData* data,std::string element);
332 void parsePwdField(parserData* data,std::string element);
333 void parseField(parserData* data,std::string element,std::string type);
334 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
335 void parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type);
336 void parseLabel(parserData* data,std::string element);
337 void parseVertLabel(parserData* data,std::string element);
338 void parseImageButton(parserData* data,std::string element,std::string type);
339 void parseItemImageButton(parserData* data,std::string element);
340 void parseTabHeader(parserData* data,std::string element);
341 void parseBox(parserData* data,std::string element);
342 void parseBackgroundColor(parserData* data,std::string element);
343 void parseListColors(parserData* data,std::string element);
346 class FormspecFormSource: public IFormSource
349 FormspecFormSource(std::string formspec,FormspecFormSource** game_formspec)
351 m_formspec = formspec;
352 m_game_formspec = game_formspec;
355 ~FormspecFormSource()
357 *m_game_formspec = 0;
360 void setForm(std::string formspec) {
361 m_formspec = formspec;
364 std::string getForm()
369 std::string m_formspec;
370 FormspecFormSource** m_game_formspec;