예제 #1
0
        public static Texture2D LoadModLogo(int modId, LogoSize size)
        {
            string    logoFilePath = CacheClient.GenerateModLogoFilePath(modId, size);
            Texture2D logoTexture  = CacheClient.ReadImageFile(logoFilePath);

            return(logoTexture);
        }
예제 #2
0
        public static Texture2D LoadModGalleryImage(int modId,
                                                    string imageFileName,
                                                    ModGalleryImageSize size)
        {
            string imageFilePath = CacheClient.GenerateModGalleryImageFilePath(modId,
                                                                               imageFileName,
                                                                               size);
            Texture2D imageTexture = CacheClient.ReadImageFile(imageFilePath);

            return(imageTexture);
        }
예제 #3
0
        // ------[ INITIALIZATION ]------
        public void OnEnable(SerializedProperty serializedEditableModProfile, ModProfile baseProfile, UserProfile user)
        {
            this.profile           = baseProfile;
            this.youtubeURLsProp   = serializedEditableModProfile.FindPropertyRelative("youtubeURLs");
            this.sketchfabURLsProp = serializedEditableModProfile.FindPropertyRelative("sketchfabURLs");
            this.galleryImagesProp = serializedEditableModProfile.FindPropertyRelative("galleryImageLocators");

            this.isYouTubeExpanded   = false;
            this.isSketchFabExpanded = false;
            this.isImagesExpanded    = false;

            // Initialize textureCache
            this.textureCache = new Dictionary <string, Texture2D>(galleryImagesProp.FindPropertyRelative("value").arraySize);
            for (int i = 0;
                 i < galleryImagesProp.FindPropertyRelative("value").arraySize;
                 ++i)
            {
                string imageFileName = GetGalleryImageFileName(i);
                string imageURL      = GetGalleryImageSource(i);

                if (!String.IsNullOrEmpty(imageFileName) &&
                    !String.IsNullOrEmpty(imageURL))
                {
                    this.textureCache[imageFileName] = ApplicationImages.LoadingPlaceholder;

                    Texture2D texture = CacheClient.ReadImageFile(imageURL);

                    if (texture != null)
                    {
                        this.textureCache[imageFileName] = texture;
                    }
                    else
                    {
                        ModManager.GetModGalleryImage(baseProfile,
                                                      imageFileName,
                                                      IMAGE_PREVIEW_SIZE,
                                                      (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; },
                                                      WebRequestError.LogAsWarning);
                    }
                }
            }
        }
 // ------[ UPDATE ]------
 public void OnUpdate()
 {
     if (File.Exists(logoLocation))
     {
         try
         {
             FileInfo imageInfo = new FileInfo(logoLocation);
             if (lastLogoWriteTime < imageInfo.LastWriteTime)
             {
                 logoTexture       = CacheClient.ReadImageFile(logoLocation);
                 lastLogoWriteTime = imageInfo.LastWriteTime;
             }
         }
         catch (Exception e)
         {
             Debug.LogWarning("[mod.io] Unable to read updates to the logo image file.\n\n"
                              + Utility.GenerateExceptionDebugString(e));
         }
     }
 }
        // ------[ INITIALIZATION ]------
        public void OnEnable(SerializedProperty serializedEditableModProfile, ModProfile baseProfile, UserProfile user)
        {
            this.editableProfileProperty = serializedEditableModProfile;
            this.profile       = baseProfile;
            this.isUndoEnabled = (baseProfile != null);

            isTagsExpanded = false;
            isKVPsExpanded = false;

            // - Game Profile -
            ModManager.GetGameProfile((g) => { this.gameProfile = g; isRepaintRequired = true; },
                                      null);

            // - Configure Properties -
            logoProperty = editableProfileProperty.FindPropertyRelative("logoLocator");

            // - Load Textures -
            if (logoProperty.FindPropertyRelative("isDirty").boolValue == true)
            {
                logoLocation = logoProperty.FindPropertyRelative("value.url").stringValue;
                logoTexture  = CacheClient.ReadImageFile(logoLocation);
                if (logoTexture != null)
                {
                    lastLogoWriteTime = (new FileInfo(logoLocation)).LastWriteTime;
                }
            }
            else if (profile != null)
            {
                logoLocation = profile.logoLocator.GetSizeURL(LOGO_PREVIEW_SIZE);
                logoTexture  = ApplicationImages.LoadingPlaceholder;

                ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE,
                                      (t) => { logoTexture = t; isRepaintRequired = true; },
                                      WebRequestError.LogAsWarning);
            }
            else
            {
                logoLocation = string.Empty;
                logoTexture  = null;
            }
        }
예제 #6
0
        private Texture2D GetGalleryImageTexture(string imageFileName,
                                                 string imageSource)
        {
            if (String.IsNullOrEmpty(imageFileName))
            {
                return(null);
            }

            Texture2D texture;

            // - Get -
            if (this.textureCache.TryGetValue(imageFileName, out texture))
            {
                return(texture);
            }
            // - Load -
            else if ((texture = CacheClient.ReadImageFile(imageSource)) != null)
            {
                this.textureCache.Add(imageFileName, texture);
                return(texture);
            }
            // - LoadOrDownload -
            else if (profile != null)
            {
                this.textureCache.Add(imageFileName, ApplicationImages.LoadingPlaceholder);

                ModManager.GetModGalleryImage(profile,
                                              imageFileName,
                                              IMAGE_PREVIEW_SIZE,
                                              (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; },
                                              null);
                return(this.textureCache[imageFileName]);
            }

            return(null);
        }
        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,
                                                               null);
                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 = CacheClient.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  = ApplicationImages.LoadingPlaceholder;

                ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE,
                                      (t) => { logoTexture = t; isRepaintRequired = true; },
                                      WebRequestError.LogAsWarning);
            }
        }
예제 #8
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 = GetGalleryImageTexture(imageFileName, imageSource);

            if (imageTexture != null)
            {
                EditorGUI.indentLevel += 2;
                EditorGUILayout.LabelField("File Name", imageFileName);
                Rect imageRect = EditorGUILayout.GetControlRect(false, 180.0f, null);
                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);
                    Texture2D newTexture = CacheClient.ReadImageFile(path);

                    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();
            }
        }