mainMenu.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // create a main 2D scene, which will persist
  17. // the space game itself uses a separate scene we can
  18. // bring up and tear down
  19. game.createScene2D();
  20. var spaceNode = game.scene.createChild("SpaceBackground");
  21. spaceNode.createJSComponent("Components/SpaceBackground.js");
  22. window.load("UI/mainMenu.ui.txt");
  23. window.resizeToFitContent();
  24. view.addChild(window);
  25. window.center();
  26. //Explicitly quitting an app is not allowed on iOS
  27. if(Atomic.platform == "iOS") {
  28. window.getWidget("quit").visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  29. }
  30. window.getWidget("new_game").onClick = function () {
  31. closeWindow();
  32. game.createScene2D();
  33. var node = game.scene.createChild("SpaceGame");
  34. node.createJSComponent("Components/SpaceGame.js");
  35. };
  36. window.getWidget("about").onClick = function () {
  37. // disable ourselves until ok is clicked on about
  38. window.setState(UI.WIDGET_STATE_DISABLED, true);
  39. var ui = require("./ui");
  40. ui.showAbout(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  41. };
  42. window.getWidget("join_server").onClick = function() {
  43. // disable ourselves until ok is clicked on about
  44. window.setState(UI.WIDGET_STATE_DISABLED, true);
  45. var ui = require("./ui");
  46. ui.showJoinServer(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  47. };
  48. window.getWidget("options").onClick = function () {
  49. // disable ourselves until ok is clicked on about
  50. window.setState(UI.WIDGET_STATE_DISABLED, true);
  51. var ui = require("./ui");
  52. ui.showOptions(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  53. };
  54. window.getWidget("quit").onClick = function () {
  55. game.engine.exit();
  56. };
  57. window.getWidget("join_server").onClick = function () {
  58. // disable ourselves until ok is clicked on about
  59. window.setState(UI.WIDGET_STATE_DISABLED, true);
  60. var ui = require("./ui");
  61. ui.showJoinServer(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  62. };
  63. };
  64. exports.shutdown = function() {
  65. closeWindow();
  66. };
  67. exports.closeMainMenu = function() {
  68. closeWindow();
  69. };