mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
change loadUI/UI.display lua API
This commit is contained in:
@@ -3,7 +3,7 @@ function table.dump(t, depth)
|
||||
for k,v in pairs(t) do
|
||||
str = string.rep(' ', depth * 2) .. k .. ': '
|
||||
if type(v) ~= "table" then
|
||||
print(str .. v)
|
||||
print(str .. tostring(v))
|
||||
else
|
||||
print(str)
|
||||
table.dump(v, depth+1)
|
||||
|
@@ -1,22 +1,38 @@
|
||||
UI = { }
|
||||
UI.root = getRootWidget()
|
||||
|
||||
function UI.loadAndDisplayLocked(otuiFile)
|
||||
local widget = loadUI(otuiFile, UI.root)
|
||||
UI.root:lockChild(widget)
|
||||
-- public functions
|
||||
function UI.display(arg1, options)
|
||||
local widget
|
||||
local parent
|
||||
if options then parent = options.parent end
|
||||
parent = parent or UI.root
|
||||
|
||||
-- display otui files
|
||||
if type(arg1) == 'string' then
|
||||
local otuiFilePath = resolveFileFullPath(arg1, 2)
|
||||
widget = loadUI(otuiFilePath, parent)
|
||||
-- display already loaded widgets
|
||||
else
|
||||
widget = arg1
|
||||
if parent:hasChild(widget) then
|
||||
widget:focus()
|
||||
widget:show()
|
||||
else
|
||||
parent:addChild(widget)
|
||||
widget:show()
|
||||
end
|
||||
end
|
||||
|
||||
-- apply display options
|
||||
if widget and options then
|
||||
for option,value in pairs(options) do
|
||||
if option == 'locked' and value then
|
||||
widget:lock()
|
||||
elseif option == 'visible' then
|
||||
widget:setVisible(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
return widget
|
||||
end
|
||||
|
||||
function UI.loadAndDisplay(otuiFile)
|
||||
local widget = loadUI(otuiFile, UI.root)
|
||||
return widget
|
||||
end
|
||||
|
||||
function UI.display(widget)
|
||||
UI.root:addChild(widget)
|
||||
end
|
||||
|
||||
function UI.displayLocked(widget)
|
||||
UI.root:addChild(widget)
|
||||
UI.root:lockChild(widget)
|
||||
end
|
||||
|
@@ -29,3 +29,27 @@ function dumpWidgets()
|
||||
print(UI.root:getChildByIndex(i):getId())
|
||||
end
|
||||
end
|
||||
|
||||
function getCallingScriptSourcePath(depth)
|
||||
depth = depth or 2
|
||||
local info = debug.getinfo(1+depth, "Sn")
|
||||
local path
|
||||
if info.short_src then
|
||||
path = info.short_src:match("(.*)/.*")
|
||||
end
|
||||
if not path then
|
||||
path = '/'
|
||||
elseif path:sub(0, 1) ~= '/' then
|
||||
path = '/' .. path
|
||||
end
|
||||
return path
|
||||
end
|
||||
|
||||
function resolveFileFullPath(filePath, depth)
|
||||
depth = depth or 1
|
||||
if filePath:sub(0, 1) ~= '/' then
|
||||
return getCallingScriptSourcePath(depth+1) .. '/' .. filePath
|
||||
else
|
||||
return filePath
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user