diff --git a/MareSynchronos/UI/CompactUI.cs b/MareSynchronos/UI/CompactUI.cs index 20fe7c2..002c0fa 100644 --- a/MareSynchronos/UI/CompactUI.cs +++ b/MareSynchronos/UI/CompactUI.cs @@ -188,7 +188,7 @@ public class CompactUi : WindowMediatorSubscriberBase { UiSharedService.TextWrapped($"You have successfully added {_lastAddedUser.UserData.AliasOrUID}. Set a local note for the user in the field below:"); ImGui.InputTextWithHint("##noteforuser", $"Note for {_lastAddedUser.UserData.AliasOrUID}", ref _lastAddedUserComment, 100); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Note")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Note")) { _serverManager.SetNoteForUid(_lastAddedUser.UserData.UID, _lastAddedUserComment); _lastAddedUser = null; @@ -217,7 +217,7 @@ public class CompactUi : WindowMediatorSubscriberBase if (keys.Any()) { if (_secretKeyIdx == -1) _secretKeyIdx = keys.First().Key; - if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Add current character with secret key")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Add current character with secret key")) { _serverManager.CurrentServer!.Authentications.Add(new MareConfiguration.Models.Authentication() { @@ -309,7 +309,7 @@ public class CompactUi : WindowMediatorSubscriberBase { using (ImRaii.PushColor(ImGuiCol.Text, color)) { - if (UiSharedService.IconButton(connectedIcon)) + if (_uiSharedService.IconButton(connectedIcon)) { _serverManager.CurrentServer.FullPause = !_serverManager.CurrentServer.FullPause; _serverManager.Save(); diff --git a/MareSynchronos/UI/Components/DrawFolderBase.cs b/MareSynchronos/UI/Components/DrawFolderBase.cs index ac4b71e..d685c47 100644 --- a/MareSynchronos/UI/Components/DrawFolderBase.cs +++ b/MareSynchronos/UI/Components/DrawFolderBase.cs @@ -108,7 +108,7 @@ public abstract class DrawFolderBase : IDrawFolder if (RenderMenu) { ImGui.SameLine(windowEndX - barButtonSize.X); - if (UiSharedService.IconButton(FontAwesomeIcon.EllipsisV)) + if (_uiSharedService.IconButton(FontAwesomeIcon.EllipsisV)) { ImGui.OpenPopup("User Flyout Menu"); } diff --git a/MareSynchronos/UI/Components/DrawFolderGroup.cs b/MareSynchronos/UI/Components/DrawFolderGroup.cs index 83341f1..621fb5b 100644 --- a/MareSynchronos/UI/Components/DrawFolderGroup.cs +++ b/MareSynchronos/UI/Components/DrawFolderGroup.cs @@ -85,21 +85,21 @@ public class DrawFolderGroup : DrawFolderBase ImGui.Separator(); ImGui.TextUnformatted("General Syncshell Actions"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Copy, "Copy ID", menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Copy, "Copy ID", menuWidth, true)) { ImGui.CloseCurrentPopup(); ImGui.SetClipboardText(_groupFullInfoDto.GroupAliasOrGID); } UiSharedService.AttachToolTip("Copy Syncshell ID to Clipboard"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Copy Notes", menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Copy Notes", menuWidth, true)) { ImGui.CloseCurrentPopup(); ImGui.SetClipboardText(UiSharedService.GetNotes(DrawPairs.Select(k => k.Pair).ToList())); } UiSharedService.AttachToolTip("Copies all your notes for all users in this Syncshell to the clipboard." + Environment.NewLine + "They can be imported via Settings -> Privacy -> Import Notes from Clipboard"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.ArrowCircleLeft, "Leave Syncshell", menuWidth, true) && UiSharedService.CtrlPressed()) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.ArrowCircleLeft, "Leave Syncshell", menuWidth, true) && UiSharedService.CtrlPressed()) { _ = _apiController.GroupLeave(_groupFullInfoDto); ImGui.CloseCurrentPopup(); @@ -117,7 +117,7 @@ public class DrawFolderGroup : DrawFolderBase if ((_groupFullInfoDto.GroupPermissions.IsPreferDisableAnimations() != disableAnims || _groupFullInfoDto.GroupPermissions.IsPreferDisableSounds() != disableSounds || _groupFullInfoDto.GroupPermissions.IsPreferDisableVFX() != disableVfx) - && UiSharedService.IconTextButton(FontAwesomeIcon.Check, "Align with suggested permissions", menuWidth, true)) + && _uiSharedService.IconTextButton(FontAwesomeIcon.Check, "Align with suggested permissions", menuWidth, true)) { perm.SetDisableVFX(_groupFullInfoDto.GroupPermissions.IsPreferDisableVFX()); perm.SetDisableSounds(_groupFullInfoDto.GroupPermissions.IsPreferDisableSounds()); @@ -126,21 +126,21 @@ public class DrawFolderGroup : DrawFolderBase ImGui.CloseCurrentPopup(); } - if (UiSharedService.IconTextButton(disableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeOff, disableSounds ? "Enable Sound Sync" : "Disable Sound Sync", menuWidth, true)) + if (_uiSharedService.IconTextButton(disableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeOff, disableSounds ? "Enable Sound Sync" : "Disable Sound Sync", menuWidth, true)) { perm.SetDisableSounds(!disableSounds); _ = _apiController.GroupChangeIndividualPermissionState(new(_groupFullInfoDto.Group, new(_apiController.UID), perm)); ImGui.CloseCurrentPopup(); } - if (UiSharedService.IconTextButton(disableAnims ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop, disableAnims ? "Enable Animation Sync" : "Disable Animation Sync", menuWidth, true)) + if (_uiSharedService.IconTextButton(disableAnims ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop, disableAnims ? "Enable Animation Sync" : "Disable Animation Sync", menuWidth, true)) { perm.SetDisableAnimations(!disableAnims); _ = _apiController.GroupChangeIndividualPermissionState(new(_groupFullInfoDto.Group, new(_apiController.UID), perm)); ImGui.CloseCurrentPopup(); } - if (UiSharedService.IconTextButton(disableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle, disableVfx ? "Enable VFX Sync" : "Disable VFX Sync", menuWidth, true)) + if (_uiSharedService.IconTextButton(disableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle, disableVfx ? "Enable VFX Sync" : "Disable VFX Sync", menuWidth, true)) { perm.SetDisableVFX(!disableVfx); _ = _apiController.GroupChangeIndividualPermissionState(new(_groupFullInfoDto.Group, new(_apiController.UID), perm)); @@ -151,7 +151,7 @@ public class DrawFolderGroup : DrawFolderBase { ImGui.Separator(); ImGui.TextUnformatted("Syncshell Admin Functions"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Cog, "Open Admin Panel", menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Cog, "Open Admin Panel", menuWidth, true)) { ImGui.CloseCurrentPopup(); _mareMediator.Publish(new OpenSyncshellAdminPanel(_groupFullInfoDto)); @@ -233,7 +233,7 @@ public class DrawFolderGroup : DrawFolderBase } ImGui.SameLine(); - if (UiSharedService.IconButton(pauseIcon)) + if (_uiSharedService.IconButton(pauseIcon)) { var perm = _groupFullInfoDto.GroupUserPermissions; perm.SetPaused(!perm.IsPaused()); diff --git a/MareSynchronos/UI/Components/DrawFolderTag.cs b/MareSynchronos/UI/Components/DrawFolderTag.cs index 3ed72dd..0a901a1 100644 --- a/MareSynchronos/UI/Components/DrawFolderTag.cs +++ b/MareSynchronos/UI/Components/DrawFolderTag.cs @@ -100,12 +100,12 @@ public class DrawFolderTag : DrawFolderBase protected override void DrawMenu(float menuWidth) { ImGui.TextUnformatted("Group Menu"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Users, "Select Pairs", menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Users, "Select Pairs", menuWidth, true)) { _selectPairForTagUi.Open(_id); } UiSharedService.AttachToolTip("Select Individual Pairs for this Pair Group"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Pair Group", menuWidth, true) && UiSharedService.CtrlPressed()) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Pair Group", menuWidth, true) && UiSharedService.CtrlPressed()) { _tagHandler.RemoveTag(_id); } @@ -141,7 +141,7 @@ public class DrawFolderTag : DrawFolderBase var buttonPauseOffset = currentRightSideX - pauseButtonX; ImGui.SameLine(buttonPauseOffset); - if (UiSharedService.IconButton(pauseButton)) + if (_uiSharedService.IconButton(pauseButton)) { if (allArePaused) { diff --git a/MareSynchronos/UI/Components/DrawUserPair.cs b/MareSynchronos/UI/Components/DrawUserPair.cs index 0f7acd5..e8b0078 100644 --- a/MareSynchronos/UI/Components/DrawUserPair.cs +++ b/MareSynchronos/UI/Components/DrawUserPair.cs @@ -71,7 +71,7 @@ public class DrawUserPair { if (!_pair.IsPaused) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.User, "Open Profile", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.User, "Open Profile", _menuWidth, true)) { _displayHandler.OpenProfile(_pair); ImGui.CloseCurrentPopup(); @@ -80,7 +80,7 @@ public class DrawUserPair } if (_pair.IsVisible) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Sync, "Reload last data", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Sync, "Reload last data", _menuWidth, true)) { _pair.ApplyLastReceivedData(forced: true); ImGui.CloseCurrentPopup(); @@ -88,7 +88,7 @@ public class DrawUserPair UiSharedService.AttachToolTip("This reapplies the last received character data to this character"); } - if (UiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Cycle pause state", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Cycle pause state", _menuWidth, true)) { _ = _apiController.CyclePause(_pair.UserData); ImGui.CloseCurrentPopup(); @@ -96,7 +96,7 @@ public class DrawUserPair ImGui.Separator(); ImGui.TextUnformatted("Pair Permission Functions"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.WindowMaximize, "Open Permissions Window", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.WindowMaximize, "Open Permissions Window", _menuWidth, true)) { _mediator.Publish(new OpenPermissionWindow(_pair)); ImGui.CloseCurrentPopup(); @@ -106,7 +106,7 @@ public class DrawUserPair var isSticky = _pair.UserPair!.OwnPermissions.IsSticky(); string stickyText = isSticky ? "Disable Preferred Permissions" : "Enable Preferred Permissions"; var stickyIcon = isSticky ? FontAwesomeIcon.ArrowCircleDown : FontAwesomeIcon.ArrowCircleUp; - if (UiSharedService.IconTextButton(stickyIcon, stickyText, _menuWidth, true)) + if (_uiSharedService.IconTextButton(stickyIcon, stickyText, _menuWidth, true)) { var permissions = _pair.UserPair.OwnPermissions; permissions.SetSticky(!isSticky); @@ -122,7 +122,7 @@ public class DrawUserPair var isDisableSounds = _pair.UserPair!.OwnPermissions.IsDisableSounds(); string disableSoundsText = isDisableSounds ? "Enable sound sync" : "Disable sound sync"; var disableSoundsIcon = isDisableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeMute; - if (UiSharedService.IconTextButton(disableSoundsIcon, disableSoundsText, _menuWidth, true)) + if (_uiSharedService.IconTextButton(disableSoundsIcon, disableSoundsText, _menuWidth, true)) { var permissions = _pair.UserPair.OwnPermissions; permissions.SetDisableSounds(!isDisableSounds); @@ -133,7 +133,7 @@ public class DrawUserPair var isDisableAnims = _pair.UserPair!.OwnPermissions.IsDisableAnimations(); string disableAnimsText = isDisableAnims ? "Enable animation sync" : "Disable animation sync"; var disableAnimsIcon = isDisableAnims ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop; - if (UiSharedService.IconTextButton(disableAnimsIcon, disableAnimsText, _menuWidth, true)) + if (_uiSharedService.IconTextButton(disableAnimsIcon, disableAnimsText, _menuWidth, true)) { var permissions = _pair.UserPair.OwnPermissions; permissions.SetDisableAnimations(!isDisableAnims); @@ -144,7 +144,7 @@ public class DrawUserPair var isDisableVFX = _pair.UserPair!.OwnPermissions.IsDisableVFX(); string disableVFXText = isDisableVFX ? "Enable VFX sync" : "Disable VFX sync"; var disableVFXIcon = isDisableVFX ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle; - if (UiSharedService.IconTextButton(disableVFXIcon, disableVFXText, _menuWidth, true)) + if (_uiSharedService.IconTextButton(disableVFXIcon, disableVFXText, _menuWidth, true)) { var permissions = _pair.UserPair.OwnPermissions; permissions.SetDisableVFX(!isDisableVFX); @@ -156,7 +156,7 @@ public class DrawUserPair { ImGui.Separator(); ImGui.TextUnformatted("Pair reporting"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.ExclamationTriangle, "Report Mare Profile", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.ExclamationTriangle, "Report Mare Profile", _menuWidth, true)) { ImGui.CloseCurrentPopup(); _mediator.Publish(new OpenReportPopupMessage(_pair)); @@ -172,12 +172,12 @@ public class DrawUserPair if (_pair.IndividualPairStatus != API.Data.Enum.IndividualPairStatus.None) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Folder, "Pair Groups", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Folder, "Pair Groups", _menuWidth, true)) { _selectTagForPairUi.Open(_pair); } UiSharedService.AttachToolTip("Choose pair groups for " + entryUID); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Unpair Permanently", _menuWidth, true) && UiSharedService.CtrlPressed()) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Unpair Permanently", _menuWidth, true) && UiSharedService.CtrlPressed()) { _ = _apiController.UserRemovePair(new(_pair.UserData)); } @@ -185,7 +185,7 @@ public class DrawUserPair } else { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Pair individually", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Pair individually", _menuWidth, true)) { _ = _apiController.UserAddPair(new(_pair.UserData)); } @@ -309,14 +309,14 @@ public class DrawUserPair ImGui.SameLine(currentRightSide); ImGui.AlignTextToFramePadding(); - if (UiSharedService.IconButton(FontAwesomeIcon.EllipsisV)) + if (_uiSharedService.IconButton(FontAwesomeIcon.EllipsisV)) { ImGui.OpenPopup("User Flyout Menu"); } currentRightSide -= (pauseIconSize.X + spacingX); ImGui.SameLine(currentRightSide); - if (UiSharedService.IconButton(pauseIcon)) + if (_uiSharedService.IconButton(pauseIcon)) { var perm = _pair.UserPair!.OwnPermissions; perm.SetPaused(!perm.IsPaused()); @@ -475,7 +475,7 @@ public class DrawUserPair { ImGui.TextUnformatted("Syncshell Moderator Functions"); var pinText = userIsPinned ? "Unpin user" : "Pin user"; - if (UiSharedService.IconTextButton(FontAwesomeIcon.Thumbtack, pinText, _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Thumbtack, pinText, _menuWidth, true)) { ImGui.CloseCurrentPopup(); if (!group.GroupPairUserInfos.TryGetValue(_pair.UserData.UID, out var userinfo)) @@ -490,14 +490,14 @@ public class DrawUserPair } UiSharedService.AttachToolTip("Pin this user to the Syncshell. Pinned users will not be deleted in case of a manually initiated Syncshell clean"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Remove user", _menuWidth, true) && UiSharedService.CtrlPressed()) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Remove user", _menuWidth, true) && UiSharedService.CtrlPressed()) { ImGui.CloseCurrentPopup(); _ = _apiController.GroupRemoveUser(new(group.Group, _pair.UserData)); } UiSharedService.AttachToolTip("Hold CTRL and click to remove user " + (_pair.UserData.AliasOrUID) + " from Syncshell"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.UserSlash, "Ban User", _menuWidth, true)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.UserSlash, "Ban User", _menuWidth, true)) { _mediator.Publish(new OpenBanUserPopupMessage(_pair, group)); ImGui.CloseCurrentPopup(); @@ -511,7 +511,7 @@ public class DrawUserPair { ImGui.TextUnformatted("Syncshell Owner Functions"); string modText = userIsModerator ? "Demod user" : "Mod user"; - if (UiSharedService.IconTextButton(FontAwesomeIcon.UserShield, modText, _menuWidth, true) && UiSharedService.CtrlPressed()) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.UserShield, modText, _menuWidth, true) && UiSharedService.CtrlPressed()) { ImGui.CloseCurrentPopup(); if (!group.GroupPairUserInfos.TryGetValue(_pair.UserData.UID, out var userinfo)) @@ -528,7 +528,7 @@ public class DrawUserPair UiSharedService.AttachToolTip("Hold CTRL to change the moderator status for " + (_pair.UserData.AliasOrUID) + Environment.NewLine + "Moderators can kick, ban/unban, pin/unpin users and clear the Syncshell."); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Crown, "Transfer Ownership", _menuWidth, true) && UiSharedService.CtrlPressed() && UiSharedService.ShiftPressed()) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Crown, "Transfer Ownership", _menuWidth, true) && UiSharedService.CtrlPressed() && UiSharedService.ShiftPressed()) { ImGui.CloseCurrentPopup(); _ = _apiController.GroupChangeOwnership(new(group.Group, _pair.UserData)); diff --git a/MareSynchronos/UI/Components/Popup/BanUserPopupHandler.cs b/MareSynchronos/UI/Components/Popup/BanUserPopupHandler.cs index 87985cb..2cd5ffa 100644 --- a/MareSynchronos/UI/Components/Popup/BanUserPopupHandler.cs +++ b/MareSynchronos/UI/Components/Popup/BanUserPopupHandler.cs @@ -11,13 +11,15 @@ namespace MareSynchronos.UI.Components.Popup; public class BanUserPopupHandler : IPopupHandler { private readonly ApiController _apiController; + private readonly UiSharedService _uiSharedService; private string _banReason = string.Empty; private GroupFullInfoDto _group = null!; private Pair _reportedPair = null!; - public BanUserPopupHandler(ApiController apiController) + public BanUserPopupHandler(ApiController apiController, UiSharedService uiSharedService) { _apiController = apiController; + _uiSharedService = uiSharedService; } public Vector2 PopupSize => new(500, 250); @@ -29,7 +31,7 @@ public class BanUserPopupHandler : IPopupHandler UiSharedService.TextWrapped("User " + (_reportedPair.UserData.AliasOrUID) + " will be banned and removed from this Syncshell."); ImGui.InputTextWithHint("##banreason", "Ban Reason", ref _banReason, 255); - if (UiSharedService.IconTextButton(FontAwesomeIcon.UserSlash, "Ban User")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.UserSlash, "Ban User")) { ImGui.CloseCurrentPopup(); var reason = _banReason; diff --git a/MareSynchronos/UI/Components/Popup/PopupHandler.cs b/MareSynchronos/UI/Components/Popup/PopupHandler.cs index 11880f0..0734fdf 100644 --- a/MareSynchronos/UI/Components/Popup/PopupHandler.cs +++ b/MareSynchronos/UI/Components/Popup/PopupHandler.cs @@ -13,10 +13,11 @@ public class PopupHandler : WindowMediatorSubscriberBase { protected bool _openPopup = false; private readonly HashSet _handlers; + private readonly UiSharedService _uiSharedService; private IPopupHandler? _currentHandler = null; public PopupHandler(ILogger logger, MareMediator mediator, IEnumerable popupHandlers, - PerformanceCollectorService performanceCollectorService) + PerformanceCollectorService performanceCollectorService, UiSharedService uiSharedService) : base(logger, mediator, "MarePopupHandler", performanceCollectorService) { Flags = ImGuiWindowFlags.NoBringToFrontOnFocus @@ -53,6 +54,7 @@ public class PopupHandler : WindowMediatorSubscriberBase _currentHandler = _handlers.OfType().Single(); IsOpen = true; }); + _uiSharedService = uiSharedService; } protected override void DrawInternal() @@ -74,7 +76,7 @@ public class PopupHandler : WindowMediatorSubscriberBase if (_currentHandler.ShowClose) { ImGui.Separator(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Times, "Close")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Times, "Close")) { ImGui.CloseCurrentPopup(); } diff --git a/MareSynchronos/UI/Components/Popup/ReportPopupHandler.cs b/MareSynchronos/UI/Components/Popup/ReportPopupHandler.cs index a43559e..57f144a 100644 --- a/MareSynchronos/UI/Components/Popup/ReportPopupHandler.cs +++ b/MareSynchronos/UI/Components/Popup/ReportPopupHandler.cs @@ -42,7 +42,7 @@ internal class ReportPopupHandler : IPopupHandler using (ImRaii.Disabled(string.IsNullOrEmpty(_reportReason))) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.ExclamationTriangle, "Send Report")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.ExclamationTriangle, "Send Report")) { ImGui.CloseCurrentPopup(); var reason = _reportReason; diff --git a/MareSynchronos/UI/Components/SelectTagForPairUi.cs b/MareSynchronos/UI/Components/SelectTagForPairUi.cs index 03d9f06..fbd01c2 100644 --- a/MareSynchronos/UI/Components/SelectTagForPairUi.cs +++ b/MareSynchronos/UI/Components/SelectTagForPairUi.cs @@ -14,6 +14,7 @@ public class SelectTagForPairUi { private readonly TagHandler _tagHandler; private readonly IdDisplayHandler _uidDisplayHandler; + private readonly UiSharedService _uiSharedService; /// /// The group UI is always open for a specific pair. This defines which pair the UI is open for. @@ -31,12 +32,13 @@ public class SelectTagForPairUi /// private string _tagNameToAdd = ""; - public SelectTagForPairUi(TagHandler tagHandler, IdDisplayHandler uidDisplayHandler) + public SelectTagForPairUi(TagHandler tagHandler, IdDisplayHandler uidDisplayHandler, UiSharedService uiSharedService) { _show = false; _pair = null; _tagHandler = tagHandler; _uidDisplayHandler = uidDisplayHandler; + _uiSharedService = uiSharedService; } public void Draw() @@ -73,7 +75,7 @@ public class SelectTagForPairUi ImGui.Separator(); ImGui.TextUnformatted($"Create a new group for {name}."); - if (UiSharedService.IconButton(FontAwesomeIcon.Plus)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Plus)) { HandleAddTag(); } diff --git a/MareSynchronos/UI/CreateSyncshellUI.cs b/MareSynchronos/UI/CreateSyncshellUI.cs index 7132f0f..a1175d0 100644 --- a/MareSynchronos/UI/CreateSyncshellUI.cs +++ b/MareSynchronos/UI/CreateSyncshellUI.cs @@ -42,7 +42,7 @@ public class CreateSyncshellUI : WindowMediatorSubscriberBase if (_lastCreatedGroup == null) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Create Syncshell")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Create Syncshell")) { try { @@ -85,7 +85,7 @@ public class CreateSyncshellUI : WindowMediatorSubscriberBase ImGui.AlignTextToFramePadding(); ImGui.TextUnformatted("Syncshell Password: " + _lastCreatedGroup.Password); ImGui.SameLine(); - if (UiSharedService.IconButton(FontAwesomeIcon.Copy)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Copy)) { ImGui.SetClipboardText(_lastCreatedGroup.Password); } diff --git a/MareSynchronos/UI/DataAnalysisUi.cs b/MareSynchronos/UI/DataAnalysisUi.cs index 0dc698a..bf75532 100644 --- a/MareSynchronos/UI/DataAnalysisUi.cs +++ b/MareSynchronos/UI/DataAnalysisUi.cs @@ -69,7 +69,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase { ImGui.TextUnformatted("BC7 Conversion in progress: " + _conversionCurrentFileProgress + "/" + _texturesToConvert.Count); UiSharedService.TextWrapped("Current file: " + _conversionCurrentFileName); - if (UiSharedService.IconTextButton(FontAwesomeIcon.StopCircle, "Cancel conversion")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.StopCircle, "Cancel conversion")) { _conversionCancellationTokenSource.Cancel(); } @@ -111,7 +111,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase { UiSharedService.ColorTextWrapped($"Analyzing {_characterAnalyzer.CurrentFile}/{_characterAnalyzer.TotalFiles}", ImGuiColors.DalamudYellow); - if (UiSharedService.IconTextButton(FontAwesomeIcon.StopCircle, "Cancel analysis")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.StopCircle, "Cancel analysis")) { _characterAnalyzer.CancelAnalyze(); } @@ -122,14 +122,14 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase { UiSharedService.ColorTextWrapped("Some entries in the analysis have file size not determined yet, press the button below to analyze your current data", ImGuiColors.DalamudYellow); - if (UiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start analysis (missing entries)")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start analysis (missing entries)")) { _ = _characterAnalyzer.ComputeAnalysis(print: false); } } else { - if (UiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start analysis (recalculate all entries)")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start analysis (recalculate all entries)")) { _ = _characterAnalyzer.ComputeAnalysis(print: false, recalculate: true); } @@ -264,7 +264,7 @@ public class DataAnalysisUi : WindowMediatorSubscriberBase Environment.NewLine + "- Conversion will convert all found texture duplicates (entries with more than 1 file path) automatically." + Environment.NewLine + "- Converting textures to BC7 is a very expensive operation and, depending on the amount of textures to convert, will take a while to complete." , ImGuiColors.DalamudYellow); - if (_texturesToConvert.Count > 0 && UiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start conversion of " + _texturesToConvert.Count + " texture(s)")) + if (_texturesToConvert.Count > 0 && _uiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Start conversion of " + _texturesToConvert.Count + " texture(s)")) { _conversionCancellationTokenSource = _conversionCancellationTokenSource.CancelRecreate(); _conversionTask = _ipcManager.Penumbra.ConvertTextureFiles(_logger, _texturesToConvert, _conversionProgress, _conversionCancellationTokenSource.Token); diff --git a/MareSynchronos/UI/EditProfileUi.cs b/MareSynchronos/UI/EditProfileUi.cs index f45863d..70d4507 100644 --- a/MareSynchronos/UI/EditProfileUi.cs +++ b/MareSynchronos/UI/EditProfileUi.cs @@ -135,7 +135,7 @@ public class EditProfileUi : WindowMediatorSubscriberBase ImGui.Separator(); _uiSharedService.BigText("Profile Settings"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.FileUpload, "Upload new profile picture")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.FileUpload, "Upload new profile picture")) { _fileDialogManager.OpenFileDialog("Select new Profile picture", ".png", (success, file) => { @@ -166,7 +166,7 @@ public class EditProfileUi : WindowMediatorSubscriberBase } UiSharedService.AttachToolTip("Select and upload a new profile picture"); ImGui.SameLine(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear uploaded profile picture")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear uploaded profile picture")) { _ = _apiController.UserSetProfile(new UserProfileDto(new UserData(_apiController.UID), Disabled: false, IsNSFW: null, "", Description: null)); } @@ -215,13 +215,13 @@ public class EditProfileUi : WindowMediatorSubscriberBase ImGui.EndChildFrame(); } - if (UiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Description")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Description")) { _ = _apiController.UserSetProfile(new UserProfileDto(new UserData(_apiController.UID), Disabled: false, IsNSFW: null, ProfilePictureBase64: null, _descriptionText)); } UiSharedService.AttachToolTip("Sets your profile description text"); ImGui.SameLine(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear Description")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear Description")) { _ = _apiController.UserSetProfile(new UserProfileDto(new UserData(_apiController.UID), Disabled: false, IsNSFW: null, ProfilePictureBase64: null, "")); } diff --git a/MareSynchronos/UI/EventViewerUI.cs b/MareSynchronos/UI/EventViewerUI.cs index 0560b60..fd4dba4 100644 --- a/MareSynchronos/UI/EventViewerUI.cs +++ b/MareSynchronos/UI/EventViewerUI.cs @@ -100,7 +100,7 @@ internal class EventViewerUI : WindowMediatorSubscriberBase { using (ImRaii.Disabled(!_eventAggregator.NewEventsAvailable)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.ArrowsToCircle, "Refresh events")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.ArrowsToCircle, "Refresh events")) { CurrentEvents = _eventAggregator.EventList.Value.OrderByDescending(f => f.EventTime).ToList(); } @@ -113,10 +113,10 @@ internal class EventViewerUI : WindowMediatorSubscriberBase UiSharedService.ColorTextWrapped("New events are available, press refresh to update", ImGuiColors.DalamudYellow); } - var buttonSize = UiSharedService.GetIconTextButtonSize(FontAwesomeIcon.FolderOpen, "Open EventLog Folder"); + var buttonSize = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.FolderOpen, "Open EventLog Folder"); var dist = ImGui.GetWindowContentRegionMax().X - buttonSize; ImGui.SameLine(dist); - if (UiSharedService.IconTextButton(FontAwesomeIcon.FolderOpen, "Open EventLog folder")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.FolderOpen, "Open EventLog folder")) { ProcessStartInfo ps = new() { @@ -131,7 +131,7 @@ internal class EventViewerUI : WindowMediatorSubscriberBase var foldOut = ImRaii.TreeNode("Filter"); if (foldOut) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Ban, "Clear Filters")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Ban, "Clear Filters")) { ClearFilters(); } diff --git a/MareSynchronos/UI/GposeUi.cs b/MareSynchronos/UI/GposeUi.cs index 6b80ecb..907e806 100644 --- a/MareSynchronos/UI/GposeUi.cs +++ b/MareSynchronos/UI/GposeUi.cs @@ -12,6 +12,7 @@ namespace MareSynchronos.UI; public class GposeUi : WindowMediatorSubscriberBase { private readonly MareConfigService _configService; + private readonly UiSharedService _uiSharedService; private readonly DalamudUtilService _dalamudUtil; private readonly FileDialogManager _fileDialogManager; private readonly MareCharaFileManager _mareCharaFileManager; @@ -20,13 +21,14 @@ public class GposeUi : WindowMediatorSubscriberBase public GposeUi(ILogger logger, MareCharaFileManager mareCharaFileManager, DalamudUtilService dalamudUtil, FileDialogManager fileDialogManager, MareConfigService configService, - MareMediator mediator, PerformanceCollectorService performanceCollectorService) + MareMediator mediator, PerformanceCollectorService performanceCollectorService, UiSharedService uiSharedService) : base(logger, mediator, "Mare Synchronos Gpose Import UI###MareSynchronosGposeUI", performanceCollectorService) { _mareCharaFileManager = mareCharaFileManager; _dalamudUtil = dalamudUtil; _fileDialogManager = fileDialogManager; _configService = configService; + _uiSharedService = uiSharedService; Mediator.Subscribe(this, (_) => StartGpose()); Mediator.Subscribe(this, (_) => EndGpose()); IsOpen = _dalamudUtil.IsInGpose; @@ -43,7 +45,7 @@ public class GposeUi : WindowMediatorSubscriberBase if (!_mareCharaFileManager.CurrentlyWorking) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.FolderOpen, "Load MCDF")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.FolderOpen, "Load MCDF")) { _fileDialogManager.OpenFileDialog("Pick MCDF file", ".mcdf", (success, paths) => { @@ -61,7 +63,7 @@ public class GposeUi : WindowMediatorSubscriberBase { UiSharedService.TextWrapped("Loaded file: " + _mareCharaFileManager.LoadedCharaFile.FilePath); UiSharedService.TextWrapped("File Description: " + _mareCharaFileManager.LoadedCharaFile.CharaFileData.Description); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Check, "Apply loaded MCDF")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Check, "Apply loaded MCDF")) { _applicationTask = Task.Run(async () => await _mareCharaFileManager.ApplyMareCharaFile(_dalamudUtil.GposeTargetGameObject, _expectedLength!.GetAwaiter().GetResult()).ConfigureAwait(false)); } diff --git a/MareSynchronos/UI/JoinSyncshellUI.cs b/MareSynchronos/UI/JoinSyncshellUI.cs index 653b748..27c021e 100644 --- a/MareSynchronos/UI/JoinSyncshellUI.cs +++ b/MareSynchronos/UI/JoinSyncshellUI.cs @@ -76,7 +76,7 @@ internal class JoinSyncshellUI : WindowMediatorSubscriberBase ImGui.InputTextWithHint("##syncshellpw", "Password", ref _syncshellPassword, 50, ImGuiInputTextFlags.Password); using (ImRaii.Disabled(string.IsNullOrEmpty(_desiredSyncshellToJoin) || string.IsNullOrEmpty(_syncshellPassword))) { - if (UiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Join Syncshell")) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Join Syncshell")) { _groupJoinInfo = _apiController.GroupJoin(new GroupPasswordDto(new API.Data.GroupData(_desiredSyncshellToJoin), _syncshellPassword)).Result; _previousPassword = _syncshellPassword; @@ -123,7 +123,7 @@ internal class JoinSyncshellUI : WindowMediatorSubscriberBase _uiSharedService.BooleanToColoredIcon(!_groupJoinInfo.GroupPermissions.IsPreferDisableSounds()); ImGui.SameLine(); using var id = ImRaii.PushId("suggestedSounds"); - if (UiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowRight, "Apply suggested")) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowRight, "Apply suggested")) { _ownPermissions.DisableGroupSounds = _groupJoinInfo.GroupPermissions.IsPreferDisableSounds(); } @@ -139,7 +139,7 @@ internal class JoinSyncshellUI : WindowMediatorSubscriberBase _uiSharedService.BooleanToColoredIcon(!_groupJoinInfo.GroupPermissions.IsPreferDisableAnimations()); ImGui.SameLine(); using var id = ImRaii.PushId("suggestedAnims"); - if (UiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowRight, "Apply suggested")) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowRight, "Apply suggested")) { _ownPermissions.DisableGroupAnimations = _groupJoinInfo.GroupPermissions.IsPreferDisableAnimations(); } @@ -155,7 +155,7 @@ internal class JoinSyncshellUI : WindowMediatorSubscriberBase _uiSharedService.BooleanToColoredIcon(!_groupJoinInfo.GroupPermissions.IsPreferDisableVFX()); ImGui.SameLine(); using var id = ImRaii.PushId("suggestedVfx"); - if (UiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowRight, "Apply suggested")) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowRight, "Apply suggested")) { _ownPermissions.DisableGroupVFX = _groupJoinInfo.GroupPermissions.IsPreferDisableVFX(); } @@ -167,7 +167,7 @@ internal class JoinSyncshellUI : WindowMediatorSubscriberBase UiSharedService.TextWrapped("Your default syncshell permissions on joining are in line with the suggested Syncshell permissions through the owner."); } ImGuiHelpers.ScaledDummy(2f); - if (UiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Finalize and join " + _groupJoinInfo.GroupAliasOrGID)) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Plus, "Finalize and join " + _groupJoinInfo.GroupAliasOrGID)) { GroupUserPreferredPermissions joinPermissions = GroupUserPreferredPermissions.NoneSet; joinPermissions.SetDisableSounds(_ownPermissions.DisableGroupSounds); diff --git a/MareSynchronos/UI/PermissionWindowUI.cs b/MareSynchronos/UI/PermissionWindowUI.cs index 1abdf3b..6e5dc2a 100644 --- a/MareSynchronos/UI/PermissionWindowUI.cs +++ b/MareSynchronos/UI/PermissionWindowUI.cs @@ -133,7 +133,7 @@ public class PermissionWindowUI : WindowMediatorSubscriberBase bool hasChanges = _ownPermissions != Pair.UserPair.OwnPermissions; using (ImRaii.Disabled(!hasChanges)) - if (UiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Save, "Save")) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Save, "Save")) { _ = _apiController.SetBulkPermissions(new( new(StringComparer.Ordinal) @@ -145,21 +145,21 @@ public class PermissionWindowUI : WindowMediatorSubscriberBase } UiSharedService.AttachToolTip("Save and apply all changes"); - var rightSideButtons = UiSharedService.GetIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.Undo, "Revert") + - UiSharedService.GetIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, "Reset to Default"); + var rightSideButtons = _uiSharedService.GetIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.Undo, "Revert") + + _uiSharedService.GetIconTextButtonSize(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, "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, "Revert")) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.Undo, "Revert")) { _ownPermissions = Pair.UserPair.OwnPermissions.DeepClone(); } UiSharedService.AttachToolTip("Revert all changes"); ImGui.SameLine(); - if (UiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, "Reset to Default")) + if (_uiSharedService.IconTextButton(Dalamud.Interface.FontAwesomeIcon.ArrowsSpin, "Reset to Default")) { var defaultPermissions = _apiController.DefaultPermissions!; _ownPermissions.SetSticky(Pair.IsDirectlyPaired || defaultPermissions.IndividualIsSticky); diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index 27812ed..7e8f77a 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -378,7 +378,7 @@ public class SettingsUi : WindowMediatorSubscriberBase ImGui.TreePop(); } #endif - if (UiSharedService.IconTextButton(FontAwesomeIcon.Copy, "[DEBUG] Copy Last created Character Data to clipboard")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Copy, "[DEBUG] Copy Last created Character Data to clipboard")) { if (LastCreatedCharacterData != null) { @@ -406,12 +406,12 @@ public class SettingsUi : WindowMediatorSubscriberBase _uiShared.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended."); using var disabled = ImRaii.Disabled(!logPerformance); - if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) + if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) { _performanceCollector.PrintPerformanceStats(); } ImGui.SameLine(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog")) + if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog")) { _performanceCollector.PrintPerformanceStats(60); } @@ -437,7 +437,7 @@ public class SettingsUi : WindowMediatorSubscriberBase if (!_mareCharaFileManager.CurrentlyWorking) { ImGui.InputTextWithHint("Export Descriptor", "This description will be shown on loading the data", ref _exportDescription, 255); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Save, "Export Character as MCDF")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Save, "Export Character as MCDF")) { string defaultFileName = string.IsNullOrEmpty(_exportDescription) ? "export.mcdf" @@ -494,7 +494,7 @@ public class SettingsUi : WindowMediatorSubscriberBase { ImGui.SameLine(); using var id = ImRaii.PushId("penumbraMonitor"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.ArrowsToCircle, "Try to reinitialize Monitor")) + if (_uiShared.IconTextButton(FontAwesomeIcon.ArrowsToCircle, "Try to reinitialize Monitor")) { _cacheMonitor.StartPenumbraWatcher(_ipcManager.Penumbra.ModDirectory); } @@ -506,14 +506,14 @@ public class SettingsUi : WindowMediatorSubscriberBase { ImGui.SameLine(); using var id = ImRaii.PushId("mareMonitor"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.ArrowsToCircle, "Try to reinitialize Monitor")) + if (_uiShared.IconTextButton(FontAwesomeIcon.ArrowsToCircle, "Try to reinitialize Monitor")) { _cacheMonitor.StartMareWatcher(_configService.Current.CacheFolder); } } if (_cacheMonitor.MareWatcher == null || _cacheMonitor.PenumbraWatcher == null) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Play, "Resume Monitoring")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Play, "Resume Monitoring")) { _cacheMonitor.StartMareWatcher(_configService.Current.CacheFolder); _cacheMonitor.StartPenumbraWatcher(_ipcManager.Penumbra.ModDirectory); @@ -527,7 +527,7 @@ public class SettingsUi : WindowMediatorSubscriberBase { using (ImRaii.Disabled(!UiSharedService.CtrlPressed())) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Stop, "Stop Monitoring")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Stop, "Stop Monitoring")) { _cacheMonitor.StopMonitoring(); } @@ -562,7 +562,7 @@ public class SettingsUi : WindowMediatorSubscriberBase ImGui.SameLine(); if (!_fileCompactor.MassCompactRunning) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.FileArchive, "Compact all files in storage")) + if (_uiShared.IconTextButton(FontAwesomeIcon.FileArchive, "Compact all files in storage")) { _ = Task.Run(() => { @@ -573,7 +573,7 @@ public class SettingsUi : WindowMediatorSubscriberBase UiSharedService.AttachToolTip("This will run compression on all files in your current Mare Storage." + Environment.NewLine + "You do not need to run this manually if you keep the file compactor enabled."); ImGui.SameLine(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.File, "Decompact all files in storage")) + if (_uiShared.IconTextButton(FontAwesomeIcon.File, "Decompact all files in storage")) { _ = Task.Run(() => { @@ -600,7 +600,7 @@ public class SettingsUi : WindowMediatorSubscriberBase "This operation, depending on how many files you have in your storage, can take a while and will be CPU and drive intensive."); using (ImRaii.Disabled(_validationTask != null && !_validationTask.IsCompleted)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Check, "Start File Storage Validation")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Check, "Start File Storage Validation")) { _validationCts?.Cancel(); _validationCts?.Dispose(); @@ -612,7 +612,7 @@ public class SettingsUi : WindowMediatorSubscriberBase if (_validationTask != null && !_validationTask.IsCompleted) { ImGui.SameLine(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Times, "Cancel")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Times, "Cancel")) { _validationCts?.Cancel(); } @@ -646,7 +646,7 @@ public class SettingsUi : WindowMediatorSubscriberBase + Environment.NewLine + "- This can make the situation of not getting other players data worse in situations of heavy file server load."); if (!_readClearCache) ImGui.BeginDisabled(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear local storage") && UiSharedService.CtrlPressed() && _readClearCache) + if (_uiShared.IconTextButton(FontAwesomeIcon.Trash, "Clear local storage") && UiSharedService.CtrlPressed() && _readClearCache) { _ = Task.Run(() => { @@ -677,11 +677,11 @@ public class SettingsUi : WindowMediatorSubscriberBase //ImGui.Separator(); _uiShared.BigText("Notes"); - if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard")) + if (_uiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard")) { ImGui.SetClipboardText(UiSharedService.GetNotes(_pairManager.DirectPairs.UnionBy(_pairManager.GroupPairs.SelectMany(p => p.Value), p => p.UserData, UserDataComparer.Instance).ToList())); } - if (UiSharedService.IconTextButton(FontAwesomeIcon.FileImport, "Import notes from clipboard")) + if (_uiShared.IconTextButton(FontAwesomeIcon.FileImport, "Import notes from clipboard")) { _notesSuccessfullyApplied = null; var notes = ImGui.GetClipboardText(); @@ -1094,7 +1094,7 @@ public class SettingsUi : WindowMediatorSubscriberBase } }, EqualityComparer>.Default.Equals(keys.FirstOrDefault(f => f.Key == item.SecretKeyIdx), default) ? keys.First() : keys.First(f => f.Key == item.SecretKeyIdx)); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Character") && UiSharedService.CtrlPressed()) + if (_uiShared.IconTextButton(FontAwesomeIcon.Trash, "Delete Character") && UiSharedService.CtrlPressed()) _serverConfigurationManager.RemoveCharacterFromServer(idx, item); UiSharedService.AttachToolTip("Hold CTRL to delete this entry."); @@ -1108,14 +1108,14 @@ public class SettingsUi : WindowMediatorSubscriberBase if (!selectedServer.Authentications.Exists(c => string.Equals(c.CharacterName, _uiShared.PlayerName, StringComparison.Ordinal) && c.WorldId == _uiShared.WorldId)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.User, "Add current character")) + if (_uiShared.IconTextButton(FontAwesomeIcon.User, "Add current character")) { _serverConfigurationManager.AddCurrentCharacterToServer(idx); } ImGui.SameLine(); } - if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Add new character")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Plus, "Add new character")) { _serverConfigurationManager.AddEmptyCharacterToServer(idx); } @@ -1147,7 +1147,7 @@ public class SettingsUi : WindowMediatorSubscriberBase } if (!selectedServer.Authentications.Exists(p => p.SecretKeyIdx == item.Key)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Secret Key") && UiSharedService.CtrlPressed()) + if (_uiShared.IconTextButton(FontAwesomeIcon.Trash, "Delete Secret Key") && UiSharedService.CtrlPressed()) { selectedServer.SecretKeys.Remove(item.Key); _serverConfigurationManager.Save(); @@ -1164,7 +1164,7 @@ public class SettingsUi : WindowMediatorSubscriberBase } ImGui.Separator(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Add new Secret Key")) + if (_uiShared.IconTextButton(FontAwesomeIcon.Plus, "Add new Secret Key")) { selectedServer.SecretKeys.Add(selectedServer.SecretKeys.Any() ? selectedServer.SecretKeys.Max(p => p.Key) + 1 : 0, new SecretKey() { @@ -1204,7 +1204,7 @@ public class SettingsUi : WindowMediatorSubscriberBase if (!isMain && selectedServer != _serverConfigurationManager.CurrentServer) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Service") && UiSharedService.CtrlPressed()) + if (_uiShared.IconTextButton(FontAwesomeIcon.Trash, "Delete Service") && UiSharedService.CtrlPressed()) { _serverConfigurationManager.DeleteServer(selectedServer); } diff --git a/MareSynchronos/UI/SyncshellAdminUI.cs b/MareSynchronos/UI/SyncshellAdminUI.cs index a724248..a581b3f 100644 --- a/MareSynchronos/UI/SyncshellAdminUI.cs +++ b/MareSynchronos/UI/SyncshellAdminUI.cs @@ -77,7 +77,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase { bool isInvitesDisabled = perm.IsDisableInvites(); - if (UiSharedService.IconTextButton(isInvitesDisabled ? FontAwesomeIcon.Unlock : FontAwesomeIcon.Lock, + if (_uiSharedService.IconTextButton(isInvitesDisabled ? FontAwesomeIcon.Unlock : FontAwesomeIcon.Lock, isInvitesDisabled ? "Unlock Syncshell" : "Lock Syncshell")) { perm.SetDisableInvites(!isInvitesDisabled); @@ -87,7 +87,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGuiHelpers.ScaledDummy(2f); UiSharedService.TextWrapped("One-time invites work as single-use passwords. Use those if you do not want to distribute your Syncshell password."); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Single one-time invite")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Single one-time invite")) { ImGui.SetClipboardText(_apiController.GroupCreateTempInvite(new(GroupFullInfo.Group), 1).Result.FirstOrDefault() ?? string.Empty); } @@ -96,7 +96,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.SameLine(); using (ImRaii.Disabled(_multiInvites <= 1 || _multiInvites > 100)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Generate " + _multiInvites + " one-time invites")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Envelope, "Generate " + _multiInvites + " one-time invites")) { _oneTimeInvites.AddRange(_apiController.GroupCreateTempInvite(new(GroupFullInfo.Group), _multiInvites).Result); } @@ -106,7 +106,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase { var invites = string.Join(Environment.NewLine, _oneTimeInvites); ImGui.InputTextMultiline("Generated Multi Invites", ref invites, 5000, new(0, 0), ImGuiInputTextFlags.ReadOnly); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Copy, "Copy Invites to clipboard")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Copy, "Copy Invites to clipboard")) { ImGui.SetClipboardText(invites); } @@ -186,7 +186,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.TableNextColumn(); // actions if (_isOwner) { - if (UiSharedService.IconButton(FontAwesomeIcon.UserShield)) + if (_uiSharedService.IconButton(FontAwesomeIcon.UserShield)) { GroupPairUserInfo userInfo = pair.Value ?? GroupPairUserInfo.None; @@ -200,7 +200,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase if (_isOwner || (pair.Value == null || (pair.Value != null && !pair.Value.Value.IsModerator()))) { - if (UiSharedService.IconButton(FontAwesomeIcon.Thumbtack)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Thumbtack)) { GroupPairUserInfo userInfo = pair.Value ?? GroupPairUserInfo.None; @@ -213,7 +213,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase using (ImRaii.Disabled(!UiSharedService.CtrlPressed())) { - if (UiSharedService.IconButton(FontAwesomeIcon.Trash)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Trash)) { _ = _apiController.GroupRemoveUser(new GroupPairDto(GroupFullInfo.Group, pair.Key.UserData)); } @@ -224,7 +224,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.SameLine(); using (ImRaii.Disabled(!UiSharedService.CtrlPressed())) { - if (UiSharedService.IconButton(FontAwesomeIcon.Ban)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Ban)) { Mediator.Publish(new OpenBanUserPopupMessage(pair.Key, GroupFullInfo)); } @@ -242,7 +242,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase { using (ImRaii.Disabled(!UiSharedService.CtrlPressed())) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Clear Syncshell")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Clear Syncshell")) { _ = _apiController.GroupClear(new(GroupFullInfo.Group)); } @@ -254,7 +254,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.Separator(); ImGuiHelpers.ScaledDummy(2f); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Unlink, "Check for Inactive Users")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Unlink, "Check for Inactive Users")) { _pruneTestTask = _apiController.GroupPrune(new(GroupFullInfo.Group), _pruneDays, execute: false); _pruneTask = null; @@ -290,7 +290,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase { using (ImRaii.Disabled(!UiSharedService.CtrlPressed())) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Prune Inactive Users")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Broom, "Prune Inactive Users")) { _pruneTask = _apiController.GroupPrune(new(GroupFullInfo.Group), _pruneDays, execute: true); _pruneTestTask = null; @@ -318,7 +318,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase var banNode = ImRaii.TreeNode("User Bans"); if (banNode) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Retweet, "Refresh Banlist from Server")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Retweet, "Refresh Banlist from Server")) { _bannedUsers = _apiController.GroupGetBannedUsers(new GroupDto(GroupFullInfo.Group)).Result; } @@ -347,7 +347,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.TableNextColumn(); UiSharedService.TextWrapped(bannedUser.Reason); ImGui.TableNextColumn(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Check, "Unban#" + bannedUser.UID)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Check, "Unban#" + bannedUser.UID)) { _ = _apiController.GroupUnbanUser(bannedUser); _bannedUsers.RemoveAll(b => string.Equals(b.UID, bannedUser.UID, StringComparison.Ordinal)); @@ -372,7 +372,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.Text("Suggest Sound Sync"); _uiSharedService.BooleanToColoredIcon(!isDisableSounds); ImGui.SameLine(230); - if (UiSharedService.IconTextButton(isDisableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeMute, + if (_uiSharedService.IconTextButton(isDisableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeMute, isDisableSounds ? "Suggest to enable sound sync" : "Suggest to disable sound sync")) { perm.SetPreferDisableSounds(!perm.IsPreferDisableSounds()); @@ -383,7 +383,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.Text("Suggest Animation Sync"); _uiSharedService.BooleanToColoredIcon(!isDisableAnimations); ImGui.SameLine(230); - if (UiSharedService.IconTextButton(isDisableAnimations ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop, + if (_uiSharedService.IconTextButton(isDisableAnimations ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop, isDisableAnimations ? "Suggest to enable animation sync" : "Suggest to disable animation sync")) { perm.SetPreferDisableAnimations(!perm.IsPreferDisableAnimations()); @@ -394,7 +394,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.Text("Suggest VFX Sync"); _uiSharedService.BooleanToColoredIcon(!isDisableVfx); ImGui.SameLine(230); - if (UiSharedService.IconTextButton(isDisableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle, + if (_uiSharedService.IconTextButton(isDisableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle, isDisableVfx ? "Suggest to enable vfx sync" : "Suggest to disable vfx sync")) { perm.SetPreferDisableVFX(!perm.IsPreferDisableVFX()); @@ -413,7 +413,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.AlignTextToFramePadding(); ImGui.TextUnformatted("New Password"); var availableWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X; - var buttonSize = UiSharedService.GetIconTextButtonSize(FontAwesomeIcon.Passport, "Change Password"); + var buttonSize = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.Passport, "Change Password"); var textSize = ImGui.CalcTextSize("New Password").X; var spacing = ImGui.GetStyle().ItemSpacing.X; @@ -423,7 +423,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase ImGui.SameLine(); using (ImRaii.Disabled(_newPassword.Length < 10)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Passport, "Change Password")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Passport, "Change Password")) { _pwChangeSuccess = _apiController.GroupChangePassword(new GroupPasswordDto(GroupFullInfo.Group, _newPassword)).Result; _newPassword = string.Empty; @@ -436,7 +436,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase UiSharedService.ColorTextWrapped("Failed to change the password. Password requires to be at least 10 characters long.", ImGuiColors.DalamudYellow); } - if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Syncshell") && UiSharedService.CtrlPressed() && UiSharedService.ShiftPressed()) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Syncshell") && UiSharedService.CtrlPressed() && UiSharedService.ShiftPressed()) { IsOpen = false; _ = _apiController.GroupDelete(new(GroupFullInfo.Group)); diff --git a/MareSynchronos/UI/TopTabMenu.cs b/MareSynchronos/UI/TopTabMenu.cs index d8406e1..d292c53 100644 --- a/MareSynchronos/UI/TopTabMenu.cs +++ b/MareSynchronos/UI/TopTabMenu.cs @@ -179,14 +179,14 @@ public class TopTabMenu private void DrawAddPair(float availableXWidth, float spacingX) { - var buttonSize = UiSharedService.GetIconTextButtonSize(FontAwesomeIcon.UserPlus, "Add"); + var buttonSize = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.UserPlus, "Add"); ImGui.SetNextItemWidth(availableXWidth - buttonSize - spacingX); ImGui.InputTextWithHint("##otheruid", "Other players UID/Alias", ref _pairToAdd, 20); ImGui.SameLine(); var alreadyExisting = _pairManager.DirectPairs.Exists(p => string.Equals(p.UserData.UID, _pairToAdd, StringComparison.Ordinal) || string.Equals(p.UserData.Alias, _pairToAdd, StringComparison.Ordinal)); using (ImRaii.Disabled(alreadyExisting || string.IsNullOrEmpty(_pairToAdd))) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.UserPlus, "Add")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.UserPlus, "Add")) { _ = _apiController.UserAddPair(new(new(_pairToAdd))); _pairToAdd = string.Empty; @@ -197,7 +197,7 @@ public class TopTabMenu private void DrawFilter(float availableWidth, float spacingX) { - var buttonSize = UiSharedService.GetIconTextButtonSize(FontAwesomeIcon.Ban, "Clear"); + var buttonSize = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.Ban, "Clear"); ImGui.SetNextItemWidth(availableWidth - buttonSize - spacingX); string filter = Filter; if (ImGui.InputTextWithHint("##filter", "Filter for UID/notes", ref filter, 255)) @@ -206,7 +206,7 @@ public class TopTabMenu } ImGui.SameLine(); using var disabled = ImRaii.Disabled(string.IsNullOrEmpty(Filter)); - if (UiSharedService.IconTextButton(FontAwesomeIcon.Ban, "Clear")) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Ban, "Clear")) { Filter = string.Empty; } @@ -467,7 +467,7 @@ public class TopTabMenu using (ImRaii.Disabled(_pairManager.GroupPairs.Select(k => k.Key).Distinct() .Count(g => string.Equals(g.OwnerUID, _apiController.UID, StringComparison.Ordinal)) >= _apiController.ServerInfo.MaxGroupsCreatedByUser)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Create new Syncshell", buttonX)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Create new Syncshell", buttonX)) { _mareMediator.Publish(new UiToggleMessage(typeof(CreateSyncshellUI))); } @@ -476,7 +476,7 @@ public class TopTabMenu using (ImRaii.Disabled(_pairManager.GroupPairs.Select(k => k.Key).Distinct().Count() >= _apiController.ServerInfo.MaxGroupsJoinedByUser)) { - if (UiSharedService.IconTextButton(FontAwesomeIcon.Users, "Join existing Syncshell", buttonX)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.Users, "Join existing Syncshell", buttonX)) { _mareMediator.Publish(new UiToggleMessage(typeof(JoinSyncshellUI))); } @@ -486,13 +486,13 @@ public class TopTabMenu private void DrawUserConfig(float availableWidth, float spacingX) { var buttonX = (availableWidth - spacingX) / 2f; - if (UiSharedService.IconTextButton(FontAwesomeIcon.UserCircle, "Edit Mare Profile", buttonX)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.UserCircle, "Edit Mare Profile", buttonX)) { _mareMediator.Publish(new UiToggleMessage(typeof(EditProfileUi))); } UiSharedService.AttachToolTip("Edit your Mare Profile"); ImGui.SameLine(); - if (UiSharedService.IconTextButton(FontAwesomeIcon.PersonCircleQuestion, "Chara Data Analysis", buttonX)) + if (_uiSharedService.IconTextButton(FontAwesomeIcon.PersonCircleQuestion, "Chara Data Analysis", buttonX)) { _mareMediator.Publish(new UiToggleMessage(typeof(DataAnalysisUi))); } @@ -519,7 +519,7 @@ public class TopTabMenu { if (ImGui.BeginPopup(popupTitle)) { - if (UiSharedService.IconTextButton(enableIcon, enableText, null, true)) + if (_uiSharedService.IconTextButton(enableIcon, enableText, null, true)) { _ = GlobalControlCountdown(10); var bulkIndividualPairs = _pairManager.PairsWithGroups.Keys @@ -533,7 +533,7 @@ public class TopTabMenu ImGui.CloseCurrentPopup(); } - if (UiSharedService.IconTextButton(disableIcon, disableText, null, true)) + if (_uiSharedService.IconTextButton(disableIcon, disableText, null, true)) { _ = GlobalControlCountdown(10); var bulkIndividualPairs = _pairManager.PairsWithGroups.Keys @@ -557,7 +557,7 @@ public class TopTabMenu if (ImGui.BeginPopup(popupTitle)) { - if (UiSharedService.IconTextButton(enableIcon, enableText, null, true)) + if (_uiSharedService.IconTextButton(enableIcon, enableText, null, true)) { _ = GlobalControlCountdown(10); var bulkSyncshells = _pairManager.GroupPairs.Keys @@ -571,7 +571,7 @@ public class TopTabMenu ImGui.CloseCurrentPopup(); } - if (UiSharedService.IconTextButton(disableIcon, disableText, null, true)) + if (_uiSharedService.IconTextButton(disableIcon, disableText, null, true)) { _ = GlobalControlCountdown(10); var bulkSyncshells = _pairManager.GroupPairs.Keys diff --git a/MareSynchronos/UI/UISharedService.cs b/MareSynchronos/UI/UISharedService.cs index a0c6055..80043ea 100644 --- a/MareSynchronos/UI/UISharedService.cs +++ b/MareSynchronos/UI/UISharedService.cs @@ -113,8 +113,38 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase })); }); GameFont = _pluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(new(GameFontFamilyAndSize.Axis12)); - IconFont = _pluginInterface.UiBuilder.IconFontHandle; + IconFont = _pluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(e => + { + e.OnPreBuild(tk => tk.AddFontAwesomeIconFont(new() + { + SizePx = _pluginInterface.UiBuilder.DefaultFontSpec.SizePx, + GlyphMinAdvanceX = _pluginInterface.UiBuilder.DefaultFontSpec.SizePx, + GlyphMaxAdvanceX = _pluginInterface.UiBuilder.DefaultFontSpec.SizePx + })); + e.OnPostBuild(tk => + { + var font = tk.Font; + var nsize = font.FontSize; + var glyphs = font.GlyphsWrapped(); + foreach (ref var glyph in glyphs.DataSpan) + { + var ratio = 1f; + if (glyph.X1 - glyph.X0 > nsize) + ratio = Math.Max(ratio, (glyph.X1 - glyph.X0) / nsize); + if (glyph.Y1 - glyph.Y0 > nsize) + ratio = Math.Max(ratio, (glyph.Y1 - glyph.Y0) / nsize); + var w = MathF.Round((glyph.X1 - glyph.X0) / ratio, MidpointRounding.ToZero); + var h = MathF.Round((glyph.Y1 - glyph.Y0) / ratio, MidpointRounding.AwayFromZero); + glyph.X0 = MathF.Round((nsize - w) / 2f, MidpointRounding.ToZero); + glyph.Y0 = MathF.Round((nsize - h) / 2f, MidpointRounding.AwayFromZero); + glyph.X1 = glyph.X0 + w; + glyph.Y1 = glyph.Y0 + h; + glyph.AdvanceX = nsize; + } + tk.BuildLookupTable(font); + }); + }); } public ApiController ApiController => _apiController; @@ -264,11 +294,12 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase public static Vector4 GetBoolColor(bool input) => input ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed; - public static float GetIconTextButtonSize(FontAwesomeIcon icon, string text) + public float GetIconTextButtonSize(FontAwesomeIcon icon, string text) { - ImGui.PushFont(UiBuilder.IconFont); - Vector2 vector = ImGui.CalcTextSize(icon.ToIconString()); - ImGui.PopFont(); + Vector2 vector; + using (IconFont.Push()) + vector = ImGui.CalcTextSize(icon.ToIconString()); + Vector2 vector2 = ImGui.CalcTextSize(text); float num = 3f * ImGuiHelpers.GlobalScale; return vector.X + vector2.X + ImGui.GetStyle().FramePadding.X * 2f + num; @@ -295,14 +326,14 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase return ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X; } - public static bool IconButton(FontAwesomeIcon icon, float? height = null) + public bool IconButton(FontAwesomeIcon icon, float? height = null) { string text = icon.ToIconString(); ImGui.PushID(text); - ImGui.PushFont(UiBuilder.IconFont); - Vector2 vector = ImGui.CalcTextSize(text); - ImGui.PopFont(); + Vector2 vector; + using (IconFont.Push()) + vector = ImGui.CalcTextSize(text); ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList(); Vector2 cursorScreenPos = ImGui.GetCursorScreenPos(); float x = vector.X + ImGui.GetStyle().FramePadding.X * 2f; @@ -310,15 +341,14 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase bool result = ImGui.Button(string.Empty, new Vector2(x, frameHeight)); Vector2 pos = new Vector2(cursorScreenPos.X + ImGui.GetStyle().FramePadding.X, cursorScreenPos.Y + (height ?? ImGui.GetFrameHeight()) / 2f - (vector.Y / 2f)); - ImGui.PushFont(UiBuilder.IconFont); - windowDrawList.AddText(pos, ImGui.GetColorU32(ImGuiCol.Text), text); - ImGui.PopFont(); + using (IconFont.Push()) + windowDrawList.AddText(pos, ImGui.GetColorU32(ImGuiCol.Text), text); ImGui.PopID(); return result; } - private static bool IconTextButtonInternal(FontAwesomeIcon icon, string text, Vector4? defaultColor = null, float? width = null) + private bool IconTextButtonInternal(FontAwesomeIcon icon, string text, Vector4? defaultColor = null, float? width = null) { int num = 0; if (defaultColor.HasValue) @@ -328,9 +358,9 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase } ImGui.PushID(text); - ImGui.PushFont(UiBuilder.IconFont); - Vector2 vector = ImGui.CalcTextSize(icon.ToIconString()); - ImGui.PopFont(); + Vector2 vector; + using (IconFont.Push()) + vector = ImGui.CalcTextSize(icon.ToIconString()); Vector2 vector2 = ImGui.CalcTextSize(text); ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList(); Vector2 cursorScreenPos = ImGui.GetCursorScreenPos(); @@ -339,9 +369,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase float frameHeight = ImGui.GetFrameHeight(); bool result = ImGui.Button(string.Empty, new Vector2(x, frameHeight)); Vector2 pos = new Vector2(cursorScreenPos.X + ImGui.GetStyle().FramePadding.X, cursorScreenPos.Y + ImGui.GetStyle().FramePadding.Y); - ImGui.PushFont(UiBuilder.IconFont); - windowDrawList.AddText(pos, ImGui.GetColorU32(ImGuiCol.Text), icon.ToIconString()); - ImGui.PopFont(); + using (IconFont.Push()) + windowDrawList.AddText(pos, ImGui.GetColorU32(ImGuiCol.Text), icon.ToIconString()); Vector2 pos2 = new Vector2(pos.X + vector.X + num2, cursorScreenPos.Y + ImGui.GetStyle().FramePadding.Y); windowDrawList.AddText(pos2, ImGui.GetColorU32(ImGuiCol.Text), text); ImGui.PopID(); @@ -353,7 +382,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase return result; } - public static bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false) + public bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false) { return IconTextButtonInternal(icon, text, isInPopup ? ColorHelpers.RgbaUintToVector4(ImGui.GetColorU32(ImGuiCol.PopupBg)) : null, @@ -843,4 +872,15 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase } public sealed record IconScaleData(Vector2 IconSize, Vector2 NormalizedIconScale, float OffsetX, float IconScaling); + + protected override void Dispose(bool disposing) + { + if (!disposing) return; + + base.Dispose(disposing); + + IconFont.Dispose(); + UidFont.Dispose(); + GameFont.Dispose(); + } } \ No newline at end of file