예제 #1
0
파일: TilesMap.cs 프로젝트: nadar71/Krea
        public void CleanTileModel(TileModel model,bool removeGorgon,bool removeAsset, bool checkIntegrity)
        {
            if (model != null)
            {
                if (checkIntegrity == true)
                {
                    if (model.GorgonSprite != null)
                    {
                        if (model.GorgonSprite.Image != null)
                        {
                            bool isUsed = this.IsGorgonImageUsedInEntireTileMap(model.GorgonSprite.Image);
                            if (isUsed == false)
                            {

                                model.GorgonSprite.Image.Dispose();

                            }

                            model.GorgonSprite.Image = null;
                        }

                        model.GorgonSprite = null;
                    }
                }
                else
                {

                    if (model.GorgonSprite != null)
                    {
                        if (model.GorgonSprite.Image != null)
                        {
                            model.GorgonSprite.Image.Dispose();

                            model.GorgonSprite.Image = null;

                        }
                        model.GorgonSprite = null;
                    }
                }

                if (removeAsset == true)
                {
                    CoronaGameProject project = this.LayerParent.SceneParent.projectParent;
                    string assetPath = Path.Combine(project.ProjectPath + "\\Resources\\TileMaps\\" + this.TilesMapName
                                            , model.Name + ".png");
                    if (File.Exists(assetPath))
                    {
                        File.Delete(assetPath);
                    }
                }

                model = null;
            }
        }
예제 #2
0
        private void objectModelsPictBx_MouseClick(object sender, MouseEventArgs e)
        {
            if (this.currentTilesMap != null)
            {
                this.mainForm.tilesMapEditor1.CreationMode = "CREATING_MODELS";
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    Point pTouched = new Point(e.Location.X, e.Location.Y - this.objectModelsTrackBar.Value);
                    this.ModelSelected = getTileModelTouched(pTouched, this.currentTilesMap.TileModelsObjectsUsed);
                    if (this.ModelSelected != null)
                    {
                        if (this.ModelsSelection != null)
                        {
                            //Verifier si le control est actif : si oui ajouter a la liste
                            if (Control.ModifierKeys == Keys.Control)
                                this.ModelsSelection.ListModelsSelected.Add(this.ModelSelected);
                            else if (Control.ModifierKeys == Keys.Shift && this.ModelsSelection.ListModelsSelected.Count > 0)
                            {
                                List<TileModel> models = this.currentTilesMap.TileModelsObjectsUsed;
                                if (models != null)
                                {
                                    int indexLastModelSelected = models.IndexOf(this.ModelsSelection.ListModelsSelected[this.ModelsSelection.ListModelsSelected.Count - 1]);
                                    int indexTileModelTouched = models.IndexOf(this.ModelSelected);

                                    if (indexLastModelSelected >= 0 && indexTileModelTouched >= 0)
                                    {
                                        if (indexTileModelTouched > indexLastModelSelected)
                                        {
                                            this.ModelsSelection.ListModelsSelected.Clear();
                                            for (int i = indexLastModelSelected; i <= indexTileModelTouched; i++)
                                            {
                                                TileModel model = models[i];
                                                this.ModelsSelection.ListModelsSelected.Add(model);
                                            }
                                        }

                                    }

                                }

                            }
                            else
                            {
                                //SInn effacer la liste et ajouter le model
                                this.ModelsSelection.ListModelsSelected.Clear();
                                this.ModelsSelection.ListModelsSelected.Add(this.ModelSelected);

                            }
                        }
                    }

                    GorgonLibrary.Gorgon.Go();
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    this.objectModelsPictBx.ContextMenuStrip = this.modelsListMenuStrip;
                    this.modelsListMenuStrip.Show();
                }

            }
        }
예제 #3
0
파일: TilesMap.cs 프로젝트: nadar71/Krea
        public void applyTextureOnAllTiles(TileModel model)
        {
            for (int i = 0; i < this.NbLines; i++)
            {
                for (int j = 0; j < this.NbColumns; j++)
                {
                    if (model.IsTexture == true)
                        this.TabTiles[i, j].setTexture(model);
                    else
                        this.TabTiles[i, j].setObjectImage(model);

                }
            }
        }
