|
|
@ -3,9 +3,8 @@ function init()
|
|
|
|
|
|
|
|
|
|
|
|
connect(Container, { onOpen = onContainerOpen,
|
|
|
|
connect(Container, { onOpen = onContainerOpen,
|
|
|
|
onClose = onContainerClose,
|
|
|
|
onClose = onContainerClose,
|
|
|
|
onAddItem = onContainerAddItem,
|
|
|
|
onSizeChange = onContainerChangeSize,
|
|
|
|
onUpdateItem = onContainerUpdateItem,
|
|
|
|
onUpdateItem = onContainerUpdateItem })
|
|
|
|
onRemoveItem = onContainerRemoveItem })
|
|
|
|
|
|
|
|
connect(Game, { onGameEnd = clean() })
|
|
|
|
connect(Game, { onGameEnd = clean() })
|
|
|
|
|
|
|
|
|
|
|
|
reloadContainers()
|
|
|
|
reloadContainers()
|
|
|
@ -14,9 +13,8 @@ end
|
|
|
|
function terminate()
|
|
|
|
function terminate()
|
|
|
|
disconnect(Container, { onOpen = onContainerOpen,
|
|
|
|
disconnect(Container, { onOpen = onContainerOpen,
|
|
|
|
onClose = onContainerClose,
|
|
|
|
onClose = onContainerClose,
|
|
|
|
onAddItem = onContainerAddItem,
|
|
|
|
onSizeChange = onContainerChangeSize,
|
|
|
|
onUpdateItem = onContainerUpdateItem,
|
|
|
|
onUpdateItem = onContainerUpdateItem })
|
|
|
|
onRemoveItem = onContainerRemoveItem })
|
|
|
|
|
|
|
|
disconnect(Game, { onGameEnd = clean() })
|
|
|
|
disconnect(Game, { onGameEnd = clean() })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -46,6 +44,38 @@ function refreshContainerItems(container)
|
|
|
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
|
|
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
|
|
|
itemWidget:setItem(container:getItem(slot))
|
|
|
|
itemWidget:setItem(container:getItem(slot))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if container:hasPages() then
|
|
|
|
|
|
|
|
refreshContainerPages(container)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toggleContainerPages(containerWindow, pages)
|
|
|
|
|
|
|
|
containerWindow:getChildById('miniwindowScrollBar'):setMarginTop(pages and 42 or 22)
|
|
|
|
|
|
|
|
containerWindow:getChildById('contentsPanel'):setMarginTop(pages and 42 or 22)
|
|
|
|
|
|
|
|
containerWindow:getChildById('pagePanel'):setVisible(pages)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function refreshContainerPages(container)
|
|
|
|
|
|
|
|
local currentPage = 1 + math.floor(container:getFirstIndex() / container:getCapacity())
|
|
|
|
|
|
|
|
local pages = 1 + math.floor(math.max(0, (container:getSize() - 1)) / container:getCapacity())
|
|
|
|
|
|
|
|
container.window:recursiveGetChildById('pageLabel'):setText(string.format('Page %i of %i', currentPage, pages))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local prevPageButton = container.window:recursiveGetChildById('prevPageButton')
|
|
|
|
|
|
|
|
if currentPage == 1 then
|
|
|
|
|
|
|
|
prevPageButton:setEnabled(false)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
prevPageButton:setEnabled(true)
|
|
|
|
|
|
|
|
prevPageButton.onClick = function() g_game.seekInContainer(container:getId(), container:getFirstIndex() - container:getCapacity()) end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local nextPageButton = container.window:recursiveGetChildById('nextPageButton')
|
|
|
|
|
|
|
|
if currentPage >= pages then
|
|
|
|
|
|
|
|
nextPageButton:setEnabled(false)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nextPageButton:setEnabled(true)
|
|
|
|
|
|
|
|
nextPageButton.onClick = function() g_game.seekInContainer(container:getId(), container:getFirstIndex() + container:getCapacity()) end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function onContainerOpen(container, previousContainer)
|
|
|
|
function onContainerOpen(container, previousContainer)
|
|
|
@ -88,11 +118,18 @@ function onContainerOpen(container, previousContainer)
|
|
|
|
itemWidget:setItem(container:getItem(slot))
|
|
|
|
itemWidget:setItem(container:getItem(slot))
|
|
|
|
itemWidget:setMargin(0)
|
|
|
|
itemWidget:setMargin(0)
|
|
|
|
itemWidget.position = container:getSlotPosition(slot)
|
|
|
|
itemWidget.position = container:getSlotPosition(slot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not container:isUnlocked() then
|
|
|
|
|
|
|
|
itemWidget:setBorderColor('red')
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
container.window = containerWindow
|
|
|
|
container.window = containerWindow
|
|
|
|
container.itemsPanel = containerPanel
|
|
|
|
container.itemsPanel = containerPanel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toggleContainerPages(containerWindow, container:hasPages())
|
|
|
|
|
|
|
|
refreshContainerPages(container)
|
|
|
|
|
|
|
|
|
|
|
|
local layout = containerPanel:getLayout()
|
|
|
|
local layout = containerPanel:getLayout()
|
|
|
|
local cellSize = layout:getCellSize()
|
|
|
|
local cellSize = layout:getCellSize()
|
|
|
|
containerWindow:setContentMinimumHeight(cellSize.height)
|
|
|
|
containerWindow:setContentMinimumHeight(cellSize.height)
|
|
|
@ -110,7 +147,7 @@ function onContainerClose(container)
|
|
|
|
destroy(container)
|
|
|
|
destroy(container)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function onContainerAddItem(container, slot, item)
|
|
|
|
function onContainerChangeSize(container, size)
|
|
|
|
if not container.window then return end
|
|
|
|
if not container.window then return end
|
|
|
|
refreshContainerItems(container)
|
|
|
|
refreshContainerItems(container)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -120,8 +157,3 @@ function onContainerUpdateItem(container, slot, item, oldItem)
|
|
|
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
|
|
|
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
|
|
|
itemWidget:setItem(item)
|
|
|
|
itemWidget:setItem(item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function onContainerRemoveItem(container, slot, item)
|
|
|
|
|
|
|
|
if not container.window then return end
|
|
|
|
|
|
|
|
refreshContainerItems(container)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|