Example #1
0
        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;
            }
        }
Example #2
0
        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;
            }
        }
Example #3
0
        // ------[ 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();
            }
        }
Example #4
0
        // - Image Locator Layouting -
        private void LayoutGalleryImageProperty(int elementIndex,
                                                SerializedProperty elementProperty)
        {
            bool   doBrowse      = false;
            bool   doClear       = false;
            string imageFileName = elementProperty.FindPropertyRelative("fileName").stringValue;
            string imageSource   = elementProperty.FindPropertyRelative("url").stringValue;

            // - Browse Field -
            EditorGUILayout.BeginHorizontal();
            doBrowse |= EditorGUILayoutExtensions.BrowseButton(imageSource,
                                                               new GUIContent("Image " + elementIndex));
            doClear = EditorGUILayoutExtensions.ClearButton();
            EditorGUILayout.EndHorizontal();

            // - Draw Texture -
            Texture2D imageTexture = GetGalleryImageByIndex(elementIndex);

            if (imageTexture != null)
            {
                EditorGUI.indentLevel += 2;
                EditorGUILayout.LabelField("File Name", imageFileName);
                Rect imageRect = EditorGUILayout.GetControlRect(false, 180.0f);
                imageRect = EditorGUI.IndentedRect(imageRect);
                EditorGUI.DrawPreviewTexture(new Rect(imageRect.x,
                                                      imageRect.y,
                                                      320.0f,
                                                      imageRect.height),
                                             imageTexture, null, ScaleMode.ScaleAndCrop);
                doBrowse |= GUI.Button(imageRect, "", GUI.skin.label);
                EditorGUI.indentLevel -= 2;
            }

            if (doBrowse)
            {
                EditorApplication.delayCall += () =>
                {
                    string path = EditorUtility.OpenFilePanelWithFilters("Select Gallery Image",
                                                                         "",
                                                                         ModMediaViewPart.IMAGE_FILE_FILTER);

                    bool   success = false;
                    byte[] data    = null;

                    success = LocalDataStorage.ReadFile(path, out data);

                    Texture2D newTexture = null;
                    if (success)
                    {
                        newTexture = IOUtilities.ParseImageData(data);
                    }

                    if (newTexture != null)
                    {
                        string fileName = GenerateUniqueFileName(path);

                        elementProperty.FindPropertyRelative("url").stringValue      = path;
                        elementProperty.FindPropertyRelative("fileName").stringValue = fileName;

                        galleryImagesProp.FindPropertyRelative("isDirty").boolValue = true;
                        galleryImagesProp.serializedObject.ApplyModifiedProperties();

                        textureCache.Add(fileName, newTexture);
                    }
                };
            }
            if (doClear)
            {
                elementProperty.FindPropertyRelative("url").stringValue      = string.Empty;
                elementProperty.FindPropertyRelative("fileName").stringValue = string.Empty;

                galleryImagesProp.FindPropertyRelative("isDirty").boolValue = true;
                galleryImagesProp.serializedObject.ApplyModifiedProperties();
            }
        }
Example #5
0
        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;
                    }
                }
            }
        }
Example #6
0
        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);
            }
        }
Example #7
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;

                                    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(!Directory.Exists(buildFilePath)))
                    #else
                    using (new EditorGUI.DisabledScope(!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();
                }
            }
        }