using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Agents
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private AxAgentObjects.AxAgent axAgent;
		private AgentObjects.IAgentCtlCharacterEx speaker;
//		private AgentObjects.IAgentCtlCharacterEx character;
		private System.Windows.Forms.ListBox listBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.button1 = new System.Windows.Forms.Button();
			this.axAgent = new AxAgentObjects.AxAgent();
			this.listBox1 = new System.Windows.Forms.ListBox();
			((System.ComponentModel.ISupportInitialize)(this.axAgent)).BeginInit();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(32, 24);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(56, 24);
			this.button1.TabIndex = 0;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// axAgent
			// 
			this.axAgent.Enabled = true;
			this.axAgent.Location = new System.Drawing.Point(0, 0);
			this.axAgent.Name = "axAgent";
			this.axAgent.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAgent.OcxState")));
			this.axAgent.Size = new System.Drawing.Size(32, 32);
			this.axAgent.TabIndex = 1;
			// 
			// listBox1
			// 
			this.listBox1.Location = new System.Drawing.Point(88, 80);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(168, 147);
			this.listBox1.TabIndex = 2;
			this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.axAgent);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.axAgent)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		public void Animate(string command)
		{
			try
			{
			//	axAgent.Characters.Load("Genie" , "genie.acs");
			//	speaker = axAgent.Characters["Genie"];
			//	speaker.Show(null);
				speaker.StopAll(null);
				speaker.MoveTo(800, 600, null);
				speaker.Play(command);
			
			}
			catch (Exception ex)
			{
				MessageBox.Show("Invalid" +ex.Message);
			}
		}
		private void button1_Click(object sender, System.EventArgs e)
		{
			string mychar = "merlin";
			try
			{
				axAgent.Characters.Load(mychar , mychar+".acs");
				speaker = axAgent.Characters[mychar];
				speaker.Show(null);
				speaker.MoveTo(800, 600, null);
				IEnumerator enumerator =
					speaker.AnimationNames.GetEnumerator();
					while (enumerator.MoveNext())
					this.listBox1.Items.Add(enumerator.Current.ToString());
				/*
				axAgent.Characters.Load("Merlin","merlin.acs");
				speaker = axAgent.Characters["merlin"];
				speaker.Show(null);
				speaker.MoveTo(600,800,null);
				axAgent.Characters.Load("Robby","robby.acs");
				speaker = axAgent.Characters["robby"];
				speaker.Show(null);
				speaker.MoveTo(500,500,null);
				axAgent.Characters.Load("Peedy","peedy.acs");
				speaker = axAgent.Characters["peedy"];
				speaker.Show(null);
				speaker.MoveTo(400,900,null);
				*/
			}
			catch (Exception ex)
			{
				MessageBox.Show("Invalid" +ex.Message);
			}
		}

		private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Animate(listBox1.Text);
		}
	}
}
