コード例 #1
0
        public void Draw(Graphics g, Font font, Color foreColor)
        {
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            var  fbrush = new SolidBrush(foreColor);
            User user;

            if (!Program.TasClient.ExistingUsers.TryGetValue(userName, out user))
            {
                return;
            }
            var    x       = (int)1;
            var    y       = 3;
            Action newLine = () =>
            {
                x  = (int)1;
                y += (int)16;
            };
            Action <string> drawString = (text) =>
            {
                //y -= 3;
                x += ToolTipHandler.TEXT_X_OFFSET;
                TextRenderer.DrawText(g, text, font, new Point(x, y + ToolTipHandler.TEXT_Y_OFFSET), Config.TextColor, TextFormatFlags.LeftAndRightPadding);
                x += TextRenderer.MeasureText(g, text, font).Width;
                //y += 3;
            };

            Action <string, Color> drawString2 = (text, color) =>
            {
                //y -= 3;
                x += ToolTipHandler.TEXT_X_OFFSET;
                TextRenderer.DrawText(g, text, font, new Point(x, y + ToolTipHandler.TEXT_Y_OFFSET), color, TextFormatFlags.LeftAndRightPadding);
                x += TextRenderer.MeasureText(g, text, font).Width;
                //y += 3;
            };


            Action <Image, int, int> drawImage = (image, w, h) =>
            {
                g.DrawImage(image, x, y, (int)w, (int)h);
                x += (int)(w + 3);
            };

            using (var boldFont = new Font(font, FontStyle.Bold)) TextRenderer.DrawText(g, user.Name, boldFont, new Point(x, y), Config.TextColor, TextFormatFlags.LeftAndRightPadding);
            y += 3;
            newLine();

            if (!user.IsBot)
            {
                var clan = ServerImagesHandler.GetClanOrFactionImage(user);
                if (clan.Item1 != null)
                {
                    drawImage(clan.Item1, 16, 16);
                    drawString2(clan.Item2, Utils.GetFactionColor(user.Faction));
                    newLine();
                }
            }

            Image flag;

            if (Images.CountryFlags.TryGetValue(user.Country, out flag) && flag != null)
            {
                //drawString("Country: ");
                y += 2;
                drawImage(flag, flag.Width, flag.Height);
                y -= 2;
                drawString(CountryNames.GetName(user.Country));
                newLine();
            }
            if (user.IsBot)
            {
                drawImage(ZklResources.robot, 16, 16);
                drawString("Bot");
                newLine();
            }
            if (user.Name == Program.TasClient.MyBattle?.FounderName)
            {
                drawImage(ZklResources.self_police, 16, 16);
                drawString("Battle founder");
                newLine();
            }
            if (user.IsAdmin)
            {
                drawImage(ZklResources.police, 16, 16);
                drawString("Administrator");
                newLine();
            }
            if (Program.TasClient.Friends.Contains(user.Name))
            {
                drawImage(ZklResources.friend, 16, 16);
                drawString("Friend");
                newLine();
            }
            if (user.SteamID != null)
            {
                drawImage(ZklResources.steam, 16, 16);
                drawString(string.Format("Steam name: {0}", user.DisplayName ?? user.Name));
                newLine();
            }
            if (!user.IsBot)
            {
                drawImage(Images.GetRank(user.Level, user.EffectiveMmElo), 16, 16);
                drawString(string.Format("Level: {0}", user.Level));
                newLine();
                if (user.AwaySince.HasValue)
                {
                    drawImage(ZklResources.away, 16, 16);
                    drawString("User idle for " + DateTime.UtcNow.Subtract(user.AwaySince.Value).PrintTimeRemaining() + ".");
                    newLine();
                }
                if (user.IsInGame)
                {
                    drawImage(Buttons.fight, 16, 16);
                    if (user.InGameSince != null)
                    {
                        var time = DateTime.UtcNow.Subtract(user.InGameSince.Value).PrintTimeRemaining();
                        drawString("Playing since " + time + " ago.");
                    }
                    newLine();
                }
                if (!string.IsNullOrEmpty(user.Avatar))
                {
                    var image = Program.ServerImages.GetAvatarImage(user);
                    if (image != null)
                    {
                        g.DrawImage(image, (int)(302 - 65), 0, (int)64, (int)64);
                    }
                }
            }
            if (user.IsInBattleRoom)
            {
                if (y < 70)
                {
                    y = 70;
                }
                if (user.IsInBattleRoom)
                {
                    var battleIcon = Program.BattleIconManager.GetBattleIcon(user.BattleID ?? 0);
                    if (battleIcon != null)
                    {
                        g.DrawImageUnscaled(battleIcon.Image, x, y);
                    }
                }
            }
            fbrush.Dispose();
        }
