diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/guiPathSelectMenu.cpp (renamed from src/guiFileSelectMenu.cpp) | 92 | ||||
-rw-r--r-- | src/guiPathSelectMenu.h (renamed from src/guiFileSelectMenu.h) | 5 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 10 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.h | 2 |
5 files changed, 54 insertions, 57 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6963d0306..08ea809c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -509,7 +509,7 @@ set(client_SRCS game.cpp guiChatConsole.cpp guiEngine.cpp - guiFileSelectMenu.cpp + guiPathSelectMenu.cpp guiFormSpecMenu.cpp guiKeyChangeMenu.cpp guiPasswordChange.cpp diff --git a/src/guiFileSelectMenu.cpp b/src/guiPathSelectMenu.cpp index 65a07be39..d992d8c0f 100644 --- a/src/guiFileSelectMenu.cpp +++ b/src/guiPathSelectMenu.cpp @@ -17,16 +17,18 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "guiFileSelectMenu.h" +#include "guiPathSelectMenu.h" GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, - const std::string &title, const std::string &formname) : + const std::string &title, const std::string &formname, + bool is_file_select) : GUIModalMenu(env, parent, id, menumgr), m_title(utf8_to_wide(title)), m_accepted(false), m_text_dst(NULL), - m_formname(formname) + m_formname(formname), + m_file_select_dialog(is_file_select) { } @@ -36,83 +38,77 @@ GUIFileSelectMenu::~GUIFileSelectMenu() setlocale(LC_NUMERIC, "C"); } -void GUIFileSelectMenu::removeChildren() -{ - const core::list<gui::IGUIElement*> &children = getChildren(); - core::list<gui::IGUIElement*> children_copy; - for (core::list<gui::IGUIElement*>::ConstIterator i = children.begin(); i - != children.end(); i++) - { - children_copy.push_back(*i); - } - for (core::list<gui::IGUIElement*>::Iterator i = children_copy.begin(); i - != children_copy.end(); i++) - { - (*i)->remove(); - } -} - void GUIFileSelectMenu::regenerateGui(v2u32 screensize) { removeChildren(); m_fileOpenDialog = 0; - core::dimension2du size(600,400); - core::rect < s32 > rect(0,0,screensize.X,screensize.Y); + core::dimension2du size(600, 400); + core::rect<s32> rect(0, 0, screensize.X, screensize.Y); DesiredRect = rect; recalculateAbsolutePosition(false); m_fileOpenDialog = - Environment->addFileOpenDialog(m_title.c_str(),false,this,-1); + Environment->addFileOpenDialog(m_title.c_str(), false, this, -1); - core::position2di pos = core::position2di(screensize.X/2 - size.Width/2,screensize.Y/2 -size.Height/2); + core::position2di pos = core::position2di(screensize.X / 2 - size.Width / 2, + screensize.Y / 2 - size.Height / 2); m_fileOpenDialog->setRelativePosition(pos); m_fileOpenDialog->setMinSize(size); } void GUIFileSelectMenu::drawMenu() { - gui::IGUISkin* skin = Environment->getSkin(); + gui::IGUISkin *skin = Environment->getSkin(); if (!skin) return; gui::IGUIElement::draw(); } -void GUIFileSelectMenu::acceptInput() { - if ((m_text_dst != 0) && (this->m_formname != "")){ +void GUIFileSelectMenu::acceptInput() +{ + if ((m_text_dst != 0) && (this->m_formname != "")) { StringMap fields; - - if (m_accepted) - fields[m_formname + "_accepted"] = wide_to_utf8(m_fileOpenDialog->getFileName()); - else + if (m_accepted) { + std::string path; + if (!m_file_select_dialog) { + core::string<fschar_t> string = + m_fileOpenDialog->getDirectoryName(); + path = std::string(string.c_str()); + } else { + path = wide_to_utf8(m_fileOpenDialog->getFileName()); + } + fields[m_formname + "_accepted"] = path; + } else { fields[m_formname + "_canceled"] = m_formname; - + } this->m_text_dst->gotText(fields); } + quitMenu(); } -bool GUIFileSelectMenu::OnEvent(const SEvent& event) +bool GUIFileSelectMenu::OnEvent(const SEvent &event) { - if (event.EventType == irr::EET_GUI_EVENT) { switch (event.GUIEvent.EventType) { - case gui::EGET_ELEMENT_CLOSED: - case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED: - m_accepted=false; - acceptInput(); - quitMenu(); - return true; - case gui::EGET_DIRECTORY_SELECTED: - case gui::EGET_FILE_SELECTED: - m_accepted=true; - acceptInput(); - quitMenu(); - return true; - default: - //ignore this event - break; + case gui::EGET_ELEMENT_CLOSED: + case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED: + m_accepted = false; + acceptInput(); + return true; + case gui::EGET_DIRECTORY_SELECTED: + m_accepted = !m_file_select_dialog; + acceptInput(); + return true; + case gui::EGET_FILE_SELECTED: + m_accepted = m_file_select_dialog; + acceptInput(); + return true; + default: + // ignore this event + break; } } return Parent ? Parent->OnEvent(event) : false; diff --git a/src/guiFileSelectMenu.h b/src/guiPathSelectMenu.h index 034823740..add4e36af 100644 --- a/src/guiFileSelectMenu.h +++ b/src/guiPathSelectMenu.h @@ -31,11 +31,9 @@ class GUIFileSelectMenu : public GUIModalMenu public: GUIFileSelectMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, const std::string &title, - const std::string &formid); + const std::string &formid, bool is_file_select); ~GUIFileSelectMenu(); - void removeChildren(); - /* Remove and re-add (or reposition) stuff */ @@ -58,6 +56,7 @@ private: TextDest *m_text_dst; std::string m_formname; + bool m_file_select_dialog; }; #endif /* GUIFILESELECTMENU_H_ */ diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 388971814..3ed2ba0e0 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiEngine.h" #include "guiMainMenu.h" #include "guiKeyChangeMenu.h" -#include "guiFileSelectMenu.h" +#include "guiPathSelectMenu.h" #include "subgame.h" #include "version.h" #include "porting.h" @@ -950,13 +950,14 @@ bool ModApiMainMenu::isMinetestPath(std::string path) } /******************************************************************************/ -int ModApiMainMenu::l_show_file_open_dialog(lua_State *L) +int ModApiMainMenu::l_show_path_select_dialog(lua_State *L) { GUIEngine* engine = getGuiEngine(L); sanity_check(engine != NULL); const char *formname= luaL_checkstring(L, 1); const char *title = luaL_checkstring(L, 2); + bool is_file_select = lua_toboolean(L, 3); GUIFileSelectMenu* fileOpenMenu = new GUIFileSelectMenu(engine->m_device->getGUIEnvironment(), @@ -964,7 +965,8 @@ int ModApiMainMenu::l_show_file_open_dialog(lua_State *L) -1, engine->m_menumanager, title, - formname); + formname, + is_file_select); fileOpenMenu->setTextDest(engine->m_buttonhandler); fileOpenMenu->drop(); return 0; @@ -1138,7 +1140,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(copy_dir); API_FCT(extract_zip); API_FCT(get_mainmenu_path); - API_FCT(show_file_open_dialog); + API_FCT(show_path_select_dialog); API_FCT(download_file); API_FCT(get_modstore_details); API_FCT(get_modstore_list); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index b5015add3..1d3e931e1 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -86,7 +86,7 @@ private: static int l_show_keys_menu(lua_State *L); - static int l_show_file_open_dialog(lua_State *L); + static int l_show_path_select_dialog(lua_State *L); static int l_set_topleft_text(lua_State *L); |