示例#1
0
        private void UpdateChat(object sender, ElapsedEventArgs e)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
            {
                if (Client.CurrentStatus != StatusBox.Text && StatusBox.Text != "Set your status message")
                    Client.CurrentStatus = StatusBox.Text;
                else if (StatusBox.Text == "Set your status message")
                    Client.CurrentStatus = "Online";

                Settings.Default.StatusMsg = StatusBox.Text;
                Settings.Default.Save();
                if (!Client.UpdatePlayers)
                    return;

                Client.UpdatePlayers = false;

                ChatListView.Children.Clear();

                #region "Groups"
                while (!Client.loadedGroups)
                {
                    await Task.Delay(1000);
                }
                foreach (Group g in Client.Groups)
                {
                    var playersListView = new ListView
                    {
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        VerticalContentAlignment = VerticalAlignment.Stretch
                    };
                    playersListView.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty,
                        ScrollBarVisibility.Disabled);
                    playersListView.Foreground = Brushes.White;
                    playersListView.Background = null;
                    playersListView.BorderBrush = null;
                    playersListView.MouseDoubleClick += PlayersListView_MouseDoubleClick;
                    playersListView.SelectionChanged += ChatListView_SelectionChanged;
                    playersListView.PreviewMouseWheel += PlayersListView_PreviewMouseWheel;

                    int players = 0;

                    foreach (var chatPlayerPair in Client.AllPlayers.ToArray().OrderBy(u => u.Value.Username))
                    {
                        var player = new ChatPlayer
                        {
                            Tag = chatPlayerPair.Value,
                            DataContext = chatPlayerPair.Value,
                            ContextMenu = (ContextMenu)Resources["PlayerChatMenu"],
                            PlayerName = { Content = chatPlayerPair.Value.Username },
                            LevelLabel = { Content = chatPlayerPair.Value.Level }
                        };

                        var bc = new BrushConverter();
                        var brush = (Brush)bc.ConvertFrom("#FFFFFFFF");
                        player.PlayerStatus.Content = chatPlayerPair.Value.Status;
                        player.PlayerStatus.Foreground = brush;

                        if (chatPlayerPair.Value.IsOnline && g.GroupName == chatPlayerPair.Value.Group)
                        {
                            player.Width = 250;
                            bc = new BrushConverter();
                            brush = (Brush)bc.ConvertFrom("#FFFFFFFF");
                            player.PlayerStatus.Foreground = brush;
                            string UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon",
                                chatPlayerPair.Value.ProfileIcon + ".png");
                            player.ProfileImage.Source = Client.GetImage(UriSource);

                            if (chatPlayerPair.Value.GameStatus != "outOfGame")
                            {
                                switch (chatPlayerPair.Value.GameStatus)
                                {
                                    case "inGame":
                                        champions inGameChamp = champions.GetChampion(chatPlayerPair.Value.Champion);
                                        if (inGameChamp != null)
                                            player.PlayerStatus.Content = "In Game as " + inGameChamp.displayName;
                                        else
                                            player.PlayerStatus.Content = "In Game";
                                        break;
                                    case "hostingPracticeGame":
                                        player.PlayerStatus.Content = "Creating Custom Game";
                                        break;
                                    case "inQueue":
                                        player.PlayerStatus.Content = "In Queue";
                                        break;
                                    case "spectating":
                                        player.PlayerStatus.Content = "Spectating";
                                        break;
                                    case "championSelect":
                                        player.PlayerStatus.Content = "In Champion Select";
                                        break;
                                    case "hostingRankedGame":
                                        player.PlayerStatus.Content = "Creating Ranked Game";
                                        break;
                                    case "teamSelect":
                                        player.PlayerStatus.Content = "In Team Select";
                                        break;
                                    case "hostingNormalGame":
                                        player.PlayerStatus.Content = "Creating Normal Game";
                                        break;
                                    case "hostingCoopVsAIGame":
                                        player.PlayerStatus.Content = "Creating Co-op vs. AI Game";
                                        break;
                                    case "inTeamBuilder":
                                        player.PlayerStatus.Content = "In Team Builder";
                                        break;
                                    case "tutorial":
                                        player.PlayerStatus.Content = "In Tutorial";
                                        break;
                                }
                                brush = (Brush)bc.ConvertFrom("#FFFFFF99");
                                player.PlayerStatus.Foreground = brush;
                            }

                            player.MouseRightButtonDown += player_MouseRightButtonDown;
                            player.MouseMove += ChatPlayerMouseOver;
                            player.MouseLeave += player_MouseLeave;
                            playersListView.Items.Add(player);
                            players++;
                        }
                        else if (!chatPlayerPair.Value.IsOnline && g.GroupName == "Offline")
                        {
                            player.Width = 250;
                            player.Height = 30;
                            player.PlayerName.Margin = new Thickness(5, 2.5, 0, 0);
                            player.LevelLabel.Visibility = Visibility.Hidden;
                            player.ProfileImage.Visibility = Visibility.Hidden;
                            playersListView.Items.Add(player);
                            players++;
                        }
                    }
                    var groupControl = new ChatGroup
                    {
                        Width = 230,
                        PlayersLabel = { Content = players },
                        NameLabel = { Content = g.GroupName }
                    };
                    groupControl.GroupListView.Children.Add(playersListView);
                    if (g.IsOpen)
                    {
                        groupControl.ExpandLabel.Content = "-";
                        groupControl.GroupListView.Visibility = Visibility.Visible;
                    }
                    if (!string.IsNullOrEmpty(g.GroupName))
                        ChatListView.Children.Add(groupControl);
                    else Client.Log("Removed a group");
                }
                #endregion

                if (ChatListView.Children.Count > 0 && ChatListView.Children[0] is ChatGroup && loaded)
                {
                    //Stop droping 100 times
                    (ChatListView.Children[0] as ChatGroup).GroupGrid_MouseDown(null, null);
                    loaded = true;
                }
            }));
        }
        private void UpdateChat(object sender, System.Timers.ElapsedEventArgs e)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                if (Client.CurrentStatus != StatusBox.Text && StatusBox.Text != "Set your status message")
                {
                    Client.CurrentStatus = StatusBox.Text;
                }
                else if (StatusBox.Text == "Set your status message")
                {
                    Client.CurrentStatus = "Online";
                }

                Properties.Settings.Default.StatusMsg = StatusBox.Text;
                Properties.Settings.Default.Save();

                if (Client.UpdatePlayers)
                {
                    Client.UpdatePlayers = false;

                    ChatListView.Children.Clear();

                    foreach (Group g in Client.Groups)
                    {
                        ListView PlayersListView = new ListView();
                        PlayersListView.HorizontalAlignment = HorizontalAlignment.Stretch;
                        PlayersListView.VerticalContentAlignment = VerticalAlignment.Stretch;
                        PlayersListView.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);
                        PlayersListView.Foreground = Brushes.White;
                        PlayersListView.Background = null;
                        PlayersListView.BorderBrush = null;
                        PlayersListView.SelectionChanged += ChatListView_SelectionChanged;
                        PlayersListView.PreviewMouseWheel += PlayersListView_PreviewMouseWheel;

                        int Players = 0;

                        foreach (KeyValuePair<string, ChatPlayerItem> ChatPlayerPair in Client.AllPlayers.ToArray())
                        {
                            ChatPlayer player = new ChatPlayer();
                            player.Tag = ChatPlayerPair.Value;
                            player.DataContext = ChatPlayerPair.Value;
                            player.ContextMenu = (ContextMenu)Resources["PlayerChatMenu"];

                            if (ChatPlayerPair.Value.IsOnline && g.GroupName == ChatPlayerPair.Value.Group)
                            {
                                player.Width = 250;
                                BrushConverter bc = new BrushConverter();
                                Brush brush = (Brush)bc.ConvertFrom("#FFFFFFFF");
                                player.PlayerStatus.Foreground = brush;
                                var uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", ChatPlayerPair.Value.ProfileIcon + ".png");
                                player.ProfileImage.Source = Client.GetImage(uriSource);

                                if (ChatPlayerPair.Value.GameStatus != "outOfGame")
                                {
                                    switch (ChatPlayerPair.Value.GameStatus)
                                    {
                                        case "inGame":
                                            champions InGameChamp = champions.GetChampion(ChatPlayerPair.Value.Champion);
                                            if (InGameChamp != null)
                                                player.PlayerStatus.Content = "In Game as " + InGameChamp.displayName;
                                            else
                                                player.PlayerStatus.Content = "In Game";
                                            break;
                                        case "hostingPracticeGame":
                                            player.PlayerStatus.Content = "Creating Custom Game";
                                            break;
                                        case "inQueue":
                                            player.PlayerStatus.Content = "In Queue";
                                            break;
                                        case "spectating":
                                            player.PlayerStatus.Content = "Spectating";
                                            break;
                                        case "championSelect":
                                            player.PlayerStatus.Content = "In Champion Select";
                                            break;
                                    }
                                    brush = (Brush)bc.ConvertFrom("#FFFFFF99");
                                    player.PlayerStatus.Foreground = brush;
                                }

                                player.MouseMove += ChatPlayerMouseOver;
                                player.MouseLeave += player_MouseLeave;
                                PlayersListView.Items.Add(player);
                                Players++;
                            }
                            else if (!ChatPlayerPair.Value.IsOnline && g.GroupName == "Offline")
                            {
                                player.Width = 250;
                                player.Height = 30;
                                player.PlayerName.Margin = new Thickness(5, 2.5, 0, 0);
                                player.LevelLabel.Visibility = System.Windows.Visibility.Hidden;
                                player.ProfileImage.Visibility = System.Windows.Visibility.Hidden;
                                PlayersListView.Items.Add(player);
                                Players++;
                            }
                        }

                        ChatGroup GroupControl = new ChatGroup();
                        GroupControl.Width = 230;
                        GroupControl.PlayersLabel.Content = Players;
                        GroupControl.NameLabel.Content = g.GroupName;
                        GroupControl.GroupListView.Children.Add(PlayersListView);
                        if (g.IsOpen)
                        {
                            GroupControl.ExpandLabel.Content = "-";
                            GroupControl.GroupListView.Visibility = System.Windows.Visibility.Visible;
                        }
                        ChatListView.Children.Add(GroupControl);
                    }
                }
            }));
        }