コード例 #1
0
        private void mnuAddDecal_Click(object sender, RoutedEventArgs e)
        {
            DecalImageModel decal = new DecalImageModel();

            decal.IdProperty          = TGIRandomGenerator.GetNext().ToHex();
            decal.AspectRatioProperty = 1;

            Decals.Add(decal);
            DecalDictionaryEntry.DecalImages.Add(decal);

            Decals.Changed();

            Refresh();
        }
コード例 #2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                RasterResult = RasterImage.CreateFromBitmap(quantizedBitmap);

                InstanceId = TGIRandomGenerator.GetNext();

                DatabaseIndex newIndex = new DatabaseIndex(_index.Owner);
                newIndex.TypeId       = (uint)TypeIds.RasterFile;
                newIndex.InstanceId   = InstanceId;
                newIndex.Flags        = 1;
                newIndex.IsModified   = true;
                newIndex.Compressed   = false;
                newIndex.ModifiedData = new ModifiedRasterFile()
                {
                    ImageFileData = RasterResult.ToIndexData()
                };
                _index.Owner.Indices.Add(newIndex);
                SimCityPak.PackageReader.DatabaseManager.Instance.Indices.Add(newIndex);

                Decal                     = new DecalImageModel();
                Decal.IdProperty          = TGIRandomGenerator.GetNext().ToHex();
                Decal.DecalIdProperty     = InstanceId.ToHex();
                Decal.Color4              = ((SolidColorBrush)rectangle1.Background).Color;
                Decal.Color1              = ((SolidColorBrush)rectangle2.Background).Color;
                Decal.Color2              = ((SolidColorBrush)rectangle3.Background).Color;
                Decal.Color3              = ((SolidColorBrush)rectangle4.Background).Color;
                Decal.AspectRatioProperty = 1;

                this.DialogResult = true;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error during generation", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #3
0
 private void btnGenerate_Click(object sender, RoutedEventArgs e)
 {
     txtInstanceId.Text = TGIRandomGenerator.GetNext().ToHex();
 }
コード例 #4
0
        public void GenerateRasterImage(string originalFile)
        {
            if (!string.IsNullOrEmpty(originalFile))
            {
                try
                {
                    nQuant.WuQuantizer    quantizer = new nQuant.WuQuantizer();
                    System.Drawing.Bitmap bitmap    = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(originalFile);

                    quantizer.QuantizeImage(bitmap);

                    QuantizedSignedDistanceFieldGenerator generator = new QuantizedSignedDistanceFieldGenerator(quantizer.Palette, bitmap.Height, bitmap.Width);
                    generator.Generate(0);
                    generator.Generate(1);
                    generator.Generate(2);
                    generator.Generate(3);

                    RasterImage RasterResult = RasterImage.CreateFromBitmap(generator.GetBitmap());

                    uint InstanceId = TGIRandomGenerator.GetNext();

                    DatabaseIndex newIndex = new DatabaseIndex(OriginalIndex.Owner);
                    newIndex.TypeId       = (uint)TypeIds.RasterFile;
                    newIndex.InstanceId   = InstanceId;
                    newIndex.Flags        = 1;
                    newIndex.IsModified   = true;
                    newIndex.Compressed   = false;
                    newIndex.ModifiedData = new ModifiedRasterFile()
                    {
                        ImageFileData = RasterResult.ToIndexData()
                    };
                    OriginalIndex.Owner.Indices.Add(newIndex);
                    SimCityPak.PackageReader.DatabaseManager.Instance.Indices.Add(newIndex);

                    UnitFileEntry.LotMask.InstanceId = InstanceId;
                    //quantizer.Palette.Colors[0].Scr
                    Color col = Color.FromArgb(quantizer.Palette.Colors[0].A, quantizer.Palette.Colors[0].R, quantizer.Palette.Colors[0].G, quantizer.Palette.Colors[0].B);
                    UnitFileEntry.LotColor4.R = col.ScR;
                    UnitFileEntry.LotColor4.G = col.ScG;
                    UnitFileEntry.LotColor4.B = col.ScB;

                    col = Color.FromArgb(quantizer.Palette.Colors[1].A, quantizer.Palette.Colors[1].R, quantizer.Palette.Colors[1].G, quantizer.Palette.Colors[1].B);
                    UnitFileEntry.LotColor1.R = col.ScR;
                    UnitFileEntry.LotColor1.G = col.ScG;
                    UnitFileEntry.LotColor1.B = col.ScB;

                    col = Color.FromArgb(quantizer.Palette.Colors[2].A, quantizer.Palette.Colors[2].R, quantizer.Palette.Colors[2].G, quantizer.Palette.Colors[2].B);
                    UnitFileEntry.LotColor2.R = col.ScR;
                    UnitFileEntry.LotColor2.G = col.ScG;
                    UnitFileEntry.LotColor2.B = col.ScB;

                    col = Color.FromArgb(quantizer.Palette.Colors[3].A, quantizer.Palette.Colors[3].R, quantizer.Palette.Colors[3].G, quantizer.Palette.Colors[3].B);
                    UnitFileEntry.LotColor3.R = col.ScR;
                    UnitFileEntry.LotColor3.G = col.ScG;
                    UnitFileEntry.LotColor3.B = col.ScB;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error during generation", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }