particle_editor_open.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SuperTux
  2. // Copyright (C) 2020 A. Semphris <semphris@protonmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "supertux/menu/particle_editor_open.hpp"
  17. #include "editor/particle_editor.hpp"
  18. #include "gui/dialog.hpp"
  19. #include "gui/menu_item.hpp"
  20. #include "gui/menu_manager.hpp"
  21. #include "supertux/level.hpp"
  22. #include "supertux/gameconfig.hpp"
  23. #include "supertux/menu/menu_storage.hpp"
  24. #include "util/gettext.hpp"
  25. #include "video/compositor.hpp"
  26. ParticleEditorOpen::ParticleEditorOpen() :
  27. m_filename()
  28. {
  29. add_label(_("Load particle file"));
  30. add_hl();
  31. std::vector<std::string> extensions;
  32. extensions.push_back("stcp");
  33. add_file(_("File"), &m_filename, extensions, "/particles/", true);
  34. add_entry(MNID_OPEN, _("Open"));
  35. add_hl();
  36. add_entry(MNID_CANCEL, _("Cancel"));
  37. }
  38. ParticleEditorOpen::~ParticleEditorOpen()
  39. {
  40. auto editor = ParticleEditor::current();
  41. if (editor == nullptr) {
  42. return;
  43. }
  44. editor->reactivate();
  45. }
  46. void
  47. ParticleEditorOpen::menu_action(MenuItem& item)
  48. {
  49. switch (item.get_id())
  50. {
  51. case MNID_OPEN:
  52. std::replace(m_filename.begin(), m_filename.end(), '\\', '/');
  53. ParticleEditor::current()->open("/particles/" + m_filename);
  54. MenuManager::instance().clear_menu_stack();
  55. break;
  56. case MNID_CANCEL:
  57. MenuManager::instance().clear_menu_stack();
  58. break;
  59. default:
  60. break;
  61. }
  62. }
  63. /* EOF */