game_over.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. if UiContainer == nil then UiContainer = {} end
  2. --- The game over screen.
  3. --
  4. -- Shown when the whole party dies in battle. It fades to black, plays the game over music, and
  5. -- when the player confirms, goes back to the begin menu.
  6. UiContainer.GameOver = {
  7. --- Music to play. Name as in the musics file (57 is the game over music of the original game).
  8. MUSIC = "57",
  9. --- Indicates that the screen is being shown.
  10. active = false,
  11. --- Indicates that the screen is fully shown and can be dismissed.
  12. ready = false,
  13. --- Shows the game over screen.
  14. show = function(self)
  15. self.active = true
  16. self.ready = false
  17. UiContainer.current_menu = "game_over"
  18. ui_manager:get_widget("GameOver.Container.Text"):set_visible(false)
  19. ui_manager:get_widget("GameOver"):set_visible(true)
  20. audio_manager:play_music(self.MUSIC)
  21. local background = ui_manager:get_widget("GameOver.Background")
  22. background:play_animation_stop("FadeIn")
  23. background:animation_sync()
  24. ui_manager:get_widget("GameOver.Container.Text"):set_visible(true)
  25. self.ready = true
  26. return 0
  27. end,
  28. --- Handles button events.
  29. --
  30. -- Confirming, once the screen is shown, leaves it.
  31. on_button = function(self, button, event)
  32. if self.active == false or self.ready == false then do return 0 end end
  33. if button == Config.ACTIONS.CONFIRM then self:leave() end
  34. return 0
  35. end,
  36. --- Leaves the game over screen and goes back to the begin menu.
  37. --
  38. -- TODO: Reload the last save, as the original game does. For now the party is healed, so the
  39. -- debug battles of the begin menu can be started again.
  40. leave = function(self)
  41. self.active = false
  42. self.ready = false
  43. ui_manager:get_widget("GameOver.Container.Text"):set_visible(false)
  44. ui_manager:get_widget("GameOver"):set_visible(false)
  45. for i = 1, Party.MAX do
  46. if Party[i] ~= nil then
  47. local stats = Characters[Party[i]].stats
  48. stats.hp.current = stats.hp.max or stats.hp.base
  49. end
  50. end
  51. Battle.finish()
  52. MenuSettings.pause_available = false
  53. UiContainer.current_menu = ""
  54. script:request_end_sync(Script.UI, "BeginMenu", "show", 0)
  55. return 0
  56. end,
  57. }