Exemplo n.º 1
0
    private void RemoveField(string schemaKey, Dictionary <string, object> schemaData, string deletedFieldKey)
    {
        newListCountDict.Remove(string.Format(GDEConstants.MetaDataFormat, schemaKey, deletedFieldKey));
        GDEItemManager.RemoveFieldFromSchema(schemaKey, schemaData, deletedFieldKey);

        SetNeedToSave(true);
    }
    protected override bool Create(object data)
    {
        bool          result    = true;
        List <object> args      = data as List <object>;
        string        schemaKey = args[0] as string;
        string        itemName  = args[1] as string;

        Dictionary <string, object> schemaData = null;

        if (GDEItemManager.AllSchemas.TryGetValue(schemaKey, out schemaData))
        {
            Dictionary <string, object> itemData = schemaData.DeepCopy();
            itemData.Add(GDEConstants.SchemaKey, schemaKey);

            string error;
            if (GDEItemManager.AddItem(itemName, itemData, out error))
            {
                SetFoldout(true, itemName);
                SetNeedToSave(true);
            }
            else
            {
                result = false;
                EditorUtility.DisplayDialog(GDEStrings.ErrorCreatingItem, error, GDEStrings.OkLbl);
            }
        }
        else
        {
            result = false;
            EditorUtility.DisplayDialog(GDEStrings.ErrorLbl, GDEStrings.SchemaNotFound + ": " + schemaKey, GDEStrings.OkLbl);
        }

        return(result);
    }
    protected override float CalculateGroupHeightsTotal()
    {
        float  totalHeight  = 0;
        float  schemaHeight = 0;
        string schema       = "";

        foreach (KeyValuePair <string, float> pair in groupHeights)
        {
            Dictionary <string, object> itemData;
            GDEItemManager.AllItems.TryGetValue(pair.Key, out itemData);
            if (ShouldFilter(pair.Key, itemData))
            {
                continue;
            }

            //Check to see if this item's height has been updated
            //otherwise use the min height for the schema
            if (entryFoldoutState.Contains(pair.Key) && pair.Value.NearlyEqual(GDEConstants.LineHeight))
            {
                schema = GDEItemManager.GetSchemaForItem(pair.Key);
                groupHeightBySchema.TryGetValue(schema, out schemaHeight);
                totalHeight += schemaHeight;
            }
            else
            {
                totalHeight += pair.Value;
            }
        }

        return(totalHeight);
    }
 void OnFocus()
 {
     if (GDEItemManager.AllItems.Count.Equals(0) && GDEItemManager.AllSchemas.Count.Equals(0))
     {
         GDEItemManager.Load();
     }
 }
Exemplo n.º 5
0
    public static void DoGenerateCustomExtensions()
    {
        GDEItemManager.Load();

        GDECodeGen.GenStaticKeysClass(GDEItemManager.AllSchemas);
        GDECodeGen.GenClasses(GDEItemManager.AllSchemas);

        AssetDatabase.Refresh();
    }
Exemplo n.º 6
0
    static void GDELoadData()
    {
        string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
        string fullPath  = Path.GetFullPath(assetPath);

        GDESettings.Instance.DataFilePath = fullPath;
        GDESettings.Instance.Save();

        GDEItemManager.Load(true);
    }
Exemplo n.º 7
0
    static void LoadDefaults()
    {
        dataFilePath = GDESettings.DefaultDataFilePath;
        GDEItemManager.CreateFileIfMissing(dataFilePath);

        createDataColor = defaultCreateDataColor.ToColor();
        defineDataColor = defaultDefineDataColor.ToColor();
        highlightColor  = GDEConstants.HighlightColor.ToColor();

        GUI.FocusControl(string.Empty);
    }
Exemplo n.º 8
0
    protected override float CalculateGroupHeightsTotal()
    {
        if (!shouldRecalculateHeights)
        {
            return(currentGroupHeightTotal);
        }

        currentGroupHeightTotal = 0;
        float  itemHeight   = 0;
        float  schemaHeight = 0;
        string schema       = string.Empty;

        foreach (var item in entriesToDraw)
        {
            groupHeights.TryGetValue(item.Key, out itemHeight);
            if (itemHeight < GDEConstants.LineHeight)
            {
                itemHeight = GDEConstants.LineHeight;
                SetGroupHeight(item.Key, itemHeight);
            }

            //Check to see if this item's height has been updated
            //otherwise use the min height for the schema
            if (entryFoldoutState.Contains(item.Key) && itemHeight.NearlyEqual(GDEConstants.LineHeight))
            {
                schema = GDEItemManager.GetSchemaForItem(item.Key);
                groupHeightBySchema.TryGetValue(schema, out schemaHeight);

                // Only use the schema height if its greater than
                // the default item height
                if (schemaHeight > itemHeight)
                {
                    currentGroupHeightTotal += schemaHeight;
                    SetGroupHeight(item.Key, schemaHeight);
                }
                else
                {
                    currentGroupHeightTotal += itemHeight;
                }
            }
            else
            {
                currentGroupHeightTotal += itemHeight;
            }
        }

        shouldRecalculateHeights = false;

        return(currentGroupHeightTotal);
    }
    protected virtual void Load()
    {
        GDEItemManager.Load();

        entryFoldoutState.Clear();
        listFieldFoldoutState.Clear();
        currentFoldoutAllState = false;
        newListCountDict.Clear();
        filterText = "";
        groupHeights.Clear();
        groupHeightBySchema.Clear();
        editingFields.Clear();
        editFieldTextDict.Clear();
    }
