TextureSelector.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. class TextureSelector extends Atomic.UIWindow {
  23. constructor(parent: Atomic.UIWidget) {
  24. super();
  25. this.text = "Select Texture";
  26. this.rect = [0, 0, 320, 512];
  27. var mainLayout = new Atomic.UILayout();
  28. mainLayout.gravity = Atomic.UI_GRAVITY_ALL;
  29. mainLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_AVAILABLE;
  30. mainLayout.axis = Atomic.UI_AXIS_Y;
  31. this.contentRoot.addChild(mainLayout);
  32. // really want a grid container
  33. var scrollContainer = new Atomic.UIScrollContainer();
  34. scrollContainer.gravity = Atomic.UI_GRAVITY_ALL;
  35. scrollContainer.scrollMode = Atomic.UI_SCROLL_MODE_Y_AUTO;
  36. scrollContainer.adaptContentSize = true;
  37. var scrollLayout = new Atomic.UILayout();
  38. scrollLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  39. scrollLayout.axis = Atomic.UI_AXIS_Y;
  40. scrollContainer.contentRoot.addChild(scrollLayout);
  41. var db = ToolCore.getAssetDatabase();
  42. var textures = db.getAssetsByImporterType("TextureImporter", "Texture2D");
  43. for (var i in textures) {
  44. var thumbnail = textures[i].cachePath + "_thumbnail.png";
  45. var cache = Atomic.getResourceCache();
  46. var textureWidget = new Atomic.UITextureWidget();
  47. textureWidget.texture = <Atomic.Texture2D> cache.getTempResource("Texture2D", thumbnail);
  48. var tlp = new Atomic.UILayoutParams();
  49. tlp.width = 64;
  50. tlp.height = 64;
  51. textureWidget.layoutParams = tlp;
  52. scrollLayout.addChild(textureWidget);
  53. }
  54. mainLayout.addChild(scrollContainer);
  55. parent.addChild(this);
  56. this.center();
  57. this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
  58. }
  59. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  60. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  61. if (ev.target != this && !this.isAncestorOf(ev.target)) {
  62. //this.close();
  63. }
  64. }
  65. return false;
  66. }
  67. }
  68. export = TextureSelector;