void UserProfileFrame_KeyUp(GUIElement sender, KeyEventArgs e)
        {
            if (labelBox.Text != String.Empty &&
                e.InterestingKeys.Contains<Keys>(Keys.Enter))
            {
                this.Exit();

            }
        }
 void UserProfileFrame_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.Enter))
     {
         foreach (LabelBox labelBox in InputFields.Values)
             if (labelBox.Text == String.Empty)
                 return;
         this.Exit();
         if (SubmitInput != null)
             SubmitInput(this);
     }
 }
        private void HandleMouseClickEvents(GUIElement sender, MouseEventArgs mouseEvents)
        {
            var game = GameEngine.Singleton.GetPlayState();
            var point =
                new Vector2((float)mouseEvents.PreviousMouseState.X,
                    (float)mouseEvents.PreviousMouseState.Y).C2P();
            OnManipulatePhysics(new ManipulatePhysicsEventArgs(point));

            if (mouseEvents.CurrentMouseState.LeftButton == ButtonState.Released)
                OnManipulatePhysicsOff(new ManipulatePhysicsEventArgs(point));
            //foreach (Actor actor in game.ActiveMap.GameObjects)
            //{
                //if (PhysicsCore.CollisionEngine.PolygonContainsPoint(
                //    actor.PolyBody,
                //    point))
                //{
                //    OnManipulatePhysics(new InteractEventArgs(actor));
                //    return;
                //}
            //}
        }
 private void HandleKeydownEvents(GUIElement sender, KeyEventArgs keyEvents)
 {
     if (keyEvents.InterestingKeys.Contains<Keys>(Keys.Space))
     {
         if (keyEvents.InterestingKeys.Contains<Keys>(Keys.D))
             OnJump(new PlayerEventArgs(Directions.Right));
         else if (keyEvents.InterestingKeys.Contains<Keys>(Keys.A))
             OnJump(new PlayerEventArgs(Directions.Left));
         else
             OnJump(new PlayerEventArgs(Directions.Static));
     }
     else if (keyEvents.InterestingKeys.Contains<Keys>(Keys.D))
         OnMove(new PlayerEventArgs(Directions.Right));
     else if (keyEvents.InterestingKeys.Contains<Keys>(Keys.A))
         OnMove(new PlayerEventArgs(Directions.Left));
     else if (keyEvents.InterestingKeys.Contains<Keys>(Keys.W))
         OnChangePhysicsGunSettings(
             new PlayerEventArgs(Directions.Up));
     else if (keyEvents.InterestingKeys.Contains<Keys>(Keys.S))
         OnChangePhysicsGunSettings(
             new PlayerEventArgs(Directions.Down));
 }
 void quitButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     GameEngine.Singleton.DestroyAndRemoveStates(2);
 }
 void continueButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     this.Exit();
 }
 void ActiveFrame_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Length > 0) {
         this.Exit();
     }
 }
 void MouseClick(GUIElement sender, MouseEventArgs e)
 {
     if (!BlockMode)
     {
         if ((ObjectType == "InterPortal") || (ObjectType == "IntraPortal"))
         {
             InputBoxFrame portalInputBox = new InputBoxFrame("New " + ObjectType, new string[] { "Portal ID", "ID of Portal To Link To" });
             portalInputBox.SubmitInput += new FrameEventHandler(
                 inputBox =>
                     EditorManager.PixelsToTile(new Vector2(currentMouseState.X, currentMouseState.Y)).addObjectContent(ObjectCreator.create(ObjectCreator.objectCodes.IndexOf(ObjectType), ((InputBoxFrame)inputBox).InputFields["Portal ID"].Text, ((InputBoxFrame)inputBox).InputFields["ID of Portal To Link To"].Text)));
             UIManager.AddAndLoad(portalInputBox);
         }
         else
         {
             EditorManager.PixelsToTile(new Vector2(currentMouseState.X, currentMouseState.Y)).addObjectContent(ObjectCreator.create(ObjectCreator.objectCodes.IndexOf(ObjectType)));
         }
     }
 }
        void PopUpMenuControl_MouseOver(GUIElement sender, MouseEventArgs e)
        {
            if (e.CurrentMouseState.LeftButton == ButtonState.Pressed)
            {
                var deltaX = e.CurrentMouseState.X - e.PreviousMouseState.X;
                var deltaY = e.CurrentMouseState.Y - e.PreviousMouseState.Y;

                this.MoveAll(this.Location + new Vector2(deltaX, deltaY));
            }
        }
 void exitButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     this.Close();
 }
 void ActiveFrame_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     var block = new Block(1, e.CurrentMouseState.X, e.CurrentMouseState.Y);
     ActiveMap.AddGameObject(block);
     PhysicsManager.AddPolyBody(block.PolyBody);
 }
 // Events
 void KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.Escape))
         this.Exit();
     if (e.InterestingKeys.Contains<Keys>(Keys.Enter))
         ParseText();
 }
 void KeyDown(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.LeftShift) ||
         e.InterestingKeys.Contains<Keys>(Keys.RightShift))
         isCaps = true;
     else isCaps = false;
 }
 void SelectGame(GUIElement sender, MouseEventArgs e)
 {
     var label = (Label)sender;
     GameEngine.Singleton.AddAndLoad(new TheGameState(label.Text, false));
 }
 void EditorConsole_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.Enter))
     {
         AcceptCommand();
     }
     else NuetralizeConsole();
     if (e.InterestingKeys.Contains<Keys>(Keys.Escape))
         CommandBox.Text = String.Empty;
 }
 void ActiveFrame_KeyDown(GUIElement sender, KeyEventArgs e)
 {
     // Only look at the first key, because only one event can happen at a time
     // hence: e.InterestingKeys[0]
     if (UIManager.ActiveFrame.ActiveControl == null &&
             keysToCheck.Contains<Keys>(e.InterestingKeys[0]))
         KeyPressed(e.InterestingKeys[0]);
     lastKeyboardState = e;
 }
 void KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (UIManager.ActiveFrame.ActiveControl == null)
     {
         if (BlockMode)
         {
             if (e.InterestingKeys.Contains<Keys>(Keys.D1))
             {
                 BlockType = "HalfBlock";
             }
             else if (e.InterestingKeys.Contains<Keys>(Keys.D2))
             {
                 BlockType = "TriangleBlock";
             }
         }
         else
         {
             if (e.InterestingKeys.Contains<Keys>(Keys.D1))
             {
                 ObjectType = "Block";
             }
             if (e.InterestingKeys.Contains<Keys>(Keys.D2))
             {
                 ObjectType = "PhysicsHatGravity";
             }
             if (e.InterestingKeys.Contains<Keys>(Keys.D3))
             {
                 ObjectType = "InterPortal";
             }
             if (e.InterestingKeys.Contains<Keys>(Keys.D4))
             {
                 ObjectType = "IntraPortal";
             }
         }
         if (e.InterestingKeys.Contains<Keys>(Keys.G))
         {
             if (EditorManager.showGrid == false)
                 EditorManager.showGrid = true;
             else
                 EditorManager.showGrid = false;
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.Tab))
         {
             BlockMode = true;
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.LeftShift))
         {
             BlockMode = false;
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.C) &&
             !UIManager.ActiveFrame.Controls.Any<Control>(c => c is EditorConsole))
         {
             UIManager.ActiveFrame.AddControl(
                 new EditorConsole(
                     new Vector2(currentMouseState.X, currentMouseState.Y)));
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.LeftControl))
         {
             FileIO.SaveToFile(EditorManager.ToList());
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.RightControl))
         {
             List<Actor> actors = FileIO.LoadFromFile();
             EditorManager.ClearAllTiles();
             bool loadTiles = true;
             foreach (Actor actor in actors)
             {
                 if (actor == null)
                     loadTiles = false;
                 else
                 {
                     if (loadTiles)
                         EditorManager.MetersToTile(actor.PolyBody.Position).BlockContents = ObjectCreator.create(actor.objectType);
                     else
                     {
                         if ((actor.objectType == ObjectCreator.objectCodes.IndexOf("InterPortal")) || (actor.objectType == ObjectCreator.objectCodes.IndexOf("IntraPortal")))
                             EditorManager.MetersToTile(actor.PolyBody.Position).addObjectContent(ObjectCreator.create(actor.objectType, ((ILinked)actor).ID, ((ILinked)actor).PartnerAddress));
                         else
                             EditorManager.MetersToTile(actor.PolyBody.Position).addObjectContent(ObjectCreator.create(actor.objectType));
                     }
                 }
             }
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.C) &&
                 !UIManager.ActiveFrame.Controls.Any<Control>(c => c is EditorConsole))
         {
             UIManager.ActiveFrame.AddControl(
                 new EditorConsole(
                     new Vector2(currentMouseState.X, currentMouseState.Y)));
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.LeftControl))
         {
             FileIO.SaveToFile(EditorManager.ToList());
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.RightControl))
         {
             List<Actor> actors = FileIO.LoadFromFile();
             EditorManager.ClearAllTiles();
             foreach (Actor actor in actors)
             {
                 EditorManager.MetersToTile(actor.PolyBody.Position).addObjectContent(ObjectCreator.create(actor.objectType));
             }
         }
         else if (e.InterestingKeys.Contains<Keys>(Keys.Escape))
             this.Exit();
         else if (e.InterestingKeys.Contains<Keys>(Keys.OemTilde))
             GameEngine.Singleton.AddAndLoad(new ConsoleState());
     }
 }
        void newGameButton_MouseClick(GUIElement sender, MouseEventArgs e)
        {
            // UNCOMMENT TO PICK MAP
            // GameEngine.Singleton.AddAndLoad(new PhysicsDemoState());
            // GameEngine.Singleton.AddAndLoad(new ConsoleState ());
            //  GameEngine.Singleton.AddAndLoad(new BouncerDemoState());
            //  GameEngine.Singleton.AddAndLoad(new MapDemoState());
            //  GameEngine.Singleton.AddAndLoad(new GraphicsDemoState());
            //  GameEngine.Singleton.AddAndLoad(new GravityManipulationDemo());
            // GameEngine.Singleton.AddAndLoad(new PuzzleDemoState());
            //  GameEngine.Singleton.AddAndLoad(new MapDemoState());
            // GameEngine.Singleton.AddAndLoad(new EditorState());
            // UIManager.AddAndLoad(new UserProfileFrame());

            InputBoxFrame userProfileFrame = new InputBoxFrame("New Game", new string[] { "Enter Profile Name" });
            userProfileFrame.SubmitInput += new FrameEventHandler(
                inputBox =>
                    GameEngine.Singleton.AddAndLoad(
                    new TheGameState(((InputBoxFrame)inputBox).InputFields["Enter Profile Name"].Text, true)));
            UIManager.AddAndLoad(userProfileFrame);
        }
 void MouseOver(GUIElement sender, MouseEventArgs e)
 {
     currentMouseState = e.CurrentMouseState;
     EditorManager.highlightTile(EditorManager.PixelsToTile(new Vector2(e.CurrentMouseState.X, e.CurrentMouseState.Y)));
 }
 void highScoreButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     UIManager.AddAndLoad(new HighScoreFrame());
 }
 void ActiveFrame_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.Escape))
         this.Exit();
     if (e.InterestingKeys.Contains<Keys>(Keys.OemTilde))
         GameEngine.Singleton.AddAndLoad(new ConsoleState());
 }
 void instructionsButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     UIManager.AddAndLoad(new InstructionsMenuFrame());
 }
 void helpButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     InstructionsMenuFrame instructionsFrame = new InstructionsMenuFrame();
     UIManager.AddAndLoad(instructionsFrame);
 }
 void loadGameButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     UIManager.AddAndLoad(new LoadGameMenuFrame());
 }
        void Client_MouseDown(GUIElement sender, MouseEventArgs e)
        {
            var point =
                new Vector2((float)e.PreviousMouseState.X,
                    (float)e.PreviousMouseState.Y).C2P();

            if (e.PreviousMouseState.LeftButton == ButtonState.Pressed)
                OnManipulatePhysicsOn(new ManipulatePhysicsEventArgs(point));
        }
 void MainMenuFrame_KeyUp(GUIElement sender, KeyEventArgs e)
 {
     if (e.InterestingKeys.Contains<Keys>(Keys.OemTilde))
         GameEngine.Singleton.AddAndLoad(new ConsoleState());
     else if (e.InterestingKeys.Contains<Keys>(Keys.E))
         GameEngine.Singleton.AddAndLoad(new EditorState());
 }
        private void HandleKeyupEvents(GUIElement sender, KeyEventArgs keyEvents)
        {
            if (keyEvents.InterestingKeys.Contains<Keys>(Keys.D) ||
                keyEvents.InterestingKeys.Contains<Keys>(Keys.A) ||
                keyEvents.InterestingKeys.Contains<Keys>(Keys.Space))
                OnStop(new PlayerEventArgs(Directions.Static));
            else if (keyEvents.InterestingKeys.Contains<Keys>(Keys.F))
                OnShoot(new PlayerEventArgs(Directions.Front));
            else if (keyEvents.InterestingKeys.Contains<Keys>(Keys.LeftShift))
            {
                var game = GameEngine.Singleton.GetPlayState();
                var player = game.ActiveMap.MainPlayer.PolyBody;

                foreach (Actor portal in game.ActiveMap.LinkedObjects.Values)
                {
                    if (portal is Actors.Portal && PhysicsCore.CollisionEngine.TestCollisionPoly(
                            portal.PolyBody, player))
                    {
                        OnEnterPortal(new InteractEventArgs(portal));
                        return;
                    }
                }
            }
        }
 void trueFalseButton_MouseClick(GUIElement sender, MouseEventArgs e)
 {
     if (trueFalseButton.TrueOrFalse)
         trueFalseButton.TrueOrFalse = false;
     else
         trueFalseButton.TrueOrFalse = true;
 }
 private void HandleMouseScrollEvents(GUIElement sender, MouseEventArgs e)
 {
     if (e.CurrentMouseState.ScrollWheelValue > e.PreviousMouseState.ScrollWheelValue)
         OnSwitchPhysicsGun(new PlayerEventArgs(Directions.Up));
     else
         OnSwitchPhysicsGun(new PlayerEventArgs(Directions.Down));
 }
        void EnterButton_MouseClick(GUIElement sender, MouseEventArgs e)
        {
            Size previousWindowSize = (Size)Utilities.DefaultSettings.Settings["WindowSize"];
            float previousPixelsPerMeterValue = (float) Utilities.DefaultSettings.Settings["PixelsPerMeter"];
            bool previousTriviaQuestionsValue = (bool) Utilities.DefaultSettings.Settings["Trivia Questions"];

            bool triviaQuestionsValue;
            float windowSizeXValue;
            float windowSizeYValue;
            float pixelsPerMeterValue;

            if (trueFalseButton.TrueOrFalse)
                triviaQuestionsValue = true;
            else
                triviaQuestionsValue = false;

            windowSizeXValue = float.Parse(WindowSizeXBox.Text);
            windowSizeYValue = float.Parse(WindowSizeYBox.Text);
            pixelsPerMeterValue = float.Parse(PixelsPerMeterBox.Text);
            Utilities.DefaultSettings.Settings["WindowSize"] = new Size(windowSizeXValue,windowSizeYValue);
            Utilities.DefaultSettings.Settings["PixelsPerMeter"] =  pixelsPerMeterValue;

            bool changedSettings = false;

            if (pixelsPerMeterValue != previousPixelsPerMeterValue
                || triviaQuestionsValue != previousTriviaQuestionsValue
                || windowSizeXValue != previousWindowSize.X
                || windowSizeYValue != previousWindowSize.Y)
                changedSettings = true;
               if (changedSettings)
               {
               this.Exit();
               UIManager.AddAndLoad(userMessageFrame);
               }
               this.Exit();
        }