-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
173 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Arma3BE.Client.Modules.ChatModule/Boxes/IColoredTextControl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
using Arma3BE.Server.Models; | ||
|
||
namespace Arma3BE.Client.Modules.ChatModule.Boxes | ||
{ | ||
public interface IColoredTextControl | ||
{ | ||
bool IsAutoScroll { get; set; } | ||
|
||
void AppendPlayerText(KeyValuePair<string, string> player, bool isIn); | ||
void AppendText(ChatMessage message, string servername = null); | ||
void ClearAll(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Arma3BE.Client.Modules.ChatModule/Boxes/RTBControl.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<UserControl x:Class="Arma3BE.Client.Modules.ChatModule.Boxes.RTBControl" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" | ||
mc:Ignorable="d" > | ||
<WindowsFormsHost> | ||
<forms:RichTextBox x:Name="rtb" ReadOnly="True"></forms:RichTextBox> | ||
</WindowsFormsHost> | ||
</UserControl> |
106 changes: 106 additions & 0 deletions
106
src/Arma3BE.Client.Modules.ChatModule/Boxes/RTBControl.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using Arma3BE.Client.Infrastructure.Extensions; | ||
using Arma3BE.Client.Modules.ChatModule.Models; | ||
using Arma3BE.Server.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace Arma3BE.Client.Modules.ChatModule.Boxes | ||
{ | ||
/// <summary> | ||
/// Interaction logic for RTBControl.xaml | ||
/// </summary> | ||
public partial class RTBControl : UserControl, IColoredTextControl | ||
{ | ||
public static readonly DependencyProperty IsAutoScrollProperty = | ||
DependencyProperty.Register("IsAutoScroll", typeof(bool), typeof(RTBControl), | ||
new FrameworkPropertyMetadata(false)); | ||
|
||
public RTBControl() | ||
{ | ||
InitializeComponent(); | ||
|
||
rtb.Font = new Font(rtb.Font.FontFamily, 12); | ||
} | ||
|
||
|
||
public bool IsAutoScroll | ||
{ | ||
get { return (bool)GetValue(IsAutoScrollProperty); } | ||
set { SetValue(IsAutoScrollProperty, value); } | ||
} | ||
|
||
public void AppendPlayerText(KeyValuePair<string, string> player, bool isIn) | ||
{ | ||
} | ||
|
||
|
||
|
||
[System.Runtime.InteropServices.DllImport("user32.dll")] | ||
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam); | ||
const int WM_USER = 0x400; | ||
const int EM_HIDESELECTION = WM_USER + 63; | ||
|
||
public void AppendText(ChatMessage message, string servername = null) | ||
{ | ||
string text; | ||
|
||
if (string.IsNullOrEmpty(servername)) | ||
{ | ||
text = $"[ {message.Date.UtcToLocalFromSettings():HH:mm:ss} ] {message.Message}\n"; | ||
} | ||
else | ||
{ | ||
text = | ||
$"[{servername}] [ {message.Date.UtcToLocalFromSettings():yyyy-MM-dd HH:mm:ss} ] {message.Message}\n"; | ||
} | ||
|
||
var color = ServerMonitorChatViewModel.GetMessageColor(message); | ||
var wformsColor = Color.FromArgb(color.A, color.R, color.G, color.B); | ||
|
||
|
||
|
||
var selection = rtb.SelectionStart; | ||
var length = rtb.SelectionLength; | ||
|
||
|
||
if (!IsAutoScroll) | ||
{ | ||
SendMessage(rtb.Handle, EM_HIDESELECTION, 1, 0); | ||
} | ||
|
||
|
||
rtb.AppendText(text); | ||
|
||
rtb.Select(rtb.TextLength - text.Length, text.Length); | ||
rtb.SelectionColor = wformsColor; | ||
|
||
|
||
if (message.Type != ChatMessage.MessageType.RCon && message.IsImportantMessage) | ||
rtb.SelectionFont = new Font(rtb.SelectionFont, System.Drawing.FontStyle.Bold); | ||
|
||
if (length != 0) | ||
{ | ||
rtb.SelectionStart = selection; | ||
rtb.SelectionLength = length; | ||
} | ||
else | ||
{ | ||
rtb.Select(rtb.TextLength, 0); | ||
} | ||
|
||
|
||
if (!IsAutoScroll) | ||
{ | ||
SendMessage(rtb.Handle, EM_HIDESELECTION, 0, 0); | ||
} | ||
} | ||
|
||
public void ClearAll() | ||
{ | ||
rtb.Clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters