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;
33 class ISimpleTextureSource;
46 virtual ~TextDest() {};
47 // This is deprecated I guess? -celeron55
48 virtual void gotText(std::wstring text){}
49 virtual void gotText(std::map<std::string, std::string> fields) = 0;
55 virtual ~IFormSource(){}
56 virtual std::string getForm() = 0;
57 // Fill in variables in field text
58 virtual std::string resolveText(std::string str){ return str; }
61 class GUIFormSpecMenu : public GUIModalMenu
69 ItemSpec(const InventoryLocation &a_inventoryloc,
70 const std::string &a_listname,
73 inventoryloc = a_inventoryloc;
74 listname = a_listname;
82 InventoryLocation inventoryloc;
92 ListDrawSpec(const InventoryLocation &a_inventoryloc,
93 const std::string &a_listname,
94 v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
95 inventoryloc(a_inventoryloc),
99 start_item_i(a_start_item_i)
103 InventoryLocation inventoryloc;
104 std::string listname;
115 ImageDrawSpec(const std::string &a_name,
116 v2s32 a_pos, v2s32 a_geom):
123 ImageDrawSpec(const std::string &a_name,
141 FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id):
154 std::wstring fdefault;
157 FormspecFieldType ftype;
159 core::rect<s32> rect;
164 BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
172 irr::video::SColor color;
176 GUIFormSpecMenu(irr::IrrlichtDevice* dev,
177 gui::IGUIElement* parent, s32 id,
178 IMenuManager *menumgr,
179 InventoryManager *invmgr,
181 ISimpleTextureSource *tsrc
186 void setFormSpec(const std::string &formspec_string,
187 InventoryLocation current_inventory_location)
189 m_formspec_string = formspec_string;
190 m_current_inventory_location = current_inventory_location;
191 regenerateGui(m_screensize_old);
194 // form_src is deleted by this GUIFormSpecMenu
195 void setFormSource(IFormSource *form_src)
197 m_form_src = form_src;
200 // text_dst is deleted by this GUIFormSpecMenu
201 void setTextDest(TextDest *text_dst)
203 m_text_dst = text_dst;
206 void allowClose(bool value)
208 m_allowclose = value;
211 void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
213 m_lockscreensize = basescreensize;
216 void removeChildren();
217 void setInitialFocus();
219 Remove and re-add (or reposition) stuff
221 void regenerateGui(v2u32 screensize);
223 ItemSpec getItemAtPos(v2s32 p) const;
224 void drawList(const ListDrawSpec &s, int phase);
225 void drawSelectedItem();
227 void updateSelectedItem();
228 ItemStack verifySelectedItem();
230 void acceptInput(bool quit);
231 bool preprocessEvent(const SEvent& event);
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;
250 ISimpleTextureSource *m_tsrc;
252 std::string m_formspec_string;
253 InventoryLocation m_current_inventory_location;
254 IFormSource *m_form_src;
255 TextDest *m_text_dst;
257 std::vector<ListDrawSpec> m_inventorylists;
258 std::vector<ImageDrawSpec> m_backgrounds;
259 std::vector<ImageDrawSpec> m_images;
260 std::vector<ImageDrawSpec> m_itemimages;
261 std::vector<BoxDrawSpec> m_boxes;
262 std::vector<FieldSpec> m_fields;
263 std::vector<std::pair<FieldSpec,gui::IGUIListBox*> > m_listboxes;
264 std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
266 ItemSpec *m_selected_item;
267 u32 m_selected_amount;
268 bool m_selected_dragging;
270 // WARNING: BLACK MAGIC
271 // Used to guess and keep up with some special things the server can do.
272 // If name is "", no guess exists.
273 ItemStack m_selected_content_guess;
274 InventoryLocation m_selected_content_guess_inventory;
276 // WARNING: BLACK IRRLICHT MAGIC, see checkListboxClick()
277 std::wstring m_listbox_click_fname;
278 int m_listbox_click_index;
279 u32 m_listbox_click_time;
280 bool m_listbox_doubleclick;
283 gui::IGUIStaticText *m_tooltip_element;
287 v2u32 m_lockscreensize;
292 core::rect<s32> rect;
296 std::wstring focused_fieldname;
297 std::map<std::wstring,int> listbox_selections;
298 std::map<std::wstring,int> listbox_scroll;
308 fs_key_pendig current_keys_pending;
310 // Determine whether listbox click was double click
311 // (Using some black Irrlicht magic)
312 bool checkListboxClick(std::wstring wlistboxname, int eventtype);
314 gui::IGUIScrollBar* getListboxScrollbar(gui::IGUIListBox *listbox);
316 void parseElement(parserData* data,std::string element);
318 void parseSize(parserData* data,std::string element);
319 void parseList(parserData* data,std::string element);
320 void parseCheckbox(parserData* data,std::string element);
321 void parseImage(parserData* data,std::string element);
322 void parseItemImage(parserData* data,std::string element);
323 void parseButton(parserData* data,std::string element,std::string typ);
324 void parseBackground(parserData* data,std::string element);
325 void parseTextList(parserData* data,std::string element);
326 void parseDropDown(parserData* data,std::string element);
327 void parsePwdField(parserData* data,std::string element);
328 void parseField(parserData* data,std::string element,std::string type);
329 void parseSimpleField(parserData* data,std::vector<std::string> &parts);
330 void parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type);
331 void parseLabel(parserData* data,std::string element);
332 void parseVertLabel(parserData* data,std::string element);
333 void parseImageButton(parserData* data,std::string element,std::string type);
334 void parseItemImageButton(parserData* data,std::string element);
335 void parseTabHeader(parserData* data,std::string element);
336 void parseBox(parserData* data,std::string element);
338 bool parseColor(std::string color, irr::video::SColor& outcolor);
341 class FormspecFormSource: public IFormSource
344 FormspecFormSource(std::string formspec,FormspecFormSource** game_formspec)
346 m_formspec = formspec;
347 m_game_formspec = game_formspec;
350 ~FormspecFormSource()
352 *m_game_formspec = 0;
355 void setForm(std::string formspec) {
356 m_formspec = formspec;
359 std::string getForm()
364 std::string m_formspec;
365 FormspecFormSource** m_game_formspec;