예제 #1
0
        public static WriteableBitmap CreateImage(EntityModel entityModel)
        {
            WriteableBitmap bankBitmap = BitmapFactory.New(64, 64);

            using (bankBitmap.GetBitmapContext())
            {
                foreach (CharacterTile tile in entityModel.Frame.Tiles)
                {
                    if (string.IsNullOrEmpty(tile.BankID) || string.IsNullOrEmpty(tile.BankTileID))
                    {
                        continue;
                    }

                    BankModel ptModel = ProjectFiles.GetModel <BankModel>(tile.BankID);
                    if (ptModel == null)
                    {
                        continue;
                    }

                    PTTileModel bankModel = ptModel.GetTileModel(tile.BankTileID);

                    if (string.IsNullOrEmpty(bankModel.GUID) && string.IsNullOrEmpty(bankModel.TileSetID))
                    {
                        continue;
                    }

                    WriteableBitmap sourceBitmap = CreateImageUtil.GetCacheBitmap(bankModel.TileSetID);

                    if (sourceBitmap == null)
                    {
                        continue;
                    }

                    using (sourceBitmap.GetBitmapContext())
                    {
                        WriteableBitmap cropped = sourceBitmap.Crop((int)bankModel.Point.X, (int)bankModel.Point.Y, 8, 8);

                        if (tile.FlipX)
                        {
                            cropped = WriteableBitmapExtensions.Flip(cropped, WriteableBitmapExtensions.FlipMode.Vertical);
                        }

                        if (tile.FlipY)
                        {
                            cropped = WriteableBitmapExtensions.Flip(cropped, WriteableBitmapExtensions.FlipMode.Horizontal);
                        }

                        int destX = (int)Math.Floor(tile.Point.X / 8) * 8;
                        int destY = (int)Math.Floor(tile.Point.Y / 8) * 8;

                        Util.CopyBitmapImageToWriteableBitmap(ref bankBitmap, destX, destY, cropped);
                    }
                }
            }

            return(bankBitmap);
        }
예제 #2
0
        public static void CreateImage(MapModel mapModel, ref WriteableBitmap mapBitmap, bool isUpdate)
        {
            if (!isUpdate)
            {
                mapBitmap = BitmapFactory.New(256, 240);
            }

            using (mapBitmap.GetBitmapContext())
            {
                for (int i = 0; i < mapModel.AttributeTable.Length; ++i)
                {
                    AttributeTable attTable = mapModel.AttributeTable[i];

                    if (attTable.MapTile == null)
                    {
                        continue;
                    }

                    bool erased     = false;
                    bool updateTile = false;

                    if (isUpdate)
                    {
                        // Only update the tiles that were affected by the change
                        if (MapViewModel.FlagMapBitmapChanges[i] == TileUpdate.None)
                        {
                            continue;
                        }

                        erased     = MapViewModel.FlagMapBitmapChanges[i] == TileUpdate.Erased;
                        updateTile = MapViewModel.FlagMapBitmapChanges[i] == TileUpdate.Normal;

                        MapViewModel.FlagMapBitmapChanges[i] = TileUpdate.None;
                    }

                    foreach (MapTile tile in attTable.MapTile)
                    {
                        if (isUpdate && !updateTile)
                        {
                            if (tile.Point != MapViewModel.PointMapBitmapChanges[i])
                            {
                                continue;
                            }
                        }

                        if (string.IsNullOrEmpty(tile.BankID) || string.IsNullOrEmpty(tile.BankTileID))
                        {
                            continue;
                        }

                        BankModel bankModel = ProjectFiles.GetModel <BankModel>(tile.BankID);

                        if (bankModel == null)
                        {
                            continue;
                        }

                        PTTileModel ptTileModel = bankModel.GetTileModel(tile.BankTileID);

                        if (ptTileModel.TileSetID == null)
                        {
                            continue;
                        }

                        WriteableBitmap tileSetBitmap = CreateImageUtil.GetCacheBitmap(ptTileModel.TileSetID);

                        if (tileSetBitmap == null)
                        {
                            continue;
                        }

                        CacheColorsFromBank(ptTileModel.Group, attTable, mapModel, bankModel);

                        WriteableBitmap cropped = tileSetBitmap.Crop((int)ptTileModel.Point.X, (int)ptTileModel.Point.Y, 8, 8);

                        using (cropped.GetBitmapContext())
                        {
                            if (erased)
                            {
                                cropped.Clear(BackgroundColor);
                            }
                            else
                            {
                                Tuple <int, PaletteIndex> colorsKey = Tuple.Create(ptTileModel.Group, (PaletteIndex)attTable.PaletteIndex);

                                if (!MapViewModel.GroupedPalettes.TryGetValue(colorsKey, out Dictionary <Color, Color> colors))
                                {
                                    colors = new Dictionary <Color, Color>();
                                }

                                CreateImageUtil.PaintPixelsBasedOnPalettes(ref cropped, ref colors);
                            }
                        }

                        int destX = (int)Math.Floor(tile.Point.X / 8) * 8;
                        int destY = (int)Math.Floor(tile.Point.Y / 8) * 8;

                        Util.CopyBitmapImageToWriteableBitmap(ref mapBitmap, destX, destY, cropped);
                    }
                }
            }
        }
