public TopicEntry GetTopic(CreatureEntity collocutor, int conversationIndex, TopicEntry parentTopic, string phrase) { TopicEntry result = null; DialogEntry dlg = Dialog; ConversationEntry curConvers = dlg.GetConversation(conversationIndex); if (parentTopic == null) { result = curConvers.GetTopic(0); } else { for (int i = 0; i < parentTopic.TopicsCount; i++) { TopicEntry subTopic = parentTopic.GetTopic(i); if ((subTopic.Phrase == phrase)) { result = subTopic; break; } } } return(result); }
private void ShowTopic(TopicEntry topic, bool isRoot) { if (topic == null) { AddText(BaseLocale.GetStr(RS.rs_NothingToSay)); } else { if (isRoot) { string qst = topic.Phrase; if (!string.IsNullOrEmpty(qst)) { AddText(qst); } } if (CheckScript(topic.Action) && !string.IsNullOrEmpty(topic.Answer)) { AddText(topic.Answer); for (int i = 0; i < topic.TopicsCount; i++) { TopicEntry subTopic = topic.GetTopic(i); if (CheckScript(subTopic.Condition)) { AddText("@" + subTopic.Phrase + "@ "); } } } } }
private void OnLinkClick(object sender, string linkValue) { int idx = fConversations.SelIndex; if (idx != -1) { SentientBrain b = (SentientBrain)fCollocutor.Brain; fCurTopic = b.GetTopic(GlobalVars.nwrGame.Player, idx, fCurTopic, linkValue); ShowTopic(fCurTopic, false); } }
private void OnConversationSelect(object sender, MouseButton button, LBItem item) { fTextBox.Lines.Clear(); int idx = fConversations.SelIndex; SentientBrain colBrain = (SentientBrain)fCollocutor.Brain; fCurTopic = colBrain.GetTopic(GlobalVars.nwrGame.Player, idx, null, ""); ShowTopic(fCurTopic, true); }
private void GenerateTopicList() { topicEntryList.ResetList(); topicEntryList = new EntryList <TopicEntry>(visibleSize); topics.Sort((x, y) => string.Compare(x.topic, y.topic)); for (int i = 0; i < topics.Count; i++) { if (topics[i].unlockDay > currentDays.value) { continue; } Transform t = Instantiate(topicPrefab, topicListParent); TopicEntry entry = topicEntryList.CreateEntry(t); bool newTopic = (currentDays.value == topics[i].unlockDay); entry.FillData(i, topics[i].topic, newTopic); } topicPrefab.gameObject.SetActive(false); UpdateTopicList(); }
static EitriBrain() { SfDialog = new DialogEntry(); ConversationEntry defConvers = SfDialog.AddConversation(); defConvers.Name = BaseLocale.GetStr(RS.rs_EitriTopic); TopicEntry rootTopic = defConvers.AddTopic(); rootTopic.Answer = BaseLocale.GetStr(RS.rs_EitriSaid) + "\"" + BaseLocale.GetStr(RS.rs_Eitri1) + "\"."; TopicEntry topic = rootTopic.AddTopic(); topic.Condition = "player.hasItem('PlatinumAnvil')"; topic.Phrase = BaseLocale.GetStr(RS.rs_Eitri_Yes); topic.Answer = BaseLocale.GetStr(RS.rs_Eitri3) + " " + BaseLocale.GetStr(RS.rs_Eitri4); topic.Action = "player.transferItem(NPC, 'PlatinumAnvil'); NPC.transferItem(player, 'DwarvenArm');"; topic = rootTopic.AddTopic(); topic.Phrase = BaseLocale.GetStr(RS.rs_Eitri_No); topic.Answer = BaseLocale.GetStr(RS.rs_Eitri2); }
/// <summary> /// Creates a new instance of the class based on an existing TopicEntry /// </summary> /// <param name="entry"></param> internal static IndexTopic FromTopicEntry(TopicEntry entry) { return(new IndexTopic(entry.EntryOffset, entry.ChmFile)); //return new IndexTopic( entry.Title, entry.Locale, entry.ChmFile.CompileFile, entry.ChmFile.ChmFilePath); }
public void RefreshDialogue(string newNodeID, bool showResponse) { //if loading a new node, first create a dialogue entry for it and push into //the stack. if (newNodeID != "") { //create dialogue entry //Debug.Log("new node ID " + newNodeID); DialogueNode node = GameManager.Inst.DBManager.DBHandlerDialogue.GetDialogueNode(newNodeID); if (showResponse) { DialogueResponse response = EvaluateResponse(node.Responses); if (response != null) { DialogueEntry entry = CreateDialogueEntry(GetSpeakerName(), ParseDialogueText(response.Text), false); _entries.Push(entry); //check if response has an event if (response.Events != null && response.Events.Count > 0) { foreach (string e in response.Events) { if (GameManager.Inst.QuestManager.Scripts.ContainsKey(e)) { StoryEventScript script = GameManager.Inst.QuestManager.Scripts[e]; script.Trigger(new object[] {}); } } } } } //create dialogue options relevant to this node foreach (Topic option in node.Options) { if (EvaluateTopicConditions(option.Conditions)) { DialogueOptionEntry optionEntry = new DialogueOptionEntry(); GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject; optionEntry.Text = o.GetComponent <UILabel>(); optionEntry.Text.text = option.Title; TopicReference reference = o.GetComponent <TopicReference>(); reference.Topic = option; UIButton button = o.GetComponent <UIButton>(); button.onClick.Add(new EventDelegate(this, "OnSelectTopic")); _options.Add(optionEntry); } } } //create topics entry Character target = GameManager.Inst.PlayerControl.SelectedPC.MyAI.BlackBoard.InteractTarget; List <Topic> topics = GameManager.Inst.DBManager.DBHandlerDialogue.GetNPCTopics(target, null); foreach (Topic topic in topics) { //if we are not at root node then don't show info topics if (topic.Type == TopicType.Info && _currentNodeID != _rootNode) { continue; } //if topic is not known to player, don't show it if (topic.Type == TopicType.Info && !GameManager.Inst.PlayerProgress.IsTopicDiscovered(topic.ID)) { continue; } TopicEntry entry = new TopicEntry(); GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject; entry.Text = o.GetComponent <UILabel>(); entry.Text.text = topic.Title; TopicReference reference = o.GetComponent <TopicReference>(); reference.Topic = topic; UIButton button = o.GetComponent <UIButton>(); button.onClick.Add(new EventDelegate(this, "OnSelectTopic")); BoxCollider2D collider = o.GetComponent <BoxCollider2D>(); collider.size = new Vector2(collider.size.x, 27); entry.Type = topic.Type; _topics.Add(entry); } //now make a copy of the stack, and start popping entries out of it, and arrange them under the dialog panel Stack <DialogueEntry> copy = new Stack <DialogueEntry>(_entries.Reverse()); float currentY = -260; _totalHeight = 0; int i = 0; while (copy.Count > 0) { DialogueEntry entry = copy.Pop(); entry.SpeakerName.transform.parent = DialogueEntryAnchor.transform; entry.SpeakerName.MakePixelPerfect(); entry.Text.transform.parent = DialogueEntryAnchor.transform; entry.Text.MakePixelPerfect(); float height = Mathf.Max(entry.SpeakerName.height * 1f, entry.Text.height * 1f); entry.SpeakerName.transform.localPosition = new Vector3(-150, currentY + height, 0); entry.Text.transform.localPosition = new Vector3(22, currentY + height, 0); currentY = currentY + height + 15; _totalHeight += (height + 15); if (_totalHeight < 400) { DialogueEntryAnchor.localPosition = new Vector3(-210, 0 - _totalHeight, 0); _dialogueAnchorTarget = new Vector3(-210, 175 - _totalHeight, 0); } else { DialogueEntryAnchor.localPosition = new Vector3(-210, -220, 0); _dialogueAnchorTarget = new Vector3(-210, -175, 0); } i++; } //now re-add collider to fix collider size NGUITools.AddWidgetCollider(DialogueScroll.gameObject); /* * if(_intro != null) * { * _intro.transform.parent = DialogueEntryAnchor.transform; * _intro.MakePixelPerfect(); * _intro.transform.localPosition = new Vector3(-150, currentY + _intro.height, 0); * } */ //arrange topic entries currentY = 200; TopicScroll.ResetPosition(); foreach (TopicEntry entry in _topics) { entry.Text.transform.parent = TopicAnchor.transform; entry.Text.MakePixelPerfect(); entry.Text.transform.localPosition = new Vector3(0, currentY, 0); currentY = currentY - entry.Text.height; if (entry.Text.text == "Goodbye") { currentY = currentY - 15; } if (entry.Type != TopicType.Info) { entry.Text.color = new Color(0.5f, 0.5f, 0.8f); } } //now re-add collider to fix collider size //NGUITools.AddWidgetCollider(TopicScroll.gameObject, false); float currentX = -128; foreach (DialogueOptionEntry entry in _options) { entry.Text.transform.parent = DialogueOptionScroll.transform; entry.Text.MakePixelPerfect(); entry.Text.width = entry.Text.text.Length * 15; entry.Text.transform.localPosition = new Vector3(currentX, 78, 0); BoxCollider2D collider = entry.Text.GetComponent <BoxCollider2D>(); collider.size = new Vector2(collider.size.x, 27); currentX = currentX + entry.Text.width + 20; } }
static VictimBrain() { SfAgnarDialog = new DialogEntry(); ConversationEntry defConvers = SfAgnarDialog.AddConversation(BaseLocale.GetStr(RS.rs_Sacrifice)); TopicEntry rootTopic = defConvers.AddTopic(); rootTopic.Answer = BaseLocale.GetStr(RS.rs_Agnar_IsStrungUp) + " " + BaseLocale.GetStr(RS.rs_VictimPleads); TopicEntry topic1 = rootTopic.AddTopic(); topic1.Phrase = BaseLocale.GetStr(RS.rs_Agnar_KickOutStump); topic1.Answer = BaseLocale.GetStr(RS.rs_SacrificeAward); topic1.Action = "NPC.sacrificeVictim();"; TopicEntry topic2 = rootTopic.AddTopic(); topic2.Phrase = BaseLocale.GetStr(RS.rs_SetHimFree); topic2.Answer = BaseLocale.GetStr(RS.rs_VictimFree); topic2.Action = "NPC.freeVictim();"; TopicEntry topic3 = rootTopic.AddTopic(); topic3.Phrase = BaseLocale.GetStr(RS.rs_DoNothing); topic3.Answer = ""; SfHaddingrDialog = new DialogEntry(); defConvers = SfHaddingrDialog.AddConversation(BaseLocale.GetStr(RS.rs_Sacrifice)); rootTopic = defConvers.AddTopic(); rootTopic.Answer = BaseLocale.GetStr(RS.rs_Haddingr_IsPinned) + " " + BaseLocale.GetStr(RS.rs_VictimPleads); topic1 = rootTopic.AddTopic(); topic1.Phrase = BaseLocale.GetStr(RS.rs_Haddingr_TwistSpear); topic1.Answer = BaseLocale.GetStr(RS.rs_SacrificeAward); topic1.Action = "NPC.sacrificeVictim();"; topic2 = rootTopic.AddTopic(); topic2.Phrase = BaseLocale.GetStr(RS.rs_SetHimFree); topic2.Answer = BaseLocale.GetStr(RS.rs_VictimFree); topic2.Action = "NPC.freeVictim();"; topic3 = rootTopic.AddTopic(); topic3.Phrase = BaseLocale.GetStr(RS.rs_DoNothing); topic3.Answer = ""; SfKetillDialog = new DialogEntry(); defConvers = SfKetillDialog.AddConversation(BaseLocale.GetStr(RS.rs_Sacrifice)); rootTopic = defConvers.AddTopic(); rootTopic.Answer = BaseLocale.GetStr(RS.rs_Ketill_IsDangling) + " " + BaseLocale.GetStr(RS.rs_VictimPleads); topic1 = rootTopic.AddTopic(); topic1.Phrase = BaseLocale.GetStr(RS.rs_Ketill_DrownHim); topic1.Answer = BaseLocale.GetStr(RS.rs_SacrificeAward); topic1.Action = "NPC.sacrificeVictim();"; topic2 = rootTopic.AddTopic(); topic2.Phrase = BaseLocale.GetStr(RS.rs_SetHimFree); topic2.Answer = BaseLocale.GetStr(RS.rs_VictimFree); topic2.Action = "NPC.freeVictim();"; topic3 = rootTopic.AddTopic(); topic3.Phrase = BaseLocale.GetStr(RS.rs_DoNothing); topic3.Answer = ""; }
public void RefreshDialogue(string newNodeID, bool showResponse) { //if loading a new node, first create a dialogue entry for it and push into //the stack. if(newNodeID != "") { //create dialogue entry DialogueNode node = GameManager.Inst.DBManager.DBHandlerDialogue.GetDialogueNode(newNodeID); if(showResponse) { DialogueResponse response = EvaluateResponse(node.Responses); if(response != null) { DialogueEntry entry = CreateDialogueEntry("Jonathan Perpy", ParseDialogueText(response.Text), false); _entries.Push(entry); } } //create dialogue options relevant to this node foreach(Topic option in node.Options) { if(EvaluateTopicConditions(option.Conditions)) { DialogueOptionEntry optionEntry = new DialogueOptionEntry(); GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject; optionEntry.Text = o.GetComponent<UILabel>(); optionEntry.Text.text = option.Title; TopicReference reference = o.GetComponent<TopicReference>(); reference.Topic = option; UIButton button = o.GetComponent<UIButton>(); button.onClick.Add(new EventDelegate(this, "OnSelectTopic")); _options.Add(optionEntry); } } } //create topics entry List<Topic> topics = GameManager.Inst.DBManager.DBHandlerDialogue.GetNPCTopics(null, null); foreach(Topic topic in topics) { //if we are not at root node then don't show info topics if(topic.Type == TopicType.Info && _currentNodeID != _rootNode) { continue; } TopicEntry entry = new TopicEntry(); GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject; entry.Text = o.GetComponent<UILabel>(); entry.Text.text = topic.Title; TopicReference reference = o.GetComponent<TopicReference>(); reference.Topic = topic; UIButton button = o.GetComponent<UIButton>(); button.onClick.Add(new EventDelegate(this, "OnSelectTopic")); _topics.Add(entry); } //now make a copy of the stack, and start popping entries out of it, and arrange them under the dialog panel Stack<DialogueEntry> copy = new Stack<DialogueEntry>(_entries.Reverse()); float currentY = -260; while(copy.Count > 0) { DialogueEntry entry = copy.Pop(); entry.SpeakerName.transform.parent = DialogueScroll.transform; entry.SpeakerName.MakePixelPerfect(); entry.Text.transform.parent = DialogueScroll.transform; entry.Text.MakePixelPerfect(); float height = Mathf.Max(entry.SpeakerName.height * 1f, entry.Text.height * 1f); entry.SpeakerName.transform.localPosition = new Vector3(-150, currentY + height, 0); entry.Text.transform.localPosition = new Vector3(22, currentY + height, 0); currentY = currentY + height + 15; } //now re-add collider to fix collider size NGUITools.AddWidgetCollider(DialogueScroll.gameObject); if(_intro != null) { _intro.transform.parent = DialogueScroll.transform; _intro.MakePixelPerfect(); _intro.transform.localPosition = new Vector3(-150, currentY + _intro.height, 0); } //arrange topic entries currentY = 85; foreach(TopicEntry entry in _topics) { entry.Text.transform.parent = TopicScroll.transform; entry.Text.MakePixelPerfect(); entry.Text.transform.localPosition = new Vector3(-122, currentY, 0); currentY = currentY - entry.Text.height; if(entry.Text.text == "Goodbye") { currentY = currentY - 4; TopicDivider.transform.localPosition = new Vector3(8, currentY, 0); currentY = currentY - 8; } } float currentX = -128; foreach(DialogueOptionEntry entry in _options) { entry.Text.transform.parent = DialogueOptionScroll.transform; entry.Text.MakePixelPerfect(); entry.Text.width = entry.Text.text.Length * 15; entry.Text.transform.localPosition = new Vector3(currentX, 78, 0); currentX = currentX + entry.Text.width; } //now re-add collider to fix collider size NGUITools.AddWidgetCollider(TopicScroll.gameObject); }