示例#1
0
        private void imgHexMap_MapClick(object sender, MapEventArgs e)
        {
            if (_lockControls)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                if (_currentDrawingTool == DrawingTools.Select)
                {
                    SelectHex(e.HexWorldCoordinate);
                }
                else
                {
                    if (GetDrawingTool() == DrawingTools.FogOfWar)
                    {
                        _fogOfWarPainter.PaintFogOfWar(e.HexWorldCoordinate);
                    }
                    else if (_painter.TryPaint(e)) //Since we are not selecting, we are painting. Try to paint
                    {
                        if (_currentDrawingTool == DrawingTools.River || _currentDrawingTool == DrawingTools.Road)
                        {
                            //For connections, we also redraw the neighboring hex, since it also gets a connection that needs drawing
                            var neighborHex = DirectionManager.NeighborTo(e.HexWorldCoordinate, e.PartOfHexClicked);
                            DrawHex(neighborHex, DrawingToolToLayer(_currentDrawingTool));
                        }
                    }
                    DrawHex(e.HexWorldCoordinate, DrawingToolToLayer(_currentDrawingTool)); //Redraw the changed hex
                    SelectHex(e.HexWorldCoordinate);
                    txtDetail.Focus();
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (GetDrawingTool() == DrawingTools.FogOfWar)
                {
                    _fogOfWarPainter.RemoveFogOfWar(e.HexWorldCoordinate);
                    _drawingHandler.RedrawFogOfWar();
                }
                else if (_painter.TryRemove(e)) //Try to delete
                {
                    if (_currentDrawingTool == DrawingTools.River)
                    {
                        //For rivers and roads we need to redraw the entire map, to remove the removed road
                        _drawingHandler.RedrawLayer(Layer.River);
                    }
                    else if (_currentDrawingTool == DrawingTools.Road)
                    {
                        _drawingHandler.RedrawLayer(Layer.Road);
                    }
                    else
                    {
                        DrawHex(e.HexWorldCoordinate, DrawingToolToLayer(_currentDrawingTool)); //Redraw the changed hex
                    }
                }
            }
        }