Skip to content

Commit

Permalink
#50 separate chat control
Browse files Browse the repository at this point in the history
  • Loading branch information
tym32167 committed Nov 18, 2016
1 parent a9daa89 commit e8db904
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 133 deletions.
22 changes: 3 additions & 19 deletions src/Arma3BE.Client.Modules.ChatModule/Boxes/ChatHistory.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:boxes="clr-namespace:Arma3BE.Client.Modules.ChatModule.Boxes"
Title="Chat history"
WindowStyle="SingleBorderWindow" Width="750" Height="500"
WindowStartupLocation="CenterScreen">
Expand All @@ -15,38 +16,21 @@
</Grid.RowDefinitions>

<ToolBar>


<xctk:DropDownButton Content="Servers">
<xctk:DropDownButton.DropDownContent>
<xctk:CheckListBox ItemsSource="{Binding ServerList}" DisplayMemberPath="Name" ValueMemberPath="Id"
SelectedValue="{Binding SelectedServers}" />
</xctk:DropDownButton.DropDownContent>
</xctk:DropDownButton>


<xctk:DateTimePicker Value="{Binding StartDate, Mode=TwoWay}" Width="200" FormatString="dd.MM.yy HH:mm:ss" />
<xctk:DateTimePicker Value="{Binding EndDate, Mode=TwoWay}" Width="200" FormatString="dd.MM.yy HH:mm:ss" />
<xctk:WatermarkTextBox Watermark="Filter" Text="{Binding Filter, Mode=TwoWay}" Width="200" />
<Button Content="Search" Command="{Binding FilterCommand}" />
</ToolBar>

<ScrollViewer Grid.Row="1" Name="ChatScrollViewer" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

<RichTextBox Name="msgBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsReadOnly="True"
IsReadOnlyCaretVisible="False"
IsUndoEnabled="False" FontSize="14" FontWeight="Medium" FontStyle="Normal"
Background="#F0F0F0">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="LineHeight" Value="5" />
</Style>
</RichTextBox.Resources>
</RichTextBox>

</ScrollViewer>
<boxes:ColoredTextControl x:Name="textControl" IsAutoScroll="True" Grid.Row="1">
</boxes:ColoredTextControl>

</Grid>
</xctk:BusyIndicator>
Expand Down
28 changes: 2 additions & 26 deletions src/Arma3BE.Client.Modules.ChatModule/Boxes/ChatHistory.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
using Arma3BE.Server.Models;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using Arma3BE.Client.Infrastructure.Extensions;

namespace Arma3BE.Client.Modules.ChatModule.Boxes
{
Expand Down Expand Up @@ -36,33 +32,13 @@ private void _model_PropertyChanged(object sender, PropertyChangedEventArgs e)

private void Refresh()
{
msgBox.Document.Blocks.Clear();
var p = new Paragraph();
textControl.ClearAll();

foreach (var chatLog in _model.Log)
{
var mes = new ChatMessage { Date = chatLog.Date, Message = chatLog.Text };
AppendText(p, ChatScrollViewer, mes, chatLog.ServerName);
textControl.AppendText(mes, chatLog.ServerName);
}

msgBox.Document.Blocks.Add(p);
}

public void AppendText(Paragraph p, ScrollViewer scroll, ChatMessage message, string servername)
{
var text = string.Format("[{0}] [ {1:yyyy-MM-dd HH:mm:ss} ] {2}\n", servername, message.Date.UtcToLocalFromSettings(),
message.Message);
var color = ServerMonitorChatViewModel.GetMessageColor(message);
var brush = new SolidColorBrush(color);
var span = new Span { Foreground = brush };

if (message.Type != ChatMessage.MessageType.RCon && message.IsImportantMessage)
{
span.FontWeight = FontWeights.Heavy;
}

span.Inlines.Add(text);
p.Inlines.Add(span);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using Arma3BE.Client.Infrastructure.Extensions;
using Arma3BE.Client.Infrastructure.Events;
using Arma3BE.Client.Infrastructure.Events.Models;
using Arma3BE.Client.Infrastructure.Extensions;
using Arma3BE.Client.Modules.ChatModule.Models;
using Arma3BE.Server.Models;
using Microsoft.Practices.ServiceLocation;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
Expand Down Expand Up @@ -40,6 +45,9 @@ private void InitBox()
msgBox.Document.Blocks.Clear();
_paragraph = new Paragraph();
msgBox.Document.Blocks.Add(_paragraph);


msgBox.IsDocumentEnabled = true;
}

public void AppendText(ChatMessage message)
Expand All @@ -65,6 +73,65 @@ private void AppendText(Paragraph p, ScrollViewer scroll, ChatMessage message)
scroll.ScrollToEnd();
}

