2 Commits

Author SHA1 Message Date
f31d310135 small fixes (vibe-sleeping) 2025-08-22 04:17:25 +03:00
26029de27d Added customs wallpaper in a menu. 2025-08-22 03:10:55 +03:00
12 changed files with 230 additions and 61 deletions

View File

@@ -92,7 +92,7 @@ namespace osu.Game.Configuration
SetDefault(OsuSetting.ExternalLinkWarning, true);
SetDefault(OsuSetting.PreferNoVideo, false);
SetDefault(OsuSetting.BackgroundCategory, "Default");
SetDefault(OsuSetting.ShowOnlineExplicitContent, false);
SetDefault(OsuSetting.NotifyOnUsernameMentioned, true);
@@ -193,7 +193,7 @@ namespace osu.Game.Configuration
SetDefault(OsuSetting.IntroSequence, IntroSequence.Triangles);
SetDefault(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin);
SetDefault(OsuSetting.SeasonalBackgroundMode, SeasonalBackgroundMode.Sometimes);
SetDefault(OsuSetting.SeasonalBackgroundMode, SeasonalBackgroundMode.Never);
SetDefault(OsuSetting.DiscordRichPresence, DiscordRichPresenceMode.Full);
@@ -436,6 +436,7 @@ namespace osu.Game.Configuration
MenuBackgroundSource,
GameplayDisableWinKey,
SeasonalBackgroundMode,
BackgroundCategory,
EditorWaveformOpacity,
EditorShowHitMarkers,
EditorAutoSeekOnPlacement,

View File

@@ -14,12 +14,6 @@ namespace osu.Game.Configuration
[LocalisableDescription(typeof(UserInterfaceStrings), nameof(UserInterfaceStrings.AlwaysSeasonalBackground))]
Always,
/// <summary>
/// Seasonal backgrounds are shown only during their corresponding season.
/// </summary>
[LocalisableDescription(typeof(UserInterfaceStrings), nameof(UserInterfaceStrings.SometimesSeasonalBackground))]
Sometimes,
/// <summary>
/// Seasonal backgrounds are never shown.
/// </summary>

View File

@@ -4,6 +4,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@@ -19,79 +20,120 @@ namespace osu.Game.Graphics.Backgrounds
{
public partial class SeasonalBackgroundLoader : Component
{
public event Action<Exception> OnLoadFailure;
public event Action BackgroundChanged;
/// <summary>
/// Fired when background should be changed due to receiving backgrounds from API
/// or when the user setting is changed (as it might require unloading the seasonal background).
/// Fired when categories have been successfully refreshed from the server.
/// </summary>
public event Action SeasonalBackgroundChanged;
public event Action OnCategoriesRefreshed;
public readonly Bindable<IEnumerable<string>> AvailableCategories = new Bindable<IEnumerable<string>>(new List<string>());
[Resolved]
private IAPIProvider api { get; set; }
private Bindable<SeasonalBackgroundMode> seasonalBackgroundMode;
private Bindable<APISeasonalBackgrounds> seasonalBackgrounds;
private Bindable<SeasonalBackgroundMode> backgroundMode;
private Bindable<string> selectedCategory;
private Bindable<APISeasonalBackgrounds> currentBackgrounds;
private int current;
private int currentBackgroundIndex;
private bool shouldShowCustomBackgrounds => backgroundMode.Value != SeasonalBackgroundMode.Never;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, SessionStatics sessionStatics)
{
seasonalBackgroundMode = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
seasonalBackgroundMode.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke());
backgroundMode = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
backgroundMode.BindValueChanged(_ => BackgroundChanged?.Invoke());
seasonalBackgrounds = sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds);
seasonalBackgrounds.BindValueChanged(_ =>
{
if (shouldShowSeasonal)
SeasonalBackgroundChanged?.Invoke();
});
selectedCategory = config.GetBindable<string>(OsuSetting.BackgroundCategory);
selectedCategory.BindValueChanged(_ => fetchBackgroundsForSelectedCategory());
fetchSeasonalBackgrounds();
currentBackgrounds = sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds);
if (shouldShowCustomBackgrounds)
fetchCategories();
}
private void fetchSeasonalBackgrounds()
/// <summary>
/// Public method to trigger a refresh of categories from the UI.
/// </summary>
public void RefreshCategories()
{
if (seasonalBackgrounds.Value != null)
return;
fetchCategories();
}
private void fetchCategories()
{
if (!shouldShowCustomBackgrounds) return;
var request = new GetBackgroundCategoriesRequest();
var request = new GetSeasonalBackgroundsRequest();
request.Success += response =>
{
seasonalBackgrounds.Value = response;
current = RNG.Next(0, response.Backgrounds?.Count ?? 0);
var serverCategories = response.Categories ?? Enumerable.Empty<string>();
AvailableCategories.Value = new[] { "Default" }.Concat(serverCategories)
.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
if (!AvailableCategories.Value.Contains(selectedCategory.Value))
selectedCategory.Value = "Default";
else
fetchBackgroundsForSelectedCategory();
OnCategoriesRefreshed?.Invoke();
};
request.Failure += exception =>
{
AvailableCategories.Value = new[] { "Íå óäàëîñü çàãðóçèòü..." };
OnLoadFailure?.Invoke(exception);
};
api.PerformAsync(request);
}
public SeasonalBackground LoadNextBackground()
private void fetchBackgroundsForSelectedCategory()
{
if (!shouldShowSeasonal)
if (!shouldShowCustomBackgrounds) return;
if (AvailableCategories.Value.Count() == 1 && AvailableCategories.Value.First().Contains("Íå óäàëîñü"))
{
currentBackgrounds.Value = new APISeasonalBackgrounds { Backgrounds = new List<APISeasonalBackground>() };
BackgroundChanged?.Invoke();
return;
}
string categoryToFetch = selectedCategory.Value == "Default" ? null : selectedCategory.Value;
var request = new GetSeasonalBackgroundsRequest(categoryToFetch);
request.Success += response =>
{
currentBackgrounds.Value = response;
currentBackgroundIndex = RNG.Next(0, response.Backgrounds?.Count ?? 0);
BackgroundChanged?.Invoke();
};
request.Failure += exception =>
{
OnLoadFailure?.Invoke(exception);
};
api.PerformAsync(request);
}
public Background LoadNextBackground()
{
if (!shouldShowCustomBackgrounds || currentBackgrounds.Value?.Backgrounds?.Any() != true)
return null;
var backgrounds = seasonalBackgrounds.Value.Backgrounds;
current = (current + 1) % backgrounds.Count;
string url = backgrounds[current].Url;
var backgrounds = currentBackgrounds.Value.Backgrounds;
currentBackgroundIndex = (currentBackgroundIndex + 1) % backgrounds.Count;
string url = backgrounds[currentBackgroundIndex].Url;
return new SeasonalBackground(url);
}
private bool shouldShowSeasonal
{
get
{
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never)
return false;
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason)
return false;
return seasonalBackgrounds.Value?.Backgrounds?.Any() == true;
}
}
private bool isInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate;
}
[LongRunningLoad]

