Exemplo n.º 1
0
        /// <summary>
        /// Renders the specified chat node to the client.
        /// </summary>
        /// <param name="node">The node to append.</param>
        /// <remarks>
        /// <para>The return value of this function is a reference to the outermost <see cref="HtmlElement">HtmlElement</see> constructed
        /// by this function.  It may create additional inner elements as needed.</para>
        /// </remarks>
        /// <returns>
        /// Returns an object instance of <see cref="HtmlElement">HtmlElement</see> that can be appended to the HTML document.
        /// </returns>
        public override Inline Render(ChatNode node)
        {
            IIconProvider provider = ProfileResourceProvider.GetForClient(null).Icons;

            ImageChatNode icn = node as ImageChatNode;

            if (icn != null)
            {
                InlineUIContainer result = new InlineUIContainer();
                Image             img    = new Image();
                img.Source  = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap((icn.Image as System.Drawing.Bitmap).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                img.ToolTip = icn.Text;
                img.Width   = provider.IconSize.Width;
                img.Height  = provider.IconSize.Height;

                result.Child = img;

                if (icn.LinkUri != null)
                {
                    Hyperlink container = new Hyperlink(result);
                    container.NavigateUri = node.LinkUri;
                    container.ToolTip     = string.Format(CultureInfo.CurrentUICulture, "Link to {0}", node.LinkUri);

                    return(container);
                }

                return(result);
            }
            else
            {
                return(base.Render(node));
            }
        }
Exemplo n.º 2
0
        private void AnnounceUser(UserEventArgs e)
        {
            ChatUser user = e.User;
            UserStats us = e.User.Stats;
            string imgID = m_prp.Icons.GetImageIdFor(user.Flags, us);
            ChatNode productNode = ChatNode.Empty;
            if (m_profile.IncludeIconsInChat)
            {
                Image img = m_prp.Icons.GetImageFor(user.Flags, us);
                productNode = new ImageChatNode(string.Concat(imgID, ".jpg"),
                    img, imgID);
            }

            switch (us.Product.ProductCode)
            {
                case "DRTL":
                case "DSHR":
                case "SSHR":
                case "STAR":
                case "SEXP":
                case "JSTR":
                case "W2BN":
                    StarcraftStats ss = us as StarcraftStats;
                    if (ss == null)
                        chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode,
                            new ChatNode(string.Format(" joined the channel with {0}.", us.Product.Name), CssClasses.JoinedChannel));
                    else
                    {
                        chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode, new ChatNode(string.Format(" joined the channel with {0} ({1} win{2}, ladder rating {3}, rank {4}).", ss.Product.Name, ss.Wins, ss.Wins != 1 ? "s" : string.Empty,
                            ss.LadderRating, ss.LadderRank), CssClasses.JoinedChannel));
                    }
                    break;
                case "D2DV":
                case "D2XP":
                    Diablo2Stats ds = us as Diablo2Stats;
                    if (ds == null)
                        chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode, new ChatNode(string.Format(" joined the channel with {0}.", us.Product.Name), CssClasses.JoinedChannel));
                    else
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(" joined the channel with ");
                        sb.Append(ds.Product.Name);
                        if (ds.IsRealmCharacter)
                        {
                            sb.Append(" as ");
                            sb.Append(ds.CharacterName);
                            sb.AppendFormat(", a level {0}", ds.Level);
                            if (ds.IsHardcoreCharacter)
                                sb.Append(" hardcore");
                            if (ds.IsLadderCharacter)
                                sb.Append(" ladder");
                            if (ds.IsExpansionCharacter)
                                sb.Append(" Expansion ");
                            else
                                sb.Append(" Classic ");
                            sb.Append(ds.CharacterClass);
                            sb.Append(".");

                            chat.AddChat(new ChatNode(ds.UserName, CssClasses.UsernameOther), new ChatNode(sb.ToString(), CssClasses.JoinedChannel));
                        }
                        else
                        {
                            chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode, new ChatNode(string.Format(" joined the channel with {0}.", us.Product.Name), CssClasses.JoinedChannel));
                        }
                    }
                    break;
                case "WAR3":
                case "W3XP":
                    Warcraft3Stats ws = us as Warcraft3Stats;
                    if (ws == null)
                        chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode, new ChatNode(string.Format(" joined the channel with {0}.", us.Product.Name), CssClasses.JoinedChannel));
                    else
                    {
                        if (string.IsNullOrEmpty(ws.ClanTag))
                        {
                            chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode, new ChatNode(string.Format(" joined the channel with {0}, {1} icon tier {2}, level {3}.", ws.Product.Name, ws.IconRace, ws.IconTier, ws.Level), CssClasses.JoinedChannel));
                        }
                        else
                        {
                            chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode, new ChatNode(string.Format(" of clan {0} joined the channel with {1}, {2} icon tier {3}, level {4}.", ws.ClanTag, ws.Product.Name, ws.IconRace, ws.IconTier, ws.Level), CssClasses.JoinedChannel));
                        }
                    }
                    break;
                default:
                    chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), productNode, new ChatNode(string.Format(" joined the channel with {0} ({1}).", us.Product.Name, us.LiteralText), CssClasses.JoinedChannel));
                    break;

            }
            if (user.Flags != UserFlags.None)
            {
                chat.AddChat(new ChatNode(user.Username, CssClasses.UsernameOther), new ChatNode(string.Format(" had the following flags: {0}", user.Flags), CssClasses.JoinedChannel));
            }
        }