diff options
author | v-rob <robinsonvincent89@gmail.com> | 2020-07-10 03:11:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-10 12:11:26 +0200 |
commit | b1ff04e06da531dc52f6ee91e2967b39743033e6 (patch) | |
tree | 3d1af58d8c8003c5099122d0021b46d87c076c6f /src/gui/guiFormSpecMenu.cpp | |
parent | 2384c10e104fd0c945f3677130e7d25c0a841482 (diff) | |
download | minetest-b1ff04e06da531dc52f6ee91e2967b39743033e6.tar.gz minetest-b1ff04e06da531dc52f6ee91e2967b39743033e6.tar.bz2 minetest-b1ff04e06da531dc52f6ee91e2967b39743033e6.zip |
Formspec: Make dropdowns optionally return event based on index, not value (#9496)
Diffstat (limited to 'src/gui/guiFormSpecMenu.cpp')
-rw-r--r-- | src/gui/guiFormSpecMenu.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 37edf3c4b..54fc94993 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1318,19 +1318,20 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element errorstream<< "Invalid textlist element(" << parts.size() << "): '" << element << "'" << std::endl; } - void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element) { - std::vector<std::string> parts = split(element,';'); + std::vector<std::string> parts = split(element, ';'); - if ((parts.size() == 5) || - ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION))) + if (parts.size() == 5 || parts.size() == 6 || + (parts.size() > 6 && m_formspec_version > FORMSPEC_API_VERSION)) { - std::vector<std::string> v_pos = split(parts[0],','); + std::vector<std::string> v_pos = split(parts[0], ','); std::string name = parts[2]; - std::vector<std::string> items = split(parts[3],','); - std::string str_initial_selection; - str_initial_selection = parts[4]; + std::vector<std::string> items = split(parts[3], ','); + std::string str_initial_selection = parts[4]; + + if (parts.size() >= 6 && is_yes(parts[5])) + m_dropdown_index_event[name] = true; MY_CHECKPOS("dropdown",0); @@ -1397,8 +1398,8 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element return; } - errorstream << "Invalid dropdown element(" << parts.size() << "): '" - << element << "'" << std::endl; + errorstream << "Invalid dropdown element(" << parts.size() << "): '" << element + << "'" << std::endl; } void GUIFormSpecMenu::parseFieldCloseOnEnter(parserData *data, const std::string &element) @@ -1414,8 +1415,8 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element { std::vector<std::string> parts = split(element,';'); - if ((parts.size() == 4) || - ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION))) + if (parts.size() == 4 || + (parts.size() > 4 && m_formspec_version > FORMSPEC_API_VERSION)) { std::vector<std::string> v_pos = split(parts[0],','); std::vector<std::string> v_geom = split(parts[1],','); @@ -2940,6 +2941,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) theme_by_name.clear(); theme_by_type.clear(); m_clickthrough_elements.clear(); + field_close_on_enter.clear(); + m_dropdown_index_event.clear(); m_bgnonfullscreen = true; m_bgfullscreen = false; @@ -3727,10 +3730,14 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) } s32 selected = e->getSelected(); if (selected >= 0) { - std::vector<std::string> *dropdown_values = - getDropDownValues(s.fname); - if (dropdown_values && selected < (s32)dropdown_values->size()) { - fields[name] = (*dropdown_values)[selected]; + if (m_dropdown_index_event.find(s.fname) != + m_dropdown_index_event.end()) { + fields[name] = std::to_string(selected + 1); + } else { + 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) { |