From c3088bb36a9820871c9dc666f2180f7a4af001bb Mon Sep 17 00:00:00 2001 From: Wafa Sadri Date: Tue, 13 May 2014 18:48:51 +0200 Subject: [PATCH] Komplettumbau und Splashscreen sollte jetzt funktionieren (Muss noch getestet werden) --- src/Backend.cs | 6 ++- src/Gui/ChatOutputBox.cs | 11 +++++- src/Gui/ChatPanel.cs | 14 ++++--- src/Gui/Gui.cs | 18 ++++++--- src/Gui/IBackend.cs | 2 + src/Gui/MapPanel.cs | 79 +++++++++++++++++++------------------ src/Gui/OnlinePlayerList.cs | 12 ++++-- src/Gui/Program.cs | 9 ++++- src/Gui/Splashscreen.cs | 21 +++++++++- src/Music.cs | 8 +++- 10 files changed, 121 insertions(+), 59 deletions(-) diff --git a/src/Backend.cs b/src/Backend.cs index dcc8655..67b1330 100644 --- a/src/Backend.cs +++ b/src/Backend.cs @@ -24,7 +24,7 @@ namespace WorldOfPeacecraft Dragons = new Dictionary (); Players = new Dictionary (); ChatMessages = new LinkedList (); - Client = new TcpClient ("localhost", 9999); + Client = new TcpClient (); Buffer receiverBuffer = new Buffer(10000); SenderBuffer = new Buffer(100); Parse = new Parser (this, receiverBuffer); @@ -182,6 +182,10 @@ namespace WorldOfPeacecraft Send.Stop (); Client.Close (); } + + public void Connect(){ + Client.Connect ("localhost", 9999); + } } } diff --git a/src/Gui/ChatOutputBox.cs b/src/Gui/ChatOutputBox.cs index be05f88..1ba0f52 100644 --- a/src/Gui/ChatOutputBox.cs +++ b/src/Gui/ChatOutputBox.cs @@ -10,12 +10,11 @@ namespace WorldOfPeacecraft private Font MessageFont; private Font SenderFont; private Font IregularSenderFont; + private Music m = new Music(); 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); @@ -43,10 +42,18 @@ namespace WorldOfPeacecraft this.AppendText (": "); this.SelectionFont = MessageFont; this.AppendText (message.GetMessage ()); + if (message.GetMessage().Contains("nyancat")) { + m.Playmusic ("poptart"); + } } } this.ResumeLayout (); } + + public void InitializeComponents(){ + this.ReadOnly = true; + this.Multiline = true; + } } } diff --git a/src/Gui/ChatPanel.cs b/src/Gui/ChatPanel.cs index ed09603..aa21096 100644 --- a/src/Gui/ChatPanel.cs +++ b/src/Gui/ChatPanel.cs @@ -15,9 +15,6 @@ namespace WorldOfPeacecraft ChatInput = new ChatInputBox (); ChatInput.ChatMessageSubmitted += OnChatMessageSent; ChatOutput = new ChatOutputBox (backend); - - this.Controls.Add (ChatInput); - this.Controls.Add (ChatOutput); } protected override void OnLayout (LayoutEventArgs levent) @@ -36,8 +33,9 @@ namespace WorldOfPeacecraft { if (message.StartsWith ("/")) { string command = message.Substring (1); - Backend.SendCommand(command); - } else { + Backend.SendCommand (command); + } + else { Backend.SendChatMessage(message); } // TODO Move focus to board? @@ -47,5 +45,11 @@ namespace WorldOfPeacecraft { ChatOutput.UpdateData (); } + + public void InitializeComponents(){ + ChatOutput.InitializeComponents (); + this.Controls.Add (ChatInput); + this.Controls.Add (ChatOutput); + } } } diff --git a/src/Gui/Gui.cs b/src/Gui/Gui.cs index a9b08fe..dec1d70 100644 --- a/src/Gui/Gui.cs +++ b/src/Gui/Gui.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; namespace WorldOfPeacecraft { - class Gui : Form, IGui + public class Gui : Form, IGui { private const int ChatWidth = 300; private const int OnlinePlayerWidth = 150; @@ -20,7 +20,7 @@ namespace WorldOfPeacecraft public Gui () { - //AllocConsole(); + } public void SetBackend (IBackend backend) @@ -42,9 +42,9 @@ namespace WorldOfPeacecraft public void InitializeComponents () { - ChatPanel = new ChatPanel (Backend); - MapPanel = new MapPanel (Backend); - OnlinePlayerList = new OnlinePlayerList (Backend); + MapPanel.InitializeComponents (); + ChatPanel.InitializeComponents (); + OnlinePlayerList.InitializeComponents (); this.SuspendLayout(); this.Size = new Size(OnlinePlayerWidth + 400 + ChatWidth, 400); OnlinePlayerList.Location = new Point(0,0); @@ -91,6 +91,14 @@ namespace WorldOfPeacecraft })); } + public void LoadResources(){ + ChatPanel = new ChatPanel (Backend); + MapPanel = new MapPanel (Backend); + OnlinePlayerList = new OnlinePlayerList (Backend); + MapPanel.LoadResources (); + OnlinePlayerList.LoadResources (); + } + [DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool AllocConsole(); diff --git a/src/Gui/IBackend.cs b/src/Gui/IBackend.cs index 96d82d0..806f0c6 100644 --- a/src/Gui/IBackend.cs +++ b/src/Gui/IBackend.cs @@ -25,5 +25,7 @@ namespace WorldOfPeacecraft void StartThreads(); void Stop(); + + void Connect(); } } diff --git a/src/Gui/MapPanel.cs b/src/Gui/MapPanel.cs index 88f5471..9b4bc5d 100644 --- a/src/Gui/MapPanel.cs +++ b/src/Gui/MapPanel.cs @@ -50,43 +50,7 @@ namespace WorldOfPeacecraft public MapPanel (IBackend backend) { - SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); Backend = backend; - this.PreviewKeyDown += board_KeyPress; - Dragon1 = Image.FromFile (ImagesFolder + "dragon1.png"); - Dragon2 = Image.FromFile (ImagesFolder + "dragon2.png"); - Dragon3 = Image.FromFile (ImagesFolder + "dragon3.png"); - Forest = Image.FromFile (ImagesFolder + "forest.png"); - ForestStag = Image.FromFile (ImagesFolder + "stag.png"); - ForestLeft = Image.FromFile (ImagesFolder + "forest_left.png"); - ForestRight = Image.FromFile (ImagesFolder + "forest_right.png"); - ForestTop = Image.FromFile (ImagesFolder + "forest_top.png"); - ForestBottom = Image.FromFile (ImagesFolder + "forest_bottom.png"); - Knight = Image.FromFile (ImagesFolder + "knight.png"); - Walkable = Image.FromFile (ImagesFolder + "walkable.jpg"); - Water = Image.FromFile (ImagesFolder + "water.jpg"); - Flowers = Image.FromFile(ImagesFolder + "flowers.png"); - BeachBottom = Image.FromFile (ImagesFolder + "beach.png"); - BeachLeft = RotateFlipImage (BeachBottom, RotateFlipType.Rotate90FlipNone); - BeachTop = RotateFlipImage (BeachBottom, RotateFlipType.Rotate180FlipNone); - BeachRight = RotateFlipImage (BeachBottom, RotateFlipType.Rotate270FlipNone); - BeachBottomRight = Image.FromFile (ImagesFolder + "beachcorner.png"); - BeachBottomLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate90FlipNone); - BeachTopLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate180FlipNone); - BeachTopRight = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate270FlipNone); - WallBase = Image.FromFile(ImagesFolder + "wall_base.png"); - WallEdgeBotLeft = Image.FromFile (ImagesFolder + "wall_edge_botleft.png"); - WallEdgeBotRight = Image.FromFile (ImagesFolder + "wall_edge_botright.png"); - WallEdgeTopLeft = Image.FromFile (ImagesFolder + "wall_edge_topleft.png"); - WallEdgeTopRight = Image.FromFile (ImagesFolder + "wall_edge_topright.png"); - WallCornerBotLeft = Image.FromFile (ImagesFolder + "wall_corner_botleft.png"); - WallCornerBotRight = Image.FromFile (ImagesFolder + "wall_corner_botright.png"); - WallCornerTopLeft = Image.FromFile (ImagesFolder + "wall_corner_topleft.png"); - WallCornerTopRight = Image.FromFile (ImagesFolder + "wall_corner_topright.png"); - WallInnerBotLeft = Image.FromFile (ImagesFolder + "wall_inner_botleft.png"); - WallInnerBotRight = Image.FromFile (ImagesFolder + "wall_inner_botright.png"); - WallInnerTopLeft = Image.FromFile (ImagesFolder + "wall_inner_topleft.png"); - WallInnerTopRight = Image.FromFile (ImagesFolder + "wall_inner_topright.png"); } private Image RotateFlipImage(Image image, RotateFlipType type) @@ -377,10 +341,47 @@ namespace WorldOfPeacecraft int y = posy + (TileSize - image.Height) / 2; g.DrawImage(image, x, y, image.Width, image.Height); } + + public void LoadResources (){ + Dragon1 = Image.FromFile (ImagesFolder + "dragon1.png"); + Dragon2 = Image.FromFile (ImagesFolder + "dragon2.png"); + Dragon3 = Image.FromFile (ImagesFolder + "dragon3.png"); + Forest = Image.FromFile (ImagesFolder + "forest.png"); + ForestStag = Image.FromFile (ImagesFolder + "stag.png"); + ForestLeft = Image.FromFile (ImagesFolder + "forest_left.png"); + ForestRight = Image.FromFile (ImagesFolder + "forest_right.png"); + ForestTop = Image.FromFile (ImagesFolder + "forest_top.png"); + ForestBottom = Image.FromFile (ImagesFolder + "forest_bottom.png"); + Knight = Image.FromFile (ImagesFolder + "knight.png"); + Walkable = Image.FromFile (ImagesFolder + "walkable.jpg"); + Water = Image.FromFile (ImagesFolder + "water.jpg"); + Flowers = Image.FromFile(ImagesFolder + "flowers.png"); + BeachBottom = Image.FromFile (ImagesFolder + "beach.png"); + BeachLeft = RotateFlipImage (BeachBottom, RotateFlipType.Rotate90FlipNone); + BeachTop = RotateFlipImage (BeachBottom, RotateFlipType.Rotate180FlipNone); + BeachRight = RotateFlipImage (BeachBottom, RotateFlipType.Rotate270FlipNone); + BeachBottomRight = Image.FromFile (ImagesFolder + "beachcorner.png"); + BeachBottomLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate90FlipNone); + BeachTopLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate180FlipNone); + BeachTopRight = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate270FlipNone); + WallBase = Image.FromFile(ImagesFolder + "wall_base.png"); + WallEdgeBotLeft = Image.FromFile (ImagesFolder + "wall_edge_botleft.png"); + WallEdgeBotRight = Image.FromFile (ImagesFolder + "wall_edge_botright.png"); + WallEdgeTopLeft = Image.FromFile (ImagesFolder + "wall_edge_topleft.png"); + WallEdgeTopRight = Image.FromFile (ImagesFolder + "wall_edge_topright.png"); + WallCornerBotLeft = Image.FromFile (ImagesFolder + "wall_corner_botleft.png"); + WallCornerBotRight = Image.FromFile (ImagesFolder + "wall_corner_botright.png"); + WallCornerTopLeft = Image.FromFile (ImagesFolder + "wall_corner_topleft.png"); + WallCornerTopRight = Image.FromFile (ImagesFolder + "wall_corner_topright.png"); + WallInnerBotLeft = Image.FromFile (ImagesFolder + "wall_inner_botleft.png"); + WallInnerBotRight = Image.FromFile (ImagesFolder + "wall_inner_botright.png"); + WallInnerTopLeft = Image.FromFile (ImagesFolder + "wall_inner_topleft.png"); + WallInnerTopRight = Image.FromFile (ImagesFolder + "wall_inner_topright.png"); + } - public void PaintEntity (Graphics g, IPositionable entity, Color color) - { - + public void InitializeComponents(){ + SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); + this.PreviewKeyDown += board_KeyPress; } } } diff --git a/src/Gui/OnlinePlayerList.cs b/src/Gui/OnlinePlayerList.cs index dcc2bc6..50fa507 100644 --- a/src/Gui/OnlinePlayerList.cs +++ b/src/Gui/OnlinePlayerList.cs @@ -12,9 +12,6 @@ namespace WorldOfPeacecraft public OnlinePlayerList(IBackend backend) { this.Backend = backend; - SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); - Font = new Font(Font, FontStyle.Bold); - PlayerOnlineImage = Image.FromFile("textures/playerOnline.png"); } protected override void OnPaint (PaintEventArgs e) @@ -32,5 +29,14 @@ namespace WorldOfPeacecraft count++; } } + + public void LoadResources(){ + Font = new Font(Font, FontStyle.Bold); + PlayerOnlineImage = Image.FromFile("textures/playerOnline.png"); + } + + public void InitializeComponents(){ + SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); + } } } \ No newline at end of file diff --git a/src/Gui/Program.cs b/src/Gui/Program.cs index 014673c..34522c4 100644 --- a/src/Gui/Program.cs +++ b/src/Gui/Program.cs @@ -9,11 +9,16 @@ namespace WorldOfPeacecraft { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Gui gui = new Gui(); Backend backend = new Backend(gui); gui.SetBackend(backend); - Application.Run (gui); + SplashScreen splash = new SplashScreen (gui,backend); + splash.GuiHasLoaded += OnGuiLoaded; + Application.Run (splash); + } + private static void OnGuiLoaded(SplashScreen screen, Gui gui){ + screen.Hide (); + gui.Show (); } } } diff --git a/src/Gui/Splashscreen.cs b/src/Gui/Splashscreen.cs index 3d87009..b8fabc8 100644 --- a/src/Gui/Splashscreen.cs +++ b/src/Gui/Splashscreen.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; @@ -10,9 +11,19 @@ namespace WorldOfPeacecraft private string ImagesFolder = "textures/"; private Image Logo; private Music m = new Music(); + private Gui gui; + private IBackend backend; - public SplashScreen () + public delegate void GuiHasLoadedEventHandler (SplashScreen screen, Gui gui); + public event GuiHasLoadedEventHandler GuiHasLoaded; + + public SplashScreen (Gui gui, IBackend backend) { + this.gui = gui; + this.backend = backend; + Thread t = new Thread (ThreadEntry); + t.Start (); + this.SetClientSizeCore (450, 150); Logo = Image.FromFile (ImagesFolder + "splashscreen.png"); m.Playmusic ("splashscreen"); } @@ -23,6 +34,14 @@ namespace WorldOfPeacecraft g.InterpolationMode = InterpolationMode.Low; g.DrawImage (Logo, 0, 0, 450, 150); } + + private void ThreadEntry(){ + gui.LoadResources (); + backend.Connect (); + Thread.Sleep (1000); + if (GuiHasLoaded != null) + GuiHasLoaded (this,gui); + } } } diff --git a/src/Music.cs b/src/Music.cs index bc108d6..9675437 100644 --- a/src/Music.cs +++ b/src/Music.cs @@ -11,19 +11,25 @@ namespace WorldOfPeacecraft private SoundPlayer minigameplayer = new SoundPlayer(musicpath + "minigame.wav"); private SoundPlayer splashscreenplayer = new SoundPlayer (soundpath + "splashscreen.wav"); private SoundPlayer walkplayer = new SoundPlayer(soundpath + "step.wav"); + private SoundPlayer poptartplayer = new SoundPlayer(musicpath + "poptart.wav"); + public Music () { } + public void Playmusic (string sound){ if (sound == "overworld") overworldplayer.PlayLooping (); if (sound == "minigame") minigameplayer.PlayLooping (); if (sound == "splashscreen") - splashscreenplayer.PlaySync (); + splashscreenplayer.Play (); if (sound == "walk") walkplayer.Play (); + if (sound == "poptart") + poptartplayer.Play (); + //TODO: Monalisa } } }