-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
397 additions
and
264 deletions.
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
109 changes: 109 additions & 0 deletions
109
fluXis.Game/Screens/Edit/BottomBar/Snap/SnapControlPopover.cs
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,109 @@ | ||
using System; | ||
using System.Linq; | ||
using fluXis.Game.Audio; | ||
using fluXis.Game.Graphics.Sprites; | ||
using fluXis.Game.Skinning; | ||
using fluXis.Game.Utils; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Extensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Input.Events; | ||
using osuTK; | ||
|
||
namespace fluXis.Game.Screens.Edit.BottomBar.Snap; | ||
|
||
public partial class SnapControlPopover : CompositeDrawable | ||
{ | ||
[Resolved] | ||
private EditorSettings settings { get; set; } | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
AutoSizeAxes = Axes.Both; | ||
|
||
InternalChild = new FillFlowContainer | ||
{ | ||
AutoSizeAxes = Axes.Both, | ||
Direction = FillDirection.Full, | ||
MaximumSize = new Vector2(196, 0), | ||
ChildrenEnumerable = SnapControl.DefaultSnaps.Select(snap => new SnapChip(snap, updateSnap)) | ||
}; | ||
} | ||
|
||
private void updateSnap(int num) | ||
{ | ||
settings.SnapDivisor = num; | ||
this.HidePopover(); | ||
} | ||
|
||
private partial class SnapChip : CompositeDrawable | ||
{ | ||
[Resolved] | ||
private UISamples samples { get; set; } | ||
|
||
private int snap { get; } | ||
private Action<int> action { get; } | ||
|
||
private Box hover; | ||
private Box flash; | ||
|
||
public SnapChip(int snap, Action<int> action) | ||
{ | ||
this.snap = snap; | ||
this.action = action; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(SkinManager skinManager) | ||
{ | ||
Size = new Vector2(96, 42); | ||
|
||
var idx = Array.IndexOf(SnapControl.DefaultSnaps, snap); | ||
Colour = skinManager.SkinJson.SnapColors.GetColor(idx); | ||
|
||
InternalChildren = new Drawable[] | ||
{ | ||
hover = new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Alpha = 0 | ||
}, | ||
flash = new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Alpha = 0 | ||
}, | ||
new FluXisSpriteText | ||
{ | ||
Text = $"1/{snap.ToOrdinalShort(true)}", | ||
WebFontSize = 14, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre | ||
} | ||
}; | ||
} | ||
|
||
protected override bool OnHover(HoverEvent e) | ||
{ | ||
hover.FadeTo(.2f, 50); | ||
samples.Hover(); | ||
return true; | ||
} | ||
|
||
protected override void OnHoverLost(HoverLostEvent e) | ||
{ | ||
hover.FadeOut(200); | ||
} | ||
|
||
protected override bool OnClick(ClickEvent e) | ||
{ | ||
samples.Click(); | ||
flash.FadeOutFromOne(1000, Easing.OutQuint); | ||
action?.Invoke(snap); | ||
return true; | ||
} | ||
} | ||
} |
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,106 @@ | ||
using System; | ||
using fluXis.Game.Audio; | ||
using fluXis.Game.Graphics.Containers; | ||
using fluXis.Game.Graphics.Sprites; | ||
using fluXis.Game.Screens.Edit.BottomBar.Snap; | ||
using fluXis.Game.Skinning; | ||
using fluXis.Game.Utils; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Extensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Cursor; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Graphics.UserInterface; | ||
using osu.Framework.Input.Events; | ||
using osu.Framework.Localisation; | ||
|
||
namespace fluXis.Game.Screens.Edit.BottomBar; | ||
|
||
public partial class SnapControl : CompositeDrawable, IHasPopover, IHasTooltip | ||
{ | ||
public static int[] DefaultSnaps { get; } = { 1, 2, 3, 4, 6, 8, 12, 16 }; | ||
|
||
public LocalisableString TooltipText => "The current beat snap.\nCan also be changed by shift-scrolling."; | ||
|
||
private FluXisSpriteText text; | ||
|
||
[Resolved] | ||
private EditorSettings settings { get; set; } | ||
|
||
[Resolved] | ||
private UISamples samples { get; set; } | ||
|
||
[Resolved] | ||
private SkinManager skinManager { get; set; } | ||
|
||
private Box hover; | ||
private Box flash; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
RelativeSizeAxes = Axes.Both; | ||
|
||
InternalChildren = new Drawable[] | ||
{ | ||
hover = new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Alpha = 0 | ||
}, | ||
flash = new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Alpha = 0 | ||
}, | ||
text = new FluXisSpriteText | ||
{ | ||
WebFontSize = 16, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre | ||
} | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
settings.SnapDivisorBindable.BindValueChanged(e => | ||
{ | ||
var snap = e.NewValue; | ||
text.Text = $"1/{snap.ToOrdinalShort(true)}"; | ||
var idx = Array.IndexOf(DefaultSnaps, snap); | ||
Colour = skinManager.SkinJson.SnapColors.GetColor(idx); | ||
}, true); | ||
} | ||
|
||
protected override bool OnHover(HoverEvent e) | ||
{ | ||
hover.FadeTo(.2f, 50); | ||
samples.Hover(); | ||
return true; | ||
} | ||
|
||
protected override void OnHoverLost(HoverLostEvent e) | ||
{ | ||
hover.FadeOut(200); | ||
} | ||
|
||
protected override bool OnClick(ClickEvent e) | ||
{ | ||
samples.Click(); | ||
flash.FadeOutFromOne(1000, Easing.OutQuint); | ||
this.ShowPopover(); | ||
return true; | ||
} | ||
|
||
public Popover GetPopover() => new FluXisPopover | ||
{ | ||
ContentPadding = 0, | ||
BodyRadius = 12, | ||
Child = new SnapControlPopover() | ||
}; | ||
} |
Oops, something went wrong.