Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DATALIST = {}
- local SELECTED = {}
- local BUTTONAMOUNT = {}
- local MakeFrame, MyADDON_ScrollBar_Update, MyADDON_Button_Toggle, MyADDON_Button_Remove
- for i = 1, 40 do
- table.insert(DATALIST, {"TestNameLong0000019", i*1000000000}) -- The number is unique
- end
- function MakeFrame(name, width, height, movable, scrollable)
- local Frame = CreateFrame("Frame", name, UIParent, nil)
- Frame:SetFrameStrata("BACKGROUND")
- Frame:SetWidth(width)
- Frame:SetHeight(height)
- Frame:SetBackdrop( {
- bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16,
- insets = { left = 4, right = 4, top = 4, bottom = 4 }
- })
- Frame:ClearAllPoints()
- Frame:SetPoint("CENTER",0,0)
- if(movable) then
- Frame:SetMovable(true)
- Frame:EnableMouse(true)
- Frame:RegisterForDrag("LeftButton")
- Frame:SetScript("OnDragStart", Frame.StartMoving)
- Frame:SetScript("OnDragStop", Frame.StopMovingOrSizing)
- Frame:SetScript("OnHide", Frame.StopMovingOrSizing)
- end
- if(scrollable) then
- local ScrollBar = CreateFrame("ScrollFrame", name.."_ScrollBar", Frame, "FauxScrollFrameTemplate")
- ScrollBar:SetPoint("TOPLEFT",0,-32)
- ScrollBar:SetPoint("BOTTOMRIGHT",-30,16)
- Frame.ButtonCount = math.floor((Frame:GetHeight()-35)/16) -- guessed 35px
- Frame.ScrollBar = ScrollBar
- Frame.Buttons = {}
- for i = 1, Frame.ButtonCount do
- local Button = CreateFrame("Button", name.."_Button"..i, ScrollBar, nil)
- Button:SetWidth(Frame:GetWidth()-55)
- Button:SetHeight(16)
- Button:SetText("") -- Without this some font things fail and give lua errors
- Button:SetNormalFontObject("GameFontNormal")
- local font = Button:GetNormalFontObject();
- font:SetJustifyH("LEFT")
- if(i == 1) then
- Button:SetPoint("TOPLEFT",ScrollBar,"TOPLEFT",8,0)
- else
- Button:SetPoint("TOPLEFT",name.."_Button"..(i-1),"BOTTOMLEFT")
- end
- -- MISCbutton:
- local MiscButton = CreateFrame("Button", Button:GetName().."_Deletes", UIParent, nil)
- MiscButton:SetWidth(16)
- MiscButton:SetHeight(16)
- MiscButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Disabled.")
- MiscButton:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-Down.")
- MiscButton:SetHighlightTexture("Interface\\Buttons\\UI-MinusButton-Up.")
- MiscButton:SetPoint("TOPLEFT", Button, "TOPRIGHT", 0, 0)
- MiscButton:SetText("XX")
- Button.MiscButton = MiscButton
- table.insert(Frame.Buttons, Button)
- end
- for k,Button in ipairs(Frame.Buttons) do
- Button:SetScript("OnClick", function() MyADDON_Button_Toggle(Frame, k) end)
- end
- ScrollBar:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, 16, MyADDON_ScrollBar_Update(Frame)) end)
- ScrollBar:Show()
- MyADDON_ScrollBar_Update(Frame)
- end
- Frame:Show()
- return Frame
- end
- function MyADDON_ScrollBar_Update(Frame)
- FauxScrollFrame_Update(Frame.ScrollBar,#DATALIST,Frame.ButtonCount,16);
- for line, Button in ipairs(Frame.Buttons) do
- local lineplusoffset = line + FauxScrollFrame_GetOffset(Frame.ScrollBar);
- if lineplusoffset <= #DATALIST then
- Button:SetText(DATALIST[lineplusoffset][2].." "..DATALIST[lineplusoffset][1]);
- Button:Show()
- Button.MiscButton:Show()
- if(SELECTED[DATALIST[lineplusoffset][2]]) then
- Button:GetFontString():SetTextColor(1, 0.8, 0)
- else
- Button:GetFontString():SetTextColor(1, 1, 1)
- end
- else
- Button:Hide()
- Button.MiscButton:Hide()
- end
- end
- Frame.ScrollBar:Show()
- end
- function MyADDON_Button_Toggle(Frame, ID)
- local Button = Frame.Buttons[ID]
- local SelID = DATALIST[FauxScrollFrame_GetOffset(Frame.ScrollBar) + ID][2]
- if(SELECTED[SelID]) then
- SELECTED[SelID] = nil
- local font = Button:GetFontString()
- if(font) then
- font:SetTextColor(1, 1, 1) -- not selecter = white
- end
- else
- SELECTED[SelID] = DATALIST[FauxScrollFrame_GetOffset(Frame.ScrollBar) + ID][1]
- local font = Button:GetFontString()
- if(font) then
- font:SetTextColor(1, 0.8, 0) -- Selected = yellow
- end
- end
- end
- function MyADDON_Button_Remove(Frame, ID)
- local DATAID = FauxScrollFrame_GetOffset(Frame.ScrollBar) + ID
- local SelID = DATALIST[DATAID][2]
- SELECTED[SelID] = nil
- table.remove(DATALIST, DATAID)
- MyADDON_ScrollBar_Update(Frame)
- end
- local SelectionFrame = MakeFrame("MyADDON_selection_List", 300, 352, true, true)
- for ID, Button in ipairs(SelectionFrame.Buttons) do
- Button.MiscButton:SetScript("OnClick", function() MyADDON_Button_Remove(SelectionFrame, ID) end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement