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