rework creation of popout windows into factory and some refactoring in general

This commit is contained in:
rootdarkarchon
2023-10-27 02:51:26 +02:00
parent a8bc5386ea
commit 5c9415b6e9
15 changed files with 239 additions and 260 deletions

View File

@@ -115,21 +115,22 @@ public class CompactUi : WindowMediatorSubscriberBase
$"It is highly recommended to keep Mare Synchronos up to date. Open /xlplugins and update the plugin.", ImGuiColors.DalamudRed);
}
UiSharedService.DrawWithID("header", DrawUIDHeader);
using (ImRaii.PushId("header")) DrawUIDHeader();
ImGui.Separator();
UiSharedService.DrawWithID("serverstatus", DrawServerStatus);
using (ImRaii.PushId("serverstatus")) DrawServerStatus();
ImGui.Separator();
if (_apiController.ServerState is ServerState.Connected)
{
UiSharedService.DrawWithID("global-topmenu", () => _tabMenu.Draw());
UiSharedService.DrawWithID("pairlist", DrawPairList);
using (ImRaii.PushId("global-topmenu")) _tabMenu.Draw();
using (ImRaii.PushId("pairlist")) DrawPairs();
TransferPartHeight = ImGui.GetCursorPosY();
ImGui.Separator();
UiSharedService.DrawWithID("transfers", DrawTransfers);
using (ImRaii.PushId("transfers")) DrawTransfers();
TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight - ImGui.GetTextLineHeight();
UiSharedService.DrawWithID("group-user-popup", () => _selectPairsForGroupUi.Draw(_pairManager.DirectPairs));
UiSharedService.DrawWithID("grouping-popup", () => _selectGroupForPairUi.Draw());
using (ImRaii.PushId("group-user-popup")) _selectPairsForGroupUi.Draw(_pairManager.DirectPairs);
using (ImRaii.PushId("grouping-popup")) _selectGroupForPairUi.Draw();
}
if (_configService.Current.OpenPopupOnAdd && _pairManager.LastAddedUser != null)
@@ -173,12 +174,6 @@ public class CompactUi : WindowMediatorSubscriberBase
}
}
private void DrawPairList()
{
UiSharedService.DrawWithID("pairs", DrawPairs);
TransferPartHeight = ImGui.GetCursorPosY();
}
private void DrawPairs()
{
var ySize = TransferPartHeight == 0
@@ -277,14 +272,16 @@ public class CompactUi : WindowMediatorSubscriberBase
if (_apiController.ServerState is not (ServerState.Reconnecting or ServerState.Disconnecting))
{
ImGui.PushStyleColor(ImGuiCol.Text, color);
if (ImGuiComponents.IconButton(connectedIcon))
using (ImRaii.PushColor(ImGuiCol.Text, color))
{
_serverManager.CurrentServer.FullPause = !_serverManager.CurrentServer.FullPause;
_serverManager.Save();
_ = _apiController.CreateConnections();
if (ImGuiComponents.IconButton(connectedIcon))
{
_serverManager.CurrentServer.FullPause = !_serverManager.CurrentServer.FullPause;
_serverManager.Save();
_ = _apiController.CreateConnections();
}
}
ImGui.PopStyleColor();
UiSharedService.AttachToolTip(!_serverManager.CurrentServer.FullPause ? "Disconnect from " + _serverManager.CurrentServer.ServerName : "Connect to " + _serverManager.CurrentServer.ServerName);
}
}
@@ -292,9 +289,7 @@ public class CompactUi : WindowMediatorSubscriberBase
private void DrawTransfers()
{
var currentUploads = _fileTransferManager.CurrentUploads.ToList();
ImGui.PushFont(UiBuilder.IconFont);
ImGui.TextUnformatted(FontAwesomeIcon.Upload.ToIconString());
ImGui.PopFont();
UiSharedService.FontText(FontAwesomeIcon.Upload.ToIconString(), UiBuilder.IconFont);
ImGui.SameLine(35 * ImGuiHelpers.GlobalScale);
if (currentUploads.Any())
@@ -317,9 +312,7 @@ public class CompactUi : WindowMediatorSubscriberBase
}
var currentDownloads = _currentDownloads.SelectMany(d => d.Value.Values).ToList();
ImGui.PushFont(UiBuilder.IconFont);
ImGui.TextUnformatted(FontAwesomeIcon.Download.ToIconString());
ImGui.PopFont();
UiSharedService.FontText(FontAwesomeIcon.Download.ToIconString(), UiBuilder.IconFont);
ImGui.SameLine(35 * ImGuiHelpers.GlobalScale);
if (currentDownloads.Any())

