using System;

namespace SharpQuake
{
	internal class MainMenu : MenuBase
	{
		public override void Show()
		{
			if (Key.Destination != keydest_t.key_menu)
			{
				this._SaveDemoNum = client.cls.demonum;
				client.cls.demonum = -1;
			}
			base.Show();
		}

		public override void KeyEvent(int key)
		{
			if (key <= 27)
			{
				if (key != 13)
				{
					if (key != 27)
					{
						return;
					}
					MenuBase.Hide();
					client.cls.demonum = this._SaveDemoNum;
					if (client.cls.demonum != -1 && !client.cls.demoplayback && client.cls.state != cactive_t.ca_connected)
					{
						client.NextDemo();
						return;
					}
				}
				else
				{
					menu.EnterSound = true;
					switch (this._Cursor)
					{
					case 0:
						MenuBase.SinglePlayerMenu.Show();
						return;
					case 1:
						MenuBase.MultiPlayerMenu.Show();
						return;
					case 2:
						MenuBase.OptionsMenu.Show();
						return;
					case 3:
						MenuBase.HelpMenu.Show();
						return;
					case 4:
						MenuBase.QuitMenu.Show();
						break;
					default:
						return;
					}
				}
			}
			else if (key != 128)
			{
				if (key != 129)
				{
					return;
				}
				snd.LocalSound("misc/menu1.wav");
				int num = this._Cursor + 1;
				this._Cursor = num;
				if (num >= 5)
				{
					this._Cursor = 0;
					return;
				}
			}
			else
			{
				snd.LocalSound("misc/menu1.wav");
				int num = this._Cursor - 1;
				this._Cursor = num;
				if (num < 0)
				{
					this._Cursor = 4;
					return;
				}
			}
		}

		public override void Draw()
		{
			menu.DrawTransPic(16, 4, Drawer.CachePic("gfx/qplaque.lmp"));
			glpic_t glpic_t = Drawer.CachePic("gfx/ttl_main.lmp");
			menu.DrawPic((320 - glpic_t.width) / 2, 4, glpic_t);
			menu.DrawTransPic(72, 32, Drawer.CachePic("gfx/mainmenu.lmp"));
			int num = (int)(host.Time * 10.0) % 6;
			menu.DrawTransPic(54, 32 + this._Cursor * 20, Drawer.CachePic(string.Format("gfx/menudot{0}.lmp", num + 1)));
		}

		private const int MAIN_ITEMS = 5;

		private int _SaveDemoNum;
	}
}
