Esempio n. 1
0
        // generate a new prompt without destroying or reloading form
        private void generateNewPrompt()
        {
            PromptGenerator generator = new PromptGenerator(categories);
            BasicTextPrompt newPrompt = generator.findAPrompt(categories, speedModeLimit);

            if (newPrompt.ERROR == true)
            {
                Console.WriteLine("BasicTextPromptForm.generateNewPrompt() : Error - failed to make new prompt");
                MessageBox.Show("Error generating prompt. Please try again.");
                return;
            }
            InitializePrompt(newPrompt);
        }
Esempio n. 2
0
        public void generatePrompt(int timeLimit)
        {
            // find a prompt to match
            BasicTextPrompt myPrompt = findAPrompt(categories, timeLimit);

            // if there was a problem finding a prompt, exit
            if (myPrompt.ERROR)
            {
                Console.WriteLine("startButton_Click(): myPrompt.ERROR = true");
                return;
            }
            // otherwise, set up a new prompt windows form and run it
            BasicTextPromptForm prompt = new BasicTextPromptForm();

            prompt.categories     = this.categories;
            prompt.speedModeLimit = timeLimit;
            //FancyTextPromptForm promptTest = new FancyTextPromptForm();
            prompt.InitializePrompt(myPrompt);
            prompt.ShowDialog();
        }
Esempio n. 3
0
        // user submits form. If input is correct, save new prompt to file
        private void createButton_Click(object sender, EventArgs e)
        {
            string promptName     = "";
            string creativityType = "";
            string category;
            int    tim        = 0;
            string boldPrompt = "";
            string grayPrompt = "";

            // check if form was filled out correctly
            int success = checkInput();

            if (success != 0)
            {
                // * if failed, user should be warned by messagebox in checkInput();
                Console.WriteLine("CreateNewPromptsForm.createButton_Click: input not formatted correctly. Returning.");
                return;
            }

            // pull creativity type
            if (convergentCheckBox.Checked && !divergentCheckBox.Checked)
            {
                creativityType = "Convergent";
            }
            else if (!convergentCheckBox.Checked && divergentCheckBox.Checked)
            {
                creativityType = "Divergent";
            }

            // find out which category was selected
            if (categoryListBox.CheckedItems.Count != 1)
            {
                return;
            }
            category = categoryListBox.CheckedItems[0].ToString();

            // pull time and prompts
            promptName = nameTextBox.Text.Trim().Replace(' ', '_');
            boldPrompt = boldPromptBox.Text;
            grayPrompt = grayPromptBox.Text;
            Int32.TryParse(timeBox.Text, out tim);

            // pull included pictures
            List <string> pics = new List <string>();

            if (!pictureLabel1.Text.Trim().Equals(noPictureText))
            {
                pics.Add(uploadFile1);
            }
            if (!pictureLabel2.Text.Trim().Equals(""))
            {
                pics.Add(uploadFile2);
            }

            BasicTextPrompt newPrompt = new BasicTextPrompt(pics, uploadFileMusic, promptName, category, creativityType, tim, boldPrompt, grayPrompt);

            success = newPrompt.writeOut();
            if (success == 0)
            {
                MessageBox.Show("Prompt created!");
            }
            else
            {
                MessageBox.Show("Failed to create prompt :(");
                return;
            }
            // For convenience of rapidly creating similar prompts, clear pictures but leave all text
            uploadFile1           = ""; uploadFile2 = "";
            pictureLabel1.Text    = noPictureText;
            pictureLabel2.Text    = "";
            uploadMusicLabel.Text = "";
        }
        public static BasicTextPrompt parsePrompt(string promptString, string category)
        {
            BasicTextPrompt newPrompt = new BasicTextPrompt();

            string nametag  = "";
            string thinking = "";
            int    tim      = 0;
            string bold     = "";
            string gray     = "";
            string pic1     = "";
            string pic2     = "";
            string mus      = "";

            string[]      promptLines = System.Text.RegularExpressions.Regex.Split(promptString, @"\r?\n|\r");
            List <string> pics        = new List <string>();
            bool          readingBold = false;

            // parse the text file and populate the new BasicTextPrompt instance
            Console.WriteLine("Trying to parse text file!");
            for (int i = 0; i < promptLines.Length; i++)
            {
                string   line   = promptLines[i];
                string[] tokens = line.Split(':');
                if (tokens.Length < 2 && line.Contains(":"))
                {
                    continue;
                }
                if (tokens.Length < 2 || !line.Contains(":"))
                {
                    if (readingBold)
                    {
                        bold += Environment.NewLine + line;
                    }
                    continue;
                }
                if (tokens[0].Equals("tag"))
                {
                    nametag = line.Substring(line.IndexOf(':') + 2);
                }
                if (tokens[0].Equals("creativityType"))
                {
                    thinking = line.Substring(line.IndexOf(':') + 2);
                }
                if (tokens[0].Equals("time"))
                {
                    tim = Convert.ToInt32(tokens[1].Trim());
                }
                if (tokens[0].Equals("picture1") && line.Contains(":"))
                {
                    pic1 = line.Substring(line.IndexOf(':') + 2);
                    if (Functions.checkFile(pic1))
                    {
                        pics.Add(pic1);
                    }
                    else
                    {
                        pics.Add("");
                    }
                }
                if (tokens[0].Equals("picture2") && line.Contains(":"))
                {
                    pic2 = line.Substring(line.IndexOf(':') + 2);
                    if (Functions.checkFile(pic2))
                    {
                        pics.Add(pic2);
                    }
                    else
                    {
                        pics.Add("");
                    }
                }
                if (tokens[0].Equals("music") && line.Contains(":"))
                {
                    mus = line.Substring(line.IndexOf(':') + 2);
                    if (!Functions.checkFile(mus))
                    {
                        mus = "";
                    }
                }
                if (tokens[0].Equals("pictureResponse"))
                {
                }
                if (tokens[0].Equals("boldPrompt"))
                {
                    readingBold = true;
                    bold        = line.Substring(line.IndexOf(':') + 2);
                    continue;
                }
                if (tokens[0].Equals("grayPrompt"))
                {
                    readingBold = false;
                    gray        = line.Substring(line.IndexOf(':') + 2);
                }
                if (readingBold)
                {
                    bold += Environment.NewLine + line;
                }
            }

            // generate the new prompt
            newPrompt = new BasicTextPrompt(pics, mus, nametag, category, thinking, tim, bold, gray);
            return(newPrompt);
        }
