pause_menu.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. -- A scene that reads the Start button itself (to end a choice) doesn't pause the game.
  20. if button == Config.ACTIONS.START and event == "Press"
  21. and not entity_manager:is_start_key_read()
  22. then
  23. System:pause()
  24. end
  25. return 0
  26. end
  27. if button == Config.ACTIONS.START and event == "Press" then
  28. System:unpause()
  29. elseif button == Config.ACTIONS.CONFIRM and event == "Press" then
  30. UiContainer.play_sound("Cursor")
  31. script:request_end_sync(Script.UI, "PauseMenu", "hide", 0)
  32. if self.cursor:index() == 2 then
  33. script:request_end_sync(Script.UI, "BeginMenu", "show", 0)
  34. map("empty")
  35. MenuSettings.pause_available = false
  36. else
  37. MenuSettings.available = true
  38. end
  39. else
  40. self.cursor:handle(button, "vertical")
  41. end
  42. return 0
  43. end,
  44. --- Shows the pause menu.
  45. show = function(self)
  46. ui_manager:get_widget("PauseMenu"):set_visible(true)
  47. end,
  48. --- Hides the pause menu
  49. hide = function(self)
  50. ui_manager:get_widget("PauseMenu"):set_visible(false)
  51. end,
  52. }