Guest User

Untitled

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