only show attractions if they're "unlocked"

This commit is contained in:
Ellpeck 2020-06-05 17:16:48 +02:00
parent 64cd304878
commit 38f8537408

View file

@ -130,6 +130,7 @@ namespace TouchyTickets {
}; };
foreach (var attraction in AttractionType.Attractions) { foreach (var attraction in AttractionType.Attractions) {
BigInteger price = 0; BigInteger price = 0;
var attractionAmount = 0;
var button = buyUi.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 40)) { var button = buyUi.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 40)) {
ChildPadding = new Vector2(4), ChildPadding = new Vector2(4),
PositionOffset = new Vector2(0, 1), PositionOffset = new Vector2(0, 1),
@ -161,19 +162,28 @@ namespace TouchyTickets {
}, },
OnAreaUpdated = e => { OnAreaUpdated = e => {
// only update the price when the area updates, since it won't change while we're in the buy ui // only update the price when the area updates, since it won't change while we're in the buy ui
var amount = GameImpl.Instance.Map.GetAttractionAmount(attraction.Value); attractionAmount = GameImpl.Instance.Map.GetAttractionAmount(attraction.Value);
// yay compound interest // yay compound interest
price = (attraction.Value.InitialPrice * (float) Math.Pow(1 + 0.1F, amount)).Ceil(); price = (attraction.Value.InitialPrice * (float) Math.Pow(1 + 0.1F, attractionAmount)).Ceil();
} }
}); });
button.OnUpdated += (e, time) => button.IsDisabled = GameImpl.Instance.Tickets < price; var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), attraction.Value.TextureRegion) {
button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), attraction.Value.TextureRegion) {
Padding = new Vector2(4) Padding = new Vector2(4)
}); });
var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1), false) {CanBeMoused = false}); var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1), false) {CanBeMoused = false});
right.AddChild(new Paragraph(Anchor.TopLeft, 1, Localization.Get(attraction.Key), true)); var name = right.AddChild(new Paragraph(Anchor.TopLeft, 1, Localization.Get(attraction.Key), true));
right.AddChild(new Paragraph(Anchor.BottomLeft, 1, p => attraction.Value.GetGenerationRate() + "<i ticket>/s", true) {TextScale = 0.08F}); var hiddenName = right.AddChild(new Paragraph(Anchor.TopLeft, 1, "?????", true) {TextColor = Color.Gray});
var genRate = right.AddChild(new Paragraph(Anchor.BottomLeft, 1, p => attraction.Value.GetGenerationRate() + "<i ticket>/s", true) {TextScale = 0.08F});
right.AddChild(new Paragraph(Anchor.BottomRight, 1, p => PrettyPrintNumber(price) + "<i ticket>", true)); right.AddChild(new Paragraph(Anchor.BottomRight, 1, p => PrettyPrintNumber(price) + "<i ticket>", true));
button.OnUpdated += (e, time) => {
button.IsDisabled = GameImpl.Instance.Tickets < price;
// we only want to show the info if we have enough tickets or we've placed the thing before
var shouldShow = !button.IsDisabled || attractionAmount > 0;
image.Color = shouldShow ? Color.White : Color.Black;
name.IsHidden = !shouldShow;
genRate.IsHidden = !shouldShow;
hiddenName.IsHidden = shouldShow;
};
} }
this.uiSystem.Add("Buy", buyUi); this.uiSystem.Add("Buy", buyUi);