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"
27 #include "constants.h"
31 #include <IGUICheckBox.h>
32 #include <IGUIEditBox.h>
33 #include <IGUIButton.h>
34 #include <IGUIStaticText.h>
36 #include <IGUIListBox.h>
37 #include <IGUITabControl.h>
38 #include <IGUIScrollBar.h>
39 #include <IGUIComboBox.h>
41 #include "tile.h" // ITextureSource
42 #include "hud.h" // drawItemStack
43 #include "util/string.h"
44 #include "util/numeric.h"
50 #define MY_CHECKPOS(a,b) \
51 if (v_pos.size() != 2) { \
52 errorstream<< "Invalid pos for element " << a << "specified: \"" \
53 << parts[b] << "\"" << std::endl; \
57 #define MY_CHECKGEOM(a,b) \
58 if (v_geom.size() != 2) { \
59 errorstream<< "Invalid pos for element " << a << "specified: \"" \
60 << parts[b] << "\"" << std::endl; \
69 GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
70 gui::IGUIElement* parent, s32 id,
71 IMenuManager *menumgr,
72 InventoryManager *invmgr,
75 GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
81 m_selected_item(NULL),
83 m_selected_dragging(false),
84 m_tooltip_element(NULL),
89 current_keys_pending.key_down = false;
90 current_keys_pending.key_up = false;
91 current_keys_pending.key_enter = false;
92 current_keys_pending.key_escape = false;
96 GUIFormSpecMenu::~GUIFormSpecMenu()
100 delete m_selected_item;
105 void GUIFormSpecMenu::removeChildren()
107 const core::list<gui::IGUIElement*> &children = getChildren();
108 core::list<gui::IGUIElement*> children_copy;
109 for(core::list<gui::IGUIElement*>::ConstIterator
110 i = children.begin(); i != children.end(); i++)
112 children_copy.push_back(*i);
114 for(core::list<gui::IGUIElement*>::Iterator
115 i = children_copy.begin();
116 i != children_copy.end(); i++)
121 gui::IGUIElement *e = getElementFromId(256);
125 if(m_tooltip_element)
127 m_tooltip_element->remove();
128 m_tooltip_element = NULL;
132 int GUIFormSpecMenu::getListboxIndex(std::string listboxname) {
134 std::wstring wlistboxname = narrow_to_wide(listboxname.c_str());
136 for(unsigned int i=0; i < m_listboxes.size(); i++) {
138 std::wstring name(m_listboxes[i].first.fname.c_str());
139 if ( name == wlistboxname) {
140 return m_listboxes[i].second->getSelected();
146 std::vector<std::string> split(const std::string &s, char delim) {
147 std::vector<std::string> tokens;
149 std::string current = "";
150 bool last_was_escape = false;
151 for(unsigned int i=0; i < s.size(); i++) {
152 if (last_was_escape) {
154 current += s.c_str()[i];
155 last_was_escape = false;
158 if (s.c_str()[i] == delim) {
159 tokens.push_back(current);
161 last_was_escape = false;
163 else if (s.c_str()[i] == '\\'){
164 last_was_escape = true;
167 current += s.c_str()[i];
168 last_was_escape = false;
173 tokens.push_back(current);
178 void GUIFormSpecMenu::parseSize(parserData* data,std::string element) {
179 std::vector<std::string> parts = split(element,',');
181 if (parts.size() == 2) {
184 if (parts[1].find(';') != std::string::npos)
185 parts[1] = parts[1].substr(0,parts[1].find(';'));
187 invsize.X = stof(parts[0]);
188 invsize.Y = stof(parts[1]);
190 infostream<<"Form size ("<<invsize.X<<","<<invsize.Y<<")"<<std::endl;
193 v2u32 current_screensize = m_device->getVideoDriver()->getScreenSize();
194 v2u32 delta = current_screensize - m_lockscreensize;
196 if (current_screensize.Y > m_lockscreensize.Y)
201 if (current_screensize.X > m_lockscreensize.X)
206 offset = v2s32(delta.X,delta.Y);
208 data->screensize = m_lockscreensize;
214 padding = v2s32(data->screensize.Y/40, data->screensize.Y/40);
215 spacing = v2s32(data->screensize.Y/12, data->screensize.Y/13);
216 imgsize = v2s32(data->screensize.Y/15, data->screensize.Y/15);
218 padding.X*2+spacing.X*(invsize.X-1.0)+imgsize.X,
219 padding.Y*2+spacing.Y*(invsize.Y-1.0)+imgsize.Y + (data->helptext_h-5)
221 data->rect = core::rect<s32>(
222 data->screensize.X/2 - data->size.X/2 + offset.X,
223 data->screensize.Y/2 - data->size.Y/2 + offset.Y,
224 data->screensize.X/2 + data->size.X/2 + offset.X,
225 data->screensize.Y/2 + data->size.Y/2 + offset.Y
228 DesiredRect = data->rect;
229 recalculateAbsolutePosition(false);
230 data->basepos = getBasePos();
234 errorstream<< "Invalid size element (" << parts.size() << "): '" << element << "'" << std::endl;
237 void GUIFormSpecMenu::parseList(parserData* data,std::string element) {
239 if (m_gamedef == 0) {
240 errorstream<<"WARNING: invalid use of 'list' with m_gamedef==0"<<std::endl;
244 std::vector<std::string> parts = split(element,';');
246 if ((parts.size() == 4) || (parts.size() == 5)) {
247 std::string location = parts[0];
248 std::string listname = parts[1];
249 std::vector<std::string> v_pos = split(parts[2],',');
250 std::vector<std::string> v_geom = split(parts[3],',');
251 std::string startindex = "";
252 if (parts.size() == 5)
253 startindex = parts[4];
255 MY_CHECKPOS("list",2);
256 MY_CHECKGEOM("list",3);
258 InventoryLocation loc;
260 if(location == "context" || location == "current_name")
261 loc = m_current_inventory_location;
263 loc.deSerialize(location);
265 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
266 pos.X += stof(v_pos[0]) * (float)spacing.X;
267 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
270 geom.X = stoi(v_geom[0]);
271 geom.Y = stoi(v_geom[1]);
272 infostream<<"list inv="<<location<<", listname="<<listname
273 <<", pos=("<<pos.X<<","<<pos.Y<<")"
274 <<", geom=("<<geom.X<<","<<geom.Y<<")"
279 start_i = stoi(startindex);
280 if(data->bp_set != 2)
281 errorstream<<"WARNING: invalid use of list without a size[] element"<<std::endl;
282 m_inventorylists.push_back(ListDrawSpec(loc, listname, pos, geom, start_i));
285 errorstream<< "Invalid list element(" << parts.size() << "): '" << element << "'" << std::endl;
288 void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element) {
289 std::vector<std::string> parts = split(element,';');
291 if ((parts.size() == 3) || (parts.size() == 4)) {
292 std::vector<std::string> v_pos = split(parts[0],',');
293 std::string name = parts[1];
294 std::string label = parts[2];
295 std::string selected = "";
297 if (parts.size() == 4)
300 MY_CHECKPOS("checkbox",0);
303 pos.X += stof(v_pos[0]) * (float) spacing.X;
304 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
306 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+300, pos.Y+((imgsize.Y/2)+15));
308 bool fselected = false;
310 if (selected == "true")
313 std::wstring wlabel = narrow_to_wide(label.c_str());
316 wlabel = wstrgettext(label);
318 FieldSpec spec = FieldSpec(
319 narrow_to_wide(name.c_str()),
325 spec.ftype = f_CheckBox;
326 spec.flabel = wlabel; //Needed for displaying text on MSVC
327 gui::IGUICheckBox* e = Environment->addCheckBox(fselected, rect, this,
328 spec.fid, spec.flabel.c_str());
329 m_checkboxes.push_back(std::pair<FieldSpec,gui::IGUICheckBox*>(spec,e));
330 m_fields.push_back(spec);
333 errorstream<< "Invalid checkbox element(" << parts.size() << "): '" << element << "'" << std::endl;
336 void GUIFormSpecMenu::parseImage(parserData* data,std::string element) {
337 std::vector<std::string> parts = split(element,';');
339 if (parts.size() == 3) {
340 std::vector<std::string> v_pos = split(parts[0],',');
341 std::vector<std::string> v_geom = split(parts[1],',');
342 std::string name = parts[2];
344 MY_CHECKPOS("image",0);
345 MY_CHECKGEOM("image",1);
347 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
348 pos.X += stof(v_pos[0]) * (float) spacing.X;
349 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
352 geom.X = stoi(v_geom[0]) * (float)imgsize.X;
353 geom.Y = stoi(v_geom[1]) * (float)imgsize.Y;
355 infostream<<"image name="<<name
356 <<", pos=("<<pos.X<<","<<pos.Y<<")"
357 <<", geom=("<<geom.X<<","<<geom.Y<<")"
359 if(data->bp_set != 2)
360 errorstream<<"WARNING: invalid use of image without a size[] element"<<std::endl;
361 m_images.push_back(ImageDrawSpec(name, pos, geom));
365 if (parts.size() == 2) {
366 std::vector<std::string> v_pos = split(parts[0],',');
367 std::string name = parts[1];
369 MY_CHECKPOS("image",0);
371 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
372 pos.X += stof(v_pos[0]) * (float) spacing.X;
373 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
375 std::cout<<"image name="<<name
376 <<", pos=("<<pos.X<<","<<pos.Y<<")"
378 if(data->bp_set != 2)
379 errorstream<<"WARNING: invalid use of image without a size[] element"<<std::endl;
380 m_images.push_back(ImageDrawSpec(name, pos));
383 errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl;
386 void GUIFormSpecMenu::parseItemImage(parserData* data,std::string element) {
387 std::vector<std::string> parts = split(element,';');
389 if (parts.size() == 3) {
390 std::vector<std::string> v_pos = split(parts[0],',');
391 std::vector<std::string> v_geom = split(parts[1],',');
392 std::string name = parts[2];
394 MY_CHECKPOS("itemimage",0);
395 MY_CHECKGEOM("itemimage",1);
397 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
398 pos.X += stof(v_pos[0]) * (float) spacing.X;
399 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
402 geom.X = stoi(v_geom[0]) * (float)imgsize.X;
403 geom.Y = stoi(v_geom[1]) * (float)imgsize.Y;
405 infostream<<"item name="<<name
406 <<", pos=("<<pos.X<<","<<pos.Y<<")"
407 <<", geom=("<<geom.X<<","<<geom.Y<<")"
409 if(data->bp_set != 2)
410 errorstream<<"WARNING: invalid use of item_image without a size[] element"<<std::endl;
411 m_itemimages.push_back(ImageDrawSpec(name, pos, geom));
414 errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl;
417 void GUIFormSpecMenu::parseButton(parserData* data,std::string element,std::string type) {
418 std::vector<std::string> parts = split(element,';');
420 if (parts.size() == 4) {
421 std::vector<std::string> v_pos = split(parts[0],',');
422 std::vector<std::string> v_geom = split(parts[1],',');
423 std::string name = parts[2];
424 std::string label = parts[3];
426 MY_CHECKPOS("button",0);
427 MY_CHECKGEOM("button",1);
430 pos.X += stof(v_pos[0]) * (float)spacing.X;
431 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
434 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
435 pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
437 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y-15, pos.X+geom.X, pos.Y+15);
439 if(data->bp_set != 2)
440 errorstream<<"WARNING: invalid use of button without a size[] element"<<std::endl;
442 label = unescape_string(label);
444 std::wstring wlabel = narrow_to_wide(label.c_str());
447 wlabel = wstrgettext(label);
449 FieldSpec spec = FieldSpec(
450 narrow_to_wide(name.c_str()),
455 spec.ftype = f_Button;
456 if(type == "button_exit")
459 Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
460 m_fields.push_back(spec);
463 errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl;
466 void GUIFormSpecMenu::parseBackground(parserData* data,std::string element) {
467 std::vector<std::string> parts = split(element,';');
469 if (parts.size() == 3) {
470 std::vector<std::string> v_pos = split(parts[0],',');
471 std::vector<std::string> v_geom = split(parts[1],',');
472 std::string name = parts[2];
474 MY_CHECKPOS("background",0);
475 MY_CHECKGEOM("background",1);
477 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
478 pos.X += stof(v_pos[0]) * (float)spacing.X - ((float)spacing.X-(float)imgsize.X)/2;
479 pos.Y += stof(v_pos[1]) * (float)spacing.Y - ((float)spacing.Y-(float)imgsize.Y)/2;
482 geom.X = stof(v_geom[0]) * (float)spacing.X;
483 geom.Y = stof(v_geom[1]) * (float)spacing.Y;
485 infostream<<"image name="<<name
486 <<", pos=("<<pos.X<<","<<pos.Y<<")"
487 <<", geom=("<<geom.X<<","<<geom.Y<<")"
489 if(data->bp_set != 2)
490 errorstream<<"WARNING: invalid use of background without a size[] element"<<std::endl;
491 m_backgrounds.push_back(ImageDrawSpec(name, pos, geom));
494 errorstream<< "Invalid background element(" << parts.size() << "): '" << element << "'" << std::endl;
497 void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) {
498 std::vector<std::string> parts = split(element,';');
500 if ((parts.size() == 5) || (parts.size() == 6)) {
501 std::vector<std::string> v_pos = split(parts[0],',');
502 std::vector<std::string> v_geom = split(parts[1],',');
503 std::string name = parts[2];
504 std::vector<std::string> items = split(parts[3],',');
505 std::string str_initial_selection = "";
506 std::string str_transparent = "false";
508 if (parts.size() >= 5)
509 str_initial_selection = parts[4];
511 if (parts.size() >= 6)
512 str_transparent = parts[5];
514 MY_CHECKPOS("textlist",0);
515 MY_CHECKGEOM("textlist",1);
518 pos.X += stof(v_pos[0]) * (float)spacing.X;
519 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
522 geom.X = stof(v_geom[0]) * (float)spacing.X;
523 geom.Y = stof(v_geom[1]) * (float)spacing.Y;
526 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
528 std::wstring fname_w = narrow_to_wide(name.c_str());
530 FieldSpec spec = FieldSpec(
537 spec.ftype = f_ListBox;
539 //now really show list
540 gui::IGUIListBox *e = Environment->addListBox(rect, this,spec.fid);
542 //don't reset if we already have a user specified selection
543 if (data->listbox_selections.find(fname_w) == data->listbox_selections.end()) {
544 e->setAutoScrollEnabled(false);
547 if (str_transparent == "false")
548 e->setDrawBackground(true);
550 for (unsigned int i=0; i < items.size(); i++) {
551 if (items[i].c_str()[0] == '#') {
552 if (items[i].c_str()[1] == '#') {
553 e->addItem(narrow_to_wide(unescape_string(items[i])).c_str() +1);
556 std::string color = items[i].substr(1,6);
558 narrow_to_wide(unescape_string(items[i]).c_str() + 7);
561 e->addItem(toadd.c_str());
563 irr::video::SColor toset;
565 if (parseColor(color, toset))
566 e->setItemOverrideColor(i,toset);
570 e->addItem(narrow_to_wide(unescape_string(items[i])).c_str());
574 if (data->listbox_selections.find(fname_w) != data->listbox_selections.end()) {
575 e->setSelected(data->listbox_selections[fname_w]);
578 if (str_initial_selection != "")
579 e->setSelected(stoi(str_initial_selection.c_str())-1);
581 m_listboxes.push_back(std::pair<FieldSpec,gui::IGUIListBox*>(spec,e));
582 m_fields.push_back(spec);
585 errorstream<< "Invalid textlist element(" << parts.size() << "): '" << element << "'" << std::endl;
589 void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element) {
590 std::vector<std::string> parts = split(element,';');
592 if (parts.size() == 5) {
593 std::vector<std::string> v_pos = split(parts[0],',');
594 std::string name = parts[2];
595 std::vector<std::string> items = split(parts[3],',');
596 std::string str_initial_selection = "";
597 str_initial_selection = parts[4];
599 MY_CHECKPOS("dropdown",0);
602 pos.X += stof(v_pos[0]) * (float)spacing.X;
603 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
605 s32 width = stof(parts[1]) * (float)spacing.Y;
607 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+width, pos.Y+30);
609 std::wstring fname_w = narrow_to_wide(name.c_str());
611 FieldSpec spec = FieldSpec(
618 spec.ftype = f_DropDown;
621 //now really show list
622 gui::IGUIComboBox *e = Environment->addComboBox(rect, this,spec.fid);
624 //don't reset if we already have a user specified selection
625 //if (data->combobox_selections.find(fname_w) == data->listbox_selections.end()) {
626 // e->setAutoScrollEnabled(false);
629 for (unsigned int i=0; i < items.size(); i++) {
630 e->addItem(narrow_to_wide(items[i]).c_str());
633 if (str_initial_selection != "")
634 e->setSelected(stoi(str_initial_selection.c_str())-1);
636 //if (data->listbox_selections.find(fname_w) != data->listbox_selections.end()) {
637 // e->setSelected(data->listbox_selections[fname_w]);
640 //m_listboxes.push_back(std::pair<FieldSpec,gui::IGUIListBox*>(spec,e));
641 m_fields.push_back(spec);
644 errorstream << "Invalid dropdown element(" << parts.size() << "): '"
645 << element << "'" << std::endl;
648 void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element) {
649 std::vector<std::string> parts = split(element,';');
651 if (parts.size() == 4) {
652 std::vector<std::string> v_pos = split(parts[0],',');
653 std::vector<std::string> v_geom = split(parts[1],',');
654 std::string name = parts[2];
655 std::string label = parts[3];
657 MY_CHECKPOS("pwdfield",0);
658 MY_CHECKGEOM("pwdfield",1);
661 pos.X += stof(v_pos[0]) * (float)spacing.X;
662 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
665 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
667 pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
671 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
673 label = unescape_string(label);
675 std::wstring wlabel = narrow_to_wide(label.c_str());
678 if (label.length() > 1)
679 wlabel = wstrgettext(label);
684 FieldSpec spec = FieldSpec(
685 narrow_to_wide(name.c_str()),
692 gui::IGUIEditBox * e = Environment->addEditBox(0, rect, true, this, spec.fid);
693 Environment->setFocus(e);
695 if (label.length() > 1)
697 rect.UpperLeftCorner.Y -= 15;
698 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 15;
699 Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
702 e->setPasswordBox(true,L'*');
705 evt.EventType = EET_KEY_INPUT_EVENT;
706 evt.KeyInput.Key = KEY_END;
707 evt.KeyInput.Char = 0;
708 evt.KeyInput.Control = 0;
709 evt.KeyInput.Shift = 0;
710 evt.KeyInput.PressedDown = true;
712 m_fields.push_back(spec);
715 errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl;
718 void GUIFormSpecMenu::parseSimpleField(parserData* data,std::vector<std::string> &parts) {
719 std::string name = parts[0];
720 std::string label = parts[1];
721 std::string default_val = parts[2];
723 core::rect<s32> rect;
727 rect = core::rect<s32>(
728 data->screensize.X/2 - 580/2,
729 data->screensize.Y/2 - 300/2,
730 data->screensize.X/2 + 580/2,
731 data->screensize.Y/2 + 300/2
734 recalculateAbsolutePosition(false);
735 data->basepos = getBasePos();
738 else if(data->bp_set == 2)
739 errorstream<<"WARNING: invalid use of unpositioned \"field\" in inventory"<<std::endl;
741 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
742 pos.Y = ((m_fields.size()+2)*60);
743 v2s32 size = DesiredRect.getSize();
745 rect = core::rect<s32>(size.X/2-150, pos.Y, (size.X/2-150)+300, pos.Y+30);
749 default_val = m_form_src->resolveText(default_val);
751 default_val = unescape_string(default_val);
752 label = unescape_string(label);
754 std::wstring wlabel = narrow_to_wide(label.c_str());
757 if (label.length() > 1)
758 wlabel = wstrgettext(label);
763 FieldSpec spec = FieldSpec(
764 narrow_to_wide(name.c_str()),
766 narrow_to_wide(default_val.c_str()),
772 // spec field id to 0, this stops submit searching for a value that isn't there
773 Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
778 gui::IGUIEditBox *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
779 Environment->setFocus(e);
782 evt.EventType = EET_KEY_INPUT_EVENT;
783 evt.KeyInput.Key = KEY_END;
784 evt.KeyInput.Char = 0;
785 evt.KeyInput.Control = 0;
786 evt.KeyInput.Shift = 0;
787 evt.KeyInput.PressedDown = true;
790 if (label.length() > 1)
792 rect.UpperLeftCorner.Y -= 15;
793 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 15;
794 Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
798 m_fields.push_back(spec);
801 void GUIFormSpecMenu::parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type) {
803 std::vector<std::string> v_pos = split(parts[0],',');
804 std::vector<std::string> v_geom = split(parts[1],',');
805 std::string name = parts[2];
806 std::string label = parts[3];
807 std::string default_val = parts[4];
810 MY_CHECKGEOM(type,1);
813 pos.X = stof(v_pos[0]) * (float) spacing.X;
814 pos.Y = stof(v_pos[1]) * (float) spacing.Y;
818 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
820 if (type == "textarea")
822 geom.Y = (stof(v_geom[1]) * (float)imgsize.Y) - (spacing.Y-imgsize.Y);
827 pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
832 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
834 if(data->bp_set != 2)
835 errorstream<<"WARNING: invalid use of positioned "<<type<<" without a size[] element"<<std::endl;
838 default_val = m_form_src->resolveText(default_val);
841 default_val = unescape_string(default_val);
842 label = unescape_string(label);
844 std::wstring wlabel = narrow_to_wide(label.c_str());
847 if (label.length() > 1)
848 wlabel = wstrgettext(label);
853 FieldSpec spec = FieldSpec(
854 narrow_to_wide(name.c_str()),
856 narrow_to_wide(default_val.c_str()),
862 // spec field id to 0, this stops submit searching for a value that isn't there
863 Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
868 gui::IGUIEditBox *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
869 Environment->setFocus(e);
871 if (type == "textarea")
873 e->setMultiLine(true);
874 e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
877 evt.EventType = EET_KEY_INPUT_EVENT;
878 evt.KeyInput.Key = KEY_END;
879 evt.KeyInput.Char = 0;
880 evt.KeyInput.Control = 0;
881 evt.KeyInput.Shift = 0;
882 evt.KeyInput.PressedDown = true;
886 if (label.length() > 1)
888 rect.UpperLeftCorner.Y -= 15;
889 rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 15;
890 Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
893 m_fields.push_back(spec);
896 void GUIFormSpecMenu::parseField(parserData* data,std::string element,std::string type) {
897 std::vector<std::string> parts = split(element,';');
899 if (parts.size() == 3) {
900 parseSimpleField(data,parts);
904 if (parts.size() == 5) {
905 parseTextArea(data,parts,type);
908 errorstream<< "Invalid field element(" << parts.size() << "): '" << element << "'" << std::endl;
911 void GUIFormSpecMenu::parseLabel(parserData* data,std::string element) {
912 std::vector<std::string> parts = split(element,';');
914 if (parts.size() == 2) {
915 std::vector<std::string> v_pos = split(parts[0],',');
916 std::string text = parts[1];
918 MY_CHECKPOS("label",0);
921 pos.X += stof(v_pos[0]) * (float)spacing.X;
922 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
924 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+300, pos.Y+((imgsize.Y/2)+15));
926 if(data->bp_set != 2)
927 errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
929 text = unescape_string(text);
931 std::wstring wlabel = narrow_to_wide(text.c_str());
934 wlabel = wstrgettext(text);
936 FieldSpec spec = FieldSpec(
942 Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
943 m_fields.push_back(spec);
946 errorstream<< "Invalid label element(" << parts.size() << "): '" << element << "'" << std::endl;
949 void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element) {
950 std::vector<std::string> parts = split(element,';');
952 if (parts.size() == 2) {
953 std::vector<std::string> v_pos = split(parts[0],',');
954 std::string text = parts[1];
956 MY_CHECKPOS("vertlabel",1);
959 pos.X += stof(v_pos[0]) * (float)spacing.X;
960 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
962 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y+((imgsize.Y/2)-15), pos.X+15, pos.Y+300);
964 if(data->bp_set != 2)
965 errorstream<<"WARNING: invalid use of label without a size[] element"<<std::endl;
967 text = unescape_string(text);
968 std::string label = "";
971 const char* toset = gettext(text.c_str());
973 text = std::string(toset);
976 for (unsigned int i=0; i < text.length(); i++) {
977 label += text.c_str()[i];
981 FieldSpec spec = FieldSpec(
983 narrow_to_wide(label.c_str()),
987 gui::IGUIStaticText *t =
988 Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid);
989 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
990 m_fields.push_back(spec);
993 errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl;
996 void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std::string type) {
997 std::vector<std::string> parts = split(element,';');
999 if ((parts.size() == 5) || (parts.size() == 7) || (parts.size() == 8)) {
1000 std::vector<std::string> v_pos = split(parts[0],',');
1001 std::vector<std::string> v_geom = split(parts[1],',');
1002 std::string image_name = parts[2];
1003 std::string name = parts[3];
1004 std::string label = parts[4];
1006 MY_CHECKPOS("imagebutton",0);
1007 MY_CHECKGEOM("imagebutton",1);
1009 v2s32 pos = padding;
1010 pos.X += stof(v_pos[0]) * (float)spacing.X;
1011 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
1013 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
1014 geom.Y = (stof(v_geom[1]) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
1016 bool noclip = false;
1017 bool drawborder = true;
1019 if ((parts.size() >= 7)) {
1020 if (parts[5] == "true")
1023 if (parts[6] == "false")
1027 std::string pressed_image_name = "";
1029 if ((parts.size() == 8)) {
1030 pressed_image_name = parts[7];
1033 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
1035 if(data->bp_set != 2)
1036 errorstream<<"WARNING: invalid use of item_image_button without a size[] element"<<std::endl;
1038 label = unescape_string(label);
1040 std::wstring wlabel = narrow_to_wide(label.c_str());
1043 wlabel = wstrgettext(label);
1045 FieldSpec spec = FieldSpec(
1046 narrow_to_wide(name.c_str()),
1048 narrow_to_wide(image_name.c_str()),
1051 spec.ftype = f_Button;
1052 if(type == "image_button_exit")
1053 spec.is_exit = true;
1055 video::ITexture *texture = 0;
1056 video::ITexture *pressed_texture = 0;
1057 //if there's no gamedef specified try to get direct
1058 //TODO check for possible texture leak
1059 if (m_gamedef != 0) {
1060 texture = m_gamedef->tsrc()->getTexture(image_name);
1061 if ((parts.size() == 8)) {
1062 pressed_texture = m_gamedef->tsrc()->getTexture(pressed_image_name);
1065 if (fs::PathExists(image_name)) {
1066 texture = Environment->getVideoDriver()->getTexture(image_name.c_str());
1067 m_Textures.push_back(texture);
1069 if (fs::PathExists(pressed_image_name)) {
1070 pressed_texture = Environment->getVideoDriver()->getTexture(pressed_image_name.c_str());
1071 m_Textures.push_back(pressed_texture);
1074 if (parts.size() < 8)
1075 pressed_texture = texture;
1077 gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
1078 e->setUseAlphaChannel(true);
1079 e->setImage(texture);
1080 e->setPressedImage(pressed_texture);
1081 e->setScaleImage(true);
1082 e->setNotClipped(noclip);
1083 e->setDrawBorder(drawborder);
1085 m_fields.push_back(spec);
1089 errorstream<< "Invalid imagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
1092 void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element) {
1093 std::vector<std::string> parts = split(element,';');
1095 if ((parts.size() == 4) || (parts.size() == 6)) {
1096 std::vector<std::string> v_pos = split(parts[0],',');
1097 std::string name = parts[1];
1098 std::vector<std::string> buttons = split(parts[2],',');
1099 std::string str_index = parts[3];
1100 bool show_background = true;
1101 bool show_border = true;
1102 int tab_index = stoi(str_index) -1;
1104 MY_CHECKPOS("tabheader",0);
1106 if (parts.size() == 6) {
1107 if (parts[4] == "true")
1108 show_background = false;
1109 if (parts[5] == "false")
1110 show_border = false;
1113 FieldSpec spec = FieldSpec(
1114 narrow_to_wide(name.c_str()),
1120 spec.ftype = f_TabHeader;
1122 v2s32 pos = padding;
1123 pos.X += stof(v_pos[0]) * (float)spacing.X;
1124 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
1126 geom.X = data->screensize.Y;
1129 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
1131 gui::IGUITabControl *e = Environment->addTabControl(rect,this,show_background,show_border,spec.fid);
1133 e->setNotClipped(true);
1135 for (unsigned int i=0; i< buttons.size(); i++) {
1136 wchar_t* wbutton = 0;
1139 wbutton = wgettext(buttons[i].c_str());
1141 wbutton = (wchar_t*) narrow_to_wide(buttons[i].c_str()).c_str();
1143 e->addTab(wbutton,-1);
1149 if ((tab_index >= 0) &&
1150 (buttons.size() < INT_MAX) &&
1151 (tab_index < (int) buttons.size()))
1152 e->setActiveTab(tab_index);
1154 m_fields.push_back(spec);
1157 errorstream<< "Invalid TabHeader element(" << parts.size() << "): '" << element << "'" << std::endl;
1160 void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element) {
1162 if (m_gamedef == 0) {
1163 errorstream<<"WARNING: invalid use of item_image_button with m_gamedef==0"<<std::endl;
1167 std::vector<std::string> parts = split(element,';');
1169 if (parts.size() == 5) {
1170 std::vector<std::string> v_pos = split(parts[0],',');
1171 std::vector<std::string> v_geom = split(parts[1],',');
1172 std::string item_name = parts[2];
1173 std::string name = parts[3];
1174 std::string label = parts[4];
1176 MY_CHECKPOS("itemimagebutton",0);
1177 MY_CHECKGEOM("itemimagebutton",1);
1179 v2s32 pos = padding;
1180 pos.X += stof(v_pos[0]) * (float)spacing.X;
1181 pos.Y += stof(v_pos[1]) * (float)spacing.Y;
1183 geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
1184 geom.Y = (stof(v_geom[1]) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
1186 core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
1188 if(data->bp_set != 2)
1189 errorstream<<"WARNING: invalid use of item_image_button without a size[] element"<<std::endl;
1191 IItemDefManager *idef = m_gamedef->idef();
1193 item.deSerialize(item_name, idef);
1194 video::ITexture *texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef);
1195 std::string tooltip = item.getDefinition(idef).description;
1197 label = unescape_string(label);
1198 FieldSpec spec = FieldSpec(
1199 narrow_to_wide(name.c_str()),
1200 narrow_to_wide(label.c_str()),
1201 narrow_to_wide(item_name.c_str()),
1205 gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
1206 e->setUseAlphaChannel(true);
1207 e->setImage(texture);
1208 e->setPressedImage(texture);
1209 e->setScaleImage(true);
1210 spec.ftype = f_Button;
1211 rect+=data->basepos-padding;
1214 spec.tooltip=tooltip;
1215 m_fields.push_back(spec);
1218 errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
1221 void GUIFormSpecMenu::parseBox(parserData* data,std::string element) {
1222 std::vector<std::string> parts = split(element,';');
1224 if (parts.size() == 3) {
1225 std::vector<std::string> v_pos = split(parts[0],',');
1226 std::vector<std::string> v_geom = split(parts[1],',');
1227 std::string color_str = parts[2];
1229 MY_CHECKPOS("box",0);
1230 MY_CHECKGEOM("box",1);
1232 v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
1233 pos.X += stof(v_pos[0]) * (float) spacing.X;
1234 pos.Y += stof(v_pos[1]) * (float) spacing.Y;
1237 geom.X = stof(v_geom[0]) * (float)spacing.X;
1238 geom.Y = stof(v_geom[1]) * (float)spacing.Y;
1240 irr::video::SColor color;
1242 if (parseColor(color_str, color)) {
1243 BoxDrawSpec spec(pos,geom,color);
1245 m_boxes.push_back(spec);
1248 errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "' INVALID COLOR" << std::endl;
1252 errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "'" << std::endl;
1255 void GUIFormSpecMenu::parseElement(parserData* data,std::string element) {
1261 std::vector<std::string> parts = split(element,'[');
1263 // ugly workaround to keep compatibility
1264 if (parts.size() > 2) {
1265 if (trim(parts[0]) == "image") {
1266 for (unsigned int i=2;i< parts.size(); i++) {
1267 parts[1] += "[" + parts[i];
1273 if (parts.size() < 2) {
1277 std::string type = trim(parts[0]);
1278 std::string description = trim(parts[1]);
1280 if ((type == "size") || (type == "invsize")){
1281 parseSize(data,description);
1285 if (type == "list") {
1286 parseList(data,description);
1290 if (type == "checkbox") {
1291 parseCheckbox(data,description);
1295 if (type == "image") {
1296 parseImage(data,description);
1300 if (type == "item_image") {
1301 parseItemImage(data,description);
1305 if ((type == "button") || (type == "button_exit")) {
1306 parseButton(data,description,type);
1310 if (type == "background") {
1311 parseBackground(data,description);
1315 if (type == "textlist"){
1316 parseTextList(data,description);
1320 if (type == "dropdown"){
1321 parseDropDown(data,description);
1325 if (type == "pwdfield") {
1326 parsePwdField(data,description);
1330 if ((type == "field") || (type == "textarea")){
1331 parseField(data,description,type);
1335 if (type == "label") {
1336 parseLabel(data,description);
1340 if (type == "vertlabel") {
1341 parseVertLabel(data,description);
1345 if (type == "item_image_button") {
1346 parseItemImageButton(data,description);
1350 if ((type == "image_button") || (type == "image_button_exit")) {
1351 parseImageButton(data,description,type);
1355 if (type == "tabheader") {
1356 parseTabHeader(data,description);
1360 if (type == "box") {
1361 parseBox(data,description);
1367 << "Unknown DrawSpec: type="<<type<<", data=\""<<description<<"\""
1373 void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
1377 //preserve listboxes
1378 for (unsigned int i = 0; i < m_listboxes.size(); i++) {
1379 int selection = m_listboxes[i].second->getSelected();
1380 if (selection != -1) {
1381 std::wstring listboxname = m_listboxes[i].first.fname;
1382 mydata.listbox_selections[listboxname] = selection;
1389 mydata.size= v2s32(100,100);
1390 mydata.helptext_h = 15;
1391 mydata.screensize = screensize;
1393 // Base position of contents of form
1394 mydata.basepos = getBasePos();
1396 // State of basepos, 0 = not set, 1= set by formspec, 2 = set by size[] element
1397 // Used to adjust form size automatically if needed
1398 // A proceed button is added if there is no size[] element
1402 /* Convert m_init_draw_spec to m_inventorylists */
1404 m_inventorylists.clear();
1406 m_backgrounds.clear();
1407 m_itemimages.clear();
1408 m_listboxes.clear();
1409 m_checkboxes.clear();
1414 std::vector<std::string> elements = split(m_formspec_string,']');
1416 for (unsigned int i=0;i< elements.size();i++) {
1417 parseElement(&mydata,elements[i]);
1420 // If there's inventory, put the usage string at the bottom
1421 if (m_inventorylists.size())
1424 core::rect<s32> rect(0, 0, mydata.size.X-padding.X*2, mydata.helptext_h);
1425 rect = rect + v2s32((mydata.size.X/2 - mydata.rect.getWidth()/2) +5,
1426 mydata.size.Y-5-mydata.helptext_h);
1427 const wchar_t *text = wgettext("Left click: Move all items, Right click: Move single item");
1428 Environment->addStaticText(text, rect, false, true, this, 256);
1432 // If there's fields, add a Proceed button
1433 if (m_fields.size() && mydata.bp_set != 2)
1435 // if the size wasn't set by an invsize[] or size[] adjust it now to fit all the fields
1436 mydata.rect = core::rect<s32>(
1437 mydata.screensize.X/2 - 580/2,
1438 mydata.screensize.Y/2 - 300/2,
1439 mydata.screensize.X/2 + 580/2,
1440 mydata.screensize.Y/2 + 240/2+(m_fields.size()*60)
1442 DesiredRect = mydata.rect;
1443 recalculateAbsolutePosition(false);
1444 mydata.basepos = getBasePos();
1448 v2s32 pos = mydata.basepos;
1449 pos.Y = ((m_fields.size()+2)*60);
1451 v2s32 size = DesiredRect.getSize();
1452 mydata.rect = core::rect<s32>(size.X/2-70, pos.Y, (size.X/2-70)+140, pos.Y+30);
1453 wchar_t* text = wgettext("Proceed");
1454 Environment->addButton(mydata.rect, this, 257, text);
1461 // Note: parent != this so that the tooltip isn't clipped by the menu rectangle
1462 m_tooltip_element = Environment->addStaticText(L"",core::rect<s32>(0,0,110,18));
1463 m_tooltip_element->enableOverrideColor(true);
1464 m_tooltip_element->setBackgroundColor(video::SColor(255,110,130,60));
1465 m_tooltip_element->setDrawBackground(true);
1466 m_tooltip_element->setDrawBorder(true);
1467 m_tooltip_element->setOverrideColor(video::SColor(255,255,255,255));
1468 m_tooltip_element->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
1469 m_tooltip_element->setWordWrap(false);
1473 GUIFormSpecMenu::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
1475 core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
1477 for(u32 i=0; i<m_inventorylists.size(); i++)
1479 const ListDrawSpec &s = m_inventorylists[i];
1481 for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
1483 s32 item_i = i + s.start_item_i;
1484 s32 x = (i%s.geom.X) * spacing.X;
1485 s32 y = (i/s.geom.X) * spacing.Y;
1487 core::rect<s32> rect = imgrect + s.pos + p0;
1488 if(rect.isPointInside(p))
1490 return ItemSpec(s.inventoryloc, s.listname, item_i);
1495 return ItemSpec(InventoryLocation(), "", -1);
1498 void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase)
1500 video::IVideoDriver* driver = Environment->getVideoDriver();
1503 gui::IGUIFont *font = NULL;
1504 gui::IGUISkin* skin = Environment->getSkin();
1506 font = skin->getFont();
1508 Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
1510 infostream<<"GUIFormSpecMenu::drawList(): WARNING: "
1511 <<"The inventory location "
1512 <<"\""<<s.inventoryloc.dump()<<"\" doesn't exist"
1516 InventoryList *ilist = inv->getList(s.listname);
1518 infostream<<"GUIFormSpecMenu::drawList(): WARNING: "
1519 <<"The inventory list \""<<s.listname<<"\" @ \""
1520 <<s.inventoryloc.dump()<<"\" doesn't exist"
1525 core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
1527 for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
1529 s32 item_i = i + s.start_item_i;
1530 if(item_i >= (s32) ilist->getSize())
1532 s32 x = (i%s.geom.X) * spacing.X;
1533 s32 y = (i/s.geom.X) * spacing.Y;
1535 core::rect<s32> rect = imgrect + s.pos + p;
1538 item = ilist->getItem(item_i);
1540 bool selected = m_selected_item
1541 && m_invmgr->getInventory(m_selected_item->inventoryloc) == inv
1542 && m_selected_item->listname == s.listname
1543 && m_selected_item->i == item_i;
1544 bool hovering = rect.isPointInside(m_pointer);
1548 if(hovering && m_selected_item)
1550 video::SColor bgcolor(255,192,192,192);
1551 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
1555 video::SColor bgcolor(255,128,128,128);
1556 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
1565 item.takeItem(m_selected_amount);
1569 drawItemStack(driver, font, item,
1570 rect, &AbsoluteClippingRect, m_gamedef);
1574 std::string tooltip_text = "";
1575 if(hovering && !m_selected_item)
1576 tooltip_text = item.getDefinition(m_gamedef->idef()).description;
1577 if(tooltip_text != "")
1579 m_tooltip_element->setVisible(true);
1580 this->bringToFront(m_tooltip_element);
1581 m_tooltip_element->setText(narrow_to_wide(tooltip_text).c_str());
1582 s32 tooltip_x = m_pointer.X + 15;
1583 s32 tooltip_y = m_pointer.Y + 15;
1584 s32 tooltip_width = m_tooltip_element->getTextWidth() + 15;
1585 s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
1586 m_tooltip_element->setRelativePosition(core::rect<s32>(
1587 core::position2d<s32>(tooltip_x, tooltip_y),
1588 core::dimension2d<s32>(tooltip_width, tooltip_height)));
1594 void GUIFormSpecMenu::drawSelectedItem()
1596 if(!m_selected_item)
1599 video::IVideoDriver* driver = Environment->getVideoDriver();
1602 gui::IGUIFont *font = NULL;
1603 gui::IGUISkin* skin = Environment->getSkin();
1605 font = skin->getFont();
1607 Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
1609 InventoryList *list = inv->getList(m_selected_item->listname);
1611 ItemStack stack = list->getItem(m_selected_item->i);
1612 stack.count = m_selected_amount;
1614 core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
1615 core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
1616 drawItemStack(driver, font, stack, rect, NULL, m_gamedef);
1619 void GUIFormSpecMenu::drawMenu()
1622 std::string newform = m_form_src->getForm();
1623 if(newform != m_formspec_string){
1624 m_formspec_string = newform;
1625 regenerateGui(m_screensize_old);
1629 m_pointer = m_device->getCursorControl()->getPosition();
1631 updateSelectedItem();
1633 gui::IGUISkin* skin = Environment->getSkin();
1636 video::IVideoDriver* driver = Environment->getVideoDriver();
1638 video::SColor bgcolor(140,0,0,0);
1639 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
1641 m_tooltip_element->setVisible(false);
1646 for(u32 i=0; i<m_backgrounds.size(); i++)
1648 const ImageDrawSpec &spec = m_backgrounds[i];
1649 video::ITexture *texture = 0;
1652 texture = m_gamedef->tsrc()->getTexture(spec.name);
1655 texture = driver->getTexture(spec.name.c_str());
1656 m_Textures.push_back(texture);
1660 // Image size on screen
1661 core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
1662 // Image rectangle on screen
1663 core::rect<s32> rect = imgrect + spec.pos;
1664 const video::SColor color(255,255,255,255);
1665 const video::SColor colors[] = {color,color,color,color};
1666 driver->draw2DImage(texture, rect,
1667 core::rect<s32>(core::position2d<s32>(0,0),
1668 core::dimension2di(texture->getOriginalSize())),
1669 NULL/*&AbsoluteClippingRect*/, colors, true);
1672 errorstream << "GUIFormSpecMenu::drawMenu() Draw backgrounds unable to load texture:" << std::endl;
1673 errorstream << "\t" << spec.name << std::endl;
1680 for(u32 i=0; i<m_boxes.size(); i++)
1682 const BoxDrawSpec &spec = m_boxes[i];
1684 irr::video::SColor todraw = spec.color;
1686 todraw.setAlpha(140);
1688 core::rect<s32> rect(spec.pos.X,spec.pos.Y,
1689 spec.pos.X + spec.geom.X,spec.pos.Y + spec.geom.Y);
1691 driver->draw2DRectangle(todraw, rect, 0);
1696 for(u32 i=0; i<m_images.size(); i++)
1698 const ImageDrawSpec &spec = m_images[i];
1699 video::ITexture *texture = 0;
1702 texture = m_gamedef->tsrc()->getTexture(spec.name);
1705 texture = driver->getTexture(spec.name.c_str());
1706 m_Textures.push_back(texture);
1709 const core::dimension2d<u32>& img_origsize = texture->getOriginalSize();
1710 // Image size on screen
1711 core::rect<s32> imgrect;
1714 imgrect = core::rect<s32>(0,0,spec.geom.X, spec.geom.Y);
1717 imgrect = core::rect<s32>(0,0,img_origsize.Width,img_origsize.Height);
1719 // Image rectangle on screen
1720 core::rect<s32> rect = imgrect + spec.pos;
1721 const video::SColor color(255,255,255,255);
1722 const video::SColor colors[] = {color,color,color,color};
1723 driver->draw2DImage(texture, rect,
1724 core::rect<s32>(core::position2d<s32>(0,0),img_origsize),
1725 NULL/*&AbsoluteClippingRect*/, colors, true);
1728 errorstream << "GUIFormSpecMenu::drawMenu() Draw images unable to load texture:" << std::endl;
1729 errorstream << "\t" << spec.name << std::endl;
1736 for(u32 i=0; i<m_itemimages.size(); i++)
1741 const ImageDrawSpec &spec = m_itemimages[i];
1742 IItemDefManager *idef = m_gamedef->idef();
1744 item.deSerialize(spec.name, idef);
1745 video::ITexture *texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef);
1746 // Image size on screen
1747 core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
1748 // Image rectangle on screen
1749 core::rect<s32> rect = imgrect + spec.pos;
1750 const video::SColor color(255,255,255,255);
1751 const video::SColor colors[] = {color,color,color,color};
1752 driver->draw2DImage(texture, rect,
1753 core::rect<s32>(core::position2d<s32>(0,0),
1754 core::dimension2di(texture->getOriginalSize())),
1755 NULL/*&AbsoluteClippingRect*/, colors, true);
1760 Phase 0: Item slot rectangles
1761 Phase 1: Item images; prepare tooltip
1762 If backgrounds used, do not draw Item slot rectangles
1765 if (m_backgrounds.size() > 0) start_phase=1;
1766 for(int phase=start_phase; phase<=1; phase++)
1767 for(u32 i=0; i<m_inventorylists.size(); i++)
1769 drawList(m_inventorylists[i], phase);
1775 gui::IGUIElement::draw();
1778 Draw fields/buttons tooltips
1780 for(u32 i=0; i<m_fields.size(); i++)
1782 const FieldSpec &spec = m_fields[i];
1783 if (spec.tooltip != "")
1785 core::rect<s32> rect = spec.rect;
1786 if (rect.isPointInside(m_pointer))
1788 m_tooltip_element->setVisible(true);
1789 this->bringToFront(m_tooltip_element);
1790 m_tooltip_element->setText(narrow_to_wide(spec.tooltip).c_str());
1791 s32 tooltip_x = m_pointer.X + 15;
1792 s32 tooltip_y = m_pointer.Y + 15;
1793 s32 tooltip_width = m_tooltip_element->getTextWidth() + 15;
1794 s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
1795 m_tooltip_element->setRelativePosition(core::rect<s32>(
1796 core::position2d<s32>(tooltip_x, tooltip_y),
1797 core::dimension2d<s32>(tooltip_width, tooltip_height)));
1803 Draw dragged item stack
1808 void GUIFormSpecMenu::updateSelectedItem()
1810 // If the selected stack has become empty for some reason, deselect it.
1811 // If the selected stack has become inaccessible, deselect it.
1812 // If the selected stack has become smaller, adjust m_selected_amount.
1813 ItemStack selected = verifySelectedItem();
1815 // WARNING: BLACK MAGIC
1816 // See if there is a stack suited for our current guess.
1817 // If such stack does not exist, clear the guess.
1818 if(m_selected_content_guess.name != "" &&
1819 selected.name == m_selected_content_guess.name &&
1820 selected.count == m_selected_content_guess.count){
1821 // Selected item fits the guess. Skip the black magic.
1823 else if(m_selected_content_guess.name != ""){
1825 for(u32 i=0; i<m_inventorylists.size() && !found; i++){
1826 const ListDrawSpec &s = m_inventorylists[i];
1827 Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
1830 InventoryList *list = inv->getList(s.listname);
1833 for(s32 i=0; i<s.geom.X*s.geom.Y && !found; i++){
1834 u32 item_i = i + s.start_item_i;
1835 if(item_i >= list->getSize())
1837 ItemStack stack = list->getItem(item_i);
1838 if(stack.name == m_selected_content_guess.name &&
1839 stack.count == m_selected_content_guess.count){
1841 infostream<<"Client: Changing selected content guess to "
1842 <<s.inventoryloc.dump()<<" "<<s.listname
1843 <<" "<<item_i<<std::endl;
1844 delete m_selected_item;
1845 m_selected_item = new ItemSpec(s.inventoryloc, s.listname, item_i);
1846 m_selected_amount = stack.count;
1851 infostream<<"Client: Discarding selected content guess: "
1852 <<m_selected_content_guess.getItemString()<<std::endl;
1853 m_selected_content_guess.name = "";
1857 // If craftresult is nonempty and nothing else is selected, select it now.
1858 if(!m_selected_item)
1860 for(u32 i=0; i<m_inventorylists.size(); i++)
1862 const ListDrawSpec &s = m_inventorylists[i];
1863 if(s.listname == "craftpreview")
1865 Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
1866 InventoryList *list = inv->getList("craftresult");
1867 if(list && list->getSize() >= 1 && !list->getItem(0).empty())
1869 m_selected_item = new ItemSpec;
1870 m_selected_item->inventoryloc = s.inventoryloc;
1871 m_selected_item->listname = "craftresult";
1872 m_selected_item->i = 0;
1873 m_selected_amount = 0;
1874 m_selected_dragging = false;
1881 // If craftresult is selected, keep the whole stack selected
1882 if(m_selected_item && m_selected_item->listname == "craftresult")
1884 m_selected_amount = verifySelectedItem().count;
1888 ItemStack GUIFormSpecMenu::verifySelectedItem()
1890 // If the selected stack has become empty for some reason, deselect it.
1891 // If the selected stack has become inaccessible, deselect it.
1892 // If the selected stack has become smaller, adjust m_selected_amount.
1893 // Return the selected stack.
1897 if(m_selected_item->isValid())
1899 Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
1902 InventoryList *list = inv->getList(m_selected_item->listname);
1903 if(list && (u32) m_selected_item->i < list->getSize())
1905 ItemStack stack = list->getItem(m_selected_item->i);
1906 if(m_selected_amount > stack.count)
1907 m_selected_amount = stack.count;
1914 // selection was not valid
1915 delete m_selected_item;
1916 m_selected_item = NULL;
1917 m_selected_amount = 0;
1918 m_selected_dragging = false;
1923 void GUIFormSpecMenu::acceptInput(int eventtype)
1927 std::map<std::string, std::string> fields;
1929 if (current_keys_pending.key_down) {
1930 fields["key_down"] = "true";
1931 current_keys_pending.key_down = false;
1934 if (current_keys_pending.key_up) {
1935 fields["key_up"] = "true";
1936 current_keys_pending.key_up = false;
1939 if (current_keys_pending.key_enter) {
1940 fields["key_enter"] = "true";
1941 current_keys_pending.key_enter = false;
1944 if (current_keys_pending.key_escape) {
1945 fields["key_escape"] = "true";
1946 current_keys_pending.key_escape = false;
1949 for(u32 i=0; i<m_fields.size(); i++)
1951 const FieldSpec &s = m_fields[i];
1954 if(s.ftype == f_Button)
1956 fields[wide_to_narrow(s.fname.c_str())] = wide_to_narrow(s.flabel.c_str());
1958 else if(s.ftype == f_ListBox) {
1959 std::stringstream ss;
1960 if (eventtype == gui::EGET_LISTBOX_CHANGED) {
1966 ss << (getListboxIndex(wide_to_narrow(s.fname.c_str()))+1);
1967 fields[wide_to_narrow(s.fname.c_str())] = ss.str();
1969 else if(s.ftype == f_DropDown) {
1970 // no dynamic cast possible due to some distributions shipped
1971 // without rtti support in irrlicht
1972 IGUIElement * element = getElementFromId(s.fid);
1973 gui::IGUIComboBox *e = NULL;
1974 if ((element) && (element->getType() == gui::EGUIET_COMBO_BOX)) {
1975 e = static_cast<gui::IGUIComboBox*>(element);
1977 fields[wide_to_narrow(s.fname.c_str())] =
1978 wide_to_narrow(e->getItem(e->getSelected()));
1980 else if (s.ftype == f_TabHeader) {
1981 // no dynamic cast possible due to some distributions shipped
1982 // without rtti support in irrlicht
1983 IGUIElement * element = getElementFromId(s.fid);
1984 gui::IGUITabControl *e = NULL;
1985 if ((element) && (element->getType() == gui::EGUIET_TAB_CONTROL)) {
1986 e = static_cast<gui::IGUITabControl*>(element);
1990 std::stringstream ss;
1991 ss << (e->getActiveTab() +1);
1992 fields[wide_to_narrow(s.fname.c_str())] = ss.str();
1995 else if (s.ftype == f_CheckBox) {
1996 // no dynamic cast possible due to some distributions shipped
1997 // without rtti support in irrlicht
1998 IGUIElement * element = getElementFromId(s.fid);
1999 gui::IGUICheckBox *e = NULL;
2000 if ((element) && (element->getType() == gui::EGUIET_CHECK_BOX)) {
2001 e = static_cast<gui::IGUICheckBox*>(element);
2006 fields[wide_to_narrow(s.fname.c_str())] = "true";
2008 fields[wide_to_narrow(s.fname.c_str())] = "false";
2013 IGUIElement* e = getElementFromId(s.fid);
2016 fields[wide_to_narrow(s.fname.c_str())] = wide_to_narrow(e->getText());
2022 m_text_dst->gotText(fields);
2026 bool GUIFormSpecMenu::OnEvent(const SEvent& event)
2028 if(event.EventType==EET_KEY_INPUT_EVENT)
2030 KeyPress kp(event.KeyInput);
2031 if (event.KeyInput.PressedDown && (kp == EscapeKey ||
2032 kp == getKeySetting("keymap_inventory")))
2037 m_text_dst->gotText(narrow_to_wide("MenuQuit"));
2040 if (event.KeyInput.PressedDown &&
2041 (event.KeyInput.Key==KEY_RETURN ||
2042 event.KeyInput.Key==KEY_UP ||
2043 event.KeyInput.Key==KEY_DOWN)
2047 switch (event.KeyInput.Key) {
2054 current_keys_pending.key_enter = true;
2057 current_keys_pending.key_up = true;
2060 current_keys_pending.key_down = true;
2064 //can't happen at all!
2065 assert("reached a source line that can't ever been reached" == 0);
2073 if(event.EventType==EET_MOUSE_INPUT_EVENT
2074 && event.MouseInput.Event != EMIE_MOUSE_MOVED)
2076 // Mouse event other than movement
2078 // Get selected item and hovered/clicked item (s)
2080 updateSelectedItem();
2081 ItemSpec s = getItemAtPos(m_pointer);
2083 Inventory *inv_selected = NULL;
2084 Inventory *inv_s = NULL;
2088 inv_selected = m_invmgr->getInventory(m_selected_item->inventoryloc);
2089 assert(inv_selected);
2090 assert(inv_selected->getList(m_selected_item->listname) != NULL);
2097 inv_s = m_invmgr->getInventory(s.inventoryloc);
2100 errorstream<<"InventoryMenu: The selected inventory location "
2101 <<"\""<<s.inventoryloc.dump()<<"\" doesn't exist"
2103 s.i = -1; // make it invalid again
2107 InventoryList *list = inv_s->getList(s.listname);
2109 verbosestream<<"InventoryMenu: The selected inventory list \""
2110 <<s.listname<<"\" does not exist"<<std::endl;
2111 s.i = -1; // make it invalid again
2115 if((u32)s.i >= list->getSize()){
2116 infostream<<"InventoryMenu: The selected inventory list \""
2117 <<s.listname<<"\" is too small (i="<<s.i<<", size="
2118 <<list->getSize()<<")"<<std::endl;
2119 s.i = -1; // make it invalid again
2123 s_count = list->getItem(s.i).count;
2126 bool identical = (m_selected_item != NULL) && s.isValid() &&
2127 (inv_selected == inv_s) &&
2128 (m_selected_item->listname == s.listname) &&
2129 (m_selected_item->i == s.i);
2131 // buttons: 0 = left, 1 = right, 2 = middle
2132 // up/down: 0 = down (press), 1 = up (release), 2 = unknown event
2135 if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
2136 { button = 0; updown = 0; }
2137 else if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
2138 { button = 1; updown = 0; }
2139 else if(event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN)
2140 { button = 2; updown = 0; }
2141 else if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
2142 { button = 0; updown = 1; }
2143 else if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
2144 { button = 1; updown = 1; }
2145 else if(event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP)
2146 { button = 2; updown = 1; }
2148 // Set this number to a positive value to generate a move action
2149 // from m_selected_item to s.
2150 u32 move_amount = 0;
2152 // Set this number to a positive value to generate a drop action
2153 // from m_selected_item.
2154 u32 drop_amount = 0;
2156 // Set this number to a positive value to generate a craft action at s.
2157 u32 craft_amount = 0;
2161 // Some mouse button has been pressed
2163 //infostream<<"Mouse button "<<button<<" pressed at p=("
2164 // <<p.X<<","<<p.Y<<")"<<std::endl;
2166 m_selected_dragging = false;
2168 if(s.isValid() && s.listname == "craftpreview")
2170 // Craft preview has been clicked: craft
2171 craft_amount = (button == 2 ? 10 : 1);
2173 else if(m_selected_item == NULL)
2177 // Non-empty stack has been clicked: select it
2178 m_selected_item = new ItemSpec(s);
2180 if(button == 1) // right
2181 m_selected_amount = (s_count + 1) / 2;
2182 else if(button == 2) // middle
2183 m_selected_amount = MYMIN(s_count, 10);
2185 m_selected_amount = s_count;
2187 m_selected_dragging = true;
2190 else // m_selected_item != NULL
2192 assert(m_selected_amount >= 1);
2196 // Clicked a slot: move
2197 if(button == 1) // right
2199 else if(button == 2) // middle
2200 move_amount = MYMIN(m_selected_amount, 10);
2202 move_amount = m_selected_amount;
2206 if(move_amount >= m_selected_amount)
2207 m_selected_amount = 0;
2209 m_selected_amount -= move_amount;
2213 else if(getAbsoluteClippingRect().isPointInside(m_pointer))
2215 // Clicked somewhere else: deselect
2216 m_selected_amount = 0;
2220 // Clicked outside of the window: drop
2221 if(button == 1) // right
2223 else if(button == 2) // middle
2224 drop_amount = MYMIN(m_selected_amount, 10);
2226 drop_amount = m_selected_amount;
2230 else if(updown == 1)
2232 // Some mouse button has been released
2234 //infostream<<"Mouse button "<<button<<" released at p=("
2235 // <<p.X<<","<<p.Y<<")"<<std::endl;
2237 if(m_selected_item != NULL && m_selected_dragging && s.isValid())
2241 // Dragged to different slot: move all selected
2242 move_amount = m_selected_amount;
2245 else if(m_selected_item != NULL && m_selected_dragging &&
2246 !(getAbsoluteClippingRect().isPointInside(m_pointer)))
2248 // Dragged outside of window: drop all selected
2249 drop_amount = m_selected_amount;
2252 m_selected_dragging = false;
2255 // Possibly send inventory action to server
2258 // Send IACTION_MOVE
2260 assert(m_selected_item && m_selected_item->isValid());
2261 assert(s.isValid());
2263 assert(inv_selected && inv_s);
2264 InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
2265 InventoryList *list_to = inv_s->getList(s.listname);
2266 assert(list_from && list_to);
2267 ItemStack stack_from = list_from->getItem(m_selected_item->i);
2268 ItemStack stack_to = list_to->getItem(s.i);
2270 // Check how many items can be moved
2271 move_amount = stack_from.count = MYMIN(move_amount, stack_from.count);
2272 ItemStack leftover = stack_to.addItem(stack_from, m_gamedef->idef());
2273 // If source stack cannot be added to destination stack at all,
2275 if(leftover.count == stack_from.count && leftover.name == stack_from.name)
2277 m_selected_amount = stack_to.count;
2278 // In case the server doesn't directly swap them but instead
2279 // moves stack_to somewhere else, set this
2280 m_selected_content_guess = stack_to;
2281 m_selected_content_guess_inventory = s.inventoryloc;
2283 // Source stack goes fully into destination stack
2284 else if(leftover.empty())
2286 m_selected_amount -= move_amount;
2287 m_selected_content_guess = ItemStack(); // Clear
2289 // Source stack goes partly into destination stack
2292 move_amount -= leftover.count;
2293 m_selected_amount -= move_amount;
2294 m_selected_content_guess = ItemStack(); // Clear
2297 infostream<<"Handing IACTION_MOVE to manager"<<std::endl;
2298 IMoveAction *a = new IMoveAction();
2299 a->count = move_amount;
2300 a->from_inv = m_selected_item->inventoryloc;
2301 a->from_list = m_selected_item->listname;
2302 a->from_i = m_selected_item->i;
2303 a->to_inv = s.inventoryloc;
2304 a->to_list = s.listname;
2306 m_invmgr->inventoryAction(a);
2308 else if(drop_amount > 0)
2310 m_selected_content_guess = ItemStack(); // Clear
2312 // Send IACTION_DROP
2314 assert(m_selected_item && m_selected_item->isValid());
2315 assert(inv_selected);
2316 InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
2318 ItemStack stack_from = list_from->getItem(m_selected_item->i);
2320 // Check how many items can be dropped
2321 drop_amount = stack_from.count = MYMIN(drop_amount, stack_from.count);
2322 assert(drop_amount > 0 && drop_amount <= m_selected_amount);
2323 m_selected_amount -= drop_amount;
2325 infostream<<"Handing IACTION_DROP to manager"<<std::endl;
2326 IDropAction *a = new IDropAction();
2327 a->count = drop_amount;
2328 a->from_inv = m_selected_item->inventoryloc;
2329 a->from_list = m_selected_item->listname;
2330 a->from_i = m_selected_item->i;
2331 m_invmgr->inventoryAction(a);
2333 else if(craft_amount > 0)
2335 m_selected_content_guess = ItemStack(); // Clear
2337 // Send IACTION_CRAFT
2339 assert(s.isValid());
2342 infostream<<"Handing IACTION_CRAFT to manager"<<std::endl;
2343 ICraftAction *a = new ICraftAction();
2344 a->count = craft_amount;
2345 a->craft_inv = s.inventoryloc;
2346 m_invmgr->inventoryAction(a);
2349 // If m_selected_amount has been decreased to zero, deselect
2350 if(m_selected_amount == 0)
2352 delete m_selected_item;
2353 m_selected_item = NULL;
2354 m_selected_amount = 0;
2355 m_selected_dragging = false;
2356 m_selected_content_guess = ItemStack();
2359 if(event.EventType==EET_GUI_EVENT)
2362 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED
2365 // find the element that was clicked
2366 for(u32 i=0; i<m_fields.size(); i++)
2368 FieldSpec &s = m_fields[i];
2369 // if its a button, set the send field so
2370 // lua knows which button was pressed
2371 if ((s.ftype == f_TabHeader) && (s.fid == event.GUIEvent.Caller->getID()))
2376 // Restore focus to the full form
2377 Environment->setFocus(this);
2382 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
2385 if(!canTakeFocus(event.GUIEvent.Element))
2387 infostream<<"GUIFormSpecMenu: Not allowing focus change."
2389 // Returning true disables focus change
2393 if((event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) ||
2394 (event.GUIEvent.EventType==gui::EGET_CHECKBOX_CHANGED))
2396 unsigned int btn_id = event.GUIEvent.Caller->getID();
2398 if (btn_id == 257) {
2403 m_text_dst->gotText(narrow_to_wide("ExitButton"));
2404 // quitMenu deallocates menu
2408 // find the element that was clicked
2409 for(u32 i=0; i<m_fields.size(); i++)
2411 FieldSpec &s = m_fields[i];
2412 // if its a button, set the send field so
2413 // lua knows which button was pressed
2414 if (((s.ftype == f_Button) || (s.ftype == f_CheckBox)) &&
2415 (s.fid == event.GUIEvent.Caller->getID()))
2423 m_text_dst->gotText(narrow_to_wide("ExitButton"));
2427 // Restore focus to the full form
2428 Environment->setFocus(this);
2434 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
2436 if(event.GUIEvent.Caller->getID() > 257)
2444 current_keys_pending.key_enter = true;
2447 // quitMenu deallocates menu
2452 if((event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN) ||
2453 (event.GUIEvent.EventType==gui::EGET_LISTBOX_CHANGED))
2455 int current_id = event.GUIEvent.Caller->getID();
2456 if(current_id > 257)
2458 // find the element that was clicked
2459 for(u32 i=0; i<m_fields.size(); i++)
2461 FieldSpec &s = m_fields[i];
2462 // if its a button, set the send field so
2463 // lua knows which button was pressed
2464 if ((s.ftype == f_ListBox) && (s.fid == current_id))
2467 acceptInput(event.GUIEvent.EventType);
2469 // Restore focus to the full form
2470 Environment->setFocus(this);
2478 return Parent ? Parent->OnEvent(event) : false;
2481 bool GUIFormSpecMenu::parseColor(std::string color, irr::video::SColor& outcolor) {
2482 outcolor = irr::video::SColor(0,0,0,0);
2484 if (!string_allowed(color, "0123456789abcdefABCDEF"))
2488 std::istringstream iss(color);
2489 iss >> std::hex >> color_value;
2491 outcolor = irr::video::SColor(color_value);
2493 outcolor.setAlpha(255);