/// <summary>Method: pnlField_MouseClick
 /// Check the right click menu and set variable to edit status
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void pnlField_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         return;
     }
     if (txtNumber.Visible)
     {
         changePlayerNumber(); // A way to finish editing Number of the editPiece
     }
     if (txtName.Visible)
     {
         changePlayerName(); // A way to finish editing Name of the editPiece
     }
     if (e.Button == MouseButtons.Right)
     {
         mouseLocation = e.Location;
         checkMenuItems();
         editPiece = null;
         ArrayList pl = model.PieceList;
         for (int i = pl.Count; i > 0; i--)
         {
             APiece p = (APiece)pl[i - 1];
             Point  m = new Point(e.X, e.Y);
             if (p.HitTest(m))
             {
                 p.Highlight = true;
                 editPiece   = p;
                 model.BringToFront(p);
                 break;
             }
         }
         try
         {
             APiece pre;
             if (editPiece != null)
             {
                 pre = (APiece)pl[pl.Count - 2];
             }
             else
             {
                 pre = (APiece)pl[pl.Count - 1];
             }
             pre.Highlight = false;
         }
         catch (ArgumentOutOfRangeException) { }
         RefreshView();
         // Control the content menu
         Point pt = pnlField.PointToScreen(e.Location);
         if (editPiece == null)
         {
             pt = pnlField.PointToScreen(e.Location);
             cmsField.Show(pt);
         }
         else if (editPiece is Player)
         {
             checkColorChecked();
             cmsPlayer.Show(pt);
         }
         else if (editPiece is Referee)
         {
             cmsReferee.Show(pt);
         }
         else if (editPiece is Ball)
         {
             checkBallTypeChecked();
             cmsBall.Show(pt);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>Method: btnUpdate_Click
        /// Update selected piece
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string o             = string.Empty;
            var    checkedButton = Controls.OfType <RadioButton>()
                                   .FirstOrDefault(r => r.Checked);

            if (checkedButton == null)
            {
                MessageBox.Show("Please select the object first");
                return;
            }
            string obj      = checkedButton.Text;
            string selector = txbSelector.Text;

            if (selector.Equals(o) && !obj.Equals("Ball"))
            {
                MessageBox.Show("Please type in the selector.");
                return;
            }
            int x = txbX.Text.Equals(string.Empty) ? 0 : Convert.ToInt32(txbX.Text);
            int y = txbY.Text.Equals(string.Empty) ? 0 : Convert.ToInt32(txbY.Text);

            if (x > max_X || y > max_Y)
            {
                MessageBox.Show("Maximum value for X is " + max_X
                                + "\r\n" + "Maximum value for Y is " + max_Y + "\r\n",
                                "Please Check the Values Entered",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (obj.Equals("Player"))
            {
                string selected_side   = string.Empty;
                string selected_number = string.Empty;
                string pattern         = @"^(home|away) (\d+)$";
                foreach (Match match in Regex.Matches(selector, pattern, RegexOptions.IgnoreCase))
                {
                    selected_side   = match.Groups[1].Value;
                    selected_number = match.Groups[2].Value;
                }
                if (selected_side == string.Empty || selected_number == string.Empty)
                {
                    MessageBox.Show("The selector of player should be Home/Away<space>Number.");
                    return;
                }
                Player player = (Player)model.GetAPiece(typeof(Player),
                                                        selected_side.ToLower(), Convert.ToInt32(selected_number));
                if (player == null)
                {
                    MessageBox.Show("Not Found the player.");
                    return;
                }
                string name = txbName.Text;
                if (!cbbColor.Text.Equals(o))
                {
                    player.Color = Color.FromName(cbbColor.Text);
                }
                if (!txbNumber.Text.Equals(o))
                {
                    player.Number = Convert.ToInt32(txbNumber.Text);
                }
                if (!txbName.Text.Equals(o))
                {
                    player.Name = txbName.Text;
                }
                if (!txbX.Text.Equals(o))
                {
                    player.x_pos = Convert.ToInt32(txbX.Text);
                }
                if (!txbY.Text.Equals(o))
                {
                    player.y_pos = Convert.ToInt32(txbY.Text);
                }
                model.BringToFront(player);
            }
            else if (obj.Equals("Ball"))
            {
                Ball ball = (Ball)model.GetAPiece(typeof(Ball), "Ball");
                if (!txbX.Text.Equals(o))
                {
                    ball.x_pos = Convert.ToInt32(txbX.Text);
                }
                if (!txbY.Text.Equals(o))
                {
                    ball.y_pos = Convert.ToInt32(txbY.Text);
                }
                if (!cbbBallType.Text.Equals(""))
                {
                    ball.BallImage = cbbBallType.Text.Equals("White")? Ball.ImageType.White : Ball.ImageType.Orange;
                }
                model.BringToFront(ball);
            }
            else if (obj.Equals("Referee"))
            {
                Referee referee = (Referee)model.GetAPiece(typeof(Referee), selector);
                if (referee == null)
                {
                    MessageBox.Show("Not Found the referee. You can check the selector example above the textbox.");
                    return;
                }
                if (!txbX.Text.Equals(o))
                {
                    referee.x_pos = Convert.ToInt32(txbX.Text);
                }
                if (!txbY.Text.Equals(o))
                {
                    referee.y_pos = Convert.ToInt32(txbY.Text);
                }
                model.BringToFront(referee);
            }
            model.UpdateViews();
        }