Beispiel #1
0
        public void DrawMapByLayer(Map aMap, bool[] aDrawedLayers)
        {
            this.FDrewElementsCount = 0;
            List <MapElement> _elements = new List <MapElement>();

            for (int i = 0; i < aMap.WORLD_SIZE; i++)
            {
                for (int j = 0; j < aMap.WORLD_SIZE; j++)
                {
                    if (i + j > 3 * aMap.WORLD_SIZE / 2 ||
                        i + j < aMap.WORLD_SIZE / 2 ||
                        i - j > aMap.WORLD_SIZE / 2 ||
                        j - i > aMap.WORLD_SIZE / 2)
                    {
                        continue;
                    }

                    _elements.Add(aMap.Elementes[aMap.WORLD_SIZE * j + i]);
                }
            }

            this.FTotalElementsCount =
                _elements.Select(x => x.pLevelNodes.
                                 Where(y => y != null).
                                 Select(y => y.tileIndexes.Length).
                                 Sum()).
                Sum();

            this.FProgress = new ProgressHolder();
            try
            {
                Thread _thr = new Thread(ProgressWindowShow);
                _thr.SetApartmentState(ApartmentState.STA);
                _thr.IsBackground = true;
                _thr.Start(this.FProgress);

                for (int i = 0; i < aDrawedLayers.Length; i++)
                {
                    DrawingVisual _layerVisual = this.DrawMapLayerByTiles(aMap, i);
                    this.FCacheVisual[i] = _layerVisual;

                    if (aDrawedLayers[i])
                    {
                        if (this.FVisuals[i] != null)
                        {
                            this.RemoveVisual(i);
                        }

                        this.AddVisual(i);
                    }
                }
            }
            finally
            {
                this.FProgress.Progress = -1;
            }
        }
Beispiel #2
0
        private void ProgressWindowShow(object aProgressHolder)
        {
            ProgressHolder _ph = (ProgressHolder)aProgressHolder;
            ProgressWindow _pw = new ProgressWindow(_ph);

            _pw.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            _pw.Topmost = true;
            _pw.Show();
            System.Windows.Threading.Dispatcher.Run();
        }
Beispiel #3
0
        public void Reload()
        {
            if (this.ViewModel == null)
            {
                return;
            }

            if (this.mgShape == null)
            {
                this.mgShape = new Model3DGroup();
            }

            this.mgShape.Children.Clear();
            this.FTiles = new List <TileGeometry>();

            if (this.ViewModel.Structure == null)
            {
                return;
            }

            int            _tilesCount = this.ViewModel.Structure.Tiles.Count;
            ProgressHolder _ph         = new ProgressHolder();

            if (_tilesCount > 1)
            {
                Thread _thr = new Thread(ProgressWindowShow);
                _thr.SetApartmentState(ApartmentState.STA);
                _thr.IsBackground = true;
                _thr.Start(_ph);
            }

            try
            {
                for (int i = 0; i < _tilesCount; i++)
                {
                    this.AddTile(this.ViewModel.Structure.Tiles[i]);
                    _ph.Progress = i * 100 / _tilesCount;
                }
            }
            finally
            {
                _ph.Progress = -1;
            }

            CreateLandSurface();
        }
Beispiel #4
0
        private void ConvertToJpeg_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog _ofd = new OpenFileDialog();

            _ofd.Title       = "Convert Map File To JPEG.";
            _ofd.Filter      = "Map Files (*.dat) | *.dat";
            _ofd.Multiselect = true;

            if (_ofd.ShowDialog() == true)
            {
                this.FPh = new ProgressHolder();
                this.FPh.IsCancelable = true;
                ProgressWindow.Run(this.FPh);
                try
                {
                    for (int i = 0; i < _ofd.FileNames.Length && this.FPh.Progress > 0; i++)
                    {
                        Map _map = new Map(_ofd.FileNames[i]);
                        _map.Load();
                        this.ViewModel.LoadMapTileSet(_map);
                        MapImage        _mapImage   = new MapImage(_map);
                        bool[]          _drewLevels = this.FLayersSwitch.Select(x => x.IsChecked == true).ToArray();
                        WriteableBitmap _bitmap     = _mapImage.GetMapBitmap(_drewLevels);

                        JpegBitmapEncoder _encoder = new JpegBitmapEncoder();
                        _encoder.QualityLevel = 100;
                        BitmapFrame _bf = BitmapFrame.Create(_bitmap);
                        _encoder.Frames.Add(_bf);
                        string _destFileName = Path.ChangeExtension(_ofd.FileNames[i], ".jpeg");
                        using (FileStream _fs = new FileStream(_destFileName, FileMode.Create, FileAccess.Write))
                        {
                            _encoder.Save(_fs);
                            _fs.Flush();
                            _fs.Close();
                        }

                        this.FPh.Progress = 100 * i / _ofd.FileNames.Length;
                    }
                }
                finally
                {
                    this.FPh.Progress = -1;
                }
            }
        }
        public void Reload()
        {
            if (this.mgShape == null)
            {
                this.mgShape = new Model3DGroup();
            }

            this.mgShape.Children.Clear();

            this.FTiles        = new List <TileGeometry>();
            this.FSelectedTile = null;
            this.ViewModel.FilledPositionCount = 0;

            int            _tilesCount = this.ViewModel.Structure.Tiles.Count;
            ProgressHolder _ph         = new ProgressHolder();

            if (_tilesCount > 1)
            {
                Thread _thr = new Thread(ProgressWindowShow);
                _thr.SetApartmentState(ApartmentState.STA);
                _thr.IsBackground = true;
                _thr.Start(_ph);
            }

            try
            {
                for (int i = 0; i < _tilesCount; i++)
                {
                    this.AddTile(this.ViewModel.Structure.Tiles[i]);
                    this.ViewModel.Structure.Tiles[i].AttachHandler(this, Tile_PropertyChanged);
                    _ph.Progress = i * 100 / _tilesCount;
                }
            }
            finally
            {
                _ph.Progress = -1;
            }

            CreateLandSurface();
            SetTransparentAll(false);
        }
Beispiel #6
0
        private static void Lab6_Example()
        {
            PriceList <Tire> priceList = new PriceList <Tire>();
            var random = new Random();

            for (int i = 0; i < 10000; ++i)
            {
                priceList.Add(new Tire("Hakkapelita", 1, 1, CarcassType.Radial, 15), random.Next());
            }
            var    progressHolder = new ProgressHolder();
            Thread thread         = new Thread(() => priceList.Sort(progressHolder));

            thread.Start();
            Console.Write("Progress: 0%");
            while (progressHolder.Progress < 100)
            {
                Console.Write("\rProgress: {0}%", progressHolder.Progress);
                Thread.Sleep(100);
            }
            Console.WriteLine("\rProgress: 100%");
            thread.Join();
        }
Beispiel #7
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult _result = MessageBox.Show(
                "Files will be overrwritten.", "Convertation JSD to JSD-HD", MessageBoxButton.OKCancel);

            if (_result != MessageBoxResult.OK)
            {
                return;
            }

            ProgressHolder _ph = new ProgressHolder();

            _ph.IsCancelable = true;
            ProgressWindow.Run(_ph);

            int _filesCount = 0;

            try
            {
                foreach (string _fileName in this.FFileNames)
                {
                    if (_ph.Progress < 0)
                    {
                        break;
                    }

                    JsdFile.ConvertJsdFileToHighDefinition(_fileName);
                    _filesCount++;

                    _ph.Progress = 100 * _filesCount / this.FFileNames.Length;
                }
            }
            finally
            {
                _ph.Progress = -1;
            }
        }