using System;

namespace SharpQuake
{
	internal class SaveMenu : LoadMenu
	{
		public override void Show()
		{
			if (!server.sv.active)
			{
				return;
			}
			if (client.cl.intermission != 0)
			{
				return;
			}
			if (server.svs.maxclients != 1)
			{
				return;
			}
			base.Show();
		}

		public override void KeyEvent(int key)
		{
			if (key == 13)
			{
				MenuBase.Hide();
				Cbuf.AddText(string.Format("save s{0}\n", this._Cursor));
				return;
			}
			if (key != 27)
			{
				switch (key)
				{
				case 128:
				case 130:
					snd.LocalSound("misc/menu1.wav");
					this._Cursor--;
					if (this._Cursor < 0)
					{
						this._Cursor = 11;
						return;
					}
					break;
				case 129:
				case 131:
					snd.LocalSound("misc/menu1.wav");
					this._Cursor++;
					if (this._Cursor >= 12)
					{
						this._Cursor = 0;
					}
					break;
				default:
					return;
				}
				return;
			}
			MenuBase.SinglePlayerMenu.Show();
		}

		public override void Draw()
		{
			glpic_t glpic_t = Drawer.CachePic("gfx/p_save.lmp");
			menu.DrawPic((320 - glpic_t.width) / 2, 4, glpic_t);
			for (int i = 0; i < 12; i++)
			{
				menu.Print(16, 32 + 8 * i, this._FileNames[i]);
			}
			menu.DrawCharacter(8, 32 + this._Cursor * 8, 12 + ((int)(host.RealTime * 4.0) & 1));
		}
	}
}
