Skip to content

Commit

Permalink
Merge pull request #22 from FFXIV-CombatReborn/merge
Browse files Browse the repository at this point in the history
Blur - Song 2
  • Loading branch information
LTS-FFXIV authored Mar 31, 2024
2 parents 9950500 + 74c6d68 commit 15beed2
Show file tree
Hide file tree
Showing 362 changed files with 994 additions and 1,048 deletions.
22 changes: 0 additions & 22 deletions BossMod/BossModule/BossModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@

namespace BossMod;

// attribute that allows customizing boss module's metadata; it is optional, each field has some defaults that are fine in most cases
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class ModuleInfoAttribute : Attribute
{
public Type? StatesType; // default: ns.xxxStates
public Type? ConfigType; // default: ns.xxxConfig
public Type? ObjectIDType; // default: ns.OID
public Type? ActionIDType; // default: ns.AID
public Type? StatusIDType; // default: ns.SID
public Type? TetherIDType; // default: ns.TetherID
public Type? IconIDType; // default: ns.IconID
public string? DisplayName;
public uint ExVersion; // default: 0
public uint QuestID; // default: 0
public uint DynamicEventID; // default: 0
public uint FateID; // default: 0
public uint NotoriousMonsterID; // default: 0
public uint NameID; // default: 0
public uint CFCID; // default: 0
public uint PrimaryActorOID; // default: OID.Boss
}

// base for boss modules - provides all the common features, so that look is standardized
// by default, module activates (transitions to phase 0) whenever "primary" actor becomes both targetable and in combat (this is how we detect 'pull') - though this can be overridden if needed
public abstract class BossModule : IDisposable
Expand Down
34 changes: 34 additions & 0 deletions BossMod/BossModule/BossModuleConfigWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Dalamud.Interface.Utility.Raii;

namespace BossMod;

public class BossModuleConfigWindow : UIWindow
{
private ModuleRegistry.Info _info;
private WorldState _ws;
private UITree _tree = new();

public BossModuleConfigWindow(ModuleRegistry.Info info, WorldState ws) : base($"{info.ModuleType.Name} config", true, new(1200, 800))
{
_info = info;
_ws = ws;
}

public override void Draw()
{
if (_info.ConfigType == null)
return; // nothing to do...

using var tabs = ImRaii.TabBar("Tabs");
if (tabs)
{
using (var tab = ImRaii.TabItem("Encounter-specific config"))
if (tab)
ConfigUI.DrawNode(Service.Config.Get<ConfigNode>(_info.ConfigType), Service.Config, _tree, _ws);
if (_ws.Party.Player() != null)
using (var tab = ImRaii.TabItem("Party roles assignment"))
if (tab)
ConfigUI.DrawNode(Service.Config.Get<PartyRolesConfig>(), Service.Config, _tree, _ws);
}
}
}
88 changes: 88 additions & 0 deletions BossMod/BossModule/BossModuleInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace BossMod;

public static class BossModuleInfo
{
public enum Expansion
{
RealmReborn,
Heavensward,
Stormblood,
Shadowbringers,
Endwalker,
Global,

Count
}

public enum Category
{
Uncategorized,
Dungeon,
Trial,
Extreme,
Raid,
Savage,
Ultimate,
Unreal,
Alliance,
Foray,
Criterion,
DeepDungeon,
FATE,
Hunt,
Quest,
TreasureHunt,
PVP,
MaskedCarnivale,
GoldSaucer,

Count
}

public enum GroupType
{
None,
CFC, // group id is ContentFinderCondition row
MaskedCarnivale, // group id is ContentFinderCondition row
RemovedUnreal, // group id is ContentFinderCondition row
Quest, // group id is Quest row
Fate, // group id is Fate row
Hunt, // group id is HuntRank
BozjaCE, // group id is ContentFinderCondition row, name id is DynamicEvent row
BozjaDuel, // group id is ContentFinderCondition row, name id is DynamicEvent row
GoldSaucer, // group id is GoldSaucerTextData row
}

public enum HuntRank : uint { B, A, S, SS }

// shorthand expansion names
public static string ShortName(this Expansion e) => e switch
{
Expansion.RealmReborn => "ARR",
Expansion.Heavensward => "HW",
Expansion.Stormblood => "SB",
Expansion.Shadowbringers => "ShB",
Expansion.Endwalker => "EW",
_ => e.ToString()
};
}

// attribute that allows customizing boss module's metadata; it is optional, each field has some defaults that are fine in most cases
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class ModuleInfoAttribute : Attribute
{
public Type? StatesType; // default: ns.xxxStates
public Type? ConfigType; // default: ns.xxxConfig
public Type? ObjectIDType; // default: ns.OID
public Type? ActionIDType; // default: ns.AID
public Type? StatusIDType; // default: ns.SID
public Type? TetherIDType; // default: ns.TetherID
public Type? IconIDType; // default: ns.IconID
public uint PrimaryActorOID; // default: OID.Boss
public BossModuleInfo.Expansion Expansion = BossModuleInfo.Expansion.Count; // default: second namespace level
public BossModuleInfo.Category Category = BossModuleInfo.Category.Count; // default: third namespace level
public BossModuleInfo.GroupType GroupType = BossModuleInfo.GroupType.None;
public uint GroupID;
public uint NameID; // usually BNpcName row, unless GroupType uses it differently
public int SortOrder; // default: first number in type name
}
10 changes: 9 additions & 1 deletion BossMod/BossModule/BossModuleMainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ImGuiNET;
using Dalamud.Interface;
using ImGuiNET;

namespace BossMod;

