Merge branch 'splashscreen_Wafa'

This commit is contained in:
Wafa Sadri
2014-05-13 19:36:04 +02:00
13 changed files with 142 additions and 65 deletions

View File

@@ -24,7 +24,7 @@ namespace WorldOfPeacecraft
Dragons = new Dictionary<int, Dragon> (); Dragons = new Dictionary<int, Dragon> ();
Players = new Dictionary<int, Player> (); Players = new Dictionary<int, Player> ();
ChatMessages = new LinkedList<Message> (); ChatMessages = new LinkedList<Message> ();
Client = new TcpClient ("localhost", 9999); Client = new TcpClient ();
Buffer receiverBuffer = new Buffer(10000); Buffer receiverBuffer = new Buffer(10000);
SenderBuffer = new Buffer(100); SenderBuffer = new Buffer(100);
Parse = new Parser (this, receiverBuffer); Parse = new Parser (this, receiverBuffer);
@@ -182,6 +182,10 @@ namespace WorldOfPeacecraft
Send.Stop (); Send.Stop ();
Client.Close (); Client.Close ();
} }
public void Connect(){
Client.Connect ("localhost", 9999);
}
} }
} }

View File

@@ -10,12 +10,11 @@ namespace WorldOfPeacecraft
private Font MessageFont; private Font MessageFont;
private Font SenderFont; private Font SenderFont;
private Font IregularSenderFont; private Font IregularSenderFont;
//private Music m = new Music();
public ChatOutputBox (IBackend backend) public ChatOutputBox (IBackend backend)
{ {
Backend = backend; Backend = backend;
this.ReadOnly = true;
this.Multiline = true;
MessageFont = this.SelectionFont; MessageFont = this.SelectionFont;
SenderFont = new Font (MessageFont, FontStyle.Bold); SenderFont = new Font (MessageFont, FontStyle.Bold);
IregularSenderFont = new Font (MessageFont, FontStyle.Bold | FontStyle.Italic); IregularSenderFont = new Font (MessageFont, FontStyle.Bold | FontStyle.Italic);
@@ -43,10 +42,18 @@ namespace WorldOfPeacecraft
this.AppendText (": "); this.AppendText (": ");
this.SelectionFont = MessageFont; this.SelectionFont = MessageFont;
this.AppendText (message.GetMessage ()); this.AppendText (message.GetMessage ());
if (message.GetMessage().Contains("nyancat")) {
//m.Playmusic ("poptart");
}
} }
} }
this.ResumeLayout (); this.ResumeLayout ();
} }
public void InitializeComponents(){
this.ReadOnly = true;
this.Multiline = true;
}
} }
} }

View File

@@ -15,9 +15,6 @@ namespace WorldOfPeacecraft
ChatInput = new ChatInputBox (); ChatInput = new ChatInputBox ();
ChatInput.ChatMessageSubmitted += OnChatMessageSent; ChatInput.ChatMessageSubmitted += OnChatMessageSent;
ChatOutput = new ChatOutputBox (backend); ChatOutput = new ChatOutputBox (backend);
this.Controls.Add (ChatInput);
this.Controls.Add (ChatOutput);
} }
protected override void OnLayout (LayoutEventArgs levent) protected override void OnLayout (LayoutEventArgs levent)
@@ -36,8 +33,9 @@ namespace WorldOfPeacecraft
{ {
if (message.StartsWith ("/")) { if (message.StartsWith ("/")) {
string command = message.Substring (1); string command = message.Substring (1);
Backend.SendCommand(command); Backend.SendCommand (command);
} else { }
else {
Backend.SendChatMessage(message); Backend.SendChatMessage(message);
} }
// TODO Move focus to board? // TODO Move focus to board?
@@ -47,5 +45,11 @@ namespace WorldOfPeacecraft
{ {
ChatOutput.UpdateData (); ChatOutput.UpdateData ();
} }
public void InitializeComponents(){
ChatOutput.InitializeComponents ();
this.Controls.Add (ChatInput);
this.Controls.Add (ChatOutput);
}
} }
} }

