using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WorldOfPeacecraft
{
	public class OnlinePlayerList : Panel
	{
		private IBackend Backend;
		private Image PlayerOnlineImage;

		public OnlinePlayerList(IBackend backend)
		{
			this.Backend = backend;
		}

		protected override void OnPaint (PaintEventArgs e)
		{
			base.OnPaint (e);
			Graphics g = e.Graphics;
			g.FillRectangle (new SolidBrush (Color.White), this.DisplayRectangle);
			g.DrawRectangle (new Pen(new SolidBrush (Color.Black)), 0, 0, Width - 1, Height - 1);
			IEnumerable<IPlayer> players = Backend.GetPlayers ();
			int count = 0;
			Brush brush = new SolidBrush(Color.Black);
			foreach (IPlayer player in players) {
				g.DrawImage(PlayerOnlineImage, 10, 12 + 40 * count, 25, 32);
				g.DrawString(player.GetName(), Font, brush, 40, 20 + 40 * count);
				count++;
			}
		}

		public void LoadResources(){
			Font = new Font(Font, FontStyle.Bold);
			PlayerOnlineImage = Image.FromFile("textures/playerOnline.png");
		}

		public void InitializeComponents(){
			SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
		}
	}
}