Chatnachrichten werden jetzt angezeigt
This commit is contained in:
@@ -78,6 +78,8 @@
|
|||||||
<Compile Include="src\Gui\IGui.cs" />
|
<Compile Include="src\Gui\IGui.cs" />
|
||||||
<Compile Include="src\Gui\ChatPanel.cs" />
|
<Compile Include="src\Gui\ChatPanel.cs" />
|
||||||
<Compile Include="src\Gui\ChatInputBox.cs" />
|
<Compile Include="src\Gui\ChatInputBox.cs" />
|
||||||
|
<Compile Include="src\Gui\ChatOutputBox.cs" />
|
||||||
|
<Compile Include="src\Gui\IChatMessage.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace WorldOfPeacecraft
|
|||||||
private TcpClient Client;
|
private TcpClient Client;
|
||||||
private Dictionary<int, Dragon> Dragons;
|
private Dictionary<int, Dragon> Dragons;
|
||||||
private Dictionary<int, Player> Players;
|
private Dictionary<int, Player> Players;
|
||||||
|
private LinkedList<Message> ChatMessages;
|
||||||
private Map Map;
|
private Map Map;
|
||||||
private Buffer SenderBuffer;
|
private Buffer SenderBuffer;
|
||||||
private IGui Gui;
|
private IGui Gui;
|
||||||
@@ -21,6 +22,7 @@ namespace WorldOfPeacecraft
|
|||||||
Gui = gui;
|
Gui = gui;
|
||||||
Dragons = new Dictionary<int, Dragon> ();
|
Dragons = new Dictionary<int, Dragon> ();
|
||||||
Players = new Dictionary<int, Player> ();
|
Players = new Dictionary<int, Player> ();
|
||||||
|
ChatMessages = new LinkedList<Message> ();
|
||||||
Client = new TcpClient ("localhost", 9999);
|
Client = new TcpClient ("localhost", 9999);
|
||||||
Buffer receiverBuffer = new Buffer(10000);
|
Buffer receiverBuffer = new Buffer(10000);
|
||||||
SenderBuffer = new Buffer(100);
|
SenderBuffer = new Buffer(100);
|
||||||
@@ -99,6 +101,16 @@ namespace WorldOfPeacecraft
|
|||||||
return Map.GetTiles ();
|
return Map.GetTiles ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddChatMessage (Message message)
|
||||||
|
{
|
||||||
|
ChatMessages.AddLast (message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IChatMessage> GetChatMessages ()
|
||||||
|
{
|
||||||
|
return ChatMessages;
|
||||||
|
}
|
||||||
|
|
||||||
public void SendCommand (string command)
|
public void SendCommand (string command)
|
||||||
{
|
{
|
||||||
SenderBuffer.AddLine (command);
|
SenderBuffer.AddLine (command);
|
||||||
|
|||||||
52
src/Gui/ChatOutputBox.cs
Normal file
52
src/Gui/ChatOutputBox.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace WorldOfPeacecraft
|
||||||
|
{
|
||||||
|
public class ChatOutputBox : RichTextBox
|
||||||
|
{
|
||||||
|
private IBackend Backend;
|
||||||
|
private Font MessageFont;
|
||||||
|
private Font SenderFont;
|
||||||
|
private Font IregularSenderFont;
|
||||||
|
|
||||||
|
public ChatOutputBox (IBackend backend)
|
||||||
|
{
|
||||||
|
Backend = backend;
|
||||||
|
this.ReadOnly = true;
|
||||||
|
this.Multiline = true;
|
||||||
|
MessageFont = this.SelectionFont;
|
||||||
|
SenderFont = new Font (MessageFont, FontStyle.Bold);
|
||||||
|
IregularSenderFont = new Font (MessageFont, FontStyle.Bold | FontStyle.Italic);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateData ()
|
||||||
|
{
|
||||||
|
this.SuspendLayout ();
|
||||||
|
this.Clear ();
|
||||||
|
IEnumerable<IChatMessage> chatMessages = Backend.GetChatMessages ();
|
||||||
|
bool firstline = true;
|
||||||
|
lock (Backend) {
|
||||||
|
foreach (IChatMessage message in chatMessages) {
|
||||||
|
if (firstline) {
|
||||||
|
firstline = false;
|
||||||
|
} else {
|
||||||
|
this.AppendText ("\n");
|
||||||
|
}
|
||||||
|
if (message.IsSenderPlayer ()) {
|
||||||
|
this.SelectionFont = SenderFont;
|
||||||
|
} else {
|
||||||
|
this.SelectionFont = IregularSenderFont;
|
||||||
|
}
|
||||||
|
this.AppendText (message.GetSender ());
|
||||||
|
this.AppendText (": ");
|
||||||
|
this.SelectionFont = MessageFont;
|
||||||
|
this.AppendText (message.GetMessage ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.ResumeLayout ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ namespace WorldOfPeacecraft
|
|||||||
public class ChatPanel : Panel
|
public class ChatPanel : Panel
|
||||||
{
|
{
|
||||||
private ChatInputBox ChatInput;
|
private ChatInputBox ChatInput;
|
||||||
private TextBox ChatOutput;
|
private ChatOutputBox ChatOutput;
|
||||||
private IBackend Backend;
|
private IBackend Backend;
|
||||||
|
|
||||||
public ChatPanel (IBackend backend)
|
public ChatPanel (IBackend backend)
|
||||||
@@ -14,9 +14,7 @@ namespace WorldOfPeacecraft
|
|||||||
Backend = backend;
|
Backend = backend;
|
||||||
ChatInput = new ChatInputBox ();
|
ChatInput = new ChatInputBox ();
|
||||||
ChatInput.ChatMessageSubmitted += OnChatMessageSent;
|
ChatInput.ChatMessageSubmitted += OnChatMessageSent;
|
||||||
ChatOutput = new TextBox ();
|
ChatOutput = new ChatOutputBox (backend);
|
||||||
ChatOutput.ReadOnly = true;
|
|
||||||
ChatOutput.Multiline = true;
|
|
||||||
|
|
||||||
this.Controls.Add (ChatInput);
|
this.Controls.Add (ChatInput);
|
||||||
this.Controls.Add (ChatOutput);
|
this.Controls.Add (ChatOutput);
|
||||||
@@ -42,5 +40,10 @@ namespace WorldOfPeacecraft
|
|||||||
}
|
}
|
||||||
// TODO Move focus to board?
|
// TODO Move focus to board?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateData()
|
||||||
|
{
|
||||||
|
ChatOutput.UpdateData ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ namespace WorldOfPeacecraft
|
|||||||
ChatPanel.Size = new Size (ChatWidth, mapHeight);
|
ChatPanel.Size = new Size (ChatWidth, mapHeight);
|
||||||
this.ResumeLayout();
|
this.ResumeLayout();
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
ChatPanel.UpdateData ();
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace WorldOfPeacecraft
|
|||||||
|
|
||||||
IEnumerable<IPositionable> GetDragons();
|
IEnumerable<IPositionable> GetDragons();
|
||||||
|
|
||||||
|
IEnumerable<IChatMessage> GetChatMessages();
|
||||||
|
|
||||||
void SendChatMessage (string message);
|
void SendChatMessage (string message);
|
||||||
|
|
||||||
void SendCommand (string command);
|
void SendCommand (string command);
|
||||||
|
|||||||
11
src/Gui/IChatMessage.cs
Normal file
11
src/Gui/IChatMessage.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace WorldOfPeacecraft
|
||||||
|
{
|
||||||
|
public interface IChatMessage
|
||||||
|
{
|
||||||
|
string GetMessage();
|
||||||
|
|
||||||
|
string GetSender();
|
||||||
|
|
||||||
|
bool IsSenderPlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace WorldOfPeacecraft
|
namespace WorldOfPeacecraft
|
||||||
{
|
{
|
||||||
public class Message
|
public class Message : IChatMessage
|
||||||
{
|
{
|
||||||
int sourceID;
|
int sourceID;
|
||||||
string source;
|
string source;
|
||||||
@@ -14,6 +14,21 @@ namespace WorldOfPeacecraft
|
|||||||
source = src;
|
source = src;
|
||||||
text = txt;
|
text = txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetMessage()
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetSender()
|
||||||
|
{
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsSenderPlayer ()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,10 @@ namespace WorldOfPeacecraft
|
|||||||
int srcid = mesBlock.GetIntValue (ValueSourceId);
|
int srcid = mesBlock.GetIntValue (ValueSourceId);
|
||||||
string src = mesBlock.GetStringValue (ValueSource);
|
string src = mesBlock.GetStringValue (ValueSource);
|
||||||
string txt = mesBlock.GetStringValue (ValueText);
|
string txt = mesBlock.GetStringValue (ValueText);
|
||||||
Message m = new Message (srcid, src, txt);
|
lock (Backend) {
|
||||||
|
Backend.AddChatMessage (new Message (srcid, src, txt));
|
||||||
|
}
|
||||||
|
Backend.RefreshGui ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessAnswer (Block block)
|
private void ProcessAnswer (Block block)
|
||||||
|
|||||||
Reference in New Issue
Block a user