// ---------[ SUPER JANKY ]--------- protected virtual void LayoutNameIDField() { bool isDirty = false; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Profile URL"); EditorGUILayout.LabelField("@", GUILayout.Width(13)); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(editableProfileProperty.FindPropertyRelative("nameId.value"), GUIContent.none); isDirty = EditorGUI.EndChangeCheck(); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); editableProfileProperty.FindPropertyRelative("nameId.isDirty").boolValue |= isDirty; if (isUndoRequested) { editableProfileProperty.FindPropertyRelative("nameId.value").stringValue = profile.nameId; editableProfileProperty.FindPropertyRelative("nameId.isDirty").boolValue = false; } }
protected virtual void LayoutMetadataKVPField() { SerializedProperty mkvpsProp = editableProfileProperty.FindPropertyRelative("metadataKVPs.value"); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginVertical(); EditorGUILayoutExtensions.CustomLayoutArrayPropertyField(mkvpsProp, "Metadata KVPs", ref isKVPsExpanded, LayoutMetadataKVPEntryField); EditorGUILayout.EndVertical(); bool isDirty = EditorGUI.EndChangeCheck(); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); editableProfileProperty.FindPropertyRelative("metadataKVPs.isDirty").boolValue |= isDirty; if (isUndoRequested) { mkvpsProp.arraySize = profile.metadataKVPs.Length; for (int i = 0; i < profile.metadataKVPs.Length; ++i) { mkvpsProp.GetArrayElementAtIndex(i).FindPropertyRelative("key").stringValue = profile.metadataKVPs[i].key; mkvpsProp.GetArrayElementAtIndex(i).FindPropertyRelative("value").stringValue = profile.metadataKVPs[i].value; } editableProfileProperty.FindPropertyRelative("metadataKVPs.isDirty").boolValue = false; } }
// ---------[ TEXT AREAS ]--------- protected void LayoutEditablePropertyTextArea(string fieldName, SerializedProperty fieldProperty, int characterLimit, out bool isUndoRequested) { SerializedProperty fieldValueProperty = fieldProperty.FindPropertyRelative("value"); int charCount = fieldValueProperty.stringValue.Length; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(fieldName); EditorGUILayout.LabelField("[" + (characterLimit - charCount).ToString() + " characters remaining]"); isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); fieldValueProperty.stringValue = EditorGUILayoutExtensions.MultilineTextField(fieldValueProperty.stringValue); if (EditorGUI.EndChangeCheck()) { if (fieldValueProperty.stringValue.Length > characterLimit) { fieldValueProperty.stringValue = fieldValueProperty.stringValue.Substring(0, characterLimit); } fieldProperty.FindPropertyRelative("isDirty").boolValue = true; } }
protected virtual void LayoutHomepageField() { EditorGUILayout.BeginHorizontal(); LayoutEditablePropertySimple("Homepage", editableProfileProperty.FindPropertyRelative("homepageURL")); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); if (isUndoRequested) { editableProfileProperty.FindPropertyRelative("homepageURL.value").stringValue = profile.homepageURL; editableProfileProperty.FindPropertyRelative("homepageURL.isDirty").boolValue = false; } }
protected virtual void LayoutVisibilityField() { EditorGUILayout.BeginHorizontal(); LayoutEditablePropertySimple("Visibility", editableProfileProperty.FindPropertyRelative("visibility")); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); if (isUndoRequested) { editableProfileProperty.FindPropertyRelative("visibility.value").intValue = (int)profile.visibility; editableProfileProperty.FindPropertyRelative("visibility.isDirty").boolValue = false; } }
// ------[ GUI ]------ public void OnGUI() { isRepaintRequired = false; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Media"); GUILayout.FlexibleSpace(); using (new EditorGUI.DisabledScope(profile == null)) { if (EditorGUILayoutExtensions.UndoButton()) { ResetModMedia(); } } EditorGUILayout.EndHorizontal(); using (new EditorGUI.IndentLevelScope()) { // - YouTube - EditorGUI.BeginChangeCheck(); EditorGUILayoutExtensions.ArrayPropertyField(youTubeURLsProp.FindPropertyRelative("value"), "YouTube Links", ref isYouTubeExpanded); youTubeURLsProp.FindPropertyRelative("isDirty").boolValue |= EditorGUI.EndChangeCheck(); // - SketchFab - EditorGUI.BeginChangeCheck(); EditorGUILayoutExtensions.ArrayPropertyField(sketchfabURLsProp.FindPropertyRelative("value"), "SketchFab Links", ref isSketchFabExpanded); sketchfabURLsProp.FindPropertyRelative("isDirty").boolValue |= EditorGUI.EndChangeCheck(); // - Gallery Images - EditorGUI.BeginChangeCheck(); EditorGUILayoutExtensions.CustomLayoutArrayPropertyField(galleryImagesProp.FindPropertyRelative("value"), "Gallery Images Links", ref isImagesExpanded, LayoutGalleryImageProperty); galleryImagesProp.FindPropertyRelative("isDirty").boolValue |= EditorGUI.EndChangeCheck(); } }
protected virtual void LayoutTagsField() { using (new EditorGUI.DisabledScope(this.gameProfile == null)) { EditorGUILayout.BeginHorizontal(); this.isTagsExpanded = EditorGUILayout.Foldout(this.isTagsExpanded, "Tags", true); GUILayout.FlexibleSpace(); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); if (this.isTagsExpanded) { if (this.gameProfile == null) { EditorGUILayout.HelpBox("The Game's Profile is not yet loaded, and thus tags cannot be displayed. Please wait...", MessageType.Warning); } else if (this.gameProfile.tagCategories.Length == 0) { EditorGUILayout.HelpBox("The developers of " + this.gameProfile.name + " have not designated any tagging options", MessageType.Info); } else { var tagsProperty = editableProfileProperty.FindPropertyRelative("tags.value"); var oldSelectedTags = new List <string>(EditorUtilityExtensions.GetSerializedPropertyStringArray(tagsProperty)); var newSelectedTags = new List <string>(); bool isDirty = false; ++EditorGUI.indentLevel; foreach (ModTagCategory tagCategory in this.gameProfile.tagCategories) { if (!tagCategory.isHidden) { using (var check = new EditorGUI.ChangeCheckScope()) { var categoryTags = LayoutTagCategoryField(tagCategory, oldSelectedTags); newSelectedTags.AddRange(categoryTags); isDirty |= check.changed; } } } --EditorGUI.indentLevel; if (isDirty || newSelectedTags.Count < oldSelectedTags.Count) { EditorUtilityExtensions.SetSerializedPropertyStringArray(tagsProperty, newSelectedTags.ToArray()); editableProfileProperty.FindPropertyRelative("tags.isDirty").boolValue = true; } } if (isUndoRequested) { var tagsProperty = editableProfileProperty.FindPropertyRelative("tags.value"); EditorUtilityExtensions.SetSerializedPropertyStringArray(tagsProperty, profile.tagNames.ToArray()); editableProfileProperty.FindPropertyRelative("tags.isDirty").boolValue = false; } } } }
protected virtual void LayoutLogoField() { bool doBrowse = false; // - Browse Field - EditorGUILayout.BeginHorizontal(); doBrowse |= EditorGUILayoutExtensions.BrowseButton(logoLocation, new GUIContent("Logo")); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); // - Draw Texture - if (logoTexture != null) { Rect logoRect = EditorGUILayout.GetControlRect(false, LOGO_PREVIEW_HEIGHT); EditorGUI.DrawPreviewTexture(new Rect((logoRect.width - LOGO_PREVIEW_WIDTH) * 0.5f, logoRect.y, LOGO_PREVIEW_WIDTH, logoRect.height), logoTexture, null, ScaleMode.ScaleAndCrop); doBrowse |= GUI.Button(logoRect, "", GUI.skin.label); } if (doBrowse) { EditorApplication.delayCall += () => { string path = EditorUtility.OpenFilePanelWithFilters("Select Mod Logo", "", IMAGE_FILE_FILTER); Texture2D newLogoTexture = IOUtilities.ReadImageFile(path); if (newLogoTexture) { logoProperty.FindPropertyRelative("value.url").stringValue = path; logoProperty.FindPropertyRelative("value.fileName").stringValue = Path.GetFileName(path); logoProperty.FindPropertyRelative("isDirty").boolValue = true; logoProperty.serializedObject.ApplyModifiedProperties(); logoTexture = newLogoTexture; logoLocation = path; lastLogoWriteTime = (new FileInfo(logoLocation)).LastWriteTime; } }; } if (isUndoRequested) { logoProperty.FindPropertyRelative("value.url").stringValue = profile.logoLocator.GetURL(); logoProperty.FindPropertyRelative("value.fileName").stringValue = profile.logoLocator.GetFileName(); logoProperty.FindPropertyRelative("isDirty").boolValue = false; logoLocation = profile.logoLocator.GetSizeURL(LOGO_PREVIEW_SIZE); logoTexture = EditorImages.LoadingPlaceholder; ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE, (t) => { logoTexture = t; isRepaintRequired = true; }, WebRequestError.LogAsWarning); } }