예제 #1
0
        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();
            }
        }
예제 #2
0
        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();
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
        }
예제 #5
0
        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();
        }
예제 #6
0
        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();
        }
예제 #7
0
 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);
 }
예제 #8
0
 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();
     }
 }
예제 #9
0
 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);
 }
예제 #10
0
 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;
 }
예제 #11
0
 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();
 }
예제 #12
0
        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();
            }
        }