Exemplo n.º 10
0
    protected override bool ShouldFilter(string schemaKey, Dictionary <string, object> schemaData)
    {
        bool schemaKeyMatch = schemaKey.ToLower().Contains(filterText.ToLower());
        bool fieldKeyMatch  = !GDEItemManager.ShouldFilterByField(schemaKey, filterText);

        // Return if the schema keys don't contain the filter text or
        // if the schema fields don't contain the filter text
        if (!schemaKeyMatch && !fieldKeyMatch)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 11
0
    private bool AddCustomField(string customType, string schemaKey, Dictionary <string, object> schemaData, string newFieldName, bool isList)
    {
        bool   result = true;
        string error;

        if (GDEItemManager.AddCustomFieldToSchema(customType, schemaKey, schemaData, newFieldName, isList, out error))
        {
            SetNeedToSave(true);
        }
        else
        {
            EditorUtility.DisplayDialog(GDEStrings.ErrorCreatingField, error, GDEStrings.OkLbl);
            result = false;
        }

        return(result);
    }
Exemplo n.º 12
0
    static void SavePreferences()
    {
        GDESettings settings = GDESettings.Instance;

        settings.CreateDataColor = createDataColor.ToHexString();
        settings.DefineDataColor = defineDataColor.ToHexString();
        settings.HighlightColor  = highlightColor.ToHexString();
        settings.DataFilePath    = dataFilePath;

        if (File.Exists(dataFilePath))
        {
            GDEItemManager.Load(true);
            GUI.FocusControl(string.Empty);
        }

        settings.Save();
    }
Exemplo n.º 13
0
    private bool AddBasicField(BasicFieldType type, string schemaKey, Dictionary <string, object> schemaData, string newFieldName, bool isList)
    {
        bool   result       = true;
        object defaultValue = GetDefaultValueForType(type);
        string error;

        if (GDEItemManager.AddBasicFieldToSchema(type, schemaKey, schemaData, newFieldName, out error, isList, defaultValue))
        {
            SetNeedToSave(true);
        }
        else
        {
            EditorUtility.DisplayDialog(GDEStrings.ErrorCreatingField, error, GDEStrings.OkLbl);
            result = false;
        }

        return(result);
    }
Exemplo n.º 14
0
    protected override void Remove(string key)
    {
        // Show a warning if we have items using this schema
        List <string> items        = GDEItemManager.GetItemsOfSchemaType(key);
        bool          shouldDelete = true;

        if (items != null && items.Count > 0)
        {
            string itemWord = items.Count == 1 ? "item" : "items";
            shouldDelete = EditorUtility.DisplayDialog(string.Format("{0} {1} will be deleted!", items.Count, itemWord), GDEStrings.SureDeleteSchema, GDEStrings.DeleteSchemaBtn, GDEStrings.CancelBtn);
        }

        if (shouldDelete)
        {
            GDEItemManager.RemoveSchema(key, true);
            SetNeedToSave(true);
        }
    }
Exemplo n.º 15
0
    void SavePreferences()
    {
        EditorPrefs.SetString(GDEConstants.CreateDataColorKey, "#" + createDataColor.ToHexString());
        EditorPrefs.SetString(GDEConstants.DefineDataColorKey, "#" + defineDataColor.ToHexString());
        EditorPrefs.SetString(GDEConstants.HighlightColorKey, "#" + highlightColor.ToHexString());

        string dataFileDirectory = dataFilePath.Replace(Path.GetFileName(dataFilePath), "");

        if (Directory.Exists(dataFileDirectory))
        {
            EditorPrefs.SetString(GDEConstants.DataFileKey, dataFilePath);
            GDEItemManager.Load(true);
            GUI.FocusControl("");
        }
        else
        {
            EditorUtility.DisplayDialog(GDEStrings.ErrorLbl, string.Format(GDEStrings.DirectoryNotFound, dataFileDirectory), GDEStrings.OkLbl);
        }
    }
Exemplo n.º 16
0
    protected override bool Create(object data)
    {
        bool   result = true;
        string key    = data as string;
        string error;

        result = GDEItemManager.AddSchema(key, new Dictionary <string, object>(), out error);
        if (result)
        {
            SetNeedToSave(true);
            SetFoldout(true, key);
        }
        else
        {
            EditorUtility.DisplayDialog(GDEStrings.ErrorCreatingSchema, error, GDEStrings.OkLbl);
            result = false;
        }

        return(result);
    }
Exemplo n.º 17
0
    protected override bool Clone(string key)
    {
        bool   result = true;
        string error;
        string newKey;

        result = GDEItemManager.CloneItem(key, out newKey, out error);
        if (result)
        {
            SetNeedToSave(true);
            SetFoldout(true, newKey);

            HighlightNew(newKey);
        }
        else
        {
            EditorUtility.DisplayDialog(GDEConstants.ErrorCloningItem, error, GDEConstants.OkLbl);
            result = false;
        }

        return(result);
    }
Exemplo n.º 18
0
    protected override bool ShouldFilter(string itemKey, Dictionary <string, object> itemData)
    {
        if (itemData == null)
        {
            return(true);
        }

        string schemaType = "<unknown>";

        itemData.TryGetString(GDMConstants.SchemaKey, out schemaType);

        // Return if we don't match any of the filter types
        if (GDEItemManager.FilterSchemaKeyArray.IsValidIndex(filterSchemaIndex) &&
            !GDEItemManager.FilterSchemaKeyArray[filterSchemaIndex].Equals(GDEConstants._AllLbl) &&
            !schemaType.Equals(GDEItemManager.FilterSchemaKeyArray[filterSchemaIndex]))
        {
            return(true);
        }
        else if (!GDEItemManager.FilterSchemaKeyArray[filterSchemaIndex].Equals(GDEConstants._AllLbl) &&
                 schemaType.Equals(GDEItemManager.FilterSchemaKeyArray[filterSchemaIndex]) &&
                 string.IsNullOrEmpty(filterText))
        {
            return(false);
        }

        bool schemaKeyMatch = schemaType.ToLower().Contains(filterText.ToLower());
        bool fieldKeyMatch  = !GDEItemManager.ShouldFilterByField(schemaType, filterText);
        bool itemKeyMatch   = itemKey.ToLower().Contains(filterText.ToLower());

        // Return if the schema keys don't contain the filter text or
        // if the schema fields don't contain the filter text
        if (!schemaKeyMatch && !fieldKeyMatch && !itemKeyMatch)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 19
0
    protected override void DrawEntry(string schemaKey, Dictionary <string, object> schemaData)
    {
        float beginningHeight = CurrentHeight();

        // Start drawing below
        if (DrawFoldout(GDEStrings.SchemaLbl + " ", schemaKey, schemaKey, schemaKey, RenameSchema))
        {
            bool shouldDrawSpace        = false;
            bool didDrawSpaceForSection = false;

            // Draw the basic types
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString());
                foreach (string fieldKey in fieldKeys)
                {
                    currentLinePosition += GDEConstants.Indent;
                    DrawSingleField(schemaKey, fieldKey, schemaData);
                    shouldDrawSpace = true;
                }
            }

            // Draw the custom types
            foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey))
            {
                if (shouldDrawSpace && !didDrawSpaceForSection)
                {
                    NewLine(0.5f);
                    didDrawSpaceForSection = true;
                }

                currentLinePosition += GDEConstants.Indent;
                DrawSingleField(schemaKey, fieldKey, schemaData);
                shouldDrawSpace = true;
            }
            didDrawSpaceForSection = false;

            // Draw the lists
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.SchemaListFieldKeysOfType(schemaKey, fieldType.ToString());

                foreach (string fieldKey in fieldKeys)
                {
                    if (shouldDrawSpace && !didDrawSpaceForSection)
                    {
                        NewLine(0.5f);
                        didDrawSpaceForSection = true;
                    }

                    currentLinePosition += GDEConstants.Indent;
                    DrawListField(schemaKey, schemaData, fieldKey);
                    shouldDrawSpace = true;
                }
            }
            didDrawSpaceForSection = false;

            // Draw the custom lists
            foreach (string fieldKey in GDEItemManager.SchemaCustomListFields(schemaKey))
            {
                if (shouldDrawSpace && !didDrawSpaceForSection)
                {
                    NewLine(0.5f);
                    didDrawSpaceForSection = true;
                }

                currentLinePosition += GDEConstants.Indent;
                DrawListField(schemaKey, schemaData, fieldKey);
                shouldDrawSpace = true;
            }

            // Remove any fields that were deleted above
            foreach (string deletedKey in deletedFields)
            {
                RemoveField(schemaKey, schemaData, deletedKey);
            }
            deletedFields.Clear();

            // Rename any fields that were renamed
            string error;
            string oldFieldKey;
            string newFieldKey;
            foreach (KeyValuePair <List <string>, Dictionary <string, object> > pair in renamedFields)
            {
                oldFieldKey = pair.Key[0];
                newFieldKey = pair.Key[1];
                if (!GDEItemManager.RenameSchemaField(oldFieldKey, newFieldKey, schemaKey, pair.Value, out error))
                {
                    EditorUtility.DisplayDialog(GDEStrings.ErrorLbl, string.Format("Couldn't rename {0} to {1}: {2}", oldFieldKey, newFieldKey, error), GDEStrings.OkLbl);
                }
            }
            renamedFields.Clear();

            NewLine();

            DrawAddFieldSection(schemaKey, schemaData);

            NewLine(2f);

            GUIContent content = new GUIContent(GDEStrings.DeleteBtn);
            float      width   = GUI.skin.button.CalcSize(content).x;
            if (GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content))
            {
                deletedSchemas.Add(schemaKey);
            }

            NewLine();

            DrawSectionSeparator();

            NewLine(0.25f);
        }

        float groupHeight = CurrentHeight() - beginningHeight;

        SetGroupHeight(schemaKey, groupHeight);
    }
