Pushed Imgui plate handler for lightfinder. need to redo options of it.
This commit is contained in:
@@ -19,12 +19,7 @@ using Microsoft.Extensions.Logging;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using LightlessSync.Services.Profiles;
|
||||
|
||||
namespace LightlessSync.UI;
|
||||
@@ -56,9 +51,9 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
"webp",
|
||||
"bmp"
|
||||
};
|
||||
private const string ImageFileDialogFilter = "Images{.png,.jpg,.jpeg,.webp,.bmp}";
|
||||
private const string _imageFileDialogFilter = "Images{.png,.jpg,.jpeg,.webp,.bmp}";
|
||||
private readonly List<int> _tagEditorSelection = new();
|
||||
private int[] _profileTagIds = Array.Empty<int>();
|
||||
private int[] _profileTagIds = [];
|
||||
private readonly List<SeStringUtils.SeStringSegment> _tagPreviewSegments = new();
|
||||
private enum ProfileEditorMode
|
||||
{
|
||||
@@ -77,8 +72,8 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
private byte[]? _queuedBannerImage;
|
||||
private readonly Vector4 _tagBackgroundColor = new(0.18f, 0.18f, 0.18f, 0.95f);
|
||||
private readonly Vector4 _tagBorderColor = new(0.35f, 0.35f, 0.35f, 0.4f);
|
||||
private const int MaxProfileTags = 12;
|
||||
private const int AvailableTagsPerPage = 6;
|
||||
private const int _maxProfileTags = 12;
|
||||
private const int _availableTagsPerPage = 6;
|
||||
private int _availableTagPage;
|
||||
private UserData? _selfProfileUserData;
|
||||
private string _descriptionText = string.Empty;
|
||||
@@ -92,10 +87,10 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
private bool _wasOpen;
|
||||
|
||||
private Vector4 _currentBg = new(0.15f, 0.15f, 0.15f, 1f);
|
||||
private bool textEnabled;
|
||||
private bool glowEnabled;
|
||||
private Vector4 textColor;
|
||||
private Vector4 glowColor;
|
||||
private bool _textEnabled;
|
||||
private bool _glowEnabled;
|
||||
private Vector4 _textColor;
|
||||
private Vector4 _glowColor;
|
||||
|
||||
private sealed record VanityState(bool TextEnabled, bool GlowEnabled, Vector4 TextColor, Vector4 GlowColor);
|
||||
private VanityState? _savedVanity;
|
||||
@@ -154,13 +149,13 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
|
||||
private void LoadVanity()
|
||||
{
|
||||
textEnabled = !string.IsNullOrEmpty(_apiController.TextColorHex);
|
||||
glowEnabled = !string.IsNullOrEmpty(_apiController.TextGlowColorHex);
|
||||
_textEnabled = !string.IsNullOrEmpty(_apiController.TextColorHex);
|
||||
_glowEnabled = !string.IsNullOrEmpty(_apiController.TextGlowColorHex);
|
||||
|
||||
textColor = textEnabled ? UIColors.HexToRgba(_apiController.TextColorHex!) : Vector4.One;
|
||||
glowColor = glowEnabled ? UIColors.HexToRgba(_apiController.TextGlowColorHex!) : Vector4.Zero;
|
||||
_textColor = _textEnabled ? UIColors.HexToRgba(_apiController.TextColorHex!) : Vector4.One;
|
||||
_glowColor = _glowEnabled ? UIColors.HexToRgba(_apiController.TextGlowColorHex!) : Vector4.Zero;
|
||||
|
||||
_savedVanity = new VanityState(textEnabled, glowEnabled, textColor, glowColor);
|
||||
_savedVanity = new VanityState(_textEnabled, _glowEnabled, _textColor, _glowColor);
|
||||
}
|
||||
|
||||
public override async void OnOpen()
|
||||
@@ -465,7 +460,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.FileUpload, "Upload new profile picture"))
|
||||
{
|
||||
var existingBanner = GetCurrentProfileBannerBase64(profile);
|
||||
_fileDialogManager.OpenFileDialog("Select new Profile picture", ImageFileDialogFilter, (success, file) =>
|
||||
_fileDialogManager.OpenFileDialog("Select new Profile picture", _imageFileDialogFilter, (success, file) =>
|
||||
{
|
||||
if (!success) return;
|
||||
_ = Task.Run(async () =>
|
||||
@@ -529,7 +524,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.FileUpload, "Upload new profile banner"))
|
||||
{
|
||||
var existingProfile = GetCurrentProfilePictureBase64(profile);
|
||||
_fileDialogManager.OpenFileDialog("Select new Profile banner", ImageFileDialogFilter, (success, file) =>
|
||||
_fileDialogManager.OpenFileDialog("Select new Profile banner", _imageFileDialogFilter, (success, file) =>
|
||||
{
|
||||
if (!success) return;
|
||||
_ = Task.Run(async () =>
|
||||
@@ -686,7 +681,7 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
var defaultTextColorU32 = ImGui.GetColorU32(ImGuiCol.Text);
|
||||
|
||||
var selectedCount = _tagEditorSelection.Count;
|
||||
ImGui.TextColored(UIColors.Get("LightlessBlue"), $"Selected Tags ({selectedCount}/{MaxProfileTags})");
|
||||
ImGui.TextColored(UIColors.Get("LightlessBlue"), $"Selected Tags ({selectedCount}/{_maxProfileTags})");
|
||||
|
||||
int? tagToRemove = null;
|
||||
int? moveUpRequest = null;
|
||||
@@ -766,9 +761,9 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
if (tagToRemove.HasValue)
|
||||
_tagEditorSelection.Remove(tagToRemove.Value);
|
||||
|
||||
bool limitReached = _tagEditorSelection.Count >= MaxProfileTags;
|
||||
bool limitReached = _tagEditorSelection.Count >= _maxProfileTags;
|
||||
if (limitReached)
|
||||
UiSharedService.ColorTextWrapped($"You have reached the maximum of {MaxProfileTags} tags. Remove one before adding more.", UIColors.Get("DimRed"));
|
||||
UiSharedService.ColorTextWrapped($"You have reached the maximum of {_maxProfileTags} tags. Remove one before adding more.", UIColors.Get("DimRed"));
|
||||
|
||||
ImGui.Dummy(new Vector2(0f, 6f * scale));
|
||||
ImGui.TextColored(UIColors.Get("LightlessPurple"), "Available Tags");
|
||||
@@ -798,10 +793,10 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
}
|
||||
else
|
||||
{
|
||||
int pageCount = Math.Max(1, (totalAvailable + AvailableTagsPerPage - 1) / AvailableTagsPerPage);
|
||||
int pageCount = Math.Max(1, (totalAvailable + _availableTagsPerPage - 1) / _availableTagsPerPage);
|
||||
_availableTagPage = Math.Clamp(_availableTagPage, 0, pageCount - 1);
|
||||
int start = _availableTagPage * AvailableTagsPerPage;
|
||||
int end = Math.Min(totalAvailable, start + AvailableTagsPerPage);
|
||||
int start = _availableTagPage * _availableTagsPerPage;
|
||||
int end = Math.Min(totalAvailable, start + _availableTagsPerPage);
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.TextDisabled($"Page {_availableTagPage + 1}/{pageCount}");
|
||||
@@ -1118,8 +1113,8 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
var monoFont = UiBuilder.MonoFont;
|
||||
using (ImRaii.PushFont(monoFont))
|
||||
{
|
||||
var previewTextColor = textEnabled ? textColor : Vector4.One;
|
||||
var previewGlowColor = glowEnabled ? glowColor : Vector4.Zero;
|
||||
var previewTextColor = _textEnabled ? _textColor : Vector4.One;
|
||||
var previewGlowColor = _glowEnabled ? _glowColor : Vector4.Zero;
|
||||
var seString = SeStringUtils.BuildFormattedPlayerName(_apiController.DisplayName, previewTextColor, previewGlowColor);
|
||||
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
@@ -1151,33 +1146,33 @@ public partial class EditProfileUi : WindowMediatorSubscriberBase
|
||||
if (!hasVanity)
|
||||
ImGui.BeginDisabled();
|
||||
|
||||
if (DrawCheckboxRow("Enable custom text color", textEnabled, out var newTextEnabled))
|
||||
textEnabled = newTextEnabled;
|
||||
if (DrawCheckboxRow("Enable custom text color", _textEnabled, out var newTextEnabled))
|
||||
_textEnabled = newTextEnabled;
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.BeginDisabled(!textEnabled);
|
||||
ImGui.ColorEdit4("Text Color##vanityTextColor", ref textColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.AlphaPreviewHalf);
|
||||
ImGui.BeginDisabled(!_textEnabled);
|
||||
ImGui.ColorEdit4("Text Color##vanityTextColor", ref _textColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.AlphaPreviewHalf);
|
||||
ImGui.EndDisabled();
|
||||
|
||||
if (DrawCheckboxRow("Enable glow color", glowEnabled, out var newGlowEnabled))
|
||||
glowEnabled = newGlowEnabled;
|
||||
if (DrawCheckboxRow("Enable glow color", _glowEnabled, out var newGlowEnabled))
|
||||
_glowEnabled = newGlowEnabled;
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.BeginDisabled(!glowEnabled);
|
||||
ImGui.ColorEdit4("Glow Color##vanityGlowColor", ref glowColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.AlphaPreviewHalf);
|
||||
ImGui.BeginDisabled(!_glowEnabled);
|
||||
ImGui.ColorEdit4("Glow Color##vanityGlowColor", ref _glowColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.AlphaPreviewHalf);
|
||||
ImGui.EndDisabled();
|
||||
|
||||
bool changed = !Equals(_savedVanity, new VanityState(textEnabled, glowEnabled, textColor, glowColor));
|
||||
bool changed = !Equals(_savedVanity, new VanityState(_textEnabled, _glowEnabled, _textColor, _glowColor));
|
||||
if (!changed)
|
||||
ImGui.BeginDisabled();
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Vanity Changes"))
|
||||
{
|
||||
string? newText = textEnabled ? UIColors.RgbaToHex(textColor) : string.Empty;
|
||||
string? newGlow = glowEnabled ? UIColors.RgbaToHex(glowColor) : string.Empty;
|
||||
string? newText = _textEnabled ? UIColors.RgbaToHex(_textColor) : string.Empty;
|
||||
string? newGlow = _glowEnabled ? UIColors.RgbaToHex(_glowColor) : string.Empty;
|
||||
|
||||
_ = _apiController.UserUpdateVanityColors(new UserVanityColorsDto(newText, newGlow));
|
||||
_savedVanity = new VanityState(textEnabled, glowEnabled, textColor, glowColor);
|
||||
_savedVanity = new VanityState(_textEnabled, _glowEnabled, _textColor, _glowColor);
|
||||
}
|
||||
|
||||
if (!changed)
|
||||
|
||||
Reference in New Issue
Block a user