Originally Posted by Fizzlemizz
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:
local _, core = ...;
local _G = _G;
local classes = { "Rogue", "Paladin", "Mage", "Warlock", "Priest", "DK", "DH", "Hunter", "Shaman", "Druid", "Monk", "Warrior" }
core.TableWidth, core.TableHeight, core.TableNumrows = 500, 18, 25;
local TableData = {}
local SelectedData = 0;
for i=1, 70 do
tinsert(TableData, { player=i, class=random(1, #classes), dkp=random(0, 10000) })
end
--[[
Table above will be structured as:
TableData = {
["player"] = "TestClass",
["class"] = "Warrior",
["dkp"] = 1000,
["previous_dkp"] = 800, --not implemented yet. set previous_dkp = dkp at beginning of raid to see how much was gained/lost during a raid.
}
--]]
function OnClick(self) -- self = Rows[]
SelectedData = self.index;
for i=1, core.TableNumrows do
self:GetParent().Rows[i]:SetNormalTexture(nil)
end
self:SetNormalTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2.blp")
--[[
for k,v in pairs(TableData[SelectedData]) do
if(tostring(k) == "class") then
print(k, " -> ", classes[v])
else
print(k, " -> ", v)
end
end
--retrieves string text
print(self.DKPInfo[1].data:GetText())
print(self.DKPInfo[2].data:GetText())
print(self.DKPInfo[3].data:GetText())
self.index selects the number of the row
--]]
end
function CreateRow(parent, id) -- Create 3 buttons for each row in the list
local f = CreateFrame("Button", "$parentLine"..id, parent)
f.DKPInfo = {}
f:SetSize(core.TableWidth, core.TableHeight)
f:SetHighlightTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2.blp");
f:SetScript("OnClick", OnClick)
for i=1, 3 do
tinsert(f.DKPInfo, CreateFrame("Frame", "$parentButton"..i, f))
f.DKPInfo[i]:SetSize(core.TableWidth/3, core.TableHeight)
f.DKPInfo[i]:SetPoint("LEFT", f.DKPInfo[i-1] or f, f.DKPInfo[i-1] and "RIGHT" or "LEFT")
end
return f
end
function MyFrame_Update(self)
local numOptions = #TableData
local index, row
local offset = FauxScrollFrame_GetOffset(self)
for i=1, core.TableNumrows do
row = self.Rows[i]
index = offset + i
if (index == SelectedData) then
row:SetNormalTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2.blp")
else
row:SetNormalTexture(nil)
end
if TableData[index] then
row:Show()
row.index = index
row.DKPInfo[1].data = row.DKPInfo[1]:CreateFontString(nil, "OVERLAY");
row.DKPInfo[1].data:SetFontObject("GameFontHighlight");
row.DKPInfo[1].data:SetTextColor(1, 1, 1, 1);
row.DKPInfo[1].data:SetPoint("CENTER", row.DKPInfo[1], "CENTER");
row.DKPInfo[1].data:SetText("Player"..TableData[index].player)
row.DKPInfo[2].data = row.DKPInfo[2]:CreateFontString(nil, "OVERLAY");
row.DKPInfo[2].data:SetFontObject("GameFontHighlight");
row.DKPInfo[2].data:SetTextColor(1, 1, 1, 1);
row.DKPInfo[2].data:SetPoint("CENTER", row.DKPInfo[2], "CENTER");
row.DKPInfo[2].data:SetText(classes[TableData[index].class])
row.DKPInfo[3].data = row.DKPInfo[3]:CreateFontString(nil, "OVERLAY");
row.DKPInfo[3].data:SetFontObject("GameFontHighlight");
row.DKPInfo[3].data:SetTextColor(1, 1, 1, 1);
row.DKPInfo[3].data:SetPoint("CENTER", row.DKPInfo[3], "CENTER");
row.DKPInfo[3].data:SetText(TableData[index].dkp)
else
row:Hide()
end
end
FauxScrollFrame_Update(self, numOptions, core.TableNumrows, core.TableHeight)
end