public class ChatPopup : Popup
{
	public static Image imgChat = GameScr.imgChat;

	public int timeOut;

	public int xArrow;

	public int yArrow;

	public int x;

	public int y;

	public int h;

	public int popupW = 60;

	private string[] chats;

	private CPlayer p;

	private bool isShow2;

	public void show(int time, int x, int y, string chat)
	{
		isShow2 = false;
		prepareData(time, x, y, chat);
		base.show();
	}

	public void show2(int time, CPlayer p, string chat)
	{
		this.p = p;
		isShow2 = true;
		chats = mFont.smallFontYellow.splitFontArray(chat, popupW - 10);
		h = 10 * chats.Length + 4;
		xArrow = x - 2;
		yArrow = y - 4;
		x = xArrow - popupW / 2;
		y = yArrow - h;
		timeOut = time;
		base.show();
	}

	private void prepareData(int time, int x, int y, string chat)
	{
		chats = mFont.smallFontYellow.splitFontArray(chat, popupW - 10);
		h = 10 * chats.Length + 4;
		xArrow = x - 2;
		yArrow = y - 4;
		this.x = xArrow - popupW / 2;
		this.y = yArrow - h;
		while (this.x < 10)
		{
			this.x++;
		}
		while (this.x + popupW > CCanvas.w - 10)
		{
			this.x--;
		}
		timeOut = time;
	}

	public void showSingle(int time, int x, int y, string chat)
	{
		prepareData(time, x, y, chat);
		base.showSingle();
	}

	public override void update()
	{
		if (isShow2 && p != null)
		{
			x = p.x;
			y = p.y - 40;
			xArrow = x - 2;
			yArrow = y - 4;
			x = xArrow - (popupW >> 1);
			y = yArrow - h;
		}
		if (timeOut > 0)
		{
			timeOut--;
			if (timeOut == 0)
			{
				CCanvas.currentPopup.removeElement(this);
			}
		}
	}

	public override void paint(mGraphics g)
	{
		if (!isShow2 || p != null)
		{
			g.setColor(16711553);
			g.fillRect(x - 5, y - 5, popupW + 10, h + 10, false);
			g.setColor(0);
			g.drawRect(x - 5, y - 5, popupW + 10, h + 10, false);
			g.drawImage(imgChat, xArrow, yArrow + 5, 0, false);
			int num = y + 2;
			for (int i = 0; i < chats.Length; i++)
			{
				mFont.tahoma_7.drawString(g, chats[i], x + popupW / 2, num, 2);
				num += 10;
			}
		}
	}
}
