public static Point PlaceByReference(Rectangle xMaster, PlaceDirection xDirection, int xMargin, Rectangle yMaster, PlaceDirection yDirection, int yMargin) { int x = 0; int y = 0; if (xDirection == PlaceDirection.Left) { x = xMaster.Left - xMargin; } else if (xDirection == PlaceDirection.Right) { x = xMaster.Right + xMargin; } else { throw new ArgumentException("xDirection must be Left or Right"); } if (yDirection == PlaceDirection.Top) { y = yMaster.Top - yMargin; } else if (yDirection == PlaceDirection.Bottom) { y = yMaster.Bottom + yMargin; } else { throw new ArgumentException("yDirection must be Top or Bottom"); } return(new Point(x, y)); }
public static Point GetDirectionValue(PlaceDirection direction) { int v = (int)direction; int col = v % 3; int row = v / 3; return(new Point(col, row)); }
virtual public void SetAttackAreas(PlaceDirection dir) { enemiesInAttackAreas.Clear(); currentAttackTarget = null; RemoveListener(); attackAreas.Clear(); attackAreasPos = new Vector2[] { new Vector2(1, 0), new Vector2(-1, 0), new Vector2(1, 1), new Vector2(-1, 1), new Vector2(0, 1), new Vector2(0, 2) }; switch (dir) { case PlaceDirection.up: break; case PlaceDirection.down: for (int i = 0; i < attackAreasPos.Length; i++) { attackAreasPos[i] = -attackAreasPos[i]; } break; case PlaceDirection.left: for (int i = 0; i < attackAreasPos.Length; i++) { float xTmp = attackAreasPos[i].x; float yTmp = -attackAreasPos[i].y; attackAreasPos[i].x = yTmp; attackAreasPos[i].y = xTmp; } break; case PlaceDirection.right: for (int i = 0; i < attackAreasPos.Length; i++) { float xTmp = attackAreasPos[i].x; float yTmp = attackAreasPos[i].y; attackAreasPos[i].x = yTmp; attackAreasPos[i].y = xTmp; //Debug.Log(attackAreasPos[i]); } break; default: break; } foreach (Vector2 item in attackAreasPos) { MapUnitPre t = MapInSceneManager.Instance.GetMapUnitPre((int)item.x + (int)transform.position.x, (int)item.y + (int)transform.position.y); if (t != null) { attackAreas.Add(t); } } }
/* * public void UpDir() * { * //这里的init作用为设置攻击方块的监听,故暂且不init并不出error * curOperator.GetComponent<BaseOperator>().Init(PlaceDirection.up); * Destroy(curDirChoosePanel); * * * showAttackAreaPreview = false; * curOperator.GetComponent<BaseOperator>().OffShowAttackArea(); * isPlacingOperator = false; * } */ void ShowAttackAreaPreview() { Vector2 lookDirection; lookDirection = Camera.main.ScreenToWorldPoint(Input.mousePosition) - curOperator.transform.position; float angle = 90 - Mathf.Atan2(lookDirection.x, lookDirection.y) * Mathf.Rad2Deg; angle = Mathf.Deg2Rad * angle; //Debug.LogFormat("Cos:{0}, Sin:{1}", Mathf.Cos(angle), Mathf.Sin(angle)); if (Mathf.Cos(angle) >= 0.7f && Mathf.Abs(Mathf.Sin(angle)) <= 0.7f) { if (dir != PlaceDirection.right) { //Debug.Log("right"); curOperator.GetComponent <BaseOperator>().OffShowAttackArea(); dir = PlaceDirection.right; curOperator.GetComponent <BaseOperator>().Init(PlaceDirection.right); curOperator.GetComponent <BaseOperator>().ShowAttackArea(); } } else if (Mathf.Abs(Mathf.Cos(angle)) <= 0.7f && Mathf.Sin(angle) >= 0.7f) { if (dir != PlaceDirection.up) { //Debug.Log("up"); curOperator.GetComponent <BaseOperator>().OffShowAttackArea(); dir = PlaceDirection.up; curOperator.GetComponent <BaseOperator>().Init(PlaceDirection.up); curOperator.GetComponent <BaseOperator>().ShowAttackArea(); } } else if (Mathf.Cos(angle) <= -0.7f && Mathf.Abs(Mathf.Sin(angle)) <= 0.7f) { if (dir != PlaceDirection.left) { //Debug.Log("left"); curOperator.GetComponent <BaseOperator>().OffShowAttackArea(); dir = PlaceDirection.left; curOperator.GetComponent <BaseOperator>().Init(PlaceDirection.left); curOperator.GetComponent <BaseOperator>().ShowAttackArea(); } } else { if (dir != PlaceDirection.down) { //Debug.Log("down"); curOperator.GetComponent <BaseOperator>().OffShowAttackArea(); dir = PlaceDirection.down; curOperator.GetComponent <BaseOperator>().Init(PlaceDirection.down); curOperator.GetComponent <BaseOperator>().ShowAttackArea(); } } }
//init此处只有设置监听的作用 public void Init(PlaceDirection dir) { placeDirection = dir; SetAttackAreas(placeDirection); isInited = true; if (placeDirection == PlaceDirection.left) { transform.localScale = new Vector3(-1, 1, 1); } SetListener(); }
public static Rectangle InnerByDirection(this Rectangle master, Size slave, PlaceDirection direction, PlaceLevel level, int margin) { var directionValue = GetDirectionValue(direction); var xs = new int[3] { master.Right - slave.Width - margin, master.Left, master.Left + margin }; var ys = new int[3] { master.Bottom - slave.Height - margin, master.Top, master.Top + margin }; var levelValue = GetLevelValue(level); var x = xs[directionValue.X] + (directionValue.X == 1 ? (int)((master.Width - slave.Width) * levelValue) : 0); var y = ys[directionValue.Y] + (directionValue.Y == 1 ? (int)((master.Height - slave.Height) * levelValue) : 0); return(new Rectangle(new Point(x, y), slave)); }
public static Point PlaceByDirection(Rectangle master, Size slave, PlaceDirection direction, PlaceLevel level, int margin) { Point directionValue = GetDirectionValue(direction); int[] xs = new int[3] { master.Left - slave.Width - margin, master.Left, master.Right + margin }; int[] ys = new int[3] { master.Top - slave.Height - margin, master.Top, master.Bottom + margin }; double levelValue = GetLevelValue(level); int x = xs[directionValue.X] + (directionValue.X == 1 ? (int)((master.Width - slave.Width) * levelValue) : 0); int y = ys[directionValue.Y] + (directionValue.Y == 1 ? (int)((master.Height - slave.Height) * levelValue) : 0); return(new Point(x, y)); }
public Point CulcStartPoint(PlacedWord placedWord, CrossPointInfo info, PlaceDirection direction, Word word) { Point pointToPlace = new Point(); Point crossPoint = new Point(); switch (placedWord.PlaceDirection) { case PlaceDirection.Horisontal: { crossPoint.X = placedWord.StartPoint.X + info.GetThisCross(placedWord.Word.Number); crossPoint.Y = placedWord.StartPoint.Y; break; } case PlaceDirection.Vertiacal: { crossPoint.X = placedWord.StartPoint.X; crossPoint.Y = placedWord.StartPoint.Y + info.GetThisCross(placedWord.Word.Number); break; } } switch (direction) { case PlaceDirection.Horisontal: { pointToPlace.X = crossPoint.X - info.GetThisCross(word.Number); pointToPlace.Y = crossPoint.Y; break; } case PlaceDirection.Vertiacal: { pointToPlace.X = crossPoint.X; pointToPlace.Y = crossPoint.Y - info.GetThisCross(word.Number); break; } } return pointToPlace; }
public static void PlaceByDirection(Control master, Control slave, PlaceDirection direction, PlaceLevel level, int margin) { slave.Bounds = DrawingUtils.PlaceByDirection(master.Bounds, slave.Size, direction, level, margin); }
public static Point PlaceByDirection(Rectangle master, Size slave, PlaceDirection direction, PlaceLevel level) { return(PlaceByDirection(master, slave, direction, level, DefaultMargin)); }
public static Point PlaceByDirection(Rectangle master, Size slave, PlaceDirection direction, int margin) { return(PlaceByDirection(master, slave, direction, PlaceLevel.Zero, margin)); }
public static Rectangle InnerByDirection(this Rectangle master, Size slave, PlaceDirection direction, int margin) { return(InnerByDirection(master, slave, direction, PlaceLevel.Zero, margin)); }
public static Rectangle PlaceByDirection2(Rectangle master, Size slave, PlaceDirection direction, PlaceLevel level, int margin) { return(new Rectangle(PlaceByDirection(master, slave, direction, level, margin), slave)); }
public static Rectangle PlaceByDirection2(Rectangle master, Size slave, PlaceDirection direction) { return(new Rectangle(PlaceByDirection(master, slave, direction), slave)); }
public static Rectangle InnerByDirection(this Rectangle master, Size slave, PlaceDirection direction, PlaceLevel level) { return(InnerByDirection(master, slave, direction, level, DefaultMargin)); }
public static Rectangle PlaceByDirection(this Rectangle master, Size slave, PlaceDirection direction) { return(PlaceByDirection(master, slave, direction, PlaceLevel.Zero)); }
public void InsertWord(Word word, PlaceDirection direction, Point startPoint) { var item = new PlacedWord { Word = word, StartPoint = startPoint, PlaceDirection = direction }; switch (item.PlaceDirection) { case PlaceDirection.Horisontal: { InsertWordHorisontal(word, item.StartPoint); break; } case PlaceDirection.Vertiacal: { InsertWordVertical(word, item.StartPoint); break; } } PlacedWords.Push(item); }
public static Point PlaceByReference(Rectangle xMaster, PlaceDirection xDirection, Rectangle yMaster, PlaceDirection yDirection, int yMargin) { int dm = DefaultMargin; return(PlaceByReference(xMaster, xDirection, dm, yMaster, yDirection, yMargin)); }
public static void PlaceByDirection(Control master, Control slave, PlaceDirection direction, PlaceLevel level) { PlaceByDirection(master, slave, direction, level, DrawingUtils.DefaultMargin); }
public static void PlaceByDirection(Control master, Control slave, PlaceDirection direction, int margin) { PlaceByDirection(master, slave, direction, PlaceLevel.Zero, margin); }
public static Dictionary <Control, Rectangle> LayoutArray(Rectangle layoutBounds, ContentAlignment anchor, PlaceDirection direction, PlaceLevel level, int margin, IEnumerable <KeyValuePair <Control, Size> > collection) { var map = new Dictionary <Control, Rectangle>(); var array = collection.ToArray(); if (array.Length > 0) { var maxWidth = array.Max(c => c.Value.Width); var maxHeight = array.Max(c => c.Value.Height); var maxSize = new Size(maxWidth, maxHeight); var first = true; var lastBounds = new Rectangle(); foreach (var pair in array) { var control = pair.Key; var size = pair.Value; var newBounds = new Rectangle(); if (first == true) { first = false; var directionValue = DrawingUtils.GetDirectionValue(direction) - new Size(1, 1); var s = new Size(directionValue.X != 0 ? size.Width : maxSize.Width, directionValue.Y != 0 ? size.Height : maxSize.Height); var initial = new Rectangle(DrawingUtils.Alignment(s, layoutBounds, anchor), s); newBounds = initial.InnerByDirection(size, direction, level, 0); } else { newBounds = lastBounds.PlaceByDirection(size, direction, level, margin); } map[control] = newBounds; lastBounds = newBounds; } } return(map); }
public static Dictionary <Control, Rectangle> LayoutArray(Rectangle layoutBounds, ContentAlignment anchor, PlaceDirection direction, PlaceLevel level, int margin, IEnumerable <Control> collection) { return(LayoutArray(layoutBounds, anchor, direction, level, margin, collection.Select(c => new KeyValuePair <Control, Size>(c, c.PreferredSize)))); }
public bool CanPlaceWord(PlacedWord placedWord, CrossPointInfo info, PlaceDirection direction, Word word) { var pointToPlace = CulcStartPoint(placedWord, info, direction, word); var result = true; switch (direction) { case PlaceDirection.Horisontal: { for (int index = 0; index < word.Text.Length; index++) { var c = word.Text[index]; var internalChar = InternalMatrix[pointToPlace.X + index, pointToPlace.Y]; if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c)) { continue; } else { result = false; } } break; } case PlaceDirection.Vertiacal: { for (int index = 0; index < word.Text.Length; index++) { var c = word.Text[index]; var internalChar = InternalMatrix[pointToPlace.X, pointToPlace.Y + index]; if ((internalChar.Symbol == DefSymbol) || (internalChar.Symbol == c)) { continue; } else { result = false; } } break; } } return result; }
public static Point GetDirectionValue(PlaceDirection direction) { var v = (int)direction; return(new Point(v % 3, v / 3)); }