mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-13 15:54:14 +01:00
minor refactoring
This commit is contained in:
parent
142c65cc9d
commit
7baca3565a
34 changed files with 554 additions and 627 deletions
|
|
@ -1,8 +1,10 @@
|
|||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.GameFonts;
|
||||
using Dalamud.Interface.ImGuiFileDialog;
|
||||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Interface.ManagedFontAtlas;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Plugin;
|
||||
|
|
@ -28,8 +30,10 @@ namespace MareSynchronos.UI;
|
|||
|
||||
public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
{
|
||||
public const string TooltipSeparator = "--SEP--";
|
||||
|
||||
public static readonly ImGuiWindowFlags PopupWindowFlags = ImGuiWindowFlags.NoResize |
|
||||
ImGuiWindowFlags.NoScrollbar |
|
||||
ImGuiWindowFlags.NoScrollbar |
|
||||
ImGuiWindowFlags.NoScrollWithMouse;
|
||||
|
||||
public readonly FileDialogManager FileDialogManager;
|
||||
|
|
@ -65,12 +69,10 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
private bool _heelsExists = false;
|
||||
|
||||
private bool _honorificExists = false;
|
||||
private bool _moodlesExists = false;
|
||||
private bool _isDirectoryWritable = false;
|
||||
|
||||
private bool _isPenumbraDirectory = false;
|
||||
private bool _isOneDrive = false;
|
||||
|
||||
private bool _isPenumbraDirectory = false;
|
||||
private bool _moodlesExists = false;
|
||||
private bool _penumbraExists = false;
|
||||
|
||||
private int _serverSelectionIndex = -1;
|
||||
|
|
@ -89,14 +91,10 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
_pluginInterface = pluginInterface;
|
||||
_localization = localization;
|
||||
_serverConfigurationManager = serverManager;
|
||||
|
||||
_localization.SetupWithLangCode("en");
|
||||
|
||||
_isDirectoryWritable = IsDirectoryWritable(_configService.Current.CacheFolder);
|
||||
|
||||
_pluginInterface.UiBuilder.BuildFonts += BuildFont;
|
||||
_pluginInterface.UiBuilder.RebuildFonts();
|
||||
|
||||
Mediator.Subscribe<DelayedFrameworkUpdateMessage>(this, (_) =>
|
||||
{
|
||||
_penumbraExists = _ipcManager.Penumbra.APIAvailable;
|
||||
|
|
@ -106,28 +104,35 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
_honorificExists = _ipcManager.Honorific.APIAvailable;
|
||||
_moodlesExists = _ipcManager.Moodles.APIAvailable;
|
||||
});
|
||||
|
||||
UidFont = _pluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(e =>
|
||||
{
|
||||
e.OnPreBuild(tk => tk.AddDalamudAssetFont(Dalamud.DalamudAsset.NotoSansJpMedium, new()
|
||||
{
|
||||
SizePx = 35
|
||||
}));
|
||||
});
|
||||
GameFont = _pluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(new(GameFontFamilyAndSize.Axis12));
|
||||
IconFont = _pluginInterface.UiBuilder.IconFontHandle;
|
||||
}
|
||||
|
||||
public ApiController ApiController => _apiController;
|
||||
|
||||
public bool EditTrackerPosition { get; set; }
|
||||
|
||||
public IFontHandle GameFont { get; init; }
|
||||
public bool HasValidPenumbraModPath => !(_ipcManager.Penumbra.ModDirectory ?? string.Empty).IsNullOrEmpty() && Directory.Exists(_ipcManager.Penumbra.ModDirectory);
|
||||
|
||||
public IFontHandle IconFont { get; init; }
|
||||
public bool IsInGpose => _dalamudUtil.IsInCutscene;
|
||||
|
||||
public string PlayerName => _dalamudUtil.GetPlayerName();
|
||||
|
||||
public ImFontPtr UidFont { get; private set; }
|
||||
|
||||
public bool UidFontBuilt { get; private set; }
|
||||
|
||||
public IFontHandle UidFont { get; init; }
|
||||
public Dictionary<ushort, string> WorldData => _dalamudUtil.WorldData.Value;
|
||||
|
||||
public uint WorldId => _dalamudUtil.GetHomeWorldId();
|
||||
|
||||
public const string TooltipSeparator = "--SEP--";
|
||||
|
||||
public static void AttachToolTip(string text)
|
||||
{
|
||||
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
|
||||
|
|
@ -152,23 +157,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
}
|
||||
}
|
||||
|
||||
public static void BooleanToColoredIcon(bool value, bool inline = true)
|
||||
{
|
||||
using var colorgreen = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.HealerGreen, value);
|
||||
using var colorred = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed, !value);
|
||||
|
||||
if (inline) ImGui.SameLine();
|
||||
|
||||
if (value)
|
||||
{
|
||||
NormalizedIcon(FontAwesomeIcon.Check);
|
||||
}
|
||||
else
|
||||
{
|
||||
NormalizedIcon(FontAwesomeIcon.Times);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ByteToString(long bytes, bool addSuffix = true)
|
||||
{
|
||||
string[] suffix = ["B", "KiB", "MiB", "GiB", "TiB"];
|
||||
|
|
@ -217,13 +205,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
|
||||
public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0;
|
||||
|
||||
public static void DrawHelpText(string helpText)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
NormalizedIcon(FontAwesomeIcon.QuestionCircle, ImGui.GetColorU32(ImGuiCol.TextDisabled));
|
||||
AttachToolTip(helpText);
|
||||
}
|
||||
|
||||
public static void DrawOutlinedFont(string text, Vector4 fontColor, Vector4 outlineColor, int thickness)
|
||||
{
|
||||
var original = ImGui.GetCursorPos();
|
||||
|
|
@ -280,20 +261,16 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
drawList.AddText(textPos, fontColor, text);
|
||||
}
|
||||
|
||||
public static void FontText(string text, ImFontPtr font, Vector4? color = null)
|
||||
{
|
||||
using var pushedFont = ImRaii.PushFont(font);
|
||||
using var pushedColor = ImRaii.PushColor(ImGuiCol.Text, Color(color ?? new Vector4(1, 1, 1, 1)), color != null);
|
||||
ImGui.TextUnformatted(text);
|
||||
}
|
||||
|
||||
public static Vector4 GetBoolColor(bool input) => input ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
|
||||
|
||||
public static Vector2 GetIconButtonSize(FontAwesomeIcon icon)
|
||||
public static float GetIconTextButtonSize(FontAwesomeIcon icon, string text)
|
||||
{
|
||||
using var font = ImRaii.PushFont(UiBuilder.IconFont);
|
||||
var buttonSize = ImGuiHelpers.GetButtonSize(icon.ToIconString());
|
||||
return buttonSize;
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
Vector2 vector = ImGui.CalcTextSize(icon.ToIconString());
|
||||
ImGui.PopFont();
|
||||
Vector2 vector2 = ImGui.CalcTextSize(text);
|
||||
float num = 3f * ImGuiHelpers.GlobalScale;
|
||||
return vector.X + vector2.X + ImGui.GetStyle().FramePadding.X * 2f + num;
|
||||
}
|
||||
|
||||
public static string GetNotes(List<Pair> pairs)
|
||||
|
|
@ -317,147 +294,52 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
return ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
|
||||
}
|
||||
|
||||
public static Vector2 GetNormalizedIconTextButtonSize(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false)
|
||||
public static bool IconButton(FontAwesomeIcon icon)
|
||||
{
|
||||
var iconData = GetIconData(icon);
|
||||
var textSize = ImGui.CalcTextSize(text);
|
||||
var padding = ImGui.GetStyle().FramePadding;
|
||||
var buttonSizeY = ImGui.GetFrameHeight();
|
||||
var iconExtraSpacing = isInPopup ? padding.X * 2 : 0;
|
||||
|
||||
if (width == null || width <= 0)
|
||||
{
|
||||
var buttonSizeX = iconData.NormalizedIconScale.X + (padding.X * 3) + iconExtraSpacing + textSize.X;
|
||||
return new Vector2(buttonSizeX, buttonSizeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector2(width.Value, buttonSizeY);
|
||||
}
|
||||
return ImGuiComponents.IconButton(icon);
|
||||
}
|
||||
|
||||
public static Vector2 NormalizedIconButtonSize(FontAwesomeIcon icon)
|
||||
private static bool IconTextButtonInternal(FontAwesomeIcon icon, string text, Vector4? defaultColor = null, float? width = null)
|
||||
{
|
||||
var iconData = GetIconData(icon);
|
||||
var padding = ImGui.GetStyle().FramePadding;
|
||||
|
||||
return iconData.NormalizedIconScale with { X = iconData.NormalizedIconScale.X + padding.X * 2, Y = iconData.NormalizedIconScale.Y + padding.Y * 2 };
|
||||
}
|
||||
|
||||
public static bool NormalizedIconButton(FontAwesomeIcon icon)
|
||||
{
|
||||
bool wasClicked = false;
|
||||
var iconData = GetIconData(icon);
|
||||
var padding = ImGui.GetStyle().FramePadding;
|
||||
var cursor = ImGui.GetCursorPos();
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var pos = ImGui.GetWindowPos();
|
||||
var scrollPosY = ImGui.GetScrollY();
|
||||
var scrollPosX = ImGui.GetScrollX();
|
||||
|
||||
var buttonSize = NormalizedIconButtonSize(icon);
|
||||
|
||||
if (ImGui.Button("###" + icon.ToIconString(), buttonSize))
|
||||
int num = 0;
|
||||
if (defaultColor.HasValue)
|
||||
{
|
||||
wasClicked = true;
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, defaultColor.Value);
|
||||
num++;
|
||||
}
|
||||
|
||||
drawList.AddText(UiBuilder.IconFont, ImGui.GetFontSize() * iconData.IconScaling,
|
||||
new(pos.X - scrollPosX + cursor.X + iconData.OffsetX + padding.X,
|
||||
pos.Y - scrollPosY + cursor.Y + (buttonSize.Y - (iconData.IconSize.Y * iconData.IconScaling)) / 2f),
|
||||
ImGui.GetColorU32(ImGuiCol.Text), icon.ToIconString());
|
||||
|
||||
return wasClicked;
|
||||
}
|
||||
|
||||
public static bool NormalizedIconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false)
|
||||
{
|
||||
var wasClicked = false;
|
||||
|
||||
var iconData = GetIconData(icon);
|
||||
var textSize = ImGui.CalcTextSize(text);
|
||||
var padding = ImGui.GetStyle().FramePadding;
|
||||
var cursor = ImGui.GetCursorPos();
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var pos = ImGui.GetWindowPos();
|
||||
var scrollPosY = ImGui.GetScrollY();
|
||||
var scrollPosX = ImGui.GetScrollX();
|
||||
|
||||
Vector2 buttonSize = GetNormalizedIconTextButtonSize(icon, text, width, isInPopup);
|
||||
var iconExtraSpacing = isInPopup ? padding.X * 2 : 0;
|
||||
|
||||
using (ImRaii.PushColor(ImGuiCol.Button, ImGui.GetColorU32(ImGuiCol.PopupBg), isInPopup))
|
||||
ImGui.PushID(text);
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
Vector2 vector = ImGui.CalcTextSize(icon.ToIconString());
|
||||
ImGui.PopFont();
|
||||
Vector2 vector2 = ImGui.CalcTextSize(text);
|
||||
ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList();
|
||||
Vector2 cursorScreenPos = ImGui.GetCursorScreenPos();
|
||||
float num2 = 3f * ImGuiHelpers.GlobalScale;
|
||||
float x = width ?? vector.X + vector2.X + ImGui.GetStyle().FramePadding.X * 2f + num2;
|
||||
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();
|
||||
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();
|
||||
if (num > 0)
|
||||
{
|
||||
if (ImGui.Button("###" + icon.ToIconString() + text, buttonSize))
|
||||
{
|
||||
wasClicked = true;
|
||||
}
|
||||
ImGui.PopStyleColor(num);
|
||||
}
|
||||
|
||||
drawList.AddText(UiBuilder.DefaultFont, ImGui.GetFontSize(),
|
||||
new(pos.X - scrollPosX + cursor.X + iconData.NormalizedIconScale.X + (padding.X * 2) + iconExtraSpacing,
|
||||
pos.Y - scrollPosY + cursor.Y + ((buttonSize.Y - textSize.Y) / 2f)),
|
||||
ImGui.GetColorU32(ImGuiCol.Text), text);
|
||||
|
||||
drawList.AddText(UiBuilder.IconFont, ImGui.GetFontSize() * iconData.IconScaling,
|
||||
new(pos.X - scrollPosX + cursor.X + iconData.OffsetX + padding.X,
|
||||
pos.Y - scrollPosY + cursor.Y + (buttonSize.Y - (iconData.IconSize.Y * iconData.IconScaling)) / 2f),
|
||||
ImGui.GetColorU32(ImGuiCol.Text), icon.ToIconString());
|
||||
|
||||
return wasClicked;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void NormalizedIcon(FontAwesomeIcon icon, uint color)
|
||||
public static bool IconTextButton(FontAwesomeIcon icon, string text, float? width = null, bool isInPopup = false)
|
||||
{
|
||||
var cursorPos = ImGui.GetCursorPos();
|
||||
var iconData = GetIconData(icon);
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var windowPos = ImGui.GetWindowPos();
|
||||
var scrollPosX = ImGui.GetScrollX();
|
||||
var scrollPosY = ImGui.GetScrollY();
|
||||
var frameHeight = ImGui.GetFrameHeight();
|
||||
|
||||
var frameOffsetY = ((frameHeight - iconData.IconSize.Y * iconData.IconScaling) / 2f);
|
||||
|
||||
drawList.AddText(UiBuilder.IconFont, UiBuilder.IconFont.FontSize * iconData.IconScaling,
|
||||
new(windowPos.X - scrollPosX + cursorPos.X + iconData.OffsetX,
|
||||
windowPos.Y - scrollPosY + cursorPos.Y + frameOffsetY),
|
||||
color, icon.ToIconString());
|
||||
|
||||
ImGui.Dummy(new(iconData.NormalizedIconScale.X, ImGui.GetFrameHeight()));
|
||||
return IconTextButtonInternal(icon, text,
|
||||
isInPopup ? ColorHelpers.RgbaUintToVector4(ImGui.GetColorU32(ImGuiCol.PopupBg)) : null, width);
|
||||
}
|
||||
|
||||
public static void NormalizedIcon(FontAwesomeIcon icon, Vector4? color = null)
|
||||
{
|
||||
NormalizedIcon(icon, color == null ? ImGui.GetColorU32(ImGuiCol.Text) : ImGui.GetColorU32(color.Value));
|
||||
}
|
||||
|
||||
private static IconScaleData CalcIconScaleData(FontAwesomeIcon icon)
|
||||
{
|
||||
using var font = ImRaii.PushFont(UiBuilder.IconFont);
|
||||
var iconSize = ImGui.CalcTextSize(icon.ToIconString());
|
||||
var iconscaling = (iconSize.X < iconSize.Y ? (iconSize.Y - iconSize.X) / 2f : 0f, iconSize.X > iconSize.Y ? 1f / (iconSize.X / iconSize.Y) : 1f);
|
||||
var normalized = iconscaling.Item2 == 1f ?
|
||||
new Vector2(iconSize.Y, iconSize.Y)
|
||||
: new((iconSize.X * iconscaling.Item2) + (iconscaling.Item1 * 2), (iconSize.X * iconscaling.Item2) + (iconscaling.Item1 * 2));
|
||||
return new(iconSize, normalized, iconscaling.Item1, iconscaling.Item2);
|
||||
}
|
||||
|
||||
public static IconScaleData GetIconData(FontAwesomeIcon icon)
|
||||
{
|
||||
if (_iconData.TryGetValue(ImGuiHelpers.GlobalScale, out var iconCache))
|
||||
{
|
||||
if (iconCache.TryGetValue(icon, out var iconData)) return iconData;
|
||||
return iconCache[icon] = CalcIconScaleData(icon);
|
||||
}
|
||||
|
||||
_iconData.Add(ImGuiHelpers.GlobalScale, new());
|
||||
return _iconData[ImGuiHelpers.GlobalScale][icon] = CalcIconScaleData(icon);
|
||||
}
|
||||
|
||||
public sealed record IconScaleData(Vector2 IconSize, Vector2 NormalizedIconScale, float OffsetX, float IconScaling);
|
||||
private static Dictionary<float, Dictionary<FontAwesomeIcon, IconScaleData>> _iconData = new();
|
||||
|
||||
public static bool IsDirectoryWritable(string dirPath, bool throwIfFails = false)
|
||||
{
|
||||
try
|
||||
|
|
@ -549,10 +431,26 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
return true;
|
||||
}
|
||||
|
||||
public void BigText(string text)
|
||||
public void BigText(string text, Vector4? color = null)
|
||||
{
|
||||
using var font = ImRaii.PushFont(UidFont, UidFontBuilt);
|
||||
ImGui.TextUnformatted(text);
|
||||
FontText(text, UidFont, color);
|
||||
}
|
||||
|
||||
public void BooleanToColoredIcon(bool value, bool inline = true)
|
||||
{
|
||||
using var colorgreen = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.HealerGreen, value);
|
||||
using var colorred = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed, !value);
|
||||
|
||||
if (inline) ImGui.SameLine();
|
||||
|
||||
if (value)
|
||||
{
|
||||
IconText(FontAwesomeIcon.Check);
|
||||
}
|
||||
else
|
||||
{
|
||||
IconText(FontAwesomeIcon.Times);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawCacheDirectorySetting()
|
||||
|
|
@ -564,7 +462,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.SameLine();
|
||||
using (ImRaii.Disabled(_cacheMonitor.MareWatcher != null))
|
||||
{
|
||||
if (NormalizedIconButton(FontAwesomeIcon.Folder))
|
||||
if (IconButton(FontAwesomeIcon.Folder))
|
||||
{
|
||||
FileDialogManager.OpenFolderDialog("Pick Mare Synchronos Storage Folder", (success, path) =>
|
||||
{
|
||||
|
|
@ -630,7 +528,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
}
|
||||
|
||||
public T? DrawCombo<T>(string comboName, IEnumerable<T> comboItems, Func<T, string> toName,
|
||||
Action<T>? onSelected = null, T? initialSelectedItem = default)
|
||||
Action<T?>? onSelected = null, T? initialSelectedItem = default)
|
||||
{
|
||||
if (!comboItems.Any()) return default;
|
||||
|
||||
|
|
@ -654,7 +552,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
{
|
||||
foreach (var item in comboItems)
|
||||
{
|
||||
bool isSelected = EqualityComparer<T>.Default.Equals(item, (T)selectedItem);
|
||||
bool isSelected = EqualityComparer<T>.Default.Equals(item, (T?)selectedItem);
|
||||
if (ImGui.Selectable(toName(item), isSelected))
|
||||
{
|
||||
_selectedComboItems[comboName] = item!;
|
||||
|
|
@ -704,7 +602,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
if (_configService.Current.InitialScanComplete)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
if (NormalizedIconTextButton(FontAwesomeIcon.Play, "Force rescan"))
|
||||
if (IconTextButton(FontAwesomeIcon.Play, "Force rescan"))
|
||||
{
|
||||
_cacheMonitor.InvokeScan();
|
||||
}
|
||||
|
|
@ -712,16 +610,23 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
}
|
||||
}
|
||||
|
||||
public void DrawHelpText(string helpText)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
IconText(FontAwesomeIcon.QuestionCircle, ImGui.GetColorU32(ImGuiCol.TextDisabled));
|
||||
AttachToolTip(helpText);
|
||||
}
|
||||
|
||||
public bool DrawOtherPluginState()
|
||||
{
|
||||
var check = FontAwesomeIcon.Check.ToIconString();
|
||||
var cross = FontAwesomeIcon.SquareXmark.ToIconString();
|
||||
var check = FontAwesomeIcon.Check;
|
||||
var cross = FontAwesomeIcon.SquareXmark;
|
||||
ImGui.TextUnformatted("Mandatory Plugins:");
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted("Penumbra");
|
||||
ImGui.SameLine();
|
||||
FontText(_penumbraExists ? check : cross, UiBuilder.IconFont, GetBoolColor(_penumbraExists));
|
||||
IconText(_penumbraExists ? check : cross, GetBoolColor(_penumbraExists));
|
||||
ImGui.SameLine();
|
||||
AttachToolTip($"Penumbra is " + (_penumbraExists ? "available and up to date." : "unavailable or not up to date."));
|
||||
ImGui.Spacing();
|
||||
|
|
@ -729,7 +634,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted("Glamourer");
|
||||
ImGui.SameLine();
|
||||
FontText(_glamourerExists ? check : cross, UiBuilder.IconFont, GetBoolColor(_glamourerExists));
|
||||
IconText(_glamourerExists ? check : cross, GetBoolColor(_glamourerExists));
|
||||
ImGui.SameLine();
|
||||
AttachToolTip($"Glamourer is " + (_glamourerExists ? "available and up to date." : "unavailable or not up to date."));
|
||||
ImGui.Spacing();
|
||||
|
|
@ -738,7 +643,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted("SimpleHeels");
|
||||
ImGui.SameLine();
|
||||
FontText(_heelsExists ? check : cross, UiBuilder.IconFont, GetBoolColor(_heelsExists));
|
||||
IconText(_heelsExists ? check : cross, GetBoolColor(_heelsExists));
|
||||
ImGui.SameLine();
|
||||
AttachToolTip($"SimpleHeels is " + (_heelsExists ? "available and up to date." : "unavailable or not up to date."));
|
||||
ImGui.Spacing();
|
||||
|
|
@ -746,7 +651,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted("Customize+");
|
||||
ImGui.SameLine();
|
||||
FontText(_customizePlusExists ? check : cross, UiBuilder.IconFont, GetBoolColor(_customizePlusExists));
|
||||
IconText(_customizePlusExists ? check : cross, GetBoolColor(_customizePlusExists));
|
||||
ImGui.SameLine();
|
||||
AttachToolTip($"Customize+ is " + (_customizePlusExists ? "available and up to date." : "unavailable or not up to date."));
|
||||
ImGui.Spacing();
|
||||
|
|
@ -754,7 +659,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted("Honorific");
|
||||
ImGui.SameLine();
|
||||
FontText(_honorificExists ? check : cross, UiBuilder.IconFont, GetBoolColor(_honorificExists));
|
||||
IconText(_honorificExists ? check : cross, GetBoolColor(_honorificExists));
|
||||
ImGui.SameLine();
|
||||
AttachToolTip($"Honorific is " + (_honorificExists ? "available and up to date." : "unavailable or not up to date."));
|
||||
ImGui.Spacing();
|
||||
|
|
@ -762,7 +667,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted("Moodles");
|
||||
ImGui.SameLine();
|
||||
FontText(_moodlesExists ? check : cross, UiBuilder.IconFont, GetBoolColor(_moodlesExists));
|
||||
IconText(_moodlesExists ? check : cross, GetBoolColor(_moodlesExists));
|
||||
ImGui.SameLine();
|
||||
AttachToolTip($"Moodles is " + (_moodlesExists ? "available and up to date." : "unavailable or not up to date."));
|
||||
ImGui.Spacing();
|
||||
|
|
@ -821,7 +726,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.SameLine();
|
||||
var text = "Connect";
|
||||
if (_serverSelectionIndex == _serverConfigurationManager.CurrentServerIndex) text = "Reconnect";
|
||||
if (NormalizedIconTextButton(FontAwesomeIcon.Link, text))
|
||||
if (IconTextButton(FontAwesomeIcon.Link, text))
|
||||
{
|
||||
_serverConfigurationManager.SelectServer(_serverSelectionIndex);
|
||||
_ = _apiController.CreateConnections();
|
||||
|
|
@ -834,7 +739,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
ImGui.InputText("Custom Service URI", ref _customServerUri, 255);
|
||||
ImGui.SetNextItemWidth(250);
|
||||
ImGui.InputText("Custom Service Name", ref _customServerName, 255);
|
||||
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Plus, "Add Custom Service")
|
||||
if (IconTextButton(FontAwesomeIcon.Plus, "Add Custom Service")
|
||||
&& !string.IsNullOrEmpty(_customServerUri)
|
||||
&& !string.IsNullOrEmpty(_customServerName))
|
||||
{
|
||||
|
|
@ -853,6 +758,40 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
return _serverSelectionIndex;
|
||||
}
|
||||
|
||||
public Vector2 GetIconButtonSize(FontAwesomeIcon icon)
|
||||
{
|
||||
using var font = IconFont.Push();
|
||||
var buttonSize = ImGuiHelpers.GetButtonSize(icon.ToIconString());
|
||||
return buttonSize;
|
||||
}
|
||||
|
||||
public Vector2 GetIconData(FontAwesomeIcon icon)
|
||||
{
|
||||
using var font = IconFont.Push();
|
||||
return ImGui.CalcTextSize(icon.ToIconString());
|
||||
}
|
||||
|
||||
public Vector2 IconButtonSize(FontAwesomeIcon icon)
|
||||
{
|
||||
using var font = IconFont.Push();
|
||||
return ImGuiHelpers.GetButtonSize(icon.ToIconString());
|
||||
}
|
||||
|
||||
public void IconText(FontAwesomeIcon icon, uint color)
|
||||
{
|
||||
FontText(icon.ToIconString(), IconFont, color);
|
||||
}
|
||||
|
||||
public void IconText(FontAwesomeIcon icon, Vector4? color = null)
|
||||
{
|
||||
IconText(icon, color == null ? ImGui.GetColorU32(ImGuiCol.Text) : ImGui.GetColorU32(color.Value));
|
||||
}
|
||||
|
||||
public IDalamudTextureWrap LoadImage(byte[] imageData)
|
||||
{
|
||||
return _pluginInterface.UiBuilder.LoadImage(imageData);
|
||||
}
|
||||
|
||||
public void LoadLocalization(string languageCode)
|
||||
{
|
||||
_localization.SetupWithLangCode(languageCode);
|
||||
|
|
@ -862,54 +801,26 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
|||
[LibraryImport("user32")]
|
||||
internal static partial short GetKeyState(int nVirtKey);
|
||||
|
||||
internal ImFontPtr GetGameFontHandle()
|
||||
{
|
||||
return _pluginInterface.UiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont;
|
||||
}
|
||||
|
||||
internal IDalamudTextureWrap LoadImage(byte[] imageData)
|
||||
{
|
||||
return _pluginInterface.UiBuilder.LoadImage(imageData);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
_pluginInterface.UiBuilder.BuildFonts -= BuildFont;
|
||||
}
|
||||
|
||||
private static void CenterWindow(float width, float height, ImGuiCond cond = ImGuiCond.None)
|
||||
{
|
||||
var center = ImGui.GetMainViewport().GetCenter();
|
||||
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
|
||||
[GeneratedRegex(@"^(?:[a-zA-Z]:\\[\w\s\-\\]+?|\/(?:[\w\s\-\/])+?)$", RegexOptions.ECMAScript, 5000)]
|
||||
private static partial Regex PathRegex();
|
||||
|
||||
private void BuildFont()
|
||||
private void FontText(string text, IFontHandle font, Vector4? color = null)
|
||||
{
|
||||
var fontFile = Path.Combine(_pluginInterface.DalamudAssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf");
|
||||
UidFontBuilt = false;
|
||||
|
||||
if (File.Exists(fontFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
UidFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontFile, 35);
|
||||
UidFontBuilt = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Font failed to load. {fontFile}", fontFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogDebug("Font doesn't exist. {fontFile}", fontFile);
|
||||
}
|
||||
FontText(text, font, color == null ? ImGui.GetColorU32(ImGuiCol.Text) : ImGui.GetColorU32(color.Value));
|
||||
}
|
||||
|
||||
private void FontText(string text, IFontHandle font, uint color)
|
||||
{
|
||||
using var pushedFont = font.Push();
|
||||
using var pushedColor = ImRaii.PushColor(ImGuiCol.Text, color);
|
||||
ImGui.TextUnformatted(text);
|
||||
}
|
||||
|
||||
public sealed record IconScaleData(Vector2 IconSize, Vector2 NormalizedIconScale, float OffsetX, float IconScaling);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue