more to notification system with new settings tab
This commit is contained in:
@@ -3,11 +3,13 @@ using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.LightlessConfiguration.Models;
|
||||
using LightlessSync.Services;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.UI.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using System.Numerics;
|
||||
using Dalamud.Bindings.ImGui;
|
||||
|
||||
@@ -17,18 +19,22 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
private readonly List<LightlessNotification> _notifications = new();
|
||||
private readonly object _notificationLock = new();
|
||||
private readonly LightlessConfigService _configService;
|
||||
|
||||
private const float NotificationWidth = 350f;
|
||||
private const float NotificationMinHeight = 60f;
|
||||
private const float NotificationMaxHeight = 200f;
|
||||
private const float NotificationSpacing = 8f;
|
||||
private const float AnimationSpeed = 10f;
|
||||
|
||||
private const float EdgeXMargin = 0;
|
||||
private const float EdgeYMargin = 30f;
|
||||
private const float SlideDistance = 100f;
|
||||
|
||||
public LightlessNotificationUI(ILogger<LightlessNotificationUI> logger, LightlessMediator mediator, PerformanceCollectorService performanceCollector)
|
||||
public LightlessNotificationUI(ILogger<LightlessNotificationUI> logger, LightlessMediator mediator, PerformanceCollectorService performanceCollector, LightlessConfigService configService)
|
||||
: base(logger, mediator, "Lightless Notifications##LightlessNotifications", performanceCollector)
|
||||
{
|
||||
_configService = configService;
|
||||
Flags = ImGuiWindowFlags.NoDecoration |
|
||||
ImGuiWindowFlags.NoMove |
|
||||
ImGuiWindowFlags.NoResize |
|
||||
@@ -141,6 +147,19 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
var deltaTime = ImGui.GetIO().DeltaTime;
|
||||
|
||||
var maxNotifications = _configService.Current.MaxSimultaneousNotifications;
|
||||
while (_notifications.Count(n => !n.IsAnimatingOut) > maxNotifications)
|
||||
{
|
||||
var oldestNotification = _notifications
|
||||
.Where(n => !n.IsAnimatingOut)
|
||||
.OrderBy(n => n.CreatedAt)
|
||||
.FirstOrDefault();
|
||||
if (oldestNotification != null)
|
||||
{
|
||||
oldestNotification.IsAnimatingOut = true;
|
||||
oldestNotification.IsAnimatingIn = false;
|
||||
}
|
||||
}
|
||||
for (int i = _notifications.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var notification = _notifications[i];
|
||||
@@ -174,9 +193,16 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
|
||||
private void DrawNotification(LightlessNotification notification, int index)
|
||||
{
|
||||
var alpha = notification.AnimationProgress;
|
||||
if (alpha <= 0f) return;
|
||||
|
||||
if (_configService.Current.EnableNotificationAnimations && alpha <= 0f)
|
||||
return;
|
||||
|
||||
var slideOffset = 0f;
|
||||
if (_configService.Current.EnableNotificationAnimations)
|
||||
{
|
||||
slideOffset = (1f - alpha) * SlideDistance;
|
||||
}
|
||||
|
||||
var slideOffset = (1f - alpha) * SlideDistance;
|
||||
var originalCursorPos = ImGui.GetCursorPos();
|
||||
ImGui.SetCursorPosX(originalCursorPos.X + slideOffset);
|
||||
|
||||
@@ -198,13 +224,18 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
|
||||
var windowPos = ImGui.GetWindowPos();
|
||||
var windowSize = ImGui.GetWindowSize();
|
||||
|
||||
var bgColor = new Vector4(30f/255f, 30f/255f, 30f/255f, 0.95f * alpha);
|
||||
var baseOpacity = _configService.Current.NotificationOpacity;
|
||||
var finalOpacity = _configService.Current.EnableNotificationAnimations ? baseOpacity * alpha : baseOpacity;
|
||||
var bgColor = new Vector4(30f/255f, 30f/255f, 30f/255f, finalOpacity);
|
||||
var accentColor = GetNotificationAccentColor(notification.Type);
|
||||
var progressBarColor = UIColors.Get("LightlessBlue");
|
||||
accentColor.W *= alpha;
|
||||
|
||||
var finalAccentAlpha = _configService.Current.EnableNotificationAnimations ? alpha : 1f;
|
||||
accentColor.W *= finalAccentAlpha;
|
||||
|
||||
var shadowOffset = new Vector2(1f, 1f);
|
||||
var shadowColor = new Vector4(0f, 0f, 0f, 0.4f * alpha);
|
||||
var shadowAlpha = _configService.Current.EnableNotificationAnimations ? 0.4f * alpha : 0.4f;
|
||||
var shadowColor = new Vector4(0f, 0f, 0f, shadowAlpha);
|
||||
drawList.AddRectFilled(
|
||||
windowPos + shadowOffset,
|
||||
windowPos + windowSize + shadowOffset,
|
||||
@@ -278,14 +309,31 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
|
||||
|
||||
ImGui.SetCursorPos(contentPos);
|
||||
|
||||
float titleHeight = 0f;
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, new Vector4(1f, 1f, 1f, alpha)))
|
||||
{
|
||||
ImGui.Text(notification.Title);
|
||||
// Set text wrap position to prevent title overflow
|
||||
ImGui.PushTextWrapPos(ImGui.GetCursorPosX() + contentSize.X);
|
||||
|
||||
var titleStartY = ImGui.GetCursorPosY();
|
||||
|
||||
if (_configService.Current.ShowNotificationTimestamp)
|
||||
{
|
||||
var timestamp = notification.CreatedAt.ToLocalTime().ToString("HH:mm:ss");
|
||||
ImGui.TextWrapped($"[{timestamp}] {notification.Title}");
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.TextWrapped(notification.Title);
|
||||
}
|
||||
|
||||
titleHeight = ImGui.GetCursorPosY() - titleStartY;
|
||||
ImGui.PopTextWrapPos();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(notification.Message))
|
||||
{
|
||||
ImGui.SetCursorPos(contentPos + new Vector2(0f, 18f));
|
||||
ImGui.SetCursorPos(contentPos + new Vector2(0f, titleHeight + 4f));
|
||||
ImGui.PushTextWrapPos(ImGui.GetCursorPosX() + contentSize.X);
|
||||
using (ImRaii.PushColor(ImGuiCol.Text, new Vector4(0.9f, 0.9f, 0.9f, alpha)))
|
||||
{
|
||||
@@ -436,24 +484,40 @@ public class LightlessNotificationUI : WindowMediatorSubscriberBase
|
||||
|
||||
private float CalculateNotificationHeight(LightlessNotification notification)
|
||||
{
|
||||
var height = 40f;
|
||||
if (!string.IsNullOrEmpty(notification.Message))
|
||||
var contentWidth = NotificationWidth - 35f; // Account for padding and accent bar
|
||||
var height = 20f; // Base height for padding
|
||||
|
||||
var titleText = notification.Title;
|
||||
if (_configService.Current.ShowNotificationTimestamp)
|
||||
{
|
||||
var textSize = ImGui.CalcTextSize(notification.Message, true, NotificationWidth - 35f);
|
||||
height += textSize.Y + 4f;
|
||||
var timestamp = notification.CreatedAt.ToLocalTime().ToString("HH:mm:ss");
|
||||
titleText = $"[{timestamp}] {titleText}";
|
||||
}
|
||||
|
||||
var titleSize = ImGui.CalcTextSize(titleText, true, contentWidth);
|
||||
height += titleSize.Y + 4f; // Title height + spacing
|
||||
|
||||
// Calculate message height
|
||||
if (!string.IsNullOrEmpty(notification.Message))
|
||||
{
|
||||
var messageSize = ImGui.CalcTextSize(notification.Message, true, contentWidth);
|
||||
height += messageSize.Y + 4f; // Message height + spacing
|
||||
}
|
||||
|
||||
// Add height for progress bar
|
||||
if (notification.ShowProgress)
|
||||
{
|
||||
height += 12f;
|
||||
}
|
||||
|
||||
// Add height for action buttons
|
||||
if (notification.Actions.Count > 0)
|
||||
{
|
||||
height += 28f;
|
||||
}
|
||||
|
||||
return Math.Max(height, NotificationMinHeight);
|
||||
// Allow notifications to grow taller but cap at maximum height
|
||||
return Math.Clamp(height, NotificationMinHeight, NotificationMaxHeight);
|
||||
}
|
||||
|
||||
private Vector4 GetNotificationAccentColor(NotificationType type)
|
||||
|
||||
Reference in New Issue
Block a user