示例#1
0
		/// <summary>
		///     Add a player to the listview
		/// </summary>
		/// <param name="player"></param>
		private void HandlePlayerAddition(Player player)
		{
			try
			{
				if (InvokeRequired)
				{
					Invoke((MethodInvoker) (() => HandlePlayerAddition(player)));
				}
				else
				{
					string[] contents =
					{
						player.Name, player.DisplayName, player.Ip, player.JoinTime.ToShortTimeString(),
						player.Location
					};
					ListViewItem item = new ListViewItem(contents) {Tag = player, ImageKey = "default"};
					if (player.Minotar != null)
					{
						imageListPlayerFaces.Images.Add(player.Name, player.Minotar);
						imageListPlayerFacesBig.Images.Add(player.Name, player.Minotar);
						item.ImageKey = player.Name;
					}

					SlvPlayers.Items.Add(item);
					player.DetailsLoaded += player_DetailsLoaded;
				}
			}
			catch (Exception exception)
			{
				Logger.Log(LogLevel.Severe, "PlayerListTab", "Failed to add player: " + player.Name, exception.Message);
			}
		}
示例#2
0
		/// <summary>
		///     Remove a player from the listview
		/// </summary>
		/// <param name="player"></param>
		private void HandlePlayerDeletion(Player player)
		{
			if (player == null || player.Name == null) return;

			try
			{
				if (InvokeRequired)
				{
					Invoke((MethodInvoker) (() => HandlePlayerDeletion(player)));
				}
				else
				{
					foreach (ListViewItem item in SlvPlayers.Items)
					{
						if (item.Tag == player) item.Remove();
					}
					if (imageListPlayerFaces.Images.ContainsKey(player.Name))
						imageListPlayerFaces.Images.RemoveByKey(player.Name);
					if (imageListPlayerFacesBig.Images.ContainsKey(player.Name))
						imageListPlayerFacesBig.Images.RemoveByKey(player.Name);
				}
			}
			catch (Exception exception)
			{
				Logger.Log(LogLevel.Severe, "PlayerListTab", "Failed to remove player: " + player.Name,
					exception.Message);
			}
		}
示例#3
0
		/// <summary>
		///     Raise a PlayerListAddition event
		/// </summary>
		/// <param name="player">the player that has been added</param>
		private static void RaisePlayerListAdditionEvent(Player player)
		{
			PlayerListAdditionEventHandler handler = PlayerListAddition;
			if (handler != null)
			{
				handler(player);
			}
		}
示例#4
0
		/// <summary>
		///     Add a player to the listview
		/// </summary>
		/// <param name="player"></param>
		private void HandlePlayerAddition(Player player)
		{
			if (InvokeRequired)
			{
				Invoke((MethodInvoker) (() => HandlePlayerAddition(player)));
			}
			else
			{
				player.DetailsLoaded += player_DetailsLoaded;
				ListViewItem lvi = new ListViewItem(player.DisplayName) {Tag = player, ImageKey = "default"};

				SlvPlayers.Items.Add(lvi);
			}
		}
示例#5
0
		/// <summary>
		///     Remove a player from the listview
		/// </summary>
		/// <param name="player"></param>
		private void HandlePlayerDeletion(Player player)
		{
			if (InvokeRequired)
			{
				Invoke((MethodInvoker) (() => HandlePlayerDeletion(player)));
			}
			else
			{
				ListViewItem lvi = FindPlayerListViewItem(player);

				if (lvi != null) SlvPlayers.Items.Remove(lvi);
				if (imgListPlayerFaces.Images.ContainsKey(player.Name))
					imgListPlayerFaces.Images.RemoveByKey(player.Name);
			}
		}
示例#6
0
		private ListViewItem FindPlayerListViewItem(Player player)
		{
			foreach (ListViewItem item in SlvPlayers.Items)
			{
				if (item.Tag == player) return item;
			}
			return null;
		}
示例#7
0
		/// <summary>
		///     Handle a player join event
		/// </summary>
		private static void HandlePlayerJoin(
			string text,
			OutputParseResult outputparseresult,
			IPlayerAction playeraction)
		{
			PlayerActionJoin join = (PlayerActionJoin) playeraction;

			Player player = new Player(join.PlayerName, join.Ip, join.PlayerName);

			AddPlayer(player);
		}
示例#8
0
		/// <summary>
		///     Get the online players
		/// </summary>
		/// <returns></returns>
		public static IEnumerable<Player> GetOnlinePlayers()
		{
			Player[] result = new Player[OnlinePlayers.Count];
			OnlinePlayers.Values.CopyTo(result, 0);
			return result;
		}
示例#9
0
		/// <summary>
		///     Remove a player from the online players list and raise the according events
		/// </summary>
		/// <param name="player">The player to remove</param>
		public static void RemovePlayer(Player player)
		{
			if (player == null || !OnlinePlayers.ContainsKey(player.Name)) return;
			OnlinePlayers.Remove(player.Name);
			RaisePlayerListChangedEvent();
			RaisePlayerListDeletionEvent(player);
		}
示例#10
0
		/// <summary>
		///     Add a player to the online players list and raise the according events
		/// </summary>
		/// <param name="player">The player to add</param>
		public static void AddPlayer(Player player)
		{
			if (player == null || string.IsNullOrEmpty(player.Name)) return;

			try
			{
				if (OnlinePlayers.ContainsKey(player.Name)) return;

				OnlinePlayers.Add(player.Name, player);
				RaisePlayerListAdditionEvent(player);
				RaisePlayerListChangedEvent();
			}
			catch (Exception exception)
			{
				Logger.Log(LogLevel.Severe, "PlayerHandler", "Failed to add player: " + player.Name, exception.Message);
			}
		}