/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\Engines\Spawner\SpawnerGump.cs
Lines of code: 151
***********************************************************/


using System;
using System.Collections;
using Server.Network;
using Server.Gumps;
using System.Collections.Generic;

namespace Server.Mobiles
{
	public class SpawnerGump : Gump
	{
		private Spawner m_Spawner;

		public SpawnerGump( Spawner spawner ) : base( 50, 50 )
		{
			m_Spawner = spawner;

			AddPage( 0 );

			AddBackground( 0, 0, 260, 418, 5054 );

			AddLabel( 95, 1, 0, "Creatures List" );

			const int starty=325;
			const int incy=22;

			//low x
			AddButton( 5, starty+(incy*0), 0xFB7, 0xFB9, 1, GumpButtonType.Reply, 0 );
			AddLabel( 38, starty+(incy*0), 0x384, "Okay" );

			AddButton( 5, starty+(incy*1), 0xFB1, 0xFB3, 0, GumpButtonType.Reply, 0 );
			AddLabel( 38, starty+(incy*1), 0x384, "Cancel" );
			
			AddButton( 5, starty+(incy*2), 0xFA5, 0xFB9, 4, GumpButtonType.Reply, 0 );
			AddLabel( 38, starty+(incy*2), 0x384, "Props" );			
			
			AddButton( 5, starty+(incy*3), 0xFA5, 0xFB9, 6, GumpButtonType.Reply, 0 );
			AddLabel( 38, starty+(incy*3), 0x384, "Goto" );	
			
			//high x
			AddButton( 110, starty+(incy*0), 0xFA8, 0xFAA, 3, GumpButtonType.Reply, 0 );
			AddLabel( 143, starty+(incy*0), 0x384, "Total Respawn" );			
			
			AddButton( 110, starty+(incy*1), 0xFA5, 0xFAA, 5, GumpButtonType.Reply, 0 );
			AddLabel( 143, starty+(incy*1), 0x384, "Bounds" );				

			AddButton( 110, starty+(incy*2), 0xFB4, 0xFB6, 2, GumpButtonType.Reply, 0 );
			AddLabel( 143, starty+(incy*2), 0x384, "Bring to Home" );

			AddButton( 110, starty+(incy*3), 0xFA5, 0xFAA, 7, GumpButtonType.Reply, 0 );
			AddLabel( 143, starty+(incy*3), 0x384, "Check Corners" );				
			
			
			const int startnextbuttons=8;

			for ( int i = 0;  i < 13; i++ )
			{
				AddButton( 5, ( 22 * i ) + 20, 0xFA5, 0xFA7, startnextbuttons + (i * 2), GumpButtonType.Reply, 0 );
				AddButton( 38, ( 22 * i ) + 20, 0xFA2, 0xFA4, startnextbuttons + 1 + (i * 2), GumpButtonType.Reply, 0 );

				AddImageTiled( 71, ( 22 * i ) + 20, 159, 23, 0xA40 );
				AddImageTiled( 72, ( 22 * i ) + 21, 157, 21, 0xBBC );

				string str = "";

				if ( i < spawner.CreaturesName.Count )
				{
					str = (string)spawner.CreaturesName[i];
					int count = m_Spawner.CountCreatures( str );

					AddLabel( 232, ( 22 * i ) + 20, 0, count.ToString() );
				}

				AddTextEntry( 75, ( 22 * i ) + 21, 154, 21, 0, i, str );
			}
		}

		public List<string> CreateArray( RelayInfo info, Mobile from )
		{
			List<string> creaturesName = new List<string>();

			for ( int i = 0;  i < 13; i++ )
			{
				TextRelay te = info.GetTextEntry( i );

				if ( te != null )
				{
					string str = te.Text;

					if ( str.Length > 0 )
					{
						str = str.Trim();

						Type type = SpawnerType.GetType( str );

						if ( type != null )
							creaturesName.Add( str );
						else
							from.SendMessage( "{0} is not a valid type name.", str );
					}
				}
			}

			return creaturesName;
		}
		
		public void ReOpen(Mobile from)
		{
		from.CloseGump(typeof(SpawnerGump));		
		from.SendGump(new SpawnerGump( m_Spawner ));		
		}
		
		public override void OnResponse( NetState state, RelayInfo info )
		{
			if ( m_Spawner.Deleted )
				return;

			switch ( info.ButtonID )
			{
				case 0: // Closed
				{
					break;
				}
				case 1: // Okay
				{
					m_Spawner.CreaturesName = CreateArray( info, state.Mobile );

					ReOpen(state.Mobile);
					break;
				}
				case 2: // Bring everything home
				{
					m_Spawner.BringToHome();

					ReOpen(state.Mobile);
					break;
				}
				case 3: // Complete respawn
				{
					m_Spawner.Respawn();

					ReOpen(state.Mobile);
					break;
				}
				case 4: //props
				{
				state.Mobile.SendGump(new PropertiesGump(state.Mobile,m_Spawner));
				
				ReOpen(state.Mobile);
				break;
				}
				case 5: //bounds
				{
				if(state.Mobile.AccessLevel>AccessLevel.Player)Server.Commands.RegionBounds.ShowObjectBounds(state.Mobile,m_Spawner,m_Spawner.HomeRange);
				ReOpen(state.Mobile);
				break;
				}
				case 6: //goto
				{
				state.Mobile.MoveToWorld(m_Spawner.Location,m_Spawner.Map);
				
				ReOpen(state.Mobile);
				break;
				}
				case 7: //corner walk
				{
				m_Spawner.CornerWalk(state.Mobile);
				ReOpen(state.Mobile);
				break;
				}
				default:
				{
					int buttonID = info.ButtonID - 4;
					int index = buttonID / 2;
					int type = buttonID % 2;

					TextRelay entry = info.GetTextEntry( index );

					if ( entry != null && entry.Text.Length > 0 )
					{
						if ( type == 0 ) // Spawn creature
							m_Spawner.Spawn(/* entry.Text */);
						else // Remove creatures
							m_Spawner.RemoveCreatures( entry.Text );

						m_Spawner.CreaturesName = CreateArray( info, state.Mobile );
					}

					ReOpen(state.Mobile);
					break;
				}
			}
			
			
		
		}
	}
}
