/// <summary> /// Dit regelt wat er gebeurd zodra op de MenuItem word geklikt. /// </summary> /// <param name="main"><see cref="Main">Main</see> instance</param> public virtual void OnClick(Main main) { // Er zijn genoeg zaadjes dus de plant kan worden geplant. if (main.StoreManager.GetSeedInventoryAmount(plant) > 0) { main.StoreManager.SetSeedInventoryAmount(plant, main.StoreManager.GetSeedInventoryAmount(plant) - 1); dirt.Plant = PlantFactory.GetPlant(plant); dirt.GrowTime = PlantFactory.GetPlant(plant).GrowTime; } else // Er zijn niet genoeg zaadjes dus moet er een alert komen. { main.ShowAlert(Constants.DangerColor, Strings.ErrorNotEnoughSeeds, Strings.ErrorNotEnoughSeedsBody.Replace("%%PLANT", plant.ToString())); } }
/// <summary> /// Teken alle visuele objecten. /// </summary> /// <param name="spriteBatch">SpriteBatch instance van MonoGame</param> /// <seealso cref="SpriteBatch"/> public void Draw(SpriteBatch spriteBatch) { if (!IsActive) { return; } int menuWidth = graphicsDevice.Viewport.Width - 100; int menuHeight = graphicsDevice.Viewport.Height - 100; spriteBatch.Draw(dummyTexture, new Rectangle(50, 50, graphicsDevice.Viewport.Width - 100, graphicsDevice.Viewport.Height - 100), Color.White); // Een lijn om verschillende producten te onderscheiden. for (int i = 1; i < 4; i++) { spriteBatch.Draw(dummyTexture, new Rectangle(50 + (int)menuWidth / 4 * i, 50, 1, menuHeight), Color.LightGray); } // // for (int i = 1; i < 3; i++) // { // spriteBatch.Draw(dummyTexture, // new Rectangle(50, 50 + (int) menuHeight / 3 * i, menuWidth, 1), Color.LightGray); // } int index = 0; int maxIndex = PlantFactory.Plants.Count; int cellWidth = menuWidth / 4; int cellHeigth = menuHeight / 3; // Ga over alle planten. for (int row = 0; row < 3; row++) { for (int column = 0; column < 4; column++) { String text = ""; // Laat zien hoeveel geld de gebruiker heeft. if (row == 0 && column == 0) { text = "Geld: $" + Money; spriteBatch.DrawString(titleFont, text, new Vector2(50 + (int)cellWidth / 2 - (int)(titleFont.MeasureString(text).X / 2), 50 + (int)cellHeigth / 2 - (int)(titleFont.MeasureString(text).Y / 2)), Color.Black); } // Sla de eerste een laatste hokje over op de eerste rij. if (row == 0 && (column < 1 || column > 2)) { continue; } // Schrijf over welke plant het gaat. text = PlantFactory.GetPlant(PlantFactory.Plants[index]).Name; spriteBatch.DrawString(spriteFont, text, new Vector2(50 + (int)cellWidth / 2 - (int)(spriteFont.MeasureString(text).X / 2) + cellWidth * column, 50 + 10 + cellHeigth * row), Color.Black); // Hoeveel zaadjes heeft de gebruiker over deze plant. text = "Zaadjes: " + GetSeedInventoryAmount(PlantFactory.Plants[index]); spriteBatch.DrawString(spriteFont, text, new Vector2(50 + (int)cellWidth / 2 - (int)(spriteFont.MeasureString(text).X / 2) + cellWidth * column, 50 + 30 + cellHeigth * row), Color.Black); // Hoeveel vruchten heeft de gebruiker over deze plant. text = "Vruchten: " + GetInventoryAmount(PlantFactory.Plants[index]); spriteBatch.DrawString(spriteFont, text, new Vector2(50 + (int)cellWidth / 2 - (int)(spriteFont.MeasureString(text).X / 2) + cellWidth * column, 50 + 50 + cellHeigth * row), Color.Black); // Laat een plaatje zien van de plant. spriteBatch.Draw(PlantFactory.GetPlant(PlantFactory.Plants[index]).Texture, new Rectangle(50 + (int)cellWidth / 2 - 25 + cellWidth * column, 80 + 50 + (int)cellHeigth * row, 50, 50), Color.White); // Teken een koop knop. text = "Kopen $" + PlantFactory.GetCostPrice(PlantFactory.Plants[index]); spriteBatch.Draw(dummyTexture, new Rectangle(50 + 5 + cellWidth * column, 50 + (int)cellHeigth - 30 + cellHeigth * row, (int)cellWidth / 2 - 18, (int)(spriteFont.MeasureString(text).Y) + 4), Color.LightBlue); spriteBatch.DrawString(spriteFont, text, new Vector2(50 + 10 + cellWidth * column, 50 + (int)cellHeigth - 28 + cellHeigth * row), Color.Black); // Teken een verkoop knop. text = "Verkopen $" + PlantFactory.GetSellPrice(PlantFactory.Plants[index]); spriteBatch.Draw(dummyTexture, new Rectangle(45 + (int)cellWidth / 2 + cellWidth * column, 50 + (int)cellHeigth - 30 + cellHeigth * row, (int)cellWidth / 2 + 3, (int)(spriteFont.MeasureString(text).Y) + 4), Color.LightBlue); spriteBatch.DrawString(spriteFont, text, new Vector2(45 + (int)cellWidth / 2 + cellWidth * column, 50 + (int)cellHeigth - 28 + cellHeigth * row), Color.Black); // Ga naar he volgende product. index++; if (index >= maxIndex) { break; } } if (index >= maxIndex) { break; } } // Laat een kruisje rechts bovenin het scherm zien. spriteBatch.Draw(closeImage, new Rectangle(50 + graphicsDevice.Viewport.Width - 140, 50, 40, 40), Color.White); }