private ExpandableView CreateExpandable(RootMenuItem rootPage) { var secondStack = new StackLayout(); secondStack.BackgroundColor = rootPage.Background; foreach (var page in rootPage.PageList) { var menuItem = new MenuPageStack { GestureRecognizers = { pageClicked // this means that the pageClicked event will be invoked }, Children = { new Label { Text = page.Title, VerticalOptions = LayoutOptions.Center, FontSize = 20, Margin = Constants.MenuChild, } }, TargetType = page.TargetType }; secondStack.Children.Add(menuItem); } return(new ExpandableView { PrimaryView = new StackLayout { Orientation = StackOrientation.Horizontal, // More parameters probably need to go in here BackgroundColor = rootPage.Background, Children = { new Image { Source = rootPage.IconSource, VerticalOptions = LayoutOptions.Center, Margin = Constants.MenuRoot, HeightRequest = 40 }, new Label { Text = rootPage.Title, FontSize = 24, VerticalOptions = LayoutOptions.Center } } }, SecondaryViewTemplate = new DataTemplate(() => secondStack) }); }
public Menu(Game game) : base(game) { Console.WriteLine("Menu Constructor"); this.game = (Game1)game; this.cursorAnimation = new Texture2D[10]; //if (Game.Services.GetService(typeof(IMenuService)) != null) // Console.WriteLine("IMenuService already exist...BUG"); Game.Services.AddService(typeof(IMenuService), this); // this.gameLogic = new GameLogic(game); // this.gameLogic.running = true; // Game.Components.Add(this.gameLogic); // game.Services.AddService(typeof(GameLogic), this.gameLogic); this.font = game.Content.Load <SpriteFont>("SimpleFont"); //this.menuBackground = game.Content.Load<Texture2D>("bugamove"); this.menuListBackground = game.Content.Load <Texture2D>("rootmenu");//game.Content.Load<Texture2D>("background");// this.scoreBackground = game.Content.Load <Texture2D>("scorelistbg"); this.root = new RootMenuItem(this.game.graphics.PreferredBackBufferHeight, this.game.graphics.PreferredBackBufferWidth, null); VerticalListMenuContainer list = new VerticalListMenuContainer("rootmenu", this.menuListBackground, this.font, Color.White, Color.Yellow); VerticalListMenuContainer sublist = new VerticalListMenuContainer("Info", this.menuListBackground, this.font, Color.White, Color.Yellow); ScoreBoard board = new ScoreBoard(this, this.scoreBackground, this.font, Color.White, Color.Yellow); sublist.addChildComponent(board); sublist.addChildComponent((new MenuEntryChoice("Credits", null, this.font, Color.White, Color.Yellow))); this.root.addChildComponent(list); MenuEntryChoice quickPlay = new MenuEntryChoice("New Game", null, this.font, Color.White, Color.Yellow); quickPlay.actionPerformed += this.StartLevel; this.root.getChild(0).addChildComponent(quickPlay); MenuEntryChoice loadGame = new MenuEntryChoice("Load Game", null, this.font, Color.White, Color.Yellow); loadGame.actionPerformed += this.LoadGame; list.addChildComponent(loadGame); MenuEntryChoice exitGame = new MenuEntryChoice("Exit Game", null, this.font, Color.White, Color.Yellow); exitGame.actionPerformed += this.ExitGame; this.root.getChild(0).addChildComponent(exitGame); this.root.getChild(0).addChildComponent(sublist); this.soundManager = new MenuSoundManager(game); Game.Components.Add(this.soundManager); Game.Services.AddService(typeof(MenuSoundManager), this.soundManager); }
// I will assume that there aren't enough items to necessitate a scrollview public MasterPage() { InitializeComponent(); // First setup the background color of the view BackgroundColor = Constants.BackgroundColor; // Second compile the list of pages FinancialItems = new List <PageType>(); TimeItems = new List <PageType>(); FinancialItems.Add(new PageType("Master", typeof(MoneyPage))); // will need to create pages other than just money pages in the future FinancialItems.Add(new PageType("Reoccuring Scheduler", typeof(ReoccurringScheduler))); TimeItems.Add(new PageType("Master", typeof(TimePage))); // Timepage is broken right now but that is ok // Third define the Root items RootFinancial = new RootMenuItem("Financial", "MoneyIcon.png", Constants.MoneyColor, FinancialItems); RootTime = new RootMenuItem("Time", "TimeIcon.png", Constants.TimeColor, TimeItems); // Fourth, generate the tapped events // first define the clicked event for each of the secondstack children pageClicked = new TapGestureRecognizer(); pageClicked.Tapped += (s, e) => { MenuPageStack MenuItem = (MenuPageStack)s; MessagingCenter.Send(this, "NewDetail", MenuItem.TargetType); // Now collapse the expanding views if (MoneyExpand.Status == ExpandStatus.Expanded) { MoneyExpand.IsExpanded = false; } if (TimeExpand.Status == ExpandStatus.Expanded) { TimeExpand.IsExpanded = false; } }; // Fifth add the expandable views to the stack layout MoneyExpand = CreateExpandable(RootFinancial); TimeExpand = CreateExpandable(RootTime); MiddleStack.Children.Add(MoneyExpand); MiddleStack.Children.Add(TimeExpand); }