protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == System.Windows.Forms.MouseButtons.Left) { DeckBuilderCard card = GetCardFromCoor(e.X, e.Y); if (card == null) { return; } draggedCard = card; draggedCard.selected = true; draggedCard.Invalidate(); } else if (e.Button == System.Windows.Forms.MouseButtons.Middle || e.Button == System.Windows.Forms.MouseButtons.Right) { DeckBuilderCard card = GetCardFromCoor(e.X, e.Y); if (card == null) { return; } // Reposition card form and draw. cardWindow.SetImage(DraftWindow.GetImage(card.cardName)); float x = card.Left + card.Width / 2f; float y = card.Top + card.Height / 2f; Point point = PointToScreen(new Point((int)Math.Round(x), (int)Math.Round(y))); cardWindow.SetLocation(point); cardWindow.Show(); Focus(); } }
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(); }
public void AddCard(String cardName) { DeckBuilderCard card = new DeckBuilderCard(); card.SizeMode = PictureBoxSizeMode.Zoom; card.Image = DraftWindow.GetImage(cardName); card.cardName = cardName; columns[columns.Count - 1][0].Add(card); Controls.Add(card); LayoutControls(); }
public void AddCard(string cardName) { var card = new DeckBuilderCard { SizeMode = PictureBoxSizeMode.Zoom, Image = DraftWindow.GetImage(cardName), cardName = cardName, cmc = DraftWindow.GetCmc(cardName) }; var colNum = Util.Clamp(0, card.cmc, ColumnCount - 2); columns[colNum][0].Add(card); Controls.Add(card); LayoutControls(); }
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[] GetColumnRowNumFromCard(DeckBuilderCard card) { 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++) { if (columns[column][row][cardNum] == card) { return new int[] { column, row, cardNum } } } } } ; return(null); }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (draggedCard == null) { return; } if (hoveredColumnRowNum != null) { // Move dragged card in columns. int[] draggedColumnRowNum = GetColumnRowNumFromCard(draggedCard); if (draggedColumnRowNum[0] != hoveredColumnRowNum[0] || draggedColumnRowNum[1] != hoveredColumnRowNum[1]) { columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].RemoveAt(draggedColumnRowNum[2]); columns[hoveredColumnRowNum[0]][hoveredColumnRowNum[1]].Insert(hoveredColumnRowNum[2], draggedCard); } else { if (hoveredColumnRowNum[2] <= draggedColumnRowNum[2]) { columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].RemoveAt(draggedColumnRowNum[2]); columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].Insert(hoveredColumnRowNum[2], draggedCard); } else { columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].Insert(hoveredColumnRowNum[2], draggedCard); columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].RemoveAt(draggedColumnRowNum[2]); } } } draggedCard.selected = false; draggedCard.Invalidate(); draggedCard = null; hoveredColumnRowNum = null; indicator.Hide(); Invalidate(); } else if (e.Button == System.Windows.Forms.MouseButtons.Middle || e.Button == System.Windows.Forms.MouseButtons.Right) { cardWindow.Hide(); } }
private DeckBuilderCard GetCardFromCoor(int x, int y) { // TODO: This should be done with calculation instead of checking every card, but since there will usually be under 50 children of this control, it's fine for now. for (int column = 0; column < columns.Count; column++) { for (int row = 0; row < 2; row++) { for (int cardNum = columns[column][row].Count - 1; cardNum >= 0; cardNum--) { DeckBuilderCard card = columns[column][row][cardNum]; if (x >= card.Left && x <= card.Right && y >= card.Top && y <= card.Bottom) { return(card); } } } } return(null); }
private int[] GetColumnRowNumFromCard(DeckBuilderCard card) { 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++) if (columns[column][row][cardNum] == card) return new int[] { column, row, cardNum }; return null; }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (draggedCard == null) return; if (hoveredColumnRowNum != null) { // Move dragged card in columns. int[] draggedColumnRowNum = GetColumnRowNumFromCard(draggedCard); if (draggedColumnRowNum[0] != hoveredColumnRowNum[0] || draggedColumnRowNum[1] != hoveredColumnRowNum[1]) { columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].RemoveAt(draggedColumnRowNum[2]); columns[hoveredColumnRowNum[0]][hoveredColumnRowNum[1]].Insert(hoveredColumnRowNum[2], draggedCard); } else { if (hoveredColumnRowNum[2] <= draggedColumnRowNum[2]) { columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].RemoveAt(draggedColumnRowNum[2]); columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].Insert(hoveredColumnRowNum[2], draggedCard); } else { columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].Insert(hoveredColumnRowNum[2], draggedCard); columns[draggedColumnRowNum[0]][draggedColumnRowNum[1]].RemoveAt(draggedColumnRowNum[2]); } } } draggedCard.selected = false; draggedCard.Invalidate(); draggedCard = null; hoveredColumnRowNum = null; indicator.Hide(); Invalidate(); } else if (e.Button == System.Windows.Forms.MouseButtons.Middle || e.Button == System.Windows.Forms.MouseButtons.Right) cardWindow.Hide(); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == System.Windows.Forms.MouseButtons.Left) { DeckBuilderCard card = GetCardFromCoor(e.X, e.Y); if (card == null) return; draggedCard = card; draggedCard.selected = true; draggedCard.Invalidate(); } else if (e.Button == System.Windows.Forms.MouseButtons.Middle || e.Button == System.Windows.Forms.MouseButtons.Right) { DeckBuilderCard card = GetCardFromCoor(e.X, e.Y); if (card == null) return; // Reposition card form and draw. cardWindow.SetImage(DraftWindow.GetImage(card.cardName)); float x = card.Left + card.Width / 2f; float y = card.Top + card.Height / 2f; Point point = PointToScreen(new Point((int)Math.Round(x), (int)Math.Round(y))); cardWindow.SetLocation(point); cardWindow.Show(); Focus(); } }