public FootholdEditor(FootholdLine[] footholds) { this.footholds = footholds; InitializeComponent(); styleManager.ManagerStyle = UserSettings.applicationStyle; int? force = footholds[0].Force; int? piece = footholds[0].Piece; bool cantThrough = footholds[0].CantThrough; bool forbidFallDown = footholds[0].ForbidFallDown; bool indeterminate = false; for (int i = 1; i < footholds.Length; i++) if (footholds[i].Force != force) { indeterminate = true; break; } if (indeterminate) forceEnable.CheckState = CheckState.Indeterminate; else if (forceEnable.Checked = force != null) forceInt.Value = (int)force; indeterminate = false; for (int i = 1; i < footholds.Length; i++) if (footholds[i].Piece != piece) { indeterminate = true; break; } if (indeterminate) pieceEnable.CheckState = CheckState.Indeterminate; else if (pieceEnable.Checked = force != null) pieceInt.Value = (int)piece; indeterminate = false; for (int i = 1; i < footholds.Length; i++) if (footholds[i].CantThrough != cantThrough) { indeterminate = true; break; } if (indeterminate) cantThroughBox.CheckState = CheckState.Indeterminate; else cantThroughBox.Checked = cantThrough; indeterminate = false; for (int i = 1; i < footholds.Length; i++) if (footholds[i].ForbidFallDown != forbidFallDown) { indeterminate = true; break; } if (indeterminate) forbidFallDownBox.CheckState = CheckState.Indeterminate; else forbidFallDownBox.Checked = forbidFallDown; }
public void Clear() { List <UndoRedoAction> foo = new List <UndoRedoAction>(); //the undoPipe here has no meaning, we don't need any undo info anyway if (currAddedObj != null) { currAddedObj.RemoveItem(ref foo); currAddedObj = null; } if (state == MouseState.Ropes || state == MouseState.Tooltip) { object[] keys = new object[BoundItems.Keys.Count]; BoundItems.Keys.CopyTo(keys, 0); if (state == MouseState.Ropes) { ((RopeAnchor)keys[0]).RemoveItem(ref foo); } else { ((ToolTipDot)keys[0]).ParentTooltip.RemoveItem(ref foo); } } else if (state == MouseState.Footholds && connectedLines.Count > 0) { FootholdLine fh = (FootholdLine)connectedLines[0]; fh.Remove(false, ref foo); Board.BoardItems.FootholdLines.Remove(fh); } InputHandler.ClearBoundItems(Board); InputHandler.ClearSelectedItems(Board); IsDown = false; }
public void TryConnectFoothold() { Xna.Point pos = new Xna.Point(X, Y); foreach (FootholdAnchor anchor in Board.BoardItems.FHAnchors) { if (MultiBoard.IsPointInsideRectangle(pos, anchor.Left, anchor.Top, anchor.Right, anchor.Bottom)) { if (connectedLines.Count > 0) { 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); FootholdLine fh = new FootholdLine(Board, anchor); Board.BoardItems.FootholdLines.Add(fh); } } else { Board.BoardItems.FootholdLines.Add(new FootholdLine(Board, anchor)); } } } }
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))); }
void MultiBoard_OnEditInstanceClicked(BoardItem item) { InputHandler.ClearBoundItems(multiBoard.SelectedBoard); try { if (item is ObjectInstance) { new ObjectInstanceEditor((ObjectInstance)item).ShowDialog(); } else if (item is TileInstance) { new TileInstanceEditor((TileInstance)item).ShowDialog(); } else if (item is Chair) { new GeneralInstanceEditor(item).ShowDialog(); } else if (item is FootholdAnchor) { FootholdLine[] selectedFootholds = FootholdLine.GetSelectedFootholds(item.Board); if (selectedFootholds.Length > 0) { new FootholdEditor(selectedFootholds).ShowDialog(); } else { new GeneralInstanceEditor(item).ShowDialog(); } } else if (item is RopeAnchor ropeItem) { new RopeInstanceEditor(ropeItem).ShowDialog(); } else if (item is LifeInstance lifeItem) { new LifeInstanceEditor(lifeItem).ShowDialog(); } else if (item is ReactorInstance reactorItem) { new ReactorInstanceEditor(reactorItem).ShowDialog(); } else if (item is BackgroundInstance backgroundItem) { new BackgroundInstanceEditor(backgroundItem).ShowDialog(); } else if (item is PortalInstance portal) { new PortalInstanceEditor(portal).ShowDialog(); } else if (item is ToolTipInstance tooltipItem) { new TooltipInstanceEditor(tooltipItem).ShowDialog(); } } catch (Exception e) { MessageBox.Show(string.Format("An error occurred while presenting the instance editor for {0}:\r\n{1}", item.GetType().Name, e.ToString())); } }
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); } }
public static FootholdLine CreateCustomFootholdLine(Board board, MapleDot firstDot, MapleDot secondDot) { FootholdLine result = new FootholdLine(); result.Board = board; result.FirstDot = firstDot; result.SecondDot = secondDot; return(result); }
private static FootholdAnchor GetOtherPoint(FootholdLine source, MapleDot point) { //This was ripped straight from HC v1.7 and edited to work with v2 -DeathRight if (((FootholdAnchor)source.FirstDot).X != point.X || ((FootholdAnchor)source.FirstDot).Y != point.Y) return (FootholdAnchor)source.FirstDot; else if (((FootholdAnchor)source.SecondDot).X != point.X || ((FootholdAnchor)source.SecondDot).Y != point.Y) return (FootholdAnchor)source.SecondDot; else throw new Exception(); }
public void ParseOffsets(TileInstance instance, Board board, Layer layer, 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, layer.LayerNumber, false); 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); } }
public override void DoSnap() { FootholdLine closestLine = null; int closestDistance = int.MaxValue; foreach (FootholdLine fh in Board.BoardItems.FootholdLines) { 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)) { int targetY = CalculateY(X, fh) + 2; int distance = Math.Abs(targetY - Y); if (closestDistance > distance) { closestDistance = distance; closestLine = fh; } } } if (closestLine != null) { this.Y = CalculateY(X, closestLine) + 2; } }
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); }
/*private static bool IsValidKeyAnchor(FootholdAnchor anchor) { int horizontalLines = 0; int nonHorizontalLines = 0; foreach (FootholdLine line in anchor.connectedLines) { if (line.FirstDot.Y == line.SecondDot.Y) horizontalLines++; else if (line.FirstDot.X != line.SecondDot.X) nonHorizontalLines++; } return horizontalLines == 1 && nonHorizontalLines == 1; }*/ private 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; } } } }
private static FootholdLine GetOtherFh(FootholdAnchor anchor, FootholdLine source, Hashtable fhListByPoint) { List<FootholdLine> connectedLines = (List<FootholdLine>)fhListByPoint[new Point(anchor.X, anchor.Y)]; if (connectedLines.Count < 2) return null; else if (connectedLines.Count == 2) { return connectedLines[1].FhEquals(source) ? connectedLines[0] : connectedLines[1]; } else //reaching this part means whoever made the map is a f*****g idiot { FootholdLine longestFh = null; int longestFhLenth = 0; foreach (FootholdLine fh in connectedLines) { int length = (int)Math.Sqrt(Math.Pow((fh.SecondDot.X - fh.FirstDot.X), 2) + Math.Pow((fh.SecondDot.Y - fh.FirstDot.Y), 2)); if (!fh.FhEquals(source) && length > longestFhLenth) { longestFh = fh; longestFhLenth = length; } } return longestFh; } }
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)); }
private int CalculateY(int x, FootholdLine fh) { return(((fh.FirstDot.Y - fh.SecondDot.Y) / (fh.FirstDot.X - fh.SecondDot.X)) * (x - fh.FirstDot.X) + fh.FirstDot.Y); // y-y1=m(x-x1) => y=(d/dx)(x-x1)+y1 }
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; }
public static FootholdLine CreateCustomFootholdLine(Board board, MapleDot firstDot, MapleDot secondDot) { FootholdLine result = new FootholdLine(); result.Board = board; result.FirstDot = firstDot; result.SecondDot = secondDot; return result; }
private static FootholdLine GetOtherLine(FootholdLine line, FootholdAnchor currAnchor) { foreach (FootholdLine currLine in currAnchor.connectedLines) if (line != currLine) return currLine; return null; }
public void ParseOffsets(TileInstance instance, Board board, Layer layer, 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, layer.LayerNumber, false); 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); } }
private static void LoadFootholds(WzImage mapImage, Board mapBoard) { List<FootholdAnchor> anchors = new List<FootholdAnchor>(); WzSubProperty footholdParent = (WzSubProperty)mapImage["foothold"]; int layer; int plat; FootholdAnchor a; FootholdAnchor b; FootholdAnchor c; FootholdAnchor d; foreach (WzSubProperty layerProp in footholdParent.WzProperties) { layer = int.Parse(layerProp.Name); foreach (WzSubProperty platProp in layerProp.WzProperties) { plat = int.Parse(platProp.Name); foreach (WzSubProperty fhProp in platProp.WzProperties) { a = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x1"]), InfoTool.GetInt(fhProp["y1"]), layer, false, plat); b = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x2"]), InfoTool.GetInt(fhProp["y2"]), layer, false, plat); int num = int.Parse(fhProp.Name); int next = InfoTool.GetInt(fhProp["next"]); int prev = InfoTool.GetInt(fhProp["prev"]); if (a.X != b.X || a.Y != b.Y) { FootholdLine fh = new FootholdLine(mapBoard, a, b); fh.num = num; fh.prev = prev; fh.next = next; fh.Name = fhProp.Name; mapBoard.BoardItems.FootholdLines.Add(fh); anchors.Add(a); anchors.Add(b); } } } anchors.Sort(new Comparison<FootholdAnchor>(FootholdAnchor.FHAnchorSorter)); int groupStart = 0; //inclusive int groupEnd = 0; //inclusive for (int i = 0; i < anchors.Count - 1; i++) { a = anchors[i]; b = anchors[i + 1]; if (a.Y != b.Y && a.X != b.X && a.LayerNumber == b.LayerNumber) { groupEnd = i; if (groupEnd - groupStart == 1) //there are 2 objects in the group, since groupEnd and groupStart are inclusive { c = anchors[groupStart]; d = anchors[groupEnd]; CheckAnchorPairMerge(c, d); } else if (groupEnd - groupStart != 0) { for (int j = groupStart; j <= groupEnd; j++) { c = anchors[j]; for (int k = groupStart; k <= groupEnd; k++) { if (c.removed) break; d = anchors[k]; if (d.removed) continue; CheckAnchorPairMerge(c, d); } } } groupStart = groupEnd + 1; } } groupEnd = anchors.Count - 1; if (groupEnd - groupStart == 1) //there are 2 objects in the group, since groupEnd and groupStart are inclusive { c = anchors[groupStart]; d = anchors[groupEnd]; CheckAnchorPairMerge(c, d); } else if (groupEnd - groupStart != 0) { for (int j = groupStart; j <= groupEnd; j++) { c = anchors[j]; for (int k = groupStart; k <= groupEnd; k++) { if (c.removed) break; d = anchors[k]; if (d.removed) continue; CheckAnchorPairMerge(c, d); } } } //FootholdAnchor.MergeAnchors(ref anchors); /*if (mapBoard.BoardItems.FHAnchors.Count + anchors.Count > mapBoard.BoardItems.FHAnchors.Capacity) mapBoard.BoardItems.FHAnchors.Capacity = mapBoard.BoardItems.FHAnchors.Count + anchors.Count; anchors.ForEach(X => if mapBoard.BoardItems.FHAnchors.Add(X)); anchors.Clear();*/ mapBoard.BoardItems.FHAnchors.Capacity = mapBoard.BoardItems.FHAnchors.Count + anchors.Count * 2; foreach (FootholdAnchor anchor in anchors) if (!anchor.removed) mapBoard.BoardItems.FHAnchors.Add(anchor); anchors.Clear(); } }
private static FootholdAnchor GetBottomAnchor(FootholdLine fh) { return fh.FirstDot.Y < fh.SecondDot.Y ? (FootholdAnchor)fh.SecondDot : (FootholdAnchor)fh.FirstDot; }
//false = prev is in second point, true = prev is in first point private static bool GetVerticalFootholdDirection(FootholdLine fh, Hashtable fhListByPoint) { FootholdLine oldFh = null; FootholdLine currFh = fh; while (currFh.FirstDot.X == currFh.SecondDot.X) { oldFh = currFh; currFh = GetOtherFh(GetTopAnchor(currFh), currFh, fhListByPoint); if (currFh == null) goto try_other_side; //no more connections, try from other side } FootholdAnchor oldFhConnectAnchor = GetTopAnchor(oldFh); FootholdAnchor otherAnchor = oldFhConnectAnchor == currFh.FirstDot ? (FootholdAnchor)currFh.SecondDot : (FootholdAnchor)currFh.FirstDot; return !((otherAnchor.X > oldFhConnectAnchor.X) ^ (fh.FirstDot.Y > fh.SecondDot.Y)); try_other_side: oldFh = null; currFh = fh; while (currFh.FirstDot.X == currFh.SecondDot.X) { oldFh = currFh; currFh = GetOtherFh(GetBottomAnchor(currFh), currFh, fhListByPoint); if (currFh == null) return false; //no more connections, return false (could be true too) because this foothold is 100% wall } oldFhConnectAnchor = GetBottomAnchor(oldFh); otherAnchor = oldFhConnectAnchor == currFh.FirstDot ? (FootholdAnchor)currFh.SecondDot : (FootholdAnchor)currFh.FirstDot; return !((otherAnchor.X > oldFhConnectAnchor.X) ^ (fh.FirstDot.Y < fh.SecondDot.Y)); }
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); } }
private int CalculateY(int x, FootholdLine fh) { return ((fh.FirstDot.Y - fh.SecondDot.Y) / (fh.FirstDot.X - fh.SecondDot.X)) * (x - fh.FirstDot.X) + fh.FirstDot.Y; // y-y1=m(x-x1) => y=(d/dx)(x-x1)+y1 }
public void TryConnectFoothold() { Xna.Point pos = new Xna.Point(X,Y); foreach (FootholdAnchor anchor in Board.BoardItems.FHAnchors) { if (MultiBoard.IsPointInsideRectangle(pos, anchor.Left, anchor.Top, anchor.Right, anchor.Bottom)) { if (connectedLines.Count > 0) { 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); FootholdLine fh = new FootholdLine(Board, anchor); Board.BoardItems.FootholdLines.Add(fh); } } else { Board.BoardItems.FootholdLines.Add(new FootholdLine(Board, anchor)); } } } }
private static FootholdAnchor GetOtherAnchor(FootholdLine line, FootholdAnchor currAnchor) { return (FootholdAnchor)(line.FirstDot == currAnchor ? line.SecondDot : line.FirstDot); }