AttributeInfoEdit.ts 24 KB

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