private void openToolStripMenuItem_Click(object sender, EventArgs e) { var cXML = new CreatureXML(); //no "data loss" warning if no character has been loaded already OR no unsaved character has been built yet if (CurrentCharacter == null) { try { CurrentCharacter = cXML.ReadFromXML(GetXMLToOpen()); if (CurrentCharacter != null) { DisplayCreature(CurrentCharacter); } } catch (Exception ex) { MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //"data loss" warning if a character has already been loaded OR an unsaved character has been built else { DialogResult result = MessageBox.Show("Opening a character file will cause all changes for this character to be lost. Continue?", "Open a Character", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { try { CurrentCharacter = cXML.ReadFromXML(GetXMLToOpen()); if (CurrentCharacter != null) { DisplayCreature(CurrentCharacter); } } catch (Exception ex) { MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// <summary> /// Sets up the main creation form based on what the user chose during startup. /// </summary> /// <param name="selection"></param> private void StartCreator(int selection) { CurrentCharacter = null; //create new character if (selection == 0) { //clear all creator controls ClearAllCreatorControls(); CurrentCharacter = null; //focus first control tbFirstName.Focus(); } //open existing character file (*.xml) else if (selection == 1) { var cXML = new CreatureXML(); try { CurrentCharacter = cXML.ReadFromXML(GetXMLToOpen()); if (CurrentCharacter != null) { //track the GUID of the loaded Creature LoadedGUID = CurrentCharacter.GetCreatureGUIDAsString(); DisplayCreature(CurrentCharacter); } } catch (Exception ex) { CurrentCharacter = null; LoadedGUID = string.Empty; MessageBox.Show($"Error: {ex.Message}", "An error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { var cXML = new CreatureXML(); if (CurrentCharacter != null) { try { cXML.WriteToXML(GetXMLToSave(), CurrentCharacter); } catch (Exception ex) { MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } ShouldSave = false; } else { MessageBox.Show("This character must be built before it can be saved.\n\n" + "Go to \"Options\" then click \"Build Character\" and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }