Esempio n. 1
0
        public MapViewModel()
        {
            CreateCommands();
            LayerViewModel = ServiceLocator.Current.GetInstance<LayerViewModel>();

            _mapCanvas = new Canvas();
            MousePosition = new Point();
            _tempTiles = new List<Tile>();
            _selectionRect = new Rectangle();
            _selectionPointEnd = new Point();
            _selectionPointStart = new Point();
            _tempSelectedTileList = new List<Tile>();

            _editor = _modelInstance._editor;
            _mapCanvas.HorizontalAlignment = HorizontalAlignment.Left;
            _mapCanvas.VerticalAlignment = VerticalAlignment.Top;

            _mapCanvas.Background = Brushes.Transparent;
            _mapCanvas.Width = _editor.GetMapWidth() * _editor.GetTileSize();
            _mapCanvas.Height = _editor.GetMapHeight() * _editor.GetTileSize();

            _mapCanvas.AddHandler(UIElement.MouseRightButtonDownEvent, (RoutedEventHandler)SelectBegin);
            _mapCanvas.AddHandler(UIElement.MouseRightButtonUpEvent, (RoutedEventHandler)SelectEnd);

            _mapCanvas.AddHandler(UIElement.MouseMoveEvent, (RoutedEventHandler)Click);
            _mapCanvas.AddHandler(UIElement.MouseDownEvent, (RoutedEventHandler)Click);
            _mapCanvas.AddHandler(UIElement.MouseLeftButtonUpEvent, (RoutedEventHandler)ClickEnd);

            int mapWidth = _editor.GetMapWidth();
            int mapHeight = _editor.GetMapHeight();

            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    Tile t = _editor.GetTile(x, y);
                    _mapCanvas.Children.Add(t);
                    Canvas.SetTop(t, y * 32);
                    Canvas.SetLeft(t, x * 32);
                }
            }

            _selectionRect.Fill = new SolidColorBrush(Colors.Black);
            _selectionRect.Stroke = new SolidColorBrush(Colors.Black);
            _selectionRect.Width = 32;
            _selectionRect.Height = 32;
            _selectionRect.Opacity = 0.5;
        }