Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

borders for the item icon and aura icons + various options relating to that #48

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1d8bfc1
actual pixel perfect borders (with mouseanchor)
NoBetaBoredom Feb 6, 2022
8758aba
borders for icon and auras with various options
NoBetaBoredom Feb 7, 2022
25e2abf
compacted the old borderstyle within the new one
NoBetaBoredom Feb 7, 2022
286d2a5
small fix
NoBetaBoredom Feb 7, 2022
a610032
removed min distance between buffs/debuffs
NoBetaBoredom Feb 7, 2022
5c6ea09
better "slight fix"
NoBetaBoredom Feb 7, 2022
5196e96
pixelperfect borders now work with any scale set in the "Special" opt…
NoBetaBoredom Feb 7, 2022
a276986
itemicon should be above the comparing tooltip
NoBetaBoredom Feb 7, 2022
3cdb83d
made applicable without /reload, fixed calc error
NoBetaBoredom Feb 8, 2022
58bf6bb
made applicable without /reload
NoBetaBoredom Feb 8, 2022
703faa0
small bug
NoBetaBoredom Feb 8, 2022
a10f5b4
item compare now takes itemicons into account
NoBetaBoredom Feb 9, 2022
88737ca
fixed retail and added SmartIcon support for comparing items
NoBetaBoredom Feb 9, 2022
55608ba
typo
NoBetaBoredom Feb 9, 2022
5cf6599
tooltip icon is now also clamped to the screen
NoBetaBoredom Feb 9, 2022
f1457fb
set insets on item icon, some applyconfig stuff
NoBetaBoredom Feb 9, 2022
65dc8ed
fixed rare error
NoBetaBoredom Feb 9, 2022
75cef6e
actually fixed the rare error
NoBetaBoredom Feb 9, 2022
c272c50
actually actually fixed the rare error
NoBetaBoredom Feb 9, 2022
5ad859d
apply insets to the cooldown texture aswell
NoBetaBoredom Feb 10, 2022
f551e2a
typo
NoBetaBoredom Feb 10, 2022
7a9c669
aura icons are also clamped to the screen now
NoBetaBoredom Feb 11, 2022
fc809bc
small fix for auraicons clamping
NoBetaBoredom Feb 12, 2022
7d4ff4a
removed unnecessary pixelconversion on itemicon
NoBetaBoredom Feb 17, 2022
b31494e
cleanup
NoBetaBoredom Feb 18, 2022
bb8b631
Merge branch 'main' into iconborders
NoBetaBoredom Feb 18, 2022
8617a2c
insets need to be converted too, or it will be wrong for different sc…
NoBetaBoredom Feb 18, 2022
cac420f
insets only with option set
NoBetaBoredom Feb 18, 2022
80311c2
need this to be able to set real pixel sizes
NoBetaBoredom Feb 18, 2022
9810a3d
need this to be able to set real pixel sizes
NoBetaBoredom Feb 18, 2022
bf553cd
Merge branch 'main' into iconborders
NoBetaBoredom Feb 19, 2022
46ddf43
refactored, optional aura pixelperfect scaling
NoBetaBoredom Feb 20, 2022
d41132a
cleanup
NoBetaBoredom Feb 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 143 additions & 35 deletions TipTac/ttAuras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,115 @@ local validSelfCasterUnits = {
--------------------------------------------------------------------------------------------------------

local function CreateAuraFrame(parent)
local aura = CreateFrame("Frame",nil,parent);
aura:SetSize(cfg.auraSize,cfg.auraSize);
local aura = CreateFrame("Frame", nil, parent);
if (cfg.auraPixelPerfectPositioning) then
aura:SetScale(tt.ppScale / cfg.gttScale);
end
aura:SetSize(cfg.auraSize, cfg.auraSize);

aura.count = aura:CreateFontString(nil,"OVERLAY");
aura.count:SetPoint("BOTTOMRIGHT",1,0);
aura.count:SetFont(GameFontNormal:GetFont(),(cfg.auraSize / 2),"OUTLINE");

aura.icon = aura:CreateTexture(nil,"BACKGROUND");
aura.icon:SetAllPoints();
aura.icon:SetTexCoord(0.07,0.93,0.07,0.93);
aura.icon = CreateFrame("Frame", nil, aura);
aura.icon:SetPoint("CENTER",aura,"CENTER");
aura.icon:SetSize(cfg.auraSize, cfg.auraSize);

aura.icon.texture = aura:CreateTexture(nil,"BACKGROUND");
aura.icon.texture:SetPoint("CENTER",aura.icon,"CENTER");
aura.icon.texture:SetTexCoord(0.07,0.93,0.07,0.93);
ttAuras:ApplyInsetsToIconTexture(aura.icon.texture, aura:GetParent().backdropInfo);

aura.cooldown = CreateFrame("Cooldown",nil,aura,"CooldownFrameTemplate");
aura.cooldown:SetReverse(1);
aura.cooldown:SetAllPoints();
aura.cooldown:SetFrameLevel(aura:GetFrameLevel());
aura.cooldown.noCooldownCount = cfg.noCooldownCount or nil;
aura.icon.cooldown = CreateFrame("Cooldown",nil,aura.icon,"CooldownFrameTemplate");
aura.icon.cooldown:SetReverse(1);
aura.icon.cooldown:SetPoint("CENTER",aura.icon,"CENTER");
aura.icon.cooldown:SetFrameLevel(aura:GetFrameLevel());
aura.icon.cooldown.noCooldownCount = cfg.noCooldownCount or nil;

aura.border = aura:CreateTexture(nil,"OVERLAY");
aura.border:SetPoint("TOPLEFT",-1,1);
aura.border:SetPoint("BOTTOMRIGHT",1,-1);
aura.border:SetTexture("Interface\\Buttons\\UI-Debuff-Overlays");
aura.border:SetTexCoord(0.296875,0.5703125,0,0.515625);
ttAuras:ApplyInsetsToIconTexture(aura.icon, aura:GetParent().backdropInfo);

aura.border = CreateFrame("Frame", nil, aura, BackdropTemplateMixin and "BackdropTemplate");
aura.border:SetAllPoints();
ttAuras:ApplyParentBackdropToAura(aura.border, aura:GetParent())
aura.border:SetFrameLevel(aura.icon.cooldown:GetFrameLevel()+1);

auras[#auras + 1] = aura;
return aura;
end

function ttAuras:ApplyParentBackdropToAura(aura, parent)
-- using the normal values here since the entire aura is scaled already
local parentBackdropInfo = parent.backdropInfo;
local backdropInfo;
if (cfg.auraPixelPerfectPositioning) then
local parentBackdropInfo = parent.backdropInfo;
backdropInfo = {
bgFile = parentBackdropInfo.bgFile,
edgeFile = parentBackdropInfo.edgeFile,
edgeSize = cfg.backdropEdgeSize,
insets = {left = cfg.backdropInsets, right = cfg.backdropInsets, top = cfg.backdropInsets, bottom = cfg.backdropInsets},
}
else
backdropInfo = parentBackdropInfo
end

aura:SetBackdrop(backdropInfo);
aura:SetBackdropColor(0, 0, 0, 0);
end

function ttAuras:ApplyInsetsToIconTexture(texture, backdropInfo)
-- manually implementing border insets because otherwise we cant remove the ugly default border
-- assumes symmetrical insets
if (cfg.auraPixelPerfectPositioning) then
texture:SetSize(cfg.auraSize - cfg.backdropInsets * 2, cfg.auraSize - cfg.backdropInsets * 2);
else
texture:SetSize(cfg.auraSize - backdropInfo.insets.left * 2, cfg.auraSize - backdropInfo.insets.top * 2);
end
end

function ttAuras:ConvertToRealPixels(pos)
if (cfg.auraPixelPerfectPositioning) then
return (pos / tt.ppScale * cfg.gttScale)
else
return pos
end
end

function ttAuras:ConvertToFakePixels(pos)
if (cfg.auraPixelPerfectPositioning) then
return (pos * tt.ppScale / cfg.gttScale)
else
return pos
end
end

function ttAuras:SetClamp(tip, furthestAuraIcon)
local basicOffset = 5;
local left, right, top, bottom = -basicOffset, basicOffset, basicOffset, -basicOffset;

if(furthestAuraIcon ~= nil) then
local leftDistance = ttAuras:ConvertToRealPixels(tip:GetLeft()) - furthestAuraIcon:GetLeft();
local rightDistance = furthestAuraIcon:GetRight() - ttAuras:ConvertToRealPixels(tip:GetRight());
local topDistance = furthestAuraIcon:GetTop() - ttAuras:ConvertToRealPixels(tip:GetTop());
local bottomDistance = ttAuras:ConvertToRealPixels(tip:GetBottom()) - furthestAuraIcon:GetBottom();

left = left + ((leftDistance > 0) and -leftDistance or 0);
right = right + ((rightDistance > 0) and rightDistance or 0);
top = top + ((topDistance > 0) and topDistance or 0);
bottom = bottom + ((bottomDistance > 0) and -bottomDistance or 0);
end

tip:SetClampedToScreen(true);
tip:SetClampRectInsets(ttAuras:ConvertToFakePixels(left), ttAuras:ConvertToFakePixels(right), ttAuras:ConvertToFakePixels(top), ttAuras:ConvertToFakePixels(bottom));
end

-- querires auras of the specific auraType, and sets up the aura frame and anchors it in the desired place
function ttAuras:DisplayAuras(tip,auraType,startingAuraFrameIndex)

local aurasPerRow = floor((tip:GetWidth() - 4) / (cfg.auraSize + 2)); -- auras we can fit into one row based on the current size of the tooltip
local xOffsetBasis = (auraType == "HELPFUL" and 1 or -1); -- is +1 or -1 based on horz anchoring
-- want them to be flush with the tooltips borders, means we subtract 1 offset since the very last one doesn't need to be there
-- aura icons don't scale because we need the exact width, have to change the size manually in the options instead.
local tooltipWidth = ttAuras:ConvertToRealPixels(tip:GetWidth());
local aurasPerRow = floor((tooltipWidth + cfg.auraOffsetX) / (cfg.auraSize + cfg.auraOffsetX)); -- auras we can fit into one row based on the current size of the tooltip
local xOffsetBasis = auraType == "HELPFUL" and cfg.auraOffsetX or -cfg.auraOffsetX; -- is +1 or -1 based on horz anchoring

local queryIndex = 1; -- aura query index for this auraType
local auraFrameIndex = startingAuraFrameIndex; -- array index for the next aura frame, initialized to the starting index
Expand All @@ -70,40 +147,59 @@ function ttAuras:DisplayAuras(tip,auraType,startingAuraFrameIndex)
if (not iconTexture) or (auraFrameIndex / aurasPerRow > cfg.auraMaxRows) then
break;
end

if (not cfg.selfAurasOnly or validSelfCasterUnits[casterUnit]) then
local aura = auras[auraFrameIndex] or CreateAuraFrame(tip);

-- Anchor It
aura:ClearAllPoints();
if ((auraFrameIndex - 1) % aurasPerRow == 0) or (auraFrameIndex == startingAuraFrameIndex) then
-- new aura line
local x = (xOffsetBasis * 2);
local y = (cfg.auraSize + 2) * floor((auraFrameIndex - 1) / aurasPerRow) + 1;
local x = 0;
local y = (cfg.auraSize + cfg.auraOffsetY) * floor((auraFrameIndex - 1) / aurasPerRow) + cfg.auraOffsetY;
y = (cfg.aurasAtBottom and -y or y);
aura:SetPoint(anchor1,tip,anchor2,x,y);
aura:SetPoint(anchor1, tip, anchor2, x, y);
else
-- anchor to last
aura:SetPoint(horzAnchor1, auras[auraFrameIndex - 1], horzAnchor2, (xOffsetBasis * 2), 0);
aura:SetPoint(horzAnchor1, auras[auraFrameIndex - 1], horzAnchor2, xOffsetBasis, 0);
end

-- Cooldown
if (cfg.showAuraCooldown) and (duration and duration > 0 and endTime and endTime > 0) then
aura.cooldown:SetCooldown(endTime - duration,duration);
aura.icon.cooldown:SetCooldown(endTime - duration,duration);
else
aura.cooldown:Hide();
aura.icon.cooldown:Hide();
end

-- Set Texture + Count
aura.icon:SetTexture(iconTexture);
aura.icon.texture:SetTexture(iconTexture);
aura.count:SetText(count and count > 1 and count or "");

-- Border -- Only shown for debuffs
if (auraType == "HARMFUL") then
local color = DebuffTypeColor[debuffType] or DebuffTypeColor["none"];
aura.border:SetVertexColor(color.r,color.g,color.b);
-- Border
if (cfg.auraCustomBorder) then
if (cfg.auraBorderUseParentColor) then
aura.border:SetBackdropBorderColor(tip:GetBackdropBorderColor());
else
if (auraType == "HARMFUL") then
if (cfg.auraBorderUseDebuffTypeColors) then
local color = DebuffTypeColor[debuffType] or DebuffTypeColor["none"];
aura.border:SetBackdropBorderColor(color.r, color.g, color.b);
else
aura.border:SetBackdropBorderColor(unpack(cfg.auraBorderDebuffColor));
end
else
aura.border:SetBackdropBorderColor(unpack(cfg.auraBorderBuffColor));
end
end
aura.border:Show();
else
aura.border:Hide();
-- old way (only debuffs)
if (auraType == "HARMFUL") then
local color = DebuffTypeColor[debuffType] or DebuffTypeColor["none"];
aura.border:SetBackdropBorderColor(color.r, color.g, color.b);
else
aura.border:Hide();
end
end

-- Show + Next, Break if exceed max desired rows of aura
Expand All @@ -121,12 +217,14 @@ end
function ttAuras:SetupAuras(tip)
--printf("[%.2f] %-24s %d x %d",GetTime(),"SetupAuras",tip:GetWidth(),tip:GetHeight())
local auraCount = 0;
if (cfg.showBuffs) then
auraCount = auraCount + self:DisplayAuras(tip,"HELPFUL",auraCount + 1);
end
if (cfg.showDebuffs) then
auraCount = auraCount + self:DisplayAuras(tip,"HARMFUL",auraCount + 1);
end
if (cfg.showBuffs) then
auraCount = auraCount + self:DisplayAuras(tip,"HELPFUL",auraCount + 1);
end

ttAuras:SetClamp(tip, auras[auraCount]); -- last one should be the furthest out

-- Hide the Unused
for i = (auraCount + 1), #auras do
Expand All @@ -147,9 +245,19 @@ function ttAuras:OnApplyConfig(cfg)
local gameFont = GameFontNormal:GetFont();
for _, aura in ipairs(auras) do
if (cfg.showBuffs or cfg.showDebuffs) then
aura:SetWidth(cfg.auraSize,cfg.auraSize);
if (cfg.auraPixelPerfectPositioning) then
aura:SetScale(tt.ppScale / cfg.gttScale);
else
aura:SetScale(1);
end
aura:SetSize(cfg.auraSize, cfg.auraSize);
aura.border:SetBackdrop(nil);
ttAuras:ApplyParentBackdropToAura(aura.border, aura:GetParent())
aura.border:SetAllPoints();
ttAuras:ApplyInsetsToIconTexture(aura.icon, aura:GetParent().backdropInfo);
ttAuras:ApplyInsetsToIconTexture(aura.icon.texture, aura:GetParent().backdropInfo);
aura.count:SetFont(gameFont,(cfg.auraSize / 2),"OUTLINE");
aura.cooldown.noCooldownCount = cfg.noCooldownCount;
aura.icon.cooldown.noCooldownCount = cfg.noCooldownCount;
else
aura:Hide();
end
Expand Down
93 changes: 90 additions & 3 deletions TipTac/ttCore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ local TT_DefaultConfig = {
auraMaxRows = 2,
showAuraCooldown = true,
noCooldownCount = false,
auraCustomBorder = true,
auraBorderUseParentColor = false,
auraBorderBuffColor = { 0, 1, 0 },
auraBorderDebuffColor = { 1, 0, 0 },
auraOffsetX = 2,
auraOffsetY = 2,
auraBorderUseDebuffTypeColors = true,
auraPixelPerfectPositioning = false,

iconRaid = true,
iconFaction = false,
Expand Down Expand Up @@ -228,8 +236,9 @@ local TT_DefaultConfig = {
if_iconSize = 42,
if_iconAnchor = "BOTTOMLEFT",
if_iconTooltipAnchor = "TOPLEFT",
if_iconOffsetX = 2.5,
if_iconOffsetY = -2.5,
if_iconOffsetX = 0,
if_iconOffsetY = 0,
if_copyParentBorder = false,
};

-- Tips modified by TipTac in appearance and scale, you can add to this list if you want to modify more tips.
Expand Down Expand Up @@ -336,11 +345,13 @@ orgGTTSFontFlags = ""; -- Set during VARIABLES_LOADED
-- Pixel Perfect Scale
local physicalScreenWidth, physicalScreenHeight, uiUnitFactor, uiScale;
local mouseOffsetX, mouseOffsetY = 0, 0;
tt.ppScale = nil

local function updatePixelPerfectScale()
physicalScreenWidth, physicalScreenHeight = GetPhysicalScreenSize();
uiUnitFactor = 768.0 / physicalScreenHeight;
uiScale = UIParent:GetEffectiveScale();
tt.ppScale = uiUnitFactor / uiScale
if (cfg) then
mouseOffsetX, mouseOffsetY = tt:GetNearestPixelSize(cfg.mouseOffsetX), tt:GetNearestPixelSize(cfg.mouseOffsetY);
end
Expand Down Expand Up @@ -699,7 +710,6 @@ function tt:ApplySettings()
tipBackdrop.insets.right = insets;
tipBackdrop.insets.top = insets;
tipBackdrop.insets.bottom = insets;

tipBackdrop.backdropColor:SetRGBA(unpack(cfg.tipColor));
tipBackdrop.backdropBorderColor:SetRGBA(unpack(cfg.tipBorderColor));

Expand Down Expand Up @@ -1051,6 +1061,82 @@ function tt:ReApplyAnchorTypeForMouse(frame, noUpdateAnchorPosition, ignoreWorld
end
end

-- anchors the comparing items tooltip with an appropriate offset to account for the item icon
function tt:anchorShoppingTooltips(frame)
if (frame:GetName() == "ShoppingTooltip1" or frame:GetName() == "ShoppingTooltip2") then

-- retail has 2 points instead of 1 in tbcc, that anchor a bit differently, here we only set the relevant point
if (isWoWRetail) then
for n = 1, frame:GetNumPoints() do
local point, anchor, anchoredTo, x, y = frame:GetPoint(n);
if (point == "LEFT" or point == "RIGHT" or point == "TOPLEFT" or point == "TOPRIGHT") then
-- this is the point we want
-- remove y offset by changing the anchor
if (point == "LEFT") then
point = "TOPLEFT";
anchoredTo = "TOPRIGHT";
elseif (point == "RIGHT") then
point = "TOPRIGHT";
anchoredTo = "TOPLEFT";
end
frame:ClearAllPoints()
frame:SetPoint(point, anchor, anchoredTo, x, y);
break;
end
end
end

if (frame:GetNumPoints() == 0) then
return;
end

local anchor, aFrame, anchorTo, x, y = frame:GetPoint();
local gapOffset = tt:GetNearestPixelSize(5);
local toTheLeft = (anchor == "TOPRIGHT");

local iconDistance = 0;
local leftIcon = false;
local rightIcon = false;

-- calculate offset if the icon is to the left or right of the tooltip
if (cfg.if_showIcon and (gtt.ttIcon ~= nil) and (frame.ttIcon:GetLeft() ~= nil)) then
local leftDistance = frame:GetLeft() - frame.ttIcon:GetLeft();
local rightDistance = frame.ttIcon:GetRight() - frame:GetRight();
if (leftDistance > 0) then
leftIcon = true;
iconDistance = leftDistance;
elseif (rightDistance > 0) then
rightIcon = true;
iconDistance = rightDistance;
end
end

-- check if icon is hidden because of "Smart Icon Appearance"
-- this doesn't work because this happens before ttitemref had a chance to update gtt
--if (not gtt.ttIcon:IsShown()) then
-- calling directly into ttitemref instead
local iconShown = (TipTacItemRef and cfg.if_showIcon);
local _, link = gtt:GetItem();
if (link and TipTacItemRef and cfg.if_smartIcons) then
local linkType, id = link:match("H?(%a+):(%d+)");
iconShown = TipTacItemRef:SmartIconEvaluation(gtt, linkType);
end
if (not iconShown) then
-- if it is, set the iconDistance to 0 for the first tooltip
if ((frame:GetName() == "ShoppingTooltip1" and toTheLeft and leftIcon) or
(frame:GetName() == "ShoppingTooltip2" and not toTheLeft and rightIcon) or
(frame:GetName() == "ShoppingTooltip1" and not toTheLeft and rightIcon and not stt2:IsShown())) then
iconDistance = 0;
end
end

local xOffset = (toTheLeft and -(gapOffset + iconDistance) or (gapOffset + iconDistance));

frame:ClearAllPoints();
frame:SetPoint(anchor, aFrame, anchorTo, xOffset, 0);
end
end

-- Removes lines from the tooltip which are unwanted, such as "PvP", "Alliance", "Horde"
-- Also removes the coalesced realm line(s), which I am unsure is still in BfA?
function tt:RemoveUnwantedLines(tip)
Expand Down Expand Up @@ -1404,6 +1490,7 @@ end
-- EventHook: OnTooltipSetItem
function gttScriptHooks:OnTooltipSetItem()
tt:ReApplyAnchorTypeForMouse(self);
tt:anchorShoppingTooltips(self);
end

-- OnHide Script -- Used to default the background and border color -- Az: May cause issues with embedded tooltips, see GameTooltip.lua:396
Expand Down
Loading