mirror of
https://github.com/minetest/minetest.git
synced 2025-03-31 07:32:32 +02:00
Make dropdowns show the string that was their argument.
This makes it work even if it contains escape sequences, which didn't work before.
This commit is contained in:
@ -240,6 +240,15 @@ GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
|
|||||||
return 0;
|
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)
|
static std::vector<std::string> split(const std::string &s, char delim)
|
||||||
{
|
{
|
||||||
std::vector<std::string> tokens;
|
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);
|
e->setSelected(stoi(str_initial_selection.c_str())-1);
|
||||||
|
|
||||||
m_fields.push_back(spec);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
errorstream << "Invalid dropdown element(" << parts.size() << "): '"
|
errorstream << "Invalid dropdown element(" << parts.size() << "): '"
|
||||||
@ -2725,8 +2742,11 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
|
|||||||
}
|
}
|
||||||
s32 selected = e->getSelected();
|
s32 selected = e->getSelected();
|
||||||
if (selected >= 0) {
|
if (selected >= 0) {
|
||||||
fields[name] =
|
std::vector<std::string> *dropdown_values =
|
||||||
wide_to_utf8(e->getItem(selected));
|
getDropDownValues(s.fname);
|
||||||
|
if (dropdown_values && selected < (s32)dropdown_values->size()) {
|
||||||
|
fields[name] = (*dropdown_values)[selected];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (s.ftype == f_TabHeader) {
|
else if (s.ftype == f_TabHeader) {
|
||||||
|
@ -357,6 +357,7 @@ public:
|
|||||||
bool pausesGame() { return doPause; }
|
bool pausesGame() { return doPause; }
|
||||||
|
|
||||||
GUITable* getTable(const std::string &tablename);
|
GUITable* getTable(const std::string &tablename);
|
||||||
|
std::vector<std::string>* getDropDownValues(const std::string &name);
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
bool getAndroidUIInput();
|
bool getAndroidUIInput();
|
||||||
@ -395,6 +396,7 @@ protected:
|
|||||||
std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
|
std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
|
||||||
std::map<std::string, TooltipSpec> m_tooltips;
|
std::map<std::string, TooltipSpec> m_tooltips;
|
||||||
std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
|
std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
|
||||||
|
std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
|
||||||
|
|
||||||
ItemSpec *m_selected_item;
|
ItemSpec *m_selected_item;
|
||||||
f32 m_timer1;
|
f32 m_timer1;
|
||||||
|
Reference in New Issue
Block a user