public class Command
{
	public ActionChat actionChat;

	public string caption;

	public string[] subCaption;

	public IActionListener actionListener;

	public int idAction;

	public bool isPlaySoundButton = true;

	public Image img;

	public int x;

	public int y;

	public int w = CScreen.cmdW;

	public int h = CScreen.cmdH;

	public int hw;

	private int lenCaption;

	public bool isFocus;

	public object p;

	public static Image close = CCanvas.loadImage("/close.png");

	public static Image back = CCanvas.loadImage("/back.png");

	public int type;

	public Command()
	{
	}

	public Command(string caption, IActionListener actionListener, int action, object p, int x, int y)
	{
		this.caption = caption;
		idAction = action;
		this.actionListener = actionListener;
		this.p = p;
		this.x = x;
		this.y = y;
	}

	public Command(string caption, IActionListener actionListener, int action, object p)
	{
		this.caption = caption;
		idAction = action;
		this.actionListener = actionListener;
		this.p = p;
	}

	public Command(string caption, int action, object p)
	{
		this.caption = caption;
		idAction = action;
		this.p = p;
	}

	public Command(string caption, int action)
	{
		this.caption = caption;
		idAction = action;
	}

	public Command(string caption, int action, int x, int y)
	{
		this.caption = caption;
		idAction = action;
		this.x = x;
		this.y = y;
	}

	public void perform(string str)
	{
		if (actionChat != null)
		{
			actionChat(str);
		}
	}

	public void setType()
	{
		type = 1;
		w = 160;
		hw = 80;
	}

	public void performAction()
	{
		CCanvas.clearAllPointerEvent();
		if (idAction > 0)
		{
			if (actionListener != null)
			{
				actionListener.perform(idAction, p);
			}
			else
			{
				CCanvas.gameScr.actionPerform(idAction, p);
			}
		}
	}

	public void paint(mGraphics g)
	{
		if (img != null)
		{
			g.drawImage(img, x, y, 0, false);
			if (isFocus)
			{
				if (img == close)
				{
					g.drawImage(GameScr.focus, x + 11, y + 11, 3, false);
				}
				else
				{
					g.drawImage(GameScr.focus, x + 17, y + 11, 3, false);
				}
			}
			return;
		}
		if (caption != string.Empty)
		{
			if (type == 1)
			{
				if (!isFocus)
				{
					paintOngMau(CScreen.btn0left, CScreen.btn0mid, CScreen.btn0right, x, y, 160, g);
				}
				else
				{
					paintOngMau(CScreen.btn1left, CScreen.btn1mid, CScreen.btn1right, x, y, 160, g);
				}
			}
			else if (!isFocus)
			{
				paintOngMau(CScreen.btn0left, CScreen.btn0mid, CScreen.btn0right, x, y, 76, g);
			}
			else
			{
				paintOngMau(CScreen.btn1left, CScreen.btn1mid, CScreen.btn1right, x, y, 76, g);
			}
		}
		int num = ((type != 1) ? (x + 38) : (x + hw));
		if (!isFocus)
		{
			mFont.tahoma_7b_dark.drawString(g, caption, num, y + 7, 2);
		}
		else
		{
			mFont.tahoma_7b_dark.drawString(g, caption, num, y + 7, 2);
		}
	}

	public static void paintOngMau(Image img0, Image img1, Image img2, float x, float y, int size, mGraphics g)
	{
		for (int i = 10; i <= size - 20; i += 10)
		{
			g.drawImage(img1, x + (float)i, y, 0, true);
		}
		int num = size % 10;
		if (num > 0)
		{
			g.drawRegion(img1, 0, 0, num, 24, 0, x + (float)size - 10f - (float)num, y, 0, true);
		}
		g.drawImage(img0, x, y, 0, true);
		g.drawImage(img2, x + (float)size - 10f, y, 0, true);
	}

	public bool isPointerPressInside()
	{
		isFocus = false;
		if (CCanvas.isPointerHoldIn(x, y, w, h))
		{
			if (CCanvas.isPointerDown)
			{
				isFocus = true;
			}
			if (CCanvas.isPointerJustRelease && CCanvas.isPointerClick)
			{
				Music.play(Music.CLICK, 10f);
				return true;
			}
		}
		return false;
	}
}
