Skip to content

Commit

Permalink
Add Directory browser (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
adryzz authored Oct 10, 2021
1 parent 3d8d67e commit 2211edf
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
68 changes: 68 additions & 0 deletions Vignette.Game/Settings/Components/SettingsDirectoryBrowser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2020 - 2021 Vignette Project
// Licensed under NPOSLv3. See LICENSE for details.

using System.IO;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osuTK;
using Vignette.Game.Graphics.UserInterface;

namespace Vignette.Game.Settings.Components
{
public class SettingsDirectoryBrowser : SettingsExpandedControl<FluentTextBox, string>, IHasPopover
{
protected override FluentTextBox CreateControl() => new FluentTextBox { RelativeSizeAxes = Axes.X, CharacterLimit = 10000 };

private readonly Bindable<DirectoryInfo> currentDirectory = new Bindable<DirectoryInfo>();

protected override void InitializeControl()
{
Foreground.Add(new GridContainer
{
Height = 28,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, 100),
},
Content = new Drawable[][]
{
new Drawable[]
{
Control = CreateControl(),
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 10 },
Child = new FluentButton
{
Text = "Browse",
Style = ButtonStyle.Primary,
RelativeSizeAxes = Axes.X,
Action = () => this.ShowPopover(),
}
}
}
}
});

currentDirectory.ValueChanged += e => Current.Value = e.NewValue.FullName;
}

public Popover GetPopover() => new FluentPopover
{
Child = new FluentDirectorySelector()
{
Size = new Vector2(600, 200),
CurrentPath = { BindTarget = currentDirectory },
}
};
}
}
2 changes: 1 addition & 1 deletion Vignette.Game/Settings/Sections/AvatarSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void load(VignetteConfigManager config, SessionConfigManager session)
{
new SettingsSubSection
{
Child = new SettingsFileBrowser
Child = new SettingsDirectoryBrowser
{
Label = "Location",
Current = config.GetBindable<string>(VignetteSetting.AvatarPath),
Expand Down

0 comments on commit 2211edf

Please sign in to comment.