editor_tilegroup_menu.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SuperTux
  2. // Copyright (C) 2015 Hume2 <teratux.mail@gmail.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/editor_tilegroup_menu.hpp"
  17. #include "editor/editor.hpp"
  18. #include "gui/menu_item.hpp"
  19. #include "gui/menu_manager.hpp"
  20. #include "util/gettext.hpp"
  21. EditorTilegroupMenu::EditorTilegroupMenu()
  22. {
  23. add_label(_("Tiles"));
  24. add_hl();
  25. int id = 0;
  26. for (auto& tg : Editor::current()->get_tilegroups()) {
  27. add_entry(id, _(tg.name));
  28. id++;
  29. }
  30. add_hl();
  31. add_entry(-1,_("Cancel"));
  32. }
  33. EditorTilegroupMenu::~EditorTilegroupMenu()
  34. {
  35. auto editor = Editor::current();
  36. if (editor == nullptr) {
  37. return;
  38. }
  39. editor->m_reactivate_request = true;
  40. }
  41. void
  42. EditorTilegroupMenu::menu_action(MenuItem& item)
  43. {
  44. if (item.get_id() >= 0)
  45. {
  46. Editor::current()->select_tilegroup(item.get_id());
  47. }
  48. MenuManager::instance().clear_menu_stack();
  49. }
  50. /* EOF */