/// <summary>
        /// Charge une matrice de régions
        /// </summary>
        /// <param name="dimensions">Dimensions de la scène</param>
        /// <param name="hotspots">Liste de hotspots</param>
        /// <param name="matrixPrecision"></param>
        /// <returns>Matrice d'octets</returns>
        public void CreateRegionMatrix(VO_Stage stage, System.Drawing.Size dimensions, List <VO_StageRegion> hotspots, int matrixPrecision)
        {
            if (!Directory.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes)))
            {
                Directory.CreateDirectory(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes));
            }
            StreamWriter sw = new StreamWriter(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_r");

            byte[,] matrix = new byte[4096, 4096];

            int height = dimensions.Height / matrixPrecision;
            int width  = dimensions.Width / matrixPrecision;

            for (int y = 0; y <= height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    matrix[x, y] = (byte)stage.Region;
                    foreach (VO_StageRegion hotspot in hotspots)
                    {
                        if (FormsTools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points)))
                        {
                            matrix[x, y] = (byte)ConvertTools.CastInt(hotspot.Ratio);
                        }
                    }
                    sw.Write(GetValueFromByte(matrix[x, y]));
                }
                sw.Write("\r\n");
            }
            sw.Close();
        }
        /// <summary>
        /// Lors de la fermeture du ressource manager
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ResourcesManager_FormClosing(object sender, FormClosingEventArgs e)
        {
            FormsManager.Instance.ResourcesManager.FormClosing -= new FormClosingEventHandler(ResourcesManager_FormClosing);
            CurrentAnimation.ResourcePath = FormsManager.Instance.ResourcesManager.SelectedFilePath;
            LoadAnimation(CurrentAnimation.Id);

            if (AnimationType == Enums.AnimationType.CharacterAnimation)
            {
                int newValue = _OriginalResourceSize.Height / GameCore.Instance.Game.Project.MovementDirections;
                if (newValue <= 0)
                {
                    newValue = 1;
                }
                ddpSpriteH.Value = newValue;
            }
            _CurrentSprite.Y = ConvertTools.CastInt(ddpRows.Value) * _CurrentSprite.Height;
        }
예제 #3
0
 /// <summary>
 /// Charge une matrice de régions
 /// </summary>
 /// <param name="dimensions">Dimensions de la scène</param>
 /// <param name="hotspots">Liste de hotspots</param>
 /// <param name="matrixPrecision"></param>
 /// <returns>Matrice d'octets</returns>
 public void LoadRegionMatrix(System.Drawing.Size dimensions, List <VO_StageRegion> hotspots, int matrixPrecision)
 {
     if (!_RegionsCreated)
     {
         int height = dimensions.Height / matrixPrecision;
         int width  = dimensions.Width / matrixPrecision;
         if (File.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + _Stage.Id.ToString() + "_r"))
         {
             StreamReader myFile = new StreamReader(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + _Stage.Id.ToString() + "_r");
             for (int y = 0; y < height; y++)
             {
                 string line = myFile.ReadLine();
                 for (int x = 0; x < width; x++)
                 {
                     int nX = 3 * x;
                     _RegionsMatrix[x, y] = Convert.ToByte(line[nX].ToString() + line[nX + 1].ToString() + line[nX + 2].ToString());
                 }
             }
             myFile.Close();
         }
         else
         {
             for (int y = 0; y <= height; y++)
             {
                 for (int x = 0; x < width; x++)
                 {
                     _RegionsMatrix[x, y] = (byte)_Stage.Region;
                     foreach (VO_StageRegion hotspot in hotspots)
                     {
                         if (Tools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points)))
                         {
                             _RegionsMatrix[x, y] = (byte)ConvertTools.CastInt(hotspot.Ratio);
                         }
                     }
                 }
             }
         }
         _RegionsCreated = true;
     }
 }
