/// <summary> /// Saves the character's information. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AcceptCharacter_Click(object sender, RoutedEventArgs e) { string errorMessage = null; bool isAlreadySet = false; string previewImage = ""; PreviewImageWindowCharacter previewWindow = null; try { if (String.IsNullOrEmpty(name)) { errorMessage = "You have to input a name."; throw new NullReferenceException(); } if (String.IsNullOrEmpty(imageMovingUp) || String.IsNullOrEmpty(imageMovingDown) || String.IsNullOrEmpty(imageMovingLeft) || String.IsNullOrEmpty(imageMovingRight)) { errorMessage = "You have to select all the moving animation images."; throw new NullReferenceException(); } if (frameCount == 0) { errorMessage = "You have to input the number of frames for the moving animation."; throw new NullReferenceException(); } if (String.IsNullOrEmpty(speed)) { errorMessage = "You have to select the speed of the character."; throw new NullReferenceException(); } if (String.IsNullOrEmpty(initialState)) { errorMessage = "You have to select the initial direction of the character."; throw new NullReferenceException(); } if ((bool)CanMelee.IsChecked) { if (String.IsNullOrEmpty(imageAttackingUp) || String.IsNullOrEmpty(initialState) || String.IsNullOrEmpty(initialState) || String.IsNullOrEmpty(initialState)) { errorMessage = "You have to select all the attacking animation images."; throw new NullReferenceException(); } if (frameAttackingCount == 0) { errorMessage = "You have to input the number of frames for the attacking animation."; throw new NullReferenceException(); } if (melee == null) { errorMessage = "You have to select an initial melee weapon."; throw new NullReferenceException(); } } else { imageAttackingUp = null; imageAttackingDown = null; imageAttackingLeft = null; imageAttackingRight = null; frameAttackingCount = 0; melee = null; attackSoundEffect = null; } name = name.Replace(" ", "_"); if (manager.CheckIfNumber(name)) { errorMessage = "The name cannot be only numbers."; throw new Exception(); } if (edit) { previewWindow = new PreviewImageWindowCharacter(manager.Player, edit); previewWindow.ShowDialog(); previewImage = manager.Player.PreviewImage; isAlreadySet = manager.Player.IsSet; manager.Player = null; } if (manager.NameRepeated(name)) { errorMessage = "This name already exits"; throw new NullReferenceException(); } manager.Player = new Character(name, strenght, intelligence, dexterity, hitPoints, mana, imageMovingUp, imageMovingDown, imageMovingLeft, imageMovingRight, imageAttackingUp, imageAttackingDown, imageAttackingLeft, imageAttackingRight, melee, distance, frameCount, frameAttackingCount, attackSoundEffect, shootSoundEffect, castSoundEffect, initialState, speed); manager.Player.IsSet = isAlreadySet; if (edit) { manager.Player.PreviewImage = previewImage; } else { previewWindow = new PreviewImageWindowCharacter(manager.Player, edit); previewWindow.ShowDialog(); } if (manager.Player.PreviewImage == null) { manager.Player = null; errorMessage = "You have to select a preview image."; throw new NullReferenceException(); } this.Close(); } catch (Exception) { MessageBox.Show(errorMessage, "Attention", MessageBoxButton.OK, MessageBoxImage.Warning); } }