TextureSelector.ts 2.3 KB

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