예제 #1
0
 public bool FhEquals(FootholdLine obj)
 {
     return(((((FootholdLine)obj).FirstDot.X == FirstDot.X && ((FootholdLine)obj).SecondDot.X == SecondDot.X) &&
             (((FootholdLine)obj).FirstDot.Y == FirstDot.Y && ((FootholdLine)obj).SecondDot.Y == SecondDot.Y)) ||
            ((((FootholdLine)obj).FirstDot.X == SecondDot.X && ((FootholdLine)obj).SecondDot.X == FirstDot.X) &&
             (((FootholdLine)obj).FirstDot.Y == SecondDot.Y && ((FootholdLine)obj).SecondDot.Y == FirstDot.Y)));
 }
예제 #2
0
        public override void DoSnap()
        {
            FootholdLine closestLine     = null;
            double       closestDistance = double.MaxValue;

            foreach (FootholdLine fh in Board.BoardItems.FootholdLines)
            {
                // Trying to snap to other selected items can mess up some of the mouse bindings
                if (fh.FirstDot.Selected || fh.SecondDot.Selected)
                {
                    continue;
                }
                if (!fh.IsWall && BetweenOrEquals(X, fh.FirstDot.X, fh.SecondDot.X, (int)UserSettings.SnapDistance) && BetweenOrEquals(Y, fh.FirstDot.Y, fh.SecondDot.Y, (int)UserSettings.SnapDistance))
                {
                    double targetY  = fh.CalculateY(X) - 1;
                    double distance = Math.Abs(targetY - Y);
                    if (closestDistance > distance)
                    {
                        closestDistance = distance; closestLine = fh;
                    }
                }
            }
            if (closestLine != null)
            {
                SnapMoveAllMouseBoundItems(new XNA.Point(Parent.X + Parent.BoundItems[this].X, (int)closestLine.CalculateY(X) - 1));
            }
        }
예제 #3
0
 public FootholdLine GetOtherLine(FootholdLine line)
 {
     foreach (FootholdLine currLine in connectedLines)
     {
         if (line != currLine)
         {
             return(currLine);
         }
     }
     return(null);
 }
예제 #4
0
 public static int FHSorter(FootholdLine a, FootholdLine b)
 {
     if (a.FirstDot.X > b.FirstDot.X)
     {
         return(1);
     }
     else if (a.FirstDot.X < b.FirstDot.X)
     {
         return(-1);
     }
     else
     {
         if (a.FirstDot.Y > b.FirstDot.Y)
         {
             return(1);
         }
         else if (a.FirstDot.Y < b.FirstDot.Y)
         {
             return(-1);
         }
         else
         {
             if (a.SecondDot.X > b.SecondDot.X)
             {
                 return(1);
             }
             else if (a.SecondDot.X < b.SecondDot.X)
             {
                 return(-1);
             }
             else
             {
                 if (a.SecondDot.Y > b.SecondDot.Y)
                 {
                     return(1);
                 }
                 else if (a.SecondDot.Y < b.SecondDot.Y)
                 {
                     return(-1);
                 }
                 else
                 {
                     return(0);
                 }
             }
         }
     }
 }
예제 #5
0
 public void DeserializeBindings(IDictionary <string, object> bindSer, Dictionary <long, ISerializable> refDict)
 {
     firstDot  = (FootholdAnchor)refDict[(long)bindSer[FIRSTDOT_KEY]];
     secondDot = (FootholdAnchor)refDict[(long)bindSer[SECONDDOT_KEY]];
     if (bindSer.ContainsKey(PREVOVERRIDE_KEY))
     {
         prevOverride = (FootholdLine)refDict[(long)bindSer[PREVOVERRIDE_KEY]];
     }
     if (bindSer.ContainsKey(NEXTOVERRIDE_KEY))
     {
         prevOverride = (FootholdLine)refDict[(long)bindSer[NEXTOVERRIDE_KEY]];
     }
     firstDot.connectedLines.Add(this);
     secondDot.connectedLines.Add(this);
     firstDot.PointMoved  += OnFirstDotMoved;
     secondDot.PointMoved += OnSecondDotMoved;
 }
예제 #6
0
        public static FootholdLine[] GetSelectedFootholds(Board board)
        {
            int length = 0;

            foreach (FootholdLine line in board.BoardItems.FootholdLines)
            {
                if (line.Selected)
                {
                    length++;
                }
            }
            FootholdLine[] result = new FootholdLine[length];
            int            index  = 0;

            foreach (FootholdLine line in board.BoardItems.FootholdLines)
            {
                if (line.Selected)
                {
                    result[index] = line; index++;
                }
            }
            return(result);
        }
