Files
LightlessClient/LightlessSync/Services/UiService.cs
defnotken 72a62b7449
All checks were successful
Tag and Release Lightless / tag-and-release (push) Successful in 2m9s
2.1.0 (#123)
# Patchnotes 2.1.0
The changes in this update are more than just "patches". With a new UI, a new feature, and a bunch of bug fixes, improvements and a new member on the dev team, we thought this was more of a minor update.

We would like to introduce @tsubasahane of MareCN to the team! We’re happy to work with them to bring Lightless and its features to the CN client as well as having another talented dev bring features and ideas to us. Speaking of which:

# Location Sharing (Big shout out to @tsubasahane for bringing this feature)

- Are you TIRED of scrambling to find the address of the venue you're in to share with your friends? We are introducing Location Sharing! An optional feature where you can share your location with direct pairs temporarily [30 minutes, 1 hour, 3 hours] minutes or until you turn it off for them. That's up to you! [#125](<#125>)  [#49](<Lightless-Sync/LightlessServer#49>)
- To share your location with a pair, click the three dots beside the pair and choose a duration to share with them. [#125](<#125>)  [#49](<Lightless-Sync/LightlessServer#49>)
- To view the location of someone who's shared with you, simply hover over the globe icon! [#125](<#125>)  [#49](<Lightless-Sync/LightlessServer#49>)

[1]

# Model Optimization (Mesh Decimating)
 - This new option can automatically “simplify” incoming character meshes to help performance by reducing triangle counts. You choose how strong the reduction is (default/recommended is 80%). [#131](<#131>)
 - Decimation only kicks in when a mesh is above a certain triangle threshold, and only for the items that qualify for it and you selected for. [#131](<#131>)
 - Hair meshes is always excluded, since simplifying hair meshes is very prone to breaking.
 - You can find everything under Settings → Performance → Model Optimization. [#131](<#131>)
+ ** IF YOU HAVE USED DECIMATION IN TESTING, PLEASE CLEAR YOUR CACHE  **

[2]

# Animation (PAP) Validation (Safer animations)
 - Lightless now checks your currently animations to see if they work with your local skeleton/bone mod. If an animation matches, it’s included in what gets sent to other players. If it doesn’t, Lightless will skip it and write a warning to your log showing how many were skipped due to skeleton changes. Its defaulted to Unsafe (off). turn it on if you experience crashes from others users. [#131](<#131>)
 - Lightless also does the same kind of check for incoming animation files, to make sure they match the body/skeleton they were sent with. [#131](<#131>)
 - Because these checks can sometimes be a little picky, you can adjust how strict they are in Settings -> General -> Animation & Bones to reduce false positives. [#131](<#131>)

# UI Changes (Thanks to @kyuwu for UI Changes)
- The top part of the main screen has gotten a makeover. You can adjust the colors of the gradiant in the Color settings of Lightless. [#127](<#127>)

[3]

- Settings have gotten some changes as well to make this change more universal, and will use the same color settings. [#127](<#127>)
- The particle effects of the gradient are toggleable in 'Settings -> UI -> Behavior' [#127](<#127>)
- Instead of showing download/upload on bottom of Main UI, it will show VRAM usage and triangles with their optimization options next to it [#138](<#138>)

# LightFinder / ShellFinder
- UI Changes that follow our new design follow the color codes for the Gradient top as the main screen does.  [#127](<#127>)

[4]

Co-authored-by: defnotken <itsdefnotken@gmail.com>
Co-authored-by: azyges <aaaaaa@aaa.aaa>
Co-authored-by: cake <admin@cakeandbanana.nl>
Co-authored-by: Tsubasa <tsubasa@noreply.git.lightless-sync.org>
Co-authored-by: choco <choco@patat.nl>
Co-authored-by: celine <aaa@aaa.aaa>
Co-authored-by: celine <celine@noreply.git.lightless-sync.org>
Co-authored-by: Tsubasahane <wozaiha@gmail.com>
Co-authored-by: cake <cake@noreply.git.lightless-sync.org>
Reviewed-on: #123
2026-01-20 19:43:00 +00:00

299 lines
10 KiB
C#

using Dalamud.Interface;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Interface.Windowing;
using LightlessSync.LightlessConfiguration;
using LightlessSync.PlayerData.Factories;
using LightlessSync.Services.Mediator;
using LightlessSync.UI;
using LightlessSync.UI.Style;
using Microsoft.Extensions.Logging;
namespace LightlessSync.Services;
public sealed class UiService : DisposableMediatorSubscriberBase
{
private readonly List<WindowMediatorSubscriberBase> _createdWindows = [];
private readonly List<WindowMediatorSubscriberBase> _registeredWindows = [];
private readonly HashSet<WindowMediatorSubscriberBase> _uiHiddenWindows = [];
private readonly IUiBuilder _uiBuilder;
private readonly FileDialogManager _fileDialogManager;
private readonly ILogger<UiService> _logger;
private readonly LightlessConfigService _lightlessConfigService;
private readonly DalamudUtilService _dalamudUtilService;
private readonly WindowSystem _windowSystem;
private readonly UiFactory _uiFactory;
private readonly PairFactory _pairFactory;
private bool _uiHideActive;
public UiService(ILogger<UiService> logger, IUiBuilder uiBuilder,
LightlessConfigService lightlessConfigService, DalamudUtilService dalamudUtilService, WindowSystem windowSystem,
IEnumerable<WindowMediatorSubscriberBase> windows,
UiFactory uiFactory, FileDialogManager fileDialogManager,
LightlessMediator lightlessMediator, PairFactory pairFactory) : base(logger, lightlessMediator)
{
_logger = logger;
_logger.LogTrace("Creating {type}", GetType().Name);
_uiBuilder = uiBuilder;
_lightlessConfigService = lightlessConfigService;
_dalamudUtilService = dalamudUtilService;
_windowSystem = windowSystem;
_uiFactory = uiFactory;
_pairFactory = pairFactory;
_fileDialogManager = fileDialogManager;
_uiBuilder.DisableGposeUiHide = true;
_uiBuilder.Draw += Draw;
_uiBuilder.OpenConfigUi += ToggleUi;
_uiBuilder.OpenMainUi += ToggleMainUi;
foreach (var window in windows)
{
_registeredWindows.Add(window);
_windowSystem.AddWindow(window);
}
Mediator.Subscribe<ProfileOpenStandaloneMessage>(this, (msg) =>
{
var resolvedPair = _pairFactory.Create(msg.Pair.UniqueIdent) ?? msg.Pair;
if (!_createdWindows.Exists(p => p is StandaloneProfileUi ui
&& ui.Pair != null
&& ui.Pair.UniqueIdent == resolvedPair.UniqueIdent))
{
var window = _uiFactory.CreateStandaloneProfileUi(resolvedPair);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
Mediator.Subscribe<GroupProfileOpenStandaloneMessage>(this, msg =>
{
var existingWindow = _createdWindows.Find(p => p is StandaloneProfileUi ui
&& ui.IsGroupProfile
&& ui.ProfileGroupData is not null
&& string.Equals(ui.ProfileGroupData.GID, msg.Group.GID, StringComparison.Ordinal));
if (existingWindow is StandaloneProfileUi existing)
{
existing.IsOpen = true;
}
else
{
var window = _uiFactory.CreateStandaloneGroupProfileUi(msg.Group);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
Mediator.Subscribe<CloseGroupProfilePreviewMessage>(this, msg =>
{
var window = _createdWindows.Find(p => p is StandaloneProfileUi ui
&& ui.IsGroupProfile
&& ui.ProfileGroupData is not null
&& string.Equals(ui.ProfileGroupData.GID, msg.Group.Group.GID, StringComparison.Ordinal));
if (window is not null)
{
_windowSystem.RemoveWindow(window);
_createdWindows.Remove(window);
window.Dispose();
}
});
Mediator.Subscribe<OpenSelfProfilePreviewMessage>(this, msg =>
{
if (!_createdWindows.Exists(p => p is StandaloneProfileUi ui
&& ui.Pair is null
&& !ui.IsGroupProfile
&& !ui.IsLightfinderContext
&& string.Equals(ui.ProfileUserData.UID, msg.User.UID, StringComparison.Ordinal)))
{
var window = _uiFactory.CreateStandaloneProfileUi(msg.User);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
Mediator.Subscribe<CloseSelfProfilePreviewMessage>(this, msg =>
{
var window = _createdWindows.Find(p => p is StandaloneProfileUi ui
&& ui.Pair is null
&& !ui.IsGroupProfile
&& !ui.IsLightfinderContext
&& string.Equals(ui.ProfileUserData.UID, msg.User.UID, StringComparison.Ordinal));
if (window is not null)
{
_windowSystem.RemoveWindow(window);
_createdWindows.Remove(window);
window.Dispose();
}
});
Mediator.Subscribe<OpenLightfinderProfileMessage>(this, msg =>
{
if (!_createdWindows.Exists(p => p is StandaloneProfileUi ui && ui.IsLightfinderContext && string.Equals(ui.LightfinderCid, msg.HashedCid, StringComparison.Ordinal)))
{
var window = _uiFactory.CreateLightfinderProfileUi(msg.User, msg.HashedCid);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
Mediator.Subscribe<OpenUserProfileMessage>(this, msg =>
{
if (!_createdWindows.Exists(p => p is StandaloneProfileUi ui
&& !ui.IsLightfinderContext
&& !ui.IsGroupProfile
&& ui.Pair is null
&& ui.ProfileUserData is not null
&& string.Equals(ui.ProfileUserData.UID, msg.User.UID, StringComparison.Ordinal)))
{
var window = _uiFactory.CreateStandaloneProfileUi(msg.User);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
Mediator.Subscribe<OpenSyncshellAdminPanel>(this, (msg) =>
{
if (!_createdWindows.Exists(p => p is SyncshellAdminUI ui
&& string.Equals(ui.GroupFullInfo.GID, msg.GroupInfo.GID, StringComparison.Ordinal)))
{
var window = _uiFactory.CreateSyncshellAdminUi(msg.GroupInfo);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
Mediator.Subscribe<OpenPermissionWindow>(this, (msg) =>
{
var resolvedPair = _pairFactory.Create(msg.Pair.UniqueIdent) ?? msg.Pair;
if (!_createdWindows.Exists(p => p is PermissionWindowUI ui
&& ui.Pair is not null
&& ui.Pair.UniqueIdent == resolvedPair.UniqueIdent))
{
var window = _uiFactory.CreatePermissionPopupUi(resolvedPair);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
Mediator.Subscribe<RemoveWindowMessage>(this, (msg) =>
{
_windowSystem.RemoveWindow(msg.Window);
_createdWindows.Remove(msg.Window);
_registeredWindows.Remove(msg.Window);
_uiHiddenWindows.Remove(msg.Window);
msg.Window.Dispose();
});
}
public void ToggleMainUi()
{
if (_lightlessConfigService.Current.HasValidSetup())
Mediator.Publish(new UiToggleMessage(typeof(CompactUi)));
else
Mediator.Publish(new UiToggleMessage(typeof(IntroUi)));
}
public void ToggleUi()
{
if (_lightlessConfigService.Current.HasValidSetup())
Mediator.Publish(new UiToggleMessage(typeof(SettingsUi)));
else
Mediator.Publish(new UiToggleMessage(typeof(IntroUi)));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_logger.LogTrace("Disposing {type}", GetType().Name);
_windowSystem.RemoveAllWindows();
foreach (var window in _createdWindows)
{
window.Dispose();
}
_uiBuilder.Draw -= Draw;
_uiBuilder.OpenConfigUi -= ToggleUi;
_uiBuilder.OpenMainUi -= ToggleMainUi;
}
private void Draw()
{
MainStyle.PushStyle();
try
{
var hideOtherUi = ShouldHideOtherUi();
UpdateUiHideState(hideOtherUi);
_windowSystem.Draw();
if (!hideOtherUi)
_fileDialogManager.Draw();
}
finally
{
MainStyle.PopStyle();
}
}
private bool ShouldHideOtherUi()
{
var config = _lightlessConfigService.Current;
if (!config.ShowUiWhenUiHidden && _dalamudUtilService.IsGameUiHidden)
return true;
if (!config.ShowUiInGpose && _dalamudUtilService.IsInGpose)
return true;
return false;
}
private void UpdateUiHideState(bool hideOtherUi)
{
if (!hideOtherUi)
{
if (_uiHideActive)
{
foreach (var window in _uiHiddenWindows)
{
window.IsOpen = true;
}
_uiHiddenWindows.Clear();
_uiHideActive = false;
}
return;
}
_uiHideActive = true;
foreach (var window in EnumerateManagedWindows())
{
if (window is ZoneChatUi)
continue;
if (!window.IsOpen)
continue;
_uiHiddenWindows.Add(window);
window.IsOpen = false;
}
}
private IEnumerable<WindowMediatorSubscriberBase> EnumerateManagedWindows()
{
foreach (var window in _registeredWindows)
{
yield return window;
}
foreach (var window in _createdWindows)
{
yield return window;
}
}
}