Пример #1
0
 public void Reset()
 {
     wp1 = null;
     lastX = 0; // Last drag location X
     lastY = 0; // Last drag location Y
     Shift = false; // Shift state
     MLeft = false; // M1 State
     MRight = false; // M2 State
     WheelClick = false; // M3 State
 }
Пример #2
0
        public void Update(Point mousePt)
        {
            bool iWalls = (MapInterface.CurrentMode >= EditMode.WALL_PLACE && MapInterface.CurrentMode <= EditMode.WALL_CHANGE);
            bool iTiles = (MapInterface.CurrentMode >= EditMode.FLOOR_PLACE && MapInterface.CurrentMode <= EditMode.EDGE_PLACE);
            bool iObjs  = (MapInterface.CurrentMode == EditMode.OBJECT_SELECT);
            bool iWps   = (MapInterface.CurrentMode == EditMode.WAYPOINT_SELECT);

            // Search for walls/tiles/objects under cursor
            statusLocation = string.Format(FORMAT_COORDINATES, mousePt.X, mousePt.Y);
            statusMapItem  = "";
            statusPolygon  = "";

            // Wall tracking
            if (iWalls)
            {
                var      wallPt = MapView.GetNearestWallPoint(mousePt);
                Map.Wall wall   = map.Walls.ContainsKey(wallPt) ? map.Walls[wallPt] : null;
                statusLocation = string.Format(FORMAT_COORDINATES, wallPt.X, wallPt.Y);

                if (wall != null)
                {
                    statusMapItem = string.Format(FORMAT_WALL_INFO, wall.Material, wall.Variation);
                }

                if (prevWall != wall)
                {
                    prevWall         = wall;
                    updateStatusbars = true;
                }
            }
            else
            {
                prevWall = null;
            }


            // Tile tracking
            if (iTiles)
            {
                var      tilePt = MapView.GetNearestTilePoint(mousePt);
                Map.Tile tile   = map.Tiles.ContainsKey(tilePt) ? map.Tiles[tilePt] : null;
                statusLocation = string.Format(FORMAT_COORDINATES, tilePt.X, tilePt.Y);

                if (tile != null)
                {
                    statusMapItem = string.Format(FORMAT_TILE_INFO, tile.Graphic, tile.Variation);
                    edgeCount     = tile.EdgeTiles.Count;
                    if (tile.EdgeTiles.Count > 0)
                    {
                        statusMapItem += string.Format(FORMAT_EDGE_COUNT, tile.EdgeTiles.Count);

                        foreach (Map.Tile.EdgeTile edge in tile.EdgeTiles)
                        {
                            statusMapItem += string.Format(FORMAT_EDGE_INFO, ThingDb.FloorTileNames[edge.Graphic], edge.Variation, edge.Dir, ThingDb.EdgeTileNames[edge.Edge]);
                        }
                    }
                }

                if (prevTile != tile)
                {
                    prevTile         = tile;
                    updateStatusbars = true;
                }
                if (prevEdge != edgeCount && tile != null)
                {
                    prevEdge         = tile.EdgeTiles.Count;
                    updateStatusbars = true;
                }
            }
            else
            {
                prevTile = null;
            }


            // Object tracking
            if (iObjs)
            {
                Map.Object obj = MapInterface.ObjectSelect(mousePt);
                if (obj == null)
                {
                    return;
                }

                statusMapItem = string.Format(FORMAT_OBJECT_INFO, obj.Name, obj.Extent);

                if (prevObj != obj)
                {
                    prevObj          = obj;
                    updateStatusbars = true;
                }
            }
            else
            {
                prevObj = null;
            }


            // Waypoint tracking
            if (iWps)
            {
                Map.Waypoint wp = MapInterface.WaypointSelect(mousePt);
                if (wp == null)
                {
                    return;
                }

                statusMapItem = string.Format(FORMAT_WAYPOINT_INFO, wp.Name, wp.Number);

                if (prevWP != wp)
                {
                    prevWP           = wp;
                    updateStatusbars = true;
                }
            }
            else
            {
                prevWP = null;
            }


            // Polygon tracking
            Map.Polygon ins   = null;
            var         ptFlt = new PointF(mousePt.X, mousePt.Y);
            int         i     = -1;

            foreach (Map.Polygon poly in map.Polygons)
            {
                i++;
                if (poly.IsPointInside(ptFlt))
                {
                    statusPolygon = poly.Name;
                    ins           = poly;

                    if (MainWindow.Instance.mapView.PolygonEditDlg.Visible && !MainWindow.Instance.mapView.PolygonEditDlg.LockedBox.Checked && MapInterface.CurrentMode == EditMode.POLYGON_RESHAPE && (MainWindow.Instance.mapView.PolygonEditDlg.SelectedPolygon != MainWindow.Instance.mapView.PolygonEditDlg.SuperPolygon || MainWindow.Instance.mapView.PolygonEditDlg.SelectedPolygon == null))
                    {
                        MainWindow.Instance.mapView.PolygonEditDlg.listBoxPolygons.SelectedIndex = i;
                        MainWindow.Instance.mapView.PolygonEditDlg.SelectedPolygon = ins;
                    }
                    break;
                }
            }
            if (prevPoly != ins)
            {
                prevPoly         = ins;
                updateStatusbars = true;
            }
        }
