using System;
using Microsoft.DirectX.DirectDraw;
using Global;
using Global.GlobalClass;
using KillerInstinct.DirectX;
namespace KillerInstinct.Sprites{
public class MenuClass : SpriteClass
{
public int activeMenuPoint = 1;
public int textDistance = 0;
public MenuClass(string file, float x, float y, int framesCount, int textdistance)
{
frame.Width = 300;
frame.Height = 50;
this.framesCount = framesCount;
framesPerRow = 2;
whichFrame = 0;
layer = LAYER_TOP;
textDistance = textdistance;
Init(file, CONST.COLORKEY_BLACK, x, y);
}
public new void Draw()
{
global.dbg.Out(Debug.DBG3, "MenuClass.Draw called");
int i=0, j=0;
try
{
global.dbg.Out(Debug.DBG3, "---------------------------------");
global.dbg.Out(Debug.DBG3, "file = " + file);
global.dbg.Out(Debug.DBG3, "posX = " + posX);
global.dbg.Out(Debug.DBG3, "posY = " + posY);
global.dbg.Out(Debug.DBG3, "whichFrame = " + whichFrame);
global.dbg.Out(Debug.DBG3, "frame.X = " + frame.X);
global.dbg.Out(Debug.DBG3, "frame.Y = " + frame.Y);
global.dbg.Out(Debug.DBG3, "framesCount = " + framesCount);
global.dbg.Out(Debug.DBG3, "textDistance = " + textDistance);
for (i=0; i<framesCount/2; ++i)
{
//global.dbg.Out(Debug.TRACE, "j = " + j);
if (activeMenuPoint == (i+1))
{
global.DC.Back.DrawFast((int)posX, (int)(posY+textDistance*i), surface, GetBitmapFrameRect(j), DrawFastFlags.Wait | DrawFastFlags.SourceColorKey);
}
else
{
global.DC.Back.DrawFast((int)posX, (int)(posY+textDistance*i), surface, GetBitmapFrameRect(j+1), DrawFastFlags.Wait | DrawFastFlags.SourceColorKey);
}
j += 2;
}
}
catch (Exception e)
{
//TODO: this exception occurs every once in a while ... ???
global.dbg.Out(Debug.WARN, "MenuClass.Draw exception: x=[" + posX + "] y=[" + posY + "] whichFrame=[" + whichFrame + "] getFRect=[" + GetBitmapFrameRect(whichFrame) + "] file=[" + file + "]" + "] i=[" + i + "]" + "] j=[" + j + "]");
global.dbg.Out(Debug.WARN, "MenuClass.Draw exception: " + e);
}
}
public string GetSoundResource(int which)
{
return (CONST.DIR_SOUND + "Menu" + which + ".bmp");
}
public void Previous(int max)
{
if (activeMenuPoint > 1)
activeMenuPoint--;
else
activeMenuPoint=max;
global.SC.Play(SoundClass.SOUND_MENUNEXT, false);
}
public void Next(int max)
{
if (activeMenuPoint < max)
activeMenuPoint++;
else
activeMenuPoint=1;
global.SC.Play(SoundClass.SOUND_MENUNEXT, false);
}
public override void Update()
{
}
public override void ReactToCollision(SpriteClass s)
{
}
public bool MouseOver()
{
for (int i=0; i<framesCount/2; i++)
{
if (global.IC.GetMouseXY().X > posX &&
global.IC.GetMouseXY().X < posX + frame.Width &&
global.IC.GetMouseXY().Y > posY + textDistance*i &&
global.IC.GetMouseXY().Y < posY + textDistance*(i+1))
{
if (activeMenuPoint!=i+1)
global.SC.Play(SoundClass.SOUND_MENUNEXT, false);
activeMenuPoint = i+1;
return true;
}
}
return false;
}
}
}
|