/// <summary>
        /// Screen initialization.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");

                gameFont = content.Load<SpriteFont>("gamefont");

                // A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.
                Thread.Sleep(200);

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.
                ScreenManager.Game.ResetElapsedTime();

                // Load Controls

                Texture2D buttonTex = content.Load<Texture2D>( "ControlStuff/TestBtn" );
                SpriteFont buttonFont = content.Load<SpriteFont>( "ControlStuff/btnText" );

                testBtn1 = new Button( new Point( 50, 50 ), 100, 100, this );
                testBtn1.Texture = buttonTex;
                testBtn1.SetFont( buttonFont, Color.Black, Color.Red, Color.Yellow, Color.LightGray );
                testBtn1.Text = "TestBtn1";
                testBtn1.RegisterCallback( testBtn1_OnClick );

                testBtn2 = new Button( new Point( 200, 50 ), 150, 75, this );
                testBtn2.Texture = buttonTex;
                testBtn2.Text = "Button 2";
                testBtn2.SetFont( buttonFont, Color.Black, Color.Red, Color.Yellow, Color.LightGray );
                testBtn2.RegisterCallback( testBtn2_OnClick );

                testlistView = new ListView(4, new Point(400, 75), 150, 200, this);
                testlistView.Texture = buttonTex;
                testlistView.Font = buttonFont;
                testlistView.ArrowTexture = buttonTex;
                testlistView.ArrowFont = buttonFont;
                testlistView.AddElement("A");
                testlistView.AddElement("B");
                testlistView.AddElement("C");
                testlistView.AddElement("D");
                testlistView.AddElement("E");
                testlistView.AddElement("F");
                testlistView.AddElement("G");
                testlistView.AddElement("H");
                testlistView.AddElement("A");
                testlistView.RemoveElement("A");
                testlistView.RemoveElement("G");
                testlistView.Clear();
                testlistView.AddElement("A");
                testlistView.AddElement("B");
                testlistView.AddElement("C");
                testlistView.AddElement("D");
                testlistView.AddElement("E");
                testlistView.AddElement("F");
                testlistView.AddElement("G");
                testlistView.AddElement("H");
                testlistView.AddElement("A");

                testSelector = new Selector(new Point(50, 300), 150, 200, this);
                testSelector.Font = buttonFont;
                testSelector.ArrowTexture = buttonTex;
                testSelector.ArrowFont = buttonFont;
                testSelector.AddElement("A");
                testSelector.AddElement("B");
                testSelector.AddElement("C");
                testSelector.AddElement("D");
                testSelector.AddElement("E");
                testSelector.AddElement("F");
                testSelector.AddElement("G");
                testSelector.AddElement("H");
                testSelector.AddElement("A");
                testSelector.RemoveElement("A");
                testSelector.RemoveElement("G");
                testSelector.Clear();
                testSelector.AddElement("A");
                testSelector.AddElement("B");
                testSelector.AddElement("C");
                testSelector.AddElement("D");
                testSelector.AddElement("E");
                testSelector.AddElement("F");
                testSelector.AddElement("G");
                testSelector.AddElement("H");
                testSelector.AddElement("Asds");

            }
        }
        public override void Activate( bool instancePreserved )
        {
            if ( !instancePreserved )
            {
                ContentManager content = ScreenManager.Game.Content;

                // Set up the title
                titleFont = content.Load<SpriteFont>( "Fonts/PageTitle" );

                // Set up the Buttons
                Texture2D buttonTex = content.Load<Texture2D>( "UITextures/GUIButton" );
                SpriteFont buttonFont = content.Load<SpriteFont>( "Fonts/GUIFont" );

                // Back Button
                backButton = new Button( BACK_BUTTON_POS, BACK_BUTTON_WIDTH, BACK_BUTTON_HEIGHT, this );
                backButton.Texture = buttonTex;
                backButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                backButton.Text = "Back";
                backButton.RegisterCallback( backButton_OnClick );

                // Refresh Lobbies List button
                refreshButton = new Button( REFRESH_BUTTON_POS, STD_BUTTON_WIDTH, STD_BUTTON_HEIGHT, this );
                refreshButton.Texture = buttonTex;
                refreshButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                refreshButton.Text = "Refresh List";
                refreshButton.RegisterCallback( refreshButton_OnClick );

                // Join Selected Lobby Button
                joinButton = new Button( JOIN_LOBBY_BUTTON_POS, STD_BUTTON_WIDTH, STD_BUTTON_HEIGHT, this );
                joinButton.Texture = buttonTex;
                joinButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                joinButton.Text = "Join Selected Lobby";
                joinButton.RegisterCallback( joinButton_OnClick );
                joinButton.Active = false;

                // New Lobby Button
                newLobbyButton = new Button( NEW_LOBBY_BUTTON_POS, STD_BUTTON_WIDTH, STD_BUTTON_HEIGHT, this );
                newLobbyButton.Texture = buttonTex;
                newLobbyButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                newLobbyButton.Text = "Create New Lobby";
                newLobbyButton.RegisterCallback( newButton_OnClick );

                // Set up lobby list
                lobbyData = new List<LobbyData>();
                lobbies = new ListView( 8, LOBBY_LIST_POS, LOBBY_LIST_WIDTH, LOBBY_LIST_HEIGHT, this );
                lobbies.Font = content.Load<SpriteFont>( "Fonts/GUIFontBold" ); ;
                lobbies.Texture = content.Load<Texture2D>( "UITextures/ListViewItemTex" );
                lobbies.ArrowTexture = content.Load<Texture2D>( "UITextures/ArrowUp" );
                lobbies.ItemTextColour = LOBBY_LIST_ITEM_COLOUR;

                // Open the network connection
                GameManager.Instance.Client.Start();
                if ( string.IsNullOrEmpty( GameSettings.SERVER_URL ) )
                {
                    //GameManager.Instance.Client.DiscoverLocalPeers( GameSettings.SERVER_PORT_NUM );
                    string s = System.IO.File.ReadAllText( "Content/host.txt" );
                    GameManager.Instance.Client.Connect( s, GameSettings.SERVER_PORT_NUM );
                    //Console.WriteLine( s );
                }
                else
                {
                    GameManager.Instance.Client.Connect( GameSettings.SERVER_URL, GameSettings.SERVER_PORT_NUM );
                }
                GameManager.Instance.RegisterForPackets( this );
            }
        }