コード例 #2
0
        void FilterPlayers()
        {
            if (!filtering)
            {
                return;
            }
            playerBox.BeginUpdate();
            var words = playerSearchBox.Text.ToUpper().Split(' ');

            foreach (var playerListItem in PlayerListItems)
            {
                var user  = playerListItem.User;
                var match = true;
                foreach (var iteratedWord in words)
                {
                    var word     = iteratedWord;
                    var negation = false;
                    if (word.StartsWith("-"))
                    {
                        negation = true;
                        word     = word.Substring(1);
                    }

                    if (String.IsNullOrEmpty(word))
                    {
                        continue;
                    }

                    bool isSpecialWordMatch;
                    if (FilterSpecialWordCheck(user, word, out isSpecialWordMatch))
                    {
                        if ((!negation && !isSpecialWordMatch) || (negation && isSpecialWordMatch))
                        {
                            match = false;
                            break;
                        }
                    }
                    else
                    {
                        var userNameFound    = playerListItem.UserName.ToUpper().Contains(word);
                        var countryFound     = user.Country.ToUpper() == word;
                        var countryNameFound = CountryNames.GetName(user.Country).ToUpper() == word;
                        var clanFound        = user.Clan != null && user.Clan.ToUpper() == word;
                        var factionFound     = user.Faction != null && user.Faction.ToUpper() == word;
                        if (!negation)
                        {
                            if (!(userNameFound || countryFound || countryNameFound || clanFound || factionFound))
                            {
                                match = false;
                                break;
                            }
                        }
                        else
                        {
                            if ((userNameFound || countryFound || countryNameFound || clanFound || factionFound))
                            {
                                match = false;
                                break;
                            }
                        }
                    }
                }
                if (match)
                {
                    playerListItem.SortCategory = (int)PlayerListItem.SortCats.SearchMatchedPlayer;
                    playerListItem.IsGrayedOut  = false;
                }
                else
                {
                    playerListItem.SortCategory = (int)PlayerListItem.SortCats.SearchNoMatchPlayer;
                    playerListItem.IsGrayedOut  = true;
                }
            }
            playerBox.Sorted = false;
            playerBox.Sorted = true;
            playerBox.EndUpdate();
        }
