Ejemplo n.º 1
0
        //Add Grid - First step of the script adding process. Paste in a script and give it a name
        private void Add_AddScriptButton_Click(object sender, RoutedEventArgs e)
        {
            Add_ScriptName.Text = Add_ScriptName.Text.Trim();
            //Ensure the script has a name
            if (Add_ScriptName.Text == "")
            {
                MessageBox.Show("You need to give this script a name.", "An error occurred");
                return;
            }
            //Ensure the name is unique
            else if (!MGSOGlobals.IsScriptNameUnique(Main_ListBox, Add_ScriptName.Text))
            {
                MessageBox.Show("Two scripts cannot have the same name.", "Duplicate script");
                return;
            }

            //Put the text box in a global array
            MGSOGlobals.StoreScript(Add_ScriptBody.Text);
            string mainGlobalScript = "";

            //If a main global script has been specified, use that one
            if (MGSOGlobals.potentialGlobalScripts.Contains(Add_ScriptMain2.Text))
            {
                mainGlobalScript = Add_ScriptMain2.Text;
            }
            //If a main global isn't specified and there's too  many scripts, return an error
            if (MGSOGlobals.potentialGlobalScripts.Count > 1 && mainGlobalScript == "")
            {
                int    count = 0;
                string test  = ""; //String that will contain all possible main global scripts listed
                foreach (string s in MGSOGlobals.potentialGlobalScripts)
                {
                    count++;
                    if (count == 1)
                    {
                        test += s;
                    }
                    else if (count == MGSOGlobals.potentialGlobalScripts.Count) //Last script needs an and
                    {
                        if (count == 2)                                         //The second script in a list of two doesn't need a comma seperating it
                        {
                            test += " and " + s;
                        }
                        else
                        {
                            test += ", and " + s;
                        }
                    }
                    else //Scripts past the first need a comma
                    {
                        test += ", " + s;
                    }
                } //Curse you, grammar!
                MessageBox.Show("MGSO has found the following global scripts: " + test + ". Please select the active (slot 2) global script from these options.", "Multiple global scripts found");
            }
            //Otherwise resume loading the script
            else
            {
                //Store the sections of a script to temp globals and return the result
                int result = MGSOGlobals.StoreScriptSections(MGSOGlobals.IdiotProofScript(Add_ScriptBody.Text), Add_ScriptName.Text, mainGlobalScript);
                if (result == 1) //Failure reading script
                {
                    MessageBox.Show("Not all parts of the global script could be read correctly.", "An error occurred");
                }
                else if (result == 2) //No example script, proceed to Add2 Grid
                {
                    MessageBoxResult mbr = MessageBox.Show("There was no example global script included. Try using functions?", "An error occurred", MessageBoxButton.YesNo);
                    if (mbr == MessageBoxResult.Yes)
                    {
                        MGSOGlobals.LoadFunctions(String.Join("\r\n", MGSOGlobals.tempHeaders.ToArray()), Add2_ListBox);

                        Grid_Add.IsEnabled  = false;
                        Grid_Add.Visibility = Visibility.Hidden;

                        Grid_Add2.IsEnabled  = true;
                        Grid_Add2.Visibility = Visibility.Visible;
                    }
                }
                else if (result == 3) //Depth issue. Hopefully resolved.
                {
                    MessageBox.Show("Something went wrong while loading the script. You probably shouldn't be seeing this message. If you are, you should maybe report it. This script you're trying to use was probably written by a madman.", "An error occurred");
                }
                else if (result == 0) //Success, return to Main Grid
                {
                    MGSOGlobals.AddScript(Main_ListBox);
                    Add_ScriptBody.Text  = "";
                    Add_ScriptName.Text  = "";
                    Add_ScriptMain2.Text = "";

                    Grid_Add.IsEnabled  = false;
                    Grid_Add.Visibility = Visibility.Hidden;

                    Grid_Main.IsEnabled  = true;
                    Grid_Main.Visibility = Visibility.Visible;
                }
            }
        }