View File

@@ -99,10 +99,7 @@ public abstract class DrawFolderBase : IDrawFolder
}
if (ImGui.BeginPopup("User Flyout Menu"))
{
UiSharedService.DrawWithID($"buttons-{_id}", () =>
{
DrawMenu(_menuWidth);
});
using (ImRaii.PushId($"buttons-{_id}")) DrawMenu(_menuWidth);
_menuWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
ImGui.EndPopup();
}

View File

@@ -408,7 +408,7 @@ public class DrawUserPair
}
if (ImGui.BeginPopup("User Flyout Menu"))
{
UiSharedService.DrawWithID($"buttons-{_pair.UserData.UID}", () =>
using (ImRaii.PushId($"buttons-{_pair.UserData.UID}"))
{
ImGui.TextUnformatted("Common Pair Functions");
DrawCommonClientMenu();
@@ -418,7 +418,7 @@ public class DrawUserPair
{
_menuRenderWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
}
});
}
ImGui.EndPopup();
}

View File

@@ -1,6 +1,7 @@
using Dalamud.Interface;
using Dalamud.Interface.Components;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility;
using ImGuiNET;
using MareSynchronos.PlayerData.Pairs;
@@ -66,7 +67,7 @@ public class SelectTagForPairUi
{
foreach (var tag in tags)
{
UiSharedService.DrawWithID($"groups-pair-{_pair.UserData.UID}-{tag}", () => DrawGroupName(_pair, tag));
using (ImRaii.PushId($"groups-pair-{_pair.UserData.UID}-{tag}")) DrawGroupName(_pair, tag);
}
ImGui.EndChild();
}

View File

@@ -95,9 +95,8 @@ public class IdDisplayHandler
{
ImGui.AlignTextToFramePadding();
if (textIsUid) ImGui.PushFont(UiBuilder.MonoFont);
ImGui.TextUnformatted(playerText);
if (textIsUid) ImGui.PopFont();
using (ImRaii.PushFont(UiBuilder.MonoFont, textIsUid)) ImGui.TextUnformatted(playerText);
if (ImGui.IsItemHovered())
{
if (!string.Equals(_lastMouseOverUid, id))

View File

@@ -1,5 +1,6 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility;
using ImGuiNET;
using MareSynchronos.FileCache;
@@ -62,9 +63,7 @@ public class IntroUi : WindowMediatorSubscriberBase
if (!_configService.Current.AcceptedAgreement && !_readFirstPage)
{
if (_uiShared.UidFontBuilt) ImGui.PushFont(_uiShared.UidFont);
ImGui.TextUnformatted("Welcome to Mare Synchronos");
if (_uiShared.UidFontBuilt) ImGui.PopFont();
_uiShared.BigText("Welcome to Mare Synchronos");
ImGui.Separator();
UiSharedService.TextWrapped("Mare Synchronos is a plugin that will replicate your full current character state including all Penumbra mods to other paired Mare Synchronos users. " +
"Note that you will have to have Penumbra as well as Glamourer installed to use this plugin.");

View File

@@ -2,6 +2,7 @@
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
using MareSynchronos.API.Data.Extensions;
using MareSynchronos.MareConfiguration;
@@ -110,9 +111,9 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
var rectMin = drawList.GetClipRectMin();
var rectMax = drawList.GetClipRectMax();
if (_uiSharedService.UidFontBuilt) ImGui.PushFont(_uiSharedService.UidFont);
UiSharedService.ColorText(_pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
if (_uiSharedService.UidFontBuilt) ImGui.PopFont();
using (ImRaii.PushFont(_uiSharedService.UidFont, _uiSharedService.UidFontBuilt))
UiSharedService.ColorText(_pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
ImGui.Dummy(new(spacing.Y, spacing.Y));
var textPos = ImGui.GetCursorPosY();
ImGui.Separator();

View File

@@ -20,6 +20,7 @@ using MareSynchronos.WebAPI.Files.Models;
using MareSynchronos.WebAPI.SignalR.Utils;
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;
using System.Globalization;
using System.Numerics;
using System.Text.Json;
@@ -249,14 +250,14 @@ public class SettingsUi : WindowMediatorSubscriberBase
foreach (var transfer in _fileTransferManager.CurrentUploads.ToArray())
{
var color = UiSharedService.UploadColor((transfer.Transferred, transfer.Total));
ImGui.PushStyleColor(ImGuiCol.Text, color);
var col = ImRaii.PushColor(ImGuiCol.Text, color);
ImGui.TableNextColumn();
ImGui.TextUnformatted(transfer.Hash);
ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Transferred));
ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Total));
ImGui.PopStyleColor();
col.Dispose();
ImGui.TableNextRow();
}
@@ -282,13 +283,13 @@ public class SettingsUi : WindowMediatorSubscriberBase
ImGui.TextUnformatted(userName);
ImGui.TableNextColumn();
ImGui.TextUnformatted(entry.Key);
ImGui.PushStyleColor(ImGuiCol.Text, color);
var col = ImRaii.PushColor(ImGuiCol.Text, color);
ImGui.TableNextColumn();
ImGui.TextUnformatted(entry.Value.TransferredFiles + "/" + entry.Value.TotalFiles);
ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(entry.Value.TransferredBytes) + "/" + UiSharedService.ByteToString(entry.Value.TotalBytes));
ImGui.TableNextColumn();
ImGui.PopStyleColor();
col.Dispose();
ImGui.TableNextRow();
}
}
@@ -352,7 +353,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
}
UiSharedService.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended.");
if (!logPerformance) ImGui.BeginDisabled();
using var disabled = ImRaii.Disabled(!logPerformance);
if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog"))
{
_performanceCollector.PrintPerformanceStats();
@@ -362,7 +363,6 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
_performanceCollector.PrintPerformanceStats(60);
}
if (!logPerformance) ImGui.EndDisabled();
}
private void DrawFileStorageSettings()
@@ -763,7 +763,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
}
UiSharedService.DrawHelpText("Enabling this will show a small notification (type: Info) in the bottom right corner when pairs go online.");
if (!onlineNotifs) ImGui.BeginDisabled();
using var disabled = ImRaii.Disabled(!onlineNotifs);
if (ImGui.Checkbox("Notify only for individual pairs", ref onlineNotifsPairsOnly))
{
_configService.Current.ShowOnlineNotificationsOnlyForIndividualPairs = onlineNotifsPairsOnly;
@@ -776,7 +776,6 @@ public class SettingsUi : WindowMediatorSubscriberBase
_configService.Save();
}
UiSharedService.DrawHelpText("Enabling this will only show online notifications (type: Info) for pairs where you have set an individual note.");
if (!onlineNotifs) ImGui.EndDisabled();
}
private void DrawServerConfiguration()
@@ -885,59 +884,58 @@ public class SettingsUi : WindowMediatorSubscriberBase
int i = 0;
foreach (var item in selectedServer.Authentications.ToList())
{
UiSharedService.DrawWithID("selectedChara" + i, () =>
using var charaId = ImRaii.PushId("selectedChara" + i);
var worldIdx = (ushort)item.WorldId;
var data = _uiShared.WorldData.OrderBy(u => u.Value, StringComparer.Ordinal).ToDictionary(k => k.Key, k => k.Value);
if (!data.TryGetValue(worldIdx, out string? worldPreview))
{
var worldIdx = (ushort)item.WorldId;
var data = _uiShared.WorldData.OrderBy(u => u.Value, StringComparer.Ordinal).ToDictionary(k => k.Key, k => k.Value);
if (!data.TryGetValue(worldIdx, out string? worldPreview))
worldPreview = data.First().Value;
}
var secretKeyIdx = item.SecretKeyIdx;
var keys = selectedServer.SecretKeys;
if (!keys.TryGetValue(secretKeyIdx, out var secretKey))
{
secretKey = new();
}
var friendlyName = secretKey.FriendlyName;
if (ImGui.TreeNode($"chara", $"Character: {item.CharacterName}, World: {worldPreview}, Secret Key: {friendlyName}"))
{
var charaName = item.CharacterName;
if (ImGui.InputText("Character Name", ref charaName, 64))
{
worldPreview = data.First().Value;
item.CharacterName = charaName;
_serverConfigurationManager.Save();
}
var secretKeyIdx = item.SecretKeyIdx;
var keys = selectedServer.SecretKeys;
if (!keys.TryGetValue(secretKeyIdx, out var secretKey))
{
secretKey = new();
}
var friendlyName = secretKey.FriendlyName;
if (ImGui.TreeNode($"chara", $"Character: {item.CharacterName}, World: {worldPreview}, Secret Key: {friendlyName}"))
{
var charaName = item.CharacterName;
if (ImGui.InputText("Character Name", ref charaName, 64))
_uiShared.DrawCombo("World##" + item.CharacterName + i, data, (w) => w.Value,
(w) =>
{
item.CharacterName = charaName;
_serverConfigurationManager.Save();
}
_uiShared.DrawCombo("World##" + item.CharacterName + i, data, (w) => w.Value,
(w) =>
if (item.WorldId != w.Key)
{
if (item.WorldId != w.Key)
{
item.WorldId = w.Key;
_serverConfigurationManager.Save();
}
}, EqualityComparer<KeyValuePair<ushort, string>>.Default.Equals(data.FirstOrDefault(f => f.Key == worldIdx), default) ? data.First() : data.First(f => f.Key == worldIdx));
item.WorldId = w.Key;
_serverConfigurationManager.Save();
}
}, EqualityComparer<KeyValuePair<ushort, string>>.Default.Equals(data.FirstOrDefault(f => f.Key == worldIdx), default) ? data.First() : data.First(f => f.Key == worldIdx));
_uiShared.DrawCombo("Secret Key##" + item.CharacterName + i, keys, (w) => w.Value.FriendlyName,
(w) =>
_uiShared.DrawCombo("Secret Key##" + item.CharacterName + i, keys, (w) => w.Value.FriendlyName,
(w) =>
{
if (w.Key != item.SecretKeyIdx)
{
if (w.Key != item.SecretKeyIdx)
{
item.SecretKeyIdx = w.Key;
_serverConfigurationManager.Save();
}
}, EqualityComparer<KeyValuePair<int, SecretKey>>.Default.Equals(keys.FirstOrDefault(f => f.Key == item.SecretKeyIdx), default) ? keys.First() : keys.First(f => f.Key == item.SecretKeyIdx));
item.SecretKeyIdx = w.Key;
_serverConfigurationManager.Save();
}
}, EqualityComparer<KeyValuePair<int, SecretKey>>.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())
_serverConfigurationManager.RemoveCharacterFromServer(idx, item);
UiSharedService.AttachToolTip("Hold CTRL to delete this entry.");
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Character") && UiSharedService.CtrlPressed())
_serverConfigurationManager.RemoveCharacterFromServer(idx, item);
UiSharedService.AttachToolTip("Hold CTRL to delete this entry.");
ImGui.TreePop();
}
});
ImGui.TreePop();
}
i++;
}
@@ -970,34 +968,32 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
foreach (var item in selectedServer.SecretKeys.ToList())
{
UiSharedService.DrawWithID("key" + item.Key, () =>
using var id = ImRaii.PushId("key" + item.Key);
var friendlyName = item.Value.FriendlyName;
if (ImGui.InputText("Secret Key Display Name", ref friendlyName, 255))
{
var friendlyName = item.Value.FriendlyName;
if (ImGui.InputText("Secret Key Display Name", ref friendlyName, 255))
item.Value.FriendlyName = friendlyName;
_serverConfigurationManager.Save();
}
var key = item.Value.Key;
if (ImGui.InputText("Secret Key", ref key, 64))
{
item.Value.Key = key;
_serverConfigurationManager.Save();
}
if (!selectedServer.Authentications.Exists(p => p.SecretKeyIdx == item.Key))
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Secret Key") && UiSharedService.CtrlPressed())
{
item.Value.FriendlyName = friendlyName;
selectedServer.SecretKeys.Remove(item.Key);
_serverConfigurationManager.Save();
}
var key = item.Value.Key;
if (ImGui.InputText("Secret Key", ref key, 64))
{
item.Value.Key = key;
_serverConfigurationManager.Save();
}
if (!selectedServer.Authentications.Exists(p => p.SecretKeyIdx == item.Key))
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Secret Key") && UiSharedService.CtrlPressed())
{
selectedServer.SecretKeys.Remove(item.Key);
_serverConfigurationManager.Save();
}
UiSharedService.AttachToolTip("Hold CTRL to delete this secret key entry");
}
else
{
UiSharedService.ColorTextWrapped("This key is in use and cannot be deleted", ImGuiColors.DalamudYellow);
}
});
UiSharedService.AttachToolTip("Hold CTRL to delete this secret key entry");
}
else
{
UiSharedService.ColorTextWrapped("This key is in use and cannot be deleted", ImGuiColors.DalamudYellow);
}
if (item.Key != selectedServer.SecretKeys.Keys.LastOrDefault())
ImGui.Separator();
@@ -1136,7 +1132,21 @@ public class SettingsUi : WindowMediatorSubscriberBase
private void DrawSettingsContent()
{
_uiShared.PrintServerState();
if (_apiController.ServerState is ServerState.Connected)
{
ImGui.TextUnformatted("Service " + _serverConfigurationManager.CurrentServer!.ServerName + ":");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, "Available");
ImGui.SameLine();
ImGui.TextUnformatted("(");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.OnlineUsers.ToString(CultureInfo.InvariantCulture));
ImGui.SameLine();
ImGui.TextUnformatted("Users Online");
ImGui.SameLine();
ImGui.TextUnformatted(")");
}
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("Community and Support:");
ImGui.SameLine();