예제 #4
0
 /// <summary>
 /// La valeur du textbox a changé
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void ddpValue_ValueChanged(object sender, EventArgs e)
 {
     CurrentVariable.Value = ConvertTools.CastInt(ddpValue.Value);
 }
 /// <summary>
 /// Déplace le curseur d'animation sur une autre ligne.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ddpRows_ValueChanged(object sender, EventArgs e)
 {
     _CurrentSprite.Y     = Convert.ToInt32(ddpRows.Value) * _CurrentSprite.Height;
     CurrentAnimation.Row = ConvertTools.CastInt(ddpRows.Value);
     ResetPreview(false);
 }
        /// <summary>
        /// Méthode qui charge l'animation courante
        /// </summary>
        public void LoadAnimation(Guid guid)
        {
            Cursor.Current = Cursors.WaitCursor;

            //Suppression des eventhandler
            this.ddpSpriteW.ValueChanged   -= new System.EventHandler(this.ddpSpriteW_ValueChanged);
            this.ddpSpriteH.ValueChanged   -= new System.EventHandler(this.ddpSpriteH_ValueChanged);
            this.ddpFrequency.ValueChanged -= new System.EventHandler(this.ddpFrequency_ValueChanged);
            this.ddpRows.ValueChanged      -= new System.EventHandler(this.ddpRows_ValueChanged);
            this.txtName.TextChanged       -= new System.EventHandler(this.txtName_TextChanged);

            //Stop Timer
            _FrequencyTimer.Stop();

            //Anim courante
            if (AnimationType == Enums.AnimationType.CharacterAnimation)
            {
                CurrentAnimation = _Service.LoadVOObject(ParentCharacter, guid);
            }
            else
            {
                CurrentAnimation = _Service.LoadVOObject(AnimationType, guid);
            }

            if (CurrentAnimation.ResourcePath != null)
            {
                //Mise en place du sprite root.
                _CurrentSprite.X      = 0;
                _CurrentSprite.Width  = CurrentAnimation.SpriteWidth;
                _CurrentSprite.Height = CurrentAnimation.SpriteHeight;
                _CurrentSprite.Y      = CurrentAnimation.Row * CurrentAnimation.SpriteHeight;
                if (!string.IsNullOrEmpty(CurrentAnimation.ResourcePath))
                {
                    _Service.LoadSurfaceFromURI(PathTools.GetProjectPath(AnimationType) + CurrentAnimation.ResourcePath);
                }
                else
                {
                    _Service.LoadSurfaceFromURI(string.Empty);
                }

                //Timer
                _FrequencyTimer.Interval = 10000 / CurrentAnimation.Frequency;
                _FrequencyTimer.Start();
            }
            else
            {
                _Service.LoadEmptySurface();
                _CurrentSprite.X              = 0;
                CurrentAnimation.SpriteWidth  = 1;
                CurrentAnimation.SpriteHeight = 1;
                _CurrentSprite.Width          = CurrentAnimation.SpriteWidth;
                _CurrentSprite.Height         = CurrentAnimation.SpriteHeight;
            }

            //Récupération de la taille de la ressource originale
            _OriginalResourceSize = _Service.GetSizeOfResource();

            //Mise à niveau de la taille des sprites
            if (CurrentAnimation.SpriteWidth > _OriginalResourceSize.Width)
            {
                CurrentAnimation.SpriteWidth = _OriginalResourceSize.Width;
            }
            if (CurrentAnimation.SpriteHeight > _OriginalResourceSize.Height)
            {
                CurrentAnimation.SpriteHeight = _OriginalResourceSize.Height;
            }

            //Mise en place des contrôles
            txtName.Text = CurrentAnimation.Title;

            _NbrRows = GetNbrRowsFromResource();
            if (_NbrRows > 0)
            {
                ddpRows.Maximum = _NbrRows - 1;
            }
            if (CurrentAnimation.Row > ddpRows.Maximum)
            {
                CurrentAnimation.Row = ConvertTools.CastInt(ddpRows.Maximum);
            }
            ddpRows.Value      = CurrentAnimation.Row;
            ddpFrequency.Value = CurrentAnimation.Frequency;
            _CurrentWidth      = CurrentAnimation.SpriteWidth;
            _CurrentHeight     = CurrentAnimation.SpriteHeight;
            ddpSpriteW.Maximum = _OriginalResourceSize.Width;
            ddpSpriteH.Maximum = _OriginalResourceSize.Height;
            if (CurrentAnimation.SpriteWidth > ddpSpriteW.Maximum)
            {
                ddpSpriteW.Value = ddpSpriteW.Maximum;
            }
            else
            {
                ddpSpriteW.Value = CurrentAnimation.SpriteWidth;
            }
            if (CurrentAnimation.SpriteHeight > ddpSpriteH.Maximum)
            {
                ddpSpriteH.Value = ddpSpriteH.Maximum;
            }
            else
            {
                ddpSpriteH.Value = CurrentAnimation.SpriteHeight;
            }

            if (CurrentAnimation.ParentCharacter != new Guid())
            {
                ddpRows.Enabled    = false;
                ddpSpriteH.Enabled = false;
                lblRows.Enabled    = false;
                lblX.Enabled       = false;
            }
            else
            {
                ddpRows.Enabled    = true;
                ddpSpriteH.Enabled = true;
                lblRows.Enabled    = true;
                lblX.Enabled       = true;
            }

            this.ddpSpriteW.ValueChanged   += new System.EventHandler(this.ddpSpriteW_ValueChanged);
            this.ddpSpriteH.ValueChanged   += new System.EventHandler(this.ddpSpriteH_ValueChanged);
            this.ddpFrequency.ValueChanged += new System.EventHandler(this.ddpFrequency_ValueChanged);
            this.ddpRows.ValueChanged      += new System.EventHandler(this.ddpRows_ValueChanged);
            this.txtName.TextChanged       += new System.EventHandler(this.txtName_TextChanged);

            grpInformations.Visible = true;
            grpPreview.Visible      = true;
            grpResource.Visible     = true;

            RefreshPreview();

            Cursor.Current = DefaultCursor;
        }
예제 #7
0
 /// <summary>
 /// Grid Height
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ddpGridHeight_ValueChanged(object sender, EventArgs e)
 {
     Menu.GridHeight             = ConvertTools.CastInt(ddpGridHeight.Value);
     crdInventoryPosition.Coords = new Rectangle(Menu.InventoryCoords, new Size(Menu.GridWidth * Menu.ItemWidth, Menu.GridHeight * Menu.ItemHeight));
     Menu.Update();
 }