示例#1
0
        /// <summary>
        /// Récupérer une image resource
        /// </summary>
        /// <param name="url">Url de l'image</param>
        /// <returns>Image</returns>
        public static Texture2D GetPermanentMenu(int width, int height, ViewerEnums.MenuType type)
        {
            //Dictionnaire d'image
            if (_PermanentResources == null)
            {
                _PermanentResources = new Dictionary <string, Texture2D>();
            }

            string serial = "MENU|" + VO_GUI.RefResource + ";" + width + ";" + height + ";" + type.ToString();

            //Création et ajout de l'image si non présente dans le dictionnaire
            if (!_PermanentResources.ContainsKey(serial))
            {
                CreateMenu(width, height, type);
            }

            //Renvoie de l'image
            try
            {
                return(_PermanentResources[serial]);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_KEY_NOT_FOUND, serial));
                LogTools.WriteDebug(e.Message);
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Crée une nouvelle image background
        /// </summary>
        /// <param name="url">Url de l'image</param>
        public static void CreateNewImageBackground(VO_BackgroundSerial serial)
        {
            //Dictionnaire d'image
            if (_ImagesBackgrounds == null)
            {
                _ImagesBackgrounds = new Dictionary <string, Image>();
            }

            //Ajout de l'image
            string serialS = serial.ToString();

            if (!_ImagesBackgrounds.ContainsKey(serialS))
            {
                try
                {
                    Image mainBackground = null;

                    if (serial.Padding == 0)
                    {
                        mainBackground = new Bitmap(serial.Size.Width, serial.Size.Height, EditorConstants.PERF_EDITOR_BITSPERPIXEL);
                        Graphics graphic = Graphics.FromImage(mainBackground);
                        graphic.FillRectangle(EditorHelper.Instance.TransparentBrushes[serial.BlockSize], new Rectangle(new Point(0, 0), serial.Size));
                        graphic.Dispose();
                    }
                    else
                    {
                        int padding = serial.Padding * 2;
                        mainBackground = new Bitmap(serial.Size.Width + padding, serial.Size.Height + padding, EditorConstants.PERF_EDITOR_BITSPERPIXEL);
                        Graphics graphics = Graphics.FromImage(mainBackground);
                        graphics.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(new Point(0, 0), new Size(serial.Size.Width + padding, serial.Size.Height + padding)));

                        Image    temp = new Bitmap(serial.Size.Width, serial.Size.Height, EditorConstants.PERF_EDITOR_BITSPERPIXEL);
                        Graphics graphicBackground = Graphics.FromImage(temp);
                        graphicBackground.FillRectangle(EditorHelper.Instance.TransparentBrushes[serial.BlockSize], new Rectangle(new Point(0, 0), serial.Size));

                        graphics.DrawImage(temp, new Rectangle(new Point(serial.Padding, serial.Padding), serial.Size));

                        temp.Dispose();
                        graphicBackground.Dispose();
                        graphics.Dispose();
                    }

                    _ImagesBackgrounds.Add(serialS, mainBackground);
                    LogTools.WriteDebug(string.Format(Logs.MANAGER_IMAGE_CREATED, serial.ToString(), Logs.MANAGER_BACKGROUNDS));
                }
                catch (InsufficientMemoryException ie)
                {
                    LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR);
                    LogTools.WriteDebug(ie.Message);
                    ResetResources();
                    CreateNewImageBackground(serial);
                }
                catch (Exception e)
                {
                    LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, serial));
                    LogTools.WriteDebug(e.Message);
                    _ImagesBackgrounds.Add(serialS, NotFoundPicture);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Récupérer une image resource
        /// </summary>
        /// <param name="url">Url de l'image</param>
        /// <returns>Image</returns>
        public Texture2D GetScreenImage(string url)
        {
            //Pas d'image envoyée
            if (string.IsNullOrEmpty(url))
            {
                return(null);
            }

            //Dictionnaire d'image
            if (_ScreenResources == null)
            {
                _ScreenResources = new Dictionary <string, Texture2D>();
            }

            //Création et ajout de l'image si non présente dans le dictionnaire
            if (!_ScreenResources.ContainsKey(url))
            {
                CreateNewScreenImage(url);
            }

            //Renvoie de l'image
            try
            {
                return(_ScreenResources[url]);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_KEY_NOT_FOUND, url));
                LogTools.WriteDebug(e.Message);
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// Récupérer une image resource
        /// </summary>
        /// <param name="url">Url de l'image</param>
        /// <returns>Image</returns>
        public static Image GetImageStageDecor(string url)
        {
            //Pas d'image envoyée
            if (string.IsNullOrEmpty(url))
            {
                return(NotFoundPicture);
            }

            //Dictionnaire d'image
            if (_ImagesStageDecors == null)
            {
                _ImagesStageDecors = new Dictionary <string, Image>();
            }

            //Création et ajout de l'image si non présente dans le dictionnaire
            if (!_ImagesStageDecors.ContainsKey(url))
            {
                CreateNewImageStageDecor(url);
            }

            //Renvoie de l'image
            try
            {
                return(_ImagesStageDecors[url]);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_KEY_NOT_FOUND, url));
                LogTools.WriteDebug(e.Message);
                return(NotFoundPicture);
            }
        }