コード例 #3
0
        public void Draw(Graphics g, Font font, Color foreColor)
        {
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            User user;

            if (!Program.TasClient.ExistingUsers.TryGetValue(userName, out user))
            {
                return;
            }
            DpiMeasurement.DpiXYMeasurement();
            var    x       = DpiMeasurement.ScaleValueX(1);
            var    y       = 0;
            Action newLine = () =>
            {
                x  = DpiMeasurement.ScaleValueX(1);
                y += DpiMeasurement.ScaleValueY(16);
            };
            Action <string> drawString = (text) =>
            {
                TextRenderer.DrawText(g, text, font, new Point(x, y), foreColor);
                x += (int)Math.Ceiling((double)TextRenderer.MeasureText(g, text, font).Width);     //Note: TextRenderer measurement already DPI aware
            };

            Action <string, Color> drawString2 = (text, color) =>
            {
                TextRenderer.DrawText(g, text, font, new Point(x, y), color);
                x += (int)Math.Ceiling((double)TextRenderer.MeasureText(g, text, font).Width); //Note: TextRenderer measurement already DPI aware
            };


            Action <Image, int, int> drawImage = (image, w, h) =>
            {
                g.DrawImage(image, x, y, DpiMeasurement.ScaleValueX(w), DpiMeasurement.ScaleValueY(h));
                x += DpiMeasurement.ScaleValueX(w + 3);
            };

            using (var boldFont = new Font(font, FontStyle.Bold)) TextRenderer.DrawText(g, user.Name, boldFont, new Point(x, y), foreColor);

            newLine();

            if (!user.IsBot)
            {
                var clan = ServerImagesHandler.GetClanOrFactionImage(user);
                if (clan.Item1 != null)
                {
                    drawImage(clan.Item1, 16, 16);
                    drawString2(clan.Item2, Utils.GetFactionColor(user.Faction));
                    newLine();
                }
            }

            Image flag;

            if (Images.CountryFlags.TryGetValue(user.Country, out flag) && flag != null)
            {
                drawString("Country: ");
                drawImage(flag, flag.Width, flag.Height);
                drawString(CountryNames.GetName(user.Country));
                newLine();
            }
            if (user.IsBot)
            {
                drawImage(ZklResources.robot, 16, 16);
                drawString("Bot");
                newLine();
            }
            if (user.IsAdmin)
            {
                drawImage(ZklResources.police, 16, 16);
                drawString("Administrator");
                newLine();
            }
            if (Program.FriendManager.Friends.Contains(user.Name))
            {
                drawImage(ZklResources.friend, 16, 16);
                drawString("Friend");
                newLine();
            }
            if (user.SteamID != null)
            {
                drawImage(ZklResources.steam, 16, 16);
                drawString(string.Format("Steam name: {0}", user.DisplayName ?? user.Name));
                newLine();
            }
            if (!user.IsBot)
            {
                drawImage(Images.GetRank(user.Level), 16, 16);
                drawString(string.Format("Level: {0}", user.Level));
                newLine();
                if (user.AwaySince.HasValue)
                {
                    drawImage(ZklResources.away, 16, 16);
                    drawString("User has been idle for " + DateTime.UtcNow.Subtract(user.AwaySince.Value).PrintTimeRemaining() + ".");
                    newLine();
                }
                if (user.IsInGame)
                {
                    drawImage(ZklResources.ingame, 16, 16);
                    if (user.InGameSince != null)
                    {
                        var time = DateTime.UtcNow.Subtract(user.InGameSince.Value).PrintTimeRemaining();
                        drawString("Playing since " + time + " ago.");
                    }
                    newLine();
                }
                var top10 = Program.SpringieServer.GetTop10Rank(user.Name);
                if (top10 > 0)
                {
                    drawImage(ZklResources.cup, 16, 16);
                    drawString(string.Format("Top 10 Rank: {0}.", top10));
                    newLine();
                }
                if (!string.IsNullOrEmpty(user.Avatar))
                {
                    var image = Program.ServerImages.GetAvatarImage(user);
                    if (image != null)
                    {
                        g.DrawImage(image, DpiMeasurement.ScaleValueX(302 - 65), 0, DpiMeasurement.ScaleValueX(64), DpiMeasurement.ScaleValueY(64));
                    }
                }
            }
            if (user.IsInBattleRoom)
            {
                var battle = Program.TasClient.ExistingBattles.Values.FirstOrDefault(b => b.Users.ContainsKey(user.Name));
                if (battle != null)
                {
                    var battleIcon = Program.BattleIconManager.GetBattleIcon(battle.BattleID);
                    if (battleIcon != null)
                    {
                        g.DrawImageUnscaled(battleIcon.Image, x, y);
                    }
                }
            }
        }