aboutsummaryrefslogtreecommitdiff
path: root/src/guiFormSpecMenu.cpp
diff options
context:
space:
mode:
authorEkdohibs <nathanael.courant@laposte.net>2016-05-05 18:50:02 +0200
committerEkdohibs <nathanael.courant@laposte.net>2016-05-07 08:33:21 +0200
commitd5c3db9c4179e27a80c32ee95d6573ad0ec7137e (patch)
treeba75f7bbc30f2ec738e5d3cae3e7074ef794fa51 /src/guiFormSpecMenu.cpp
parentbb925479a56e7b961e3520024c20b74245640035 (diff)
downloadminetest-d5c3db9c4179e27a80c32ee95d6573ad0ec7137e.tar.gz
minetest-d5c3db9c4179e27a80c32ee95d6573ad0ec7137e.tar.bz2
minetest-d5c3db9c4179e27a80c32ee95d6573ad0ec7137e.zip
Make dropdowns show the string that was their argument.
This makes it work even if it contains escape sequences, which didn't work before.
Diffstat (limited to 'src/guiFormSpecMenu.cpp')
-rw-r--r--src/guiFormSpecMenu.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp
index 23cff3eb7..ca374151f 100644
--- a/src/guiFormSpecMenu.cpp
+++ b/src/guiFormSpecMenu.cpp
@@ -240,6 +240,15 @@ GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
return 0;
}
+std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &name)
+{
+ for (u32 i = 0; i < m_dropdowns.size(); ++i) {
+ if (name == m_dropdowns[i].first.fname)
+ return &m_dropdowns[i].second;
+ }
+ return NULL;
+}
+
static std::vector<std::string> split(const std::string &s, char delim)
{
std::vector<std::string> tokens;
@@ -894,6 +903,14 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
e->setSelected(stoi(str_initial_selection.c_str())-1);
m_fields.push_back(spec);
+
+ m_dropdowns.push_back(std::pair<FieldSpec,
+ std::vector<std::string> >(spec, std::vector<std::string>()));
+ std::vector<std::string> &values = m_dropdowns.back().second;
+ for (unsigned int i = 0; i < items.size(); i++) {
+ values.push_back(unescape_string(items[i]));
+ }
+
return;
}
errorstream << "Invalid dropdown element(" << parts.size() << "): '"
@@ -2725,8 +2742,11 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
}
s32 selected = e->getSelected();
if (selected >= 0) {
- fields[name] =
- wide_to_utf8(e->getItem(selected));
+ std::vector<std::string> *dropdown_values =
+ getDropDownValues(s.fname);
+ if (dropdown_values && selected < (s32)dropdown_values->size()) {
+ fields[name] = (*dropdown_values)[selected];
+ }
}
}
else if (s.ftype == f_TabHeader) {