예제 #1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Left)
            {
                var draggedPosition = GetPosFromClickCoor(e.X, e.Y, false);
                var card            = TryGetCardFromPos(draggedPosition);
                if (card == null)
                {
                    return;
                }
                dragged       = draggedPosition;
                card.selected = true;
                card.Invalidate();
            }
            else if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.Right)
            {
                var card = TryGetCardFromPos(GetPosFromClickCoor(e.X, e.Y, false));
                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
        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();
            }
        }
예제 #3
0
        public DraftClient(DraftWindow draftWindow, string hostname, string alias)
        {
            this.draftWindow = draftWindow;
            this.alias       = alias;

            if (!IPAddress.TryParse(hostname, out var address))
            {
                IPHostEntry hostEntry = Dns.GetHostEntry(hostname);
                if (hostEntry.AddressList.Length == 0)
                {
                    draftWindow.PrintLine("Couldn't resolve hostname!");
                    return;
                }
                address = hostEntry.AddressList[0];
            }

            client = new EventDrivenTCPClient(address, Util.PORT, false)
            {
                DataEncoding = Encoding.UTF8
            };
            client.ConnectionStatusChanged += client_ConnectionStatusChanged;
            client.DataReceived            += client_DataReceived;

            client.Connect();
        }
예제 #4
0
 public void Populate(List <String> cardNames)
 {
     this.cardNames = cardNames;
     foreach (String cardName in cardNames)
     {
         DraftWindow.LoadImage(cardName);
     }
     Invalidate();
 }
예제 #5
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();
        }
예제 #6
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();
        }
예제 #7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (cardNames.Count == 0)
            {
                return;
            }

            // Calculate size of each card.
            float usableWidth = ClientSize.Width * (1 - SPACING_PERCENTAGE);
            float usableHeight = ClientSize.Height * (1 - SPACING_PERCENTAGE);
            float currentMaxScale = 0, currentTestScale = 1;

            for (int i = 0; i < 20; i++)
            {
                int rows = (int)Math.Floor(usableWidth / (CARD_WIDTH * currentTestScale));
                int cols = (int)Math.Floor(usableHeight / (CARD_HEIGHT * currentTestScale));
                if (rows * cols < cardNames.Count)
                {
                    currentTestScale = (currentMaxScale + currentTestScale) / 2;
                }
                else
                {
                    float nextTestScale = currentTestScale + (currentTestScale - currentMaxScale) / 2;
                    currentMaxScale  = currentTestScale;
                    currentTestScale = nextTestScale;
                }
            }
            scale = currentMaxScale;

            perRow  = (int)Math.Floor(usableWidth / (CARD_WIDTH * scale));
            spacing = (ClientSize.Width * SPACING_PERCENTAGE) / (perRow + 1);
            for (int i = 0; i < cardNames.Count; i++)
            {
                int   row = i / perRow, col = i % perRow;
                float x = col * CARD_WIDTH * scale + (col + 1) * spacing;
                float y = row * CARD_HEIGHT * scale + (row + 1) * spacing;
                e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                e.Graphics.DrawImage(DraftWindow.GetImage(cardNames[i]), new RectangleF(x, y, CARD_WIDTH * scale, CARD_HEIGHT * scale));
            }
        }
예제 #8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.Right)
            {
                // Find which card was clicked.
                int i = GetIndexFromCoor(e.X, e.Y);
                if (i == -1)
                {
                    return;
                }

                // Reposition card form and draw.
                cardWindow.SetImage(DraftWindow.GetImage(cardNames[i]));
                float x     = (i % perRow) * (spacing + CARD_WIDTH * scale) + spacing + (CARD_WIDTH * scale / 2);
                float y     = (i / perRow) * (spacing + CARD_HEIGHT * scale) + spacing + (CARD_HEIGHT * scale / 2);
                Point point = PointToScreen(new Point((int)Math.Round(x), (int)Math.Round(y)));
                cardWindow.SetLocation(point);
                cardWindow.Show();
                Focus();
            }
        }
