Chatnachrichten werden jetzt angezeigt
This commit is contained in:
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
|
||||
{
|
||||
private ChatInputBox ChatInput;
|
||||
private TextBox ChatOutput;
|
||||
private ChatOutputBox ChatOutput;
|
||||
private IBackend Backend;
|
||||
|
||||
public ChatPanel (IBackend backend)
|
||||
@@ -14,9 +14,7 @@ namespace WorldOfPeacecraft
|
||||
Backend = backend;
|
||||
ChatInput = new ChatInputBox ();
|
||||
ChatInput.ChatMessageSubmitted += OnChatMessageSent;
|
||||
ChatOutput = new TextBox ();
|
||||
ChatOutput.ReadOnly = true;
|
||||
ChatOutput.Multiline = true;
|
||||
ChatOutput = new ChatOutputBox (backend);
|
||||
|
||||
this.Controls.Add (ChatInput);
|
||||
this.Controls.Add (ChatOutput);
|
||||
@@ -42,5 +40,10 @@ namespace WorldOfPeacecraft
|
||||
}
|
||||
// TODO Move focus to board?
|
||||
}
|
||||
|
||||
public void UpdateData()
|
||||
{
|
||||
ChatOutput.UpdateData ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ namespace WorldOfPeacecraft
|
||||
ChatPanel.Size = new Size (ChatWidth, mapHeight);
|
||||
this.ResumeLayout();
|
||||
this.PerformLayout();
|
||||
ChatPanel.UpdateData ();
|
||||
this.Refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace WorldOfPeacecraft
|
||||
|
||||
IEnumerable<IPositionable> GetDragons();
|
||||
|
||||
IEnumerable<IChatMessage> GetChatMessages();
|
||||
|
||||
void SendChatMessage (string message);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user