ResourceSelection.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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("../EditorUI");
  8. import EditorEvents = require("../../editor/EditorEvents");
  9. import ModalWindow = require("./ModalWindow");
  10. class ResourceSelection extends ModalWindow {
  11. folderList: Atomic.UIListView;
  12. callback: (asset: ToolCore.Asset, args:any) => void;
  13. args:any;
  14. populate(importerType: string) {
  15. var db = ToolCore.assetDatabase;
  16. var assets = db.getAssetsByImporterType(importerType);
  17. for (var i in assets) {
  18. var asset = assets[i];
  19. if (importerType == "JavascriptImporter") {
  20. if (!(<ToolCore.JavascriptImporter> asset.importer).isComponentFile())
  21. continue;
  22. }
  23. this.folderList.addRootItem(asset.relativePath, "", asset.guid);
  24. }
  25. }
  26. constructor(windowText: string, importerType: string, callback: (asset: ToolCore.Asset, args:any) => void, args:any) {
  27. super();
  28. this.callback = callback;
  29. this.args = args;
  30. this.load("AtomicEditor/editor/ui/resourceselection.tb.txt");
  31. var foldercontainer = this.getWidget("resourcecontainer");
  32. var folderList = this.folderList = new Atomic.UIListView();
  33. folderList.rootList.id = "resourceList_";
  34. foldercontainer.addChild(folderList);
  35. this.populate(importerType);
  36. this.text = windowText;
  37. this.setSize(800, 600);
  38. this.center();
  39. }
  40. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  41. if(ev.count >= 2) {
  42. var id = ev.target.id;
  43. if(id == this.folderList.rootList.id) {
  44. this.selectFile();
  45. }
  46. }
  47. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  48. var id = ev.target.id;
  49. if (id == "select") {
  50. return this.selectFile();
  51. }
  52. if (id == "cancel") {
  53. this.hide();
  54. return true;
  55. }
  56. }
  57. }
  58. selectFile():boolean {
  59. var id = this.folderList.selectedItemID;
  60. if(id.length) {
  61. this.callback(ToolCore.assetDatabase.getAssetByGUID(id), this.args);
  62. this.hide();
  63. return true;
  64. }
  65. return false;
  66. }
  67. }
  68. export = ResourceSelection;