Пример #1
0
        private void buildCharacterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (CurrentCharacter != null)
                {
                    DialogResult result = MessageBox.Show("Are you sure you want to build this Character?\n\n" +
                                                          "Currently-loaded character information will be disgarded.",
                                                          "Build Character and Generate GUID",
                                                          MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                    if (result == DialogResult.Yes)
                    {
                        CurrentCharacter = BuildCreature();

                        LoadedGUID  = CurrentCharacter.GetCreatureGUIDAsString() ?? string.Empty;
                        tbGUID.Text = CurrentCharacter.GetCreatureGUIDAsString().ToUpper() ?? string.Empty;
                    }
                }
                else
                {
                    CurrentCharacter = BuildCreature();

                    LoadedGUID  = CurrentCharacter.GetCreatureGUIDAsString() ?? string.Empty;
                    tbGUID.Text = CurrentCharacter.GetCreatureGUIDAsString().ToUpper() ?? string.Empty;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{ex.Message}\n\n" +
                                "Note: Attempting to build a character while leaving fields other than \"Surname\" or \"Subrace\" empty " +
                                "will result in failure. Please check all other fields then try to build the character again.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        /// <summary>
        /// Parses all values from the creation form to create a new Creature object.
        /// </summary>
        /// <returns>Returns an object of a class that derives from the Creature class.</returns>
        private Creature BuildCreature()
        {
            if (ParseEnumValues(out Dictionary <string, Enum> parsedEnums) &&
                ParseIntValues(out Dictionary <string, int> parsedInts) &&
                !string.IsNullOrEmpty(tbFirstName.Text))
            {
                //do this if building a NEW character
                if (CurrentCharacter == null)
                {
                    //create a new creature with a derived type specified by the "Race" setting
                    CreatureBuilder cb          = new CreatureBuilder((Race)parsedEnums["Race"]);
                    Creature        newCreature = cb.NewCreature;

                    //assign parsed values to the new Creature object
                    AssignValues(newCreature, parsedEnums, parsedInts);

                    LoadedGUID  = newCreature.GetCreatureGUIDAsString();
                    tbGUID.Text = newCreature.GetCreatureGUIDAsString().ToUpper();

                    return(newCreature);
                }
                //do this if building on an EXISTING character
                else
                {
                    //assign parsed values to the current character
                    //will change the values of the CurrentCharacter property
                    AssignValues(CurrentCharacter, parsedEnums, parsedInts);

                    Creature existingCreature = CurrentCharacter;

                    LoadedGUID  = CurrentCharacter.GetCreatureGUIDAsString();
                    tbGUID.Text = CurrentCharacter.GetCreatureGUIDAsString().ToUpper();

                    return(existingCreature);
                }
            }
            else
            {
                MessageBox.Show("Error: The character could not be created because a value failed to parse correctly.\n\n" +
                                "The only two fields that can be empty are the Subrace and Surname fields.\n\n" +
                                "Fields that are meant to contain numbers can only contain numbers, usually positive integers.\n\n" +
                                "Please check all other fields and try again.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(null);
            }
        }
Пример #3
0
        /// <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);
                }
            }
        }