예제 #3
0
        public static WriteableBitmap CreateImage(CharacterModel characterModel, int animationIndex, int frameIndex, ref GroupedPalettes groupedPalettes)
        {
            if (characterModel.Animations[animationIndex].Frames == null)
            {
                return(null);
            }

            if (characterModel.Animations[animationIndex].Frames[frameIndex].Tiles == null)
            {
                return(null);
            }

            WriteableBitmap bankBitmap = BitmapFactory.New(64, 64);

            using (bankBitmap.GetBitmapContext())
            {
                foreach (CharacterTile tile in characterModel.Animations[animationIndex].Frames[frameIndex].Tiles)
                {
                    if (string.IsNullOrEmpty(tile.BankID) || string.IsNullOrEmpty(tile.BankTileID))
                    {
                        continue;
                    }

                    BankModel ptModel = ProjectFiles.GetModel <BankModel>(tile.BankID);
                    if (ptModel == null)
                    {
                        continue;
                    }

                    PTTileModel bankModel = ptModel.GetTileModel(tile.BankTileID);

                    if (string.IsNullOrEmpty(bankModel.GUID) && string.IsNullOrEmpty(bankModel.TileSetID))
                    {
                        continue;
                    }

                    WriteableBitmap sourceBitmap = CreateImageUtil.GetCacheBitmap(bankModel.TileSetID);

                    if (sourceBitmap == null)
                    {
                        continue;
                    }

                    WriteableBitmap cropped = sourceBitmap.Crop((int)bankModel.Point.X, (int)bankModel.Point.Y, 8, 8);

                    using (cropped.GetBitmapContext())
                    {
                        if (tile.FlipX)
                        {
                            cropped = WriteableBitmapExtensions.Flip(cropped, WriteableBitmapExtensions.FlipMode.Vertical);
                        }

                        if (tile.FlipY)
                        {
                            cropped = WriteableBitmapExtensions.Flip(cropped, WriteableBitmapExtensions.FlipMode.Horizontal);
                        }

                        Tuple <int, PaletteIndex> tuple = Tuple.Create(bankModel.Group, (PaletteIndex)tile.PaletteIndex);

                        if (!groupedPalettes.TryGetValue(tuple, out Dictionary <Color, Color> colors))
                        {
                            colors = FillColorCacheByGroup(tile, bankModel.Group, characterModel.PaletteIDs[tile.PaletteIndex]);

                            groupedPalettes.Add(tuple, colors);
                        }

                        CreateImageUtil.PaintPixelsBasedOnPalettes(ref cropped, ref colors);
                    }

                    int destX = (int)Math.Floor(tile.Point.X / 8) * 8;
                    int destY = (int)Math.Floor(tile.Point.Y / 8) * 8;

                    Util.CopyBitmapImageToWriteableBitmap(ref bankBitmap, destX, destY, cropped);
                }
            }

            bankBitmap.Freeze();

            return(bankBitmap);
        }