mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +01:00
Update IconBrowserWidget
This commit is contained in:
parent
5eadfc1b4d
commit
2920d18afa
1 changed files with 35 additions and 43 deletions
|
|
@ -1,12 +1,10 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
using Dalamud.Data;
|
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Utility;
|
using Dalamud.Interface.Utility;
|
||||||
using Dalamud.Utility;
|
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
||||||
namespace Dalamud.Interface.Internal.Windows.Data.Widgets;
|
namespace Dalamud.Interface.Internal.Windows.Data.Widgets;
|
||||||
|
|
@ -54,7 +52,8 @@ public class IconBrowserWidget : IDataWindowWidget
|
||||||
|
|
||||||
if (ImGui.BeginChild("ScrollableSection", ImGui.GetContentRegionAvail(), false, ImGuiWindowFlags.NoMove))
|
if (ImGui.BeginChild("ScrollableSection", ImGui.GetContentRegionAvail(), false, ImGuiWindowFlags.NoMove))
|
||||||
{
|
{
|
||||||
var itemsPerRow = (int)MathF.Floor(ImGui.GetContentRegionMax().X / (this.iconSize.X + ImGui.GetStyle().ItemSpacing.X));
|
var itemsPerRow = (int)MathF.Floor(
|
||||||
|
ImGui.GetContentRegionMax().X / (this.iconSize.X + ImGui.GetStyle().ItemSpacing.X));
|
||||||
var itemHeight = this.iconSize.Y + ImGui.GetStyle().ItemSpacing.Y;
|
var itemHeight = this.iconSize.Y + ImGui.GetStyle().ItemSpacing.Y;
|
||||||
|
|
||||||
ImGuiClip.ClippedDraw(this.valueRange, this.DrawIcon, itemsPerRow, itemHeight);
|
ImGuiClip.ClippedDraw(this.valueRange, this.DrawIcon, itemsPerRow, itemHeight);
|
||||||
|
|
@ -114,17 +113,13 @@ public class IconBrowserWidget : IDataWindowWidget
|
||||||
|
|
||||||
private void DrawIcon(int iconId)
|
private void DrawIcon(int iconId)
|
||||||
{
|
{
|
||||||
|
var texm = Service<TextureManager>.Get();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var cursor = ImGui.GetCursorScreenPos();
|
var cursor = ImGui.GetCursorScreenPos();
|
||||||
|
var texture = texm.ImmediateGetFromGameIcon(new((uint)iconId));
|
||||||
|
|
||||||
if (!this.IsIconValid(iconId))
|
if (texm.ImmediateGetStateFromGameIcon(new((uint)iconId), out var exc) || exc is null)
|
||||||
{
|
|
||||||
this.nullValues.Add(iconId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Service<TextureManager>.Get().GetIcon((uint)iconId) is { } texture)
|
|
||||||
{
|
{
|
||||||
ImGui.Image(texture.ImGuiHandle, this.iconSize);
|
ImGui.Image(texture.ImGuiHandle, this.iconSize);
|
||||||
|
|
||||||
|
|
@ -136,7 +131,8 @@ public class IconBrowserWidget : IDataWindowWidget
|
||||||
var scale = GetImageScaleFactor(texture);
|
var scale = GetImageScaleFactor(texture);
|
||||||
|
|
||||||
var textSize = ImGui.CalcTextSize(iconId.ToString());
|
var textSize = ImGui.CalcTextSize(iconId.ToString());
|
||||||
ImGui.SetCursorPosX(texture.Size.X * scale / 2.0f - textSize.X / 2.0f + ImGui.GetStyle().FramePadding.X * 2.0f);
|
ImGui.SetCursorPosX(
|
||||||
|
texture.Size.X * scale / 2.0f - textSize.X / 2.0f + ImGui.GetStyle().FramePadding.X * 2.0f);
|
||||||
ImGui.Text(iconId.ToString());
|
ImGui.Text(iconId.ToString());
|
||||||
|
|
||||||
ImGui.Image(texture.ImGuiHandle, texture.Size * scale);
|
ImGui.Image(texture.ImGuiHandle, texture.Size * scale);
|
||||||
|
|
@ -155,7 +151,10 @@ public class IconBrowserWidget : IDataWindowWidget
|
||||||
this.nullValues.Add(iconId);
|
this.nullValues.Add(iconId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.GetWindowDrawList().AddRect(cursor, cursor + this.iconSize, ImGui.GetColorU32(ImGuiColors.DalamudWhite));
|
ImGui.GetWindowDrawList().AddRect(
|
||||||
|
cursor,
|
||||||
|
cursor + this.iconSize,
|
||||||
|
ImGui.GetColorU32(ImGuiColors.DalamudWhite));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
@ -195,13 +194,6 @@ public class IconBrowserWidget : IDataWindowWidget
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the icon has a valid filepath, and exists in the game data.
|
|
||||||
private bool IsIconValid(int iconId)
|
|
||||||
{
|
|
||||||
var filePath = Service<TextureManager>.Get().GetIconPath((uint)iconId);
|
|
||||||
return !filePath.IsNullOrEmpty() && Service<DataManager>.Get().FileExists(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RecalculateIndexRange()
|
private void RecalculateIndexRange()
|
||||||
{
|
{
|
||||||
if (this.stopRange <= this.startRange || this.stopRange <= 0 || this.startRange < 0)
|
if (this.stopRange <= this.startRange || this.stopRange <= 0 || this.startRange < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue