Thread: Trying to Learn
View Single Post
06-29-19, 05:25 PM   #29
Aeriez
A Fallenroot Satyr
Join Date: May 2007
Posts: 24
Originally Posted by Fizzlemizz View Post
You could make each row a single button with 3 FontStrings or ...
I went ahead and made each row a single button with 3 embedded fontstrings so you could get the highlight effect on mouseover for the entire row. But when it scrolls, it simply overwrites the previous fontstring (you end up with a dozen or more strings stacked on top of each other in each row). I've tried clearing the fontstring prior to setting it, but that doesn't seem to work. And I don't feel like clearing and rebuilding the entire table on scroll would be efficient.

Lua Code:
  1. local _, core = ...;
  2. local _G = _G;
  3. local classes = { "Rogue", "Paladin", "Mage", "Warlock", "Priest", "DK", "DH", "Hunter", "Shaman", "Druid", "Monk", "Warrior" }
  4. core.TableWidth, core.TableHeight, core.TableNumrows = 500, 18, 25;
  5. local TableData = {}
  6. local SelectedData = 0;
  7.  
  8. for i=1, 70 do
  9.     tinsert(TableData, { player=i, class=random(1, #classes), dkp=random(0, 10000) })
  10. end
  11.  
  12. --[[
  13.   Table above will be structured as:
  14.  
  15. TableData = {
  16.   ["player"] = "TestClass",
  17.   ["class"] = "Warrior",
  18.   ["dkp"] = 1000,
  19.   ["previous_dkp"] = 800, --not implemented yet. set previous_dkp = dkp at beginning of raid to see how much was gained/lost during a raid.
  20.  
  21. }
  22. --]]
  23.  
  24. function OnClick(self)   -- self = Rows[]
  25.     SelectedData = self.index;
  26.     for i=1, core.TableNumrows do
  27.       self:GetParent().Rows[i]:SetNormalTexture(nil)
  28.     end
  29.     self:SetNormalTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2.blp")
  30.     --[[  
  31.     for k,v in pairs(TableData[SelectedData]) do
  32.       if(tostring(k) == "class") then
  33.         print(k, " -> ", classes[v])
  34.       else
  35.         print(k, " -> ", v)
  36.       end
  37.     end
  38.     --retrieves string text
  39.     print(self.DKPInfo[1].data:GetText())
  40.     print(self.DKPInfo[2].data:GetText())
  41.     print(self.DKPInfo[3].data:GetText())
  42.     self.index selects the number of the row
  43.     --]]
  44. end
  45.  
  46. function CreateRow(parent, id) -- Create 3 buttons for each row in the list
  47.     local f = CreateFrame("Button", "$parentLine"..id, parent)
  48.     f.DKPInfo = {}
  49.     f:SetSize(core.TableWidth, core.TableHeight)
  50.     f:SetHighlightTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2.blp");
  51.     f:SetScript("OnClick", OnClick)
  52.     for i=1, 3 do
  53.         tinsert(f.DKPInfo, CreateFrame("Frame", "$parentButton"..i, f))
  54.         f.DKPInfo[i]:SetSize(core.TableWidth/3, core.TableHeight)
  55.         f.DKPInfo[i]:SetPoint("LEFT", f.DKPInfo[i-1] or f, f.DKPInfo[i-1] and "RIGHT" or "LEFT")
  56.     end
  57.     return f
  58. end
  59.  
  60. function MyFrame_Update(self)
  61.     local numOptions = #TableData
  62.     local index, row
  63.     local offset = FauxScrollFrame_GetOffset(self)
  64.     for i=1, core.TableNumrows do
  65.         row = self.Rows[i]
  66.         index = offset + i
  67.         if (index == SelectedData) then
  68.           row:SetNormalTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2.blp")
  69.         else
  70.           row:SetNormalTexture(nil)
  71.         end
  72.         if TableData[index] then
  73.             row:Show()
  74.             row.index = index
  75.             row.DKPInfo[1].data = row.DKPInfo[1]:CreateFontString(nil, "OVERLAY");
  76.             row.DKPInfo[1].data:SetFontObject("GameFontHighlight");
  77.             row.DKPInfo[1].data:SetTextColor(1, 1, 1, 1);
  78.             row.DKPInfo[1].data:SetPoint("CENTER", row.DKPInfo[1], "CENTER");
  79.             row.DKPInfo[1].data:SetText("Player"..TableData[index].player)
  80.  
  81.             row.DKPInfo[2].data = row.DKPInfo[2]:CreateFontString(nil, "OVERLAY");
  82.             row.DKPInfo[2].data:SetFontObject("GameFontHighlight");
  83.             row.DKPInfo[2].data:SetTextColor(1, 1, 1, 1);
  84.             row.DKPInfo[2].data:SetPoint("CENTER", row.DKPInfo[2], "CENTER");
  85.             row.DKPInfo[2].data:SetText(classes[TableData[index].class])
  86.  
  87.             row.DKPInfo[3].data = row.DKPInfo[3]:CreateFontString(nil, "OVERLAY");
  88.             row.DKPInfo[3].data:SetFontObject("GameFontHighlight");
  89.             row.DKPInfo[3].data:SetTextColor(1, 1, 1, 1);
  90.             row.DKPInfo[3].data:SetPoint("CENTER", row.DKPInfo[3], "CENTER");
  91.             row.DKPInfo[3].data:SetText(TableData[index].dkp)
  92.         else
  93.             row:Hide()
  94.         end
  95.     end
  96.     FauxScrollFrame_Update(self, numOptions, core.TableNumrows, core.TableHeight)
  97. end

Last edited by Aeriez : 06-29-19 at 06:14 PM.
  Reply With Quote