예제 #7
0
 public bool FhEquals(FootholdLine obj)
 {
     return ((((FootholdLine)obj).FirstDot.X == FirstDot.X && ((FootholdLine)obj).SecondDot.X == SecondDot.X)
         && (((FootholdLine)obj).FirstDot.Y == FirstDot.Y && ((FootholdLine)obj).SecondDot.Y == SecondDot.Y))
         || ((((FootholdLine)obj).FirstDot.X == SecondDot.X && ((FootholdLine)obj).SecondDot.X == FirstDot.X)
         && (((FootholdLine)obj).FirstDot.Y == SecondDot.Y && ((FootholdLine)obj).SecondDot.Y == FirstDot.Y));
 }
예제 #8
0
 public void DeserializeBindings(IDictionary<string, object> bindSer, Dictionary<long, ISerializable> refDict)
 {
     firstDot = (FootholdAnchor)refDict[(long)bindSer[FIRSTDOT_KEY]];
     secondDot = (FootholdAnchor)refDict[(long)bindSer[SECONDDOT_KEY]];
     if (bindSer.ContainsKey(PREVOVERRIDE_KEY))
         prevOverride = (FootholdLine)refDict[(long)bindSer[PREVOVERRIDE_KEY]];
     if (bindSer.ContainsKey(NEXTOVERRIDE_KEY))
         prevOverride = (FootholdLine)refDict[(long)bindSer[NEXTOVERRIDE_KEY]];
     firstDot.connectedLines.Add(this);
     secondDot.connectedLines.Add(this);
     firstDot.PointMoved += OnFirstDotMoved;
     secondDot.PointMoved += OnSecondDotMoved;
 }
예제 #9
0
 public static FootholdLine[] GetSelectedFootholds(Board board)
 {
     int length = 0;
     foreach (FootholdLine line in board.BoardItems.FootholdLines)
         if (line.Selected) length++;
     FootholdLine[] result = new FootholdLine[length];
     int index = 0;
     foreach (FootholdLine line in board.BoardItems.FootholdLines)
         if (line.Selected) { result[index] = line; index++; }
     return result;
 }
예제 #10
0
 public static int FHSorter(FootholdLine a, FootholdLine b)
 {
     if (a.FirstDot.X > b.FirstDot.X)
         return 1;
     else if (a.FirstDot.X < b.FirstDot.X)
         return -1;
     else
     {
         if (a.FirstDot.Y > b.FirstDot.Y)
             return 1;
         else if (a.FirstDot.Y < b.FirstDot.Y)
             return -1;
         else
         {
             if (a.SecondDot.X > b.SecondDot.X)
                 return 1;
             else if (a.SecondDot.X < b.SecondDot.X)
                 return -1;
             else
             {
                 if (a.SecondDot.Y > b.SecondDot.Y)
                     return 1;
                 else if (a.SecondDot.Y < b.SecondDot.Y)
                     return -1;
                 else
                     return 0;
             }
         }
     }
 }
예제 #11
0
 private void CreateFootholdsFromAnchorList(Board board, List<FootholdAnchor> anchors)
 {
     for (int i = 0; i < anchors.Count - 1; i++)
     {
         FootholdLine fh = new FootholdLine(board, anchors[i], anchors[i + 1]);
         board.BoardItems.FootholdLines.Add(fh);
     }
 }
예제 #12
0
파일: Mouse.cs 프로젝트: kokose1234/HaSuite
 public void TryConnectFoothold()
 {
     lock (Board.ParentControl)
     {
         Xna.Point pos = new Xna.Point(X, Y);
         SelectionInfo sel = board.GetUserSelectionInfo();
         foreach (FootholdAnchor anchor in Board.BoardItems.FHAnchors)
         {
             if (MultiBoard.IsPointInsideRectangle(pos, anchor.Left, anchor.Top, anchor.Right, anchor.Bottom) && anchor.CheckIfLayerSelected(sel))
             {
                 if (anchor.connectedLines.Count > 1)
                 {
                     continue;
                 }
                 if (connectedLines.Count > 0) // Are we already holding a foothold?
                 {
                     // We are, so connect the two ends
                     // Check that we are not connecting a foothold to itself, or creating duplicate footholds
                     if (connectedLines[0].FirstDot != anchor && !FootholdLine.Exists(anchor.X, anchor.Y, connectedLines[0].FirstDot.X, connectedLines[0].FirstDot.Y, Board))
                     {
                         Board.UndoRedoMan.AddUndoBatch(new List<UndoRedoAction> { UndoRedoManager.LineAdded(connectedLines[0], connectedLines[0].FirstDot, anchor) });
                         connectedLines[0].ConnectSecondDot(anchor);
                         // Now that we finished the previous foothold, create a new one between the anchor and the mouse
                         FootholdLine fh = new FootholdLine(Board, anchor);
                         Board.BoardItems.FootholdLines.Add(fh);
                     }
                 }
                 else // Construct a footholdline between the anchor and the mouse
                 {
                     Board.BoardItems.FootholdLines.Add(new FootholdLine(Board, anchor));
                 }
             }
         }
     }
 }
