Files
ClubPenguinClient/MareSynchronos/UI/PermissionWindowUI.cs
Loporrit d601b6fcd1 Merge tag '0.9.17' into mare-classic
* tag '0.9.17':
  add census popup on connection
  api update
  census update
  heave fewer redraws as main method for data application, minor fixes
  remove unnecessary exists check
  add visibility for loaded mods size for pair, use menu bar for settings, remove settings button
  fix staging issues
  add download throttling, change header of mare, fix reverting players when going offline/paused when not visible
  use name for glamourer revert
  fix startup breaking
  add inner exception stacktraces
  calc correct button size
  wording
  add permission popup ui
  fix getting identifier during zoning
  indent nonscaled
  remove unnecessary usings
  ui icon boogaloo
  fix cache dict wtf
  add normalized icons
  add owner/moderator/pinned user icons
  check tokentime more precisely in both directions
  more cleanup
  fix sorting and cleanup
  make local groups more usable for pause/resume
  fix outlined font
  rework creation of popout windows into factory and some refactoring in general
  make syncshell admin ui to standalone window
  remove close button on intro ui
  do not allow to open main ui without finishing setup
  readonly bla
  wait for plugin disposal
  fix palette
  wording
  fix palette application and add experimental less redraws option
  some minor fixes
  check for timezone
  idk
  adjust token handling
  fix total user count in syncshell (distinct by UIDs)
  fix text alignment
  fix some shit maybe
  idk some fixes I guess
  fix offset for transfer bar at the bottom, use async collections, clear filter on tab change + add button to clear, require ctrl for align syncshells
  blah
  Some display options for DTR tooltip (#66)
  add ordering
  adjust api to latest
  rework main ui
  add total count on mouseover, make syncshell windows non-blocking
  fix token for character change, add online count to syncshells and groups
  argh
  fix broken font in header
  add more options for the compactui
  fix icons and text of buttons being static in place
  remove logspam
2023-12-08 16:35:14 +00:00

163 lines
7.2 KiB
C#

using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
using MareSynchronos.API.Data.Enum;
using MareSynchronos.API.Data.Extensions;
using MareSynchronos.PlayerData.Pairs;
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<PermissionWindowUI> logger, Pair pair, MareMediator mediator, UiSharedService uiSharedService,
ApiController apiController) : base(logger, mediator, "Permissions for " + pair.UserData.AliasOrUID + "###MareSynchronosPermissions" + pair.UserData.UID)
{
Pair = pair;
_uiSharedService = uiSharedService;
_apiController = apiController;
_ownPermissions = pair.UserPair.OwnPermissions.DeepClone();
Flags = ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoResize;
SizeConstraints = new()
{
MinimumSize = new(450, 100),
MaximumSize = new(450, 500)
};
IsOpen = true;
}
public override void Draw()
{
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("Permissions for " + Pair.UserData.AliasOrUID);
ImGuiHelpers.ScaledDummy(1f);
if (ImGui.Checkbox("Pause Sync", ref paused))
{
_ownPermissions.SetPaused(paused);
}
UiSharedService.DrawHelpText("Pausing will completely cease any sync with this user." + UiSharedService.TooltipSeparator
+ "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();
ImGui.Text(Pair.UserData.AliasOrUID + " has " + (!otherIsPaused ? "not " : string.Empty) + "paused you");
}
ImGuiHelpers.ScaledDummy(0.5f);
ImGui.Separator();
ImGuiHelpers.ScaledDummy(0.5f);
if (ImGui.Checkbox("Disable Sounds", ref disableSounds))
{
_ownPermissions.SetDisableSounds(disableSounds);
}
UiSharedService.DrawHelpText("Disabling sounds will remove all sounds synced with this user on both sides." + UiSharedService.TooltipSeparator
+ "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();
ImGui.Text(Pair.UserData.AliasOrUID + " has " + (!otherDisableSounds ? "not " : string.Empty) + "disabled sound sync with you");
}
if (ImGui.Checkbox("Disable Animations", ref disableAnimations))
{
_ownPermissions.SetDisableAnimations(disableAnimations);
}
UiSharedService.DrawHelpText("Disabling sounds will remove all animations synced with this user on both sides." + UiSharedService.TooltipSeparator
+ "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();
ImGui.Text(Pair.UserData.AliasOrUID + " has " + (!otherDisableAnimations ? "not " : string.Empty) + "disabled animation sync with you");
}
if (ImGui.Checkbox("Disable VFX", ref disableVfx))
{
_ownPermissions.SetDisableVFX(disableVfx);
}
UiSharedService.DrawHelpText("Disabling sounds will remove all VFX synced with this user on both sides." + UiSharedService.TooltipSeparator
+ "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();
ImGui.Text(Pair.UserData.AliasOrUID + " has " + (!otherDisableVFX ? "not " : string.Empty) + "disabled VFX sync with you");
}
ImGuiHelpers.ScaledDummy(0.5f);
ImGui.Separator();
ImGuiHelpers.ScaledDummy(0.5f);
bool hasChanges = _ownPermissions != Pair.UserPair.OwnPermissions;
using (ImRaii.Disabled(!hasChanges))
if (UiSharedService.NormalizedIconTextButton(Dalamud.Interface.FontAwesomeIcon.Save, "Save"))
{
_ = _apiController.UserSetPairPermissions(new(Pair.UserData, _ownPermissions));
}
UiSharedService.AttachToolTip("Save and apply all changes");
var rightSideButtons = UiSharedService.GetNormalizedIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.Undo, "Revert").X +
UiSharedService.GetNormalizedIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, "Reset to Default").X;
var availableWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
ImGui.SameLine(availableWidth - rightSideButtons);
using (ImRaii.Disabled(!hasChanges))
if (UiSharedService.NormalizedIconTextButton(Dalamud.Interface.FontAwesomeIcon.Undo, "Revert"))
{
_ownPermissions = Pair.UserPair.OwnPermissions.DeepClone();
}
UiSharedService.AttachToolTip("Revert all changes");
ImGui.SameLine();
if (UiSharedService.NormalizedIconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, "Reset to Default"))
{
_ownPermissions.SetPaused(false);
_ownPermissions.SetDisableVFX(false);
_ownPermissions.SetDisableSounds(false);
_ownPermissions.SetDisableAnimations(false);
_ = _apiController.UserSetPairPermissions(new(Pair.UserData, _ownPermissions));
}
UiSharedService.AttachToolTip("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));
}
}