public string GetText(string dialogHeader, string textHeader, string suggestedText) { var inputTextWindow = new InputTextWindow(); inputTextWindow.Dialog.Title = dialogHeader; inputTextWindow.TextHeaderLabel.Content = textHeader; inputTextWindow.TextTextBox.Text = suggestedText; inputTextWindow.TextTextBox.SelectionStart = 0; inputTextWindow.TextTextBox.SelectionLength = suggestedText.Length; inputTextWindow.ShowDialog(); var inputTextWindowContext = inputTextWindow.DataContext as InputTextWindowViewModel; Cancelled = (inputTextWindowContext.Result == null || inputTextWindowContext.Result == false); return(inputTextWindow.TextTextBox.Text); }
public static string InputNewProfileName(string prompt = null, string title = null) { if (string.IsNullOrWhiteSpace(prompt)) { prompt = ResourceHelper.Get(StringKey.EnterProfileName); } if (string.IsNullOrWhiteSpace(title)) { title = ResourceHelper.Get(StringKey.NewProfile); } string profileName = null; bool isValid = false; do { isValid = true; InputTextWindow inputBox = new InputTextWindow(title, prompt); bool? dialogResult = inputBox.ShowDialog(); if (!dialogResult.GetValueOrDefault(false)) { return(null); } profileName = inputBox.ViewModel.TextInput; if (string.IsNullOrEmpty(profileName)) { isValid = false; MessageDialogWindow.Show(ResourceHelper.Get(StringKey.ProfileNameIsEmpty), ResourceHelper.Get(StringKey.ProfileError), MessageBoxButton.OK, MessageBoxImage.Error); } } while (!isValid); return(profileName); }
public static string InputNewProfileName(string prompt = null, string title = null) { if (string.IsNullOrWhiteSpace(prompt)) { prompt = "Enter new profile name:"; } if (string.IsNullOrWhiteSpace(title)) { title = "New Profile"; } string profileName = null; bool isValid = false; do { isValid = true; InputTextWindow inputBox = new InputTextWindow(title, prompt); bool? dialogResult = inputBox.ShowDialog(); if (!dialogResult.GetValueOrDefault(false)) { return(null); } profileName = inputBox.ViewModel.TextInput; if (string.IsNullOrEmpty(profileName)) { isValid = false; MessageDialogWindow.Show("Profile Name is empty.", "Profile Error", MessageBoxButton.OK, MessageBoxImage.Error); } } while (!isValid); return(profileName); }
internal void SaveNewCustomControl() { bool isValid = true; string title = ResourceHelper.Get(StringKey.SaveControlConfiguration); string prompt = ResourceHelper.Get(StringKey.SaveControlsPreset); string controlName; string pathToFile; do { isValid = true; InputTextWindow inputBox = new InputTextWindow(title, prompt); inputBox.ViewModel.MaxCharLength = 24; bool?dialogResult = inputBox.ShowDialog(); if (!dialogResult.GetValueOrDefault(false)) { return; } controlName = inputBox.ViewModel.TextInput; if (string.IsNullOrEmpty(controlName)) { isValid = false; MessageDialogWindow.Show(ResourceHelper.Get(StringKey.ControlNameIsEmpty), ResourceHelper.Get(StringKey.SaveError), MessageBoxButton.OK, MessageBoxImage.Error); continue; } if (Path.GetInvalidFileNameChars().Any(c => controlName.Contains(c))) { isValid = false; MessageDialogWindow.Show(ResourceHelper.Get(StringKey.ControlNameContainsInvalidChars), ResourceHelper.Get(StringKey.SaveError), MessageBoxButton.OK, MessageBoxImage.Error); continue; } // construct path and check if already exists if name is valid if (isValid) { if (controlName.EndsWith(".cfg")) { controlName = controlName.Substring(0, controlName.Length - 4); } pathToFile = Path.Combine(Sys.PathToControlsFolder, $"{controlName}.cfg"); if (File.Exists(pathToFile)) { isValid = false; MessageDialogWindow.Show(ResourceHelper.Get(StringKey.ControlsWithThatNameAlreadyExist), ResourceHelper.Get(StringKey.SaveError), MessageBoxButton.OK, MessageBoxImage.Error); } } } while (!isValid); try { string pathToDefaultFile = Path.Combine(Sys.PathToControlsFolder, InGameConfigurationMap[_defaultControlNames[0]]); ControlMapper.CopyConfigurationFileAndSaveAsNew(pathToDefaultFile, $"{controlName}.cfg", LoadedConfiguration); InitInGameConfigOptions(); SelectedGameConfigOption = controlName; //StatusMessage = ResourceHelper.Get(StringKey.SuccessfullyCreatedCustomControls); } catch (Exception e) { Logger.Error(e); //StatusMessage = $"{ResourceHelper.Get(StringKey.FailedToCreateCustomControls)}: {e.Message}"; } }
internal void SaveNewCustomControl() { bool isValid = true; string title = "Save Control Configuration"; string prompt = "Import current controls from game and save as..."; string controlName; string pathToFile; do { isValid = true; InputTextWindow inputBox = new InputTextWindow(title, prompt); inputBox.ViewModel.MaxCharLength = 24; bool?dialogResult = inputBox.ShowDialog(); if (!dialogResult.GetValueOrDefault(false)) { return; } controlName = inputBox.ViewModel.TextInput; if (string.IsNullOrEmpty(controlName)) { isValid = false; MessageDialogWindow.Show("Control name is empty.", "Save Error", MessageBoxButton.OK, MessageBoxImage.Error); continue; } if (Path.GetInvalidFileNameChars().Any(c => controlName.Contains(c))) { isValid = false; MessageDialogWindow.Show("Control name contains invalid characters.", "Save Error", MessageBoxButton.OK, MessageBoxImage.Error); continue; } // construct path and check if already exists if name is valid if (isValid) { if (controlName.EndsWith(".cfg")) { controlName = controlName.Substring(0, controlName.Length - 4); } pathToFile = Path.Combine(Sys.PathToControlsFolder, $"{controlName}.cfg"); if (File.Exists(pathToFile)) { isValid = false; MessageDialogWindow.Show("Custom controls with that name already exist.", "Save Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } while (!isValid); try { CopyInputCfgToCustomCfg(true, $"{controlName}.cfg"); InitInGameConfigOptions(); SelectedGameConfigOption = controlName; StatusMessage = $"Successfully created custom controls."; } catch (Exception e) { Logger.Error(e); StatusMessage = $"Failed to create custom controls: {e.Message}"; } }