
class D3DSkillMenu : ListMenu
{
	int idelay;
	int delaylimit;
	int iselecteditem;

	override void Init(Menu parent, ListMenuDescriptor desc)
	{
		idelay = -1;
		Super.Init(parent,desc);
	}

	override bool MenuEvent (int mkey, bool fromcontroller)
	{
		if(idelay<0) {
			if (mkey==MKEY_Enter && mDesc.mSelectedItem>0)
			{
				if (d3d_skillsound==1) {
					delaylimit = 0;
				} else {
					delaylimit = 3 * Thinker.TICRATE;
					if (mDesc.mSelectedItem==1) MenuSound("duke/suck");
					else if (mDesc.mSelectedItem==2) MenuSound("duke/cake");
					else if (mDesc.mSelectedItem==3) MenuSound("duke/letsrock");
					else if (mDesc.mSelectedItem==4) MenuSound("duke/getsome");
					else if (mDesc.mSelectedItem==5) MenuSound("duke/imgood");
				}
				idelay++;
				iselecteditem = mDesc.mSelectedItem;
				return false;
			} else {
				return Super.MenuEvent(mkey, fromcontroller);
			}
		}  else {
			return true;
		}
	}

	override bool OnUIEvent(UIEvent ev)
	{
		if(idelay<0) {
			return Super.OnUIEvent(ev);
		} else {
			if (ev.type != UIEvent.Type_MouseMove) idelay = delaylimit;
			return true;
		}
	}

	override void Drawer ()
	{
		if(idelay<0) {
			Super.Drawer();
		} else {
			for(int i=0;i<mDesc.mItems.Size(); i++)
			{
				if (mDesc.mItems[i].mEnabled) mDesc.mItems[i].Drawer(mDesc.mSelectedItem == i);
			}
		}
	}

	override void Ticker()
	{
		if(idelay >= 0  && idelay < delaylimit) {
			idelay++;
		} else {
			if(idelay == delaylimit) {idelay++; mDesc.mItems[iselecteditem].Activate();}
			Super.Ticker();
		}
	}

}

class D3DStatusScreen : DoomStatusScreen
{

	enum EState2
	{
		LockLoad = 3
	};

	int ibreathe;
	int ilockload;
	int breathanimmul;
	int lockloadanimmul;

	override void Start (wbstartstruct wbstartstruct)
	{
		ibreathe = 0;
		ilockload = 0;
		breathanimmul = 10;;
		lockloadanimmul = 17;

		Super.Start(wbstartstruct);
	}

	override void updateStats ()
	{
		ibreathe++;
		if(ibreathe>=breathanimmul*4) ibreathe = 0;

		Super.updateStats();
	}

