mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Renew IPC mechanism
This commit is contained in:
parent
db23235191
commit
041485cad4
4 changed files with 64 additions and 13 deletions
40
Penumbra.GameData/Enums/ChangedItemType.cs
Normal file
40
Penumbra.GameData/Enums/ChangedItemType.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
using System;
|
||||||
|
using Lumina.Excel.GeneratedSheets;
|
||||||
|
using Action = Lumina.Excel.GeneratedSheets.Action;
|
||||||
|
|
||||||
|
namespace Penumbra.GameData.Enums
|
||||||
|
{
|
||||||
|
public enum ChangedItemType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Item,
|
||||||
|
Action,
|
||||||
|
Customization,
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ChangedItemExtensions
|
||||||
|
{
|
||||||
|
public static (ChangedItemType, uint) ChangedItemToTypeAndId( object? item )
|
||||||
|
{
|
||||||
|
return item switch
|
||||||
|
{
|
||||||
|
null => ( ChangedItemType.None, 0 ),
|
||||||
|
Item i => ( ChangedItemType.Item, i.RowId ),
|
||||||
|
Action a => ( ChangedItemType.Action, a.RowId ),
|
||||||
|
_ => ( ChangedItemType.Customization, 0 ),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object? GetObject( this ChangedItemType type, uint id )
|
||||||
|
{
|
||||||
|
return type switch
|
||||||
|
{
|
||||||
|
ChangedItemType.None => null,
|
||||||
|
ChangedItemType.Item => ObjectIdentification.DataManager?.GetExcelSheet< Item >()?.GetRow( id ),
|
||||||
|
ChangedItemType.Action => ObjectIdentification.DataManager?.GetExcelSheet< Action >()?.GetRow( id ),
|
||||||
|
ChangedItemType.Customization => null,
|
||||||
|
_ => throw new ArgumentOutOfRangeException( nameof( type ), type, null )
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Dalamud;
|
using Dalamud;
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
using Dalamud.Plugin;
|
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
using Penumbra.GameData.Enums;
|
using Penumbra.GameData.Enums;
|
||||||
using Penumbra.GameData.Structs;
|
using Penumbra.GameData.Structs;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ namespace Penumbra.GameData
|
||||||
{
|
{
|
||||||
internal class ObjectIdentification : IObjectIdentifier
|
internal class ObjectIdentification : IObjectIdentifier
|
||||||
{
|
{
|
||||||
|
public static DataManager? DataManager = null!;
|
||||||
private readonly List< (ulong, HashSet< Item >) > _weapons;
|
private readonly List< (ulong, HashSet< Item >) > _weapons;
|
||||||
private readonly List< (ulong, HashSet< Item >) > _equipment;
|
private readonly List< (ulong, HashSet< Item >) > _equipment;
|
||||||
private readonly Dictionary< string, HashSet< Action > > _actions;
|
private readonly Dictionary< string, HashSet< Action > > _actions;
|
||||||
|
|
@ -66,6 +67,7 @@ namespace Penumbra.GameData
|
||||||
|
|
||||||
public ObjectIdentification( DataManager dataManager, ClientLanguage clientLanguage )
|
public ObjectIdentification( DataManager dataManager, ClientLanguage clientLanguage )
|
||||||
{
|
{
|
||||||
|
DataManager = dataManager;
|
||||||
var items = dataManager.GetExcelSheet< Item >( clientLanguage )!;
|
var items = dataManager.GetExcelSheet< Item >( clientLanguage )!;
|
||||||
SortedList< ulong, HashSet< Item > > weapons = new();
|
SortedList< ulong, HashSet< Item > > weapons = new();
|
||||||
SortedList< ulong, HashSet< Item > > equipment = new();
|
SortedList< ulong, HashSet< Item > > equipment = new();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using Dalamud.Game.ClientState.Objects.Types;
|
using Dalamud.Game.ClientState.Objects.Types;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Logging;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Ipc;
|
||||||
using Penumbra.GameData.Enums;
|
using Penumbra.GameData.Enums;
|
||||||
|
|
||||||
namespace Penumbra.Api
|
namespace Penumbra.Api
|
||||||
|
|
@ -18,14 +19,14 @@ namespace Penumbra.Api
|
||||||
public const string LabelProviderChangedItemTooltip = "Penumbra.ChangedItemTooltip";
|
public const string LabelProviderChangedItemTooltip = "Penumbra.ChangedItemTooltip";
|
||||||
public const string LabelProviderChangedItemClick = "Penumbra.ChangedItemClick";
|
public const string LabelProviderChangedItemClick = "Penumbra.ChangedItemClick";
|
||||||
|
|
||||||
internal ICallGateProvider< int >? ProviderApiVersion;
|
internal ICallGateProvider< int >? ProviderApiVersion;
|
||||||
internal ICallGateProvider< string, int, object >? ProviderRedrawName;
|
internal ICallGateProvider< string, int, object >? ProviderRedrawName;
|
||||||
internal ICallGateProvider< GameObject, int, object >? ProviderRedrawObject;
|
internal ICallGateProvider< GameObject, int, object >? ProviderRedrawObject;
|
||||||
internal ICallGateProvider< int, object >? ProviderRedrawAll;
|
internal ICallGateProvider< int, object >? ProviderRedrawAll;
|
||||||
internal ICallGateProvider< string, string >? ProviderResolveDefault;
|
internal ICallGateProvider< string, string >? ProviderResolveDefault;
|
||||||
internal ICallGateProvider< string, string, string >? ProviderResolveCharacter;
|
internal ICallGateProvider< string, string, string >? ProviderResolveCharacter;
|
||||||
internal ICallGateProvider< object?, object >? ProviderChangedItemTooltip;
|
internal ICallGateProvider< ChangedItemType, uint, object >? ProviderChangedItemTooltip;
|
||||||
internal ICallGateProvider< int, object?, object >? ProviderChangedItemClick;
|
internal ICallGateProvider< MouseButton, ChangedItemType, uint, object >? ProviderChangedItemClick;
|
||||||
|
|
||||||
internal readonly IPenumbraApi Api;
|
internal readonly IPenumbraApi Api;
|
||||||
|
|
||||||
|
|
@ -41,7 +42,16 @@ namespace Penumbra.Api
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClick( MouseButton click, object? item )
|
private void OnClick( MouseButton click, object? item )
|
||||||
=> ProviderChangedItemClick?.SendMessage( ( int )click, item );
|
{
|
||||||
|
var (type, id) = ChangedItemExtensions.ChangedItemToTypeAndId( item );
|
||||||
|
ProviderChangedItemClick?.SendMessage( click, type, id );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTooltip( object? item )
|
||||||
|
{
|
||||||
|
var (type, id) = ChangedItemExtensions.ChangedItemToTypeAndId( item );
|
||||||
|
ProviderChangedItemTooltip?.SendMessage( type, id );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public PenumbraIpc( DalamudPluginInterface pi, IPenumbraApi api )
|
public PenumbraIpc( DalamudPluginInterface pi, IPenumbraApi api )
|
||||||
|
|
@ -114,8 +124,8 @@ namespace Penumbra.Api
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderChangedItemTooltip = pi.GetIpcProvider< object?, object >( LabelProviderChangedItemTooltip );
|
ProviderChangedItemTooltip = pi.GetIpcProvider< ChangedItemType, uint, object >( LabelProviderChangedItemTooltip );
|
||||||
api.ChangedItemTooltip += ProviderChangedItemTooltip.SendMessage;
|
api.ChangedItemTooltip += OnTooltip;
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
|
|
@ -124,7 +134,7 @@ namespace Penumbra.Api
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderChangedItemClick = pi.GetIpcProvider< int, object?, object >( LabelProviderChangedItemClick );
|
ProviderChangedItemClick = pi.GetIpcProvider< MouseButton, ChangedItemType, uint, object >( LabelProviderChangedItemClick );
|
||||||
api.ChangedItemClicked += OnClick;
|
api.ChangedItemClicked += OnClick;
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue