Advertisement
Guest User

TalentFrameBase.lua

a guest
Oct 1st, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.00 KB | None | 0 0
  1. MAX_TALENT_GROUPS = 2;
  2. MAX_TALENT_TABS = 3;
  3. MAX_NUM_TALENT_TIERS = 6;
  4. NUM_TALENT_COLUMNS = 4;
  5. MAX_NUM_TALENTS = 18;
  6. PLAYER_TALENTS_PER_TIER = 1;
  7. PET_TALENTS_PER_TIER = 1;
  8.  
  9. DEFAULT_TALENT_SPEC = "spec1";
  10. DEFAULT_TALENT_TAB = 1;
  11.  
  12. TALENT_BUTTON_SIZE = 32;
  13. MAX_NUM_BRANCH_TEXTURES = 30;
  14. MAX_NUM_ARROW_TEXTURES = 30;
  15. INITIAL_TALENT_OFFSET_X = 35;
  16. INITIAL_TALENT_OFFSET_Y = 20;
  17.  
  18. TALENT_HYBRID_ICON = "Interface\\Icons\\Ability_DualWieldSpecialization";
  19.  
  20. TALENT_BRANCH_TEXTURECOORDS = {
  21.     up = {
  22.         [1] = {0.12890625, 0.25390625, 0 , 0.484375},
  23.         [-1] = {0.12890625, 0.25390625, 0.515625 , 1.0}
  24.     },
  25.     down = {
  26.         [1] = {0, 0.125, 0, 0.484375},
  27.         [-1] = {0, 0.125, 0.515625, 1.0}
  28.     },
  29.     left = {
  30.         [1] = {0.2578125, 0.3828125, 0, 0.5},
  31.         [-1] = {0.2578125, 0.3828125, 0.5, 1.0}
  32.     },
  33.     right = {
  34.         [1] = {0.2578125, 0.3828125, 0, 0.5},
  35.         [-1] = {0.2578125, 0.3828125, 0.5, 1.0}
  36.     },
  37.     topright = {
  38.         [1] = {0.515625, 0.640625, 0, 0.5},
  39.         [-1] = {0.515625, 0.640625, 0.5, 1.0}
  40.     },
  41.     topleft = {
  42.         [1] = {0.640625, 0.515625, 0, 0.5},
  43.         [-1] = {0.640625, 0.515625, 0.5, 1.0}
  44.     },
  45.     bottomright = {
  46.         [1] = {0.38671875, 0.51171875, 0, 0.5},
  47.         [-1] = {0.38671875, 0.51171875, 0.5, 1.0}
  48.     },
  49.     bottomleft = {
  50.         [1] = {0.51171875, 0.38671875, 0, 0.5},
  51.         [-1] = {0.51171875, 0.38671875, 0.5, 1.0}
  52.     },
  53.     tdown = {
  54.         [1] = {0.64453125, 0.76953125, 0, 0.5},
  55.         [-1] = {0.64453125, 0.76953125, 0.5, 1.0}
  56.     },
  57.     tup = {
  58.         [1] = {0.7734375, 0.8984375, 0, 0.5},
  59.         [-1] = {0.7734375, 0.8984375, 0.5, 1.0}
  60.     },
  61. };
  62.  
  63. TALENT_ARROW_TEXTURECOORDS = {
  64.     top = {
  65.         [1] = {0, 0.5, 0, 0.5},
  66.         [-1] = {0, 0.5, 0.5, 1.0}
  67.     },
  68.     right = {
  69.         [1] = {1.0, 0.5, 0, 0.5},
  70.         [-1] = {1.0, 0.5, 0.5, 1.0}
  71.     },
  72.     left = {
  73.         [1] = {0.5, 1.0, 0, 0.5},
  74.         [-1] = {0.5, 1.0, 0.5, 1.0}
  75.     },
  76. };
  77.  
  78.  
  79. local min = min;
  80. local max = max;
  81. local huge = math.huge;
  82. local rshift = bit.rshift;
  83.  
  84.  
  85. function TalentFrame_Load(TalentFrame)
  86.     TalentFrame.TALENT_BRANCH_ARRAY={};
  87.     for i=1, MAX_NUM_TALENT_TIERS do
  88.         TalentFrame.TALENT_BRANCH_ARRAY[i] = {};
  89.         for j=1, NUM_TALENT_COLUMNS do
  90.             TalentFrame.TALENT_BRANCH_ARRAY[i][j] = {id=nil, up=0, left=0, right=0, down=0, leftArrow=0, rightArrow=0, topArrow=0};
  91.         end
  92.     end
  93. end
  94.  
  95. function TalentFrame_Update(TalentFrame)
  96.     if ( not TalentFrame ) then
  97.         return;
  98.     end
  99.  
  100.     if ( TalentFrame.updateFunction ) then
  101.         TalentFrame.updateFunction();
  102.     end
  103.  
  104.     local talentFrameName = TalentFrame:GetName();
  105.     local selectedTab = PanelTemplates_GetSelectedTab(TalentFrame);
  106.     local preview = GetCVarBool("previewTalents");
  107.  
  108.     -- get active talent group
  109.     local isActiveTalentGroup;
  110.     if ( TalentFrame.inspect ) then
  111.         -- even though we have inspection data for more than one talent group, we're only showing one for now
  112.         isActiveTalentGroup = true;
  113.     else
  114.         isActiveTalentGroup = TalentFrame.talentGroup == GetActiveTalentGroup(TalentFrame.inspect, TalentFrame.pet);
  115.     end
  116.     -- Setup Frame
  117.     local base;
  118.     local name, icon, pointsSpent, background, previewPointsSpent = GetTalentTabInfo(selectedTab, TalentFrame.inspect, TalentFrame.pet, TalentFrame.talentGroup);
  119.     if ( name ) then
  120.         base = "Interface\\TalentFrame\\"..background.."-";
  121.     else
  122.         -- temporary default for classes without talents poor guys
  123.         base = "Interface\\TalentFrame\\MageFire-";
  124.     end
  125.     -- desaturate the background if this isn't the active talent group
  126.     local backgroundPiece = _G[talentFrameName.."BackgroundTopLeft"];
  127.     backgroundPiece:SetTexture(base.."TopLeft");
  128.     SetDesaturation(backgroundPiece, not isActiveTalentGroup);
  129.     backgroundPiece = _G[talentFrameName.."BackgroundTopRight"];
  130.     backgroundPiece:SetTexture(base.."TopRight");
  131.     SetDesaturation(backgroundPiece, not isActiveTalentGroup);
  132.     backgroundPiece = _G[talentFrameName.."BackgroundBottomLeft"];
  133.     backgroundPiece:SetTexture(base.."BottomLeft");
  134.     SetDesaturation(backgroundPiece, not isActiveTalentGroup);
  135.     backgroundPiece = _G[talentFrameName.."BackgroundBottomRight"];
  136.     backgroundPiece:SetTexture(base.."BottomRight");
  137.     SetDesaturation(backgroundPiece, not isActiveTalentGroup);
  138.  
  139.     local numTalents = GetNumTalents(selectedTab, TalentFrame.inspect, TalentFrame.pet);
  140.     -- Just a reminder error if there are more talents than available buttons
  141.     if ( numTalents > MAX_NUM_TALENTS ) then
  142.         message("Too many talents in talent frame!");
  143.     end
  144.     -- get unspent talent points
  145.     local unspentPoints = TalentFrame_UpdateTalentPoints(TalentFrame);
  146.     -- compute tab points spent if any
  147.     local tabPointsSpent;
  148.     if ( TalentFrame.pointsSpent and TalentFrame.previewPointsSpent ) then
  149.         tabPointsSpent = TalentFrame.pointsSpent + TalentFrame.previewPointsSpent;
  150.     else
  151.         tabPointsSpent = 0;
  152.     end
  153.  
  154.     TalentFrame_ResetBranches(TalentFrame);
  155.     local talentFrameTalentName = talentFrameName.."Talent";
  156.     local forceDesaturated, tierUnlocked;
  157.     for i=1, MAX_NUM_TALENTS do
  158.         local buttonName = talentFrameTalentName..i;
  159.         local button = _G[buttonName];
  160.         if ( i <= numTalents ) then
  161.             -- Set the button info
  162.             local name, iconTexture, tier, column, rank, maxRank, isExceptional, meetsPrereq, previewRank, meetsPreviewPrereq =
  163.                 GetTalentInfo(selectedTab, i, TalentFrame.inspect, TalentFrame.pet, TalentFrame.talentGroup);
  164.             if ( name ) then
  165.                 local displayRank;
  166.                 if ( preview ) then
  167.                     displayRank = previewRank;
  168.                 else
  169.                     displayRank = rank;
  170.                 end
  171.  
  172.                 _G[buttonName.."Rank"]:SetText(displayRank);
  173.                 SetTalentButtonLocation(button, tier, column);
  174.                 TalentFrame.TALENT_BRANCH_ARRAY[tier][column].id = button:GetID();
  175.            
  176.                 -- If player has no talent points or this is the inactive talent group then show only talents with points in them
  177.                 if ( (unspentPoints <= 0 or not isActiveTalentGroup) and displayRank == 0 ) then
  178.                     forceDesaturated = 1;
  179.                 else
  180.                     forceDesaturated = nil;
  181.                 end
  182.  
  183.                 -- is this talent's tier unlocked?
  184.                 if ( ((tier - 1) * (TalentFrame.pet and PET_TALENTS_PER_TIER or PLAYER_TALENTS_PER_TIER) <= tabPointsSpent) ) then
  185.                     tierUnlocked = 1;
  186.                 else
  187.                     tierUnlocked = nil;
  188.                 end
  189.  
  190.                 SetItemButtonTexture(button, iconTexture);
  191.  
  192.                 -- Talent must meet prereqs or the player must have no points to spend
  193.                 local prereqsSet =
  194.                     TalentFrame_SetPrereqs(TalentFrame, tier, column, forceDesaturated, tierUnlocked, preview,
  195.                     GetTalentPrereqs(selectedTab, i, TalentFrame.inspect, TalentFrame.pet, TalentFrame.talentGroup));
  196.                 if ( prereqsSet and ((preview and meetsPreviewPrereq) or (not preview and meetsPrereq)) ) then
  197.                     SetItemButtonDesaturated(button, nil);
  198.  
  199.                     if ( displayRank < maxRank ) then
  200.                         -- Rank is green if not maxed out
  201.                         _G[buttonName.."Slot"]:SetVertexColor(0.1, 1.0, 0.1);
  202.                         _G[buttonName.."Rank"]:SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b);
  203.                     else
  204.                         _G[buttonName.."Slot"]:SetVertexColor(1.0, 0.82, 0);
  205.                         _G[buttonName.."Rank"]:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
  206.                     end
  207.                     _G[buttonName.."RankBorder"]:Show();
  208.                     _G[buttonName.."Rank"]:Show();
  209.                 else
  210.                     SetItemButtonDesaturated(button, 1, 0.65, 0.65, 0.65);
  211.                     _G[buttonName.."Slot"]:SetVertexColor(0.5, 0.5, 0.5);
  212.                     if ( rank == 0 ) then
  213.                         _G[buttonName.."RankBorder"]:Hide();
  214.                         _G[buttonName.."Rank"]:Hide();
  215.                     else
  216.                         _G[buttonName.."RankBorder"]:SetVertexColor(0.5, 0.5, 0.5);
  217.                         _G[buttonName.."Rank"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
  218.                     end
  219.                 end
  220.                 button:Show();
  221.             else
  222.                 button:Hide();
  223.             end
  224.         else   
  225.             button:Hide();
  226.         end
  227.     end
  228.  
  229.     -- Draw the prereq branches
  230.     local node;
  231.     local textureIndex = 1;
  232.     local xOffset, yOffset;
  233.     local texCoords;
  234.     -- Variable that decides whether or not to ignore drawing pieces
  235.     local ignoreUp;
  236.     local tempNode;
  237.     TalentFrame_ResetBranchTextureCount(TalentFrame);
  238.     TalentFrame_ResetArrowTextureCount(TalentFrame);
  239.     for i=1, MAX_NUM_TALENT_TIERS do
  240.         for j=1, NUM_TALENT_COLUMNS do
  241.             node = TalentFrame.TALENT_BRANCH_ARRAY[i][j];
  242.            
  243.             -- Setup offsets
  244.             xOffset = ((j - 1) * 63) + INITIAL_TALENT_OFFSET_X + 2;
  245.             yOffset = -((i - 1) * 63) - INITIAL_TALENT_OFFSET_Y - 2;
  246.        
  247.             if ( node.id ) then
  248.                 -- Has talent
  249.                 if ( node.up ~= 0 ) then
  250.                     if ( not ignoreUp ) then
  251.                         TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["up"][node.up], xOffset, yOffset + TALENT_BUTTON_SIZE, TalentFrame);
  252.                     else
  253.                         ignoreUp = nil;
  254.                     end
  255.                 end
  256.                 if ( node.down ~= 0 ) then
  257.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset, yOffset - TALENT_BUTTON_SIZE + 1, TalentFrame);
  258.                 end
  259.                 if ( node.left ~= 0 ) then
  260.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["left"][node.left], xOffset - TALENT_BUTTON_SIZE, yOffset, TalentFrame);
  261.                 end
  262.                 if ( node.right ~= 0 ) then
  263.                     -- See if any connecting branches are gray and if so color them gray
  264.                     tempNode = TalentFrame.TALENT_BRANCH_ARRAY[i][j+1];
  265.                     if ( tempNode.left ~= 0 and tempNode.down < 0 ) then
  266.                         TalentFrame_SetBranchTexture(i, j-1, TALENT_BRANCH_TEXTURECOORDS["right"][tempNode.down], xOffset + TALENT_BUTTON_SIZE, yOffset, TalentFrame);
  267.                     else
  268.                         TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["right"][node.right], xOffset + TALENT_BUTTON_SIZE + 1, yOffset, TalentFrame);
  269.                     end
  270.                    
  271.                 end
  272.                 -- Draw arrows
  273.                 if ( node.rightArrow ~= 0 ) then
  274.                     TalentFrame_SetArrowTexture(i, j, TALENT_ARROW_TEXTURECOORDS["right"][node.rightArrow], xOffset + TALENT_BUTTON_SIZE/2 + 5, yOffset, TalentFrame);
  275.                 end
  276.                 if ( node.leftArrow ~= 0 ) then
  277.                     TalentFrame_SetArrowTexture(i, j, TALENT_ARROW_TEXTURECOORDS["left"][node.leftArrow], xOffset - TALENT_BUTTON_SIZE/2 - 5, yOffset, TalentFrame);
  278.                 end
  279.                 if ( node.topArrow ~= 0 ) then
  280.                     TalentFrame_SetArrowTexture(i, j, TALENT_ARROW_TEXTURECOORDS["top"][node.topArrow], xOffset, yOffset + TALENT_BUTTON_SIZE/2 + 5, TalentFrame);
  281.                 end
  282.             else
  283.                 -- Doesn't have a talent
  284.                 if ( node.up ~= 0 and node.left ~= 0 and node.right ~= 0 ) then
  285.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["tup"][node.up], xOffset , yOffset, TalentFrame);
  286.                 elseif ( node.down ~= 0 and node.left ~= 0 and node.right ~= 0 ) then
  287.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["tdown"][node.down], xOffset , yOffset, TalentFrame);
  288.                 elseif ( node.left ~= 0 and node.down ~= 0 ) then
  289.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["topright"][node.left], xOffset , yOffset, TalentFrame);
  290.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset , yOffset - 32, TalentFrame);
  291.                 elseif ( node.left ~= 0 and node.up ~= 0 ) then
  292.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["bottomright"][node.left], xOffset , yOffset, TalentFrame);
  293.                 elseif ( node.left ~= 0 and node.right ~= 0 ) then
  294.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["right"][node.right], xOffset + TALENT_BUTTON_SIZE, yOffset, TalentFrame);
  295.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["left"][node.left], xOffset + 1, yOffset, TalentFrame);
  296.                 elseif ( node.right ~= 0 and node.down ~= 0 ) then
  297.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["topleft"][node.right], xOffset , yOffset, TalentFrame);
  298.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset , yOffset - 32, TalentFrame);
  299.                 elseif ( node.right ~= 0 and node.up ~= 0 ) then
  300.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["bottomleft"][node.right], xOffset , yOffset, TalentFrame);
  301.                 elseif ( node.up ~= 0 and node.down ~= 0 ) then
  302.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["up"][node.up], xOffset , yOffset, TalentFrame);
  303.                     TalentFrame_SetBranchTexture(i, j, TALENT_BRANCH_TEXTURECOORDS["down"][node.down], xOffset , yOffset - 32, TalentFrame);
  304.                     ignoreUp = 1;
  305.                 end
  306.             end
  307.         end
  308.     end
  309.     -- Hide any unused branch textures
  310.     for i=TalentFrame_GetBranchTextureCount(TalentFrame), MAX_NUM_BRANCH_TEXTURES do
  311.         _G[talentFrameName.."Branch"..i]:Hide();
  312.     end
  313.     -- Hide and unused arrowl textures
  314.     for i=TalentFrame_GetArrowTextureCount(TalentFrame), MAX_NUM_ARROW_TEXTURES do
  315.         _G[talentFrameName.."Arrow"..i]:Hide();
  316.     end
  317. end
  318.  
  319. function TalentFrame_SetArrowTexture(tier, column, texCoords, xOffset, yOffset, TalentFrame)
  320.     local talentFrameName = TalentFrame:GetName();
  321.     local arrowTexture = TalentFrame_GetArrowTexture(TalentFrame);
  322.     arrowTexture:SetTexCoord(texCoords[1], texCoords[2], texCoords[3], texCoords[4]);
  323.     arrowTexture:SetPoint("TOPLEFT", talentFrameName.."ArrowFrame", "TOPLEFT", xOffset, yOffset);
  324. end
  325.  
  326. function TalentFrame_SetBranchTexture(tier, column, texCoords, xOffset, yOffset, TalentFrame)
  327.     local talentFrameName = TalentFrame:GetName();
  328.     local branchTexture = TalentFrame_GetBranchTexture(TalentFrame);
  329.     branchTexture:SetTexCoord(texCoords[1], texCoords[2], texCoords[3], texCoords[4]);
  330.     branchTexture:SetPoint("TOPLEFT", talentFrameName.."ScrollChildFrame", "TOPLEFT", xOffset, yOffset);
  331. end
  332.  
  333. function TalentFrame_GetArrowTexture(TalentFrame)
  334.     local talentFrameName = TalentFrame:GetName();
  335.     local arrowTexture = _G[talentFrameName.."Arrow"..TalentFrame.arrowIndex];
  336.     TalentFrame.arrowIndex = TalentFrame.arrowIndex + 1;
  337.     if ( not arrowTexture ) then
  338.         message("Not enough arrow textures");
  339.     else
  340.         arrowTexture:Show();
  341.         return arrowTexture;
  342.     end
  343. end
  344.  
  345. function TalentFrame_GetBranchTexture(TalentFrame)
  346.     local talentFrameName = TalentFrame:GetName();
  347.     local branchTexture = _G[talentFrameName.."Branch"..TalentFrame.textureIndex];
  348.     TalentFrame.textureIndex = TalentFrame.textureIndex + 1;
  349.     if ( not branchTexture ) then
  350.         --branchTexture = CreateTexture("TalentFrameBranch"..TalentFrame.textureIndex);
  351.         message("Not enough branch textures");
  352.     else
  353.         branchTexture:Show();
  354.         return branchTexture;
  355.     end
  356. end
  357.  
  358. function TalentFrame_ResetArrowTextureCount(TalentFrame)
  359.     TalentFrame.arrowIndex = 1;
  360. end
  361.  
  362. function TalentFrame_ResetBranchTextureCount(TalentFrame)
  363.     TalentFrame.textureIndex = 1;
  364. end
  365.  
  366. function TalentFrame_GetArrowTextureCount(TalentFrame)
  367.     return TalentFrame.arrowIndex;
  368. end
  369.  
  370. function TalentFrame_GetBranchTextureCount(TalentFrame)
  371.     return TalentFrame.textureIndex;
  372. end
  373.  
  374. function TalentFrame_SetPrereqs(TalentFrame, buttonTier, buttonColumn, forceDesaturated, tierUnlocked, preview, ...)
  375.     local requirementsMet = tierUnlocked and not forceDesaturated;
  376.     for i=1, select("#", ...), 4 do
  377.         local tier, column, isLearnable, isPreviewLearnable = select(i, ...);
  378.         if ( forceDesaturated or tierUnlocked or
  379.              (preview and not isPreviewLearnable) or
  380.              (not preview and not isLearnable) ) then
  381.             requirementsMet = nil;
  382.         end
  383.         TalentFrame_DrawLines(buttonTier, buttonColumn, tier, column, requirementsMet, TalentFrame);
  384.     end
  385.     return requirementsMet;
  386. end
  387.  
  388.  
  389. function TalentFrame_DrawLines(buttonTier, buttonColumn, tier, column, requirementsMet, TalentFrame)
  390.     if ( requirementsMet ) then
  391.         requirementsMet = 1;
  392.     else
  393.         requirementsMet = -1;
  394.     end
  395.    
  396.     -- Check to see if are in the same column
  397.     if ( buttonColumn == column ) then
  398.         -- Check for blocking talents
  399.         if ( (buttonTier - tier) > 1 ) then
  400.             -- If more than one tier difference
  401.             for i=tier + 1, buttonTier - 1 do
  402.                 if ( TalentFrame.TALENT_BRANCH_ARRAY[i][buttonColumn].id ) then
  403.                     -- If there's an id, there's a blocker
  404.                     message("Error this layout is blocked vertically "..TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][i].id);
  405.                     return;
  406.                 end
  407.             end
  408.         end
  409.        
  410.         -- Draw the lines
  411.         for i=tier, buttonTier - 1 do
  412.             TalentFrame.TALENT_BRANCH_ARRAY[i][buttonColumn].down = requirementsMet;
  413.             if ( (i + 1) <= (buttonTier - 1) ) then
  414.                 TalentFrame.TALENT_BRANCH_ARRAY[i + 1][buttonColumn].up = requirementsMet;
  415.             end
  416.         end
  417.        
  418.         -- Set the arrow
  419.         TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][buttonColumn].topArrow = requirementsMet;
  420.         return;
  421.     end
  422.     -- Check to see if they're in the same tier
  423.     if ( buttonTier == tier ) then
  424.         local left = min(buttonColumn, column);
  425.         local right = max(buttonColumn, column);
  426.        
  427.         -- See if the distance is greater than one space
  428.         if ( (right - left) > 1 ) then
  429.             -- Check for blocking talents
  430.             for i=left + 1, right - 1 do
  431.                 if ( TalentFrame.TALENT_BRANCH_ARRAY[tier][i].id ) then
  432.                     -- If there's an id, there's a blocker
  433.                     message("there's a blocker "..tier.." "..i);
  434.                     return;
  435.                 end
  436.             end
  437.         end
  438.         -- If we get here then we're in the clear
  439.         for i=left, right - 1 do
  440.             TalentFrame.TALENT_BRANCH_ARRAY[tier][i].right = requirementsMet;
  441.             TalentFrame.TALENT_BRANCH_ARRAY[tier][i+1].left = requirementsMet;
  442.         end
  443.         -- Determine where the arrow goes
  444.         if ( buttonColumn < column ) then
  445.             TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][buttonColumn].rightArrow = requirementsMet;
  446.         else
  447.             TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][buttonColumn].leftArrow = requirementsMet;
  448.         end
  449.         return;
  450.     end
  451.     -- Now we know the prereq is diagonal from us
  452.     local left = min(buttonColumn, column);
  453.     local right = max(buttonColumn, column);
  454.     -- Don't check the location of the current button
  455.     if ( left == column ) then
  456.         left = left + 1;
  457.     else
  458.         right = right - 1;
  459.     end
  460.     -- Check for blocking talents
  461.     local blocked = nil;
  462.     for i=left, right do
  463.         if ( TalentFrame.TALENT_BRANCH_ARRAY[tier][i].id ) then
  464.             -- If there's an id, there's a blocker
  465.             blocked = 1;
  466.         end
  467.     end
  468.     left = min(buttonColumn, column);
  469.     right = max(buttonColumn, column);
  470.     if ( not blocked ) then
  471.         TalentFrame.TALENT_BRANCH_ARRAY[tier][buttonColumn].down = requirementsMet;
  472.         TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][buttonColumn].up = requirementsMet;
  473.        
  474.         for i=tier, buttonTier - 1 do
  475.             TalentFrame.TALENT_BRANCH_ARRAY[i][buttonColumn].down = requirementsMet;
  476.             TalentFrame.TALENT_BRANCH_ARRAY[i + 1][buttonColumn].up = requirementsMet;
  477.         end
  478.  
  479.         for i=left, right - 1 do
  480.             TalentFrame.TALENT_BRANCH_ARRAY[tier][i].right = requirementsMet;
  481.             TalentFrame.TALENT_BRANCH_ARRAY[tier][i+1].left = requirementsMet;
  482.         end
  483.         -- Place the arrow
  484.         TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][buttonColumn].topArrow = requirementsMet;
  485.         return;
  486.     end
  487.     -- If we're here then we were blocked trying to go vertically first so we have to go over first, then up
  488.     if ( left == buttonColumn ) then
  489.         left = left + 1;
  490.     else
  491.         right = right - 1;
  492.     end
  493.     -- Check for blocking talents
  494.     for i=left, right do
  495.         if ( TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][i].id ) then
  496.             -- If there's an id, then throw an error
  497.             message("Error, this layout is undrawable "..TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][i].id);
  498.             return;
  499.         end
  500.     end
  501.     -- If we're here we can draw the line
  502.     left = min(buttonColumn, column);
  503.     right = max(buttonColumn, column);
  504.     --TALENT_BRANCH_ARRAY[tier][column].down = requirementsMet;
  505.     --TALENT_BRANCH_ARRAY[buttonTier][column].up = requirementsMet;
  506.  
  507.     for i=tier, buttonTier-1 do
  508.         TalentFrame.TALENT_BRANCH_ARRAY[i][column].up = requirementsMet;
  509.         TalentFrame.TALENT_BRANCH_ARRAY[i+1][column].down = requirementsMet;
  510.     end
  511.  
  512.     -- Determine where the arrow goes
  513.     if ( buttonColumn < column ) then
  514.         TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][buttonColumn].rightArrow =  requirementsMet;
  515.     else
  516.         TalentFrame.TALENT_BRANCH_ARRAY[buttonTier][buttonColumn].leftArrow =  requirementsMet;
  517.     end
  518. end
  519.  
  520.  
  521.  
  522. -- Helper functions
  523.  
  524. function TalentFrame_UpdateTalentPoints(TalentFrame)
  525.     local talentPoints = GetUnspentTalentPoints(TalentFrame.inspect, TalentFrame.pet, TalentFrame.talentGroup);
  526.     local unspentPoints = talentPoints - GetGroupPreviewTalentPointsSpent(TalentFrame.pet, TalentFrame.talentGroup);
  527.     local talentFrameName = TalentFrame:GetName();
  528.     _G[talentFrameName.."TalentPointsText"]:SetFormattedText(UNSPENT_TALENT_POINTS, HIGHLIGHT_FONT_COLOR_CODE..unspentPoints..FONT_COLOR_CODE_CLOSE);
  529.     TalentFrame_ResetBranches(TalentFrame);
  530.     _G[talentFrameName.."ScrollFrameScrollBarScrollDownButton"]:SetScript("OnClick", _G[talentFrameName.."DownArrow_OnClick"]);
  531.     return unspentPoints;
  532. end
  533.  
  534. function SetTalentButtonLocation(button, tier, column)
  535.     column = ((column - 1) * 63) + INITIAL_TALENT_OFFSET_X;
  536.     tier = -((tier - 1) * 63) - INITIAL_TALENT_OFFSET_Y;
  537.     button:SetPoint("TOPLEFT", button:GetParent(), "TOPLEFT", column, tier);
  538. end
  539.  
  540. function TalentFrame_ResetBranches(TalentFrame)
  541.     for i=1, MAX_NUM_TALENT_TIERS do
  542.         for j=1, NUM_TALENT_COLUMNS do
  543.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].id = nil;
  544.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].up = 0;
  545.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].down = 0;
  546.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].left = 0;
  547.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].right = 0;
  548.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].rightArrow = 0;
  549.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].leftArrow = 0;
  550.             TalentFrame.TALENT_BRANCH_ARRAY[i][j].topArrow = 0;
  551.         end
  552.     end
  553. end
  554.  
  555. local sortedTabPointsSpentBuf = { };
  556. function TalentFrame_UpdateSpecInfoCache(cache, inspect, pet, talentGroup)
  557.     -- initialize some cache info
  558.     cache.primaryTabIndex = 0;
  559.     cache.totalPointsSpent = 0;
  560.  
  561.     local preview = GetCVarBool("previewTalents");
  562.  
  563.     local highPointsSpent = 0;
  564.     local highPointsSpentIndex;
  565.     local lowPointsSpent = huge;
  566.     local lowPointsSpentIndex;
  567.  
  568.     local numTabs = GetNumTalentTabs(inspect, pet);
  569.     cache.numTabs = numTabs;
  570.     for i = 1, MAX_TALENT_TABS do
  571.         cache[i] = cache[i] or { };
  572.         if ( i <= numTabs ) then
  573.             local name, icon, pointsSpent, background, previewPointsSpent = GetTalentTabInfo(i, inspect, pet, talentGroup);
  574.  
  575.             local displayPointsSpent = pointsSpent + previewPointsSpent;
  576.  
  577.             -- cache the info we care about
  578.             cache[i].name = name;
  579.             cache[i].pointsSpent = displayPointsSpent;
  580.             cache[i].icon = icon;
  581.  
  582.             -- update total points
  583.             cache.totalPointsSpent = cache.totalPointsSpent + displayPointsSpent;
  584.  
  585.             -- update the high and low points spent info
  586.             if ( displayPointsSpent > highPointsSpent ) then
  587.                 highPointsSpent = displayPointsSpent;
  588.                 highPointsSpentIndex = i;
  589.             end
  590.             if ( displayPointsSpent < lowPointsSpent ) then
  591.                 lowPointsSpent = displayPointsSpent;
  592.                 lowPointsSpentIndex = i;
  593.             end
  594.  
  595.             -- initialize the points spent buffer element
  596.             sortedTabPointsSpentBuf[i] = 0;
  597.             -- insert the points spent into our buffer in ascending order
  598.             local insertIndex = i;
  599.             for j = 1, i, 1 do
  600.                 local currPointsSpent = sortedTabPointsSpentBuf[j];
  601.                 if ( currPointsSpent > displayPointsSpent ) then
  602.                     insertIndex = j;
  603.                     break;
  604.                 end
  605.             end
  606.             for j = i, insertIndex + 1, -1 do
  607.                 sortedTabPointsSpentBuf[j] = sortedTabPointsSpentBuf[j - 1];
  608.             end
  609.             sortedTabPointsSpentBuf[insertIndex] = displayPointsSpent;
  610.         else
  611.             cache[i].name = nil;
  612.         end
  613.     end
  614.  
  615.     if ( highPointsSpentIndex and lowPointsSpentIndex ) then
  616.         -- now that our points spent buffer is filled, we can compute the mid points spent
  617.         local midPointsSpentIndex = rshift(numTabs, 1) + 1;
  618.         local midPointsSpent = sortedTabPointsSpentBuf[midPointsSpentIndex];
  619.         -- now let's use our crazy formula to determine which tab is the primary one
  620.         if ( 3*(midPointsSpent-lowPointsSpent) < 2*(highPointsSpent-lowPointsSpent) ) then
  621.             cache.primaryTabIndex = highPointsSpentIndex;
  622.         end
  623.     end
  624. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement