Splashscreen wechselt jetzt erst zur gui nachdem die Map vom server empfangen wurde

This commit is contained in:
2014-05-14 10:31:41 +02:00
parent f4325f6030
commit a640c92961
4 changed files with 30 additions and 28 deletions

View File

@@ -17,6 +17,8 @@ namespace WorldOfPeacecraft
private Buffer SenderBuffer; private Buffer SenderBuffer;
private IGui Gui; private IGui Gui;
private int SelfId; private int SelfId;
private AutoResetEvent InitializedEvent = new AutoResetEvent(false);
private bool initialized = false;
public Backend (IGui gui) public Backend (IGui gui)
{ {
@@ -30,9 +32,9 @@ namespace WorldOfPeacecraft
Parse = new Parser (this, receiverBuffer); Parse = new Parser (this, receiverBuffer);
Rec = new Receiver (Client, receiverBuffer); Rec = new Receiver (Client, receiverBuffer);
Send = new Sender (Client, SenderBuffer); Send = new Sender (Client, SenderBuffer);
SenderBuffer.AddLine ("get:map");
SenderBuffer.AddLine ("get:me"); SenderBuffer.AddLine ("get:me");
SenderBuffer.AddLine ("get:ents"); SenderBuffer.AddLine ("get:ents");
SenderBuffer.AddLine ("get:map");
} }
public void SetSelfId (int id) public void SetSelfId (int id)
@@ -98,6 +100,7 @@ namespace WorldOfPeacecraft
public void SetMap (Map map) public void SetMap (Map map)
{ {
this.Map = map; this.Map = map;
InitializedEvent.Set();
} }
public ITile[,] GetMap () public ITile[,] GetMap ()
@@ -166,12 +169,12 @@ namespace WorldOfPeacecraft
} }
} }
public void RefreshGui() public void RefreshGui ()
{ {
Gui.PerformRefresh(); Gui.PerformRefresh ();
} }
public void StartThreads() { private void StartThreads() {
Parse.Start (); Parse.Start ();
Rec.Start (); Rec.Start ();
Send.Start (); Send.Start ();
@@ -183,8 +186,11 @@ namespace WorldOfPeacecraft
Client.Close (); Client.Close ();
} }
public void Connect(){ public void Initialize(){
Client.Connect ("localhost", 9999); Client.Connect ("localhost", 9999);
StartThreads ();
InitializedEvent.WaitOne();
initialized = true;
} }
} }
} }

View File

@@ -16,6 +16,7 @@ namespace WorldOfPeacecraft
private MapPanel MapPanel; private MapPanel MapPanel;
private ChatPanel ChatPanel; private ChatPanel ChatPanel;
private OnlinePlayerList OnlinePlayerList; private OnlinePlayerList OnlinePlayerList;
private bool loaded = false;
//private Music m = new Music(); //private Music m = new Music();
@@ -44,7 +45,6 @@ namespace WorldOfPeacecraft
{ {
base.OnLoad (e); base.OnLoad (e);
InitializeComponents (); InitializeComponents ();
Backend.StartThreads ();
} }
protected override void OnPaint (PaintEventArgs e) protected override void OnPaint (PaintEventArgs e)
@@ -62,11 +62,7 @@ namespace WorldOfPeacecraft
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);
OnlinePlayerList.Size = new Size(OnlinePlayerWidth, 400);
MapPanel.Location = new Point(OnlinePlayerWidth,0); MapPanel.Location = new Point(OnlinePlayerWidth,0);
MapPanel.Size = new Size(400, 400);
ChatPanel.Location = new Point (OnlinePlayerWidth + 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;
@@ -78,6 +74,8 @@ namespace WorldOfPeacecraft
this.Controls.Add (ChatPanel); this.Controls.Add (ChatPanel);
this.ResumeLayout(); this.ResumeLayout();
loaded = true;
this.PerformRefresh();
//m.Playmusic ("overworld"); //m.Playmusic ("overworld");
} }
@@ -91,13 +89,12 @@ namespace WorldOfPeacecraft
public void PerformRefresh () public void PerformRefresh ()
{ {
this.BeginInvoke(new MethodInvoker(delegate if (loaded) {
{ this.BeginInvoke (new MethodInvoker (delegate {
MapPanel.PerformLayout (); MapPanel.PerformLayout ();
this.SuspendLayout(); this.SuspendLayout();
this.SetClientSizeCore(OnlinePlayerWidth + MapPanel.Width + ChatWidth, MapPanel.Height); this.SetClientSizeCore(OnlinePlayerWidth + MapPanel.Width + ChatWidth, MapPanel.Height);
OnlinePlayerList.Size = new Size(OnlinePlayerWidth, MapPanel.Height); OnlinePlayerList.Size = new Size(OnlinePlayerWidth, MapPanel.Height);
MapPanel.Location = new Point(OnlinePlayerWidth, 0);
ChatPanel.Location = new Point (OnlinePlayerWidth + MapPanel.Width, 0); ChatPanel.Location = new Point (OnlinePlayerWidth + MapPanel.Width, 0);
ChatPanel.Size = new Size (ChatWidth, MapPanel.Height); ChatPanel.Size = new Size (ChatWidth, MapPanel.Height);
this.ResumeLayout(); this.ResumeLayout();
@@ -105,6 +102,7 @@ namespace WorldOfPeacecraft
this.Refresh(); this.Refresh();
})); }));
} }
}
public void LoadResources(){ public void LoadResources(){
MapPanel.LoadResources (); MapPanel.LoadResources ();

View File

@@ -22,10 +22,8 @@ namespace WorldOfPeacecraft
void moveRight(); void moveRight();
void MoveTo(int x, int y); void MoveTo(int x, int y);
void StartThreads();
void Stop(); void Stop();
void Connect(); void Initialize();
} }
} }

View File

@@ -37,9 +37,9 @@ namespace WorldOfPeacecraft
} }
private void ThreadEntry(){ private void ThreadEntry(){
Thread.Sleep(250);
gui.LoadResources (); gui.LoadResources ();
backend.Connect (); backend.Initialize ();
Thread.Sleep (1000);
if (GuiHasLoaded != null) if (GuiHasLoaded != null)
GuiHasLoaded (this,gui); GuiHasLoaded (this,gui);
} }