Skip to content

Commit

Permalink
[#244] feature(core; options dialog): added ability to disable aura o…
Browse files Browse the repository at this point in the history
…n pet's nameplates
  • Loading branch information
casualshammy committed Nov 3, 2024
1 parent 083701d commit 80d782f
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 54 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<strong>110002.10-release (2024/10/13)</strong>
<strong>110005.0-release (2024/11/03)</strong>
<ul>
<li>Added option to select instance types for dispellable auras (https://github.com/casualshammy/NameplateAuras/issues/240)</li>
<li>Added option to disable aura on pet nameplates (https://github.com/casualshammy/NameplateAuras/issues/244)</li>
<li>TOC update</li>
</ul>
<br>
<details>
<summary>Previous versions</summary>
<strong>110002.10-release (2024/10/13)</strong>
<ul>
<li>Added option to select instance types for dispellable auras (https://github.com/casualshammy/NameplateAuras/issues/240)</li>
</ul>
<br>
<strong>110002.9-release (2024/09/22)</strong>
<ul>
<li>Localization update</li>
Expand Down
2 changes: 1 addition & 1 deletion NameplateAuras.toc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Interface: 110002
## Interface: 110005
## Title: NameplateAuras
## Notes: Displays people's buffs/debuffs above their nameplates
## SavedVariables: NameplateAurasAceDB
Expand Down
6 changes: 3 additions & 3 deletions locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ L["options:apps:dr:pvp"] = "PvP"
L["options:apps:dr:pve"] = "PvE (stun only)"
L["options:general:show-on-target-only"] = "Show auras on target's nameplate only"
L["options:alpha:use-target-alpha-if-not-target-selected"] = "Display auras with target's alpha if no target selected"
L["options:auras:show-on-npcs-and-players"] = "Show this aura on players and NPC"
L["options:auras:show-on-players"] = "Show this aura on players only"
L["options:auras:show-on-npcs"] = "Show this aura on NPC only"
L["options:apps:spiteful"] = "Highlight Spiteful Shade (Spiteful M+ affix)";
L["instance-type:arena"] = "Arenas"
L["instance-type:none"] = "Open World"
Expand Down Expand Up @@ -258,5 +255,8 @@ L["options:size-and-position:anchor-frame:healthbar"] = "Healthbar";
L["options:size-and-position:anchor-point-to-nameplate"] = "Anchor point";
L["options:size-and-position:anchor-point-of-frame"] = "Anchor point of icons group";
L["options:apps:dispellable-spells:instance-types"] = "Set the instance types in which dispelable auras will be displayed";
L["options:auras:show-on-players-1"] = "Show on players";
L["options:auras:show-on-npcs-1"] = "Show on NPCs";
L["options:auras:show-on-pets"] = "Show on pets";

--@end-debug@
3 changes: 0 additions & 3 deletions locales/ruRU.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ L["options:auras:enabled-state:tooltip"] = [=[%s: аура не будет по
%s: показывать все ауры]=]
L["options:auras:enabled-state-all"] = "Включено, показывать все ауры"
L["options:auras:enabled-state-mineonly"] = "Включено, показывать только мои ауры"
L["options:auras:show-on-npcs"] = "Показывать эту ауру только на НПС"
L["options:auras:show-on-npcs-and-players"] = "Показывать эту ауру на игроках и НПС"
L["options:auras:show-on-players"] = "Показывать эту ауру только на игроках"
L["options:borders:BORDER_TYPE_BUILTIN"] = "Встроенный"
L["options:borders:BORDER_TYPE_CUSTOM"] = "Пользовательский"
L["options:borders:border-file-path"] = "Путь до файла текстуры границы (начинается с 'Interface\\')"
Expand Down
28 changes: 19 additions & 9 deletions src/NameplateAuras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ do
BORDER_TEXTURES = addonTable.BORDER_TEXTURES;
end
local ATTACH_TYPE_NAMEPLATE, ATTACH_TYPE_HEALTHBAR, ATTACH_TYPE_TPTP = addonTable.ATTACH_TYPE_NAMEPLATE, addonTable.ATTACH_TYPE_HEALTHBAR, addonTable.ATTACH_TYPE_TPTP;
local UNIT_TYPE_PLAYER, UNIT_TYPE_NPC, UNIT_TYPE_PET = addonTable.UNIT_TYPE_PLAYER, addonTable.UNIT_TYPE_NPC, addonTable.UNIT_TYPE_PET;

-- // utilities
local Print, SpellTextureByID, SpellNameByID = addonTable.Print, addonTable.SpellTextureByID, addonTable.SpellNameByID;
local Print, SpellTextureByID, SpellNameByID, GetUnitTypeByGuid = addonTable.Print, addonTable.SpellTextureByID, addonTable.SpellNameByID, addonTable.GetUnitTypeByGuid;

local UpdateUnitAurasFull, UpdateUnitAurasIncremental;
do
Expand Down Expand Up @@ -378,7 +379,6 @@ do
local GLOW_TYPE_NONE, GLOW_TYPE_ACTIONBUTTON, GLOW_TYPE_AUTOUSE, GLOW_TYPE_PIXEL, GLOW_TYPE_ACTIONBUTTON_DIM =
addonTable.GLOW_TYPE_NONE, addonTable.GLOW_TYPE_ACTIONBUTTON, addonTable.GLOW_TYPE_AUTOUSE, addonTable.GLOW_TYPE_PIXEL, addonTable.GLOW_TYPE_ACTIONBUTTON_DIM;
local AURA_SORT_MODE_CUSTOM = addonTable.AURA_SORT_MODE_CUSTOM;
local SHOW_ON_PLAYERS, SHOW_ON_NPC = addonTable.SHOW_ON_PLAYERS, addonTable.SHOW_ON_NPC;
local glowInfo = { };
local animationInfo = { };
local defaultCustomSortFunction = function(aura1, aura2) return aura1.spellName < aura2.spellName; end;
Expand Down Expand Up @@ -926,7 +926,7 @@ do
end
addonTable.UpdateAllNameplates = UpdateAllNameplates;

local function ProcAurasForNmplt_Filter(auraType, _auraData, unitIsFriend, dbEntry, unitIsPlayer, unitId, _iconGroupIndex)
local function ProcAurasForNmplt_Filter(auraType, _auraData, unitIsFriend, dbEntry, _unitType, unitId, _iconGroupIndex)
if (dbEntry == nil) then
return false;
end
Expand All @@ -947,9 +947,18 @@ do
return false;
end

local playerNpcMode = dbEntry.playerNpcMode;
if ((playerNpcMode == SHOW_ON_NPC and unitIsPlayer) or (playerNpcMode == SHOW_ON_PLAYERS and not unitIsPlayer)) then
return false;
if (_unitType == UNIT_TYPE_PLAYER) then
if (not dbEntry.showOnPlayers) then
return false;
end
elseif (_unitType == UNIT_TYPE_NPC) then
if (not dbEntry.showOnNpcs) then
return false;
end
elseif (_unitType == UNIT_TYPE_PET) then
if (not dbEntry.showOnPets) then
return false;
end
end

if (dbEntry.checkSpellID ~= nil and not dbEntry.checkSpellID[_auraData.spellId]) then
Expand Down Expand Up @@ -1043,7 +1052,7 @@ do
end
end

local function ProcAurasForNmplt_OnNewAuraEx(_auraData, unitIsFriend, frame, unitIsPlayer, unitId, _iconGroupsToUpdate)
local function ProcAurasForNmplt_OnNewAuraEx(_auraData, unitIsFriend, frame, _unitType, unitId, _iconGroupsToUpdate)
local auraType = _auraData.isHarmful and AURA_TYPE_DEBUFF or AURA_TYPE_BUFF;
local auraName = _auraData.name;
for iconGroupIndex, iconGroup in pairs(_iconGroupsToUpdate) do
Expand All @@ -1052,7 +1061,7 @@ do
local cache = spellCache[auraName];
if (cache ~= nil) then
for _, dbEntry in pairs(cache) do
if (ProcAurasForNmplt_Filter(auraType, _auraData, unitIsFriend, dbEntry, unitIsPlayer, unitId, iconGroupIndex)) then
if (ProcAurasForNmplt_Filter(auraType, _auraData, unitIsFriend, dbEntry, _unitType, unitId, iconGroupIndex)) then
AurasPerNameplate[frame][iconGroupIndex][tSize+1] = {
["duration"] = _auraData.duration,
["expires"] = _auraData.expirationTime,
Expand Down Expand Up @@ -1159,6 +1168,7 @@ do
local unitIsFriend = (UnitReaction("player", unitID) or 0) > 4; -- 4 = neutral
local unitIsPlayer = UnitIsPlayer(unitID);
local unitGUID = UnitGUID(unitID);
local unitType = GetUnitTypeByGuid(unitGUID);

local iconGroupsToUpdate = {};
for iconGroupIndex, iconGroup in pairs(db.IconGroups) do
Expand Down Expand Up @@ -1189,7 +1199,7 @@ do
local auras = PlayerAurasPerGuid[unitGUID];
if (auras ~= nil) then
for _, auraData in pairs(auras) do
ProcAurasForNmplt_OnNewAuraEx(auraData, unitIsFriend, frame, unitIsPlayer, unitID, iconGroupsToUpdate);
ProcAurasForNmplt_OnNewAuraEx(auraData, unitIsFriend, frame, unitType, unitID, iconGroupsToUpdate);
end
end

Expand Down
10 changes: 5 additions & 5 deletions src/consts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ addonTable.DR_TEXTURES = {
["taunt"] = [[Interface\AddOns\NameplateAuras\media\square-red.tga]],
};

addonTable.SHOW_ON_PLAYERS_AND_NPC = 1;
addonTable.SHOW_ON_PLAYERS = 2;
addonTable.SHOW_ON_NPC = 3;

addonTable.SPITEFUL_NPC_ID_STRING = "174773";
addonTable.SPITEFUL_SPELL_ID = 69861;

Expand All @@ -94,4 +90,8 @@ addonTable.EPIC_BG_ZONE_IDS = {

addonTable.ATTACH_TYPE_NAMEPLATE = 1;
addonTable.ATTACH_TYPE_HEALTHBAR = 2;
addonTable.ATTACH_TYPE_TPTP = 3;
addonTable.ATTACH_TYPE_TPTP = 3;

addonTable.UNIT_TYPE_PLAYER = 1;
addonTable.UNIT_TYPE_NPC = 2;
addonTable.UNIT_TYPE_PET = 3;
26 changes: 24 additions & 2 deletions src/database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,22 @@ local migrations = {
end
end
end,
[33] = function()
local db = addonTable.db;
for _, spellInfo in pairs(db.CustomSpells2) do
local playerNpcMode = spellInfo.playerNpcMode;
if (spellInfo.showOnPlayers == nil) then
spellInfo.showOnPlayers = (playerNpcMode == 1 or playerNpcMode == 2); -- SHOW_ON_PLAYERS_AND_NPC or SHOW_ON_PLAYERS
end
if (spellInfo.showOnNpcs == nil) then
spellInfo.showOnNpcs = (playerNpcMode == 1 or playerNpcMode == 3); -- SHOW_ON_PLAYERS_AND_NPC or SHOW_ON_NPC
end
if (spellInfo.showOnPets == nil) then
spellInfo.showOnPets = (playerNpcMode == 1 or playerNpcMode == 3); -- SHOW_ON_PLAYERS_AND_NPC or SHOW_ON_NPC
end
spellInfo.playerNpcMode = nil;
end
end,
};

local function FillInMissingEntriesIsSpells()
Expand Down Expand Up @@ -579,8 +595,14 @@ local function FillInMissingEntriesIsSpells()
if (spellInfo.showOnEnemies == nil) then
spellInfo.showOnEnemies = true;
end
if (spellInfo.playerNpcMode == nil) then
spellInfo.playerNpcMode = addonTable.SHOW_ON_PLAYERS_AND_NPC;
if (spellInfo.showOnPlayers == nil) then
spellInfo.showOnPlayers = true;
end
if (spellInfo.showOnNpcs == nil) then
spellInfo.showOnNpcs = true;
end
if (spellInfo.showOnPets == nil) then
spellInfo.showOnPets = true;
end
if (spellInfo.auraType == nil) then
spellInfo.auraType = AURA_TYPE_ANY;
Expand Down
73 changes: 45 additions & 28 deletions src/options-dialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ local function GetDefaultDBSpellEntry(enabledState, spellName, checkSpellID)
["checkSpellID"] = checkSpellID,
["showOnFriends"] = true,
["showOnEnemies"] = true,
["playerNpcMode"] = addonTable.SHOW_ON_PLAYERS_AND_NPC,
["showOnPlayers"] = true,
["showOnNpcs"] = true,
["showOnPets"] = true,
["showGlow"] = nil,
["glowType"] = addonTable.GLOW_TYPE_AUTOUSE,
["animationType"] = addonTable.ICON_ANIMATION_TYPE_ALPHA,
Expand Down Expand Up @@ -1966,10 +1968,11 @@ local function GUICategory_4(index)
local selectedSpell = 0;
local dropdownMenuSpells = VGUI.CreateDropdownMenu2();
local spellArea, editboxAddSpell, buttonAddSpell, sliderSpellIconSizeWidth, dropdownSpellShowType, editboxSpellID, buttonDeleteSpell, checkboxShowOnFriends, checkboxAnimationRelative,
checkboxShowOnEnemies, checkboxPvPMode, checkboxEnabled, checkboxGlow, areaGlow, sliderGlowThreshold, areaIconSize, areaAuraType, areaIDs, checkboxGlowRelative,
checkboxShowOnEnemies, checkboxEnabled, checkboxGlow, areaGlow, sliderGlowThreshold, areaIconSize, areaAuraType, areaIDs, checkboxGlowRelative,
dropdownGlowType, areaAnimation, checkboxAnimation, dropdownAnimationType, sliderAnimationThreshold, sliderSpellIconSizeHeight;
local areaCustomBorder, checkboxCustomBorder, textboxCustomBorderPath, sliderCustomBorderSize, colorPickerCustomBorderColor, buttonExportSpell, areaTooltip, editboxSpellTooltip;
local areaIconGroups, dropdownIconGroups, checkboxConsolidate, checkboxOverrideSize, currentSpellTitle;
local checkboxPlayers, checkboxNpcs, checkboxPets;

local AuraTypesLocalization = {
[AURA_TYPE_BUFF] = L["Buff"],
Expand Down Expand Up @@ -2052,13 +2055,9 @@ local function GUICategory_4(index)
else
checkboxEnabled:SetTriState(1);
end
if (spellInfo.playerNpcMode == addonTable.SHOW_ON_PLAYERS_AND_NPC) then
checkboxPvPMode:SetTriState(0);
elseif (spellInfo.playerNpcMode == addonTable.SHOW_ON_PLAYERS) then
checkboxPvPMode:SetTriState(1);
else
checkboxPvPMode:SetTriState(2);
end
checkboxPlayers:SetChecked(spellInfo.showOnPlayers);
checkboxNpcs:SetChecked(spellInfo.showOnNpcs);
checkboxPets:SetChecked(spellInfo.showOnPets);
if (spellInfo.showGlow == nil) then
checkboxGlow:SetTriState(0);
sliderGlowThreshold:Hide();
Expand Down Expand Up @@ -2729,27 +2728,45 @@ local function GUICategory_4(index)
table_insert(controls, checkboxShowOnEnemies);
end

-- // checkboxPvPMode
-- // checkboxPlayers
do
checkboxPvPMode = VGUI.CreateCheckBoxTristate();
checkboxPvPMode:SetTextEntries({
L["options:auras:show-on-npcs-and-players"],
addonTable.ColorizeText(L["options:auras:show-on-players"], 1, 0, 0),
addonTable.ColorizeText(L["options:auras:show-on-npcs"], 0, 1, 0),
});
checkboxPvPMode:SetOnClickHandler(function(self)
if (self:GetTriState() == 0) then
addonTable.db.CustomSpells2[selectedSpell].playerNpcMode = addonTable.SHOW_ON_PLAYERS_AND_NPC;
elseif (self:GetTriState() == 1) then
addonTable.db.CustomSpells2[selectedSpell].playerNpcMode = addonTable.SHOW_ON_PLAYERS;
else
addonTable.db.CustomSpells2[selectedSpell].playerNpcMode = addonTable.SHOW_ON_NPC;
end
checkboxPlayers = VGUI.CreateCheckBox();
checkboxPlayers:SetText(L["options:auras:show-on-players-1"]);
checkboxPlayers:SetOnClickHandler(function(_self)
addonTable.db.CustomSpells2[selectedSpell].showOnPlayers = _self:GetChecked();
addonTable.UpdateAllNameplates(false);
end);
checkboxPlayers:SetParent(spellArea.controlsFrame);
checkboxPlayers:SetPoint("TOPLEFT", checkboxShowOnEnemies, "TOPLEFT", 0, -20);
table_insert(controls, checkboxPlayers);

end

-- // checkboxNpcs
do
checkboxNpcs = VGUI.CreateCheckBox();
checkboxNpcs:SetText(L["options:auras:show-on-npcs-1"]);
checkboxNpcs:SetOnClickHandler(function(_self)
addonTable.db.CustomSpells2[selectedSpell].showOnNpcs = _self:GetChecked();
addonTable.UpdateAllNameplates(false);
end);
checkboxNpcs:SetParent(spellArea.controlsFrame);
checkboxNpcs:SetPoint("TOPLEFT", checkboxPlayers, "TOPLEFT", 0, -20);
table_insert(controls, checkboxNpcs);

end

-- // checkboxPets
do
checkboxPets = VGUI.CreateCheckBox();
checkboxPets:SetText(L["options:auras:show-on-pets"]);
checkboxPets:SetOnClickHandler(function(_self)
addonTable.db.CustomSpells2[selectedSpell].showOnPets = _self:GetChecked();
addonTable.UpdateAllNameplates(false);
end);
checkboxPvPMode:SetParent(spellArea.controlsFrame);
checkboxPvPMode:SetPoint("TOPLEFT", 15, -75);
table_insert(controls, checkboxPvPMode);
checkboxPets:SetParent(spellArea.controlsFrame);
checkboxPets:SetPoint("TOPLEFT", checkboxNpcs, "TOPLEFT", 0, -20);
table_insert(controls, checkboxPets);

end

Expand All @@ -2763,7 +2780,7 @@ local function GUICategory_4(index)
addonTable.UpdateAllNameplates(false);
end);
checkboxConsolidate:SetParent(spellArea.controlsFrame);
checkboxConsolidate:SetPoint("TOPLEFT", checkboxPvPMode, "BOTTOMLEFT", 0, 0);
checkboxConsolidate:SetPoint("TOPLEFT", checkboxPets, "BOTTOMLEFT", 0, 0);
table_insert(controls, checkboxConsolidate);
end

Expand Down
24 changes: 23 additions & 1 deletion src/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ local L = LibStub("AceLocale-3.0"):GetLocale("NameplateAuras");
local SML = LibStub("LibSharedMedia-3.0");
SML:Register("font", "NAuras_TeenBold", "Interface\\AddOns\\NameplateAuras\\media\\teen_bold.ttf", 255);
SML:Register("font", "NAuras_TexGyreHerosBold", "Interface\\AddOns\\NameplateAuras\\media\\texgyreheros-bold-webfont.ttf", 255);
local pairs, select, string_format = pairs, select, format;
local pairs, select, string_format, string_find = pairs, select, format, string.find;
local GetSpellTexture, GetSpellInfo, GetPlayerInfoByGUID, GetUnitName, wipe = C_Spell.GetSpellTexture, C_Spell.GetSpellInfo, GetPlayerInfoByGUID, GetUnitName, wipe;
local UNIT_TYPE_PLAYER, UNIT_TYPE_NPC, UNIT_TYPE_PET = addonTable.UNIT_TYPE_PLAYER, addonTable.UNIT_TYPE_NPC, addonTable.UNIT_TYPE_PET;
local p_unitNameByGuid = { };
local p_unitTypeByGuid = { };

addonTable.SpellTextureByID = setmetatable({
[197690] = GetSpellTexture(71), -- // override for defensive stance
Expand Down Expand Up @@ -177,6 +179,26 @@ function addonTable.GetOrAddUnitNameByGuid(_unitGuid, _unitId)
end
end

function addonTable.GetUnitTypeByGuid(_unitGuid)
local cachedType = p_unitTypeByGuid[_unitGuid];
if (cachedType ~= nil) then
return cachedType;
end

if (string_find(_unitGuid, "Player-") == 1) then
p_unitTypeByGuid[_unitGuid] = UNIT_TYPE_PLAYER;
return UNIT_TYPE_PLAYER;
end

if (string_find(_unitGuid, "Pet-") == 1) then
p_unitTypeByGuid[_unitGuid] = UNIT_TYPE_PET;
return UNIT_TYPE_PET;
end

p_unitTypeByGuid[_unitGuid] = UNIT_TYPE_NPC;
return UNIT_TYPE_NPC;
end

-- // CoroutineProcessor
do
addonTable.CoroutineProcessor = {};
Expand Down

0 comments on commit 80d782f

Please sign in to comment.