| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025 |
- //
- // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- import EditorUI = require("ui/EditorUI");
- import InspectorUtils = require("./InspectorUtils");
- import SerializableEditType = require("./SerializableEditType");
- import EditorEvents = require("editor/EditorEvents");
- class AttributeInfoEdit extends Atomic.UILayout {
- attrInfo: Atomic.AttributeInfo;
- editType: SerializableEditType;
- editWidget: Atomic.UIWidget;
- nameOverride: string;
- hideName: boolean = false;
- constructor() {
- super();
- }
- initialize(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): boolean {
- this.editType = editType;
- this.attrInfo = attrInfo;
- this.createLayout();
- return true;
- }
- handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
- return false;
- }
- createLayout() {
- this.createEditWidget();
- this.editWidget.subscribeToEvent(this.editWidget, "WidgetEvent", (data) => this.handleWidgetEvent(data));
- var attr = this.attrInfo;
- var attrNameLP = AttributeInfoEdit.attrNameLP;
- this.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
- if (attr.type == Atomic.VAR_VECTOR3 || attr.type == Atomic.VAR_COLOR ||
- attr.type == Atomic.VAR_QUATERNION) {
- this.axis = Atomic.UI_AXIS_Y;
- this.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
- this.skinBg = "InspectorVectorAttrLayout";
- }
- if (!this.hideName) {
- var name = new Atomic.UITextField();
- name.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
- name.skinBg = "InspectorTextAttrName";
- name.layoutParams = attrNameLP;
- var bname = attr.name;
- if (bname == "Is Enabled")
- bname = "Enabled";
- if (this.nameOverride)
- name.text = this.nameOverride;
- else
- name.text = bname;
- name.fontDescription = AttributeInfoEdit.fontDesc;
- this.addChild(name);
- }
- this.addChild(this.editWidget);
- }
- createEditWidget() {
- }
- refresh() {
- }
- static createAttrEdit(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): AttributeInfoEdit {
- var type: typeof AttributeInfoEdit;
- var customTypes = AttributeInfoEdit.customAttrEditTypes[editType.typeName];
- if (customTypes) {
- type = customTypes[attrInfo.name];
- }
- if (!type) {
- type = AttributeInfoEdit.standardAttrEditTypes[attrInfo.type];
- }
- if (!type)
- return null;
- var attrEdit = new type();
- if (!attrEdit.initialize(editType, attrInfo))
- return null;
- return attrEdit;
- }
- // atttribute name layout param
- static attrNameLP: Atomic.UILayoutParams;
- static fontDesc: Atomic.UIFontDescription;
- static standardAttrEditTypes: { [variantType: number /*Atomic.VariantType*/]: typeof AttributeInfoEdit } = {};
- static customAttrEditTypes: { [typeName: string]: { [name: string]: typeof AttributeInfoEdit } } = {};
- static registerCustomAttr(typeName: string, attrName: string, edit: typeof AttributeInfoEdit) {
- if (!AttributeInfoEdit.customAttrEditTypes[typeName]) {
- AttributeInfoEdit.customAttrEditTypes[typeName] = {};
- }
- AttributeInfoEdit.customAttrEditTypes[typeName][attrName] = edit;
- }
- private static Ctor = (() => {
- var attrNameLP = AttributeInfoEdit.attrNameLP = new Atomic.UILayoutParams();
- attrNameLP.width = 120;
- var fd = AttributeInfoEdit.fontDesc = new Atomic.UIFontDescription();
- fd.id = "Vera";
- fd.size = 11;
- })();
- }
- class BoolAttributeEdit extends AttributeInfoEdit {
- createEditWidget() {
- var box = new Atomic.UICheckBox();
- this.editWidget = box;
- }
- refresh() {
- var uniform = this.editType.getUniformValue(this.attrInfo);
- if (uniform) {
- var object = this.editType.getFirstObject();
- this.editWidget.skinBg = "TBGreyCheckBox";
- if (object) {
- var value = object.getAttribute(this.attrInfo.name);
- this.editWidget.value = (value ? 1 : 0);
- }
- } else {
- this.editWidget.skinBg = "TBGreyCheckBoxNonUniform";
- this.editWidget.value = 1;
- }
- }
- handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
- if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
- this.editType.onAttributeInfoEdited(this.attrInfo, this.editWidget.value ? true : false);
- this.refresh();
- return true;
- }
- return false;
- }
- }
- class StringAttributeEdit extends AttributeInfoEdit {
- createEditWidget() {
- var field = new Atomic.UIEditField();
- field.textAlign = Atomic.UI_TEXT_ALIGN_LEFT;
- field.skinBg = "TBAttrEditorField";
- field.fontDescription = AttributeInfoEdit.fontDesc;
- var lp = new Atomic.UILayoutParams();
- lp.width = 160;
- lp.height = 24;
- field.layoutParams = lp;
- field.subscribeToEvent(field, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
- this.editWidget = field;
- }
- refresh() {
- var uniform = this.editType.getUniformValue(this.attrInfo);
- if (uniform) {
- var object = this.editType.getFirstObject();
- if (object) {
- var value = object.getAttribute(this.attrInfo.name);
- this.editWidget.text = value;
- }
- } else {
- this.editWidget.text = "--";
- }
- }
- handleUIWidgetEditCompleteEvent(ev) {
- this.editType.onAttributeInfoEdited(this.attrInfo, this.editWidget.text);
- this.refresh();
- }
- handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
- if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
- return true;
- }
- return false;
- }
- }
- class IntAttributeEdit extends AttributeInfoEdit {
- enumSource: Atomic.UISelectItemSource;
- createEditWidget() {
- var attrInfo = this.attrInfo;
- if (attrInfo.enumNames.length) {
- var enumSource = this.enumSource = new Atomic.UISelectItemSource();
- for (var i in attrInfo.enumNames) {
- enumSource.addItem(new Atomic.UISelectItem(attrInfo.enumNames[i], (Number(i) + 1).toString()));
- }
- var button = new Atomic.UIButton();
- button.fontDescription = AttributeInfoEdit.fontDesc;
- button.text = "Enum Value!";
- var lp = new Atomic.UILayoutParams();
- lp.width = 140;
- button.layoutParams = lp;
- this.editWidget = button;
- } else {
- var field = new Atomic.UIEditField();
- field.textAlign = Atomic.UI_TEXT_ALIGN_CENTER;
- field.skinBg = "TBAttrEditorField";
- field.fontDescription = AttributeInfoEdit.fontDesc;
- var lp = new Atomic.UILayoutParams();
- lp.width = 140;
- lp.height = 24;
- field.layoutParams = lp;
- field.subscribeToEvent(field, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
- this.editWidget = field;
- }
- }
- refresh() {
- var uniform = this.editType.getUniformValue(this.attrInfo);
- if (uniform) {
- var object = this.editType.getFirstObject();
- if (object) {
- var value = object.getAttribute(this.attrInfo.name);
- var widget = this.editWidget;
- var attrInfo = this.attrInfo;
- if (attrInfo.enumNames.length) {
- widget.text = attrInfo.enumNames[value];
- }
- else {
- widget.text = value.toString();
- }
- }
- } else {
- this.editWidget.text = "--";
- }
- }
- handleUIWidgetEditCompleteEvent(ev) {
- // non-enum
- this.editType.onAttributeInfoEdited(this.attrInfo, Number(this.editWidget.text));
- this.refresh();
- }
- handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
- if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
- return true;
- }
- if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
- var id = this.attrInfo.name + " enum popup";
- if (ev.target.id == id) {
- this.editType.onAttributeInfoEdited(this.attrInfo, Number(ev.refid) - 1);
- this.refresh();
- }
- else if (this.editWidget == ev.target && this.attrInfo.enumNames.length) {
- if (this.enumSource) {
- var menu = new Atomic.UIMenuWindow(ev.target, id);
- menu.show(this.enumSource);
- }
- return true;
- }
- }
- return false;
- }
- }
- class FloatAttributeEdit extends AttributeInfoEdit {
- createEditWidget() {
- var attrInfo = this.attrInfo;
- var field = new Atomic.UIEditField();
- field.textAlign = Atomic.UI_TEXT_ALIGN_CENTER;
- field.skinBg = "TBAttrEditorField";
- field.fontDescription = AttributeInfoEdit.fontDesc;
- var lp = new Atomic.UILayoutParams();
- lp.width = 140;
- lp.height = 24;
- field.layoutParams = lp;
- field.subscribeToEvent(field, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
- this.editWidget = field;
- }
- refresh() {
- var uniform = this.editType.getUniformValue(this.attrInfo);
- if (uniform) {
- var object = this.editType.getFirstObject();
- if (object) {
- var widget = this.editWidget;
- var attrInfo = this.attrInfo;
- var value = object.getAttribute(attrInfo.name);
- if (value == undefined) {
- console.log("WARNING: Undefined value for object: ", this.editType.typeName + "." + attrInfo.name);
- widget.text = "???";
- } else {
- widget.text = parseFloat(value.toFixed(5)).toString();
- }
- }
- } else {
- this.editWidget.text = "--";
- }
- }
- handleUIWidgetEditCompleteEvent(ev) {
- this.editType.onAttributeInfoEdited(this.attrInfo, Number(this.editWidget.text));
- this.refresh();
- }
- handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
- if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
- return true;
- }
- return false;
- }
- }
- class NumberArrayAttributeEdit extends AttributeInfoEdit {
- selects: Atomic.UIInlineSelect[] = [];
- private numElements: number;
- constructor(numElements: number) {
- super();
- this.numElements = numElements;
- }
- createEditWidget() {
- var attrInfo = this.attrInfo;
- var layout = new Atomic.UILayout();
- layout.spacing = 0;
- var lp = new Atomic.UILayoutParams();
- lp.width = this.numElements != 4 ? 100 : 70;
- for (var i = 0; i < this.numElements; i++) {
- var select = new Atomic.UIInlineSelect();
- this.selects.push(select);
- select.id = String(i + 1);
- select.fontDescription = AttributeInfoEdit.fontDesc;
- select.skinBg = "InspectorVectorAttrName";
- select.setLimits(-10000000, 10000000);
- if (this.numElements != 4) {
- var editlp = new Atomic.UILayoutParams();
- editlp.minWidth = 60;
- select.editFieldLayoutParams = editlp;
- }
- select.layoutParams = lp;
- layout.addChild(select);
- select["_edit"] = select.getWidget("edit");
- select["_dec"] = select.getWidget("dec");
- select["_inc"] = select.getWidget("inc");
- select.subscribeToEvent(select, "WidgetEvent", (ev) => this.handleWidgetEvent(ev));
- select.subscribeToEvent(select, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
- }
- this.editWidget = layout;
- }
- refresh() {
- for (var i = 0; i < this.selects.length; i++) {
- var select = this.selects[i];
- if (select["_edit"].focus || select["_dec"].captured || select["_inc"].captured)
- continue;
- var uniform = this.editType.getUniformValue(this.attrInfo, i);
- if (uniform) {
- var object = this.editType.getFirstObject();
- if (object) {
- var value = object.getAttribute(this.attrInfo.name);
- select.value = parseFloat(value[i].toFixed(5));
- }
- } else {
- select["_edit"].text = "--";
- }
- }
- }
- handleUIWidgetEditCompleteEvent(ev: Atomic.UIWidgetEditCompleteEvent) {
- var index = Number(ev.widget.id) - 1;
- this.editType.onAttributeInfoEdited(this.attrInfo, ev.widget.value, index);
- this.refresh();
- }
- handleWidgetEvent(ev: Atomic.UIWidgetEvent): boolean {
- if (ev.type == Atomic.UI_EVENT_TYPE_CHANGED) {
- var captured = false;
- for (var i in this.selects) {
- var select = this.selects[i];
- if (select["_dec"].captured || select["_inc"].captured) {
- captured = true;
- break;
- }
- }
- if (captured) {
- var index = Number(ev.target.id) - 1;
- this.editType.onAttributeInfoEdited(this.attrInfo, ev.target.value, index, false);
- }
- return true;
- }
- return false;
- }
- }
- class Vector2AttributeEdit extends NumberArrayAttributeEdit {
- constructor() {
- super(2);
- }
- }
- class Vector3AttributeEdit extends NumberArrayAttributeEdit {
- constructor() {
- super(3);
- }
- }
- class QuaternionAttributeEdit extends NumberArrayAttributeEdit {
- constructor() {
- super(3);
- }
- }
- class ColorAttributeEdit extends NumberArrayAttributeEdit {
- constructor() {
- super(4);
- }
- }
- class ResourceRefAttributeEdit extends AttributeInfoEdit {
- refListIndex: number;
- editField: Atomic.UIEditField;
- constructor(refListIndex: number = -1) {
- super();
- this.refListIndex = refListIndex;
- }
- onResourceChanged(resource: Atomic.Resource) {
- var parent = this.parent;
- while (parent) {
- if (parent.typeName == "UISection") {
- break;
- }
- parent = parent.parent;
- }
- if (parent) {
- parent.sendEvent("AttributeEditResourceChanged", { attrInfoEdit: this, resource: resource });
- }
- }
- initialize(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): boolean {
- if (!attrInfo.resourceTypeName)
- return false;
- if (this.refListIndex >= 0)
- this.nameOverride = attrInfo.resourceTypeName + " " + this.refListIndex;
- var importerName = ToolCore.assetDatabase.getResourceImporterName(attrInfo.resourceTypeName);
- if (!importerName)
- return false;
- return super.initialize(editType, attrInfo);
- }
- refresh() {
- var uniform = this.editType.getUniformValue(this.attrInfo, this.refListIndex);
- if (uniform) {
- var object = this.editType.getFirstObject();
- if (object) {
- // for cached resources, use the asset name, otherwise use the resource path name
- var resource: Atomic.Resource;
- if (this.refListIndex != -1) {
- resource = object.getAttribute(this.attrInfo.name).resources[this.refListIndex];
- } else {
- resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name);
- }
- var text = "";
- if (resource) {
- if (resource instanceof Atomic.Animation) {
- text = (<Atomic.Animation>resource).animationName;
- } else {
- text = resource.name;
- var asset = ToolCore.assetDatabase.getAssetByCachePath(resource.name);
- if (asset)
- text = asset.name;
- }
- }
- this.editField.text = text;
- this.editField.subscribeToEvent(this.editField, "WidgetEvent", (ev: Atomic.UIWidgetEvent) => {
- if (ev.type == Atomic.UI_EVENT_TYPE_POINTER_DOWN) {
- resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name);
- if (resource instanceof Atomic.JSComponentFile) {
- var pathName = resource.name;
- this.sendEvent(EditorEvents.InspectorProjectReference, { "path": pathName });
- } else if (resource instanceof Atomic.Model) {
- var asset = ToolCore.assetDatabase.getAssetByCachePath(resource.name);
- this.sendEvent(EditorEvents.InspectorProjectReference, { "path": asset.getRelativePath() });
- } else if (resource instanceof Atomic.Animation) {
- var animCacheReferenceName = resource.name.replace("_"+(<Atomic.Animation>resource).animationName, "");
- var asset = ToolCore.assetDatabase.getAssetByCachePath(animCacheReferenceName);
- this.sendEvent(EditorEvents.InspectorProjectReference, { "path": asset.getRelativePath() });
- } else {
- //Unknown Resource
- }
- }
- });
- }
- } else {
- this.editField.text = "--";
- }
- }
- createEditWidget() {
- var layout = new Atomic.UILayout();
- var o = InspectorUtils.createAttrEditFieldWithSelectButton("", layout);
- this.editField = o.editField;
- layout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
- layout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
- layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
- var lp = new Atomic.UILayoutParams();
- lp.width = 140;
- lp.height = 24;
- o.editField.layoutParams = lp;
- o.editField.readOnly = true;
- this.editWidget = layout;
- var selectButton = o.selectButton;
- var resourceTypeName = this.attrInfo.resourceTypeName;
- var importerName = ToolCore.assetDatabase.getResourceImporterName(resourceTypeName);
- selectButton.onClick = () => {
- EditorUI.getModelOps().showResourceSelection("Select " + resourceTypeName + " Resource", importerName, resourceTypeName, function(retObject: any) {
- var resource: Atomic.Resource = null;
- if (retObject instanceof ToolCore.Asset) {
- resource = (<ToolCore.Asset>retObject).getResource(resourceTypeName);
- } else if (retObject instanceof Atomic.Resource) {
- resource = <Atomic.Resource>retObject;
- }
- this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex);
- this.onResourceChanged(resource);
- this.refresh();
- }.bind(this));
- };
- // handle dropping of component on field
- this.editField.subscribeToEvent(this.editField, "DragEnded", (ev: Atomic.DragEndedEvent) => {
- if (ev.target == o.editField) {
- var dragObject = ev.dragObject;
- var importer;
- if (dragObject.object && dragObject.object.typeName == "Asset") {
- var asset = <ToolCore.Asset>dragObject.object;
- if (asset.importerTypeName == importerName) {
- importer = asset.importer;
- }
- }
- if (importer) {
- var resource = asset.getResource(resourceTypeName);
- this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex);
- this.onResourceChanged(resource);
- this.refresh();
- }
- }
- });
- }
- }
- class ResourceRefListAttributeEdit extends AttributeInfoEdit {
- layout: Atomic.UILayout;
- refEdits: ResourceRefAttributeEdit[] = [];
- sizeEdit: Atomic.UIEditField;
- initialize(editType: SerializableEditType, attrInfo: Atomic.AttributeInfo): boolean {
- return super.initialize(editType, attrInfo);
- }
- createRefEdit(index: number) {
- var refEdit = new ResourceRefAttributeEdit(index);
- refEdit.initialize(this.editType, this.attrInfo);
- this.layout.addChild(refEdit);
- this.refEdits.push(refEdit);
- }
- createEditWidget() {
- this.spacing = 0;
- var layout = this.layout = new Atomic.UILayout();
- layout.axis = Atomic.UI_AXIS_Y;
- layout.spacing = 2;
- layout.layoutSize = Atomic.UI_LAYOUT_SIZE_AVAILABLE;
- layout.gravity = Atomic.UI_GRAVITY_LEFT_RIGHT;
- layout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP;
- layout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_GRAVITY;
- var lp = new Atomic.UILayoutParams();
- lp.width = 304;
- layout.layoutParams = lp;
- var name = this.attrInfo.name + " Size";
- if (name == "AnimationResources Size")
- name = "Animations";
- var sizeEdit = this.sizeEdit = InspectorUtils.createAttrEditField(name, layout);
- lp = new Atomic.UILayoutParams();
- lp.width = 160;
- sizeEdit.layoutParams = lp;
- sizeEdit.subscribeToEvent(sizeEdit, "UIWidgetEditComplete", (ev) => this.handleUIWidgetEditCompleteEvent(ev));
- this.editWidget = layout;
- }
- createLayout() {
- this.createEditWidget();
- this.editWidget.subscribeToEvent(this.editWidget, "WidgetEvent", (data) => this.handleWidgetEvent(data));
- this.addChild(this.editWidget);
- }
- handleUIWidgetEditCompleteEvent(ev) {
- var size = Number(this.sizeEdit.text);
- if (size > 64 || size < 0)
- return;
- var editType = this.editType;
- var refresh = false;
- for (var i in editType.objects) {
- var object = editType.objects[i];
- var value = object.getAttribute(this.attrInfo.name);
- if (value.resources.length > size) {
- value.resources.length = size;
- object.setAttribute(this.attrInfo.name, value);
- refresh = true;
- } else if (value.resources.length < size) {
- for (var j = value.resources.length; j < size; j++) {
- value.resources.push(null);
- }
- object.setAttribute(this.attrInfo.name, value);
- refresh = true;
- }
- }
- if (refresh)
- this.refresh();
- }
- refresh() {
- var editType = this.editType;
- var object = this.editType.getFirstObject();
- if (!object) {
- this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
- return;
- }
- this.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
- var maxLength = -1;
- var i;
- for (i in editType.objects) {
- object = editType.objects[i];
- var value = object.getAttribute(this.attrInfo.name);
- if (value.resources.length > maxLength) {
- maxLength = value.resources.length;
- }
- }
- this.sizeEdit.text = maxLength.toString();
- if (maxLength == -1) {
- this.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
- return;
- }
- for (i = this.refEdits.length; i < maxLength; i++) {
- this.createRefEdit(i);
- }
- for (i = 0; i < this.refEdits.length; i++) {
- var refEdit = this.refEdits[i];
- if (i < maxLength) {
- refEdit.visibility = Atomic.UI_WIDGET_VISIBILITY_VISIBLE;
- refEdit.refresh();
- }
- else {
- refEdit.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
- }
- }
- }
- }
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_BOOL] = BoolAttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_INT] = IntAttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_FLOAT] = FloatAttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_STRING] = StringAttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_VECTOR2] = Vector2AttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_VECTOR3] = Vector3AttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_QUATERNION] = QuaternionAttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_COLOR] = ColorAttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_RESOURCEREF] = ResourceRefAttributeEdit;
- AttributeInfoEdit.standardAttrEditTypes[Atomic.VAR_RESOURCEREFLIST] = ResourceRefListAttributeEdit;
- export = AttributeInfoEdit;
|