using System; using System.Collections.Generic; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework;
namespace Animated_Sprite_Test_1 { /// <summary> /// A fairly simple base class for dialog handling /// </summary> public class Dialog { //a list of all the lines in the script public string[] script = new string[] { };
public string[] paragraphs = new string[] { };
//public string[,] lines = new string[,] { };
//the index of the currently selected line public List<string> lines = new List<string>(); public int currentLine = 0;
public bool Showing = false;
ContentManager content; Texture2D dBox; Texture2D MoreArrow;
public int XOffset = 0; public int YOffset = 0;
public void Show() { Showing = true; }
public void Hide() { Showing = false; }
public Dialog(string Script, Game game) { content = game.Services.GetService(typeof(ContentManager)) as ContentManager; //script = Script; lines = NormalizeScript(Script); dBox = content.Load<Texture2D>("Dialog Box"); MoreArrow = content.Load<Texture2D>("More Arrow"); }
public void NewScript(string Script) { lines = NormalizeScript(Script); } public bool NextLine() { if (lines.Count > currentLine + 2) { currentLine += 1; return true; } else { return false; } }
public void SetLine(int Line) { if (lines.Count > Line) currentLine = Line; }
/// <summary> /// Draws the menu to the screen /// </summary> /// <param name="spriteBatch">The SpriteBatch to use for rendering</param> /// <param name="font">The font in which the text will be drawn</param> public void Draw(SpriteBatch spriteBatch, SpriteFont font) { spriteBatch.Draw(dBox, new Vector2(0, 263), Color.White); /*if (lines.Count > 0) spriteBatch.DrawString(font, lines[0], new Vector2(8, 270), Color.Black); if (lines.Count > 1) spriteBatch.DrawString(font, lines[1], new Vector2(8, 290), Color.Black);*/ if (currentLine + 1 < lines.Count - 1) spriteBatch.Draw(MoreArrow, new Vector2(229, 306), Color.Black); if (lines.Count > currentLine) spriteBatch.DrawString(font, lines[currentLine], new Vector2(8, 270), Color.Black); if (lines.Count > currentLine + 1) spriteBatch.DrawString(font, lines[currentLine + 1], new Vector2(8, 290), Color.Black); }
public List<string> NormalizeScript(string Script) { string[] Lines = new string[] { }; List<string> lines = new List<string>(); Script = Script.Replace("$ash$", "IAN"); Script = Script.Replace("$gary$", "GARY"); Lines = Script.Split('\n'); foreach (string line in Lines) { int i = 0; string tempLine = line; while (tempLine.Length > 22) { /* int spacerPos = tempLine.IndexOf('|'); if (spacerPos < 1 || spacerPos > 23)*/ int spacerPos = tempLine.LastIndexOfAny(new char[] { ' ', '-' }, tempLine.Length > 22 ? 23 : tempLine.Length - 1, tempLine.Length >= 22 ? 22: tempLine.Length); lines.Add(tempLine.Length > 0 ? tempLine.Substring(0, spacerPos) : ""); i++; if (tempLine.Length > 0) tempLine = tempLine.Remove(0, spacerPos); tempLine = tempLine.Trim(); } if (tempLine.Length > 0) lines.Add(tempLine); } return lines; } } }
using System; using System.Collections.Generic; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework; namespace Animated_Sprite_Test_1 { /// <summary> /// A fairly simple base class for dialog handling /// </summary> public class Dialog { //a list of all the lines in the script public string[] script = new string[] { }; public string[] paragraphs = new string[] { }; //public string[,] lines = new string[,] { }; //the index of the currently selected line public List<string> lines = new List<string>(); public int currentLine = 0; public bool Showing = false; ContentManager content; Texture2D dBox; Texture2D MoreArrow; public int XOffset = 0; public int YOffset = 0; public void Show() { Showing = true; } public void Hide() { Showing = false; } public Dialog(string Script, Game game) { content = game.Services.GetService(typeof(ContentManager)) as ContentManager; //script = Script; lines = NormalizeScript(Script); dBox = content.Load<Texture2D>("Dialog Box"); MoreArrow = content.Load<Texture2D>("More Arrow"); } public void NewScript(string Script) { lines = NormalizeScript(Script); } public bool NextLine() { if (lines.Count > currentLine + 2) { currentLine += 1; return true; } else { return false; } } public void SetLine(int Line) { if (lines.Count > Line) currentLine = Line; } /// <summary> /// Draws the menu to the screen /// </summary> /// <param name="spriteBatch">The SpriteBatch to use for rendering</param> /// <param name="font">The font in which the text will be drawn</param> public void Draw(SpriteBatch spriteBatch, SpriteFont font) { spriteBatch.Draw(dBox, new Vector2(0, 263), Color.White); /*if (lines.Count > 0) spriteBatch.DrawString(font, lines[0], new Vector2(8, 270), Color.Black); if (lines.Count > 1) spriteBatch.DrawString(font, lines[1], new Vector2(8, 290), Color.Black);*/ if (currentLine + 1 < lines.Count - 1) spriteBatch.Draw(MoreArrow, new Vector2(229, 306), Color.Black); if (lines.Count > currentLine) spriteBatch.DrawString(font, lines[currentLine], new Vector2(8, 270), Color.Black); if (lines.Count > currentLine + 1) spriteBatch.DrawString(font, lines[currentLine + 1], new Vector2(8, 290), Color.Black); } public List<string> NormalizeScript(string Script) { string[] Lines = new string[] { }; List<string> lines = new List<string>(); Script = Script.Replace("$ash$", "IAN"); Script = Script.Replace("$gary$", "GARY"); Lines = Script.Split('\n'); foreach (string line in Lines) { int i = 0; string tempLine = line; while (tempLine.Length > 22) { /* int spacerPos = tempLine.IndexOf('|'); if (spacerPos < 1 || spacerPos > 23)*/ int spacerPos = tempLine.LastIndexOfAny(new char[] { ' ', '-' }, tempLine.Length > 22 ? 23 : tempLine.Length - 1, tempLine.Length >= 22 ? 22: tempLine.Length); lines.Add(tempLine.Length > 0 ? tempLine.Substring(0, spacerPos) : ""); i++; if (tempLine.Length > 0) tempLine = tempLine.Remove(0, spacerPos); tempLine = tempLine.Trim(); } if (tempLine.Length > 0) lines.Add(tempLine); } return lines; } } }
|