Advertisement
Guest User

Blizzard_TalentUI.lua

a guest
Jan 21st, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 34.70 KB | None | 0 0
  1.  
  2. StaticPopupDialogs["CONFIRM_LEARN_PREVIEW_TALENTS"] = {
  3.     text = CONFIRM_LEARN_PREVIEW_TALENTS,
  4.     button1 = YES,
  5.     button2 = NO,
  6.     OnAccept = function (self)
  7.         LearnPreviewTalents(PlayerTalentFrame.pet);
  8.     end,
  9.     OnCancel = function (self)
  10.     end,
  11.     hideOnEscape = 1,
  12.     timeout = 0,
  13.     exclusive = 1,
  14. }
  15.  
  16. UIPanelWindows["PlayerTalentFrame"] = { area = "left", pushable = 6, whileDead = 1 };
  17.  
  18.  
  19. -- global constants
  20. GLYPH_TALENT_TAB = 5;
  21.  
  22.  
  23. -- speed references
  24. local next = next;
  25. local ipairs = ipairs;
  26.  
  27. -- local data
  28. local specs = {
  29.     ["spec1"] = {
  30.         name = TALENT_SPEC_PRIMARY,
  31.         talentGroup = 1,
  32.         unit = "player",
  33.         pet = false,
  34.         tooltip = TALENT_SPEC_PRIMARY,
  35.         portraitUnit = "player",
  36.         defaultSpecTexture = "Interface\\Icons\\Ability_Marksmanship",
  37.         hasGlyphs = true,
  38.         glyphName = TALENT_SPEC_PRIMARY_GLYPH,
  39.     },
  40.     ["spec2"] = {
  41.         name = TALENT_SPEC_SECONDARY,
  42.         talentGroup = 2,
  43.         unit = "player",
  44.         pet = false,
  45.         tooltip = TALENT_SPEC_SECONDARY,
  46.         portraitUnit = "player",
  47.         defaultSpecTexture = "Interface\\Icons\\Ability_Marksmanship",
  48.         hasGlyphs = true,
  49.         glyphName = TALENT_SPEC_SECONDARY_GLYPH,
  50.     },
  51.     ["petspec1"] = {
  52.         name = TALENT_SPEC_PET_PRIMARY,
  53.         talentGroup = 1,
  54.         unit = "pet",
  55.         tooltip = TALENT_SPEC_PET_PRIMARY,
  56.         pet = true,
  57.         portraitUnit = "pet",
  58.         defaultSpecTexture = nil,
  59.         hasGlyphs = false,
  60.         glyphName = nil,
  61.     },
  62. };
  63.  
  64. local specTabs = { };   -- filled in by PlayerSpecTab_OnLoad
  65. local numSpecTabs = 0;
  66. local selectedSpec = nil;
  67. local activeSpec = nil;
  68.  
  69.  
  70. -- cache talent info so we can quickly display cool stuff like the number of points spent in each tab
  71. local talentSpecInfoCache = {
  72.     ["spec1"]       = { },
  73.     ["spec2"]       = { },
  74.     ["petspec1"]    = { },
  75. };
  76. -- cache talent tab widths so we can resize tabs to fit for localization
  77. local talentTabWidthCache = { };
  78.  
  79.  
  80.  
  81. -- ACTIVESPEC_DISPLAYTYPE values:
  82. -- "BLUE", "GOLD_INSIDE", "GOLD_BACKGROUND"
  83. local ACTIVESPEC_DISPLAYTYPE = nil;
  84.  
  85. -- SELECTEDSPEC_DISPLAYTYPE values:
  86. -- "BLUE", "GOLD_INSIDE", "PUSHED_OUT", "PUSHED_OUT_CHECKED"
  87. local SELECTEDSPEC_DISPLAYTYPE = "GOLD_INSIDE";
  88. local SELECTEDSPEC_OFFSETX;
  89. if ( SELECTEDSPEC_DISPLAYTYPE == "PUSHED_OUT" or SELECTEDSPEC_DISPLAYTYPE == "PUSHED_OUT_CHECKED" ) then
  90.     SELECTEDSPEC_OFFSETX = 5;
  91. else
  92.     SELECTEDSPEC_OFFSETX = 0;
  93. end
  94.  
  95.  
  96. -- PlayerTalentFrame
  97.  
  98. function PlayerTalentFrame_Toggle(pet, suggestedTalentGroup)
  99.     local hidden;
  100.     local talentTabSelected = PanelTemplates_GetSelectedTab(PlayerTalentFrame) ~= GLYPH_TALENT_TAB;
  101.     if ( not PlayerTalentFrame:IsShown() ) then
  102.         ShowUIPanel(PlayerTalentFrame);
  103.         hidden = false;
  104.     else
  105.         local spec = selectedSpec and specs[selectedSpec];
  106.         if ( spec and talentTabSelected ) then
  107.             -- if a talent tab is selected then toggle the frame off
  108.             HideUIPanel(PlayerTalentFrame);
  109.             hidden = true;
  110.         else
  111.             hidden = false;
  112.         end
  113.     end
  114.     if ( not hidden ) then
  115.         -- open the spec with the requested talent group (or the current talent group if the selected
  116.         -- spec has one)
  117.         if ( selectedSpec ) then
  118.             local spec = specs[selectedSpec];
  119.             if ( spec.pet == pet ) then
  120.                 suggestedTalentGroup = spec.talentGroup;
  121.             end
  122.         end
  123.         for _, index in ipairs(TALENT_SORT_ORDER) do
  124.             local spec = specs[index];
  125.             if ( spec.pet == pet and spec.talentGroup == suggestedTalentGroup ) then
  126.                 PlayerSpecTab_OnClick(specTabs[index]);
  127.                 if ( not talentTabSelected ) then
  128.                     PlayerTalentTab_OnClick(_G["PlayerTalentFrameTab"..PlayerTalentTab_GetBestDefaultTab(index)]);
  129.                 end
  130.                 break;
  131.             end
  132.         end
  133.     end
  134. end
  135.  
  136. function PlayerTalentFrame_Open(pet, talentGroup)
  137.     ShowUIPanel(PlayerTalentFrame);
  138.     -- open the spec with the requested talent group
  139.     for index, spec in next, specs do
  140.         if ( spec.pet == pet and spec.talentGroup == talentGroup ) then
  141.             PlayerSpecTab_OnClick(specTabs[index]);
  142.             break;
  143.         end
  144.     end
  145. end
  146.  
  147. function PlayerTalentFrame_ToggleGlyphFrame(suggestedTalentGroup)
  148.     GlyphFrame_LoadUI();
  149.     if ( GlyphFrame ) then
  150.         local hidden;
  151.         if ( not PlayerTalentFrame:IsShown() ) then
  152.             ShowUIPanel(PlayerTalentFrame);
  153.             hidden = false;
  154.         else
  155.             local spec = selectedSpec and specs[selectedSpec];
  156.             if ( spec and spec.hasGlyphs and
  157.                  PanelTemplates_GetSelectedTab(PlayerTalentFrame) == GLYPH_TALENT_TAB ) then
  158.                 -- if the glyph tab is selected then toggle the frame off
  159.                 HideUIPanel(PlayerTalentFrame);
  160.                 hidden = true;
  161.             else
  162.                 hidden = false;
  163.             end
  164.         end
  165.         if ( not hidden ) then
  166.             -- open the spec with the requested talent group (or the current talent group if the selected
  167.             -- spec has one)
  168.             if ( selectedSpec ) then
  169.                 local spec = specs[selectedSpec];
  170.                 if ( spec.hasGlyphs ) then
  171.                     suggestedTalentGroup = spec.talentGroup;
  172.                 end
  173.             end
  174.             for _, index in ipairs(TALENT_SORT_ORDER) do
  175.                 local spec = specs[index];
  176.                 if ( spec.hasGlyphs and spec.talentGroup == suggestedTalentGroup ) then
  177.                     PlayerSpecTab_OnClick(specTabs[index]);
  178.                     PlayerTalentTab_OnClick(_G["PlayerTalentFrameTab"..GLYPH_TALENT_TAB]);
  179.                     break;
  180.                 end
  181.             end
  182.         end
  183.     end
  184. end
  185.  
  186. function PlayerTalentFrame_OpenGlyphFrame(talentGroup)
  187.     GlyphFrame_LoadUI();
  188.     if ( GlyphFrame ) then
  189.         ShowUIPanel(PlayerTalentFrame);
  190.         -- open the spec with the requested talent group
  191.         for index, spec in next, specs do
  192.             if ( spec.hasGlyphs and spec.talentGroup == talentGroup ) then
  193.                 PlayerSpecTab_OnClick(specTabs[index]);
  194.                 PlayerTalentTab_OnClick(_G["PlayerTalentFrameTab"..GLYPH_TALENT_TAB]);
  195.                 break;
  196.             end
  197.         end
  198.     end
  199. end
  200.  
  201. function PlayerTalentFrame_ShowGlyphFrame()
  202.     GlyphFrame_LoadUI();
  203.     if ( GlyphFrame ) then
  204.         -- set the title text of the GlyphFrame
  205.         if ( selectedSpec and specs[selectedSpec].glyphName and GetNumTalentGroups() > 1 ) then
  206.             GlyphFrameTitleText:SetText(specs[selectedSpec].glyphName);
  207.         else
  208.             GlyphFrameTitleText:SetText(GLYPHS);
  209.         end
  210.         -- show/update the glyph frame
  211.         if ( GlyphFrame:IsShown() ) then
  212.             GlyphFrame_Update();
  213.         else
  214.             GlyphFrame:Show();
  215.         end
  216.         -- don't forget to hide the scroll button overlay or it may show up on top of the GlyphFrame!
  217.         UIFrameFlashStop(PlayerTalentFrameScrollButtonOverlay);
  218.     end
  219. end
  220.  
  221. function PlayerTalentFrame_HideGlyphFrame()
  222.     if ( not GlyphFrame or not GlyphFrame:IsShown() ) then
  223.         return;
  224.     end
  225.  
  226.     GlyphFrame_LoadUI();
  227.     if ( GlyphFrame ) then
  228.         GlyphFrame:Hide();
  229.     end
  230. end
  231.  
  232.  
  233. function PlayerTalentFrame_OnLoad(self)
  234.     self:RegisterEvent("ADDON_LOADED");
  235.     self:RegisterEvent("PREVIEW_TALENT_POINTS_CHANGED");
  236.     self:RegisterEvent("PREVIEW_PET_TALENT_POINTS_CHANGED");
  237.     self:RegisterEvent("UNIT_PORTRAIT_UPDATE");
  238.     self:RegisterEvent("UNIT_PET");
  239.     self:RegisterEvent("PLAYER_LEVEL_UP");
  240.     self:RegisterEvent("PLAYER_TALENT_UPDATE");
  241.     self:RegisterEvent("PET_TALENT_UPDATE");
  242.     self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
  243.     self.unit = "player";
  244.     self.inspect = false;
  245.     self.pet = false;
  246.     self.talentGroup = 1;
  247.     self.updateFunction = PlayerTalentFrame_Update;
  248.  
  249.     TalentFrame_Load(self);
  250.  
  251.     -- setup talent buttons
  252.     local button;
  253.     for i = 1, MAX_NUM_TALENTS do
  254.         button = _G["PlayerTalentFrameTalent"..i];
  255.         if ( button ) then
  256.             button:SetScript("OnClick", PlayerTalentFrameTalent_OnClick);
  257.             button:SetScript("OnEvent", PlayerTalentFrameTalent_OnEvent);
  258.             button:SetScript("OnEnter", PlayerTalentFrameTalent_OnEnter);
  259.         end
  260.     end
  261.  
  262.     -- setup tabs
  263.     PanelTemplates_SetNumTabs(self, MAX_TALENT_TABS + 1);   -- add one for the GLYPH_TALENT_TAB
  264.  
  265.     -- initialize active spec as a fail safe
  266.     local activeTalentGroup = GetActiveTalentGroup();
  267.     local numTalentGroups = GetNumTalentGroups();
  268.     PlayerTalentFrame_UpdateActiveSpec(activeTalentGroup, numTalentGroups);
  269.  
  270.     -- setup active spec highlight
  271.     if ( ACTIVESPEC_DISPLAYTYPE == "BLUE" ) then
  272.         PlayerTalentFrameActiveSpecTabHighlight:SetDrawLayer("OVERLAY");
  273.         PlayerTalentFrameActiveSpecTabHighlight:SetBlendMode("ADD");
  274.         PlayerTalentFrameActiveSpecTabHighlight:SetTexture("Interface\\Buttons\\UI-Button-Outline");
  275.     elseif ( ACTIVESPEC_DISPLAYTYPE == "GOLD_INSIDE" ) then
  276.         PlayerTalentFrameActiveSpecTabHighlight:SetDrawLayer("OVERLAY");
  277.         PlayerTalentFrameActiveSpecTabHighlight:SetBlendMode("ADD");
  278.         PlayerTalentFrameActiveSpecTabHighlight:SetTexture("Interface\\Buttons\\CheckButtonHilight");
  279.     elseif ( ACTIVESPEC_DISPLAYTYPE == "GOLD_BACKGROUND" ) then
  280.         PlayerTalentFrameActiveSpecTabHighlight:SetDrawLayer("BACKGROUND");
  281.         PlayerTalentFrameActiveSpecTabHighlight:SetWidth(74);
  282.         PlayerTalentFrameActiveSpecTabHighlight:SetHeight(86);
  283.         PlayerTalentFrameActiveSpecTabHighlight:SetTexture("Interface\\SpellBook\\SpellBook-SkillLineTab-Glow");
  284.     end
  285. end
  286.  
  287. function PlayerTalentFrame_OnShow(self)
  288.     -- Stop buttons from flashing after skill up
  289.     SetButtonPulse(TalentMicroButton, 0, 1);
  290.  
  291.     PlaySound("TalentScreenOpen");
  292.     UpdateMicroButtons();
  293.  
  294.     if ( not selectedSpec ) then
  295.         -- if no spec was selected, try to select the active one
  296.         PlayerSpecTab_OnClick(activeSpec and specTabs[activeSpec] or specTabs[DEFAULT_TALENT_SPEC]);
  297.     else
  298.         PlayerTalentFrame_Refresh();
  299.     end
  300.  
  301.     -- Set flag
  302.     if ( not GetCVarBool("talentFrameShown") ) then
  303.         SetCVar("talentFrameShown", 1);
  304.         UIFrameFlash(PlayerTalentFrameScrollButtonOverlay, 0.5, 0.5, 60);
  305.     end
  306. end
  307.  
  308. function  PlayerTalentFrame_OnHide()
  309.     UpdateMicroButtons();
  310.     PlaySound("TalentScreenClose");
  311.     UIFrameFlashStop(PlayerTalentFrameScrollButtonOverlay);
  312.     -- clear caches
  313.     for _, info in next, talentSpecInfoCache do
  314.         wipe(info);
  315.     end
  316.     wipe(talentTabWidthCache);
  317. end
  318.  
  319. function PlayerTalentFrame_OnEvent(self, event, ...)
  320.     if ( event == "PLAYER_TALENT_UPDATE" or event == "PET_TALENT_UPDATE" ) then
  321.         PlayerTalentFrame_Refresh();
  322.     elseif ( event == "PREVIEW_TALENT_POINTS_CHANGED" ) then
  323.         --local talentIndex, tabIndex, groupIndex, points = ...;
  324.         if ( selectedSpec and not specs[selectedSpec].pet ) then
  325.             PlayerTalentFrame_Refresh();
  326.         end
  327.     elseif ( event == "PREVIEW_PET_TALENT_POINTS_CHANGED" ) then
  328.         --local talentIndex, tabIndex, groupIndex, points = ...;
  329.         if ( selectedSpec and specs[selectedSpec].pet ) then
  330.             PlayerTalentFrame_Refresh();
  331.         end
  332.     elseif ( event == "UNIT_PORTRAIT_UPDATE" ) then
  333.         local unit = ...;
  334.         -- update the talent frame's portrait
  335.         if ( unit == PlayerTalentFramePortrait.unit ) then
  336.             SetPortraitTexture(PlayerTalentFramePortrait, unit);
  337.         end
  338.         -- update spec tabs' portraits
  339.         for _, frame in next, specTabs do
  340.             if ( frame.usingPortraitTexture ) then
  341.                 local spec = specs[frame.specIndex];
  342.                 if ( unit == spec.unit and spec.portraitUnit ) then
  343.                     SetPortraitTexture(frame:GetNormalTexture(), unit);
  344.                 end
  345.             end
  346.         end
  347.     elseif ( event == "UNIT_PET" ) then
  348.         local summoner = ...;
  349.         if ( summoner == "player" ) then
  350.             if ( selectedSpec and specs[selectedSpec].pet ) then
  351.                 -- if the selected spec is a pet spec...
  352.                 local numTalentGroups = GetNumTalentGroups(false, true);
  353.                 if ( numTalentGroups == 0 ) then
  354.                     --...and a pet spec is not available, select the default spec
  355.                     PlayerSpecTab_OnClick(activeSpec and specTabs[activeSpec] or specTabs[DEFAULT_TALENT_SPEC]);
  356.                     return;
  357.                 end
  358.             end
  359.             PlayerTalentFrame_Refresh();
  360.         end
  361.     elseif ( event == "PLAYER_LEVEL_UP" ) then
  362.         if ( selectedSpec and not specs[selectedSpec].pet ) then
  363.             local level = ...;
  364.             PlayerTalentFrame_Update(level);
  365.         end
  366.     elseif ( event == "ACTIVE_TALENT_GROUP_CHANGED" ) then
  367.         MainMenuBar_ToPlayerArt(MainMenuBarArtFrame);
  368.     end
  369. end
  370.  
  371. function PlayerTalentFrame_Refresh()
  372.     local selectedTab = PanelTemplates_GetSelectedTab(PlayerTalentFrame);
  373.     if ( selectedTab == GLYPH_TALENT_TAB ) then
  374.         PlayerTalentFrame_ShowGlyphFrame();
  375.     else
  376.         PlayerTalentFrame_HideGlyphFrame();
  377.     end
  378.     TalentFrame_Update(PlayerTalentFrame);
  379. end
  380.  
  381. function PlayerTalentFrame_Update(playerLevel)
  382.     local activeTalentGroup, numTalentGroups = GetActiveTalentGroup(false, false), GetNumTalentGroups(false, false);
  383.     local activePetTalentGroup, numPetTalentGroups = GetActiveTalentGroup(false, true), GetNumTalentGroups(false, true);
  384.  
  385.     -- update specs
  386.     if ( not PlayerTalentFrame_UpdateSpecs(activeTalentGroup, numTalentGroups, activePetTalentGroup, numPetTalentGroups) ) then
  387.         -- the current spec is not selectable any more, discontinue updates
  388.         return;
  389.     end
  390.  
  391.     -- update tabs
  392.     if ( not PlayerTalentFrame_UpdateTabs(playerLevel) ) then
  393.         -- the current spec is not selectable any more, discontinue updates
  394.         return;
  395.     end
  396.  
  397.     -- set the frame portrait
  398.     SetPortraitTexture(PlayerTalentFramePortrait, PlayerTalentFrame.unit);
  399.  
  400.     -- update active talent group stuff
  401.     PlayerTalentFrame_UpdateActiveSpec(activeTalentGroup, numTalentGroups);
  402.  
  403.     -- update talent controls
  404.     PlayerTalentFrame_UpdateControls(activeTalentGroup, numTalentGroups);
  405. end
  406.  
  407. function PlayerTalentFrame_UpdateActiveSpec(activeTalentGroup, numTalentGroups)
  408.     -- set the active spec
  409.     activeSpec = DEFAULT_TALENT_SPEC;
  410.     for index, spec in next, specs do
  411.         if ( not spec.pet and spec.talentGroup == activeTalentGroup ) then
  412.             activeSpec = index;
  413.             break;
  414.         end
  415.     end
  416.     -- make UI adjustments
  417.     local spec = selectedSpec and specs[selectedSpec];
  418.  
  419.     local hasMultipleTalentGroups = numTalentGroups > 1;
  420.     if ( spec and hasMultipleTalentGroups ) then
  421.         PlayerTalentFrameTitleText:SetText(spec.name);
  422.     else
  423.         PlayerTalentFrameTitleText:SetText(TALENTS);
  424.     end
  425.  
  426.     if ( selectedSpec == activeSpec and hasMultipleTalentGroups ) then
  427.         --PlayerTalentFrameActiveTalentGroupFrame:Show();
  428.     else
  429.         PlayerTalentFrameActiveTalentGroupFrame:Hide();
  430.     end
  431. end
  432.  
  433.  
  434. -- PlayerTalentFrameTalents
  435.  
  436. function PlayerTalentFrameTalent_OnClick(self, button)
  437.     if ( IsModifiedClick("CHATLINK") ) then
  438.         local link = GetTalentLink(PanelTemplates_GetSelectedTab(PlayerTalentFrame), self:GetID(),
  439.             PlayerTalentFrame.inspect, PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup, GetCVarBool("previewTalents"));
  440.         if ( link ) then
  441.             ChatEdit_InsertLink(link);
  442.         end
  443.     elseif ( selectedSpec and (activeSpec == selectedSpec or specs[selectedSpec].pet) ) then
  444.         -- only allow functionality if an active spec is selected
  445.         if ( button == "LeftButton" ) then
  446.             if ( GetCVarBool("previewTalents") ) then
  447.                 AddPreviewTalentPoints(PanelTemplates_GetSelectedTab(PlayerTalentFrame), self:GetID(), 1, PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup);
  448.             else
  449.                 LearnTalent(PanelTemplates_GetSelectedTab(PlayerTalentFrame), self:GetID(), PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup);
  450.             end
  451.         elseif ( button == "RightButton" ) then
  452.             if ( GetCVarBool("previewTalents") ) then
  453.                 AddPreviewTalentPoints(PanelTemplates_GetSelectedTab(PlayerTalentFrame), self:GetID(), -1, PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup);
  454.             end
  455.         end
  456.     end
  457. end
  458.  
  459. function PlayerTalentFrameTalent_OnEvent(self, event, ...)
  460.     if ( GameTooltip:IsOwned(self) ) then
  461.         GameTooltip:SetTalent(PanelTemplates_GetSelectedTab(PlayerTalentFrame), self:GetID(),
  462.             PlayerTalentFrame.inspect, PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup, GetCVarBool("previewTalents"));
  463.     end
  464. end
  465.  
  466. function PlayerTalentFrameTalent_OnEnter(self)
  467.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  468.     GameTooltip:SetTalent(PanelTemplates_GetSelectedTab(PlayerTalentFrame), self:GetID(),
  469.         PlayerTalentFrame.inspect, PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup, GetCVarBool("previewTalents"));
  470. end
  471.  
  472.  
  473. -- Controls
  474.  
  475. function PlayerTalentFrame_UpdateControls(activeTalentGroup, numTalentGroups)
  476.     local spec = selectedSpec and specs[selectedSpec];
  477.  
  478.     local isActiveSpec = selectedSpec == activeSpec;
  479.  
  480.     -- show the multi-spec status frame if this is not a pet spec or we have more than one talent group
  481.     local showStatusFrame = not spec.pet and numTalentGroups > 1;
  482.     -- show the activate button if we were going to show the status frame but this is not the active spec
  483.     local showActivateButton = showStatusFrame and not isActiveSpec;
  484.     if ( showActivateButton ) then
  485.         PlayerTalentFrameActivateButton:Show();
  486.         PlayerTalentFrameStatusFrame:Hide();
  487.     else
  488.         PlayerTalentFrameActivateButton:Hide();
  489.         if ( showStatusFrame ) then
  490.             PlayerTalentFrameStatusFrame:Show();
  491.         else
  492.             PlayerTalentFrameStatusFrame:Hide();
  493.         end
  494.     end
  495.  
  496.     local preview = GetCVarBool("previewTalents");
  497.  
  498.     -- enable the control bar if this is the active spec, preview is enabled, and preview points were spent
  499.     local talentPoints = GetUnspentTalentPoints(false, spec.pet, spec.talentGroup);
  500.     if ( (spec.pet or isActiveSpec) and talentPoints > 0 and preview ) then
  501.         PlayerTalentFramePreviewBar:Show();
  502.         -- enable accept/cancel buttons if preview talent points were spent
  503.         if ( GetGroupPreviewTalentPointsSpent(spec.pet, spec.talentGroup) > 0 ) then
  504.             PlayerTalentFrameLearnButton:Enable();
  505.             PlayerTalentFrameResetButton:Enable();
  506.         else
  507.             PlayerTalentFrameLearnButton:Disable();
  508.             PlayerTalentFrameResetButton:Disable();
  509.         end
  510.         -- squish all frames to make room for this bar
  511.         PlayerTalentFramePointsBar:SetPoint("BOTTOM", PlayerTalentFramePreviewBar, "TOP", 0, -4);
  512.     else
  513.         PlayerTalentFramePreviewBar:Hide();
  514.         -- unsquish frames since the bar is now hidden
  515.         PlayerTalentFramePointsBar:SetPoint("BOTTOM", PlayerTalentFrame, "BOTTOM", 0, 81);
  516.     end
  517. end
  518.  
  519. function PlayerTalentFrameActivateButton_OnLoad(self)
  520.     self:SetWidth(self:GetTextWidth() + 40);
  521. end
  522.  
  523. function PlayerTalentFrameActivateButton_OnClick(self)
  524.     if ( selectedSpec ) then
  525.         local talentGroup = specs[selectedSpec].talentGroup;
  526.         if ( talentGroup ) then
  527.             SetActiveTalentGroup(talentGroup);
  528.         end
  529.     end
  530. end
  531.  
  532. function PlayerTalentFrameActivateButton_OnShow(self)
  533.     self:RegisterEvent("CURRENT_SPELL_CAST_CHANGED");
  534.     PlayerTalentFrameActivateButton_Update();
  535. end
  536.  
  537. function PlayerTalentFrameActivateButton_OnHide(self)
  538.     self:UnregisterEvent("CURRENT_SPELL_CAST_CHANGED");
  539. end
  540.  
  541. function PlayerTalentFrameActivateButton_OnEvent(self, event, ...)
  542.     PlayerTalentFrameActivateButton_Update();
  543. end
  544.  
  545. function PlayerTalentFrameActivateButton_Update()
  546.     local spec = selectedSpec and specs[selectedSpec];
  547.     if ( spec and PlayerTalentFrameActivateButton:IsShown() ) then
  548.         -- if the activation spell is being cast currently, disable the activate button
  549.         if ( IsCurrentSpell(TALENT_ACTIVATION_SPELLS[spec.talentGroup]) ) then
  550.             PlayerTalentFrameActivateButton:Disable();
  551.         else
  552.             PlayerTalentFrameActivateButton:Enable();
  553.         end
  554.     end
  555. end
  556.  
  557. function PlayerTalentFrameResetButton_OnEnter(self)
  558.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  559.     GameTooltip:SetText(TALENT_TOOLTIP_RESETTALENTGROUP);
  560. end
  561.  
  562. function PlayerTalentFrameResetButton_OnClick(self)
  563.     ResetGroupPreviewTalentPoints(PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup);
  564. end
  565.  
  566. function PlayerTalentFrameLearnButton_OnEnter(self)
  567.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  568.     GameTooltip:SetText(TALENT_TOOLTIP_LEARNTALENTGROUP);
  569. end
  570.  
  571. function PlayerTalentFrameLearnButton_OnClick(self)
  572.     StaticPopup_Show("CONFIRM_LEARN_PREVIEW_TALENTS");
  573. end
  574.  
  575.  
  576. -- PlayerTalentFrameDownArrow
  577.  
  578. function PlayerTalentFrameDownArrow_OnClick(self, button)
  579.     local parent = self:GetParent();
  580.     parent:SetValue(parent:GetValue() + (parent:GetHeight() / 2));
  581.     PlaySound("UChatScrollButton");
  582.     UIFrameFlashStop(PlayerTalentFrameScrollButtonOverlay);
  583. end
  584.  
  585.  
  586. -- PlayerTalentFrameTab
  587.  
  588. function PlayerTalentFrame_UpdateTabs(playerLevel)
  589.     local totalTabWidth = 0;
  590.  
  591.     local firstShownTab;
  592.  
  593.     -- setup talent tabs
  594.     local maxPointsSpent = 0;
  595.     local selectedTab = PanelTemplates_GetSelectedTab(PlayerTalentFrame);
  596.     local numTabs = GetNumTalentTabs(PlayerTalentFrame.inspect, PlayerTalentFrame.pet);
  597.     local tab;
  598.     for i = 1, MAX_TALENT_TABS do
  599.         -- clear cached widths
  600.         talentTabWidthCache[i] = 0;
  601.         tab = _G["PlayerTalentFrameTab"..i];
  602.         if ( tab ) then
  603.             if ( i <= numTabs ) then
  604.                 local name, icon, pointsSpent, background, previewPointsSpent = GetTalentTabInfo(i, PlayerTalentFrame.inspect, PlayerTalentFrame.pet, PlayerTalentFrame.talentGroup);
  605.                 if ( i == selectedTab ) then
  606.                     -- If tab is the selected tab set the points spent info
  607.                     local displayPointsSpent = pointsSpent + previewPointsSpent;
  608.                     PlayerTalentFrameSpentPointsText:SetFormattedText(MASTERY_POINTS_SPENT, name, HIGHLIGHT_FONT_COLOR_CODE..displayPointsSpent..FONT_COLOR_CODE_CLOSE);
  609.                     PlayerTalentFrame.pointsSpent = pointsSpent;
  610.                     PlayerTalentFrame.previewPointsSpent = previewPointsSpent;
  611.                 end
  612.                 tab:SetText(name);
  613.                 PanelTemplates_TabResize(tab, 0);
  614.                 -- record the text width to see if we need to display a tooltip
  615.                 tab.textWidth = tab:GetTextWidth();
  616.                 -- record the tab widths for resizing later
  617.                 talentTabWidthCache[i] = PanelTemplates_GetTabWidth(tab);
  618.                 totalTabWidth = totalTabWidth + talentTabWidthCache[i];
  619.                 tab:Show();
  620.                 firstShownTab = firstShownTab or tab;
  621.             else
  622.                 tab:Hide();
  623.                 tab.textWidth = 0;
  624.             end
  625.         end
  626.     end
  627.  
  628.     local spec = specs[selectedSpec];
  629.  
  630.     -- setup glyph tabs, right now there is only one
  631.     playerLevel = playerLevel or UnitLevel("player");
  632.     local meetsGlyphLevel = playerLevel >= SHOW_INSCRIPTION_LEVEL;
  633.     tab = _G["PlayerTalentFrameTab"..GLYPH_TALENT_TAB];
  634.     if ( meetsGlyphLevel and spec.hasGlyphs ) then
  635.         tab:Show();
  636.         firstShownTab = firstShownTab or tab;
  637.         PanelTemplates_TabResize(tab, 0);
  638.         talentTabWidthCache[GLYPH_TALENT_TAB] = PanelTemplates_GetTabWidth(tab);
  639.         totalTabWidth = totalTabWidth + talentTabWidthCache[GLYPH_TALENT_TAB];
  640.     else
  641.         tab:Hide();
  642.         talentTabWidthCache[GLYPH_TALENT_TAB] = 0;
  643.     end
  644.     local numGlyphTabs = 1;
  645.  
  646.     -- select the first shown tab if the selected tab does not exist for the selected spec
  647.     tab = _G["PlayerTalentFrameTab"..selectedTab];
  648.     if ( tab and not tab:IsShown() ) then
  649.         if ( firstShownTab ) then
  650.             PlayerTalentFrameTab_OnClick(firstShownTab);
  651.         end
  652.         return false;
  653.     end
  654.  
  655.     -- readjust tab sizes to fit
  656.     local maxTotalTabWidth = PlayerTalentFrame:GetWidth();
  657.     while ( totalTabWidth >= maxTotalTabWidth ) do
  658.         -- progressively shave 10 pixels off of the largest tab until they all fit within the max width
  659.         local largestTab = 1;
  660.         for i = 2, #talentTabWidthCache do
  661.             if ( talentTabWidthCache[largestTab] < talentTabWidthCache[i] ) then
  662.                 largestTab = i;
  663.             end
  664.         end
  665.         -- shave the width
  666.         talentTabWidthCache[largestTab] = talentTabWidthCache[largestTab] - 10;
  667.         -- apply the shaved width
  668.         tab = _G["PlayerTalentFrameTab"..largestTab];
  669.         PanelTemplates_TabResize(tab, 0, talentTabWidthCache[largestTab]);
  670.         -- now update the total width
  671.         totalTabWidth = totalTabWidth - 10;
  672.     end
  673.  
  674.     -- update the tabs
  675.     PanelTemplates_SetNumTabs(PlayerTalentFrame, numTabs + numGlyphTabs);
  676.     PanelTemplates_UpdateTabs(PlayerTalentFrame);
  677.  
  678.     return true;
  679. end
  680.  
  681. function PlayerTalentFrameTab_OnLoad(self)
  682.     self:SetFrameLevel(self:GetFrameLevel() + 2);
  683. end
  684.  
  685. function PlayerTalentFrameTab_OnClick(self)
  686.     local id = self:GetID();
  687.     PanelTemplates_SetTab(PlayerTalentFrame, id);
  688.     PlayerTalentFrame_Refresh();
  689.     PlaySound("igCharacterInfoTab");
  690. end
  691.  
  692. function PlayerTalentFrameTab_OnEnter(self)
  693.     if ( self.textWidth and self.textWidth > self:GetFontString():GetWidth() ) then --We're ellipsizing.
  694.         GameTooltip:SetOwner(self, "ANCHOR_BOTTOM");
  695.         GameTooltip:SetText(self:GetText());
  696.     end
  697. end
  698.  
  699.  
  700. -- PlayerTalentTab
  701.  
  702. function PlayerTalentTab_OnLoad(self)
  703.     PlayerTalentFrameTab_OnLoad(self);
  704.  
  705.     self:RegisterEvent("PLAYER_LEVEL_UP");
  706. end
  707.  
  708. function PlayerTalentTab_OnClick(self)
  709.     PlayerTalentFrameTab_OnClick(self);
  710.     for i=1, MAX_TALENT_TABS do
  711.         SetButtonPulse(_G["PlayerTalentFrameTab"..i], 0, 0);
  712.     end
  713. end
  714.  
  715. function PlayerTalentTab_OnEvent(self, event, ...)
  716.     if ( UnitLevel("player") == (SHOW_TALENT_LEVEL - 1) and PanelTemplates_GetSelectedTab(PlayerTalentFrame) ~= self:GetID() ) then
  717.         SetButtonPulse(self, 60, 0.75);
  718.     end
  719. end
  720.  
  721. function PlayerTalentTab_GetBestDefaultTab(specIndex)
  722.     if ( not specIndex ) then
  723.         return DEFAULT_TALENT_TAB;
  724.     end
  725.  
  726.     local spec = specs[specIndex];
  727.     if ( not spec ) then
  728.         return DEFAULT_TALENT_TAB;
  729.     end
  730.  
  731.     local specInfoCache = talentSpecInfoCache[specIndex];
  732.     TalentFrame_UpdateSpecInfoCache(specInfoCache, false, spec.pet, spec.talentGroup);
  733.     if ( specInfoCache.primaryTabIndex > 0 ) then
  734.         return talentSpecInfoCache[specIndex].primaryTabIndex;
  735.     else
  736.         return DEFAULT_TALENT_TAB;
  737.     end
  738. end
  739.  
  740.  
  741. -- PlayerGlyphTab
  742.  
  743. function PlayerGlyphTab_OnLoad(self)
  744.     PlayerTalentFrameTab_OnLoad(self);
  745.  
  746.     self:RegisterEvent("PLAYER_LEVEL_UP");
  747.     GLYPH_TALENT_TAB = self:GetID();
  748.     -- we can record the text width for the glyph tab now since it never changes
  749.     self.textWidth = self:GetTextWidth();
  750. end
  751.  
  752. function PlayerGlyphTab_OnClick(self)
  753.     PlayerTalentFrameTab_OnClick(self);
  754.     SetButtonPulse(_G["PlayerTalentFrameTab"..GLYPH_TALENT_TAB], 0, 0);
  755. end
  756.  
  757. function PlayerGlyphTab_OnEvent(self, event, ...)
  758.     if ( UnitLevel("player") == (SHOW_INSCRIPTION_LEVEL - 1) and PanelTemplates_GetSelectedTab(PlayerTalentFrame) ~= self:GetID() ) then
  759.         SetButtonPulse(self, 60, 0.75);
  760.     end
  761. end
  762.  
  763.  
  764. -- Specs
  765.  
  766. -- PlayerTalentFrame_UpdateSpecs is a helper function for PlayerTalentFrame_Update.
  767. -- Returns true on a successful update, false otherwise. An update may fail if the currently
  768. -- selected tab is no longer selectable. In this case, the first selectable tab will be selected.
  769. function PlayerTalentFrame_UpdateSpecs(activeTalentGroup, numTalentGroups, activePetTalentGroup, numPetTalentGroups)
  770.     -- set the active spec highlight to be hidden initially, if a spec is the active one then it will
  771.     -- be shown in PlayerSpecTab_Update
  772.     PlayerTalentFrameActiveSpecTabHighlight:Hide();
  773.  
  774.     -- update each of the spec tabs
  775.     local firstShownTab, lastShownTab;
  776.     local numShown = 0;
  777.     local offsetX = 0;
  778.     for i = 1, numSpecTabs do
  779.         local frame = _G["PlayerSpecTab"..i];
  780.         local specIndex = frame.specIndex;
  781.         local spec = specs[specIndex];
  782.         if ( PlayerSpecTab_Update(frame, activeTalentGroup, numTalentGroups, activePetTalentGroup, numPetTalentGroups) ) then
  783.             firstShownTab = firstShownTab or frame;
  784.             numShown = numShown + 1;
  785.             frame:ClearAllPoints();
  786.             -- set an offsetX fudge if we're the selected tab, otherwise use the previous offsetX
  787.             offsetX = specIndex == selectedSpec and SELECTEDSPEC_OFFSETX or offsetX;
  788.             if ( numShown == 1 ) then
  789.                 --...start the first tab off at a base location
  790.                 frame:SetPoint("TOPLEFT", frame:GetParent(), "TOPRIGHT", -32 + offsetX, -65);
  791.                 -- we'll need to negate the offsetX after the first tab so all subsequent tabs offset
  792.                 -- to their default positions
  793.                 offsetX = -offsetX;
  794.             else
  795.                 --...offset subsequent tabs from the previous one
  796.                 if ( spec.pet ~= specs[lastShownTab.specIndex].pet ) then
  797.                     frame:SetPoint("TOPLEFT", lastShownTab, "BOTTOMLEFT", 0 + offsetX, -39);
  798.                 else
  799.                     frame:SetPoint("TOPLEFT", lastShownTab, "BOTTOMLEFT", 0 + offsetX, -22);
  800.                 end
  801.             end
  802.             lastShownTab = frame;
  803.         else
  804.             -- if the selected tab is not shown then clear out the selected spec
  805.             if ( specIndex == selectedSpec ) then
  806.                 selectedSpec = nil;
  807.             end
  808.         end
  809.     end
  810.  
  811.     if ( not selectedSpec ) then
  812.         if ( firstShownTab ) then
  813.             PlayerSpecTab_OnClick(firstShownTab);
  814.         end
  815.         return false;
  816.     end
  817.  
  818.     if ( numShown == 1 and lastShownTab ) then
  819.         -- if we're only showing one tab, we might as well hide it since it doesn't need to be there
  820.         lastShownTab:Hide();
  821.     end
  822.  
  823.     return true;
  824. end
  825.  
  826. function PlayerSpecTab_Update(self, ...)
  827.     local activeTalentGroup, numTalentGroups, activePetTalentGroup, numPetTalentGroups = ...;
  828.  
  829.     local specIndex = self.specIndex;
  830.     local spec = specs[specIndex];
  831.  
  832.     -- determine whether or not we need to hide the tab
  833.     local canShow;
  834.     if ( spec.pet ) then
  835.         canShow = spec.talentGroup <= numPetTalentGroups;
  836.     else
  837.         canShow = spec.talentGroup <= numTalentGroups;
  838.     end
  839.     if ( not canShow ) then
  840.         self:Hide();
  841.         return false;
  842.     end
  843.  
  844.     local isSelectedSpec = specIndex == selectedSpec;
  845.     local isActiveSpec = not spec.pet and spec.talentGroup == activeTalentGroup;
  846.     local normalTexture = self:GetNormalTexture();
  847.  
  848.     -- set the background based on whether or not we're selected
  849.     if ( isSelectedSpec and (SELECTEDSPEC_DISPLAYTYPE == "PUSHED_OUT" or SELECTEDSPEC_DISPLAYTYPE == "PUSHED_OUT_CHECKED") ) then
  850.         local name = self:GetName();
  851.         local backgroundTexture = _G[name.."Background"];
  852.         backgroundTexture:SetTexture("Interface\\TalentFrame\\UI-TalentFrame-SpecTab");
  853.         backgroundTexture:SetPoint("TOPLEFT", self, "TOPLEFT", -13, 11);
  854.         if ( SELECTEDSPEC_DISPLAYTYPE == "PUSHED_OUT_CHECKED" ) then
  855.             self:GetCheckedTexture():Show();
  856.         else
  857.             self:GetCheckedTexture():Hide();
  858.         end
  859.     else
  860.         local name = self:GetName();
  861.         local backgroundTexture = _G[name.."Background"];
  862.         backgroundTexture:SetTexture("Interface\\SpellBook\\SpellBook-SkillLineTab");
  863.         backgroundTexture:SetPoint("TOPLEFT", self, "TOPLEFT", -3, 11);
  864.     end
  865.  
  866.     -- update the active spec info
  867.     local hasMultipleTalentGroups = numTalentGroups > 1;
  868.     if ( isActiveSpec and hasMultipleTalentGroups ) then
  869.         PlayerTalentFrameActiveSpecTabHighlight:ClearAllPoints();
  870.         if ( ACTIVESPEC_DISPLAYTYPE == "BLUE" ) then
  871.             PlayerTalentFrameActiveSpecTabHighlight:SetParent(self);
  872.             PlayerTalentFrameActiveSpecTabHighlight:SetPoint("TOPLEFT", self, "TOPLEFT", -13, 14);
  873.             PlayerTalentFrameActiveSpecTabHighlight:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 15, -14);
  874.             PlayerTalentFrameActiveSpecTabHighlight:Show();
  875.         elseif ( ACTIVESPEC_DISPLAYTYPE == "GOLD_INSIDE" ) then
  876.             PlayerTalentFrameActiveSpecTabHighlight:SetParent(self);
  877.             PlayerTalentFrameActiveSpecTabHighlight:SetAllPoints(self);
  878.             PlayerTalentFrameActiveSpecTabHighlight:Show();
  879.         elseif ( ACTIVESPEC_DISPLAYTYPE == "GOLD_BACKGROUND" ) then
  880.             PlayerTalentFrameActiveSpecTabHighlight:SetParent(self);
  881.             PlayerTalentFrameActiveSpecTabHighlight:SetPoint("TOPLEFT", self, "TOPLEFT", -3, 20);
  882.             PlayerTalentFrameActiveSpecTabHighlight:Show();
  883.         else
  884.             PlayerTalentFrameActiveSpecTabHighlight:Hide();
  885.         end
  886.     end
  887.  
  888. --[[
  889.     if ( not spec.pet ) then
  890.         SetDesaturation(normalTexture, not isActiveSpec);
  891.     end
  892. --]]
  893.  
  894.     -- update the spec info cache
  895.     TalentFrame_UpdateSpecInfoCache(talentSpecInfoCache[specIndex], false, spec.pet, spec.talentGroup);
  896.  
  897.     -- update spec tab icon
  898.     self.usingPortraitTexture = false;
  899.     if ( hasMultipleTalentGroups ) then
  900.         local specInfoCache = talentSpecInfoCache[specIndex];
  901.         local primaryTabIndex = specInfoCache.primaryTabIndex;
  902.         if ( primaryTabIndex > 0 ) then
  903.             -- the spec had a primary tab, set the icon to that tab's icon
  904.             normalTexture:SetTexture(specInfoCache[primaryTabIndex].icon);
  905.         else
  906.             if ( specInfoCache.numTabs > 1 and specInfoCache.totalPointsSpent > 0 ) then
  907.                 -- the spec is only considered a hybrid if the spec had more than one tab and at least
  908.                 -- one point was spent in one of the tabs
  909.                 normalTexture:SetTexture(TALENT_HYBRID_ICON);
  910.             else
  911.                 if ( spec.defaultSpecTexture ) then
  912.                     -- the spec is probably untalented...set to the default spec texture if we have one
  913.                     normalTexture:SetTexture(spec.defaultSpecTexture);
  914.                 elseif ( spec.portraitUnit ) then
  915.                     -- last check...if there is no default spec texture, try the portrait unit
  916.                     SetPortraitTexture(normalTexture, spec.portraitUnit);
  917.                     self.usingPortraitTexture = true;
  918.                 end
  919.             end
  920.         end
  921.     else
  922.         if ( spec.portraitUnit ) then
  923.             -- set to the portrait texture if we only have one talent group
  924.             SetPortraitTexture(normalTexture, spec.portraitUnit);
  925.             self.usingPortraitTexture = true;
  926.         end
  927.     end
  928. --[[
  929.     -- update overlay icon
  930.     local name = self:GetName();
  931.     local overlayIcon = _G[name.."OverlayIcon"];
  932.     if ( overlayIcon ) then
  933.         if ( hasMultipleTalentGroups ) then
  934.             overlayIcon:Show();
  935.         else
  936.             overlayIcon:Hide();
  937.         end
  938.     end
  939. --]]
  940.     self:Show();
  941.     return true;
  942. end
  943.  
  944. function PlayerSpecTab_Load(self, specIndex)
  945.     self.specIndex = specIndex;
  946.     specTabs[specIndex] = self;
  947.     numSpecTabs = numSpecTabs + 1;
  948.  
  949.     -- set the spec's portrait
  950.     local spec = specs[self.specIndex];
  951.     if ( spec.portraitUnit ) then
  952.         SetPortraitTexture(self:GetNormalTexture(), spec.portraitUnit);
  953.         self.usingPortraitTexture = true;
  954.     else
  955.         self.usingPortraitTexture = false;
  956.     end
  957.  
  958.     -- set the checked texture
  959.     if ( SELECTEDSPEC_DISPLAYTYPE == "BLUE" ) then
  960.         local checkedTexture = self:GetCheckedTexture();
  961.         checkedTexture:SetTexture("Interface\\Buttons\\UI-Button-Outline");
  962.         checkedTexture:SetWidth(64);
  963.         checkedTexture:SetHeight(64);
  964.         checkedTexture:ClearAllPoints();
  965.         checkedTexture:SetPoint("CENTER", self, "CENTER", 0, 0);
  966.     elseif ( SELECTEDSPEC_DISPLAYTYPE == "GOLD_INSIDE" ) then
  967.         local checkedTexture = self:GetCheckedTexture();
  968.         checkedTexture:SetTexture("Interface\\Buttons\\CheckButtonHilight");
  969.     end
  970.  
  971.     local activeTalentGroup, numTalentGroups = GetActiveTalentGroup(false, false), GetNumTalentGroups(false, false);
  972.     local activePetTalentGroup, numPetTalentGroups = GetActiveTalentGroup(false, true), GetNumTalentGroups(false, true);
  973.     PlayerSpecTab_Update(self, activeTalentGroup, numTalentGroups, activePetTalentGroup, numPetTalentGroups);
  974. end
  975.  
  976. function PlayerSpecTab_OnClick(self)
  977.     -- set all specs as unchecked initially
  978.     for _, frame in next, specTabs do
  979.         frame:SetChecked(nil);
  980.     end
  981.  
  982.     -- check ourselves (before we wreck ourselves)
  983.     self:SetChecked(1);
  984.  
  985.     -- update the selected to this spec
  986.     local specIndex = self.specIndex;
  987.     selectedSpec = specIndex;
  988.  
  989.     -- set data on the talent frame
  990.     local spec = specs[specIndex];
  991.     PlayerTalentFrame.pet = spec.pet;
  992.     PlayerTalentFrame.unit = spec.unit;
  993.     PlayerTalentFrame.talentGroup = spec.talentGroup;
  994.  
  995.     -- select a tab if one is not already selected
  996.     if ( not PanelTemplates_GetSelectedTab(PlayerTalentFrame) ) then
  997.         PanelTemplates_SetTab(PlayerTalentFrame, PlayerTalentTab_GetBestDefaultTab(specIndex));
  998.     end
  999.  
  1000.     -- update the talent frame
  1001.     PlayerTalentFrame_Refresh();
  1002. end
  1003.  
  1004. function PlayerSpecTab_OnEnter(self)
  1005.     local specIndex = self.specIndex;
  1006.     local spec = specs[specIndex];
  1007.     if ( spec.tooltip ) then
  1008.         GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  1009.         -- name
  1010.         if ( GetNumTalentGroups(false, true) <= 1 and GetNumTalentGroups(false, false) <= 1 ) then
  1011.             -- set the tooltip to be the unit's name
  1012.             GameTooltip:AddLine(UnitName(spec.unit), NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
  1013.         else
  1014.             -- set the tooltip to be the spec name
  1015.             GameTooltip:AddLine(spec.tooltip);
  1016.             if ( self.specIndex == activeSpec ) then
  1017.                 -- add text to indicate that this spec is active
  1018.                 GameTooltip:AddLine(TALENT_ACTIVE_SPEC_STATUS, GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b);
  1019.             end
  1020.         end
  1021.         -- points spent
  1022.         local pointsColor;
  1023.         for index, info in ipairs(talentSpecInfoCache[specIndex]) do
  1024.             if ( info.name ) then
  1025.                 -- assign a special color to a tab that surpasses the max points spent threshold
  1026.                 if ( talentSpecInfoCache[specIndex].primaryTabIndex == index ) then
  1027.                     pointsColor = GREEN_FONT_COLOR;
  1028.                 else
  1029.                     pointsColor = HIGHLIGHT_FONT_COLOR;
  1030.                 end
  1031.                 GameTooltip:AddDoubleLine(
  1032.                     info.name,
  1033.                     info.pointsSpent,
  1034.                     HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
  1035.                     pointsColor.r, pointsColor.g, pointsColor.b,
  1036.                     1
  1037.                 );
  1038.             end
  1039.         end
  1040.         GameTooltip:Show();
  1041.     end
  1042. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement