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