1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 02:22:59 +08:00
osu-lazer/osu.Game/Configuration/OsuConfigManager.cs

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

388 lines
15 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-01-25 18:17:48 +08:00
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Diagnostics;
using osu.Framework.Bindables;
2016-08-26 11:28:23 +08:00
using osu.Framework.Configuration;
2018-05-02 18:37:47 +08:00
using osu.Framework.Configuration.Tracking;
2019-01-04 13:18:29 +08:00
using osu.Framework.Extensions;
2021-10-11 10:35:25 +08:00
using osu.Framework.Extensions.LocalisationExtensions;
2021-10-11 16:02:26 +08:00
using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps.Drawables.Cards;
using osu.Game.Input;
using osu.Game.Input.Bindings;
2021-10-11 10:35:25 +08:00
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods.Input;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
using osu.Game.Skinning;
2018-04-13 17:19:50 +08:00
2016-08-26 11:28:23 +08:00
namespace osu.Game.Configuration
{
[ExcludeFromDynamicCompile]
public class OsuConfigManager : IniConfigManager<OsuSetting>, IGameplaySettings
2016-08-26 11:28:23 +08:00
{
public OsuConfigManager(Storage storage)
: base(storage)
{
Migrate();
}
2016-08-26 11:28:23 +08:00
protected override void InitialiseDefaults()
{
// UI/selection defaults
SetDefault(OsuSetting.Ruleset, string.Empty);
SetDefault(OsuSetting.Skin, SkinInfo.ARGON_SKIN.ToString());
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.BeatmapDetailTab, PlayBeatmapDetailArea.TabType.Details);
SetDefault(OsuSetting.BeatmapDetailModsFilter, false);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.ShowConvertedBeatmaps, true);
SetDefault(OsuSetting.DisplayStarsMinimum, 0.0, 0, 10, 0.1);
SetDefault(OsuSetting.DisplayStarsMaximum, 10.1, 0, 10.1, 0.1);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.SongSelectGroupingMode, GroupMode.All);
SetDefault(OsuSetting.SongSelectSortingMode, SortMode.Title);
SetDefault(OsuSetting.RandomSelectAlgorithm, RandomSelectAlgorithm.RandomPermutation);
SetDefault(OsuSetting.ModSelectHotkeyStyle, ModSelectHotkeyStyle.Sequential);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2f, 1f);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.BeatmapListingCardSize, BeatmapCardSize.Normal);
SetDefault(OsuSetting.ProfileCoverExpanded, true);
SetDefault(OsuSetting.ToolbarClockDisplayMode, ToolbarClockDisplayMode.Full);
2023-01-25 15:28:38 +08:00
SetDefault(OsuSetting.SongSelectBackgroundBlur, true);
// Online settings
SetDefault(OsuSetting.Username, string.Empty);
SetDefault(OsuSetting.Token, string.Empty);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.AutomaticallyDownloadWhenSpectating, false);
SetDefault(OsuSetting.SavePassword, false).ValueChanged += enabled =>
{
if (enabled.NewValue) SetValue(OsuSetting.SaveUsername, true);
};
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.SaveUsername, true).ValueChanged += enabled =>
{
if (!enabled.NewValue) SetValue(OsuSetting.SavePassword, false);
};
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.ExternalLinkWarning, true);
SetDefault(OsuSetting.PreferNoVideo, false);
SetDefault(OsuSetting.ShowOnlineExplicitContent, false);
SetDefault(OsuSetting.NotifyOnUsernameMentioned, true);
SetDefault(OsuSetting.NotifyOnPrivateMessage, true);
2019-12-16 07:45:33 +08:00
// Audio
SetDefault(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.MenuVoice, true);
SetDefault(OsuSetting.MenuMusic, true);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.AudioOffset, 0, -500.0, 500.0, 1);
2018-04-13 17:19:50 +08:00
// Input
SetDefault(OsuSetting.MenuCursorSize, 1.0f, 0.5f, 2f, 0.01f);
SetDefault(OsuSetting.GameplayCursorSize, 1.0f, 0.1f, 2f, 0.01f);
SetDefault(OsuSetting.GameplayCursorDuringTouch, false);
SetDefault(OsuSetting.AutoCursorSize, false);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.MouseDisableButtons, false);
SetDefault(OsuSetting.MouseDisableWheel, false);
SetDefault(OsuSetting.ConfineMouseMode, OsuConfineMouseMode.DuringGameplay);
2018-04-13 17:19:50 +08:00
// Graphics
SetDefault(OsuSetting.ShowFpsDisplay, false);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.ShowStoryboard, true);
SetDefault(OsuSetting.BeatmapSkins, true);
SetDefault(OsuSetting.BeatmapColours, true);
SetDefault(OsuSetting.BeatmapHitsounds, true);
2018-04-25 15:15:23 +08:00
SetDefault(OsuSetting.CursorRotation, true);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.MenuParallax, true);
2018-04-13 17:19:50 +08:00
// See https://stackoverflow.com/a/63307411 for default sourcing.
2022-11-11 21:10:27 +08:00
SetDefault(OsuSetting.Prefer24HourTime, !CultureInfoHelper.SystemCulture.DateTimeFormat.ShortTimePattern.Contains(@"tt"));
// Gameplay
SetDefault(OsuSetting.PositionalHitsoundsLevel, 0.2f, 0, 1);
SetDefault(OsuSetting.DimLevel, 0.7, 0, 1, 0.01);
SetDefault(OsuSetting.BlurLevel, 0, 0, 1, 0.01);
SetDefault(OsuSetting.LightenDuringBreaks, true);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.HitLighting, true);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.HUDVisibilityMode, HUDVisibilityMode.Always);
SetDefault(OsuSetting.ShowHealthDisplayWhenCantFail, true);
SetDefault(OsuSetting.FadePlayfieldWhenHealthLow, true);
SetDefault(OsuSetting.KeyOverlay, false);
2022-09-26 20:07:43 +08:00
SetDefault(OsuSetting.GameplayLeaderboard, true);
SetDefault(OsuSetting.AlwaysPlayFirstComboBreak, true);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.FloatingComments, false);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.ScoreDisplayMode, ScoringMode.Standardised);
SetDefault(OsuSetting.IncreaseFirstObjectVisibility, true);
SetDefault(OsuSetting.GameplayDisableWinKey, true);
// Update
SetDefault(OsuSetting.ReleaseStream, ReleaseStream.Lazer);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.Version, string.Empty);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.ShowFirstRunSetup, true);
SetDefault(OsuSetting.ScreenshotFormat, ScreenshotFormat.Jpg);
SetDefault(OsuSetting.ScreenshotCaptureMenuCursor, false);
2018-04-13 17:19:50 +08:00
SetDefault(OsuSetting.SongSelectRightMouseScroll, false);
SetDefault(OsuSetting.Scaling, ScalingMode.Off);
SetDefault(OsuSetting.SafeAreaConsiderations, true);
2019-01-04 12:29:37 +08:00
SetDefault(OsuSetting.ScalingSizeX, 0.8f, 0.2f, 1f);
SetDefault(OsuSetting.ScalingSizeY, 0.8f, 0.2f, 1f);
2019-01-04 12:29:37 +08:00
SetDefault(OsuSetting.ScalingPositionX, 0.5f, 0f, 1f);
SetDefault(OsuSetting.ScalingPositionY, 0.5f, 0f, 1f);
2019-01-04 12:29:37 +08:00
SetDefault(OsuSetting.UIScale, 1f, 0.8f, 1.6f, 0.01f);
SetDefault(OsuSetting.UIHoldActivationDelay, 200.0, 0.0, 500.0, 50.0);
2019-08-09 19:05:28 +08:00
SetDefault(OsuSetting.IntroSequence, IntroSequence.Triangles);
SetDefault(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin);
SetDefault(OsuSetting.SeasonalBackgroundMode, SeasonalBackgroundMode.Sometimes);
2019-09-24 17:42:06 +08:00
SetDefault(OsuSetting.DiscordRichPresence, DiscordRichPresenceMode.Full);
SetDefault(OsuSetting.EditorDim, 0.25f, 0f, 0.75f, 0.25f);
SetDefault(OsuSetting.EditorWaveformOpacity, 0.25f, 0f, 1f, 0.25f);
SetDefault(OsuSetting.EditorShowHitMarkers, true);
SetDefault(OsuSetting.EditorAutoSeekOnPlacement, true);
SetDefault(OsuSetting.LastProcessedMetadataId, -1);
SetDefault(OsuSetting.ComboColourNormalisationAmount, 0.2f, 0f, 1f, 0.01f);
2017-01-28 18:10:05 +08:00
}
2018-04-13 17:19:50 +08:00
protected override bool CheckLookupContainsPrivateInformation(OsuSetting lookup)
{
switch (lookup)
{
case OsuSetting.Token:
return true;
}
return false;
}
public void Migrate()
2019-01-04 14:34:32 +08:00
{
// arrives as 2020.123.0
string rawVersion = Get<string>(OsuSetting.Version);
if (rawVersion.Length < 6)
return;
string[] pieces = rawVersion.Split('.');
// on a fresh install or when coming from a non-release build, execution will end here.
// we don't want to run migrations in such cases.
if (!int.TryParse(pieces[0], out int year)) return;
if (!int.TryParse(pieces[1], out int monthDay)) return;
// ReSharper disable once UnusedVariable
int combined = (year * 10000) + monthDay;
// migrations can be added here using a condition like:
// if (combined < 20220103) { performMigration() }
}
2018-05-02 18:37:47 +08:00
public override TrackedSettings CreateTrackedSettings()
2019-01-04 14:34:32 +08:00
{
// these need to be assigned in normal game startup scenarios.
Debug.Assert(LookupKeyBindings != null);
Debug.Assert(LookupSkinName != null);
return new TrackedSettings
{
2022-07-20 20:05:20 +08:00
new TrackedSetting<bool>(OsuSetting.ShowFpsDisplay, state => new SettingDescription(
rawValue: state,
name: GlobalActionKeyBindingStrings.ToggleFPSCounter,
value: state ? CommonStrings.Enabled.ToLower() : CommonStrings.Disabled.ToLower(),
shortcut: LookupKeyBindings(GlobalAction.ToggleFPSDisplay))
),
new TrackedSetting<bool>(OsuSetting.MouseDisableButtons, disabledState => new SettingDescription(
rawValue: !disabledState,
name: GlobalActionKeyBindingStrings.ToggleGameplayMouseButtons,
value: disabledState ? CommonStrings.Disabled.ToLower() : CommonStrings.Enabled.ToLower(),
shortcut: LookupKeyBindings(GlobalAction.ToggleGameplayMouseButtons))
),
2021-10-19 16:22:50 +08:00
new TrackedSetting<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode, visibilityMode => new SettingDescription(
rawValue: visibilityMode,
name: GameplaySettingsStrings.HUDVisibilityMode,
2021-10-19 16:22:50 +08:00
value: visibilityMode.GetLocalisableDescription(),
shortcut: new TranslatableString(@"_", @"{0}: {1} {2}: {3}",
GlobalActionKeyBindingStrings.ToggleInGameInterface,
LookupKeyBindings(GlobalAction.ToggleInGameInterface),
GlobalActionKeyBindingStrings.HoldForHUD,
LookupKeyBindings(GlobalAction.HoldForHUD)))
),
new TrackedSetting<ScalingMode>(OsuSetting.Scaling, scalingMode => new SettingDescription(
rawValue: scalingMode,
name: GraphicsSettingsStrings.ScreenScaling,
value: scalingMode.GetLocalisableDescription()
)
),
new TrackedSetting<string>(OsuSetting.Skin, skin =>
{
string skinName = string.Empty;
if (Guid.TryParse(skin, out var id))
skinName = LookupSkinName(id) ?? string.Empty;
return new SettingDescription(
rawValue: skinName,
name: SkinSettingsStrings.SkinSectionHeader,
value: skinName,
shortcut: new TranslatableString(@"_", @"{0}: {1}",
GlobalActionKeyBindingStrings.RandomSkin,
LookupKeyBindings(GlobalAction.RandomSkin))
);
2021-10-11 10:55:02 +08:00
}),
new TrackedSetting<float>(OsuSetting.UIScale, scale => new SettingDescription(
rawValue: scale,
name: GraphicsSettingsStrings.UIScaling,
value: $"{scale:N2}x"
// TODO: implement lookup for framework platform key bindings
)
),
};
}
public Func<Guid, string> LookupSkinName { private get; set; } = _ => @"unknown";
public Func<GlobalAction, LocalisableString> LookupKeyBindings { get; set; } = _ => @"unknown";
IBindable<float> IGameplaySettings.ComboColourNormalisationAmount => GetOriginalBindable<float>(OsuSetting.ComboColourNormalisationAmount);
IBindable<float> IGameplaySettings.PositionalHitsoundsLevel => GetOriginalBindable<float>(OsuSetting.PositionalHitsoundsLevel);
2016-08-26 11:28:23 +08:00
}
2018-04-13 17:19:50 +08:00
2021-08-16 15:59:59 +08:00
// IMPORTANT: These are used in user configuration files.
// The naming of these keys should not be changed once they are deployed in a release, unless migration logic is also added.
2017-05-15 09:56:27 +08:00
public enum OsuSetting
2016-08-26 11:28:23 +08:00
{
2017-04-15 04:22:41 +08:00
Ruleset,
2016-11-03 07:37:52 +08:00
Token,
2017-03-22 00:16:23 +08:00
MenuCursorSize,
GameplayCursorSize,
2017-05-13 08:46:37 +08:00
AutoCursorSize,
GameplayCursorDuringTouch,
2016-11-03 07:37:52 +08:00
DimLevel,
2017-12-26 09:11:49 +08:00
BlurLevel,
EditorDim,
LightenDuringBreaks,
2017-09-14 21:44:36 +08:00
ShowStoryboard,
2016-11-03 07:37:52 +08:00
KeyOverlay,
2022-09-26 20:07:43 +08:00
GameplayLeaderboard,
PositionalHitsoundsLevel,
AlwaysPlayFirstComboBreak,
2017-05-17 20:39:26 +08:00
FloatingComments,
HUDVisibilityMode,
ShowHealthDisplayWhenCantFail,
FadePlayfieldWhenHealthLow,
2016-11-03 07:37:52 +08:00
MouseDisableButtons,
MouseDisableWheel,
ConfineMouseMode,
/// <summary>
/// Globally applied audio offset.
/// This is added to the audio track's current time. Higher values will cause gameplay to occur earlier, relative to the audio track.
/// </summary>
AudioOffset,
VolumeInactive,
2016-11-03 07:37:52 +08:00
MenuMusic,
MenuVoice,
2017-09-17 06:47:55 +08:00
CursorRotation,
2016-11-03 07:37:52 +08:00
MenuParallax,
Prefer24HourTime,
BeatmapDetailTab,
BeatmapDetailModsFilter,
2016-11-03 07:37:52 +08:00
Username,
ReleaseStream,
SavePassword,
SaveUsername,
DisplayStarsMinimum,
DisplayStarsMaximum,
SongSelectGroupingMode,
SongSelectSortingMode,
2017-12-13 17:10:32 +08:00
RandomSelectAlgorithm,
ModSelectHotkeyStyle,
ShowFpsDisplay,
ChatDisplayHeight,
BeatmapListingCardSize,
ToolbarClockDisplayMode,
2023-01-25 15:28:38 +08:00
SongSelectBackgroundBlur,
Version,
ShowFirstRunSetup,
ShowConvertedBeatmaps,
Skin,
ScreenshotFormat,
ScreenshotCaptureMenuCursor,
2018-04-20 23:17:57 +08:00
SongSelectRightMouseScroll,
2018-04-25 15:15:23 +08:00
BeatmapSkins,
BeatmapColours,
BeatmapHitsounds,
IncreaseFirstObjectVisibility,
ScoreDisplayMode,
2019-01-04 12:29:37 +08:00
ExternalLinkWarning,
2020-04-11 19:08:16 +08:00
PreferNoVideo,
2019-01-04 12:29:37 +08:00
Scaling,
ScalingPositionX,
ScalingPositionY,
ScalingSizeX,
ScalingSizeY,
2019-08-09 19:05:28 +08:00
UIScale,
2019-12-16 07:45:33 +08:00
IntroSequence,
NotifyOnUsernameMentioned,
NotifyOnPrivateMessage,
UIHoldActivationDelay,
2019-09-24 17:42:06 +08:00
HitLighting,
MenuBackgroundSource,
2020-08-02 01:44:30 +08:00
GameplayDisableWinKey,
SeasonalBackgroundMode,
EditorWaveformOpacity,
EditorShowHitMarkers,
EditorAutoSeekOnPlacement,
DiscordRichPresence,
AutomaticallyDownloadWhenSpectating,
2021-01-17 21:40:24 +08:00
ShowOnlineExplicitContent,
LastProcessedMetadataId,
SafeAreaConsiderations,
ComboColourNormalisationAmount,
ProfileCoverExpanded,
2016-08-26 11:28:23 +08:00
}
}