Advertisement
Guest User

Spells.lua

a guest
Aug 17th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.18 KB | None | 0 0
  1. -- Spells.lua
  2.  
  3. -- Adds a spell predicter to aceconfig.  This work is from AceGUI-3.0-Spell-EditBox
  4. -- changed to a non lib to work in my addon.
  5. -- Further modifications were done.
  6. -- This version returns the Name and SpellID
  7. -------------------------------------------------------------------------------
  8. -- GUB   shared data table between all parts of the addon
  9. -------------------------------------------------------------------------------
  10. local MyAddon, GUB = ...
  11. local Main = GUB.Main
  12.  
  13. local AceGUI = LibStub('AceGUI-3.0')
  14.  
  15. -- localize some globals.
  16. local GetSpellInfo, SPELL_PASSIVE, pairs, type, CreateFrame, select, floor, strlower, strmatch, format, tinsert, print =
  17.       GetSpellInfo, SPELL_PASSIVE, pairs, type, CreateFrame, select, floor, strlower, strmatch, format, tinsert, print
  18. local table, GameTooltip, ClearOverrideBindings, SetOverrideBindingClick, GetCursorInfo, GetSpellBookItemName =
  19.       table, GameTooltip, ClearOverrideBindings, SetOverrideBindingClick, GetCursorInfo, GetSpellBookItemName
  20. local ClearCursor, GameTooltip, UIParent, GameFontHighlight, GameFontNormal, ChatFontNormal, OKAY =
  21.       ClearCursor, GameTooltip, UIParent, GameFontHighlight, GameFontNormal, ChatFontNormal, OKAY
  22.  
  23. -------------------------------------------------------------------------------
  24. -- Locals
  25. --
  26. -- SpellList         Contains a list of loaded spells used in the editbox.
  27. -- SpellsLoaded      if true then spells are already loaded.
  28. -- SpellsPerRun      Amount of spells to load at one time.
  29. -- Predictorlines    Amount of lines the predictor uses.
  30. -- Predictors        Table that keeps track of predictor frames.
  31. --                   The keyname is the Frame and the value is true or nil
  32. -------------------------------------------------------------------------------
  33. local SpellsTPS = 0.10 -- 10 times per second.
  34. local SpellsPerRun = 1000
  35. local SpellsLoaded = false
  36. local Tooltip = nil
  37. local HyperLinkSt = 'spell:%s'
  38.  
  39. local PredictorLines = 20
  40. local EditBoxWidgetVersion = 1
  41. local AuraEditBoxWidgetVersion = 1
  42.  
  43. local EditBoxWidgetType = 'GUB_Predictor_Base'
  44. local AuraEditBoxWidgetType = 'GUB_Aura_EditBox'
  45.  
  46. local SpellsTimer = {}
  47. local SpellList = {}
  48. local Predictors = {}
  49. local SpellFilterCache = {}
  50.  
  51. local PredictorBackdrop = {
  52.   bgFile   = [[Interface\ChatFrame\ChatFrameBackground]],
  53.   edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]],
  54.   edgeSize = 26,
  55.   insets = {
  56.     left = 9 ,
  57.     right = 9,
  58.     top = 9,
  59.     bottom = 9
  60.   }
  61. }
  62.  
  63. --*****************************************************************************
  64. --
  65. -- Spell utility
  66. --
  67. --*****************************************************************************
  68.  
  69. -------------------------------------------------------------------------------
  70. -- RegisterSpellPredictor
  71. --
  72. -- Frame    Frame that will contain the predicted spells
  73. -------------------------------------------------------------------------------
  74. local function RegisterSpellPredictor(Frame)
  75.   Predictors[Frame] = true
  76. end
  77.  
  78. -------------------------------------------------------------------------------
  79. -- UnegisterSpellPredictor
  80. --
  81. -- Frame    Frame that will no longer contain the predicted spells
  82. -------------------------------------------------------------------------------
  83. local function UnregisterSpellPredictor(Frame)
  84.   Predictors[Frame] = nil
  85. end
  86.  
  87. -------------------------------------------------------------------------------
  88. -- LoadSpells
  89. --
  90. -- Loads spells just once.  This is used for the predictor.
  91. -------------------------------------------------------------------------------
  92. local function LoadSpells()
  93.   if not SpellsLoaded then
  94.     local TotalInvalid = 0
  95.     local CurrentIndex = 0
  96.     local NumSpells = 0
  97.  
  98.     local Exclude = {
  99.       ['interface\\icons\\trade_alchemy'] = true,
  100.       ['interface\\icons\\trade_blacksmithing'] = true,
  101.       ['interface\\icons\\trade_brewpoison'] = true,
  102.       ['interface\\icons\\trade_engineering'] = true,
  103.       ['interface\\icons\\trade_engraving'] = true,
  104.       ['interface\\icons\\trade_fishing'] = true,
  105.       ['interface\\icons\\trade_herbalism'] = true,
  106.       ['interface\\icons\\trade_leatherworking'] = true,
  107.       ['interface\\icons\\trade_mining'] = true,
  108.       ['interface\\icons\\trade_tailoring'] = true,
  109.       ['interface\\icons\\temp'] = true,
  110.     }
  111.  
  112.     local ScanTooltip = CreateFrame('GameTooltip')
  113.  
  114.     ScanTooltip:SetOwner(UIParent, 'ANCHOR_NONE')
  115.     for i = 1, 6 do
  116.       ScanTooltip['TextLeft' .. i] = ScanTooltip:CreateFontString()
  117.       ScanTooltip['TextRight' .. i] = ScanTooltip:CreateFontString()
  118.       ScanTooltip:AddFontStrings(ScanTooltip['TextLeft' .. i], ScanTooltip['TextRight' .. i])
  119.     end
  120.  
  121.     local function LoadSpells(self)
  122.  
  123.       -- 5,000 invalid spells in a row means it's a safe assumption that there are no more spells to query
  124.       if TotalInvalid >= 5000 then
  125.         Main:SetTimer(self, nil)
  126.         return
  127.       end
  128.  
  129.       -- Load as many spells in
  130.       for SpellID = CurrentIndex + 1, CurrentIndex + SpellsPerRun do
  131.         local Name, SubName, Icon = GetSpellInfo(SpellID)
  132.         local IsAura = false
  133.  
  134.         -- Pretty much every profession spell uses Trade_* and 99% of the random spells use the Trade_Engineering icon
  135.         -- we can safely exclude any of these spells as they are not needed. Can get away with this because things like
  136.         -- Alchemy use two icons, the Trade_* for the actual crafted spell and a different icon for the actual buff
  137.         -- Passive spells have no use as well, since they are well passive and can't actually be used
  138.         if Name and Name ~= '' and Exclude[strlower(Icon)] == nil and SubName ~= SPELL_PASSIVE then
  139.  
  140.           -- Scan tooltip for debuff/buff
  141.           ScanTooltip:SetHyperlink(format(HyperLinkSt, SpellID))
  142.  
  143.           IsAura = true
  144.           for i = 1, ScanTooltip:NumLines() do
  145.             local Text = ScanTooltip['TextLeft' .. i]
  146.  
  147.             if Text and false then
  148.               local r, g, b = Text:GetTextColor()
  149.  
  150.               r = floor(r + 0.10)
  151.               g = floor(g + 0.10)
  152.               b = floor(b + 0.10)
  153.  
  154.               -- Gold first text, it's a profession link
  155.               -- If first line is not white then reject it.
  156.               if i == 1 and (r ~= 1 or g ~= 1 or b ~= 1) then
  157.                 break
  158.  
  159.               -- Gold for anything else and it should be a valid aura
  160.               -- line 2 or after is not white except it.
  161.               elseif r ~= 1 or g ~= 1 or b ~= 1 then
  162.                 IsAura = true
  163.                 break
  164.               end
  165.             end
  166.           end
  167.         end
  168.  
  169.         if IsAura then
  170.           NumSpells = NumSpells + 1
  171.           SpellList[SpellID] = strlower(Name)
  172.  
  173.           TotalInvalid = 0
  174.         else
  175.           TotalInvalid = TotalInvalid + 1
  176.         end
  177.       end
  178.  
  179.       -- Every ~1 second it will update any visible predictors to make up for the fact that the data is delay loaded
  180.       if CurrentIndex % 5000 == 0 then
  181.         for Frame in pairs(Predictors) do
  182.           if Frame:IsVisible() then
  183.             Frame:PopulatePredictor()
  184.           end
  185.         end
  186.       end
  187.  
  188.       -- Increment and do it all over!
  189.       CurrentIndex = CurrentIndex + SpellsPerRun
  190.     end
  191.  
  192.     Main:SetTimer(SpellsTimer, LoadSpells, SpellsTPS)
  193.     SpellsLoaded = true
  194.   end
  195. end
  196.  
  197. --*****************************************************************************
  198. --
  199. -- Editbox for the predictor
  200. --
  201. --*****************************************************************************
  202.  
  203. ------------------------------------------------------------------------------
  204. -- OnAcquire
  205. --
  206. -- Gets called after a new widget is created or reused.
  207. ------------------------------------------------------------------------------
  208. local function OnAcquire(self)
  209.   self:SetHeight(26)
  210.   self:SetWidth(200)
  211.   self:SetDisabled(false)
  212.   self:SetLabel()
  213.   self.showButton = true
  214.  
  215.   RegisterSpellPredictor(self.PredictFrame)
  216.   LoadSpells()
  217. end
  218.  
  219. ------------------------------------------------------------------------------
  220. -- OnRelease
  221. --
  222. -- Gets called when the widget is released
  223. ------------------------------------------------------------------------------
  224. local function OnRelease(self)
  225.   self.frame:ClearAllPoints()
  226.   self.frame:Hide()
  227.   self.PredictFrame:Hide()
  228.   self.SpellFilter = nil
  229.  
  230.   self:SetDisabled(false)
  231.  
  232.   UnregisterSpellPredictor(self.PredictFrame)
  233. end
  234.  
  235. -------------------------------------------------------------------------------
  236. -- EditBoxOnEnter
  237. --
  238. -- Gets called when the mouse enters the edit box.
  239. -------------------------------------------------------------------------------
  240. local function EditBoxOnEnter(self)
  241.   self.Object:Fire('OnEnter')
  242. end
  243.  
  244. -------------------------------------------------------------------------------
  245. -- EditBoxOnLeave
  246. --
  247. -- Gets called when the mouse enters the edit box.
  248. -------------------------------------------------------------------------------
  249. local function EditBoxOnLeave(self)
  250.   self.Object:Fire('OnLeave')
  251. end
  252.  
  253. -------------------------------------------------------------------------------
  254. -- PopulatePredictorFrame
  255. --
  256. -- Populates the predictorframe using a SpellList table and SearchSt
  257. --
  258. -- Type    Type of spelllist
  259. --            'spells'   Came from SpellList
  260. --            'auras'  Came from TrackedAurasList
  261. -------------------------------------------------------------------------------
  262.  
  263. -------------------------------------------------------------------------------
  264. -- AddPredictorButton
  265. --
  266. -- Adds a button to the predictor frame
  267. --
  268. -- ActiveButton    Button position to add one at.
  269. -- FormatText      Format string
  270. -- SpellID         SpellID to add to button
  271. -------------------------------------------------------------------------------
  272. local function AddPredictorButton(self, ActiveButton, FormatText, SpellID)
  273.  
  274.   -- Ran out of text to suggest :<
  275.   local Button = self.Buttons[ActiveButton]
  276.   local Name, _, Icon = GetSpellInfo(SpellID)
  277.  
  278.   Button:SetFormattedText(FormatText, Icon, Name)
  279.   Button.SpellID = SpellID
  280.   Button:Show()
  281.  
  282.   -- Highlight if needed
  283.   if ActiveButton ~= self.SelectedButton then
  284.     Button:UnlockHighlight()
  285.  
  286.     if GameTooltip:IsOwned(Button) then
  287.       GameTooltip:Hide()
  288.     end
  289.   end
  290. end
  291.  
  292. -------------------------------------------------------------------------------
  293. -- PopulatePredictor
  294. --
  295. -- Populates the predictor with a list of spells matching the spell name entered.
  296. -------------------------------------------------------------------------------
  297. local function PopulatePredictor(self)
  298.   local Object = self.Object
  299.   local SearchSt = '^' .. strlower(Object.EditBox:GetText())
  300.   local TrackedAurasList = Main.TrackedAurasList
  301.   local ActiveButtons = 0
  302.  
  303.   for _, Button in pairs(self.Buttons) do
  304.     Button:Hide()
  305.   end
  306.  
  307.   -- Do auras
  308.   if TrackedAurasList then
  309.     for SpellID, _ in pairs(TrackedAurasList) do
  310.       local Name = strlower(GetSpellInfo(SpellID))
  311.  
  312.       if strmatch(Name, SearchSt) then
  313.         if ActiveButtons < PredictorLines then
  314.           ActiveButtons = ActiveButtons + 1
  315.           AddPredictorButton(self, ActiveButtons, '|T%s:15:15:2:11|t |cFFFFFFFF%s|r', SpellID)
  316.         else
  317.           break
  318.         end
  319.       end
  320.     end
  321.   end
  322.  
  323.   -- Do SpellList
  324.   for SpellID, Name in pairs(SpellList) do
  325.     if strmatch(Name, SearchSt) then
  326.       local Found = TrackedAurasList and TrackedAurasList[SpellID] or nil
  327.  
  328.       if Found == nil then
  329.         if ActiveButtons < PredictorLines then
  330.           ActiveButtons = ActiveButtons + 1
  331.           AddPredictorButton(self, ActiveButtons, '|T%s:15:15:2:11|t %s', SpellID)
  332.         else
  333.           break
  334.         end
  335.       end
  336.     end
  337.   end
  338.  
  339.   if ActiveButtons > 0 then
  340.     self:SetHeight(15 + ActiveButtons * 17)
  341.     self:Show()
  342.   else
  343.     self:Hide()
  344.   end
  345.  
  346.   self.ActiveButtons = ActiveButtons
  347. end
  348.  
  349. -------------------------------------------------------------------------------
  350. -- PredictorShowButton
  351. --
  352. -- Shows a button in the editbox selector
  353. -------------------------------------------------------------------------------
  354. local function PredictorShowButton(self)
  355.   if self.LastText ~= '' then
  356.     self.PredictFrame.SelectedButton = nil
  357.     PopulatePredictor(self.PredictFrame)
  358.   else
  359.     self.PredictFrame:Hide()
  360.   end
  361.  
  362.   if self.showButton then
  363.     self.Button:Show()
  364.     self.EditBox:SetTextInsets(0, 20, 3, 3)
  365.   end
  366. end
  367.  
  368. -------------------------------------------------------------------------------
  369. -- PredictorHideButton
  370. --
  371. -- Hides a button in the editbox selector
  372. -------------------------------------------------------------------------------
  373. local function PredictorHideButton(self)
  374.   self.Button:Hide()
  375.   self.EditBox:SetTextInsets(0, 0, 3, 3)
  376.  
  377.   self.PredictFrame.SelectedButton = nil
  378.   self.PredictFrame:Hide()
  379. end
  380.  
  381. -------------------------------------------------------------------------------
  382. -- PredictorOnHide
  383. --
  384. -- Hides the predictor editbox and restores binds, tooltips
  385. -------------------------------------------------------------------------------
  386. local function PredictorOnHide(self)
  387.  
  388.   -- Allow users to use arrows to go back and forth again without the fix
  389.   self.Object.EditBox:SetAltArrowKeyMode(false)
  390.  
  391.   -- Make sure the tooltip isn't kept open if one of the buttons was using it
  392.   for _, Button in pairs(self.Buttons) do
  393.     if GameTooltip:IsOwned(Button) then
  394.       GameTooltip:Hide()
  395.     end
  396.   end
  397.  
  398.   -- Reset all bindings set on this predictor
  399.   ClearOverrideBindings(self)
  400. end
  401.  
  402. -------------------------------------------------------------------------------
  403. -- EditBoxOnEnterPressed
  404. --
  405. -- Gets called when something is entered into the edit box
  406. -------------------------------------------------------------------------------
  407. local function EditBoxOnEnterPressed(self)
  408.   local Object = self.Object
  409.  
  410.   -- Something is selected in the predictor, use that value instead of whatever is in the input box
  411.   if Object.PredictFrame.SelectedButton then
  412.     Object.PredictFrame.Buttons[Object.PredictFrame.SelectedButton]:Click()
  413.     return
  414.   end
  415.  
  416.   local cancel = Object:Fire('OnEnterPressed', self:GetText())
  417.   if not cancel then
  418.     PredictorHideButton(Object)
  419.   end
  420.  
  421.   -- Reactive the cursor, odds are if someone is adding spells they are adding more than one
  422.   -- and if they aren't, it can't hurt anyway.
  423.   -- Object.EditBox:SetFocus()
  424. end
  425.  
  426. -------------------------------------------------------------------------------
  427. -- EditBoxOnEscapePressed
  428. --
  429. -- Gets called when esckey is pressed which clears the focus
  430. -------------------------------------------------------------------------------
  431. local function EditBoxOnEscapePressed(self)
  432.   self:ClearFocus()
  433. end
  434.  
  435. -------------------------------------------------------------------------------
  436. -- EditBoxFixCursorPosition
  437. --
  438. -- When using SetAltArrowKeyMode the ability to move the cursor with left and right arrows is disabled
  439. -- this reenables that so the user doesn't notice anything wrong
  440. -------------------------------------------------------------------------------
  441. local function EditBoxFixCursorPosition(self, Direction)
  442.   self:SetCursorPosition(self:GetCursorPosition() + (Direction == 'RIGHT' and 1 or -1))
  443. end
  444.  
  445. -------------------------------------------------------------------------------
  446. -- EditBoxOnReceiveDrag
  447. --
  448. -- Gets called when a button is selected.
  449. -------------------------------------------------------------------------------
  450. local function EditBoxOnReceiveDrag(self)
  451.   local Object = self.Object
  452.   local Type, ID, Info = GetCursorInfo()
  453.  
  454.   ClearCursor()
  455.  
  456.   PredictorHideButton(Object)
  457.   AceGUI:ClearFocus()
  458. end
  459.  
  460. -------------------------------------------------------------------------------
  461. -- EditBoxOnTextChanged
  462. --
  463. -- Gets called when the text changes in the edit box.
  464. -------------------------------------------------------------------------------
  465. local function EditBoxOnTextChanged(self)
  466.   local Object = self.Object
  467.   local Value = self:GetText()
  468.  
  469.   if Value ~= Object.LastText then
  470.     Object:Fire('OnTextChanged', Value)
  471.     Object.LastText = Value
  472.  
  473.     PredictorShowButton(Object)
  474.   end
  475. end
  476.  
  477. -------------------------------------------------------------------------------
  478. -- EditBoxOnFocusLost
  479. --
  480. -- Gets called when the edit box loses focus
  481. -------------------------------------------------------------------------------
  482. local function EditBoxOnEditFocusLost(self)
  483.   PredictorOnHide(self.Object.PredictFrame)
  484. end
  485.  
  486. -------------------------------------------------------------------------------
  487. -- EditBoxButtonOnclick
  488. --
  489. -- called when the 'edit' button in the edit box is clicked
  490. -------------------------------------------------------------------------------
  491. local function EditBoxButtonOnClick(self)
  492.   EditBoxOnEnterPressed(self.Object.EditBox)
  493. end
  494.  
  495. --*****************************************************************************
  496. --
  497. -- Editbox for the predictor
  498. -- API calls
  499. --
  500. --*****************************************************************************
  501.  
  502. -------------------------------------------------------------------------------
  503. -- EditBoxSetDisabled
  504. --
  505. -- Disables the edit box
  506. -------------------------------------------------------------------------------
  507. local function EditBoxSetDisabled(self, Disabled)
  508.   self.disabled = Disabled
  509.  
  510.   if Disabled then
  511.     self.EditBox:EnableMouse(false)
  512.     self.EditBox:ClearFocus()
  513.     self.EditBox:SetTextColor(0.5, 0.5, 0.5)
  514.     self.Label:SetTextColor(0.5, 0.5, 0.5)
  515.   else
  516.     self.EditBox:EnableMouse(true)
  517.     self.EditBox:SetTextColor(1, 1, 1)
  518.     self.Label:SetTextColor(1, 0.82, 0)
  519.   end
  520. end
  521.  
  522. -------------------------------------------------------------------------------
  523. -- EditBoxSetText
  524. --
  525. -- Changes the text in the edit box
  526. -------------------------------------------------------------------------------
  527. local function EditBoxSetText(self, Text, Cursor)
  528.   self.LastText = Text or ''
  529.   self.EditBox:SetText(self.LastText)
  530.   self.EditBox:SetCursorPosition(Cursor or 0)
  531.  
  532.   PredictorHideButton(self)
  533. end
  534.  
  535. -------------------------------------------------------------------------------
  536. -- EditBoxSetLabel
  537. --
  538. -- Sets the label on the edit box.
  539. -------------------------------------------------------------------------------
  540. local function EditBoxSetLabel(self, Text)
  541.   if Text and Text ~= '' then
  542.     self.Label:SetText(Text)
  543.     self.Label:Show()
  544.     self.EditBox:SetPoint('TOPLEFT', self.frame, 'TOPLEFT', 7, -18)
  545.     self:SetHeight(44)
  546.     self.alignoffset = 30
  547.   else
  548.     self.Label:SetText('')
  549.     self.Label:Hide()
  550.     self.EditBox:SetPoint('TOPLEFT', self.frame, 'TOPLEFT', 7, 0)
  551.     self:SetHeight(26)
  552.     self.alignoffset = 12
  553.   end
  554. end
  555.  
  556. -------------------------------------------------------------------------------
  557. -- PredictorOnMouseDown
  558. --
  559. -- Gets called when the mouse is clicked on the predictor.
  560. -------------------------------------------------------------------------------
  561. local function PredictorOnMouseDown(self, Direction)
  562.  
  563.   -- Fix the cursor positioning if left or right arrow key was used
  564.   if Direction == 'LEFT' or Direction == 'RIGHT' then
  565.     EditBoxFixCursorPosition(self.EditBox, Direction)
  566.   end
  567. end
  568.  
  569. -------------------------------------------------------------------------------
  570. -- PredictorButtonOnClick
  571. --
  572. -- Sets the editbox to the button that was clicked in the selector
  573. -------------------------------------------------------------------------------
  574. local function PredictorButtonOnClick(self)
  575.   local Name = GetSpellInfo(self.SpellID)
  576.  
  577.   EditBoxSetText(self.parent.Object, Name, #Name)
  578.  
  579.   self.parent.SelectedButton = nil
  580.   self.parent.Object:Fire('OnEnterPressed', Name, self.SpellID)
  581. end
  582.  
  583. -------------------------------------------------------------------------------
  584. -- PredictorButtonOnEnter
  585. --
  586. -- Highlights the predictor button when the mouse enters the button area
  587. -------------------------------------------------------------------------------
  588. local function PredictorButtonOnEnter(self)
  589.   self.parent.SelectedButton = nil
  590.   self:LockHighlight()
  591.   local SpellID = self.SpellID
  592.  
  593.   GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 3)
  594.   GameTooltip:SetHyperlink(format(HyperLinkSt, SpellID))
  595.   GameTooltip:AddLine(format('|cFFFFFF00SpellID:|r|cFF00FF00%s|r', SpellID))
  596.  
  597.   -- Need to show to make sure the tooltip surrounds the AddLine text
  598.   -- after SetHyperlink
  599.   GameTooltip:Show()
  600. end
  601.  
  602. -------------------------------------------------------------------------------
  603. -- PredictorButtonOnLeave
  604. --
  605. -- Highlights the predictor button when the mouse enters the button area
  606. -------------------------------------------------------------------------------
  607. local function PredictorButtonOnLeave(self)
  608.   self:UnlockHighlight()
  609.   GameTooltip:Hide()
  610. end
  611.  
  612. -------------------------------------------------------------------------------
  613. -- CreateButton
  614. --
  615. -- Creates a button for the predictor frame.
  616. --
  617. -- PredictFrame       Frame the will contain the buttons
  618. -- EditBox            Reference to the EditBox
  619. -- Index              Button Index, needed for setpoint
  620. --
  621. -- Returns
  622. --   Button           Created buttom.
  623. -------------------------------------------------------------------------------
  624. local function CreateButton(PredictFrame, EditBox, Index)
  625.   local Buttons = PredictFrame.Buttons
  626.   local Button = CreateFrame('Button', nil, PredictFrame)
  627.  
  628.   Button:SetHeight(17)
  629.   Button:SetWidth(1)
  630.   Button:SetPushedTextOffset(-2, 0)
  631.   Button:SetScript('OnClick', PredictorButtonOnClick)
  632.   Button:SetScript('OnEnter', PredictorButtonOnEnter)
  633.   Button:SetScript('OnLeave', PredictorButtonOnLeave)
  634.   Button.parent = PredictFrame
  635.   Button.EditBox = EditBox
  636.   Button:Hide()
  637.  
  638.   if Index > 1 then
  639.     Button:SetPoint('TOPLEFT', Buttons[Index - 1], 'BOTTOMLEFT', 0, 0)
  640.     Button:SetPoint('TOPRIGHT', Buttons[Index - 1], 'BOTTOMRIGHT', 0, 0)
  641.   else
  642.     Button:SetPoint('TOPLEFT', PredictFrame, 8, -8)
  643.     Button:SetPoint('TOPRIGHT', PredictFrame, -7, 0)
  644.   end
  645.  
  646.   -- Create the actual text
  647.   local Text = Button:CreateFontString(nil, 'ARTWORK', 'GameFontNormal')
  648.   Text:SetHeight(1)
  649.   Text:SetWidth(1)
  650.   Text:SetJustifyH('LEFT')
  651.   Text:SetAllPoints(Button)
  652.   Button:SetFontString(Text)
  653.  
  654.   -- Setup the highlighting
  655.   local Texture = Button:CreateTexture(nil, 'ARTWORK')
  656.   Texture:SetTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]])
  657.   Texture:ClearAllPoints()
  658.   Texture:SetPoint('TOPLEFT', Button, 0, -2)
  659.   Texture:SetPoint('BOTTOMRIGHT', Button, 5, 2)
  660.   Texture:SetAlpha(0.70)
  661.  
  662.   Button:SetHighlightTexture(Texture)
  663.   Button:SetHighlightFontObject(GameFontHighlight)
  664.   Button:SetNormalFontObject(GameFontNormal)
  665.  
  666.   return Button
  667. end
  668.  
  669. -------------------------------------------------------------------------------
  670. -- PredictorConstructor
  671. --
  672. -- Creates the widget for the edit box and predictor
  673. -------------------------------------------------------------------------------
  674. local function PredictorConstructor()
  675.   local Frame = CreateFrame('Frame', nil, UIParent)
  676. --local EditBox = CreateFrame('EditBox', 'AceGUI30SpellEditBox' .. Num, Frame, 'InputBoxTemplate')
  677.   local EditBox = CreateFrame('EditBox', nil, Frame, 'InputBoxTemplate')
  678.  
  679.   -- Don't feel like looking up the specific callbacks for when a widget resizes, so going to be creative with SetPoint instead!
  680. --local PredictFrame = CreateFrame('Frame', 'AceGUI30SpellEditBox' .. Num .. 'Predictor', UIParent)
  681.   local PredictFrame = CreateFrame('Frame', nil, UIParent)
  682.   local Buttons = {}
  683.   PredictFrame:SetBackdrop(PredictorBackdrop)
  684.   PredictFrame:SetBackdropColor(0, 0, 0, 0.85)
  685.   PredictFrame:SetWidth(1)
  686.   PredictFrame:SetHeight(150)
  687.   PredictFrame:SetPoint('TOPLEFT', EditBox, 'BOTTOMLEFT', -6, 0)
  688.   PredictFrame:SetPoint('TOPRIGHT', EditBox, 'BOTTOMRIGHT', 0, 0)
  689.   PredictFrame:SetFrameStrata('TOOLTIP')
  690.   PredictFrame:SetClampedToScreen(true)
  691.   PredictFrame.Buttons = {}
  692.   PredictFrame.PopulatePredictor = PopulatePredictor
  693.   PredictFrame.EditBox = EditBox
  694.   PredictFrame.Buttons = Buttons
  695.   PredictFrame:Hide()
  696.  
  697.   -- Create the mass of predictor rows
  698.   for Index = 1, PredictorLines do
  699.     Buttons[Index] = CreateButton(PredictFrame, EditBox, Index)
  700.   end
  701.  
  702.   -- Set the main info things for this thingy
  703.   local self = {}
  704.   self.type = EditBoxWidgetType
  705.   self.frame = Frame
  706.  
  707.   self.OnRelease = OnRelease
  708.   self.OnAcquire = OnAcquire
  709.  
  710.   self.SetDisabled = EditBoxSetDisabled
  711.   self.SetText = EditBoxSetText
  712.   self.SetLabel = EditBoxSetLabel
  713.  
  714.   self.PredictFrame = PredictFrame
  715.   self.EditBox = EditBox
  716.  
  717.   self.alignoffset = 30
  718.  
  719.   Frame:SetHeight(44)
  720.   Frame:SetWidth(200)
  721.  
  722.   Frame.Object = self
  723.   EditBox.Object = self
  724.   PredictFrame.Object = self
  725.  
  726.   -- EditBoxes override the OnKeyUp/OnKeyDown events so that they can function, meaning in order to make up and down
  727.   -- arrow navigation of the menu work, I have to do some trickery with temporary bindings.
  728.   -- This is currently taken out since no one uses a keyboard for dropdowns.
  729.   PredictFrame:SetScript('OnMouseDown', PredictorOnMouseDown)
  730.   PredictFrame:SetScript('OnHide', PredictorOnHide)
  731.   --PredictFrame:SetScript('OnShow', PredictorOnShow)
  732.  
  733.   EditBox:SetScript('OnEnter', EditBoxOnEnter)
  734.   EditBox:SetScript('OnLeave', EditBoxOnLeave)
  735.  
  736.   EditBox:SetAutoFocus(false)
  737.   EditBox:SetFontObject(ChatFontNormal)
  738.   EditBox:SetScript('OnEscapePressed', EditBoxOnEscapePressed)
  739.   EditBox:SetScript('OnEnterPressed', EditBoxOnEnterPressed)
  740.   EditBox:SetScript('OnTextChanged', EditBoxOnTextChanged)
  741.   EditBox:SetScript('OnReceiveDrag', EditBoxOnReceiveDrag)
  742.   EditBox:SetScript('OnMouseDown', EditBoxOnReceiveDrag)
  743.   --EditBox:SetScript('OnEditFocusGained', EditBoxOnEditFocusGained)
  744.   EditBox:SetScript('OnEditFocusLost', EditBoxOnEditFocusLost)
  745.  
  746.   EditBox:SetTextInsets(0, 0, 3, 3)
  747.   EditBox:SetMaxLetters(256)
  748.  
  749.   EditBox:SetPoint('BOTTOMLEFT', Frame, 'BOTTOMLEFT', 6, 0)
  750.   EditBox:SetPoint('BOTTOMRIGHT', Frame, 'BOTTOMRIGHT', 0, 0)
  751.   EditBox:SetHeight(19)
  752.  
  753.   local Label = Frame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
  754.   Label:SetPoint('TOPLEFT', Frame, 'TOPLEFT', 0, -2)
  755.   Label:SetPoint('TOPRIGHT', Frame, 'TOPRIGHT', 0, -2)
  756.   Label:SetJustifyH('LEFT')
  757.   Label:SetHeight(18)
  758.  
  759.   self.Label = Label
  760.  
  761.   local Button = CreateFrame('Button', nil, EditBox, 'UIPanelButtonTemplate')
  762.   Button:SetPoint('RIGHT', EditBox, 'RIGHT', -2, 0)
  763.   Button:SetScript('OnClick', EditBoxButtonOnClick)
  764.   Button:SetWidth(40)
  765.   Button:SetHeight(20)
  766.   Button:SetText(OKAY)
  767.   Button:Hide()
  768.  
  769.   self.Button = Button
  770.   Button.Object = self
  771.  
  772.   AceGUI:RegisterAsWidget(self)
  773.   return self
  774. end
  775.  
  776. --*****************************************************************************
  777. --
  778. -- Aura_EditBox dialog control
  779. --
  780. --*****************************************************************************
  781.  
  782. -------------------------------------------------------------------------------
  783. -- AuraEditBoxConstructor
  784. --
  785. -- Creates the widget for the Aura_EditBox
  786. --
  787. -- I know theres a better way of doing this than this, but not sure for the time being, works fine though!
  788. -------------------------------------------------------------------------------
  789. local function AuraEditBoxConstructor()
  790.   return AceGUI:Create(EditBoxWidgetType)
  791. end
  792.  
  793. AceGUI:RegisterWidgetType(EditBoxWidgetType, PredictorConstructor, EditBoxWidgetVersion)
  794. AceGUI:RegisterWidgetType(AuraEditBoxWidgetType, AuraEditBoxConstructor, AuraEditBoxWidgetVersion)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement