// Resets the GUI and re-enables the relevant portions // Updates the dialogue text and name box private void DisplayMessage(Message message) { ResetGui(); string speakerKey = message.Who + message.Location.ToString(); Speaker speaker; if (!mSpeakers.ContainsKey(speakerKey)) { speaker = mSpeakers["None" + message.Location.ToString()]; } else { speaker = mSpeakers[speakerKey]; } speaker.Activate(message.State); SpeakerLocation location = message.Location; string messageText = Utility.WordWrappedString(message.Text, mTextBoxes[location], mTextWidth[location]); mTextBoxes[location].enabled = true; mTextBoxes[location].text = messageText; mNameBoxes[location].enabled = true; mNameBoxes[location].text = speaker.DisplayedName; }
private Dialogue GetMessagesFromFile(StreamReader file) { Dialogue dialogue = new Dialogue(); char[] delim = { ' ', ',' }; while (true) { string line = file.ReadLine(); string [] values = line.Split(delim, 6, StringSplitOptions.RemoveEmptyEntries); if (values[0].Contains("<<<")) // end trigger { break; } // read the message float duration = float.Parse(values[0]); SpeakerState state = EnumUtil.FromString <SpeakerState>(values[1]); string speaker = values[2]; SpeakerLocation location = EnumUtil.FromString <SpeakerLocation>(values[3]); // ignore the literal "---" string message = values[5]; dialogue.AddMessage(duration, state, speaker, location, message); } return(dialogue); }
// when, how, who, where, what // ex. for <5> seconds, <Nervous> <King> (<Left> side), says <"Hello world!">, // for <3.2> seconds, <Normal> <Peasant> (<Right> side), says <"....blargh."> public void AddMessage(float duration, SpeakerState state, string speaker, SpeakerLocation location, string text) { Message message = new Message (); message.Duration = duration; message.Who = speaker; message.Text = text; message.Location = location; message.State = state; mMessages.Enqueue (message); }
// when, how, who, where, what // ex. for <5> seconds, <Nervous> <King> (<Left> side), says <"Hello world!">, // for <3.2> seconds, <Normal> <Peasant> (<Right> side), says <"....blargh."> public void AddMessage(float duration, SpeakerState state, string speaker, SpeakerLocation location, string text) { Message message = new Message(); message.Duration = duration; message.Who = speaker; message.Text = text; message.Location = location; message.State = state; mMessages.Enqueue(message); }
/////////////////////////////////////////////////////////////////////////////////// // Unity Overrides /////////////////////////////////////////////////////////////////////////////////// void Awake() { mDialogueQueue = new Dictionary <DialogueType, Queue <Dialogue> >(); foreach (DialogueType d in EnumUtil.GetValues <DialogueType>()) { mDialogueQueue[d] = new Queue <Dialogue>(); } mTriggers = new Dictionary <DialogueType, Dictionary <string, Dialogue> >(); foreach (DialogueType d in EnumUtil.GetValues <DialogueType>()) { mTriggers[d] = new Dictionary <string, Dialogue>(); } mTextBoxes = new Dictionary <SpeakerLocation, GUIText>(); mNameBoxes = new Dictionary <SpeakerLocation, GUIText>(); mTextWidth = new Dictionary <SpeakerLocation, float>(); for (int i = 0; i < SpeakerLocations.Count; ++i) { SpeakerLocation location = SpeakerLocations[i]; mTextBoxes.Add(location, DialogueTextBoxes[i]); mTextWidth[location] = mTextBoxes[location].GetScreenRect().width; mTextBoxes[location].text = ""; mNameBoxes.Add(location, NameTextBoxes[i]); mNameBoxes[location].text = ""; } mSpeakers = new Dictionary <string, Speaker>(); for (int i = 0; i < Speakers.Count; ++i) { string speakerKey = Speakers[i].SpeakerName + Speakers[i].Location.ToString(); mSpeakers.Add(speakerKey, Speakers[i]); } string dialoguePath = "Data/IngameDialogue/dialogue_" + GameState.GameEra.ToString() + ".txt"; LoadDialogueFromFile(dialoguePath); this.TriggerDialogue("ArcherMage"); this.TriggerDialogue("Tutorial"); mIsIdle = true; mDialogueType = DialogueType.Standard; mRealtimeStamp = Time.realtimeSinceStartup; TriggerRealtimeDialogue("Pause"); //mDialogue = mDialogueQueue[DialogueType.Standard].Dequeue(); }
private Vector3 SetSpeakerPosition(SpeakerLocation speakerLocation) { Vector3 location = new Vector3(); if (speakerLocation == SpeakerLocation.LeftRight) { location = new Vector3(1, 0, 1); } if (speakerLocation == SpeakerLocation.Left) { location = new Vector3(-1, 0, 0); } if (speakerLocation == SpeakerLocation.Right) { location = new Vector3(1, 0, 0); } return(location); }
/// <summary> /// Playback the audio /// </summary> /// <param name="unencodedData">Raw byte data</param> /// <param name="recordingFormat">OpenAL sound format</param> /// <param name="sampleFrequency">Frequency of the samples</param> /// <param name="speakerLocation">Speaker location</param> public void PlayBackAudio(byte[] unencodedData, ALFormat recordingFormat, int sampleFrequency, SpeakerLocation speakerLocation) { //Determine if sources needed to be switched if (sourcesLeft == 0) { sourcesLeft = sources.Length; } //Used to rotate the sources being used. sourcesLeft--; int buf = AL.GenBuffer(); AL.BufferData(buf, recordingFormat, unencodedData, unencodedData.Length, sampleFrequency); position = SetSpeakerPosition(speakerLocation); AL.Source(sources[sourcesLeft], ALSource3f.Position, ref position); AL.SourceQueueBuffer(sources[sourcesLeft], buf); if (AL.GetSourceState(sources[sourcesLeft]) != ALSourceState.Playing) { ClearSourcePlayBackBuffers(sources[sourcesLeft]); AL.SourcePlay(sources[sourcesLeft]); } ClearSourcePlayBackBuffers(sources[sourcesLeft]); }