Beispiel #1
0
        public static void CreateAssetInstance()
        {
            ScriptableModProfile asset = ScriptableObject.CreateInstance <ScriptableModProfile>();

            int profileCount
                = System.IO.Directory.GetFiles(Application.dataPath, "NewModProfile*.asset").Length;

            string fileNameAddition = (profileCount > 0
                                       ? " (" + profileCount.ToString() + ")"
                                       : "");

            AssetDatabase.CreateAsset(asset, "Assets/NewModProfile" + fileNameAddition + ".asset");
            AssetDatabase.SaveAssets();

            EditorUtility.FocusProjectWindow();

            Selection.activeObject = asset;
        }
Beispiel #2
0
        // ------[ LOGIN PROMPT ]------
        protected virtual void LayoutSubmissionFields()
        {
            using (new EditorGUI.DisabledScope(isAwaitingServerResponse))
            {
                // - Account Header -
                EditorGUILayout.BeginHorizontal();
                {
                    if (this.user == null)
                    {
                        EditorGUILayout.LabelField("Not logged in to mod.io");
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Log In"))
                        {
                            LoginWindow.GetWindow <LoginWindow>("Login to mod.io");
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Logged in as:  " + this.user.username);
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Log Out"))
                        {
                            EditorApplication.delayCall += () =>
                            {
                                if (EditorDialogs.ConfirmLogOut(this.user.username))
                                {
                                    this.user = null;

                                    UserAuthenticationData.instance = UserAuthenticationData.NONE;

                                    isAwaitingServerResponse = false;

                                    Repaint();
                                }
                            };
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

                // - Submission Section -
                if (!String.IsNullOrEmpty(uploadSucceededMessage))
                {
                    EditorGUILayout.HelpBox(uploadSucceededMessage,
                                            MessageType.Info);
                }
                else if (!String.IsNullOrEmpty(uploadFailedMessage))
                {
                    EditorGUILayout.HelpBox(uploadFailedMessage,
                                            MessageType.Error);
                }
                else if (profile == null)
                {
                    EditorGUILayout.HelpBox("Please select a mod profile as a the upload target.",
                                            MessageType.Info);
                }
                else if (profile.modId > 0)
                {
                    EditorGUILayout.HelpBox(profile.editableModProfile.name.value
                                            + " will be updated as used as the upload target on the server.",
                                            MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox(profile.editableModProfile.name.value
                                            + " will be created as a new profile on the server.",
                                            MessageType.Info);
                }
                EditorGUILayout.Space();


                // TODO(@jackson): Support mods that haven't been downloaded?
                profile = EditorGUILayout.ObjectField("Mod Profile",
                                                      profile,
                                                      typeof(ScriptableModProfile),
                                                      false) as ScriptableModProfile;

                // - Build Profile -
                using (new EditorGUI.DisabledScope(profile == null))
                {
                    EditorGUILayout.BeginHorizontal();
                    if (EditorGUILayoutExtensions.BrowseButton(buildFilePath, new GUIContent("Modfile")))
                    {
                        EditorApplication.delayCall += () =>
                        {
                                #if UPLOAD_MOD_BINARY_AS_DIRECTORY
                            string path = EditorUtility.OpenFolderPanel("Set Build Location",
                                                                        "",
                                                                        "ModBinary");
                                #else
                            string path = EditorUtility.OpenFilePanelWithFilters("Set Build Location",
                                                                                 "",
                                                                                 modBinaryFileExtensionFilters);
                                #endif

                            if (path.Length != 0)
                            {
                                buildFilePath = path;
                            }
                        };
                    }
                    if (EditorGUILayoutExtensions.ClearButton())
                    {
                        buildFilePath = string.Empty;
                    }
                    EditorGUILayout.EndHorizontal();

                    // - Build Profile -
                    #if UPLOAD_MOD_BINARY_AS_DIRECTORY
                    using (new EditorGUI.DisabledScope(!System.IO.Directory.Exists(buildFilePath)))
                    #else
                    using (new EditorGUI.DisabledScope(!System.IO.File.Exists(buildFilePath)))
                    #endif
                    {
                        // - Version -
                        EditorGUI.BeginChangeCheck();
                        buildProfile.version.value = EditorGUILayout.TextField("Version",
                                                                               buildProfile.version.value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            buildProfile.version.isDirty = true;
                        }
                        // - Changelog -
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PrefixLabel("Changelog");
                        buildProfile.changelog.value = EditorGUILayoutExtensions.MultilineTextField(buildProfile.changelog.value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            buildProfile.changelog.isDirty = true;
                        }
                        // - Metadata -
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PrefixLabel("Metadata");
                        buildProfile.metadataBlob.value = EditorGUILayoutExtensions.MultilineTextField(buildProfile.metadataBlob.value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            buildProfile.metadataBlob.isDirty = true;
                        }
                    }

                    // TODO(@jackson): if(profile) -> show build list?
                    EditorGUILayout.Space();
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Upload to Server"))
                    {
                        UploadToServer();
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
        protected virtual void LayoutProfileInitialization()
        {
            EditorGUILayout.LabelField("Initialize Mod Profile");

            // ---[ DISPLAY ]---
            EditorGUILayout.Space();

            if (GUILayout.Button("Create New"))
            {
                EditorApplication.delayCall += () =>
                {
                    ScriptableModProfile smp = this.target as ScriptableModProfile;
                    Undo.RecordObject(smp, "Initialize Mod Profile");

                    smp.modId = 0;
                    smp.editableModProfile = new EditableModProfile();

                    OnDisable();
                    OnEnable();
                    isRepaintRequired = true;
                };
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("---- OR ----");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Load Existing Profile");

            if (user == null)
            {
                EditorGUILayout.HelpBox("Log in required to load existing mods",
                                        MessageType.Info);
                if (GUILayout.Button("Log In to mod.io"))
                {
                    LoginWindow.GetWindow <LoginWindow>("Login to mod.io");
                }
            }
            else if (modOptions.Length > 0)
            {
                using (new EditorGUI.DisabledScope(isModListLoading))
                {
                    modInitializationOptionIndex = EditorGUILayout.Popup("Select Mod", modInitializationOptionIndex, modOptions);
                    if (GUILayout.Button("Load"))
                    {
                        ModProfile profile = modList[modInitializationOptionIndex];
                        EditorApplication.delayCall += () =>
                        {
                            ScriptableModProfile smp = this.target as ScriptableModProfile;
                            Undo.RecordObject(smp, "Initialize Mod Profile");

                            smp.modId = profile.id;
                            smp.editableModProfile = EditableModProfile.CreateFromProfile(profile);

                            string smpFilePath = AssetDatabase.GetAssetPath(smp);
                            string smpDir      = System.IO.Path.GetDirectoryName(smpFilePath);

                            int profileCount
                                = System.IO.Directory.GetFiles(smpDir, profile.name + "*.asset").Length;

                            string fileNameAddition = (profileCount > 0
                                                       ? " (" + profileCount.ToString() + ")"
                                                       : "");

                            AssetDatabase.RenameAsset(smpFilePath, profile.name + fileNameAddition + ".asset");

                            OnDisable();
                            OnEnable();
                            isRepaintRequired = true;
                        };
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("No loadable mod profiles detected.",
                                        MessageType.Info);
            }
        }
        // ------[ GUI ]------
        public override void OnInspectorGUI()
        {
            if (serializedObject.FindProperty("modId").intValue == ScriptableModProfile.UNINITIALIZED_MOD_ID)
            {
                LayoutProfileInitialization();
            }
            else
            {
                serializedObject.Update();

                bool isProfileSyncRequested = false;

                if (!String.IsNullOrEmpty(profileGetErrorMessage))
                {
                    EditorGUILayout.HelpBox(profileGetErrorMessage, MessageType.Warning);
                }

                using (new EditorGUI.DisabledScope(isProfileSyncing))
                {
                    if (profileViewParts != null &&
                        profileViewParts.Length > 0)
                    {
                        using (new EditorGUI.DisabledScope(modIdProperty.intValue == 0))
                        {
                            string syncButtonText;
                            if (profile == null)
                            {
                                syncButtonText = "Retry Fetching Server Data";
                            }
                            else
                            {
                                syncButtonText = "Pull Server Data Updates";
                            }
                            isProfileSyncRequested = GUILayout.Button(syncButtonText);
                            EditorGUILayout.Space();
                        }
                    }

                    foreach (IModProfileViewPart viewPart in profileViewParts)
                    {
                        viewPart.OnGUI();
                    }
                    serializedObject.ApplyModifiedProperties();
                }

                if (isProfileSyncRequested)
                {
                    isProfileSyncing = true;
                    APIClient.GetMod(modIdProperty.intValue,
                                     (modProfile) =>
                    {
                        CacheClient.SaveModProfile(modProfile);
                        this.profile = modProfile;

                        ScriptableModProfile smp = this.target as ScriptableModProfile;
                        Undo.RecordObject(smp, "Update Mod Profile");
                        smp.editableModProfile.ApplyBaseProfileChanges(profile);

                        isProfileSyncing       = false;
                        profileGetErrorMessage = null;

                        this.OnDisable();
                        this.OnEnable();
                    },
                                     (e) =>
                    {
                        isProfileSyncing       = false;
                        profileGetErrorMessage = ("Unable to fetch the mod profile data on the server.\n"
                                                  + e.displayMessage);
                    });
                }
            }

            isRepaintRequired = false;
        }