-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add skin mounting flow #30226
Open
smallketchup82
wants to merge
12
commits into
ppy:master
Choose a base branch
from
smallketchup82:skin-mounting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+327
−3
Open
Add skin mounting flow #30226
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4d09e94
Initial implementation
smallketchup82 9de248f
Fix changes not being applied instantly, Improve import performance, …
smallketchup82 a20bd5c
Abstract out logic to SkinImporter
smallketchup82 b7883f1
Add a toggle for checking overwriting
smallketchup82 ee16c96
Make everything translatable
smallketchup82 2b7eb56
Rename oldskin
smallketchup82 0dc77a7
Revert "Add a toggle for checking overwriting"
smallketchup82 942efce
Merge branch 'master' into skin-mounting
smallketchup82 3d16e45
Remove a comment
smallketchup82 44fe7f2
Switch to using an overlay interface for skin mounting
smallketchup82 ca5a74d
Switch overlay colour scheme to purple
smallketchup82 15c7a12
Switch colour scheme to blue
smallketchup82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Extensions; | ||
using osu.Framework.Extensions.Color4Extensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Input.Events; | ||
using osu.Framework.Logging; | ||
using osu.Framework.Platform; | ||
using osu.Framework.Testing; | ||
using osu.Game.Database; | ||
using osu.Game.Graphics; | ||
using osu.Game.Graphics.Containers; | ||
using osu.Game.Graphics.Sprites; | ||
using osu.Game.Graphics.UserInterface; | ||
using osu.Game.Graphics.UserInterfaceV2; | ||
using osu.Game.Input.Bindings; | ||
using osu.Game.Localisation; | ||
using osu.Game.Online.Multiplayer; | ||
using osu.Game.Screens.OnlinePlay.Match.Components; | ||
using osu.Game.Skinning; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Game.Overlays | ||
{ | ||
public partial class ExternalEditOverlay : OsuFocusedOverlayContainer | ||
{ | ||
private const double transition_duration = 300; | ||
private FillFlowContainer flow = null!; | ||
|
||
[Cached] | ||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should inherit from the skin editor's colours, no? |
||
|
||
[Resolved] | ||
private GameHost gameHost { get; set; } = null!; | ||
|
||
private ExternalEditOperation<SkinInfo>? editOperation; | ||
|
||
private Bindable<Skin>? skinBindable; | ||
private SkinManager? skinManager; | ||
|
||
protected override bool DimMainContent => false; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
RelativeSizeAxes = Axes.Both; | ||
InternalChild = new Container | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Masking = true, | ||
Children = new Drawable[] | ||
{ | ||
// Since we're drawing this overlay on top of another overlay (SkinEditor), the dimming effect isn't applied. So we need to add a dimming effect manually. | ||
new Box | ||
{ | ||
Colour = Color4.Black.Opacity(0.5f), | ||
RelativeSizeAxes = Axes.Both, | ||
}, | ||
new Container | ||
{ | ||
Masking = true, | ||
CornerRadius = 20, | ||
AutoSizeAxes = Axes.Both, | ||
AutoSizeDuration = 500, | ||
AutoSizeEasing = Easing.OutQuint, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Children = new Drawable[] | ||
{ | ||
new Box | ||
{ | ||
Colour = colourProvider.Background5, | ||
RelativeSizeAxes = Axes.Both, | ||
}, | ||
flow = new FillFlowContainer | ||
{ | ||
Margin = new MarginPadding(20), | ||
AutoSizeAxes = Axes.Both, | ||
Direction = FillDirection.Vertical, | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
Spacing = new Vector2(15), | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
public async Task Begin(SkinInfo skinInfo, Bindable<Skin> skinBindable, SkinManager skinManager) | ||
{ | ||
Show(); | ||
showSpinner("Mounting external skin..."); | ||
|
||
await Task.Delay(500).ConfigureAwait(true); | ||
|
||
try | ||
{ | ||
editOperation = await skinManager.BeginExternalEditing(skinInfo).ConfigureAwait(false); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.Log($"Failed to initialize external edit operation: {ex}", LoggingTarget.Database, LogLevel.Error); | ||
Schedule(() => showSpinner("Export failed!")); | ||
await Task.Delay(1000).ConfigureAwait(true); | ||
Hide(); | ||
} | ||
|
||
this.skinBindable = skinBindable; | ||
this.skinManager = skinManager; | ||
|
||
Schedule(() => | ||
{ | ||
flow.Children = new Drawable[] | ||
{ | ||
new OsuSpriteText | ||
{ | ||
Text = "Skin is mounted externally", | ||
Font = OsuFont.Default.With(size: 30), | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
}, | ||
new OsuTextFlowContainer | ||
{ | ||
Padding = new MarginPadding(5), | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
Width = 350, | ||
AutoSizeAxes = Axes.Y, | ||
Text = "Any changes made to the exported folder will be imported to the game, including file additions, modifications and deletions.", | ||
}, | ||
new PurpleRoundedButton | ||
{ | ||
Text = "Open folder", | ||
Width = 350, | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
Action = openDirectory, | ||
Enabled = { Value = false } | ||
}, | ||
new DangerousRoundedButton | ||
{ | ||
Text = EditorStrings.FinishEditingExternally, | ||
Width = 350, | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
Action = () => finish().FireAndForget(), | ||
Enabled = { Value = false } | ||
} | ||
}; | ||
}); | ||
|
||
Scheduler.AddDelayed(() => | ||
{ | ||
foreach (var b in flow.ChildrenOfType<RoundedButton>()) | ||
b.Enabled.Value = true; | ||
openDirectory(); | ||
}, 1000); | ||
} | ||
|
||
private void openDirectory() | ||
{ | ||
if (editOperation == null) | ||
return; | ||
|
||
gameHost.OpenFileExternally(editOperation.MountedPath.TrimDirectorySeparator() + Path.DirectorySeparatorChar); | ||
} | ||
|
||
private async Task finish() | ||
{ | ||
showSpinner("Cleaning up..."); | ||
await Task.Delay(500).ConfigureAwait(true); | ||
|
||
try | ||
{ | ||
await editOperation!.Finish().ConfigureAwait(false); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.Log($"Failed to finish external edit operation: {ex}", LoggingTarget.Database, LogLevel.Error); | ||
showSpinner("Import failed!"); | ||
await Task.Delay(1000).ConfigureAwait(true); | ||
Hide(); | ||
} | ||
|
||
Schedule(() => | ||
{ | ||
var oldSkin = skinBindable!.Value; | ||
var newSkinInfo = oldSkin.SkinInfo.PerformRead(s => s); | ||
|
||
// Create a new skin instance to ensure the skin is reloaded | ||
// If there's a better way to reload the skin, this should be replaced with it. | ||
skinBindable.Value = newSkinInfo.CreateInstance(skinManager!); | ||
|
||
oldSkin.Dispose(); | ||
|
||
Hide(); | ||
}); | ||
} | ||
|
||
protected override void PopIn() | ||
{ | ||
this.FadeIn(transition_duration, Easing.OutQuint); | ||
} | ||
|
||
protected override void PopOut() | ||
{ | ||
this.FadeOut(transition_duration, Easing.OutQuint).Finally(_ => | ||
{ | ||
// Set everything to a clean state | ||
editOperation = null; | ||
skinManager = null; | ||
skinBindable = null; | ||
flow.Children = Array.Empty<Drawable>(); | ||
}); | ||
} | ||
|
||
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e) | ||
{ | ||
if (e.Repeat) | ||
return false; | ||
|
||
switch (e.Action) | ||
{ | ||
case GlobalAction.Back: | ||
case GlobalAction.Select: | ||
if (editOperation == null) return base.OnPressed(e); | ||
|
||
finish().FireAndForget(); | ||
return true; | ||
} | ||
|
||
return base.OnPressed(e); | ||
} | ||
|
||
private void showSpinner(string text) | ||
{ | ||
foreach (var b in flow.ChildrenOfType<RoundedButton>()) | ||
b.Enabled.Value = false; | ||
|
||
flow.Children = new Drawable[] | ||
{ | ||
new OsuSpriteText | ||
{ | ||
Text = text, | ||
Font = OsuFont.Default.With(size: 30), | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
}, | ||
new LoadingSpinner | ||
{ | ||
Anchor = Anchor.TopCentre, | ||
Origin = Anchor.TopCentre, | ||
State = { Value = Visibility.Visible } | ||
}, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into an issue where detaching the skin doesn't actually end up detaching the files, resulting in a
Realms.Exceptions.RealmException: Realm accessed from incorrect thread.
exception.I couldn't find a way to fix it apart from this. Fortunately, we only access the realm files here to mount them, so we aren't modifying the files in a way that requires them to be attached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions:
SkinInfo
? It sure isn't registered in the automapper detach machinery.osu/osu.Game/Database/RealmObjectExtensions.cs
Lines 171 to 179 in 74675c8
Maybe adding
SkinInfo
in there just fixes this. I dunno.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The skin is being detached here
CurrentSkin.Value.SkinInfo
inSkinEditor
returns aLive<SkinInfo>
. My original idea for fixing the issue with "realm being accessed from an incorrect thread" was to detach theLive<SkinInfo>
so that we're only working with aSkinInfo
. Though, simply stopping here (without detachingFiles
) doesn't work and results in the thread error. Adding in the.Detach()
tomodel.Files
fixes it.I got here via trial and error so I don't know for certain. But my best guess is that it likely has to do with
RealmNamedFileUsage
being in the automapper detach machinery in which you specified. Maybe it's only detaching theFiles
that ends up fixing the issue, not necessarily the detaching of theLive<SkinInfo>
.At any rate, I guess detaching the
Live<SkinInfo>
serves only to convert fromLive<SkinInfo>
toSkinInfo
. But a quick test without detaching theLive<SkinInfo>
seems to work fine. So maybe that's unnecessary?