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"
32 class InventoryManager;
45 virtual ~TextDest() {};
46 // This is deprecated I guess? -celeron55
47 virtual void gotText(std::wstring text){}
48 virtual void gotText(std::map<std::string, std::string> fields) = 0;
54 virtual ~IFormSource(){}
55 virtual std::string getForm() = 0;
56 // Fill in variables in field text
57 virtual std::string resolveText(std::string str){ return str; }
60 class GUIFormSpecMenu : public GUIModalMenu
68 ItemSpec(const InventoryLocation &a_inventoryloc,
69 const std::string &a_listname,
72 inventoryloc = a_inventoryloc;
73 listname = a_listname;
81 InventoryLocation inventoryloc;
91 ListDrawSpec(const InventoryLocation &a_inventoryloc,
92 const std::string &a_listname,
93 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
94 inventoryloc(a_inventoryloc),
98 start_item_i(a_start_item_i)
102 InventoryLocation inventoryloc;
103 std::string listname;
114 ImageDrawSpec(const std::string &a_name,
115 v2s32 a_pos, v2s32 a_geom):
122 ImageDrawSpec(const std::string &a_name,
140 FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id):
153 std::wstring fdefault;
156 FormspecFieldType ftype;
158 core::rect<s32> rect;
163 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
171 irr::video::SColor color;
175 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
176 gui::IGUIElement* parent, s32 id,
177 IMenuManager *menumgr,
178 InventoryManager *invmgr,
184 void setFormSpec(const std::string &formspec_string,
185 InventoryLocation current_inventory_location)
187 m_formspec_string = formspec_string;
188 m_current_inventory_location = current_inventory_location;
189 regenerateGui(m_screensize_old);
192 // form_src is deleted by this GUIFormSpecMenu
193 void setFormSource(IFormSource *form_src)
195 m_form_src = form_src;
198 // text_dst is deleted by this GUIFormSpecMenu
199 void setTextDest(TextDest *text_dst)
201 m_text_dst = text_dst;
204 void allowClose(bool value)
206 m_allowclose = value;
209 void useGettext(bool value) {
210 m_use_gettext = true;
213 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
215 m_lockscreensize = basescreensize;
218 void removeChildren();
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(int evttype=-1);
232 bool OnEvent(const SEvent& event);
234 int getListboxIndex(std::string listboxname);
237 v2s32 getBasePos() const
239 return padding + offset + AbsoluteRect.UpperLeftCorner;
247 irr::IrrlichtDevice* m_device;
248 InventoryManager *m_invmgr;
251 std::string m_formspec_string;
252 InventoryLocation m_current_inventory_location;
253 IFormSource *m_form_src;
254 TextDest *m_text_dst;
256 std::vector<ListDrawSpec> m_inventorylists;
257 std::vector<ImageDrawSpec> m_backgrounds;
258 std::vector<ImageDrawSpec> m_images;
259 std::vector<ImageDrawSpec> m_itemimages;
260 std::vector<BoxDrawSpec> m_boxes;
261 std::vector<FieldSpec> m_fields;
262 std::vector<std::pair<FieldSpec,gui::IGUIListBox*> > m_listboxes;
263 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
265 ItemSpec *m_selected_item;
266 u32 m_selected_amount;
267 bool m_selected_dragging;
269 // WARNING: BLACK MAGIC
270 // Used to guess and keep up with some special things the server can do.
271 // If name is "", no guess exists.
272 ItemStack m_selected_content_guess;
273 InventoryLocation m_selected_content_guess_inventory;
276 gui::IGUIStaticText *m_tooltip_element;
281 v2u32 m_lockscreensize;
286 core::rect<s32> rect;
290 std::map<std::wstring,int> listbox_selections;
300 std::vector<video::ITexture *> m_Textures;
302 fs_key_pendig current_keys_pending;
304 void parseElement(parserData* data,std::string element);
306 void parseSize(parserData* data,std::string element);
307 void parseList(parserData* data,std::string element);
308 void parseCheckbox(parserData* data,std::string element);
309 void parseImage(parserData* data,std::string element);
310 void parseItemImage(parserData* data,std::string element);
311 void parseButton(parserData* data,std::string element,std::string typ);
312 void parseBackground(parserData* data,std::string element);
313 void parseTextList(parserData* data,std::string element);
314 void parseDropDown(parserData* data,std::string element);
315 void parsePwdField(parserData* data,std::string element);
316 void parseField(parserData* data,std::string element,std::string type);
317 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
318 void parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type);
319 void parseLabel(parserData* data,std::string element);
320 void parseVertLabel(parserData* data,std::string element);
321 void parseImageButton(parserData* data,std::string element,std::string type);
322 void parseItemImageButton(parserData* data,std::string element);
323 void parseTabHeader(parserData* data,std::string element);
324 void parseBox(parserData* data,std::string element);
326 bool parseColor(std::string color, irr::video::SColor& outcolor);
329 class FormspecFormSource: public IFormSource
332 FormspecFormSource(std::string formspec,FormspecFormSource** game_formspec)
334 m_formspec = formspec;
335 m_game_formspec = game_formspec;
338 ~FormspecFormSource()
340 *m_game_formspec = 0;
343 void setForm(std::string formspec) {
344 m_formspec = formspec;
347 std::string getForm()
352 std::string m_formspec;
353 FormspecFormSource** m_game_formspec;