controller.script 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. function init(self)
  2. msg.post(".", "acquire_input_focus") -- <1>
  3. msg.post("#splashscreenproxy", "async_load") -- <2>
  4. end
  5. function on_message(self, message_id, message, sender)
  6. if message_id == hash("proxy_loaded") then -- <3>
  7. if sender.fragment == hash("splashscreenproxy") then -- <4>
  8. msg.post("#splashscreenproxy", "enable") -- <5>
  9. msg.post("#menuproxy", "async_load") -- <6>
  10. self.menu_loading_started_time = os.time() -- <7>
  11. elseif sender.fragment == hash("menuproxy") then -- <8>
  12. local total_menu_loading_time = os.time() - self.menu_loading_started_time
  13. local minimum_splash_duration = 5
  14. local delay = math.max(minimum_splash_duration - total_menu_loading_time, 0) -- <9>
  15. timer.delay(delay, false, function() -- <10>
  16. msg.post("#splashscreenproxy", "unload") -- <11>
  17. msg.post("#menuproxy", "enable") -- <12>
  18. end)
  19. end
  20. end
  21. end
  22. --[[
  23. 1. Acquire input focus for this game object. This is required for input to be able to propagate into any of the collection proxies on the same game object as this script.
  24. 2. Load the splash screen
  25. 3. The "proxy_loaded" message is received whenever a collection proxy has been loaded
  26. 4. Here we check if it was the splash screen proxy which was loaded
  27. 5. Enable the splash screen proxy so that the splash screen is shown
  28. 6. Load the menu screen
  29. 7. Save the time when the menu screen loading was started
  30. 8. Was the menu proxy loaded?
  31. 9. Calculate how much longer the splash screen should remain visible, based on how long it took to load the menu
  32. 10. Start a timer for the remaining time
  33. 11. Unload the splash screen
  34. 12. Show the menu
  35. --]]