CSComponentClassSelector.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. import EditorUI = require("ui/EditorUI");
  8. class CSComponentClassSelector extends Atomic.UIWindow {
  9. constructor(editField: Atomic.UIEditField, component: AtomicNET.CSComponent) {
  10. super();
  11. var assemblyFile = component.assemblyFile;
  12. this.text = "Select Class: " + assemblyFile.name;
  13. this.rect = [0, 0, 400, 512];
  14. var mainLayout = new Atomic.UILayout();
  15. mainLayout.gravity = Atomic.UI_GRAVITY_ALL;
  16. mainLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_AVAILABLE;
  17. mainLayout.axis = Atomic.UI_AXIS_Y;
  18. this.contentRoot.addChild(mainLayout);
  19. // really want a grid container
  20. var scrollContainer = new Atomic.UIScrollContainer();
  21. scrollContainer.gravity = Atomic.UI_GRAVITY_ALL;
  22. scrollContainer.scrollMode = Atomic.UI_SCROLL_MODE_Y_AUTO;
  23. scrollContainer.adaptContentSize = true;
  24. var scrollLayout = new Atomic.UILayout();
  25. scrollLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  26. scrollLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  27. scrollLayout.axis = Atomic.UI_AXIS_Y;
  28. scrollContainer.contentRoot.addChild(scrollLayout);
  29. var window = this;
  30. for (var i in assemblyFile.classNames) {
  31. var classname = assemblyFile.classNames[i];
  32. var button = new Atomic.UIButton();
  33. button.text = classname;
  34. button.onClick = function() {
  35. editField.text = this.text;
  36. component.componentClassName = this.text;
  37. window.close();
  38. }.bind(button);
  39. scrollLayout.addChild(button);
  40. }
  41. mainLayout.addChild(scrollContainer);
  42. EditorUI.getMainFrame().addChild(this);
  43. this.center();
  44. this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
  45. }
  46. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  47. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  48. if (ev.target != this && !this.isAncestorOf(ev.target)) {
  49. //this.close();
  50. }
  51. }
  52. return false;
  53. }
  54. }
  55. export = CSComponentClassSelector;