2022-04-18 17:58:14 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-04-18 17:58:14 +08:00
|
|
|
using System;
|
2022-05-08 03:20:00 +08:00
|
|
|
using System.Collections.Generic;
|
2022-04-19 15:37:38 +08:00
|
|
|
using System.Linq;
|
2022-04-18 17:58:14 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-04-19 15:37:38 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Bindables;
|
2022-04-18 17:58:14 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-04-19 15:37:38 +08:00
|
|
|
using osu.Framework.Graphics.Textures;
|
2022-04-18 17:58:14 +08:00
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Framework.Screens;
|
2022-04-19 15:37:38 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2022-04-18 17:58:14 +08:00
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Localisation;
|
|
|
|
using osu.Game.Overlays.Settings;
|
2022-04-19 15:37:38 +08:00
|
|
|
using osu.Game.Rulesets;
|
2022-05-08 03:20:00 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-04-18 17:58:14 +08:00
|
|
|
using osu.Game.Screens;
|
|
|
|
using osu.Game.Screens.Menu;
|
|
|
|
using osu.Game.Screens.Select;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.FirstRunSetup
|
|
|
|
{
|
2022-04-26 15:22:41 +08:00
|
|
|
[LocalisableDescription(typeof(GraphicsSettingsStrings), nameof(GraphicsSettingsStrings.UIScaling))]
|
2022-04-18 17:58:14 +08:00
|
|
|
public class ScreenUIScale : FirstRunSetupScreen
|
|
|
|
{
|
|
|
|
[BackgroundDependencyLoader]
|
2022-04-19 17:00:39 +08:00
|
|
|
private void load(OsuConfigManager config)
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
2022-05-10 16:44:23 +08:00
|
|
|
const float screen_width = 640;
|
|
|
|
|
2022-04-19 15:37:38 +08:00
|
|
|
Content.Children = new Drawable[]
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
2022-05-10 16:33:37 +08:00
|
|
|
new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: CONTENT_FONT_SIZE))
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
2022-04-19 15:37:38 +08:00
|
|
|
Text = FirstRunSetupOverlayStrings.UIScaleDescription,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
new SettingsSlider<float, UIScaleSlider>
|
|
|
|
{
|
|
|
|
LabelText = GraphicsSettingsStrings.UIScaling,
|
2022-04-19 17:00:39 +08:00
|
|
|
Current = config.GetBindable<float>(OsuSetting.UIScale),
|
2022-04-19 15:37:38 +08:00
|
|
|
KeyboardStep = 0.01f,
|
|
|
|
},
|
|
|
|
new InverseScalingDrawSizePreservingFillContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.None,
|
2022-05-10 16:44:23 +08:00
|
|
|
Size = new Vector2(screen_width, screen_width / 16f * 9 / 2),
|
2022-04-19 15:37:38 +08:00
|
|
|
Children = new Drawable[]
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
2022-04-19 15:37:38 +08:00
|
|
|
new GridContainer
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
2022-04-19 15:37:38 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Content = new[]
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
2022-04-19 15:37:38 +08:00
|
|
|
new Drawable[]
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
2022-04-19 15:37:38 +08:00
|
|
|
new SampleScreenContainer(new PinnedMainMenu()),
|
2022-04-24 17:15:35 +08:00
|
|
|
new SampleScreenContainer(new NestedSongSelect()),
|
2022-04-19 15:37:38 +08:00
|
|
|
},
|
|
|
|
// TODO: add more screens here in the future (gameplay / results)
|
|
|
|
// requires a bit more consideration to isolate their behaviour from the "parent" game.
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
2022-04-19 15:37:38 +08:00
|
|
|
}
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-19 15:37:38 +08:00
|
|
|
private class InverseScalingDrawSizePreservingFillContainer : ScalingContainer.ScalingDrawSizePreservingFillContainer
|
|
|
|
{
|
|
|
|
private Vector2 initialSize;
|
|
|
|
|
|
|
|
public InverseScalingDrawSizePreservingFillContainer()
|
|
|
|
: base(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
initialSize = Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
Size = initialSize / CurrentScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-24 17:15:35 +08:00
|
|
|
private class NestedSongSelect : PlaySongSelect
|
|
|
|
{
|
|
|
|
protected override bool ControlGlobalMusic => false;
|
2022-05-02 16:42:56 +08:00
|
|
|
|
|
|
|
public override bool? AllowTrackAdjustments => false;
|
2022-04-24 17:15:35 +08:00
|
|
|
}
|
|
|
|
|
2022-04-19 15:37:38 +08:00
|
|
|
private class PinnedMainMenu : MainMenu
|
|
|
|
{
|
2022-04-22 04:29:23 +08:00
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2022-04-19 15:37:38 +08:00
|
|
|
{
|
2022-04-22 04:29:23 +08:00
|
|
|
base.OnEntering(e);
|
2022-04-19 15:37:38 +08:00
|
|
|
|
|
|
|
Buttons.ReturnToTopOnIdle = false;
|
|
|
|
Buttons.State = ButtonSystemState.TopLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class UIScaleSlider : OsuSliderBar<float>
|
|
|
|
{
|
|
|
|
public override LocalisableString TooltipText => base.TooltipText + "x";
|
|
|
|
}
|
|
|
|
|
2022-04-18 17:58:14 +08:00
|
|
|
private class SampleScreenContainer : CompositeDrawable
|
|
|
|
{
|
2022-05-10 17:08:17 +08:00
|
|
|
private readonly OsuScreen screen;
|
2022-06-08 15:53:06 +08:00
|
|
|
|
2022-04-19 15:37:38 +08:00
|
|
|
// Minimal isolation from main game.
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
[Cached(typeof(IBindable<RulesetInfo>))]
|
|
|
|
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
[Cached(typeof(IBindable<WorkingBeatmap>))]
|
|
|
|
protected Bindable<WorkingBeatmap> Beatmap { get; private set; } = new Bindable<WorkingBeatmap>();
|
|
|
|
|
2022-05-08 03:20:00 +08:00
|
|
|
[Cached]
|
|
|
|
[Cached(typeof(IBindable<IReadOnlyList<Mod>>))]
|
|
|
|
protected Bindable<IReadOnlyList<Mod>> SelectedMods { get; private set; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
|
|
|
|
2022-04-18 17:58:14 +08:00
|
|
|
public override bool HandlePositionalInput => false;
|
|
|
|
public override bool HandleNonPositionalInput => false;
|
|
|
|
public override bool PropagatePositionalInputSubTree => false;
|
|
|
|
public override bool PropagateNonPositionalInputSubTree => false;
|
|
|
|
|
2022-05-10 17:08:17 +08:00
|
|
|
public SampleScreenContainer(OsuScreen screen)
|
|
|
|
{
|
|
|
|
this.screen = screen;
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2022-06-08 15:53:06 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
|
|
|
new DependencyContainer(new DependencyIsolationContainer(base.CreateChildDependencies(parent)));
|
|
|
|
|
2022-04-19 15:37:38 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(AudioManager audio, TextureStore textures, RulesetStore rulesets)
|
|
|
|
{
|
|
|
|
Beatmap.Value = new DummyWorkingBeatmap(audio, textures);
|
|
|
|
Beatmap.Value.LoadTrack();
|
|
|
|
|
|
|
|
Ruleset.Value = rulesets.AvailableRulesets.First();
|
|
|
|
|
2022-04-18 17:58:14 +08:00
|
|
|
OsuScreenStack stack;
|
|
|
|
OsuLogo logo;
|
|
|
|
|
2022-04-19 15:37:38 +08:00
|
|
|
Padding = new MarginPadding(5);
|
|
|
|
|
2022-04-18 17:58:14 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new DependencyProvidingContainer
|
|
|
|
{
|
|
|
|
CachedDependencies = new (Type, object)[]
|
|
|
|
{
|
|
|
|
(typeof(OsuLogo), logo = new OsuLogo
|
|
|
|
{
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
Position = new Vector2(0.5f),
|
|
|
|
})
|
|
|
|
},
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-04-19 15:37:38 +08:00
|
|
|
new ScalingContainer.ScalingDrawSizePreservingFillContainer(true)
|
2022-04-18 17:58:14 +08:00
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
stack = new OsuScreenStack(),
|
|
|
|
logo
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-05-10 17:08:17 +08:00
|
|
|
// intentionally load synchronously so it is included in the initial load of the first run screen.
|
|
|
|
stack.PushSynchronously(screen);
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-08 15:53:06 +08:00
|
|
|
|
|
|
|
private class DependencyIsolationContainer : IReadOnlyDependencyContainer
|
|
|
|
{
|
|
|
|
private readonly IReadOnlyDependencyContainer parentDependencies;
|
|
|
|
|
|
|
|
private readonly Type[] isolatedTypes =
|
|
|
|
{
|
|
|
|
typeof(OsuGame)
|
|
|
|
};
|
|
|
|
|
|
|
|
public DependencyIsolationContainer(IReadOnlyDependencyContainer parentDependencies)
|
|
|
|
{
|
|
|
|
this.parentDependencies = parentDependencies;
|
|
|
|
}
|
|
|
|
|
|
|
|
public object Get(Type type)
|
|
|
|
{
|
|
|
|
if (isolatedTypes.Contains(type))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return parentDependencies.Get(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public object Get(Type type, CacheInfo info)
|
|
|
|
{
|
|
|
|
if (isolatedTypes.Contains(type))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return parentDependencies.Get(type, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Inject<T>(T instance) where T : class
|
|
|
|
{
|
|
|
|
parentDependencies.Inject(instance);
|
|
|
|
}
|
|
|
|
}
|
2022-04-18 17:58:14 +08:00
|
|
|
}
|
|
|
|
}
|