Skip to content

Commit

Permalink
Merge pull request FFXIV-CombatReborn#479 from ffxivcode/master
Browse files Browse the repository at this point in the history
Added TitleBar button to AI UI that sets DrawUI config to false;
  • Loading branch information
awgil authored Sep 8, 2024
2 parents 4fc2e36 + bbca6bf commit 72bcc49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion BossMod/AI/AIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface;
using Dalamud.Interface.Utility.Raii;
using FFXIVClientStructs.FFXIV.Client.Game.Group;
using ImGuiNET;
using static Dalamud.Interface.Windowing.Window;

namespace BossMod.AI;

Expand Down Expand Up @@ -45,11 +47,13 @@ public AIManager(RotationModuleManager autorot, ActionManagerEx amex, MovementOv
_autorot = autorot;
_controller = new(amex, movement);
_config = Service.Config.Get<AIConfig>();
List<TitleBarButton> _titlebarButtons = [new() { Icon = FontAwesomeIcon.WindowClose, IconOffset = new(1, 1), Click = _ => _config.DrawUI = false }];
_ui = new("###AI", DrawOverlay, false, new(100, 100), ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.NoFocusOnAppearing)
{
RespectCloseHotkey = false,
ShowCloseButton = false,
WindowName = $"AI: off###AI"
WindowName = $"AI: off###AI",
TitleBarButtons = _titlebarButtons
};
Service.ChatGui.ChatMessage += OnChatMessage;
Service.CommandManager.AddHandler("/vbmai", new Dalamud.Game.Command.CommandInfo(OnCommand) { HelpMessage = "Toggle AI mode" });
Expand Down
12 changes: 8 additions & 4 deletions BossMod/Util/UIWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dalamud.Interface.Windowing;
using ImGuiNET;
using static Dalamud.Interface.Windowing.Window;

namespace BossMod;

Expand All @@ -17,13 +18,16 @@ public abstract class UIWindow : Window, IDisposable
{
public bool DisposeOnClose; // defaults to true for detached windows, false for normal windows

protected UIWindow(string name, bool detached, Vector2 initialSize, ImGuiWindowFlags flags = ImGuiWindowFlags.None) : base(name, flags)
protected UIWindow(string name, bool detached, Vector2 initialSize, ImGuiWindowFlags flags = ImGuiWindowFlags.None, List<TitleBarButton>? titleBarButtons = null) : base(name, flags)
{
DisposeOnClose = detached;
Size = initialSize;
SizeCondition = ImGuiCond.FirstUseEver;
AllowClickthrough = AllowPinning = false; // this breaks uidev

if (titleBarButtons != null)
{
TitleBarButtons = titleBarButtons;
}
var existingWindow = Service.WindowSystem!.Windows.FirstOrDefault(w => w.WindowName == WindowName);
if (existingWindow == null)
{
Expand Down Expand Up @@ -61,8 +65,8 @@ public override void OnClose()
}

// utility: window that uses custom delegate to perform drawing - allows avoiding creating derived classes in simple cases
public class UISimpleWindow(string name, Action draw, bool detached, Vector2 initialSize, ImGuiWindowFlags flags = ImGuiWindowFlags.None)
: UIWindow(name, detached, initialSize, flags)
public class UISimpleWindow(string name, Action draw, bool detached, Vector2 initialSize, ImGuiWindowFlags flags = ImGuiWindowFlags.None, List<TitleBarButton>? titleBarButtons = null)
: UIWindow(name, detached, initialSize, flags, titleBarButtons)
{
private readonly Action _draw = draw;

Expand Down

0 comments on commit 72bcc49

Please sign in to comment.