mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +01:00
feat: add plugins & settings option to main menu bar system context
This commit is contained in:
parent
c2f5941435
commit
7b2f939003
3 changed files with 53 additions and 20 deletions
|
|
@ -11,7 +11,6 @@ using Dalamud.Memory;
|
|||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
|
||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||
using Serilog;
|
||||
|
||||
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
||||
|
||||
|
|
@ -86,18 +85,6 @@ namespace Dalamud.Game.Gui.ContextMenus
|
|||
|
||||
private ContextMenuAddressResolver Address { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enable this subsystem.
|
||||
/// </summary>
|
||||
public void Enable()
|
||||
{
|
||||
this.contextMenuOpeningHook.Enable();
|
||||
this.contextMenuOpenedHook.Enable();
|
||||
this.contextMenuItemSelectedHook.Enable();
|
||||
this.subContextMenuOpeningHook.Enable();
|
||||
this.subContextMenuOpenedHook.Enable();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
|
|
@ -108,6 +95,18 @@ namespace Dalamud.Game.Gui.ContextMenus
|
|||
this.contextMenuOpeningHook.Disable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable this subsystem.
|
||||
/// </summary>
|
||||
internal void Enable()
|
||||
{
|
||||
this.contextMenuOpeningHook.Enable();
|
||||
this.contextMenuOpenedHook.Enable();
|
||||
this.contextMenuItemSelectedHook.Enable();
|
||||
this.subContextMenuOpeningHook.Enable();
|
||||
this.subContextMenuOpenedHook.Enable();
|
||||
}
|
||||
|
||||
private static unsafe bool IsInventoryContext(AgentContextInterface* agentContextInterface)
|
||||
{
|
||||
return agentContextInterface == AgentInventoryContext.Instance();
|
||||
|
|
@ -129,8 +128,6 @@ namespace Dalamud.Game.Gui.ContextMenus
|
|||
|
||||
private unsafe bool ContextMenuOpenedDetour(AddonContextMenu* addonContextMenu, int atkValueCount, AtkValue* atkValues)
|
||||
{
|
||||
Log.Information("Poop " + Marshal.PtrToStringUTF8(new IntPtr(((AtkUnitBase*)addonContextMenu)->Name)));
|
||||
|
||||
try
|
||||
{
|
||||
this.ContextMenuOpenedImplementation(addonContextMenu, ref atkValueCount, ref atkValues);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
|
||||
namespace Dalamud.Game.Gui.ContextMenus
|
||||
{
|
||||
|
|
@ -13,7 +15,7 @@ namespace Dalamud.Game.Gui.ContextMenus
|
|||
/// <param name="name">The name of the item.</param>
|
||||
/// <param name="opened">The action that will be called when the item is selected.</param>
|
||||
internal OpenSubContextMenuItem(SeString name, ContextMenuOpenedDelegate opened)
|
||||
: base(name)
|
||||
: base(new SeString().Append(new UIForegroundPayload(539)).Append($"{SeIconChar.BoxedLetterD.ToIconString()} ").Append(new UIForegroundPayload(0)).Append(name))
|
||||
{
|
||||
this.Opened = opened;
|
||||
this.Indicator = ContextMenuItemIndicator.Next;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using CheapLoc;
|
||||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Data;
|
||||
using Dalamud.Game.Gui.ContextMenus;
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
|
|
@ -11,6 +12,7 @@ using Dalamud.Hooking;
|
|||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using Serilog;
|
||||
|
||||
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
||||
|
|
@ -31,6 +33,9 @@ namespace Dalamud.Game.Internal
|
|||
|
||||
private readonly Hook<AtkUnitBaseReceiveGlobalEvent> hookAtkUnitBaseReceiveGlobalEvent;
|
||||
|
||||
private readonly string locDalamudPlugins;
|
||||
private readonly string locDalamudSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DalamudAtkTweaks"/> class.
|
||||
/// </summary>
|
||||
|
|
@ -53,6 +58,12 @@ namespace Dalamud.Game.Internal
|
|||
|
||||
var atkUnitBaseReceiveGlobalEventAddress = sigScanner.ScanText("48 89 5C 24 ?? 48 89 7C 24 ?? 55 41 56 41 57 48 8B EC 48 83 EC 50 44 0F B7 F2 ");
|
||||
this.hookAtkUnitBaseReceiveGlobalEvent = new Hook<AtkUnitBaseReceiveGlobalEvent>(atkUnitBaseReceiveGlobalEventAddress, this.AtkUnitBaseReceiveGlobalEventDetour);
|
||||
|
||||
this.locDalamudPlugins = Loc.Localize("SystemMenuPlugins", "Dalamud Plugins");
|
||||
this.locDalamudSettings = Loc.Localize("SystemMenuSettings", "Dalamud Settings");
|
||||
|
||||
var contextMenu = Service<ContextMenu>.Get();
|
||||
contextMenu.ContextMenuOpened += this.ContextMenuOnContextMenuOpened;
|
||||
}
|
||||
|
||||
private delegate void AgentHudOpenSystemMenuPrototype(void* thisPtr, AtkValue* atkValueArgs, uint menuSize);
|
||||
|
|
@ -75,6 +86,27 @@ namespace Dalamud.Game.Internal
|
|||
this.hookAtkUnitBaseReceiveGlobalEvent.Enable();
|
||||
}
|
||||
|
||||
private void ContextMenuOnContextMenuOpened(ContextMenuOpenedArgs args)
|
||||
{
|
||||
var systemText = Service<DataManager>.Get().GetExcelSheet<Addon>()!.GetRow(1059)!.Text.RawString; // "System"
|
||||
var configuration = Service<DalamudConfiguration>.Get();
|
||||
|
||||
if (args.Title == systemText && configuration.DoButtonsSystemMenu)
|
||||
{
|
||||
var dalamudInterface = Service<DalamudInterface>.Get();
|
||||
|
||||
args.Items.Insert(0, new CustomContextMenuItem(this.locDalamudSettings, selectedArgs =>
|
||||
{
|
||||
dalamudInterface.ToggleSettingsWindow();
|
||||
}));
|
||||
|
||||
args.Items.Insert(0, new CustomContextMenuItem(this.locDalamudPlugins, selectedArgs =>
|
||||
{
|
||||
dalamudInterface.TogglePluginInstallerWindow();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private IntPtr AtkUnitBaseReceiveGlobalEventDetour(AtkUnitBase* thisPtr, ushort cmd, uint a3, IntPtr a4, uint* arg)
|
||||
{
|
||||
// Log.Information("{0}: cmd#{1} a3#{2} - HasAnyFocus:{3}", Marshal.PtrToStringAnsi(new IntPtr(thisPtr->Name)), cmd, a3, WindowSystem.HasAnyWindowSystemFocus);
|
||||
|
|
@ -150,11 +182,11 @@ namespace Dalamud.Game.Internal
|
|||
var strPlugins = new SeString().Append(new UIForegroundPayload(color))
|
||||
.Append($"{SeIconChar.BoxedLetterD.ToIconString()} ")
|
||||
.Append(new UIForegroundPayload(0))
|
||||
.Append(Loc.Localize("SystemMenuPlugins", "Dalamud Plugins")).Encode();
|
||||
.Append(this.locDalamudPlugins).Encode();
|
||||
var strSettings = new SeString().Append(new UIForegroundPayload(color))
|
||||
.Append($"{SeIconChar.BoxedLetterD.ToIconString()} ")
|
||||
.Append(new UIForegroundPayload(0))
|
||||
.Append(Loc.Localize("SystemMenuSettings", "Dalamud Settings")).Encode();
|
||||
.Append(this.locDalamudSettings).Encode();
|
||||
|
||||
// do this the most terrible way possible since im lazy
|
||||
var bytes = stackalloc byte[strPlugins.Length + 1];
|
||||
|
|
@ -229,6 +261,8 @@ namespace Dalamud.Game.Internal
|
|||
this.hookAgentHudOpenSystemMenu.Dispose();
|
||||
this.hookUiModuleRequestMainCommand.Dispose();
|
||||
this.hookAtkUnitBaseReceiveGlobalEvent.Dispose();
|
||||
|
||||
Service<ContextMenu>.Get().ContextMenuOpened -= this.ContextMenuOnContextMenuOpened;
|
||||
}
|
||||
|
||||
this.disposed = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue