mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-02 13:53:40 +01:00
feat: add toast options
This commit is contained in:
parent
98d441318c
commit
e81356d476
1 changed files with 38 additions and 13 deletions
|
|
@ -8,7 +8,7 @@ using Dalamud.Hooking;
|
|||
|
||||
namespace Dalamud.Game.Internal.Gui
|
||||
{
|
||||
public class ToastGui : IDisposable
|
||||
public sealed class ToastGui : IDisposable
|
||||
{
|
||||
#region Events
|
||||
|
||||
|
|
@ -27,13 +27,13 @@ namespace Dalamud.Game.Internal.Gui
|
|||
|
||||
#endregion
|
||||
|
||||
private delegate IntPtr ShowToastDelegate(IntPtr manager, IntPtr text, int layer, byte bool1, byte bool2, int logMessageId);
|
||||
private delegate IntPtr ShowToastDelegate(IntPtr manager, IntPtr text, int layer, byte isTop, byte isFast, int logMessageId);
|
||||
|
||||
private Dalamud Dalamud { get; }
|
||||
|
||||
private ToastGuiAddressResolver Address { get; }
|
||||
|
||||
private Queue<byte[]> ToastQueue { get; } = new Queue<byte[]>();
|
||||
private Queue<(byte[] message, ToastOptions options)> ToastQueue { get; } = new Queue<(byte[] message, ToastOptions options)>();
|
||||
|
||||
|
||||
public ToastGui(SigScanner scanner, Dalamud dalamud)
|
||||
|
|
@ -61,18 +61,22 @@ namespace Dalamud.Game.Internal.Gui
|
|||
/// Show a toast message with the given content.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be shown</param>
|
||||
public void Show(string message)
|
||||
/// <param name="options">Options for the toast</param>
|
||||
public void Show(string message, ToastOptions options = null)
|
||||
{
|
||||
this.ToastQueue.Enqueue(Encoding.UTF8.GetBytes(message));
|
||||
options ??= new ToastOptions();
|
||||
this.ToastQueue.Enqueue((Encoding.UTF8.GetBytes(message), options));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show a toast message with the given content.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to be shown</param>
|
||||
public void Show(SeString message)
|
||||
/// <param name="options">Options for the toast</param>
|
||||
public void Show(SeString message, ToastOptions options = null)
|
||||
{
|
||||
this.ToastQueue.Enqueue(message.Encode());
|
||||
options ??= new ToastOptions();
|
||||
this.ToastQueue.Enqueue((message.Encode(), options));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -82,13 +86,15 @@ namespace Dalamud.Game.Internal.Gui
|
|||
{
|
||||
while (this.ToastQueue.Count > 0)
|
||||
{
|
||||
var message = this.ToastQueue.Dequeue();
|
||||
this.Show(message);
|
||||
var (message, options) = this.ToastQueue.Dequeue();
|
||||
this.Show(message, options);
|
||||
}
|
||||
}
|
||||
|
||||
private void Show(byte[] bytes)
|
||||
private void Show(byte[] bytes, ToastOptions options = null)
|
||||
{
|
||||
options ??= new ToastOptions();
|
||||
|
||||
var manager = this.Dalamud.Framework.Gui.GetUIModule();
|
||||
|
||||
// terminate the string
|
||||
|
|
@ -100,12 +106,12 @@ namespace Dalamud.Game.Internal.Gui
|
|||
{
|
||||
fixed (byte* ptr = terminated)
|
||||
{
|
||||
this.HandleToastDetour(manager, (IntPtr)ptr, 5, 0, 1, 0);
|
||||
this.HandleToastDetour(manager, (IntPtr)ptr, 5, (byte)options.Position, (byte)options.Speed, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IntPtr HandleToastDetour(IntPtr manager, IntPtr text, int layer, byte bool1, byte bool2, int logMessageId)
|
||||
private IntPtr HandleToastDetour(IntPtr manager, IntPtr text, int layer, byte isTop, byte isFast, int logMessageId)
|
||||
{
|
||||
if (text == IntPtr.Zero)
|
||||
{
|
||||
|
|
@ -145,9 +151,28 @@ namespace Dalamud.Game.Internal.Gui
|
|||
{
|
||||
fixed (byte* message = terminated)
|
||||
{
|
||||
return this.showToastHook.Original(manager, (IntPtr)message, layer, bool1, bool2, logMessageId);
|
||||
return this.showToastHook.Original(manager, (IntPtr)message, layer, isTop, isFast, logMessageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ToastOptions
|
||||
{
|
||||
public ToastPosition Position { get; set; } = ToastPosition.Bottom;
|
||||
|
||||
public ToastSpeed Speed { get; set; } = ToastSpeed.Slow;
|
||||
}
|
||||
|
||||
public enum ToastPosition : byte
|
||||
{
|
||||
Bottom = 0,
|
||||
Top = 1,
|
||||
}
|
||||
|
||||
public enum ToastSpeed : byte
|
||||
{
|
||||
Slow = 0,
|
||||
Fast = 1,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue