public SerializableLevel initiateLoad(string filenamePassed)
 {
     level = new SerializableLevel(new Level());
     filename = filenamePassed + ".sav";
     StorageDevice.BeginShowSelector(PlayerIndex.One, this.loadLevel, null);
     return level;
 }
        public override void Update(GameTime gameTime)
        {
            // Update stuff here!
            if (switchToLoad == true)
            {
                switchToLoad = false;
                AddScreenAndChill(new LevelEditScreen());

            }
            if (btnLemBack.IsClicked())
            {
                AddScreenAndChill(new LevelEditScreen());

            }
            if (btnLemSave.IsClicked())
            {
                GameManager.GlobalInstance.LevelNames.addFilename(GameManager.GlobalInstance.activeLevel.levelName);
                var sLevel = new SerializableLevel(GameManager.GlobalInstance.activeLevel);
                new SaveLevel().initiateSave(sLevel);
                wasSaveSuccess = true;
                //AddScreenAndChill(new LevelEditScreen());
            }
            if (btnLemLoad.IsClicked())
            {
                var confirmResult = System.Windows.Forms.MessageBox.Show("Do you want to save the level before loading?", "Confirm Save!", System.Windows.Forms.MessageBoxButtons.YesNo);
                if (confirmResult.ToString() == "Yes")
                {
                    // if 'Yes' do something here
                    GameManager.GlobalInstance.LevelNames.addFilename(GameManager.GlobalInstance.activeLevel.levelName);
                    var sLevel = new SerializableLevel(GameManager.GlobalInstance.activeLevel);
                    new SaveLevel().initiateSave(sLevel);
                    System.Windows.Forms.MessageBox.Show("Save Successful");
                }
                else
                {
                    // if 'No' do something here
                    System.Windows.Forms.MessageBox.Show("Level Changes Discarded!");
                }
                AddScreenAndChill(new LoadLevelScreen());
            }
            if (btnLemClear.IsClicked())
            {
                //Clear the current level that you have been building and go to the level
                //editor screen with a blank level.
                var confirmResult = System.Windows.Forms.MessageBox.Show("Are you sure you want to clear all objects?", "Confirm Clear!", System.Windows.Forms.MessageBoxButtons.YesNo);
                if (confirmResult.ToString() == "Yes")
                {
                    //clear the levlel of all object
                    this.playingLevel.clearAllObjects();
                    //clear the undo/redo history
                    CommandManager commandManager = CommandManager.getInstance();
                    commandManager.clearUndoRedo();

                }
                else
                {

                }
                AddScreenAndChill(new LevelEditScreen());
            }
            if (btnLemExit.IsClicked())
            {
                var confirmResult = System.Windows.Forms.MessageBox.Show("Do you want to save the level before exiting?", "Confirm Save!", System.Windows.Forms.MessageBoxButtons.YesNo);
                if (confirmResult.ToString() == "Yes")
                {
                    // if 'Yes' do something here
                    GameManager.GlobalInstance.LevelNames.addFilename(GameManager.GlobalInstance.activeLevel.levelName);
                    var sLevel = new SerializableLevel(GameManager.GlobalInstance.activeLevel);
                    new SaveLevel().initiateSave(sLevel);
                    System.Windows.Forms.MessageBox.Show("Save Successful");
                }
                else
                {
                    // if 'No' do something here
                    System.Windows.Forms.MessageBox.Show("Level Changes Discarded!");
                }
                ScreenManager.Exit();
            }
            btnLemSave.Update(MouseState);
            btnLemLoad.Update(MouseState);
            btnLemExit.Update(MouseState);
            btnLemClear.Update(MouseState);
            btnLemBack.Update(MouseState);
        }
 public void initiateSave(SerializableLevel levelPassed)
 {
     level = levelPassed;
     device = null;
     StorageDevice.BeginShowSelector(PlayerIndex.One, this.saveLevel, null);
 }
        public override void Update(GameTime gameTime)
        {
            // Update the palette -- and make sure the rest should be updated.
            palette.Update(MouseState);

            if (palette.ShouldBeModal)
            {
                return;
            }

            // Update stuff here!
            if (btns["Home"].IsClicked())
            {
                var confirmResult = System.Windows.Forms.MessageBox.Show("Do you want to save the level before going home?", "Confirm Save!", System.Windows.Forms.MessageBoxButtons.YesNo);
                if (confirmResult.ToString() == "Yes")
                {
                    // if 'Yes' do something here
                    GameManager.GlobalInstance.LevelNames.addFilename(GameManager.GlobalInstance.activeLevel.levelName);
                    var sLevel = new SerializableLevel(GameManager.GlobalInstance.activeLevel);
                    new SaveLevel().initiateSave(sLevel);
                    System.Windows.Forms.MessageBox.Show("Save Successful");
                }
                else
                {
                    // if 'No' do something here
                    System.Windows.Forms.MessageBox.Show("Level Changes Discarded!");
                }
                AddScreenAndChill(new MenuScreen());
            }
            if (btns["Menu"].IsClicked())
            {
                AddScreenAndChill(new LevelEditorMenuScreen());
            }
            if (btns["Play"].IsClicked())
            {
                //going to set the gameManager to have a reference to myLevel so that we can access
                //all the objects that we've created and now want to display on the gamescreen.
                //GameManager.GlobalInstance.activeLevel = myLevel; //commented out as were just re referencing, didn't seem to break anything.
                //also we want to check to make sure that there are objects on the playing field. if there are not then dont allow
                //transfer to the gameScreen.
                if(myLevel.objectList.Count == 0){
                    //show popup saying that you need to add at least 1 object to the level
                    System.Windows.Forms.MessageBox.Show("A minimum of 1 object must be added prior to playing the level.");
                }
                else{
                    //otherwise go to the gamescreen and play the level.
                    AddScreenAndChill(new GameScreen());
                }

            }
            if (btns["UpTime"].IsClicked() )
            {
                //Call A Method Defined In Another Class
            }
            if (btns["MoreUp"].IsClicked())
            {
                if (intUpTime < 30)
                {
                    intUpTime++;
                    GameManager.GlobalInstance.activeLevel.upTime = intUpTime;
                }
            }
            if (btns["LessUp"].IsClicked())
            {
                if (intUpTime > 1 && intUpTime > intHoldTime)
                {
                    intUpTime--;
                    GameManager.GlobalInstance.activeLevel.upTime = intUpTime;
                }
            }
            if (btns["MoreHold"].IsClicked())
            {
                if ((intHoldTime < 30) && (intHoldTime < intUpTime))
                {
                    intHoldTime++;
                    GameManager.GlobalInstance.activeLevel.holdTime = intHoldTime;
                }
            }
            if (btns["LessHold"].IsClicked())
            {
                if (intHoldTime > 0)
                {
                    intHoldTime--;
                    GameManager.GlobalInstance.activeLevel.holdTime = intHoldTime;
                }
            }
            if (btns["Redo"].IsClicked())
            {
                //get the command manager to redo
                CommandManager commandManager = CommandManager.getInstance();
                commandManager.redo();

            }
            if (btns["Undo"].IsClicked())
            {
                //get the command manager to undo
                CommandManager commandManager = CommandManager.getInstance();
                commandManager.undo();

            }
            if (btns["AddAlpha"].IsClicked())
            {
                palette.RequestStateChange("Alph");
                palette.Show();
            }
            if (btns["AddShape"].IsClicked())
            {
                palette.RequestStateChange("Shape");
                palette.Show();
            }
            if (btns["AddNumbr"].IsClicked())
            {
                palette.RequestStateChange("Num");
                palette.Show();
            }
            //if (btns["Edit"].IsClicked())
            //{

            //}
            if (btns["HelpBtn"].IsClicked())
            {
                AddScreenAndChill(new LEHelpScreen());
            }
            if (btns["Multiple"].IsClicked())
            {
                if (multiState)
                {
                    multiState = false;
                    btns["Multiple"] = MakeButton(355, 30, "LevelEditorGUI/multipleToggleOff");
                    btns["Multiple"].Update(MouseState);
                    GameManager.GlobalInstance.activeLevel.multiSelect = false;
                }
                else
                {
                    multiState = true;
                    btns["Multiple"] = MakeButton(355, 30, "LevelEditorGUI/multipleToggleOn");
                    btns["Multiple"].Update(MouseState);
                    GameManager.GlobalInstance.activeLevel.multiSelect = true;
                }
                //Call A Method Defined In Another Class
            }

            // Handle the creation of object/entities.
            if (palette.ObjectFactory.IsReady())
            {
                var entity = palette.ObjectFactory.Make(Content);

                //will call the commandManager to add a new object to the level (ie. our model)
                CommandManager commandManager = CommandManager.getInstance();
                CommandInterface command = new ChangeLevelCommand(this.myLevel, entity);
                commandManager.invokeCommand(command);
                //myLevel.addObject(entity);

                palette.Reset();
            }

            // Update the state of all buttons.
            foreach (var button in btns.Values)
            {
                button.Update(MouseState);
            }

            // This foreach loop will check if a button in the list of buttonlists
            // is clicked and if it is then we are going assign a reference to it via this.objBeingMoved
            // and when the next mouse click is registered put the object at the new coordinates.
            foreach (var myListofObjects in myLevel.objectList)
            {
                foreach (var myObject in myListofObjects)
                {

                    if (myObject.IsClicked())
                    {
                        //now were going to set the current clicked object on the leveleditor grid
                        //to have its property shouldIbeDrawn = false.
                        //myObject.shouldIbeDrawn = false;
                        //now make a temporary reference to this object so that once we register a
                        //new mouse click anywhere on the level editor grid we set the reference to
                        //have the new coordinates and put its shouldIBeDrawn property back to true;
                        this.objBeingMoved = myObject;
                    }
                }
            }

            //now we test if the mouse has been clickd and if it has move the current selected object to the coordinates clicked.
            //also only register one mouse click with the initial if statement
            this.mouseStateCurrent = MouseState;
            if (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Released)
            {
                Console.WriteLine("Ive been clicked");
                if (this.objBeingMoved != null)
                {
                    Console.WriteLine("Object is not null, starting moving it.");
                    //need to implement a check to see if the spot we are clicking in intersects within the
                    //rectangle of the grid.

                    //set new position of the objectbeingMoved to wherever the mouse was just clicked.
                    int newXcoord = MouseState.X - (this.objBeingMoved.rectangle.Width / 2);
                    int newYcoord = MouseState.Y - (this.objBeingMoved.rectangle.Height / 2);
                    //set the new width and height of the objectBeingMoved
                    int newWidth = this.objBeingMoved.rectangle.Width;
                    int newHeight = this.objBeingMoved.rectangle.Height;

                    //create a new rectangle based on the above coordinates and width,height.
                    Rectangle newObjectBeingMovedPosition = new Rectangle(newXcoord, newYcoord, newWidth, newHeight);

                    //Test if the rectangle is contained in the gridRect
                    //if it is set it to the new position else dont allow it to be drawn, notify the user somehow that they need to
                    //click inside the grid.
                    if(this.gridRect.Contains(newObjectBeingMovedPosition)){

                        Console.WriteLine("Good: New position was inside the grid");

                        //TODO: now we need to check if the object we are about to re-draw to a new position
                        //overlaps with any of the current objects.

                            //if there is only one object in the entire list then we can assume we are comparing
                            //the object being moved to itself. so we can just ignore intersection checking and
                            //set the new position of the object.
                            if (myLevel.objectList.Count == 1 && this.myLevel.objectList[0].Count == 1)
                            {
                                Console.WriteLine("Good: Only one object in the list.");

                                this.objBeingMoved.rectangle = newObjectBeingMovedPosition;

                                //Now set it so that the object being moved property of shouldIBeDrawn is set back to true
                                //So this will now redraw the object at the new position.
                                this.objBeingMoved.shouldIbeDrawn = true;

                                //now remove the reference so we no long change the actual object in the list.
                                this.objBeingMoved = null;
                                Console.WriteLine("Object now has new coordinates, set it to null so we no longer move it.");

                            }
                            else
                            {
                                Console.WriteLine("Good: Multile objects in the list.");

                                //bool to keep track if there was an intersect
                                bool isThereAnIntersect = false;
                                foreach (List<TargetTapping.Back_end.Object> myListofObjects in myLevel.objectList)
                                {
                                    //check if the object being moved doesnt intersect with any other objects
                                    foreach (TargetTapping.Back_end.Object myObject in myListofObjects)
                                    {
                                        //if were comparing the object being redrawn to its self in the list just ignore it
                                        //and skip this iteration of the loop.
                                        if(this.objBeingMoved.Equals(myObject)){
                                            Console.WriteLine("It's equal to itself, skipping this iteration.");
                                            continue;
                                        }
                                        //check a intersect with a specific object
                                        if (newObjectBeingMovedPosition.Intersects(myObject.rectangle))
                                        {
                                            Console.WriteLine("collided with another");
                                            isThereAnIntersect = true;
                                        }

                                    }
                                }

                                //now see if there was an intersect tell the user to pick a new spot else just draw it to
                                //the new location.
                                if (isThereAnIntersect)
                                {
                                    Console.WriteLine("Bad: there was an intersect with another object in the list, pick a new spot");
                                }
                                else
                                {
                                    Console.WriteLine("Good: multiple objects in list but no intersects.");

                                    this.objBeingMoved.rectangle = newObjectBeingMovedPosition;

                                    //Now set it so that the object being moved property of shouldIBeDrawn is set back to true
                                    //So this will now redraw the object at the new position.
                                    this.objBeingMoved.shouldIbeDrawn = true;

                                    //now remove the reference so we no long change the actual object in the list.
                                    this.objBeingMoved = null;
                                    Console.WriteLine("Object now has new coordinates, set it to null so we no longer move it.");

                                }

                            }

                    }
                    else{

                        Console.WriteLine("Bad: New position was outside the grid");

                    }

                 }
            }
            mouseStatePrevious = mouseStateCurrent;

            //update the mousestate of each object (ie. test if its been clicked)
            foreach (var myListofObjects in myLevel.objectList)
            {
                foreach (var myObject in myListofObjects)
                {
                   myObject.Update(MouseState);
                }
            }

            base.Update(gameTime);
        }