}//end of DialogLineToForm
        /// <summary>
        /// Converts form data and values to a DialogLine object
        /// </summary>
        void FromFormToDialogLine()
        {
            DialogLine created = new DialogLine()
            {
                LineID = LineIDTextBox.Text,
                DialogString = DialogStringTextBox.Text,
                SpeakerID = (CharacterNames)SpeakerIDComboBox.SelectedValue,
                SpeakerMood = (MoodTypes)SpeakerMoodComboBox.SelectedValue
            };

            created.PassID = PassIDComboBox.SelectedIndex != 0 ? PassIDComboBox.SelectedValue.ToString() : null;
            created.RegFailID = RegFailIDComboBox.SelectedIndex != 0 ? RegFailIDComboBox.SelectedValue.ToString() : null;
            created.CritFailID = CritFailIDComboBox.SelectedIndex != 0 ? CritFailIDComboBox.SelectedValue.ToString() : null;

            if (TotalTargetMoodPairs > 0)
            {
                foreach (var item in ActiveTargetMoodPairEntries)
                {
                    created.TargetMoodPairs.Add((CharacterNames)item.Value.Key.SelectedValue, (MoodTypes)item.Value.Value.SelectedValue);
                }
            }

            if (TotalResponseIDs > 0)
            {
                foreach (var item in ActiveResponseIDEntries)
                {
                    created.Responses.Add(item.Content.ToString());
                }
            }

            DialogLoader.MasterDialogLinesList.Add(created.LineID, created);
            PopulateFromMasterDialogLinesList();
            ClearForm();
        }//end of FromFormToDialogLine
        }//end of RemoveTMPButton_Click

        /// <summary>
        /// Create a new DialogLine object and add it to the master list to the left, orged alphabetically and named via LineID
        /// </summary>
        private void CreateDialogLineButton_Click(object sender, RoutedEventArgs e)
        {
            if (!DialogLoader.MasterDialogLineList.ContainsKey(LineIDBox.Text))
            {
                DialogLine item = new DialogLine()
                {
                    LineID = LineIDBox.Text,
                    DialogString = DialogBox.Text ?? "null",
                    SpeakerID = SpeakerIDBox.Text ?? "null",
                    SpeakerMood = (MoodTypes)SpeakerMoodBox.SelectedItem,
                    PassTarget = PassBox.Text ?? "null",
                    FailTarget = FailBox.Text ?? "null",
                    CritFailTarget = CritFailBox.Text ?? "null",
                };

                List<string> responses = new List<string>();
                foreach (var response in ResponsesPanel.Children)
                {
                    if (response is CheckBox)
                    {
                        responses.Add((response as CheckBox).Content.ToString());
                    }
                }

                DialogLoader.MasterDialogLineList.Add(item.LineID, item);
            }
        }//end of CreateDialogLineButton_Click