예제 #4
0
파일: TilesMap.cs 프로젝트: nadar71/Krea
        public void applyTextureOnTilePointed(Point p,TileModel model)
        {
            Tile tileTouched = this.getTileAtLocation(p);
            if (tileTouched != null)
            {

                if (model.IsTexture == true)
                    tileTouched.setTexture(model);
                else
                    tileTouched.setObjectImage(model);
            }
        }
예제 #5
0
파일: TilesMap.cs 프로젝트: nadar71/Krea
        public void UpdateGorgonTileModel(TileModel model, bool shouldExport)
        {
            if (model != null)
            {
                if (shouldExport == true)
                {
                    this.ExportTileModelToProjectResources(model);
                }

                this.CleanTileModel(model, true, false, true);

                string projectPath = this.LayerParent.SceneParent.projectParent.ProjectPath;
                string filename = Path.Combine(projectPath + "\\Resources\\TileMaps\\" + this.TilesMapName
                                                   , model.Name + ".png");

                if (File.Exists(filename))
                {
                    GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(model.Name,
                        GorgonLibrary.Graphics.Image.FromFile(filename));

                    model.GorgonSprite = sprite;

                    sprite.Color = Color.White;

                }
            }
        }
예제 #6
0
파일: TilesMap.cs 프로젝트: nadar71/Krea
        public List<Tile> GetTileUsingTileModel(TileModel model)
        {
            if(this.TabTiles != null)
            {
                List<Tile> tilesUsingModels = new List<Tile>();
                for (int i = 0; i < this.NbLines; i++)
                {
                    for (int j = 0; j < this.NbColumns; j++)
                    {
                        Tile tile = this.TabTiles[i, j];
                        if (tile.TileModelImageObject != null && tile.TileModelImageObject == model)
                        {
                            tilesUsingModels.Add(tile);
                            continue;
                        }

                        if (tile.TileModelTexture != null && tile.TileModelTexture == model)
                        {
                            tilesUsingModels.Add(tile);
                            continue;
                        }

                        if (tile.TileTextureSequence != null && tile.TileTextureSequence.Frames.Contains(model))
                        {

                            tilesUsingModels.Add(tile);
                            continue;
                        }

                        if (tile.TileObjectSequence != null && tile.TileObjectSequence.Frames.Contains(model))
                        {
                            tilesUsingModels.Add(tile);
                            continue;
                        }
                    }
                }

                if (tilesUsingModels.Count > 0)
                    return tilesUsingModels;
                else return null;
            }

            return null;
        }
예제 #7
0
파일: TilesMap.cs 프로젝트: nadar71/Krea
        public void ExportTileModelToProjectResources(TileModel tileModel)
        {
            CoronaGameProject project = this.LayerParent.SceneParent.projectParent;
            if (project != null)
            {
                if (!Directory.Exists(project.ProjectPath + "\\Resources\\TileMaps\\"+this.TilesMapName))
                    Directory.CreateDirectory(project.ProjectPath + "\\Resources\\TileMaps\\" + this.TilesMapName);

                if (tileModel.Image != null)
                {

                    string filename = Path.Combine(project.ProjectPath + "\\Resources\\TileMaps\\" + this.TilesMapName
                                                    , tileModel.Name + ".png");

                    if (!File.Exists(filename))
                         tileModel.Image.Save(filename);

                    tileModel.Image.Dispose();
                    tileModel.Image = null;
                }
                else if (tileModel.GorgonSprite != null)
                {

                    if (tileModel.GorgonSprite.Image != null)
                    {
                        string filename = Path.Combine(project.ProjectPath + "\\Resources\\TileMaps\\" + this.TilesMapName
                                                        , tileModel.Name + ".png");

                        Image temp = tileModel.GorgonSprite.Image.SaveBitmap();
                        if (!File.Exists(filename))
                            temp.Save(filename);

                        temp.Dispose();
                        temp = null;
                    }
                }

            }
        }