示例#5
0
        /// <summary>
        /// Récupérer une image resource
        /// </summary>
        /// <param name="url">Url de l'image</param>
        /// <returns>Image</returns>
        public static Image GetImageStageChar(Guid value)
        {
            //Pas d'image envoyée
            if (value == new Guid())
            {
                return(NotFoundPicture);
            }

            //Dictionnaire d'image
            if (_ImagesStageChars == null)
            {
                _ImagesStageChars = new Dictionary <Guid, Image>();
            }

            //Création et ajout de l'image si non présente dans le dictionnaire
            if (!_ImagesStageChars.ContainsKey(value))
            {
                CreateNewImageStageCharacter(value);
            }

            //Renvoie de l'image
            try
            {
                return(_ImagesStageChars[value]);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_KEY_NOT_FOUND, value));
                LogTools.WriteDebug(e.Message);
                return(NotFoundPicture);
            }
        }
示例#6
0
        /// <summary>
        /// Récupérer une image background
        /// </summary>
        /// <param name="url">Url de l'image</param>
        /// <returns>Image</returns>
        public static Image GetImageBackground(VO_BackgroundSerial serial)
        {
            //Pas d'image envoyée
            if (serial == null)
            {
                return(NotFoundPicture);
            }

            //Dictionnaire d'image
            if (_ImagesBackgrounds == null)
            {
                _ImagesBackgrounds = new Dictionary <string, Image>();
            }

            //Création et ajout de l'image si non présente dans le dictionnaire
            string serialS = serial.ToString();

            if (!_ImagesBackgrounds.ContainsKey(serialS))
            {
                CreateNewImageBackground(serial);
            }

            //Renvoie de l'image
            try
            {
                return(_ImagesBackgrounds[serialS]);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_KEY_NOT_FOUND, serial.ToString()));
                LogTools.WriteDebug(e.Message);
                return(NotFoundPicture);
            }
        }
示例#7
0
        /// <summary>
        /// Renvoie une image colorée
        /// </summary>
        /// <param name="url">Url de l'image</param>
        /// <param name="color">Modifications de couleur</param>
        /// <param name="type">Type de ressource</param>
        /// <returns>Image</returns>
        public Texture2D GetColoredImage(string url, VO_ColorTransformation color, ViewerEnums.ImageResourceType type)
        {
            string serial = url + ";" + color.ToString();

            if (_ColoredResources != null && _ColoredResources.ContainsKey(serial))
            {
                return(_ColoredResources[serial]);
            }

            //Dictionnaire d'image
            if (_ColoredResources == null)
            {
                _ColoredResources = new Dictionary <string, Texture2D>();
            }

            Texture2D originalImage = null;

            switch (type)
            {
            case ViewerEnums.ImageResourceType.Permanent:
                originalImage = GetPermanentImage(url);
                break;

            case ViewerEnums.ImageResourceType.Screen:
                originalImage = GetScreenImage(url);
                break;
            }

            try
            {
                //if (!color.IsUnmodifiedColor())
                //    ApplyColorFilters(serial, color, new Texture2D(url));
                //else
                _ColoredResources.Add(serial, originalImage);
                return(_ColoredResources[serial]);
            }
            catch (InsufficientMemoryException ie)
            {
                LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR);
                LogTools.WriteDebug(ie.Message);
                FreeScreenImages();
                return(GetColoredImage(url, color, type));
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, url));
                LogTools.WriteDebug(e.Message);
                _ColoredResources.Add(serial, null);
            }
            return(null);
        }
