private void cmbLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e) { string lang = e.AddedItems[0].ToString(); if (!Dialogues.ContainsKey(lang)) { Dialogues.Add(lang, new List <Dialogue>()); } if (!DialogueID.ContainsKey(lang)) { DialogueID.Add(lang, new HashSet <int>()); } if (!Choices.ContainsKey(lang)) { Choices.Add(lang, new List <Choice>()); } lstDialogues.ItemsSource = Dialogues[lang]; lstDialogues.Items.Refresh(); lstChoices.ItemsSource = Choices[lang]; lstChoices.Items.Refresh(); }
public DialogueWindow(Event ev) { InitializeComponent(); SetupDictionaries(); lstDialogues.ItemsSource = Dialogues["english"]; cmbLanguage.SelectedValue = "english"; Event_ = ev; if (Event_.args.Count == 0) { return; } // Json stuffs goin on - parse try { bool found = false; foreach (string language in cmbLanguage.Items) { if (Event_.args.First().Key == language) { found = true; // Make sure the lists exist if (!Dialogues.ContainsKey(language)) { Dialogues.Add(language, new List <Dialogue>()); DialogueID.Add(language, new HashSet <int>()); Choices.Add(language, new List <Choice>()); } break; } } // the languages are defined if (Event_.args.Count > 0) { if (found) { // Load the languages foreach (var o in Event_.args) { JObject jObject = o.Value as JObject; Dictionary <string, object> dict = jObject.ToObject <Dictionary <string, object> >(); // handle language load foreach (var s in dict) { if (s.Key.Contains("dialogue")) { jObject = s.Value as JObject; Dialogue d = jObject.ToObject <Dialogue>(); Dialogues[o.Key].Add(d); DialogueID[o.Key].Add(d.id); } else if (s.Key.Contains("choice")) { jObject = s.Value as JObject; Choices[o.Key].Add(jObject.ToObject <Choice>()); } } } } else { // handle non-language load foreach (var o in Event_.args) { if (o.Key.Contains("dialogue")) { JObject jObject = o.Value as JObject; Dialogue d = jObject.ToObject <Dialogue>(); Dialogues["english"].Add(d); DialogueID["english"].Add(d.id); } else if (o.Key.Contains("choice")) { JObject jObject = o.Value as JObject; Choices["english"].Add(jObject.ToObject <Choice>()); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } lstDialogues.Items.Refresh(); }