Esempio n. 1
0
        public void SendMessage(string Text, Player Speaker = null, bool Host = false)
        {
            if (CurrentRoom.IsHost(App.CurrentUser))
            {
                foreach (var Client in App.Server)
                {
                    Client.SendAsync(Encoding.UTF8.GetBytes("ChatMessage|*|" +
                                                            (Speaker?.Id.ToString() ?? "System") + "|*|" + Text));
                }
            }
            else
            {
                App.Client.SendAsync(Encoding.UTF8.GetBytes("ChatMessage|*|" +
                                                            (Speaker?.Id.ToString() ?? "System") + "|*|" + Text));
            }

            bool        ScrollToBottom = ChatScrollViewer.HorizontalOffset >= ChatStack.ActualHeight - ChatScrollViewer.ActualHeight;
            ChatterItem Item           = new ChatterItem();

            Item.Init(Text, Speaker, Host);

            Item.Opacity = 0;
            ChatStack.Children.Add(Item);
            var HeightAnimation = new DoubleAnimation()
            {
                From           = ChatStack.ActualHeight,
                To             = ChatStack.Children.OfType <FrameworkElement>().Sum(O => O.Height),
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            };

            HeightAnimation.Completed += delegate
            {
                Item.BeginAnimation(OpacityProperty, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 1,
                    Duration       = TimeSpan.FromSeconds(0.2),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    }
                });
                if (ScrollToBottom)
                {
                    ChatScrollViewer.ScrollToBottom();
                }
            };
            ChatStack.BeginAnimation(HeightProperty, HeightAnimation);
        }
Esempio n. 2
0
        public void SendMessageAlone(string Text, Player Speaker = null, bool Host = false)
        {
            bool        ScrollToBottom = ChatScrollViewer.HorizontalOffset >= ChatStack.ActualHeight - ChatScrollViewer.ActualHeight;
            ChatterItem Item           = new ChatterItem();

            Item.Init(Text, Speaker, Host);

            Item.Opacity = 0;
            ChatStack.Children.Add(Item);
            var HeightAnimation = new DoubleAnimation()
            {
                From           = ChatStack.ActualHeight,
                To             = ChatStack.Children.OfType <FrameworkElement>().Sum(O => O.Height),
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            };

            HeightAnimation.Completed += delegate
            {
                Item.BeginAnimation(OpacityProperty, new DoubleAnimation()
                {
                    From           = 0,
                    To             = 1,
                    Duration       = TimeSpan.FromSeconds(0.2),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    }
                });
                if (ScrollToBottom)
                {
                    ChatScrollViewer.ScrollToBottom();
                }
            };
            ChatStack.BeginAnimation(HeightProperty, HeightAnimation);
        }