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
1 changed files with 15 additions and 7 deletions

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable enable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -9,13 +11,15 @@
namespace osu.Game.Graphics.UserInterfaceV2 namespace osu.Game.Graphics.UserInterfaceV2
{ {
/// <summary> /// <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> /// </summary>
public class ThemedDropdown<T> : OsuDropdown<T> public class ThemedDropdown<T> : OsuDropdown<T>
{ {
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider? colourProvider)
{ {
if (colourProvider == null) return;
AccentColour = colourProvider.Light4; AccentColour = colourProvider.Light4;
} }
@ -25,9 +29,11 @@ private void load(OverlayColourProvider colourProvider)
protected class ThemedDropdownMenu : OsuDropdownMenu protected class ThemedDropdownMenu : OsuDropdownMenu
{ {
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider? colourProvider)
{ {
if (colourProvider == null) return;
BackgroundColour = colourProvider.Background5; BackgroundColour = colourProvider.Background5;
((IHasAccentColour)ContentContainer).AccentColour = colourProvider.Highlight1; ((IHasAccentColour)ContentContainer).AccentColour = colourProvider.Highlight1;
} }
@ -35,9 +41,11 @@ private void load(OverlayColourProvider colourProvider)
protected class ThemedDropdownHeader : OsuDropdownHeader protected class ThemedDropdownHeader : OsuDropdownHeader
{ {
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider? colourProvider)
{ {
if (colourProvider == null) return;
BackgroundColour = colourProvider.Background5; BackgroundColour = colourProvider.Background5;
BackgroundColourHover = colourProvider.Light4; BackgroundColourHover = colourProvider.Light4;
} }