Merge branch '2.0.0' into dotnet10-api14-migration
This commit is contained in:
@@ -4,6 +4,7 @@ using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.GameFonts;
|
||||
using Dalamud.Interface.ImGuiFileDialog;
|
||||
using Dalamud.Interface.ManagedFontAtlas;
|
||||
using Dalamud.Interface.Textures;
|
||||
using Dalamud.Interface.Textures.TextureWraps;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
@@ -400,10 +401,21 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
|
||||
public static bool ShiftPressed() => (GetKeyState(0xA1) & 0x8000) != 0 || (GetKeyState(0xA0) & 0x8000) != 0;
|
||||
|
||||
public static void TextWrapped(string text, float wrapPos = 0)
|
||||
public static void TextWrapped(string text, float wrapPos = 0, Vector4? color = null)
|
||||
{
|
||||
ImGui.PushTextWrapPos(wrapPos);
|
||||
if (color.HasValue)
|
||||
{
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, color.Value);
|
||||
}
|
||||
|
||||
ImGui.TextUnformatted(text);
|
||||
|
||||
if (color.HasValue)
|
||||
{
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
ImGui.PopTextWrapPos();
|
||||
}
|
||||
|
||||
@@ -519,8 +531,9 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
|
||||
bool changed = ImGui.Checkbox(label, ref value);
|
||||
|
||||
var boxSize = ImGui.GetFrameHeight();
|
||||
var min = pos;
|
||||
var max = ImGui.GetItemRectMax();
|
||||
var max = new Vector2(pos.X + boxSize, pos.Y + boxSize);
|
||||
|
||||
var col = ImGui.GetColorU32(borderColor ?? ImGuiColors.DalamudGrey);
|
||||
ImGui.GetWindowDrawList().AddRect(min, max, col, rounding, ImDrawFlags.None, borderThickness);
|
||||
@@ -1220,6 +1233,100 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
return _textureProvider.CreateFromImageAsync(imageData).Result;
|
||||
}
|
||||
|
||||
private static readonly (bool ItemHq, bool HiRes)[] IconLookupOrders =
|
||||
[
|
||||
(false, true),
|
||||
(true, true),
|
||||
(false, false),
|
||||
(true, false)
|
||||
];
|
||||
|
||||
public bool TryGetIcon(uint iconId, out IDalamudTextureWrap? wrap)
|
||||
{
|
||||
foreach (var (itemHq, hiRes) in IconLookupOrders)
|
||||
{
|
||||
if (TryGetIconWithLookup(iconId, itemHq, hiRes, out wrap))
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var (itemHq, hiRes) in IconLookupOrders)
|
||||
{
|
||||
if (!_textureProvider.TryGetIconPath(new GameIconLookup(iconId, itemHq, hiRes), out var path) || string.IsNullOrEmpty(path))
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
var reference = _textureProvider.GetFromGame(path);
|
||||
if (reference.TryGetWrap(out var texture, out _))
|
||||
{
|
||||
wrap = texture;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogTrace(ex, "Failed to load icon {IconId} from path {Path}", iconId, path);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var hiRes in new[] { true, false })
|
||||
{
|
||||
var manualPath = BuildIconPath(iconId, hiRes);
|
||||
if (TryLoadTextureFromPath(manualPath, iconId, out wrap))
|
||||
return true;
|
||||
}
|
||||
|
||||
wrap = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryLoadTextureFromPath(string path, uint iconId, out IDalamudTextureWrap? wrap)
|
||||
{
|
||||
try
|
||||
{
|
||||
var reference = _textureProvider.GetFromGame(path);
|
||||
if (reference.TryGetWrap(out var texture, out _))
|
||||
{
|
||||
wrap = texture;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogTrace(ex, "Failed to load icon {IconId} from manual path {Path}", iconId, path);
|
||||
}
|
||||
|
||||
wrap = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string BuildIconPath(uint iconId, bool hiRes)
|
||||
{
|
||||
var folder = iconId - iconId % 1000;
|
||||
var basePath = $"ui/icon/{folder:000000}/{iconId:000000}";
|
||||
return hiRes ? $"{basePath}_hr1.tex" : $"{basePath}.tex";
|
||||
}
|
||||
|
||||
private bool TryGetIconWithLookup(uint iconId, bool itemHq, bool hiRes, out IDalamudTextureWrap? wrap)
|
||||
{
|
||||
try
|
||||
{
|
||||
var icon = _textureProvider.GetFromGameIcon(new GameIconLookup(iconId, itemHq, hiRes));
|
||||
if (icon.TryGetWrap(out var texture, out _))
|
||||
{
|
||||
wrap = texture;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogTrace(ex, "Failed to load icon {IconId} (HQ:{ItemHq}, HR:{HiRes})", iconId, itemHq, hiRes);
|
||||
}
|
||||
|
||||
wrap = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LoadLocalization(string languageCode)
|
||||
{
|
||||
_localization.SetupWithLangCode(languageCode);
|
||||
@@ -1286,13 +1393,24 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
num++;
|
||||
}
|
||||
|
||||
ImGui.PushID(text);
|
||||
string displayText = text;
|
||||
string idText = text;
|
||||
int idSeparatorIndex = text.IndexOf("##", StringComparison.Ordinal);
|
||||
if (idSeparatorIndex >= 0)
|
||||
{
|
||||
displayText = text[..idSeparatorIndex];
|
||||
idText = text[(idSeparatorIndex + 2)..];
|
||||
if (string.IsNullOrEmpty(idText))
|
||||
idText = displayText;
|
||||
}
|
||||
|
||||
ImGui.PushID(idText);
|
||||
|
||||
Vector2 vector;
|
||||
using (IconFont.Push())
|
||||
vector = ImGui.CalcTextSize(icon.ToIconString());
|
||||
|
||||
Vector2 vector2 = ImGui.CalcTextSize(text);
|
||||
Vector2 vector2 = ImGui.CalcTextSize(displayText);
|
||||
ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList();
|
||||
Vector2 cursorScreenPos = ImGui.GetCursorScreenPos();
|
||||
float num2 = 3f * ImGuiHelpers.GlobalScale;
|
||||
@@ -1317,7 +1435,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
|
||||
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);
|
||||
windowDrawList.AddText(pos2, ImGui.GetColorU32(ImGuiCol.Text), displayText);
|
||||
ImGui.PopID();
|
||||
if (num > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user