UI.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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("Star Maker!");
  20. titleBar.addChild(windowTitle);
  21. window.addChild(titleBar);
  22. var button = new Atomic.Button();
  23. button.setName ("Star Button");
  24. button.setMinHeight(24);
  25. var buttonText = new Atomic.Text();
  26. buttonText.text = "Add Star";
  27. var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
  28. buttonText.setFont(font, 12);
  29. buttonText.color = [0, 1, 0, 1];
  30. buttonText.horizontalAlignment = Atomic.HA_CENTER;
  31. buttonText.verticalAlignment = Atomic.VA_CENTER;
  32. button.addChild(buttonText);
  33. window.addChild(button);
  34. window.movable = true;
  35. window.resizeable = true;
  36. window.setStyleAuto();
  37. titleBar.setStyleAuto();
  38. windowTitle.setStyleAuto();
  39. button.setStyleAuto();
  40. self.onMouseClick = function(element) {
  41. var width = game.graphics.width * Atomic.PIXEL_SIZE * 0.5;
  42. var height = game.graphics.height * Atomic.PIXEL_SIZE * 0.5;
  43. var x = -width/2 + width * Math.random();
  44. var y = -height/2 + height * Math.random();
  45. if (element.name == "Star Button") {
  46. var starNode = game.scene.createChild("Star");
  47. starNode.createJSComponent("Star");
  48. starNode.position2D = [x, y];
  49. }
  50. }
  51. function start() {
  52. self.listenToEvent(null, "UIMouseClick", self.onMouseClick );
  53. }
  54. function update(timeStep) {
  55. }