public void AppendText(ChatMessage message, string servername)
{
AppendText(_paragraph, message, servername);
}

private void AppendText(Paragraph p, ChatMessage message, string servername)
{
var text = string.Format("[{0}] [ {1:yyyy-MM-dd HH:mm:ss} ] {2}\n", servername, message.Date.UtcToLocalFromSettings(),
message.Message);
var color = ServerMonitorChatViewModel.GetMessageColor(message);
var brush = new SolidColorBrush(color);
var span = new Span { Foreground = brush };

if (message.Type != ChatMessage.MessageType.RCon && message.IsImportantMessage)
{
span.FontWeight = FontWeights.Heavy;
}

span.Inlines.Add(text);
p.Inlines.Add(span);
}


public void AppendPlayerText(KeyValuePair<string, string> player, bool isIn)
{
var text = $"[ {DateTime.UtcNow.UtcToLocalFromSettings():HH:mm:ss} ] ";

var p = new Paragraph
{
Margin = new Thickness(0),
Foreground = new SolidColorBrush(isIn ? Colors.Green : Colors.Red),
FontSize = 13
};
// remove indent between paragraphs

Hyperlink link = new Hyperlink { IsEnabled = true };
link.DataContext = player.Key;
link.Inlines.Add(player.Value);
link.NavigateUri = new Uri("http://local/");
link.RequestNavigate += (sender, args) =>
{
var context = (sender as FrameworkContentElement)?.DataContext as string;
if (string.IsNullOrEmpty(context) == false)
{
var aggregator = ServiceLocator.Current.TryResolve<IEventAggregator>();
aggregator.GetEvent<ShowUserInfoEvent>().Publish(new ShowUserModel(context));
}
};

p.Inlines.Add(text);
p.Inlines.Add(link);
p.Inlines.Add(new Run(isIn ? " Connected" : " Disconnected") { FontSize = 10 });

msgBox.Document.Blocks.Add(p);

if (IsAutoScroll)
ChatScrollViewer.ScrollToEnd();
}

public void ClearAll()
{
msgBox.Document.Blocks.Clear();
Expand Down
21 changes: 3 additions & 18 deletions src/Arma3BE.Client.Modules.ChatModule/Chat/ChatControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,15 @@

</TabItem>
<TabItem Header="Console">

<ScrollViewer Grid.ColumnSpan="2" Name="ConsoleScrollViewer">

<ScrollViewer Name="ConsoleScrollViewer">
<TextBox Name="msgConsole" FontSize="12" IsReadOnly="True" />

</ScrollViewer>
</TabItem>


<TabItem Header="Players Log">

<ScrollViewer Grid.ColumnSpan="2" Name="HistoryScrollViewer">

<RichTextBox Name="histBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
IsReadOnly="True" IsReadOnlyCaretVisible="False"
FontSize="14" FontWeight="Medium" FontStyle="Normal" Background="#F0F0F0">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0" />
</Style>
</RichTextBox.Resources>
</RichTextBox>

</ScrollViewer>
<boxes:ColoredTextControl x:Name="textPlayerControl" IsAutoScroll="{Binding AutoScroll}" >
</boxes:ColoredTextControl>
</TabItem>

</TabControl>
Expand Down
72 changes: 3 additions & 69 deletions src/Arma3BE.Client.Modules.ChatModule/Chat/ChatControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Arma3BE.Client.Infrastructure.Extensions;
using Arma3BE.Client.Modules.ChatModule.Models;
using Arma3BE.Server.Models;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace Arma3BE.Client.Modules.ChatModule.Chat
{
Expand All @@ -19,7 +16,6 @@ public partial class ChatControl : UserControl
public ChatControl()
{
InitializeComponent();
InitBox();
}

private ServerMonitorChatViewModel Model => DataContext as ServerMonitorChatViewModel;
Expand Down Expand Up @@ -48,30 +44,6 @@ private void SendMessage(object sender, RoutedEventArgs e)
}
}

