Skip to content

Commit

Permalink
enhance: 单独创建一个SettingsSubPanel展示Hikariii插件设置
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 25, 2024
1 parent 8369b02 commit a2c2327
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.IGPlayer.Feature.Player.Interfaces.Plugins;
using osuTK;

namespace osu.Game.Rulesets.IGPlayer.Feature.Player.Plugins.Config
{
Expand All @@ -28,7 +30,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
}
}

public partial class PluginSettingsSubsection : SettingsSubsection
public partial class PluginSettingsSubsection : SettingsSection
{
private readonly LLinPlugin plugin;

Expand All @@ -41,7 +43,16 @@ public PluginSettingsSubsection(LLinPlugin plugin)
RelativeSizeAxes = Axes.X;
}

protected override LocalisableString Header => plugin.Name;
public override Drawable CreateIcon()
{
return new SpriteIcon
{
Icon = FontAwesome.Solid.Atom,
Size = new Vector2(18)
};
}

public override LocalisableString Header => plugin.Name;

[BackgroundDependencyLoader]
private void load(LLinPluginManager pluginManager)
Expand Down
51 changes: 49 additions & 2 deletions osu.Game.Rulesets.IGPlayer/Settings/Mf/MfMainSection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
using System.Linq;
using System.Reflection;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings;

namespace osu.Game.Rulesets.IGPlayer.Settings.Mf
Expand All @@ -7,11 +14,51 @@ public sealed partial class MfMainSection : RulesetSettingsSubsection
{
protected override LocalisableString Header { get; } = "Hikariii";

private readonly SubPanel subPanel = new();

private readonly SettingsButton settingsButton;

public MfMainSection(Ruleset ruleset)
: base(ruleset)
{
Add(new MfMvisPluginSection());
//Add(new LinuxSection());
var button = new SettingsButton();

button.Text = "打开设置面板";
button.Action = () => subPanel.ToggleVisibility();
Add(button);

settingsButton = button;
}

[BackgroundDependencyLoader]
private void load(SettingsOverlay settingsOverlay)
{
var targetMethod = settingsOverlay.GetType()
.GetRuntimeMethods()
.FirstOrDefault(method => method.Name == "createSubPanel")
?.MakeGenericMethod(typeof(SubPanel));

if (targetMethod == null)
{
Logging.Log($"未能找到对应的方法, 无法添加Hikariii设置到界面中", level: LogLevel.Important);
settingsButton.Enabled.Value = false;
return;
}

object? targetContainer = settingsOverlay.GetType()
.GetRuntimeFields()
.FirstOrDefault(field => field.Name == "ContentContainer")
?.GetValue(settingsOverlay);

if (targetContainer is not Container<Drawable> contentContainer)
{
Logging.Log($"未能找到对应的字段, 无法添加Hikariii设置到界面中", level: LogLevel.Important);
settingsButton.Enabled.Value = false;
return;
}

targetMethod.Invoke(settingsOverlay, [this.subPanel]);
this.Schedule(() => contentContainer.Add(subPanel));
}
}
}
25 changes: 25 additions & 0 deletions osu.Game.Rulesets.IGPlayer/Settings/Mf/SubPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.IGPlayer.Feature.Player.Interfaces.Plugins;
using osu.Game.Rulesets.IGPlayer.Feature.Player.Plugins;
using osu.Game.Rulesets.IGPlayer.Feature.Player.Plugins.Config;

namespace osu.Game.Rulesets.IGPlayer.Settings.Mf;

public partial class SubPanel : SettingsSubPanel
{
protected override Drawable CreateHeader()
{
return new SettingsHeader("Hikariii", "播放器和插件设置");
}

[BackgroundDependencyLoader]
private void load(LLinPluginManager manager)
{
foreach (LLinPlugin pl in manager.GetAllPlugins(false).Where(pl => manager.GetSettingsFor(pl)?.Length > 0))
AddSection(new PluginSettingsSubsection(pl));
}
}

0 comments on commit a2c2327

Please sign in to comment.