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

371 lines
14 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.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
2018-04-13 17:19:50 +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;
2018-04-13 17:19:50 +08:00
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;
2018-04-13 17:19:50 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.Mods.Input;
using osu.Game.Rulesets.Scoring;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
using osu.Game.Skinning;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Configuration
{
[ExcludeFromDynamicCompile]
2018-04-13 17:19:50 +08:00
public class OsuConfigManager : IniConfigManager<OsuSetting>
{
protected override void InitialiseDefaults()
{
// UI/selection defaults
SetDefault(OsuSetting.Ruleset, string.Empty);
SetDefault(OsuSetting.Skin, SkinInfo.DEFAULT_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.ToolbarClockDisplayMode, ToolbarClockDisplayMode.Full);
2018-04-13 17:19:50 +08:00
// 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 =>
2018-04-13 17:19:50 +08:00
{
if (enabled.NewValue) SetValue(OsuSetting.SaveUsername, true);
2018-04-13 17:19:50 +08:00
};
SetDefault(OsuSetting.SaveUsername, true).ValueChanged += enabled =>
2018-04-13 17:19:50 +08:00
{
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
2018-04-13 17:19:50 +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.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.
SetDefault(OsuSetting.Prefer24HourTime, CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.Contains(@"tt"));
2018-04-13 17:19:50 +08:00
// Gameplay
SetDefault(OsuSetting.PositionalHitsounds, true); // replaced by level setting below, can be removed 20220703.
SetDefault(OsuSetting.PositionalHitsoundsLevel, 0.2f, 0, 1);
SetDefault(OsuSetting.DimLevel, 0.8, 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.ShowProgressGraph, true);
SetDefault(OsuSetting.ShowHealthDisplayWhenCantFail, true);
SetDefault(OsuSetting.FadePlayfieldWhenHealthLow, true);
SetDefault(OsuSetting.KeyOverlay, false);
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);
2018-04-13 17:19:50 +08:00
// 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);
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.EditorWaveformOpacity, 0.25f);
SetDefault(OsuSetting.LastProcessedMetadataId, -1);
2018-04-13 17:19:50 +08:00
}
public IDictionary<OsuSetting, string> GetLoggableState() =>
new Dictionary<OsuSetting, string>(ConfigStore.Where(kvp => !keyContainsPrivateInformation(kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToString()));
private static bool keyContainsPrivateInformation(OsuSetting argKey)
{
switch (argKey)
{
case OsuSetting.Token:
return true;
}
return false;
}
2019-01-04 13:18:29 +08:00
public OsuConfigManager(Storage storage)
: base(storage)
2018-04-13 17:19:50 +08:00
{
Migrate();
2018-04-13 17:19:50 +08:00
}
2018-05-02 18:37:47 +08:00
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;
int combined = (year * 10000) + monthDay;
if (combined < 20220103)
{
var positionalHitsoundsEnabled = GetBindable<bool>(OsuSetting.PositionalHitsounds);
if (!positionalHitsoundsEnabled.Value)
SetValue(OsuSetting.PositionalHitsoundsLevel, 0);
}
2018-04-13 17:19:50 +08:00
}
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
{
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";
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.
2018-04-13 17:19:50 +08:00
public enum OsuSetting
{
Ruleset,
Token,
MenuCursorSize,
GameplayCursorSize,
AutoCursorSize,
DimLevel,
BlurLevel,
LightenDuringBreaks,
2018-04-13 17:19:50 +08:00
ShowStoryboard,
KeyOverlay,
PositionalHitsounds,
PositionalHitsoundsLevel,
AlwaysPlayFirstComboBreak,
2018-04-13 17:19:50 +08:00
FloatingComments,
HUDVisibilityMode,
// This has been migrated to the component itself. can be removed 20221027.
ShowProgressGraph,
ShowHealthDisplayWhenCantFail,
FadePlayfieldWhenHealthLow,
2018-04-13 17:19:50 +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>
2018-04-13 17:19:50 +08:00
AudioOffset,
2018-04-13 17:19:50 +08:00
VolumeInactive,
MenuMusic,
MenuVoice,
CursorRotation,
MenuParallax,
Prefer24HourTime,
2018-04-13 17:19:50 +08:00
BeatmapDetailTab,
BeatmapDetailModsFilter,
2018-04-13 17:19:50 +08:00
Username,
ReleaseStream,
SavePassword,
SaveUsername,
DisplayStarsMinimum,
DisplayStarsMaximum,
SongSelectGroupingMode,
SongSelectSortingMode,
2018-04-13 17:19:50 +08:00
RandomSelectAlgorithm,
ModSelectHotkeyStyle,
2018-04-13 17:19:50 +08:00
ShowFpsDisplay,
ChatDisplayHeight,
BeatmapListingCardSize,
ToolbarClockDisplayMode,
2018-04-13 17:19:50 +08:00
Version,
ShowFirstRunSetup,
2018-04-13 17:19:50 +08:00
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,
DiscordRichPresence,
AutomaticallyDownloadWhenSpectating,
2021-01-17 21:40:24 +08:00
ShowOnlineExplicitContent,
LastProcessedMetadataId
2018-04-13 17:19:50 +08:00
}
}