Example #1
0
        //---------------------------------------------------------------------------

        private void OnCreateLevelClicked(object sender, EventArgs e)
        {
            string name = NameInput.Text;

            if (string.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show("Input for Name is not correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                NameInput.Focus();
                return;
            }

            int width = 0;

            if (!int.TryParse(WidthInput.Text, out width) || width < 3)
            {
                MessageBox.Show("Input for Width is not correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                WidthInput.Focus();
                return;
            }

            int height = 0;

            if (!int.TryParse(HeightInput.Text, out height) || height < 3)
            {
                MessageBox.Show("Input for Height is not correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                HeightInput.Focus();
                return;
            }

            int tileWidth = 0;

            if (!int.TryParse(TileWidthInput.Text, out tileWidth) || tileWidth == 0)
            {
                MessageBox.Show("Input for TileWidth is not correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                TileWidthInput.Focus();
                return;
            }

            int tileHeight = 0;

            if (!int.TryParse(TileHeightInput.Text, out tileHeight) || tileHeight == 0)
            {
                MessageBox.Show("Input for TileHeight is not correct.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                TileHeightInput.Focus();
                return;
            }

            MapManager.Get().Create(name, width, height, tileWidth, tileHeight);
            MapManager.Get().UpdateImage();
            //LevelManager.Get().Create(width, height);
            Close();
        }
Example #2
0
        private void WidthInput_Validating(object sender, CancelEventArgs e)
        {
            string errorMessage;

            if (!ValidIntegerWidth(WidthInput.Text, out errorMessage))
            {
                // Cancel the event and select the text to be corrected by the user.
                e.Cancel = true;
                WidthInput.Select(0, WidthInput.Text.Length);

                // Set the ErrorProvider error with the text to display.
                this.errorProvider1.SetError(WidthInput, errorMessage);
            }
        }