view Gui.lua @ 38:7bfbff27a3d7

"Working" list display using a TreeGroup control. There's a small limitation where I can't accurately detect which subtree is open unless the user has made a selection in that tab. Not sure I love that. Loot lists are displayed with colored names. People not in the raid are grayed out.
author John@Doomsday
date Wed, 14 Mar 2012 08:31:31 -0400
parents 21c58930f74e
children 90622848932b
line wrap: on
line source
local AceGUI = LibStub("AceGUI-3.0")

local ChangeTab = function(container, event, group)
    container:ReleaseChildren()
    if group == "tab2" then
        local desc = AceGUI:Create("Label")
        desc:SetText("This is Tab 1")
        desc:SetFullWidth(true)
        container:AddChild(desc)

        local button = AceGUI:Create("Button")
        button:SetText("Tab 1 Button")
        button:SetWidth(200)
        container:AddChild(button)
    elseif group == "tab1" then
        --local leftGroup = AceGUI:Create("InlineGroup")
        --leftGroup:SetFullHeight()
        --leftGroup:SetWidth(200)

        local rightGroup = AceGUI:Create("InlineGroup")
        rightGroup:SetTitle("title")
        --rightGroup:SetWidth(600)
        --rightGroup:SetHeight(200)
        rightGroup.width = 'fill'
        --rightGroup:SetFullWidth()
        --rightGroup.alignoffset = 25
        rightGroup:SetLayout("Flow")

        --local desc = AceGUI:Create("Label")
        --desc:SetText("This is Tab 1")
        --desc:SetFullWidth(true)
        --container:AddChild(desc)
        local icon = AceGUI:Create("Icon")
        icon:SetImage([[Interface\Icons\INV_Misc_PocketWatch_01]])
        local sz = 64 * icon.frame:GetEffectiveScale() -- 64 matches the character frame icon size
        icon:SetWidth(sz,sz)
        icon:SetHeight(sz,sz)
        icon:SetImageSize(sz,sz)
        icon:SetCallback("OnEnter", function(widget) GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT");  GameTooltip:SetHyperlink("item:16846:0:0:0:0:0:0:0"); GameTooltip:Show() end )
        icon:SetCallback("OnLeave", function(widget) GameTooltip:Hide() end )
        rightGroup:AddChild(icon)

        for i=1,12 do
            icon = AceGUI:Create("Icon")
            icon:SetImage([[Interface\Icons\INV_Misc_PocketWatch_01]])
            local sz = 64 * icon.frame:GetEffectiveScale() -- 64 matches the character frame icon size
            icon:SetWidth(sz,sz)
            icon:SetHeight(sz,sz)
            icon:SetImageSize(sz,sz)
            icon:SetCallback("OnEnter", function(widget) GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT");  GameTooltip:SetHyperlink("item:16846:0:0:0:0:0:0:0"); GameTooltip:Show() end )
            icon:SetCallback("OnLeave", function(widget) GameTooltip:Hide() end )
            rightGroup:AddChild(icon)
        end

        local item2 = {string="item2!", color = {r=1,g=0,b=0.5} }
        local itemList = {"Item1", "item2", "Item3", "Item4"}
        for i=5,29 do
           table.insert(itemList,"Item"..i)
        end

        local colorize = function(str,color)
            if str==nil or str=="" then return "" end
            if type(color) == "table" then
                color = string.format("%02x%02x%02x",255*color.r,255*color.g,255*color.b)
            end
            if color == nil then return str end
            return "|cff"..tostring(color or "ffffff")..str.."|r"
        end
        local tree = {}
        for i,v in pairs(bsk.lists) do
            local entry = {value=i,text=v.name}
            if getn(v) > 0 then
                entry.children = {}
                for x,y in ipairs(v) do
                    local p = bsk.persons[y.id]
                    local line = {value=y.id,text=p.main,icon=[[Interface\Glues\CharacterCreate\UI-CharacterCreate-Classes]]}
                    line.iconCoords=CLASS_ICON_TCOORDS[p.class]
                    bsk:PopulateRaidList() -- todo: this should be elsewhere
                    if not bsk.raidIdP[y.id] and not bsk.reserveIdP[y.id] then
                        line.disabled = true
                    else
                        line.text=colorize(line.text,RAID_CLASS_COLORS[p.class])
                    end
                    table.insert(entry.children,line)
                end
            else
                entry.disabled=true
            end
            table.insert(tree,entry)
        end
        local treegroup = AceGUI:Create("TreeGroup")
        treegroup:SetTree(tree)
        treegroup:EnableButtonTooltips(false)
        treegroup:SetFullWidth(true)
        treegroup:SetFullHeight(true)
        treegroup:SetAutoAdjustHeight(false)

        treegroup:SetCallback("OnGroupSelected", function(widget,_,uniquevalue) bsk:Print("OGS: uniquevalue: "..uniquevalue)
        end)
        treegroup:SetCallback("OnClick", function(widget,_,uniquevalue) bsk:Print("Onclick: uniquevalue: " .. uniquevalue) end)
        treegroup:SetCallback("OnButtonEnter", function(widget,_,value) bsk:Print("OnButtonEnter: value: " .. value) end)

        container:AddChild(treegroup)

        local scroller = AceGUI:Create("ScrollFrame")
        scroller:SetLayout("List")
        scroller:SetHeight(0) -- prevents a nasty graphical bug, dont ask me why
        scroller:SetFullHeight(true)
        scroller:SetFullWidth(true)

        local label = AceGUI:Create("InteractiveLabel")
        label:SetText("fucking hell\n")
        scroller:AddChild(label)
        scroller:AddChild(rightGroup)
        --widget:ReleaseChildren()
        --widget:SetLayout("List")
        --widget:AddChild(scroller)
        treegroup:AddChild(scroller)
    end
end

--local myhook = function(tooltip, spellid)
--tooltip:AddLine("MSS was here", 1, 1, 1)
--tooltip:Show()
--end
--if GameTooltip:GetScript("OnTooltipSetSpell") then
--GameTooltip:HookScript("OnTooltipSetSpell", myhook)
--else
--GameTooltip:SetScript("OnTooltipSetSpell", myhook)
--end

function bsk:CreateGUI()

    -- Create a container frame
    self.frame = AceGUI:Create("Frame")
    self.frame:SetCallback("OnClose",function(widget) AceGUI:Release(widget) end)
    self.frame:SetTitle("BSK")
    self.frame:SetLayout("Flow")
    self.frame:SetHeight(700) 
    self.frame:SetWidth(700)

    --local opts = 
    --{
         
    --}






    --local tab = AceGUI:Create("TabGroup")
    --tab:SetLayout("Flow")
    --tab:SetTabs(
    --   {
    --       {
    --           text="Tab 1",
    --           value="tab1"
    --       },

    --       {
    --           text="Tab 2",
    --           value="tab2"
    --       },
    --       {
    --           text="Tab 3",
    --           value="tab3"
    --       },
    --       {
    --           text="Tab 4",
    --           value="tab4"
    --       }
    --   }
    --)
    --tab.width = "fill"
    --tab.height = "fill"

    --tab:SetCallback("OnGroupSelected",ChangeTab)
    --tab:SelectTab("tab1")
    --self.frame:AddChild(tab)
    ChangeTab(self.frame,0,"tab1")

    -- Create a button
    --local btn = AceGUI:Create("Button")
    --btn:SetWidth(170)
    --btn:SetText("Button !")
    --btn:SetCallback("OnClick", function() print("Click!") end)
    -- Add the button to the container
    --self.frame:AddChild(btn)
end