Skip to content

Commit

Permalink
add increment buttons for bpm and offset
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Dec 12, 2024
1 parent b169f4e commit aee4519
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
using fluXis.Game.Map.Structures.Bases;
using fluXis.Game.Screens.Edit.Tabs.Shared.Points.List;
using fluXis.Game.Screens.Edit.Tabs.Shared.Points.Settings;
using fluXis.Game.Screens.Edit.Tabs.Shared.Points.Settings.Preset;
using fluXis.Game.Screens.Edit.Tabs.Shared.Points.Settings.Waveform;
using fluXis.Game.Utils;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics;

namespace fluXis.Game.Screens.Edit.Tabs.Charting.Points.Entries;
Expand All @@ -20,6 +23,12 @@ public partial class TimingPointEntry : PointListEntry

private TimingPoint timing => Object as TimingPoint;

[CanBeNull]
private PointSettingsTime timeBox;

[CanBeNull]
private PointSettingsTextBox bpmBox;

public TimingPointEntry(TimingPoint timing)
: base(timing)
{
Expand All @@ -33,28 +42,35 @@ public TimingPointEntry(TimingPoint timing)
HideLines = timing.HideLines
};

protected override Drawable[] CreateValueContent()
protected override Drawable[] CreateValueContent() => new Drawable[]
{
return new Drawable[]
new FluXisSpriteText
{
new FluXisSpriteText
{
Text = $"{timing.BPM.ToStringInvariant("0.0")}bpm {timing.Signature}/4",
Colour = Color
}
};
Text = $"{timing.BPM.ToStringInvariant("0.0")}bpm {timing.Signature}/4",
Colour = Color
}
};

protected override void OnValueUpdate()
{
if (timeBox is not null)
timeBox.TextBox.Text = timing.Time.ToStringInvariant("0");
if (bpmBox is not null)
bpmBox.TextBox.Text = timing.BPM.ToStringInvariant("0.##");
}

protected override IEnumerable<Drawable> CreateSettings()
{
return base.CreateSettings().Concat(new Drawable[]
return base.CreateSettings().Take(1).Concat(new Drawable[]
{
timeBox = new PointSettingsTime(Map, Object),
new WaveformDisplay(timing),
new PointSettingsTextBox
new PointSettingsIncrements(Map, timing),
bpmBox = new PointSettingsTextBox
{
Text = "BPM",
TooltipText = "The beats per minute of the timing point.",
DefaultText = timing.BPM.ToStringInvariant("0.00"),
DefaultText = timing.BPM.ToStringInvariant("0.##"),
OnTextChanged = box =>
{
if (float.TryParse(box.Text, CultureInfo.InvariantCulture, out var result) && result > 0)
Expand All @@ -81,6 +97,17 @@ protected override IEnumerable<Drawable> CreateSettings()

Map.Update(timing);
}
},
new PointSettingsToggle
{
Text = "Hide Lines",
TooltipText = "Hides the lines that appear every 4 beats during gameplay.",
Bindable = new Bindable<bool>(timing.HideLines),
OnStateChanged = enabled =>
{
timing.HideLines = enabled;
Map.Update(timing);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ public void UpdateValues()

valueFlow.Clear();
valueFlow.AddRange(CreateValueContent());
OnValueUpdate();
}

protected virtual void OnValueUpdate() { }

protected override bool OnHover(HoverEvent e)
{
samples.Hover();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using System;
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Graphics.UserInterface;
using fluXis.Game.Map.Structures;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osuTK;

namespace fluXis.Game.Screens.Edit.Tabs.Shared.Points.Settings;

public partial class PointSettingsIncrements : GridContainer
{
public PointSettingsIncrements(EditorMap map, TimingPoint point)
{
RelativeSizeAxes = Axes.X;
Height = 48;

ColumnDimensions = new Dimension[]
{
new(),
new(GridSizeMode.Absolute, 16),
new()
};

Content = new[]
{
new[]
{
new IncrementSection("Offset", v =>
{
point.Time += v;
map.Update(point);
}),
Empty(),
new IncrementSection("BPM", v =>
{
point.BPM = Math.Clamp(point.BPM + v, 1, 10000);
map.Update(point);
}),
}
};
}

private partial class IncrementSection : CompositeDrawable
{
private string text { get; }
private Action<int> change { get; }

public IncrementSection(string text, Action<int> change)
{
this.text = text;
this.change = change;
}

[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.Both;

InternalChildren = new Drawable[]
{
new IncrementButton(FontAwesome6.Solid.Minus, v => change(-v)),
new FluXisSpriteText
{
Text = text,
WebFontSize = 16,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
new IncrementButton(FontAwesome6.Solid.Plus, v => change(v))
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
},
};
}
}

private partial class IncrementButton : CompositeDrawable
{
private Action<int> action { get; }

private HoverLayer hover { get; }
private FlashLayer flash { get; }

private InputManager input;

public IncrementButton(IconUsage icon, Action<int> action)
{
this.action = action;

Width = 28;
RelativeSizeAxes = Axes.Y;
CornerRadius = 6;
Masking = true;

InternalChildren = new Drawable[]
{
hover = new HoverLayer(),
flash = new FlashLayer(),
new FluXisSpriteIcon
{
Icon = icon,
Size = new Vector2(14),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
};
}

protected override void LoadComplete()
{
input = GetContainingInputManager();
base.LoadComplete();
}

protected override bool OnHover(HoverEvent e)
{
hover.Show();
return true;
}

protected override void OnHoverLost(HoverLostEvent e)
{
hover.Hide();
}

protected override bool OnClick(ClickEvent e)
{
flash.Show();

var change = 1;
change *= input.CurrentState.Keyboard.ControlPressed ? 10 : 1;
change *= input.CurrentState.Keyboard.ShiftPressed ? 5 : 1;
action?.Invoke(change);

return true;
}
}
}

0 comments on commit aee4519

Please sign in to comment.