	override void drawStats (void)
	{
		TextureID tex;

		if(ibreathe>=0 && ibreathe<breathanimmul) {
			tex = TexMan.checkForTexture("DUKE01", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*2) {
			tex = TexMan.checkForTexture("DUKE02", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*3) {
			tex = TexMan.checkForTexture("DUKE03", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*4) {
			tex = TexMan.checkForTexture("DUKE02", TexMan.Type_Any);
		}

		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		drawStatsSP();
	}

	void drawStatsSP (void)
	{
		// line height
		int lh = IntermissionFont.GetHeight() * 3 / 2;

		drawLF();

		screen.DrawTexture (Kills, true, SP_TIMEX, SP_STATSY, DTA_Clean, true);
		drawPercent (IntermissionFont, 195 - SP_TIMEX, SP_STATSY, cnt_kills[0], wbs.maxkills);

		screen.DrawTexture (Items, true, SP_TIMEX, SP_STATSY+lh, DTA_Clean, true);
		drawPercent (IntermissionFont, 195 - SP_TIMEX, SP_STATSY+lh, cnt_items[0], wbs.maxitems);

		screen.DrawTexture (P_secret, true, SP_TIMEX, SP_STATSY+2*lh, DTA_Clean, true);
		drawPercent (IntermissionFont, 195 - SP_TIMEX, SP_STATSY+2*lh, cnt_secret[0], wbs.maxsecret);

		screen.DrawTexture (Timepic, true, SP_TIMEX, SP_TIMEY - lh, DTA_Clean, true);
		drawTime (195 - SP_TIMEX, SP_TIMEY - lh, cnt_time);
		if (wi_showtotaltime)
		{
			drawTime (195 - SP_TIMEX, SP_TIMEY, cnt_total_time, true);	// no 'sucks' for total time ever!
		}

		if (wbs.partime)
		{
			screen.DrawTexture (Par, true, SP_TIMEX, SP_TIMEY + lh, DTA_Clean, true);
			drawTime (195 - SP_TIMEX, SP_TIMEY + lh, cnt_par);
		}
	}

	override void initShowNextLoc ()
	{
		CurState = LockLoad;
	}

	void updateLockLoad()
	{
		if(ilockload==0) PlaySound("intermission/lockload");
		else if(ilockload==lockloadanimmul) PlaySound("shotgun/pump");
		else if(ilockload>=(lockloadanimmul*3-1)) RealinitShowNextLoc();
		ilockload++;
	}

	void drawLockLoad(void)
	{
		TextureID tex;

		if(ilockload>=0 && ilockload<lockloadanimmul) {
			tex = TexMan.checkForTexture("DUKE04", TexMan.Type_Any);
		} else if(ilockload<lockloadanimmul*2) {
			tex = TexMan.checkForTexture("DUKE05", TexMan.Type_Any);
		} else if(ilockload<lockloadanimmul*3) {
			tex = TexMan.checkForTexture("DUKE04", TexMan.Type_Any);
		}

		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		drawStatsSP();
	}

	void RealinitShowNextLoc ()
	{
		Super.initShowNextLoc();
	}

	override void drawShowNextLoc(void)
	{
		TextureID tex = TexMan.checkForTexture("DN3Dload", TexMan.Type_Any);
		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		drawELNameOnly (); 
	}

	void drawELNameOnly ()
	{
		let size = TexMan.GetScaledSize(wbs.LName1);
		int y = (screen.GetHeight() - size.Y * CleanYfac) /2;
		y += (size.Y + BigFont.GetHeight()*2) * CleanYfac;

		DrawName(y, wbs.LName1, lnametexts[1]);
	}

	override void Ticker(void)
	{
		Super.Ticker();

		if(CurState==LockLoad) updateLockLoad();
	}
	
	override void Drawer (void)
	{
		Super.Drawer();

		if(CurState==LockLoad) drawLockLoad();
	}

}

class D3DCoopStatusScreen : CoopStatusScreen
{

	enum EState2
	{
		LockLoad = 3
	};

	int ibreathe;
	int ilockload;
	int breathanimmul;
	int lockloadanimmul;

	override void Start (wbstartstruct wbstartstruct)
	{
		ibreathe = 0;
		ilockload = 0;
		breathanimmul = 10;;
		lockloadanimmul = 17;

		Super.Start(wbstartstruct);
	}

	override void updateStats ()
	{
		ibreathe++;
		if(ibreathe>=breathanimmul*4) ibreathe = 0;

		Super.updateStats();
	}

	override void drawStats (void)
	{
		TextureID tex;

		if(ibreathe>=0 && ibreathe<breathanimmul) {
			tex = TexMan.checkForTexture("DUKE01", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*2) {
			tex = TexMan.checkForTexture("DUKE02", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*3) {
			tex = TexMan.checkForTexture("DUKE03", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*4) {
			tex = TexMan.checkForTexture("DUKE02", TexMan.Type_Any);
		}

		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		Super.drawStats();
	}

	override void initShowNextLoc ()
	{
		CurState = LockLoad;
	}

	void updateLockLoad()
	{
		if(ilockload==0) PlaySound("intermission/lockload");
		else if(ilockload==lockloadanimmul) PlaySound("shotgun/pump");
		else if(ilockload>=(lockloadanimmul*3-1)) RealinitShowNextLoc();
		ilockload++;
	}

	void drawLockLoad(void)
	{
		TextureID tex;

		if(ilockload>=0 && ilockload<lockloadanimmul) {
			tex = TexMan.checkForTexture("DUKE04", TexMan.Type_Any);
		} else if(ilockload<lockloadanimmul*2) {
			tex = TexMan.checkForTexture("DUKE05", TexMan.Type_Any);
		} else if(ilockload<lockloadanimmul*3) {
			tex = TexMan.checkForTexture("DUKE04", TexMan.Type_Any);
		}

		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		Super.drawStats();
	}

	void RealinitShowNextLoc ()
	{
		Super.initShowNextLoc();
	}

	override void drawShowNextLoc(void)
	{
		TextureID tex = TexMan.checkForTexture("DN3Dload", TexMan.Type_Any);
		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		drawELNameOnly (); 
	}

	void drawELNameOnly ()
	{
		let size = TexMan.GetScaledSize(wbs.LName1);
		int y = (screen.GetHeight() - size.Y * CleanYfac) /2;
		y += (size.Y + BigFont.GetHeight()*2) * CleanYfac;

		DrawName(y, wbs.LName1, lnametexts[1]);
	}

	override void Ticker(void)
	{
		Super.Ticker();

		if(CurState==LockLoad) updateLockLoad();
	}
	
	override void Drawer (void)
	{
		Super.Drawer();

		if(CurState==LockLoad) drawLockLoad();
	}

}

class D3DDeathmatchStatusScreen : DeathmatchStatusScreen
{

	enum EState2
	{
		LockLoad = 3
	};

	int ibreathe;
	int ilockload;
	int breathanimmul;
	int lockloadanimmul;

	override void Start (wbstartstruct wbstartstruct)
	{
		ibreathe = 0;
		ilockload = 0;
		breathanimmul = 10;;
		lockloadanimmul = 17;

		Super.Start(wbstartstruct);
	}

	override void updateStats ()
	{
		ibreathe++;
		if(ibreathe>=breathanimmul*4) ibreathe = 0;

		Super.updateStats();
	}

	override void drawStats (void)
	{
		TextureID tex;

		if(ibreathe>=0 && ibreathe<breathanimmul) {
			tex = TexMan.checkForTexture("DUKE01", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*2) {
			tex = TexMan.checkForTexture("DUKE02", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*3) {
			tex = TexMan.checkForTexture("DUKE03", TexMan.Type_Any);
		} else if(ibreathe<breathanimmul*4) {
			tex = TexMan.checkForTexture("DUKE02", TexMan.Type_Any);
		}

		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		Super.drawStats();
	}

	override void initShowNextLoc ()
	{
		CurState = LockLoad;
	}

	void updateLockLoad()
	{
		if(ilockload==0) PlaySound("intermission/lockload");
		else if(ilockload==lockloadanimmul) PlaySound("shotgun/pump");
		else if(ilockload>=(lockloadanimmul*3-1)) RealinitShowNextLoc();
		ilockload++;
	}

	void drawLockLoad(void)
	{
		TextureID tex;

		if(ilockload>=0 && ilockload<lockloadanimmul) {
			tex = TexMan.checkForTexture("DUKE04", TexMan.Type_Any);
		} else if(ilockload<lockloadanimmul*2) {
			tex = TexMan.checkForTexture("DUKE05", TexMan.Type_Any);
		} else if(ilockload<lockloadanimmul*3) {
			tex = TexMan.checkForTexture("DUKE04", TexMan.Type_Any);
		}

		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		Super.drawStats();
	}

	void RealinitShowNextLoc ()
	{
		Super.initShowNextLoc();
	}

	override void drawShowNextLoc(void)
	{
		TextureID tex = TexMan.checkForTexture("DN3Dload", TexMan.Type_Any);
		screen.Dim(0, 1.0, 0,0, screen.GetWidth(), screen.GetHeight());
		screen.DrawTexture (tex, false, 0, 0, DTA_Fullscreen, true);

		drawELNameOnly (); 
	}

	void drawELNameOnly ()
	{
		let size = TexMan.GetScaledSize(wbs.LName1);
		int y = (screen.GetHeight() - size.Y * CleanYfac) /2;
		y += (size.Y + BigFont.GetHeight()*2) * CleanYfac;

		DrawName(y, wbs.LName1, lnametexts[1]);
	}

	override void Ticker(void)
	{
		Super.Ticker();

		if(CurState==LockLoad) updateLockLoad();
	}
	
	override void Drawer (void)
	{
		Super.Drawer();

		if(CurState==LockLoad) drawLockLoad();
	}

}