]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiFormSpecMenu.cpp
Move hex.h to util/
[dragonfireclient.git] / src / guiFormSpecMenu.cpp
index 22fbf0cfc1555ed970e104f1ff0b2c6de8ec5289..a3cc0313108bf1986dbfd5f88ed30feece2f9a5b 100644 (file)
@@ -39,9 +39,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "log.h"
 #include "tile.h" // ITextureSource
 #include "hud.h" // drawItemStack
-#include "hex.h"
-#include "util/string.h"
-#include "util/numeric.h"
 #include "filesys.h"
 #include "gettime.h"
 #include "gettext.h"
@@ -50,8 +47,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "main.h"
 #include "settings.h"
 #include "client.h"
-#include "util/string.h" // for parseColorString()
 #include "fontengine.h"
+#include "util/hex.h"
+#include "util/numeric.h"
+#include "util/string.h" // for parseColorString()
 
 #define MY_CHECKPOS(a,b)                                                                                                       \
        if (v_pos.size() != 2) {                                                                                                \
@@ -97,6 +96,7 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
        m_form_src(fsrc),
        m_text_dst(tdst),
        m_formspec_version(0),
+       m_focused_element(L""),
        m_font(NULL)
 #ifdef __ANDROID__
        ,m_JavaDialogFieldName(L"")
@@ -374,7 +374,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
                if (selected == "true")
                        fselected = true;
 
-               std::wstring wlabel = narrow_to_wide(label.c_str());
+               std::wstring wlabel = narrow_to_wide(label);
 
                core::rect<s32> rect = core::rect<s32>(
                                pos.X, pos.Y + ((imgsize.Y/2) - m_btn_height),
@@ -382,7 +382,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
                                pos.Y + ((imgsize.Y/2) + m_btn_height));
 
                FieldSpec spec(
-                               narrow_to_wide(name.c_str()),
+                               narrow_to_wide(name),
                                wlabel, //Needed for displaying text on MSVC
                                wlabel,
                                258+m_fields.size()
@@ -434,7 +434,7 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, std::string element)
                                core::rect<s32>(pos.X, pos.Y, pos.X + dim.X, pos.Y + dim.Y);
 
                FieldSpec spec(
-                               narrow_to_wide(name.c_str()),
+                               narrow_to_wide(name),
                                L"",
                                L"",
                                258+m_fields.size()
@@ -572,10 +572,10 @@ void GUIFormSpecMenu::parseButton(parserData* data,std::string element,
 
                label = unescape_string(label);
 
-               std::wstring wlabel = narrow_to_wide(label.c_str());
+               std::wstring wlabel = narrow_to_wide(label);
 
                FieldSpec spec(
-                       narrow_to_wide(name.c_str()),
+                       narrow_to_wide(name),
                        wlabel,
                        L"",
                        258+m_fields.size()
@@ -697,7 +697,7 @@ void GUIFormSpecMenu::parseTable(parserData* data,std::string element)
 
                core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
 
-               std::wstring fname_w = narrow_to_wide(name.c_str());
+               std::wstring fname_w = narrow_to_wide(name);
 
                FieldSpec spec(
                        fname_w,
@@ -771,7 +771,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element)
 
                core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
 
-               std::wstring fname_w = narrow_to_wide(name.c_str());
+               std::wstring fname_w = narrow_to_wide(name);
 
                FieldSpec spec(
                        fname_w,
@@ -836,7 +836,7 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
                core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y,
                                pos.X + width, pos.Y + (m_btn_height * 2));
 
-               std::wstring fname_w = narrow_to_wide(name.c_str());
+               std::wstring fname_w = narrow_to_wide(name);
 
                FieldSpec spec(
                        fname_w,
@@ -899,10 +899,10 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
 
                label = unescape_string(label);
 
-               std::wstring wlabel = narrow_to_wide(label.c_str());
+               std::wstring wlabel = narrow_to_wide(label);
 
                FieldSpec spec(
-                       narrow_to_wide(name.c_str()),
+                       narrow_to_wide(name),
                        wlabel,
                        L"",
                        258+m_fields.size()
@@ -965,12 +965,12 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
        default_val = unescape_string(default_val);
        label = unescape_string(label);
 
-       std::wstring wlabel = narrow_to_wide(label.c_str());
+       std::wstring wlabel = narrow_to_wide(label);
 
        FieldSpec spec(
-               narrow_to_wide(name.c_str()),
+               narrow_to_wide(name),
                wlabel,
-               narrow_to_wide(default_val.c_str()),
+               narrow_to_wide(default_val),
                258+m_fields.size()
        );
 
@@ -1055,12 +1055,12 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,
        default_val = unescape_string(default_val);
        label = unescape_string(label);
 
-       std::wstring wlabel = narrow_to_wide(label.c_str());
+       std::wstring wlabel = narrow_to_wide(label);
 
        FieldSpec spec(
-               narrow_to_wide(name.c_str()),
+               narrow_to_wide(name),
                wlabel,
-               narrow_to_wide(default_val.c_str()),
+               narrow_to_wide(default_val),
                258+m_fields.size()
        );
 
@@ -1158,7 +1158,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
                        // in the integer cases: 0.4 is not exactly
                        // representable in binary floating point.
                        s32 posy = pos.Y + ((float)i) * spacing.Y * 2.0 / 5.0;
-                       std::wstring wlabel = narrow_to_wide(lines[i].c_str());
+                       std::wstring wlabel = narrow_to_wide(lines[i]);
                        core::rect<s32> rect = core::rect<s32>(
                                pos.X, posy - m_btn_height,
                                pos.X + m_font->getDimension(wlabel.c_str()).Width,
@@ -1279,12 +1279,12 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
                pressed_image_name = unescape_string(pressed_image_name);
                label = unescape_string(label);
 
-               std::wstring wlabel = narrow_to_wide(label.c_str());
+               std::wstring wlabel = narrow_to_wide(label);
 
                FieldSpec spec(
-                       narrow_to_wide(name.c_str()),
+                       narrow_to_wide(name),
                        wlabel,
-                       narrow_to_wide(image_name.c_str()),
+                       narrow_to_wide(image_name),
                        258+m_fields.size()
                );
                spec.ftype = f_Button;
@@ -1344,7 +1344,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element)
                }
 
                FieldSpec spec(
-                       narrow_to_wide(name.c_str()),
+                       narrow_to_wide(name),
                        L"",
                        L"",
                        258+m_fields.size()
@@ -1431,16 +1431,16 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
                item.deSerialize(item_name, idef);
                video::ITexture *texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_gamedef);
 
-               m_tooltips[narrow_to_wide(name.c_str())] =
+               m_tooltips[narrow_to_wide(name)] =
                        TooltipSpec (item.getDefinition(idef).description,
                                                m_default_tooltip_bgcolor,
                                                m_default_tooltip_color);
 
                label = unescape_string(label);
                FieldSpec spec(
-                       narrow_to_wide(name.c_str()),
-                       narrow_to_wide(label.c_str()),
-                       narrow_to_wide(item_name.c_str()),
+                       narrow_to_wide(name),
+                       narrow_to_wide(label),
+                       narrow_to_wide(item_name),
                        258+m_fields.size()
                );
 
@@ -1550,13 +1550,13 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, std::string element)
        std::vector<std::string> parts = split(element,';');
        if (parts.size() == 2) {
                std::string name = parts[0];
-               m_tooltips[narrow_to_wide(name.c_str())] = TooltipSpec (parts[1], m_default_tooltip_bgcolor, m_default_tooltip_color);
+               m_tooltips[narrow_to_wide(name)] = TooltipSpec (parts[1], m_default_tooltip_bgcolor, m_default_tooltip_color);
                return;
        } else if (parts.size() == 4) {
                std::string name = parts[0];
                video::SColor tmp_color1, tmp_color2;
                if ( parseColorString(parts[2], tmp_color1, false) && parseColorString(parts[3], tmp_color2, false) ) {
-                       m_tooltips[narrow_to_wide(name.c_str())] = TooltipSpec (parts[1], tmp_color1, tmp_color2);
+                       m_tooltips[narrow_to_wide(name)] = TooltipSpec (parts[1], tmp_color1, tmp_color2);
                        return;
                }
        }
@@ -1757,8 +1757,6 @@ void GUIFormSpecMenu::parseElement(parserData* data, std::string element)
                <<std::endl;
 }
 
-
-
 void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
 {
        /* useless to regenerate without a screensize */
@@ -1775,6 +1773,10 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                mydata.table_dyndata[tablename] = table->getDynamicData();
        }
 
+       //set focus
+       if (!m_focused_element.empty())
+               mydata.focused_fieldname = m_focused_element;
+
        //preserve focus
        gui::IGUIElement *focused_element = Environment->getFocus();
        if (focused_element && focused_element->getParent() == this) {
@@ -2000,7 +2002,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
                        mydata.rect =
                                        core::rect<s32>(size.X/2-70, pos.Y,
                                                        (size.X/2-70)+140, pos.Y + (m_btn_height*2));
-                       wchar_t* text = wgettext("Proceed");
+                       const wchar_t *text = wgettext("Proceed");
                        Environment->addButton(mydata.rect, this, 257, text);
                        delete[] text;
                }