Example #1
0
        public static void CreateMenu(Rectangle rect, List<string> msgList, CommandHandler command, Menu parent, Color? colorBG)
        {
            if (rect == null)
            {

                 rect = new Rectangle(100, 100, 275, 50);
            }
                   //new List<string>(new string[] { "Menu 1" })
            Menu menu= new Menu(Orchid.game, Orchid.graphicsDevice, spriteBatch, rect, Color.GreenYellow,
                msgList, parent: parent, subMenus: null, command: command, textColor:Color.Green);

            //return menu;
        }
Example #2
0
        //bool guiFound = false;
        public InputHandler(Game1 game)
        {
            //save a refernce to the main game, to easily access its attributes
            this.theGame = game;

            //create empty element
            emptyElement = new GuiElement(this.theGame, this.theGame.spriteBatch);
            hoveredElement = new GuiElement(this.theGame, this.theGame.spriteBatch);
            activeElement = new GuiElement(this.theGame, this.theGame.spriteBatch);

            emptyMenu = new Menu(this.theGame, this.theGame.GraphicsDevice,
                    this.theGame.spriteBatch, new Rectangle(10,10,10,10),
                    Color.Black, Orchid.CreateMsgList("empty menu"), null, null,
                    null, Color.White);
            //so the emptyMenu is never seen
            emptyMenu.IsHidden = true;
            //so the other menus know that it's not normal
            emptyMenu.name = "empty menu not a real one";
        }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="textColor">If left empty, it'll be black</param>
        public Menu(Game1 game,
                    GraphicsDevice graphicsDevice,
                    SpriteBatch spriteBatch,
                    Rectangle rect,
                    Color colorBG,
                    List<string> msgList,
                    Menu parent,
                    List<Menu> subMenus,
                    CommandHandler command,
                    Color textColor)
            : base(game, graphicsDevice, spriteBatch, rect, colorBG, msgList,
                textColor: textColor, moveLocked: false)
        {
            this.parent = parent;
            //for now this just adds itself to its parent,if applicable
            this.NotifyParent();

            if (subMenus == null)
            {
                this.subMenus = new List<Menu>();
            }
            else if (subMenus != null)
            {
                this.subMenus = subMenus;
            }

            if (command != null)
            {
                this.command += command;
            }
            else
            {
                this.command +=
                    () =>
                    this.CreateSubMenu(null,
                                new List<string>(new string[]
                                {"test default"}));
            }
        }
Example #4
0
 private void CreateTopMenu()
 {
     //Creates a menu that will be drawn before it ever gets clicked on.
     this.TopMenu = new Menu(game, this.graphicsDevice, spriteBatch,
             rect, colorBG, Orchid.CreateMsgList(this.TopMenuName),
             //colorBG is given to the MenuContainer constructor
             null, null, null, textColor: Color.Black);
 }
Example #5
0
        public void CreateVisibleMenu()
        {
            //loop over all the menu items and create a surface to draw to
            //screen
            for (int i = 0; i < MenuItems.Count; i++)
            {
                //rect to change size for more than one menu shows, instead of
                //being on top of each other
                Rectangle size  = this.rect;
                size.Offset(size.Height * i, 0);
                Menu new_menu = new Menu(game, this.GraphicsDevice,
                                         spriteBatch, rect, colorBG,
                                         new List<string>(new string[] {"TEST!"}),
                                         null, null, null,
                                         Color.Black);

            }
        }
Example #6
0
        //object to build all the menu items once the MenuContainer is told
        //to begin building
        public MenuContainer(Menu parent,
                             Game1 game,
                             GraphicsDevice
                                 graphicsDevice,
                             SpriteBatch spriteBatch,
                             Rectangle rect,
                             Color colorBG,
                             string name = "Default MenuContainer")
            : base(game, spriteBatch)
        {
            this.TopMenuName = name;
            this.graphicsDevice = graphicsDevice;
            this.rect = rect;

            this.colorBG = colorBG;

            this.CreateTopMenu();
            this.parent = parent;
        }
