1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 05:27:40 +08:00
osu-lazer/osu.Game/Screens/Edit/Setup/DesignSection.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
6.1 KiB
C#
Raw Normal View History

// 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.Globalization;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterfaceV2;
using osuTK;
namespace osu.Game.Screens.Edit.Setup
{
internal class DesignSection : SetupSection
{
2021-08-30 00:01:40 +08:00
protected LabelledSwitchButton EnableCountdown;
2021-09-01 04:40:58 +08:00
protected FillFlowContainer CountdownSettings;
2021-08-30 00:01:40 +08:00
protected LabelledEnumDropdown<CountdownType> CountdownSpeed;
protected LabelledNumberBox CountdownOffset;
private LabelledSwitchButton widescreenSupport;
private LabelledSwitchButton epilepsyWarning;
private LabelledSwitchButton letterboxDuringBreaks;
private LabelledSwitchButton samplesMatchPlaybackRate;
public override LocalisableString Title => "Design";
[BackgroundDependencyLoader]
private void load()
{
Children = new[]
{
2021-08-30 00:01:40 +08:00
EnableCountdown = new LabelledSwitchButton
{
Label = "Enable countdown",
Current = { Value = Beatmap.BeatmapInfo.Countdown != CountdownType.None },
Description = "If enabled, an \"Are you ready? 3, 2, 1, GO!\" countdown will be inserted at the beginning of the beatmap, assuming there is enough time to do so."
},
2021-09-01 04:40:58 +08:00
CountdownSettings = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(10),
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
2021-08-30 00:01:40 +08:00
CountdownSpeed = new LabelledEnumDropdown<CountdownType>
{
Label = "Countdown speed",
Current = { Value = Beatmap.BeatmapInfo.Countdown != CountdownType.None ? Beatmap.BeatmapInfo.Countdown : CountdownType.Normal },
Items = Enum.GetValues(typeof(CountdownType)).Cast<CountdownType>().Where(type => type != CountdownType.None)
},
2021-08-30 00:01:40 +08:00
CountdownOffset = new LabelledNumberBox
{
Label = "Countdown offset",
Current = { Value = Beatmap.BeatmapInfo.CountdownOffset.ToString() },
Description = "If the countdown sounds off-time, use this to make it appear one or more beats early.",
}
}
},
Empty(),
widescreenSupport = new LabelledSwitchButton
{
Label = "Widescreen support",
Description = "Allows storyboards to use the full screen space, rather than be confined to a 4:3 area.",
Current = { Value = Beatmap.BeatmapInfo.WidescreenStoryboard }
},
epilepsyWarning = new LabelledSwitchButton
{
Label = "Epilepsy warning",
Description = "Recommended if the storyboard or video contain scenes with rapidly flashing colours.",
Current = { Value = Beatmap.BeatmapInfo.EpilepsyWarning }
},
letterboxDuringBreaks = new LabelledSwitchButton
{
Label = "Letterbox during breaks",
Description = "Adds horizontal letterboxing to give a cinematic look during breaks.",
Current = { Value = Beatmap.BeatmapInfo.LetterboxInBreaks }
},
samplesMatchPlaybackRate = new LabelledSwitchButton
{
Label = "Samples match playback rate",
Description = "When enabled, all samples will speed up or slow down when rate-changing mods are enabled.",
Current = { Value = Beatmap.BeatmapInfo.SamplesMatchPlaybackRate }
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
2021-08-30 00:01:40 +08:00
EnableCountdown.Current.BindValueChanged(_ => updateCountdownSettingsVisibility(), true);
2021-08-30 00:01:40 +08:00
EnableCountdown.Current.BindValueChanged(_ => updateBeatmap());
CountdownSpeed.Current.BindValueChanged(_ => updateBeatmap());
CountdownOffset.OnCommit += (_, __) => onOffsetCommitted();
widescreenSupport.Current.BindValueChanged(_ => updateBeatmap());
epilepsyWarning.Current.BindValueChanged(_ => updateBeatmap());
letterboxDuringBreaks.Current.BindValueChanged(_ => updateBeatmap());
samplesMatchPlaybackRate.Current.BindValueChanged(_ => updateBeatmap());
}
2021-09-01 04:40:58 +08:00
private void updateCountdownSettingsVisibility() => CountdownSettings.FadeTo(EnableCountdown.Current.Value ? 1 : 0);
2021-08-30 00:01:40 +08:00
private void onOffsetCommitted()
{
updateBeatmap();
// update displayed text to ensure parsed value matches display (i.e. if empty string was provided).
CountdownOffset.Current.Value = Beatmap.BeatmapInfo.CountdownOffset.ToString(CultureInfo.InvariantCulture);
}
private void updateBeatmap()
{
2021-08-30 00:01:40 +08:00
Beatmap.BeatmapInfo.Countdown = EnableCountdown.Current.Value ? CountdownSpeed.Current.Value : CountdownType.None;
Beatmap.BeatmapInfo.CountdownOffset = int.TryParse(CountdownOffset.Current.Value, NumberStyles.None, CultureInfo.InvariantCulture, out int offset) ? offset : 0;
Beatmap.BeatmapInfo.WidescreenStoryboard = widescreenSupport.Current.Value;
Beatmap.BeatmapInfo.EpilepsyWarning = epilepsyWarning.Current.Value;
Beatmap.BeatmapInfo.LetterboxInBreaks = letterboxDuringBreaks.Current.Value;
Beatmap.BeatmapInfo.SamplesMatchPlaybackRate = samplesMatchPlaybackRate.Current.Value;
}
}
}