示例#8
0
 /// <summary>
 /// Supprimer une image
 /// </summary>
 /// <param name="url">Url de l'image</param>
 public void DeleteColoredImage(string url)
 {
     if (_ColoredResources.ContainsKey(url))
     {
         try
         {
             _ColoredResources[url].Dispose();
             _ColoredResources.Remove(url);
         }
         catch (Exception e)
         {
             LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, url));
             LogTools.WriteDebug(e.Message);
         }
     }
 }
示例#9
0
 /// <summary>
 /// Supprimer une image
 /// </summary>
 /// <param name="url">Url de l'image</param>
 public static void DeleteImageStageDecor(string url)
 {
     if (_ImagesStageDecors.ContainsKey(url))
     {
         try
         {
             _ImagesStageDecors[url].Dispose();
             _ImagesStageDecors.Remove(url);
         }
         catch (Exception e)
         {
             LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, url));
             LogTools.WriteDebug(e.Message);
         }
     }
 }
示例#10
0
 /// <summary>
 /// Supprimer une image
 /// </summary>
 /// <param name="url">Url de l'image</param>
 public static void DeleteImageStageChar(Guid value)
 {
     if (_ImagesStageChars.ContainsKey(value))
     {
         try
         {
             _ImagesStageChars[value].Dispose();
             _ImagesStageChars.Remove(value);
         }
         catch (Exception e)
         {
             LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, value));
             LogTools.WriteDebug(e.Message);
         }
     }
 }
 /// <summary>
 /// Supprimer un sprite
 /// </summary>
 /// <param name="id">Id du sprite</param>
 public static void DeleteScreenSprite(Guid id)
 {
     if (_ScreenSprites.ContainsKey(id))
     {
         try
         {
             _ScreenSprites[id].Dispose();
             _ScreenSprites.Remove(id);
         }
         catch (Exception e)
         {
             LogTools.WriteInfo(string.Format(Logs.MANAGER_SPRITE_NOT_FOUND, id));
             LogTools.WriteDebug(e.Message);
         }
     }
 }
        /// <summary>
        /// Crée un perso
        /// </summary>
        /// <param name="Character"></param>
        public static void CreatePlayer(Guid player)
        {
            if (_Players == null)
            {
                _Players = new Dictionary <Guid, VO_Player>();
            }

            try
            {
                VO_Player characterSprite = new VO_Player(GameCore.Instance.GetPlayableCharacterById(player));
                _Players.Add(player, characterSprite);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_CHARACTER_NOT_LOADED, player));
                LogTools.WriteDebug(e.Message);
            }
        }
示例#13
0
        /// <summary>
        /// Supprimer une image background
        /// </summary>
        /// <param name="url">Url de l'image</param>
        public static void DeleteImageBackground(VO_BackgroundSerial serial)
        {
            string serialS = serial.ToString();

            if (_ImagesBackgrounds.ContainsKey(serialS))
            {
                try
                {
                    _ImagesBackgrounds[serialS].Dispose();
                    _ImagesBackgrounds.Remove(serialS);
                }
                catch (Exception e)
                {
                    LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, serial.ToString()));
                    LogTools.WriteDebug(e.Message);
                }
            }
        }
