AttributeInfoEdit.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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("ui/EditorUI");
  8. import InspectorUtils = require("./InspectorUtils");
  9. import SerializableEditType = require("./SerializableEditType");
  10. class AttributeInfoEdit extends Atomic.UILayout {
  11. attrInfo: Atomic.AttributeInfo;
  12. editType: SerializableEditType;
  13. editWidget: Atomic.UIWidget;
  14. nameOverride: string;
  15. hideName: boolean = false;
  16. constructor() {
  17. super();
  18. }
  19. initialize(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): boolean {
  20. this.editType = editType;
  21. this.attrInfo = attrInfo;
  22. this.createLayout();
  23. return true;
  24. }
  25. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  26. return false;
  27. }
  28. createLayout() {
  29. this.createEditWidget();
  30. this.editWidget.subscribeToEvent(this.editWidget, "WidgetEvent", (data) => this.handleWidgetEvent(data));
  31. var attr = this.attrInfo;
  32. var attrNameLP = AttributeInfoEdit.attrNameLP;
  33. this.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  34. if (attr.type == Atomic.VAR_VECTOR3 || attr.type == Atomic.VAR_COLOR ||
  35. attr.type == Atomic.VAR_QUATERNION) {
  36. this.axis = Atomic.UI_AXIS_Y;
  37. this.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  38. this.skinBg = "InspectorVectorAttrLayout";
  39. }
  40. if (!this.hideName) {
  41. var name = new Atomic.UITextField();
  42. name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  43. name.skinBg = "InspectorTextAttrName";
  44. name.layoutParams = attrNameLP;
  45. var bname = attr.name;
  46. if (bname == "Is Enabled")
  47. bname = "Enabled";
  48. if (this.nameOverride)
  49. name.text = this.nameOverride;
  50. else
  51. name.text = bname;
  52. name.fontDescription = AttributeInfoEdit.fontDesc;
  53. this.addChild(name);
  54. }
  55. this.addChild(this.editWidget);
  56. }
  57. createEditWidget() {
  58. }
  59. refresh() {
  60. }
  61. static createAttrEdit(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): AttributeInfoEdit {
  62. var type: typeof AttributeInfoEdit;
  63. var customTypes = AttributeInfoEdit.customAttrEditTypes[editType.typeName];
  64. if (customTypes) {
  65. type = customTypes[attrInfo.name];
  66. }
  67. if (!type) {
  68. type = AttributeInfoEdit.standardAttrEditTypes[attrInfo.type];
  69. }
  70. if (!type)
  71. return null;
  72. var attrEdit = new type();
  73. if (!attrEdit.initialize(editType, attrInfo))
  74. return null;
  75. return attrEdit;
  76. }
  77. // atttribute name layout param
  78. static attrNameLP: Atomic.UILayoutParams;
  79. static fontDesc: Atomic.UIFontDescription;
  80. static standardAttrEditTypes: { [variantType: number /*Atomic.VariantType*/]: typeof AttributeInfoEdit } = {};
  81. static customAttrEditTypes: { [typeName: string]: { [name: string]: typeof AttributeInfoEdit } } = {};
  82. static registerCustomAttr(typeName: string, attrName: string, edit: typeof AttributeInfoEdit) {
  83. if (!AttributeInfoEdit.customAttrEditTypes[typeName]) {
  84. AttributeInfoEdit.customAttrEditTypes[typeName] = {};
  85. }
  86. AttributeInfoEdit.customAttrEditTypes[typeName][attrName] = edit;
  87. }
  88. private static Ctor = (() => {
  89. var attrNameLP = AttributeInfoEdit.attrNameLP = new Atomic.UILayoutParams();
  90. attrNameLP.width = 120;
  91. var fd = AttributeInfoEdit.fontDesc = new Atomic.UIFontDescription();
  92. fd.id = "Vera";
  93. fd.size = 11;
  94. })();
  95. }
  96. class BoolAttributeEdit extends AttributeInfoEdit {
  97. createEditWidget() {
  98. var box = new Atomic.UICheckBox();
  99. this.editWidget = box;
  100. }
  101. refresh() {
  102. var uniform = this.editType.getUniformValue(this.attrInfo);
  103. if (uniform) {
  104. var object = this.editType.getFirstObject();
  105. this.editWidget.skinBg = "TBGreyCheckBox";
  106. if (object) {
  107. var value = object.getAttribute(this.attrInfo.name);
  108. this.editWidget.value = (value ? 1 : 0);
  109. }
  110. } else {
  111. this.editWidget.skinBg = "TBGreyCheckBoxNonUniform";
  112. this.editWidget.value = 1;
  113. }
  114. }
  115. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  116. if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
  117. this.editType.onAttributeInfoEdited(this.attrInfo, this.editWidget.value ? true : false);
  118. this.refresh();
  119. return true;
  120. }
  121. return false;
  122. }
  123. }
  124. class StringAttributeEdit extends AttributeInfoEdit {
  125. createEditWidget() {
  126. var field = new Atomic.UIEditField();
  127. field.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
  128. field.skinBg = "TBAttrEditorField";;
  129. field.fontDescription = AttributeInfoEdit.fontDesc;
  130. var lp = new Atomic.UILayoutParams();
  131. lp.width = 160;
  132. field.layoutParams = lp;
  133. field.subscribeToEvent(field, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
  134. this.editWidget = field;
  135. }
  136. refresh() {
  137. var uniform = this.editType.getUniformValue(this.attrInfo);
  138. if (uniform) {
  139. var object = this.editType.getFirstObject();
  140. if (object) {
  141. var value = object.getAttribute(this.attrInfo.name);
  142. this.editWidget.text = value;
  143. }
  144. } else {
  145. this.editWidget.text = "--";
  146. }
  147. }
  148. handleUIWidgetEditCompleteEvent(ev) {
  149. this.editType.onAttributeInfoEdited(this.attrInfo, this.editWidget.text);
  150. this.refresh();
  151. }
  152. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  153. if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
  154. return true;
  155. }
  156. return false;
  157. }
  158. }
  159. class IntAttributeEdit extends AttributeInfoEdit {
  160. enumSource: Atomic.UISelectItemSource;
  161. createEditWidget() {
  162. var attrInfo = this.attrInfo;
  163. if (attrInfo.enumNames.length) {
  164. var enumSource = this.enumSource = new Atomic.UISelectItemSource();
  165. for (var i in attrInfo.enumNames) {
  166. enumSource.addItem(new Atomic.UISelectItem(attrInfo.enumNames[i], (Number(i) + 1).toString()));
  167. }
  168. var button = new Atomic.UIButton();
  169. button.fontDescription = AttributeInfoEdit.fontDesc;
  170. button.text = "Enum Value!";
  171. var lp = new Atomic.UILayoutParams();
  172. lp.width = 140;
  173. button.layoutParams = lp;
  174. this.editWidget = button;
  175. } else {
  176. var field = new Atomic.UIEditField();
  177. field.textAlign = Atomic.UI_TEXT_ALIGN_CENTER;
  178. field.skinBg = "TBAttrEditorField";;
  179. field.fontDescription = AttributeInfoEdit.fontDesc;
  180. var lp = new Atomic.UILayoutParams();
  181. lp.width = 140;
  182. field.layoutParams = lp;
  183. field.subscribeToEvent(field, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
  184. this.editWidget = field;
  185. }
  186. }
  187. refresh() {
  188. var uniform = this.editType.getUniformValue(this.attrInfo);
  189. if (uniform) {
  190. var object = this.editType.getFirstObject();
  191. if (object) {
  192. var value = object.getAttribute(this.attrInfo.name);
  193. var widget = this.editWidget;
  194. var attrInfo = this.attrInfo;
  195. if (attrInfo.enumNames.length) {
  196. widget.text = attrInfo.enumNames[value];
  197. }
  198. else {
  199. widget.text = value.toString();
  200. }
  201. }
  202. } else {
  203. this.editWidget.text = "--";
  204. }
  205. }
  206. handleUIWidgetEditCompleteEvent(ev) {
  207. // non-enum
  208. this.editType.onAttributeInfoEdited(this.attrInfo, Number(this.editWidget.text));
  209. this.refresh();
  210. }
  211. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  212. if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
  213. return true;
  214. }
  215. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  216. var id = this.attrInfo.name + " enum popup";
  217. if (ev.target.id == id) {
  218. this.editType.onAttributeInfoEdited(this.attrInfo, Number(ev.refid) - 1);
  219. this.refresh();
  220. }
  221. else if (this.editWidget == ev.target && this.attrInfo.enumNames.length) {
  222. if (this.enumSource) {
  223. var menu = new Atomic.UIMenuWindow(ev.target, id);
  224. menu.show(this.enumSource);
  225. }
  226. return true;
  227. }
  228. }
  229. return false;
  230. }
  231. }
  232. class FloatAttributeEdit extends AttributeInfoEdit {
  233. createEditWidget() {
  234. var attrInfo = this.attrInfo;
  235. var field = new Atomic.UIEditField();
  236. field.textAlign = Atomic.UI_TEXT_ALIGN_CENTER;
  237. field.skinBg = "TBAttrEditorField";;
  238. field.fontDescription = AttributeInfoEdit.fontDesc;
  239. var lp = new Atomic.UILayoutParams();
  240. lp.width = 140;
  241. field.layoutParams = lp;
  242. field.subscribeToEvent(field, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
  243. this.editWidget = field;
  244. }
  245. refresh() {
  246. var uniform = this.editType.getUniformValue(this.attrInfo);
  247. if (uniform) {
  248. var object = this.editType.getFirstObject();
  249. if (object) {
  250. var widget = this.editWidget;
  251. var attrInfo = this.attrInfo;
  252. var value = object.getAttribute(attrInfo.name);
  253. if (value == undefined) {
  254. console.log("WARNING: Undefined value for object: ", this.editType.typeName + "." + attrInfo.name);
  255. widget.text = "???";
  256. } else {
  257. widget.text = parseFloat(value.toFixed(5)).toString();
  258. }
  259. }
  260. } else {
  261. this.editWidget.text = "--";
  262. }
  263. }
  264. handleUIWidgetEditCompleteEvent(ev) {
  265. this.editType.onAttributeInfoEdited(this.attrInfo, Number(this.editWidget.text));
  266. this.refresh();
  267. }
  268. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  269. if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
  270. return true;
  271. }
  272. return false;
  273. }
  274. }
  275. class NumberArrayAttributeEdit extends AttributeInfoEdit {
  276. selects: Atomic.UIInlineSelect[] = [];
  277. private numElements: number;
  278. constructor(numElements: number) {
  279. super();
  280. this.numElements = numElements;
  281. }
  282. createEditWidget() {
  283. var attrInfo = this.attrInfo;
  284. var layout = new Atomic.UILayout();
  285. layout.spacing = 0;
  286. var lp = new Atomic.UILayoutParams();
  287. lp.width = this.numElements != 4 ? 100 : 70;
  288. for (var i = 0; i < this.numElements; i++) {
  289. var select = new Atomic.UIInlineSelect();
  290. this.selects.push(select);
  291. select.id = String(i + 1);
  292. select.fontDescription = AttributeInfoEdit.fontDesc;
  293. select.skinBg = "InspectorVectorAttrName";
  294. select.setLimits(-10000000, 10000000);
  295. if (this.numElements != 4) {
  296. var editlp = new Atomic.UILayoutParams();
  297. editlp.minWidth = 60;
  298. select.editFieldLayoutParams = editlp;
  299. }
  300. select.layoutParams = lp;
  301. layout.addChild(select);
  302. select["_edit"] = select.getWidget("edit");
  303. select["_dec"] = select.getWidget("dec");
  304. select["_inc"] = select.getWidget("inc");
  305. select.subscribeToEvent(select, "WidgetEvent", (ev) => this.handleWidgetEvent(ev));
  306. select.subscribeToEvent(select, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
  307. }
  308. this.editWidget = layout;
  309. }
  310. refresh() {
  311. for (var i in this.selects) {
  312. var select = this.selects[i];
  313. if (select["_edit"].focus || select["_dec"].captured || select["_inc"].captured)
  314. continue;
  315. var uniform = this.editType.getUniformValue(this.attrInfo, i);
  316. if (uniform) {
  317. var object = this.editType.getFirstObject();
  318. if (object) {
  319. var value = object.getAttribute(this.attrInfo.name);
  320. select.value = parseFloat(value[i].toFixed(5));
  321. }
  322. } else {
  323. select["_edit"].text = "--";
  324. }
  325. }
  326. }
  327. handleUIWidgetEditCompleteEvent(ev: Atomic.UIWidgetEditCompleteEvent) {
  328. var index = Number(ev.widget.id) - 1;
  329. this.editType.onAttributeInfoEdited(this.attrInfo, ev.widget.value, index);
  330. this.refresh();
  331. }
  332. handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
  333. if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
  334. var captured = false;
  335. for (var i in this.selects) {
  336. var select = this.selects[i];
  337. if (select["_dec"].captured || select["_inc"].captured) {
  338. captured = true;
  339. break;
  340. }
  341. }
  342. if (captured) {
  343. var index = Number(ev.target.id) - 1;
  344. this.editType.onAttributeInfoEdited(this.attrInfo, ev.target.value, index, false);
  345. }
  346. return true;
  347. }
  348. return false;
  349. }
  350. }
  351. class Vector2AttributeEdit extends NumberArrayAttributeEdit {
  352. constructor() {
  353. super(2);
  354. }
  355. }
  356. class Vector3AttributeEdit extends NumberArrayAttributeEdit {
  357. constructor() {
  358. super(3);
  359. }
  360. }
  361. class QuaternionAttributeEdit extends NumberArrayAttributeEdit {
  362. constructor() {
  363. super(3);
  364. }
  365. }
  366. class ColorAttributeEdit extends NumberArrayAttributeEdit {
  367. constructor() {
  368. super(4);
  369. }
  370. }
  371. class ResourceRefAttributeEdit extends AttributeInfoEdit {
  372. refListIndex: number;
  373. editField: Atomic.UIEditField;
  374. constructor(refListIndex: number = -1) {
  375. super();
  376. this.refListIndex = refListIndex;
  377. }
  378. onResourceChanged(resource: Atomic.Resource) {
  379. var parent = this.parent;
  380. while (parent) {
  381. if (parent.typeName == "UISection") {
  382. break;
  383. }
  384. parent = parent.parent;
  385. }
  386. if (parent) {
  387. parent.sendEvent("AttributeEditResourceChanged", { attrInfoEdit: this, resource: resource });
  388. }
  389. }
  390. initialize(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): boolean {
  391. if (!attrInfo.resourceTypeName)
  392. return false;
  393. if (this.refListIndex >= 0)
  394. this.nameOverride = attrInfo.resourceTypeName + " " + this.refListIndex;
  395. var importerName = ToolCore.assetDatabase.getResourceImporterName(attrInfo.resourceTypeName);
  396. if (!importerName)
  397. return false;
  398. return super.initialize(editType, attrInfo);
  399. }
  400. refresh() {
  401. var uniform = this.editType.getUniformValue(this.attrInfo, this.refListIndex);
  402. if (uniform) {
  403. var object = this.editType.getFirstObject();
  404. if (object) {
  405. // for cached resources, use the asset name, otherwise use the resource path name
  406. var resource: Atomic.Resource;
  407. if (this.refListIndex != -1) {
  408. resource = object.getAttribute(this.attrInfo.name).resources[this.refListIndex];
  409. } else {
  410. resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name);
  411. }
  412. var text = "";
  413. if (resource) {
  414. if (resource instanceof Atomic.Animation) {
  415. text = (<Atomic.Animation>resource).animationName;
  416. } else {
  417. text = resource.name;
  418. var asset = ToolCore.assetDatabase.getAssetByCachePath(resource.name);
  419. if (asset)
  420. text = asset.name;
  421. }
  422. }
  423. this.editField.text = text;
  424. }
  425. } else {
  426. this.editField.text = "--";
  427. }
  428. }
  429. createEditWidget() {
  430. var layout = new Atomic.UILayout();
  431. var o = InspectorUtils.createAttrEditFieldWithSelectButton("", layout);
  432. this.editField = o.editField;
  433. layout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  434. layout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
  435. layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  436. var lp = new Atomic.UILayoutParams();
  437. lp.width = 140;
  438. o.editField.layoutParams = lp;
  439. o.editField.readOnly = true;
  440. this.editWidget = layout;
  441. var selectButton = o.selectButton;
  442. var resourceTypeName = this.attrInfo.resourceTypeName;
  443. var importerName = ToolCore.assetDatabase.getResourceImporterName(resourceTypeName);
  444. selectButton.onClick = () => {
  445. EditorUI.getModelOps().showResourceSelection("Select " + resourceTypeName + " Resource", importerName, resourceTypeName, function(retObject: any) {
  446. var resource: Atomic.Resource = null;
  447. if (retObject instanceof ToolCore.Asset) {
  448. resource = (<ToolCore.Asset>retObject).getResource(resourceTypeName);
  449. } else if (retObject instanceof Atomic.Resource) {
  450. resource = <Atomic.Resource>retObject;
  451. }
  452. this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex);
  453. this.onResourceChanged(resource);
  454. this.refresh();
  455. }.bind(this));
  456. }
  457. // handle dropping of component on field
  458. this.editField.subscribeToEvent(this.editField, "DragEnded", (ev: Atomic.DragEndedEvent) => {
  459. if (ev.target == o.editField) {
  460. var dragObject = ev.dragObject;
  461. var importer;
  462. if (dragObject.object && dragObject.object.typeName == "Asset") {
  463. var asset = <ToolCore.Asset>dragObject.object;
  464. if (asset.importerTypeName == importerName) {
  465. importer = asset.importer;
  466. }
  467. }
  468. if (importer) {
  469. var resource = asset.getResource(resourceTypeName);
  470. this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex);
  471. this.onResourceChanged(resource);
  472. this.refresh();
  473. }
  474. }
  475. });
  476. }
  477. }
  478. class ResourceRefListAttributeEdit extends AttributeInfoEdit {
  479. layout: Atomic.UILayout;
  480. refEdits: ResourceRefAttributeEdit[] = [];
  481. sizeEdit: Atomic.UIEditField;
  482. initialize(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): boolean {
  483. return super.initialize(editType, attrInfo);
  484. }
  485. createRefEdit(index: number) {
  486. var refEdit = new ResourceRefAttributeEdit(index);
  487. refEdit.initialize(this.editType, this.attrInfo);
  488. this.layout.addChild(refEdit);
  489. this.refEdits.push(refEdit);
  490. }
  491. createEditWidget() {
  492. this.spacing = 0;
  493. var layout = this.layout = new Atomic.UILayout();
  494. layout.axis = Atomic.UI_AXIS_Y;
  495. layout.spacing = 2;
  496. layout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
  497. layout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
  498. layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
  499. layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
  500. var lp = new Atomic.UILayoutParams();
  501. lp.width = 304;
  502. layout.layoutParams = lp;
  503. var name = this.attrInfo.name + " Size";
  504. if (name == "AnimationResources Size")
  505. name = "Animations";
  506. var sizeEdit = this.sizeEdit = InspectorUtils.createAttrEditField(name, layout);
  507. var lp = new Atomic.UILayoutParams();
  508. lp.width = 160;
  509. sizeEdit.layoutParams = lp;
  510. sizeEdit.subscribeToEvent(sizeEdit, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
  511. this.editWidget = layout;
  512. }
  513. createLayout() {
  514. this.createEditWidget();
  515. this.editWidget.subscribeToEvent(this.editWidget, "WidgetEvent", (data) => this.handleWidgetEvent(data));
  516. this.addChild(this.editWidget);
  517. }
  518. handleUIWidgetEditCompleteEvent(ev) {
  519. var size = Number(this.sizeEdit.text);
  520. if (size > 64 || size < 0)
  521. return;
  522. var editType = this.editType;
  523. var refresh = false;
  524. for (var i in editType.objects) {
  525. var object = editType.objects[i];
  526. var value = object.getAttribute(this.attrInfo.name);
  527. if (value.resources.length > size) {
  528. value.resources.length = size;
  529. object.setAttribute(this.attrInfo.name, value);
  530. refresh = true;
  531. } else if (value.resources.length < size) {
  532. for (var j = value.resources.length; j < size; j++) {
  533. value.resources.push(null);
  534. }
  535. object.setAttribute(this.attrInfo.name, value);
  536. refresh = true;
  537. }
  538. }
  539. if (refresh)
  540. this.refresh();
  541. }
  542. refresh() {
  543. var editType = this.editType;
  544. var object = this.editType.getFirstObject();
  545. if (!object) {
  546. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  547. return;
  548. }
  549. this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  550. var maxLength = -1;
  551. var i;
  552. for (i in editType.objects) {
  553. object = editType.objects[i];
  554. var value = object.getAttribute(this.attrInfo.name);
  555. if (value.resources.length > maxLength) {
  556. maxLength = value.resources.length;
  557. }
  558. }
  559. this.sizeEdit.text = maxLength.toString();
  560. if (maxLength == -1) {
  561. this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  562. return;
  563. }
  564. for (i = this.refEdits.length; i < maxLength; i++) {
  565. this.createRefEdit(i);
  566. }
  567. for (i = 0; i < this.refEdits.length; i++) {
  568. var refEdit = this.refEdits[i];
  569. if (i < maxLength) {
  570. refEdit.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
  571. refEdit.refresh();
  572. }
  573. else {
  574. refEdit.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  575. }
  576. }
  577. }
  578. }
  579. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_BOOL] = BoolAttributeEdit;
  580. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_INT] = IntAttributeEdit;
  581. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_FLOAT] = FloatAttributeEdit;
  582. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_STRING] = StringAttributeEdit;
  583. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_VECTOR2] = Vector2AttributeEdit;
  584. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_VECTOR3] = Vector3AttributeEdit;
  585. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_QUATERNION] = QuaternionAttributeEdit;
  586. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_COLOR] = ColorAttributeEdit;
  587. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_RESOURCEREF] = ResourceRefAttributeEdit;
  588. AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_RESOURCEREFLIST] = ResourceRefListAttributeEdit;
  589. export = AttributeInfoEdit;