UI.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Atomic Component
  2. var game = Atomic.game;
  3. var node = self.node;
  4. var ui = game.ui;
  5. var root = ui.getRoot();
  6. var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
  7. var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
  8. root.defaultStyle = uiStyle;
  9. var container = new Atomic.UIElement();
  10. container.horizontalAlignment = Atomic.HA_RIGHT;
  11. container.verticalAlignment = Atomic.VA_CENTER;
  12. container.layoutMode = Atomic.LM_VERTICAL;
  13. root.addChild(container);
  14. var buttons = {};
  15. function addButton(name, text, callback) {
  16. var button = new Atomic.Button();
  17. button.setName(name);
  18. button.setMinWidth(120);
  19. button.setMinHeight(24);
  20. var buttonText = new Atomic.Text();
  21. buttonText.text = text;
  22. buttonText.setFont(font, 12);
  23. buttonText.color = [0, 1, 0, 1];
  24. buttonText.horizontalAlignment = Atomic.HA_CENTER;
  25. buttonText.verticalAlignment = Atomic.VA_CENTER;
  26. button.addChild(buttonText);
  27. container.addChild(button);
  28. button.setStyleAuto();
  29. buttons[name] = callback;
  30. }
  31. addButton("PlayIdle", "Idle", function() { TheImp.playAnimation("idle"); });
  32. addButton("PlayRun", "Run", function() { TheImp.playAnimation("run"); });
  33. addButton("PlayAttack", "Attack", function() { TheImp.playAnimation("attack"); });
  34. addButton("PlayHit", "Hit", function() { TheImp.playAnimation("hit"); });
  35. addButton("PlayDead", "Dead", function() { TheImp.playAnimation("dead"); });
  36. self.onMouseClick = function(element) {
  37. var name = element.name;
  38. buttons[name]();
  39. }
  40. function start() {
  41. self.listenToEvent(null, "UIMouseClick", self.onMouseClick );
  42. }
  43. function update(timeStep) {
  44. }