using Dalamud.Bindings.ImGui; using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using MareSynchronos.API.Data.Enum; using MareSynchronos.API.Data.Extensions; using MareSynchronos.PlayerData.Pairs; using MareSynchronos.Services; using MareSynchronos.Services.Mediator; using MareSynchronos.Utils; using MareSynchronos.WebAPI; using Microsoft.Extensions.Logging; namespace MareSynchronos.UI; public class PermissionWindowUI : WindowMediatorSubscriberBase { public Pair Pair { get; init; } private readonly UiSharedService _uiSharedService; private readonly ApiController _apiController; private UserPermissions _ownPermissions; public PermissionWindowUI(ILogger logger, Pair pair, MareMediator mediator, UiSharedService uiSharedService, ApiController apiController, PerformanceCollectorService performanceCollectorService) : base(logger, mediator, uiSharedService.Localize("PermissionWindow.Title", "Permissions for {0}", pair.UserData.AliasOrUID) + "###UmbraSyncPermissions" + pair.UserData.UID, performanceCollectorService) { Pair = pair; _uiSharedService = uiSharedService; _apiController = apiController; _ownPermissions = pair.UserPair?.OwnPermissions.DeepClone() ?? default; Flags = ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoResize; SizeConstraints = new() { MinimumSize = new(450, 100), MaximumSize = new(450, 500) }; IsOpen = true; } private string L(string key, string fallback, params object[] args) => _uiSharedService.Localize(key, fallback, args); protected override void DrawInternal() { var paused = _ownPermissions.IsPaused(); var disableSounds = _ownPermissions.IsDisableSounds(); var disableAnimations = _ownPermissions.IsDisableAnimations(); var disableVfx = _ownPermissions.IsDisableVFX(); var style = ImGui.GetStyle(); var indentSize = ImGui.GetFrameHeight() + style.ItemSpacing.X; _uiSharedService.BigText(L("PermissionWindow.Title", "Permissions for {0}", Pair.UserData.AliasOrUID)); ImGuiHelpers.ScaledDummy(1f); if (Pair.UserPair == null) return; if (ImGui.Checkbox(L("PermissionWindow.Pause.Label", "Pause Sync"), ref paused)) { _ownPermissions.SetPaused(paused); } _uiSharedService.DrawHelpText(L("PermissionWindow.Pause.HelpMain", "Pausing will completely cease any sync with this user.") + UiSharedService.TooltipSeparator + L("PermissionWindow.Pause.HelpNote", "Note: this is bidirectional, either user pausing will cease sync completely.")); var otherPerms = Pair.UserPair.OtherPermissions; var otherIsPaused = otherPerms.IsPaused(); var otherDisableSounds = otherPerms.IsDisableSounds(); var otherDisableAnimations = otherPerms.IsDisableAnimations(); var otherDisableVFX = otherPerms.IsDisableVFX(); using (ImRaii.PushIndent(indentSize, false)) { _uiSharedService.BooleanToColoredIcon(!otherIsPaused, false); ImGui.SameLine(); ImGui.AlignTextToFramePadding(); var pausedText = otherIsPaused ? L("PermissionWindow.OtherPaused.True", "{0} has paused you", Pair.UserData.AliasOrUID) : L("PermissionWindow.OtherPaused.False", "{0} has not paused you", Pair.UserData.AliasOrUID); ImGui.TextUnformatted(pausedText); } ImGuiHelpers.ScaledDummy(0.5f); ImGui.Separator(); ImGuiHelpers.ScaledDummy(0.5f); if (ImGui.Checkbox(L("PermissionWindow.Sounds.Label", "Disable Sounds"), ref disableSounds)) { _ownPermissions.SetDisableSounds(disableSounds); } _uiSharedService.DrawHelpText(L("PermissionWindow.Sounds.HelpMain", "Disabling sounds will remove all sounds synced with this user on both sides.") + UiSharedService.TooltipSeparator + L("PermissionWindow.Sounds.HelpNote", "Note: this is bidirectional, either user disabling sound sync will stop sound sync on both sides.")); using (ImRaii.PushIndent(indentSize, false)) { _uiSharedService.BooleanToColoredIcon(!otherDisableSounds, false); ImGui.SameLine(); ImGui.AlignTextToFramePadding(); var soundText = otherDisableSounds ? L("PermissionWindow.OtherSoundDisabled.True", "{0} has disabled sound sync with you", Pair.UserData.AliasOrUID) : L("PermissionWindow.OtherSoundDisabled.False", "{0} has not disabled sound sync with you", Pair.UserData.AliasOrUID); ImGui.TextUnformatted(soundText); } if (ImGui.Checkbox(L("PermissionWindow.Animations.Label", "Disable Animations"), ref disableAnimations)) { _ownPermissions.SetDisableAnimations(disableAnimations); } _uiSharedService.DrawHelpText(L("PermissionWindow.Animations.HelpMain", "Disabling sounds will remove all animations synced with this user on both sides.") + UiSharedService.TooltipSeparator + L("PermissionWindow.Animations.HelpNote", "Note: this is bidirectional, either user disabling animation sync will stop animation sync on both sides.")); using (ImRaii.PushIndent(indentSize, false)) { _uiSharedService.BooleanToColoredIcon(!otherDisableAnimations, false); ImGui.SameLine(); ImGui.AlignTextToFramePadding(); var animText = otherDisableAnimations ? L("PermissionWindow.OtherAnimationDisabled.True", "{0} has disabled animation sync with you", Pair.UserData.AliasOrUID) : L("PermissionWindow.OtherAnimationDisabled.False", "{0} has not disabled animation sync with you", Pair.UserData.AliasOrUID); ImGui.TextUnformatted(animText); } if (ImGui.Checkbox(L("PermissionWindow.Vfx.Label", "Disable VFX"), ref disableVfx)) { _ownPermissions.SetDisableVFX(disableVfx); } _uiSharedService.DrawHelpText(L("PermissionWindow.Vfx.HelpMain", "Disabling sounds will remove all VFX synced with this user on both sides.") + UiSharedService.TooltipSeparator + L("PermissionWindow.Vfx.HelpNote", "Note: this is bidirectional, either user disabling VFX sync will stop VFX sync on both sides.")); using (ImRaii.PushIndent(indentSize, false)) { _uiSharedService.BooleanToColoredIcon(!otherDisableVFX, false); ImGui.SameLine(); ImGui.AlignTextToFramePadding(); var vfxText = otherDisableVFX ? L("PermissionWindow.OtherVfxDisabled.True", "{0} has disabled VFX sync with you", Pair.UserData.AliasOrUID) : L("PermissionWindow.OtherVfxDisabled.False", "{0} has not disabled VFX sync with you", Pair.UserData.AliasOrUID); ImGui.TextUnformatted(vfxText); } ImGuiHelpers.ScaledDummy(0.5f); ImGui.Separator(); ImGuiHelpers.ScaledDummy(0.5f); bool hasChanges = _ownPermissions != Pair.UserPair.OwnPermissions; using (ImRaii.Disabled(!hasChanges)) if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Save, L("PermissionWindow.Button.Save", "Save"))) { _ = _apiController.UserSetPairPermissions(new(Pair.UserData, _ownPermissions)); } UiSharedService.AttachToolTip(L("PermissionWindow.Tooltip.Save", "Save and apply all changes")); var rightSideButtons = _uiSharedService.GetIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.Undo, L("PermissionWindow.Button.Revert", "Revert")) + _uiSharedService.GetIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, L("PermissionWindow.Button.Reset", "Reset to Default")); var availableWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X; ImGui.SameLine(availableWidth - rightSideButtons); using (ImRaii.Disabled(!hasChanges)) if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Undo, L("PermissionWindow.Button.Revert", "Revert"))) { _ownPermissions = Pair.UserPair.OwnPermissions.DeepClone(); } UiSharedService.AttachToolTip(L("PermissionWindow.Tooltip.Revert", "Revert all changes")); ImGui.SameLine(); if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, L("PermissionWindow.Button.Reset", "Reset to Default"))) { _ownPermissions.SetPaused(false); _ownPermissions.SetDisableVFX(false); _ownPermissions.SetDisableSounds(false); _ownPermissions.SetDisableAnimations(false); _ = _apiController.UserSetPairPermissions(new(Pair.UserData, _ownPermissions)); } UiSharedService.AttachToolTip(L("PermissionWindow.Tooltip.Reset", "This will set all permissions to their default setting")); var ySize = ImGui.GetCursorPosY() + style.FramePadding.Y * ImGuiHelpers.GlobalScale + style.FrameBorderSize; ImGui.SetWindowSize(new(400, ySize)); } public override void OnClose() { Mediator.Publish(new RemoveWindowMessage(this)); } }