mainMenu.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. var game = Atomic.game;
  3. var view = game.uiView;
  4. var UI = Atomic.UI;
  5. var UIWindow = Atomic.UIWindow;
  6. var window;
  7. function closeWindow() {
  8. if (window)
  9. window.die();
  10. window = null;
  11. }
  12. exports.init = function() {
  13. window = new UIWindow();
  14. window.settings = Atomic.UI.WINDOW_SETTINGS_TITLEBAR;
  15. window.text = "Main Menu";
  16. window.load("UI/mainMenu.ui.txt");
  17. window.resizeToFitContent();
  18. view.addChild(window);
  19. window.center();
  20. //Explicitly quitting an app is not allowed on iOS
  21. if(Atomic.platform == "iOS") {
  22. window.getWidget("quit").visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  23. }
  24. window.getWidget("new_game").onClick = function () {
  25. closeWindow();
  26. var node = game.scene.createChild("SpaceGame");
  27. node.createJSComponent("Components/SpaceGame.js");
  28. }
  29. window.getWidget("about").onClick = function () {
  30. // disable ourselves until ok is clicked on about
  31. window.setState(UI.WIDGET_STATE_DISABLED, true);
  32. var ui = require("./ui");
  33. ui.showAbout(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  34. }
  35. window.getWidget("options").onClick = function () {
  36. // disable ourselves until ok is clicked on about
  37. window.setState(UI.WIDGET_STATE_DISABLED, true);
  38. var ui = require("./ui");
  39. ui.showOptions(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  40. }
  41. window.getWidget("quit").onClick = function () {
  42. game.engine.exit();
  43. }
  44. }
  45. exports.shutdown = function() {
  46. closeWindow();
  47. }