Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dui.lua #448

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions client/dui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
local duiCounter = 0
local availableDuis = {}
local duis = {}

local function GetDui(url, width, height)
width = width or 512
height = height or 512

local duiSize = tostring(width) .. "x" .. tostring(height)

if (availableDuis[duiSize] and #availableDuis[duiSize] > 0) then
local n, t = pairs(availableDuis[duiSize])
local nextKey, nextValue = n(t)
local id = nextValue
local dictionary = duis[id].textureDictName
local texture = duis[id].textureName

nextValue = nil
table.remove(availableDuis[duiSize], nextKey)
SetDuiUrl(duis[id].duiObject, url)
return {id = id, dictionary = dictionary, texture = texture}
end

duiCounter = duiCounter + 1
local generatedDictName = duiSize .. "-dict-" .. tostring(duiCounter)
local generatedTxtName = duiSize .. "-txt-" .. tostring(duiCounter)
local duiObject = CreateDui(url, width, height)
local dictObject = CreateRuntimeTxd(generatedDictName)
local duiHandle = GetDuiHandle(duiObject)
local txdObject = CreateRuntimeTextureFromDuiHandle(dictObject, generatedTxtName, duiHandle)

duis[duiCounter] = {
duiSize = duiSize,
duiObject = duiObject,
duiHandle = duiHandle,
dictionaryObject = dictObject,
textureObject = txdObject,
textureDictName = generatedDictName,
textureName = generatedTxtName
}

return {id = duiCounter, dictionary = generatedDictName, texture = generatedTxtName}
end

exports("GetDui", GetDui)

local function ChangeDuiUrl(id, url)
if (not duis[id]) then
return
end

local settings = duis[id]
SetDuiUrl(settings.duiObject, url)
end

exports("ChangeDuiUrl", ChangeDuiUrl)

local function ReleaseDui(id)
if (not duis[id]) then
return
end

local settings = duis[id]
local duiSize = settings.duiSize

SetDuiUrl(settings.duiObject, "about:blank")
if not availableDuis[duiSize] then
availableDuis[duiSize] = {}
end
availableDuis[duiSize][#availableDuis[duiSize] + 1] = id
end

exports("ReleaseDui", ReleaseDui)
Loading