Allow null in mod list to generate a placeholder ModButton.

This commit is contained in:
Huo Yaoyuan 2017-03-07 19:52:51 +08:00
parent ffd79bee06
commit b19405c987
1 changed files with 13 additions and 5 deletions

View File

@ -54,7 +54,8 @@ private int selectedIndex
iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, EasingTypes.OutElastic);
foregroundIcon.Colour = Selected ? SelectedColour : ButtonColour;
displaySelectedMod();
if (mod != null)
displayMod(SelectedMod ?? Mods[0]);
}
}
@ -102,10 +103,18 @@ public Mod Mod
}
set
{
if (mod == value) return;
mod = value;
Mods = (mod as MultiMod)?.Mods ?? new[] { mod };
if (mod == null)
{
Mods = new Mod[0];
Alpha = 0;
}
else
{
Mods = (mod as MultiMod)?.Mods ?? new[] { mod };
Alpha = 1;
}
createIcons();
if (Mods.Length > 0)
@ -165,8 +174,6 @@ private void displayMod(Mod mod)
text.Text = mod.Name;
}
private void displaySelectedMod() => displayMod(SelectedMod ?? Mods[0]);
private void createIcons()
{
iconsContainer.Clear();
@ -216,6 +223,7 @@ public ModButton(Mod m)
Direction = FillDirection.Vertical;
Spacing = new Vector2(0f, -5f);
Size = new Vector2(100f);
AlwaysPresent = true;
Children = new Drawable[]
{