Jump to content

Web Asset Browser


Josh
 Share

Recommended Posts

Here is a basic skeleton for a downloader. The idea is to have one system with multiple content providers that can be plugged in to download assets from other sources.

image.thumb.png.35ef3281eb7f14be1a8cb3f689fbe7e9.png

local extension = {}
extension.providers = {}

function extension:Initialize()

    local sidepanelwidth = 280
    local x = 4
    local y = 4

    extension.window = CreateWindow("Asset Library", 0, 0, 1024, 768, program.window, WINDOW_HIDDEN | WINDOW_TITLEBAR | WINDOW_CENTER | WINDOW_RESIZABLE)
    extension.ui = CreateInterface(extension.window)
    extension.treeview = CreateTreeView(x, y, sidepanelwidth, extension.ui.background.size.y - y * 2, extension.ui.background)
    extension.treeview:SetLayout(1,0,1,1)
    extension.panel = CreatePanel(x + sidepanelwidth + 4, y, extension.ui.background.size.x - sidepanelwidth - 4 - 2 * x, extension.ui.background.size.y - 2 * y, extension.ui.background, PANEL_BORDER)
    extension.panel:SetLayout(1,1,1,1)
    --extension.panel:SetColor(extension.panel:GetColor(WIDGETCOLOR_SUNKEN))
    extension.panel:SetColor(0,0,0,1)

    --Set DPI scale if needed
    if program.window.display.scale ~= 1 then
        local scale = program.window.display.scale
        local pos = extension.window.position
        local size = extension.window.size
        extension.window:SetShape(pos.x, pos.y, size.x * scale, size.y * scale)
        extension.ui:SetScale(scale)
    end

    ListenEvent(EVENT_WINDOWCLOSE, extension.window, extension.ProcessEvent, extension)
    ListenEvent(EVENT_WINDOWSIZE, extension.window, extension.ProcessEvent, extension)

    local s = FetchUrl("https://ambientcg.com/api/v2/categories_json")
    local t = LoadTable(s)
    local n

    local groups = {}

    for n = 1, #t do
        local name = t[n].categoryName
        local group = t[n].defaultDataTypeId
        if groups[group] == nil then
            groups[group] = {}
        end
        groups[group][name] = t
        --extension.treeview.root:AddNode(name)
    end

    local k,v

    local base = extension.treeview.root:AddNode("AmbientCG")

    for k,v in pairs(groups) do
        local node = base:AddNode(k)
        local k2, v2
        for k2, v2 in pairs(v) do
            node:AddNode(k2)
        end
    end

    base:Expand()

end

function extension.ProcessEvent(event, extension)

    if event.id == EVENT_WIDGETACTION then

        if event.source == extension.menuitem then
            if extension.window == nil then
                extension:Initialize()
            end
            extension.window:SetHidden(false)
            extension.window:Activate()
            return false
        end

    elseif event.id == EVENT_WINDOWCLOSE then

        if event.source == extension.window then
            program.window:Activate()
            extension.window:SetHidden(true)
            return false
        end

    end
end

local submenu = program.menu:FindChild("Scripting")
if submenu == nil then
    Print("Error: Could not find script menu")
    return
end
extension.menuitem = CreateMenu("Asset Library", submenu)

ListenEvent(EVENT_WIDGETACTION, extension.menuitem, extension.ProcessEvent, extension)

--Add a content provider
local t = {}

function t:GetCategories()

end


table.insert(extension.providers, t)

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I think I am going to make the interface in C++, built into the program, and then use Lua for the various integrations with different websites.

Here is the final version of the pure Lua approach. It doesn't download assets but it's a nice example of asynchronous behavior with Lua.

AssetLibrary.lua

image.thumb.jpeg.bda502b205d02df718ec13964b5b16a3.jpeg

  • Like 3

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Josh changed the title to Web Asset Browser
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...