menubar.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Flexlay - A Generic 2D Game Editor
  2. # Copyright (C) 2014 Ingo Ruhnke <grumbel@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. from typing import cast, Callable, TYPE_CHECKING
  17. from flexlay.util.config import Config
  18. if TYPE_CHECKING:
  19. from flexlay.gui_manager import GUIManager
  20. from supertux.gui import SuperTuxGUI
  21. class SuperTuxMenuBar:
  22. def __init__(self, gui_manager: 'GUIManager', editor: 'SuperTuxGUI') -> None:
  23. self.gui_manager = gui_manager
  24. # Create Menu
  25. self.menubar = self.gui_manager.create_menubar()
  26. file_menu = self.menubar.add_menu("&File")
  27. submenu_new = file_menu.add_menu("New")
  28. submenu_new.add_item("Level...", editor.gui_level_new)
  29. submenu_new.add_item("Add-on...", editor.gui_addon_new)
  30. file_menu.add_item("Open...", editor.gui_level_load)
  31. self.recent_files_menu = file_menu.add_menu("Open Recent")
  32. assert Config.current is not None
  33. for filename in Config.current.recent_files:
  34. self.recent_files_menu.add_item(filename,
  35. cast(Callable[[], None],
  36. lambda filename=filename: editor.load_level(filename)))
  37. file_menu.add_item("Save...", editor.gui_level_save)
  38. # file_menu.add_item("Save Commands...", menu_file_save_commands)
  39. file_menu.add_item("Save As...", editor.gui_level_save_as)
  40. file_menu.add_item("Properties...", editor.gui_edit_level)
  41. file_menu.add_item("Quit", editor.gui.quit)
  42. edit_menu = self.menubar.add_menu("&Edit")
  43. edit_menu.add_item("Smooth Selection", editor.gui_smooth_level_struct)
  44. edit_menu.add_item("Resize", editor.gui_resize_sector)
  45. edit_menu.add_item("Resize to selection", editor.gui_resize_sector_to_selection)
  46. edit_menu.add_item("Change Tileset", cast(Callable[[], None], editor.gui_change_tileset))
  47. zoom_menu = self.menubar.add_menu("&Zoom")
  48. zoom_menu.add_item("1:4 (25%) ", lambda: editor.gui_set_zoom(0.25))
  49. zoom_menu.add_item("1:2 (50%) ", lambda: editor.gui_set_zoom(0.5))
  50. zoom_menu.add_item("1:1 (100%) ", lambda: editor.gui_set_zoom(1.0))
  51. zoom_menu.add_item("2:1 (200%) ", lambda: editor.gui_set_zoom(2.0))
  52. zoom_menu.add_item("4:1 (400%) ", lambda: editor.gui_set_zoom(4.0))
  53. layer_menu = self.menubar.add_menu("&Layer")
  54. layer_menu.add_item("Show All", editor.layer_selector.show_all)
  55. layer_menu.add_item("Hide All", editor.layer_selector.show_all)
  56. # layer_menu.add_item("Show Only Selected", (lambda: print("\"Show Only Selected\" is not implemented")))
  57. sector_menu = self.menubar.add_menu("&Sector")
  58. # sector = editor.workspace.get_map().metadata
  59. # for i in sector.parent.get_sectors():
  60. # if sector.name == i:
  61. # current = " [current]"
  62. # else:
  63. # current = ""
  64. #
  65. # def on_sector_callback():
  66. # print("Switching to %s" % i)
  67. # editor.workspace.get_map().metadata.parent.activate_sector(i, editor.workspace)
  68. #
  69. # mymenu.add_item(mysprite, ("Sector (%s)%s" % [i, current]), on_sector_callback)
  70. sector_menu.add_item("Create New Sector", editor.gui_add_sector)
  71. sector_menu.add_item("Remove Current Sector", editor.gui_remove_sector)
  72. sector_menu.add_item("Edit Sector Properties", editor.gui_edit_sector)
  73. run_menu = self.menubar.add_menu("&Run")
  74. run_menu.add_item("Run Level", editor.gui_run_level)
  75. run_menu.add_item("Record Level Playthrough", editor.gui_record_level)
  76. run_menu.add_item("Play A Demo", editor.gui_play_demo)
  77. run_menu.add_item("Play Example Demo", editor.gui_watch_example)
  78. self.editor = editor
  79. def update_recent_files(self) -> None:
  80. self.recent_files_menu.menu.clear()
  81. assert Config.current is not None
  82. for filename in Config.current.recent_files:
  83. self.recent_files_menu.add_item(filename,
  84. cast(Callable[[], None],
  85. lambda filename=filename: self.editor.load_level(filename)))
  86. # EOF #