FindDependencyQueryWnd.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const FileUtils_1 = require("./FileUtils");
  4. const UIWindow_1 = require("./UIWindow");
  5. const FairyGUI = CS.FairyGUI;
  6. const FairyEditor = CS.FairyEditor;
  7. const System = CS.System;
  8. const App = FairyEditor.App;
  9. class FindDependencyQueryWnd extends UIWindow_1.default {
  10. constructor() {
  11. super(new UIWindow_1.WindData("Extend", "FindDependencyQuery"));
  12. }
  13. static show() {
  14. let url = FileUtils_1.default.joinUrl("Extend", "FindDependencyQuery");
  15. if (UIWindow_1.default.FindUrl(url) == undefined) {
  16. UIWindow_1.default.add(new this);
  17. }
  18. super.show(url);
  19. }
  20. projectCount;
  21. projectList;
  22. yilaiList;
  23. yilaiCount;
  24. resList;
  25. resCount;
  26. externalCount;
  27. externalList;
  28. close;
  29. //依赖选中的包体集合
  30. yilaiSelectPkgs = new Array();
  31. //点击锁定查询的pkgs
  32. lockPkgs = new Array();
  33. yilaiCB;
  34. state;
  35. progress;
  36. onInit() {
  37. super.onInit();
  38. let self = this;
  39. this.projectCount = this.contentPane.GetChild("projectCount").asTextField;
  40. this.yilaiCount = this.contentPane.GetChild("yilaiCount").asTextField;
  41. this.resCount = this.contentPane.GetChild("resCount").asTextField;
  42. this.projectList = this.contentPane.GetChild("projectList").asList;
  43. this.yilaiList = this.contentPane.GetChild("yilaiList").asList;
  44. this.resList = this.contentPane.GetChild("resList").asList;
  45. this.externalCount = this.contentPane.GetChild("externalCount").asTextField;
  46. this.externalList = this.contentPane.GetChild("externalList").asList;
  47. this.state = this.contentPane.GetController("state");
  48. this.progress = this.contentPane.GetChild("progress").asProgress;
  49. this.contentPane.GetChild("close").onClick.Add(this.onCloseClick.bind(this));
  50. this.yilaiCB = this.contentPane.GetChild("yilaiCB").asButton;
  51. this.yilaiCB.onClick.Add(() => {
  52. self.onUpdateShown();
  53. });
  54. //复选框: 发布清除的资源不显示
  55. this.yilaiCB.visible = false;
  56. this.projectList.itemRenderer = this.onProjectListRenderer.bind(this);
  57. this.yilaiList.itemRenderer = this.onYiLaiListItemRenderer.bind(this);
  58. this.projectList.onClickItem.Add(this.onProjectListClickItem.bind(this));
  59. this.yilaiList.onClickItem.Add(this.onYiLaiListClickItem.bind(this));
  60. this.resList.itemRenderer = this.onResListItemRenderer.bind(this);
  61. this.resList.onClickItem.Add(this.onResListClickItem.bind(this));
  62. this.externalList.itemRenderer = this.onExternalListItemRenderer.bind(this);
  63. this.externalList.onClickItem.Add(this.onExternalListClickItem.bind(this));
  64. this.resList.SetVirtual();
  65. }
  66. onShown() {
  67. super.onShown();
  68. this.onUpdateShown();
  69. this.yilaiCB.selected = false;
  70. }
  71. onHide() {
  72. super.onHide();
  73. this.projectList.numItems = 0;
  74. this.yilaiList.numItems = 0;
  75. this.projectList.data = null;
  76. this.yilaiList.data = null;
  77. this.resList.numItems = 0;
  78. this.resList.data = null;
  79. this.externalList.data = null;
  80. this.externalList.numItems = 0;
  81. }
  82. onUpdateShown() {
  83. //获取项目包体
  84. let pkgs = [];
  85. for (let index = 0; index < App.project.allPackages.Count; index++) {
  86. pkgs.push(App.project.allPackages.get_Item(index));
  87. }
  88. this.projectList.data = pkgs;
  89. this.projectList.numItems = pkgs.length;
  90. this.projectCount.templateVars = this.getTemplateVars(["value"], [pkgs.length.toString()]);
  91. }
  92. onProjectListRenderer(index, obj) {
  93. let data = this.projectList.data[index];
  94. obj.text = data.name;
  95. obj.data = data;
  96. obj.__onDispose = () => {
  97. obj.text = "";
  98. obj.data = null;
  99. };
  100. }
  101. /**点击项目包体 查找对应的包体总依赖 */
  102. async onProjectListClickItem(item) {
  103. this.state.selectedIndex = 1;
  104. let querys = new Array();
  105. let pkg = item.data.data;
  106. let count = pkg.items.Count;
  107. this.progress.max = count;
  108. this.progress.value = 0;
  109. let list3Array = new Array();
  110. let map = new Map();
  111. for (let index = 0; index < count; index++) {
  112. let item = pkg.items.get_Item(index);
  113. this.progress.value = index;
  114. if (index % 50 == 0) {
  115. await FileUtils_1.default.sleep(0);
  116. }
  117. //未导出资源 不查找
  118. if (!item.exported)
  119. continue;
  120. if (item.type != FairyEditor.FPackageItemType.COMPONENT) {
  121. continue;
  122. }
  123. if (this.yilaiCB.selected) {
  124. FileUtils_1.default.isClearOnPublish(item, map, 0);
  125. }
  126. else {
  127. // //获取包体对应的依赖
  128. let list = FileUtils_1.default.createGenericList(FairyEditor.FPackageItem);
  129. list.Add(item);
  130. let data = new FairyEditor.DependencyQuery();
  131. data.QueryDependencies(list, FairyEditor.DependencyQuery.SeekLevel.ALL);
  132. for (let index = 0; index < data.references.Count; index++) {
  133. let reference = data.references.get_Item(index);
  134. let pkgID = reference.pkgId;
  135. let yilaipkg = App.project.GetPackage(pkgID);
  136. if (yilaipkg == null)
  137. continue;
  138. if (yilaipkg.GetItem(reference.itemId) && querys.indexOf(yilaipkg) == -1) {
  139. querys.push(yilaipkg);
  140. }
  141. }
  142. }
  143. list3Array.push({
  144. item: item,
  145. querts: null
  146. });
  147. }
  148. this.clearSelectPkgs();
  149. this.lockPkgs = [];
  150. if (this.yilaiCB.selected) {
  151. map.forEach((v, k) => {
  152. App.consoleView.Log(v.name);
  153. }, this);
  154. querys = Array.from(map).map(v => v[1]);
  155. }
  156. this.yilaiList.data = querys;
  157. this.yilaiList.numItems = querys.length;
  158. this.yilaiCount.templateVars = this.getTemplateVars(["value"], [querys.length.toString()]);
  159. this.resList.data = list3Array;
  160. this.resList.numItems = list3Array.length;
  161. this.resCount.templateVars = this.getTemplateVars(["value"], [list3Array.length.toString()]);
  162. this.externalList.numItems = null;
  163. this.externalList.data = null;
  164. this.externalCount.templateVars = this.getTemplateVars(["value"], ['0']);
  165. this.state.selectedIndex = 0;
  166. }
  167. /**获取资源点击的依赖包体 */
  168. getResYiLaiArray(item) {
  169. let querys = new Array();
  170. let list = FileUtils_1.default.createGenericList(FairyEditor.FPackageItem);
  171. list.Add(item);
  172. let data = new FairyEditor.DependencyQuery();
  173. data.QueryDependencies(list, FairyEditor.DependencyQuery.SeekLevel.ALL);
  174. for (let index = 0; index < data.references.Count; index++) {
  175. let reference = data.references.get_Item(index);
  176. let pkgID = reference.pkgId;
  177. let yilaipkg = App.project.GetPackage(pkgID);
  178. if (yilaipkg == null)
  179. continue;
  180. if (yilaipkg.GetItem(reference.itemId) && querys.indexOf(yilaipkg) == -1) {
  181. querys.push(yilaipkg);
  182. }
  183. }
  184. return querys;
  185. }
  186. onResListItemRenderer(index, obj) {
  187. let data = this.resList.data[index];
  188. obj.text = data.item.name;
  189. obj.data = data;
  190. if (this.yilaiCB.selected) {
  191. let map = new Map();
  192. FileUtils_1.default.isClearOnPublish(data.item, map, 0);
  193. data.querts = Array.from(map).map(x => x[1]);
  194. }
  195. else {
  196. data.querts = this.getResYiLaiArray(data.item);
  197. }
  198. let state = 0;
  199. if (this.yilaiSelectPkgs.length != 0) {
  200. if (this.isResInYiLai(obj, this.yilaiSelectPkgs)) {
  201. state = 1;
  202. }
  203. else {
  204. state = 2;
  205. }
  206. }
  207. obj.asCom.GetController("state").selectedIndex = state;
  208. obj.__onDispose = () => {
  209. obj.text = "";
  210. obj.data = null;
  211. };
  212. }
  213. onResListClickItem(obj) {
  214. let data = obj.data.data;
  215. let item = data.item;
  216. this.clearSelectPkgs();
  217. this.yilaiList.data = data.querts;
  218. this.yilaiList.numItems = data.querts.length;
  219. this.yilaiCount.templateVars = this.getTemplateVars(["value"], [data.querts.length.toString()]);
  220. //获取当前显示的包体 是否在锁定查询的信息里面
  221. let lockPkgs = new Array();
  222. for (let index = 0; index < data.querts.length; index++) {
  223. let pkg = data.querts[index];
  224. if (this.lockPkgs.indexOf(pkg) != -1) {
  225. lockPkgs.push(pkg);
  226. this.yilaiSelectPkgs.push(pkg);
  227. }
  228. }
  229. for (let index = 0; index < this.resList.numChildren; index++) {
  230. let item = this.resList.GetChildAt(index);
  231. if (this.isResInYiLai(item, lockPkgs))
  232. this.resList.GetChildAt(index).asCom.GetController("state").selectedIndex = 1;
  233. else
  234. this.resList.GetChildAt(index).asCom.GetController("state").selectedIndex = 2;
  235. }
  236. App.consoleView.Log(FileUtils_1.default.getUBBUrl(item.GetURL(), item.name));
  237. this.updateExternalList(item);
  238. }
  239. //刷新外部资源列表
  240. updateExternalList(item) {
  241. //刷新当前选中的包体 对应的依赖资源
  242. let query = this.getDependencyQuery(item);
  243. //如果勾选的外部依赖包体 那么只查找对应的 否则显示全部
  244. if (this.yilaiSelectPkgs.length > 0)
  245. for (let index = query.length - 1; index >= 0; index--) {
  246. const element = query[index];
  247. if (this.yilaiSelectPkgs.indexOf(element.owner) == -1) {
  248. query.splice(index, 1);
  249. }
  250. }
  251. this.externalList.data = query;
  252. this.externalList.numItems = this.externalList.data.length;
  253. this.externalCount.templateVars = this.getTemplateVars(["value"], [this.externalList.data.length + ""]);
  254. }
  255. //渲染点击的资源 外部依赖的详细资源
  256. onExternalListItemRenderer(index, obj) {
  257. let data = this.externalList.data[index];
  258. obj.text = data.name;
  259. obj.data = data;
  260. obj.GetChild("icon").asLoader.url = data.GetIcon(false, false, true);
  261. obj.__onDispose = () => {
  262. obj.text = "";
  263. obj.data = null;
  264. obj.GetChild("icon").asLoader.url = "";
  265. };
  266. }
  267. onExternalListClickItem(obj) {
  268. let data = obj.data.data;
  269. App.consoleView.Log(FileUtils_1.default.getUBBUrl(data.GetURL(), `依赖:${data.owner.name}/${data.name}`));
  270. }
  271. /**生成模板值 */
  272. getTemplateVars(keys, nums) {
  273. let dic = FileUtils_1.default.createGenericDictionary(System.String, System.String);
  274. keys.forEach((key, index) => {
  275. dic.set_Item(key, nums[index]);
  276. }, this);
  277. return dic;
  278. }
  279. //清空依赖选中
  280. clearSelectPkgs() {
  281. this.yilaiList.SelectNone();
  282. this.yilaiSelectPkgs = [];
  283. }
  284. /**获取依赖清单 */
  285. getDependencyQuery(item) {
  286. //获取包体对应的依赖
  287. let yilaiItems = new Array();
  288. if (this.yilaiCB.selected) {
  289. let map = new Map();
  290. FileUtils_1.default.getClearOnPublishPackageItem(item, map, 0);
  291. yilaiItems = Array.from(map).map(x => x[1]);
  292. }
  293. else {
  294. let list = FileUtils_1.default.createGenericList(FairyEditor.FPackageItem);
  295. list.Add(item);
  296. let data = new FairyEditor.DependencyQuery();
  297. data.QueryDependencies(list, FairyEditor.DependencyQuery.SeekLevel.ALL);
  298. for (let index = 0; index < data.references.Count; index++) {
  299. let reference = data.references.get_Item(index);
  300. let pkgID = reference.pkgId;
  301. let yilaipkg = App.project.GetPackage(pkgID);
  302. if (yilaipkg == null)
  303. continue;
  304. let yilaiItem = yilaipkg.GetItem(reference.itemId);
  305. if (yilaiItem && yilaiItems.indexOf(yilaiItem) == -1) {
  306. //App.consoleView.Log(FileUtils.getUBBUrl(yilaiItem.GetURL(), yilaiItem.name));
  307. yilaiItems.push(yilaiItem);
  308. }
  309. }
  310. }
  311. return yilaiItems;
  312. }
  313. onYiLaiListClickItem(obj) {
  314. let btn = obj.data;
  315. //锁定的包体不允许取消选中
  316. if (!btn.selected && this.lockPkgs.indexOf(btn.data) != -1) {
  317. btn.selected = true;
  318. return;
  319. }
  320. this.getSelectYiLaiPkgs();
  321. //获取选中的物体
  322. for (let index = 0; index < this.resList.numChildren; index++) {
  323. let resItem = this.resList.GetChildAt(index);
  324. if (this.isResInYiLai(resItem, this.yilaiSelectPkgs) || this.isResInYiLai(resItem, this.lockPkgs)) {
  325. resItem.asCom.GetController("state").selectedIndex = 1;
  326. }
  327. else {
  328. resItem.asCom.GetController("state").selectedIndex = 2;
  329. }
  330. }
  331. //刷新当前外部资源列表
  332. if (this.resList.selectedIndex < 0) {
  333. this.externalList.numItems = 0;
  334. this.externalList.data = null;
  335. this.externalCount.templateVars = this.getTemplateVars(['value'], ['0']);
  336. }
  337. else {
  338. let res = this.resList.GetChildAt(this.resList.selectedIndex).data;
  339. this.updateExternalList(res.item);
  340. }
  341. }
  342. //获取依赖列表全部选中的包
  343. getSelectYiLaiPkgs() {
  344. //获取全部选中的物体
  345. let selectIndexs = this.yilaiList.GetSelection();
  346. let selectPkgs = new Array();
  347. for (let index = 0; index < selectIndexs.Count; index++) {
  348. selectPkgs.push(this.yilaiList.GetChildAt(selectIndexs.get_Item(index)).data);
  349. }
  350. this.yilaiSelectPkgs = selectPkgs;
  351. }
  352. //资源是否在依赖列表中
  353. isResInYiLai(obj, pkgs) {
  354. let querts = obj.data.querts;
  355. if (pkgs.length == 0)
  356. return false;
  357. //判断两个数组是否有相同的值
  358. return pkgs.some(pkg => {
  359. return querts.some(resItem => {
  360. return resItem.name == pkg.name;
  361. });
  362. });
  363. }
  364. onYiLaiListItemRenderer(index, obj) {
  365. let data = this.yilaiList.data[index];
  366. obj.text = data.name;
  367. obj.data = data;
  368. obj.selected = this.lockPkgs.indexOf(data) != -1;
  369. let cb = obj.GetChild("cb").asButton;
  370. cb.selected = obj.selected;
  371. cb.RemoveEventListeners();
  372. cb.onClick.Add(this.onCBLock.bind(this, data, obj));
  373. obj.__onDispose = () => {
  374. obj.text = "";
  375. obj.data = null;
  376. };
  377. }
  378. //CB锁定
  379. onCBLock(data, obj, item) {
  380. let index = this.lockPkgs.indexOf(data);
  381. if (index == -1) {
  382. if (obj.selected)
  383. item.StopPropagation();
  384. this.lockPkgs.push(data);
  385. }
  386. else {
  387. this.lockPkgs.splice(index, 1);
  388. item.StopPropagation();
  389. }
  390. }
  391. onCloseClick() {
  392. let self = this;
  393. self.Hide();
  394. FairyGUI.Timers.inst.Add(0.05, 1, () => {
  395. UIWindow_1.default.remove(this);
  396. });
  397. }
  398. }
  399. exports.default = FindDependencyQueryWnd;