View File

@@ -6,21 +6,22 @@ using System.Runtime.InteropServices;
namespace WorldOfPeacecraft namespace WorldOfPeacecraft
{ {
class Gui : Form, IGui public class Gui : Form, IGui
{ {
private const int ChatWidth = 300; private const int ChatWidth = 300;
private const int OnlinePlayerWidth = 150; private const int OnlinePlayerWidth = 150;
private IBackend Backend; private IBackend Backend;
public Form MainForm { get; set; }
private MapPanel MapPanel; private MapPanel MapPanel;
private ChatPanel ChatPanel; private ChatPanel ChatPanel;
private OnlinePlayerList OnlinePlayerList; private OnlinePlayerList OnlinePlayerList;
private Music m = new Music(); //private Music m = new Music();
public Gui () public Gui ()
{ {
//AllocConsole();
} }
public void SetBackend (IBackend backend) public void SetBackend (IBackend backend)
@@ -40,11 +41,18 @@ namespace WorldOfPeacecraft
Backend.StartThreads (); Backend.StartThreads ();
} }
protected override void OnPaint (PaintEventArgs e)
{
lock (Backend) {
base.OnPaint(e);
}
}
public void InitializeComponents () public void InitializeComponents ()
{ {
ChatPanel = new ChatPanel (Backend); MapPanel.InitializeComponents ();
MapPanel = new MapPanel (Backend); ChatPanel.InitializeComponents ();
OnlinePlayerList = new OnlinePlayerList (Backend); OnlinePlayerList.InitializeComponents ();
this.SuspendLayout(); this.SuspendLayout();
this.Size = new Size(OnlinePlayerWidth + 400 + ChatWidth, 400); this.Size = new Size(OnlinePlayerWidth + 400 + ChatWidth, 400);
OnlinePlayerList.Location = new Point(0,0); OnlinePlayerList.Location = new Point(0,0);
@@ -65,12 +73,13 @@ namespace WorldOfPeacecraft
this.ResumeLayout(); this.ResumeLayout();
m.Playmusic ("overworld"); //m.Playmusic ("overworld");
} }
protected override void OnClosing (System.ComponentModel.CancelEventArgs e) protected override void OnClosing (System.ComponentModel.CancelEventArgs e)
{ {
base.OnClosing (e); base.OnClosing (e);
MainForm.Close();
Backend.Stop (); Backend.Stop ();
} }
@@ -91,6 +100,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)] [DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole(); static extern bool AllocConsole();

View File

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

View File

@@ -50,43 +50,7 @@ namespace WorldOfPeacecraft
public MapPanel (IBackend backend) public MapPanel (IBackend backend)
{ {
SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
Backend = backend; 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) private Image RotateFlipImage(Image image, RotateFlipType type)
@@ -377,10 +341,47 @@ namespace WorldOfPeacecraft
int y = posy + (TileSize - image.Height) / 2; int y = posy + (TileSize - image.Height) / 2;
g.DrawImage(image, x, y, image.Width, image.Height); 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;
} }
} }
} }

View File

@@ -12,9 +12,6 @@ namespace WorldOfPeacecraft
public OnlinePlayerList(IBackend backend) public OnlinePlayerList(IBackend backend)
{ {
this.Backend = 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) protected override void OnPaint (PaintEventArgs e)
@@ -32,5 +29,14 @@ namespace WorldOfPeacecraft
count++; 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,18 @@ namespace WorldOfPeacecraft
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Gui gui = new Gui(); Gui gui = new Gui();
Backend backend = new Backend(gui); Backend backend = new Backend(gui);
gui.SetBackend(backend); 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.BeginInvoke(new MethodInvoker(delegate {
screen.Hide ();
gui.Show ();
}));
} }
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Windows.Forms; using System.Windows.Forms;
@@ -9,12 +10,23 @@ namespace WorldOfPeacecraft
{ {
private string ImagesFolder = "textures/"; private string ImagesFolder = "textures/";
private Image Logo; private Image Logo;
private Music m = new Music(); //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;
gui.MainForm = this;
this.backend = backend;
Thread t = new Thread (ThreadEntry);
t.Start ();
this.SetClientSizeCore (450, 150);
Logo = Image.FromFile (ImagesFolder + "splashscreen.png"); Logo = Image.FromFile (ImagesFolder + "splashscreen.png");
m.Playmusic ("splashscreen"); //m.Playmusic ("splashscreen");
} }
protected override void OnPaint (PaintEventArgs e) protected override void OnPaint (PaintEventArgs e)
@@ -23,6 +35,14 @@ namespace WorldOfPeacecraft
g.InterpolationMode = InterpolationMode.Low; g.InterpolationMode = InterpolationMode.Low;
g.DrawImage (Logo, 0, 0, 450, 150); 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

