quit_menu.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. if UiContainer == nil then UiContainer = {} end
  2. --- The quit menu.
  3. --
  4. -- Only shows a window warning that the unsaved progress will be lost. Confirming quits the game,
  5. -- declining (or cancelling) goes back to the main menu.
  6. UiContainer.QuitMenu = UiContainer.Menu.new{
  7. id = "quit",
  8. parent = "main",
  9. --- Cursor over Yes and No.
  10. cursor = UiContainer.Cursor.new{
  11. widget = "QuitMenu.Container.Confirm.Cursor",
  12. total = 2,
  13. },
  14. states = {
  15. [""] = {
  16. cursor = function(self) return self.cursor end,
  17. axis = "vertical",
  18. confirm = function(self, cursor)
  19. if cursor:index() == 1 then
  20. console("quit")
  21. else
  22. script:request_end_sync(Script.UI, "QuitMenu", "hide", 0)
  23. end
  24. end,
  25. cancel = function(self)
  26. script:request_end_sync(Script.UI, "QuitMenu", "hide", 0)
  27. end,
  28. },
  29. },
  30. --- Opens the window. The cursor starts on No.
  31. show = function(self)
  32. self:activate()
  33. self.cursor:set(2)
  34. ui_manager:get_widget("QuitMenu"):set_visible(true)
  35. return 0
  36. end,
  37. --- Closes the window and goes back to the main menu.
  38. hide = function(self)
  39. ui_manager:get_widget("QuitMenu"):set_visible(false)
  40. self:deactivate()
  41. return 0
  42. end,
  43. }