• 0

    posted a message on FauxScrollFrameTemplate XML to LUA
    Quote from Lombra
    Without going through your code thoroughly, I can at least tell you that OnLoad only ever fires for widgets created in XML. Using Lua, you'd just put all the OnLoad code after CreateFrame. This might solve a few things. Also, getglobal has been deprecated in favour of _G.
    getglobal("MyModEntry"..line) -> _G["MyModEntry"..line]



    Thanks for your reply.
    I have change the OnLoad to OnShow and change getglobal to _getglobal.

    But the result is the same as above :( I see only the Frame "MyModFrame" in WoW. No buttons, no text, no scrollbar :(

    i don't understand why :(

    local btnMyModEntryTemplate = CreateFrame("Button", "MyModEntryTemplate")
    btnMyModEntryTemplate:SetWidth(150)
    btnMyModEntryTemplate:SetHeight(16)
    btnMyModEntryTemplate:SetHighlightFontObject(GameFontHighlightLeft)
    btnMyModEntryTemplate:Hide()
    
    local MyMod = CreateFrame("Frame", "MyModFrame", UIParent);
    MyMod:EnableMouse(true)
    MyMod:SetWidth(196)
    MyMod:SetHeight(96)
    MyMod:SetPoint("CENTER",0,0)
    MyMod: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}}
    )
    
    local MyModScrollBar = CreateFrame("ScrollFrame", "MyModScrollBarFrame", MyMod, "FauxScrollFrameTemplate")
    MyModScrollBar:SetPoint("TOPLEFT", 0, -8)
    MyModScrollBar:SetPoint("BOTTOMRIGHT", -30, 8)
    MyModScrollBar:Hide()
    MyModScrollBar:SetScript("OnVerticalScroll", function () 
    	FauxScrollFrame_OnVerticalScroll(self, offset, 16, MyModScrollBar_Update);
    end)
    MyModScrollBar:SetScript("OnShow", function () 
    	MyModScrollBar_Update()
    end)
    MyMod:SetScript("OnShow", function () 
    	MyModData = {}
    	for i=1,50 do
    		MyModData[i] = "Test "..math.random(100)
    	end
    	MyModScrollBar:Show()
    end)
    
    local btnMyModEntry1 = CreateFrame("Button", "MyModEntry1Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry1:SetPoint("TOPLEFT", MyModScrollBar, "TOPLEFT", 8, 0)
    
    local btnMyModEntry2 = CreateFrame("Button", "MyModEntry2Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry2:SetPoint("TOPLEFT", btnMyModEntry1, "BOTTOMLEFT")
    
    local btnMyModEntry3 = CreateFrame("Button", "MyModEntry3Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry3:SetPoint("TOPLEFT", btnMyModEntry2, "BOTTOMLEFT")
    
    local btnMyModEntry4 = CreateFrame("Button", "MyModEntry4Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry4:SetPoint("TOPLEFT", btnMyModEntry3, "BOTTOMLEFT")
    
    local btnMyModEntry5 = CreateFrame("Button", "MyModEntry5Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry5:SetPoint("TOPLEFT", btnMyModEntry4, "BOTTOMLEFT")
    
    
    function MyModScrollBar_Update()
      local line; -- 1 through 5 of our window to scroll
      local lineplusoffset; -- an index into our data calculated from the scroll offset
      FauxScrollFrame_Update(MyModScrollBar,50,5,16);
      for line=1,5 do
        lineplusoffset = line + FauxScrollFrame_GetOffset(MyModScrollBar);
        if lineplusoffset <= 50 then
    		_getglobal("MyModEntry"..line):SetText(MyModData[lineplusoffset]);
    		_getglobal("MyModEntry"..line):Show();
        else
    		_getglobal("MyModEntry"..line):Hide();
        end
      end
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on FauxScrollFrameTemplate XML to LUA
    Hello,
    write addons is new for me.

    My first addon test is translate the FauxScrollFrameTemplate XML part to LUA. I will not use XML.

    http://www.wowwiki.com/Making_a_scrollable_list_using_FauxScrollFrameTemplate

    Thats my translated code:
    MyModData = {}
    
    function MyMod_OnLoad(MyModScrollBar)
      for i=1,50 do
        MyModData[i] = "Test "..math.random(100)
      end
      MyModScrollBar:Show()
    end
    
    function MyModScrollBar_Update(MyModScrollBar)
      local line; -- 1 through 5 of our window to scroll
      local lineplusoffset; -- an index into our data calculated from the scroll offset
      FauxScrollFrame_Update(MyModScrollBar,50,5,16);
      for line=1,5 do
        lineplusoffset = line + FauxScrollFrame_GetOffset(MyModScrollBar);
        if lineplusoffset <= 50 then
          getglobal("MyModEntry"..line):SetText(MyModData[lineplusoffset]);
          getglobal("MyModEntry"..line):Show();
        else
          getglobal("MyModEntry"..line):Hide();
        end
      end
    end
    
    local btnMyModEntryTemplate = CreateFrame("Button", "MyModEntryTemplate")
    btnMyModEntryTemplate:SetWidth(150)
    btnMyModEntryTemplate:SetHeight(16)
    btnMyModEntryTemplate:SetHighlightFontObject(GameFontHighlightLeft)
    btnMyModEntryTemplate:Hide()
    
    local MyMod = CreateFrame("Frame", "MyModFrame", UIParent);
    MyMod:EnableMouse(true)
    MyMod:SetWidth(196)
    MyMod:SetHeight(96)
    MyMod:SetPoint("CENTER",0,0)
    MyMod:SetScript("OnLoad", function () 
    	MyMod_OnLoad()
    end)
    MyMod: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}}
    )
    
    local MyModScrollBar = CreateFrame("ScrollFrame", "MyModScrollBarFrame", MyMod, "FauxScrollFrameTemplate")
    MyModScrollBar:SetPoint("TOPLEFT", 0, -8)
    MyModScrollBar:SetPoint("BOTTOMRIGHT", -30, 8)
    MyModScrollBar:Hide()
    MyModScrollBar:SetScript("OnVerticalScroll", function () 
    	FauxScrollFrame_OnVerticalScroll(self, offset, 16, MyModScrollBar_Update);
    end)
    MyModScrollBar:SetScript("OnShow", function () 
    	MyModScrollBar_Update()
    end)
      
    local btnMyModEntry1 = CreateFrame("Button", "MyModEntry1Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry1:SetPoint("TOPLEFT", MyModScrollBar, "TOPLEFT", 8, 0)
    
    local btnMyModEntry2 = CreateFrame("Button", "MyModEntry2Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry2:SetPoint("TOPLEFT", btnMyModEntry1, "BOTTOMLEFT")
    
    local btnMyModEntry3 = CreateFrame("Button", "MyModEntry3Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry3:SetPoint("TOPLEFT", btnMyModEntry2, "BOTTOMLEFT")
    
    local btnMyModEntry4 = CreateFrame("Button", "MyModEntry4Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry4:SetPoint("TOPLEFT", btnMyModEntry3, "BOTTOMLEFT")
    
    local btnMyModEntry5 = CreateFrame("Button", "MyModEntry5Button", MyMod, "MyModEntryTemplate")
    btnMyModEntry5:SetPoint("TOPLEFT", btnMyModEntry4, "BOTTOMLEFT")


    The problem is: I see no buttons.
    I think the "OnLoad", "OnShow" and "OnVerticalScroll" scripts will never called.

    Why FauxScrollFrameTemplate? It was the only Template there i found a making of guide.

    Has anyone an idea whats wrong on my code and can help me, plaese?
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.