feat: add commands and option to dock to pf window

This commit is contained in:
Anna 2021-01-15 20:12:46 -05:00
parent 4db5f74c46
commit df1dd701a1
5 changed files with 158 additions and 5 deletions

38
BetterPartyFinder/Commands.cs Executable file
View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using Dalamud.Game.Command;
namespace BetterPartyFinder {
public class Commands : IDisposable {
private static readonly Dictionary<string, string> CommandNames = new() {
["/betterpartyfinder"] = "Opens the main interface. Use with args \"c\" or \"config\" to open the settings.",
["/bpf"] = "Alias for /betterpartyfinder",
};
private Plugin Plugin { get; }
internal Commands(Plugin plugin) {
this.Plugin = plugin;
foreach (var name in CommandNames) {
this.Plugin.Interface.CommandManager.AddHandler(name.Key, new CommandInfo(this.OnCommand) {
HelpMessage = name.Value,
});
}
}
public void Dispose() {
foreach (var name in CommandNames.Keys) {
this.Plugin.Interface.CommandManager.RemoveHandler(name);
}
}
private void OnCommand(string command, string args) {
if (args == "c" || args == "config") {
this.Plugin.Ui.SettingsVisible = !this.Plugin.Ui.SettingsVisible;
} else {
this.Plugin.Ui.Visible = !this.Plugin.Ui.Visible;
}
}
}
}

View File

@ -12,6 +12,9 @@ namespace BetterPartyFinder {
public Dictionary<Guid, ConfigurationFilter> Presets { get; } = new();
public Guid? SelectedPreset { get; set; }
public bool ShowWhenPfOpen { get; set; }
public WindowSide WindowSide { get; set; } = WindowSide.Left;
internal static Configuration? Load(Plugin plugin) {
return (Configuration?) plugin.Interface.GetPluginConfig();
}
@ -115,4 +118,9 @@ namespace BetterPartyFinder {
Whitelist,
Blacklist,
}
public enum WindowSide {
Left,
Right,
}
}

View File

