private void ModProfileSubmissionSucceeded(ModProfile updatedProfile, string profileFilePath) { if (updatedProfile == null) { isAwaitingServerResponse = false; return; } uploadFailedMessage = null; // Update ScriptableModProfile profile.modId = updatedProfile.id; profile.editableModProfile = EditableModProfile.CreateFromProfile(updatedProfile); EditorUtility.SetDirty(profile); AssetDatabase.SaveAssets(); // Upload Build #if UPLOAD_MOD_BINARY_AS_DIRECTORY if (LocalDataStorage.GetDirectoryExists(buildFilePath)) #else if (LocalDataStorage.GetFileExists(buildFilePath)) #endif { Action <WebRequestError> onSubmissionFailed = (e) => { EditorUtility.DisplayDialog("Upload Failed", "Failed to upload the mod build to the server.\n" + e.displayMessage, "Close"); uploadFailedMessage = e.displayMessage; if (e.fieldValidationMessages != null && e.fieldValidationMessages.Count > 0) { foreach (var kvp in e.fieldValidationMessages) { uploadFailedMessage += "\n [" + kvp.Key + "]: " + kvp.Value; } } isAwaitingServerResponse = false; Repaint(); }; #if UPLOAD_MOD_BINARY_AS_DIRECTORY ModManager.UploadModBinaryDirectory(profile.modId, buildProfile, buildFilePath, true, mf => NotifySubmissionSucceeded(updatedProfile.name, updatedProfile.profileURL), onSubmissionFailed); #else ModManager.UploadModBinary_Unzipped(profile.modId, buildProfile, buildFilePath, true, mf => NotifySubmissionSucceeded(updatedProfile.name, updatedProfile.profileURL), onSubmissionFailed); #endif } else { NotifySubmissionSucceeded(updatedProfile.name, updatedProfile.profileURL); } }
// ------[ 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; LocalUser.instance = new LocalUser(); LocalUser.Save(); 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(!LocalDataStorage.GetDirectoryExists(buildFilePath))) #else using (new EditorGUI.DisabledScope(!LocalDataStorage.GetFileExists(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(); } } }
// ---------[ GUI FUNCTIONALITY ]--------- public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { int gameId = property.serializedObject.FindProperty("m_data.gameId").intValue; // render base field Rect basePropertyRect = position; basePropertyRect.height = position.height - EditorGUIUtility.singleLineHeight; EditorGUI.PropertyField(basePropertyRect, property, label); // draw unwrapped directory string dir = property.stringValue; dir = PluginSettings.ReplaceDirectoryVariables(dir, gameId); Rect previewRect = position; previewRect.width = position.width - BUTTON_WIDTH; previewRect.y = basePropertyRect.height + basePropertyRect.y; previewRect.height = EditorGUIUtility.singleLineHeight; Rect buttonRect = previewRect; buttonRect.x = previewRect.xMax; buttonRect.width = BUTTON_WIDTH; using (new EditorGUI.DisabledScope(true)) { // NOTE(@jackson): The second param of GUIContent is a tooltip EditorGUI.LabelField(previewRect, new GUIContent(dir, dir)); } bool directoryIsValid = false; try { string testDir = dir; while (!directoryIsValid && !string.IsNullOrEmpty(testDir)) { testDir = Path.GetDirectoryName(testDir); directoryIsValid = LocalDataStorage.GetDirectoryExists(testDir); } } catch { directoryIsValid = false; } using (new EditorGUI.DisabledScope(!directoryIsValid)) { string toolTip = null; if (directoryIsValid) { toolTip = "Locate directory"; } else { toolTip = "Invalid directory"; } if (GUI.Button(buttonRect, new GUIContent("...", toolTip))) { if (!LocalDataStorage.GetDirectoryExists(dir)) { LocalDataStorage.CreateDirectory(dir); } if (dir.StartsWith(Application.dataPath)) { string assetDir = dir.Substring(Application.dataPath.Length); assetDir = "Assets" + assetDir; var folderObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(assetDir); int folderId = folderObject.GetInstanceID(); EditorGUIUtility.PingObject(folderId); UnityEditor.Selection.activeObject = folderObject; } else { EditorUtility.RevealInFinder(dir); } } } }