예제 #8
0
        private void addToPaletteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.TilesSelection != null)
            {
                TilesMap currentMap = this.TilesSelection.TilesMapParent;
                if (currentMap != null)
                {
                    for (int i = 0; i < this.TilesSelection.ListModelsSelected.Count; i++)
                    {
                        TileModel model = this.TilesSelection.ListModelsSelected[i];

                        if (model != null)
                        {
                            string finalName = model.Name.Replace("_MODEL", "");
                            if (model.IsTexture == true)
                            {
                                if (!currentMap.IsTileModelExists(currentMap.TileModelsTextureUsed, finalName))
                                {
                                    //Clone gorgon image
                                    Image img = model.GorgonSprite.Image.SaveBitmap();
                                    GorgonLibrary.Graphics.Image newImage = GorgonLibrary.Graphics.Image.FromBitmap(finalName, img);
                                    GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(finalName, newImage);
                                    TileModel newModel = new TileModel(finalName, model.surfaceRect.Location, model.surfaceRect.Size,
                                            sprite, false, true);
                                    img.Dispose();
                                    img = null;

                                    currentMap.TileModelsTextureUsed.Add(newModel);
                                    currentMap.UpdateGorgonTileModel(newModel, true);

                                }
                            }
                            else
                            {
                                if (!currentMap.IsTileModelExists(currentMap.TileModelsObjectsUsed, finalName))
                                {
                                    //Clone gorgon image
                                    Image img = model.GorgonSprite.Image.SaveBitmap();
                                    GorgonLibrary.Graphics.Image newImage = GorgonLibrary.Graphics.Image.FromBitmap(finalName, img);
                                    GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(finalName, newImage);
                                    TileModel newModel = new TileModel(finalName, model.surfaceRect.Location, model.surfaceRect.Size,
                                            sprite, false, false);
                                    img.Dispose();
                                    img = null;

                                    currentMap.TileModelsObjectsUsed.Add(newModel);
                                    currentMap.UpdateGorgonTileModel(newModel, true);

                                }
                            }

                        }
                    }
                    GorgonLibrary.Gorgon.Go();
                }
            }
        }
예제 #9
0
        private void addTextureSetToList(string pathImage,string name,Size tilesSize)
        {
            TileSheetModel sheetModel = new TileSheetModel(name,pathImage, true);

            //Charger la texture set
            Bitmap textureSet = new Bitmap(Image.FromFile(pathImage));

            //Recuperer le nombre de texture par ligne et colonne
            int nbTexturesLigne = textureSet.Width / tilesSize.Width;
            int nbTexturesColonne = textureSet.Height / tilesSize.Height;

            //Creer et ajouter les textures
            for (int i = 0; i < nbTexturesColonne; i++)
            {
                for (int j = 0; j < nbTexturesLigne; j++)
                {
                    //Recuperer l'image de la texture
                    Bitmap texture = textureSet.Clone(new Rectangle(new Point(j * tilesSize.Width, i * tilesSize.Height), new Size(tilesSize.Width, tilesSize.Height)), System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                    //Creer une texture model et l'ajouter a la liste
                    int index = i * nbTexturesLigne + j;
                    string modelName = "TEXTURE_" + sheetModel.ToString() + "_" + index + "_MODEL";
                    GorgonLibrary.Graphics.Sprite sprite = new GorgonLibrary.Graphics.Sprite(modelName, GorgonLibrary.Graphics.Image.FromBitmap(modelName,texture));
                    texture.Dispose();

                    TileModel model = new TileModel(modelName, new Point(0, 0), tilesSize, sprite, true, true);

                    sheetModel.TileModels.Add(model);

                }
            }

            //Relacher la texture Set principale
            textureSet.Dispose();

            this.textureSheetCombBx.Items.Add(sheetModel);
        }