UI.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'atomic component';
  2. //define font description style
  3. var fd = new Atomic.UIFontDescription();
  4. fd.id = "Vera";
  5. fd.size = 22;
  6. var particleEmitter;
  7. function createButton(self, text, peffectName, layout) {
  8. //create UIButton element
  9. var button = new Atomic.UIButton();
  10. //set its text and font description style
  11. button.text = text;
  12. button.fontDescription = fd;
  13. //laying on the right side
  14. button.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_RIGHT;
  15. //this event will be called when buttons is clicked
  16. button.onClick = function() {
  17. particleEmitter.effect = Atomic.cache.getResource("ParticleEffect", "Particles/" + peffectName + ".peffect");
  18. };
  19. //add button
  20. layout.addChild(button);
  21. }
  22. //UI component
  23. exports.component = function(self) {
  24. particleEmitter = self.getComponent("ParticleEmitter");
  25. // root view
  26. self.uiView = new Atomic.UIView();
  27. // Create a layout, otherwise child widgets won't know how to size themselves
  28. // and would manually need to be sized
  29. var layout = new Atomic.UILayout();
  30. layout.rect = self.uiView.rect;
  31. layout.axis = Atomic.UI_AXIS.UI_AXIS_Y;
  32. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_GRAVITY;
  33. //add our layout
  34. self.uiView.addChild(layout);
  35. //create buttons
  36. createButton(self, "Disco", "Disco", layout);
  37. createButton(self, "Fire", "Fire", layout);
  38. createButton(self, "Smoke", "Smoke", layout);
  39. createButton(self, "SmokeStack", "SmokeStack", layout);
  40. createButton(self, "SnowExplosion", "SnowExplosion", layout);
  41. };