private void OpenMenu_Click(object sender, RoutedEventArgs e) { OpenGameWindow openGameWindow = new OpenGameWindow(); bool didOpen = openGameWindow.ShowDialog() ?? false; if (didOpen) { SavedGame savedGame = openGameWindow.SelectedSavedGame; if (savedGame == null) { MessageBox.Show("No saved game selected.", "Error"); } else { OpenSavedGame(savedGame); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string stardewValleySavesPath = Path.Combine(appDataPath, "StardewValley", "Saves"); string[] saves = Directory.GetDirectories(stardewValleySavesPath); foreach (string save in saves) { SavedGame savedGame = GetSavedGameFromPath(save); comboBox.Items.Add(savedGame); } if (comboBox.Items.Count == 0) { MessageBox.Show("Could not find any saved games."); comboBox.IsEnabled = false; openButton.IsEnabled = false; } else { comboBox.SelectedIndex = 0; } }
public string GetSavedFileName(SavedGame savedGame) { return(Path.Combine(savedGame.FullPath, Path.GetFileName(savedGame.FullPath))); }
private void OpenSavedGame(SavedGame savedGame) { _savedGame = null; //try { string path = Path.Combine(savedGame.FullPath, GetSavedFileName(savedGame)); string xmlData = File.ReadAllText(path); _originalData = xmlData; _changedData = xmlData; _loadingXml = true; _xmlDoc = new XmlDocument(); _xmlDoc.LoadXml(xmlData); foreach (JsonTab tab in _config.Tabs) { if (tab.Items != null) { foreach (JsonItem item in tab.Items) { string xmlPath = tab.Path + item.Path + "/text()"; if (item.Type == ItemType.Number) { object inputObject = null; if (item.InputReference.TryGetTarget(out inputObject)) { Xceed.Wpf.Toolkit.DecimalUpDown inputTextBox = inputObject as Xceed.Wpf.Toolkit.DecimalUpDown; if (inputTextBox != null) { inputTextBox.IsEnabled = true; decimal value = 0; if (decimal.TryParse(_xmlDoc.SelectSingleNode(xmlPath).Value, out value)) { inputTextBox.Value = value; } } } } else if (item.Type == ItemType.Season) { object inputObject = null; if (item.InputReference.TryGetTarget(out inputObject)) { ComboBox sesaonComboBox = inputObject as ComboBox; if (sesaonComboBox != null) { sesaonComboBox.IsEnabled = true; foreach (string seasonItem in sesaonComboBox.Items) { if (seasonItem.ToLower() == _xmlDoc.SelectSingleNode(xmlPath).Value) { sesaonComboBox.SelectedItem = seasonItem; break; } } } } } else if (item.Type == ItemType.String) { object inputObject = null; if (item.InputReference.TryGetTarget(out inputObject)) { TextBox inputTextBox = inputObject as TextBox; if (inputTextBox != null) { inputTextBox.IsEnabled = true; inputTextBox.Text = _xmlDoc.SelectSingleNode(xmlPath).Value; } } } else if (item.Type == ItemType.Boolean) { object inputObject = null; if (item.InputReference.TryGetTarget(out inputObject)) { CheckBox inputCheckBox = inputObject as CheckBox; if (inputCheckBox != null) { inputCheckBox.IsEnabled = true; inputCheckBox.IsChecked = (_xmlDoc.SelectSingleNode(xmlPath).Value == "true"); } } } else if (item.Type == ItemType.Decimal) { object inputObject = null; if (item.InputReference.TryGetTarget(out inputObject)) { Xceed.Wpf.Toolkit.DecimalUpDown inputTextBox = inputObject as Xceed.Wpf.Toolkit.DecimalUpDown; if (inputTextBox != null) { inputTextBox.IsEnabled = true; decimal value = 0; if (decimal.TryParse(_xmlDoc.SelectSingleNode(xmlPath).Value, out value)) { inputTextBox.Value = value; } } } } else if (item.Type == ItemType.Name) { object inputObject = null; if (item.InputReference.TryGetTarget(out inputObject)) { TextBox inputTextBox = inputObject as TextBox; if (inputTextBox != null) { // Don't enable editing of name just yet. inputTextBox.IsEnabled = false; inputTextBox.Text = _xmlDoc.SelectSingleNode(xmlPath).Value; } } } else if (item.Type == ItemType.Gender) { object inputObject = null; if (item.InputReference.TryGetTarget(out inputObject)) { ComboBox genderComboBox = inputObject as ComboBox; if (genderComboBox != null) { genderComboBox.IsEnabled = true; string value = _xmlDoc.SelectSingleNode(xmlPath).Value; if (_xmlDoc.SelectSingleNode(xmlPath).Value == "true") { genderComboBox.SelectedItem = "Male"; } else { genderComboBox.SelectedItem = "Female"; } } } } } } } _loadingXml = false; _savedGame = savedGame; } //catch (Exception err) // { // _savedGame = null; // MessageBox.Show($"Could not load saved game. ({err.Message})", "Error", MessageBoxButton.OK, MessageBoxImage.Error); // } }
private void openButton_Click(object sender, RoutedEventArgs e) { SelectedSavedGame = comboBox.SelectedItem as SavedGame; DialogResult = true; }