public DialogueWordsData(DialogueWords words, DialogueData parent) { model = words; this.parent = parent; if (model.Options.Count > 0 && parent) { int index = parent.model.Words.IndexOf(words); for (int i = 0; i < model.Options.Count; i++) { int indexBack = index; WordsOption option = model.Options[i]; if (words.NeedToChusCorrectOption) { if (model.IndexOfCorrectOption == i) { indexBack++; } } else { indexBack = option.IndexToGoBack > 0 && option.OptionType != WordsOptionType.SubmitAndGet && option.OptionType != WordsOptionType.OnlyGet && parent.model.StoryDialogue && (option.OptionType == WordsOptionType.BranchDialogue || option.OptionType == WordsOptionType.BranchWords) && !option.GoBack ? option.IndexToGoBack : indexBack; } WordsOptionData od = new WordsOptionData(option, this, indexBack); optionDatas.Add(od); } } }
public void GoBackDefault() { currentOption = null; wordsOptionInstances.Clear(); ClearOptions(); HideQuestDescription(); StartNormalDialogue(CurrentTalker); }
public void Recycle() { titleText.text = string.Empty; TalkObjective = null; SubmitObjective = null; MQuest = null; BranchDialogue = null; OptionType = OptionType.None; ObjectPool.Put(gameObject); }
public void Init(string text, WordsOption option) { titleText.text = text; if (option.OptionType == WordsOptionType.SubmitAndGet) { if (option.IsValid) { titleText.text += string.Format("(需[{0}]{1}个)", option.ItemToSubmit.ItemName, option.ItemToSubmit.Amount); } } OptionType = OptionType.Option; BranchDialogue = option; }
public override void CloseWindow() { base.CloseWindow(); if (IsUIOpen) { return; } CurrentType = DialogueType.Normal; CurrentTalker = null; CurrentQuest = null; currentDialog = null; currentOption = null; currentTalkObj = null; currentSubmitObj = null; wordsOptionInstances.Clear(); ClearOptions(); HideQuestDescription(); if (!BuildingManager.Instance.IsPreviewing) { WindowsManager.Instance.PauseAll(false); } if (WarehouseManager.Instance.IsPausing) { WarehouseManager.Instance.PauseDisplay(false); } if (WarehouseManager.Instance.IsUIOpen) { WarehouseManager.Instance.CloseWindow(); } if (ShopManager.Instance.IsPausing) { ShopManager.Instance.PauseDisplay(false); } if (ShopManager.Instance.IsUIOpen) { ShopManager.Instance.CloseWindow(); } IsTalking = false; UIManager.Instance.EnableJoyStick(true); PlayerManager.Instance.PlayerController.controlAble = true; }
public int IndexOfOption(WordsOption option) { return(Options.IndexOf(option)); }
public bool IsCorrectOption(WordsOption option) { return(NeedToChusCorrectOption && Options.Contains(option) && Options.IndexOf(option) == IndexOfCorrectOption); }
public WordsOptionData(WordsOption option, DialogueWordsData parent, int indexToGoBack) { model = option; this.parent = parent; this.indexToGoBack = indexToGoBack; }
/// <summary> /// 处理最后一句分支对话 /// </summary> private void HandlingLastOptionWords() { WordsOption topOptionInstance = wordsOptionInstances.Pop(); if (topOptionInstance.runtimeDialogParent) { DialogueWords topWordsParent = null; if (topOptionInstance.runtimeWordsParentIndex > -1 && topOptionInstance.runtimeWordsParentIndex < topOptionInstance.runtimeDialogParent.Words.Count) { topWordsParent = topOptionInstance.runtimeDialogParent.Words[topOptionInstance.runtimeWordsParentIndex];//找到包含当前分支的语句 } if (topWordsParent != null) { int indexOfWordsParent = topOptionInstance.runtimeDialogParent.IndexOfWords(topWordsParent); string dialogParentID = topOptionInstance.runtimeDialogParent.ID; if (topOptionInstance.OptionType == WordsOptionType.Choice && topWordsParent.NeedToChusCorrectOption) //该对话需要选择正确选项,且该选项是选择型选项 { if (topWordsParent.IsCorrectOption(currentOption)) //该选项是正确选项 //传入currentOption而不是topOptionInstance是因为前者是存于本地的原始数据,后者是实例化的数据 { foreach (WordsOption option in topWordsParent.Options.Where(x => x.OptionType == WordsOptionType.Choice)) //则其他选择型选项就跟着完成了 { CompleteOption(option, out var result); result.complete = true; var choiceOptions = topWordsParent.Options.Where(x => x.OptionType == WordsOptionType.Choice).ToList(); for (int i = 0; i < choiceOptions.Count; i++) { if (result.IsOptionCmplt(i) || !choiceOptions[i].DeleteWhenCmplt) { continue; } result.complete = false; break; } } StartDialogue(topOptionInstance.runtimeDialogParent, topOptionInstance.runtimeIndexToGoBack, false); } else if (topOptionInstance.DeleteWhenCmplt)//若该选项不是正确选项,但完成后需要删除 { CompleteOption(currentOption, out _); } } void CompleteOption(WordsOption option, out DialogueWordsData result) { dialogueDatas.TryGetValue(dialogParentID, out var dFound); if (dFound == null) { dFound = new DialogueData(option.runtimeDialogParent); dialogueDatas.Add(dialogParentID, dFound); } result = dFound.wordsDatas.Find(x => x.wordsIndex == indexOfWordsParent); if (result == null) { result = new DialogueWordsData(indexOfWordsParent); dFound.wordsDatas.Add(result); } int indexOfOption = topWordsParent.IndexOfOption(option); if (!result.cmpltOptionIndexes.Contains(indexOfOption)) { result.cmpltOptionIndexes.Add(indexOfOption); //该分支已完成 } //Debug.Log($"完成选项{indexOfOption}: " + option.Title); } if (dialogueDatas.TryGetValue(dialogParentID, out var dfind)) { if (dfind.wordsDatas.TrueForAll(x => x.complete)) { ExecuteEvents(topWordsParent); } } else if (!topWordsParent.NeedToChusCorrectOption)//找不到,且该句子不需要选择正确选项,可以直接完成 { ExecuteEvents(topWordsParent); } if (topWordsParent != null && topWordsParent.NeedToChusCorrectOption && !topWordsParent.IsCorrectOption(currentOption))//选择错误,则说选择错误时应该说的话 { StartOneWords(new DialogueWords(topWordsParent.TalkerInfo, topWordsParent.WordsWhenChusWB, topWordsParent.TalkerType), topOptionInstance.runtimeDialogParent, topOptionInstance.runtimeIndexToGoBack); } else if (topOptionInstance.GoBack)//处理普通的带返回的分支 { StartDialogue(topOptionInstance.runtimeDialogParent, topOptionInstance.runtimeIndexToGoBack, false); } } } currentOption = null; }
public void StartOptionDialogue(WordsOption option) { if (option == null || !option.IsValid) { return; } var optionInstance = option.Cloned; optionInstance.runtimeWordsParentIndex = currentDialog.IndexOfWords(currentWords); if (currentWords.NeedToChusCorrectOption) { optionInstance.runtimeDialogParent = currentDialog; if (currentWords.IndexOfCorrectOption == currentWords.IndexOfOption(option)) { optionInstance.runtimeIndexToGoBack = optionInstance.runtimeWordsParentIndex + 1; } else { optionInstance.runtimeIndexToGoBack = optionInstance.runtimeWordsParentIndex; } } else if (option.GoBack) { optionInstance.runtimeDialogParent = currentDialog; if (option.OptionType == WordsOptionType.SubmitAndGet || option.OptionType == WordsOptionType.OnlyGet || option.IndexToGoBack < 0) { optionInstance.runtimeIndexToGoBack = optionInstance.runtimeWordsParentIndex; } else { optionInstance.runtimeIndexToGoBack = option.IndexToGoBack; } } wordsOptionInstances.Push(optionInstance); currentOption = option; if (option.OptionType == WordsOptionType.SubmitAndGet && option.IsValid) { if (BackpackManager.Instance.TryLoseItem_Boolean(option.ItemToSubmit, option.ItemCanGet)) { BackpackManager.Instance.LoseItem(option.ItemToSubmit, option.ItemCanGet); } else { wordsOptionInstances.Pop(); currentOption = null; return; } } if (option.OptionType == WordsOptionType.OnlyGet && option.IsValid) { if (!BackpackManager.Instance.TryGetItem_Boolean(option.ItemCanGet)) { wordsOptionInstances.Pop(); currentOption = null; return; } else { BackpackManager.Instance.GetItem(option.ItemCanGet); } } if (option.OptionType == WordsOptionType.Choice && (!option.HasWordsToSay || option.HasWordsToSay && string.IsNullOrEmpty(option.Words))) { HandlingLastOptionWords(); SayNextWords(); return; } if (option.OptionType == WordsOptionType.BranchDialogue && option.Dialogue) { StartDialogue(optionInstance.Dialogue, optionInstance.SpecifyIndex); } else if (!string.IsNullOrEmpty(option.Words)) { TalkerInformation talkerInfo = null; if (optionInstance.TalkerType == TalkerType.NPC) { if (!currentDialog.UseUnifiedNPC && optionInstance.runtimeWordsParentIndex > -1 && optionInstance.runtimeWordsParentIndex < currentDialog.Words.Count) { talkerInfo = currentDialog.Words[optionInstance.runtimeWordsParentIndex].TalkerInfo; //Debug.Log(talkerInfo + "A"); } else if (currentDialog.UseUnifiedNPC && currentDialog.UseCurrentTalkerInfo) { talkerInfo = CurrentTalker.Info; //Debug.Log(talkerInfo + "B"); } else if (currentDialog.UseUnifiedNPC && !currentDialog.UseCurrentTalkerInfo) { talkerInfo = currentDialog.UnifiedNPC; //Debug.Log(talkerInfo + "C"); } } if (option.GoBack) { StartOneWords(new DialogueWords(talkerInfo, optionInstance.Words, optionInstance.TalkerType), currentDialog, optionInstance.runtimeIndexToGoBack); } else { StartOneWords(new DialogueWords(talkerInfo, optionInstance.Words, optionInstance.TalkerType)); } SayNextWords(); } }