View File

@@ -69,6 +69,11 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString SeasonalBackgrounds => new TranslatableString(getKey(@"seasonal_backgrounds"), @"Seasonal backgrounds");
/*/// <summary>
/// "Seasonal backgrounds"
/// </summary>*/
/* public static LocalisableString SeasonalBackgroundsCategories => new TranslatableString(getKey(@"seasonal_backgrounds_categories"), @"Seasonal backgrounds categories");
*/
/// <summary>
/// "Changes to this setting will only apply with an active osu!supporter tag."
/// </summary>

View File

@@ -0,0 +1,12 @@
// 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.
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class GetBackgroundCategoriesRequest : APIRequest<APIBackgroundCategories>
{
protected override string Target => @"seasonal-backgrounds-categories";
}
}

View File

@@ -1,12 +1,33 @@
// 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 System.Net;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class GetSeasonalBackgroundsRequest : APIRequest<APISeasonalBackgrounds>
{
protected override string Target => @"seasonal-backgrounds";
private readonly string? category;
public GetSeasonalBackgroundsRequest()
{
}
public GetSeasonalBackgroundsRequest(string? category)
{
this.category = category;
}
protected override string Target => getPath();
private string getPath()
{
if (string.IsNullOrEmpty(category))
return @"seasonal-backgrounds";
return $@"seasonal-backgrounds?category={WebUtility.UrlEncode(category)}";
}
}
}

View File

@@ -0,0 +1,14 @@
// 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.
using System.Collections.Generic;
using Newtonsoft.Json;
namespace osu.Game.Online.API.Requests.Responses
{
public class APIBackgroundCategories
{
[JsonProperty("categories")]
public List<string>? Categories { get; set; }
}
}

View File

@@ -11,11 +11,11 @@ namespace osu.Game.Online
{
protected override string GetLookupUrl(string url)
{
/* if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || !uri.Host.EndsWith(@".ppy.sh", StringComparison.OrdinalIgnoreCase))
if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || !uri.Host.EndsWith(@".jvnko.boats", StringComparison.OrdinalIgnoreCase))
{
Logger.Log($@"Blocking resource lookup from external website: {url}", LoggingTarget.Network, LogLevel.Important);
return string.Empty;
}*/
}
return url;
}

View File

