UI.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. var game = Atomic.game;
  2. var ui = game.ui;
  3. var root = ui.getRoot();
  4. var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
  5. root.defaultStyle = uiStyle;
  6. var window = new Atomic.Window();
  7. root.addChild(window);
  8. window.setMinSize(384, 192);
  9. window.setAlignment(Atomic.HA_CENTER, Atomic.VA_CENTER);
  10. window.setLayout(Atomic.LM_VERTICAL, 6, [6, 6, 6, 6]);
  11. window.setName("Window");
  12. var titleBar = new Atomic.UIElement();
  13. titleBar.setMinSize(0, 24);
  14. titleBar.setVerticalAlignment(Atomic.VA_TOP);
  15. titleBar.setLayoutMode(Atomic.LM_HORIZONTAL);
  16. // Create the Window title Text
  17. var windowTitle = new Atomic.Text();
  18. windowTitle.setName("WindowTitle");
  19. windowTitle.setText("Please select Daytime of Nighttime");
  20. titleBar.addChild(windowTitle);
  21. window.addChild(titleBar);
  22. // Daytime button
  23. var button = new Atomic.Button();
  24. button.setName ("Daytime");
  25. button.setMinHeight(48);
  26. var buttonText = new Atomic.Text();
  27. buttonText.text = "Daytime";
  28. var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
  29. buttonText.setFont(font, 12);
  30. buttonText.color = [1, 1, 0, 1];
  31. buttonText.horizontalAlignment = Atomic.HA_CENTER;
  32. buttonText.verticalAlignment = Atomic.VA_CENTER;
  33. button.addChild(buttonText);
  34. window.addChild(button);
  35. button.setStyleAuto();
  36. // Nighttime button
  37. button = new Atomic.Button();
  38. button.setName ("Nighttime");
  39. button.setMinHeight(48);
  40. buttonText = new Atomic.Text();
  41. buttonText.text = "Nighttime";
  42. buttonText.setFont(font, 12);
  43. buttonText.color = [0, 1, 1, 1];
  44. buttonText.horizontalAlignment = Atomic.HA_CENTER;
  45. buttonText.verticalAlignment = Atomic.VA_CENTER;
  46. button.addChild(buttonText);
  47. window.addChild(button);
  48. button.setStyleAuto();
  49. window.movable = true;
  50. window.resizeable = true;
  51. window.setStyleAuto();
  52. titleBar.setStyleAuto();
  53. windowTitle.setStyleAuto();
  54. self.onMouseClick = function(element) {
  55. var go = 0;
  56. if (element.name == "Daytime") {
  57. go = 1;
  58. }
  59. if (element.name == "Nighttime") {
  60. go = 2;
  61. }
  62. if (go) {
  63. root.removeChild(window);
  64. var musicFile = game.cache.getResource("Sound", "Sounds/JumpingBat.ogg");
  65. musicFile.looped = true;
  66. var musicNode = game.scene.createChild("MusicNode");
  67. var musicSource = musicNode.createComponent("SoundSource");
  68. musicSource.gain = 1.0;
  69. musicSource.soundType = Atomic.SOUND_MUSIC;
  70. musicSource.play(musicFile);
  71. var platformerNode = game.scene.createChild("Platformer");
  72. var platformer = platformerNode.createJSComponent("Platformer");
  73. platformer.init(go == 1);
  74. }
  75. }
  76. function start() {
  77. self.listenToEvent(null, "UIMouseClick", self.onMouseClick );
  78. }
  79. function update(timeStep) {
  80. }