Skip to content

Commit

Permalink
Zone module example.
Browse files Browse the repository at this point in the history
  • Loading branch information
awgil committed Oct 7, 2024
1 parent 02cc804 commit bab9f89
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 69 deletions.
9 changes: 4 additions & 5 deletions BossMod/BossModule/BossModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ImGuiNET;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;

namespace BossMod;

Expand Down Expand Up @@ -261,23 +262,21 @@ protected virtual void DrawEnemies(int pcSlot, Actor pc)

private void DrawGlobalHints(BossComponent.GlobalHints hints)
{
ImGui.PushStyleColor(ImGuiCol.Text, 0xffffff00);
using var color = ImRaii.PushColor(ImGuiCol.Text, 0xffffff00);
foreach (var hint in hints)
{
ImGui.TextUnformatted(hint);
ImGui.SameLine();
}
ImGui.PopStyleColor();
ImGui.NewLine();
}

private void DrawPlayerHints(BossComponent.TextHints hints)
{
foreach ((var hint, bool risk) in hints)
{
ImGui.PushStyleColor(ImGuiCol.Text, risk ? ArenaColor.Danger : ArenaColor.Safe);
using var color = ImRaii.PushColor(ImGuiCol.Text, risk ? ArenaColor.Danger : ArenaColor.Safe);
ImGui.TextUnformatted(hint);
ImGui.PopStyleColor();
ImGui.SameLine();
}
ImGui.NewLine();
Expand Down
25 changes: 18 additions & 7 deletions BossMod/BossModule/BossModuleHintsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,42 @@ namespace BossMod;
public class BossModuleHintsWindow : UIWindow
{
private readonly BossModuleManager _mgr;
private readonly ZoneModuleManager _zmm;

public BossModuleHintsWindow(BossModuleManager mgr) : base("Boss module hints", false, new(400, 100))
public BossModuleHintsWindow(BossModuleManager mgr, ZoneModuleManager zmm) : base("Boss module hints", false, new(400, 100))
{
_mgr = mgr;
_zmm = zmm;
RespectCloseHotkey = false;
}

public override void PreOpenCheck()
{
IsOpen = _mgr.Config.HintsInSeparateWindow && _mgr.ActiveModule != null;
IsOpen = _mgr.Config.HintsInSeparateWindow && (_mgr.ActiveModule != null || ShowZoneModule());
Flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse;
if (_mgr.Config.Lock)
Flags |= ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoInputs;
}

public override void Draw()
{
try
if (ShowZoneModule())
{
_mgr.ActiveModule?.Draw(default, PartyState.PlayerSlot, true, false);
_zmm.ActiveModule?.DrawGlobalHints();
}
catch (Exception ex)
else
{
Service.Log($"Boss module draw-hints crashed: {ex}");
_mgr.ActiveModule = null;
try
{
_mgr.ActiveModule?.Draw(default, PartyState.PlayerSlot, true, false);
}
catch (Exception ex)
{
Service.Log($"Boss module draw-hints crashed: {ex}");
_mgr.ActiveModule = null;
}
}
}

private bool ShowZoneModule() => _mgr.ActiveModule?.StateMachine.ActivePhase == null && (_zmm.ActiveModule?.WantToBeDrawn() ?? false);
}
23 changes: 16 additions & 7 deletions BossMod/BossModule/BossModuleMainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ namespace BossMod;
public class BossModuleMainWindow : UIWindow
{
private readonly BossModuleManager _mgr;
private readonly ZoneModuleManager _zmm;

private const string _windowID = "###Boss module";

public BossModuleMainWindow(BossModuleManager mgr) : base(_windowID, false, new(400, 400))
public BossModuleMainWindow(BossModuleManager mgr, ZoneModuleManager zmm) : base(_windowID, false, new(400, 400))
{
_mgr = mgr;
_zmm = zmm;
RespectCloseHotkey = false;
TitleBarButtons.Add(new() { Icon = FontAwesomeIcon.Cog, IconOffset = new(1), Click = _ => OpenModuleConfig() });
}

public override void PreOpenCheck()
{
IsOpen = _mgr.Config.Enable && _mgr.LoadedModules.Count > 0;
ShowCloseButton = _mgr.ActiveModule != null;
WindowName = (_mgr.ActiveModule != null ? $"Boss module ({_mgr.ActiveModule.GetType().Name})" : "Loaded boss modules") + _windowID;
var showZoneModule = ShowZoneModule();
IsOpen = _mgr.Config.Enable && (_mgr.LoadedModules.Count > 0 || showZoneModule);
ShowCloseButton = _mgr.ActiveModule != null && !showZoneModule;
WindowName = (showZoneModule ? $"Zone module ({_zmm.ActiveModule?.GetType().Name})" : _mgr.ActiveModule != null ? $"Boss module ({_mgr.ActiveModule.GetType().Name})" : "Loaded boss modules") + _windowID;
Flags = ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse;
if (_mgr.Config.TrishaMode)
Flags |= ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoBackground;
Expand All @@ -31,12 +34,12 @@ public override void PreOpenCheck()

public override void OnOpen()
{
Service.Log($"[BMM] Opening main window; there are {_mgr.LoadedModules.Count} loaded modules, active is {_mgr.ActiveModule?.GetType().FullName ?? "<n/a>"}");
Service.Log($"[BMM] Opening main window; there are {_mgr.LoadedModules.Count} loaded modules, active is {_mgr.ActiveModule?.GetType().FullName ?? "<n/a>"}; zone module is {_zmm.ActiveModule?.GetType().FullName ?? "<n/a>"}");
}

public override void OnClose()
{
Service.Log($"[BMM] Closing main window; there are {_mgr.LoadedModules.Count} loaded modules, active is {_mgr.ActiveModule?.GetType().FullName ?? "<n/a>"}");
Service.Log($"[BMM] Closing main window; there are {_mgr.LoadedModules.Count} loaded modules, active is {_mgr.ActiveModule?.GetType().FullName ?? "<n/a>"}; zone module is {_zmm.ActiveModule?.GetType().FullName ?? "<n/a>"}");
}

public override void PostDraw()
Expand All @@ -53,7 +56,11 @@ public override void PostDraw()

public override void Draw()
{
if (_mgr.ActiveModule != null)
if (ShowZoneModule())
{
_zmm.ActiveModule?.DrawGlobalHints();
}
else if (_mgr.ActiveModule != null)
{
try
{
Expand Down Expand Up @@ -102,4 +109,6 @@ private void OpenModuleConfig()
if (_mgr.ActiveModule?.Info != null)
_ = new BossModuleConfigWindow(_mgr.ActiveModule.Info, _mgr.WorldState);
}

private bool ShowZoneModule() => _mgr.Config.ShowGlobalHints && !_mgr.Config.HintsInSeparateWindow && _mgr.ActiveModule?.StateMachine.ActivePhase == null && (_zmm.ActiveModule?.WantToBeDrawn() ?? false);
}
18 changes: 17 additions & 1 deletion BossMod/BossModule/ZoneModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace BossMod;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;

namespace BossMod;

public abstract class ZoneModule(WorldState ws) : IDisposable
{
Expand All @@ -15,5 +18,18 @@ protected virtual void Dispose(bool disposing)
}

public virtual void Update() { }
public virtual bool WantToBeDrawn() => false; // return true if it wants to be drawn (higher priority than inactive boss modules, but lower priority than active)
public virtual List<string> CalculateGlobalHints() => [];
public virtual void CalculateAIHints(Actor player, AIHints hints) { } // note: this is called after framework automatically fills auto-detected hints

public void DrawGlobalHints()
{
using var color = ImRaii.PushColor(ImGuiCol.Text, 0xffffff00);
foreach (var hint in CalculateGlobalHints())
{
ImGui.TextUnformatted(hint);
//ImGui.SameLine();
}
//ImGui.NewLine();
}
}
4 changes: 2 additions & 2 deletions BossMod/Framework/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public unsafe Plugin(IDalamudPluginInterface dalamud, ICommandManager commandMan

var replayDir = new DirectoryInfo(dalamud.ConfigDirectory.FullName + "/replays");
_configUI = new(Service.Config, _ws, replayDir, _rotationDB);
_wndBossmod = new(_bossmod);
_wndBossmodHints = new(_bossmod);
_wndBossmod = new(_bossmod, _zonemod);
_wndBossmodHints = new(_bossmod, _zonemod);
_wndReplay = new(_ws, _rotationDB, replayDir);
_wndRotation = new(_rotation, _amex, () => OpenConfigUI("Autorotation Presets"));
_wndDebug = new(_ws, _rotation, _amex, _hintsBuilder, dalamud);
Expand Down
42 changes: 0 additions & 42 deletions BossMod/Modules/RealmReborn/Dungeon/D01Sastasha/D010Switch.cs

This file was deleted.

42 changes: 42 additions & 0 deletions BossMod/Modules/RealmReborn/Dungeon/D01Sastasha/D01Sastasha.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace BossMod.RealmReborn.Dungeon.D01Sastasha;

public enum OID : uint
{
BloodyMemoBlue = 0x1E8554,
BloodyMemoRed = 0x1E8A8C,
BloodyMemoGreen = 0x1E8A8D,
CoralFormationBlue = 0x1E8555,
CoralFormationRed = 0x1E8556,
CoralFormationGreen = 0x1E8557,
InconspicuousSwitch = 0x1E8558,
}

[ZoneModuleInfo(BossModuleInfo.Maturity.Verified, 4)]
public class D01Sastasha(WorldState ws) : ZoneModule(ws)
{
public enum Switch { Unknown, Blue, Red, Green, Resolved }

private Switch _switchColor;

public override void Update()
{
if (_switchColor == Switch.Unknown)
{
_switchColor = (OID)(WorldState.Actors.FirstOrDefault(a => a.IsTargetable && (OID)a.OID is OID.BloodyMemoBlue or OID.BloodyMemoRed or OID.BloodyMemoGreen)?.OID ?? 0) switch
{
OID.BloodyMemoBlue => Switch.Blue,
OID.BloodyMemoRed => Switch.Red,
OID.BloodyMemoGreen => Switch.Green,
_ => Switch.Unknown
};
}
else if (_switchColor != Switch.Resolved && WorldState.Actors.Any(a => a.IsTargetable && (OID)a.OID == OID.InconspicuousSwitch))
{
_switchColor = Switch.Resolved;
}
}

public override bool WantToBeDrawn() => _switchColor != Switch.Resolved;

public override List<string> CalculateGlobalHints() => [$"Correct switch: {_switchColor}"];
}
3 changes: 2 additions & 1 deletion BossMod/Replay/Visualization/ReplayDetailsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public override void Draw()

DrawControlRow();
DrawTimelineRow();
ImGui.TextUnformatted($"Num loaded modules: {_mgr.LoadedModules.Count}, num active modules: {_mgr.LoadedModules.Count(m => m.StateMachine.ActiveState != null)}, active module: {_mgr.ActiveModule?.GetType()}");
ImGui.TextUnformatted($"Num loaded modules: {_mgr.LoadedModules.Count}, num active modules: {_mgr.LoadedModules.Count(m => m.StateMachine.ActiveState != null)}, active module: {_mgr.ActiveModule?.GetType()}, zone module: {_zmm.ActiveModule?.GetType()}");
_zmm.ActiveModule?.DrawGlobalHints();
if (!_azimuthOverride)
_azimuth = _mgr.WorldState.Client.CameraAzimuth.Deg;
ImGui.DragFloat("Camera azimuth", ref _azimuth, 1, -180, 180);
Expand Down
6 changes: 2 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ immediate plans
- merge prs!
- collisions for pathfinding
-- embedded mode
- zone module manager
-- drawing in main/hint windows and in replays
-- replay visualization
-- sastasha as example
- brd rotation

general:
Expand Down Expand Up @@ -41,6 +37,8 @@ general:
-- use that for targeting utils in aihints
- debug utility to play action animations, spawn actors, play vfx, etc...
- encounter hints (to show before pull)
- zone modules: replay visualization
- zone modules: module info ui

boss modules:
- timers
Expand Down

0 comments on commit bab9f89

Please sign in to comment.