pause_menu.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. if UiContainer == nil then UiContainer = {} end
  2. --- The pause menu.
  3. --
  4. -- Unlike the other menus it isn't driven by UiContainer.current_menu: it reacts to the START
  5. -- button while the game is paused.
  6. UiContainer.PauseMenu = UiContainer.Menu.new{
  7. id = "pause",
  8. --- Cursor over the pause options. 1: Continue, 2: Exit to the begin menu.
  9. cursor = UiContainer.Cursor.new{
  10. widget = "PauseMenu.Menu.Cursor",
  11. total = 2,
  12. },
  13. --- Handles button events.
  14. --
  15. -- If the game is paused, it handles the navigation in the pause menu. If the game is not
  16. -- paused, it only handles the pause event.
  17. on_button = function(self, button, event)
  18. if System:is_paused() == false then
  19. if button == Config.ACTIONS.START and event == "Press" then
  20. System:pause()
  21. end
  22. return 0
  23. end
  24. if button == Config.ACTIONS.START and event == "Press" then
  25. System:unpause()
  26. elseif button == Config.ACTIONS.CONFIRM and event == "Press" then
  27. UiContainer.play_sound("Cursor")
  28. script:request_end_sync(Script.UI, "PauseMenu", "hide", 0)
  29. if self.cursor:index() == 2 then
  30. script:request_end_sync(Script.UI, "BeginMenu", "show", 0)
  31. map("empty")
  32. MenuSettings.pause_available = false
  33. else
  34. MenuSettings.available = true
  35. end
  36. else
  37. self.cursor:handle(button, "vertical")
  38. end
  39. return 0
  40. end,
  41. --- Shows the pause menu.
  42. show = function(self)
  43. ui_manager:get_widget("PauseMenu"):set_visible(true)
  44. end,
  45. --- Hides the pause menu
  46. hide = function(self)
  47. ui_manager:get_widget("PauseMenu"):set_visible(false)
  48. end,
  49. }