mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-21 07:17:45 +01:00
Switch INotificationManager and ITitleScreenMenu to use ISharedImmediateTexture (#1879)
* Switch INotificationManager and ITitleScreenMenu to use ISharedImmediateTexture #1879 * Remove SetIconTexture Remove some remarks that no longer apply * Cleanup StyleCop warnings
This commit is contained in:
parent
577977350f
commit
19ba6a961f
13 changed files with 176 additions and 274 deletions
|
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
|||
using Dalamud.Game.Text;
|
||||
using Dalamud.Interface.ImGuiNotification;
|
||||
using Dalamud.Interface.ImGuiNotification.Internal;
|
||||
using Dalamud.Interface.Textures;
|
||||
using Dalamud.Interface.Textures.Internal;
|
||||
using Dalamud.Interface.Textures.TextureWraps;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Storage.Assets;
|
||||
using Dalamud.Utility;
|
||||
|
||||
using ImGuiNET;
|
||||
|
||||
|
|
@ -144,8 +144,6 @@ internal class ImGuiWidget : IDataWindowWidget
|
|||
"Action Bar (always on if not user dismissable for the example)",
|
||||
ref this.notificationTemplate.ActionBar);
|
||||
|
||||
ImGui.Checkbox("Leave Textures Open", ref this.notificationTemplate.LeaveTexturesOpen);
|
||||
|
||||
if (ImGui.Button("Add notification"))
|
||||
{
|
||||
var text =
|
||||
|
|
@ -212,35 +210,34 @@ internal class ImGuiWidget : IDataWindowWidget
|
|||
switch (this.notificationTemplate.IconInt)
|
||||
{
|
||||
case 5:
|
||||
n.SetIconTexture(
|
||||
DisposeLoggingTextureWrap.Wrap(
|
||||
dam.GetDalamudTextureWrap(
|
||||
Enum.Parse<DalamudAsset>(
|
||||
NotificationTemplate.AssetSources[this.notificationTemplate.IconAssetInt]))),
|
||||
this.notificationTemplate.LeaveTexturesOpen);
|
||||
break;
|
||||
case 6:
|
||||
n.SetIconTexture(
|
||||
dam.GetDalamudTextureWrapAsync(
|
||||
Enum.Parse<DalamudAsset>(
|
||||
NotificationTemplate.AssetSources[this.notificationTemplate.IconAssetInt]))
|
||||
.ContinueWith(
|
||||
r => r.IsCompletedSuccessfully
|
||||
? Task.FromResult<IDalamudTextureWrap>(DisposeLoggingTextureWrap.Wrap(r.Result))
|
||||
: r).Unwrap(),
|
||||
this.notificationTemplate.LeaveTexturesOpen);
|
||||
var textureWrap = DisposeLoggingTextureWrap.Wrap(
|
||||
dam.GetDalamudTextureWrap(
|
||||
Enum.Parse<DalamudAsset>(
|
||||
NotificationTemplate.AssetSources[this.notificationTemplate.IconAssetInt])));
|
||||
|
||||
if (textureWrap != null)
|
||||
{
|
||||
n.IconTexture = new ForwardingSharedImmediateTexture(textureWrap);
|
||||
}
|
||||
|
||||
break;
|
||||
case 7:
|
||||
n.SetIconTexture(
|
||||
DisposeLoggingTextureWrap.Wrap(
|
||||
tm.Shared.GetFromGame(this.notificationTemplate.IconText).GetWrapOrDefault()),
|
||||
this.notificationTemplate.LeaveTexturesOpen);
|
||||
var textureWrap2 = DisposeLoggingTextureWrap.Wrap(
|
||||
tm.Shared.GetFromGame(this.notificationTemplate.IconText).GetWrapOrDefault());
|
||||
if (textureWrap2 != null)
|
||||
{
|
||||
n.IconTexture = new ForwardingSharedImmediateTexture(textureWrap2);
|
||||
}
|
||||
|
||||
break;
|
||||
case 8:
|
||||
n.SetIconTexture(
|
||||
DisposeLoggingTextureWrap.Wrap(
|
||||
tm.Shared.GetFromFile(this.notificationTemplate.IconText).GetWrapOrDefault()),
|
||||
this.notificationTemplate.LeaveTexturesOpen);
|
||||
var textureWrap3 = DisposeLoggingTextureWrap.Wrap(
|
||||
tm.Shared.GetFromFile(this.notificationTemplate.IconText).GetWrapOrDefault());
|
||||
if (textureWrap3 != null)
|
||||
{
|
||||
n.IconTexture = new ForwardingSharedImmediateTexture(textureWrap3);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -303,15 +300,15 @@ internal class ImGuiWidget : IDataWindowWidget
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Replace images using setter"))
|
||||
{
|
||||
foreach (var n in this.notifications)
|
||||
{
|
||||
var i = (uint)Random.Shared.NextInt64(0, 200000);
|
||||
n.IconTexture = DisposeLoggingTextureWrap.Wrap(
|
||||
Service<TextureManager>.Get().Shared.GetFromGameIcon(new(i)).GetWrapOrDefault());
|
||||
|
||||
n.IconTexture = Service<TextureManager>.Get().Shared.GetFromGameIcon(new(i, false, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -428,7 +425,6 @@ internal class ImGuiWidget : IDataWindowWidget
|
|||
public bool Minimized;
|
||||
public bool UserDismissable;
|
||||
public bool ActionBar;
|
||||
public bool LeaveTexturesOpen;
|
||||
public int ProgressMode;
|
||||
|
||||
public void Reset()
|
||||
|
|
@ -450,7 +446,6 @@ internal class ImGuiWidget : IDataWindowWidget
|
|||
this.Minimized = true;
|
||||
this.UserDismissable = true;
|
||||
this.ActionBar = true;
|
||||
this.LeaveTexturesOpen = true;
|
||||
this.ProgressMode = 0;
|
||||
this.RespectUiHidden = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ using ImGuiNET;
|
|||
|
||||
using Lumina.Text.ReadOnly;
|
||||
|
||||
using Serilog;
|
||||
|
||||
using LSeStringBuilder = Lumina.Text.SeStringBuilder;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows;
|
||||
|
|
@ -185,6 +187,23 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
if (!entry.IsShowConditionSatisfied())
|
||||
continue;
|
||||
|
||||
if (entry.Texture.TryGetWrap(out var textureWrap, out var exception))
|
||||
{
|
||||
if (textureWrap.Width != 64 && textureWrap.Height != 64)
|
||||
{
|
||||
Log.Error("Texture provided for ITitleScreenMenuEntry must be 64x64. Entry will be removed.");
|
||||
this.titleScreenMenu.RemoveEntry(entry);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
Log.Error(exception, "An exception occurred while attempting to get the texture wrap for a ITitleScreenMenuEntry. Entry will be removed.");
|
||||
this.titleScreenMenu.RemoveEntry(entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this.moveEasings.TryGetValue(entry.Id, out var moveEasing))
|
||||
{
|
||||
moveEasing = new InOutQuint(TimeSpan.FromMilliseconds(400));
|
||||
|
|
@ -259,6 +278,23 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
if (!entry.IsShowConditionSatisfied())
|
||||
continue;
|
||||
|
||||
if (entry.Texture.TryGetWrap(out var textureWrap, out var exception))
|
||||
{
|
||||
if (textureWrap.Width != 64 && textureWrap.Height != 64)
|
||||
{
|
||||
Log.Error($"Texture provided for ITitleScreenMenuEntry {entry.Name} must be 64x64. Entry will be removed.");
|
||||
this.titleScreenMenu.RemoveEntry(entry);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
Log.Error(exception, $"An exception occurred while attempting to get the texture wrap for ITitleScreenMenuEntry {entry.Name}. Entry will be removed.");
|
||||
this.titleScreenMenu.RemoveEntry(entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
var finalPos = (i + 1) * this.shadeTexture.Value.Height * scale;
|
||||
|
||||
this.DrawEntry(entry, i != 0, true, i == 0, false, false);
|
||||
|
|
@ -374,7 +410,9 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 1f);
|
||||
}
|
||||
|
||||
ImGui.Image(entry.Texture.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize * scale));
|
||||
// Wrap should always be valid at this point due to us checking the validity of the image each frame
|
||||
var dalamudTextureWrap = entry.Texture.GetWrapOrEmpty();
|
||||
ImGui.Image(dalamudTextureWrap.ImGuiHandle, new Vector2(TitleScreenMenu.TextureSize * scale));
|
||||
if (overrideAlpha || isFirst)
|
||||
{
|
||||
ImGui.PopStyleVar();
|
||||
|
|
@ -388,7 +426,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
var textHeight = ImGui.GetTextLineHeightWithSpacing();
|
||||
var cursor = ImGui.GetCursorPos();
|
||||
|
||||
cursor.Y += (entry.Texture.Height * scale / 2) - (textHeight / 2);
|
||||
cursor.Y += (dalamudTextureWrap.Height * scale / 2) - (textHeight / 2);
|
||||
|
||||
if (overrideAlpha)
|
||||
{
|
||||
|
|
@ -411,7 +449,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
|
|||
ImGui.PopStyleVar();
|
||||
}
|
||||
|
||||
initialCursor.Y += entry.Texture.Height * scale;
|
||||
initialCursor.Y += dalamudTextureWrap.Height * scale;
|
||||
ImGui.SetCursorPos(initialCursor);
|
||||
|
||||
return isHover;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue