private void LayoutControls() { AutoScrollMargin = new Size(0, VerticalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0); DeckBuilderLayout layout = new DeckBuilderLayout(this); for (int column = 0; column < columns.Count; column++) { for (int row = 0; row < 2; row++) { for (int cardNum = 0; cardNum < columns[column][row].Count; cardNum++) { // Set location and size. DeckBuilderCard card = columns[column][row][cardNum]; layout.GetCardLeftAndTop(new CardPosition(column, row, cardNum), out var left, out var top); card.Left = (int)Math.Round(left); card.Top = (int)Math.Round(top); card.Width = (int)Math.Round(layout.cardWidth); card.Height = (int)Math.Round(layout.cardHeight); // Set child index. Controls.SetChildIndex(card, columns[column][row].Count - cardNum); } } } indicator.BringToFront(); SetCardCounts(); }
private int[] GetColumnRowNumFromCoor(int x, int y) { DeckBuilderLayout layout = new DeckBuilderLayout(this); if (Math.Floor(x / (layout.scale * CARD_WIDTH + layout.spacing)) > columns.Count - 1) { x -= (int)Math.Round(layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1)); } if (x % (layout.scale * CARD_WIDTH + layout.spacing) < layout.spacing) { return(null); } int column = (int)Math.Floor(x / (layout.scale * CARD_WIDTH + layout.spacing)); if (column >= columns.Count) { return(null); } bool isEmpty = GetMaxFirstRowLength() == 0; y += VerticalScroll.Value; int row = y < layout.secondRowY || isEmpty || column == columns.Count - 1 ? 0 : 1; int cardNum; if (columns[column][row].Count == 0) // Dragged card should get put as the first element in the now-empty column. { cardNum = 0; } else { if (column == columns.Count - 1) { y -= (int)Math.Round(layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1)); } if (row == 1) { y -= (int)Math.Round(layout.secondRowY); } y -= (int)Math.Round(layout.spacing); int count = columns[column][row].Count; if (y > (count - 1) * CARD_HEIGHT * layout.scale * CARD_HEADER_PERCENTAGE + CARD_HEIGHT * layout.scale) { return(null); } cardNum = (int)Math.Floor(y / (CARD_HEIGHT * layout.scale * CARD_HEADER_PERCENTAGE)); if (cardNum < 0) { return(null); } if (cardNum > count) { cardNum = count; } } return(new int[] { column, row, cardNum }); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (dragged == CardPosition.None) { return; } var columnRowNum = GetPosFromClickCoor(e.X, e.Y, true); // Check if the hovered area has changed. if (columnRowNum == hovered) { return; } // Toggle visibility of indicator or change position. hovered = columnRowNum; if (hovered == CardPosition.None) { indicator.Hide(); } else { // If the hovered position is immediately before or after the dragged card, don't draw the indicator. if (hovered.Col == dragged.Col && hovered.Row == dragged.Row && (hovered.Num == dragged.Num || hovered.Num == dragged.Num + 1)) { indicator.Hide(); } // Otherwise, draw the indicator. else { DeckBuilderLayout layout = new DeckBuilderLayout(this); layout.GetCardLeftAndTop(hovered, out var left, out var top); if (hovered.Num != 0 && hovered.Num == columns[hovered.Col][hovered.Row].Count) { // draw at bottom of last card top += layout.cardHeight - layout.headerSize; } indicator.Left = (int)Math.Round(left - 2); indicator.Top = (int)Math.Round(top - 1); indicator.Width = (int)Math.Round(layout.cardWidth + 4); indicator.Height = 2; indicator.Show(); } } Invalidate(); }
private void LayoutControls() { if (VerticalScroll.Visible) { AutoScrollMargin = new Size(0, System.Windows.Forms.SystemInformation.HorizontalScrollBarHeight); } else { AutoScrollMargin = new Size(0, 0); } DeckBuilderLayout layout = new DeckBuilderLayout(this); for (int column = 0; column < columns.Count; column++) { for (int row = 0; row < 2; row++) { for (int cardNum = 0; cardNum < columns[column][row].Count; cardNum++) { // Set location and size. DeckBuilderCard card = columns[column][row][cardNum]; float x = layout.spacing * (column + 1) + (CARD_WIDTH * layout.scale * column); float y = layout.spacing + (layout.headerSize * cardNum); if (column == columns.Count - 1) { x += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); y += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); } if (row == 1) { y += layout.secondRowY; } y -= VerticalScroll.Value; card.Left = (int)Math.Round(x); card.Top = (int)Math.Round(y); card.Width = (int)Math.Round(CARD_WIDTH * layout.scale); card.Height = (int)Math.Round(CARD_HEIGHT * layout.scale); // Set child index. Controls.SetChildIndex(card, columns[column][row].Count - cardNum); } } } indicator.BringToFront(); SetCardCounts(); }
private CardPosition GetPosFromClickCoor(int x, int y, bool isDestination) { var layout = new DeckBuilderLayout(this); if (!layout.TryGetColumn(x, out var column)) { return(CardPosition.None); } y += VerticalScroll.Value; int row = y < layout.secondRowY || column == columns.Count - 1 ? 0 : 1; int cardNum; if (columns[column][row].Count == 0) // Dragged card should get put as the first element in the now-empty column. { cardNum = 0; } else { if (column == columns.Count - 1) { y -= (int)Math.Round(layout.spacing * (DeckBuilderLayout.SIDEBOARD_SPACING_MULTIPLIER - 1)); } if (row == 1) { y -= (int)Math.Round(layout.secondRowY); } y -= (int)Math.Round(layout.spacing); if (y < 0) { return(CardPosition.None); } int count = columns[column][row].Count; cardNum = (int)Math.Floor(y / layout.headerSize); if (cardNum >= count) { cardNum = isDestination ? count : count - 1; } } return(new CardPosition(column, row, cardNum)); }
private void LayoutControls() { if (VerticalScroll.Visible) AutoScrollMargin = new Size(0, System.Windows.Forms.SystemInformation.HorizontalScrollBarHeight); else AutoScrollMargin = new Size(0, 0); DeckBuilderLayout layout = new DeckBuilderLayout(this); for (int column = 0; column < columns.Count; column++) for (int row = 0; row < 2; row++) for (int cardNum = 0; cardNum < columns[column][row].Count; cardNum++) { // Set location and size. DeckBuilderCard card = columns[column][row][cardNum]; float x = layout.spacing * (column + 1) + (CARD_WIDTH * layout.scale * column); float y = layout.spacing + (layout.headerSize * cardNum); if (column == columns.Count - 1) { x += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); y += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); } if (row == 1) y += layout.secondRowY; y -= VerticalScroll.Value; card.Left = (int)Math.Round(x); card.Top = (int)Math.Round(y); card.Width = (int)Math.Round(CARD_WIDTH * layout.scale); card.Height = (int)Math.Round(CARD_HEIGHT * layout.scale); // Set child index. Controls.SetChildIndex(card, columns[column][row].Count - cardNum); } indicator.BringToFront(); SetCardCounts(); }
private int[] GetColumnRowNumFromCoor(int x, int y) { DeckBuilderLayout layout = new DeckBuilderLayout(this); if (Math.Floor(x / (layout.scale * CARD_WIDTH + layout.spacing)) > columns.Count - 1) x -= (int)Math.Round(layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1)); if (x % (layout.scale * CARD_WIDTH + layout.spacing) < layout.spacing) return null; int column = (int)Math.Floor(x / (layout.scale * CARD_WIDTH + layout.spacing)); if (column >= columns.Count) return null; bool isEmpty = GetMaxFirstRowLength() == 0; y += VerticalScroll.Value; int row = y < layout.secondRowY || isEmpty || column == columns.Count - 1 ? 0 : 1; int cardNum; if (columns[column][row].Count == 0) // Dragged card should get put as the first element in the now-empty column. cardNum = 0; else { if (column == columns.Count - 1) y -= (int)Math.Round(layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1)); if (row == 1) y -= (int)Math.Round(layout.secondRowY); y -= (int)Math.Round(layout.spacing); int count = columns[column][row].Count; if (y > (count - 1) * CARD_HEIGHT * layout.scale * CARD_HEADER_PERCENTAGE + CARD_HEIGHT * layout.scale) return null; cardNum = (int)Math.Floor(y / (CARD_HEIGHT * layout.scale * CARD_HEADER_PERCENTAGE)); if (cardNum < 0) return null; if (cardNum > count) cardNum = count; } return new int[] { column, row, cardNum }; }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (draggedCard == null) return; int[] columnRowNum = GetColumnRowNumFromCoor(e.X, e.Y); // Check if the hovered area has changed. if (columnRowNum == null && hoveredColumnRowNum == null) return; if (columnRowNum != null && hoveredColumnRowNum != null && columnRowNum.SequenceEqual(hoveredColumnRowNum)) return; // Toggle visibility of indicator or change position. hoveredColumnRowNum = columnRowNum; if (hoveredColumnRowNum == null) indicator.Hide(); else { int column = hoveredColumnRowNum[0]; int row = hoveredColumnRowNum[1]; int cardNum = hoveredColumnRowNum[2]; // If the hovered position is immediately before or after the dragged card, don't draw the indicator. int[] draggedColumnRowNum = GetColumnRowNumFromCard(draggedCard); if (column == draggedColumnRowNum[0] && row == draggedColumnRowNum[1] && (cardNum == draggedColumnRowNum[2] || cardNum == draggedColumnRowNum[2] + 1)) { indicator.Hide(); } // Otherwise, draw the indicator. else { DeckBuilderLayout layout = new DeckBuilderLayout(this); // TODO: COPIED FROM LayoutControls()! Bad! float x = layout.spacing * (column + 1) + (CARD_WIDTH * layout.scale * column); float y = layout.spacing + (layout.headerSize * cardNum); if (column == columns.Count - 1) { x += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); y += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); } if (row == 1) y += layout.secondRowY; if (cardNum != 0 && cardNum == columns[column][row].Count) y += CARD_HEIGHT * layout.scale - layout.headerSize; y -= VerticalScroll.Value; // END COPY indicator.Left = (int)Math.Round(x - 2); indicator.Top = (int)Math.Round(y - 1); indicator.Width = (int)Math.Round(CARD_WIDTH * layout.scale + 4); indicator.Height = 2; indicator.Show(); } } Invalidate(); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (draggedCard == null) { return; } int[] columnRowNum = GetColumnRowNumFromCoor(e.X, e.Y); // Check if the hovered area has changed. if (columnRowNum == null && hoveredColumnRowNum == null) { return; } if (columnRowNum != null && hoveredColumnRowNum != null && columnRowNum.SequenceEqual(hoveredColumnRowNum)) { return; } // Toggle visibility of indicator or change position. hoveredColumnRowNum = columnRowNum; if (hoveredColumnRowNum == null) { indicator.Hide(); } else { int column = hoveredColumnRowNum[0]; int row = hoveredColumnRowNum[1]; int cardNum = hoveredColumnRowNum[2]; // If the hovered position is immediately before or after the dragged card, don't draw the indicator. int[] draggedColumnRowNum = GetColumnRowNumFromCard(draggedCard); if (column == draggedColumnRowNum[0] && row == draggedColumnRowNum[1] && (cardNum == draggedColumnRowNum[2] || cardNum == draggedColumnRowNum[2] + 1)) { indicator.Hide(); } // Otherwise, draw the indicator. else { DeckBuilderLayout layout = new DeckBuilderLayout(this); // TODO: COPIED FROM LayoutControls()! Bad! float x = layout.spacing * (column + 1) + (CARD_WIDTH * layout.scale * column); float y = layout.spacing + (layout.headerSize * cardNum); if (column == columns.Count - 1) { x += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); y += layout.spacing * (SIDEBOARD_SPACING_MULTIPLIER - 1); } if (row == 1) { y += layout.secondRowY; } if (cardNum != 0 && cardNum == columns[column][row].Count) { y += CARD_HEIGHT * layout.scale - layout.headerSize; } y -= VerticalScroll.Value; // END COPY indicator.Left = (int)Math.Round(x - 2); indicator.Top = (int)Math.Round(y - 1); indicator.Width = (int)Math.Round(CARD_WIDTH * layout.scale + 4); indicator.Height = 2; indicator.Show(); } } Invalidate(); }