Skip to content

Commit

Permalink
Merge pull request #5 from MATRIX-feather/percydan-import-screen
Browse files Browse the repository at this point in the history
  • Loading branch information
PercyDan54 authored Dec 4, 2020
2 parents 579e61e + 7104230 commit 5eeb4bc
Showing 1 changed file with 60 additions and 111 deletions.
171 changes: 60 additions & 111 deletions osu.Game/Screens/Import/FileImportScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterfaceV2;
using osuTK;
using osu.Game.Overlays;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.Containers;
using osuTK.Graphics;
Expand All @@ -22,29 +21,32 @@ namespace osu.Game.Screens.Import
{
public class FileImportScreen : OsuScreen
{
private Container contentContainer;
private FileSelector fileSelector;
private Container fileSelectContainer;

public override bool HideOverlaysOnEnter => true;

private string defaultPath;
private readonly Bindable<FileInfo> currentFile = new Bindable<FileInfo>();
private readonly IBindable<DirectoryInfo> currentDirectory = new Bindable<DirectoryInfo>();

private FileSelector fileSelector;
private Container contentContainer;
private TextFlowContainer currentFileText;
private OsuScrollContainer fileNameScroll;
private readonly OverlayColourProvider overlayColourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);

private const float duration = 300;
private const float button_height = 50;
private const float button_vertical_margin = 15;

[Resolved]
private OsuGameBase gameBase { get; set; }

[Resolved]
private OsuColour colours { get; set; }

[BackgroundDependencyLoader(true)]
private void load(Storage storage)
{
storage.GetStorageForDirectory("imports");
var originalPath = storage.GetFullPath("imports", true);
string[] fileExtensions = { ".osk", ".osr", ".osz" };
defaultPath = originalPath;

InternalChild = contentContainer = new Container
{
Expand All @@ -58,103 +60,62 @@ private void load(Storage storage)
{
new Box
{
Colour = overlayColourProvider.Background5,
Colour = colours.GreySeafoamDark,
RelativeSizeAxes = Axes.Both,
},
fileSelectContainer = new Container
fileSelector = new FileSelector(initialPath: originalPath, validFileExtensions: fileExtensions)
{
RelativeSizeAxes = Axes.Both,
Width = 0.65f,
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Width = 0.65f
},
new Container
{
RelativeSizeAxes = Axes.Both,
Width = 0.35f,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Masking = true,
CornerRadius = 10,
Children = new Drawable[]
{
new GridContainer
new Box
{
Colour = colours.GreySeafoamDarker,
RelativeSizeAxes = Axes.Both
},
new Container
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
Padding = new MarginPadding { Bottom = button_height + button_vertical_margin * 2 },
Child = fileNameScroll = new OsuScrollContainer
{
new Drawable[]
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Child = currentFileText = new TextFlowContainer(t => t.Font = OsuFont.Default.With(size: 30))
{
new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Children = new Drawable[]
{
new Box
{
Colour = overlayColourProvider.Background3,
RelativeSizeAxes = Axes.Both
},
fileNameScroll = new OsuScrollContainer
{
Masking = false,
RelativeSizeAxes = Axes.Both,
Child = currentFileText = new TextFlowContainer(t => t.Font = OsuFont.Default.With(size: 30))
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextAnchor = Anchor.Centre
},
},
}
},
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextAnchor = Anchor.Centre
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Bottom = 15, Top = 15 },
Children = new Drawable[]
{
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new TriangleButton
{
Text = "Import",
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X,
Height = 50,
Width = 0.9f,
Action = () =>
{
var d = currentFile.Value?.FullName;
if (d != null)
startImport(d);
else
currentFileText.FlashColour(Color4.Red, 500);
}
}
}
}
}
}
}
},
},
new TriangleButton
{
Text = "Import",
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X,
Height = button_height,
Width = 0.9f,
Margin = new MarginPadding { Vertical = button_vertical_margin },
Action = () =>
{
var d = currentFile.Value?.FullName;
if (d != null)
startImport(d);
else
currentFileText.FlashColour(Color4.Red, 500);
}
}
}
Expand All @@ -165,25 +126,15 @@ private void load(Storage storage)
fileNameScroll.ScrollContent.Origin = Anchor.Centre;

currentFile.BindValueChanged(updateFileSelectionText, true);
currentDirectory.BindValueChanged(_ =>
{
currentFile.Value = null;
});
currentFile.UnbindBindings();
currentDirectory.UnbindBindings();

fileSelector?.Expire();

var directory = currentDirectory.Value?.FullName ?? defaultPath;
fileSelector = new FileSelector(initialPath: directory, validFileExtensions: fileExtensions)
{
RelativeSizeAxes = Axes.Both
};
currentDirectory.BindValueChanged(onCurrentDirectoryChanged);

currentDirectory.BindTo(fileSelector.CurrentPath);
currentFile.BindTo(fileSelector.CurrentFile);
}

fileSelectContainer.Add(fileSelector);
private void onCurrentDirectoryChanged(ValueChangedEvent<DirectoryInfo> v)
{
currentFile.Value = null;
}

private void updateFileSelectionText(ValueChangedEvent<FileInfo> v)
Expand All @@ -195,18 +146,16 @@ public override void OnEntering(IScreen last)
{
base.OnEntering(last);

contentContainer.FadeOut().Then().ScaleTo(0.8f).RotateTo(-15).MoveToX(300)
contentContainer.FadeOut().Then().ScaleTo(0.95f)
.Then()
.ScaleTo(1, 1500, Easing.OutElastic)
.FadeIn(500)
.MoveToX(0, 500, Easing.OutQuint)
.RotateTo(0, 500, Easing.OutQuint);
.ScaleTo(1, duration, Easing.OutQuint)
.FadeIn(duration);
}

public override bool OnExiting(IScreen next)
{
contentContainer.ScaleTo(0.8f, 500, Easing.OutExpo).RotateTo(-15, 500, Easing.OutExpo).MoveToX(300, 500, Easing.OutQuint).FadeOut(500);
this.FadeOut(500, Easing.OutExpo);
contentContainer.ScaleTo(0.95f, duration, Easing.OutQuint);
this.FadeOut(duration, Easing.OutQuint);

return base.OnExiting(next);
}
Expand All @@ -218,8 +167,8 @@ private void startImport(string path)

if (!File.Exists(path))
{
currentFileText.Text = "File not exist";
currentFileText.FlashColour(Color4.Red, 500);
currentFileText.Text = "No such file";
currentFileText.FlashColour(colours.Red, duration);
return;
}

Expand Down

0 comments on commit 5eeb4bc

Please sign in to comment.