using Microsoft.Xna.Framework; using MLEM.Extensions; using MLEM.Ui; using MLEM.Ui.Elements; using TouchyTickets.Attractions; namespace TouchyTickets { public class Tutorial { private static readonly Step[] Steps = { new Step(g => true, "Tutorial1"), new Step(g => g.Tickets >= AttractionType.Carousel.InitialPrice, "Tutorial2"), new Step(g => g.DrawMap && g.Map.PlacingAttraction?.Type == AttractionType.Carousel, "Tutorial3"), new Step(g => g.Map.GetAttractionAmount(AttractionType.Carousel) > 0, "Tutorial4", "Tutorial5", "Tutorial6"), new Step(g => g.Tickets >= g.GetStarPrice(), "Tutorial7"), new Step(g => g.Stars > 0, "Tutorial8", "Tutorial9") }; public int CurrentStep; private int currentStepMessage; public void Update(GameImpl game) { // stop if the tutorial is finished if (this.CurrentStep >= Steps.Length) return; // don't do anything while a tutorial box is already displaying if (game.UiSystem.Get("TutorialBox") != null) return; var step = Steps[this.CurrentStep]; if (step.ShouldContinue(game)) { var infoBox = new Group(Anchor.TopLeft, Vector2.One, false) { OnDrawn = (e2, time, batch, alpha) => batch.Draw(batch.GetBlankTexture(), e2.DisplayArea, Color.Black * 0.35F) }; var panel = infoBox.AddChild(new Panel(Anchor.Center, new Vector2(0.8F), Vector2.Zero, true)); panel.AddChild(new Paragraph(Anchor.AutoLeft, 1, Localization.Get(step.Content[this.currentStepMessage]))); panel.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 30), Localization.Get("Okay")) { OnPressed = e2 => { game.UiSystem.Remove(e2.Root.Name); this.currentStepMessage++; if (this.currentStepMessage >= step.Content.Length) { this.currentStepMessage = 0; this.CurrentStep++; } } }); game.UiSystem.Add("TutorialBox", infoBox); } } private class Step { public readonly ContinueDelegate ShouldContinue; public readonly string[] Content; public Step(ContinueDelegate shouldContinue, params string[] content) { this.ShouldContinue = shouldContinue; this.Content = content; } public delegate bool ContinueDelegate(GameImpl game); } } }