2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-05-19 15:44:22 +08:00
|
|
|
|
using System;
|
2018-11-28 19:36:21 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
2021-07-23 04:43:35 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-02-22 16:14:13 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2020-05-24 12:44:11 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2021-11-25 15:36:30 +08:00
|
|
|
|
using osu.Game.Database;
|
2023-12-27 22:53:01 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-08-12 11:40:22 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2023-01-26 17:21:04 +08:00
|
|
|
|
using osu.Game.Overlays.SkinEditor;
|
2022-06-08 06:01:40 +08:00
|
|
|
|
using osu.Game.Screens.Select;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2022-01-26 16:48:11 +08:00
|
|
|
|
using Realms;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class SkinSection : SettingsSection
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-14 17:02:38 +08:00
|
|
|
|
private SkinSettingsDropdown skinDropdown;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-08-12 11:40:22 +08:00
|
|
|
|
public override LocalisableString Header => SkinSettingsStrings.SkinSectionHeader;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-04-26 02:35:46 +08:00
|
|
|
|
public override Drawable CreateIcon() => new SpriteIcon
|
|
|
|
|
{
|
2023-12-27 22:53:01 +08:00
|
|
|
|
Icon = OsuIcon.SkinB
|
2020-04-26 02:35:46 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-01-26 12:37:33 +08:00
|
|
|
|
private static readonly Live<SkinInfo> random_skin_info = new SkinInfo
|
2020-11-11 10:54:40 +08:00
|
|
|
|
{
|
|
|
|
|
ID = SkinInfo.RANDOM_SKIN,
|
|
|
|
|
Name = "<Random Skin>",
|
2021-12-14 13:21:23 +08:00
|
|
|
|
}.ToLiveUnmanaged();
|
2018-11-25 10:50:26 +08:00
|
|
|
|
|
2022-01-26 17:25:27 +08:00
|
|
|
|
private readonly List<Live<SkinInfo>> dropdownItems = new List<Live<SkinInfo>>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-14 21:14:00 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private SkinManager skins { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-11-29 15:18:34 +08:00
|
|
|
|
[Resolved]
|
2022-01-24 18:59:58 +08:00
|
|
|
|
private RealmAccess realm { get; set; }
|
2021-11-29 15:18:34 +08:00
|
|
|
|
|
|
|
|
|
private IDisposable realmSubscription;
|
2022-01-21 18:39:49 +08:00
|
|
|
|
|
2021-07-20 18:36:12 +08:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2022-09-12 18:51:49 +08:00
|
|
|
|
private void load([CanBeNull] SkinEditorOverlay skinEditor)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-10-12 13:42:22 +08:00
|
|
|
|
skinDropdown = new SkinSettingsDropdown
|
|
|
|
|
{
|
2023-12-06 03:53:24 +08:00
|
|
|
|
AlwaysShowSearchBar = true,
|
2023-12-06 03:53:35 +08:00
|
|
|
|
AllowNonContiguousMatching = true,
|
2022-07-07 17:26:04 +08:00
|
|
|
|
LabelText = SkinSettingsStrings.CurrentSkin,
|
2022-09-12 18:51:49 +08:00
|
|
|
|
Current = skins.CurrentSkinInfo,
|
2023-12-06 03:53:24 +08:00
|
|
|
|
Keywords = new[] { @"skins" },
|
2021-10-12 13:42:22 +08:00
|
|
|
|
},
|
2021-07-20 18:36:12 +08:00
|
|
|
|
new SettingsButton
|
|
|
|
|
{
|
2021-08-12 11:40:22 +08:00
|
|
|
|
Text = SkinSettingsStrings.SkinLayoutEditor,
|
2022-03-21 15:52:06 +08:00
|
|
|
|
Action = () => skinEditor?.ToggleVisibility(),
|
2021-07-20 18:36:12 +08:00
|
|
|
|
},
|
2020-05-24 22:15:24 +08:00
|
|
|
|
new ExportSkinButton(),
|
2022-06-08 06:01:40 +08:00
|
|
|
|
new DeleteSkinButton(),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
};
|
2021-11-29 17:04:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2018-11-25 10:50:26 +08:00
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
|
realmSubscription = realm.RegisterForNotifications(_ => realm.Realm.All<SkinInfo>()
|
2022-01-26 16:48:11 +08:00
|
|
|
|
.Where(s => !s.DeletePending)
|
2022-09-17 22:58:42 +08:00
|
|
|
|
.OrderBy(s => s.Name, StringComparer.OrdinalIgnoreCase), skinsChanged);
|
2018-07-02 15:49:07 +08:00
|
|
|
|
|
2022-09-12 18:51:49 +08:00
|
|
|
|
skinDropdown.Current.BindValueChanged(skin =>
|
2018-11-25 10:50:26 +08:00
|
|
|
|
{
|
2022-09-12 18:51:49 +08:00
|
|
|
|
if (skin.NewValue == random_skin_info)
|
2020-11-11 10:54:40 +08:00
|
|
|
|
{
|
2022-09-12 18:51:49 +08:00
|
|
|
|
// before selecting random, set the skin back to the previous selection.
|
|
|
|
|
// this is done because at this point it will be random_skin_info, and would
|
|
|
|
|
// cause SelectRandomSkin to be unable to skip the previous selection.
|
|
|
|
|
skins.CurrentSkinInfo.Value = skin.OldValue;
|
|
|
|
|
skins.SelectRandomSkin();
|
2022-01-26 16:48:11 +08:00
|
|
|
|
}
|
2022-09-12 18:51:49 +08:00
|
|
|
|
});
|
2022-01-26 16:48:11 +08:00
|
|
|
|
}
|
2021-11-29 15:18:34 +08:00
|
|
|
|
|
2023-07-06 12:37:42 +08:00
|
|
|
|
private void skinsChanged(IRealmCollection<SkinInfo> sender, ChangeSet changes)
|
2022-01-26 16:48:11 +08:00
|
|
|
|
{
|
|
|
|
|
// This can only mean that realm is recycling, else we would see the protected skins.
|
|
|
|
|
// Because we are using `Live<>` in this class, we don't need to worry about this scenario too much.
|
2022-01-26 17:25:27 +08:00
|
|
|
|
if (!sender.Any())
|
2022-01-26 16:48:11 +08:00
|
|
|
|
return;
|
2020-11-11 10:54:40 +08:00
|
|
|
|
|
2022-01-26 17:25:27 +08:00
|
|
|
|
// For simplicity repopulate the full list.
|
|
|
|
|
// In the future we should change this to properly handle ChangeSet events.
|
|
|
|
|
dropdownItems.Clear();
|
2022-09-17 22:58:42 +08:00
|
|
|
|
|
2022-09-15 15:02:57 +08:00
|
|
|
|
dropdownItems.Add(sender.Single(s => s.ID == SkinInfo.ARGON_SKIN).ToLive(realm));
|
2022-12-12 14:52:29 +08:00
|
|
|
|
dropdownItems.Add(sender.Single(s => s.ID == SkinInfo.ARGON_PRO_SKIN).ToLive(realm));
|
2022-09-17 23:14:49 +08:00
|
|
|
|
dropdownItems.Add(sender.Single(s => s.ID == SkinInfo.TRIANGLES_SKIN).ToLive(realm));
|
2022-09-17 22:58:42 +08:00
|
|
|
|
dropdownItems.Add(sender.Single(s => s.ID == SkinInfo.CLASSIC_SKIN).ToLive(realm));
|
|
|
|
|
|
|
|
|
|
dropdownItems.Add(random_skin_info);
|
|
|
|
|
|
|
|
|
|
foreach (var skin in sender.Where(s => !s.Protected))
|
2022-01-26 17:25:27 +08:00
|
|
|
|
dropdownItems.Add(skin.ToLive(realm));
|
2022-01-26 16:48:11 +08:00
|
|
|
|
|
2022-09-12 18:51:49 +08:00
|
|
|
|
Schedule(() => skinDropdown.Items = dropdownItems);
|
2021-01-29 18:16:10 +08:00
|
|
|
|
}
|
2021-01-15 15:34:28 +08:00
|
|
|
|
|
2021-11-05 17:05:31 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
2021-11-29 15:18:34 +08:00
|
|
|
|
realmSubscription?.Dispose();
|
2021-11-05 17:05:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class SkinSettingsDropdown : SettingsDropdown<Live<SkinInfo>>
|
2018-11-14 17:02:38 +08:00
|
|
|
|
{
|
2022-01-26 12:37:33 +08:00
|
|
|
|
protected override OsuDropdown<Live<SkinInfo>> CreateDropdown() => new SkinDropdownControl();
|
2018-11-14 17:02:38 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
private partial class SkinDropdownControl : DropdownControl
|
2018-11-14 17:02:38 +08:00
|
|
|
|
{
|
2022-01-26 12:37:33 +08:00
|
|
|
|
protected override LocalisableString GenerateItemText(Live<SkinInfo> item) => item.ToString();
|
2018-11-14 17:02:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-25 10:50:26 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class ExportSkinButton : SettingsButton
|
2020-05-24 22:15:24 +08:00
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private SkinManager skins { get; set; }
|
|
|
|
|
|
|
|
|
|
private Bindable<Skin> currentSkin;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-11-17 22:38:24 +08:00
|
|
|
|
private void load()
|
2020-05-24 22:15:24 +08:00
|
|
|
|
{
|
2021-08-12 11:40:22 +08:00
|
|
|
|
Text = SkinSettingsStrings.ExportSkinButton;
|
2020-05-24 22:15:24 +08:00
|
|
|
|
Action = export;
|
2021-11-29 15:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2020-05-24 22:15:24 +08:00
|
|
|
|
|
|
|
|
|
currentSkin = skins.CurrentSkin.GetBoundCopy();
|
2021-12-02 12:41:20 +08:00
|
|
|
|
currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.PerformRead(s => !s.Protected), true);
|
2020-05-24 22:15:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void export()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-04-09 21:15:00 +08:00
|
|
|
|
skins.ExportCurrentSkin();
|
2020-05-24 22:15:24 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log($"Could not export current skin: {e.Message}", level: LogLevel.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-08 06:01:40 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DeleteSkinButton : DangerousSettingsButton
|
2022-06-08 06:01:40 +08:00
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private SkinManager skins { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
|
private IDialogOverlay dialogOverlay { get; set; }
|
|
|
|
|
|
|
|
|
|
private Bindable<Skin> currentSkin;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
Text = SkinSettingsStrings.DeleteSkinButton;
|
|
|
|
|
Action = delete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
currentSkin = skins.CurrentSkin.GetBoundCopy();
|
|
|
|
|
currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.PerformRead(s => !s.Protected), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void delete()
|
|
|
|
|
{
|
2022-06-08 16:57:59 +08:00
|
|
|
|
dialogOverlay?.Push(new SkinDeleteDialog(currentSkin.Value));
|
2022-06-08 06:01:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|