mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
improve containers
This commit is contained in:
79
modules/game_containers/containers.lua
Normal file
79
modules/game_containers/containers.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
Containers = {}
|
||||
|
||||
-- private variables
|
||||
local m_containers = {}
|
||||
|
||||
-- public functions
|
||||
function Containers.clean()
|
||||
m_containers = {}
|
||||
end
|
||||
|
||||
function Containers.getFreeContainerId()
|
||||
for i=0,15 do
|
||||
if not m_containers[i] then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent)
|
||||
local container = m_containers[containerId]
|
||||
if container then
|
||||
Game.gameRightPanel:removeChild(container)
|
||||
end
|
||||
|
||||
container = displayUI('container.otui', { parent = Game.gameRightPanel })
|
||||
container:setText(name)
|
||||
|
||||
-- set icon, itemid
|
||||
-- closebutton
|
||||
-- resize
|
||||
if hasParent then
|
||||
-- parent button
|
||||
end
|
||||
|
||||
container.itemCount = 0
|
||||
container.capacity = capacity
|
||||
|
||||
for i=1,capacity do
|
||||
local item = UIItem.create()
|
||||
item:setStyle('Item')
|
||||
container:addChild(item)
|
||||
end
|
||||
|
||||
m_containers[containerId] = container
|
||||
print("opencid ".. containerId)
|
||||
end
|
||||
|
||||
function Containers.onContainerClose(containerId)
|
||||
print("closecid ".. containerId)
|
||||
local container = m_containers[containerId]
|
||||
if container then
|
||||
Game.gameRightPanel:removeChild(container)
|
||||
end
|
||||
m_containers[containerId] = nil
|
||||
end
|
||||
|
||||
function Containers.onContainerAddItem(containerId, item)
|
||||
print("addcid ".. containerId)
|
||||
local container = m_containers[containerId]
|
||||
if not container or not item or container.itemCount >= container.capacity then return end
|
||||
|
||||
-- maybe this has to be moved to client internal's files
|
||||
local pos = item:getPos()
|
||||
pos.z = container.itemCount
|
||||
item:setPos(pos)
|
||||
|
||||
local itemWidget = container:getChildByIndex(container.itemCount + 1)
|
||||
itemWidget:setItem(item)
|
||||
container.itemCount = container.itemCount + 1
|
||||
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = Containers.clean,
|
||||
onLogout = Containers.clean,
|
||||
onContainerOpen = Containers.onContainerOpen,
|
||||
onContainerClose = Containers.onContainerClose,
|
||||
onContainerAddItem = Containers.onContainerAddItem })
|
Reference in New Issue
Block a user