Advertisement
Rochet2

Faux ScrollBar

Sep 8th, 2012
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.51 KB | None | 0 0
  1. local DATALIST = {}
  2. local SELECTED = {}
  3. local BUTTONAMOUNT = {}
  4. local MakeFrame, MyADDON_ScrollBar_Update, MyADDON_Button_Toggle, MyADDON_Button_Remove
  5.  
  6. for i = 1, 40 do
  7.     table.insert(DATALIST, {"TestNameLong0000019", i*1000000000}) -- The number is unique
  8. end
  9.  
  10. function MakeFrame(name, width, height, movable, scrollable)
  11.     local Frame = CreateFrame("Frame", name, UIParent, nil)
  12.     Frame:SetFrameStrata("BACKGROUND")
  13.     Frame:SetWidth(width)
  14.     Frame:SetHeight(height)
  15.     Frame:SetBackdrop( {
  16.       bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  17.       edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16,
  18.       insets = { left = 4, right = 4, top = 4, bottom = 4 }
  19.     })
  20.     Frame:ClearAllPoints()
  21.     Frame:SetPoint("CENTER",0,0)
  22.     if(movable) then
  23.         Frame:SetMovable(true)
  24.         Frame:EnableMouse(true)
  25.         Frame:RegisterForDrag("LeftButton")
  26.         Frame:SetScript("OnDragStart", Frame.StartMoving)
  27.         Frame:SetScript("OnDragStop", Frame.StopMovingOrSizing)
  28.         Frame:SetScript("OnHide", Frame.StopMovingOrSizing)
  29.     end
  30.     if(scrollable) then
  31.         local ScrollBar = CreateFrame("ScrollFrame", name.."_ScrollBar", Frame, "FauxScrollFrameTemplate")
  32.         ScrollBar:SetPoint("TOPLEFT",0,-32)
  33.         ScrollBar:SetPoint("BOTTOMRIGHT",-30,16)
  34.         Frame.ButtonCount = math.floor((Frame:GetHeight()-35)/16) -- guessed 35px
  35.         Frame.ScrollBar = ScrollBar
  36.         Frame.Buttons = {}
  37.         for i = 1, Frame.ButtonCount do
  38.             local Button = CreateFrame("Button", name.."_Button"..i, ScrollBar, nil)
  39.             Button:SetWidth(Frame:GetWidth()-55)
  40.             Button:SetHeight(16)
  41.             Button:SetText("") -- Without this some font things fail and give lua errors
  42.             Button:SetNormalFontObject("GameFontNormal")
  43.             local font = Button:GetNormalFontObject();
  44.             font:SetJustifyH("LEFT")
  45.             if(i == 1) then
  46.                 Button:SetPoint("TOPLEFT",ScrollBar,"TOPLEFT",8,0)
  47.             else
  48.                 Button:SetPoint("TOPLEFT",name.."_Button"..(i-1),"BOTTOMLEFT")
  49.             end
  50.             -- MISCbutton:
  51.                 local MiscButton = CreateFrame("Button", Button:GetName().."_Deletes", UIParent, nil)
  52.                 MiscButton:SetWidth(16)
  53.                 MiscButton:SetHeight(16)
  54.                 MiscButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Disabled.")
  55.                 MiscButton:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-Down.")
  56.                 MiscButton:SetHighlightTexture("Interface\\Buttons\\UI-MinusButton-Up.")
  57.                 MiscButton:SetPoint("TOPLEFT", Button, "TOPRIGHT", 0, 0)
  58.                 MiscButton:SetText("XX")
  59.                 Button.MiscButton = MiscButton
  60.             table.insert(Frame.Buttons, Button)
  61.         end
  62.         for k,Button in ipairs(Frame.Buttons) do
  63.             Button:SetScript("OnClick", function() MyADDON_Button_Toggle(Frame, k) end)
  64.         end
  65.         ScrollBar:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, 16, MyADDON_ScrollBar_Update(Frame)) end)
  66.         ScrollBar:Show()
  67.         MyADDON_ScrollBar_Update(Frame)
  68.     end
  69.     Frame:Show()
  70.     return Frame
  71. end
  72. function MyADDON_ScrollBar_Update(Frame)
  73.     FauxScrollFrame_Update(Frame.ScrollBar,#DATALIST,Frame.ButtonCount,16);
  74.     for line, Button in ipairs(Frame.Buttons) do
  75.         local lineplusoffset = line + FauxScrollFrame_GetOffset(Frame.ScrollBar);
  76.         if lineplusoffset <= #DATALIST then
  77.             Button:SetText(DATALIST[lineplusoffset][2].."  "..DATALIST[lineplusoffset][1]);
  78.             Button:Show()
  79.             Button.MiscButton:Show()
  80.             if(SELECTED[DATALIST[lineplusoffset][2]]) then
  81.                 Button:GetFontString():SetTextColor(1, 0.8, 0)
  82.             else
  83.                 Button:GetFontString():SetTextColor(1, 1, 1)
  84.             end
  85.         else
  86.             Button:Hide()
  87.             Button.MiscButton:Hide()
  88.         end
  89.     end
  90.     Frame.ScrollBar:Show()
  91. end
  92. function MyADDON_Button_Toggle(Frame, ID)
  93.     local Button = Frame.Buttons[ID]
  94.     local SelID = DATALIST[FauxScrollFrame_GetOffset(Frame.ScrollBar) + ID][2]
  95.     if(SELECTED[SelID]) then
  96.         SELECTED[SelID] = nil
  97.         local font = Button:GetFontString()
  98.         if(font) then
  99.             font:SetTextColor(1, 1, 1) -- not selecter = white
  100.         end
  101.     else
  102.         SELECTED[SelID] = DATALIST[FauxScrollFrame_GetOffset(Frame.ScrollBar) + ID][1]
  103.         local font = Button:GetFontString()
  104.         if(font) then
  105.             font:SetTextColor(1, 0.8, 0) -- Selected = yellow
  106.         end
  107.     end
  108. end
  109. function MyADDON_Button_Remove(Frame, ID)
  110.     local DATAID = FauxScrollFrame_GetOffset(Frame.ScrollBar) + ID
  111.     local SelID = DATALIST[DATAID][2]
  112.     SELECTED[SelID] = nil
  113.     table.remove(DATALIST, DATAID)
  114.     MyADDON_ScrollBar_Update(Frame)
  115. end
  116.  
  117. local SelectionFrame = MakeFrame("MyADDON_selection_List", 300, 352, true, true)
  118. for ID, Button in ipairs(SelectionFrame.Buttons) do
  119.     Button.MiscButton:SetScript("OnClick", function() MyADDON_Button_Remove(SelectionFrame, ID) end)
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement