1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 12:33:01 +08:00

Allow using ThemedDropdown even if OverlayColourProvider not available

This is to accommodate `SettingsDropdown` usages without an available
`OverlayColourProvider`, such as mod settings controls and tournament
client usages.
This commit is contained in:
Bartłomiej Dach 2021-10-12 23:09:41 +02:00
parent 7139c832b0
commit 7c5bd2db7b
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -1,6 +1,8 @@
// 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.
#nullable enable
using osu.Framework.Allocation;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
@ -9,13 +11,15 @@ using osu.Game.Overlays;
namespace osu.Game.Graphics.UserInterfaceV2
{
/// <summary>
/// A variant of <see cref="OsuDropdown{T}"/> that uses the nearest <see cref="OverlayColourProvider"/> for theming purposes.
/// A variant of <see cref="OsuDropdown{T}"/> that uses the nearest <see cref="OverlayColourProvider"/> for theming purposes, if one is available.
/// </summary>
public class ThemedDropdown<T> : OsuDropdown<T>
{
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider? colourProvider)
{
if (colourProvider == null) return;
AccentColour = colourProvider.Light4;
}
@ -25,9 +29,11 @@ namespace osu.Game.Graphics.UserInterfaceV2
protected class ThemedDropdownMenu : OsuDropdownMenu
{
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider? colourProvider)
{
if (colourProvider == null) return;
BackgroundColour = colourProvider.Background5;
((IHasAccentColour)ContentContainer).AccentColour = colourProvider.Highlight1;
}
@ -35,9 +41,11 @@ namespace osu.Game.Graphics.UserInterfaceV2
protected class ThemedDropdownHeader : OsuDropdownHeader
{
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider? colourProvider)
{
if (colourProvider == null) return;
BackgroundColour = colourProvider.Background5;
BackgroundColourHover = colourProvider.Light4;
}