public void Display() { Simulation.OnPropertyChanged(""); mainText.Text = string.Empty; responsesPanel.Children.Clear(); formatter.Markup(npcNameText, FormatText(Character.DisplayName) ?? string.Empty); for (int i = 0; i < Dialogue.Messages.Count; i++) { NPCMessage msg = Dialogue.Messages[i]; if (msg.conditions.All(d => d.Check(Simulation))) { foreach (NPC.Conditions.Condition c in msg.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in msg.rewards) { r.Give(Simulation); } lastMessageId = i; lastPage = 0; lastMessage = msg; if (msg.prev != 0) { NPCDialogue prevNext; if (GameAssetManager.TryGetAsset <GameDialogueAsset>(msg.prev, out var gameDialogueAsset)) { prevNext = gameDialogueAsset.dialogue; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_DialogueNotFound", msg.prev)); Close(); return; } Previous = prevNext; } DisplayPage(msg, i, 0); break; } } }
IEnumerator MessageUpdate() { while (true) { yield return(new WaitForSeconds(Random.Range(2f, 15f))); msgData = npcInfo.talkList[Random.Range(0, npcInfo.talkList.Count)]; msgData.Context += npcInfo.speech.tailTalk; MsgSet(); yield return(new WaitForSeconds(Random.Range(2f, 4f))); msgBox.SetActive(false); } }
public void Display() { Simulation.OnPropertyChanged(""); mainText.Text = string.Empty; responsesPanel.Children.Clear(); formatter.Markup(npcNameText, FormatText(Character.displayName) ?? string.Empty); for (int i = 0; i < Dialogue.messages.Count; i++) { NPCMessage msg = Dialogue.messages[i]; if (msg.conditions.All(d => d.Check(Simulation))) { foreach (NPC.Conditions.Condition c in msg.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in msg.rewards) { r.Give(Simulation); } lastMessageId = i; lastPage = 0; lastMessage = msg; if (msg.prev != 0) { Previous = MainWindow.CurrentProject.data.dialogues.SingleOrDefault(d => d.id == msg.prev); } DisplayPage(msg, i, 0); break; } } }
//Displays next npc message by popping from stack. //Cannot happen if playerTalking is true(player options are showing) void NPCTalk() { NPCMessage currMessage = null; //To store popped message. if (NPCMessageStack.Count > 0) //If any remaining messages in the stack. { currMessage = NPCMessageStack.Pop(); //Pop and store message. } if (currMessage != null) //If there is a popped message. { GameObject newNPCPanel = AddNewDialogueBox(npcPanelPrefab); //Instantiate new NPC dialogue box. Text newNPCText = newNPCPanel.GetComponentInChildren <Text>(); //Store text of new NPC dialogue box. newNPCText.text = currMessage.getText(); //Replace text with current message text. StartCoroutine(ScrollAllDialogue()); //Scroll all dialogue boxes. if (currMessage.hasResponses()) //If player has responses to npc message. { playerTalking = true; //Can add new player buttons. currPResponses = currMessage.getResponses(); //Store player response array. npcTalking = false; //Set to false so we don't show new npc dialogues while player options are showing. //playerTalking = true; //Can add new player button. } } }
private static void Export_Dialogues(IEnumerable <NPCDialogue> dialogues) { foreach (NPCDialogue dialogue in dialogues) { try { Directory.CreateDirectory(dir + $@"Dialogues\{dialogue.guid}_{dialogue.id}"); using (StreamWriter asset = new StreamWriter(dir + $@"Dialogues\{dialogue.guid}_{dialogue.id}\Asset.dat", false, Encoding.UTF8)) using (StreamWriter local = new StreamWriter(dir + $@"Dialogues\{dialogue.guid}_{dialogue.id}\English.dat", false, Encoding.UTF8)) { asset.WriteLine(WaterText); local.WriteLine(WaterText); if (AppConfig.Instance.generateGuids) { asset.WriteLine($"GUID {dialogue.guid}"); } asset.WriteLine($"Type Dialogue"); asset.WriteLine($"ID {dialogue.id}"); if (dialogue.MessagesAmount > 0) { asset.WriteLine($"Messages {dialogue.MessagesAmount}"); for (int k = 0; k < dialogue.MessagesAmount; k++) { NPCMessage message = dialogue.messages[k]; if (message.PagesAmount > 0) { asset.WriteLine($"Message_{k}_Pages {message.PagesAmount}"); } List <NPCResponse> visibleResponses = dialogue.responses.Where(d => d.VisibleInAll || d.visibleIn.Length <= k || d.visibleIn[k] == 1).ToList(); if (visibleResponses.Count() > 0 && visibleResponses.Count() < dialogue.responses.Count()) { asset.WriteLine($"Message_{k}_Responses {visibleResponses.Count()}"); int visResCnt = visibleResponses.Count(); for (int c = 0; c < visResCnt; c++) { NPCResponse response = visibleResponses[c]; int id = dialogue.responses.IndexOf(response); asset.WriteLine($"Message_{k}_Response_{c} {id}"); } } if (message.conditions.Length > 0) { asset.WriteLine($"Message_{k}_Conditions {message.conditions.Length}"); for (int c = 0; c < message.conditions.Length; c++) { NPC.Conditions.Condition cond = message.conditions[c]; asset.WriteLine(ExportCondition(cond, $"Message_{k}_", c)); if (!string.IsNullOrEmpty(cond.Localization)) { local.WriteLine($"Message_{k}_Condition_{c} {cond.Localization}"); } } } if (message.rewards.Length > 0) { asset.WriteLine($"Message_{k}_Rewards {message.rewards.Length}"); for (int c = 0; c < message.rewards.Length; c++) { Reward rew = message.rewards[c]; asset.WriteLine(ExportReward(rew, $"Message_{k}_", c)); if (!string.IsNullOrEmpty(rew.Localization)) { local.WriteLine($"Message_{k}_Reward_{c} {rew.Localization}"); } } } if (message.prev > 0) { asset.WriteLine($"Message_{k}_Prev {message.prev}"); } } } if (dialogue.ResponsesAmount > 0) { asset.WriteLine($"Responses {dialogue.ResponsesAmount}"); for (int k = 0; k < dialogue.ResponsesAmount; k++) { NPCResponse response = dialogue.responses[k]; if (!response.VisibleInAll) { asset.WriteLine($"Response_{k}_Messages {response.visibleIn.Count(d => d == 1)}"); for (int c = 0, ind = 0; c < dialogue.MessagesAmount; c++) { NPCMessage currentMessage = dialogue.messages[c]; if (response.visibleIn.Length <= c || response.visibleIn[c] == 1) { asset.WriteLine($"Response_{k}_Message_{ind++} {dialogue.messages.IndexOf(currentMessage)}"); } } } if (response.openDialogueId > 0) { asset.WriteLine($"Response_{k}_Dialogue {response.openDialogueId}"); } if (response.openQuestId > 0) { asset.WriteLine($"Response_{k}_Quest {response.openQuestId}"); } if (response.openVendorId > 0) { asset.WriteLine($"Response_{k}_Vendor {response.openVendorId}"); } if (response.conditions.Count() > 0) { asset.WriteLine($"Response_{k}_Conditions {response.conditions.Count()}"); int cndCnt = response.conditions.Count(); for (int c = 0; c < cndCnt; c++) { NPC.Conditions.Condition cond = response.conditions[c]; asset.WriteLine(ExportCondition(cond, $"Response_{k}_", c)); if (!string.IsNullOrEmpty(cond.Localization)) { local.WriteLine($"Response_{k}_Condition_{c} {cond.Localization}"); } } } if (response.rewards.Count() > 0) { asset.WriteLine($"Response_{k}_Rewards {response.rewards.Count()}"); int rwrdCnt = response.rewards.Count(); for (int c = 0; c < rwrdCnt; c++) { Reward rew = response.rewards[c]; asset.WriteLine(ExportReward(rew, $"Response_{k}_", c)); if (!string.IsNullOrEmpty(rew.Localization)) { local.WriteLine($"Response_{k}_Reward_{c} {rew.Localization}"); } } } } } for (int k = 0; k < dialogue.MessagesAmount; k++) { for (int c = 0; c < dialogue.messages[k].PagesAmount; c++) { local.WriteLine($"Message_{k}_Page_{c} {dialogue.messages[k].pages[c]}"); } } for (int k = 0; k < dialogue.ResponsesAmount; k++) { local.WriteLine($"Response_{k} {dialogue.responses[k].mainText}"); } } } catch (Exception ex) { App.Logger.LogException($"Can't export dialogue {dialogue.id}", ex: ex); App.NotificationManager.Notify(LocalizationManager.Current.Notification.Translate("Export_Dialogue_Error", dialogue.id)); } } }
public void DisplayPage(NPCMessage message, int i, int page) { Simulation.OnPropertyChanged(""); formatter.Markup(mainText, FormatText(message.pages[page])); lastPage = page; if (!canDisplayNextPage) { foreach (NPCResponse res in Dialogue.Responses) { if ((res.VisibleInAll || res.visibleIn.Length <= i || res.visibleIn[i] == 1) && res.conditions.All(d => d.Check(Simulation))) { Border border = new Border() { BorderBrush = App.Current.Resources["AccentColor"] as Brush, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4), Margin = new Thickness(0, 2.5, 0, 2.5) }; border.PreviewMouseLeftButtonDown += (sender, e) => { bool shouldClose = true; if (res.openQuestId > 0) { shouldClose = false; NPCQuest questAsset; if (GameAssetManager.TryGetAsset <GameQuestAsset>(res.openQuestId, out var gameQuestAsset)) { questAsset = gameQuestAsset.quest; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_QuestNotFound", res.openQuestId)); Close(); return; } Quest_Status questStatus = Simulation.GetQuestStatus(questAsset.ID); QuestView_Window.EMode _mode; switch (questStatus) { case Quest_Status.Ready: _mode = QuestView_Window.EMode.END_QUEST; break; default: _mode = QuestView_Window.EMode.BEGIN_QUEST; break; } QuestView_Window qvw = new QuestView_Window(Character, Simulation, questAsset, _mode); if (qvw.ShowDialog() == true) { foreach (NPC.Conditions.Condition c in res.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in res.rewards) { r.Give(Simulation); } if (res.openDialogueId > 0) { Previous = Start; NPCDialogue next; if (GameAssetManager.TryGetAsset <GameDialogueAsset>(res.openDialogueId, out var gameDialogueAsset)) { next = gameDialogueAsset.dialogue; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_DialogueNotFound", res.openDialogueId)); Close(); return; } Dialogue = next; Display(); } } return; } else if (res.openVendorId > 0) { shouldClose = false; NPCVendor vendorAsset; if (GameAssetManager.TryGetAsset <GameVendorAsset>(res.openVendorId, out var gameVendorAsset)) { vendorAsset = gameVendorAsset.vendor; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_VendorNotFound", res.openVendorId)); Close(); return; } VendorView_Window qvw = new VendorView_Window(Character, Simulation, vendorAsset); qvw.ShowDialog(); foreach (NPC.Conditions.Condition c in res.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in res.rewards) { r.Give(Simulation); } if (res.openDialogueId > 0) { Previous = Start; NPCDialogue next; if (GameAssetManager.TryGetAsset <GameDialogueAsset>(res.openDialogueId, out var gameDialogueAsset)) { next = gameDialogueAsset.dialogue; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_DialogueNotFound", res.openDialogueId)); Close(); return; } Dialogue = next; Display(); } return; } foreach (NPC.Conditions.Condition c in res.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in res.rewards) { r.Give(Simulation); } if (res.openDialogueId > 0) { Previous = Dialogue; NPCDialogue next; if (GameAssetManager.TryGetAsset <GameDialogueAsset>(res.openDialogueId, out var gameDialogueAsset)) { next = gameDialogueAsset.dialogue; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_DialogueNotFound", res.openDialogueId)); Close(); return; } Display(); } else if (shouldClose) { Close(); } }; Grid g = new Grid(); TextBlock tb = new TextBlock(); formatter.Markup(tb, FormatText(res.mainText)); Label l = new Label() { Content = tb, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(5) }; g.Children.Add(l); PackIconMaterial icon = null; if (res.openQuestId > 0) { switch (Simulation.GetQuestStatus(res.openQuestId)) { case Quest_Status.Ready: icon = new PackIconMaterial() { Kind = PackIconMaterialKind.Help }; break; default: icon = new PackIconMaterial() { Kind = PackIconMaterialKind.Exclamation }; break; } } else if (res.openVendorId > 0) { icon = new PackIconMaterial() { Kind = PackIconMaterialKind.ShoppingOutline }; } if (icon != null) { icon.VerticalAlignment = VerticalAlignment.Center; icon.HorizontalAlignment = HorizontalAlignment.Left; icon.Margin = new Thickness(5); icon.Foreground = App.Current.Resources["AccentColor"] as Brush; g.Children.Add(icon); } border.Child = g; responsesPanel.Children.Add(border); } } } }