Exemplo n.º 20
0
    void DrawListField(string schemaKey, string itemKey, string fieldKey, Dictionary <string, object> itemData)
    {
        try
        {
            string foldoutKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            bool   newFoldoutState;
            bool   currentFoldoutState = listFieldFoldoutState.Contains(foldoutKey);
            object defaultResizeValue  = null;

            string fieldType;
            itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

            BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;
            if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
            {
                fieldTypeEnum      = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
                fieldType          = GDEItemManager.GetVariableTypeFor(fieldTypeEnum);
                defaultResizeValue = GDEItemManager.GetDefaultValueForType(fieldTypeEnum);
            }

            content.text = string.Format("List<{0}>", fieldType);
            drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.TypeSuffix, content, EditorStyles.foldout, out size);
            size.x          = Math.Max(size.x, GDEConstants.MinLabelWidth);
            newFoldoutState = EditorGUI.Foldout(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), currentFoldoutState, content);
            drawHelper.CurrentLinePosition += (size.x + 2);

            content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
            drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.LblSuffix, content, labelStyle, out size);
            size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);
            GUI.Label(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), fieldKey.HighlightSubstring(filterText, highlightColor), labelStyle);
            drawHelper.CurrentLinePosition += (size.x + 2);

            if (newFoldoutState != currentFoldoutState)
            {
                if (newFoldoutState)
                {
                    listFieldFoldoutState.Add(foldoutKey);
                }
                else
                {
                    listFieldFoldoutState.Remove(foldoutKey);
                }
            }

            object temp = null;
            IList  list = null;

            if (itemData.TryGetValue(fieldKey, out temp))
            {
                list = temp as IList;
            }

            content.text = GDEConstants.SizeLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeSizeLblKey, content, EditorStyles.label, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content);
            drawHelper.CurrentLinePosition += (size.x + 2);

            int    newListCount;
            string listCountKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            if (newListCountDict.ContainsKey(listCountKey))
            {
                newListCount = newListCountDict[listCountKey];
            }
            else
            {
                newListCount = list.Count;
                newListCountDict.Add(listCountKey, newListCount);
            }

            size.x       = 40;
            newListCount = EditorGUI.IntField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, drawHelper.StandardHeight()), newListCount);
            drawHelper.CurrentLinePosition += (size.x + 4);

            content.text = GDEConstants.ResizeBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeResizeBtnKey, content, GUI.skin.button, out size);
            newListCountDict[listCountKey] = newListCount;
            if (newListCount != list.Count && GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
            {
                ResizeList(list, newListCount, defaultResizeValue);
                newListCountDict[listCountKey]  = newListCount;
                drawHelper.CurrentLinePosition += (size.x + 2);
            }

            drawHelper.NewLine();

            if (newFoldoutState)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    drawHelper.CurrentLinePosition += GDEConstants.Indent * 2;
                    content.text = string.Format("[{0}]:", i);

                    switch (fieldTypeEnum)
                    {
                    case BasicFieldType.Bool:
                    {
                        DrawListBool(content, i, Convert.ToBoolean(list[i]), list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Int:
                    {
                        DrawListInt(content, i, Convert.ToInt32(list[i]), list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Float:
                    {
                        DrawListFloat(content, i, Convert.ToSingle(list[i]), list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.String:
                    {
                        DrawListString(content, i, list[i] as string, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Vector2:
                    {
                        DrawListVector2(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Vector3:
                    {
                        DrawListVector3(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Vector4:
                    {
                        DrawListVector4(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Color:
                    {
                        DrawListColor(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.GameObject:
                    {
                        DrawListObject <GameObject>(foldoutKey + i, content, i, list[i] as GameObject, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Texture2D:
                    {
                        DrawListObject <Texture2D>(foldoutKey + i, content, i, list[i] as Texture2D, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Material:
                    {
                        DrawListObject <Material>(foldoutKey + i, content, i, list[i] as Material, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.AudioClip:
                    {
                        DrawListAudio(foldoutKey + i, content, i, list[i] as AudioClip, list);
                        drawHelper.NewLine();
                        break;
                    }

                    default:
                    {
                        List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
                        DrawListCustom(content, i, list[i] as string, list, true, itemKeys);
                        drawHelper.NewLine();
                        break;
                    }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }
Exemplo n.º 21
0
    void Draw2DListField(string schemaKey, string itemKey, string fieldKey, Dictionary <string, object> itemData)
    {
        try
        {
            string foldoutKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            object defaultResizeValue;

            string fieldType;
            itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

            BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;
            if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
            {
                fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
                fieldType     = GDEItemManager.GetVariableTypeFor(fieldTypeEnum);
            }

            content.text = string.Format("List<List<{0}>>", fieldType);
            bool isOpen = DrawFoldout(content.text, foldoutKey, string.Empty, string.Empty, null);

            drawHelper.CurrentLinePosition = Math.Max(drawHelper.CurrentLinePosition, GDEConstants.MinLabelWidth + GDEConstants.Indent + 4);
            content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
            drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.LblSuffix, content, labelStyle, out size);

            size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), fieldKey.HighlightSubstring(filterText, highlightColor), labelStyle);
            drawHelper.CurrentLinePosition += (size.x + 2);

            object temp = null;
            IList  list = null;

            if (itemData.TryGetValue(fieldKey, out temp))
            {
                list = temp as IList;
            }

            content.text = GDEConstants.SizeLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeSizeLblKey, content, EditorStyles.label, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content);
            drawHelper.CurrentLinePosition += (size.x + 2);

            int    newListCount;
            string listCountKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            if (newListCountDict.ContainsKey(listCountKey))
            {
                newListCount = newListCountDict[listCountKey];
            }
            else
            {
                newListCount = list.Count;
                newListCountDict.Add(listCountKey, newListCount);
            }

            size.x       = 40;
            newListCount = EditorGUI.IntField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, drawHelper.StandardHeight()), newListCount);
            drawHelper.CurrentLinePosition += (size.x + 4);

            content.text = GDEConstants.ResizeBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeResizeBtnKey, content, GUI.skin.button, out size);
            newListCountDict[listCountKey] = newListCount;
            if (list != null && newListCount != list.Count && GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
            {
                if (GDEItemManager.IsUnityType(fieldTypeEnum))
                {
                    defaultResizeValue = Activator.CreateInstance(list.GetType().GetGenericArguments()[0]);
                }
                else
                {
                    defaultResizeValue = new List <object>();
                }

                ResizeList(list, newListCount, defaultResizeValue);
                newListCountDict[listCountKey]  = newListCount;
                drawHelper.CurrentLinePosition += (size.x + 2);
            }

            drawHelper.NewLine();

            if (isOpen)
            {
                defaultResizeValue = GDEItemManager.GetDefaultValueForType(fieldTypeEnum);
                for (int index = 0; index < list.Count; index++)
                {
                    IList subList = list[index] as IList;

                    drawHelper.CurrentLinePosition += GDEConstants.Indent * 2;
                    content.text = string.Format("[{0}]:    List<{1}>", index, fieldType);

                    isOpen = DrawFoldout(content.text, foldoutKey + "_" + index, string.Empty, string.Empty, null);
                    drawHelper.CurrentLinePosition += 4;

                    // Draw resize
                    content.text = GDEConstants.SizeLbl;
                    drawHelper.TryGetCachedSize(GDEConstants.SizeSizeLblKey, content, EditorStyles.label, out size);
                    EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content);
                    drawHelper.CurrentLinePosition += (size.x + 2);

                    listCountKey = string.Format(GDMConstants.MetaDataFormat, schemaKey, fieldKey) + "_" + index;
                    if (newListCountDict.ContainsKey(listCountKey))
                    {
                        newListCount = newListCountDict[listCountKey];
                    }
                    else
                    {
                        newListCount = subList.Count;
                        newListCountDict.Add(listCountKey, newListCount);
                    }

                    size.x       = 40;
                    newListCount = EditorGUI.IntField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, drawHelper.StandardHeight()), newListCount);
                    drawHelper.CurrentLinePosition += (size.x + 2);

                    newListCountDict[listCountKey] = newListCount;

                    content.text = GDEConstants.ResizeBtn;
                    drawHelper.TryGetCachedSize(GDEConstants.SizeResizeBtnKey, content, GUI.skin.button, out size);
                    if (newListCount != subList.Count)
                    {
                        if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
                        {
                            ResizeList(subList, newListCount, defaultResizeValue);
                        }
                        drawHelper.CurrentLinePosition += (size.x + 2);
                    }

                    drawHelper.NewLine();

                    if (isOpen)
                    {
                        for (int x = 0; x < subList.Count; x++)
                        {
                            drawHelper.CurrentLinePosition += GDEConstants.Indent * 3;
                            content.text = string.Format("[{0}][{1}]:", index, x);

                            switch (fieldTypeEnum)
                            {
                            case BasicFieldType.Bool:
                            {
                                DrawListBool(content, x, Convert.ToBoolean(subList[x]), subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Int:
                            {
                                DrawListInt(content, x, Convert.ToInt32(subList[x]), subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Float:
                            {
                                DrawListFloat(content, x, Convert.ToSingle(subList[x]), subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.String:
                            {
                                DrawListString(content, x, subList[x] as string, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Vector2:
                            {
                                DrawListVector2(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                                break;
                            }

                            case BasicFieldType.Vector3:
                            {
                                DrawListVector3(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                                break;
                            }

                            case BasicFieldType.Vector4:
                            {
                                DrawListVector4(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                                break;
                            }

                            case BasicFieldType.Color:
                            {
                                DrawListColor(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.GameObject:
                            {
                                DrawListObject <GameObject>(foldoutKey + index + "_" + x, content, x, subList[x] as GameObject, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Texture2D:
                            {
                                DrawListObject <Texture2D>(foldoutKey + index + "_" + x, content, x, subList[x] as Texture2D, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Material:
                            {
                                DrawListObject <Material>(foldoutKey + index + "_" + x, content, x, subList[x] as Material, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.AudioClip:
                            {
                                DrawListAudio(foldoutKey + index + "_" + x, content, x, subList[x] as AudioClip, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            default:
                            {
                                List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
                                DrawListCustom(content, x, subList[x] as string, subList, true, itemKeys);
                                drawHelper.NewLine();
                                break;
                            }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }
Exemplo n.º 22
0
    protected override void DrawEntry(string itemKey, Dictionary <string, object> data)
    {
        float  beginningHeight = drawHelper.CurrentHeight();
        string schemaType      = "<unknown>";
        object temp;

        if (data.TryGetValue(GDMConstants.SchemaKey, out temp))
        {
            schemaType = temp as string;
        }

        bool currentFoldoutState = entryFoldoutState.Contains(itemKey);

        // Start drawing below
        bool isOpen = DrawFoldout(schemaType + ":", itemKey, itemKey, itemKey, RenameItem);

        drawHelper.NewLine();

        if (isOpen)
        {
            bool shouldDrawSpace        = false;
            bool didDrawSpaceForSection = false;
            bool isFirstSection         = true;

            // Draw the basic types
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.ItemFieldKeysOfType(itemKey, fieldType.ToString(), 0);
                foreach (string fieldKey in fieldKeys)
                {
                    drawHelper.CurrentLinePosition += GDEConstants.Indent;
                    DrawSingleField(schemaType, itemKey, fieldKey, data);
                    shouldDrawSpace = true;
                    isFirstSection  = false;
                }
            }

            // Draw the custom types
            foreach (string fieldKey in GDEItemManager.ItemCustomFieldKeys(itemKey, 0))
            {
                if (shouldDrawSpace && !didDrawSpaceForSection && !isFirstSection)
                {
                    drawHelper.NewLine(0.5f);
                    didDrawSpaceForSection = true;
                }

                drawHelper.CurrentLinePosition += GDEConstants.Indent;
                DrawSingleField(schemaType, itemKey, fieldKey, data);
                shouldDrawSpace = true;
                isFirstSection  = false;
            }
            didDrawSpaceForSection = false;

            // Draw the basic lists
            for (int dimension = 1; dimension <= 2; dimension++)
            {
                foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
                {
                    List <string> fieldKeys = GDEItemManager.ItemFieldKeysOfType(itemKey, fieldType.ToString(), dimension);
                    foreach (string fieldKey in fieldKeys)
                    {
                        if (shouldDrawSpace && !didDrawSpaceForSection && !isFirstSection)
                        {
                            drawHelper.NewLine(0.5f);
                            didDrawSpaceForSection = true;
                        }

                        drawHelper.CurrentLinePosition += GDEConstants.Indent;

                        if (dimension == 1)
                        {
                            DrawListField(schemaType, itemKey, fieldKey, data);
                        }
                        else
                        {
                            Draw2DListField(schemaType, itemKey, fieldKey, data);
                        }

                        shouldDrawSpace        = true;
                        isFirstSection         = false;
                        didDrawSpaceForSection = true;
                    }
                }
                didDrawSpaceForSection = false;
            }

            // Draw the custom lists
            for (int dimension = 1; dimension <= 2; dimension++)
            {
                foreach (string fieldKey in GDEItemManager.ItemCustomFieldKeys(itemKey, dimension))
                {
                    if (shouldDrawSpace && !didDrawSpaceForSection && !isFirstSection)
                    {
                        drawHelper.NewLine(0.5f);
                        didDrawSpaceForSection = true;
                    }

                    drawHelper.CurrentLinePosition += GDEConstants.Indent;
                    if (dimension == 1)
                    {
                        DrawListField(schemaType, itemKey, fieldKey, data);
                    }
                    else
                    {
                        Draw2DListField(schemaType, itemKey, fieldKey, data);
                    }

                    shouldDrawSpace        = true;
                    isFirstSection         = false;
                    didDrawSpaceForSection = true;
                }
                didDrawSpaceForSection = false;
            }

            drawHelper.NewLine(0.5f);

            DrawEntryFooter(GDEConstants.CloneItem, GDEConstants.SizeCloneItemKey, itemKey);
        }
        else if (!isOpen && currentFoldoutState)
        {
            // Collapse any list foldouts as well
            List <string> listKeys = GDEItemManager.ItemListFieldKeys(itemKey);
            string        foldoutKey;
            foreach (string listKey in listKeys)
            {
                foldoutKey = string.Format(GDMConstants.MetaDataFormat, itemKey, listKey);
                listFieldFoldoutState.Remove(foldoutKey);
            }
        }

        float newGroupHeight = drawHelper.CurrentHeight() - beginningHeight;
        float currentGroupHeight;

        groupHeights.TryGetValue(itemKey, out currentGroupHeight);

        if (!newGroupHeight.NearlyEqual(currentGroupHeight))
        {
            currentGroupHeightTotal -= currentGroupHeight;
            currentGroupHeightTotal += newGroupHeight;

            SetSchemaHeight(schemaType, newGroupHeight);
        }

        SetGroupHeight(itemKey, newGroupHeight);
    }
Exemplo n.º 23
0
    void DrawSingleField(string schemaKey, string itemKey, string fieldKey, Dictionary <string, object> itemData)
    {
        string fieldPreviewKey = schemaKey + "_" + itemKey + "_" + fieldKey;
        string fieldType;

        itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

        BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;

        if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
        {
            fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
            fieldType     = GDEItemManager.GetVariableTypeFor(fieldTypeEnum);
        }

        content.text = fieldType;
        drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.TypeSuffix, content, labelStyle, out size);
        size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);

        GUI.Label(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
        drawHelper.CurrentLinePosition += (size.x + 2);

        content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
        drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.LblSuffix, content, labelStyle, out size);
        size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);

        GUI.Label(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
        drawHelper.CurrentLinePosition += (size.x + 2);

        switch (fieldTypeEnum)
        {
        case BasicFieldType.Bool:
        {
            DrawBool(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Int:
        {
            DrawInt(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Float:
        {
            DrawFloat(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.String:
        {
            DrawString(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Vector2:
        {
            DrawVector2(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
            break;
        }

        case BasicFieldType.Vector3:
        {
            DrawVector3(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
            break;
        }

        case BasicFieldType.Vector4:
        {
            DrawVector4(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
            break;
        }

        case BasicFieldType.Color:
        {
            DrawColor(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.GameObject:
        {
            DrawObject <GameObject>(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Texture2D:
        {
            DrawObject <Texture2D>(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Material:
        {
            DrawObject <Material>(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.AudioClip:
        {
            DrawAudio(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        default:
        {
            List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
            DrawCustom(fieldKey, itemData, true, itemKeys);
            drawHelper.NewLine();
            break;
        }
        }
    }
    protected override void DrawEntry(string key, Dictionary <string, object> data)
    {
        float  beginningHeight = CurrentHeight();
        string schemaType      = "<unknown>";
        object temp;

        if (data.TryGetValue(GDEConstants.SchemaKey, out temp))
        {
            schemaType = temp as string;
        }

        // Start drawing below
        if (DrawFoldout(schemaType + ":", key, key, key, RenameItem))
        {
            bool shouldDrawSpace        = false;
            bool didDrawSpaceForSection = false;

            // Draw the basic types
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.ItemFieldKeysOfType(key, fieldType.ToString());
                foreach (string fieldKey in fieldKeys)
                {
                    currentLinePosition += GDEConstants.Indent;
                    DrawSingleField(schemaType, fieldKey, data);
                    shouldDrawSpace = true;
                }
            }

            // Draw the custom types
            foreach (string fieldKey in GDEItemManager.ItemCustomFieldKeys(key))
            {
                if (shouldDrawSpace && !didDrawSpaceForSection)
                {
                    NewLine(0.5f);
                    didDrawSpaceForSection = true;
                }

                currentLinePosition += GDEConstants.Indent;
                DrawSingleField(schemaType, fieldKey, data);
                shouldDrawSpace = true;
            }
            didDrawSpaceForSection = false;

            // Draw the lists
            foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes)
            {
                List <string> fieldKeys = GDEItemManager.ItemListFieldKeysOfType(key, fieldType.ToString());
                foreach (string fieldKey in fieldKeys)
                {
                    if (shouldDrawSpace && !didDrawSpaceForSection)
                    {
                        NewLine(0.5f);
                        didDrawSpaceForSection = true;
                    }

                    currentLinePosition += GDEConstants.Indent;
                    DrawListField(schemaType, key, fieldKey, data);
                    shouldDrawSpace = true;
                }
            }
            didDrawSpaceForSection = false;

            // Draw the custom lists
            foreach (string fieldKey in GDEItemManager.ItemCustomListFields(key))
            {
                if (shouldDrawSpace && !didDrawSpaceForSection)
                {
                    NewLine(0.5f);
                    didDrawSpaceForSection = true;
                }

                currentLinePosition += GDEConstants.Indent;
                DrawListField(schemaType, key, fieldKey, data);
                shouldDrawSpace = true;
            }

            NewLine(0.5f);

            GUIContent content = new GUIContent(GDEStrings.DeleteBtn);
            float      width   = GUI.skin.button.CalcSize(content).x;
            if (GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content))
            {
                deletedItems.Add(key);
            }

            NewLine();

            DrawSectionSeparator();

            NewLine(0.25f);
        }
        else
        {
            // Collapse any list foldouts as well
            List <string> listKeys = GDEItemManager.ItemListFieldKeys(key);
            string        foldoutKey;
            foreach (string listKey in listKeys)
            {
                foldoutKey = string.Format(GDEConstants.MetaDataFormat, key, listKey);
                listFieldFoldoutState.Remove(foldoutKey);
            }
        }

        float newGroupHeight = CurrentHeight() - beginningHeight;
        float currentGroupHeight;

        groupHeights.TryGetValue(key, out currentGroupHeight);

        // Set the minimum height for the schema type
        if (currentGroupHeight.NearlyEqual(GDEConstants.LineHeight) && !newGroupHeight.NearlyEqual(GDEConstants.LineHeight))
        {
            SetSchemaHeight(schemaType, newGroupHeight);
        }

        SetGroupHeight(key, newGroupHeight);
    }
Exemplo n.º 25
0
    protected override void OnGUI()
    {
        mainHeaderText = GDEConstants.GameDataHeader;

        // Set the header color
        headerColor   = GDESettings.Instance.CreateDataColor.ToColor();
        headerColor.a = 1f;

        if (shouldRebuildEntriesList || entriesToDraw == null || GDEItemManager.ShouldReloadItems)
        {
            entriesToDraw                    = GetEntriesToDraw(GDEItemManager.AllItems);
            shouldRebuildEntriesList         = false;
            shouldRecalculateHeights         = true;
            GDEItemManager.ShouldReloadItems = false;
        }

        base.OnGUI();

        DrawExpandCollapseAllFoldout(GDEItemManager.AllItems.Keys.ToArray(), GDEConstants.ItemListHeader);


        float currentGroupHeightTotal = CalculateGroupHeightsTotal();

        scrollViewHeight          = drawHelper.HeightToBottomOfWindow();
        scrollViewY               = drawHelper.TopOfLine();
        verticalScrollbarPosition = GUI.BeginScrollView(new Rect(drawHelper.CurrentLinePosition, scrollViewY, drawHelper.FullWindowWidth(), scrollViewHeight),
                                                        verticalScrollbarPosition,
                                                        new Rect(drawHelper.CurrentLinePosition, scrollViewY, drawHelper.ScrollViewWidth(), currentGroupHeightTotal));

        int count = 0;

        foreach (KeyValuePair <string, Dictionary <string, object> > item in entriesToDraw)
        {
            float currentGroupHeight;
            groupHeights.TryGetValue(item.Key, out currentGroupHeight);

            if (currentGroupHeight == 0f ||
                (currentGroupHeight.NearlyEqual(GDEConstants.LineHeight) && entryFoldoutState.Contains(item.Key)))
            {
                string itemSchema = GDEItemManager.GetSchemaForItem(item.Key);
                if (!groupHeightBySchema.TryGetValue(itemSchema, out currentGroupHeight))
                {
                    currentGroupHeight = GDEConstants.LineHeight;
                }
            }

            int isVisible = drawHelper.IsVisible(verticalScrollbarPosition, scrollViewHeight, scrollViewY, currentGroupHeight);
            if (isVisible == 1)
            {
                break;
            }

            if (isVisible == 0 ||
                (count == GDEItemManager.AllItems.Count - 1 && verticalScrollbarPosition.y.NearlyEqual(currentGroupHeightTotal - GDEConstants.LineHeight)))
            {
                DrawEntry(item.Key, item.Value);
            }
            else if (isVisible == -1)
            {
                drawHelper.NewLine(currentGroupHeight / GDEConstants.LineHeight);
            }

            count++;
        }
        GUI.EndScrollView();

        // Remove any items that were deleted
        foreach (string deletedkey in deleteEntries)
        {
            Remove(deletedkey);
        }
        deleteEntries.Clear();

        // Rename any items that were renamed
        string error;

        foreach (KeyValuePair <string, string> pair in renamedItems)
        {
            if (!GDEItemManager.RenameItem(pair.Key, pair.Value, null, out error))
            {
                EditorUtility.DisplayDialog(GDEConstants.ErrorLbl, string.Format(GDEConstants.CouldNotRenameFormat, pair.Key, pair.Value, error), GDEConstants.OkLbl);
            }
        }

        renamedItems.Clear();

        // Clone any items
        foreach (string itemKey in cloneEntries)
        {
            Clone(itemKey);
        }
        cloneEntries.Clear();
    }
Exemplo n.º 26
0
 protected override void Remove(string key)
 {
     GDEItemManager.RemoveItem(key);
     SetNeedToSave(true);
 }
Exemplo n.º 27
0
    protected override void OnGUI()
    {
        mainHeaderText = GDEStrings.DefineDataHeader;
        headerColor    = EditorPrefs.GetString(GDEConstants.DefineDataColorKey, GDEConstants.DefineDataColor);

        base.OnGUI();

        DrawExpandCollapseAllFoldout(GDEItemManager.AllSchemas.Keys.ToArray(), GDEStrings.SchemaListHeader);

        float currentGroupHeightTotal = CalculateGroupHeightsTotal();

        scrollViewHeight          = HeightToBottomOfWindow();
        scrollViewY               = TopOfLine();
        verticalScrollbarPosition = GUI.BeginScrollView(new Rect(currentLinePosition, scrollViewY, FullWindowWidth(), scrollViewHeight),
                                                        verticalScrollbarPosition,
                                                        new Rect(currentLinePosition, scrollViewY, ScrollViewWidth(), currentGroupHeightTotal));

        foreach (KeyValuePair <string, Dictionary <string, object> > schema in GDEItemManager.AllSchemas)
        {
            // If we are filtered out, return
            if (ShouldFilter(schema.Key, schema.Value))
            {
                continue;
            }

            float currentGroupHeight;
            if (!groupHeights.TryGetValue(schema.Key, out currentGroupHeight))
            {
                currentGroupHeight = GDEConstants.LineHeight;
            }

            if (IsVisible(currentGroupHeight))
            {
                DrawEntry(schema.Key, schema.Value);
            }
            else
            {
                NewLine(currentGroupHeight / GDEConstants.LineHeight);
            }
        }
        GUI.EndScrollView();

        //Remove any schemas that were deleted
        foreach (string deletedSchemaKey in deletedSchemas)
        {
            Remove(deletedSchemaKey);
        }
        deletedSchemas.Clear();

        // Rename any schemas that were renamed
        string error;

        foreach (KeyValuePair <string, string> pair in renamedSchemas)
        {
            if (!GDEItemManager.RenameSchema(pair.Key, pair.Value, out error))
            {
                EditorUtility.DisplayDialog(GDEStrings.ErrorLbl, string.Format("Couldn't rename {0} to {1}: {2}", pair.Key, pair.Value, error), GDEStrings.OkLbl);
            }
        }
        renamedSchemas.Clear();
    }
    protected override void OnGUI()
    {
        mainHeaderText = GDEStrings.GameDataHeader;
        headerColor    = EditorPrefs.GetString(GDEConstants.CreateDataColorKey, GDEConstants.CreateDataColor);

        base.OnGUI();

        DrawExpandCollapseAllFoldout(GDEItemManager.AllItems.Keys.ToArray(), GDEStrings.ItemListHeader);


        float currentGroupHeightTotal = CalculateGroupHeightsTotal();

        scrollViewHeight          = HeightToBottomOfWindow();
        scrollViewY               = TopOfLine();
        verticalScrollbarPosition = GUI.BeginScrollView(new Rect(currentLinePosition, scrollViewY, FullWindowWidth(), scrollViewHeight),
                                                        verticalScrollbarPosition,
                                                        new Rect(currentLinePosition, scrollViewY, ScrollViewWidth(), currentGroupHeightTotal));

        int count = 0;

        foreach (KeyValuePair <string, Dictionary <string, object> > item in GDEItemManager.AllItems)
        {
            // If we are filtered out, continue
            if (ShouldFilter(item.Key, item.Value))
            {
                continue;
            }

            float currentGroupHeight;
            groupHeights.TryGetValue(item.Key, out currentGroupHeight);

            if (currentGroupHeight == 0f ||
                (currentGroupHeight.NearlyEqual(GDEConstants.LineHeight) && entryFoldoutState.Contains(item.Key)))
            {
                string itemSchema = GDEItemManager.GetSchemaForItem(item.Key);
                if (!groupHeightBySchema.TryGetValue(itemSchema, out currentGroupHeight))
                {
                    currentGroupHeight = GDEConstants.LineHeight;
                }
            }

            if (IsVisible(currentGroupHeight) ||
                (count == GDEItemManager.AllItems.Count - 1 && verticalScrollbarPosition.y.NearlyEqual(currentGroupHeightTotal - GDEConstants.LineHeight)))
            {
                DrawEntry(item.Key, item.Value);
            }
            else
            {
                NewLine(currentGroupHeight / GDEConstants.LineHeight);
            }

            count++;
        }
        GUI.EndScrollView();

        //Remove any items that were deleted
        foreach (string deletedkey in deletedItems)
        {
            Remove(deletedkey);
        }
        deletedItems.Clear();

        //Rename any items that were renamed
        string error;

        foreach (KeyValuePair <string, string> pair in renamedItems)
        {
            if (!GDEItemManager.RenameItem(pair.Key, pair.Value, null, out error))
            {
                EditorUtility.DisplayDialog(GDEStrings.ErrorLbl, string.Format("Couldn't rename {0} to {1}: {2}", pair.Key, pair.Value, error), GDEStrings.OkLbl);
            }
        }

        renamedItems.Clear();
    }
Exemplo n.º 29
0
 public override void OnEnable()
 {
     GDEItemManager.Load(true);
     GetSchemas();
 }
Exemplo n.º 30
0
    static void OnGUI()
    {
        SetStyles();
        LoadPreferences();

        content.text = GDEConstants.FileSettingsLbl;
        drawHelper.TryGetCachedSize(GDEConstants.FileSettingsLbl, content, headerStyle, out size);
        GUILayout.Label(content.text, headerStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));

        EditorGUILayout.BeginHorizontal();
        content.text = GDEConstants.CreateDataFileLbl;
        drawHelper.TryGetCachedSize(content.text, content, EditorStyles.label, out size);
        EditorGUILayout.LabelField(content.text, string.Empty, GUILayout.Width(size.x + 2));
        dataFilePath = EditorGUILayout.TextArea(dataFilePath, textFieldStyle);

        content.text = GDEConstants.BrowseBtn;
        drawHelper.TryGetCachedSize(content.text, content, GUI.skin.button, out size);
        if (GUILayout.Button(content.text, GUILayout.Width(size.x)))
        {
            string newDataFilePath = EditorUtility.OpenFilePanel(GDEConstants.OpenDataFileLbl, dataFilePath, string.Empty);
            if (!string.IsNullOrEmpty(newDataFilePath) && !newDataFilePath.Equals(dataFilePath))
            {
                dataFilePath = newDataFilePath;
            }
            GUI.FocusControl(string.Empty);
        }
        EditorGUILayout.EndHorizontal();

        if (!File.Exists(dataFilePath))
        {
            GUILayout.Space(drawHelper.LineHeight / 4f);

            content.text = GDEConstants.FileDoesNotExistWarning;
            drawHelper.TryGetCachedSize(content.text, content, EditorStyles.label, out size);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginVertical(GUILayout.Width(size.x * 1.5f));
            GUILayout.Space(3);
            EditorGUILayout.HelpBox(content.text, MessageType.Warning);
            EditorGUILayout.EndVertical();

            content.text = GDEConstants.CreateFileLbl;
            drawHelper.TryGetCachedSize(content.text, content, GUI.skin.button, out size);
            if (GUILayout.Button(content, GUILayout.Width(size.x), GUILayout.ExpandHeight(true)))
            {
                GDEItemManager.CreateFileIfMissing(dataFilePath);
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }

        GUILayout.Space(drawHelper.LineHeight / 2f);

        EditorGUILayout.BeginHorizontal();
        content.text = GDEConstants.PrettyJsonLbl;
        drawHelper.TryGetCachedSize(content.text, content, EditorStyles.toggle, out size);

        prettyJson = EditorGUILayout.Toggle(prettyJson, GUILayout.Width(20));

        EditorGUILayout.LabelField(content, GUILayout.Width(size.x + 2));

        if (prettyJson)
        {
            EditorGUILayout.HelpBox(GDEConstants.PrettyJsonMsg, MessageType.Warning);
        }
        else
        {
            EditorGUILayout.HelpBox(GDEConstants.PrettyJsonMsg, MessageType.Info);
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(drawHelper.LineHeight);

        content.text = GDEConstants.ColorsLbl;
        drawHelper.TryGetCachedSize(content.text, content, headerStyle, out size);
        GUILayout.Label(content.text, headerStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));

        createDataColor = EditorGUILayout.ColorField(GDEConstants.CreateDataColorLbl, createDataColor);
        defineDataColor = EditorGUILayout.ColorField(GDEConstants.DefineDataColorLbl, defineDataColor);
        highlightColor  = EditorGUILayout.ColorField(GDEConstants.HighlightLbl, highlightColor);

        GUILayout.FlexibleSpace();

        content.text = GDEConstants.UseDefaults;
        drawHelper.TryGetCachedSize(content.text, content, GUI.skin.button, out size);
        if (GUILayout.Button(GDEConstants.UseDefaults, GUILayout.Width(size.x * 1.52f)))
        {
            LoadDefaults();
        }

        if (GUI.changed)
        {
            SavePreferences();
        }
    }