Die Gui hat nun ein Chatfenster. Bisher können lediglich nachrichten
versandt, jedoch nicht empfangen werden.
This commit is contained in:
13
inf3.csproj
13
inf3.csproj
@@ -9,26 +9,27 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>inf3</RootNamespace>
|
<RootNamespace>inf3</RootNamespace>
|
||||||
<AssemblyName>inf3</AssemblyName>
|
<AssemblyName>inf3</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>True</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>False</Optimize>
|
||||||
<OutputPath>bin\Debug</OutputPath>
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
<DefineConstants>DEBUG;</DefineConstants>
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>False</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>True</Optimize>
|
||||||
<OutputPath>bin\Release</OutputPath>
|
<OutputPath>bin\Release</OutputPath>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>False</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -75,6 +76,8 @@
|
|||||||
<Compile Include="src\Gui\IPositionable.cs" />
|
<Compile Include="src\Gui\IPositionable.cs" />
|
||||||
<Compile Include="src\Buffer.cs" />
|
<Compile Include="src\Buffer.cs" />
|
||||||
<Compile Include="src\Gui\IGui.cs" />
|
<Compile Include="src\Gui\IGui.cs" />
|
||||||
|
<Compile Include="src\Gui\ChatPanel.cs" />
|
||||||
|
<Compile Include="src\Gui\ChatInputBox.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -99,12 +99,14 @@ namespace WorldOfPeacecraft
|
|||||||
return Map.GetTiles ();
|
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()
|
public void RefreshGui()
|
||||||
|
|||||||
82
src/Gui/ChatInputBox.cs
Normal file
82
src/Gui/ChatInputBox.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace WorldOfPeacecraft
|
||||||
|
{
|
||||||
|
public class ChatInputBox : TextBox
|
||||||
|
{
|
||||||
|
private LinkedList<string> InputHistory = new LinkedList<string>();
|
||||||
|
private LinkedListNode<string> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
46
src/Gui/ChatPanel.cs
Normal file
46
src/Gui/ChatPanel.cs
Normal file
@@ -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?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,13 @@ namespace WorldOfPeacecraft
|
|||||||
{
|
{
|
||||||
class Gui : Form, IGui
|
class Gui : Form, IGui
|
||||||
{
|
{
|
||||||
private const int tileSize = 32;
|
private const int TileSize = 32;
|
||||||
private const int entitySize = 10;
|
private const int EntitySize = 10;
|
||||||
|
private const int ChatWidth = 300;
|
||||||
private IBackend Backend;
|
private IBackend Backend;
|
||||||
|
|
||||||
private Panel Board = new Panel();
|
private Panel Board = new Panel();
|
||||||
|
private ChatPanel ChatPanel;
|
||||||
|
|
||||||
public Gui ()
|
public Gui ()
|
||||||
{
|
{
|
||||||
@@ -33,18 +35,23 @@ namespace WorldOfPeacecraft
|
|||||||
|
|
||||||
public void InitializeComponents ()
|
public void InitializeComponents ()
|
||||||
{
|
{
|
||||||
|
ChatPanel = new ChatPanel (Backend);
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
this.Size = new Size(400, 400);
|
this.Size = new Size(400 + ChatWidth, 400);
|
||||||
Board.Location = new Point(0,0);
|
Board.Location = new Point(0,0);
|
||||||
Board.Size = new Size(400, 400);
|
Board.Size = new Size(400, 400);
|
||||||
Board.Paint += DoPaint;
|
Board.Paint += DoPaint;
|
||||||
|
ChatPanel.Location = new Point (400, 0);
|
||||||
|
ChatPanel.Size = new Size (300, 400);
|
||||||
this.DoubleBuffered = true;
|
this.DoubleBuffered = true;
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||||
this.Name = "WorldOfPeacecraft";
|
this.Name = "WorldOfPeacecraft";
|
||||||
this.ShowIcon = false;
|
this.ShowIcon = false;
|
||||||
|
|
||||||
this.Controls.Add(Board);
|
this.Controls.Add (Board);
|
||||||
|
this.Controls.Add (ChatPanel);
|
||||||
|
|
||||||
this.ResumeLayout();
|
this.ResumeLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +89,8 @@ namespace WorldOfPeacecraft
|
|||||||
|
|
||||||
public void PaintTile (Graphics g, ITile tile, int x, int y)
|
public void PaintTile (Graphics g, ITile tile, int x, int y)
|
||||||
{
|
{
|
||||||
int posx = x * tileSize;
|
int posx = x * TileSize;
|
||||||
int posy = y * tileSize;
|
int posy = y * TileSize;
|
||||||
Color color;
|
Color color;
|
||||||
if (tile.IsForest ()) {
|
if (tile.IsForest ()) {
|
||||||
color = Color.Green;
|
color = Color.Green;
|
||||||
@@ -99,7 +106,7 @@ namespace WorldOfPeacecraft
|
|||||||
} else {
|
} else {
|
||||||
color = Color.Black;
|
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)
|
public void PaintEntities (Graphics g)
|
||||||
@@ -116,10 +123,10 @@ namespace WorldOfPeacecraft
|
|||||||
|
|
||||||
public void PaintEntity (Graphics g, IPositionable entity)
|
public void PaintEntity (Graphics g, IPositionable entity)
|
||||||
{
|
{
|
||||||
int x = entity.GetX () * tileSize + tileSize / 2 - entitySize / 2;
|
int x = entity.GetX () * TileSize + TileSize / 2 - EntitySize / 2;
|
||||||
int y = entity.GetY () * 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.FillRectangle (new SolidBrush (Color.Red), x, y, EntitySize, EntitySize);
|
||||||
g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, entitySize, entitySize);
|
g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, EntitySize, EntitySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PerformRefresh ()
|
public void PerformRefresh ()
|
||||||
@@ -130,11 +137,13 @@ namespace WorldOfPeacecraft
|
|||||||
if (map == null) {
|
if (map == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int mapWidth = (map.GetLength(0)) * tileSize;
|
int mapWidth = (map.GetLength(0)) * TileSize;
|
||||||
int mapHeight = (map.GetLength(1)) * tileSize;
|
int mapHeight = (map.GetLength(1)) * TileSize;
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
this.SetClientSizeCore(mapWidth, mapHeight);
|
this.SetClientSizeCore(mapWidth + ChatWidth, mapHeight);
|
||||||
Board.Size = new Size(mapWidth, mapHeight);
|
Board.Size = new Size(mapWidth, mapHeight);
|
||||||
|
ChatPanel.Location = new Point (mapWidth, 0);
|
||||||
|
ChatPanel.Size = new Size (ChatWidth, mapHeight);
|
||||||
this.ResumeLayout();
|
this.ResumeLayout();
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ namespace WorldOfPeacecraft
|
|||||||
|
|
||||||
IEnumerable<IPositionable> GetDragons();
|
IEnumerable<IPositionable> GetDragons();
|
||||||
|
|
||||||
|
void SendChatMessage (string message);
|
||||||
|
|
||||||
|
void SendCommand (string command);
|
||||||
|
|
||||||
void StartThreads();
|
void StartThreads();
|
||||||
|
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|||||||
Reference in New Issue
Block a user