private void EnqueueCharacterLine(StoryOutput s) { string outputString = s.Text; if (outputString.IsBlank()) { return; } int startOrderIndex = outputString.IndexOf('<'); int finishOrderIndex = outputString.IndexOf('>') - 1; if (startOrderIndex >= 0) { if (finishOrderIndex >= 0) { int ordersLength = finishOrderIndex - startOrderIndex; string orders = outputString.Substring(startOrderIndex + 1, ordersLength); string [] separateOrders = orders.Split(';'); foreach (string order in separateOrders) { dialogExecutioner.EnqueueOrder(order); } } else { Debug.LogError("ERROR in DialogManager: TwineAction tag does not close on line " + s.Index + " of " + currentStory.CurrentPassage.Name); } } else { string displayLineOrder = "DisplayLine/" + outputString; dialogExecutioner.EnqueueOrder(displayLineOrder); } }
QueuedAction GenerateQueueAction(StoryOutput output) { if (output is StoryText) { GameObject textElement = Instantiate(textTemplate); QueuedDisplayText action = new QueuedDisplayText(textElement, output); return(action); } else if (output is StoryLink) { GameObject newLinkElement = Instantiate(linkTemplate); LinkButton link = newLinkElement.GetComponent <LinkButton>(); link.Initialize(() => { link.Deactivate(true); this.DoLink((StoryLink)output); }, output.Text); return(new QueuedDisplayLink(newLinkElement, (StoryLink)output)); } return(new EmptyQueueAction()); }
void Story_OnOutput(StoryOutput output) { tempList.Add(output); //if (!this.AutoDisplay) // return; //DisplayOutput(output); }
private void Story_OnOutput(StoryOutput obj) { string tType = obj.GetType().ToString(); if (tType == "Cradle.StoryText" || tType == "Cradle.StoryLink" || tType == "Cradle.LineBreak") { if (tType == "Cradle.LineBreak") { currStoryText += "\n"; } else { currStoryText += obj.Text; } } //switch (tType) //{ // case "Cradle.StoryText": // currStoryText += obj.Text; // break; // case "Cradle.StoryLink": // currStoryLink.Add(obj.Text); // break; //} ScreenText.SetText(currStoryText); }
public QueuedDisplayText(GameObject _newTextElement, StoryOutput _output) { field = _newTextElement.GetComponent <Text>(); text = _output.Text; //field.text = text; _newTextElement.SetActive(false); lastSize = 0; }
private void EnqueueDialogLink(StoryOutput s) { StoryLink link = (StoryLink)s; string order = "DisplayNextLink"; dialogExecutioner.EnqueueOrder(order); dialogExecutioner.EnqueueLink(link); }
void Story_OnOutput(StoryOutput output) { if (!this.AutoDisplay) { return; } DisplayOutput(output); }
void Story_OnOutputRemoved(StoryOutput outputThatWasRemoved) { // Remove all elements related to this output foreach (var elem in Container.GetComponentsInChildren <TwineTextPlayerElement>() .Where(e => e.SourceOutput == outputThatWasRemoved)) { elem.transform.SetParent(null); GameObject.Destroy(elem.gameObject); } }
IEnumerator sea_Output(StoryOutput output) { if (output is StoryLink && output.Name == "continue") { yield return(StartCoroutine(ClickForAlarm(output as StoryLink))); } else if (output is StoryText && output.Text.Trim().Length > 0) { sea_sfxBubbles.PlayOneShot(sea_sfxBubbleSounds[Random.Range(0, sea_sfxBubbleSounds.Length)], sea_sfxBubbles.volume); } }
void alone_Output(StoryOutput output) { if (output is StoryLink && ((StoryLink)output).PassageName == "getUp") { CursorHoverActions( cursorAnimator => cursorAnimator.SetBool("hover", true), cursorAnimator => cursorAnimator.SetBool("hover", false), new StoryLink[] { (StoryLink)output } ); } }
private void StoryOnOutput(StoryOutput output) { if (output is StoryLink) { EnqueueDialogLink(output); } else { EnqueueCharacterLine(output); } }
void AddToUI(RectTransform rect, StoryOutput output, int index) { rect.SetParent(Container); if (index >= 0) { rect.SetSiblingIndex(index); } var elem = rect.gameObject.AddComponent <TwineTextPlayerElement>(); elem.SourceOutput = output; }
public override void DisplayOutput(StoryOutput output) { if (output is StoryText) { var text = (StoryText)output; // HACK: Don't knwo why the f**k this is needed but the links are being interpretted as story text so.... foreach (var commandStr in commandToNameMap.Values) { if (commandStr.Contains(text.Text)) { return; } } //Debug.Log("Printing text for story text:" + text.Text); if (!string.IsNullOrEmpty(text.Text)) { targetStoryText += text.Text.Replace('’', '\''); } } else if (output is StoryLink) { //var link = (StoryLink)output; //if (!ShowNamedLinks && link.IsNamed) // return; //Button uiLink = (Button)Instantiate(LinkTemplate); //uiLink.gameObject.SetActive(true); //uiLink.name = "[[" + link.Text + "]]"; //Text uiLinkText = uiLink.GetComponentInChildren<Text>(); //uiLinkText.text = link.Text; //uiLink.onClick.AddListener(() => //{ // this.Story.DoLink(link); //}); //AddToUI((RectTransform)uiLink.transform, output, uiInsertIndex); } else if (output is LineBreak) { targetStoryText += "\n\n"; } //else if (output is OutputGroup) //{ // // Add an empty indicator to later positioning // var groupMarker = new GameObject(); // groupMarker.name = output.ToString(); // AddToUI(groupMarker.AddComponent<RectTransform>(), output, uiInsertIndex); //} }
IEnumerator relationship_Output(StoryOutput output) { if (output is StoryText && output.Text.Trim().Length > 0) { if (!relationship_sfxCough.isPlaying) { relationship_sfxCough.clip = relationship_sfxCoughSounds[relationship_cough++ % relationship_sfxCoughSounds.Length]; relationship_sfxCough.Play(); } } else if (output is StoryLink && output.Name == "continue") { relationship_lastClick = true; yield return(StartCoroutine(ClickForAlarm(output as StoryLink))); } }
void OnOutput(StoryOutput output) { if (output is StoryText) { if (output.Text.Trim().Equals("")) { return; } _fullPassageText += output.Text; } else if (output is LineBreak) { _fullPassageText += "\n"; } else if (output is StoryLink link) { _storyLinks.Add(link); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); var story = target as Story; if (story == null || story.Output == null) { return; } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Story State", story.State.ToString()); EditorGUILayout.LabelField("Current Passage", story.CurrentPassage == null ? "(none)" : story.CurrentPassage.Name); EditorGUILayout.Separator(); int defaultIndent = EditorGUI.indentLevel; for (int i = 0; i < story.Output.Count; i++) { StoryOutput output = story.Output[i]; if (output is Embed) { continue; } int groupCount = 0; OutputGroup group = output.Group; while (group != null) { groupCount++; group = group.Group; } EditorGUI.indentLevel = defaultIndent + groupCount; EditorGUILayout.LabelField(output.ToString()); } EditorGUI.indentLevel = defaultIndent; }
public override void OnInspectorGUI() { StoryOutput output = ((TwineTextElement)target).SourceOutput; bool unused; EditorGUILayout.LabelField("Type", output.GetType().Name); EditorGUILayout.LabelField("Id", idGenerator.GetId(output, out unused).ToString()); EditorGUILayout.LabelField("Name", output.Name); EditorGUILayout.LabelField("Text", output.Text); EditorGUILayout.LabelField("Style"); EditorGUI.indentLevel++; Style style = output.GetAppliedStyle(); foreach (var pair in style) { EditorGUILayout.LabelField(pair.Key, pair.Value != null ? pair.Value.ToString() : null); } EditorGUI.indentLevel--; }
void her_Update() { if (her_done) { return; } float delta = (Input.mousePosition - her_lastMousePos).magnitude; float move = Mathf.Clamp(delta / Screen.height, 0f, 1f); Color color = uiImage.color; if (move < her_minScreenMove) { if (!ImageFade.IsInProgress(uiImage) && color.a > 0f) { ImageFade.Start(uiImage, 1f, 0f, move < her_minScreenMove ? her_minFadeoutTime : her_maxFadeoutTime); } } else if (!her_lineTriggered) { ImageFade.Stop(uiImage); color.a = Mathf.Clamp(color.a + move * her_alphaFactor, 0f, 1f); uiImage.color = color; if (!her_sfxMatchStrike.isPlaying) { her_sfxMatchStrike.clip = her_sfxMatchStrikeSounds[Random.Range(0, her_sfxMatchStrikeSounds.Length)]; her_sfxMatchStrike.Play(); } } // Show another line if (!her_lineTriggered && color.a >= her_alphaLineTriggerUp) { StoryOutput output = null; while (her_outputIndex < story.Output.Count && !(output is LineBreak)) { output = story.Output[her_outputIndex]; if (output is StoryText) { var line = (StoryText)output; uiTextPlayer.DisplayOutput(line); } else if (output is StoryLink && output.Name == "continue") { her_done = true; StartCoroutine(her_alarm(output as StoryLink)); break; } her_outputIndex++; } // Show the closing line break, if any if (output != null) { uiTextPlayer.DisplayOutput(output); } // Play the match light sound if (!her_done) { her_sfxMatchLight.Play(); her_cursorFlame.SetTrigger("light"); } her_lineTriggered = true; } else if (her_lineTriggered && color.a <= her_alphaLineTriggerDown) { her_lineTriggered = false; } her_lastMousePos = Input.mousePosition; }
public virtual void DisplayOutput(StoryOutput output) { // Deternine where to place this output in the hierarchy - right after the last UI element associated with the previous output, if exists TwineTextPlayerElement last = Container.GetComponentsInChildren <TwineTextPlayerElement>() .Where(elem => elem.SourceOutput.Index < output.Index) .OrderBy(elem => elem.SourceOutput.Index) .LastOrDefault(); int uiInsertIndex = last == null ? -1 : last.transform.GetSiblingIndex() + 1; // Temporary hack to allow other scripts to change the templates based on the output's Style property SendMessage("Twine_BeforeDisplayOutput", output, SendMessageOptions.DontRequireReceiver); if (output is StoryText) { var text = (StoryText)output; if (!string.IsNullOrEmpty(text.Text)) { foreach (Match m in rx_splitText.Matches(text.Text)) { string word = m.Value; Text uiWord = (Text)Instantiate(WordTemplate); uiWord.gameObject.SetActive(true); uiWord.text = word; uiWord.name = word; AddToUI(uiWord.rectTransform, output, uiInsertIndex); if (uiInsertIndex >= 0) { uiInsertIndex++; } } } } else if (output is StoryLink) { var link = (StoryLink)output; if (!ShowNamedLinks && link.IsNamed) { return; } Button uiLink = (Button)Instantiate(LinkTemplate); uiLink.gameObject.SetActive(true); uiLink.name = "[[" + link.Text + "]]"; Text uiLinkText = uiLink.GetComponentInChildren <Text>(); uiLinkText.text = link.Text; uiLink.onClick.AddListener(() => { this.Story.DoLink(link); }); AddToUI((RectTransform)uiLink.transform, output, uiInsertIndex); } else if (output is LineBreak) { var br = (RectTransform)Instantiate(LineBreakTemplate); br.gameObject.SetActive(true); br.gameObject.name = "(br)"; AddToUI(br, output, uiInsertIndex); } else if (output is OutputGroup) { // Add an empty indicator to later positioning var groupMarker = new GameObject(); groupMarker.name = output.ToString(); AddToUI(groupMarker.AddComponent <RectTransform>(), output, uiInsertIndex); } }
public void RefreshText() { StringBuilder builder = new StringBuilder(); Stack <StyleGroup> _styleGroups = new Stack <StyleGroup>(); int lineBreaks = 0; for (int i = 0; i < Story.Output.Count; i++) { StoryOutput output = Story.Output[i]; if (this.StyleSheet != null) { while (_styleGroups.Count > 0 && !output.BelongsToStyleGroup(_styleGroups.Peek())) { FormatStyle(_styleGroups.Pop().Style, StyleFormatType.Suffix, builder); } } if (output is StoryText) { if (this.StyleSheet != null) { builder.AppendFormat(Unescape(this.StyleSheet.Text), output.Text); } else { builder.Append(output.Text); } } else if (output is StoryLink) { var link = (StoryLink)output; if (this.ShowNamedLinks || !link.IsNamed) { builder.AppendFormat( this.StyleSheet != null ? Unescape(this.StyleSheet.Link) : TwineTMProStyleSheet.DefaultLink, TwineTMProLinkHandler.Escape(link.Name), link.Text); } } if (output is LineBreak) { if (!CollapseLineBreaks || lineBreaks < 2) { builder.Append(this.StyleSheet != null ? Unescape(this.StyleSheet.LineBreak) : TwineTMProStyleSheet.DefaultLineBreak); lineBreaks++; } } else { lineBreaks = 0; } if (this.StyleSheet != null && output is StyleGroup) { var styleGroup = (StyleGroup)output; FormatStyle(styleGroup.Style, StyleFormatType.Prefix, builder); _styleGroups.Push(styleGroup); } } TextUI.SetText(builder); }
protected EmbedFragment enchant(StoryVar reference, HarloweEnchantCommand command, Func <IStoryThread> fragment) { bool isHookRef = reference.Value is HarloweHookRef; string str = isHookRef ? ((HarloweHookRef)reference.Value).HookName : reference.ToString(); List <HarloweEnchantment> enchantments = new List <HarloweEnchantment>(); HarloweEnchantment lastHookEnchantment = null; for (int i = 0; i < this.Output.Count; i++) { StoryOutput output = this.Output[i]; if (isHookRef) { // Check if matching hook found in the current group, otherwise skip if (!(output is StyleGroup)) { continue; } var group = output as StyleGroup; if (group.Style.Get <string>(HarloweStyleSettings.Hook) != str) { continue; } // Matching hook was found, but enchantment metadata is not up to date if (lastHookEnchantment == null || lastHookEnchantment.HookGroup != group) { lastHookEnchantment = new HarloweEnchantment() { ReferenceType = HarloweEnchantReferenceType.Hook, Command = command, HookGroup = group, Affected = new List <StoryOutput>() }; enchantments.Add(lastHookEnchantment); } // Add all outputs associated with this group i++; while (i < this.Output.Count && this.Output[i].BelongsToStyleGroup(group)) { lastHookEnchantment.Affected.Add(this.Output[i]); i++; } } else if (output is StoryText) { var occurences = new Regex(Regex.Escape(str)); if (occurences.IsMatch(output.Text)) { enchantments.Add(new HarloweEnchantment { ReferenceType = HarloweEnchantReferenceType.Text, Command = command, Affected = new List <StoryOutput>() { output }, Text = str, Occurences = occurences }); } } } return(new EmbedFragment(() => EnchantExecute(enchantments, fragment))); }
void street_Update() { if (!street_FootstepsPaused && Clicked) { // Boost the street speed street_speed = Mathf.Clamp(street_speed + street_speedBoost, 1f, street_maxSpeed); street_lastClickSpeed = street_speed; street_lastClickTime = Time.time; } else { street_speed = Mathf.Lerp(street_lastClickSpeed, 0f, (Time.time - street_lastClickTime) / street_slowTime); } if (street_speed == 0f) { return; } if (Time.time - street_lastStepTime > 1f / street_speed) { street_lastStepTime = Time.time; AudioSource audio = street_lastIsLeft ? street_sfxFootstep1 : street_sfxFootstep2; AudioClip[] clips = street_lastIsLeft ? street_sfxFootstep1Sounds : street_sfxFootstep2Sounds; audio.clip = clips[Random.Range(0, clips.Length)]; audio.time = 0f; audio.Play(); // shake image uiImage.GetComponent <Animator>().SetTrigger("sidewalkShake"); // switch feet street_lastIsLeft = !street_lastIsLeft; } if (street_FootstepsPaused) { return; } if (street_speed >= street_walkTimeSpeed) { street_walkTime += Time.deltaTime; } else { street_walkTime = 0f; } if (street_walkTime >= street_walkTimeTarget) { street_walkTime = 0f; if (street_currentOutput >= story.Output.Count - 1) { street_lineShown = false; if (story.CurrentPassageName == "street3") { StartCoroutine(street_alarm()); } else { story.DoLink("continue"); } } else { while (true) { StoryOutput output = story.Output[street_currentOutput++]; uiTextPlayer.DisplayOutput(output); street_lineShown |= output is StoryText; if (output is StoryText && story.CurrentPassageName == "street3" && output.Text.ToLower().Contains("lips")) { street_arousalCounter++; if (street_arousalCoroutine == null) { street_arousalCoroutine = StartCoroutine(street3_Arousal()); } } if (street_lineShown && output is LineBreak) { break; } } StartCoroutine(street_PauseFootSteps()); } } }
public void Display(StoryOutput output) { QueuedAction action = GenerateQueueAction(output); queue.Enqueue(action); }