mirror of
https://github.com/osukey/osukey.git
synced 2025-05-03 20:57:28 +09:00
Merge branch 'master' into editor-dont-block-keys-unnecessarily
This commit is contained in:
commit
e1fc8d76fb
@ -1,9 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
@ -14,75 +15,80 @@ namespace osu.Game.Rulesets.Taiko.Edit
|
|||||||
{
|
{
|
||||||
public class TaikoSelectionHandler : SelectionHandler
|
public class TaikoSelectionHandler : SelectionHandler
|
||||||
{
|
{
|
||||||
|
private readonly Bindable<TernaryState> selectionRimState = new Bindable<TernaryState>();
|
||||||
|
private readonly Bindable<TernaryState> selectionStrongState = new Bindable<TernaryState>();
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
selectionStrongState.ValueChanged += state =>
|
||||||
|
{
|
||||||
|
switch (state.NewValue)
|
||||||
|
{
|
||||||
|
case TernaryState.False:
|
||||||
|
SetStrongState(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TernaryState.True:
|
||||||
|
SetStrongState(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
selectionRimState.ValueChanged += state =>
|
||||||
|
{
|
||||||
|
switch (state.NewValue)
|
||||||
|
{
|
||||||
|
case TernaryState.False:
|
||||||
|
SetRimState(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TernaryState.True:
|
||||||
|
SetRimState(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetStrongState(bool state)
|
||||||
|
{
|
||||||
|
var hits = SelectedHitObjects.OfType<Hit>();
|
||||||
|
|
||||||
|
ChangeHandler.BeginChange();
|
||||||
|
|
||||||
|
foreach (var h in hits)
|
||||||
|
h.IsStrong = state;
|
||||||
|
|
||||||
|
ChangeHandler.EndChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetRimState(bool state)
|
||||||
|
{
|
||||||
|
var hits = SelectedHitObjects.OfType<Hit>();
|
||||||
|
|
||||||
|
ChangeHandler.BeginChange();
|
||||||
|
|
||||||
|
foreach (var h in hits)
|
||||||
|
h.Type = state ? HitType.Rim : HitType.Centre;
|
||||||
|
|
||||||
|
ChangeHandler.EndChange();
|
||||||
|
}
|
||||||
|
|
||||||
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
|
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
|
||||||
{
|
{
|
||||||
if (selection.All(s => s.HitObject is Hit))
|
if (selection.All(s => s.HitObject is Hit))
|
||||||
{
|
yield return new TernaryStateMenuItem("Rim") { State = { BindTarget = selectionRimState } };
|
||||||
var hits = selection.Select(s => s.HitObject).OfType<Hit>();
|
|
||||||
|
|
||||||
yield return new TernaryStateMenuItem("Rim", action: state =>
|
|
||||||
{
|
|
||||||
ChangeHandler.BeginChange();
|
|
||||||
|
|
||||||
foreach (var h in hits)
|
|
||||||
{
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case TernaryState.True:
|
|
||||||
h.Type = HitType.Rim;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TernaryState.False:
|
|
||||||
h.Type = HitType.Centre;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ChangeHandler.EndChange();
|
|
||||||
})
|
|
||||||
{
|
|
||||||
State = { Value = getTernaryState(hits, h => h.Type == HitType.Rim) }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selection.All(s => s.HitObject is TaikoHitObject))
|
if (selection.All(s => s.HitObject is TaikoHitObject))
|
||||||
{
|
yield return new TernaryStateMenuItem("Strong") { State = { BindTarget = selectionStrongState } };
|
||||||
var hits = selection.Select(s => s.HitObject).OfType<TaikoHitObject>();
|
|
||||||
|
|
||||||
yield return new TernaryStateMenuItem("Strong", action: state =>
|
|
||||||
{
|
|
||||||
ChangeHandler.BeginChange();
|
|
||||||
|
|
||||||
foreach (var h in hits)
|
|
||||||
{
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case TernaryState.True:
|
|
||||||
h.IsStrong = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TernaryState.False:
|
|
||||||
h.IsStrong = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorBeatmap?.UpdateHitObject(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
ChangeHandler.EndChange();
|
|
||||||
})
|
|
||||||
{
|
|
||||||
State = { Value = getTernaryState(hits, h => h.IsStrong) }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TernaryState getTernaryState<T>(IEnumerable<T> selection, Func<T, bool> func)
|
protected override void UpdateTernaryStates()
|
||||||
{
|
{
|
||||||
if (selection.Any(func))
|
base.UpdateTernaryStates();
|
||||||
return selection.All(func) ? TernaryState.True : TernaryState.Indeterminate;
|
|
||||||
|
|
||||||
return TernaryState.False;
|
selectionRimState.Value = GetStateFromSelection(SelectedHitObjects.OfType<Hit>(), h => h.Type == HitType.Rim);
|
||||||
|
selectionStrongState.Value = GetStateFromSelection(SelectedHitObjects.OfType<TaikoHitObject>(), h => h.IsStrong);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,35 +36,64 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
|
|
||||||
private bool pressHandledThisFrame;
|
private bool pressHandledThisFrame;
|
||||||
|
|
||||||
private Bindable<HitType> type;
|
private readonly Bindable<HitType> type;
|
||||||
|
|
||||||
public DrawableHit(Hit hit)
|
public DrawableHit(Hit hit)
|
||||||
: base(hit)
|
: base(hit)
|
||||||
{
|
{
|
||||||
|
type = HitObject.TypeBindable.GetBoundCopy();
|
||||||
FillMode = FillMode.Fit;
|
FillMode = FillMode.Fit;
|
||||||
|
|
||||||
|
updateActionsFromType();
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
type = HitObject.TypeBindable.GetBoundCopy();
|
|
||||||
type.BindValueChanged(_ =>
|
type.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
updateType();
|
updateActionsFromType();
|
||||||
|
|
||||||
|
// will overwrite samples, should only be called on change.
|
||||||
|
updateSamplesFromTypeChange();
|
||||||
|
|
||||||
RecreatePieces();
|
RecreatePieces();
|
||||||
});
|
});
|
||||||
|
|
||||||
updateType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateType()
|
private HitSampleInfo[] getRimSamples() => HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE).ToArray();
|
||||||
|
|
||||||
|
protected override void LoadSamples()
|
||||||
|
{
|
||||||
|
base.LoadSamples();
|
||||||
|
|
||||||
|
type.Value = getRimSamples().Any() ? HitType.Rim : HitType.Centre;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSamplesFromTypeChange()
|
||||||
|
{
|
||||||
|
var rimSamples = getRimSamples();
|
||||||
|
|
||||||
|
bool isRimType = HitObject.Type == HitType.Rim;
|
||||||
|
|
||||||
|
if (isRimType != rimSamples.Any())
|
||||||
|
{
|
||||||
|
if (isRimType)
|
||||||
|
HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_CLAP });
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var sample in rimSamples)
|
||||||
|
HitObject.Samples.Remove(sample);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateActionsFromType()
|
||||||
{
|
{
|
||||||
HitActions =
|
HitActions =
|
||||||
HitObject.Type == HitType.Centre
|
HitObject.Type == HitType.Centre
|
||||||
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
|
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
|
||||||
: new[] { TaikoAction.LeftRim, TaikoAction.RightRim };
|
: new[] { TaikoAction.LeftRim, TaikoAction.RightRim };
|
||||||
|
|
||||||
RecreatePieces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override SkinnableDrawable CreateMainPiece() => HitObject.Type == HitType.Centre
|
protected override SkinnableDrawable CreateMainPiece() => HitObject.Type == HitType.Centre
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Input.Bindings;
|
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
|
||||||
using osuTK;
|
|
||||||
using System.Linq;
|
|
||||||
using osu.Game.Audio;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
|
using osu.Framework.Input.Bindings;
|
||||||
|
using osu.Game.Audio;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||||
{
|
{
|
||||||
@ -120,7 +120,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
protected Vector2 BaseSize;
|
protected Vector2 BaseSize;
|
||||||
protected SkinnableDrawable MainPiece;
|
protected SkinnableDrawable MainPiece;
|
||||||
|
|
||||||
private Bindable<bool> isStrong;
|
private readonly Bindable<bool> isStrong;
|
||||||
|
|
||||||
private readonly Container<DrawableStrongNestedHit> strongHitContainer;
|
private readonly Container<DrawableStrongNestedHit> strongHitContainer;
|
||||||
|
|
||||||
@ -128,6 +128,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
: base(hitObject)
|
: base(hitObject)
|
||||||
{
|
{
|
||||||
HitObject = hitObject;
|
HitObject = hitObject;
|
||||||
|
isStrong = HitObject.IsStrongBindable.GetBoundCopy();
|
||||||
|
|
||||||
Anchor = Anchor.CentreLeft;
|
Anchor = Anchor.CentreLeft;
|
||||||
Origin = Anchor.Custom;
|
Origin = Anchor.Custom;
|
||||||
@ -140,8 +141,40 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
isStrong = HitObject.IsStrongBindable.GetBoundCopy();
|
isStrong.BindValueChanged(_ =>
|
||||||
isStrong.BindValueChanged(_ => RecreatePieces(), true);
|
{
|
||||||
|
// will overwrite samples, should only be called on change.
|
||||||
|
updateSamplesFromStrong();
|
||||||
|
|
||||||
|
RecreatePieces();
|
||||||
|
});
|
||||||
|
|
||||||
|
RecreatePieces();
|
||||||
|
}
|
||||||
|
|
||||||
|
private HitSampleInfo[] getStrongSamples() => HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_FINISH).ToArray();
|
||||||
|
|
||||||
|
protected override void LoadSamples()
|
||||||
|
{
|
||||||
|
base.LoadSamples();
|
||||||
|
|
||||||
|
isStrong.Value = getStrongSamples().Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSamplesFromStrong()
|
||||||
|
{
|
||||||
|
var strongSamples = getStrongSamples();
|
||||||
|
|
||||||
|
if (isStrong.Value != strongSamples.Any())
|
||||||
|
{
|
||||||
|
if (isStrong.Value)
|
||||||
|
HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_FINISH });
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var sample in strongSamples)
|
||||||
|
HitObject.Samples.Remove(sample);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RecreatePieces()
|
protected virtual void RecreatePieces()
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Platform;
|
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Settings
|
namespace osu.Game.Tests.Visual.Settings
|
||||||
@ -11,7 +10,7 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
public class TestSceneDirectorySelector : OsuTestScene
|
public class TestSceneDirectorySelector : OsuTestScene
|
||||||
{
|
{
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(GameHost host)
|
private void load()
|
||||||
{
|
{
|
||||||
Add(new DirectorySelector { RelativeSizeAxes = Axes.Both });
|
Add(new DirectorySelector { RelativeSizeAxes = Axes.Both });
|
||||||
}
|
}
|
||||||
|
24
osu.Game.Tests/Visual/Settings/TestSceneFileSelector.cs
Normal file
24
osu.Game.Tests/Visual/Settings/TestSceneFileSelector.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Settings
|
||||||
|
{
|
||||||
|
public class TestSceneFileSelector : OsuTestScene
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestAllFiles()
|
||||||
|
{
|
||||||
|
AddStep("create", () => Child = new FileSelector { RelativeSizeAxes = Axes.Both });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestJpgFilesOnly()
|
||||||
|
{
|
||||||
|
AddStep("create", () => Child = new FileSelector(validFileExtensions: new[] { ".jpg" }) { RelativeSizeAxes = Axes.Both });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -129,7 +129,7 @@ namespace osu.Game.Tournament.Screens
|
|||||||
|
|
||||||
protected virtual void ChangePath()
|
protected virtual void ChangePath()
|
||||||
{
|
{
|
||||||
var target = directorySelector.CurrentDirectory.Value.FullName;
|
var target = directorySelector.CurrentPath.Value.FullName;
|
||||||
var fileBasedIpc = ipc as FileBasedIPC;
|
var fileBasedIpc = ipc as FileBasedIPC;
|
||||||
Logger.Log($"Changing Stable CE location to {target}");
|
Logger.Log($"Changing Stable CE location to {target}");
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
private GameHost host { get; set; }
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
public readonly Bindable<DirectoryInfo> CurrentDirectory = new Bindable<DirectoryInfo>();
|
public readonly Bindable<DirectoryInfo> CurrentPath = new Bindable<DirectoryInfo>();
|
||||||
|
|
||||||
public DirectorySelector(string initialPath = null)
|
public DirectorySelector(string initialPath = null)
|
||||||
{
|
{
|
||||||
CurrentDirectory.Value = new DirectoryInfo(initialPath ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
|
CurrentPath.Value = new DirectoryInfo(initialPath ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -74,7 +74,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentDirectory.BindValueChanged(updateDisplay, true);
|
CurrentPath.BindValueChanged(updateDisplay, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDisplay(ValueChangedEvent<DirectoryInfo> directory)
|
private void updateDisplay(ValueChangedEvent<DirectoryInfo> directory)
|
||||||
@ -92,22 +92,27 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
directoryFlow.Add(new ParentDirectoryPiece(CurrentDirectory.Value.Parent));
|
directoryFlow.Add(new ParentDirectoryPiece(CurrentPath.Value.Parent));
|
||||||
|
|
||||||
foreach (var dir in CurrentDirectory.Value.GetDirectories().OrderBy(d => d.Name))
|
directoryFlow.AddRange(GetEntriesForPath(CurrentPath.Value));
|
||||||
{
|
|
||||||
if ((dir.Attributes & FileAttributes.Hidden) == 0)
|
|
||||||
directoryFlow.Add(new DirectoryPiece(dir));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
CurrentDirectory.Value = directory.OldValue;
|
CurrentPath.Value = directory.OldValue;
|
||||||
this.FlashColour(Color4.Red, 300);
|
this.FlashColour(Color4.Red, 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual IEnumerable<DisplayPiece> GetEntriesForPath(DirectoryInfo path)
|
||||||
|
{
|
||||||
|
foreach (var dir in path.GetDirectories().OrderBy(d => d.Name))
|
||||||
|
{
|
||||||
|
if ((dir.Attributes & FileAttributes.Hidden) == 0)
|
||||||
|
yield return new DirectoryPiece(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class CurrentDirectoryDisplay : CompositeDrawable
|
private class CurrentDirectoryDisplay : CompositeDrawable
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -126,7 +131,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Spacing = new Vector2(5),
|
Spacing = new Vector2(5),
|
||||||
Height = DirectoryPiece.HEIGHT,
|
Height = DisplayPiece.HEIGHT,
|
||||||
Direction = FillDirection.Horizontal,
|
Direction = FillDirection.Horizontal,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -150,7 +155,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
|
|
||||||
flow.ChildrenEnumerable = new Drawable[]
|
flow.ChildrenEnumerable = new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuSpriteText { Text = "Current Directory: ", Font = OsuFont.Default.With(size: DirectoryPiece.HEIGHT), },
|
new OsuSpriteText { Text = "Current Directory: ", Font = OsuFont.Default.With(size: DisplayPiece.HEIGHT), },
|
||||||
new ComputerPiece(),
|
new ComputerPiece(),
|
||||||
}.Concat(pathPieces);
|
}.Concat(pathPieces);
|
||||||
}
|
}
|
||||||
@ -198,24 +203,44 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DirectoryPiece : CompositeDrawable
|
protected class DirectoryPiece : DisplayPiece
|
||||||
{
|
{
|
||||||
public const float HEIGHT = 20;
|
|
||||||
|
|
||||||
protected const float FONT_SIZE = 16;
|
|
||||||
|
|
||||||
protected readonly DirectoryInfo Directory;
|
protected readonly DirectoryInfo Directory;
|
||||||
|
|
||||||
private readonly string displayName;
|
|
||||||
|
|
||||||
protected FillFlowContainer Flow;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<DirectoryInfo> currentDirectory { get; set; }
|
private Bindable<DirectoryInfo> currentDirectory { get; set; }
|
||||||
|
|
||||||
public DirectoryPiece(DirectoryInfo directory, string displayName = null)
|
public DirectoryPiece(DirectoryInfo directory, string displayName = null)
|
||||||
|
: base(displayName)
|
||||||
{
|
{
|
||||||
Directory = directory;
|
Directory = directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
currentDirectory.Value = Directory;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string FallbackName => Directory.Name;
|
||||||
|
|
||||||
|
protected override IconUsage? Icon => Directory.Name.Contains(Path.DirectorySeparatorChar)
|
||||||
|
? FontAwesome.Solid.Database
|
||||||
|
: FontAwesome.Regular.Folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract class DisplayPiece : CompositeDrawable
|
||||||
|
{
|
||||||
|
public const float HEIGHT = 20;
|
||||||
|
|
||||||
|
protected const float FONT_SIZE = 16;
|
||||||
|
|
||||||
|
private readonly string displayName;
|
||||||
|
|
||||||
|
protected FillFlowContainer Flow;
|
||||||
|
|
||||||
|
protected DisplayPiece(string displayName = null)
|
||||||
|
{
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,20 +284,14 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Text = displayName ?? Directory.Name,
|
Text = displayName ?? FallbackName,
|
||||||
Font = OsuFont.Default.With(size: FONT_SIZE)
|
Font = OsuFont.Default.With(size: FONT_SIZE)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected abstract string FallbackName { get; }
|
||||||
{
|
|
||||||
currentDirectory.Value = Directory;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual IconUsage? Icon => Directory.Name.Contains(Path.DirectorySeparatorChar)
|
protected abstract IconUsage? Icon { get; }
|
||||||
? FontAwesome.Solid.Database
|
|
||||||
: FontAwesome.Regular.Folder;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
94
osu.Game/Graphics/UserInterfaceV2/FileSelector.cs
Normal file
94
osu.Game/Graphics/UserInterfaceV2/FileSelector.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.UserInterfaceV2
|
||||||
|
{
|
||||||
|
public class FileSelector : DirectorySelector
|
||||||
|
{
|
||||||
|
private readonly string[] validFileExtensions;
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
public readonly Bindable<FileInfo> CurrentFile = new Bindable<FileInfo>();
|
||||||
|
|
||||||
|
public FileSelector(string initialPath = null, string[] validFileExtensions = null)
|
||||||
|
: base(initialPath)
|
||||||
|
{
|
||||||
|
this.validFileExtensions = validFileExtensions ?? Array.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<DisplayPiece> GetEntriesForPath(DirectoryInfo path)
|
||||||
|
{
|
||||||
|
foreach (var dir in base.GetEntriesForPath(path))
|
||||||
|
yield return dir;
|
||||||
|
|
||||||
|
IEnumerable<FileInfo> files = path.GetFiles();
|
||||||
|
|
||||||
|
if (validFileExtensions.Length > 0)
|
||||||
|
files = files.Where(f => validFileExtensions.Contains(f.Extension));
|
||||||
|
|
||||||
|
foreach (var file in files.OrderBy(d => d.Name))
|
||||||
|
{
|
||||||
|
if ((file.Attributes & FileAttributes.Hidden) == 0)
|
||||||
|
yield return new FilePiece(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class FilePiece : DisplayPiece
|
||||||
|
{
|
||||||
|
private readonly FileInfo file;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<FileInfo> currentFile { get; set; }
|
||||||
|
|
||||||
|
public FilePiece(FileInfo file)
|
||||||
|
{
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
currentFile.Value = file;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string FallbackName => file.Name;
|
||||||
|
|
||||||
|
protected override IconUsage? Icon
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
switch (file.Extension)
|
||||||
|
{
|
||||||
|
case ".ogg":
|
||||||
|
case ".mp3":
|
||||||
|
case ".wav":
|
||||||
|
return FontAwesome.Regular.FileAudio;
|
||||||
|
|
||||||
|
case ".jpg":
|
||||||
|
case ".jpeg":
|
||||||
|
case ".png":
|
||||||
|
return FontAwesome.Regular.FileImage;
|
||||||
|
|
||||||
|
case ".mp4":
|
||||||
|
case ".avi":
|
||||||
|
case ".mov":
|
||||||
|
case ".flv":
|
||||||
|
return FontAwesome.Regular.FileVideo;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return FontAwesome.Regular.File;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
|
|
||||||
protected override OsuTextBox CreateComponent() => new OsuTextBox
|
protected override OsuTextBox CreateComponent() => new OsuTextBox
|
||||||
{
|
{
|
||||||
|
CommitOnFocusLost = true,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
@ -106,7 +106,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
|
|
||||||
private void start()
|
private void start()
|
||||||
{
|
{
|
||||||
var target = directorySelector.CurrentDirectory.Value;
|
var target = directorySelector.CurrentPath.Value;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -208,7 +208,7 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
|
|
||||||
if (checkRightToggleFromKey(e.Key, out var rightIndex))
|
if (checkRightToggleFromKey(e.Key, out var rightIndex))
|
||||||
{
|
{
|
||||||
var item = togglesCollection.Children[rightIndex];
|
var item = togglesCollection.ElementAtOrDefault(rightIndex);
|
||||||
|
|
||||||
if (item is SettingsCheckbox checkbox)
|
if (item is SettingsCheckbox checkbox)
|
||||||
{
|
{
|
||||||
|
@ -157,6 +157,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
updateState(ArmedState.Idle, true);
|
updateState(ArmedState.Idle, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked by the base <see cref="DrawableHitObject"/> to populate samples, once on initial load and potentially again on any change to the samples collection.
|
||||||
|
/// </summary>
|
||||||
protected virtual void LoadSamples()
|
protected virtual void LoadSamples()
|
||||||
{
|
{
|
||||||
if (Samples != null)
|
if (Samples != null)
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Humanizer;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
@ -59,6 +61,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
|
createStateBindables();
|
||||||
|
|
||||||
InternalChild = content = new Container
|
InternalChild = content = new Container
|
||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -308,6 +312,90 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Selection State
|
||||||
|
|
||||||
|
private readonly Bindable<TernaryState> selectionNewComboState = new Bindable<TernaryState>();
|
||||||
|
|
||||||
|
private readonly Dictionary<string, Bindable<TernaryState>> selectionSampleStates = new Dictionary<string, Bindable<TernaryState>>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set up ternary state bindables and bind them to selection/hitobject changes (in both directions)
|
||||||
|
/// </summary>
|
||||||
|
private void createStateBindables()
|
||||||
|
{
|
||||||
|
// hit samples
|
||||||
|
var sampleTypes = new[] { HitSampleInfo.HIT_WHISTLE, HitSampleInfo.HIT_CLAP, HitSampleInfo.HIT_FINISH };
|
||||||
|
|
||||||
|
foreach (var sampleName in sampleTypes)
|
||||||
|
{
|
||||||
|
var bindable = new Bindable<TernaryState>
|
||||||
|
{
|
||||||
|
Description = sampleName.Replace("hit", string.Empty).Titleize()
|
||||||
|
};
|
||||||
|
|
||||||
|
bindable.ValueChanged += state =>
|
||||||
|
{
|
||||||
|
switch (state.NewValue)
|
||||||
|
{
|
||||||
|
case TernaryState.False:
|
||||||
|
RemoveHitSample(sampleName);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TernaryState.True:
|
||||||
|
AddHitSample(sampleName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
selectionSampleStates[sampleName] = bindable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// new combo
|
||||||
|
selectionNewComboState.ValueChanged += state =>
|
||||||
|
{
|
||||||
|
switch (state.NewValue)
|
||||||
|
{
|
||||||
|
case TernaryState.False:
|
||||||
|
SetNewCombo(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TernaryState.True:
|
||||||
|
SetNewCombo(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// bring in updates from selection changes
|
||||||
|
EditorBeatmap.HitObjectUpdated += _ => UpdateTernaryStates();
|
||||||
|
EditorBeatmap.SelectedHitObjects.CollectionChanged += (sender, args) => UpdateTernaryStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when context menu ternary states may need to be recalculated (selection changed or hitobject updated).
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void UpdateTernaryStates()
|
||||||
|
{
|
||||||
|
selectionNewComboState.Value = GetStateFromSelection(SelectedHitObjects.OfType<IHasComboInformation>(), h => h.NewCombo);
|
||||||
|
|
||||||
|
foreach (var (sampleName, bindable) in selectionSampleStates)
|
||||||
|
{
|
||||||
|
bindable.Value = GetStateFromSelection(SelectedHitObjects, h => h.Samples.Any(s => s.Name == sampleName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Given a selection target and a function of truth, retrieve the correct ternary state for display.
|
||||||
|
/// </summary>
|
||||||
|
protected TernaryState GetStateFromSelection<T>(IEnumerable<T> selection, Func<T, bool> func)
|
||||||
|
{
|
||||||
|
if (selection.Any(func))
|
||||||
|
return selection.All(func) ? TernaryState.True : TernaryState.Indeterminate;
|
||||||
|
|
||||||
|
return TernaryState.False;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Context Menu
|
#region Context Menu
|
||||||
|
|
||||||
public MenuItem[] ContextMenuItems
|
public MenuItem[] ContextMenuItems
|
||||||
@ -322,7 +410,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
items.AddRange(GetContextMenuItemsForSelection(selectedBlueprints));
|
items.AddRange(GetContextMenuItemsForSelection(selectedBlueprints));
|
||||||
|
|
||||||
if (selectedBlueprints.All(b => b.HitObject is IHasComboInformation))
|
if (selectedBlueprints.All(b => b.HitObject is IHasComboInformation))
|
||||||
items.Add(createNewComboMenuItem());
|
{
|
||||||
|
items.Add(new TernaryStateMenuItem("New combo") { State = { BindTarget = selectionNewComboState } });
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedBlueprints.Count == 1)
|
if (selectedBlueprints.Count == 1)
|
||||||
items.AddRange(selectedBlueprints[0].ContextMenuItems);
|
items.AddRange(selectedBlueprints[0].ContextMenuItems);
|
||||||
@ -331,12 +421,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
{
|
{
|
||||||
new OsuMenuItem("Sound")
|
new OsuMenuItem("Sound")
|
||||||
{
|
{
|
||||||
Items = new[]
|
Items = selectionSampleStates.Select(kvp =>
|
||||||
{
|
new TernaryStateMenuItem(kvp.Value.Description) { State = { BindTarget = kvp.Value } }).ToArray()
|
||||||
createHitSampleMenuItem("Whistle", HitSampleInfo.HIT_WHISTLE),
|
|
||||||
createHitSampleMenuItem("Clap", HitSampleInfo.HIT_CLAP),
|
|
||||||
createHitSampleMenuItem("Finish", HitSampleInfo.HIT_FINISH)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
new OsuMenuItem("Delete", MenuItemType.Destructive, deleteSelected),
|
new OsuMenuItem("Delete", MenuItemType.Destructive, deleteSelected),
|
||||||
});
|
});
|
||||||
@ -353,76 +439,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
protected virtual IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
|
protected virtual IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint> selection)
|
||||||
=> Enumerable.Empty<MenuItem>();
|
=> Enumerable.Empty<MenuItem>();
|
||||||
|
|
||||||
private MenuItem createNewComboMenuItem()
|
|
||||||
{
|
|
||||||
return new TernaryStateMenuItem("New combo", MenuItemType.Standard, setNewComboState)
|
|
||||||
{
|
|
||||||
State = { Value = getHitSampleState() }
|
|
||||||
};
|
|
||||||
|
|
||||||
void setNewComboState(TernaryState state)
|
|
||||||
{
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case TernaryState.False:
|
|
||||||
SetNewCombo(false);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TernaryState.True:
|
|
||||||
SetNewCombo(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TernaryState getHitSampleState()
|
|
||||||
{
|
|
||||||
int countExisting = selectedBlueprints.Select(b => (IHasComboInformation)b.HitObject).Count(h => h.NewCombo);
|
|
||||||
|
|
||||||
if (countExisting == 0)
|
|
||||||
return TernaryState.False;
|
|
||||||
|
|
||||||
if (countExisting < SelectedHitObjects.Count())
|
|
||||||
return TernaryState.Indeterminate;
|
|
||||||
|
|
||||||
return TernaryState.True;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private MenuItem createHitSampleMenuItem(string name, string sampleName)
|
|
||||||
{
|
|
||||||
return new TernaryStateMenuItem(name, MenuItemType.Standard, setHitSampleState)
|
|
||||||
{
|
|
||||||
State = { Value = getHitSampleState() }
|
|
||||||
};
|
|
||||||
|
|
||||||
void setHitSampleState(TernaryState state)
|
|
||||||
{
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case TernaryState.False:
|
|
||||||
RemoveHitSample(sampleName);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TernaryState.True:
|
|
||||||
AddHitSample(sampleName);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TernaryState getHitSampleState()
|
|
||||||
{
|
|
||||||
int countExisting = SelectedHitObjects.Count(h => h.Samples.Any(s => s.Name == sampleName));
|
|
||||||
|
|
||||||
if (countExisting == 0)
|
|
||||||
return TernaryState.False;
|
|
||||||
|
|
||||||
if (countExisting < SelectedHitObjects.Count())
|
|
||||||
return TernaryState.Indeterminate;
|
|
||||||
|
|
||||||
return TernaryState.True;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user