From c96f3ce55b7bcddbceff4dbe5df4a1c3c40fea83 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 17 Jun 2020 01:48:35 +0200 Subject: [PATCH] hide modifiers if you can't buy them --- TouchyTickets/ParkMap.cs | 4 ++++ TouchyTickets/TouchyTickets.csproj | 2 +- TouchyTickets/Ui.cs | 29 ++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/TouchyTickets/ParkMap.cs b/TouchyTickets/ParkMap.cs index 707b23d..196c398 100644 --- a/TouchyTickets/ParkMap.cs +++ b/TouchyTickets/ParkMap.cs @@ -208,6 +208,10 @@ namespace TouchyTickets { return this.attractions.Sum(a => a.Item2.GetModifierAmount(modifier)); } + public bool IsAnyAttractionAffected(AttractionModifier modifier) { + return this.attractions.Any(a => modifier.IsAffected(a.Item2)); + } + public ParkMap Copy(int? newWidth = null, int? newHeight = null) { var newMap = new ParkMap(newWidth ?? this.Width, newHeight ?? this.Height); foreach (var (pos, attraction) in this.attractions) diff --git a/TouchyTickets/TouchyTickets.csproj b/TouchyTickets/TouchyTickets.csproj index 403a6b2..a59d4da 100644 --- a/TouchyTickets/TouchyTickets.csproj +++ b/TouchyTickets/TouchyTickets.csproj @@ -6,7 +6,7 @@ - + all diff --git a/TouchyTickets/Ui.cs b/TouchyTickets/Ui.cs index 84e1deb..bff974d 100644 --- a/TouchyTickets/Ui.cs +++ b/TouchyTickets/Ui.cs @@ -260,16 +260,35 @@ namespace TouchyTickets { this.FadeUi(true); } }); - button.OnUpdated += (e, time) => button.IsDisabled = GameImpl.Instance.Tickets < modifier.InitialPrice; - button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), modifier.Texture) { + var image = button.AddChild(new Image(Anchor.CenterLeft, new Vector2(0.2F, 40), modifier.Texture) { Padding = new Vector2(4) }); var right = button.AddChild(new Group(Anchor.TopRight, new Vector2(0.8F, 1)) {CanBeMoused = false}); - right.AddChild(new Paragraph(Anchor.TopLeft, 1, Localization.Get(modifier.Name), true)); - right.AddChild(new Paragraph(Anchor.AutoLeft, 1, Localization.Get(modifier.Name + "Description"), true) {TextScale = 0.08F}); + var name = right.AddChild(new Paragraph(Anchor.TopLeft, 1, Localization.Get(modifier.Name), true)); + var hiddenName = right.AddChild(new Paragraph(Anchor.TopLeft, 1, "?????", true) {TextColor = Color.Gray}); + var desc = right.AddChild(new Paragraph(Anchor.AutoLeft, 1, Localization.Get(modifier.Name + "Description"), true) {TextScale = 0.08F}); right.AddChild(new Paragraph(Anchor.AutoRight, 1, p => PrettyPrintNumber(modifier.InitialPrice) + "", true)); - right.AddChild(new Paragraph(Anchor.BottomLeft, 1, $"x{modifier.Multiplier}", true) {TextScale = 0.08F}); + var genRate = right.AddChild(new Paragraph(Anchor.BottomLeft, 1, $"x{modifier.Multiplier}", true) {TextScale = 0.08F}); + + var shouldShow = false; + button.OnAreaUpdated += e => { + // this is a pretty expensive operation, so only do it when the area changes + shouldShow = GameImpl.Instance.Map.IsAnyAttractionAffected(modifier); + e.SetData("Show", shouldShow); + }; + button.OnUpdated += (e, time) => { + button.IsDisabled = !shouldShow || GameImpl.Instance.Tickets < modifier.InitialPrice; + image.Color = shouldShow ? Color.White : Color.Black; + name.IsHidden = !shouldShow; + hiddenName.IsHidden = shouldShow; + genRate.IsHidden = !shouldShow; + desc.IsHidden = !shouldShow; + }; } + modifierUi.OnAreaUpdated += e => { + // sort children by whether they should be shown or not + modifierUi.ReorderChildren((e1, e2) => Comparer.Default.Compare(e2.GetData("Show"), e1.GetData("Show"))); + }; this.uiSystem.Add("Modifiers", modifierUi); // upgrade ui