mainMenu.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. var network;
  8. function closeWindow() {
  9. if (window)
  10. window.die();
  11. window = null;
  12. }
  13. exports.init = function() {
  14. window = new UIWindow();
  15. window.settings = Atomic.UI.WINDOW_SETTINGS_TITLEBAR;
  16. window.text = "Main Menu";
  17. window.load("UI/mainMenu.ui.txt");
  18. window.resizeToFitContent();
  19. view.addChild(window);
  20. window.center();
  21. //Explicitly quitting an app is not allowed on iOS
  22. if(Atomic.platform == "iOS") {
  23. window.getWidget("quit").visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  24. }
  25. window.getWidget("new_game").onClick = function () {
  26. closeWindow();
  27. game.createScene2D();
  28. var node = game.scene.createChild("SpaceGame");
  29. node.createJSComponent("Components/SpaceGame.js");
  30. }
  31. window.getWidget("about").onClick = function () {
  32. closeWindow();
  33. // disable ourselves until ok is clicked on about
  34. //window.setState(UI.WIDGET_STATE_DISABLED, true);
  35. //var ui = require("./ui");
  36. //ui.showAbout(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  37. game.createScene2D();
  38. network = new Atomic.Network();
  39. network.connectSimple('127.0.0.1', 27000, game.scene);
  40. }
  41. window.getWidget("options").onClick = function () {
  42. // disable ourselves until ok is clicked on about
  43. window.setState(UI.WIDGET_STATE_DISABLED, true);
  44. var ui = require("./ui");
  45. ui.showOptions(function() {window.setState(UI.WIDGET_STATE_DISABLED, false);});
  46. }
  47. window.getWidget("quit").onClick = function () {
  48. game.engine.exit();
  49. }
  50. }
  51. exports.shutdown = function() {
  52. closeWindow();
  53. }