particle_editor_menu.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_menu.hpp"
  17. #include "editor/particle_editor.hpp"
  18. #include "gui/dialog.hpp"
  19. #include "gui/menu_filesystem.hpp"
  20. #include "gui/menu_item.hpp"
  21. #include "gui/menu_manager.hpp"
  22. #include "supertux/level.hpp"
  23. #include "supertux/gameconfig.hpp"
  24. #include "supertux/menu/menu_storage.hpp"
  25. #include "util/gettext.hpp"
  26. #include "video/compositor.hpp"
  27. ParticleEditorMenu::ParticleEditorMenu()
  28. {
  29. add_label(_("Particle Editor"));
  30. add_hl();
  31. add_entry(MNID_RETURNTOEDITOR, _("Return to Editor"));
  32. add_entry(MNID_NEW, _("New Particle Config"));
  33. add_entry(MNID_SAVE, _("Save Particle Config"));
  34. add_entry(MNID_SAVE_AS, _("Save Particle Config as..."));
  35. add_entry(MNID_LOAD, _("Load Another Particle Config"));
  36. add_hl();
  37. add_entry(MNID_OPEN_DIR, _("Open Particle Directory"));
  38. add_entry(MNID_HELP, _("Keyboard Shortcuts"));
  39. add_hl();
  40. add_entry(MNID_QUITEDITOR, _("Exit Particle Editor"));
  41. }
  42. ParticleEditorMenu::~ParticleEditorMenu()
  43. {
  44. auto editor = ParticleEditor::current();
  45. if (editor == nullptr) {
  46. return;
  47. }
  48. editor->reactivate();
  49. }
  50. void
  51. ParticleEditorMenu::menu_action(MenuItem& item)
  52. {
  53. switch (item.get_id())
  54. {
  55. case MNID_RETURNTOEDITOR:
  56. MenuManager::instance().clear_menu_stack();
  57. break;
  58. case MNID_NEW:
  59. {
  60. MenuManager::instance().clear_menu_stack();
  61. auto editor = ParticleEditor::current();
  62. editor->check_unsaved_changes([editor] {
  63. editor->new_file();
  64. });
  65. }
  66. break;
  67. case MNID_SAVE:
  68. {
  69. MenuManager::instance().clear_menu_stack();
  70. auto editor = ParticleEditor::current();
  71. editor->request_save();
  72. }
  73. break;
  74. case MNID_SAVE_AS:
  75. {
  76. MenuManager::instance().clear_menu_stack();
  77. auto editor = ParticleEditor::current();
  78. editor->request_save(true);
  79. }
  80. break;
  81. case MNID_OPEN_DIR:
  82. ParticleEditor::current()->open_particle_directory();
  83. break;
  84. case MNID_LOAD:
  85. //MenuManager::instance().set_menu(MenuStorage::PARTICLE_EDITOR_OPEN);
  86. {
  87. const std::vector<std::string>& filter = {".stcp"};
  88. MenuManager::instance().push_menu(std::make_unique<FileSystemMenu>(
  89. &ParticleEditor::current()->m_filename,
  90. filter,
  91. "/particles",
  92. true,
  93. [](const std::string& new_filename) {
  94. ParticleEditor::current()->open("/particles/" +
  95. ParticleEditor::current()->m_filename);
  96. MenuManager::instance().clear_menu_stack();
  97. }
  98. ));
  99. }
  100. break;
  101. case MNID_HELP:
  102. {
  103. auto dialog = std::make_unique<Dialog>();
  104. dialog->set_text(_("Keyboard Shortcuts:\n---------------------\nEsc = Open Menu\nCtrl+S = Save\nCtrl+Shift+S = Save as\nCtrl+O = Open\nCtrl+Z = Undo\nCtrl+Y = Redo"));
  105. dialog->add_cancel_button(_("Got it!"));
  106. MenuManager::instance().set_dialog(std::move(dialog));
  107. }
  108. break;
  109. case MNID_QUITEDITOR:
  110. MenuManager::instance().clear_menu_stack();
  111. ParticleEditor::current()->m_quit_request = true;
  112. break;
  113. default:
  114. break;
  115. }
  116. }
  117. /* EOF */