View File

@@ -2,6 +2,7 @@
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
using MareSynchronos.API.Data.Extensions;
using MareSynchronos.PlayerData.Pairs;
@@ -76,9 +77,9 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
var rectMax = drawList.GetClipRectMax();
var headerSize = ImGui.GetCursorPosY() - ImGui.GetStyle().WindowPadding.Y;
if (_uiSharedService.UidFontBuilt) ImGui.PushFont(_uiSharedService.UidFont);
UiSharedService.ColorText(Pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
if (_uiSharedService.UidFontBuilt) ImGui.PopFont();
using (ImRaii.PushFont(_uiSharedService.UidFont, _uiSharedService.UidFontBuilt))
UiSharedService.ColorText(Pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
ImGuiHelpers.ScaledDummy(new Vector2(spacing.Y, spacing.Y));
var textPos = ImGui.GetCursorPosY() - headerSize;
ImGui.Separator();

View File

@@ -24,7 +24,8 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
private int _multiInvites;
private string _newPassword;
private bool _pwChangeSuccess;
public SyncshellAdminUI(ILogger<SyncshellAdminUI> logger, MareMediator mediator, GroupFullInfoDto groupFullInfo, ApiController apiController, UiSharedService uiSharedService, PairManager pairManager)
public SyncshellAdminUI(ILogger<SyncshellAdminUI> logger, MareMediator mediator, ApiController apiController,
UiSharedService uiSharedService, PairManager pairManager, GroupFullInfoDto groupFullInfo)
: base(logger, mediator, "Syncshell Admin Panel (" + groupFullInfo.GID + ")")
{
GroupFullInfo = groupFullInfo;

View File

@@ -207,16 +207,14 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public static void ColorText(string text, Vector4 color)
{
ImGui.PushStyleColor(ImGuiCol.Text, color);
using var raiicolor = ImRaii.PushColor(ImGuiCol.Text, color);
ImGui.TextUnformatted(text);
ImGui.PopStyleColor();
}
public static void ColorTextWrapped(string text, Vector4 color)
{
ImGui.PushStyleColor(ImGuiCol.Text, color);
using var raiicolor = ImRaii.PushColor(ImGuiCol.Text, color);
TextWrapped(text);
ImGui.PopStyleColor();
}
public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0;
@@ -224,18 +222,19 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public static void DrawHelpText(string helpText)
{
ImGui.SameLine();
ImGui.PushFont(UiBuilder.IconFont);
ImGui.SetWindowFontScale(0.8f);
ImGui.TextDisabled(FontAwesomeIcon.Question.ToIconString());
ImGui.SetWindowFontScale(1.0f);
ImGui.PopFont();
using (ImRaii.PushFont(UiBuilder.IconFont))
{
ImGui.SetWindowFontScale(0.8f);
ImGui.TextDisabled(FontAwesomeIcon.Question.ToIconString());
ImGui.SetWindowFontScale(1.0f);
}
if (ImGui.IsItemHovered())
{
ImGui.BeginTooltip();
using var tooltip = ImRaii.Tooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * 35.0f);
ImGui.TextUnformatted(helpText);
ImGui.PopTextWrapPos();
ImGui.EndTooltip();
}
}
@@ -243,31 +242,34 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
{
var original = ImGui.GetCursorPos();
ImGui.PushStyleColor(ImGuiCol.Text, outlineColor);
ImGui.SetCursorPos(original with { Y = original.Y - thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { Y = original.Y + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y - thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y - thickness });
ImGui.TextUnformatted(text);
ImGui.PopStyleColor();
using (ImRaii.PushColor(ImGuiCol.Text, outlineColor))
{
ImGui.PushStyleColor(ImGuiCol.Text, outlineColor);
ImGui.SetCursorPos(original with { Y = original.Y - thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { Y = original.Y + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y - thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y + thickness });
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y - thickness });
ImGui.TextUnformatted(text);
}
ImGui.PushStyleColor(ImGuiCol.Text, fontColor);
ImGui.SetCursorPos(original);
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original);
ImGui.TextUnformatted(text);
ImGui.PopStyleColor();
using (ImRaii.PushColor(ImGuiCol.Text, fontColor))
{
ImGui.SetCursorPos(original);
ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original);
ImGui.TextUnformatted(text);
}
}
public static void DrawOutlinedFont(ImDrawListPtr drawList, string text, Vector2 textPos, uint fontColor, uint outlineColor, int thickness)
@@ -293,13 +295,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
drawList.AddText(textPos, fontColor, text);
}
public static void DrawWithID(string id, Action drawSubSection)
{
ImGui.PushID(id);
drawSubSection.Invoke();
ImGui.PopID();
}
public static void FontText(string text, ImFontPtr font, Vector4? color = null)
{
using var pushedFont = ImRaii.PushFont(font);
@@ -309,22 +304,17 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public static Vector4 GetBoolColor(bool input) => input ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
public static Vector4 GetCpuLoadColor(double input) => input < 50 ? ImGuiColors.ParsedGreen :
input < 90 ? ImGuiColors.DalamudYellow : ImGuiColors.DalamudRed;
public static Vector2 GetIconButtonSize(FontAwesomeIcon icon)
{
ImGui.PushFont(UiBuilder.IconFont);
using var font = ImRaii.PushFont(UiBuilder.IconFont);
var buttonSize = ImGuiHelpers.GetButtonSize(icon.ToIconString());
ImGui.PopFont();
return buttonSize;
}
public static Vector2 GetIconSize(FontAwesomeIcon icon)
{
ImGui.PushFont(UiBuilder.IconFont);
using var font = ImRaii.PushFont(UiBuilder.IconFont);
var iconSize = ImGui.CalcTextSize(icon.ToIconString());
ImGui.PopFont();
return iconSize;
}
@@ -449,23 +439,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
}
}
public static void OutlineTextWrapped(string text, Vector4 textcolor, Vector4 outlineColor, float dist = 3)
{
var cursorPos = ImGui.GetCursorPos();
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X, cursorPos.Y + dist));
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X + dist, cursorPos.Y));
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X + dist, cursorPos.Y + dist));
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X + dist / 2, cursorPos.Y + dist / 2));
ColorTextWrapped(text, textcolor);
ImGui.SetCursorPos(new(cursorPos.X + dist / 2, cursorPos.Y + dist / 2));
ColorTextWrapped(text, textcolor);
}
public static void SetScaledWindowSize(float width, bool centerWindow = true)
{
var newLineHeight = ImGui.GetCursorPosY();
@@ -537,9 +510,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public void BigText(string text)
{
if (UidFontBuilt) ImGui.PushFont(UidFont);
using var font = ImRaii.PushFont(UidFont, UidFontBuilt);
ImGui.TextUnformatted(text);
if (UidFontBuilt) ImGui.PopFont();
}
public void DrawCacheDirectorySetting()
@@ -854,24 +826,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
Strings.ToS = new Strings.ToSStrings();
}
public void PrintServerState()
{
if (_apiController.ServerState is ServerState.Connected)
{
ImGui.TextUnformatted("Service " + _serverConfigurationManager.CurrentServer!.ServerName + ":");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, "Available");
ImGui.SameLine();
ImGui.TextUnformatted("(");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.OnlineUsers.ToString(CultureInfo.InvariantCulture));
ImGui.SameLine();
ImGui.TextUnformatted("Users Online");
ImGui.SameLine();
ImGui.TextUnformatted(")");
}
}
public void RecalculateFileCacheSize()
{
_cacheScanner.InvokeScan(forced: true);
@@ -903,7 +857,9 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
ImGui.SetWindowPos(new Vector2(center.X - width / 2, center.Y - height / 2), cond);
}
#pragma warning disable MA0009 // Add regex evaluation timeout
[GeneratedRegex(@"^(?:[a-zA-Z]:\\[\w\s\-\\]+?|\/(?:[\w\s\-\/])+?)$", RegexOptions.ECMAScript)]
#pragma warning restore MA0009 // Add regex evaluation timeout
private static partial Regex PathRegex();
private void BuildFont()