
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using FlatRedBall;
//using FlatRedBall.Input;
//using FlatRedBall.Math.Geometry;
//using Lidgren.Network;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Audio;
//using Microsoft.Xna.Framework.Content;
//using Microsoft.Xna.Framework.GamerServices;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//using Microsoft.Xna.Framework.Media;
//using Microsoft.Xna.Framework.Net;
//using Microsoft.Xna.Framework.Storage;
//using Wizard_Duel.Screens;
//using System;
//using TomShane.Neoforce.Controls;




//namespace Wizard_Duel.Screens
//{
//    public class NetworkScreen : Screen
//    {
       
//        // Neoforce GUI manager
        
//        #region Methods

//        Sprite background;
//        TextBox txtEdit;
//        Window window;
//        Button button;
//        Button button2;

//        public static bool isHost
//        {
//            get;
//            set; // could make this private if we don't want anyone but the Screen to set this
//        }
//        public static bool isClient
//        {
//            get;
//            set; // could make this private if we don't want anyone but the Screen to set this
//        }

//        public static NetPeerConfiguration config
//        {
//            get;
//            set; // could make this private if we don't want anyone but the Screen to set this
//        }

//        public static NetServer server
//        {
//            get;
//            set; // could make this private if we don't want anyone but the Screen to set this
//        }

//        public static NetClient client
//        {
//            get;
//            set; // could make this private if we don't want anyone but the Screen to set this
//        }

//        #region Constructor and Initialize

//        public NetworkScreen()
//            : base("NetworkScreen")
//        {
//            // Don't put initialization code here, do it in
//            // the Initialize method below
//            //   |   |   |   |   |   |   |   |   |   |   |
//            //   |   |   |   |   |   |   |   |   |   |   |
//            //   V   V   V   V   V   V   V   V   V   V   V

//        }

        

//        public override void Initialize(bool addToManagers)
//        {


            




//            // Set the screen up here instead of in the Constructor to avoid
//            // exceptions occurring during the constructor.

//            // The Screen even provides a content manager for us.  How nice!
//            Manager manager = Wizard_Duel.Game1.Manager;
//            FlatRedBallServices.Game.IsMouseVisible = true;

//            background = SpriteManager.AddSprite("Etherlight.jpg");
//            background.PixelSize = .0173f;

//            window = new Window(manager);
//            window.Init();
//            window.Text = "Network Menu";
//            window.Top = 150; // this is in pixels, top-left is the origin
//            window.Left = 250;
//            window.Width = 350;
//            window.Height = 350;
             
//            manager.Add(window);

//            // Create Button control and set the previous window as its parent.
//            button = new Button(manager);
//            button.Init();
//            button.Text = "Host";
//            button.Width = 72;
//            button.Height = 24;
//            button.Left = (window.ClientWidth / 2) - (button.Width / 2) - 40;
//            button.Top = window.ClientHeight - button.Height - 8;
//            button.Anchor = Anchors.Bottom;
//            button.Parent = window;
//            button.Click += new TomShane.Neoforce.Controls.EventHandler(host_Click);
            
//            button2 = new Button(manager);
//            button2.Init();
//            button2.Text = "Join";
//            button2.Width = 72;
//            button2.Height = 24;
//            button2.Left = (window.ClientWidth / 2) - (button2.Width / 2) + 40;
//            button2.Top = window.ClientHeight - button2.Height - 8;
//            button2.Anchor = Anchors.Bottom;
//            button2.Parent = window;
//            button2.Click += new TomShane.Neoforce.Controls.EventHandler(join_Click);

//            txtEdit = new TextBox(manager);
//            txtEdit.Init();
//            txtEdit.Parent = window;
//            txtEdit.Left = 16;
//            txtEdit.Top = 24;
//            txtEdit.Width = window.ClientWidth - 32;
//            txtEdit.Height = 20;
//            txtEdit.Anchor = Anchors.Left | Anchors.Top | Anchors.Right | Anchors.Bottom;
//            txtEdit.Text = "Enter IP Address Here";

//            // Manager setup -- we use default skin and do not 
//            // register manager as a component
//            // AddToManagers should be called LAST in this method:
//            if (addToManagers)
//            {
//                AddToManagers();
//            }
//        }

//        public override void AddToManagers()
//        {


//        }

//        #endregion

//        #region Public Methods

//        public override void Activity(bool firstTimeCalled)
//        {
//            base.Activity(firstTimeCalled);
//            if (isHost == true)
//            {
//                server_routine();
//            }
//            else if (isClient == true )
//            {
//                client_routine();
//            }
            
//        }

//        public override void Destroy()
//        {
//            base.Destroy();

//        }

//        public void host_Click(object source, TomShane.Neoforce.Controls.EventArgs e)
//        {

//            window.Remove(button);
//            button2.Dispose();
//            txtEdit.Dispose();

//            config = new NetPeerConfiguration("WizardNetConfig");
//            config.Port = 14242;
//            config.MaximumConnections = 100;

//            server = new NetServer(config);
//            server.Start();

//            isHost = true;
//            window.Text = "Waiting for connection";
            
//        }
//        public void join_Click(object source, TomShane.Neoforce.Controls.EventArgs e)
//        {

//            button.Dispose();
//            button2.Dispose();
//            txtEdit.Dispose();

//            window.Text = "Attempting to connect...";

//            NetPeerConfiguration config = new NetPeerConfiguration("WizardNetConfig");
//            client = new NetClient(config);


//            client.Start();
//            NetOutgoingMessage hail = client.CreateMessage();

//            string connectIP = txtEdit.Text;
            
//            client.Connect(connectIP, 14242);

//            isHost = false;
//            isClient = true;
//        }


//        public void server_routine()
//        {
//            NetIncomingMessage im;
//            while ((im = server.ReadMessage()) != null)
//            {
//                // handle incoming message
//                switch (im.MessageType)
//                {
//                    case NetIncomingMessageType.DebugMessage:
//                    case NetIncomingMessageType.ErrorMessage:
//                    case NetIncomingMessageType.WarningMessage:
//                    case NetIncomingMessageType.VerboseDebugMessage:
//                        string text = im.ReadString();

//                        break;
//                    case NetIncomingMessageType.StatusChanged:
//                        NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();
//                        if (status == NetConnectionStatus.Connected)
//                        {
//                            window.Visible = false;
//                            SpriteManager.RemoveSprite(background);
//                            MoveToScreen(typeof(GameScreen).FullName);
//                        }
//                        break;
//                }
                
//            }


//        }

//        public void client_routine()
//        {
           
//             NetIncomingMessage om;
//             while ((om = client.ReadMessage()) != null)
//             {
//                //  handle incoming message
//                 switch (om.MessageType)
//                 {

//                     case NetIncomingMessageType.StatusChanged:
//                         NetConnectionStatus status = (NetConnectionStatus)om.ReadByte();

//                        if (status == NetConnectionStatus.Connected)
//                         {
//                             window.Visible = false;
//                             SpriteManager.RemoveSprite(background);
//                             MoveToScreen(typeof(GameScreen).FullName);
//                         }
//                         break;


//                 }
//             }
            

//        }

        
//        #endregion


//        #endregion
//    }
//}
