Redone syncshell admin ui, fixed some bugs on edit profile.

This commit is contained in:
cake
2025-12-09 05:45:19 +01:00
parent 25f0d41581
commit 675918624d
12 changed files with 684 additions and 344 deletions

View File

@@ -43,7 +43,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
"<bold(1|0)> <italic(1|0)> <shadow(1|0)> <edge(1|0)> - toggle style flags.\n" +
"<link(0x0E,...)> - create clickable links.";
private static readonly HashSet<string> SupportedImageExtensions = new(StringComparer.OrdinalIgnoreCase)
private static readonly HashSet<string> _supportedImageExtensions = new(StringComparer.OrdinalIgnoreCase)
{
"png",
"jpg",
@@ -52,7 +52,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
"bmp"
};
private const string _imageFileDialogFilter = "Images{.png,.jpg,.jpeg,.webp,.bmp}";
private readonly List<int> _tagEditorSelection = new();
private readonly List<int> _tagEditorSelection = [];
private int[] _profileTagIds = [];
private readonly List<SeStringUtils.SeStringSegment> _tagPreviewSegments = new();
private enum ProfileEditorMode
@@ -68,6 +68,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
private bool _groupIsDisabled;
private bool _groupServerIsNsfw;
private bool _groupServerIsDisabled;
private bool _groupVisibilityInitialized;
private byte[]? _queuedProfileImage;
private byte[]? _queuedBannerImage;
private readonly Vector4 _tagBackgroundColor = new(0.18f, 0.18f, 0.18f, 0.95f);
@@ -85,6 +86,9 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
private bool _showProfileImageError = false;
private bool _showBannerImageError = false;
private bool _wasOpen;
private bool _userServerIsNsfw;
private bool _isNsfwInitialized;
private bool _isNsfw;
private Vector4 _currentBg = new(0.15f, 0.15f, 0.15f, 1f);
private bool _textEnabled;
@@ -171,6 +175,8 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
return;
}
_isNsfwInitialized = false;
var user = await EnsureSelfProfileUserDataAsync().ConfigureAwait(false);
if (user is not null)
{
@@ -339,13 +345,12 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
}
SyncProfileState(profile);
DrawSection("Profile Preview", scale, () => DrawProfileSnapshot(profile, scale));
DrawSection("Profile Image", scale, () => DrawProfileImageControls(profile, scale));
DrawSection("Profile Banner", scale, () => DrawProfileBannerControls(profile, scale));
DrawSection("Profile Description", scale, () => DrawProfileDescriptionEditor(profile, scale));
DrawSection("Profile Tags", scale, () => DrawProfileTagsEditor(profile, scale));
DrawSection("Visibility", scale, () => DrawProfileVisibilityControls(profile));
DrawSection("Visibility", scale, () => DrawProfileVisibilityControls());
}
private void DrawProfileSnapshot(LightlessUserProfileData profile, float scale)
@@ -877,21 +882,46 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
UiSharedService.AttachToolTip(saveTooltip);
}
private void DrawProfileVisibilityControls(LightlessUserProfileData profile)
private void DrawProfileVisibilityControls()
{
var isNsfw = profile.IsNSFW;
if (DrawCheckboxRow("Mark profile as NSFW", isNsfw, out var newValue, "Enable when your profile could be considered NSFW."))
if (!_isNsfwInitialized)
ImGui.BeginDisabled();
bool changed = DrawCheckboxRow("Mark profile as NSFW", _isNsfw, out var newValue, "Enable when your profile could be considered NSFW.");
if (changed)
_isNsfw = newValue;
bool visibilityChanged = _isNsfwInitialized && (_isNsfw != _userServerIsNsfw);
if (!_isNsfwInitialized)
ImGui.EndDisabled();
if (!_isNsfwInitialized || !visibilityChanged)
ImGui.BeginDisabled();
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Save, "Apply Visibility Changes"))
{
_userServerIsNsfw = _isNsfw;
_ = _apiController.UserSetProfile(new UserProfileDto(
new UserData(_apiController.UID),
Disabled: false,
newValue,
ProfilePictureBase64: GetCurrentProfilePictureBase64(profile),
IsNSFW: _isNsfw,
ProfilePictureBase64: null,
BannerPictureBase64: null,
Description: null,
BannerPictureBase64: GetCurrentProfileBannerBase64(profile),
Tags: GetServerTagPayload()));
Tags: null));
}
UiSharedService.AttachToolTip("Apply the visibility toggles above.");
if (!_isNsfwInitialized || !visibilityChanged)
ImGui.EndDisabled();
ImGui.SameLine();
if (_uiSharedService.IconTextButton(FontAwesomeIcon.SyncAlt, "Reset") && _isNsfwInitialized)
_isNsfw = _userServerIsNsfw;
}
private string? GetCurrentProfilePictureBase64(LightlessUserProfileData profile)
@@ -932,7 +962,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
foreach (var ext in format.FileExtensions)
{
if (SupportedImageExtensions.Contains(ext))
if (_supportedImageExtensions.Contains(ext))
return true;
}
@@ -1183,7 +1213,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
});
}
private void DrawSection(string title, float scale, Action body)
private static void DrawSection(string title, float scale, Action body)
{
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(6f, 4f) * scale);
@@ -1199,9 +1229,8 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
}
}
private bool DrawCheckboxRow(string label, bool currentValue, out bool newValue, string? tooltip = null)
private static bool DrawCheckboxRow(string label, bool currentValue, out bool newValue, string? tooltip = null)
{
bool value = currentValue;
bool changed = UiSharedService.CheckboxWithBorder(label, ref value, UIColors.Get("LightlessPurple"), 1.5f);
if (!string.IsNullOrEmpty(tooltip))
@@ -1214,7 +1243,17 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
private void SyncProfileState(LightlessUserProfileData profile)
{
if (string.Equals(profile.Description, LoadingProfileDescription, StringComparison.Ordinal))
{
_isNsfwInitialized = false;
return;
}
if (!_isNsfwInitialized)
{
_userServerIsNsfw = profile.IsNSFW;
_isNsfw = profile.IsNSFW;
_isNsfwInitialized = true;
}
var profileBytes = profile.ImageData.Value;
if (_pfpTextureWrap == null || !_profileImage.SequenceEqual(profileBytes))
@@ -1239,11 +1278,11 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
_descriptionText = _profileDescription;
}
var serverTags = profile.Tags ?? Array.Empty<int>();
var serverTags = profile.Tags ?? [];
if (!TagsEqual(serverTags, _profileTagIds))
{
var previous = _profileTagIds;
_profileTagIds = serverTags.Count == 0 ? Array.Empty<int>() : serverTags.ToArray();
_profileTagIds = serverTags.Count == 0 ? [] : [.. serverTags];
if (TagsEqual(_tagEditorSelection, previous))
{