public override void DrawGroupRow(AttributeData data, int index, bool drawAdvanced)
        {
            float lineHeight = EditorGUIUtility.singleLineHeight + 2;
            Rect  original   = this.fullRect;

            this.operatorOverride = null;
            this.SetupAreas(this.fullRect.AddY(lineHeight).Scale(0.48f, 1));
            this.labelRect = this.labelRect.SetWidth(1);
            this.valueRect = this.fullRect.Add(this.labelRect.width, 0, -labelRect.width, 0);
            if (data.usage == AttributeUsage.Direct)
            {
                data.usage = AttributeUsage.Shaped;
            }
            this.attribute.canDirect = false;
            this.DrawFormulaPart(data, index);
            if (GUI.changed)
            {
                this.dirty  = true;
                GUI.changed = false;
            }
            int dataIndex = this.attribute.data.IndexOf(data);

            AttributeData[] dataB = this.attribute.info.dataB;
            this.SetupAreas(this.fullRect.AddX(this.fullRect.width + 3));
            this.labelRect            = this.labelRect.SetWidth(1);
            this.valueRect            = this.fullRect.Add(this.labelRect.width, 0, -labelRect.width, 0);
            this.activeDataset        = dataB;
            this.attribute.defaultSet = "B";
            if (dataIndex < dataB.Length && dataB[dataIndex] != null)
            {
                string dataType    = data.GetType().Name.Remove("Data", "Attribute").Replace("Int", "Number").Replace("Float", "Number");
                string compareType = dataB[dataIndex].GetType().Name.Remove("Data", "Attribute").Replace("Int", "Number").Replace("Float", "Number");
                if (!AttributeBool.comparers.ContainsKey(dataType + compareType))
                {
                    string warning = "Cannot compare <b>" + dataType + "</b> and <b>" + compareType + "</b>.";
                    if (this.valueRect.Clicked(0) || this.valueRect.Clicked(1))
                    {
                        this.DrawTypeMenu(dataB[dataIndex]);
                    }
                    warning.Draw(this.valueRect, "", this.skin.GetStyle("WarningLabel"));
                }
                else
                {
                    this.operatorOverride = AttributeBool.comparers[dataType + compareType].ToList();
                    if (AttributeBool.comparers.ContainsKey(dataType + compareType))
                    {
                        this.attribute.canDirect = true;
                        this.DrawFormulaPart(dataB[dataIndex], index + 1);
                    }
                }
            }
            else if (GUI.Button(this.valueRect.SetWidth(120), "Add Comparison"))
            {
                this.DrawAddMenu();
            }
            this.attribute.defaultSet  = "A";
            this.activeDataset         = this.attribute.info.data;
            this.fullRect              = original.AddY(lineHeight);
            this.drawer.overallHeight += lineHeight;
        }
Esempio n. 2
0
        public virtual void DrawOperator(Rect area, AttributeData data, bool disabled = false)
        {
            Rect operatorRect = area.Add(18, 0, 0, 0).SetWidth(50);

            EditorGUIUtility.AddCursorRect(operatorRect, MouseCursor.Arrow);
            GUIStyle style = new GUIStyle(EditorStyles.popup);

            style.alignment     = TextAnchor.MiddleRight;
            style.contentOffset = new Vector2(-3, 0);
            style.fontStyle     = FontStyle.Bold;
            List <string> operatorList = new List <string>();

            if (disabled)
            {
                GUI.enabled = false;
                operatorList.Add("=");
                operatorList.Draw(operatorRect, 0, "", style);
                GUI.enabled = true;
                return;
            }
            operatorList = this.operatorOverride;
            if (operatorList == null)
            {
                var operatorCollection = typeof(AttributeType).GetVariable <Dictionary <Type, string[]> >("operators");
                operatorList = operatorCollection[data.GetType()].ToList();
            }
            int operatorIndex = Mathf.Clamp(data.operation, 0, operatorList.Count - 1);

            data.operation = operatorList.Draw(operatorRect, operatorIndex, "", style);
        }
Esempio n. 3
0
        public virtual void DrawTypeMenu(AttributeData data, GenericMenu menu = null)
        {
            bool openMenu = menu == null;

            menu = menu ?? new GenericMenu();
            Type[] types = this.attribute.GetFormulaTypes();
            if (types.Length > 0)
            {
                int index = this.activeDataset.IndexOf(data);
                foreach (Type attributeType in types)
                {
                    Type         type     = attributeType;
                    string       name     = type.Name.Remove("Attribute", "Data");
                    string       set      = this.attribute.defaultSet;
                    MenuFunction swapType = () => { this.SwapType(index, type, set); };
                    menu.AddItem(new GUIContent("Type/" + name), (data.GetType() == type), swapType);
                }
            }
            if (openMenu)
            {
                menu.ShowAsContext();
            }
        }
