stoneharry

Untitled

May 3rd, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.27 KB | None | 0 0
  1. SECURITYMATRIX_NUM_ROWS = 10;
  2. SECURITYMATRIX_NUM_COLUMNS = 8;
  3. SECURITYMATRIX_GRID_SIZE = 32;
  4. SECURITYMATRIX_CELL_HIGHLIGHT_SCALE = 1.2; --2.0 is good for 64 pixel cells, 0.8 is good for 32 pixel cells
  5. SECURITYMATRIX_GRID_OVERLAP = 6;
  6. SECURITYMATRIX_HIGHLIGHT_OVERHANG = 4;
  7. SECURITYMATRIX_PINWHEEL_BUTTON_SIZE = 32;
  8. SECURITYMATRIX_PINWHEEL_VERTICAL_OFFSET = 18;
  9. SECURITYMATRIX_NUM_MIN_DIGITS = 2;
  10. SECURITYMATRIX_NUM_MAX_DIGITS = 2;
  11. -- Default is Columns are Alphabetic, rows are numeric.
  12. SECURITYMATRIX_FLIP_COORDS = false;
  13. SECURITYMATRIX_TEXT_LENGTH = 0
  14. SECURITYMATRIX_ALL_COLUMN_HEADERS = {}
  15. SECURITYMATRIX_ALL_ROW_HEADERS = {}
  16. SECURITYMATRIX_ALL_ELEMENTS = {}
  17.  
  18. SecurityMatrix_Alphabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  19.  
  20. SecurityMatrix_currentColumn = 1;
  21. SecurityMatrix_currentRow = 1;
  22. SecurityMatrix_currentValue = 0;
  23. SecurityMatrix_isMoving = false;
  24. SecurityMatrix_updateSpeed = 0.005;
  25.  
  26. -------------------------------------------------------------------------------
  27.  
  28. function SecurityMatrix_CreateHeaders()
  29.     local prevFrame = nil;
  30.     for i=1, SECURITYMATRIX_NUM_ROWS do
  31.         local newFrame = SECURITYMATRIX_ALL_ROW_HEADERS[i]
  32.         if not newFrame then
  33.             newFrame = CreateFrame("Frame", "SecurityMatrixFrameRowHeader"..i, SecurityMatrixFrame, "SecurityMatrixHeaderElementTextFrameTemplate");
  34.             SECURITYMATRIX_ALL_ROW_HEADERS[i] = newFrame
  35.         end
  36.         newFrame:Show()
  37.         if(i == 1) then
  38.             newFrame:SetPoint("TOPLEFT", 0, -(SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP));
  39.         else
  40.             newFrame:SetPoint("TOP", prevFrame, "BOTTOM", 0, SECURITYMATRIX_GRID_OVERLAP);
  41.         end
  42.         newFrame:SetWidth(SECURITYMATRIX_GRID_SIZE);
  43.         newFrame:SetHeight(SECURITYMATRIX_GRID_SIZE);
  44.         if SECURITYMATRIX_FLIP_COORDS then
  45.             _G["SecurityMatrixFrameRowHeader"..i.."Text"]:SetText(SecurityMatrix_Alphabet[i])
  46.         else
  47.             _G["SecurityMatrixFrameRowHeader"..i.."Text"]:SetText(i);
  48.         end
  49.         _G["SecurityMatrixFrameRowHeader"..i]:SetID(i);
  50.         prevFrame = newFrame;
  51.     end
  52.     for i=1, SECURITYMATRIX_NUM_COLUMNS do
  53.         local newFrame = SECURITYMATRIX_ALL_COLUMN_HEADERS[i]
  54.         if not newFrame then
  55.             newFrame = CreateFrame("Frame", "SecurityMatrixFrameColumnHeader"..i, SecurityMatrixFrame, "SecurityMatrixHeaderElementTextFrameTemplate");
  56.             SECURITYMATRIX_ALL_COLUMN_HEADERS[i] = newFrame
  57.         end
  58.         newFrame:Show()
  59.         if(i == 1) then
  60.             newFrame:SetPoint("TOPLEFT", (SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP), 0);
  61.         else
  62.             newFrame:SetPoint("LEFT", prevFrame, "RIGHT", -SECURITYMATRIX_GRID_OVERLAP, 0);
  63.         end
  64.         newFrame:SetWidth(SECURITYMATRIX_GRID_SIZE);
  65.         newFrame:SetHeight(SECURITYMATRIX_GRID_SIZE);
  66.         if SECURITYMATRIX_FLIP_COORDS then
  67.             _G["SecurityMatrixFrameColumnHeader"..i.."Text"]:SetText(tostring(i))
  68.         else
  69.             _G["SecurityMatrixFrameColumnHeader"..i.."Text"]:SetText(SecurityMatrix_Alphabet[i]);
  70.         end
  71.         _G["SecurityMatrixFrameColumnHeader"..i]:SetID(i);
  72.         prevFrame = newFrame;
  73.     end
  74. end
  75.  
  76. function SecurityMatrix_HideHeaders()
  77.     for i, v in ipairs(SECURITYMATRIX_ALL_COLUMN_HEADERS) do
  78.         v:Hide()
  79.     end
  80.     for i, v in ipairs(SECURITYMATRIX_ALL_ROW_HEADERS) do
  81.         v:Hide()
  82.     end
  83. end
  84.  
  85. function SecurityMatrix_CreateElements()
  86.     local prevFrame = nil;
  87.     --loop through all the rows
  88.     for i=1, SECURITYMATRIX_NUM_ROWS do
  89.         --loop through all the columns
  90.         if not SECURITYMATRIX_ALL_ELEMENTS[i] then SECURITYMATRIX_ALL_ELEMENTS[i] = {} end
  91.         for j=1, SECURITYMATRIX_NUM_COLUMNS do
  92.             --create a new frame and name it with a suffix of column+row
  93.             if not SECURITYMATRIX_ALL_ELEMENTS[i][j] then SECURITYMATRIX_ALL_ELEMENTS[i][j] = {} end
  94.             local newBackgroundFrame = SECURITYMATRIX_ALL_ELEMENTS[i][j].background
  95.             if not newBackgroundFrame then
  96.                 newBackgroundFrame = CreateFrame("Frame", "$parentElement"..i.."_"..j, SecurityMatrixFrame, "SecurityMatrixElementFrameTemplate");
  97.                 SECURITYMATRIX_ALL_ELEMENTS[i][j].background = newBackgroundFrame
  98.             end
  99.             newBackgroundFrame:Show()
  100.             local newSparkleFrame = SECURITYMATRIX_ALL_ELEMENTS[i][j].sparkle
  101.             if not newSparkleFrame then
  102.                 newSparkleFrame = CreateFrame("Frame", "$parentElementSparkle"..i.."_"..j, SecurityMatrixFrame, "SecurityMatrixElementSparkleFrameTemplate");
  103.                 SECURITYMATRIX_ALL_ELEMENTS[i][j].sparkle = newSparkleFrame
  104.             end
  105.             newSparkleFrame:Show()
  106.             --if this is the first frame then anchor it to the top left of the parent frame
  107.             if(j == 1) then
  108.                 newBackgroundFrame:SetPoint("TOPLEFT", (SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP), -((SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)*(i)));
  109.             else
  110.                 newBackgroundFrame:SetPoint("LEFT", prevBackgroundFrame, "RIGHT", -SECURITYMATRIX_GRID_OVERLAP, 0);
  111.             end
  112.             --increment the frame layer for each frame so that they tile a little nicer
  113.             newBackgroundFrame:SetFrameLevel(i*SECURITYMATRIX_NUM_COLUMNS + j + 10);
  114.             --set the width/height here so we can change it easily without having to find it in the XML
  115.             newBackgroundFrame:SetWidth(SECURITYMATRIX_GRID_SIZE);
  116.             newBackgroundFrame:SetHeight(SECURITYMATRIX_GRID_SIZE);
  117.             --line the text frame and highlight up with the background frame
  118.             newSparkleFrame:SetAllPoints(newBackgroundFrame);
  119.             _G["SecurityMatrixFrameElementSparkle"..i.."_"..j.."Highlight"]:SetModelScale(SECURITYMATRIX_CELL_HIGHLIGHT_SCALE);
  120.             _G["SecurityMatrixFrameElementSparkle"..i.."_"..j.."Highlight"]:SetWidth(SECURITYMATRIX_GRID_SIZE);
  121.             _G["SecurityMatrixFrameElementSparkle"..i.."_"..j.."Highlight"]:SetHeight(SECURITYMATRIX_GRID_SIZE);
  122.             prevBackgroundFrame = newBackgroundFrame;
  123.         end
  124.     end
  125. end
  126.  
  127. function SecurityMatrix_HideElements()
  128.     for columnNum, column in ipairs(SECURITYMATRIX_ALL_ELEMENTS) do
  129.         for rowNum, cell in ipairs(column) do
  130.             SECURITYMATRIX_ALL_ELEMENTS[columnNum][rowNum].background:Hide()
  131.             SECURITYMATRIX_ALL_ELEMENTS[columnNum][rowNum].sparkle:Hide()
  132.         end
  133.     end
  134. end
  135.  
  136. function SecurityMatrix_NewCoordinate(row, column)
  137.     --start the movement animation
  138.     SecurityMatrix_isMoving = true;
  139.    
  140.     --turn off the sparkle on the old cell
  141.     _G["SecurityMatrixFrameElementSparkle"..SecurityMatrix_currentRow.."_"..SecurityMatrix_currentColumn.."Highlight"]:Hide();
  142.     _G["SecurityMatrixFrameElementSparkle"..SecurityMatrix_currentRow.."_"..SecurityMatrix_currentColumn.."Texture"]:Hide();
  143.    
  144.     --turn off the text highlight on the old row/column headers
  145.     if SECURITYMATRIX_FLIP_COORDS then
  146.         _G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn.."Text"]:SetText(_G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn]:GetID());
  147.         _G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow.."Text"]:SetText(SecurityMatrix_Alphabet[_G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow]:GetID()]);
  148.     else
  149.         _G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow.."Text"]:SetText(_G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow]:GetID());
  150.         _G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn.."Text"]:SetText(SecurityMatrix_Alphabet[_G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn]:GetID()]);
  151.     end
  152.    
  153.     --set the new row/column
  154.     SecurityMatrix_currentRow = row;
  155.     SecurityMatrix_currentColumn = column;
  156.    
  157.     --turn on the sparkle on the new cell
  158.     _G["SecurityMatrixFrameElementSparkle"..SecurityMatrix_currentRow.."_"..SecurityMatrix_currentColumn.."Highlight"]:Show();
  159.     _G["SecurityMatrixFrameElementSparkle"..SecurityMatrix_currentRow.."_"..SecurityMatrix_currentColumn.."Texture"]:Show();
  160.    
  161.     --turn on the text highlight on the new row/column headers
  162.     if SECURITYMATRIX_FLIP_COORDS then
  163.         _G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn.."Text"]:SetText("|cFF00FF00".._G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn]:GetID().."|r");
  164.         _G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow.."Text"]:SetText("|cFF00FF00"..SecurityMatrix_Alphabet[_G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow]:GetID()].."|r");
  165.     else
  166.         _G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow.."Text"]:SetText("|cFF00FF00".._G["SecurityMatrixFrameRowHeader"..SecurityMatrix_currentRow]:GetID().."|r");
  167.         _G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn.."Text"]:SetText("|cFF00FF00"..SecurityMatrix_Alphabet[_G["SecurityMatrixFrameColumnHeader"..SecurityMatrix_currentColumn]:GetID()].."|r");
  168.     end
  169.    
  170.     --set the direction text to mention the new cell
  171.     if SECURITYMATRIX_FLIP_COORDS then
  172.         SecurityMatrixKeypadDirections:SetText(string.format(SECURITYMATRIX_ENTER_CELL, SecurityMatrix_Alphabet[SecurityMatrix_currentRow], SecurityMatrix_currentColumn));
  173.     else
  174.         SecurityMatrixKeypadDirections:SetText(string.format(SECURITYMATRIX_ENTER_CELL, SecurityMatrix_Alphabet[SecurityMatrix_currentColumn], SecurityMatrix_currentRow));
  175.     end
  176.    
  177.     --set a flag so the update function knows we are just starting a move
  178.     SecurityMatrix_startMoving = true;
  179. end
  180.  
  181. function SecurityMatrix_GetNewCoordinates()
  182.     --get the next set of coordinates
  183.     local notDone, x, y = GetMatrixCoordinates();
  184.     --if we are done entering numbers then hide the matrix
  185.     if(not notDone) then
  186.         SecurityMatrixLoginFrame:Hide();
  187.         return;
  188.     end
  189.     --move to the next set of coordinates
  190.     SecurityMatrix_NewCoordinate(y + 1, x + 1);
  191.     --enable the rotating buttons
  192.     SecurityMatrixPinwheel_EnableNumbers();
  193. end
  194.  
  195. function SecurityMatrix_ButtonClick(self)
  196.     -- Don't allow too many digits
  197.     if(SECURITYMATRIX_TEXT_LENGTH >= SECURITYMATRIX_NUM_MAX_DIGITS) then return end
  198.  
  199.     --show another star to the user
  200.     SecurityMatrix_SetShownLength(SECURITYMATRIX_TEXT_LENGTH+1)
  201.     -- If we have enough digits, enable the Ok button
  202.     if(SECURITYMATRIX_TEXT_LENGTH >= SECURITYMATRIX_NUM_MIN_DIGITS) then
  203.         --enable the OK button if we have both digits
  204.         SecurityMatrixKeypadButtonOK:Enable();
  205.     end
  206.    
  207.     -- If we've hit the max, disable the inputs
  208.     if(SECURITYMATRIX_TEXT_LENGTH >= SECURITYMATRIX_NUM_MAX_DIGITS) then
  209.         --disable the rotating buttons so the user doesn't enter more
  210.         SecurityMatrixPinwheel_DisableNumbers();
  211.     end
  212.    
  213.     -- Send the number to the client
  214.     MatrixEntered(self:GetID());
  215.     --enable the clear button if it's not already
  216.     SecurityMatrixKeypadButtonClear:Enable();
  217. end
  218.  
  219. function SecurityMatrix_OKClick()
  220.     --don't move on to the next coordinate if this one is not filled in
  221.     if(SECURITYMATRIX_TEXT_LENGTH < SECURITYMATRIX_NUM_MIN_DIGITS) then return; end
  222.     --clear the *s
  223.     SecurityMatrix_SetShownLength(0)
  224.     --enter the coordinates
  225.     MatrixCommit();
  226.     SecurityMatrix_GetNewCoordinates();
  227.     --disable the OK button until we have two digits from the user
  228.     SecurityMatrixKeypadButtonOK:Disable();
  229.     SecurityMatrixKeypadButtonClear:Disable();
  230. end
  231.  
  232. function SecurityMatrix_ClearClick()
  233.     MatrixRevert();
  234.     --hide the current cell *s
  235.     SecurityMatrix_SetShownLength(0)
  236.     --disable the clear and OK buttons
  237.     SecurityMatrixKeypadButtonClear:Disable();
  238.     SecurityMatrixKeypadButtonOK:Disable();
  239.     --enable the rotating buttons
  240.     SecurityMatrixPinwheel_EnableNumbers();
  241. end
  242.  
  243. function SecurityMatrix_SetShownLength(length)
  244.     SecurityMatrixKeypadEntryDigits:SetText(string.rep('*', length))
  245.     SECURITYMATRIX_TEXT_LENGTH = length
  246. end
  247.  
  248. function SecurityMatrix_OnLoad()
  249.     SecurityMatrixFrame.timeSinceLastUpdate = 0;
  250.     SecurityMatrix_CreateElements();
  251.     SecurityMatrix_CreateHeaders();
  252.    
  253.     SecurityMatrixFrameHorizontalHighlightSlider:SetWidth((SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)*(SECURITYMATRIX_NUM_COLUMNS+1) + (SECURITYMATRIX_HIGHLIGHT_OVERHANG + SECURITYMATRIX_GRID_OVERLAP));
  254.     SecurityMatrixFrameHorizontalHighlightSlider:SetHeight(SECURITYMATRIX_GRID_SIZE+SECURITYMATRIX_HIGHLIGHT_OVERHANG*2);
  255.     SecurityMatrixFrameVerticalHighlightSlider:SetHeight((SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)*(SECURITYMATRIX_NUM_ROWS+1) + (SECURITYMATRIX_HIGHLIGHT_OVERHANG + SECURITYMATRIX_GRID_OVERLAP));
  256.     SecurityMatrixFrameVerticalHighlightSlider:SetWidth(SECURITYMATRIX_GRID_SIZE+SECURITYMATRIX_HIGHLIGHT_OVERHANG*2);
  257.     SecurityMatrixFrame:SetWidth((SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)*(SECURITYMATRIX_NUM_COLUMNS+1) + (SECURITYMATRIX_HIGHLIGHT_OVERHANG + SECURITYMATRIX_GRID_OVERLAP));
  258.     SecurityMatrixFrame:SetHeight((SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)*(SECURITYMATRIX_NUM_ROWS+1) + (SECURITYMATRIX_HIGHLIGHT_OVERHANG + SECURITYMATRIX_GRID_OVERLAP));
  259. end
  260.  
  261. function SecurityMatrixLoginFrame_OnLoad()
  262.     SecurityMatrixLoginFrame:RegisterEvent("PLAYER_ENTER_MATRIX");
  263.     SecurityMatrixLoginFrame:EnableKeyboard(true);
  264.    
  265.     SecurityMatrixKeypadDirections:SetPoint("TOPLEFT", SecurityMatrixFrame, "TOPRIGHT", 0, 16);
  266.     SecurityMatrixKeypadDirections:SetPoint("BOTTOMRIGHT", SecurityMatrixKeypadFrame, "TOPRIGHT", 0, 4);
  267.    
  268.     SecurityMatrixLoginFrame:SetWidth(SecurityMatrixFrame:GetWidth() + SecurityMatrixKeypadFrame:GetWidth() + 16);
  269.     SecurityMatrixLoginFrame:SetHeight(math.max(SecurityMatrixFrame:GetHeight(), SecurityMatrixKeypadFrame:GetHeight() + SecurityMatrixKeypadDirections:GetHeight()) + 58);
  270.    
  271.     SecurityMatrixKeypadButtonOK:Disable();
  272.     SecurityMatrixKeypadButtonClear:Disable();
  273. end
  274.  
  275. function SecurityMatrixLoginFrame_Adjust()
  276.     SecurityMatrixKeypadDirections:SetWidth(SecurityMatrixKeypadFrame:GetWidth())
  277.     SecurityMatrixLoginFrame:SetHeight(math.max(SecurityMatrixFrame:GetHeight(), SecurityMatrixKeypadFrame:GetHeight() + SecurityMatrixKeypadDirections:GetHeight()) + 58);
  278. end
  279.  
  280.  
  281. function SecurityMatrix_Cleanup()
  282.     SecurityMatrix_HideHeaders();
  283.     SecurityMatrix_HideElements();
  284. end
  285.  
  286. function SecurityMatrixLoginFrame_OnEvent(event, height, width, minDigits, maxDigits, flipCoords)
  287.     if(event == "PLAYER_ENTER_MATRIX") then
  288.         SecurityMatrix_Cleanup();
  289.         SECURITYMATRIX_NUM_COLUMNS = height;
  290.         SECURITYMATRIX_NUM_ROWS = width;
  291.         SECURITYMATRIX_NUM_MIN_DIGITS = minDigits;
  292.         SECURITYMATRIX_NUM_MAX_DIGITS = maxDigits;
  293.         SECURITYMATRIX_FLIP_COORDS = flipCoords
  294.         SecurityMatrix_OnLoad();
  295.         SecurityMatrixLoginFrame_OnLoad();
  296.         SecurityMatrix_GetNewCoordinates();
  297.         SecurityMatrixLoginFrame_Adjust();
  298.         SecurityMatrixLoginFrame:Show();
  299.     end
  300. end
  301.  
  302. function SecurityMatrix_OnUpdateFade(self, elapsed)
  303.     --don't do anything if the security matrix isn't currently fading in
  304.     if(not SecurityMatrix_isMoving) then
  305.         self.timeSinceLastUpdate = 0;
  306.         return;
  307.     end
  308.    
  309.     --if this is the first run then setup the highlights
  310.     if(SecurityMatrix_startMoving) then
  311.         --move the highlight bars to the appropriate location and fade them all the way out
  312.         SecurityMatrixFrameHorizontalHighlightSlider:SetPoint("TOPLEFT", 0, -((SecurityMatrix_currentRow)*(SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)-SECURITYMATRIX_HIGHLIGHT_OVERHANG));
  313.         SecurityMatrixFrameVerticalHighlightSlider:SetPoint("TOPLEFT", ((SecurityMatrix_currentColumn)*(SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)-SECURITYMATRIX_HIGHLIGHT_OVERHANG), 0);
  314.         SecurityMatrixFrameHorizontalHighlightSlider:SetAlpha(0.0);
  315.         SecurityMatrixFrameVerticalHighlightSlider:SetAlpha(0.0);
  316.         SecurityMatrix_startMoving = false;
  317.     end
  318.    
  319.     --update the time since our last update
  320.     self.timeSinceLastUpdate = self.timeSinceLastUpdate + elapsed;
  321.     --keep the fading frame rate independant, increasing 1% every update
  322.     while(self.timeSinceLastUpdate > SecurityMatrix_updateSpeed) do
  323.         if(SecurityMatrixFrameVerticalHighlightSlider:GetAlpha() ~= 1.0) then
  324.             SecurityMatrixFrameVerticalHighlightSlider:SetAlpha(SecurityMatrixFrameVerticalHighlightSlider:GetAlpha() + 0.01);
  325.         elseif(SecurityMatrixFrameHorizontalHighlightSlider:GetAlpha() ~= 1.0) then
  326.             SecurityMatrixFrameHorizontalHighlightSlider:SetAlpha(SecurityMatrixFrameHorizontalHighlightSlider:GetAlpha() + 0.01);
  327.         else
  328.             SecurityMatrix_isMoving = false;
  329.         end
  330.         self.timeSinceLastUpdate = self.timeSinceLastUpdate - SecurityMatrix_updateSpeed;
  331.     end
  332. end
  333.  
  334. function SecurityMatrix_OnUpdateSlide(self, elapsed)
  335.     --don't do anything if the security matrix isn't currently moving
  336.     if(not SecurityMatrix_isMoving) then
  337.         self.timeSinceLastUpdate = 0;
  338.         return;
  339.     end
  340.    
  341.     --if this is the first run then setup the slider
  342.     if(SecurityMatrix_startMoving) then
  343.         --set the new row/column goal coordinates (so we don't have to keep calculating them over and over)
  344.         SecurityMatrixFrame.goalHorizontalOffset = -((SecurityMatrix_currentRow)*(SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)-SECURITYMATRIX_HIGHLIGHT_OVERHANG);
  345.         SecurityMatrixFrame.goalVerticalOffset = ((SecurityMatrix_currentColumn)*(SECURITYMATRIX_GRID_SIZE-SECURITYMATRIX_GRID_OVERLAP)-SECURITYMATRIX_HIGHLIGHT_OVERHANG);
  346.         SecurityMatrix_startMoving = false;
  347.     end
  348.    
  349.     --make the sliders visible, otherwise the fade code will make the sliders invisible
  350.     SecurityMatrixFrameHorizontalHighlightSlider:SetAlpha(1.0);
  351.     SecurityMatrixFrameVerticalHighlightSlider:SetAlpha(1.0);
  352.    
  353.     --update the time since our last update
  354.     self.timeSinceLastUpdate = self.timeSinceLastUpdate + elapsed;
  355.     --keep the animation frame rate independant moving every 0.01 seconds
  356.     while(self.timeSinceLastUpdate > SecurityMatrix_updateSpeed) do
  357.         --get the current yOffset for the horizontal highlight
  358.         horizontalPoint, horizontalRelativeTo, horizontalRelativePoint, horizontalXOfs, horizontalYOfs = SecurityMatrixFrameHorizontalHighlightSlider:GetPoint(1)
  359.         --fix the floating point errors in WoW UI coordinates
  360.         horizontalYOfs = floor(horizontalYOfs+0.5);
  361.         --if the horizontal highlight is below the target row then move it up
  362.         if(horizontalYOfs < self.goalHorizontalOffset) then
  363.             SecurityMatrixFrameHorizontalHighlightSlider:ClearAllPoints();
  364.             SecurityMatrixFrameHorizontalHighlightSlider:SetPoint("TOPLEFT", 0, horizontalYOfs + 1);
  365.         --if the horizontal highlight is above the target row then move it down
  366.         elseif(horizontalYOfs > self.goalHorizontalOffset) then
  367.             SecurityMatrixFrameHorizontalHighlightSlider:ClearAllPoints();
  368.             SecurityMatrixFrameHorizontalHighlightSlider:SetPoint("TOPLEFT", 0, horizontalYOfs - 1);
  369.         end
  370.        
  371.         --get the current yOffset for the horizontal highlight
  372.         verticalPoint, verticalRelativeTo, verticalRelativePoint, verticalXOfs, verticalYOfs = SecurityMatrixFrameVerticalHighlightSlider:GetPoint(1)
  373.         --fix the floating point errors in WoW UI coordinates
  374.         verticalXOfs = floor(verticalXOfs+0.5);
  375.         --if the vertical highlight is below the target row then move it up
  376.         if(verticalXOfs+0.5 < self.goalVerticalOffset) then
  377.             SecurityMatrixFrameVerticalHighlightSlider:ClearAllPoints();
  378.             SecurityMatrixFrameVerticalHighlightSlider:SetPoint("TOPLEFT", verticalXOfs + 1, 0);
  379.         --if the vertical highlight is above the target row then move it down
  380.         elseif(verticalXOfs > self.goalVerticalOffset) then
  381.             SecurityMatrixFrameVerticalHighlightSlider:ClearAllPoints();
  382.             SecurityMatrixFrameVerticalHighlightSlider:SetPoint("TOPLEFT", verticalXOfs - 1, 0);
  383.         end
  384.        
  385.         --check to see if we are done moving
  386.         if(verticalXOfs == self.goalVerticalOffset and horizontalYOfs == self.goalHorizontalOffset) then
  387.             SecurityMatrix_isMoving = false;
  388.         end
  389.        
  390.         --we are done with this update frame, go on to the next
  391.         self.timeSinceLastUpdate = self.timeSinceLastUpdate - SecurityMatrix_updateSpeed;
  392.     end
  393. end
  394.  
  395. function SecurityMatrixPinwheel_OnLoad(self)
  396.     self.angle = 36 * self:GetID();
  397.     self.timeSinceLastUpdate = 0;
  398.     self:SetWidth(SECURITYMATRIX_PINWHEEL_BUTTON_SIZE);
  399.     self:SetHeight(SECURITYMATRIX_PINWHEEL_BUTTON_SIZE);
  400.     self:SetPoint("CENTER", SecurityMatrixKeypadFrame, "CENTER", (-(SECURITYMATRIX_PINWHEEL_BUTTON_SIZE*2) * math.cos(self.angle * (math.pi/180))), (15+(SECURITYMATRIX_PINWHEEL_BUTTON_SIZE*2) * math.sin(self.angle * (math.pi/180))));
  401. end
  402.  
  403. function SecurityMatrixPinwheel_OnShow(self)
  404.     self.stopSpinning = false;
  405. end
  406.  
  407. function SecurityMatrixPinwheel_OnHide(self)
  408.     self.stopSpinning = true;
  409. end
  410.  
  411. function SecurityMatrixPinwheel_OnUpdate(self, elapsed)
  412.     if(self.stopSpinning) then
  413.         self.timeSinceLastUpdate = 0;
  414.         return;
  415.     end
  416.    
  417.     local cursorX, cursorY = GetCursorPosition(SecurityMatrixKeypadFrame);
  418.     local centerX, centerY = SecurityMatrixKeypadFrame:GetCenter();
  419.     xOffset = cursorX - centerX;
  420.     yOffset = cursorY - centerY - SECURITYMATRIX_PINWHEEL_VERTICAL_OFFSET;
  421.     distance = math.sqrt(xOffset*xOffset + yOffset*yOffset);
  422.    
  423.     self.timeSinceLastUpdate = self.timeSinceLastUpdate + elapsed;
  424.     while(self.timeSinceLastUpdate > 0.01) do
  425.         self.timeSinceLastUpdate = self.timeSinceLastUpdate - 0.01;
  426.         if(SecurityMatrixKeypadFrame.superSpin) then
  427.             self.angle = self.angle + 3;
  428.         else
  429.             self.angle = self.angle + (distance - SECURITYMATRIX_PINWHEEL_BUTTON_SIZE*2)/100;
  430.         end
  431.         if(self.angle > 360) then
  432.             self.angle = self.angle-360;
  433.         end
  434.         self:ClearAllPoints();
  435.         self:SetPoint("CENTER", SecurityMatrixKeypadFrame, "CENTER", (-(SECURITYMATRIX_PINWHEEL_BUTTON_SIZE*2) * math.cos(self.angle * (math.pi/180))), (SECURITYMATRIX_PINWHEEL_VERTICAL_OFFSET+(SECURITYMATRIX_PINWHEEL_BUTTON_SIZE*2) * math.sin(self.angle * (math.pi/180))));
  436.     end
  437. end
  438.  
  439. function SecurityMatrixPinwheel_HideNumbers()
  440.     for i=0, 9, 1 do
  441.         button = _G["SecurityMatrixPinwheelButton"..i];
  442.         button:SetText("");
  443.         button.stopSpinning = true;
  444.     end
  445. end
  446.  
  447. function SecurityMatrixPinwheel_ShowNumbers()
  448.     for i=0, 9, 1 do
  449.         button = _G["SecurityMatrixPinwheelButton"..i];
  450.         button:SetText(i);
  451.         button.stopSpinning = false;
  452.     end
  453. end
  454.  
  455. function SecurityMatrixPinwheel_EnableNumbers()
  456.     for i=0, 9, 1 do
  457.         button = _G["SecurityMatrixPinwheelButton"..i];
  458.         button:Enable();
  459.     end
  460. end
  461.  
  462. function SecurityMatrixPinwheel_DisableNumbers()
  463.     for i=0, 9, 1 do
  464.         button = _G["SecurityMatrixPinwheelButton"..i];
  465.         button:Disable();
  466.     end
  467. end
Advertisement
Add Comment
Please, Sign In to add comment