Esempio n. 5
0
        public void InitializePrompt(BasicTextPrompt input)
        {
            timer1.Stop();
            timer1.Interval = secondSpeed;

            // reset basic format
            boldPromptBox.Font         = new Font(boldPromptBox.Font.FontFamily, 11, FontStyle.Bold);
            uploadPictureLabel.Visible = false;
            uploadedFileLabel.Text     = "";
            fileToUpload                        = "";
            richTextBox1.Text                   = "<enter text>";
            this.picture1                       = ""; this.picture2 = "";
            pictureBoxCenter.Visible            = false;
            pictureBoxCenter.Size               = new Size(10, 10);
            pictureBox1.Visible                 = false;
            pictureBox1.Size                    = new Size(10, 10);
            pictureBox2.Visible                 = false;
            pictureBox2.Size                    = new Size(10, 10);
            axWindowsMediaPlayer1.Visible       = false;
            axWindowsMediaPlayer1.settings.mute = true;
            // reduce extension if currently extended
            this.Height      = this.Height - currentExtension;
            currentExtension = 0;

            // pull prompt contents
            this.promptTag       = input.tag;
            this.promptCategory  = input.category;
            this.boldPrompt      = input.boldPrompt;
            this.picture1        = input.picture1;
            this.picture2        = input.picture2;
            promptTypeLabel.Text = input.creativityType + " Thinking";
            boldPromptBox.Text   = input.boldPrompt;
            greyPromptBox.Text   = input.greyPrompt;
            timeLabel.Text       = input.suggestedTime + ":00";
            richTextBox1.Visible = true;

            //if (input.useUploadPicture == true)
            //{
            uploadPictureLabel.Visible = true;
            //}

            // if one picture, add and center it
            if (!picture1.Trim().Equals("") && picture2.Trim().Equals(""))
            {
                // load and scale picture
                pictureBoxCenter.Visible = true;
                Bitmap     image   = new Bitmap(this.picture1);
                List <int> scaling = findPictureScale(this.picture1);
                image = new Bitmap(image, new Size(scaling[0], scaling[1]));
                pictureBoxCenter.Image = image;
                pictureBoxCenter.Size  = pictureBoxCenter.Image.Size;
                // resize form to fit
                this.Height      = this.Height + scaling[1];
                currentExtension = currentExtension + scaling[1];
                // center picture
                centerPicture(pictureBoxCenter, pictureBoxCenter.Width, 0.50);
                //pictureBoxCenter.Location = new Point(newXLoc, pictureBoxCenter.Location.Y);
            }
            // if two pictures, place them side by side
            else if (!picture1.Trim().Equals("") && !picture2.Trim().Equals(""))
            {
                pictureBox1.Visible = true; pictureBox2.Visible = true;

                Bitmap     image1   = new Bitmap(picture1);
                List <int> scaling1 = findPictureScale(picture1);
                image1            = new Bitmap(image1, new Size(scaling1[0], scaling1[1]));
                pictureBox1.Image = image1;
                pictureBox1.Size  = pictureBox1.Image.Size;
                // center picture
                centerPicture(pictureBox1, pictureBox1.Width, 0.27);
                //pictureBox1.Location = new Point(newXLoc, pictureBox1.Location.Y);

                Bitmap     image2   = new Bitmap(picture2);
                List <int> scaling2 = findPictureScale(picture2);
                image2            = new Bitmap(image2, new Size(scaling2[0], scaling2[1]));
                pictureBox2.Image = image2;
                pictureBox2.Size  = pictureBox2.Image.Size;
                // center picture
                centerPicture(pictureBox2, pictureBox2.Width, 0.73);
                //pictureBox2.Location = new Point(newXLoc, pictureBox2.Location.Y);

                // see which picture is taller and resize form to fit
                int tallest = 0;
                if (pictureBox1.Height > pictureBox2.Height)
                {
                    tallest = scaling1[1];
                }
                else
                {
                    tallest = scaling2[1];
                }
                this.Height      = this.Height + tallest;
                currentExtension = currentExtension + tallest;
            }

            // add music player if necessary
            if (!input.music.Equals(""))
            {
                axWindowsMediaPlayer1.Visible       = true;
                axWindowsMediaPlayer1.URL           = input.music;
                axWindowsMediaPlayer1.settings.mute = false;
            }
            // if prompt is big, reduce font size
            if (boldPromptBox.Text.Length > 200)
            {
                boldPromptBox.Font = new Font(boldPromptBox.Font.FontFamily, 11);
            }
            if (boldPromptBox.Text.Length > 300)
            {
                boldPromptBox.Font = new Font(boldPromptBox.Font.FontFamily, 9);
            }

            // center form on screen
            this.CenterToScreen();

            // restart timer
            timer1.Start();
        }
