TextureSelector.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. class TextureSelector extends Atomic.UIWindow {
  2. constructor(parent: Atomic.UIWidget) {
  3. super();
  4. this.text = "Select Texture";
  5. this.rect = [0, 0, 320, 512];
  6. var mainLayout = new Atomic.UILayout();
  7. mainLayout.gravity = Atomic.UI_GRAVITY_ALL;
  8. mainLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_AVAILABLE;
  9. mainLayout.axis = Atomic.UI_AXIS_Y;
  10. this.contentRoot.addChild(mainLayout);
  11. // really want a grid container
  12. var scrollContainer = new Atomic.UIScrollContainer();
  13. scrollContainer.gravity = Atomic.UI_GRAVITY_ALL;
  14. scrollContainer.scrollMode = Atomic.UI_SCROLL_MODE_Y_AUTO;
  15. scrollContainer.adaptContentSize = true;
  16. var scrollLayout = new Atomic.UILayout();
  17. scrollLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  18. scrollLayout.axis = Atomic.UI_AXIS_Y;
  19. scrollContainer.contentRoot.addChild(scrollLayout);
  20. var db = ToolCore.getAssetDatabase();
  21. var textures = db.getAssetsByImporterType("TextureImporter");
  22. for (var i in textures) {
  23. var thumbnail = textures[i].cachePath + "_thumbnail.png";
  24. var cache = Atomic.getResourceCache();
  25. var textureWidget = new Atomic.UITextureWidget();
  26. textureWidget.texture = <Atomic.Texture2D> cache.getTempResource("Texture2D", thumbnail);
  27. var tlp = new Atomic.UILayoutParams();
  28. tlp.width = 64;
  29. tlp.height = 64;
  30. textureWidget.layoutParams = tlp;
  31. scrollLayout.addChild(textureWidget);
  32. }
  33. mainLayout.addChild(scrollContainer);
  34. parent.addChild(this);
  35. this.center();
  36. this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
  37. }
  38. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  39. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  40. if (ev.target != this && !this.isAncestorOf(ev.target)) {
  41. //this.close();
  42. }
  43. }
  44. return false;
  45. }
  46. }
  47. export = TextureSelector;