164 lines
5.1 KiB
C#
164 lines
5.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Dalamud.Game.ClientState.Objects.SubKinds;
|
|
using Dalamud.Game.Command;
|
|
using Dalamud.Game.Gui.ContextMenu;
|
|
using Dalamud.Interface.Windowing;
|
|
using Dalamud.IoC;
|
|
using Dalamud.Plugin;
|
|
using Dalamud.Plugin.Services;
|
|
using HighRollerClassic.Windows;
|
|
using Lumina.Data.Parsing.Layer;
|
|
|
|
namespace HighRollerClassic;
|
|
|
|
public sealed class Plugin : IDalamudPlugin
|
|
{
|
|
private const string CommandName = "/hrc";
|
|
private readonly WindowSystem windowSystem = new("HighRollerClassic");
|
|
private readonly List<GambaWindow> gambaWindows = [];
|
|
|
|
public Plugin()
|
|
{
|
|
Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
|
|
|
|
SettingsWindow = new SettingsWindow(this);
|
|
windowSystem.AddWindow(SettingsWindow);
|
|
|
|
CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
|
|
{
|
|
HelpMessage = "Opens the HRC Settings"
|
|
});
|
|
|
|
// Tell the UI system that we want our windows to be drawn through the window system
|
|
PluginInterface.UiBuilder.Draw += windowSystem.Draw;
|
|
|
|
// This adds a button to the plugin installer entry of this plugin which allows
|
|
// toggling the display status of the configuration ui
|
|
PluginInterface.UiBuilder.OpenConfigUi += ToggleSettingsUi;
|
|
|
|
// Adds another button doing the same but for the main ui of the plugin
|
|
// PluginInterface.UiBuilder.OpenMainUi += ToggleMainUi;
|
|
|
|
// Add a simple message to the log with level set to information
|
|
// Use /xllog to open the log window in-game
|
|
// Example Output: 00:57:54.959 | INF | [HighRollerClassic] ===A cool log message from Sample Plugin===
|
|
Log.Information($"===A cool log message from {PluginInterface.Manifest.Name}===");
|
|
|
|
// Set up context menu
|
|
ContextMenu.OnMenuOpened += OnContextMenuOpened;
|
|
}
|
|
|
|
[PluginService]
|
|
internal static IDalamudPluginInterface PluginInterface { get; private set; } = null!;
|
|
|
|
[PluginService]
|
|
internal static ITextureProvider TextureProvider { get; private set; } = null!;
|
|
|
|
[PluginService]
|
|
internal static ICommandManager CommandManager { get; private set; } = null!;
|
|
|
|
[PluginService]
|
|
internal static IClientState ClientState { get; private set; } = null!;
|
|
|
|
[PluginService]
|
|
internal static IPlayerState PlayerState { get; private set; } = null!;
|
|
|
|
[PluginService]
|
|
internal static IDataManager DataManager { get; private set; } = null!;
|
|
|
|
[PluginService]
|
|
internal static IPluginLog Log { get; private set; } = null!;
|
|
|
|
[PluginService]
|
|
internal static IContextMenu ContextMenu { get; private set; } = null!;
|
|
|
|
public Configuration Configuration { get; init; }
|
|
private SettingsWindow SettingsWindow { get; init; }
|
|
private List<GambaWindow> Windows { get; init; }
|
|
|
|
public void Dispose()
|
|
{
|
|
// Unregister all actions to not leak anything during disposal of plugin
|
|
PluginInterface.UiBuilder.Draw -= windowSystem.Draw;
|
|
PluginInterface.UiBuilder.OpenConfigUi -= ToggleSettingsUi;
|
|
|
|
windowSystem.RemoveAllWindows();
|
|
|
|
SettingsWindow.Dispose();
|
|
foreach (var window in gambaWindows)
|
|
{
|
|
window.Dispose();
|
|
}
|
|
|
|
CommandManager.RemoveHandler(CommandName);
|
|
|
|
ContextMenu.OnMenuOpened -= OnContextMenuOpened;
|
|
}
|
|
|
|
private void OnCommand(string command, string args)
|
|
{
|
|
// In response to the slash command, toggle the display status of our main ui
|
|
SettingsWindow.Toggle();
|
|
}
|
|
|
|
public void ToggleSettingsUi()
|
|
{
|
|
SettingsWindow.Toggle();
|
|
}
|
|
|
|
public bool PlayerIsLoaded()
|
|
{
|
|
return PlayerState.IsLoaded;
|
|
}
|
|
|
|
private void OnContextMenuOpened(IMenuOpenedArgs args)
|
|
{
|
|
if (args.MenuType == ContextMenuType.Inventory) return;
|
|
|
|
var target = (MenuTargetDefault)args.Target;
|
|
|
|
// target must be a player that is not self
|
|
if (target.TargetObject is not IPlayerCharacter || target.TargetContentId == PlayerState.ContentId)
|
|
{
|
|
Log.Debug("Not a foreign player");
|
|
return;
|
|
}
|
|
|
|
// call main window with content id
|
|
args.AddMenuItem(new MenuItem
|
|
{
|
|
Name = "High Roller Classic",
|
|
PrefixChar = 'H',
|
|
OnClicked = ContextMenuPlayerGameStart(target)
|
|
});
|
|
}
|
|
|
|
private Action<IMenuItemClickedArgs> ContextMenuPlayerGameStart(MenuTargetDefault target)
|
|
{
|
|
return _ =>
|
|
{
|
|
Log.Debug($"Starting gamba with {target.TargetName}");
|
|
CreateGambaWindow(target);
|
|
};
|
|
}
|
|
|
|
private void CreateGambaWindow(MenuTargetDefault target)
|
|
{
|
|
var existingWindow = gambaWindows.Find(p => p.WindowName.Contains(target.TargetContentId.ToString()));
|
|
if (existingWindow is { IsOpen: false })
|
|
{
|
|
existingWindow.Toggle();
|
|
return;
|
|
}
|
|
|
|
var window = new GambaWindow(this, target)
|
|
{
|
|
IsOpen = true,
|
|
};
|
|
|
|
gambaWindows.Add(window);
|
|
windowSystem.AddWindow(window);
|
|
}
|
|
}
|