/// <summary> /// Checks that the Height input field only has numeric characters and .'s /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HeightInput_TextChanged(object sender, EventArgs e) { if (!(System.Text.RegularExpressions.Regex.IsMatch(HeightInput.Text, @"(^((\+|\-)?(\d)([0-9])*)?\.?([0-9])*$)")) && HeightInput.Text.Length > 0) { MessageBox.Show("Only numeric data is allowed"); HeightInput.Clear(); } }
private void OnValidate() { if (HeightInputType.Type == null) { HeightInput = null; } else if (HeightInput == null || HeightInput.GetType() != HeightInputType.Type) { HeightInput = Activator.CreateInstance(HeightInputType) as HeightInput; } if (DimensionsInputType.Type == null) { DimensionsInput = null; } else if (DimensionsInput == null || DimensionsInput.GetType() != DimensionsInputType.Type) { DimensionsInput = Activator.CreateInstance(DimensionsInputType) as DimensionsInput; } if (GrassMapInputType.Type == null) { GrassMapInput = null; } else if (GrassMapInput == null || GrassMapInput.GetType() != GrassMapInputType.Type) { GrassMapInput = Activator.CreateInstance(GrassMapInputType) as GrassMapInput; } if (NormalInputType.Type == null) { NormalInput = null; } else if (NormalInput == null || NormalInput.GetType() != NormalInputType.Type) { NormalInput = Activator.CreateInstance(NormalInputType) as NormalInput; } if (PositionInputType.Type == null) { PositionInput = null; } else if (PositionInput == null || PositionInput.GetType() != PositionInputType.Type) { PositionInput = Activator.CreateInstance(PositionInputType) as PositionInput; } if (PatchContainerType.Type == null) { PatchContainer = null; } else if (PatchContainer == null || PatchContainer.GetType() != PatchContainerType.Type) { PatchContainer = Activator.CreateInstance(PatchContainerType) as PatchContainer; } }
//--------------------------------------------------------------------------- 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(); }