@@ -38,6 +38,7 @@ using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
@@ -169,6 +170,9 @@ namespace osu.Game
[Cached]
private readonly ScreenshotManager screenshotManager = new ScreenshotManager();
[Cached]
private readonly SeasonalBackgroundLoader backgroundLoader;
protected SentryLogger SentryLogger;
public virtual StableStorage GetStorageForStableInstall() => null;
@@ -249,6 +253,10 @@ namespace osu.Game
public OsuGame(string[] args = null)
{
backgroundLoader = new SeasonalBackgroundLoader();
backgroundLoader.OnLoadFailure += handleBackgroundLoadFailure;
backgroundLoader.OnCategoriesRefreshed += handleCategoriesRefreshed;
this.args = args;
Logger.NewEntry += forwardGeneralLogToNotifications;
@@ -401,6 +409,17 @@ namespace osu.Game
}
}
}
private void handleCategoriesRefreshed()
{
Schedule(() =>
{
Notifications?.Post(new SimpleNotification
{
Text = "Ñïèñîê êàòåãîðèé ôîíîâ îáíîâëåí.",
Icon = FontAwesome.Solid.CheckCircle
});
});
}
[BackgroundDependencyLoader]
private void load()
@@ -1232,6 +1251,8 @@ namespace osu.Game
loadComponentSingleFile(screenshotManager, Add);
loadComponentSingleFile(backgroundLoader, Add);
// dependency on notification overlay, dependent by settings overlay
loadComponentSingleFile(CreateUpdateManager(), Add, true);
@@ -1333,6 +1354,17 @@ namespace osu.Game
handleStartupImport();
}
private void handleBackgroundLoadFailure(Exception exception)
{
Schedule(() =>
{
Notifications?.Post(new SimpleNotification
{
Text = "Íå óäàëîñü çàãðóçèòü ôîíû. Ïðîâåðüòå ïîäêëþ÷åíèå ê èíòåðíåòó.",
Icon = FontAwesome.Solid.ExclamationTriangle
});
});
}
private void handleBackButton()
{
// TODO: this is SUPER SUPER bad.
@@ -1701,6 +1733,11 @@ namespace osu.Game
{
case IntroScreen intro:
introScreen = intro;
SimpleNotification notification = new SimpleNotification
{
Text = "Welcome to jvnkosu!lazer!",
};
Notifications?.Post(notification);
devBuildBanner?.Show();
break;

View File

@@ -8,9 +8,11 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Settings;
namespace osu.Game.Overlays.Settings.Sections.UserInterface
{
@@ -18,6 +20,9 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
{
protected override LocalisableString Header => UserInterfaceStrings.MainMenuHeader;
[Resolved]
private SeasonalBackgroundLoader backgroundLoader { get; set; }
private IBindable<APIUser> user;
private SettingsEnumDropdown<BackgroundSource> backgroundSourceDropdown;
@@ -27,6 +32,46 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
{
user = api.LocalUser.GetBoundCopy();
var backgroundModeBindable = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
var enabledProxyBindable = new Bindable<bool>();
backgroundModeBindable.BindValueChanged(mode => enabledProxyBindable.Value = mode.NewValue == SeasonalBackgroundMode.Always, true);
enabledProxyBindable.BindValueChanged(enabled => backgroundModeBindable.Value = enabled.NewValue ? SeasonalBackgroundMode.Always : SeasonalBackgroundMode.Never);
var backgroundToggle = new SettingsCheckbox
{
LabelText = "Пользовательские фоны",
Current = enabledProxyBindable
};
var categoryDropdown = new SettingsDropdown<string>
{
LabelText = "Категория фонов",
Current = config.GetBindable<string>(OsuSetting.BackgroundCategory)
};
var refreshButton = new SettingsButton
{
Text = "Обновить список категорий",
Action = () => backgroundLoader.RefreshCategories()
};
backgroundLoader.AvailableCategories.BindValueChanged(categories => categoryDropdown.Items = categories.NewValue, true);
backgroundModeBindable.BindValueChanged(mode =>
{
if (mode.NewValue == SeasonalBackgroundMode.Always)
{
categoryDropdown.Show();
refreshButton.Show();
}
else
{
categoryDropdown.Hide();
refreshButton.Hide();
}
}, true);
Children = new Drawable[]
{
new SettingsCheckbox
@@ -56,11 +101,9 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
LabelText = UserInterfaceStrings.BackgroundSource,
Current = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource),
},
new SettingsEnumDropdown<SeasonalBackgroundMode>
{
LabelText = UserInterfaceStrings.SeasonalBackgrounds,
Current = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode),
}
backgroundToggle,
categoryDropdown,
refreshButton,
};
}

View File

@@ -62,7 +62,7 @@ namespace osu.Game.Screens.Backgrounds
source.ValueChanged += _ => Scheduler.AddOnce(next);
beatmap.ValueChanged += _ => Scheduler.AddOnce(next);
introSequence.ValueChanged += _ => Scheduler.AddOnce(next);
seasonalBackgroundLoader.SeasonalBackgroundChanged += () => Scheduler.AddOnce(next);
seasonalBackgroundLoader.BackgroundChanged += () => Scheduler.AddOnce(next);
currentDisplay = RNG.Next(0, background_count);
Next();

View File

@@ -36,7 +36,7 @@ namespace osu.Game.Users.Drawables
if (user != null && user.OnlineID > 1)
// TODO: The fallback here should not need to exist. Users should be looked up and populated via UserLookupCache or otherwise
// in remaining cases where this is required (chat tabs, local leaderboard), at which point this should be removed.
Texture = textures.Get((user as APIUser)?.AvatarUrl ?? $@"https://a.ppy.sh/{user.OnlineID}");
Texture = textures.Get((user as APIUser)?.AvatarUrl ?? $@"https://osu.jvnko.boats/uploads-avatar/{user.OnlineID}");
Texture ??= textures.Get(@"Online/avatar-guest");
}