PasteAll.org
http://pasteall.org/1149/csharp 16 Jun 2008 11:52
Loading
		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;
}
}
}
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework.Graphics;
  4. using Microsoft.Xna.Framework.Content;
  5. using Microsoft.Xna.Framework;
  6.  
  7. namespace Animated_Sprite_Test_1
  8. {
  9.         /// <summary>
  10.         /// A fairly simple base class for dialog handling
  11.         /// </summary>
  12.         public class Dialog
  13.         {
  14.         //a list of all the lines in the script
  15.                 public string[] script = new string[] { };
  16.  
  17.         public string[] paragraphs = new string[] { };
  18.  
  19.         //public string[,] lines = new string[,] { };
  20.  
  21.                 //the index of the currently selected line
  22.                 public List<string> lines = new List<string>();
  23.         public int currentLine = 0;
  24.  
  25.         public bool Showing = false;
  26.  
  27.         ContentManager content;
  28.         Texture2D dBox;
  29.         Texture2D MoreArrow;
  30.  
  31.         public int XOffset = 0;
  32.         public int YOffset = 0;
  33.  
  34.         public void Show()
  35.         {
  36.             Showing = true;
  37.         }
  38.  
  39.         public void Hide()
  40.         {
  41.             Showing = false;
  42.         }
  43.  
  44.         public Dialog(string Script, Game game)
  45.         {
  46.             content =  game.Services.GetService(typeof(ContentManager)) as ContentManager;
  47.             //script = Script;
  48.             lines = NormalizeScript(Script);
  49.             dBox = content.Load<Texture2D>("Dialog Box");
  50.             MoreArrow = content.Load<Texture2D>("More Arrow");
  51.         }
  52.  
  53.         public void NewScript(string Script)
  54.         {
  55.             lines = NormalizeScript(Script);
  56.         }
  57.        
  58.         public bool NextLine()
  59.         {
  60.             if (lines.Count > currentLine + 2)
  61.             {
  62.                 currentLine += 1;
  63.                 return true;
  64.             }
  65.             else
  66.             {
  67.                 return false;
  68.             }
  69.         }
  70.  
  71.         public void SetLine(int Line)
  72.         {
  73.             if (lines.Count > Line)
  74.                 currentLine = Line;
  75.         }
  76.  
  77.                 /// <summary>
  78.                 /// Draws the menu to the screen
  79.                 /// </summary>
  80.                 /// <param name="spriteBatch">The SpriteBatch to use for rendering</param>
  81.                 /// <param name="font">The font in which the text will be drawn</param>
  82.         public void Draw(SpriteBatch spriteBatch, SpriteFont font)
  83.                 {
  84.                         spriteBatch.Draw(dBox, new Vector2(0, 263), Color.White);
  85.             /*if (lines.Count > 0)
  86.                 spriteBatch.DrawString(font, lines[0], new Vector2(8, 270), Color.Black);
  87.             if (lines.Count > 1)
  88.                 spriteBatch.DrawString(font, lines[1], new Vector2(8, 290), Color.Black);*/
  89.             if (currentLine + 1 < lines.Count - 1)
  90.                 spriteBatch.Draw(MoreArrow, new Vector2(229, 306), Color.Black);
  91.             if (lines.Count > currentLine)
  92.                 spriteBatch.DrawString(font, lines[currentLine], new Vector2(8, 270), Color.Black);
  93.             if (lines.Count > currentLine + 1)
  94.                 spriteBatch.DrawString(font, lines[currentLine + 1], new Vector2(8, 290), Color.Black);
  95.         }
  96.  
  97.         public List<string> NormalizeScript(string Script)
  98.         {
  99.             string[] Lines = new string[] { };
  100.             List<string> lines = new List<string>();
  101.             Script = Script.Replace("$ash$", "IAN");
  102.             Script = Script.Replace("$gary$", "GARY");
  103.             Lines = Script.Split('\n');
  104.             foreach (string line in Lines)
  105.             {
  106.                 int i = 0;
  107.                 string tempLine = line;
  108.                 while (tempLine.Length > 22)
  109.                 {
  110. /*                    int spacerPos = tempLine.IndexOf('|');
  111.                     if (spacerPos < 1 || spacerPos > 23)*/
  112.                     int spacerPos = tempLine.LastIndexOfAny(new char[] { ' ', '-' }, tempLine.Length > 22 ? 23 : tempLine.Length - 1, tempLine.Length >= 22 ? 22: tempLine.Length);
  113.                     lines.Add(tempLine.Length > 0 ? tempLine.Substring(0, spacerPos) : "");
  114.                     i++;
  115.                     if (tempLine.Length > 0)
  116.                         tempLine = tempLine.Remove(0, spacerPos);
  117.                     tempLine = tempLine.Trim();
  118.                 }
  119.                 if (tempLine.Length > 0)
  120.                     lines.Add(tempLine);
  121.             }
  122.             return lines;
  123.         }
  124.         }
  125. }
  126.  
go to heaven
PasteAll.org is brought to you by the monkeys of GraphicAll.org - About