editor_objectgroup_menu.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_objectgroup_menu.hpp"
  17. #include "editor/editor.hpp"
  18. #include "editor/object_group.hpp"
  19. #include "gui/menu_item.hpp"
  20. #include "gui/menu_manager.hpp"
  21. #include "supertux/level.hpp"
  22. #include "util/gettext.hpp"
  23. EditorObjectgroupMenu::EditorObjectgroupMenu()
  24. {
  25. bool worldmap = Editor::current()->get_level()->is_worldmap();
  26. add_label(_("Objects"));
  27. add_hl();
  28. int id = 0;
  29. for (auto& og : Editor::current()->get_objectgroups()) {
  30. if (worldmap == og.is_worldmap()) {
  31. add_entry(id, og.get_name());
  32. }
  33. id++;
  34. }
  35. add_hl();
  36. add_entry(-1,_("Cancel"));
  37. }
  38. EditorObjectgroupMenu::~EditorObjectgroupMenu()
  39. {
  40. auto editor = Editor::current();
  41. if (editor == nullptr) {
  42. return;
  43. }
  44. editor->m_reactivate_request = true;
  45. }
  46. void
  47. EditorObjectgroupMenu::menu_action(MenuItem& item)
  48. {
  49. if (item.get_id() >= 0)
  50. {
  51. Editor::current()->select_objectgroup(item.get_id());
  52. }
  53. MenuManager::instance().clear_menu_stack();
  54. }
  55. /* EOF */