Esempio n. 6
0
        public BasicTextPrompt findAPrompt(List <string> categories, int timeLimit)
        {
            BasicTextPrompt newPrompt = new BasicTextPrompt();

            // pick a random category
            Random rnd           = new Random();
            int    categoryIndex = rnd.Next(categories.Count);
            string category      = categories[categoryIndex];

            string fullPath = Functions.getCategoryFileName(category);

            Console.WriteLine("path for prompt files: " + fullPath);

            // if path to desired category returned an error, return
            if (fullPath.Contains("ERROR"))
            {
                System.Windows.Forms.MessageBox.Show("Error - failed to generate prompt for category " + category);
                newPrompt.ERROR = true;
                return(newPrompt);
            }

            // find available prompts in prompt file
            List <string> availablePrompts = Functions.getPromptsFromFile(fullPath);

            //foreach (string prompt in availablePrompts)
            //{
            //    //Console.WriteLine(prompt);
            //}

            // if no prompts, return error
            if (availablePrompts.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show("No available prompts for category " + category + ". Please create some!");
                newPrompt.ERROR = true;
                return(newPrompt);
            }

            // pick one using a random number
            int numAvailablePrompts = availablePrompts.Count;

            if (numAvailablePrompts < 1)
            {
                System.Windows.Forms.MessageBox.Show("No prompts available for category " + category);
                newPrompt.ERROR = true;
                return(newPrompt);
            }

            Random rnd2         = new Random();
            int    choiceIndex  = rnd2.Next(0, numAvailablePrompts);
            string choicePrompt = availablePrompts[choiceIndex];

            Console.WriteLine("chosen file = " + choicePrompt);

            // process the prompt
            int failures = 0;

            if (timeLimit == 0)
            {
                newPrompt = BasicTextPrompt.parsePrompt(choicePrompt, category);
                return(newPrompt);
            }
            else
            {
                while (failures < Constants.speedModeFailureLimit)
                {
                    if (BasicTextPrompt.checkIfOverTimeLimit(choicePrompt, timeLimit).Equals("OK"))
                    {
                        newPrompt = BasicTextPrompt.parsePrompt(choicePrompt, category);
                        return(newPrompt);
                    }
                    failures++;
                    rnd2         = new Random();
                    choiceIndex  = rnd2.Next(0, numAvailablePrompts);
                    choicePrompt = availablePrompts[choiceIndex];
                }
                System.Windows.Forms.MessageBox.Show("Sorry, had trouble finding a speed mode prompt. To try again, skip the current prompt.");
                newPrompt = BasicTextPrompt.parsePrompt(choicePrompt, category);
                return(newPrompt);
            }

            // return the final prompt
            //return newPrompt;
        }