Esempio n. 4
0
        public virtual void DrawShaped(Rect area, AttributeData data, GUIContent label, bool?drawSpecial = null, bool?drawOperator = null)
        {
            label.ToLabel().DrawLabel(this.labelRect);
            Rect toggleRect   = area.SetWidth(16);
            bool toggleActive = this.targetMode.ContainsKey(data) ? this.targetMode[data] : !data.referenceID.IsEmpty();

            this.targetMode[data] = toggleActive.Draw(toggleRect, "", this.skin.GetStyle("CheckmarkToggle"));
            if (!this.targetMode[data])
            {
                Rect targetRect = area.Add(18, 0, -18, 0);
                bool ticked     = GUI.changed;
                TargetDrawer.Draw(targetRect, data.target, new GUIContent(""));
                if (this.attribute is AttributeGameObject && !ticked && GUI.changed)
                {
                    data.referenceID   = "";
                    data.referencePath = "";
                    data.reference     = null;
                }
                return;
            }
            List <string> attributeNames = new List <string>();
            List <string> attributeIDs   = new List <string>();
            int           attributeIndex = -1;
            GameObject    targetScope    = data.target.Get();

            if (!targetScope.IsNull() && Attribute.lookup.ContainsKey(targetScope))
            {
                var lookup = Attribute.lookup[targetScope];
                foreach (var item in lookup)
                {
                    if (item.Value.data.Length < 1)
                    {
                        continue;
                    }
                    if (item.Value.info.type != data.GetType())
                    {
                        continue;
                    }
                    bool isSelf = (item.Value.info.id == this.attribute.info.id) || (item.Value.data[0].referenceID == this.attribute.info.id);
                    if (!isSelf)
                    {
                        attributeNames.Add(item.Value.info.path);
                    }
                }
                if (attributeNames.Count != this.attributeNames.AddNew(data).Count)
                {
                    this.attributeNames[data] = attributeNames.Order().OrderBy(item => item.Contains("/")).ToList();
                }
                foreach (string name in this.attributeNames[data])
                {
                    var attribute = lookup.Values.ToList().Find(x => x.info.path == name);
                    if (attribute != null)
                    {
                        attributeIDs.Add(attribute.info.id);
                    }
                }
                if (!data.referenceID.IsEmpty())
                {
                    attributeIndex = attributeIDs.IndexOf(data.referenceID);
                }
            }
            else
            {
                this.attributeNames.Clear();
            }
            if (this.attributeNames.Count > 0)
            {
                Rect line        = area;
                bool showSpecial = drawSpecial != null && (EditorPref.Get <bool>(data.path + "Advanced") || data.special != 0);
                if (attributeIndex == -1)
                {
                    string message = data.referenceID.IsEmpty() ? "[Not Set]" : "[Missing] " + data.referencePath;
                    attributeIndex = 0;
                    this.attributeNames[data].Insert(0, message);
                    attributeIDs.Insert(0, "0");
                }
                if (drawOperator != null)
                {
                    this.DrawOperator(line, data, (bool)!drawOperator);
                    line = line.Add(51, 0, -51, 0);
                }
                if (showSpecial)
                {
                    this.DrawSpecial(line, data);
                    line = line.Add(51, 0, -51, 0);
                }
                Rect attributeRect = line.Add(18, 0, -18, 0);
                int  previousIndex = attributeIndex;
                attributeIndex = this.attributeNames[data].Draw(attributeRect, attributeIndex);
                string name = this.attributeNames[data][attributeIndex];
                string id   = attributeIDs[attributeIndex];
                if (attributeIndex != previousIndex)
                {
                    data.referencePath = name;
                    data.referenceID   = id;
                    data.reference     = Attribute.lookup[targetScope][data.referenceID];
                }
            }
            else
            {
                Rect   warningRect = area.Add(18, 0, -18, 0);
                string targetName  = targetScope.IsNull() ? "Target" : targetScope.ToString().Remove("(UnityEngine.GameObject)").Trim();
                string typeName    = data.GetType().Name.Trim("Attribute", "Data");
                string message     = "<b>" + targetName.Truncate(24) + "</b> has no <b>" + typeName + "</b> attributes.";
                message.ToLabel().DrawLabel(warningRect, this.skin.GetStyle("WarningLabel"));
            }
        }