hide modifiers if you can't buy them

This commit is contained in:
Ellpeck 2020-06-17 01:48:35 +02:00
parent 7aa02bb8d1
commit c96f3ce55b
3 changed files with 29 additions and 6 deletions

View file

@ -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)

View file

@ -6,7 +6,7 @@
<ItemGroup>
<PackageReference Include="Coroutine" Version="2.0.0" />
<PackageReference Include="MLEM.Startup" Version="4.0.0-214" />
<PackageReference Include="MLEM.Startup" Version="4.0.0-216" />
<PackageReference Include="MonoGame.Framework.Portable" Version="3.7.1.189">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View file

@ -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) + "<i ticket>", true));
right.AddChild(new Paragraph(Anchor.BottomLeft, 1, $"x{modifier.Multiplier}<i ticket>", true) {TextScale = 0.08F});
var genRate = right.AddChild(new Paragraph(Anchor.BottomLeft, 1, $"x{modifier.Multiplier}<i ticket>", 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<bool>.Default.Compare(e2.GetData<bool>("Show"), e1.GetData<bool>("Show")));
};
this.uiSystem.Add("Modifiers", modifierUi);
// upgrade ui