diff --git a/inf3.csproj b/inf3.csproj
index 9f8ef15..d71f91a 100644
--- a/inf3.csproj
+++ b/inf3.csproj
@@ -9,26 +9,27 @@
Exe
inf3
inf3
+ v4.0
- true
+ True
full
- false
+ False
bin\Debug
DEBUG;
prompt
4
x86
- false
+ False
none
- true
+ True
bin\Release
prompt
4
x86
- false
+ False
@@ -75,6 +76,8 @@
+
+
diff --git a/src/Backend.cs b/src/Backend.cs
index 07ce862..f42b9e8 100644
--- a/src/Backend.cs
+++ b/src/Backend.cs
@@ -99,12 +99,14 @@ namespace WorldOfPeacecraft
return Map.GetTiles ();
}
- public void sendCommand (string command)
+ public void SendCommand (string command)
{
+ SenderBuffer.AddLine (command);
}
- public void sendChat (string message)
+ public void SendChatMessage (string message)
{
+ SenderBuffer.AddLine ("ask:say:" + message);
}
public void RefreshGui()
diff --git a/src/Gui/ChatInputBox.cs b/src/Gui/ChatInputBox.cs
new file mode 100644
index 0000000..2ff32f8
--- /dev/null
+++ b/src/Gui/ChatInputBox.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+
+namespace WorldOfPeacecraft
+{
+ public class ChatInputBox : TextBox
+ {
+ private LinkedList InputHistory = new LinkedList();
+ private LinkedListNode CurrentHistoryEntry;
+
+ public delegate void ChatMessageSubmittedEventHandler (string message);
+ public event ChatMessageSubmittedEventHandler ChatMessageSubmitted;
+
+ public ChatInputBox ()
+ {
+ this.KeyDown += KeyDownEvent;
+ this.KeyPress += KeyPressEvent;
+ }
+
+ private void KeyPressEvent (object o, KeyPressEventArgs args)
+ {
+ // Supress the "ding"-sound
+ if (args.KeyChar == (char)Keys.Return) {
+ args.Handled = true;
+ }
+ }
+
+ private void KeyDownEvent (object o, KeyEventArgs args)
+ {
+ if (args.KeyCode == Keys.Return) {
+ if (this.Text != "")
+ {
+ string message = this.Text;
+ this.Text = "";
+ if (CurrentHistoryEntry == null) {
+ InputHistory.AddLast (message);
+ }
+ else {
+ CurrentHistoryEntry.Value = message;
+ CurrentHistoryEntry = null;
+ }
+ if (ChatMessageSubmitted != null) {
+ this.ChatMessageSubmitted (message);
+ }
+ }
+ args.Handled = true;
+ } else if (args.KeyCode == Keys.Up) {
+ if (InputHistory.Count > 0) {
+ if (CurrentHistoryEntry == null) {
+ CurrentHistoryEntry = InputHistory.Last;
+ if (this.Text != "")
+ {
+ InputHistory.AddLast(this.Text);
+ }
+ this.Text = CurrentHistoryEntry.Value;
+ args.Handled = true;
+ } else {
+ if (CurrentHistoryEntry != InputHistory.First) {
+ CurrentHistoryEntry.Value = this.Text;
+ CurrentHistoryEntry = CurrentHistoryEntry.Previous;
+ this.Text = CurrentHistoryEntry.Value;
+ args.Handled = true;
+ }
+ }
+ }
+ } else if (args.KeyCode == Keys.Down) {
+ if (CurrentHistoryEntry != null)
+ {
+ CurrentHistoryEntry.Value = this.Text;
+ CurrentHistoryEntry = CurrentHistoryEntry.Next;
+ if (CurrentHistoryEntry == null) {
+ this.Text = "";
+ } else {
+ this.Text = CurrentHistoryEntry.Value;
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/Gui/ChatPanel.cs b/src/Gui/ChatPanel.cs
new file mode 100644
index 0000000..3a95af3
--- /dev/null
+++ b/src/Gui/ChatPanel.cs
@@ -0,0 +1,46 @@
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace WorldOfPeacecraft
+{
+ public class ChatPanel : Panel
+ {
+ private ChatInputBox ChatInput;
+ private TextBox ChatOutput;
+ private IBackend Backend;
+
+ public ChatPanel (IBackend backend)
+ {
+ Backend = backend;
+ ChatInput = new ChatInputBox ();
+ ChatInput.ChatMessageSubmitted += OnChatMessageSent;
+ ChatOutput = new TextBox ();
+ ChatOutput.ReadOnly = true;
+ ChatOutput.Multiline = true;
+
+ this.Controls.Add (ChatInput);
+ this.Controls.Add (ChatOutput);
+ }
+
+ protected override void OnLayout (LayoutEventArgs levent)
+ {
+ int outputHeight = this.ClientSize.Height - ChatInput.Height;
+ ChatOutput.Location = new Point (0, 0);
+ ChatOutput.Size = new Size (this.ClientSize.Width, outputHeight);
+ ChatInput.Location = new Point (0, outputHeight);
+ ChatInput.Size = new Size (this.ClientSize.Width, ChatInput.ClientSize.Width);
+ base.OnLayout (levent);
+ }
+
+ private void OnChatMessageSent (string message)
+ {
+ if (message.StartsWith ("/")) {
+ string command = message.Substring (1);
+ Backend.SendCommand(command);
+ } else {
+ Backend.SendChatMessage(message);
+ }
+ // TODO Move focus to board?
+ }
+ }
+}
diff --git a/src/Gui/Gui.cs b/src/Gui/Gui.cs
index bfc04a5..5323578 100644
--- a/src/Gui/Gui.cs
+++ b/src/Gui/Gui.cs
@@ -8,11 +8,13 @@ namespace WorldOfPeacecraft
{
class Gui : Form, IGui
{
- private const int tileSize = 32;
- private const int entitySize = 10;
+ private const int TileSize = 32;
+ private const int EntitySize = 10;
+ private const int ChatWidth = 300;
private IBackend Backend;
private Panel Board = new Panel();
+ private ChatPanel ChatPanel;
public Gui ()
{
@@ -33,18 +35,23 @@ namespace WorldOfPeacecraft
public void InitializeComponents ()
{
+ ChatPanel = new ChatPanel (Backend);
this.SuspendLayout();
- this.Size = new Size(400, 400);
+ this.Size = new Size(400 + ChatWidth, 400);
Board.Location = new Point(0,0);
Board.Size = new Size(400, 400);
Board.Paint += DoPaint;
+ ChatPanel.Location = new Point (400, 0);
+ ChatPanel.Size = new Size (300, 400);
this.DoubleBuffered = true;
this.MaximizeBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "WorldOfPeacecraft";
this.ShowIcon = false;
- this.Controls.Add(Board);
+ this.Controls.Add (Board);
+ this.Controls.Add (ChatPanel);
+
this.ResumeLayout();
}
@@ -82,8 +89,8 @@ namespace WorldOfPeacecraft
public void PaintTile (Graphics g, ITile tile, int x, int y)
{
- int posx = x * tileSize;
- int posy = y * tileSize;
+ int posx = x * TileSize;
+ int posy = y * TileSize;
Color color;
if (tile.IsForest ()) {
color = Color.Green;
@@ -99,7 +106,7 @@ namespace WorldOfPeacecraft
} else {
color = Color.Black;
}
- g.FillRectangle(new SolidBrush(color), posx, posy, tileSize, tileSize);
+ g.FillRectangle(new SolidBrush(color), posx, posy, TileSize, TileSize);
}
public void PaintEntities (Graphics g)
@@ -116,10 +123,10 @@ namespace WorldOfPeacecraft
public void PaintEntity (Graphics g, IPositionable entity)
{
- int x = entity.GetX () * tileSize + tileSize / 2 - entitySize / 2;
- int y = entity.GetY () * tileSize + tileSize / 2 - entitySize / 2;
- g.FillRectangle (new SolidBrush (Color.Red), x, y, entitySize, entitySize);
- g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, entitySize, entitySize);
+ int x = entity.GetX () * TileSize + TileSize / 2 - EntitySize / 2;
+ int y = entity.GetY () * TileSize + TileSize / 2 - EntitySize / 2;
+ g.FillRectangle (new SolidBrush (Color.Red), x, y, EntitySize, EntitySize);
+ g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, EntitySize, EntitySize);
}
public void PerformRefresh ()
@@ -130,11 +137,13 @@ namespace WorldOfPeacecraft
if (map == null) {
return;
}
- int mapWidth = (map.GetLength(0)) * tileSize;
- int mapHeight = (map.GetLength(1)) * tileSize;
+ int mapWidth = (map.GetLength(0)) * TileSize;
+ int mapHeight = (map.GetLength(1)) * TileSize;
this.SuspendLayout();
- this.SetClientSizeCore(mapWidth, mapHeight);
+ this.SetClientSizeCore(mapWidth + ChatWidth, mapHeight);
Board.Size = new Size(mapWidth, mapHeight);
+ ChatPanel.Location = new Point (mapWidth, 0);
+ ChatPanel.Size = new Size (ChatWidth, mapHeight);
this.ResumeLayout();
this.PerformLayout();
this.Refresh();
diff --git a/src/Gui/IBackend.cs b/src/Gui/IBackend.cs
index 0a583af..1128290 100644
--- a/src/Gui/IBackend.cs
+++ b/src/Gui/IBackend.cs
@@ -10,6 +10,10 @@ namespace WorldOfPeacecraft
IEnumerable GetDragons();
+ void SendChatMessage (string message);
+
+ void SendCommand (string command);
+
void StartThreads();
void Stop();