public BackstoryFile SaveBackstoryDialog(bool AlienRace = false, bool newFile = false) { if (!TryLoadTraitEntries()) { return(null); } string prefix = AlienRace ? BackstoryUtility.ErdsPrefix : BackstoryUtility.JecsPrefix; BackstoryFile saveFile = null; // Displays a SaveFileDialog so the user can save the XML SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "XML File|*.xml"; saveFileDialog1.Title = "Save an XML File"; saveFileDialog1.ShowDialog(); // If the file name is not an empty string open it for saving. if (saveFileDialog1.FileName != "") { saveFile = new BackstoryFile(saveFileDialog1.FileName); // Saves the Image via a FileStream created by the OpenFile method. saveFile.Save(prefix, !newFile); //MessageBox.Show("Created successfully"); LoadedBackstoryFile = LoadBackstoryFile(saveFileDialog1.FileName); LoadedTraitEntryFile.UpdateLabelsFor(LoadedBackstoryFile); } formViewer.UpdateForm(UpdateEvent.CreateFile); return(saveFile); }
public void UpdateLabelsFor(BackstoryFile backstoryFile) { foreach (Backstory bs in backstoryFile.Backstories) { if (bs.forcedTraits != null && bs.forcedTraits.Count() > 0) { foreach (var trait in bs.forcedTraits) { trait.label = entries.FirstOrDefault(x => x.defName == trait.defName && x.degree == trait.degree).label ?? ""; } } if (bs.disallowedTraits != null && bs.disallowedTraits.Count() > 0) { foreach (var trait in bs.disallowedTraits) { trait.label = entries.FirstOrDefault(x => x.defName == trait.defName && x.degree == trait.degree).label ?? ""; } } } }
private BackstoryFile LoadBackstoryFile(string fileName, bool newFile = false) { var result = BackstoryFile.Load(fileName); return(result); }