Skip to content

Commit 6128849

Browse files
committed
Automatically cancel druid flightform when attempting to respec (closes #8)
1 parent 5e2b541 commit 6128849

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

TalentLoadoutBroker.lua

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ ns.TLB = {};
55
local TLB = ns.TLB;
66

77
local starterConfigID = Constants.TraitConsts.STARTER_BUILD_TRAIT_CONFIG_ID;
8+
local isDruid = select(2, UnitClass('player')) == 'DRUID';
9+
local cancelFormButton = CreateFrame('Button', nil, UIParent, 'InsecureActionButtonTemplate');
810

911
function TLB:Init()
1012
EventUtil.ContinueOnAddOnLoaded(addonName, function()
@@ -28,6 +30,19 @@ function TLB:Init()
2830
SlashCmdList['TALENT_LOADOUT_BROKER'] = function() ns.Config:OpenConfig(); end
2931
end);
3032

33+
cancelFormButton:SetAttribute('type', 'macro');
34+
cancelFormButton:SetAttribute('macrotext', '/cancelform [form:3]');
35+
cancelFormButton:SetAttribute('useOnKeyDown', true);
36+
cancelFormButton:RegisterForClicks('AnyDown')
37+
cancelFormButton:SetFrameStrata('FULLSCREEN_DIALOG');
38+
cancelFormButton:SetFrameLevel(9999);
39+
cancelFormButton:SetPropagateMouseMotion(true);
40+
cancelFormButton:HookScript('OnClick', function(self)
41+
self.elementDescription:Pick(MenuInputContext.MouseButton, 'LeftButton');
42+
self:ClearAllPoints();
43+
self:Hide();
44+
end);
45+
3146
self.configIDs, self.configIDToName, self.currentConfigID = nil, nil, nil;
3247
self.updatePending, self.pendingDisableStarterBuild, self.pendingConfigID = false, false, nil;
3348
self.currentConfigID = nil;
@@ -238,7 +253,7 @@ function TLB:FormatSpecText(name, icon)
238253
return string.format('|T%s:14:14:0:0:64:64:4:60:4:60|t %s', icon, name );
239254
end
240255

241-
---@param rootDescription RootDescriptionProxy
256+
---@param rootDescription RootMenuDescriptionProxy
242257
function TLB:GenerateLoadoutDropdown(rootDescription)
243258
self:RefreshLoadoutText();
244259
if TalentLoadoutManagerAPI then
@@ -248,7 +263,7 @@ function TLB:GenerateLoadoutDropdown(rootDescription)
248263
end
249264
end
250265

251-
---@param rootDescription RootDescriptionProxy
266+
---@param rootDescription RootMenuDescriptionProxy
252267
function TLB:GenerateDefaultUILoadoutDropdown(rootDescription)
253268
local specID = PlayerUtil.GetCurrentSpecID();
254269
if not specID then return; end
@@ -274,7 +289,7 @@ function TLB:GenerateDefaultUILoadoutDropdown(rootDescription)
274289
end
275290
end
276291

277-
---@param rootDescription RootDescriptionProxy
292+
---@param rootDescription RootMenuDescriptionProxy
278293
function TLB:GenerateTLMLoadoutDropdown(rootDescription)
279294
local specID = PlayerUtil.GetCurrentSpecID();
280295
if not specID then return; end
@@ -377,14 +392,14 @@ function TLB:SortTLMLoadouts(loadouts)
377392
end);
378393
end
379394

380-
---@param rootDescription RootDescriptionProxy
395+
---@param rootDescription RootMenuDescriptionProxy
381396
function TLB:GenerateSpecDropdown(rootDescription)
382397
local activeSpecIndex = GetSpecialization();
383398
if not activeSpecIndex then return; end
384399

385400
self:RefreshSpecText();
386401

387-
local numSpecs = GetNumSpecializationsForClassID(PlayerUtil.GetClassID());
402+
local numSpecs = C_SpecializationInfo.GetNumSpecializationsForClassID(PlayerUtil.GetClassID());
388403

389404
-- spec selection
390405
do
@@ -394,12 +409,30 @@ function TLB:GenerateSpecDropdown(rootDescription)
394409

395410
for specIndex = 1, numSpecs do
396411
local _, name, _, icon = GetSpecializationInfoForClassID(PlayerUtil.GetClassID(), specIndex);
397-
rootDescription:CreateRadio(
412+
local button = rootDescription:CreateRadio(
398413
self:FormatSpecText(name, icon),
399414
isSelected,
400415
selectSpec,
401416
specIndex
402417
);
418+
if isDruid then
419+
button:HookOnEnter(function(frame, elementDescription)
420+
cancelFormButton:ClearAllPoints();
421+
cancelFormButton:SetAllPoints(frame);
422+
cancelFormButton:Show();
423+
cancelFormButton.elementDescription = elementDescription;
424+
if GetShapeshiftForm() == 3 then
425+
GameTooltip:SetOwner(frame, 'ANCHOR_TOP');
426+
GameTooltip:SetText('This will cancel your travel form!');
427+
GameTooltip:Show();
428+
end
429+
end);
430+
button:HookOnLeave(function()
431+
cancelFormButton:ClearAllPoints();
432+
cancelFormButton:Hide();
433+
GameTooltip:Hide();
434+
end);
435+
end
403436
end
404437
end
405438
-- lootspec selection

0 commit comments

Comments
 (0)