Пример #3
0
        private void mapPanel_MouseDown(object sender, MouseEventArgs e)
        {
            Point pt = new Point(e.X, e.Y);
            Point tilePt = GetNearestTilePoint(pt);
            Point wallPt = GetNearestWallPoint(pt);
               // if (CurrentMode != Mode.MAKE_WAYPOINT && CurrentMode != Mode.EDIT_WAYPOINT)
            //    KeyStates.wp1 = null;

            if (e.Button.Equals(MouseButtons.Middle)/* && e.Clicks == 1*/)//if middle click
            {
                KeyStates.WheelClick = true;
                // KeyStates.lastX = mouseLocation.X;
                // KeyStates.lastY = mouseLocation.Y;
                if (CurrentMode == Mode.MAKE_FLOOR || CurrentMode == Mode.EDIT_EDGE)
                {
                    threeFloorBox.Checked = !threeFloorBox.Checked;
                }
               // else if (CurrentMode == Mode.EDIT_WAYPOINT)
                //{
                 //   Map.Waypoints.SetNameFromPoint(pt, wpNameBox.Text);
               // }
            }
            if (e.Button.Equals(MouseButtons.Right)/* && e.Clicks == 1*/)//if single right click
            {
                KeyStates.MRight = true;

                // Add context menu popup
                if( SelectedObject != null && (CurrentMode == Mode.MAKE_OBJECT || CurrentMode == Mode.SELECT))
                    contextMenu.Show(mapPanel,mouseLocation);
                if( CurrentMode == Mode.MAKE_FLOOR )
                    RemoveTile(tilePt);
                else if (CurrentMode == Mode.EDIT_EDGE)
                {
                    RemoveEdge(tilePt);
                }
                else if (CurrentMode == Mode.MAKE_WAYPOINT)
                {
                    Map.Waypoint wp = Map.Waypoints.GetWPFromPoint(pt);
                    if (wp != null)
                    {
                        Map.Waypoints.Remove(wp);
                    }
                    //KeyStates.wp1 = null;
                }
                else if (CurrentMode == Mode.EDIT_WAYPOINT)
                {
                    Map.Waypoint wp = Map.Waypoints.GetWPFromPoint(pt);
                    if (wp != null && KeyStates.wp1 != null && KeyStates.wp1 != wp)
                    {
                        //wp.RemoveConnByNum(KeyStates.wp1);
                        KeyStates.wp1.RemoveConnByNum(wp);
                        KeyStates.wp1 = null;
                    }
                    else
                    {
                        KeyStates.wp1 = wp;
                    }
                }
            }
            if (e.Button.Equals(MouseButtons.Left)/* && e.Clicks == 1*/)//if single left click
            {
                KeyStates.MLeft = true;
                if (CurrentMode == Mode.SELECT)
                {
                    //dragging = Map.SelectObject(pointClicked) == SelectedObject;//only start "dragging" if this object has already been selected
                    if (SelectObject(pt) == SelectedObject)
                        dragging = true;
                    else
                    {
                        SelectedObject = SelectObject(pt);
                        KeyStates.MLeft = false;
                    }
                }
                else if (CurrentMode == Mode.EDIT_EDGE)
                {
                    EditEdge(tilePt);
                }
                else if (CurrentMode == Mode.MAKE_WALL)
                {
                    if (!Map.Walls.ContainsKey(wallPt))
                    {
                        Map.Walls.Add(wallPt, wallSelector.NewWall(wallPt));
                        Map.Wall.WallFacing facing = Map.Walls[wallPt].Facing;
                        if (
                            facing == Map.Wall.WallFacing.NORTH ||
                            facing == Map.Wall.WallFacing.WEST)
                        {
                            Map.Walls[wallPt].Variation = CreateVariationW(wallPt, (ushort)Map.Walls[wallPt].Variation, (ushort)Map.Walls[wallPt].Variations, true);
                        }
                        else
                        {
                            Map.Walls[wallPt].Variation = CreateVariationW(wallPt, (ushort)Map.Walls[wallPt].Variation, (ushort)Map.Walls[wallPt].Variations, false);
                        }
                        wallDrag = wallPt;
                        dragging = true;
                    }
                    else
                        Map.Walls.Remove(wallPt);
                }
                else if (CurrentMode == Mode.MAKE_OBJECT)
                {
                    string m_ExePath = Process.GetCurrentProcess().MainModule.FileName;
                    m_ExePath = Path.GetDirectoryName(m_ExePath);
                    Map.Object obj = (Map.Object)DefaultObject.Clone();

                    obj.Name = cboObjCreate.Items[cboObjCreate.SelectedIndex].ToString();
                    //boxMod.Clear();
                    string mod = "";
                    if (File.Exists(m_ExePath + "\\scripts\\objects\\defaultmods\\" + obj.Name + ".txt"))
                    {
                        StreamReader SR;
                        SR = File.OpenText(m_ExePath + "\\scripts\\objects\\defaultmods\\" + obj.Name + ".txt");
                        if (SR != null)
                        {
                            obj.Properties = (Map.Object.Property)Convert.ToInt16(SR.ReadLine());
                            obj.Terminator = Convert.ToByte(SR.ReadLine());
                            while (!SR.EndOfStream)
                            {
                                mod += SR.ReadLine() + " ";
                            }
                        }
                        SR.Close();
                    }
                    //boxMod.Text = mod;

                    if (mod.Length > 0)
                    {
                        MemoryStream stream = new MemoryStream();
                        BinaryWriter wtr = new BinaryWriter(stream);
                        Regex bytes = new Regex("[0-9|a-f|A-F]{2}");
                        foreach (Match match in bytes.Matches(mod))
                            wtr.Write(Convert.ToByte(match.Value, 16));
                        obj.modbuf = stream.ToArray();
                    }
                    else
                        obj.modbuf = new byte[0];
                    //}
                    if (SnapGrid)//snap to grid when grid is on
                        pt = new Point((int)Math.Round((decimal)(pt.X / squareSize)) * squareSize, (int)Math.Round((decimal)(pt.Y / squareSize)) * squareSize);

                    if (SnapHalfGrid)//snap to half grid when grid is on
                        pt = new Point((int)Math.Round((decimal)((pt.X / (squareSize)) * squareSize) + squareSize / 2), (int)Math.Round((decimal)((pt.Y / (squareSize)) * squareSize) + squareSize / 2));

                    obj.Location = pt;
                    obj.Extent = DefaultObject.Extent + 1;
                    obj.UniqueID = IdCount++;
                    while (Map.Objects.extents.Contains(obj.Extent))
                        obj.Extent++;
                    Map.Objects.Add(obj);
                    unsafe
                    {
                        IntPtr ptr = Marshal.StringToHGlobalAnsi(obj.Name);
                        int val = obj.UniqueID;
                        MainWindow.myMap.AddObject(ptr.ToPointer(), (int)obj.Location.X, (int)obj.Location.Y, val);
                    }
                }
                else if (CurrentMode == Mode.MAKE_WINDOW)
                {
                    if (Map.Walls.ContainsKey(wallPt))
                        Map.Walls[wallPt].Window = !Map.Walls[wallPt].Window;
                }
                else if (CurrentMode == Mode.MAKE_DESTRUCTABLE)
                {
                    if (Map.Walls.ContainsKey(wallPt))
                        Map.Walls[wallPt].Destructable = !Map.Walls[wallPt].Destructable;
                }

                else if (CurrentMode == Mode.MAKE_SECRET)
                {
                    if (Map.Walls.ContainsKey(wallPt))
                    {
                        Map.Walls[wallPt].Secret = !Map.Walls[wallPt].Secret;
                        Map.Walls[wallPt].Secret_flags = (uint)Map.Wall.SecretFlags.Unknown100;
                        foreach (String s in secretFlagsBoxes.CheckedItems)
                            Map.Walls[wallPt].Secret_flags = Map.Walls[wallPt].Secret_flags | (uint)Enum.Parse(typeof(Map.Wall.SecretFlags), s);
                    }
                }
                else if (CurrentMode == Mode.MAKE_WAYPOINT)
                {
                    int i;
                    for (i = 1; Map.Waypoints.num_wp.ContainsKey(i); i++) ;
                    Map.Waypoint wp = new Map.Waypoint(wpNameBox.Text, pt, i);
                    wp.enabled = 1;
                    Map.Waypoints.Add(wp);
                    Map.Waypoints.num_wp.Add(i, wp);
                    //if (chkAutoLink1.Checked && KeyStates.wp1 != null)
                    //{
                    //    wp.AddConnByNum(KeyStates.wp1, Convert.ToByte(txtWpDefault.Text));
                    //}
                    //if (chkAutoLink2.Checked && KeyStates.wp1 != null)
                    //{
                    //    KeyStates.wp1.AddConnByNum(wp, Convert.ToByte(txtWpDefault.Text));
                    //}
                    //KeyStates.wp1 = wp;
                }
                else if (CurrentMode == Mode.EDIT_WAYPOINT)
                {
                    Map.Waypoint wp = Map.Waypoints.GetWPFromPoint(pt);
                    if (wp != null && KeyStates.wp1 != null && wp != KeyStates.wp1)
                    {
                        //wp.AddConnByNum(KeyStates.wp1,Map.Waypoint.WaypointConnection.DefaultFlag);
                        KeyStates.wp1.AddConnByNum(wp, Convert.ToByte(txtWpDefault.Text));
                        KeyStates.wp1 = null;
                    }
                    else
                    {
                        KeyStates.wp1 = wp;
                    }
                }
                else if (CurrentMode == Mode.SELECT_WAYPOINT)
                {
                    Map.Waypoint wp = Map.Waypoints.GetWPFromPoint(pt);
                    if (wp != null && wp != KeyStates.wp1)
                    {
                        string oldname = wpNameBox.Text;
                        OverrideChecking = true;
                        checkBox3.Checked = Convert.ToBoolean(wp.enabled);
                        OverrideChecking = false;
                        wpNameBox.Text = wp.Name;
                        if( KeyStates.wp1 !=null)
                            KeyStates.wp1.Name = oldname;
                        KeyStates.wp1 = wp;
                        KeyStates.MLeft = false;
                    }
                }
                else if (CurrentMode == Mode.MAKE_FLOOR)
                {
                    AddTile(tilePt);
                }
                else if (CurrentMode == Mode.ADD_POLYGON_PT)
                {
                    Map.Polygon poly = (Map.Polygon)Map.Polygons[listPolygons.SelectedIndex];
                    if (poly != null)
                        poly.Points.Add(new PointF(pt.X, pt.Y));
                }
                mapPanel.Invalidate();
            }
        }