Example #7
0
        public void CheckMouseAgainstElements(List<GuiElement> guiElementList)
        {
            currentMouseState = Mouse.GetState();
            Point mousePos = new Point(currentMouseState.X, currentMouseState.Y);

            //this.theGame.testArea.Drag(currentMouseState, lastMouseState);

            //if mouse1 is pressed, but not dragging
            if (currentMouseState.LeftButton == ButtonState.Pressed &
                lastMouseState.LeftButton  != ButtonState.Pressed)
            {

                //for making sure an element is found
                bool elem_found = false;

                //loop over the elements in the gui list
                foreach (GuiElement elem in guiElementList)
                {
                    //if it's a Button or a child
                    if (elem is Button)
                    {

                        Button castedElem = elem as Button;
                        //elem = elem as Button;
                        if (castedElem.rect.Contains(mousePos))
                        {
                            activeElement = elem;
                            castedElem.OnMouseDown();

                            elem_found = true;
                        }
                    }

                    //if it's a child of Surface
                    else if (elem is Surface)
                    {
                        //if it's gotten clicked
                        if (elem.rect.Contains(mousePos))
                        {
                            Surface castedElem = elem as Surface;
                            string text = String.Format("{0}, the Surface, has mouse down", castedElem);
                            theGame.msgList.Add(text);

                            //activate the pressed element
                            activeElement = castedElem;

                            //set active menu if you've clicked a menu otherwise
                            //reset it
                            if (elem is Menu)
                            {
                                activeMenu = (Menu)elem;
                            }
                            else { activeMenu = emptyMenu;}

                            elem_found = true;
                        }
                    }

                }

            //if no element was found to be clicked on reset em all to default
            //empty
            if (! elem_found)
            {
                activeElement = emptyElement;

                activeMenu = emptyMenu;

            }
            }

            //if the mouse1 button is being dragged
            if (currentMouseState.LeftButton == ButtonState.Pressed &
                lastMouseState.LeftButton == ButtonState.Pressed)
            {                             //if mousepos is along the left side of the box
                // make sure it's not too high

                if (activeElement is Surface)
                {
                    Surface castedElem = (Surface)activeElement;
                    if ((castedElem.rect.Top < mousePos.Y &
                        mousePos.Y < castedElem.rect.Bottom) )
                        //&
                        //// make sure its not too far the the left or right.
                        //(castedElem.rect.Left - (castedElem.rect.Width * .1) < mousePos.X) &
                        //(castedElem.rect.Left + (castedElem.rect.Width * .1) > mousePos.X))
                    {
                        string text2 = String.Format("{0}, the Surface, has mouse in", castedElem);
                        theGame.msgList.Add(text2);
                        //Console.WriteLine("RESIZING");
                        castedElem.Resize(currentMouseState, lastMouseState);

                    }
                }
            }

            //if mouse1 is clicked
            if (currentMouseState.LeftButton == ButtonState.Released &&
                   lastMouseState.LeftButton == ButtonState.Pressed)
            {
                //Console.WriteLine("trying for a mouse up");
                activeElement.OnMouseUp();
                activeElement = emptyElement;

                foreach (GuiElement elem in guiElementList)
                {
                    if (elem is TextEntry)
                    {
                        if (elem.rect.Contains(mousePos))
                        {
                            TextEntry castedElem = (TextEntry)elem;
                            castedElem.OnMouseDown();

                            activeElement = elem;

                            theGame.currentGameState = theGame.typingGameState;

                        }
                    }
                }

            }

            //if mouse2 is pressed
            if  (lastMouseState.RightButton == ButtonState.Pressed)
            {
                //Console.WriteLine("trying for a mouse up");
                //activeElement.OnMouseUp();
                //activeElement = emptyElement;

                bool guiFound = false;
                foreach (GuiElement elem in Orchid.masterGuiElementList)
                {
                    if (elem.rect.Contains(mousePos) && !guiFound)
                    {
                        if (elem is MessageBox)
                        {
                            MessageBox msgbox = (MessageBox)elem;
                            msgbox.Drag(currentMouseState, lastMouseState);
                            Console.WriteLine("dragging something");
                            guiFound = true;
                        }

                        else { Console.WriteLine("is not message box"); }
                    }
                }

            }

            //if the mouse is just chilling, hovering
            if (currentMouseState.LeftButton == ButtonState.Released &&
                currentMouseState.RightButton == ButtonState.Released)
            {

                //TODO: will need to make sure that hoveredElement becomes null or default
                // because it just keeps on calling OffMouseHover until a new element comes along
                if (!hoveredElement.rect.Contains(mousePos))
                {
                    hoveredElement.OffMouseHover();

                    //reset hoveredElement
                    hoveredElement = emptyElement;
                }

                List<GuiElement> orig_elemlist = new List<GuiElement>(guiElementList);
                foreach (GuiElement elem in orig_elemlist)
                {
                    if (elem.rect.Contains(mousePos))
                    {
                        //called hover method and set a element that is hovered over
                        elem.OnMouseHover();
                        hoveredElement = elem;
                    }

                }
            }

            //cache the mouse state so you have something to compare it against next frame.
            lastMouseState = currentMouseState;
        }