Пример #1
0
        protected SolidColorBrush GetBrush(ICharacter character)
        {
            if (Permissions != null && Permissions.IsModerator(character.Name))
            {
                return((SolidColorBrush)Application.Current.FindResource("ModeratorBrush"));
            }

            if (characters != null && characters.IsOnList(character.Name, ListKind.NotInterested))
            {
                return((SolidColorBrush)Application.Current.FindResource("NotAvailableBrush"));
            }

            var normalColorName = character.IsInteresting && ApplicationSettings.AllowOfInterestColoring
                ? "Contrast"
                : GetGenderName(character.Gender);

            if (!ApplicationSettings.AllowStatusDiscolor)
            {
                return((SolidColorBrush)TryGet(normalColorName, true));
            }

            if (character.Status == StatusType.Crown ||
                character.Status == StatusType.Online ||
                character.Status == StatusType.Looking)
            {
                return((SolidColorBrush)TryGet(normalColorName, true));
            }

            return((SolidColorBrush)Application.Current.FindResource("NotAvailableBrush"));
        }
Пример #2
0
        public object Convert(object value, Type type, object parameter, CultureInfo cultureInfo)
        {
            var inlines = new List <Inline>();

            if (value == null)
            {
                return(null);
            }

            var message = value as IMessage; // this is the beef of the message
            var text    = message == null ? value as string : message.Message;

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            // show more logic
            if (message != null)
            {
                // we don't want to collapse only one small sentence
                const int wiggleRoom = 75;

                if (message.Type == MessageType.Ad &&
                    text.Length > (ApplicationSettings.ShowMoreInAdsLength + wiggleRoom))
                {
                    // try to find a nice sentence to break after
                    var start = ApplicationSettings.ShowMoreInAdsLength;
                    do
                    {
                        if (char.IsPunctuation(text[start]) && char.IsWhiteSpace(text[start + 1]))
                        {
                            break;
                        }
                        start--;
                    } while (start != 0);

                    // if we didn't find one, just aggressively break at our point
                    if (start == 0)
                    {
                        start = ApplicationSettings.ShowMoreInAdsLength;
                        do
                        {
                            if (char.IsWhiteSpace(text[start]))
                            {
                                break;
                            }
                            start--;
                        } while (start != 0);
                    }

                    if (start != 0)
                    {
                        var sb = new StringBuilder(text);
                        sb.Insert(start + 1, "[collapse=Read More]");
                        sb.Append("[/collapse]");
                        text = sb.ToString();
                    }
                }
            }


            text = HttpUtility.HtmlDecode(text); // translate the HTML characters

            if (text[0] == '/')
            {
                var check   = text.Substring(0, text.IndexOf(' ') + 1);
                var command = ' ';
                Func <string, string> nonCommandCommand;

                if (CommandDefinitions.NonCommandCommands.TryGetValue(check, out nonCommandCommand))
                {
                    command = text[1];
                    text    = nonCommandCommand(text);
                }

                if (command == 'w' && permissions.IsModerator(message.Poster.Name))
                {
                    // a warn "command" gets a different appearance
                    var toAdd = Parse(text);
                    toAdd.Foreground = Locator.Find <Brush>("ModeratorBrush");
                    toAdd.FontWeight = FontWeights.Medium;
                    inlines.Add(toAdd);
                }
                else if (command == 'm') // is an emote
                {
                    inlines.Add(new Italic(Parse(text)));
                }
                else
                {
                    inlines.Add(new Run(" : "));
                    inlines.Add(Parse(text));
                }

                return(inlines);
            }
            inlines.Add(new Run(": "));
            inlines.Add(Parse(text));
            return(inlines);
        }