예제 #1
0
    bool DrawLoadService()
    {
        contentColor    = GUI.contentColor;
        backgroundColor = GUI.backgroundColor;

        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = EditorHelpers.orangeColor;
        if (GUILayout.Button("Load", GUILayout.Width(60)))
        {
            LoadData();
        }

        GUI.backgroundColor = EditorHelpers.yellowColor;
        if (GUILayout.Button("New", GUILayout.Width(60)))
        {
            ItemConfigData newData = new ItemConfigData();
            newData.id = "New Item " + newItemNameSufix.ToString();
            ++newItemNameSufix;
            EditorHelpers.allItems.Insert(0, newData);
            EditorHelpers.InitItemConfigNames();
            selectedItemIndex = 0;
            itemData          = newData;
            ShowNotification(new GUIContent("New Item added."));
            dirty = true;
        }
        GUI.backgroundColor = EditorHelpers.greenColor;
        if (GUILayout.Button("Save", GUILayout.Width(60)))
        {
            Save();
        }
        GUI.backgroundColor = backgroundColor;
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        if (EditorHelpers.allItems == null)
        {
            EditorGUILayout.HelpBox("It seems that there is no data... try reopening the editor.", MessageType.Error);
            return(false);
        }

        iapCreatorSectionOpened = EditorGUILayout.Foldout(iapCreatorSectionOpened, "iAP Creator");

        if (iapCreatorSectionOpened)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("iAP Name:", GUILayout.Width(100));
            iapName = EditorGUILayout.TextField(iapName, GUILayout.Width(250));
            if (GUILayout.Button("Create", GUILayout.Width(70)))
            {
                if (iapName.Length > 0)
                {
                    bool exists = false;
                    foreach (var id in EditorHelpers.allIAPs)
                    {
                        if (id.id == iapName)
                        {
                            ShowNotification(new GUIContent("iAP with id (" + iapName + ") already exists."));
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                    {
                        IAPConfigData newiAP = new IAPConfigData();
                        newiAP.id   = iapName;
                        newiAP.name = iapName;
                        var newIAPData = new IAPData(StoreType.All, iapName);
                        newiAP.iapData.Add(newIAPData);
                        EditorHelpers.allIAPs.Add(newiAP);
                        EditorHelpers.InitIAPNames(true);
                        ShowNotification(new GUIContent("New iAP created."));
                        if (EditorHelpers.allIAPs.Count > 0)
                        {
                            EditorHelpers.gameDB.DeleteAllConfigs(EditorHelpers.allIAPs[0].GetTableName());
                        }
                        foreach (var p in EditorHelpers.allIAPs)
                        {
                            EditorHelpers.gameDB.SaveConfig(p.GetTableName(), p.id, LitJson.JsonMapper.ToJson(p));
                        }
                        EditorHelpers.gameDB.IncrementLocalDBVersion();
                    }
                }
                else
                {
                    ShowNotification(new GUIContent("iAP must have a name."));
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator(); EditorGUILayout.Separator();
        }

        if (EditorHelpers.DrawItemsFilter("Item Filter:"))
        {
            selectedItemIndex = -1;
            itemData          = null;
        }
        if (EditorHelpers.allItems.Count > 0)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Items:", GUILayout.Width(100));
            int oldIntValue = selectedItemIndex;
            selectedItemIndex = EditorGUILayout.Popup(oldIntValue, EditorHelpers.itemConfigNames, GUILayout.Width(250));
            if (oldIntValue != selectedItemIndex)
            {
                itemData = EditorHelpers.allItems[selectedItemIndex];
            }
            if (itemData != null)
            {
                GUI.backgroundColor = EditorHelpers.redColor;
                if (GUILayout.Button("Delete", GUILayout.Width(70)))
                {
                    if (EditorUtility.DisplayDialog("Deleting Item!", "Are you sure you want to delete parameter '" + itemData.id + "'?", "Yes, Delete it.", "No!"))
                    {
                        EditorHelpers.gameDB.DeleteConfig(itemData.GetTableName(), itemData.id);
                        EditorHelpers.allItems.Remove(itemData);
                        EditorHelpers.InitItemConfigNames();
                        selectedItemIndex = -1;
                        itemData          = null;
                        ShowNotification(new GUIContent("Item deleted."));
                        return(false);
                    }
                }
                GUI.backgroundColor = EditorHelpers.blueColor;
                if (GUILayout.Button("Duplicate", GUILayout.Width(100)))
                {
                    ItemConfigData newData = itemData.Clone() as ItemConfigData;
                    newData.id = itemData.id + "(Clone)";
                    EditorHelpers.allItems.Insert(0, newData);
                    EditorHelpers.InitItemConfigNames();
                    selectedItemIndex = 0;
                    itemData          = newData;
                    ShowNotification(new GUIContent("Item duplicated."));
                    dirty = true;
                }
                GUI.backgroundColor = backgroundColor;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator();
        }

        return(itemData != null);
    }