Skip to content

Commit

Permalink
InspectDiff Tweak now supports Talent Tree Viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Numynum committed Dec 26, 2022
1 parent 1d5df7c commit 14c250a
Showing 1 changed file with 174 additions and 35 deletions.
209 changes: 174 additions & 35 deletions modules/inspectDiff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@ local Main = TTT.Main;
local Module = Main:NewModule('InspectDiff', 'AceHook-3.0');

function Module:OnEnable()
self.buttonTextures = self.buttonTextures or {};
self.blizzardButtonTextures = self.blizzardButtonTextures or {};
EventUtil.ContinueOnAddOnLoaded('Blizzard_ClassTalentUI', function()
self:SetupHook();
self:SetupBlizzardHook();
end);

self.viewerButtonTextures = self.viewerButtonTextures or {};
EventUtil.ContinueOnAddOnLoaded('TalentTreeViewer', function()
self:SetupViewerHook();
end);
end

function Module:OnDisable()
self:UnhookAll();
if(self.buttonTextures) then
for _, texture in pairs(self.buttonTextures) do
if(self.blizzardButtonTextures) then
for _, texture in pairs(self.blizzardButtonTextures) do
texture:Hide();
end
end
if(self.viewerButtonTextures) then
for _, texture in pairs(self.viewerButtonTextures) do
texture:Hide();
end
end
Expand Down Expand Up @@ -50,6 +60,7 @@ function Module:GetOptions(defaultOptionsTable, db)
b = 0,
a = 0.75,
},
enableTalentTreeViewerDiff = true,
}
for k, v in pairs(defaults) do
if db[k] == nil then
Expand All @@ -64,7 +75,8 @@ function Module:GetOptions(defaultOptionsTable, db)
local function SetColor(info, r, g, b, a)
local color = self.db[info[#info]];
color.r, color.g, color.b, color.a = r, g, b, a;
self:UpdateColors();
self:UpdateBlizzardColors();
self:UpdateViewerColors();
end
defaultOptionsTable.args.colorRed = {
type = 'color',
Expand Down Expand Up @@ -98,68 +110,195 @@ function Module:GetOptions(defaultOptionsTable, db)
self.db.colorRed = defaults.colorRed;
self.db.colorGreen = defaults.colorGreen;
self.db.colorYellow = defaults.colorYellow;
self:UpdateColors();
self:UpdateBlizzardColors();
self:UpdateViewerColors();
end,
order = 10,
};
defaultOptionsTable.args.enableTalentTreeViewerDiff = {
type = 'toggle',
name = 'Enable Talent Tree Viewer Diff',
desc = 'Show the difference between your talent choices, and the talent build in Talent Tree Viewer.',
get = function() return self.db.enableTalentTreeViewerDiff end,
set = function(_, value)
self.db.enableTalentTreeViewerDiff = value
if self.viewerButtonTextures then
if not value then
for _, texture in pairs(self.viewerButtonTextures) do
texture:Hide();
end
else
self:UpdateViewerColors();
end
end
end,
disabled = function() return not Main:IsTalentTreeViewerEnabled() end,
width = 'full',
order = 15,
};

return defaultOptionsTable;
end

function Module:SetupHook()
self:SecureHook(ClassTalentFrame.TalentsTab, 'UpdateInspecting');
self:UpdateInspecting();
function Module:SetupBlizzardHook()
local talentFrame = ClassTalentFrame.TalentsTab;
self:SecureHook(talentFrame, 'UpdateInspecting');
self:UpdateInspecting(talentFrame);

self:SecureHook(talentFrame, 'ShowSelections', 'OnBlizzardShowSelections');

talentFrame:RegisterCallback(TalentFrameBaseMixin.Event.TalentButtonAcquired, self.OnBlizzardTalentButtonAcquired, self);
for talentButton in talentFrame:EnumerateAllTalentButtons() do
self:OnBlizzardTalentButtonAcquired(talentButton);
end
end

function Module:SetupViewerHook()
local talentViewerFrame = TalentViewer:GetTalentFrame();
self:InitCheckbox(talentViewerFrame);
self:SecureHook(TalentViewer, 'SelectSpec', 'UpdateViewerSpec');
self:UpdateViewerSpec(TalentViewer, talentViewerFrame:GetClassID(), talentViewerFrame:GetSpecID());

self:SecureHook(ClassTalentFrame.TalentsTab, 'ShowSelections');
self:SecureHook(talentViewerFrame, 'ShowSelections', 'OnViewerShowSelections');

ClassTalentFrame.TalentsTab:RegisterCallback(TalentFrameBaseMixin.Event.TalentButtonAcquired, self.OnTalentButtonAcquired, self);
for talentButton in ClassTalentFrame.TalentsTab:EnumerateAllTalentButtons() do
self:OnTalentButtonAcquired(talentButton);
talentViewerFrame:RegisterCallback(TalentFrameBaseMixin.Event.TalentButtonAcquired, self.OnViewerTalentButtonAcquired, self);
for talentButton in talentViewerFrame:EnumerateAllTalentButtons() do
self:OnViewerTalentButtonAcquired(talentButton);
end
self:SecureHook(TalentViewer, 'ReduceCurrency', 'ViewerNodeChanged');
self:SecureHook(TalentViewer, 'RestoreCurrency', 'ViewerNodeChanged');

self.viewerCheckbox:Show();
self.viewerCheckbox:SetChecked(self.db.enableTalentTreeViewerDiff);
end

function Module:InitCheckbox(talentViewerFrame)
if self.viewerCheckbox then
return;
end

local checkbox = CreateFrame('CheckButton', nil, talentViewerFrame, 'UICheckButtonTemplate');
checkbox:SetPoint('TOPLEFT', talentViewerFrame.IgnoreRestrictions, 'BOTTOMLEFT');
checkbox:SetSize(25, 25);
checkbox:SetScript('OnClick', function()
self.db.enableTalentTreeViewerDiff = checkbox:GetChecked();
if self.db.enableTalentTreeViewerDiff then
self:UpdateViewerColors();
else
for _, texture in pairs(self.viewerButtonTextures) do
texture:Hide();
end
end
end);
checkbox:SetScript('OnEnter', function()
GameTooltip:SetOwner(checkbox, 'ANCHOR_RIGHT');
GameTooltip:AddLine('TalentTreeTweaks Diff Viewer');
GameTooltip:AddLine('Show the difference between your talent choices, and the talent build in Talent Tree Viewer.', 1, 1, 1, true);
GameTooltip:Show();
end);
checkbox:SetScript('OnLeave', function() GameTooltip:Hide(); end);
checkbox.Text:SetText('Show Diff');
checkbox:SetHitRectInsets(0, -checkbox.Text:GetWidth(), 0, 0);

self.viewerCheckbox = checkbox;
end

function Module:UpdateInspecting()
local talentsTab = ClassTalentFrame.TalentsTab;
function Module:ViewerNodeChanged(TalentViewer, nodeID)
local talentFrame = TalentViewer:GetTalentFrame();
local button = talentFrame:GetTalentButtonByNodeID(nodeID);
if button and self.viewerButtonTextures[button] then
C_Timer.After(0, function()
self:SetViewerButtonState(button, self.viewerButtonTextures[button]);
end)
end
end

function Module:UpdateInspecting(talentsTab)
self.isInspectingSameSpec = talentsTab:IsInspecting() and talentsTab:GetSpecID() == PlayerUtil.GetCurrentSpecID();

self:UpdateColors();
self:UpdateBlizzardColors();
end

function Module:ShowSelections()
for _, button in pairs(ClassTalentFrame.TalentsTab.SelectionChoiceFrame.selectionFrameArray) do
self:OnTalentButtonAcquired(button);
function Module:UpdateViewerSpec(TalentViewer, classID, specID)
self.isViewerSameSpec = specID == PlayerUtil.GetCurrentSpecID();
self.viewerCheckbox:SetEnabled(self.isViewerSameSpec);

self:UpdateViewerColors();
end

function Module:OnBlizzardShowSelections(talentsTab)
for _, button in pairs(talentsTab.SelectionChoiceFrame.selectionFrameArray) do
self:OnBlizzardTalentButtonAcquired(button);
end
end

function Module:OnTalentButtonAcquired(button)
if not self.buttonTextures[button] then
self.buttonTextures[button] = button:CreateTexture(nil, 'OVERLAY')
local texture = self.buttonTextures[button];
texture:SetAllPoints(button);
texture:SetTexture('Interface/Tooltips/UI-Tooltip-Background');
texture:SetVertexColor(self.db.colorRed.r, self.db.colorRed.g, self.db.colorRed.b, self.db.colorRed.a);
texture:AddMaskTexture(button.IconMask);
texture:Hide();
function Module:OnViewerShowSelections(talentFrame)
for _, button in pairs(talentFrame.SelectionChoiceFrame.selectionFrameArray) do
self:OnViewerTalentButtonAcquired(button);
end
end

function Module:CreateTexture(button)
local texture = button:CreateTexture(nil, 'OVERLAY');
texture:SetAllPoints(button);
texture:SetTexture('Interface/Tooltips/UI-Tooltip-Background');
texture:SetVertexColor(self.db.colorRed.r, self.db.colorRed.g, self.db.colorRed.b, self.db.colorRed.a);
texture:AddMaskTexture(button.IconMask);
texture:Hide();
return texture;
end

function Module:OnBlizzardTalentButtonAcquired(button)
if not self.blizzardButtonTextures[button] then
self.blizzardButtonTextures[button] = self:CreateTexture(button);
end

self:SetButtonState(button);
self:SetBlizzardButtonState(button, self.blizzardButtonTextures[button]);
end

function Module:UpdateColors()
for button, _ in pairs(self.buttonTextures) do
self:SetButtonState(button);
function Module:OnViewerTalentButtonAcquired(button)
if not self.viewerButtonTextures[button] then
self.viewerButtonTextures[button] = self:CreateTexture(button);
end

self:SetViewerButtonState(button, self.viewerButtonTextures[button]);
end

function Module:SetButtonState(button)
local texture = self.buttonTextures[button];
if not texture then return; end
function Module:UpdateBlizzardColors()
for button, texture in pairs(self.blizzardButtonTextures) do
self:SetBlizzardButtonState(button, texture);
end
end

function Module:UpdateViewerColors()
if not self.db.enableTalentTreeViewerDiff then
return;
end

for button, texture in pairs(self.viewerButtonTextures) do
self:SetViewerButtonState(button, texture);
end
end

function Module:SetBlizzardButtonState(button, texture)
if not self.isInspectingSameSpec then
texture:Hide();
return;
end

self:SetButtonState(button, texture);
end

function Module:SetViewerButtonState(button, texture)
if not self.isViewerSameSpec then
texture:Hide();
return;
end

self:SetButtonState(button, texture);
end

function Module:SetButtonState(button, texture)
local isChoiceButton = not not button.selectionIndex

local colorToUse
Expand Down

0 comments on commit 14c250a

Please sign in to comment.