private void InitBox()
{
histBox.Document.Blocks.Clear();
histBox.IsDocumentEnabled = true;
}

public void AppendText(Paragraph p, ScrollViewer scroll, ChatMessage message)
{
var text = $"[ {message.Date.UtcToLocalFromSettings():HH:mm:ss} ] {message.Message}\n";
var color = ServerMonitorChatViewModel.GetMessageColor(message);

var brush = new SolidColorBrush(color);
var span = new Span { Foreground = brush };
span.Inlines.Add(text);

if (message.Type != ChatMessage.MessageType.RCon && message.IsImportantMessage)
span.FontWeight = FontWeights.Heavy;

p.Inlines.Add(span);

if (Model.AutoScroll)
scroll.ScrollToEnd();
}

public void AppendText(TextBox block, ScrollViewer scroll, MessageBase message)
{
var text = $"[ {message.Date.UtcToLocalFromSettings():HH:mm:ss} ] {message.Message}\n";
Expand Down Expand Up @@ -99,7 +71,7 @@ private void ModelOnPlayersOutHandler(object sender, IEnumerable<KeyValuePair<st
if (!Model.EnableChat) return;
foreach (var pair in keyValuePairs)
{
AppendPlayerText(HistoryScrollViewer, pair, false);
textPlayerControl.AppendPlayerText(pair, false);
}

}
Expand All @@ -109,48 +81,10 @@ private void ModelOnPlayersInHandler(object sender, IEnumerable<KeyValuePair<str
if (!Model.EnableChat) return;
foreach (var pair in keyValuePairs)
{
AppendPlayerText(HistoryScrollViewer, pair, true);
textPlayerControl.AppendPlayerText(pair, true);
}
}



public void AppendPlayerText(ScrollViewer scroll, KeyValuePair<string, string> player, bool isIn)
{
var text = $"[ {DateTime.UtcNow.UtcToLocalFromSettings():HH:mm:ss} ] ";

var p = new Paragraph
{
Margin = new Thickness(0),
Foreground = new SolidColorBrush(isIn ? Colors.Green : Colors.Red),
FontSize = 13
};
// remove indent between paragraphs

Hyperlink link = new Hyperlink { IsEnabled = true };
link.DataContext = player.Key;
link.Inlines.Add(player.Value);
link.NavigateUri = new Uri("http://local/");
link.RequestNavigate += (sender, args) =>
{
var context = (sender as FrameworkContentElement)?.DataContext as string;
Model.ShowPlayer(context);
};

p.Inlines.Add(text);
p.Inlines.Add(link);
p.Inlines.Add(new Run(isIn ? " Connected" : " Disconnected") { FontSize = 10 });

histBox.Document.Blocks.Add(p);


if (Model.AutoScroll)
scroll.ScrollToEnd();
}




private void Model_LogMessageEventHandler(object sender, ServerMonitorLogViewModelEventArgs e)
{
Dispatcher.Invoke(() =>
Expand All @@ -162,7 +96,7 @@ private void Model_LogMessageEventHandler(object sender, ServerMonitorLogViewMod

private void ClearAll_Click(object sender, RoutedEventArgs e)
{
histBox.Document.Blocks.Clear();
textPlayerControl.ClearAll();
msgConsole.Text = string.Empty;
textControl.ClearAll();
}
Expand Down

0 comments on commit e8db904

Please sign in to comment.