Exemple #3
0
        public override void Activate( bool instancePreserved )
        {
            if ( !instancePreserved )
            {
                ContentManager content = ScreenManager.Game.Content;

                titleFont = content.Load<SpriteFont>( "Fonts/PageTitle" );
                listHeadingFont = content.Load<SpriteFont>( "Fonts/ListHeading" );

                // Set up the Buttons
                Texture2D buttonTex = content.Load<Texture2D>( "UITextures/GUIButton" );
                SpriteFont buttonFont = content.Load<SpriteFont>( "Fonts/GUIFont" );

                // Ready Button
                readyButton = new Button( READY_BUTTON_POS, STD_BUTTON_WIDTH, STD_BUTTON_HEIGHT, this );
                readyButton.Texture = buttonTex;
                readyButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                readyButton.Text = "Ready!";
                readyButton.RegisterCallback( readyButton_OnClick );

                // Back Button
                backButton = new Button( BACK_BUTTON_POS, BACK_BUTTON_WIDTH, BACK_BUTTON_HEIGHT, this );
                backButton.Texture = buttonTex;
                backButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                backButton.Text = "Back";
                backButton.RegisterCallback( backButton_OnClick );

                // Switch Team Button
                teamButton = new Button( TEAM_BUTTON_POS, STD_BUTTON_WIDTH, STD_BUTTON_HEIGHT, this );
                teamButton.Texture = buttonTex;
                teamButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                teamButton.Text = "Change Team";
                teamButton.RegisterCallback( teamButton_OnClick );

                // Switch Role Button
                roleButton = new Button( ROLE_BUTTON_POS, STD_BUTTON_WIDTH, STD_BUTTON_HEIGHT, this );
                roleButton.Texture = buttonTex;
                roleButton.SetFont( buttonFont,
                    BTNTEXT_INERT_COLOUR,
                    BTNTEXT_HOVER_COLOUR,
                    BTNTEXT_PRIMED_COLOUR,
                    BTNTEXT_INACTIVE_COLOUR );
                roleButton.Text = "Change Role";
                roleButton.RegisterCallback( roleButton_OnClick );

                // Set up the team lists
                Texture2D listItemTex = content.Load<Texture2D>( "UITextures/ListViewItemTex" );
                SpriteFont listItemFont = content.Load<SpriteFont>( "Fonts/GUIFontBold" );

                // Red team list
                redTeamList = new ListView( 8, RED_LIST_POS, LIST_WIDTH, LIST_HEIGHT, this );
                redTeamList.Texture = listItemTex;
                redTeamList.Font = listItemFont;
                redTeamList.ItemTextColour = TEAM_LIST_TEXT_COLOUR;

                // Blue team list
                blueTeamList = new ListView( 8, BLUE_LIST_POS, LIST_WIDTH, LIST_HEIGHT, this );
                blueTeamList.Texture = listItemTex;
                blueTeamList.Font = listItemFont;
                blueTeamList.ItemTextColour = TEAM_LIST_TEXT_COLOUR;

                GameManager.Instance.RegisterForPackets( this );
            }
        }