From f749eb6180698b5035c3fbf7d13f91961eb2db2f Mon Sep 17 00:00:00 2001 From: Daniel Herrmann Date: Fri, 2 May 2014 11:32:33 +0200 Subject: [PATCH] Key-Listener ist initialisiert. Fokus liegt aber noch auf Chat --- src/Backend.cs | 18 ++++++++++++++++++ src/Gui/ChatPanel.cs | 2 ++ src/Gui/IBackend.cs | 6 ++++++ src/Gui/MapPanel.cs | 21 +++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/src/Backend.cs b/src/Backend.cs index 433e674..6049b05 100644 --- a/src/Backend.cs +++ b/src/Backend.cs @@ -121,6 +121,24 @@ namespace WorldOfPeacecraft SenderBuffer.AddLine ("ask:say:" + message); } + public void moveUp() + { + SenderBuffer.AddLine("ask:mv:up"); + } + + public void moveDown() + { + SenderBuffer.AddLine("ask:mv:dwn"); + } + public void moveLeft() + { + SenderBuffer.AddLine("ask:mv:lft"); + } + public void moveRight() + { + SenderBuffer.AddLine("ask:mv:rgt"); + } + public void RefreshGui() { Gui.PerformRefresh(); diff --git a/src/Gui/ChatPanel.cs b/src/Gui/ChatPanel.cs index bcc3e4e..ed09603 100644 --- a/src/Gui/ChatPanel.cs +++ b/src/Gui/ChatPanel.cs @@ -30,6 +30,8 @@ namespace WorldOfPeacecraft base.OnLayout (levent); } + + private void OnChatMessageSent (string message) { if (message.StartsWith ("/")) { diff --git a/src/Gui/IBackend.cs b/src/Gui/IBackend.cs index 7361313..2cda33a 100644 --- a/src/Gui/IBackend.cs +++ b/src/Gui/IBackend.cs @@ -16,6 +16,12 @@ namespace WorldOfPeacecraft void SendCommand (string command); + void moveUp(); + + void moveDown(); + void moveLeft(); + void moveRight(); + void StartThreads(); void Stop(); diff --git a/src/Gui/MapPanel.cs b/src/Gui/MapPanel.cs index 89e52a7..3af4666 100644 --- a/src/Gui/MapPanel.cs +++ b/src/Gui/MapPanel.cs @@ -14,6 +14,7 @@ namespace WorldOfPeacecraft { Backend = backend; this.Paint += DoPaint; + this.PreviewKeyDown += board_KeyPress; } protected override void OnLayout (LayoutEventArgs levent) @@ -27,6 +28,26 @@ namespace WorldOfPeacecraft base.OnLayout (levent); } + private void board_KeyPress(object sender, PreviewKeyDownEventArgs e) + { + switch (e.KeyCode) + { + case Keys.A: + this.Backend.moveLeft(); + break; + case Keys.D: + this.Backend.moveRight(); + break; + case Keys.W: + this.Backend.moveUp(); + break; + case Keys.S: + this.Backend.moveDown(); + break; + } + } + + public void DoPaint (object source, PaintEventArgs args) { BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate (this.CreateGraphics (), this.DisplayRectangle);