Skip to content

Commit

Permalink
Add option to show free company members
Browse files Browse the repository at this point in the history
  • Loading branch information
SheepGoMeh committed Sep 12, 2020
1 parent 14c68f2 commit d33634b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 14 deletions.
44 changes: 41 additions & 3 deletions Visibility/Configuration/VisibilityConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ public bool HideChocobo
set => _hideChocobo = value;
}

public bool ShowCompanyPet
{
get => _showCompanyPet;
set => _showCompanyPet = value;
}

public bool ShowCompanyPlayer
{
get => _showCompanyPlayer;
set => _showCompanyPlayer = value;
}

public bool ShowCompanyChocobo
{
get => _showCompanyChocobo;
set => _showCompanyChocobo = value;
}

public bool ShowPartyPet
{
get => _showPartyPet;
Expand Down Expand Up @@ -143,10 +161,17 @@ public bool ShowDeadPlayer
private bool _showFriendChocobo = false;
[NonSerialized]
private bool _showDeadPlayer = false;

[NonSerialized]
private bool _showCompanyPet = false;
[NonSerialized]
private bool _showCompanyPlayer = false;
[NonSerialized]
private bool _showCompanyChocobo = false;

[NonSerialized]
public readonly Dictionary<string, Action<bool>> settingDictionary = new Dictionary<string, Action<bool>>();


public void Init(VisibilityPlugin plugin, DalamudPluginInterface pluginInterface)
{
_plugin = plugin;
Expand All @@ -155,6 +180,9 @@ public void Init(VisibilityPlugin plugin, DalamudPluginInterface pluginInterface
settingDictionary["hidepet"] = x => _hidePet = x;
settingDictionary["hideplayer"] = x => _hidePlayer = x;
settingDictionary["hideminion"] = x => _hideMinion = x;
settingDictionary["showcompanypet"] = x => _showCompanyPet = x;
settingDictionary["showcompanyplayer"] = x => _showCompanyPlayer = x;
settingDictionary["showcompanychocobo"] = x => _showCompanyChocobo = x;
settingDictionary["showpartypet"] = x => _showPartyPet = x;
settingDictionary["showpartyplayer"] = x => _showPartyPlayer = x;
settingDictionary["showpartychocobo"] = x => _showPartyChocobo = x;
Expand All @@ -181,7 +209,7 @@ public bool DrawConfigUi()

var scale = ImGui.GetIO().FontGlobalScale;

ImGui.SetNextWindowSize(new Vector2(450 * scale, 230), ImGuiCond.Always);
ImGui.SetNextWindowSize(new Vector2(500 * scale, 230), ImGuiCond.Always);
ImGui.Begin($"{_plugin.Name} Config", ref drawConfig, ImGuiWindowFlags.NoResize);

if (ImGui.Checkbox($"###{nameof(_plugin.enabled)}", ref _plugin.enabled))
Expand All @@ -194,7 +222,7 @@ public bool DrawConfigUi()
ImGui.Text("Enable");
ImGui.Separator();

ImGui.Columns(5, "###cols", false);
ImGui.Columns(6, "###cols", false);

ImGui.NextColumn();
ImGui.Text("Hide all");
Expand All @@ -205,6 +233,8 @@ public bool DrawConfigUi()
ImGui.NextColumn();
ImGui.Text("Show dead");
ImGui.NextColumn();
ImGui.Text("Show FC");
ImGui.NextColumn();
ImGui.Separator();
ImGui.Text("Pets");
ImGui.NextColumn();
Expand All @@ -215,6 +245,8 @@ public bool DrawConfigUi()
Checkbox(nameof(_showFriendPet), ref _showFriendPet);
ImGui.NextColumn();
ImGui.NextColumn();
Checkbox(nameof(_showCompanyPet), ref _showCompanyPet);
ImGui.NextColumn();

ImGui.Text("Minions");
ImGui.NextColumn();
Expand All @@ -223,6 +255,7 @@ public bool DrawConfigUi()
ImGui.NextColumn();
ImGui.NextColumn();
ImGui.NextColumn();
ImGui.NextColumn();

ImGui.Text("Chocobos");
ImGui.NextColumn();
Expand All @@ -233,6 +266,8 @@ public bool DrawConfigUi()
Checkbox(nameof(_showFriendChocobo), ref _showFriendChocobo);
ImGui.NextColumn();
ImGui.NextColumn();
Checkbox(nameof(_showCompanyChocobo), ref _showCompanyChocobo);
ImGui.NextColumn();

ImGui.Text("Players");
ImGui.NextColumn();
Expand All @@ -244,6 +279,8 @@ public bool DrawConfigUi()
ImGui.NextColumn();
Checkbox(nameof(_showDeadPlayer), ref _showDeadPlayer);
ImGui.NextColumn();
Checkbox(nameof(_showCompanyPlayer), ref _showCompanyPlayer);
ImGui.NextColumn();
ImGui.Separator();

if (ImGui.Button("Refresh"))
Expand All @@ -255,6 +292,7 @@ public bool DrawConfigUi()
ImGui.NextColumn();
ImGui.NextColumn();
ImGui.NextColumn();
ImGui.NextColumn();

if (ImGui.Button("VoidList"))
{
Expand Down
30 changes: 19 additions & 11 deletions Visibility/VisibilityPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ private void OnChatMessage(XivChatType type, uint senderId, ref SeString sender,
}
}

private void CheckRender<T>(IEnumerable<T> collection, ICollection<int> friendCollection, ref bool oneShot,
bool hide = false, bool showParty = false, bool showFriend = false, bool showDead = false, IEnumerable<Actor> mounts = null) where T: Actor
private void CheckRender<T>(IEnumerable<T> collection, ICollection<int> friendCollection,
ICollection<int> companyCollection, ref bool oneShot, bool hide = false, bool showParty = false,
bool showFriend = false, bool showCompany = false, bool showDead = false, IEnumerable<Actor> mounts = null)
where T : Actor
{
if (hide)
{
Expand All @@ -263,6 +265,7 @@ private void CheckRender<T>(IEnumerable<T> collection, ICollection<int> friendCo
var lookupId = item is BattleNpc battleNpc ? battleNpc.OwnerId : item.ActorId;
if ((showParty && _partyActorId.Contains(lookupId))
|| (showFriend && friendCollection.Contains(lookupId))
|| (showCompany && companyCollection.Contains(lookupId))
|| (showDead && (item as Chara).CurrentHp == 0))
{
item.Render();
Expand Down Expand Up @@ -329,8 +332,10 @@ where actor is PlayerCharacter character
where actor.IsStatus(StatusFlags.Friend)
select actor.ActorId).ToHashSet();

var partyMembers = (from actor in _pluginInterface.ClientState.Actors
where Array.Exists(_partyActorId, actorId => actorId == actor.ActorId)
var companyMembers = (from actor in _pluginInterface.ClientState.Actors
where actor is PlayerCharacter playerCharacter
&& !string.IsNullOrEmpty(playerCharacter.CompanyTag)
&& playerCharacter.CompanyTag == _pluginInterface.ClientState.LocalPlayer?.CompanyTag
select actor.ActorId).ToHashSet();

var pets = from actor in _pluginInterface.ClientState.Actors
Expand All @@ -354,15 +359,17 @@ where actor is BattleNpc npc
&& npc.OwnerId != _pluginInterface.ClientState.LocalPlayer?.ActorId
select actor as BattleNpc;

CheckRender(chocobos, friends,
CheckRender(chocobos, friends, companyMembers,
ref _oneShot[0], _pluginConfig.HideChocobo,
_pluginConfig.ShowPartyChocobo,
_pluginConfig.ShowFriendChocobo);
_pluginConfig.ShowFriendChocobo,
_pluginConfig.ShowCompanyChocobo);

CheckRender(pets, friends,
CheckRender(pets, friends, companyMembers,
ref _oneShot[1], _pluginConfig.HidePet,
_pluginConfig.ShowPartyPet,
_pluginConfig.ShowFriendPet);
_pluginConfig.ShowFriendPet,
_pluginConfig.ShowCompanyPet);

if (!_pluginInterface.ClientState.Condition[ConditionFlag.BoundByDuty])
{
Expand All @@ -371,15 +378,16 @@ where actor is BattleNpc npc
item.Hide();
}

CheckRender(players, friends,
CheckRender(players, friends, companyMembers,
ref _oneShot[2], _pluginConfig.HidePlayer,
_pluginConfig.ShowPartyPlayer,
_pluginConfig.ShowFriendPlayer,
_pluginConfig.ShowCompanyPlayer,
_pluginConfig.ShowDeadPlayer);
}

CheckRender(minions, friends, ref _oneShot[3],
_pluginConfig.HideMinion, false, false, false, mounts);
CheckRender(minions, friends, companyMembers, ref _oneShot[3],
_pluginConfig.HideMinion, false, false, false, false, mounts);

foreach (var item in voidItems)
{
Expand Down

0 comments on commit d33634b

Please sign in to comment.