// Parses a Text Event int parseTextEvent(int start_pos, string text, DialogueItem d_item, StringBuilder parsed) { int end_pos = text.IndexOf(']', start_pos); int eq_pos = text.IndexOf('=', start_pos); string evt; string[] opt; if (eq_pos == -1 || eq_pos > end_pos) // if no '=' { evt = text.Substring(start_pos + 1, end_pos - start_pos - 1); opt = new string[0]; } else { evt = text.Substring(start_pos + 1, eq_pos - start_pos - 1); opt = text.Substring(eq_pos + 1, end_pos - eq_pos - 1).Split(opt_delim); } if (d_item.text_events [parsed.Length] == null) { d_item.text_events [parsed.Length] = new List <TextEvent> (); } d_item.text_events [parsed.Length].Add(new TextEvent(evt, opt)); //Debug.Log (" text_event:" + evt + ":" + opt.Aggregate("", (acc, next) => acc + "," + next)); return(end_pos); }
void Awake() { displayedDialogue = new DialogueItem(); sentences = new Queue <DialogueItem>(); characterController = FindObjectOfType <PlayerController>(); codeChecker = FindObjectOfType <CodeChecker>(); }
private void HandleCurrentContextChanged(object sender, EventArgs e) { Dialogue currentDialogue = FindCurrentDialogue(); // Reset repetitions count for dialogues, unless actively prevented: if (currentDialogue != null) { currentDialogue.ResetRepetitionCount(); if (workingMemory.CurrentID == "") // If no ID has been set, then just start from the beginning. { workingMemory.CurrentID = currentDialogue.DialogueItemList[0].ID; } else { DialogueItem currentDialogueItem = FindCurrentDialogueItem(); PropertyInfo timeoutProperty = currentDialogueItem.GetType().GetProperty(AgentConstants.TIMEOUT_INTERVAL_PROPERTY_NAME); if (timeoutProperty != null) { dialogueItemTimer.Stop(); // Just in case it was running previously. double timeoutInterval = (double)timeoutProperty.GetValue(currentDialogueItem); dialogueItemTimer.Run(timeoutInterval); } } } }
private void LoadNextDialogue() { m_current_dialogue = m_dialogues.Dequeue(); m_name_text.text = m_current_dialogue.GetTalkerName(); m_dialogue_image.overrideSprite = m_current_dialogue.GetTalkerImage(); m_dialogue_text.text = m_current_dialogue.NextTextSegment(); }
// Show input options when text is done scrolling IEnumerator showInput(DialogueItem d_item, DialogueBox d_box, Coroutine d_box_init) { yield return(d_box_init); // Wait for d_box to finish setting up yield return(new WaitUntil(() => d_box.cr_scroll == null)); // Wait for scroll to end input_field.gameObject.SetActive(true); input_field.ActivateInputField(); //spacebar_icon_vn.SetActive(true); curr_spacebar_animator.Play("anim_key_spacebar_no"); if (d_item.input_display != null) { input_display = Instantiate(d_item.input_display, transform); } if (d_item.input_options.Length > 0) { switch (d_item.input_options.Length) { case 2: input_display_C.SetActive(false); break; case 3: input_display_C.SetActive(true); break; } populateChoices(); input_display_choices.SetActive(true); } }
void CreateControl(DialogueItem item = null) { DialogueItem dialogueItem = item; if (item == null) { dialogueItem = ScriptableObject.CreateInstance <DialogueItem> (); dialogueItem.id = dialogueCount++; } DialogueItemWindow newWindow = new DialogueItemWindow(dialogueItem, this); //Default Dialogue Window Rect Size Reference for Zooming newWindow.orgRect = new Rect( newWindow.rect.x, newWindow.rect.y, newWindow.rect.width, newWindow.rect.height ); // //Adapt to zoomed size if adding a window after zooming newWindow.rect = new Rect( newWindow.rect.x, newWindow.rect.y, newWindow.rect.width * _zoomLevel, newWindow.rect.height * _zoomLevel ); // controls.Add(newWindow); }
private void MouseOver(GameObject gameObject) { switch (gameObject.tag) { case "Interactable": gameObject.SendMessage("Over"); if (Input.GetMouseButtonUp(0)) { InventoryItem item = gameObject.GetComponent <InventoryItem>(); if (item != null) { inventory.AddItem(item); } } break; case "NPC": gameObject.SendMessage("Over"); if (Input.GetMouseButtonUp(0)) { DialogueItem item = gameObject.GetComponent <DialogueItem>(); if (item != null) { dialogue.StartDialogue(item); } } break; } }
private bool IsReadyForCompletion(DialogueItem dialogueItem) { return(dialogueItem .GetValidLines() .Select(x => x.GetAssociatedQuestModel()) .Where(x => x != null && Quest.IsQuestEventReadyForCompletion(x)) .Count() > 0); }
public void Display(DialogueItem item) { if (item != null) { name.text = item.name; sentences.text = item.sentences; } }
DialogueItem item; // Current item in the slot // Add item to the slot public void AddItem(DialogueItem newItem) { item = newItem; info.text = item.infoGained; info.enabled = true; //removeButton.interactable = true; }
// Clear the slot public void ClearSlot() { item = null; info.text = ""; info.enabled = false; //removeButton.interactable = false; }
public void Enqueue(DialogueItem i) { queue.Enqueue(i); if (queue.Count == 1) { Present(); } }
private void InitText() { displayedDialogue = sentences.Dequeue(); displayedDialogue.SelectedIndex = 0; StopCoroutine("DisplaySentence"); dialogueText.text = ""; StartCoroutine("DisplaySentence"); DisplayOptions(); }
public void StartDialogue(DialogueItem dialogue) { dialogue.OnStartDialogue(); if (DialogueStarted != null) { DialogueStarted(this, new DialogueItemEventArgs(dialogue)); } }
// Remove an item public void Remove(DialogueItem item) { info.Remove(item); if (onItemChangedCallback != null) { onItemChangedCallback.Invoke(); } }
public void CreateReward(List <Item> reward) { DialogueItem i = Instantiate <DialogueItem>(itemPrefab, content.transform); i.SetText(""); dialogues.Add(i); item.AddItems(ItemLibrary.GenerateAmounts(reward, 500)); //placeholder value item.SetText("Yours for the taking..."); }
public DialogueItemWindow(DialogueItem dialogueItem, DialogueEditor parent) { _dialogue = dialogueItem; _parent = parent; //Set default rect if its unitialized if (_dialogue.rect == Rect.zero) { _dialogue.rect = new Rect(10, 10, 200, 150); } }
// Fill the choice display boxes with current options text public void populateChoices() { Text[] choiceText = input_display_choices.GetComponentsInChildren <Text>(); DialogueItem d_item = curr_dialogue.GetComponents <DialogueItem> () [curr_line]; int j = 0; for (int i = 1; (i < choiceText.Length) && (j < d_item.input_options.Length); i = i + 2) { choiceText [i].text = d_item.input_options[j]; ++j; } }
// Methods used for Dialog private void DialogueStarted(object sender, DialogueItemEventArgs e) { _currentDialogue = e.Dialogue; _sentences.Clear(); foreach (DialogueSentence sentance in _currentDialogue.Sentences) { _sentences.Enqueue(sentance); } _dialogPanel.SetActive(true); DisplayNextSentence(); }
private void EndDialogue() { speaking = false; displayedDialogue = new DialogueItem(); dialoguePanel.SetActive(false); GameObject teleporter = GameObject.Find("Teleporter"); if (teleporter != null) { GameObject door = GameObject.Find("Door"); door.SetActive(false); } }
private void Present() { dialogueBox.SetActive(true); DialogueItem d = queue.Peek(); textField.text = d.text; buttonField.text = d.buttonText; advanceButton.gameObject.SetActive(buttonField.text != ""); if (d.time > 0) { StartCoroutine(AdvanceAfter(d.time)); } }
// Parses an effect's ending tag, and matches with top of effect stack void parseEffectEnd(int start_pos, string text, DialogueItem d_item, StringBuilder parsed) { int end_pos = text.IndexOf('\\', start_pos) - 1; string fx_name = text.Substring(start_pos, end_pos - start_pos + 1); FXTextEffect top = effect_stack.Pop(); if (text_effect_map [fx_name].GetType() != top.GetType()) { Debug.LogException(new System.Exception("Mismatched FXTextEffect tags:" + fx_name)); } top.chars [1] = parsed.Length; d_item.fx_text_effects.Add(top); }
/// <summary> /// Retrieves all Diagloue items from dialogue txt files /// </summary> public static void LoadDialogueItems() { DialogueItems = new Dictionary <string, DialogueItem>(); //Get each text file in the primary objectives folder TextAsset[] DialogueList = Resources.LoadAll <TextAsset>("Text/Dialogue"); //Loop through each file in folder foreach (TextAsset txt in DialogueList) { DialogueItem newDialogue = LoadDialogueFromText(txt); DialogueItems.Add(txt.name, newDialogue); } }
// Add a new item if enough room public void Add(DialogueItem item) { if (info.Contains(item)) { return; } info.Add(item); if (onItemChangedCallback != null) { onItemChangedCallback.Invoke(); } }
private DialogueItem FindCurrentDialogueItem() { Dialogue currentDialogue = FindCurrentDialogue(); if (currentDialogue != null) { DialogueItem currentDialogueItem = currentDialogue.DialogueItemList.Find(d => d.ID == workingMemory.CurrentID); return(currentDialogueItem); } else { return(null); } }
public DialogueProperties(DialogueItem di) { InitializeComponent(); current = di; portraitSource.Text = current.portrait; AttemptSetPortrait(portraitSource.Text); dialogue.Text = current.text; entryPoint.Checked = current.entry; loadOptions(); }
// Parses dialogue item, returning updated text and modifying fields public string parse(DialogueItem d_item, DialogueBox d_box) { //Debug.Log ("parse:" + d_item.text); StringBuilder parsed = new StringBuilder(); // Processes string string text = substituteMacros(d_item.text); d_item.fx_text_effects = new List <FXTextEffect> (); d_item.text_events = new List <TextEvent> [text.Length]; bool tag = false; // Are we parsing a tag? int i = 0; for (; i < text.Length; ++i) { char c = text [i]; if (c == '|') // FXTextEffect start tag { tag = !tag; if (tag) { parseEffectStart(i + 1, text, parsed, d_box); } } else if (c == '\\') // FXTextEffect end tag { tag = !tag; if (tag) { parseEffectEnd(i + 1, text, d_item, parsed); } } else if (c == '[' || c == ']') // Text Event { i = parseTextEvent(i, text, d_item, parsed); } else if (!tag) { if (c == '’') { parsed.Append("'"); } else { parsed.Append(c); } } } return(parsed.ToString()); }
void OnGUI() { GUIStyle a = skin.button; if (answerNode.questions.Length != 0) { for (int i = 0; i < answerNode.questions.Length; i++) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 4, 600 + i * 50, Screen.width / 2, 50), answerNode.questions[i].text, a)) { answerNode = answerNode.questions[i].question; UpdateUi(); } } } }
void OnGUI() { GUIStyle a = skin.button; if (answerNode.questions.Length != 0) { for (int i = 0; i < answerNode.questions.Length; i++) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - Screen.height / 5 + i * 45, Screen.width / 5, 45), answerNode.questions[i].text, a)) { answerNode = answerNode.questions[i].question; UpdateUi(); } } } }
public DialogueEventProperties(DialogueItem di) { InitializeComponent(); current = di; switch (di.eventType) { case "GiveItem": giveItemPanel.Visible = true; LoadItemOptions(); break; case "LoadMap": loadMapPanel.Visible = true; LoadMapOptions(); break; case "AffectPlayer": affectPlayerPanel.Visible = true; LoadAffectPlayerOptions(); break; case "SpawnNPC": spawnNPCPanel.Visible = true; LoadSpawnNPCOptions(); break; case "ShowQuest": showQuestPanel.Visible = true; loadShowQuestOptions(); break; } repeatable.Checked = current.repeatable; nextIndex.Value = current.options[0].next; nextIndex1.Value = current.options[1].next; }