@ -48,6 +48,13 @@ namespace BetterPartyFinder {
var needToRewrite = false;
var raw = Marshal.AllocHGlobal(PacketInfo.PacketSize);
Marshal.StructureToPtr(packet, raw, false);
var bytes = new byte[PacketInfo.PacketSize];
Marshal.Copy(raw, bytes, 0, PacketInfo.PacketSize);
PluginLog.Log(string.Join("", bytes.Select(b => b.ToString("x2"))));
Marshal.FreeHGlobal(raw);
for (var i = 0; i < packet.listings.Length; i++) {
if (packet.listings[i].IsNull()) {
continue;

View File

@ -8,8 +8,9 @@ namespace BetterPartyFinder {
internal DalamudPluginInterface Interface { get; private set; } = null!;
internal Configuration Config { get; private set; } = null!;
internal GameFunctions Functions { get; private set; } = null!;
internal Filter Filter { get; set; } = null!;
private PluginUi Ui { get; set; } = null!;
private Filter Filter { get; set; } = null!;
internal PluginUi Ui { get; set; } = null!;
private Commands Commands { get; set; } = null!;
public void Initialize(DalamudPluginInterface pluginInterface) {
this.Interface = pluginInterface;
@ -20,12 +21,14 @@ namespace BetterPartyFinder {
this.Functions = new GameFunctions(this);
this.Filter = new Filter(this);
this.Ui = new PluginUi(this);
this.Commands = new Commands(this);
// start task to determine maximum item level (based on max chestpiece)
Task.Run(() => Util.CalculateMaxItemLevel(this.Interface.Data));
}
public void Dispose() {
this.Commands.Dispose();
this.Ui.Dispose();
this.Filter.Dispose();
this.Functions.Dispose();

View File

@ -6,6 +6,7 @@ using Dalamud.Data;
using Dalamud.Interface;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using GameAddon = Dalamud.Game.Internal.Gui.Addon.Addon;
namespace BetterPartyFinder {
public class PluginUi : IDisposable {
@ -23,12 +24,24 @@ namespace BetterPartyFinder {
private Plugin Plugin { get; }
private bool _visible;
public bool Visible {
get => this._visible;
set => this._visible = value;
}
private bool _settingsVisible;
public bool SettingsVisible {
get => this._settingsVisible;
set => this._settingsVisible = value;
}
private string DutySearchQuery { get; set; } = string.Empty;
private string PresetName { get; set; } = string.Empty;
private bool[] _openSlots = new bool[8];
internal PluginUi(Plugin plugin) {
this.Plugin = plugin;
@ -54,10 +67,73 @@ namespace BetterPartyFinder {
return result;
}
private GameAddon? PartyFinderAddon() {
return this.Plugin.Interface.Framework.Gui.GetAddonByName("LookingForGroup", 1);
}
private void Draw() {
this.DrawFiltersWindow();
this.DrawSettingsWindow();
}
private void DrawSettingsWindow() {
ImGui.SetNextWindowSize(new Vector2(-1f, -1f), ImGuiCond.FirstUseEver);
if (!this.SettingsVisible || !ImGui.Begin($"{this.Plugin.Name} settings", ref this._settingsVisible)) {
return;
}
var openWithPf = this.Plugin.Config.ShowWhenPfOpen;
if (ImGui.Checkbox("Open with PF", ref openWithPf)) {
this.Plugin.Config.ShowWhenPfOpen = openWithPf;
this.Plugin.Config.Save();
}
var sideOptions = new[] {
"Left",
"Right",
};
var sideIdx = this.Plugin.Config.WindowSide == WindowSide.Left ? 0 : 1;
ImGui.TextUnformatted("Side of PF window to dock to");
if (ImGui.Combo("###window-side", ref sideIdx, sideOptions, sideOptions.Length)) {
this.Plugin.Config.WindowSide = sideIdx switch {
0 => WindowSide.Left,
1 => WindowSide.Right,
_ => this.Plugin.Config.WindowSide,
};
this.Plugin.Config.Save();
}
ImGui.End();
}
private void DrawFiltersWindow() {
ImGui.SetNextWindowSize(new Vector2(550f, 510f), ImGuiCond.FirstUseEver);
if (!ImGui.Begin($"{this.Plugin.Name} settings")) {
var showWindow = this.Visible;
if (!showWindow && this.Plugin.Config.ShowWhenPfOpen) {
var addon = this.PartyFinderAddon();
if (addon != null && addon.Visible) {
showWindow = true;
if (this.Plugin.Config.WindowSide == WindowSide.Right) {
float? width;
try {
width = addon.Width;
} catch (NullReferenceException) {
width = null;
}
if (width != null) {
ImGui.SetNextWindowPos(new Vector2(addon.X + addon.Width, addon.Y));
}
}
}
}
if (!showWindow || !ImGui.Begin(this.Plugin.Name, ref this._visible)) {
return;
}
@ -142,12 +218,33 @@ namespace BetterPartyFinder {
}
}
ImGui.SameLine();
if (IconButton(FontAwesomeIcon.Cog, "settings")) {
this.SettingsVisible = true;
}
ImGui.Separator();
if (selected != null && this.Plugin.Config.Presets.TryGetValue(selected.Value, out var filter)) {
this.DrawPresetConfiguration(filter);
}
if (this.Plugin.Config.ShowWhenPfOpen && this.Plugin.Config.WindowSide == WindowSide.Left) {
var addon = this.PartyFinderAddon();
var currentWidth = ImGui.GetWindowWidth();
float? addonWidth;
try {
addonWidth = addon?.Width;
} catch (NullReferenceException) {
addonWidth = null;
}
if (addon != null && addonWidth != null) {
ImGui.SetWindowPos(new Vector2(addon.X - currentWidth, addon.Y));
}
}
ImGui.End();
}