page.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # The zori UI consists of several "pages" or screens of UI.
  2. # Only one page can be active at the same time, and the size fo a page is
  3. # that of the screen.
  4. # The page named :default is normally active and is supposed to be used
  5. # for the in-engine UI and HUD elements, dialogs, etc.
  6. # Other pages are for screens such as the start screen, save screen,
  7. # main menu, inventory, etc.
  8. #
  9. module Zori
  10. class Page
  11. include Zori::Widget
  12. attr_reader :name
  13. # Creates a new UI page with the given name.
  14. def initialize(params={}, &block)
  15. super(params, &block)
  16. @name = params[:name].to_sym
  17. end
  18. # Called when this page is activated.
  19. def on_enter(data = {})
  20. self.show
  21. on_event(:enter)
  22. end
  23. # Called when this page is deactivated.
  24. def on_leave(name=nil)
  25. self.hide
  26. on_event(:leave, name)
  27. end
  28. # Override this in pages to do special case handling
  29. def handle_event(*data)
  30. return false
  31. end
  32. end
  33. end