bool OnGUIUserInfo()
    {
        if (!RemoteConfig.IsInitialized())
        {
            RemoteConfig.Init();
        }

        CheckLogin();

        if (APIUser.IsLoggedInWithCredentials)
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            EditorGUILayout.Space();

            if (uploadedWorlds == null)
            {
                EditorGUILayout.EndScrollView();
                return(true);
            }

            EditorGUILayout.LabelField("Worlds", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(200));
            EditorGUILayout.LabelField("Image", EditorStyles.boldLabel, GUILayout.Width(75));
            EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
            //EditorGUILayout.LabelField("Version", EditorStyles.boldLabel, GUILayout.Width (75));
            EditorGUILayout.LabelField("Release Status", EditorStyles.boldLabel, GUILayout.Width(100));
            EditorGUILayout.EndHorizontal();

            List <ApiWorld> tmpWorlds = new List <ApiWorld>();

            if (uploadedWorlds != null)
            {
                tmpWorlds = new List <ApiWorld>(uploadedWorlds);
            }

            foreach (ApiWorld w in tmpWorlds)
            {
                if (justDeletedContents != null && justDeletedContents.Contains(w.id))
                {
                    continue;
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(w.name, GUILayout.Width(200));
                if (worldImages != null && worldImages.ContainsKey(w.id))
                {
                    if (GUILayout.Button(worldImages[w.id], GUILayout.Height(100), GUILayout.Width(100)))
                    {
                        Application.OpenURL(w.imageUrl);
                    }
                }
                else
                {
                    GUILayout.Label("No Image", GUILayout.Height(100), GUILayout.Width(100));
                }
                EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                EditorGUILayout.LabelField(w.releaseStatus, GUILayout.Width(100));
                EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                if (GUILayout.Button("Copy ID", GUILayout.Width(75)))
                {
                    TextEditor te = new TextEditor();
                    te.text = w.id;
                    te.SelectAll();
                    te.Copy();
                }
                if (GUILayout.Button("Delete", GUILayout.Width(75)))
                {
                    if (EditorUtility.DisplayDialog("Delete " + w.name + "?", "Are you sure you want to delete " + w.name + "? This cannot be undone.", "Delete", "Cancel"))
                    {
                        ApiWorld.Delete(w.id, null, null);
                        uploadedWorlds.RemoveAll(world => world.id == w.id);

                        if (justDeletedContents == null)
                        {
                            justDeletedContents = new List <string>();
                        }
                        justDeletedContents.Add(w.id);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Avatars", EditorStyles.boldLabel);
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(200));
            EditorGUILayout.LabelField("Image", EditorStyles.boldLabel, GUILayout.Width(75));
            EditorGUILayout.EndHorizontal();

            List <ApiAvatar> tmpAvatars = new List <ApiAvatar>();

            if (uploadedAvatars != null)
            {
                tmpAvatars = new List <ApiAvatar>(uploadedAvatars);
            }

            foreach (ApiAvatar a in tmpAvatars)
            {
                if (justDeletedContents != null && justDeletedContents.Contains(a.id))
                {
                    continue;
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(a.name, GUILayout.Width(200));
                if (avatarImages != null && avatarImages.ContainsKey(a.id))
                {
                    if (GUILayout.Button(avatarImages[a.id], GUILayout.Height(100), GUILayout.Width(100)))
                    {
                        Application.OpenURL(a.imageUrl);
                    }
                }
                else
                {
                    GUILayout.Label("No Image", GUILayout.Height(100), GUILayout.Width(100));
                }
                EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));

                if (GUILayout.Button("Copy ID", GUILayout.Width(75)))
                {
                    TextEditor te = new TextEditor();
                    te.text = a.id;
                    te.SelectAll();
                    te.Copy();
                }

                if (GUILayout.Button("Delete", GUILayout.Width(75)))
                {
                    if (EditorUtility.DisplayDialog("Delete " + a.name + "?", "Are you sure you want to delete " + a.name + "? This cannot be undone.", "Delete", "Cancel"))
                    {
                        ApiAvatar.Delete(a.id, null, null);
                        uploadedAvatars.RemoveAll(avatar => avatar.id == a.id);

                        if (justDeletedContents == null)
                        {
                            justDeletedContents = new List <string>();
                        }
                        justDeletedContents.Add(a.id);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #2
0
    bool OnGUIUserInfo()
    {
        if (!RemoteConfig.IsInitialized())
        {
            RemoteConfig.Init();
        }

        if (APIUser.IsLoggedInWithCredentials && uploadedWorlds != null && uploadedAvatars != null)
        {
            EditorGUILayout.LabelField(string.Format(fetchingWorlds != null ? "Fetching Worlds... {0}" : "{0} Worlds", uploadedWorlds.Count.ToString()), EditorStyles.helpBox);
            EditorGUILayout.LabelField(string.Format(fetchingAvatars != null ? "Fetching Avatars... {0}" : "{0} Avatars", uploadedAvatars.Count.ToString()), EditorStyles.helpBox);

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            if (uploadedWorlds.Count > 0)
            {
                EditorGUILayout.Space();

                EditorGUILayout.LabelField("Worlds", EditorStyles.boldLabel);
                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(200));
                EditorGUILayout.LabelField("Image", EditorStyles.boldLabel, GUILayout.Width(75));
                EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                //EditorGUILayout.LabelField("Version", EditorStyles.boldLabel, GUILayout.Width (75));
                EditorGUILayout.LabelField("Release Status", EditorStyles.boldLabel, GUILayout.Width(100));
                EditorGUILayout.EndHorizontal();

                List <ApiWorld> tmpWorlds = new List <ApiWorld>();

                if (uploadedWorlds.Count > 0)
                {
                    tmpWorlds = new List <ApiWorld>(uploadedWorlds);
                }

                foreach (ApiWorld w in tmpWorlds)
                {
                    if (justDeletedContents != null && justDeletedContents.Contains(w.id))
                    {
                        uploadedWorlds.Remove(w);
                        continue;
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(w.name, GUILayout.Width(200));
                    if (ImageCache.ContainsKey(w.id))
                    {
                        if (GUILayout.Button(ImageCache[w.id], GUILayout.Height(100), GUILayout.Width(100)))
                        {
                            Application.OpenURL(w.imageUrl);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("", GUILayout.Height(100), GUILayout.Width(100)))
                        {
                            Application.OpenURL(w.imageUrl);
                        }
                    }
                    EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                    EditorGUILayout.LabelField(w.releaseStatus, GUILayout.Width(100));
                    EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                    if (GUILayout.Button("Copy ID", GUILayout.Width(75)))
                    {
                        TextEditor te = new TextEditor();
                        te.text = w.id;
                        te.SelectAll();
                        te.Copy();
                    }
                    if (GUILayout.Button("Delete", GUILayout.Width(75)))
                    {
                        if (EditorUtility.DisplayDialog("Delete " + w.name + "?", "Are you sure you want to delete " + w.name + "? This cannot be undone.", "Delete", "Cancel"))
                        {
                            ApiWorld.Delete(w.id, null, null);
                            uploadedWorlds.RemoveAll(world => world.id == w.id);
                            if (ImageCache.ContainsKey(w.id))
                            {
                                ImageCache.Remove(w.id);
                            }

                            if (justDeletedContents == null)
                            {
                                justDeletedContents = new List <string>();
                            }
                            justDeletedContents.Add(w.id);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            if (uploadedAvatars.Count > 0)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Avatars", EditorStyles.boldLabel);
                EditorGUILayout.Space();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(200));
                EditorGUILayout.LabelField("Image", EditorStyles.boldLabel, GUILayout.Width(75));
                EditorGUILayout.EndHorizontal();

                List <ApiAvatar> tmpAvatars = new List <ApiAvatar>();

                if (uploadedAvatars.Count > 0)
                {
                    tmpAvatars = new List <ApiAvatar>(uploadedAvatars);
                }

                if (justUpdatedAvatars != null)
                {
                    foreach (ApiAvatar a in justUpdatedAvatars)
                    {
                        int index = tmpAvatars.FindIndex((av) => av.id == a.id);
                        if (index != -1)
                        {
                            tmpAvatars[index] = a;
                        }
                    }
                }

                foreach (ApiAvatar a in tmpAvatars)
                {
                    if (justDeletedContents != null && justDeletedContents.Contains(a.id))
                    {
                        uploadedAvatars.Remove(a);
                        continue;
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(a.name, GUILayout.Width(200));
                    if (ImageCache.ContainsKey(a.id))
                    {
                        if (GUILayout.Button(ImageCache[a.id], GUILayout.Height(100), GUILayout.Width(100)))
                        {
                            Application.OpenURL(a.imageUrl);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("", GUILayout.Height(100), GUILayout.Width(100)))
                        {
                            Application.OpenURL(a.imageUrl);
                        }
                    }
                    EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                    EditorGUILayout.LabelField(a.releaseStatus, GUILayout.Width(100));
                    EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));

                    string oppositeReleaseStatus = a.releaseStatus == "public" ? "private" : "public";
                    if (GUILayout.Button("Make " + oppositeReleaseStatus, GUILayout.Width(100)))
                    {
                        a.releaseStatus = oppositeReleaseStatus;

                        a.Save(true, delegate(ApiModel model)
                        {
                            ApiAvatar savedBP = (ApiAvatar)model;

                            if (justUpdatedAvatars == null)
                            {
                                justUpdatedAvatars = new List <ApiAvatar>();
                            }
                            justUpdatedAvatars.Add(savedBP);

                            EditorUtility.DisplayDialog("Avatar Updated", "Avatar made " + savedBP.releaseStatus, "OK");
                        },
                               delegate(string error)
                        {
                            Debug.LogError(error);
                            EditorUtility.DisplayDialog("Avatar Updated", "Failed to change avatar release status", "OK");
                        });
                    }

                    if (GUILayout.Button("Copy ID", GUILayout.Width(75)))
                    {
                        TextEditor te = new TextEditor();
                        te.text = a.id;
                        te.SelectAll();
                        te.Copy();
                    }

                    if (GUILayout.Button("Delete", GUILayout.Width(75)))
                    {
                        if (EditorUtility.DisplayDialog("Delete " + a.name + "?", "Are you sure you want to delete " + a.name + "? This cannot be undone.", "Delete", "Cancel"))
                        {
                            ApiAvatar.Delete(a.id, null, null);
                            uploadedAvatars.RemoveAll(avatar => avatar.id == a.id);
                            if (ImageCache.ContainsKey(a.id))
                            {
                                ImageCache.Remove(a.id);
                            }

                            if (justDeletedContents == null)
                            {
                                justDeletedContents = new List <string>();
                            }
                            justDeletedContents.Add(a.id);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.EndScrollView();

            return(true);
        }
        else
        {
            return(false);
        }
    }
    bool OnGUIUserInfo()
    {
        if (!RemoteConfig.IsInitialized())
        {
            RemoteConfig.Init();
        }

        if (!APIUser.IsLoggedInWithCredentials && APIUser.IsCached)
        {
            APIUser.CachedLogin(null, null, false);
        }

        GUILayout.Label("Account Info", EditorStyles.boldLabel);
        if (APIUser.IsLoggedInWithCredentials)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Logged in as " + APIUser.CurrentUser.displayName);
            if (GUILayout.Button("Logout"))
            {
                APIUser.Logout();
                GUILayout.EndHorizontal();
                return(false);
            }
            else
            {
                GUILayout.EndHorizontal();
                GUILayout.Label("Developer Status: " + APIUser.CurrentUser.developerType);

                if (APIUser.CurrentUser.developerType == APIUser.DeveloperType.Internal)
                {
                    string apiMessage = ApiModel.IsDevApi() ? "Dev" : "Release";
                    GUILayout.Label("API: " + apiMessage);
                }


                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

                EditorGUILayout.Space();

                if (uploadedWorlds == null)
                {
                    EditorGUILayout.EndScrollView();
                    return(true);
                }

                EditorGUILayout.LabelField("Worlds", EditorStyles.boldLabel);
                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(200));
                EditorGUILayout.LabelField("Image", EditorStyles.boldLabel, GUILayout.Width(75));
                EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                //EditorGUILayout.LabelField("Version", EditorStyles.boldLabel, GUILayout.Width (75));
                EditorGUILayout.LabelField("Release Status", EditorStyles.boldLabel, GUILayout.Width(100));
                EditorGUILayout.EndHorizontal();

                List <ApiWorld> tmpWorlds = new List <ApiWorld>();

                if (uploadedWorlds != null)
                {
                    tmpWorlds = new List <ApiWorld>(uploadedWorlds);
                }

                foreach (ApiWorld w in tmpWorlds)
                {
                    if (justDeletedContents != null && justDeletedContents.Contains(w.id))
                    {
                        continue;
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(w.name, GUILayout.Width(200));
                    if (worldImages != null && worldImages.ContainsKey(w.id))
                    {
                        if (GUILayout.Button(worldImages[w.id], GUILayout.Height(100), GUILayout.Width(100)))
                        {
                            Application.OpenURL(w.imageUrl);
                        }
                    }
                    else
                    {
                        GUILayout.Label("No Image", GUILayout.Height(100), GUILayout.Width(100));
                    }
                    EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                    EditorGUILayout.LabelField(w.releaseStatus, GUILayout.Width(100));
                    EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));
                    if (GUILayout.Button("Copy ID", GUILayout.Width(75)))
                    {
                        TextEditor te = new TextEditor();
                        te.text = w.id;
                        te.SelectAll();
                        te.Copy();
                    }
                    if (GUILayout.Button("Delete", GUILayout.Width(75)))
                    {
                        if (EditorUtility.DisplayDialog("Delete " + w.name + "?", "Are you sure you want to delete " + w.name + "? This cannot be undone.", "Delete", "Cancel"))
                        {
                            ApiWorld.Delete(w.id, null, null);
                            uploadedWorlds.RemoveAll(world => world.id == w.id);

                            if (justDeletedContents == null)
                            {
                                justDeletedContents = new List <string>();
                            }
                            justDeletedContents.Add(w.id);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Avatars", EditorStyles.boldLabel);
                EditorGUILayout.Space();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(200));
                EditorGUILayout.LabelField("Image", EditorStyles.boldLabel, GUILayout.Width(75));
                EditorGUILayout.EndHorizontal();

                List <ApiAvatar> tmpAvatars = new List <ApiAvatar>();

                if (uploadedAvatars != null)
                {
                    tmpAvatars = new List <ApiAvatar>(uploadedAvatars);
                }

                foreach (ApiAvatar a in tmpAvatars)
                {
                    if (justDeletedContents != null && justDeletedContents.Contains(a.id))
                    {
                        continue;
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(a.name, GUILayout.Width(200));
                    if (avatarImages != null && avatarImages.ContainsKey(a.id))
                    {
                        if (GUILayout.Button(avatarImages[a.id], GUILayout.Height(100), GUILayout.Width(100)))
                        {
                            Application.OpenURL(a.imageUrl);
                        }
                    }
                    else
                    {
                        GUILayout.Label("No Image", GUILayout.Height(100), GUILayout.Width(100));
                    }
                    EditorGUILayout.LabelField("", EditorStyles.boldLabel, GUILayout.Width(50));

                    if (GUILayout.Button("Copy ID", GUILayout.Width(75)))
                    {
                        TextEditor te = new TextEditor();
                        te.text = a.id;
                        te.SelectAll();
                        te.Copy();
                    }

                    if (GUILayout.Button("Delete", GUILayout.Width(75)))
                    {
                        if (EditorUtility.DisplayDialog("Delete " + a.name + "?", "Are you sure you want to delete " + a.name + "? This cannot be undone.", "Delete", "Cancel"))
                        {
                            ApiAvatar.Delete(a.id, null, null);
                            uploadedAvatars.RemoveAll(avatar => avatar.id == a.id);

                            if (justDeletedContents == null)
                            {
                                justDeletedContents = new List <string>();
                            }
                            justDeletedContents.Add(a.id);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndScrollView();

                return(true);
            }
        }
        else
        {
            VRC.Core.ApiModel.ResetApi();

            username = EditorGUILayout.TextField("Username", username);
            password = EditorGUILayout.PasswordField("Password", password);

            if (GUILayout.Button("Sign In"))
            {
                APIUser.Login(username, password,
                              delegate(APIUser user)
                {
                    UnityEditor.EditorUtility.ClearProgressBar();
                    FetchWorldData();
                },
                              delegate(string message)
                {
                    VRC.Core.Logger.Log("Error logging in - " + message);
                    UnityEditor.EditorUtility.ClearProgressBar();
                    UnityEditor.EditorUtility.DisplayDialog("Error logging in", message, "Okay");
                }
                              );
                UnityEditor.EditorUtility.DisplayProgressBar("Logging in!", "Hang tight...", 0.5f);
            }
            if (GUILayout.Button("Sign up"))
            {
                Application.OpenURL("http://www.vrchat.net/auth/register");
            }
            return(false);
        }
    }