protected override void Init() { font = Content.Load <SpriteFont>("fonts/menu_font"); blank = Content.Load <Texture2D>("textures/blank"); background = new ImageItem(blank); background.HGrow = background.VGrow = 1; background.Color = Color.Black; background.Alpha = 0.3f; TextItem msg = new TextItem(font, message); msg.HAlign = HAlignment.Center; ListMenu menu = new ListMenu(); menu.VAlign = VAlignment.Center; VPane vPane = new VPane(msg, menu); vPane.HAlign = HAlignment.Center; vPane.VGrow = 1; ImageItem vpBack = new ImageItem(blank); vpBack.HGrow = vpBack.VGrow = 1; vpBack.Color = Color.Black; vpBack.Alpha = 0.3f; StackPane sPane = new StackPane(vpBack, vPane); sPane.VAlign = VAlignment.Center; sPane.VGrow = 0.2f; sPane.HGrow = 1; responds.ForEach(respond => { if (respond != responds[0]) { MenuItem gap = new MenuItem(" ", font); gap.IsDisabled = true; menu.AddItem(gap); } MenuItem item = new MenuItem(respond.Text, font); menu.AddItem(item); item.FocusGain += (s, a) => item.TextItem.Color = Color.Yellow; item.FocusLoss += (s, a) => item.TextItem.Color = Color.White; item.Action += (s, a) => { action = respond.Action; Close(); }; }); ViewPane.Clear(); RootPane = new StackPane(background, sPane); RootPane.HGrow = RootPane.VGrow = 1; ViewPane.Add(RootPane); }
private void InitMapPane(HPane mapPane) { int w = Width / Map.Tiles.Length; int h = Height / Map.Tiles[0].Length; for (int x = 0; x < Map.Tiles.Length; ++x) { ListMenu vList = new ListMenu(); vList.ItemsOrientation = Orientation.Vertical; // vList.KeyBoardEnabled = false; mapPane.Add(vList); for (int y = 0; y < Map.Tiles[0].Length; ++y) { MenuItem item = new MenuItem(hiddenTexture, w, h); itemMap.Add(item, new Point(x, y)); vList.AddItem(item); item.FocusGain += (s, a) => item.ImageItem.Color = Color.Silver; item.FocusLoss += (s, a) => item.ImageItem.Color = Color.White; item.Action += (s, a) => { Point p = itemMap[item]; while (Map.RevealedTiles == 0 && Map.Tiles[p.X][p.Y].HasMine) { Map.ShuffleMines(); } if (Map.RevealTile(p.X, p.Y)) { Media.PlaySound(1); } else { Media.PlaySound(0); } if (IsGameOver()) { Manager.Add(CreateGameOverView()); State = ViewState.Suspended; } }; Map.Tiles[x][y].Revealed += (s, a) => { MapTile tile = (MapTile)s; item.IsDisabled = !tile.IsHidden; item.ImageItem.Image = tile.IsHidden ? hiddenTexture : tile.HasMine ? revealedTextures[9] : revealedTextures[tile.GetMineCount()]; // TODO test tile.GetNeighbours().ToList().ForEach(n => CutOutMine(n)); }; } } }
protected override void Init() { Background = Content.Load <Texture2D>("textures/home_back"); banner = Content.Load <Texture2D>("textures/banner"); font = Content.Load <SpriteFont>("fonts/menu_font"); backItem = new ImageItem(Background); backItem.HGrow = backItem.VGrow = 1; MenuItem start = new MenuItem("Start Game", font); MenuItem highscore = new MenuItem("Highscores", font); MenuItem settings = new MenuItem("Settings", font); MenuItem quit = new MenuItem("Quit", font); start.FocusGain += (s, a) => start.TextItem.Color = Color.Yellow; settings.FocusGain += (s, a) => settings.TextItem.Color = Color.Yellow; highscore.FocusGain += (s, a) => highscore.TextItem.Color = Color.Yellow; quit.FocusGain += (s, a) => quit.TextItem.Color = Color.Yellow; start.FocusLoss += (s, a) => start.TextItem.Color = Color.White; settings.FocusLoss += (s, a) => settings.TextItem.Color = Color.White; highscore.FocusLoss += (s, a) => highscore.TextItem.Color = Color.White; quit.FocusLoss += (s, a) => quit.TextItem.Color = Color.White; // ListMenu menu = new ListMenu(start, settings, highscore, quit); // TODO fix ctor ListMenu menu = new ListMenu(); menu.ItemsOrientation = Orientation.Vertical; menu.VAlign = VAlignment.Top; menu.AddItem(start); menu.AddItem(highscore); menu.AddItem(settings); menu.AddItem(quit); HPane menuPane = new HPane(menu); menuPane.HAlign = HAlignment.Center; menuPane.VGrow = 1; ImageItem bannerItem = new ImageItem(banner, 400, 200); bannerItem.VAlign = VAlignment.Center; bannerItem.HGrow = 1; HPane bannerPane = new HPane(bannerItem); bannerPane.HGrow = bannerPane.VGrow = 1; VPane vPane = new VPane(bannerPane, menuPane); vPane.HAlign = HAlignment.Center; vPane.HGrow = 0.8f; vPane.VGrow = 1; ViewPane.Clear(); RootPane = new StackPane(backItem, vPane); RootPane.HGrow = RootPane.VGrow = 1; ViewPane.Add(RootPane); start.Action += (s, a) => { Manager.Add(Game.CreateMapView(this)); Hide(); }; settings.Action += (s, a) => { Manager.Add(new SettingsView(this, Game)); Hide(); }; highscore.Action += (s, a) => { Manager.Add(new HighscoreView(this, Game)); Hide(); }; quit.Action += (s, a) => Close(); }