示例#14
0
        /// <summary>
        /// Crée une image de menu
        /// </summary>
        /// <param name="width">Largeur du menu</param>
        /// <param name="height">Hauteur du menu</param>
        /// <param name="type">Type de menu (back ou front)</param>
        public static void CreateMenu(int width, int height, ViewerEnums.MenuType type)
        {
            //Dictionnaire d'image
            if (_PermanentResources == null)
            {
                _PermanentResources = new Dictionary <string, Texture2D>();
            }

            string serial = "MENU|" + VO_GUI.RefResource + ";" + width + ";" + height + ";" + type.ToString();

            //Ajout de l'image
            if (!_PermanentResources.ContainsKey(serial))
            {
                try
                {
                    switch (type)
                    {
                    case ViewerEnums.MenuType.Back:
                        _PermanentResources.Add(serial, CreateMenuBack(width, height));
                        break;

                    case ViewerEnums.MenuType.Front:
                        _PermanentResources.Add(serial, CreateMenuFront(width, height));
                        break;
                    }

                    LogTools.WriteDebug(string.Format(Logs.MANAGER_IMAGE_CREATED, serial, Logs.MANAGER_PERMANENT));
                }
                catch (InsufficientMemoryException ie)
                {
                    LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR);
                    LogTools.WriteDebug(ie.Message);
                    FreePermanentImages();
                    CreateMenu(width, height, type);
                }
                catch (Exception e)
                {
                    LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, serial));
                    LogTools.WriteDebug(e.Message);
                    _PermanentResources.Add(serial, null);
                }
            }
        }
        /// <summary>
        /// Récupérer le sprite resource
        /// </summary>
        /// <param name="id">Id du Sprite</param>
        /// <returns>Sprite</returns>
        public static VO_Sprite GetScreenSprite(Guid id)
        {
            //Pas d'image envoyée
            if (id == new Guid() || _ScreenSprites == null || !_ScreenSprites.ContainsKey(id))
            {
                return(null);
            }

            //Renvoie de l'image
            try
            {
                return(_ScreenSprites[id]);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_SPRITE_KEY_NOT_FOUND, id));
                LogTools.WriteDebug(e.Message);
                return(null);
            }
        }
示例#16
0
        /// <summary>
        /// Crée une nouvelle image
        /// </summary>
        /// <param name="url">Url de l'image</param>
        public static void CreateNewImageStageCharacter(Guid value)
        {
            //Dictionnaire d'image
            if (_ImagesStageChars == null)
            {
                _ImagesStageChars = new Dictionary <Guid, Image>();
            }

            //Pas d'image envoyée
            if (value == new Guid())
            {
                return;
            }

            //Ajout de l'image
            if (!_ImagesStageChars.ContainsKey(value))
            {
                try
                {
                    VO_Character charObject = GameCore.Instance.GetCharacterById(value);
                    VO_Animation animObject = GameCore.Instance.GetCharAnimationById(value, charObject.StandingAnim);
                    _ImagesStageChars.Add(value, FromFileThenClose(PathTools.GetProjectPath(Enums.AnimationType.CharacterAnimation) + animObject.ResourcePath));
                    LogTools.WriteDebug(string.Format(Logs.MANAGER_IMAGE_CREATED, value.ToString(), Logs.MANAGER_CHARS));
                }
                catch (InsufficientMemoryException ie)
                {
                    LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR);
                    LogTools.WriteDebug(ie.Message);
                    ResetResources();
                    CreateNewImageStageCharacter(value);
                }
                catch (Exception e)
                {
                    LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, value));
                    LogTools.WriteDebug(e.Message);
                    _ImagesStageChars.Add(value, NotFoundPicture);
                }
            }
        }
        /// <summary>
        /// Récupérer un personnage
        /// </summary>
        /// <param name="character">Guid du personnage</param>
        /// <param name="x">X de départ</param>
        /// <param name="y">Y de départ</param>
        /// <returns>Objet perso</returns>
        public static VO_Player GetPlayer(Guid character)
        {
            if (_Players == null)
            {
                _Players = new Dictionary <Guid, VO_Player>();
            }

            if (!_Players.ContainsKey(character))
            {
                CreatePlayer(character);
            }

            try
            {
                return(_Players[character]);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_CHARACTER_KEY_NOT_FOUND, character));
                LogTools.WriteDebug(e.Message);
                return(null);
            }
        }
示例#18
0
        /// <summary>
        /// Crée une nouvelle image
        /// </summary>
        /// <param name="url">Url de l'image</param>
        public static void CreateNewPermanentImage(string url)
        {
            //Dictionnaire d'image
            if (_PermanentResources == null)
            {
                _PermanentResources = new Dictionary <string, Texture2D>();
            }

            //Pas d'image envoyée
            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            //Ajout de l'image
            if (!_PermanentResources.ContainsKey(url))
            {
                try
                {
                    _PermanentResources.Add(url, FromFileThenClose(url));
                    LogTools.WriteDebug(string.Format(Logs.MANAGER_IMAGE_CREATED, url, Logs.MANAGER_PERMANENT));
                }
                catch (InsufficientMemoryException ie)
                {
                    LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR);
                    LogTools.WriteDebug(ie.Message);
                    FreePermanentImages();
                    CreateNewPermanentImage(url);
                }
                catch (Exception e)
                {
                    LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, url));
                    LogTools.WriteDebug(e.Message);
                    _PermanentResources.Add(url, null);
                }
            }
        }
