Komplettumbau und Splashscreen sollte jetzt funktionieren (Muss noch getestet werden)

This commit is contained in:
Wafa Sadri
2014-05-13 18:48:51 +02:00
parent 810e69e759
commit c3088bb36a
10 changed files with 121 additions and 59 deletions

View File

@@ -24,7 +24,7 @@ namespace WorldOfPeacecraft
Dragons = new Dictionary<int, Dragon> ();
Players = new Dictionary<int, Player> ();
ChatMessages = new LinkedList<Message> ();
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);
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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();

View File

@@ -25,5 +25,7 @@ namespace WorldOfPeacecraft
void StartThreads();
void Stop();
void Connect();
}
}

View File

@@ -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)
@@ -378,9 +342,46 @@ namespace WorldOfPeacecraft
g.DrawImage(image, x, y, image.Width, image.Height);
}
public void PaintEntity (Graphics g, IPositionable entity, Color color)
{
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 InitializeComponents(){
SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
this.PreviewKeyDown += board_KeyPress;
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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 ();
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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
}
}
}