Beispiel #1
0
        public Point GetHexTopLeftCorner(ViewPortData view, Hex hex)
        {
            double x = hex.X * s * 1.5;
            double y = hex.Y * hexHeight + (hex.X % 2) * hexHeight / 2;

            x = x + (view.Width / 2) - view.CentreX;
            y = y + (view.Height / 2) - view.CentreY;

            return(new Point(x, y));
        }
Beispiel #2
0
        public Hex SelectHex(ViewPortData view, Map map, int pixX, int pixY)
        {
            pixX = pixX - (view.Width / 2) + view.CentreX;
            pixY = pixY - (view.Height / 2) + view.CentreY;

            int sx = (int)(pixX / s / 1.5);
            int sy = (int)(pixY - ((sx % 2) * hexHeight) / 2) / hexHeight;

            return(map.Hexes[sy, sx]);
        }
        public EditorControl(Map mapToEdit, MainWindow mainWindow)
        {
            InitializeComponent();
            Map = mapToEdit;
            MainWnd = mainWindow;
            Mapping = new Mapping(50, 42);
            this.DataContext = Map;
            ViewPortData viewPort = new ViewPortData() { CentreX = 0, CentreY = 0, Height = 500, Width = 500, Zoom = 1 };

            //var uriSource = new Uri(@"/WpfApplication1;component/Untitled.png", UriKind.Relative);
            //foo.Source = new BitmapImage(uriSource);
            BitmapImage img = new BitmapImage(new Uri("C:/Development/projects/Landwar/Shared/HexRed.png"));

            /*ImageBrush imgBrush = new ImageBrush(img);
            imgBrush.Viewbox = new Rect(0, 0, 1, 1);
            imgBrush.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox;
            imgBrush.Stretch = Stretch.Uniform;*/

            SolidColorBrush redSolidColorBrush = new SolidColorBrush();
            redSolidColorBrush.Color = Color.FromArgb(255, 255, 0, 0);
            SolidColorBrush grnSolidColorBrush = new SolidColorBrush();
            grnSolidColorBrush.Color = Color.FromArgb(255, 0, 255, 0);

            for (int j = 0; j < mapToEdit.Height; ++j)
            {
                for (int i = 0; i < mapToEdit.Width; ++i)
                {
                    Point hexTopLeft = Mapping.GetHexTopLeftCorner(viewPort, mapToEdit.Hexes[j,i]);

                    Polygon pGon = GenerateHex(hexTopLeft.X, hexTopLeft.Y, Mapping.hexHeight, Mapping.hexWidth);
                    pGon.Stroke = Brushes.Purple;
                    pGon.StrokeThickness = 0;
                    pGon.ClipToBounds = true;
                    //pGon.Fill = imgBrush;

                    if (((double)i) % 2 == 0)
                    {
                        pGon.Fill = redSolidColorBrush;
                    }
                    else
                    {
                        pGon.Fill = grnSolidColorBrush;
                    }

                    pGon.MouseEnter += Polygon_MouseMove;

                    this.cnvMap.Children.Add(pGon);
                }
            }
        }