mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-04-30 03:09:20 +02:00
71 lines
1.5 KiB
Lua
71 lines
1.5 KiB
Lua
local activeWindow
|
|
|
|
function init()
|
|
g_ui.importStyle('itemselector')
|
|
|
|
connect(g_game, { onGameEnd = destroyWindow })
|
|
end
|
|
|
|
function terminate()
|
|
disconnect(g_game, { onGameEnd = destroyWindow })
|
|
|
|
destroyWindow()
|
|
end
|
|
|
|
function destroyWindow()
|
|
if activeWindow then
|
|
activeWindow:destroy()
|
|
activeWindow = nil
|
|
end
|
|
end
|
|
|
|
function show(itemWidget)
|
|
if not itemWidget then
|
|
return
|
|
end
|
|
if activeWindow then
|
|
destroyWindow()
|
|
end
|
|
local window = g_ui.createWidget('ItemSelectorWindow', rootWidget)
|
|
|
|
local destroy = function()
|
|
window:destroy()
|
|
if window == activeWindow then
|
|
activeWindow = nil
|
|
end
|
|
end
|
|
local doneFunc = function()
|
|
itemWidget:setItemId(window.item:getItemId())
|
|
itemWidget:setItemCount(window.item:getItemCount())
|
|
destroy()
|
|
end
|
|
|
|
window.okButton.onClick = doneFunc
|
|
window.cancelButton.onClick = destroy
|
|
window.onEnter = doneFunc
|
|
window.onEscape = destroy
|
|
|
|
window.item:setItemId(itemWidget:getItemId())
|
|
window.item:setItemCount(itemWidget:getItemCount())
|
|
|
|
window.itemId:setValue(itemWidget:getItemId())
|
|
if itemWidget:getItemCount() > 1 then
|
|
window.itemCount:setValue(itemWidget:getItemCount())
|
|
end
|
|
|
|
window.itemId.onValueChange = function(widget, value)
|
|
window.item:setItemId(value)
|
|
end
|
|
window.itemCount.onValueChange = function(widget, value)
|
|
window.item:setItemCount(value)
|
|
end
|
|
|
|
activeWindow = window
|
|
activeWindow:raise()
|
|
activeWindow:focus()
|
|
end
|
|
|
|
function hide()
|
|
destroyWindow()
|
|
end
|