예제 #9
0
        public DraftClient(DraftWindow draftWindow, string hostname, string alias)
        {
            this.draftWindow = draftWindow;
            this.alias = alias;

            IPAddress address;
            if (!IPAddress.TryParse(hostname, out address))
            {
                IPHostEntry hostEntry = Dns.GetHostEntry(hostname);
                if (hostEntry.AddressList.Length == 0)
                {
                    draftWindow.PrintLine("Couldn't resolve hostname!");
                    return;
                }
                address = hostEntry.AddressList[0];
            }
            client = new EventDrivenTCPClient(address, 10024, false);
            client.DataEncoding = Encoding.UTF8;
            client.ConnectionStatusChanged += new EventDrivenTCPClient.delConnectionStatusChanged(client_ConnectionStatusChanged);
            client.DataReceived += new EventDrivenTCPClient.delDataReceived(client_DataReceived);

            client.Connect();
        }
예제 #10
0
 public void Populate(List <CardInfo> cards)
 {
     DraftWindow.LoadImages(cards);
     cardNames = cards.Select(c => c.Name).ToList();
     Invalidate();
 }
예제 #11
0
 private void HandleMessage(string msg)
 {
     string[] parts = msg.Split('|');
     if (parts[0] == "OK")
     {
         if (parts[1] == "HELLO")
         {
             client.Send("VERSION|" + Util.version);
         }
         else if (parts[1] == "VERSION")
         {
             draftWindow.PrintLine("Version OK.");
             client.Send("ALIAS|" + alias);
         }
         else if (parts[1] == "ALIAS")
         {
             draftWindow.PrintLine("Connected as " + alias + ".");
         }
         else if (parts[1] == "PICK")
         {
             draftWindow.ClearDraftPicker();
             draftWindow.EnableDraftPicker();
         }
     }
     else if (parts[0] == "ERROR")
     {
         if (parts[1] == "OLD_CLIENT_VERSION")
         {
             draftWindow.PrintLine("Your client is out of date. Please update to the latest version.");
         }
         else if (parts[1] == "OLD_SERVER_VERSION")
         {
             draftWindow.PrintLine("The server is out of date. Please update it to the latest version.");
         }
         else if (parts[1] == "ALIAS_IN_USE")
         {
             draftWindow.PrintLine("That alias is in use. Please choose another alias.");
         }
         else if (parts[1] == "DRAFT_IN_PROGRESS")
         {
             draftWindow.PrintLine("A draft is in progress on that server. To rejoin, use the same alias you were using when it started.");
         }
         else
         {
             draftWindow.PrintLine("Unknown error from server: " + parts[1]);
         }
         client.Disconnect();
     }
     else if (parts[0] == "USER_CONNECTED")
     {
         if (parts[1] != alias)
         {
             draftWindow.PrintLine(parts[1] + " joined the lobby.");
         }
     }
     else if (parts[0] == "USER_DISCONNECTED")
     {
         if (parts[1] != alias)
         {
             draftWindow.PrintLine(parts[1] + " left the lobby.");
         }
     }
     else if (parts[0] == "USER_LIST")
     {
         parts[0] = "";
         string userList = string.Join(", ", parts).Substring(2);
         draftWindow.PrintLine("There are now " + (parts.Length - 1) + " users in the lobby: " + userList);
     }
     else if (parts[0] == "PACK_COUNT")
     {
         draftWindow.SetPackCounts(msg);
     }
     else if (parts[0] == "BOOSTER")
     {
         draftWindow.PopulateDraftPicker(msg);
         draftWindow.EnableDraftPicker();
     }
     else if (parts[0] == "CARD_POOL")
     {
         draftWindow.PrintLine("Loading draft in progress...");
         var cards = parts.Skip(1).Select(CardInfo.FromString).ToArray();
         DraftWindow.LoadImages(cards);
         foreach (var card in cards)
         {
             draftWindow.AddCardToPool(card.Name);
         }
         draftWindow.PrintLine("Loaded draft.");
     }
     else if (parts[0] == "CHAT")
     {
         draftWindow.PrintLine("<" + parts[1] + ">: " + parts[2]);
     }
     else if (parts[0] == "DONE")
     {
         draftDone = true;
         draftWindow.PrintLine("The draft has ended.");
         draftWindow.ClearPackCounts();
     }
     else
     {
         draftWindow.PrintLine("Unknown message from server: " + msg);
     }
 }