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.
26 #include "guiFormSpecMenu.h"
28 #include "constants.h"
31 #include "util/strfnd.h"
32 #include <IGUICheckBox.h>
33 #include <IGUIEditBox.h>
34 #include <IGUIButton.h>
35 #include <IGUIStaticText.h>
37 #include <IGUITabControl.h>
38 #include <IGUIComboBox.h>
40 #include "client/tile.h" // ITextureSource
41 #include "hud.h" // drawItemStack
45 #include "scripting_server.h"
49 #include "fontengine.h"
51 #include "util/numeric.h"
52 #include "util/string.h" // for parseColorString()
53 #include "irrlicht_changes/static_text.h"
54 #include "guiscalingfilter.h"
56 #if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
57 #include "intlGUIEditBox.h"
60 #define MY_CHECKPOS(a,b) \
61 if (v_pos.size() != 2) { \
62 errorstream<< "Invalid pos for element " << a << "specified: \"" \
63 << parts[b] << "\"" << std::endl; \
67 #define MY_CHECKGEOM(a,b) \
68 if (v_geom.size() != 2) { \
69 errorstream<< "Invalid pos for element " << a << "specified: \"" \
70 << parts[b] << "\"" << std::endl; \
76 static unsigned int font_line_height(gui::IGUIFont *font)
78 return font->getDimension(L"Ay").Height + font->getKerningHeight();
81 GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
82 JoystickController *joystick,
83 gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
85 ISimpleTextureSource *tsrc, IFormSource* fsrc, TextDest* tdst,
86 bool remap_dbl_click) :
87 GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
92 m_selected_item(NULL),
94 m_selected_dragging(false),
95 m_tooltip_element(NULL),
98 m_rmouse_auto_place(false),
103 m_formspec_version(0),
104 m_focused_element(""),
105 m_joystick(joystick),
106 current_field_enter_pending(""),
108 m_remap_dbl_click(remap_dbl_click)
110 , m_JavaDialogFieldName("")
113 current_keys_pending.key_down = false;
114 current_keys_pending.key_up = false;
115 current_keys_pending.key_enter = false;
116 current_keys_pending.key_escape = false;
118 m_doubleclickdetect[0].time = 0;
119 m_doubleclickdetect[1].time = 0;
121 m_doubleclickdetect[0].pos = v2s32(0, 0);
122 m_doubleclickdetect[1].pos = v2s32(0, 0);
124 m_tooltip_show_delay = (u32)g_settings->getS32("tooltip_show_delay");
127 GUIFormSpecMenu::~GUIFormSpecMenu()
131 for (u32 i = 0; i < m_tables.size(); ++i) {
132 GUITable *table = m_tables[i].second;
136 delete m_selected_item;
138 if (m_form_src != NULL) {
141 if (m_text_dst != NULL) {
146 void GUIFormSpecMenu::removeChildren()
148 const core::list<gui::IGUIElement*> &children = getChildren();
150 while(!children.empty()) {
151 (*children.getLast())->remove();
154 if(m_tooltip_element) {
155 m_tooltip_element->remove();
156 m_tooltip_element->drop();
157 m_tooltip_element = NULL;
162 void GUIFormSpecMenu::setInitialFocus()
164 // Set initial focus according to following order of precedence:
165 // 1. first empty editbox
169 // 5. first focusable (not statictext, not tabheader)
170 // 6. first child element
172 core::list<gui::IGUIElement*> children = getChildren();
174 // in case "children" contains any NULL elements, remove them
175 for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
176 it != children.end();) {
180 it = children.erase(it);
183 // 1. first empty editbox
184 for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
185 it != children.end(); ++it) {
186 if ((*it)->getType() == gui::EGUIET_EDIT_BOX
187 && (*it)->getText()[0] == 0) {
188 Environment->setFocus(*it);
194 for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
195 it != children.end(); ++it) {
196 if ((*it)->getType() == gui::EGUIET_EDIT_BOX) {
197 Environment->setFocus(*it);
203 for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
204 it != children.end(); ++it) {
205 if ((*it)->getTypeName() == std::string("GUITable")) {
206 Environment->setFocus(*it);
212 for (core::list<gui::IGUIElement*>::Iterator it = children.getLast();
213 it != children.end(); --it) {
214 if ((*it)->getType() == gui::EGUIET_BUTTON) {
215 Environment->setFocus(*it);
220 // 5. first focusable (not statictext, not tabheader)
221 for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
222 it != children.end(); ++it) {
223 if ((*it)->getType() != gui::EGUIET_STATIC_TEXT &&
224 (*it)->getType() != gui::EGUIET_TAB_CONTROL) {
225 Environment->setFocus(*it);
230 // 6. first child element
231 if (children.empty())
232 Environment->setFocus(this);
234 Environment->setFocus(*(children.begin()));
237 GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
239 for (u32 i = 0; i < m_tables.size(); ++i) {
240 if (tablename == m_tables[i].first.fname)
241 return m_tables[i].second;
246 std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &name)
248 for (u32 i = 0; i < m_dropdowns.size(); ++i) {
249 if (name == m_dropdowns[i].first.fname)
250 return &m_dropdowns[i].second;
255 void GUIFormSpecMenu::parseSize(parserData* data, const std::string &element)
257 std::vector<std::string> parts = split(element,',');
259 if (((parts.size() == 2) || parts.size() == 3) ||
260 ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
262 if (parts[1].find(';') != std::string::npos)
263 parts[1] = parts[1].substr(0,parts[1].find(';'));
265 data->invsize.X = MYMAX(0, stof(parts[0]));
266 data->invsize.Y = MYMAX(0, stof(parts[1]));
269 if (parts.size() == 3) {
270 if (parts[2] == "true") {
271 lockSize(true,v2u32(800,600));
275 data->explicit_size = true;
278 errorstream<< "Invalid size element (" << parts.size() << "): '" << element << "'" << std::endl;
281 void GUIFormSpecMenu::parseContainer(parserData* data, const std::string &element)
283 std::vector<std::string> parts = split(element, ',');
285 if (parts.size() >= 2) {
286 if (parts[1].find(';') != std::string::npos)
287 parts[1] = parts[1].substr(0, parts[1].find(';'));
289 container_stack.push(pos_offset);
290 pos_offset.X += MYMAX(0, stof(parts[0]));
291 pos_offset.Y += MYMAX(0, stof(parts[1]));
294 errorstream<< "Invalid container start element (" << parts.size() << "): '" << element << "'" << std::endl;
297 void GUIFormSpecMenu::parseContainerEnd(parserData* data)
299 if (container_stack.empty()) {
300 errorstream<< "Invalid container end element, no matching container start element" << std::endl;
302 pos_offset = container_stack.top();
303 container_stack.pop();
307 void GUIFormSpecMenu::parseList(parserData* data, const std::string &element)
310 warningstream<<"invalid use of 'list' with m_client==0"<<std::endl;
314 std::vector<std::string> parts = split(element,';');
316 if (((parts.size() == 4) || (parts.size() == 5)) ||
317 ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
319 std::string location = parts[0];
320 std::string listname = parts[1];
321 std::vector<std::string> v_pos = split(parts[2],',');
322 std::vector<std::string> v_geom = split(parts[3],',');
323 std::string startindex = "";
324 if (parts.size() == 5)
325 startindex = parts[4];
327 MY_CHECKPOS("list",2);
328 MY_CHECKGEOM("list",3);
330 InventoryLocation loc;
332 if(location == "context" || location == "current_name")
333 loc = m_current_inventory_location;
335 loc.deSerialize(location);
337 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
338 pos.X += stof(v_pos[0]) * (float)spacing.X;
339 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
342 geom.X = stoi(v_geom[0]);
343 geom.Y = stoi(v_geom[1]);
347 start_i = stoi(startindex);
349 if (geom.X < 0 || geom.Y < 0 || start_i < 0) {
350 errorstream<< "Invalid list element: '" << element << "'" << std::endl;
354 if(!data->explicit_size)
355 warningstream<<"invalid use of list without a size[] element"<<std::endl;
356 m_inventorylists.push_back(ListDrawSpec(loc, listname, pos, geom, start_i));
359 errorstream<< "Invalid list element(" << parts.size() << "): '" << element << "'" << std::endl;
362 void GUIFormSpecMenu::parseListRing(parserData* data, const std::string &element)
365 errorstream << "WARNING: invalid use of 'listring' with m_client==0" << std::endl;
369 std::vector<std::string> parts = split(element, ';');
371 if (parts.size() == 2) {
372 std::string location = parts[0];
373 std::string listname = parts[1];
375 InventoryLocation loc;
377 if (location == "context" || location == "current_name")
378 loc = m_current_inventory_location;
380 loc.deSerialize(location);
382 m_inventory_rings.push_back(ListRingSpec(loc, listname));
384 } else if ((element == "") && (m_inventorylists.size() > 1)) {
385 size_t siz = m_inventorylists.size();
386 // insert the last two inv list elements into the list ring
387 const ListDrawSpec &spa = m_inventorylists[siz - 2];
388 const ListDrawSpec &spb = m_inventorylists[siz - 1];
389 m_inventory_rings.push_back(ListRingSpec(spa.inventoryloc, spa.listname));
390 m_inventory_rings.push_back(ListRingSpec(spb.inventoryloc, spb.listname));
393 errorstream<< "Invalid list ring element(" << parts.size() << ", "
394 << m_inventorylists.size() << "): '" << element << "'" << std::endl;
397 void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element)
399 std::vector<std::string> parts = split(element,';');
401 if (((parts.size() >= 3) && (parts.size() <= 4)) ||
402 ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION)))
404 std::vector<std::string> v_pos = split(parts[0],',');
405 std::string name = parts[1];
406 std::string label = parts[2];
407 std::string selected = "";
409 if (parts.size() >= 4)
412 MY_CHECKPOS("checkbox",0);
414 v2s32 pos = padding + pos_offset * spacing;
415 pos.X += stof(v_pos[0]) * (float) spacing.X;
416 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
418 bool fselected = false;
420 if (selected == "true")
423 std::wstring wlabel = utf8_to_wide(unescape_string(label));
425 core::rect<s32> rect = core::rect<s32>(
426 pos.X, pos.Y + ((imgsize.Y/2) - m_btn_height),
427 pos.X + m_font->getDimension(wlabel.c_str()).Width + 25, // text size + size of checkbox
428 pos.Y + ((imgsize.Y/2) + m_btn_height));
432 wlabel, //Needed for displaying text on MSVC
437 spec.ftype = f_CheckBox;
439 gui::IGUICheckBox* e = Environment->addCheckBox(fselected, rect, this,
440 spec.fid, spec.flabel.c_str());
442 if (spec.fname == data->focused_fieldname) {
443 Environment->setFocus(e);
446 m_checkboxes.push_back(std::pair<FieldSpec,gui::IGUICheckBox*>(spec,e));
447 m_fields.push_back(spec);
450 errorstream<< "Invalid checkbox element(" << parts.size() << "): '" << element << "'" << std::endl;
453 void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &element)
455 std::vector<std::string> parts = split(element,';');
457 if (parts.size() >= 5) {
458 std::vector<std::string> v_pos = split(parts[0],',');
459 std::vector<std::string> v_dim = split(parts[1],',');
460 std::string name = parts[3];
461 std::string value = parts[4];
463 MY_CHECKPOS("scrollbar",0);
465 v2s32 pos = padding + pos_offset * spacing;
466 pos.X += stof(v_pos[0]) * (float) spacing.X;
467 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
469 if (v_dim.size() != 2) {
470 errorstream<< "Invalid size for element " << "scrollbar"
471 << "specified: \"" << parts[1] << "\"" << std::endl;
476 dim.X = stof(v_dim[0]) * (float) spacing.X;
477 dim.Y = stof(v_dim[1]) * (float) spacing.Y;
479 core::rect<s32> rect =
480 core::rect<s32>(pos.X, pos.Y, pos.X + dim.X, pos.Y + dim.Y);
489 bool is_horizontal = true;
491 if (parts[2] == "vertical")
492 is_horizontal = false;
494 spec.ftype = f_ScrollBar;
496 gui::IGUIScrollBar* e =
497 Environment->addScrollBar(is_horizontal,rect,this,spec.fid);
501 e->setPos(stoi(parts[4]));
503 e->setLargeStep(100);
505 m_scrollbars.push_back(std::pair<FieldSpec,gui::IGUIScrollBar*>(spec,e));
506 m_fields.push_back(spec);
509 errorstream<< "Invalid scrollbar element(" << parts.size() << "): '" << element << "'" << std::endl;
512 void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element)
514 std::vector<std::string> parts = split(element,';');
516 if ((parts.size() == 3) ||
517 ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
519 std::vector<std::string> v_pos = split(parts[0],',');
520 std::vector<std::string> v_geom = split(parts[1],',');
521 std::string name = unescape_string(parts[2]);
523 MY_CHECKPOS("image", 0);
524 MY_CHECKGEOM("image", 1);
526 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
527 pos.X += stof(v_pos[0]) * (float) spacing.X;
528 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
531 geom.X = stof(v_geom[0]) * (float)imgsize.X;
532 geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
534 if (!data->explicit_size)
535 warningstream<<"invalid use of image without a size[] element"<<std::endl;
536 m_images.push_back(ImageDrawSpec(name, pos, geom));
538 } else if (parts.size() == 2) {
539 std::vector<std::string> v_pos = split(parts[0],',');
540 std::string name = unescape_string(parts[1]);
542 MY_CHECKPOS("image", 0);
544 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
545 pos.X += stof(v_pos[0]) * (float) spacing.X;
546 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
548 if (!data->explicit_size)
549 warningstream<<"invalid use of image without a size[] element"<<std::endl;
550 m_images.push_back(ImageDrawSpec(name, pos));
553 errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl;
556 void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &element)
558 std::vector<std::string> parts = split(element,';');
560 if ((parts.size() == 3) ||
561 ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
563 std::vector<std::string> v_pos = split(parts[0],',');
564 std::vector<std::string> v_geom = split(parts[1],',');
565 std::string name = parts[2];
567 MY_CHECKPOS("itemimage",0);
568 MY_CHECKGEOM("itemimage",1);
570 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
571 pos.X += stof(v_pos[0]) * (float) spacing.X;
572 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
575 geom.X = stof(v_geom[0]) * (float)imgsize.X;
576 geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
578 if(!data->explicit_size)
579 warningstream<<"invalid use of item_image without a size[] element"<<std::endl;
580 m_itemimages.push_back(ImageDrawSpec("", name, pos, geom));
583 errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl;
586 void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
587 const std::string &type)
589 std::vector<std::string> parts = split(element,';');
591 if ((parts.size() == 4) ||
592 ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION)))
594 std::vector<std::string> v_pos = split(parts[0],',');
595 std::vector<std::string> v_geom = split(parts[1],',');
596 std::string name = parts[2];
597 std::string label = parts[3];
599 MY_CHECKPOS("button",0);
600 MY_CHECKGEOM("button",1);
602 v2s32 pos = padding + pos_offset * spacing;
603 pos.X += stof(v_pos[0]) * (float)spacing.X;
604 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
607 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
608 pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
610 core::rect<s32> rect =
611 core::rect<s32>(pos.X, pos.Y - m_btn_height,
612 pos.X + geom.X, pos.Y + m_btn_height);
614 if(!data->explicit_size)
615 warningstream<<"invalid use of button without a size[] element"<<std::endl;
617 std::wstring wlabel = utf8_to_wide(unescape_string(label));
625 spec.ftype = f_Button;
626 if(type == "button_exit")
628 gui::IGUIButton* e = Environment->addButton(rect, this, spec.fid,
629 spec.flabel.c_str());
631 if (spec.fname == data->focused_fieldname) {
632 Environment->setFocus(e);
635 m_fields.push_back(spec);
638 errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl;
641 void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &element)
643 std::vector<std::string> parts = split(element,';');
645 if (((parts.size() == 3) || (parts.size() == 4)) ||
646 ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION)))
648 std::vector<std::string> v_pos = split(parts[0],',');
649 std::vector<std::string> v_geom = split(parts[1],',');
650 std::string name = unescape_string(parts[2]);
652 MY_CHECKPOS("background",0);
653 MY_CHECKGEOM("background",1);
655 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
656 pos.X += stof(v_pos[0]) * (float)spacing.X - ((float)spacing.X - (float)imgsize.X)/2;
657 pos.Y += stof(v_pos[1]) * (float)spacing.Y - ((float)spacing.Y - (float)imgsize.Y)/2;
660 geom.X = stof(v_geom[0]) * (float)spacing.X;
661 geom.Y = stof(v_geom[1]) * (float)spacing.Y;
663 if (!data->explicit_size)
664 warningstream<<"invalid use of background without a size[] element"<<std::endl;
667 if (parts.size() == 4 && is_yes(parts[3])) {
668 pos.X = stoi(v_pos[0]); //acts as offset
669 pos.Y = stoi(v_pos[1]); //acts as offset
672 m_backgrounds.push_back(ImageDrawSpec(name, pos, geom, clip));
676 errorstream<< "Invalid background element(" << parts.size() << "): '" << element << "'" << std::endl;
679 void GUIFormSpecMenu::parseTableOptions(parserData* data, const std::string &element)
681 std::vector<std::string> parts = split(element,';');
683 data->table_options.clear();
684 for (size_t i = 0; i < parts.size(); ++i) {
685 // Parse table option
686 std::string opt = unescape_string(parts[i]);
687 data->table_options.push_back(GUITable::splitOption(opt));
691 void GUIFormSpecMenu::parseTableColumns(parserData* data, const std::string &element)
693 std::vector<std::string> parts = split(element,';');
695 data->table_columns.clear();
696 for (size_t i = 0; i < parts.size(); ++i) {
697 std::vector<std::string> col_parts = split(parts[i],',');
698 GUITable::TableColumn column;
700 if (!col_parts.empty())
701 column.type = col_parts[0];
702 // Parse column options
703 for (size_t j = 1; j < col_parts.size(); ++j) {
704 std::string opt = unescape_string(col_parts[j]);
705 column.options.push_back(GUITable::splitOption(opt));
707 data->table_columns.push_back(column);
711 void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element)
713 std::vector<std::string> parts = split(element,';');
715 if (((parts.size() == 4) || (parts.size() == 5)) ||
716 ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
718 std::vector<std::string> v_pos = split(parts[0],',');
719 std::vector<std::string> v_geom = split(parts[1],',');
720 std::string name = parts[2];
721 std::vector<std::string> items = split(parts[3],',');
722 std::string str_initial_selection = "";
723 std::string str_transparent = "false";
725 if (parts.size() >= 5)
726 str_initial_selection = parts[4];
728 MY_CHECKPOS("table",0);
729 MY_CHECKGEOM("table",1);
731 v2s32 pos = padding + pos_offset * spacing;
732 pos.X += stof(v_pos[0]) * (float)spacing.X;
733 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
736 geom.X = stof(v_geom[0]) * (float)spacing.X;
737 geom.Y = stof(v_geom[1]) * (float)spacing.Y;
739 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
748 spec.ftype = f_Table;
750 for (unsigned int i = 0; i < items.size(); ++i) {
751 items[i] = unescape_enriched(unescape_string(items[i]));
754 //now really show table
755 GUITable *e = new GUITable(Environment, this, spec.fid, rect,
758 if (spec.fname == data->focused_fieldname) {
759 Environment->setFocus(e);
762 e->setTable(data->table_options, data->table_columns, items);
764 if (data->table_dyndata.find(name) != data->table_dyndata.end()) {
765 e->setDynamicData(data->table_dyndata[name]);
768 if ((str_initial_selection != "") &&
769 (str_initial_selection != "0"))
770 e->setSelected(stoi(str_initial_selection.c_str()));
772 m_tables.push_back(std::pair<FieldSpec,GUITable*>(spec, e));
773 m_fields.push_back(spec);
776 errorstream<< "Invalid table element(" << parts.size() << "): '" << element << "'" << std::endl;
779 void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element)
781 std::vector<std::string> parts = split(element,';');
783 if (((parts.size() == 4) || (parts.size() == 5) || (parts.size() == 6)) ||
784 ((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION)))
786 std::vector<std::string> v_pos = split(parts[0],',');
787 std::vector<std::string> v_geom = split(parts[1],',');
788 std::string name = parts[2];
789 std::vector<std::string> items = split(parts[3],',');
790 std::string str_initial_selection = "";
791 std::string str_transparent = "false";
793 if (parts.size() >= 5)
794 str_initial_selection = parts[4];
796 if (parts.size() >= 6)
797 str_transparent = parts[5];
799 MY_CHECKPOS("textlist",0);
800 MY_CHECKGEOM("textlist",1);
802 v2s32 pos = padding + pos_offset * spacing;
803 pos.X += stof(v_pos[0]) * (float)spacing.X;
804 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
807 geom.X = stof(v_geom[0]) * (float)spacing.X;
808 geom.Y = stof(v_geom[1]) * (float)spacing.Y;
811 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
820 spec.ftype = f_Table;
822 for (unsigned int i = 0; i < items.size(); ++i) {
823 items[i] = unescape_enriched(unescape_string(items[i]));
826 //now really show list
827 GUITable *e = new GUITable(Environment, this, spec.fid, rect,
830 if (spec.fname == data->focused_fieldname) {
831 Environment->setFocus(e);
834 e->setTextList(items, is_yes(str_transparent));
836 if (data->table_dyndata.find(name) != data->table_dyndata.end()) {
837 e->setDynamicData(data->table_dyndata[name]);
840 if ((str_initial_selection != "") &&
841 (str_initial_selection != "0"))
842 e->setSelected(stoi(str_initial_selection.c_str()));
844 m_tables.push_back(std::pair<FieldSpec,GUITable*>(spec, e));
845 m_fields.push_back(spec);
848 errorstream<< "Invalid textlist element(" << parts.size() << "): '" << element << "'" << std::endl;
852 void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element)
854 std::vector<std::string> parts = split(element,';');
856 if ((parts.size() == 5) ||
857 ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
859 std::vector<std::string> v_pos = split(parts[0],',');
860 std::string name = parts[2];
861 std::vector<std::string> items = split(parts[3],',');
862 std::string str_initial_selection = "";
863 str_initial_selection = parts[4];
865 MY_CHECKPOS("dropdown",0);
867 v2s32 pos = padding + pos_offset * spacing;
868 pos.X += stof(v_pos[0]) * (float)spacing.X;
869 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
871 s32 width = stof(parts[1]) * (float)spacing.Y;
873 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y,
874 pos.X + width, pos.Y + (m_btn_height * 2));
883 spec.ftype = f_DropDown;
886 //now really show list
887 gui::IGUIComboBox *e = Environment->addComboBox(rect, this,spec.fid);
889 if (spec.fname == data->focused_fieldname) {
890 Environment->setFocus(e);
893 for (unsigned int i=0; i < items.size(); i++) {
894 e->addItem(unescape_enriched(unescape_string(
895 utf8_to_wide(items[i]))).c_str());
898 if (str_initial_selection != "")
899 e->setSelected(stoi(str_initial_selection.c_str())-1);
901 m_fields.push_back(spec);
903 m_dropdowns.push_back(std::pair<FieldSpec,
904 std::vector<std::string> >(spec, std::vector<std::string>()));
905 std::vector<std::string> &values = m_dropdowns.back().second;
906 for (unsigned int i = 0; i < items.size(); i++) {
907 values.push_back(unescape_string(items[i]));
912 errorstream << "Invalid dropdown element(" << parts.size() << "): '"
913 << element << "'" << std::endl;
916 void GUIFormSpecMenu::parseFieldCloseOnEnter(parserData *data, const std::string &element)
918 std::vector<std::string> parts = split(element,';');
919 if (parts.size() == 2 ||
920 (parts.size() > 2 && m_formspec_version > FORMSPEC_API_VERSION)) {
921 field_close_on_enter[parts[0]] = is_yes(parts[1]);
925 void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element)
927 std::vector<std::string> parts = split(element,';');
929 if ((parts.size() == 4) || (parts.size() == 5) ||
930 ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
932 std::vector<std::string> v_pos = split(parts[0],',');
933 std::vector<std::string> v_geom = split(parts[1],',');
934 std::string name = parts[2];
935 std::string label = parts[3];
937 MY_CHECKPOS("pwdfield",0);
938 MY_CHECKGEOM("pwdfield",1);
940 v2s32 pos = pos_offset * spacing;
941 pos.X += stof(v_pos[0]) * (float)spacing.X;
942 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
945 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
947 pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
948 pos.Y -= m_btn_height;
949 geom.Y = m_btn_height*2;
951 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
953 std::wstring wlabel = utf8_to_wide(unescape_string(label));
963 gui::IGUIEditBox * e = Environment->addEditBox(0, rect, true, this, spec.fid);
965 if (spec.fname == data->focused_fieldname) {
966 Environment->setFocus(e);
969 if (label.length() >= 1)
971 int font_height = g_fontengine->getTextHeight();
972 rect.UpperLeftCorner.Y -= font_height;
973 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
974 addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
977 e->setPasswordBox(true,L'*');
980 evt.EventType = EET_KEY_INPUT_EVENT;
981 evt.KeyInput.Key = KEY_END;
982 evt.KeyInput.Char = 0;
983 evt.KeyInput.Control = 0;
984 evt.KeyInput.Shift = 0;
985 evt.KeyInput.PressedDown = true;
988 if (parts.size() >= 5) {
989 // TODO: remove after 2016-11-03
990 warningstream << "pwdfield: use field_close_on_enter[name, enabled]" <<
991 " instead of the 5th param" << std::endl;
992 field_close_on_enter[name] = is_yes(parts[4]);
995 m_fields.push_back(spec);
998 errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl;
1001 void GUIFormSpecMenu::parseSimpleField(parserData* data,
1002 std::vector<std::string> &parts)
1004 std::string name = parts[0];
1005 std::string label = parts[1];
1006 std::string default_val = parts[2];
1008 core::rect<s32> rect;
1010 if(data->explicit_size)
1011 warningstream<<"invalid use of unpositioned \"field\" in inventory"<<std::endl;
1013 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
1014 pos.Y = ((m_fields.size()+2)*60);
1015 v2s32 size = DesiredRect.getSize();
1017 rect = core::rect<s32>(size.X / 2 - 150, pos.Y,
1018 (size.X / 2 - 150) + 300, pos.Y + (m_btn_height*2));
1022 default_val = m_form_src->resolveText(default_val);
1025 std::wstring wlabel = utf8_to_wide(unescape_string(label));
1030 utf8_to_wide(unescape_string(default_val)),
1036 // spec field id to 0, this stops submit searching for a value that isn't there
1037 addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, spec.fid);
1042 gui::IGUIElement *e;
1043 #if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
1044 if (g_settings->getBool("freetype")) {
1045 e = (gui::IGUIElement *) new gui::intlGUIEditBox(spec.fdefault.c_str(),
1046 true, Environment, this, spec.fid, rect);
1052 e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
1054 if (spec.fname == data->focused_fieldname) {
1055 Environment->setFocus(e);
1059 evt.EventType = EET_KEY_INPUT_EVENT;
1060 evt.KeyInput.Key = KEY_END;
1061 evt.KeyInput.Char = 0;
1062 evt.KeyInput.Control = 0;
1063 evt.KeyInput.Shift = 0;
1064 evt.KeyInput.PressedDown = true;
1067 if (label.length() >= 1)
1069 int font_height = g_fontengine->getTextHeight();
1070 rect.UpperLeftCorner.Y -= font_height;
1071 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
1072 addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
1076 if (parts.size() >= 4) {
1077 // TODO: remove after 2016-11-03
1078 warningstream << "field/simple: use field_close_on_enter[name, enabled]" <<
1079 " instead of the 4th param" << std::endl;
1080 field_close_on_enter[name] = is_yes(parts[3]);
1083 m_fields.push_back(spec);
1086 void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>& parts,
1087 const std::string &type)
1090 std::vector<std::string> v_pos = split(parts[0],',');
1091 std::vector<std::string> v_geom = split(parts[1],',');
1092 std::string name = parts[2];
1093 std::string label = parts[3];
1094 std::string default_val = parts[4];
1096 MY_CHECKPOS(type,0);
1097 MY_CHECKGEOM(type,1);
1099 v2s32 pos = pos_offset * spacing;
1100 pos.X += stof(v_pos[0]) * (float) spacing.X;
1101 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
1105 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
1107 if (type == "textarea")
1109 geom.Y = (stof(v_geom[1]) * (float)imgsize.Y) - (spacing.Y-imgsize.Y);
1110 pos.Y += m_btn_height;
1114 pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
1115 pos.Y -= m_btn_height;
1116 geom.Y = m_btn_height*2;
1119 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
1121 if(!data->explicit_size)
1122 warningstream<<"invalid use of positioned "<<type<<" without a size[] element"<<std::endl;
1125 default_val = m_form_src->resolveText(default_val);
1128 std::wstring wlabel = utf8_to_wide(unescape_string(label));
1133 utf8_to_wide(unescape_string(default_val)),
1139 // spec field id to 0, this stops submit searching for a value that isn't there
1140 addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, spec.fid);
1146 gui::IGUIEditBox *e;
1147 #if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
1148 if (g_settings->getBool("freetype")) {
1149 e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(spec.fdefault.c_str(),
1150 true, Environment, this, spec.fid, rect);
1156 e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
1159 if (spec.fname == data->focused_fieldname) {
1160 Environment->setFocus(e);
1163 if (type == "textarea")
1165 e->setMultiLine(true);
1166 e->setWordWrap(true);
1167 e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
1170 evt.EventType = EET_KEY_INPUT_EVENT;
1171 evt.KeyInput.Key = KEY_END;
1172 evt.KeyInput.Char = 0;
1173 evt.KeyInput.Control = 0;
1174 evt.KeyInput.Shift = 0;
1175 evt.KeyInput.PressedDown = true;
1179 if (label.length() >= 1)
1181 int font_height = g_fontengine->getTextHeight();
1182 rect.UpperLeftCorner.Y -= font_height;
1183 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
1184 addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
1188 if (parts.size() >= 6) {
1189 // TODO: remove after 2016-11-03
1190 warningstream << "field/textarea: use field_close_on_enter[name, enabled]" <<
1191 " instead of the 6th param" << std::endl;
1192 field_close_on_enter[name] = is_yes(parts[5]);
1195 m_fields.push_back(spec);
1198 void GUIFormSpecMenu::parseField(parserData* data, const std::string &element,
1199 const std::string &type)
1201 std::vector<std::string> parts = split(element,';');
1203 if (parts.size() == 3 || parts.size() == 4) {
1204 parseSimpleField(data,parts);
1208 if ((parts.size() == 5) || (parts.size() == 6) ||
1209 ((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION)))
1211 parseTextArea(data,parts,type);
1214 errorstream<< "Invalid field element(" << parts.size() << "): '" << element << "'" << std::endl;
1217 void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
1219 std::vector<std::string> parts = split(element,';');
1221 if ((parts.size() == 2) ||
1222 ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
1224 std::vector<std::string> v_pos = split(parts[0],',');
1225 std::string text = parts[1];
1227 MY_CHECKPOS("label",0);
1229 v2s32 pos = padding + pos_offset * spacing;
1230 pos.X += stof(v_pos[0]) * (float)spacing.X;
1231 pos.Y += (stof(v_pos[1]) + 7.0/30.0) * (float)spacing.Y;
1233 if(!data->explicit_size)
1234 warningstream<<"invalid use of label without a size[] element"<<std::endl;
1236 std::vector<std::string> lines = split(text, '\n');
1238 for (unsigned int i = 0; i != lines.size(); i++) {
1239 // Lines are spaced at the nominal distance of
1240 // 2/5 inventory slot, even if the font doesn't
1241 // quite match that. This provides consistent
1242 // form layout, at the expense of sometimes
1243 // having sub-optimal spacing for the font.
1244 // We multiply by 2 and then divide by 5, rather
1245 // than multiply by 0.4, to get exact results
1246 // in the integer cases: 0.4 is not exactly
1247 // representable in binary floating point.
1248 s32 posy = pos.Y + ((float)i) * spacing.Y * 2.0 / 5.0;
1249 std::wstring wlabel = utf8_to_wide(unescape_string(lines[i]));
1250 core::rect<s32> rect = core::rect<s32>(
1251 pos.X, posy - m_btn_height,
1252 pos.X + m_font->getDimension(wlabel.c_str()).Width,
1253 posy + m_btn_height);
1260 gui::IGUIStaticText *e =
1261 addStaticText(Environment, spec.flabel.c_str(),
1262 rect, false, false, this, spec.fid);
1263 e->setTextAlignment(gui::EGUIA_UPPERLEFT,
1265 m_fields.push_back(spec);
1270 errorstream<< "Invalid label element(" << parts.size() << "): '" << element << "'" << std::endl;
1273 void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &element)
1275 std::vector<std::string> parts = split(element,';');
1277 if ((parts.size() == 2) ||
1278 ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
1280 std::vector<std::string> v_pos = split(parts[0],',');
1281 std::wstring text = unescape_enriched(
1282 unescape_string(utf8_to_wide(parts[1])));
1284 MY_CHECKPOS("vertlabel",1);
1286 v2s32 pos = padding + pos_offset * spacing;
1287 pos.X += stof(v_pos[0]) * (float)spacing.X;
1288 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
1290 core::rect<s32> rect = core::rect<s32>(
1291 pos.X, pos.Y+((imgsize.Y/2)- m_btn_height),
1293 font_line_height(m_font)
1295 +((imgsize.Y/2)- m_btn_height));
1296 //actually text.length() would be correct but adding +1 avoids to break all mods
1298 if(!data->explicit_size)
1299 warningstream<<"invalid use of label without a size[] element"<<std::endl;
1301 std::wstring label = L"";
1303 for (unsigned int i=0; i < text.length(); i++) {
1314 gui::IGUIStaticText *t =
1315 addStaticText(Environment, spec.flabel.c_str(), rect, false, false, this, spec.fid);
1316 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
1317 m_fields.push_back(spec);
1320 errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl;
1323 void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &element,
1324 const std::string &type)
1326 std::vector<std::string> parts = split(element,';');
1328 if ((((parts.size() >= 5) && (parts.size() <= 8)) && (parts.size() != 6)) ||
1329 ((parts.size() > 8) && (m_formspec_version > FORMSPEC_API_VERSION)))
1331 std::vector<std::string> v_pos = split(parts[0],',');
1332 std::vector<std::string> v_geom = split(parts[1],',');
1333 std::string image_name = parts[2];
1334 std::string name = parts[3];
1335 std::string label = parts[4];
1337 MY_CHECKPOS("imagebutton",0);
1338 MY_CHECKGEOM("imagebutton",1);
1340 v2s32 pos = padding + pos_offset * spacing;
1341 pos.X += stof(v_pos[0]) * (float)spacing.X;
1342 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
1344 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
1345 geom.Y = (stof(v_geom[1]) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
1347 bool noclip = false;
1348 bool drawborder = true;
1349 std::string pressed_image_name = "";
1351 if (parts.size() >= 7) {
1352 if (parts[5] == "true")
1354 if (parts[6] == "false")
1358 if (parts.size() >= 8) {
1359 pressed_image_name = parts[7];
1362 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
1364 if(!data->explicit_size)
1365 warningstream<<"invalid use of image_button without a size[] element"<<std::endl;
1367 image_name = unescape_string(image_name);
1368 pressed_image_name = unescape_string(pressed_image_name);
1370 std::wstring wlabel = utf8_to_wide(unescape_string(label));
1375 utf8_to_wide(image_name),
1378 spec.ftype = f_Button;
1379 if(type == "image_button_exit")
1380 spec.is_exit = true;
1382 video::ITexture *texture = 0;
1383 video::ITexture *pressed_texture = 0;
1384 texture = m_tsrc->getTexture(image_name);
1385 if (pressed_image_name != "")
1386 pressed_texture = m_tsrc->getTexture(pressed_image_name);
1388 pressed_texture = texture;
1390 gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
1392 if (spec.fname == data->focused_fieldname) {
1393 Environment->setFocus(e);
1396 e->setUseAlphaChannel(true);
1397 e->setImage(guiScalingImageButton(
1398 Environment->getVideoDriver(), texture, geom.X, geom.Y));
1399 e->setPressedImage(guiScalingImageButton(
1400 Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y));
1401 e->setScaleImage(true);
1402 e->setNotClipped(noclip);
1403 e->setDrawBorder(drawborder);
1405 m_fields.push_back(spec);
1409 errorstream<< "Invalid imagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
1412 void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &element)
1414 std::vector<std::string> parts = split(element,';');
1416 if (((parts.size() == 4) || (parts.size() == 6)) ||
1417 ((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION)))
1419 std::vector<std::string> v_pos = split(parts[0],',');
1420 std::string name = parts[1];
1421 std::vector<std::string> buttons = split(parts[2],',');
1422 std::string str_index = parts[3];
1423 bool show_background = true;
1424 bool show_border = true;
1425 int tab_index = stoi(str_index) -1;
1427 MY_CHECKPOS("tabheader",0);
1429 if (parts.size() == 6) {
1430 if (parts[4] == "true")
1431 show_background = false;
1432 if (parts[5] == "false")
1433 show_border = false;
1443 spec.ftype = f_TabHeader;
1445 v2s32 pos = pos_offset * spacing;
1446 pos.X += stof(v_pos[0]) * (float)spacing.X;
1447 pos.Y += stof(v_pos[1]) * (float)spacing.Y - m_btn_height * 2;
1449 geom.X = DesiredRect.getWidth();
1450 geom.Y = m_btn_height*2;
1452 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X,
1455 gui::IGUITabControl *e = Environment->addTabControl(rect, this,
1456 show_background, show_border, spec.fid);
1457 e->setAlignment(irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT,
1458 irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_LOWERRIGHT);
1459 e->setTabHeight(m_btn_height*2);
1461 if (spec.fname == data->focused_fieldname) {
1462 Environment->setFocus(e);
1465 e->setNotClipped(true);
1467 for (unsigned int i = 0; i < buttons.size(); i++) {
1468 e->addTab(unescape_enriched(unescape_string(
1469 utf8_to_wide(buttons[i]))).c_str(), -1);
1472 if ((tab_index >= 0) &&
1473 (buttons.size() < INT_MAX) &&
1474 (tab_index < (int) buttons.size()))
1475 e->setActiveTab(tab_index);
1477 m_fields.push_back(spec);
1480 errorstream << "Invalid TabHeader element(" << parts.size() << "): '"
1481 << element << "'" << std::endl;
1484 void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &element)
1487 if (m_client == 0) {
1488 warningstream << "invalid use of item_image_button with m_client==0"
1493 std::vector<std::string> parts = split(element,';');
1495 if ((parts.size() == 5) ||
1496 ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
1498 std::vector<std::string> v_pos = split(parts[0],',');
1499 std::vector<std::string> v_geom = split(parts[1],',');
1500 std::string item_name = parts[2];
1501 std::string name = parts[3];
1502 std::string label = parts[4];
1504 label = unescape_string(label);
1505 item_name = unescape_string(item_name);
1507 MY_CHECKPOS("itemimagebutton",0);
1508 MY_CHECKGEOM("itemimagebutton",1);
1510 v2s32 pos = padding + pos_offset * spacing;
1511 pos.X += stof(v_pos[0]) * (float)spacing.X;
1512 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
1514 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
1515 geom.Y = (stof(v_geom[1]) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
1517 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
1519 if(!data->explicit_size)
1520 warningstream<<"invalid use of item_image_button without a size[] element"<<std::endl;
1522 IItemDefManager *idef = m_client->idef();
1524 item.deSerialize(item_name, idef);
1527 TooltipSpec(item.getDefinition(idef).description,
1528 m_default_tooltip_bgcolor,
1529 m_default_tooltip_color);
1533 utf8_to_wide(label),
1534 utf8_to_wide(item_name),
1535 258 + m_fields.size()
1538 gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, L"");
1540 if (spec.fname == data->focused_fieldname) {
1541 Environment->setFocus(e);
1544 spec.ftype = f_Button;
1545 rect+=data->basepos-padding;
1547 m_fields.push_back(spec);
1548 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
1549 pos.X += stof(v_pos[0]) * (float) spacing.X;
1550 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
1551 m_itemimages.push_back(ImageDrawSpec("", item_name, e, pos, geom));
1552 m_static_texts.push_back(StaticTextSpec(utf8_to_wide(label), rect, e));
1555 errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
1558 void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element)
1560 std::vector<std::string> parts = split(element,';');
1562 if ((parts.size() == 3) ||
1563 ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
1565 std::vector<std::string> v_pos = split(parts[0],',');
1566 std::vector<std::string> v_geom = split(parts[1],',');
1568 MY_CHECKPOS("box",0);
1569 MY_CHECKGEOM("box",1);
1571 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
1572 pos.X += stof(v_pos[0]) * (float) spacing.X;
1573 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
1576 geom.X = stof(v_geom[0]) * (float)spacing.X;
1577 geom.Y = stof(v_geom[1]) * (float)spacing.Y;
1579 video::SColor tmp_color;
1581 if (parseColorString(parts[2], tmp_color, false)) {
1582 BoxDrawSpec spec(pos, geom, tmp_color);
1584 m_boxes.push_back(spec);
1587 errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "' INVALID COLOR" << std::endl;
1591 errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "'" << std::endl;
1594 void GUIFormSpecMenu::parseBackgroundColor(parserData* data, const std::string &element)
1596 std::vector<std::string> parts = split(element,';');
1598 if (((parts.size() == 1) || (parts.size() == 2)) ||
1599 ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
1601 parseColorString(parts[0],m_bgcolor,false);
1603 if (parts.size() == 2) {
1604 std::string fullscreen = parts[1];
1605 m_bgfullscreen = is_yes(fullscreen);
1609 errorstream<< "Invalid bgcolor element(" << parts.size() << "): '" << element << "'" << std::endl;
1612 void GUIFormSpecMenu::parseListColors(parserData* data, const std::string &element)
1614 std::vector<std::string> parts = split(element,';');
1616 if (((parts.size() == 2) || (parts.size() == 3) || (parts.size() == 5)) ||
1617 ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
1619 parseColorString(parts[0], m_slotbg_n, false);
1620 parseColorString(parts[1], m_slotbg_h, false);
1622 if (parts.size() >= 3) {
1623 if (parseColorString(parts[2], m_slotbordercolor, false)) {
1624 m_slotborder = true;
1627 if (parts.size() == 5) {
1628 video::SColor tmp_color;
1630 if (parseColorString(parts[3], tmp_color, false))
1631 m_default_tooltip_bgcolor = tmp_color;
1632 if (parseColorString(parts[4], tmp_color, false))
1633 m_default_tooltip_color = tmp_color;
1637 errorstream<< "Invalid listcolors element(" << parts.size() << "): '" << element << "'" << std::endl;
1640 void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element)
1642 std::vector<std::string> parts = split(element,';');
1643 if (parts.size() == 2) {
1644 std::string name = parts[0];
1645 m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
1646 m_default_tooltip_bgcolor, m_default_tooltip_color);
1648 } else if (parts.size() == 4) {
1649 std::string name = parts[0];
1650 video::SColor tmp_color1, tmp_color2;
1651 if ( parseColorString(parts[2], tmp_color1, false) && parseColorString(parts[3], tmp_color2, false) ) {
1652 m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
1653 tmp_color1, tmp_color2);
1657 errorstream<< "Invalid tooltip element(" << parts.size() << "): '" << element << "'" << std::endl;
1660 bool GUIFormSpecMenu::parseVersionDirect(const std::string &data)
1666 std::vector<std::string> parts = split(data,'[');
1668 if (parts.size() < 2) {
1672 if (parts[0] != "formspec_version") {
1676 if (is_number(parts[1])) {
1677 m_formspec_version = mystoi(parts[1]);
1684 bool GUIFormSpecMenu::parseSizeDirect(parserData* data, const std::string &element)
1689 std::vector<std::string> parts = split(element,'[');
1691 if (parts.size() < 2)
1694 std::string type = trim(parts[0]);
1695 std::string description = trim(parts[1]);
1697 if (type != "size" && type != "invsize")
1700 if (type == "invsize")
1701 log_deprecated("Deprecated formspec element \"invsize\" is used");
1703 parseSize(data, description);
1708 bool GUIFormSpecMenu::parsePositionDirect(parserData *data, const std::string &element)
1710 if (element.empty())
1713 std::vector<std::string> parts = split(element, '[');
1715 if (parts.size() != 2)
1718 std::string type = trim(parts[0]);
1719 std::string description = trim(parts[1]);
1721 if (type != "position")
1724 parsePosition(data, description);
1729 void GUIFormSpecMenu::parsePosition(parserData *data, const std::string &element)
1731 std::vector<std::string> parts = split(element, ',');
1733 if (parts.size() == 2) {
1734 data->offset.X = stof(parts[0]);
1735 data->offset.Y = stof(parts[1]);
1739 errorstream << "Invalid position element (" << parts.size() << "): '" << element << "'" << std::endl;
1742 bool GUIFormSpecMenu::parseAnchorDirect(parserData *data, const std::string &element)
1744 if (element.empty())
1747 std::vector<std::string> parts = split(element, '[');
1749 if (parts.size() != 2)
1752 std::string type = trim(parts[0]);
1753 std::string description = trim(parts[1]);
1755 if (type != "anchor")
1758 parseAnchor(data, description);
1763 void GUIFormSpecMenu::parseAnchor(parserData *data, const std::string &element)
1765 std::vector<std::string> parts = split(element, ',');
1767 if (parts.size() == 2) {
1768 data->anchor.X = stof(parts[0]);
1769 data->anchor.Y = stof(parts[1]);
1773 errorstream << "Invalid anchor element (" << parts.size() << "): '" << element
1774 << "'" << std::endl;
1777 void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
1783 std::vector<std::string> parts = split(element,'[');
1785 // ugly workaround to keep compatibility
1786 if (parts.size() > 2) {
1787 if (trim(parts[0]) == "image") {
1788 for (unsigned int i=2;i< parts.size(); i++) {
1789 parts[1] += "[" + parts[i];
1795 if (parts.size() < 2) {
1799 std::string type = trim(parts[0]);
1800 std::string description = trim(parts[1]);
1802 if (type == "container") {
1803 parseContainer(data, description);
1807 if (type == "container_end") {
1808 parseContainerEnd(data);
1812 if (type == "list") {
1813 parseList(data, description);
1817 if (type == "listring") {
1818 parseListRing(data, description);
1822 if (type == "checkbox") {
1823 parseCheckbox(data, description);
1827 if (type == "image") {
1828 parseImage(data, description);
1832 if (type == "item_image") {
1833 parseItemImage(data, description);
1837 if (type == "button" || type == "button_exit") {
1838 parseButton(data, description, type);
1842 if (type == "background") {
1843 parseBackground(data,description);
1847 if (type == "tableoptions"){
1848 parseTableOptions(data,description);
1852 if (type == "tablecolumns"){
1853 parseTableColumns(data,description);
1857 if (type == "table"){
1858 parseTable(data,description);
1862 if (type == "textlist"){
1863 parseTextList(data,description);
1867 if (type == "dropdown"){
1868 parseDropDown(data,description);
1872 if (type == "field_close_on_enter") {
1873 parseFieldCloseOnEnter(data, description);
1877 if (type == "pwdfield") {
1878 parsePwdField(data,description);
1882 if ((type == "field") || (type == "textarea")){
1883 parseField(data,description,type);
1887 if (type == "label") {
1888 parseLabel(data,description);
1892 if (type == "vertlabel") {
1893 parseVertLabel(data,description);
1897 if (type == "item_image_button") {
1898 parseItemImageButton(data,description);
1902 if ((type == "image_button") || (type == "image_button_exit")) {
1903 parseImageButton(data,description,type);
1907 if (type == "tabheader") {
1908 parseTabHeader(data,description);
1912 if (type == "box") {
1913 parseBox(data,description);
1917 if (type == "bgcolor") {
1918 parseBackgroundColor(data,description);
1922 if (type == "listcolors") {
1923 parseListColors(data,description);
1927 if (type == "tooltip") {
1928 parseTooltip(data,description);
1932 if (type == "scrollbar") {
1933 parseScrollBar(data, description);
1939 << "Unknown DrawSpec: type="<<type<<", data=\""<<description<<"\""
1943 void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
1945 /* useless to regenerate without a screensize */
1946 if ((screensize.X <= 0) || (screensize.Y <= 0)) {
1953 for (u32 i = 0; i < m_tables.size(); ++i) {
1954 std::string tablename = m_tables[i].first.fname;
1955 GUITable *table = m_tables[i].second;
1956 mydata.table_dyndata[tablename] = table->getDynamicData();
1960 if (!m_focused_element.empty())
1961 mydata.focused_fieldname = m_focused_element;
1964 gui::IGUIElement *focused_element = Environment->getFocus();
1965 if (focused_element && focused_element->getParent() == this) {
1966 s32 focused_id = focused_element->getID();
1967 if (focused_id > 257) {
1968 for (u32 i=0; i<m_fields.size(); i++) {
1969 if (m_fields[i].fid == focused_id) {
1970 mydata.focused_fieldname =
1981 for (u32 i = 0; i < m_tables.size(); ++i) {
1982 GUITable *table = m_tables[i].second;
1986 mydata.size= v2s32(100,100);
1987 mydata.screensize = screensize;
1988 mydata.offset = v2f32(0.5f, 0.5f);
1989 mydata.anchor = v2f32(0.5f, 0.5f);
1991 // Base position of contents of form
1992 mydata.basepos = getBasePos();
1994 /* Convert m_init_draw_spec to m_inventorylists */
1996 m_inventorylists.clear();
1998 m_backgrounds.clear();
1999 m_itemimages.clear();
2001 m_checkboxes.clear();
2002 m_scrollbars.clear();
2006 m_inventory_rings.clear();
2007 m_static_texts.clear();
2009 // Set default values (fits old formspec values)
2010 m_bgcolor = video::SColor(140,0,0,0);
2011 m_bgfullscreen = false;
2013 m_slotbg_n = video::SColor(255,128,128,128);
2014 m_slotbg_h = video::SColor(255,192,192,192);
2016 m_default_tooltip_bgcolor = video::SColor(255,110,130,60);
2017 m_default_tooltip_color = video::SColor(255,255,255,255);
2019 m_slotbordercolor = video::SColor(200,0,0,0);
2020 m_slotborder = false;
2024 assert(m_tooltip_element == NULL);
2025 // Note: parent != this so that the tooltip isn't clipped by the menu rectangle
2026 m_tooltip_element = addStaticText(Environment, L"",core::rect<s32>(0,0,110,18));
2027 m_tooltip_element->enableOverrideColor(true);
2028 m_tooltip_element->setBackgroundColor(m_default_tooltip_bgcolor);
2029 m_tooltip_element->setDrawBackground(true);
2030 m_tooltip_element->setDrawBorder(true);
2031 m_tooltip_element->setOverrideColor(m_default_tooltip_color);
2032 m_tooltip_element->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
2033 m_tooltip_element->setWordWrap(false);
2034 //we're not parent so no autograb for this one!
2035 m_tooltip_element->grab();
2038 std::vector<std::string> elements = split(m_formspec_string,']');
2041 /* try to read version from first element only */
2042 if (elements.size() >= 1) {
2043 if ( parseVersionDirect(elements[0]) ) {
2048 /* we need size first in order to calculate image scale */
2049 mydata.explicit_size = false;
2050 for (; i< elements.size(); i++) {
2051 if (!parseSizeDirect(&mydata, elements[i])) {
2056 /* "position" element is always after "size" element if it used */
2057 for (; i< elements.size(); i++) {
2058 if (!parsePositionDirect(&mydata, elements[i])) {
2063 /* "anchor" element is always after "position" (or "size" element) if it used */
2064 for (; i< elements.size(); i++) {
2065 if (!parseAnchorDirect(&mydata, elements[i])) {
2071 if (mydata.explicit_size) {
2072 // compute scaling for specified form size
2074 v2u32 current_screensize = m_device->getVideoDriver()->getScreenSize();
2075 v2u32 delta = current_screensize - m_lockscreensize;
2077 if (current_screensize.Y > m_lockscreensize.Y)
2082 if (current_screensize.X > m_lockscreensize.X)
2087 offset = v2s32(delta.X,delta.Y);
2089 mydata.screensize = m_lockscreensize;
2091 offset = v2s32(0,0);
2094 double gui_scaling = g_settings->getFloat("gui_scaling");
2095 double screen_dpi = porting::getDisplayDensity() * 96;
2099 // In fixed-size mode, inventory image size
2100 // is 0.53 inch multiplied by the gui_scaling
2101 // config parameter. This magic size is chosen
2102 // to make the main menu (15.5 inventory images
2103 // wide, including border) just fit into the
2104 // default window (800 pixels wide) at 96 DPI
2105 // and default scaling (1.00).
2106 use_imgsize = 0.5555 * screen_dpi * gui_scaling;
2108 // In variable-size mode, we prefer to make the
2109 // inventory image size 1/15 of screen height,
2110 // multiplied by the gui_scaling config parameter.
2111 // If the preferred size won't fit the whole
2112 // form on the screen, either horizontally or
2113 // vertically, then we scale it down to fit.
2114 // (The magic numbers in the computation of what
2115 // fits arise from the scaling factors in the
2116 // following stanza, including the form border,
2117 // help text space, and 0.1 inventory slot spare.)
2118 // However, a minimum size is also set, that
2119 // the image size can't be less than 0.3 inch
2120 // multiplied by gui_scaling, even if this means
2121 // the form doesn't fit the screen.
2122 double prefer_imgsize = mydata.screensize.Y / 15 *
2124 double fitx_imgsize = mydata.screensize.X /
2125 ((5.0/4.0) * (0.5 + mydata.invsize.X));
2126 double fity_imgsize = mydata.screensize.Y /
2127 ((15.0/13.0) * (0.85 * mydata.invsize.Y));
2128 double screen_dpi = porting::getDisplayDensity() * 96;
2129 double min_imgsize = 0.3 * screen_dpi * gui_scaling;
2130 use_imgsize = MYMAX(min_imgsize, MYMIN(prefer_imgsize,
2131 MYMIN(fitx_imgsize, fity_imgsize)));
2134 // Everything else is scaled in proportion to the
2135 // inventory image size. The inventory slot spacing
2136 // is 5/4 image size horizontally and 15/13 image size
2137 // vertically. The padding around the form (incorporating
2138 // the border of the outer inventory slots) is 3/8
2139 // image size. Font height (baseline to baseline)
2140 // is 2/5 vertical inventory slot spacing, and button
2141 // half-height is 7/8 of font height.
2142 imgsize = v2s32(use_imgsize, use_imgsize);
2143 spacing = v2s32(use_imgsize*5.0/4, use_imgsize*15.0/13);
2144 padding = v2s32(use_imgsize*3.0/8, use_imgsize*3.0/8);
2145 m_btn_height = use_imgsize*15.0/13 * 0.35;
2147 m_font = g_fontengine->getFont();
2149 mydata.size = v2s32(
2150 padding.X*2+spacing.X*(mydata.invsize.X-1.0)+imgsize.X,
2151 padding.Y*2+spacing.Y*(mydata.invsize.Y-1.0)+imgsize.Y + m_btn_height*2.0/3.0
2153 DesiredRect = mydata.rect = core::rect<s32>(
2154 (s32)((f32)mydata.screensize.X * mydata.offset.X) - (s32)(mydata.anchor.X * (f32)mydata.size.X) + offset.X,
2155 (s32)((f32)mydata.screensize.Y * mydata.offset.Y) - (s32)(mydata.anchor.Y * (f32)mydata.size.Y) + offset.Y,
2156 (s32)((f32)mydata.screensize.X * mydata.offset.X) + (s32)((1.0 - mydata.anchor.X) * (f32)mydata.size.X) + offset.X,
2157 (s32)((f32)mydata.screensize.Y * mydata.offset.Y) + (s32)((1.0 - mydata.anchor.Y) * (f32)mydata.size.Y) + offset.Y
2160 // Non-size[] form must consist only of text fields and
2161 // implicit "Proceed" button. Use default font, and
2162 // temporary form size which will be recalculated below.
2163 m_font = g_fontengine->getFont();
2164 m_btn_height = font_line_height(m_font) * 0.875;
2165 DesiredRect = core::rect<s32>(
2166 (s32)((f32)mydata.screensize.X * mydata.offset.X) - (s32)(mydata.anchor.X * 580.0),
2167 (s32)((f32)mydata.screensize.Y * mydata.offset.Y) - (s32)(mydata.anchor.Y * 300.0),
2168 (s32)((f32)mydata.screensize.X * mydata.offset.X) + (s32)((1.0 - mydata.anchor.X) * 580.0),
2169 (s32)((f32)mydata.screensize.Y * mydata.offset.Y) + (s32)((1.0 - mydata.anchor.Y) * 300.0)
2172 recalculateAbsolutePosition(false);
2173 mydata.basepos = getBasePos();
2174 m_tooltip_element->setOverrideFont(m_font);
2176 gui::IGUISkin* skin = Environment->getSkin();
2177 sanity_check(skin != NULL);
2178 gui::IGUIFont *old_font = skin->getFont();
2179 skin->setFont(m_font);
2181 pos_offset = v2s32();
2182 for (; i< elements.size(); i++) {
2183 parseElement(&mydata, elements[i]);
2186 if (!container_stack.empty()) {
2187 errorstream << "Invalid formspec string: container was never closed!"
2191 // If there are fields without explicit size[], add a "Proceed"
2192 // button and adjust size to fit all the fields.
2193 if (m_fields.size() && !mydata.explicit_size) {
2194 mydata.rect = core::rect<s32>(
2195 mydata.screensize.X/2 - 580/2,
2196 mydata.screensize.Y/2 - 300/2,
2197 mydata.screensize.X/2 + 580/2,
2198 mydata.screensize.Y/2 + 240/2+(m_fields.size()*60)
2200 DesiredRect = mydata.rect;
2201 recalculateAbsolutePosition(false);
2202 mydata.basepos = getBasePos();
2205 v2s32 pos = mydata.basepos;
2206 pos.Y = ((m_fields.size()+2)*60);
2208 v2s32 size = DesiredRect.getSize();
2210 core::rect<s32>(size.X/2-70, pos.Y,
2211 (size.X/2-70)+140, pos.Y + (m_btn_height*2));
2212 const wchar_t *text = wgettext("Proceed");
2213 Environment->addButton(mydata.rect, this, 257, text);
2219 //set initial focus if parser didn't set it
2220 focused_element = Environment->getFocus();
2221 if (!focused_element
2222 || !isMyChild(focused_element)
2223 || focused_element->getType() == gui::EGUIET_TAB_CONTROL)
2226 skin->setFont(old_font);
2230 bool GUIFormSpecMenu::getAndroidUIInput()
2232 /* no dialog shown */
2233 if (m_JavaDialogFieldName == "") {
2238 if (porting::getInputDialogState() == -1) {
2242 std::string fieldname = m_JavaDialogFieldName;
2243 m_JavaDialogFieldName = "";
2245 /* no value abort dialog processing */
2246 if (porting::getInputDialogState() != 0) {
2250 for(std::vector<FieldSpec>::iterator iter = m_fields.begin();
2251 iter != m_fields.end(); ++iter) {
2253 if (iter->fname != fieldname) {
2256 IGUIElement* tochange = getElementFromId(iter->fid);
2258 if (tochange == 0) {
2262 if (tochange->getType() != irr::gui::EGUIET_EDIT_BOX) {
2266 std::string text = porting::getInputDialogValue();
2268 ((gui::IGUIEditBox*) tochange)->
2269 setText(utf8_to_wide(text).c_str());
2275 GUIFormSpecMenu::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
2277 core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
2279 for(u32 i=0; i<m_inventorylists.size(); i++)
2281 const ListDrawSpec &s = m_inventorylists[i];
2283 for(s32 i=0; i<s.geom.X*s.geom.Y; i++) {
2284 s32 item_i = i + s.start_item_i;
2285 s32 x = (i%s.geom.X) * spacing.X;
2286 s32 y = (i/s.geom.X) * spacing.Y;
2288 core::rect<s32> rect = imgrect + s.pos + p0;
2289 if(rect.isPointInside(p))
2291 return ItemSpec(s.inventoryloc, s.listname, item_i);
2296 return ItemSpec(InventoryLocation(), "", -1);
2299 void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase,
2302 video::IVideoDriver* driver = Environment->getVideoDriver();
2304 Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
2306 warningstream<<"GUIFormSpecMenu::drawList(): "
2307 <<"The inventory location "
2308 <<"\""<<s.inventoryloc.dump()<<"\" doesn't exist"
2312 InventoryList *ilist = inv->getList(s.listname);
2314 warningstream<<"GUIFormSpecMenu::drawList(): "
2315 <<"The inventory list \""<<s.listname<<"\" @ \""
2316 <<s.inventoryloc.dump()<<"\" doesn't exist"
2321 core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
2323 for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
2325 s32 item_i = i + s.start_item_i;
2326 if(item_i >= (s32) ilist->getSize())
2328 s32 x = (i%s.geom.X) * spacing.X;
2329 s32 y = (i/s.geom.X) * spacing.Y;
2331 core::rect<s32> rect = imgrect + s.pos + p;
2334 item = ilist->getItem(item_i);
2336 bool selected = m_selected_item
2337 && m_invmgr->getInventory(m_selected_item->inventoryloc) == inv
2338 && m_selected_item->listname == s.listname
2339 && m_selected_item->i == item_i;
2340 bool hovering = rect.isPointInside(m_pointer);
2341 ItemRotationKind rotation_kind = selected ? IT_ROT_SELECTED :
2342 (hovering ? IT_ROT_HOVERED : IT_ROT_NONE);
2346 item_hovered = true;
2347 driver->draw2DRectangle(m_slotbg_h, rect, &AbsoluteClippingRect);
2349 driver->draw2DRectangle(m_slotbg_n, rect, &AbsoluteClippingRect);
2353 //Draw inv slot borders
2355 s32 x1 = rect.UpperLeftCorner.X;
2356 s32 y1 = rect.UpperLeftCorner.Y;
2357 s32 x2 = rect.LowerRightCorner.X;
2358 s32 y2 = rect.LowerRightCorner.Y;
2360 driver->draw2DRectangle(m_slotbordercolor,
2361 core::rect<s32>(v2s32(x1 - border, y1 - border),
2362 v2s32(x2 + border, y1)), NULL);
2363 driver->draw2DRectangle(m_slotbordercolor,
2364 core::rect<s32>(v2s32(x1 - border, y2),
2365 v2s32(x2 + border, y2 + border)), NULL);
2366 driver->draw2DRectangle(m_slotbordercolor,
2367 core::rect<s32>(v2s32(x1 - border, y1),
2368 v2s32(x1, y2)), NULL);
2369 driver->draw2DRectangle(m_slotbordercolor,
2370 core::rect<s32>(v2s32(x2, y1),
2371 v2s32(x2 + border, y2)), NULL);
2379 item.takeItem(m_selected_amount);
2383 drawItemStack(driver, m_font, item,
2384 rect, &AbsoluteClippingRect, m_client,
2389 std::wstring tooltip_text = L"";
2390 if (hovering && !m_selected_item) {
2391 const std::string &desc = item.metadata.getString("description");
2394 utf8_to_wide(item.getDefinition(m_client->idef()).description);
2396 tooltip_text = utf8_to_wide(desc);
2397 // Show itemstring as fallback for easier debugging
2398 if (!item.name.empty() && tooltip_text.empty())
2399 tooltip_text = utf8_to_wide(item.name);
2401 if (tooltip_text != L"") {
2402 std::vector<std::wstring> tt_rows = str_split(tooltip_text, L'\n');
2403 m_tooltip_element->setBackgroundColor(m_default_tooltip_bgcolor);
2404 m_tooltip_element->setOverrideColor(m_default_tooltip_color);
2405 m_tooltip_element->setVisible(true);
2406 this->bringToFront(m_tooltip_element);
2407 setStaticText(m_tooltip_element, tooltip_text.c_str());
2408 s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
2409 #if (IRRLICHT_VERSION_MAJOR <= 1 && IRRLICHT_VERSION_MINOR <= 8 && IRRLICHT_VERSION_REVISION < 2) || USE_FREETYPE == 1
2410 s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
2412 s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
2414 v2u32 screenSize = driver->getScreenSize();
2415 int tooltip_offset_x = m_btn_height;
2416 int tooltip_offset_y = m_btn_height;
2418 tooltip_offset_x *= 3;
2419 tooltip_offset_y = 0;
2420 if (m_pointer.X > (s32)screenSize.X / 2)
2421 tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1;
2423 s32 tooltip_x = m_pointer.X + tooltip_offset_x;
2424 s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
2425 if (tooltip_x + tooltip_width > (s32)screenSize.X)
2426 tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
2427 if (tooltip_y + tooltip_height > (s32)screenSize.Y)
2428 tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
2429 m_tooltip_element->setRelativePosition(core::rect<s32>(
2430 core::position2d<s32>(tooltip_x, tooltip_y),
2431 core::dimension2d<s32>(tooltip_width, tooltip_height)));
2437 void GUIFormSpecMenu::drawSelectedItem()
2439 video::IVideoDriver* driver = Environment->getVideoDriver();
2441 if (!m_selected_item) {
2442 drawItemStack(driver, m_font, ItemStack(),
2443 core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
2444 NULL, m_client, IT_ROT_DRAGGED);
2448 Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
2450 InventoryList *list = inv->getList(m_selected_item->listname);
2452 ItemStack stack = list->getItem(m_selected_item->i);
2453 stack.count = m_selected_amount;
2455 core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
2456 core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
2457 rect.constrainTo(driver->getViewPort());
2458 drawItemStack(driver, m_font, stack, rect, NULL, m_client, IT_ROT_DRAGGED);
2461 void GUIFormSpecMenu::drawMenu()
2464 std::string newform = m_form_src->getForm();
2465 if(newform != m_formspec_string){
2466 m_formspec_string = newform;
2467 regenerateGui(m_screensize_old);
2471 gui::IGUISkin* skin = Environment->getSkin();
2472 sanity_check(skin != NULL);
2473 gui::IGUIFont *old_font = skin->getFont();
2474 skin->setFont(m_font);
2476 updateSelectedItem();
2478 video::IVideoDriver* driver = Environment->getVideoDriver();
2480 v2u32 screenSize = driver->getScreenSize();
2481 core::rect<s32> allbg(0, 0, screenSize.X , screenSize.Y);
2483 driver->draw2DRectangle(m_bgcolor, allbg, &allbg);
2485 driver->draw2DRectangle(m_bgcolor, AbsoluteRect, &AbsoluteClippingRect);
2487 m_tooltip_element->setVisible(false);
2492 for(u32 i=0; i<m_backgrounds.size(); i++)
2494 const ImageDrawSpec &spec = m_backgrounds[i];
2495 video::ITexture *texture = m_tsrc->getTexture(spec.name);
2498 // Image size on screen
2499 core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
2500 // Image rectangle on screen
2501 core::rect<s32> rect = imgrect + spec.pos;
2504 core::dimension2d<s32> absrec_size = AbsoluteRect.getSize();
2505 rect = core::rect<s32>(AbsoluteRect.UpperLeftCorner.X - spec.pos.X,
2506 AbsoluteRect.UpperLeftCorner.Y - spec.pos.Y,
2507 AbsoluteRect.UpperLeftCorner.X + absrec_size.Width + spec.pos.X,
2508 AbsoluteRect.UpperLeftCorner.Y + absrec_size.Height + spec.pos.Y);
2511 const video::SColor color(255,255,255,255);
2512 const video::SColor colors[] = {color,color,color,color};
2513 draw2DImageFilterScaled(driver, texture, rect,
2514 core::rect<s32>(core::position2d<s32>(0,0),
2515 core::dimension2di(texture->getOriginalSize())),
2516 NULL/*&AbsoluteClippingRect*/, colors, true);
2518 errorstream << "GUIFormSpecMenu::drawMenu() Draw backgrounds unable to load texture:" << std::endl;
2519 errorstream << "\t" << spec.name << std::endl;
2526 for(u32 i=0; i<m_boxes.size(); i++)
2528 const BoxDrawSpec &spec = m_boxes[i];
2530 irr::video::SColor todraw = spec.color;
2532 todraw.setAlpha(140);
2534 core::rect<s32> rect(spec.pos.X,spec.pos.Y,
2535 spec.pos.X + spec.geom.X,spec.pos.Y + spec.geom.Y);
2537 driver->draw2DRectangle(todraw, rect, 0);
2543 gui::IGUIElement::draw();
2548 for(u32 i=0; i<m_images.size(); i++)
2550 const ImageDrawSpec &spec = m_images[i];
2551 video::ITexture *texture = m_tsrc->getTexture(spec.name);
2554 const core::dimension2d<u32>& img_origsize = texture->getOriginalSize();
2555 // Image size on screen
2556 core::rect<s32> imgrect;
2559 imgrect = core::rect<s32>(0,0,spec.geom.X, spec.geom.Y);
2562 imgrect = core::rect<s32>(0,0,img_origsize.Width,img_origsize.Height);
2564 // Image rectangle on screen
2565 core::rect<s32> rect = imgrect + spec.pos;
2566 const video::SColor color(255,255,255,255);
2567 const video::SColor colors[] = {color,color,color,color};
2568 draw2DImageFilterScaled(driver, texture, rect,
2569 core::rect<s32>(core::position2d<s32>(0,0),img_origsize),
2570 NULL/*&AbsoluteClippingRect*/, colors, true);
2573 errorstream << "GUIFormSpecMenu::drawMenu() Draw images unable to load texture:" << std::endl;
2574 errorstream << "\t" << spec.name << std::endl;
2581 for(u32 i=0; i<m_itemimages.size(); i++)
2586 const ImageDrawSpec &spec = m_itemimages[i];
2587 IItemDefManager *idef = m_client->idef();
2589 item.deSerialize(spec.item_name, idef);
2590 core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
2591 // Viewport rectangle on screen
2592 core::rect<s32> rect = imgrect + spec.pos;
2593 if (spec.parent_button && spec.parent_button->isPressed()) {
2594 #if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
2595 rect += core::dimension2d<s32>(
2596 0.05 * (float)rect.getWidth(), 0.05 * (float)rect.getHeight());
2598 rect += core::dimension2d<s32>(
2599 skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
2600 skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
2603 drawItemStack(driver, m_font, item, rect, &AbsoluteClippingRect,
2604 m_client, IT_ROT_NONE);
2609 Phase 0: Item slot rectangles
2610 Phase 1: Item images; prepare tooltip
2612 bool item_hovered = false;
2613 int start_phase = 0;
2614 for (int phase = start_phase; phase <= 1; phase++) {
2615 for (u32 i = 0; i < m_inventorylists.size(); i++) {
2616 drawList(m_inventorylists[i], phase, item_hovered);
2619 if (!item_hovered) {
2620 drawItemStack(driver, m_font, ItemStack(),
2621 core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
2622 NULL, m_client, IT_ROT_HOVERED);
2625 /* TODO find way to show tooltips on touchscreen */
2626 #ifndef HAVE_TOUCHSCREENGUI
2627 m_pointer = m_device->getCursorControl()->getPosition();
2631 Draw static text elements
2633 for (u32 i = 0; i < m_static_texts.size(); i++) {
2634 const StaticTextSpec &spec = m_static_texts[i];
2635 core::rect<s32> rect = spec.rect;
2636 if (spec.parent_button && spec.parent_button->isPressed()) {
2637 #if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
2638 rect += core::dimension2d<s32>(
2639 0.05 * (float)rect.getWidth(), 0.05 * (float)rect.getHeight());
2641 // Use image offset instead of text's because its a bit smaller
2642 // and fits better, also TEXT_OFFSET_X is always 0
2643 rect += core::dimension2d<s32>(
2644 skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
2645 skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
2648 video::SColor color(255, 255, 255, 255);
2649 m_font->draw(spec.text.c_str(), rect, color, true, true, &rect);
2653 Draw fields/buttons tooltips
2655 gui::IGUIElement *hovered =
2656 Environment->getRootGUIElement()->getElementFromPoint(m_pointer);
2658 if (hovered != NULL) {
2659 s32 id = hovered->getID();
2663 m_old_tooltip_id = id;
2664 m_old_tooltip = L"";
2666 if (id == m_old_tooltip_id) {
2667 delta = porting::getDeltaMs(m_hovered_time, porting::getTimeMs());
2669 m_hovered_time = porting::getTimeMs();
2670 m_old_tooltip_id = id;
2674 if (id != -1 && delta >= m_tooltip_show_delay) {
2675 for(std::vector<FieldSpec>::iterator iter = m_fields.begin();
2676 iter != m_fields.end(); ++iter) {
2677 if (iter->fid == id && m_tooltips[iter->fname].tooltip != L"") {
2678 if (m_old_tooltip != m_tooltips[iter->fname].tooltip) {
2679 m_tooltip_element->setBackgroundColor(m_tooltips[iter->fname].bgcolor);
2680 m_tooltip_element->setOverrideColor(m_tooltips[iter->fname].color);
2681 m_old_tooltip = m_tooltips[iter->fname].tooltip;
2682 setStaticText(m_tooltip_element, m_tooltips[iter->fname].tooltip.c_str());
2683 std::vector<std::wstring> tt_rows = str_split(m_tooltips[iter->fname].tooltip, L'\n');
2684 s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
2685 s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
2686 int tooltip_offset_x = m_btn_height;
2687 int tooltip_offset_y = m_btn_height;
2689 tooltip_offset_x *= 3;
2690 tooltip_offset_y = 0;
2691 if (m_pointer.X > (s32)screenSize.X / 2)
2692 tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1;
2694 s32 tooltip_x = m_pointer.X + tooltip_offset_x;
2695 s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
2696 if (tooltip_x + tooltip_width > (s32)screenSize.X)
2697 tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
2698 if (tooltip_y + tooltip_height > (s32)screenSize.Y)
2699 tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
2700 m_tooltip_element->setRelativePosition(core::rect<s32>(
2701 core::position2d<s32>(tooltip_x, tooltip_y),
2702 core::dimension2d<s32>(tooltip_width, tooltip_height)));
2704 m_tooltip_element->setVisible(true);
2705 this->bringToFront(m_tooltip_element);
2712 m_tooltip_element->draw();
2715 Draw dragged item stack
2719 skin->setFont(old_font);
2722 void GUIFormSpecMenu::updateSelectedItem()
2724 // If the selected stack has become empty for some reason, deselect it.
2725 // If the selected stack has become inaccessible, deselect it.
2726 // If the selected stack has become smaller, adjust m_selected_amount.
2727 ItemStack selected = verifySelectedItem();
2729 // WARNING: BLACK MAGIC
2730 // See if there is a stack suited for our current guess.
2731 // If such stack does not exist, clear the guess.
2732 if(m_selected_content_guess.name != "" &&
2733 selected.name == m_selected_content_guess.name &&
2734 selected.count == m_selected_content_guess.count){
2735 // Selected item fits the guess. Skip the black magic.
2737 else if(m_selected_content_guess.name != ""){
2739 for(u32 i=0; i<m_inventorylists.size() && !found; i++){
2740 const ListDrawSpec &s = m_inventorylists[i];
2741 Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
2744 InventoryList *list = inv->getList(s.listname);
2747 for(s32 i=0; i<s.geom.X*s.geom.Y && !found; i++){
2748 u32 item_i = i + s.start_item_i;
2749 if(item_i >= list->getSize())
2751 ItemStack stack = list->getItem(item_i);
2752 if(stack.name == m_selected_content_guess.name &&
2753 stack.count == m_selected_content_guess.count){
2755 infostream<<"Client: Changing selected content guess to "
2756 <<s.inventoryloc.dump()<<" "<<s.listname
2757 <<" "<<item_i<<std::endl;
2758 delete m_selected_item;
2759 m_selected_item = new ItemSpec(s.inventoryloc, s.listname, item_i);
2760 m_selected_amount = stack.count;
2765 infostream<<"Client: Discarding selected content guess: "
2766 <<m_selected_content_guess.getItemString()<<std::endl;
2767 m_selected_content_guess.name = "";
2771 // If craftresult is nonempty and nothing else is selected, select it now.
2772 if(!m_selected_item)
2774 for(u32 i=0; i<m_inventorylists.size(); i++)
2776 const ListDrawSpec &s = m_inventorylists[i];
2777 if(s.listname == "craftpreview")
2779 Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
2780 InventoryList *list = inv->getList("craftresult");
2781 if(list && list->getSize() >= 1 && !list->getItem(0).empty())
2783 m_selected_item = new ItemSpec;
2784 m_selected_item->inventoryloc = s.inventoryloc;
2785 m_selected_item->listname = "craftresult";
2786 m_selected_item->i = 0;
2787 m_selected_amount = 0;
2788 m_selected_dragging = false;
2795 // If craftresult is selected, keep the whole stack selected
2796 if(m_selected_item && m_selected_item->listname == "craftresult")
2798 m_selected_amount = verifySelectedItem().count;
2802 ItemStack GUIFormSpecMenu::verifySelectedItem()
2804 // If the selected stack has become empty for some reason, deselect it.
2805 // If the selected stack has become inaccessible, deselect it.
2806 // If the selected stack has become smaller, adjust m_selected_amount.
2807 // Return the selected stack.
2811 if(m_selected_item->isValid())
2813 Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
2816 InventoryList *list = inv->getList(m_selected_item->listname);
2817 if(list && (u32) m_selected_item->i < list->getSize())
2819 ItemStack stack = list->getItem(m_selected_item->i);
2820 if(m_selected_amount > stack.count)
2821 m_selected_amount = stack.count;
2828 // selection was not valid
2829 delete m_selected_item;
2830 m_selected_item = NULL;
2831 m_selected_amount = 0;
2832 m_selected_dragging = false;
2837 void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
2843 if (quitmode == quit_mode_accept) {
2844 fields["quit"] = "true";
2847 if (quitmode == quit_mode_cancel) {
2848 fields["quit"] = "true";
2849 m_text_dst->gotText(fields);
2853 if (current_keys_pending.key_down) {
2854 fields["key_down"] = "true";
2855 current_keys_pending.key_down = false;
2858 if (current_keys_pending.key_up) {
2859 fields["key_up"] = "true";
2860 current_keys_pending.key_up = false;
2863 if (current_keys_pending.key_enter) {
2864 fields["key_enter"] = "true";
2865 current_keys_pending.key_enter = false;
2868 if (!current_field_enter_pending.empty()) {
2869 fields["key_enter_field"] = current_field_enter_pending;
2870 current_field_enter_pending = "";
2873 if (current_keys_pending.key_escape) {
2874 fields["key_escape"] = "true";
2875 current_keys_pending.key_escape = false;
2878 for(unsigned int i=0; i<m_fields.size(); i++) {
2879 const FieldSpec &s = m_fields[i];
2881 std::string name = s.fname;
2882 if (s.ftype == f_Button) {
2883 fields[name] = wide_to_utf8(s.flabel);
2884 } else if (s.ftype == f_Table) {
2885 GUITable *table = getTable(s.fname);
2887 fields[name] = table->checkEvent();
2890 else if(s.ftype == f_DropDown) {
2891 // no dynamic cast possible due to some distributions shipped
2892 // without rtti support in irrlicht
2893 IGUIElement * element = getElementFromId(s.fid);
2894 gui::IGUIComboBox *e = NULL;
2895 if ((element) && (element->getType() == gui::EGUIET_COMBO_BOX)) {
2896 e = static_cast<gui::IGUIComboBox*>(element);
2898 s32 selected = e->getSelected();
2899 if (selected >= 0) {
2900 std::vector<std::string> *dropdown_values =
2901 getDropDownValues(s.fname);
2902 if (dropdown_values && selected < (s32)dropdown_values->size()) {
2903 fields[name] = (*dropdown_values)[selected];
2907 else if (s.ftype == f_TabHeader) {
2908 // no dynamic cast possible due to some distributions shipped
2909 // without rtti support in irrlicht
2910 IGUIElement * element = getElementFromId(s.fid);
2911 gui::IGUITabControl *e = NULL;
2912 if ((element) && (element->getType() == gui::EGUIET_TAB_CONTROL)) {
2913 e = static_cast<gui::IGUITabControl*>(element);
2917 std::stringstream ss;
2918 ss << (e->getActiveTab() +1);
2919 fields[name] = ss.str();
2922 else if (s.ftype == f_CheckBox) {
2923 // no dynamic cast possible due to some distributions shipped
2924 // without rtti support in irrlicht
2925 IGUIElement * element = getElementFromId(s.fid);
2926 gui::IGUICheckBox *e = NULL;
2927 if ((element) && (element->getType() == gui::EGUIET_CHECK_BOX)) {
2928 e = static_cast<gui::IGUICheckBox*>(element);
2933 fields[name] = "true";
2935 fields[name] = "false";
2938 else if (s.ftype == f_ScrollBar) {
2939 // no dynamic cast possible due to some distributions shipped
2940 // without rtti support in irrlicht
2941 IGUIElement * element = getElementFromId(s.fid);
2942 gui::IGUIScrollBar *e = NULL;
2943 if ((element) && (element->getType() == gui::EGUIET_SCROLL_BAR)) {
2944 e = static_cast<gui::IGUIScrollBar*>(element);
2948 std::stringstream os;
2950 if (s.fdefault == L"Changed")
2951 fields[name] = "CHG:" + os.str();
2953 fields[name] = "VAL:" + os.str();
2958 IGUIElement* e = getElementFromId(s.fid);
2960 fields[name] = wide_to_utf8(e->getText());
2966 m_text_dst->gotText(fields);
2970 static bool isChild(gui::IGUIElement * tocheck, gui::IGUIElement * parent)
2972 while(tocheck != NULL) {
2973 if (tocheck == parent) {
2976 tocheck = tocheck->getParent();
2981 bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
2983 // The IGUITabControl renders visually using the skin's selected
2984 // font, which we override for the duration of form drawing,
2985 // but computes tab hotspots based on how it would have rendered
2986 // using the font that is selected at the time of button release.
2987 // To make these two consistent, temporarily override the skin's
2988 // font while the IGUITabControl is processing the event.
2989 if (event.EventType == EET_MOUSE_INPUT_EVENT &&
2990 event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
2991 s32 x = event.MouseInput.X;
2992 s32 y = event.MouseInput.Y;
2993 gui::IGUIElement *hovered =
2994 Environment->getRootGUIElement()->getElementFromPoint(
2995 core::position2d<s32>(x, y));
2996 if (hovered && isMyChild(hovered) &&
2997 hovered->getType() == gui::EGUIET_TAB_CONTROL) {
2998 gui::IGUISkin* skin = Environment->getSkin();
2999 sanity_check(skin != NULL);
3000 gui::IGUIFont *old_font = skin->getFont();
3001 skin->setFont(m_font);
3002 bool retval = hovered->OnEvent(event);
3003 skin->setFont(old_font);
3008 // Fix Esc/Return key being eaten by checkboxen and tables
3009 if(event.EventType==EET_KEY_INPUT_EVENT) {
3010 KeyPress kp(event.KeyInput);
3011 if (kp == EscapeKey || kp == CancelKey
3012 || kp == getKeySetting("keymap_inventory")
3013 || event.KeyInput.Key==KEY_RETURN) {
3014 gui::IGUIElement *focused = Environment->getFocus();
3015 if (focused && isMyChild(focused) &&
3016 (focused->getType() == gui::EGUIET_LIST_BOX ||
3017 focused->getType() == gui::EGUIET_CHECK_BOX)) {
3023 // Mouse wheel events: send to hovered element instead of focused
3024 if(event.EventType==EET_MOUSE_INPUT_EVENT
3025 && event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
3026 s32 x = event.MouseInput.X;
3027 s32 y = event.MouseInput.Y;
3028 gui::IGUIElement *hovered =
3029 Environment->getRootGUIElement()->getElementFromPoint(
3030 core::position2d<s32>(x, y));
3031 if (hovered && isMyChild(hovered)) {
3032 hovered->OnEvent(event);
3037 if (event.EventType == EET_MOUSE_INPUT_EVENT) {
3038 s32 x = event.MouseInput.X;
3039 s32 y = event.MouseInput.Y;
3040 gui::IGUIElement *hovered =
3041 Environment->getRootGUIElement()->getElementFromPoint(
3042 core::position2d<s32>(x, y));
3043 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
3044 m_old_tooltip_id = -1;
3045 m_old_tooltip = L"";
3047 if (!isChild(hovered,this)) {
3048 if (DoubleClickDetection(event)) {
3055 // display software keyboard when clicking edit boxes
3056 if (event.EventType == EET_MOUSE_INPUT_EVENT
3057 && event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
3058 gui::IGUIElement *hovered =
3059 Environment->getRootGUIElement()->getElementFromPoint(
3060 core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
3061 if ((hovered) && (hovered->getType() == irr::gui::EGUIET_EDIT_BOX)) {
3062 bool retval = hovered->OnEvent(event);
3064 Environment->setFocus(hovered);
3066 m_JavaDialogFieldName = getNameByID(hovered->getID());
3067 std::string message = gettext("Enter ");
3068 std::string label = wide_to_utf8(getLabelByID(hovered->getID()));
3072 message += gettext(label) + ":";
3074 /* single line text input */
3077 /* multi line text input */
3078 if (((gui::IGUIEditBox*) hovered)->isMultiLineEnabled()) {
3082 /* passwords are always single line */
3083 if (((gui::IGUIEditBox*) hovered)->isPasswordBox()) {
3087 porting::showInputDialog(gettext("ok"), "",
3088 wide_to_utf8(((gui::IGUIEditBox*) hovered)->getText()),
3094 if (event.EventType == EET_TOUCH_INPUT_EVENT)
3097 memset(&translated, 0, sizeof(SEvent));
3098 translated.EventType = EET_MOUSE_INPUT_EVENT;
3099 gui::IGUIElement* root = Environment->getRootGUIElement();
3103 << "GUIFormSpecMenu::preprocessEvent unable to get root element"
3107 gui::IGUIElement* hovered = root->getElementFromPoint(
3108 core::position2d<s32>(
3110 event.TouchInput.Y));
3112 translated.MouseInput.X = event.TouchInput.X;
3113 translated.MouseInput.Y = event.TouchInput.Y;
3114 translated.MouseInput.Control = false;
3116 bool dont_send_event = false;
3118 if (event.TouchInput.touchedCount == 1) {
3119 switch (event.TouchInput.Event) {
3120 case ETIE_PRESSED_DOWN:
3121 m_pointer = v2s32(event.TouchInput.X,event.TouchInput.Y);
3122 translated.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
3123 translated.MouseInput.ButtonStates = EMBSM_LEFT;
3124 m_down_pos = m_pointer;
3127 m_pointer = v2s32(event.TouchInput.X,event.TouchInput.Y);
3128 translated.MouseInput.Event = EMIE_MOUSE_MOVED;
3129 translated.MouseInput.ButtonStates = EMBSM_LEFT;
3132 translated.MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
3133 translated.MouseInput.ButtonStates = 0;
3134 hovered = root->getElementFromPoint(m_down_pos);
3135 /* we don't have a valid pointer element use last
3136 * known pointer pos */
3137 translated.MouseInput.X = m_pointer.X;
3138 translated.MouseInput.Y = m_pointer.Y;
3140 /* reset down pos */
3141 m_down_pos = v2s32(0,0);
3144 dont_send_event = true;
3145 //this is not supposed to happen
3147 << "GUIFormSpecMenu::preprocessEvent unexpected usecase Event="
3148 << event.TouchInput.Event << std::endl;
3150 } else if ( (event.TouchInput.touchedCount == 2) &&
3151 (event.TouchInput.Event == ETIE_PRESSED_DOWN) ) {
3152 hovered = root->getElementFromPoint(m_down_pos);
3154 translated.MouseInput.Event = EMIE_RMOUSE_PRESSED_DOWN;
3155 translated.MouseInput.ButtonStates = EMBSM_LEFT | EMBSM_RIGHT;
3156 translated.MouseInput.X = m_pointer.X;
3157 translated.MouseInput.Y = m_pointer.Y;
3160 hovered->OnEvent(translated);
3163 translated.MouseInput.Event = EMIE_RMOUSE_LEFT_UP;
3164 translated.MouseInput.ButtonStates = EMBSM_LEFT;
3168 hovered->OnEvent(translated);
3170 dont_send_event = true;
3172 /* ignore unhandled 2 touch events ... accidental moving for example */
3173 else if (event.TouchInput.touchedCount == 2) {
3174 dont_send_event = true;
3176 else if (event.TouchInput.touchedCount > 2) {
3178 << "GUIFormSpecMenu::preprocessEvent to many multitouch events "
3179 << event.TouchInput.touchedCount << " ignoring them" << std::endl;
3182 if (dont_send_event) {
3186 /* check if translated event needs to be preprocessed again */
3187 if (preprocessEvent(translated)) {
3192 bool retval = hovered->OnEvent(translated);
3194 if (event.TouchInput.Event == ETIE_LEFT_UP) {
3196 m_pointer = v2s32(0,0);
3204 if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
3205 /* TODO add a check like:
3206 if (event.JoystickEvent != joystick_we_listen_for)
3209 bool handled = m_joystick->handleEvent(event.JoystickEvent);
3211 if (m_joystick->wasKeyDown(KeyType::ESC)) {
3213 } else if (m_joystick->wasKeyDown(KeyType::JUMP)) {
3215 acceptInput(quit_mode_accept);
3226 /******************************************************************************/
3227 bool GUIFormSpecMenu::DoubleClickDetection(const SEvent event)
3229 /* The following code is for capturing double-clicks of the mouse button
3230 * and translating the double-click into an EET_KEY_INPUT_EVENT event
3231 * -- which closes the form -- under some circumstances.
3233 * There have been many github issues reporting this as a bug even though it
3234 * was an intended feature. For this reason, remapping the double-click as
3235 * an ESC must be explicitly set when creating this class via the
3236 * /p remap_dbl_click parameter of the constructor.
3239 if (!m_remap_dbl_click)
3242 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
3243 m_doubleclickdetect[0].pos = m_doubleclickdetect[1].pos;
3244 m_doubleclickdetect[0].time = m_doubleclickdetect[1].time;
3246 m_doubleclickdetect[1].pos = m_pointer;
3247 m_doubleclickdetect[1].time = porting::getTimeMs();
3249 else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
3250 u32 delta = porting::getDeltaMs(m_doubleclickdetect[0].time, porting::getTimeMs());
3255 double squaredistance =
3256 m_doubleclickdetect[0].pos
3257 .getDistanceFromSQ(m_doubleclickdetect[1].pos);
3259 if (squaredistance > (30*30)) {
3263 SEvent* translated = new SEvent();
3264 assert(translated != 0);
3265 //translate doubleclick to escape
3266 memset(translated, 0, sizeof(SEvent));
3267 translated->EventType = irr::EET_KEY_INPUT_EVENT;
3268 translated->KeyInput.Key = KEY_ESCAPE;
3269 translated->KeyInput.Control = false;
3270 translated->KeyInput.Shift = false;
3271 translated->KeyInput.PressedDown = true;
3272 translated->KeyInput.Char = 0;
3273 OnEvent(*translated);
3275 // no need to send the key up event as we're already deleted
3276 // and no one else did notice this event
3284 void GUIFormSpecMenu::tryClose()
3288 acceptInput(quit_mode_cancel);
3291 m_text_dst->gotText(L"MenuQuit");
3295 bool GUIFormSpecMenu::OnEvent(const SEvent& event)
3297 if (event.EventType==EET_KEY_INPUT_EVENT) {
3298 KeyPress kp(event.KeyInput);
3299 if (event.KeyInput.PressedDown && (
3300 (kp == EscapeKey) || (kp == CancelKey) ||
3301 ((m_client != NULL) && (kp == getKeySetting("keymap_inventory"))))) {
3304 } else if (m_client != NULL && event.KeyInput.PressedDown &&
3305 (kp == getKeySetting("keymap_screenshot"))) {
3306 m_client->makeScreenshot(m_device);
3308 if (event.KeyInput.PressedDown &&
3309 (event.KeyInput.Key==KEY_RETURN ||
3310 event.KeyInput.Key==KEY_UP ||
3311 event.KeyInput.Key==KEY_DOWN)
3313 switch (event.KeyInput.Key) {
3315 current_keys_pending.key_enter = true;
3318 current_keys_pending.key_up = true;
3321 current_keys_pending.key_down = true;
3325 //can't happen at all!
3326 FATAL_ERROR("Reached a source line that can't ever been reached");
3329 if (current_keys_pending.key_enter && m_allowclose) {
3330 acceptInput(quit_mode_accept);
3340 /* Mouse event other than movement, or crossing the border of inventory
3341 field while holding right mouse button
3343 if (event.EventType == EET_MOUSE_INPUT_EVENT &&
3344 (event.MouseInput.Event != EMIE_MOUSE_MOVED ||
3345 (event.MouseInput.Event == EMIE_MOUSE_MOVED &&
3346 event.MouseInput.isRightPressed() &&
3347 getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i))) {
3349 // Get selected item and hovered/clicked item (s)
3351 m_old_tooltip_id = -1;
3352 updateSelectedItem();
3353 ItemSpec s = getItemAtPos(m_pointer);
3355 Inventory *inv_selected = NULL;
3356 Inventory *inv_s = NULL;
3357 InventoryList *list_s = NULL;
3359 if (m_selected_item) {
3360 inv_selected = m_invmgr->getInventory(m_selected_item->inventoryloc);
3361 sanity_check(inv_selected);
3362 sanity_check(inv_selected->getList(m_selected_item->listname) != NULL);
3369 inv_s = m_invmgr->getInventory(s.inventoryloc);
3372 errorstream << "InventoryMenu: The selected inventory location "
3373 << "\"" << s.inventoryloc.dump() << "\" doesn't exist"
3375 s.i = -1; // make it invalid again
3379 list_s = inv_s->getList(s.listname);
3380 if (list_s == NULL) {
3381 verbosestream << "InventoryMenu: The selected inventory list \""
3382 << s.listname << "\" does not exist" << std::endl;
3383 s.i = -1; // make it invalid again
3387 if ((u32)s.i >= list_s->getSize()) {
3388 infostream << "InventoryMenu: The selected inventory list \""
3389 << s.listname << "\" is too small (i=" << s.i << ", size="
3390 << list_s->getSize() << ")" << std::endl;
3391 s.i = -1; // make it invalid again
3395 s_count = list_s->getItem(s.i).count;
3398 bool identical = (m_selected_item != NULL) && s.isValid() &&
3399 (inv_selected == inv_s) &&
3400 (m_selected_item->listname == s.listname) &&
3401 (m_selected_item->i == s.i);
3403 // buttons: 0 = left, 1 = right, 2 = middle
3404 // up/down: 0 = down (press), 1 = up (release), 2 = unknown event, -1 movement
3407 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
3408 { button = 0; updown = 0; }
3409 else if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
3410 { button = 1; updown = 0; }
3411 else if (event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN)
3412 { button = 2; updown = 0; }
3413 else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
3414 { button = 0; updown = 1; }
3415 else if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
3416 { button = 1; updown = 1; }
3417 else if (event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP)
3418 { button = 2; updown = 1; }
3419 else if (event.MouseInput.Event == EMIE_MOUSE_MOVED)
3422 // Set this number to a positive value to generate a move action
3423 // from m_selected_item to s.
3424 u32 move_amount = 0;
3426 // Set this number to a positive value to generate a move action
3427 // from s to the next inventory ring.
3428 u32 shift_move_amount = 0;
3430 // Set this number to a positive value to generate a drop action
3431 // from m_selected_item.
3432 u32 drop_amount = 0;
3434 // Set this number to a positive value to generate a craft action at s.
3435 u32 craft_amount = 0;
3438 // Some mouse button has been pressed
3440 //infostream<<"Mouse button "<<button<<" pressed at p=("
3441 // <<p.X<<","<<p.Y<<")"<<std::endl;
3443 m_selected_dragging = false;
3445 if (s.isValid() && s.listname == "craftpreview") {
3446 // Craft preview has been clicked: craft
3447 craft_amount = (button == 2 ? 10 : 1);
3448 } else if (m_selected_item == NULL) {
3450 // Non-empty stack has been clicked: select or shift-move it
3451 m_selected_item = new ItemSpec(s);
3454 if (button == 1) // right
3455 count = (s_count + 1) / 2;
3456 else if (button == 2) // middle
3457 count = MYMIN(s_count, 10);
3461 if (!event.MouseInput.Shift) {
3462 // no shift: select item
3463 m_selected_amount = count;
3464 m_selected_dragging = true;
3465 m_rmouse_auto_place = false;
3467 // shift pressed: move item
3469 shift_move_amount = count;
3470 else // count of 1 at left click like after drag & drop
3471 shift_move_amount = 1;
3474 } else { // m_selected_item != NULL
3475 assert(m_selected_amount >= 1);
3478 // Clicked a slot: move
3479 if (button == 1) // right
3481 else if (button == 2) // middle
3482 move_amount = MYMIN(m_selected_amount, 10);
3484 move_amount = m_selected_amount;
3487 if (move_amount >= m_selected_amount)
3488 m_selected_amount = 0;
3490 m_selected_amount -= move_amount;
3494 else if (!getAbsoluteClippingRect().isPointInside(m_pointer)) {
3495 // Clicked outside of the window: drop
3496 if (button == 1) // right
3498 else if (button == 2) // middle
3499 drop_amount = MYMIN(m_selected_amount, 10);
3501 drop_amount = m_selected_amount;
3505 else if (updown == 1) {
3506 // Some mouse button has been released
3508 //infostream<<"Mouse button "<<button<<" released at p=("
3509 // <<p.X<<","<<p.Y<<")"<<std::endl;
3511 if (m_selected_item != NULL && m_selected_dragging && s.isValid()) {
3513 // Dragged to different slot: move all selected
3514 move_amount = m_selected_amount;
3516 } else if (m_selected_item != NULL && m_selected_dragging &&
3517 !(getAbsoluteClippingRect().isPointInside(m_pointer))) {
3518 // Dragged outside of window: drop all selected
3519 drop_amount = m_selected_amount;
3522 m_selected_dragging = false;
3523 // Keep count of how many times right mouse button has been
3524 // clicked. One click is drag without dropping. Click + release
3525 // + click changes to drop one item when moved mode
3526 if (button == 1 && m_selected_item != NULL)
3527 m_rmouse_auto_place = !m_rmouse_auto_place;
3528 } else if (updown == -1) {
3529 // Mouse has been moved and rmb is down and mouse pointer just
3530 // entered a new inventory field (checked in the entry-if, this
3531 // is the only action here that is generated by mouse movement)
3532 if (m_selected_item != NULL && s.isValid()) {
3534 // TODO: middle mouse to move 10 items might be handy
3535 if (m_rmouse_auto_place) {
3536 // Only move an item if the destination slot is empty
3537 // or contains the same item type as what is going to be
3539 InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
3540 InventoryList *list_to = list_s;
3541 assert(list_from && list_to);
3542 ItemStack stack_from = list_from->getItem(m_selected_item->i);
3543 ItemStack stack_to = list_to->getItem(s.i);
3544 if (stack_to.empty() || stack_to.name == stack_from.name)
3550 // Possibly send inventory action to server
3551 if (move_amount > 0) {
3552 // Send IACTION_MOVE
3554 assert(m_selected_item && m_selected_item->isValid());
3555 assert(s.isValid());
3557 assert(inv_selected && inv_s);
3558 InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
3559 InventoryList *list_to = list_s;
3560 assert(list_from && list_to);
3561 ItemStack stack_from = list_from->getItem(m_selected_item->i);
3562 ItemStack stack_to = list_to->getItem(s.i);
3564 // Check how many items can be moved
3565 move_amount = stack_from.count = MYMIN(move_amount, stack_from.count);
3566 ItemStack leftover = stack_to.addItem(stack_from, m_client->idef());
3567 // If source stack cannot be added to destination stack at all,
3569 if ((leftover.count == stack_from.count) &&
3570 (leftover.name == stack_from.name)) {
3571 m_selected_amount = stack_to.count;
3572 // In case the server doesn't directly swap them but instead
3573 // moves stack_to somewhere else, set this
3574 m_selected_content_guess = stack_to;
3575 m_selected_content_guess_inventory = s.inventoryloc;
3577 // Source stack goes fully into destination stack
3578 else if (leftover.empty()) {
3579 m_selected_amount -= move_amount;
3580 m_selected_content_guess = ItemStack(); // Clear
3582 // Source stack goes partly into destination stack
3584 move_amount -= leftover.count;
3585 m_selected_amount -= move_amount;
3586 m_selected_content_guess = ItemStack(); // Clear
3589 infostream << "Handing IACTION_MOVE to manager" << std::endl;
3590 IMoveAction *a = new IMoveAction();
3591 a->count = move_amount;
3592 a->from_inv = m_selected_item->inventoryloc;
3593 a->from_list = m_selected_item->listname;
3594 a->from_i = m_selected_item->i;
3595 a->to_inv = s.inventoryloc;
3596 a->to_list = s.listname;
3598 m_invmgr->inventoryAction(a);
3599 } else if (shift_move_amount > 0) {
3600 u32 mis = m_inventory_rings.size();
3602 for (; i < mis; i++) {
3603 const ListRingSpec &sp = m_inventory_rings[i];
3604 if (sp.inventoryloc == s.inventoryloc
3605 && sp.listname == s.listname)
3609 if (i >= mis) // if not found
3611 u32 to_inv_ind = (i + 1) % mis;
3612 const ListRingSpec &to_inv_sp = m_inventory_rings[to_inv_ind];
3613 InventoryList *list_from = list_s;
3616 Inventory *inv_to = m_invmgr->getInventory(to_inv_sp.inventoryloc);
3619 InventoryList *list_to = inv_to->getList(to_inv_sp.listname);
3622 ItemStack stack_from = list_from->getItem(s.i);
3623 assert(shift_move_amount <= stack_from.count);
3624 if (m_client->getProtoVersion() >= 25) {
3625 infostream << "Handing IACTION_MOVE to manager" << std::endl;
3626 IMoveAction *a = new IMoveAction();
3627 a->count = shift_move_amount;
3628 a->from_inv = s.inventoryloc;
3629 a->from_list = s.listname;
3631 a->to_inv = to_inv_sp.inventoryloc;
3632 a->to_list = to_inv_sp.listname;
3633 a->move_somewhere = true;
3634 m_invmgr->inventoryAction(a);
3636 // find a place (or more than one) to add the new item
3637 u32 ilt_size = list_to->getSize();
3639 for (u32 slot_to = 0; slot_to < ilt_size
3640 && shift_move_amount > 0; slot_to++) {
3641 list_to->itemFits(slot_to, stack_from, &leftover);
3642 if (leftover.count < stack_from.count) {
3643 infostream << "Handing IACTION_MOVE to manager" << std::endl;
3644 IMoveAction *a = new IMoveAction();
3645 a->count = MYMIN(shift_move_amount,
3646 (u32) (stack_from.count - leftover.count));
3647 shift_move_amount -= a->count;
3648 a->from_inv = s.inventoryloc;
3649 a->from_list = s.listname;
3651 a->to_inv = to_inv_sp.inventoryloc;
3652 a->to_list = to_inv_sp.listname;
3654 m_invmgr->inventoryAction(a);
3655 stack_from = leftover;
3660 } else if (drop_amount > 0) {
3661 m_selected_content_guess = ItemStack(); // Clear
3663 // Send IACTION_DROP
3665 assert(m_selected_item && m_selected_item->isValid());
3666 assert(inv_selected);
3667 InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
3669 ItemStack stack_from = list_from->getItem(m_selected_item->i);
3671 // Check how many items can be dropped
3672 drop_amount = stack_from.count = MYMIN(drop_amount, stack_from.count);
3673 assert(drop_amount > 0 && drop_amount <= m_selected_amount);
3674 m_selected_amount -= drop_amount;
3676 infostream << "Handing IACTION_DROP to manager" << std::endl;
3677 IDropAction *a = new IDropAction();
3678 a->count = drop_amount;
3679 a->from_inv = m_selected_item->inventoryloc;
3680 a->from_list = m_selected_item->listname;
3681 a->from_i = m_selected_item->i;
3682 m_invmgr->inventoryAction(a);
3683 } else if (craft_amount > 0) {
3684 m_selected_content_guess = ItemStack(); // Clear
3686 // Send IACTION_CRAFT
3688 assert(s.isValid());
3691 infostream << "Handing IACTION_CRAFT to manager" << std::endl;
3692 ICraftAction *a = new ICraftAction();
3693 a->count = craft_amount;
3694 a->craft_inv = s.inventoryloc;
3695 m_invmgr->inventoryAction(a);
3698 // If m_selected_amount has been decreased to zero, deselect
3699 if (m_selected_amount == 0) {
3700 delete m_selected_item;
3701 m_selected_item = NULL;
3702 m_selected_amount = 0;
3703 m_selected_dragging = false;
3704 m_selected_content_guess = ItemStack();
3706 m_old_pointer = m_pointer;
3708 if (event.EventType == EET_GUI_EVENT) {
3710 if (event.GUIEvent.EventType == gui::EGET_TAB_CHANGED
3712 // find the element that was clicked
3713 for (unsigned int i=0; i<m_fields.size(); i++) {
3714 FieldSpec &s = m_fields[i];
3715 if ((s.ftype == f_TabHeader) &&
3716 (s.fid == event.GUIEvent.Caller->getID())) {
3724 if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST
3726 if (!canTakeFocus(event.GUIEvent.Element)) {
3727 infostream<<"GUIFormSpecMenu: Not allowing focus change."
3729 // Returning true disables focus change
3733 if ((event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) ||
3734 (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) ||
3735 (event.GUIEvent.EventType == gui::EGET_COMBO_BOX_CHANGED) ||
3736 (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED)) {
3737 unsigned int btn_id = event.GUIEvent.Caller->getID();
3739 if (btn_id == 257) {
3741 acceptInput(quit_mode_accept);
3745 m_text_dst->gotText(L"ExitButton");
3747 // quitMenu deallocates menu
3751 // find the element that was clicked
3752 for (u32 i = 0; i < m_fields.size(); i++) {
3753 FieldSpec &s = m_fields[i];
3754 // if its a button, set the send field so
3755 // lua knows which button was pressed
3756 if (((s.ftype == f_Button) || (s.ftype == f_CheckBox)) &&
3757 (s.fid == event.GUIEvent.Caller->getID())) {
3761 acceptInput(quit_mode_accept);
3764 m_text_dst->gotText(L"ExitButton");
3768 acceptInput(quit_mode_no);
3772 } else if ((s.ftype == f_DropDown) &&
3773 (s.fid == event.GUIEvent.Caller->getID())) {
3774 // only send the changed dropdown
3775 for (u32 i = 0; i < m_fields.size(); i++) {
3776 FieldSpec &s2 = m_fields[i];
3777 if (s2.ftype == f_DropDown) {
3782 acceptInput(quit_mode_no);
3784 // revert configuration to make sure dropdowns are sent on
3785 // regular button click
3786 for (u32 i = 0; i < m_fields.size(); i++) {
3787 FieldSpec &s2 = m_fields[i];
3788 if (s2.ftype == f_DropDown) {
3793 } else if ((s.ftype == f_ScrollBar) &&
3794 (s.fid == event.GUIEvent.Caller->getID())) {
3795 s.fdefault = L"Changed";
3796 acceptInput(quit_mode_no);
3802 if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
3803 if (event.GUIEvent.Caller->getID() > 257) {
3804 bool close_on_enter = true;
3805 for (u32 i = 0; i < m_fields.size(); i++) {
3806 FieldSpec &s = m_fields[i];
3807 if (s.ftype == f_Unknown &&
3808 s.fid == event.GUIEvent.Caller->getID()) {
3809 current_field_enter_pending = s.fname;
3810 UNORDERED_MAP<std::string, bool>::const_iterator it =
3811 field_close_on_enter.find(s.fname);
3812 if (it != field_close_on_enter.end())
3813 close_on_enter = (*it).second;
3819 if (m_allowclose && close_on_enter) {
3820 current_keys_pending.key_enter = true;
3821 acceptInput(quit_mode_accept);
3824 current_keys_pending.key_enter = true;
3827 // quitMenu deallocates menu
3832 if (event.GUIEvent.EventType == gui::EGET_TABLE_CHANGED) {
3833 int current_id = event.GUIEvent.Caller->getID();
3834 if (current_id > 257) {
3835 // find the element that was clicked
3836 for (u32 i = 0; i < m_fields.size(); i++) {
3837 FieldSpec &s = m_fields[i];
3838 // if it's a table, set the send field
3839 // so lua knows which table was changed
3840 if ((s.ftype == f_Table) && (s.fid == current_id)) {
3851 return Parent ? Parent->OnEvent(event) : false;
3855 * get name of element by element id
3856 * @param id of element
3857 * @return name string or empty string
3859 std::string GUIFormSpecMenu::getNameByID(s32 id)
3861 for(std::vector<FieldSpec>::iterator iter = m_fields.begin();
3862 iter != m_fields.end(); ++iter) {
3863 if (iter->fid == id) {
3871 * get label of element by id
3872 * @param id of element
3873 * @return label string or empty string
3875 std::wstring GUIFormSpecMenu::getLabelByID(s32 id)
3877 for(std::vector<FieldSpec>::iterator iter = m_fields.begin();
3878 iter != m_fields.end(); ++iter) {
3879 if (iter->fid == id) {
3880 return iter->flabel;