using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Graphics; using System.Xml; /// /// Scope of all ScreenObjects in the game, includes Dialogue, ImageDisplay, TextDisplay /// namespace DW.UI.ScreenObjects { /// /// Used to run dialogues in the game, inheirits from HUD /// public class Dialogue : HUD { private int displayLength = 0; List triggerList = new List(); string speaker, message; /// /// Holds the triggerConditions, used for the EventSystem (not included) /// public struct TriggerCondition { public string name; public object condition; public TriggerCondition(string n, object c) { name = n; condition = c; } } /// /// Constructor for Dialogue, takes an XML node and reads in the dialogues /// /// XMLNode "Triggers", see text.xml for example public Dialogue(XmlNode xmlNode ) { foreach (XmlNode node in xmlNode) { if (node.Name == "Triggers") { for (int x = 0; x < node.Attributes.Count; x++) { TriggerCondition tc = new TriggerCondition(node.Attributes[x].Name, node.Attributes[x].Value); triggerList.Add(tc); } } if (node.Name == "Speaker") { speaker = node.InnerText; } if (node.Name == "Message") { message = node.InnerText; } if (node.Name == "TimeLimit") { displayLength = int.Parse(node.InnerText); } } } /// /// Removes dialogue once time limit expires /// public void UpdateDialogue() { //Remove dialogue once the limit has passed if (imageDisplays[getHUDIndex("dialogueBox")].stopWatch.ElapsedMilliseconds >= displayLength) { RemoveDialog(); imageDisplays[getHUDIndex("dialogueBox")].stopWatch.Reset(); displayLength = 0; } } /// /// Inits the dialogue control system /// public void InitializeDialogControl() { try { imageDisplays[getHUDIndex("dialogueBox")].stopWatch.Reset(); } catch (Exception ex) { Console.WriteLine("HUD::InitializeDialogControl - No Timer Dialog Loaded"); } } /// /// Shows the dialogue /// /// Which image to post in the background /// Who is talking /// What the message is public void ShowDialog(Texture2D backgroundImage, string speaker, string message) { imageDisplays[getHUDIndex("dialogueBox")].visible = true; textDisplays[getHUDIndex("speakerText")].text = speaker; textDisplays[getHUDIndex("speakerText")].visible = true; textDisplays[getHUDIndex("dialogueText")].text = message; textDisplays[getHUDIndex("dialogueText")].visible = true; } /// /// Removes the dialogue from the HUD /// public void RemoveDialog() { imageDisplays[getHUDIndex("dialogueBox")].visible = false; textDisplays[getHUDIndex("dialogueBox")].text = "ERROR"; textDisplays[getHUDIndex("speakerText")].visible = false; textDisplays[getHUDIndex("speakerText")].color = Color.White; textDisplays[getHUDIndex("dialogueText")].text = "YOU SHOULDN'T EVER SEE THIS"; textDisplays[getHUDIndex("dialogueText")].visible = false; textDisplays[getHUDIndex("dialogueText")].color = Color.White; } /// /// Displays the dialogue on the HUD /// /// Which image to post in the background /// Who is talking /// What the message is /// Time limit to display message public void DisplayDialog(Texture2D backgroundImage, string speaker, string message, int limitMilli) { displayLength = limitMilli; if (!imageDisplays[getHUDIndex("dialogueBox")].stopWatch.IsRunning) { displayLength = limitMilli; imageDisplays[getHUDIndex("dialogueBox")].stopWatch.Start(); } else { displayLength = limitMilli; imageDisplays[getHUDIndex("dialogueBox")].stopWatch.Reset(); } ShowDialog(backgroundImage, speaker, message); } } }