Esempio n. 1
0
        //Pass Click to Move + Tile Selector
        private void MainCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.LeftShift))
            {
                CanvasPos pos = new CanvasPos(e.GetPosition(MainCanvas));
                PosLabel.Content = $"({pos.X},{pos.Y})";

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    if (GetBackgroundAt(pos.X, pos.Y, out BackgroundName bg))
                    {
                        backgroundMap.TryGetValue(bg, out BitmapImage src);
                        Image image = new Image()
                        {
                            Source = src
                        };
                        _selectedTile = new Tile(TileType.Background, image);
                        SelectTile(TileType.Background, bg.ToString());
                        LabelImg.Source   = src;
                        TileHover.Content = bg;
                    }
                }
                else if (e.RightButton == MouseButtonState.Pressed)
                {
                    GetForegroundAt(pos.X, pos.Y, out BlockName bl);
                    if (GetForegroundAt(pos.X, pos.Y, out bl))
                    {
                        blockMap.TryGetValue(bl, out BitmapImage src);
                        Image image = new Image()
                        {
                            Source = src
                        };
                        _selectedTile = new Tile(TileType.Foreground, image);
                        SelectTile(TileType.Foreground, bl.ToString());
                        LabelImg.Source   = src;
                        TileHover.Content = bl;
                    }
                }
            }
            else
            {
                MainCanvas_MouseMove(sender, e);
            }
        }
Esempio n. 2
0
        //Painter
        public void MainCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            CanvasPos pos = new CanvasPos(e.GetPosition(MainCanvas));

            PosLabel.Content = $"({pos.X},{pos.Y})";

            //Last pixel crashes the entire thing. Why? No idea.
            if (pos.Y == 60)
            {
                return;
            }

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                //Check if a tile has been selected before doing anything first.
                if (FirstSelected)
                {
                    //Check if the tile selected can be placed at a position
                    if (!SameTypeAt(_selectedTile, pos.X, pos.Y) && !AlreadyHasBothTypes(pos.X, pos.Y))
                    {
                        //So we can make sure to put a confirm box if the user makes a new world or opens one
                        if (!firstPlaced)
                        {
                            firstPlaced = true;
                        }

                        PlaceAt(pos.X, pos.Y, _selectedTile);
                    }
                }
            }

            //Delete Tiles
            if (e.RightButton == MouseButtonState.Pressed)
            {
                DeleteAt(pos.X, pos.Y, _selectedTile);
            }
        }