Example #1
0
 protected override void ColumnHeaderGUI(MultiColumnHeaderState.Column column, Rect headerRect, int columnIndex)
 {
     if (columnIndex == 0)
     {
         var newAllSettingsToggle = GUI.Toggle(new Rect(0, 3, 18, 18), allSettingsToggle, "");
         if (allSettingsToggle != newAllSettingsToggle)
         {
             OnSelectAllSettingsClicked?.Invoke(newAllSettingsToggle);
         }
     }
     else
     {
         base.ColumnHeaderGUI(column, headerRect, columnIndex);
     }
 }
Example #2
0
        protected override void ColumnHeaderGUI(MultiColumnHeaderState.Column column, Rect headerRect, int columnIndex)
        {
            var ruleVariants = (JArray)rule["value"];

            if (columnIndex == 0)
            {
                var allSettingsToggle    = GetAllSettingsToggleState();
                var newAllSettingsToggle = GUI.Toggle(new Rect(0, 3, 18, 18), allSettingsToggle, "");
                if (allSettingsToggle != newAllSettingsToggle)
                {
                    OnSelectAllSettingsClicked?.Invoke(newAllSettingsToggle);
                }
            }
            if (columnIndex > 2 && columnIndex != state.columns.Length - 1)
            {
                var guiStyle = new GUIStyle(GUI.skin.textField);
                guiStyle.alignment = TextAnchor.LowerLeft;
                //override the rendering of column two for now
                var variantNameRect  = new Rect(headerRect.x, headerRect.y + headerRect.height - 24f, headerRect.width * 0.6f, 22f);
                var variantAllocRect = new Rect(headerRect.x + variantNameRect.width, headerRect.y + headerRect.height - 24f, (headerRect.width * 0.2f) - 1f, 22f);

                var variant        = (JObject)((JArray)rule["value"])[columnIndex - 3];
                var variantName    = variant["id"].Value <string>();
                var newVariantName = EditorGUI.TextField(variantNameRect, variantName, guiStyle);

                int    variantWeightInt;
                string variantWeight;
                if (string.IsNullOrEmpty(variant["weight"].ToString()))
                {
                    variantWeight = null;
                }
                else if (Int32.TryParse(variant["weight"].ToString(), out variantWeightInt))
                {
                    variantWeight = variantWeightInt.ToString();
                }
                else
                {
                    variantWeight = null;
                }

                var newVariantWeight = EditorGUI.TextField(variantAllocRect, variantWeight, guiStyle);

                EditorGUI.BeginDisabledGroup(ruleVariants.Count == 1);
                if (GUI.Button(new Rect(headerRect.x + variantNameRect.width + variantAllocRect.width, headerRect.y + headerRect.height - 24f, headerRect.width * 0.2f - 1f, 22f),
                               new GUIContent("X", m_variantWeightTooltip)))
                {
                    OnDeleteVariant?.Invoke(variantName);
                }
                EditorGUI.EndDisabledGroup();
                int newVariantWeightInt;
                if (Int32.TryParse(newVariantWeight, out newVariantWeightInt) || string.IsNullOrEmpty(newVariantWeight))
                {
                    if (newVariantName != variantName || newVariantWeight != variantWeight)
                    {
                        var newVariant = (JObject)variant.DeepClone();
                        newVariant["id"] = newVariantName;
                        if (string.IsNullOrEmpty(newVariantWeight))
                        {
                            newVariant["weight"] = null;
                        }
                        else
                        {
                            newVariant["weight"] = newVariantWeightInt;
                        }

                        OnVariantUpdated?.Invoke(variant, newVariant);
                    }
                }
            }
            else if (columnIndex == state.columns.Length - 1)
            {
                var addVariantBtnRect = new Rect(headerRect.x, headerRect.y + 2, headerRect.width, 22f);
                if (GUI.Button(addVariantBtnRect, new GUIContent("Add Variant", m_variantWeightTooltip)))
                {
                    OnAddVariantClicked?.Invoke();
                }
            }
            else
            {
                base.ColumnHeaderGUI(column, headerRect, columnIndex);
            }
        }