@@ -240,6 +240,15 @@ GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
240
240
return 0 ;
241
241
}
242
242
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
+
243
252
static std::vector<std::string> split (const std::string &s, char delim)
244
253
{
245
254
std::vector<std::string> tokens;
@@ -894,6 +903,14 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
894
903
e->setSelected (stoi (str_initial_selection.c_str ())-1 );
895
904
896
905
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
+
897
914
return ;
898
915
}
899
916
errorstream << " Invalid dropdown element(" << parts.size () << " ): '"
@@ -2725,8 +2742,11 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
2725
2742
}
2726
2743
s32 selected = e->getSelected ();
2727
2744
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
+ }
2730
2750
}
2731
2751
}
2732
2752
else if (s.ftype == f_TabHeader) {
0 commit comments