//Returns true index A is aligned between index B and index C along cardinals or diagonals or both bool IsAlignedBetween(TileIndex a, TileIndex b, TileIndex c, AlignmentMode mode) { if (!IsAligned(a, b, c, mode)) { return(false); } if (mode == AlignmentMode.Cardinal || mode == AlignmentMode.Both) { if (c.row == b.row) { return(a.col < Math.Max(c.col, b.col) && a.col > Math.Min(c.col, b.col)); } if (c.col == b.col) { return(a.row < Math.Max(c.row, b.row) && a.row > Math.Min(c.row, b.row)); } } if (mode == AlignmentMode.Diagonal || mode == AlignmentMode.Both) { //Already must be aligned diagonally if reached here return(a.row < Math.Max(c.row, b.row) && a.row > Math.Min(c.row, b.row)); } return(false); }
/*public LayoutStyle CreateStyle() * { * return CreateStyle(AlignmentMode.NotSet); * }*/ /// <summary> /// 创建一个样式。注意:样式尽可能的重用,以减少样式的定义数量。 /// </summary> public LayoutStyle CreateStyle(bool hasBorder = false, AlignmentMode alignment = AlignmentMode.NotSet, bool fontBold = false, short fontPoints = 0) { var style = CreateStyle(alignment, AlignmentMode.Center, false, fontBold, fontPoints); style.HasBorder = hasBorder; return(style); }
private void updateBackgroundAlignment(pSprite s, AlignmentMode alignmentMode, BackgroundAdjustmentDelegate backgroundAdjustment) { if (s == null || BackgroundTexture == null) { return; } if ((alignmentMode & AlignmentMode.Storyboard) != 0) { s.ScaleToScreen((alignmentMode & AlignmentMode.Widescreen) != 0); } else { //first align based on height s.Scale = (float)GameBase.WindowManager.SpriteRes / BackgroundTexture.DisplayHeight; //if it isn't wide enough, let's make it so. if (s.Width * s.Scale * GameBase.WindowManager.RatioInverse < GameBase.WindowManager.Width) { s.Scale = GameBase.WindowManager.Width / ((float)s.Width * GameBase.WindowManager.RatioInverse); } } if (backgroundAdjustment != null) { backgroundAdjustment(BackgroundSprite); } currentAlignmentMode = alignmentMode; currentBackgroundAdjustment = backgroundAdjustment; }
internal void UpdateBackground(AlignmentMode alignmentMode = AlignmentMode.Default, BackgroundAdjustmentDelegate backgroundAdjustment = null) { BackgroundTexture = null; showBackground = true; backgroundUpdateCount++; updateBackground(alignmentMode, backgroundAdjustment); }
/// <summary> /// Constructor with fields. /// </summary> /// <param name="k"></param> /// <param name="mode"></param> /// <param name="task"></param> /// <param name="additionalEqualities"></param> /// <param name="additionalEqualitiesLength"></param> public AlignmentConfig(int k, AlignmentMode mode, AlignmentTask task, EqualityPair[] additionalEqualities, int additionalEqualitiesLength) { K = k; Mode = mode; Task = task; AdditionalEqualities = additionalEqualities; AdditionalEqualitiesLength = additionalEqualitiesLength; }
public UISprite(UIElement parent, Sprite sprite, float scale, AlignmentMode alignment, GameObject linkedObject) { this.gameObject = linkedObject; this.Sprite = sprite; this.Scale = scale; this.Position = Vector2.Zero; this.Padding = Vector2.Zero; this.SetParent(parent); this.initRenderer(); this.SetAlignment(alignment); }
//-------------------------------------------------------------------------------------------------- #endregion #region Create CircularArray() { Name = "Circular Array"; _Quantity = 1; Radius = 10; KeepOrientation = false; _OriginalAngle = 0; _Range = 360; _Alignment = AlignmentMode.First; _Plane = PlaneType.XY; }
public UIText(UIElement parent, AlignmentMode alignment, string text, Color4 color, Font font, float scale, GameObject linkedObject) { this.Text = text; this.Color = color; this.gameObject = linkedObject; this.Font = font; this.Scale = scale; this.Position = Vector2.Zero; this.Padding = Vector2.Zero; this.initRenderer(); this.SetParent(parent); this.SetAlignment(alignment); }
private pSprite createBackgroundSprite(AlignmentMode alignmentMode) { if (BackgroundTexture == null || BackgroundTexture.IsDisposed) { BackgroundTexture = TextureManager.Load(@"menu-background", SkinSource.Osu); } Fields field = (alignmentMode & AlignmentMode.Storyboard) != 0 ? Fields.StoryboardCentre : Fields.Centre; pSprite s = new pSprite(BackgroundTexture, field, Origins.Centre, Clocks.Game, Vector2.Zero, SpriteManager.drawOrderBwd(GameBase.Time), true, Color.White); return(s); }
//-------------------------------------------------------------------------------------------------- #endregion #region Create LinearArray() { Name = "Linear Array"; _Plane = PlaneType.XY; _Rotation = 0; _Quantity1 = 1; _Distance1 = 1.0; _DistanceMode1 = DistanceMode.Interval; _Alignment1 = AlignmentMode.First; _Quantity2 = 1; _Distance2 = 1.0; _DistanceMode2 = DistanceMode.Interval; _Alignment2 = AlignmentMode.First; _Border = false; }
public LayoutStyle CreateStyle(AlignmentMode alignment, AlignmentMode verticalAlignment = AlignmentMode.Center, bool applyToColumn = false, bool fontBold = false, short fontPoints = 0, string backColor = null) { var style = new LayoutStyle { Alignment = alignment, VerticalAlignment = verticalAlignment, FontBold = fontBold, FontPoints = fontPoints, ApplyToColumn = applyToColumn, BackgroundColor = backColor, //HasBorder = true }; SheetStyles.Add(style); return(style); }
internal void UpdateBackground() { if (backgroundUsedInStoryboard && showStoryboard) { GameBase.TransitionManager.ClearBackground(); backgroundIsReady = true; } else { Ruleset ruleset = Ruleset.Instance; pSprite eventSprite = backgroundEvent != null ? backgroundEvent.Sprite : null; bool storyboardVisible = HasStoryboard && showStoryboard; bool hasBackgroundOffset = eventSprite != null && eventSprite.Position != Vector2.Zero; bool applyRulesetAdjustment = ruleset != null && !HasStoryboard; AlignmentMode alignmentMode = storyboardVisible ? WidescreenStoryboard ? AlignmentMode.StoryboardWidescreen : AlignmentMode.Storyboard : AlignmentMode.Default; // Background offsets are relative to the StoryboardCentre Field, // if there is an offset, make sure that the background is on this field. if (hasBackgroundOffset && (alignmentMode & AlignmentMode.Storyboard) == 0) { alignmentMode = AlignmentMode.StoryboardWidescreen; } backgroundIsReady = false; GameBase.TransitionManager.UpdateBackground(alignmentMode, backgroundSprite => { if (hasBackgroundOffset) { backgroundSprite.Position = eventSprite.Position; } if (applyRulesetAdjustment) { ruleset.AdjustBackgroundSprite(backgroundSprite); } backgroundIsReady = true; }); } }
//Returns true index A and B are aligned along cardinals or diagonals or both bool IsAligned(TileIndex a, TileIndex b, AlignmentMode mode) { //check aligned vertically or horizontally if (mode == AlignmentMode.Cardinal || mode == AlignmentMode.Both) { if (a.row == b.row) { return(true); } if (a.col == b.col) { return(true); } } if (mode == AlignmentMode.Diagonal || mode == AlignmentMode.Both) { if (Math.Abs(a.row - b.row) == Math.Abs(a.col - b.col)) { return(true); } } return(false); }
//Returns true if index A and B and C are aligned along cardinals or diagonals or both bool IsAligned(TileIndex a, TileIndex b, TileIndex c, AlignmentMode mode) { //check aligned vertically or horizontally if (mode == AlignmentMode.Cardinal || mode == AlignmentMode.Both) { if (a.row == b.row && a.row == c.row) { return(true); } if (a.col == b.col && a.row == c.row) { return(true); } } if (mode == AlignmentMode.Diagonal || mode == AlignmentMode.Both) { //Needs to check all 3 on the same diagonal so cannot use abs //(y2-y1)/(x2-x1) = 1 or -1 //Positive diagonal: if (b.row - a.row == b.col - a.col) { if (c.row - a.row == c.col - a.col) { return(true); } } //Negative diagonal: if (b.row - a.row == a.col - b.col) { if (c.row - a.row == a.col - c.col) { return(true); } } } return(false); }
public void SetAlignment(AlignmentMode alignment) { this.Alignment = alignment; if (this.Parent != null && this.Parent is ICanvas) { Vector2 position = this.Position; Vector2 pPos = this.Parent.Position; ICanvas pCanvas = (ICanvas)(this.Parent); Size pSize = pCanvas.Size; int spritePixelWidth = (int)(this.Sprite.Texture.Width * this.Sprite.Size.X); int spritePixelHeight = (int)(this.Sprite.Texture.Height * this.Sprite.Size.Y); if (this.RescaleMode != ScaleMode.Fill) { switch (alignment) { case AlignmentMode.Center: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + ((pSize.Width - spritePixelWidth) / 2); } else { position.X = pPos.X + (pSize.Width / 2); } position.Y = (pPos.Y + (pSize.Height / 2)) - (spritePixelHeight / 2); break; } case AlignmentMode.CenterLeft: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + this.Padding.X; } else { position.X = pPos.X; } position.Y = (pPos.Y + (pSize.Height / 2)) - (spritePixelHeight / 2); break; } case AlignmentMode.CenterRight: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + (pSize.Width - spritePixelWidth - this.Padding.X); } else { position.X = pPos.X + (pSize.Width - spritePixelWidth); } position.Y = (pPos.Y + (pSize.Height / 2)) - (spritePixelHeight / 2); break; } case AlignmentMode.BottomCenter: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + ((pSize.Width - spritePixelWidth) / 2); } else { position.X = pPos.X + (pSize.Width / 2); } position.Y = pPos.Y + this.Padding.Y; break; } case AlignmentMode.BottomLeft: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + this.Padding.X; } else { position.X = pPos.X; } position.Y = pPos.Y + this.Padding.Y; break; } case AlignmentMode.BottomRight: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + (pSize.Width - spritePixelWidth - this.Padding.X); } else { position.X = pPos.X + (pSize.Width - spritePixelWidth); } position.Y = pPos.Y + this.Padding.Y; break; } case AlignmentMode.TopCenter: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + ((pSize.Width - spritePixelWidth) / 2); } else { position.X = pPos.X + (pSize.Width / 2); } position.Y = pPos.Y + (pSize.Height - this.Padding.Y); break; } case AlignmentMode.TopLeft: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + this.Padding.X; } else { position.X = pPos.X; } position.Y = pPos.Y + (pSize.Height - this.Padding.Y); break; } case AlignmentMode.TopRight: { if (spritePixelWidth <= pSize.Width) { position.X = pPos.X + (pSize.Width - spritePixelWidth - this.Padding.X); } else { position.X = pPos.X + (pSize.Width - spritePixelWidth); } position.Y = pPos.Y + (pSize.Height - this.Padding.Y); break; } } } else { position = pPos; } this.Position = position; this.Sprite.Position = position; this.spriteRenderer.UpdateVertexBuffer(); } }
//// All the texture2D with alignment ///// <summary> ///// Texture that uses all the Texture2D given with Alignment ///// </summary> ///// <param name="texture"></param> ///// <param name="alignmentOffsetX"></param> ///// <param name="alignmentOffsetY"></param> //public Texture(Texture2D texture, int alignmentOffsetX, int alignmentOffsetY) // : this(texture, 0, 0, texture.Width, texture.Height, alignmentOffsetX, alignmentOffsetY) //{ //} // All the texture2D with alignment preset mode /// <summary> /// Texture that uses all the Texture2D given with Alignment preset (Center, Left, Right) /// </summary> /// <param name="texture"></param> /// <param name="mode"></param> public Texture(Texture2D texture, AlignmentMode mode) : this(texture) { if (mode == AlignmentMode.Center) this.AlignmentOffset = new Point(-(Width - TileInfo.TileWidth) / 2, Height - TileInfo.TileHeight); }
public void SetAlignment(AlignmentMode alignment) { this.Alignment = alignment; if (this.Parent != null && this.Parent is ICanvas) { Vector2 position = this.Position; Vector2 pPos = this.Parent.Position; ICanvas pCanvas = (ICanvas)(this.Parent); System.Drawing.Size pSize = pCanvas.Size; int textPixelWidth = (int)this.textRenderer.GetPixelWidth(); int textPixelHeight = this.textRenderer.GetPixelHeight(); if (this.RescaleMode == ScaleMode.Fill) { textPixelWidth -= 1; } switch (alignment) { case AlignmentMode.Center: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + ((pSize.Width - textPixelWidth) / 2); } else { position.X = pPos.X + (pSize.Width / 2); } position.Y = pPos.Y + (pSize.Height / 2) - (textPixelHeight / 2); break; } case AlignmentMode.CenterLeft: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + this.Padding.X; } else { position.X = pPos.X; } position.Y = pPos.Y + (pSize.Height / 2) - (textPixelHeight / 2); break; } case AlignmentMode.CenterRight: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + (pSize.Width - textPixelWidth - this.Padding.X); } else { position.X = pPos.X + (pSize.Width - textPixelWidth); } position.Y = pPos.Y + (pSize.Height / 2) - (textPixelHeight / 2); break; } case AlignmentMode.BottomCenter: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + ((pSize.Width - textPixelWidth) / 2); } else { position.X = pPos.X + (pSize.Width / 2); } position.Y = pPos.Y + this.Padding.Y; break; } case AlignmentMode.BottomLeft: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + this.Padding.X; } else { position.X = pPos.X; } position.Y = pPos.Y + this.Padding.Y; break; } case AlignmentMode.BottomRight: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + (pSize.Width - textPixelWidth - this.Padding.X); } else { position.X = pPos.X + (pSize.Width - textPixelWidth); } position.Y = pPos.Y + this.Padding.Y; break; } case AlignmentMode.TopCenter: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + ((pSize.Width - textPixelWidth) / 2); } else { position.X = pPos.X + (pSize.Width / 2); } position.Y = pPos.Y + (pSize.Height - this.Padding.Y); break; } case AlignmentMode.TopLeft: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + this.Padding.X; } else { position.X = pPos.X; } position.Y = pPos.Y + (pSize.Height - this.Padding.Y); break; } case AlignmentMode.TopRight: { if (textPixelWidth <= pSize.Width) { position.X = pPos.X + (pSize.Width - textPixelWidth - this.Padding.X); } else { position.X = pPos.X + (pSize.Width - textPixelWidth); } position.Y = pPos.Y + (pSize.Height - this.Padding.Y); break; } } this.textRenderer.Position = position; this.textRenderer.UpdateVertexBuffer(); } }
/// <summary> /// This script is executed in the editor and so this will be called if something changes in the editor /// It keeps track of the parents changes in scale and calculates the correct alignment /// </summary> void Update() { if (firstUpdate) { Initialize(); firstUpdate = false; } // clean up the scale effect to be either 1 or 0 scaleEffect = new Vector3( Mathf.Max(0, Mathf.Min(1, Mathf.Round(scaleEffect.x))), Mathf.Max(0, Mathf.Min(1, Mathf.Round(scaleEffect.y))), Mathf.Max(0, Mathf.Min(1, Mathf.Round(scaleEffect.z)))); // make sure that the scale of the parent is not 0 if (transform.localScale.x != 0 && transform.localScale.y != 0 && transform.localScale.z != 0) { ratio = transform.parent.localScale; Transform current = transform.parent.parent; while (current != null) { ratio.Scale(current.localScale); current = current.parent; } } if (alignmentMode == AlignmentMode.NONE) { alignTo = null; previousAlignmentMode = alignmentMode; return; } if (alignmentMode == AlignmentMode.TRANSFORM) { // if we just got into this mode => restore alignment transform if (previousAlignmentMode != alignmentMode) { // restore the transform if it was set in the align-to-transform mode if (alignTo == null && previousAlignTo != null) { alignTo = previousAlignTo; AutoCalculateOffset(alignTo.position); } } // if the target transform changed: // calculate the offset so that the object itself stays at the same position if (alignTo != null && alignTo != previousAlignTo) { AutoCalculateOffset(alignTo.position); } if (alignTo != null) { AlignToPosition(alignTo.position); } // store the alignTo in order to detect changes previousAlignTo = alignTo; } else { // delete the reference of the alignTo to indicate that this field not used in another mode alignTo = null; Vector3 alignmentPos = new Vector3(); // get alignment position switch (alignmentMode) { case AlignmentMode.CENTER: alignmentPos = transform.parent.TransformPoint(Vector3.zero); break; case AlignmentMode.LEFT: alignmentPos = transform.parent.TransformPoint(new Vector3(0, 0, 0.5f)); break; case AlignmentMode.RIGHT: alignmentPos = transform.parent.TransformPoint(new Vector3(0, 0, -0.5f)); break; case AlignmentMode.TOP: alignmentPos = transform.parent.TransformPoint(new Vector3(0, 0.5f, 0)); break; case AlignmentMode.BOTTOM: alignmentPos = transform.parent.TransformPoint(new Vector3(0, -0.5f, 0)); break; case AlignmentMode.TOP_LEFT: alignmentPos = transform.parent.TransformPoint(new Vector3(0, 0.5f, 0.5f)); break; case AlignmentMode.TOP_RIGHT: alignmentPos = transform.parent.TransformPoint(new Vector3(0, 0.5f, -0.5f)); break; case AlignmentMode.BOTTOM_LEFT: alignmentPos = transform.parent.TransformPoint(new Vector3(0, -0.5f, 0.5f)); break; case AlignmentMode.BOTTOM_RIGHT: alignmentPos = transform.parent.TransformPoint(new Vector3(0, -0.5f, -0.5f)); break; default: alignmentPos = transform.position; break; } // automatically change the offset if the alignment mode is changed to fit to the calculated alignment if (previousAlignmentMode != alignmentMode) { AutoCalculateOffset(alignmentPos); } // align to the calculated position AlignToPosition(alignmentPos); } previousAlignmentMode = alignmentMode; }
private void updateBackground(AlignmentMode alignmentMode, BackgroundAdjustmentDelegate backgroundAdjustment, pTexture loadedTexture = null) { if (!showBackground) { return; } if (BackgroundSprite != null && GameBase.Time >= Menu.IntroLength) { BackgroundSprite.FadeTo(1, 100); } if (loadedTexture == null || loadedTexture.IsDisposed) { //we need to load a new texture. int updateCountAtStart = backgroundUpdateCount; GameBase.RunBackgroundThread(delegate { if (updateCountAtStart != backgroundUpdateCount) { return; } pTexture loaded = null; //load from beatmap if (BeatmapManager.Current != null && !string.IsNullOrEmpty(BeatmapManager.Current.BackgroundImage)) { switch (GameBase.Mode) { case OsuModes.Edit: case OsuModes.SelectEdit: case OsuModes.SelectMulti: case OsuModes.SelectPlay: case OsuModes.Play: case OsuModes.Rank: case OsuModes.RankingTagCoop: case OsuModes.RankingTeam: case OsuModes.RankingVs: loaded = TextureManager.Load(BeatmapManager.Current.BackgroundImage, SkinSource.Beatmap); if (loaded != null) { loaded.Disposable = true; } break; } } #if CHRISTMAS if (loaded == null) { const int available_xmas_backgrounds = 13; if (loadedBackgroundIndex < 0) { loadedBackgroundIndex = RNG.Next(1, available_xmas_backgrounds + 1); } else if (GameBase.Mode == OsuModes.Menu) { loadedBackgroundIndex = Math.Max(1, (loadedBackgroundIndex + 1) % (available_xmas_backgrounds + 1)); } loaded = TextureManager.Load(@"menu-background-xmas-" + loadedBackgroundIndex, SkinSource.Osu); } #endif //if we are a supporter, we can also check the skin for a custom menu-background. if (loaded == null && (BanchoClient.Permission & Permissions.Supporter) > 0 && !SkinManager.IsDefault) { loaded = TextureManager.Load(@"menu-background.jpg", SkinSource.Skin); } //if we still haven't found a texture, we can fall back to the default. if (loaded == null) { loaded = TextureManager.Load(@"menu-background", SkinSource.Osu); } //perform the final load. if (loaded != null) { GameBase.Scheduler.Add(delegate { if (updateCountAtStart != backgroundUpdateCount) { return; } updateBackground(alignmentMode, backgroundAdjustment, loaded); }); } }); } else { //we have finished loading a texture. BackgroundTexture = loadedTexture; loadedBackgroundMode = BanchoClient.Permission; bool isSameTexture = BackgroundSprite != null && BackgroundTexture == BackgroundSprite.Texture; if (isSameTexture && currentBackgroundAdjustment == null && backgroundAdjustment == null && currentAlignmentMode == alignmentMode) { return; } bool firstChange = BackgroundSprite == null; ClearBackground(false); BackgroundSprite = createBackgroundSprite(alignmentMode); if (GameBase.Time >= Menu.IntroLength) { BackgroundSprite.FadeInFromZero(50); } else { BackgroundSprite.Alpha = 0; } updateBackgroundAlignment(BackgroundSprite, alignmentMode, backgroundAdjustment); SpriteManager backgroundSpriteManager = (alignmentMode & AlignmentMode.Widescreen) != 0 ? spriteManagerBackWide : spriteManagerBack; backgroundSpriteManager.Add(BackgroundSprite); if (TrianglesBack != null) { if (SkinManager.Current.TriangleColours.Count != 0) { GameBase.Scheduler.Add(delegate { TrianglesBack.SetColours(SkinManager.Current.TriangleColours); }); } else { switch (BackgroundTexture.Source) { case SkinSource.Beatmap: TrianglesBack.SetColours(BeatmapManager.Current.GetFileStream(BeatmapManager.Current.BackgroundImage), finishedReadingColours); break; case SkinSource.Skin: Stream stream = new FileStream(BackgroundTexture.Filename, FileMode.Open, FileAccess.Read, FileShare.Read); TrianglesBack.SetColours(stream, finishedReadingColours); break; default: TrianglesBack.SetColours(null, finishedReadingColours); break; } } } if (OnBackgroundChanged != null) { OnBackgroundChanged(); } TrianglesBack.VelocityCurrent = firstChange ? 150 : 50; } }
//Sets piece flags for weather piece is pinned or not private void FlagPinnedPieces() { //-send vectors from kings position //-if hit enemy piece stop //-if hit friendly count and continue //-if hit another friendly stop //-if hit enemy queen bishop or rook get the alignment type //-set pinned if correct type TileIndex wKing = board.wKingIndex; TileIndex bKing = board.bKingIndex; FlagPinnedPieces(wKing); FlagPinnedPieces(bKing); //Flags any pieces pinned to the provided tileIndex piece void FlagPinnedPieces(TileIndex king) { Team team = board.GetTilePiecePropertiesAt(king).Team; for (int colDir = -1; colDir < 2; colDir++) { for (int rowDir = -1; rowDir < 2; rowDir++) { int checkCol = king.col + colDir; int checkRow = king.row + rowDir; int teamPieceCount = 0; TileIndex potentialPin = TileIndex.Null; //no pin state while (IsIndexOnBoard(new TileIndex(checkRow, checkCol))) { ChessPieceProperties checkPiece = board.GetTilePiecePropertiesAt(checkRow, checkCol); if (!ReferenceEquals(checkPiece, null)) { if (checkPiece.Team == team) { teamPieceCount++; //Count friendly pieces if (teamPieceCount == 2) //if a second piece is found can stop checking for pin { break; } potentialPin = new TileIndex(checkRow, checkCol); } else { //Enemy Piece found if (teamPieceCount == 1) { if (potentialPin.row != -1) //if there is a potential pin { AlignmentMode mode = GetAlignmentMode(potentialPin, king); switch (checkPiece.Type) //if aligned correctly for piece type pin the unit { case PieceType.Queen: board.GetTilePiecePropertiesAt(potentialPin).isPinned = true; board.GetTilePiecePropertiesAt(potentialPin).pinningPieceIndex = new TileIndex(checkRow, checkCol); break; case PieceType.Bishop: board.GetTilePiecePropertiesAt(potentialPin).isPinned = mode == AlignmentMode.Diagonal; board.GetTilePiecePropertiesAt(potentialPin).pinningPieceIndex = new TileIndex(checkRow, checkCol); break; case PieceType.Rook: board.GetTilePiecePropertiesAt(potentialPin).isPinned = mode == AlignmentMode.Cardinal; board.GetTilePiecePropertiesAt(potentialPin).pinningPieceIndex = new TileIndex(checkRow, checkCol); break; } } } break; //Can stop checking in direction when a opposing piece is found } } checkCol += colDir; checkRow += rowDir; } } } } }