diff options
author | sapier <Sapier at GMX dot net> | 2013-06-23 18:30:21 +0200 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-07-02 19:58:20 -0400 |
commit | 967121a34bbc60e6b46c7ec470b151f668ef1fef (patch) | |
tree | e5cc5ec845d3c286bcb0e203e3a5f146950bfaf1 /src/guiFileSelectMenu.cpp | |
parent | fe4ce03d529f70346b2e2c4872223ebdcd37fffa (diff) | |
download | hax-minetest-server-967121a34bbc60e6b46c7ec470b151f668ef1fef.tar.gz hax-minetest-server-967121a34bbc60e6b46c7ec470b151f668ef1fef.zip |
Replace C++ mainmenu by formspec powered one
Diffstat (limited to 'src/guiFileSelectMenu.cpp')
-rw-r--r-- | src/guiFileSelectMenu.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/src/guiFileSelectMenu.cpp b/src/guiFileSelectMenu.cpp new file mode 100644 index 000000000..93d43f786 --- /dev/null +++ b/src/guiFileSelectMenu.cpp @@ -0,0 +1,133 @@ +/* + Minetest + Copyright (C) 2013 sapier + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "guiFileSelectMenu.h" +#include "util/string.h" +#include <locale.h> + +GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env, + gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, + std::string title, std::string formname) : +GUIModalMenu(env, parent, id, menumgr) +{ + m_title = narrow_to_wide(title); + m_parent = parent; + m_formname = formname; + m_text_dst = 0; + m_accepted = false; + m_previous_locale = setlocale(LC_ALL,0); +} + +GUIFileSelectMenu::~GUIFileSelectMenu() +{ + removeChildren(); + setlocale(LC_ALL,m_previous_locale.c_str()); +} + +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); + + DesiredRect = rect; + recalculateAbsolutePosition(false); + + m_fileOpenDialog = + 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); + m_fileOpenDialog->setRelativePosition(pos); + m_fileOpenDialog->setMinSize(size); +} + +void GUIFileSelectMenu::drawMenu() +{ + gui::IGUISkin* skin = Environment->getSkin(); + if (!skin) + return; + + gui::IGUIElement::draw(); +} + +void GUIFileSelectMenu::acceptInput() { + if ((m_text_dst != 0) && (this->m_formname != "")){ + std::map<std::string, std::string> fields; + + if (m_accepted) + fields[m_formname + "_accepted"] = wide_to_narrow(m_fileOpenDialog->getFileName()); + else + fields[m_formname + "_canceled"] = m_formname; + + this->m_text_dst->gotText(fields); + } +} + +bool GUIFileSelectMenu::OnEvent(const SEvent& event) +{ + + if (event.EventType == irr::EET_GUI_EVENT) { + + int callerId = event.GUIEvent.Caller->getID(); + if (callerId >= 0) { + std::cout << "CallerId:" << callerId << std::endl; + } + + switch (event.GUIEvent.EventType) { + case gui::EGET_ELEMENT_CLOSED: + case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED: + m_accepted=false; + acceptInput(); + quitMenu(); + return true; + break; + + case gui::EGET_DIRECTORY_SELECTED: + case gui::EGET_FILE_SELECTED: + m_accepted=true; + acceptInput(); + quitMenu(); + return true; + break; + + default: + //ignore this event + break; + } + } + return Parent ? Parent->OnEvent(event) : false; +} |