feat: use new context menus

This commit is contained in:
Anna 2022-06-06 16:35:29 -04:00
parent 472f0885e8
commit af52ebd8bd
5 changed files with 39 additions and 17 deletions

View File

@ -6,6 +6,7 @@ using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Game.Gui; using Dalamud.Game.Gui;
using Dalamud.Game.Gui.ContextMenus;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.Plugin; using Dalamud.Plugin;
using RoleplayersToolbox.Tools; using RoleplayersToolbox.Tools;
@ -37,6 +38,9 @@ namespace RoleplayersToolbox {
[PluginService] [PluginService]
internal CommandManager CommandManager { get; init; } = null!; internal CommandManager CommandManager { get; init; } = null!;
[PluginService]
internal ContextMenu ContextMenu { get; init; } = null!;
[PluginService] [PluginService]
internal DataManager DataManager { get; init; } = null!; internal DataManager DataManager { get; init; } = null!;
@ -61,7 +65,7 @@ namespace RoleplayersToolbox {
public Plugin() { public Plugin() {
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration(); this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
this.Common = new XivCommonBase(Hooks.ContextMenu | Hooks.PartyFinderListings); this.Common = new XivCommonBase(Hooks.PartyFinderListings);
this.Tools.Add(new HousingTool(this)); this.Tools.Add(new HousingTool(this));
this.Tools.Add(new TargetingTool(this)); this.Tools.Add(new TargetingTool(this));

View File

@ -53,8 +53,8 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.5"/> <PackageReference Include="DalamudPackager" Version="2.1.7"/>
<PackageReference Include="F23.StringSimilarity" Version="4.1.0"/> <PackageReference Include="F23.StringSimilarity" Version="5.0.0"/>
<PackageReference Include="XivCommon" Version="4.0.0-alpha.2"/> <PackageReference Include="XivCommon" Version="5.0.1-alpha.1"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,5 +1,6 @@
name: The Roleplayer's Toolbox name: The Roleplayer's Toolbox
author: ascclemens author: ascclemens
punchline: "The Roleplayer's Toolbox"
description: |- description: |-
A collection of useful tools for roleplayers. A collection of useful tools for roleplayers.

View File

@ -14,6 +14,9 @@ namespace RoleplayersToolbox.Tools.Housing {
[HousingArea.Goblet] = new() { [HousingArea.Goblet] = new() {
[4] = 1966113, // Goblet Exchange [4] = 1966113, // Goblet Exchange
}, },
[HousingArea.Mist] = new() {
[46] = 1966095, // Central Mist Subdivision
},
[HousingArea.Shirogane] = new() { [HousingArea.Shirogane] = new() {
[5] = 1966135, // Southern Shirogane [5] = 1966135, // Southern Shirogane
}, },

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Dalamud.Game; using Dalamud.Game;
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Game.Gui.ContextMenus;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI;
@ -10,7 +11,6 @@ using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI; using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET; using ImGuiNET;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
using XivCommon.Functions.ContextMenu;
namespace RoleplayersToolbox.Tools.Housing { namespace RoleplayersToolbox.Tools.Housing {
internal class HousingTool : BaseTool, IDisposable { internal class HousingTool : BaseTool, IDisposable {
@ -58,7 +58,7 @@ namespace RoleplayersToolbox.Tools.Housing {
this._addonMapHide = Marshal.GetDelegateForFunctionPointer<AddonMapHideDelegate>(addonMapHidePtr); this._addonMapHide = Marshal.GetDelegateForFunctionPointer<AddonMapHideDelegate>(addonMapHidePtr);
} }
this.Plugin.Common.Functions.ContextMenu.OpenContextMenu += this.OnContextMenu; this.Plugin.ContextMenu.ContextMenuOpened += this.OnContextMenu;
this.Plugin.Framework.Update += this.OnFramework; this.Plugin.Framework.Update += this.OnFramework;
this.Plugin.CommandManager.AddHandler("/route", new CommandInfo(this.OnRouteCommand) { this.Plugin.CommandManager.AddHandler("/route", new CommandInfo(this.OnRouteCommand) {
HelpMessage = "Extract housing information from the given text and open the routing window", HelpMessage = "Extract housing information from the given text and open the routing window",
@ -72,7 +72,7 @@ namespace RoleplayersToolbox.Tools.Housing {
this.Plugin.CommandManager.RemoveHandler("/bookmarks"); this.Plugin.CommandManager.RemoveHandler("/bookmarks");
this.Plugin.CommandManager.RemoveHandler("/route"); this.Plugin.CommandManager.RemoveHandler("/route");
this.Plugin.Framework.Update -= this.OnFramework; this.Plugin.Framework.Update -= this.OnFramework;
this.Plugin.Common.Functions.ContextMenu.OpenContextMenu -= this.OnContextMenu; this.Plugin.ContextMenu.ContextMenuOpened -= this.OnContextMenu;
} }
public override void DrawSettings(ref bool anyChanged) { public override void DrawSettings(ref bool anyChanged) {
@ -198,19 +198,26 @@ namespace RoleplayersToolbox.Tools.Housing {
this.BookmarksUi.ShouldDraw ^= true; this.BookmarksUi.ShouldDraw ^= true;
} }
private void OnContextMenu(ContextMenuOpenArgs args) { private void OnContextMenu(ContextMenuOpenedArgs args) {
if (args.ParentAddonName != "LookingForGroup" || args.ContentIdLower == 0) { if (args.ParentAddonName != "LookingForGroup" || args.GameObjectContext?.ContentId is null or 0) {
return; return;
} }
args.Items.Add(new NormalContextSubMenuItem("Roleplayer's Toolbox", args => { args.AddCustomSubMenu("Roleplayer's Toolbox", args => {
args.Items.Add(new NormalContextMenuItem("Select as Destination", this.SelectDestination)); args.AddCustomItem("Select as Destination", this.SelectDestination);
args.Items.Add(new NormalContextMenuItem("Add Bookmark", this.AddBookmark)); args.AddCustomItem("Add Bookmark", this.AddBookmark);
})); });
} }
private void SelectDestination(ContextMenuItemSelectedArgs args) { private void SelectDestination(CustomContextMenuItemSelectedArgs args) {
var listing = this.Plugin.Common.Functions.PartyFinder.CurrentListings.Values.FirstOrDefault(listing => listing.ContentIdLower == args.ContentIdLower); var contentId = args.ContextMenuOpenedArgs.GameObjectContext?.ContentId;
if (contentId is null or 0) {
return;
}
var contentIdLower = contentId & 0xFFFFFFFF;
var listing = this.Plugin.Common.Functions.PartyFinder.CurrentListings.Values.FirstOrDefault(listing => listing.ContentIdLower == contentIdLower);
if (listing == null) { if (listing == null) {
return; return;
} }
@ -219,8 +226,15 @@ namespace RoleplayersToolbox.Tools.Housing {
this.Destination = InfoExtractor.Extract(listing.Description.TextValue, listing.World.Value.DataCenter.Row, this.Plugin.DataManager, this.Info); this.Destination = InfoExtractor.Extract(listing.Description.TextValue, listing.World.Value.DataCenter.Row, this.Plugin.DataManager, this.Info);
} }
private void AddBookmark(ContextMenuItemSelectedArgs args) { private void AddBookmark(CustomContextMenuItemSelectedArgs args) {
var listing = this.Plugin.Common.Functions.PartyFinder.CurrentListings.Values.FirstOrDefault(listing => listing.ContentIdLower == args.ContentIdLower); var contentId = args.ContextMenuOpenedArgs.GameObjectContext?.ContentId;
if (contentId is null or 0) {
return;
}
var contentIdLower = contentId & 0xFFFFFFFF;
var listing = this.Plugin.Common.Functions.PartyFinder.CurrentListings.Values.FirstOrDefault(listing => listing.ContentIdLower == contentIdLower);
if (listing == null) { if (listing == null) {
return; return;
} }