1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 15:12:57 +08:00

Add the ability to revert all skin changes

This commit is contained in:
Dean Herbert 2021-05-11 11:57:12 +09:00
parent 4769a95b49
commit 81902ad6a6

View File

@ -13,6 +13,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Skinning.Editor namespace osu.Game.Skinning.Editor
{ {
@ -20,7 +21,7 @@ namespace osu.Game.Skinning.Editor
{ {
public const double TRANSITION_DURATION = 500; public const double TRANSITION_DURATION = 500;
private readonly Drawable target; private readonly Drawable targetScreen;
private OsuTextFlowContainer headerText; private OsuTextFlowContainer headerText;
@ -29,9 +30,9 @@ namespace osu.Game.Skinning.Editor
[Resolved] [Resolved]
private SkinManager skins { get; set; } private SkinManager skins { get; set; }
public SkinEditor(Drawable target) public SkinEditor(Drawable targetScreen)
{ {
this.target = target; this.targetScreen = targetScreen;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
@ -52,18 +53,20 @@ namespace osu.Game.Skinning.Editor
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X RelativeSizeAxes = Axes.X
}, },
new SkinBlueprintContainer(target), new SkinBlueprintContainer(targetScreen),
new SkinComponentToolbox(600) new SkinComponentToolbox(600)
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
RequestPlacement = placeComponent RequestPlacement = placeComponent
}, },
new TriangleButton new FillFlowContainer
{ {
Text = "Save Changes", Direction = FillDirection.Horizontal,
Width = 140, AutoSizeAxes = Axes.Both,
Height = 50, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Spacing = new Vector2(5),
Padding = new MarginPadding Padding = new MarginPadding
{ {
Top = 10, Top = 10,
@ -74,7 +77,21 @@ namespace osu.Game.Skinning.Editor
Right = 10, Right = 10,
Bottom = 10, Bottom = 10,
}, },
Action = save, Children = new Drawable[]
{
new TriangleButton
{
Text = "Save Changes",
Width = 140,
Action = save,
},
new DangerousTriangleButton
{
Text = "Revert to default",
Width = 140,
Action = revert,
},
}
}, },
} }
}; };
@ -89,11 +106,14 @@ namespace osu.Game.Skinning.Editor
private void placeComponent(Type type) private void placeComponent(Type type)
{ {
var instance = (Drawable)Activator.CreateInstance(type); Drawable instance = (Drawable)Activator.CreateInstance(type);
var targetContainer = target.ChildrenOfType<IDefaultSkinnableTarget>().FirstOrDefault(); getTarget(SkinnableTarget.MainHUDComponents)?.Add(instance);
}
(targetContainer as Container)?.Add(instance); private ISkinnableTarget getTarget(SkinnableTarget target)
{
return targetScreen.ChildrenOfType<ISkinnableTarget>().FirstOrDefault(c => c.Target == target);
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -102,6 +122,26 @@ namespace osu.Game.Skinning.Editor
Show(); Show();
} }
private void revert()
{
var currentSkin = skins.CurrentSkin.Value;
var legacySkin = currentSkin as LegacySkin;
if (legacySkin == null)
return;
SkinnableElementTargetContainer[] targetContainers = targetScreen.ChildrenOfType<SkinnableElementTargetContainer>().ToArray();
foreach (var t in targetContainers)
{
legacySkin.ResetDrawableTarget(t);
// add back default components
getTarget(t.Target).Reload();
}
}
private void save() private void save()
{ {
var currentSkin = skins.CurrentSkin.Value; var currentSkin = skins.CurrentSkin.Value;
@ -111,7 +151,7 @@ namespace osu.Game.Skinning.Editor
if (legacySkin == null) if (legacySkin == null)
return; return;
SkinnableElementTargetContainer[] targetContainers = target.ChildrenOfType<SkinnableElementTargetContainer>().ToArray(); SkinnableElementTargetContainer[] targetContainers = targetScreen.ChildrenOfType<SkinnableElementTargetContainer>().ToArray();
foreach (var t in targetContainers) foreach (var t in targetContainers)
legacySkin.UpdateDrawableTarget(t); legacySkin.UpdateDrawableTarget(t);