示例#19
0
        /// <summary>
        /// Crée une nouvelle image
        /// </summary>
        /// <param name="url">Url de l'image</param>
        public static void CreateNewImageStageDecor(string url)
        {
            //Dictionnaire d'image
            if (_ImagesStageDecors == null)
            {
                _ImagesStageDecors = new Dictionary <string, Image>();
            }

            //Pas d'image envoyée
            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            //Ajout de l'image
            if (!_ImagesStageDecors.ContainsKey(url))
            {
                try
                {
                    _ImagesStageDecors.Add(url, FromFileThenClose(url));
                    LogTools.WriteDebug(string.Format(Logs.MANAGER_IMAGE_CREATED, url, Logs.MANAGER_DECORS));
                }
                catch (InsufficientMemoryException ie)
                {
                    LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR);
                    LogTools.WriteDebug(ie.Message);
                    ResetResources();
                    CreateNewImageStageDecor(url);
                }
                catch (Exception e)
                {
                    LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, url));
                    LogTools.WriteDebug(e.Message);
                    _ImagesStageDecors.Add(url, NotFoundPicture);
                }
            }
        }
示例#20
0
        /// <summary>
        /// Méthode delegate de try/catch
        /// </summary>
        /// <param name="method">Methode qui sera executée</param>
        /// <param name="errorMessage">Message d'erreur utilisateur</param>
        /// <param name="writelog">Doit écrire dans le log</param>
        /// <param name="values">Valeurs de log</param>
        protected void RunServiceTask(ServiceTask method, ServiceMemoryError memoryMethod, string errorMessage, bool writelog, params string[] values)
        {
            if (writelog)
            {
                EnteringMethodLogMessage(method.Method, values);
            }

            try
            {
                method();
            }
            catch (InsufficientMemoryException ie)
            {
                LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR);
                LogTools.WriteDebug(ie.Message);
                if (memoryMethod != null)
                {
                    memoryMethod();
                }
            }
            catch (Exception ex)
            {
                if (LogTools.IsDebugModeActive())
                {
                    MessageBox.Show(errorMessage + "\r\n" + Errors.ERROR_METHOD + method.Method.Name + ": " + ex.Message, Errors.ERROR_BOX_TITLE);
                    if (writelog)
                    {
                        LogTools.WriteDebug(errorMessage + "\r\n" + Errors.ERROR_METHOD + method.Method.Name + ": " + ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show(errorMessage, Errors.ERROR_BOX_TITLE);
                }
            }
        }
        /// <summary>
        /// Créer un sprite
        /// </summary>
        /// <param name="id">Id du sprite</param>
        /// <param name="url">Url de l'image</param>
        /// <param name="location">Location</param>
        /// <param name="color">Couleur</param>
        public static void CreateScreenSprite(Guid id, string url, Vector2 location, Rectangle source, VO_ColorTransformation color)
        {
            //Dictionnaire d'image
            if (_ScreenSprites == null)
            {
                _ScreenSprites = new Dictionary <Guid, VO_Sprite>();
            }

            //Pas d'image envoyée
            if (id == new Guid())
            {
                return;
            }

            //Ajout de l'image
            if (!_ScreenSprites.ContainsKey(id))
            {
                try
                {
                    VO_Sprite newSprite = new VO_Sprite(id);
                    newSprite.ResourceUrl = url;
                    newSprite.Scale       = new Vector2(1.0f, 1.0f);
                    newSprite.Image       = ImageManager.CurrentStage.GetScreenImage(url);
                    newSprite.Position    = new Vector2(location.X, location.Y);
                    newSprite.Source      = source;
                    _ScreenSprites.Add(id, newSprite);
                    LogTools.WriteDebug(string.Format(Logs.MANAGER_SPRITE_CREATED, id, Logs.MANAGER_SCREEN));
                }
                catch (Exception e)
                {
                    LogTools.WriteInfo(string.Format(Logs.MANAGER_SPRITE_NOT_FOUND, url));
                    LogTools.WriteDebug(e.Message);
                    _ScreenSprites.Add(id, null);
                }
            }
        }