Expand All @@ -12,6 +13,7 @@ public class BossModuleMainWindow : UIWindow
{
_mgr = mgr;
RespectCloseHotkey = false;
TitleBarButtons.Add(new() { Icon = FontAwesomeIcon.Cog, IconOffset = new(1), Click = _ => OpenModuleConfig() });
}

public override void PreOpenCheck()
Expand Down Expand Up @@ -94,4 +96,10 @@ private void DrawMovementHints(BossComponent.MovementHints? arrows, float y)
Camera.Instance.DrawWorldLine(arrowStart - offset, end3, color);
}
}

private void OpenModuleConfig()
{
if (_mgr.ActiveModule?.Info?.ConfigType != null)
new BossModuleConfigWindow(_mgr.ActiveModule.Info, _mgr.WorldState);
}
}
68 changes: 38 additions & 30 deletions BossMod/Config/ConfigUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BossMod;

public class ConfigUI
public class ConfigUI : IDisposable
{
private class UINode
{
Expand Down Expand Up @@ -54,6 +54,11 @@ public ConfigUI(ConfigRoot config, WorldState ws)
SortByOrder(_roots);
}

public void Dispose()
{
_mv.Dispose();
}

public void Draw()
{
using var tabs = ImRaii.TabBar("Tabs");
Expand All @@ -68,6 +73,29 @@ public void Draw()
}
}

public static void DrawNode(ConfigNode node, ConfigRoot root, UITree tree, WorldState ws)
{
// draw standard properties
foreach (var field in node.GetType().GetFields())
{
var props = field.GetCustomAttribute<PropertyDisplayAttribute>();
if (props == null)
continue;

_ = field.GetValue(node) switch
{
bool v => DrawProperty(props, node, field, v),
Enum v => DrawProperty(props, node, field, v),
float v => DrawProperty(props, node, field, v),
GroupAssignment v => DrawProperty(props, node, field, v, root, tree, ws),
_ => false
};
}

// draw custom stuff
node.DrawCustom(tree, ws);
}

private static string GenerateNodeName(Type t) => t.Name.EndsWith("Config") ? t.Name.Remove(t.Name.Length - "Config".Length) : t.Name;

private void SortByOrder(List<UINode> nodes)
Expand All @@ -81,32 +109,12 @@ private void DrawNodes(List<UINode> nodes)
{
foreach (var n in _tree.Nodes(nodes, n => new(n.Name)))
{
// draw standard properties
foreach (var field in n.Node.GetType().GetFields())
{
var props = field.GetCustomAttribute<PropertyDisplayAttribute>();
if (props == null)
continue;

_ = field.GetValue(n.Node) switch
{
bool v => DrawProperty(props, n.Node, field, v),
Enum v => DrawProperty(props, n.Node, field, v),
float v => DrawProperty(props, n.Node, field, v),
GroupAssignment v => DrawProperty(props, n.Node, field, v),
_ => false
};
}

// draw custom stuff
n.Node.DrawCustom(_tree, _ws);

// draw subnodes
DrawNode(n.Node, _root, _tree, _ws);
DrawNodes(n.Children);
}
}

private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, bool v)
private static bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, bool v)
{
var combo = member.GetCustomAttribute<PropertyComboAttribute>();
if (combo != null)
Expand All @@ -128,7 +136,7 @@ private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, Field
return true;
}

private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, Enum v)
private static bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, Enum v)
{
if (UICombo.Enum(props.Label, ref v))
{
Expand All @@ -138,7 +146,7 @@ private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, Field
return true;
}

private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, float v)
private static bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, float v)
{
var slider = member.GetCustomAttribute<PropertySliderAttribute>();
if (slider != null)
Expand All @@ -163,15 +171,15 @@ private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, Field
return true;
}

private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, GroupAssignment v)
private static bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, FieldInfo member, GroupAssignment v, ConfigRoot root, UITree tree, WorldState ws)
{
var group = member.GetCustomAttribute<GroupDetailsAttribute>();
if (group == null)
return false;

foreach (var tn in _tree.Node(props.Label, false, v.Validate() ? 0xffffffff : 0xff00ffff, () => DrawPropertyContextMenu(node, member, v)))
foreach (var tn in tree.Node(props.Label, false, v.Validate() ? 0xffffffff : 0xff00ffff, () => DrawPropertyContextMenu(node, member, v)))
{
var assignments = _root.Get<PartyRolesConfig>().SlotsPerAssignment(_ws.Party);
var assignments = root.Get<PartyRolesConfig>().SlotsPerAssignment(ws.Party);
if (ImGui.BeginTable("table", group.Names.Length + 2, ImGuiTableFlags.SizingFixedFit))
{
foreach (var n in group.Names)
Expand Down Expand Up @@ -201,7 +209,7 @@ private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, Field

string name = r.ToString();
if (assignments.Length > 0)
name += $" ({_ws.Party[assignments[i]]?.Name})";
name += $" ({ws.Party[assignments[i]]?.Name})";
ImGui.TableNextColumn();
ImGui.TextUnformatted(name);
}
Expand All @@ -211,7 +219,7 @@ private bool DrawProperty(PropertyDisplayAttribute props, ConfigNode node, Field
return true;
}

private void DrawPropertyContextMenu(ConfigNode node, FieldInfo member, GroupAssignment v)
private static void DrawPropertyContextMenu(ConfigNode node, FieldInfo member, GroupAssignment v)
{
foreach (var preset in member.GetCustomAttributes<GroupPresetAttribute>())
{
Expand Down
Loading

0 comments on commit 15beed2

Please sign in to comment.