1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Merge pull request #18935 from peppy/ruleset-guard-icon-creation-failure

Guard against ruleset icon creation failures to avoid whole game death
This commit is contained in:
Dean Herbert 2022-06-29 20:57:58 +09:00 committed by GitHub
commit 6a16b84edb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 35 deletions

View File

@ -3,11 +3,11 @@
#nullable disable
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Development;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -28,32 +28,17 @@ namespace osu.Game.Overlays.Settings
Direction = FillDirection.Vertical;
Padding = new MarginPadding { Top = 20, Bottom = 30, Horizontal = SettingsPanel.CONTENT_MARGINS };
var modes = new List<Drawable>();
foreach (var ruleset in rulesets.AvailableRulesets)
{
var icon = new ConstrainedIconContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Icon = ruleset.CreateInstance().CreateIcon(),
Colour = Color4.Gray,
Size = new Vector2(20),
};
modes.Add(icon);
}
FillFlowContainer modes;
Children = new Drawable[]
{
new FillFlowContainer
modes = new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Direction = FillDirection.Full,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = modes,
Spacing = new Vector2(5),
Padding = new MarginPadding { Bottom = 10 },
},
@ -70,6 +55,27 @@ namespace osu.Game.Overlays.Settings
Origin = Anchor.TopCentre,
}
};
foreach (var ruleset in rulesets.AvailableRulesets)
{
try
{
var icon = new ConstrainedIconContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Icon = ruleset.CreateInstance().CreateIcon(),
Colour = Color4.Gray,
Size = new Vector2(20),
};
modes.Add(icon);
}
catch
{
Logger.Log($"Could not create ruleset icon for {ruleset.Name}. Please check for an update from the developer.", level: LogLevel.Error);
}
}
}
private class BuildDisplay : OsuAnimatedButton

View File

@ -5,6 +5,7 @@
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Allocation;
using osu.Framework.Logging;
namespace osu.Game.Rulesets
{
@ -18,8 +19,17 @@ namespace osu.Game.Rulesets
[BackgroundDependencyLoader]
private void load()
{
foreach (var r in Rulesets.AvailableRulesets)
AddItem(r);
foreach (var ruleset in Rulesets.AvailableRulesets)
{
try
{
AddItem(ruleset);
}
catch
{
Logger.Log($"Could not create ruleset icon for {ruleset.Name}. Please check for an update from the developer.", level: LogLevel.Error);
}
}
}
}
}

View File

@ -4,7 +4,6 @@
#nullable disable
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -14,6 +13,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Textures;
using osu.Framework.Logging;
using osu.Framework.Utils;
using osu.Framework.Timing;
using osu.Game.Graphics;
@ -340,24 +340,28 @@ namespace osu.Game.Screens.Menu
[BackgroundDependencyLoader]
private void load(RulesetStore rulesets)
{
var modes = new List<Drawable>();
foreach (var ruleset in rulesets.AvailableRulesets)
{
var icon = new ConstrainedIconContainer
{
Icon = ruleset.CreateInstance().CreateIcon(),
Size = new Vector2(30),
};
modes.Add(icon);
}
AutoSizeAxes = Axes.Both;
Children = modes;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
foreach (var ruleset in rulesets.AvailableRulesets)
{
try
{
var icon = new ConstrainedIconContainer
{
Icon = ruleset.CreateInstance().CreateIcon(),
Size = new Vector2(30),
};
Add(icon);
}
catch
{
Logger.Log($"Could not create ruleset icon for {ruleset.Name}. Please check for an update from the developer.", level: LogLevel.Error);
}
}
}
}