Beispiel #3
0
        }//end of PopulateDialogLines

        /// <summary>
        /// Parses kvps from text file into kvp string,MoodTypes. Being as this method is called at the end of each chunk being built, it can be used in the future for additional/broader parsing
        /// </summary>
        /// <param name="targetMoods">list of raw strings from text files</param>
        /// <param name="buffer">buffer ref used to add parsed kvps to</param>
        static void ParseTargetIDMoodPairs(List<string> targetMoods, DialogLine buffer)
        {
            foreach (string targetMood in targetMoods)
            {
                int separatorIndex = targetMood.IndexOf('|');
                string target = targetMood.Substring(0, separatorIndex);
                MoodTypes mood = (MoodTypes)Enum.Parse(typeof(MoodTypes), targetMood.Substring(separatorIndex + 1));
                buffer.TargetMoods.Add(new KeyValuePair<string, MoodTypes>(target, mood));
            }
            //string targetID = line.Substring()
        }//end of ParseTargetIDMoodPairs
        }//end of ClearForm()

        /// <summary>
        /// Populates form values with selected DialogLine
        /// </summary>
        /// <param name="lineID"></param>
        private void PopulateForm(string lineID)
        {
            ClearForm();
            DialogLine selected = DialogLoader.MasterDialogLineList[lineID];

            LineIDBox.Text = lineID;
            SpeakerIDBox.SelectedItem = selected.SpeakerID;
            SpeakerMoodBox.SelectedItem = selected.SpeakerMood;
            IsExtensionBox.IsChecked = false;
            HierarchyTypeLabel.Content = "N/A";
            DialogBox.Text = selected.DialogString;
            PassBox.Text = selected.PassTarget;
            FailBox.Text = selected.FailTarget;
            CritFailBox.Text = selected.CritFailTarget;

            foreach (string response in selected.PossibleResponses)
            {
                CheckBox item = new CheckBox() { Content = response };

                item.Checked += (object subSender, RoutedEventArgs subE) =>
                {
                    SelectedResponses.Add(item);
                    if (SelectedResponses.Count == ResponsesCount && !(bool)SelectAllResponsesBox.IsChecked)
                    {
                        SelectAllResponsesBox.IsChecked = true;
                    }
                };//end of item.Checked

                item.Unchecked += (object subSender, RoutedEventArgs subE) =>
                {
                    SelectedResponses.Remove(item);
                    if (SelectedResponses.Count <= 0 && (bool)SelectAllResponsesBox.IsChecked)
                    {
                        SelectAllResponsesBox.IsChecked = false;
                    }
                };//end of item.Unchecked

                ResponsesPanel.Children.Add(new CheckBox() { Content = response });
                ResponsesCount++;
            }

            foreach (var kvp in selected.TargetMoods)
            {
                TargetMoodPairControl item = new TargetMoodPairControl(TMPsPanel, SelectAllTMPsBox);

                item.targets.SelectedItem = (CharacterNames)Enum.Parse(typeof(CharacterNames), kvp.Key);
                item.moods.SelectedItem = kvp.Value;
                TMPCount++;
            }

            SelectAllTMPsBox.IsChecked = false;
            SelectAllResponsesBox.IsChecked = false;
        }//end of PopulateForm()
 }//end of CleanLists
 /// <summary>
 /// Transliterates a DialogLine object's values onto the form. Should be called when selecting from active dialoglines list
 /// </summary>
 void FromDialogLineToForm(DialogLine selected)
 {
     ClearForm();
     LineIDTextBox.Text = selected.LineID;
     SpeakerIDComboBox.SelectedItem = selected.SpeakerID;
     SpeakerMoodComboBox.SelectedItem = selected.SpeakerMood;
     DialogStringTextBox.Text = selected.DialogString;
     PassIDComboBox.SelectedValue = selected.PassID ?? "Choose Option";
     RegFailIDComboBox.SelectedValue = selected.RegFailID ?? "Choose Option";
     CritFailIDComboBox.SelectedValue = selected.CritFailID ?? "Choose Option";
     PopulateTargetMoodPairEntries(selected.TargetMoodPairs);
     PopulateResponseIDEntries(selected.Responses);
     ResponseIDsComboBox.SelectedIndex = 0;
 }//end of DialogLineToForm
        }//end of PopulateConsistentFormValues
        /// <summary>
        /// Populates the active dialoglines list with all the entries from the master. This should get called when opening up a new file(s)
        /// </summary>
        void PopulateFromMasterDialogLinesList()
        {
            //This populates all of the Line ID based lists/drop downs with all of the dialog line objects' Line IDs from the master list. I feel like there's a better way to do this but I don't know how right now
            ActiveDialogLinesListBox.Items.Clear();
            foreach (var item in DialogLoader.MasterDialogLinesList)
            {
                ListBoxItem active = new ListBoxItem() { Content = item.Key };
                active.Selected += (object sender, RoutedEventArgs e) =>
                {
                    ClearForm();
                    SelectedDialogLine = DialogLoader.MasterDialogLinesList[item.Key.ToString()];
                    FromDialogLineToForm(SelectedDialogLine);
                };

                ActiveDialogLinesListBox.Items.Add(active);
                ParentDialogLinesComboBox.Items.Add(item.Key);
                PassIDComboBox.Items.Add(item.Key);
                RegFailIDComboBox.Items.Add(item.Key);
                CritFailIDComboBox.Items.Add(item.Key);
                ResponseIDsComboBox.Items.Add(item.Key);
            }
        }//end of PopulateFromMasterDialogLinesList
