From 54ee56dbc87451eb71561b921aa9105609052bb4 Mon Sep 17 00:00:00 2001 From: Loporrit <141286461+loporrit@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:03:27 +0000 Subject: [PATCH] Use new icon buttons on legacy UI too --- MareSynchronos/UI/CompactUI.cs | 36 ++++++++----------- MareSynchronos/UI/Components/DrawGroupPair.cs | 4 +-- MareSynchronos/UI/Components/DrawUserPair.cs | 4 +-- MareSynchronos/UI/Components/GroupPanel.cs | 8 ++--- MareSynchronos/UI/Components/PairGroupsUi.cs | 4 +-- MareSynchronos/UI/EventViewerUI.cs | 2 +- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/MareSynchronos/UI/CompactUI.cs b/MareSynchronos/UI/CompactUI.cs index 27e5979..b77f2bf 100644 --- a/MareSynchronos/UI/CompactUI.cs +++ b/MareSynchronos/UI/CompactUI.cs @@ -275,13 +275,9 @@ public class CompactUi : WindowMediatorSubscriberBase ImGui.InputTextWithHint("##otheruid", "Other players UID/Alias", ref _pairToAdd, 20); ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth() - buttonSize.X); var canAdd = !_pairManager.DirectPairs.Any(p => string.Equals(p.UserData.UID, _pairToAdd, StringComparison.Ordinal) || string.Equals(p.UserData.Alias, _pairToAdd, StringComparison.Ordinal)); - if (!canAdd) + using (ImRaii.Disabled(!canAdd)) { - ImGuiComponents.DisabledButton(FontAwesomeIcon.Plus); - } - else - { - if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Plus)) { _ = _apiController.UserAddPair(new(new(_pairToAdd))); _pairToAdd = string.Empty; @@ -334,13 +330,14 @@ public class CompactUi : WindowMediatorSubscriberBase break; } - var button = _buttonState ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause; - - if (!_timeout.IsRunning || _timeout.ElapsedMilliseconds > 15000) - { + if (_timeout.ElapsedMilliseconds > 5000) _timeout.Reset(); - if (ImGuiComponents.IconButton(button) && UiSharedService.CtrlPressed()) + var button = _buttonState ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause; + + using (ImRaii.Disabled(_timeout.IsRunning)) + { + if (_uiSharedService.IconButton(button) && UiSharedService.CtrlPressed()) { foreach (var entry in users) { @@ -352,13 +349,10 @@ public class CompactUi : WindowMediatorSubscriberBase _timeout.Start(); _buttonState = !_buttonState; } - UiSharedService.AttachToolTip($"Hold Control to {(button == FontAwesomeIcon.Play ? "resume" : "pause")} pairing with {users.Count} out of {userCount} displayed users."); - } - else - { - var availableAt = (15000 - _timeout.ElapsedMilliseconds) / 1000; - ImGuiComponents.DisabledButton(button); - UiSharedService.AttachToolTip($"Next execution is available at {availableAt} seconds"); + if (!_timeout.IsRunning) + UiSharedService.AttachToolTip($"Hold Control to {(button == FontAwesomeIcon.Play ? "resume" : "pause")} pairing with {users.Count} out of {userCount} displayed users."); + else + UiSharedService.AttachToolTip($"Next execution is available at {(5000 - _timeout.ElapsedMilliseconds) / 1000} seconds"); } } @@ -431,7 +425,7 @@ public class CompactUi : WindowMediatorSubscriberBase if (_apiController.ServerState is ServerState.Connected) { ImGui.SetCursorPosX(0 + ImGui.GetStyle().ItemSpacing.X); - if (ImGuiComponents.IconButton(FontAwesomeIcon.UserCircle)) + if (_uiSharedService.IconButton(FontAwesomeIcon.UserCircle)) { Mediator.Publish(new UiToggleMessage(typeof(EditProfileUi))); } @@ -536,7 +530,7 @@ public class CompactUi : WindowMediatorSubscriberBase buttonSizeX -= buttonSize.X - ImGui.GetStyle().ItemSpacing.X * 2; ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth() - buttonSize.X); ImGui.SetCursorPosY(originalPos.Y + uidTextSize.Y / 2 - buttonSize.Y / 2); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Cog)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Cog)) { Mediator.Publish(new OpenSettingsUiMessage()); } @@ -549,7 +543,7 @@ public class CompactUi : WindowMediatorSubscriberBase { buttonSizeX += _uiSharedService.GetIconButtonSize(FontAwesomeIcon.Copy).X - ImGui.GetStyle().ItemSpacing.X * 2; ImGui.SetCursorPosY(originalPos.Y + uidTextSize.Y / 2 - buttonSize.Y / 2); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Copy)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Copy)) { ImGui.SetClipboardText(_apiController.DisplayName); } diff --git a/MareSynchronos/UI/Components/DrawGroupPair.cs b/MareSynchronos/UI/Components/DrawGroupPair.cs index 6649b08..f042364 100644 --- a/MareSynchronos/UI/Components/DrawGroupPair.cs +++ b/MareSynchronos/UI/Components/DrawGroupPair.cs @@ -249,7 +249,7 @@ public class DrawGroupPair : DrawPairBase { ImGui.SetCursorPosY(originalY); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Plus)) { _ = _apiController.UserAddPair(new UserDto(new(_pair.UserData.UID))); } @@ -261,7 +261,7 @@ public class DrawGroupPair : DrawPairBase { ImGui.SetCursorPosY(originalY); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Bars)) { ImGui.OpenPopup("Popup"); } diff --git a/MareSynchronos/UI/Components/DrawUserPair.cs b/MareSynchronos/UI/Components/DrawUserPair.cs index 3b07054..14d4c3a 100644 --- a/MareSynchronos/UI/Components/DrawUserPair.cs +++ b/MareSynchronos/UI/Components/DrawUserPair.cs @@ -172,7 +172,7 @@ public class DrawUserPair : DrawPairBase } ImGui.SameLine(windowEndX - barButtonSize.X - spacingX - pauseIconSize.X); ImGui.SetCursorPosY(originalY); - if (ImGuiComponents.IconButton(pauseIcon)) + if (_uiSharedService.IconButton(pauseIcon)) { var perm = _pair.UserPair!.OwnPermissions; perm.SetPaused(!perm.IsPaused()); @@ -191,7 +191,7 @@ public class DrawUserPair : DrawPairBase ImGui.SameLine(windowEndX - barButtonSize.X); ImGui.SetCursorPosY(originalY); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Bars)) { ImGui.OpenPopup("User Flyout Menu"); } diff --git a/MareSynchronos/UI/Components/GroupPanel.cs b/MareSynchronos/UI/Components/GroupPanel.cs index d51b34b..606fa62 100644 --- a/MareSynchronos/UI/Components/GroupPanel.cs +++ b/MareSynchronos/UI/Components/GroupPanel.cs @@ -88,7 +88,7 @@ internal sealed class GroupPanel || string.Equals(p.Group.GID, _syncShellToJoin, StringComparison.Ordinal)); if (alreadyInGroup) ImGui.BeginDisabled(); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus)) + if (_uiShared.IconButton(FontAwesomeIcon.Plus)) { if (!string.IsNullOrEmpty(_syncShellToJoin)) { @@ -170,7 +170,7 @@ internal sealed class GroupPanel ImGui.AlignTextToFramePadding(); ImGui.TextUnformatted("Syncshell Password: " + _lastCreatedGroup.Password); ImGui.SameLine(); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Copy)) + if (_uiShared.IconButton(FontAwesomeIcon.Copy)) { ImGui.SetClipboardText(_lastCreatedGroup.Password); } @@ -584,7 +584,7 @@ internal sealed class GroupPanel ImGui.SameLine(); } - if (ImGuiComponents.IconButton(pauseIcon)) + if (_uiShared.IconButton(pauseIcon)) { var userPerm = groupDto.GroupUserPermissions ^ GroupUserPermissions.Paused; _ = ApiController.GroupChangeIndividualPermissionState(new GroupPairUserPermissionDto(groupDto.Group, new UserData(ApiController.UID), userPerm)); @@ -592,7 +592,7 @@ internal sealed class GroupPanel UiSharedService.AttachToolTip((groupDto.GroupUserPermissions.IsPaused() ? "Resume" : "Pause") + " pairing with all users in this Syncshell"); ImGui.SameLine(); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars)) + if (_uiShared.IconButton(FontAwesomeIcon.Bars)) { ImGui.OpenPopup("ShellPopup"); } diff --git a/MareSynchronos/UI/Components/PairGroupsUi.cs b/MareSynchronos/UI/Components/PairGroupsUi.cs index 2919984..529371b 100644 --- a/MareSynchronos/UI/Components/PairGroupsUi.cs +++ b/MareSynchronos/UI/Components/PairGroupsUi.cs @@ -54,7 +54,7 @@ public class PairGroupsUi var buttonPauseOffset = windowX + windowWidth - flyoutMenuX - spacingX - pauseButtonX; ImGui.SameLine(buttonPauseOffset); - if (ImGuiComponents.IconButton(pauseButton)) + if (_uiSharedService.IconButton(pauseButton)) { // If all of the currently visible pairs (after applying filters to the pairs) // are paused we display a resume button to resume all currently visible (after filters) @@ -81,7 +81,7 @@ public class PairGroupsUi var buttonDeleteOffset = windowX + windowWidth - flyoutMenuX; ImGui.SameLine(buttonDeleteOffset); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Bars)) { ImGui.OpenPopup("Group Flyout Menu"); } diff --git a/MareSynchronos/UI/EventViewerUI.cs b/MareSynchronos/UI/EventViewerUI.cs index e5a3235..5f0ebc4 100644 --- a/MareSynchronos/UI/EventViewerUI.cs +++ b/MareSynchronos/UI/EventViewerUI.cs @@ -113,7 +113,7 @@ internal class EventViewerUI : WindowMediatorSubscriberBase using (ImRaii.Disabled(_filterFreeText.IsNullOrEmpty())) { ImGui.SameLine(); - if (ImGuiComponents.IconButton(FontAwesomeIcon.Ban)) + if (_uiSharedService.IconButton(FontAwesomeIcon.Ban)) { _filterFreeText = string.Empty; _filteredEvents = RecreateFilter();