/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); Texture2D texture = new Texture2D(GraphicsDevice, 1, 1); texture.SetData(new[] { Color.Gray }); startScreen = new StartScreen(this, spriteBatch, Content.Load<SpriteFont>("fonts/menufont"), texture); Components.Add(startScreen); startScreen.Hide(); mainScreen = new MainScreen(this, spriteBatch, Content.Load<SpriteFont>("fonts/myFont")); Components.Add(mainScreen); mainScreen.Hide(); loadScreen = new LoadScreen(this, spriteBatch, Content.Load<SpriteFont>("fonts/menufont")); Components.Add(loadScreen); loadScreen.Hide(); saveScreen = new SaveScreen(this, spriteBatch, Content.Load<SpriteFont>("fonts/myFont"), Content); Components.Add(saveScreen); saveScreen.Hide(); activeScreen = startScreen; activeScreen.Show(); // TODO: use this.Content to load your game content here }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); keyboardState = Keyboard.GetState(); mouseState = Mouse.GetState(); // TODO: Add your update logic here #region Screens if (activeScreen == startScreen) { if (checkKey(Keys.Enter) || checkLeftMouseKey()) { switch (startScreen.SelectedIndex) { case 0: //To let the last Screen shine through: activeScreen.Enabled = false; activeScreen.Hide(); activeScreen = mainScreen; activeScreen.Show(); break; case 1: this.Exit(); break; } } } if (activeScreen != mainScreen) ((UIComponent_Toolbar)mainScreen.UIComponent).ToolID = 0; if (activeScreen == mainScreen) { if (checkKey(Keys.Escape)) { activeScreen.Hide(); activeScreen = startScreen; activeScreen.Show(); } if (mainScreen.LoadMap || checkKey(Keys.L)) { activeScreen.DrawOnly(); activeScreen = loadScreen; activeScreen.Show(); } if (mainScreen.SaveMap || checkKey(Keys.S)) { activeScreen.DrawOnly(); activeScreen = saveScreen; activeScreen.Show(); } } if (activeScreen == loadScreen) { if (keyboardState.IsKeyDown(Keys.Escape) || loadScreen.CancelButton.IsPressed) { activeScreen.Hide(); activeScreen = mainScreen; activeScreen.Show(); } string sItem = loadScreen.UISelectBox.SelectedItem; if (sItem != null) { mainScreen.MapComponent.ToolValue = 0; mainScreen.MapComponent = loadScreen.Load(sItem); activeScreen.Hide(); activeScreen = mainScreen; activeScreen.Show(); } } if (activeScreen == saveScreen) { if (saveScreen.Save(mainScreen.MapComponent)) { activeScreen.Hide(); activeScreen = mainScreen; activeScreen.Show(); } if (keyboardState.IsKeyDown(Keys.Escape) || saveScreen.CancelButton.IsPressed) { activeScreen.Hide(); activeScreen = mainScreen; activeScreen.Show(); } } #endregion base.Update(gameTime); oldKeyboardState = keyboardState; oldMouseState = mouseState; }