Skip to content

Commit d5c3db9

Browse files
committedMay 7, 2016
Make dropdowns show the string that was their argument.
This makes it work even if it contains escape sequences, which didn't work before.
1 parent bb92547 commit d5c3db9

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
 

‎src/guiFormSpecMenu.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
240240
return 0;
241241
}
242242

243+
std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &name)
244+
{
245+
for (u32 i = 0; i < m_dropdowns.size(); ++i) {
246+
if (name == m_dropdowns[i].first.fname)
247+
return &m_dropdowns[i].second;
248+
}
249+
return NULL;
250+
}
251+
243252
static std::vector<std::string> split(const std::string &s, char delim)
244253
{
245254
std::vector<std::string> tokens;
@@ -894,6 +903,14 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
894903
e->setSelected(stoi(str_initial_selection.c_str())-1);
895904

896905
m_fields.push_back(spec);
906+
907+
m_dropdowns.push_back(std::pair<FieldSpec,
908+
std::vector<std::string> >(spec, std::vector<std::string>()));
909+
std::vector<std::string> &values = m_dropdowns.back().second;
910+
for (unsigned int i = 0; i < items.size(); i++) {
911+
values.push_back(unescape_string(items[i]));
912+
}
913+
897914
return;
898915
}
899916
errorstream << "Invalid dropdown element(" << parts.size() << "): '"
@@ -2725,8 +2742,11 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
27252742
}
27262743
s32 selected = e->getSelected();
27272744
if (selected >= 0) {
2728-
fields[name] =
2729-
wide_to_utf8(e->getItem(selected));
2745+
std::vector<std::string> *dropdown_values =
2746+
getDropDownValues(s.fname);
2747+
if (dropdown_values && selected < (s32)dropdown_values->size()) {
2748+
fields[name] = (*dropdown_values)[selected];
2749+
}
27302750
}
27312751
}
27322752
else if (s.ftype == f_TabHeader) {

‎src/guiFormSpecMenu.h

+2
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ class GUIFormSpecMenu : public GUIModalMenu
357357
bool pausesGame() { return doPause; }
358358

359359
GUITable* getTable(const std::string &tablename);
360+
std::vector<std::string>* getDropDownValues(const std::string &name);
360361

361362
#ifdef __ANDROID__
362363
bool getAndroidUIInput();
@@ -395,6 +396,7 @@ class GUIFormSpecMenu : public GUIModalMenu
395396
std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
396397
std::map<std::string, TooltipSpec> m_tooltips;
397398
std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
399+
std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
398400

399401
ItemSpec *m_selected_item;
400402
f32 m_timer1;

0 commit comments

Comments
 (0)
Please sign in to comment.