TouchyTickets/TouchyTickets/Tutorial.cs
2020-06-08 22:55:33 +02:00

71 lines
No EOL
3 KiB
C#

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 = {
// introduction
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"),
// modifier tutorial
new Step(g => g.Map.GetAttractionAmount(null) >= 3, "Tutorial11"),
new Step(g => g.Map.PlacingModifier != null, "Tutorial12"),
new Step(g => g.Map.GetModifierAmount(null) > 0, "Tutorial13"),
// star tutorial
new Step(g => g.Tickets >= g.GetStarPrice(), "Tutorial7", "Tutorial8"),
new Step(g => g.Stars > 0, "Tutorial9", "Tutorial10")
};
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);
}
}
}