public void OnMouseUp(TinkerText tinkerText) { if (tinkerText.stanza != null && stanzas.Contains(tinkerText.stanza)) { tinkerText.stanza.OnMouseUp(tinkerText); } }
// Begins an auto play starting w/ a stanza private IEnumerator StartAutoPlay(Stanza startingStanza, TinkerText startingTinkerText) { // If we aren't starting from the beginning, read the audio progress from the startingTinkerText GetComponent <AudioSource>().time = startingTinkerText.GetStartTime(); Debug.Log("start time:" + startingTinkerText + startingTinkerText.GetStartTime()); // Start playing the full stanza audio GetComponent <AudioSource>().Play(); int startingStanzaIndex = stanzas.IndexOf(startingStanza); Debug.Log("time:" + startingTinkerText.GetStartTime() + "index:" + startingStanzaIndex); for (int i = startingStanzaIndex; i < stanzas.Count; i++) { if (i == startingStanzaIndex) { yield return(StartCoroutine(stanzas[i].AutoPlay(startingTinkerText))); } else { yield return(StartCoroutine(stanzas[i].AutoPlay())); } // Abort early? if (CancelAutoPlay()) { autoPlaying = false; GetComponent <AudioSource>().Stop(); yield break; } } autoPlaying = false; yield break; }
public void OnMouseDown(TinkerText tinkerText) { // Assign this new one mouseDownTinkerText = tinkerText; // And signal the tinkerText tinkerText.OnMouseDown(); }
// Sets up a trigger between TinkerTexts and SceneObjects. private void loadTrigger(Trigger trigger) { switch (trigger.type) { case TriggerType.CLICK_TINKERTEXT_SCENE_OBJECT: // It's possible this sceneObject was not added because we found that it // overlapped with a previous object. This is fine, just skip it. if (!this.sceneObjects.ContainsKey(trigger.args.sceneObjectId)) { return; } SceneObjectManipulator manip = this.sceneObjects[trigger.args.sceneObjectId] .GetComponent <SceneObjectManipulator>(); TinkerText tinkerText = this.tinkerTexts[trigger.args.textId] .GetComponent <TinkerText>(); Action action = manip.Highlight(Constants.SCENE_OBJECT_HIGHLIGHT_COLOR); tinkerText.AddClickHandler(action); manip.AddClickHandler(tinkerText.Highlight()); break; default: Logger.LogError("Unknown TriggerType: " + trigger.type); break; } }
public void OnDrag(TinkerText tinkerText) { // and reassign it to currently down int currentTextIndex = tinkerTexts.IndexOf(tinkerText); stanzaManager.RequestAutoPlay(this, tinkerTexts[currentTextIndex]); }
public void OnMouseDown(TinkerText tinkerText) { Debug.Log("stanzamanager" + tinkerText.name); if (tinkerText.stanza != null && stanzas.Contains(tinkerText.stanza)) { tinkerText.stanza.OnMouseDown(tinkerText); } }
public void OnMouseUp(TinkerText tinkerText) { if (tinkerText.stanza != null && stanzas.Contains(tinkerText.stanza)) { GetComponent <AudioSource>().Stop(); tinkerText.stanza.OnMouseUp(tinkerText); } }
public void OnDragBegin(TinkerText tinkerText) { drag = true; if (tinkerText.stanza != null && stanzas.Contains(tinkerText.stanza)) { tinkerText.stanza.OnDrag(tinkerText); } }
// Helper function to wrap together two actions: // (1) loading a page and (2) sending the StorybookPageInfo message over ROS. private void loadPageAndSendRosMessage(SceneDescription sceneDescription) { // Load the page. this.storyManager.LoadPage(sceneDescription); // Send the ROS message to update the controller about what page we're on now. StorybookPageInfo updatedInfo = new StorybookPageInfo(); updatedInfo.storyName = this.currentStory.GetName(); updatedInfo.pageNumber = this.currentPageNumber; updatedInfo.sentences = this.storyManager.stanzaManager.GetAllSentenceTexts(); // Update state (will get automatically sent to the controller. StorybookStateManager.SetStorySelected(this.currentStory.GetName(), this.currentStory.GetNumPages()); // Gather information about scene objects. StorybookSceneObject[] sceneObjects = new StorybookSceneObject[sceneDescription.sceneObjects.Length]; for (int i = 0; i < sceneDescription.sceneObjects.Length; i++) { SceneObject so = sceneDescription.sceneObjects[i]; StorybookSceneObject sso = new StorybookSceneObject(); sso.id = so.id; sso.label = so.label; sso.inText = so.inText; sceneObjects[i] = sso; } updatedInfo.sceneObjects = sceneObjects; // Gather information about tinker texts. StorybookTinkerText[] tinkerTexts = new StorybookTinkerText[this.storyManager.tinkerTexts.Count]; for (int i = 0; i < this.storyManager.tinkerTexts.Count; i++) { TinkerText tt = this.storyManager.tinkerTexts[i].GetComponent <TinkerText>(); StorybookTinkerText stt = new StorybookTinkerText(); stt.word = tt.word; stt.hasSceneObject = false; stt.sceneObjectId = -1; tinkerTexts[i] = stt; } foreach (Trigger trigger in sceneDescription.triggers) { if (trigger.type == TriggerType.CLICK_TINKERTEXT_SCENE_OBJECT) { tinkerTexts[trigger.args.textId].hasSceneObject = true; tinkerTexts[trigger.args.textId].sceneObjectId = trigger.args.sceneObjectId; } } updatedInfo.tinkerTexts = tinkerTexts; // Send the message. if (Constants.USE_ROS) { this.rosManager.SendStorybookPageInfoAction(updatedInfo); } }
public void OnMouseUp(TinkerText tinkerText) { // Assign this new one mouseDownTinkerText = tinkerText; // And signal the tinkerTextt if (!stanzaManager.IsDrag()) { tinkerText.OnMouseUp(); } }
// Method to request an auto play starting w/ a stanza public void RequestAutoPlay(Stanza startingStanza, TinkerText startingTinkerText = null) { Debug.Log("request" + autoPlaying); if (!autoPlaying) // && !sceneManager.disableAutoplay) { autoPlaying = true; cancelAutoPlay = false; // reset our cancel flag StartCoroutine(StartAutoPlay(startingStanza, startingTinkerText)); } }
private void setUpTinkerTextRosHandlers() { // If we're using ROS, attach a click handler to the tinkertext so that there's a message // sent over ROS whenever the user taps on a word. foreach (GameObject obj in this.tinkerTexts) { TinkerText tt = obj.GetComponent <TinkerText>(); tt.AddClickHandler(this.rosManager.SendTinkerTextTappedAction( tt.GetIndex(), tt.word, tt.phrase)); } }
// Sets up a timestamp trigger on the audio manager. private void loadAudioTriggers() { foreach (GameObject t in this.tinkerTexts) { TinkerText tinkerText = t.GetComponent <TinkerText>(); this.audioManager.AddTrigger(tinkerText.audioStartTime, tinkerText.OnStartAudioTrigger, tinkerText.isFirstInStanza); this.audioManager.AddTrigger( tinkerText.audioEndTime, tinkerText.OnEndAudioTrigger); } }
private void loadTinkerTextLabelPairTriggers() { foreach (KeyValuePair <int, List <int> > item in this.sceneObjectToTinkerText) { // Need to break these into actual phrases. (Don't want Clifford Clifford). List <List <int> > phrases = new List <List <int> >(); item.Value.Sort(); int prevIndex = -2; foreach (int index in item.Value) { if (index - prevIndex > 1) { // Start a new phrase. phrases.Add(new List <int>()); } // Add this index to latest phrase. phrases[phrases.Count - 1].Add(index); prevIndex = index; } // For each phrase, link the tinker texts. foreach (List <int> phraseIndexes in phrases) { string phrase = ""; foreach (int index in phraseIndexes) { TinkerText tt = this.tinkerTexts[index].GetComponent <TinkerText>(); phrase += tt.word + " "; } phrase = phrase.Substring(0, phrase.Length - 1); foreach (int index in phraseIndexes) { TinkerText tt = this.tinkerTexts[index].GetComponent <TinkerText>(); tt.SetSceneObjectId(item.Key); tt.SetPhraseIndexes(item.Value); tt.phrase = phrase; foreach (int j in item.Value) { TinkerText tt_j = this.tinkerTexts[j].GetComponent <TinkerText>(); if (j != index) { tt.AddClickHandler(tt_j.Highlight()); } } } } } }
// Sets up a timestamp trigger on the audio manager. private void loadAudioTriggers() { foreach (GameObject t in this.tinkerTexts) { TinkerText tinkerText = t.GetComponent <TinkerText>(); this.audioManager.AddTrigger(tinkerText.audioStartTime, tinkerText.OnStartAudioTrigger, tinkerText.isFirstInStanza); this.audioManager.AddTrigger( tinkerText.triggerAudioEndTime, tinkerText.OnEndAudioTrigger); if (tinkerText.word == "out.") { Logger.Log("out!!! " + tinkerText.audioEndTime + " " + tinkerText.triggerAudioEndTime); } } }
// Sets up a trigger between TinkerTexts and SceneObjects. private void loadTrigger(Trigger trigger) { switch (trigger.type) { case TriggerType.CLICK_TINKERTEXT_SCENE_OBJECT: SceneObjectManipulator manip = this.sceneObjects[trigger.args.sceneObjectId] .GetComponent <SceneObjectManipulator>(); TinkerText tinkerText = this.tinkerTexts[trigger.args.textId] .GetComponent <TinkerText>(); Action action = manip.Highlight(new Color(0, 1, 1, 60f / 255)); tinkerText.AddClickHandler(action); break; default: Logger.LogError("Unknown TriggerType: " + trigger.type.ToString()); break; } }
// Auto play the word audio in this stanza public IEnumerator AutoPlay(TinkerText startingTinkerText = null) { int startingTinkerTextIndex = 0; if (startingTinkerText != null) { startingTinkerTextIndex = tinkerTexts.IndexOf(startingTinkerText); } for (int i = startingTinkerTextIndex; i < tinkerTexts.Count; i++) { // delay according to timing data //animation not integrated //yield return new WaitForSeconds(tinkerTexts[i].GetAnimationDelay()); // If we aren't on last word, delay before playing next word if (i < tinkerTexts.Count - 1) { float pauseDelay = tinkerTexts[i + 1].GetStartTime() - tinkerTexts[i].GetEndTime(); yield return(new WaitForSeconds(pauseDelay)); } else // Delay before next stanza { yield return(new WaitForSeconds(endDelay)); } // Abort early? if (stanzaManager.CancelAutoPlay()) { yield break; } } // Stop the coroutine yield break; }
// Bulk of the work is here, add a new TinkerText to the stanzas, following the rules: // 1) Don't break phrases (unless the entire thing doesn't fit in one stanza). // 2) Fill up each stanza as much as possible. // and don't forget about these requirements: // 1) Must tell a TinkerText if it's the first in a stanza. // 2) Stanzas that start mid-phrase should not be swipeable. // 3) Stanzas that are swipeable must have accurate start and end times for audio. // // General Logic: // // If preferred <= remaining, easy case. // Add the text to the stanza via the move to stanza function. // If it's first in stanza and if it's isMidPhrase, set this stanza to be unswipeable, // and if not isMidPhrase, then set the start time of this stanza, tell it that it's // first in stanza and change lastStartStanza to this new one. // (or can just always set start time since it just won't be swipeable anyway). // Bookkeeping: add it to a phrase, check if there's punctuation to // update stanzaIsOnePhrase variable. // // If preferred > remaining, need to do stuff. // If stanzaIsOnePhrase, then just clear the buffer, reset remaining width, // create a new stanza, and add the tinkertext again recursively, setting isMidPhrase. // If not stanzaIsOnePhrase, then move the latest phrase to this new stanza, // update the remaining width, update the end time of lastStartStanza, set isMidphrase // to false and set stanzaIsOnePhrase to true because new stanzas always have it as true, // and try adding the tinkertexts in the buffer recursively. // Finally, add the new tinkertext to the newly created stanza. // public void AddTinkerText(GameObject tinkerTextObject) { TinkerText tinkerText = tinkerTextObject.GetComponent <TinkerText>(); float preferredWidth = LayoutUtility.GetPreferredWidth( tinkerText.text.GetComponent <RectTransform>()); // Set the correct width. tinkerText.SetWidth(preferredWidth); // Case where we don't need to make a new stanza. if (preferredWidth <= this.remainingStanzaWidth) { bool firstInStanza = System.Math.Abs( this.remainingStanzaWidth - this.maxStanzaWidth()) < Constants.EPSILON; if (firstInStanza) { if (this.isMidPhrase) { // Beginning a new stanza but continuing a previous phrase. this.currentStanza().GetComponent <Stanza>().SetSwipeable(false); } else { // Beginning a new stanza and a new phrase. this.lastPhraseStartStanza = this.currentStanza(); } tinkerText.SetFirstInStanza(); this.currentStanza().GetComponent <Stanza>().SetStartTimestamp( tinkerText.audioStartTime); } else { // Check if we've started a new phrase in this stanza. // Only check for this if it's not the first word in the stanza, // otherwise we can't actually know if stanza is one phrase or not. if (this.prevWordEndsPhrase) { this.isMidPhrase = false; // Possibly repetitive setting of this variable. this.stanzaIsOnePhrase = false; } } // Add tinkertext to the current stanza. this.moveTinkerTextToStanza(tinkerTextObject, this.currentStanza()); // Check for phrase endings. if (Util.WordShouldEndStanza(tinkerText.word)) { this.prevWordEndsPhrase = true; this.isMidPhrase = false; // Set the end timestamp of this stanza. It will be overwritten later if // a phrase is moved out of this stanza to the next one. this.lastPhraseStartStanza.GetComponent <Stanza>().SetEndTimestamp( tinkerText.audioEndTime); // Clear the buffer. this.tinkerTextPhraseBuffer.Clear(); } else { this.prevWordEndsPhrase = false; // Add tinkertext to current phrase. this.tinkerTextPhraseBuffer.Add(tinkerTextObject); } } else { // Create a new stanza. GameObject newStanza = Instantiate((GameObject)Resources.Load("Prefabs/StanzaPanel")); newStanza.transform.SetParent(this.textPanel.transform, false); newStanza.GetComponent <Stanza>().Init( this.audioManager, this.textPanel.GetComponent <RectTransform>().position ); // Save the new stanza. this.stanzas.Add(newStanza); // Reset remainingStanzaWidth. this.remainingStanzaWidth = this.maxStanzaWidth(); if (this.stanzaIsOnePhrase && !this.prevWordEndsPhrase) { // Overflow but everything is one phrase, so we can't do anything. // We just set isMidPhrase to true so we know the next stanza is // a continuation of this one. this.isMidPhrase = true; this.tinkerTextPhraseBuffer.Clear(); } else { // Set the end time of the previous stanza. if (this.lastPhraseStartStanza != null) { if (this.tinkerTextPhraseBuffer.Count > 0) { this.lastPhraseStartStanza.GetComponent <Stanza>().SetEndTimestamp( this.tinkerTextPhraseBuffer[0].GetComponent <TinkerText>().audioStartTime); } } // Add everything from the phrase buffer, recursively. this.isMidPhrase = false; this.stanzaIsOnePhrase = true; // Use a dummy buffer, otherwise will be modifying the real buffer // while also iterating over it, which will cause problems. List <GameObject> buffer = new List <GameObject>(); foreach (GameObject tt in this.tinkerTextPhraseBuffer) { buffer.Add(tt); } foreach (GameObject tt in buffer) { this.AddTinkerText(tt); } buffer.Clear(); } // Add the new TinkerText again. this.AddTinkerText(tinkerTextObject); } }
public void OnMouseDown(TinkerText tinkerText) { }