예제 #13
0
 public FootholdLine GetOtherLine(FootholdLine line)
 {
     foreach (FootholdLine currLine in connectedLines)
     {
         if (line != currLine)
         {
             return currLine;
         }
     }
     return null;
 }
예제 #14
0
 public void ParseOffsets(TileInstance instance, Board board, int x, int y)
 {
     List<FootholdAnchor> anchors = new List<FootholdAnchor>();
     foreach (XNA.Point foothold in footholdOffsets)
     {
         FootholdAnchor anchor = new FootholdAnchor(board, x + foothold.X, y + foothold.Y, instance.LayerNumber, instance.PlatformNumber, true);
         anchors.Add(anchor);
         board.BoardItems.FHAnchors.Add(anchor);
         instance.BindItem(anchor, foothold);
     }
     for (int i = 0; i < anchors.Count - 1; i++)
     {
         FootholdLine fh = new FootholdLine(board, anchors[i], anchors[i + 1]);
         board.BoardItems.FootholdLines.Add(fh);
     }
 }
예제 #15
0
        public override void DoSnap()
        {
            // Lookup possible snap to foothold
            FootholdLine closestLine         = null;
            double       closestDistanceLine = double.MaxValue;

            foreach (FootholdLine fh in Board.BoardItems.FootholdLines)
            {
                if (fh.FirstDot.Selected || fh.SecondDot.Selected)
                {
                    continue;
                }
                if (!fh.IsWall && BetweenOrEquals(X, fh.FirstDot.X, fh.SecondDot.X, (int)UserSettings.SnapDistance) && BetweenOrEquals(Y, fh.FirstDot.Y, fh.SecondDot.Y, (int)UserSettings.SnapDistance))
                {
                    double targetY  = fh.CalculateY(X) + 2;
                    double distance = Math.Abs(targetY - Y);
                    if (closestDistanceLine > distance)
                    {
                        closestDistanceLine = distance;
                        closestLine         = fh;
                    }
                }
            }

            // Lookup possible snap to rope/ladder
            XNA.Point?closestRopeHint     = null;
            double    closestDistanceRope = double.MaxValue;
            bool      closestIsLadder     = false;

            foreach (LayeredItem li in Board.BoardItems.TileObjs)
            {
                if (!(li is ObjectInstance) || li.Selected)
                {
                    continue;
                }
                ObjectInstance objInst = (ObjectInstance)li;
                ObjectInfo     objInfo = (ObjectInfo)objInst.BaseInfo;
                if (objInfo.RopeOffsets != null)
                {
                    LookupSnapInOffsetMap(objInst, objInfo.RopeOffsets, false, ref closestRopeHint, ref closestDistanceRope, ref closestIsLadder);
                }
                if (objInfo.LadderOffsets != null)
                {
                    LookupSnapInOffsetMap(objInst, objInfo.LadderOffsets, true, ref closestRopeHint, ref closestDistanceRope, ref closestIsLadder);
                }
            }

            if (closestDistanceRope >= closestDistanceLine && closestLine != null)
            {
                // If foothold is closer, snap to it
                SnapMoveAllMouseBoundItems(new XNA.Point(Parent.X + Parent.BoundItems[this].X, (int)closestLine.CalculateY(X) + 2));
            }
            else if (closestDistanceRope <= closestDistanceLine && closestRopeHint.HasValue)
            {
                // If rope/ladder is closer, snap to it and change our rope/ladder policy, unless it was hard-set by the user
                SnapMoveAllMouseBoundItems(new XNA.Point(closestRopeHint.Value.X, closestRopeHint.Value.Y));
                if (!this.parentRope.ladderSetByUser)
                {
                    this.parentRope.ladder = closestIsLadder;
                }
            }
        }