@@ -3,7 +3,7 @@ using System.Media;
namespace WorldOfPeacecraft namespace WorldOfPeacecraft
{ {
public class Music /*public class Music
{ {
private static string musicpath = "./music/"; private static string musicpath = "./music/";
private static string soundpath = "./sounds/"; private static string soundpath = "./sounds/";
@@ -11,20 +11,26 @@ namespace WorldOfPeacecraft
private SoundPlayer minigameplayer = new SoundPlayer(musicpath + "minigame.wav"); private SoundPlayer minigameplayer = new SoundPlayer(musicpath + "minigame.wav");
private SoundPlayer splashscreenplayer = new SoundPlayer (soundpath + "splashscreen.wav"); private SoundPlayer splashscreenplayer = new SoundPlayer (soundpath + "splashscreen.wav");
private SoundPlayer walkplayer = new SoundPlayer(soundpath + "step.wav"); private SoundPlayer walkplayer = new SoundPlayer(soundpath + "step.wav");
private SoundPlayer poptartplayer = new SoundPlayer(musicpath + "poptart.wav");
public Music () public Music ()
{ {
} }
public void Playmusic (string sound){ public void Playmusic (string sound){
if (sound == "overworld") if (sound == "overworld")
overworldplayer.PlayLooping (); overworldplayer.PlayLooping ();
if (sound == "minigame") if (sound == "minigame")
minigameplayer.PlayLooping (); minigameplayer.PlayLooping ();
if (sound == "splashscreen") if (sound == "splashscreen")
splashscreenplayer.PlaySync (); splashscreenplayer.Play ();
if (sound == "walk") if (sound == "walk")
walkplayer.Play (); walkplayer.Play ();
if (sound == "poptart")
poptartplayer.Play ();
//TODO: Monalisa
} }
} }*/
} }

View File

@@ -61,6 +61,7 @@ namespace WorldOfPeacecraft
Message = new LinkedList<string> (); Message = new LinkedList<string> ();
LastLineRegex = new Regex ("^end:[0-9]+$"); LastLineRegex = new Regex ("^end:[0-9]+$");
ParserThread = new Thread (new ThreadStart (this.RunParser)); ParserThread = new Thread (new ThreadStart (this.RunParser));
ParserThread.IsBackground = true;
} }
private void RunParser () private void RunParser ()

View File

@@ -17,6 +17,7 @@ namespace WorldOfPeacecraft
this.Client = client; this.Client = client;
this.ReceiverBuffer = buffer; this.ReceiverBuffer = buffer;
ReceiverThread = new Thread(new ThreadStart(this.doReceive)); ReceiverThread = new Thread(new ThreadStart(this.doReceive));
ReceiverThread.IsBackground = true;
} }
public string Receive () public string Receive ()

View File

@@ -17,6 +17,7 @@ namespace WorldOfPeacecraft
this.Client = client; this.Client = client;
this.Buffer = buffer; this.Buffer = buffer;
this.SenderThread = new Thread(new ThreadStart(this.threadStart)); this.SenderThread = new Thread(new ThreadStart(this.threadStart));
this.SenderThread.IsBackground = true;
} }
public void Send (String message) public void Send (String message)