Beispiel #7
0
        }//end of Initialize

        /// <summary>
        /// Reads each file in the Dialogs folder, later amendments will account for a dialog file prefixed by Day for more organization, though its superfluous and wont actually affect the functionality
        /// </summary>
        public static void LoadDialogLinesFromFile(string file)
        {
            DialogLine buffer = new DialogLine();
            List<string> targetMoods = new List<string>();
            using (StreamReader reader = new StreamReader(File.Open(file,FileMode.Open,FileAccess.Read,FileShare.None)))
            {
                do
                {
                    string raw = reader.ReadLine();
                    if (raw.Contains('['))//check for chunk start indicator and instantiate a new DialogLine buffer object
                    {
                        buffer = new DialogLine();
                    }
                    else if (raw.Contains(']')) //check for chunk end indicator and then check to see if the master reference contains key, add to master accordingly
                    {
                        ParseTargetIDMoodPairs(targetMoods, buffer);
                        MasterDialogLineList.Add(buffer.LineID, buffer);
                    }
                    else//in between start and end, check to see if ChunkIdentifierTypes (cit) is contained in the string currently being read, if so switch and set buffer.citValue to the string
                    {
                        foreach (ChunkIdentifierTypes cit in Enum.GetValues(typeof(ChunkIdentifierTypes)))
                        {
                            if (raw.Contains(cit.ToString()))
                            {
                                raw = raw.Substring(raw.IndexOf(':') + 1);
                                switch (cit)
                                {
                                    case ChunkIdentifierTypes.DialogString:
                                        buffer.DialogString = raw;
                                        break;
                                    case ChunkIdentifierTypes.LineID:
                                        buffer.LineID = raw;
                                        break;
                                    case ChunkIdentifierTypes.SpeakerID:
                                        buffer.SpeakerID = raw;
                                        break;
                                    case ChunkIdentifierTypes.PassTarget:
                                        buffer.PassTarget = raw;
                                        break;
                                    case ChunkIdentifierTypes.FailTarget:
                                        buffer.FailTarget = raw;
                                        break;
                                    case ChunkIdentifierTypes.CriticalFailTarget:
                                        buffer.CritFailTarget = raw;
                                        break;
                                    case ChunkIdentifierTypes.SpeakerMood:
                                        buffer.SpeakerMood = (MoodTypes)Enum.Parse(typeof(MoodTypes), raw);
                                        break;
                                    case ChunkIdentifierTypes.TargetMoods:
                                        targetMoods.Clear();
                                        do
                                        {
                                            string targetMood = reader.ReadLine();
                                            if (targetMood.Contains('{'))
                                            {
                                                continue;
                                            }
                                            else if (targetMood.Contains('}'))//end of targetblock block, break loop and read to the next line
                                            {
                                                reader.ReadLine();
                                                break;
                                            }
                                            else
                                            {
                                                if (!string.IsNullOrEmpty(targetMood))
                                                {
                                                    targetMoods.Add(targetMood); //here its just adding the raw data from the file, it gets parsed at the end of each chunk
                                                }
                                            }
                                        } while (true);
                                        break;
                                    case ChunkIdentifierTypes.Responses:
                                        do
                                        {
                                            string response = reader.ReadLine();
                                            if (response.Contains('{'))
                                            {
                                                continue;
                                            }
                                            else if (response.Contains('}'))//end of response block, break loop and read to the next line
                                            {
                                                reader.ReadLine();
                                                break;
                                            }
                                            else
                                            {
                                                if (!string.IsNullOrEmpty(response))
                                                {
                                                    buffer.PossibleResponses.Add(response);
                                                }
                                            }
                                        } while (true);
                                        break;
                                    case ChunkIdentifierTypes.Fail:
                                    case ChunkIdentifierTypes.CriticalFail:
                                    case ChunkIdentifierTypes.Available:
                                        //handle requirements later
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                    }
                } while (!reader.EndOfStream);
            }
        }//end of PopulateDialogLines
 }//end of ConvertFromTextToDialogLine
 /// <summary>
 /// Handles conversion of DialogLines to text
 /// </summary>
 /// <param name="dialogLine"></param>
 public static void ConvertFromDialogLineToText(DialogLine dialogLine)
 {
     //TODO: after convert from text to DialogLine
 }//end of ConvertFromDialogLineToText
 }//end of WriteDialogTextFiles
 /// <summary>
 /// Handles conversion of text to DialogLines (assuming its in the proper format)
 /// </summary>
 /// <param name="file">Path of file to be read and converted, passed as a Stream object</param>
 public static void ConvertFromTextToDialogLine(Stream file)
 {
     //simple reference for the DialogLine object currently being built
     DialogLine bufferDialogLine = null;
     //stores all of the target ids for the current DialogLine object being built
     List<CharacterNames> bufferTargets = null;
     //stores all of the target moods for the current DialogLine object being built
     List<MoodTypes> bufferMoods = null;
     using (StreamReader reader = new StreamReader(file))
     {
         do
         {
             string line = reader.ReadLine();
             if (line.Contains('['))
             {
                 bufferDialogLine = new DialogLine();
             }
             else if (line.Contains(']'))
             {
                 for (int i = 0; i < bufferTargets.Count; i++)
                 {
                     bufferDialogLine.TargetMoodPairs.Add(bufferTargets[i], bufferMoods[i]);
                 }
                 MasterDialogLinesList.Add(bufferDialogLine.LineID, bufferDialogLine);
             }
             else
             {
                 ChunkIdentifierTypes chunk = (ChunkIdentifierTypes)Enum.Parse(typeof(ChunkIdentifierTypes), line.Substring(0, line.IndexOf(':')));
                 if (line[line.Length - 1] != ':')
                 {
                     string value = line.Substring(line.IndexOf(':') + 1);
                     switch (chunk)
                     {
                         case ChunkIdentifierTypes.LineID:
                             bufferDialogLine.LineID = value;
                             break;
                         case ChunkIdentifierTypes.DialogString:
                             bufferDialogLine.DialogString = value;
                             break;
                         case ChunkIdentifierTypes.SpeakerID:
                             bufferDialogLine.SpeakerID = (CharacterNames)Enum.Parse(typeof(CharacterNames), value);
                             break;
                         case ChunkIdentifierTypes.SpeakerMood:
                             bufferDialogLine.SpeakerMood = (MoodTypes)Enum.Parse(typeof(MoodTypes), value);
                             break;
                         case ChunkIdentifierTypes.Pass:
                             bufferDialogLine.PassID = value;
                             break;
                         case ChunkIdentifierTypes.RegFail:
                             bufferDialogLine.RegFailID = value;
                             break;
                         case ChunkIdentifierTypes.CritFail:
                             bufferDialogLine.CritFailID = value;
                             break;
                         case ChunkIdentifierTypes.Responses:
                         case ChunkIdentifierTypes.Targets:
                         case ChunkIdentifierTypes.Moods:
                             bufferTargets = chunk == ChunkIdentifierTypes.Targets ? new List<CharacterNames>() : bufferTargets;
                             bufferMoods = chunk == ChunkIdentifierTypes.Moods ? new List<MoodTypes>() : bufferMoods;
                             do
                             {
                                 string option = reader.ReadLine();
                                 if (option.Contains('{'))
                                 {
                                     continue;
                                 }
                                 else if (option.Contains('}'))
                                 {
                                     break;
                                 }
                                 else
                                 {
                                     if (!string.IsNullOrEmpty(option) || !string.IsNullOrWhiteSpace(option))
                                     {
                                         switch (chunk)
                                         {
                                             case ChunkIdentifierTypes.Responses:
                                                 bufferDialogLine.Responses.Add(option);
                                                 break;
                                             case ChunkIdentifierTypes.Targets:
                                                 bufferTargets.Add((CharacterNames)Enum.Parse(typeof(CharacterNames), option));
                                                 break;
                                             case ChunkIdentifierTypes.Moods:
                                                 bufferMoods.Add((MoodTypes)Enum.Parse(typeof(MoodTypes), option));
                                                 break;
                                             default:
                                                 break;
                                         }
                                     }
                                 }
                             } while (true);
                             break;
                         case ChunkIdentifierTypes.ReqRegFail:
                             break;
                         case ChunkIdentifierTypes.ReqCritFail:
                             break;
                         case ChunkIdentifierTypes.ReqAvailable:
                             break;
                         default:
                             break;
                     }
                 }
             }
         } while (!reader.EndOfStream);
     }
 }//end of ConvertFromTextToDialogLine