Esempio n. 1
0
        public GameMenu(Game1 game) : base(game)
        {
            this.game = game;
            Console.WriteLine("GameMenu");
            this.cursorAnimation = new Texture2D[5];

            this.font = Game.Content.Load <SpriteFont>("SimpleFont");
            //  this.menuBackground = game.Content.Load<Texture2D>("fractal");
            this.menuListBackground = Game.Content.Load <Texture2D>("rootmenu");

            this.root = new RootMenuItem(this.game.graphics.PreferredBackBufferHeight, this.game.graphics.PreferredBackBufferWidth, null);
            VerticalListMenuContainer list = new VerticalListMenuContainer("Game Paused", this.menuListBackground, this.font, Color.White, Color.Yellow);

            this.root.addChildComponent(list);
            resume = new MenuEntryChoice("Resume", null, this.font, Color.White, Color.Yellow);
            exit   = new MenuEntryChoice("Back to Main Menu", null, this.font, Color.White, Color.Yellow);
            save   = new MenuEntryChoice("Save Game", null, this.font, Color.White, Color.Yellow);


            this.root.getChild(0).addChildComponent(resume);
            this.root.getChild(0).addChildComponent(exit);
            this.root.getChild(0).addChildComponent(save);


            this.traverser = new MenuTraverser(this.root);

            Game.Services.AddService(typeof(IGameMenuService), this);
        }
Esempio n. 2
0
        public MenuTraverser(RootMenuItem menu)
        {
            this.menu = menu;
            //    this.OnMenuActionCachedHandler = (action) => this.OnMenuAction(action);

            this.componentsTraversedIndexes = new Stack <int>();
            MenuComponentComposite firstChild = this.menu.getChild(0);


            if (firstChild != null)
            {
                firstChild.setExpanded(true);

                this.currentSelectedComponent = firstChild;
                this.currentComponentIndex    = 0;

                MenuComponentComposite c = firstChild.getChild(0);
                //first child of the first child of root is a container with at least one child. Start traversing from here
                if (c != null)
                {
                    this.componentsTraversedIndexes.Push(this.currentComponentIndex);
                    this.currentSelectedComponent = c;
                    this.currentSelectedComponent.setFocus(true);
                    this.currentComponentIndex = 0;
                    // this.currentSelectedComponent.setExpanded(true);
                }
                else
                {
                    firstChild.setFocus(true);
                }
            }
            else
            {
                //that's pretty strange. a root component should always have a child component
            }
        }