116 lines
2.9 KiB
C#
116 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace WorldOfPeacecraft
|
|
{
|
|
public class Gui : Form, IGui
|
|
{
|
|
private const int ChatWidth = 300;
|
|
private const int OnlinePlayerWidth = 150;
|
|
private IBackend Backend;
|
|
public Form MainForm { get; set; }
|
|
|
|
private MapPanel MapPanel;
|
|
private ChatPanel ChatPanel;
|
|
private OnlinePlayerList OnlinePlayerList;
|
|
|
|
//private Music m = new Music();
|
|
|
|
public Gui ()
|
|
{
|
|
|
|
}
|
|
|
|
public void SetBackend (IBackend backend)
|
|
{
|
|
Backend = backend;
|
|
}
|
|
|
|
public void FocusMap ()
|
|
{
|
|
MapPanel.Focus();
|
|
}
|
|
|
|
protected override void OnLoad (EventArgs e)
|
|
{
|
|
base.OnLoad (e);
|
|
InitializeComponents ();
|
|
Backend.StartThreads ();
|
|
}
|
|
|
|
protected override void OnPaint (PaintEventArgs e)
|
|
{
|
|
lock (Backend) {
|
|
base.OnPaint(e);
|
|
}
|
|
}
|
|
|
|
public void InitializeComponents ()
|
|
{
|
|
MapPanel.InitializeComponents ();
|
|
ChatPanel.InitializeComponents ();
|
|
OnlinePlayerList.InitializeComponents ();
|
|
this.SuspendLayout();
|
|
this.Size = new Size(OnlinePlayerWidth + 400 + ChatWidth, 400);
|
|
OnlinePlayerList.Location = new Point(0,0);
|
|
OnlinePlayerList.Size = new Size(OnlinePlayerWidth, 400);
|
|
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.MaximizeBox = false;
|
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
|
this.Text = "World of Peacecraft";
|
|
this.ShowIcon = false;
|
|
|
|
this.Controls.Add (OnlinePlayerList);
|
|
this.Controls.Add (MapPanel);
|
|
this.Controls.Add (ChatPanel);
|
|
|
|
this.ResumeLayout();
|
|
|
|
//m.Playmusic ("overworld");
|
|
}
|
|
|
|
protected override void OnClosing (System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
base.OnClosing (e);
|
|
MainForm.Close();
|
|
Backend.Stop ();
|
|
}
|
|
|
|
public void PerformRefresh ()
|
|
{
|
|
this.BeginInvoke(new MethodInvoker(delegate
|
|
{
|
|
MapPanel.PerformLayout ();
|
|
this.SuspendLayout();
|
|
this.SetClientSizeCore(OnlinePlayerWidth + MapPanel.Width + ChatWidth, MapPanel.Height);
|
|
OnlinePlayerList.Size = new Size(OnlinePlayerWidth, MapPanel.Height);
|
|
MapPanel.Location = new Point(OnlinePlayerWidth, 0);
|
|
ChatPanel.Location = new Point (OnlinePlayerWidth + MapPanel.Width, 0);
|
|
ChatPanel.Size = new Size (ChatWidth, MapPanel.Height);
|
|
this.ResumeLayout();
|
|
ChatPanel.UpdateData ();
|
|
this.Refresh();
|
|
}));
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|