tibia-client/modules/game_inventory/inventory.lua

82 lines
2.1 KiB
Lua
Raw Normal View History

InventorySlotStyles = {
[InventorySlotHead] = "HeadSlot",
[InventorySlotNeck] = "NeckSlot",
[InventorySlotBack] = "BackSlot",
[InventorySlotBody] = "BodySlot",
[InventorySlotRight] = "RightSlot",
[InventorySlotLeft] = "LeftSlot",
[InventorySlotLeg] = "LegSlot",
[InventorySlotFeet] = "FeetSlot",
[InventorySlotFinger] = "FingerSlot",
[InventorySlotAmmo] = "AmmoSlot"
}
inventoryWindow = nil
inventoryPanel = nil
inventoryButton = nil
2011-11-10 06:29:25 +01:00
function init()
connect(LocalPlayer, { onInventoryChange = onInventoryChange })
connect(g_game, { onGameStart = refresh })
g_keyboard.bindKeyDown('Ctrl+I', toggle)
inventoryButton = modules.client_topmenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', '/images/topbuttons/inventory', toggle)
inventoryButton:setOn(true)
inventoryWindow = g_ui.loadUI('inventory', modules.game_interface.getRightPanel())
inventoryWindow:disableResize()
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
refresh()
2012-08-21 23:40:47 +02:00
inventoryWindow:setup()
2011-11-10 06:29:25 +01:00
end
function terminate()
disconnect(LocalPlayer, { onInventoryChange = onInventoryChange })
disconnect(g_game, { onGameStart = refresh })
2012-06-26 00:13:30 +02:00
g_keyboard.unbindKeyDown('Ctrl+I')
inventoryWindow:destroy()
inventoryButton:destroy()
end
function refresh()
local player = g_game.getLocalPlayer()
for i=InventorySlotFirst,InventorySlotLast do
2012-07-26 08:10:28 +02:00
if g_game.isOnline() then
onInventoryChange(player, i, player:getInventoryItem(i))
2012-04-27 22:35:39 +02:00
else
onInventoryChange(player, i, nil)
2012-04-27 22:35:39 +02:00
end
end
end
function toggle()
2012-06-21 21:31:22 +02:00
if inventoryButton:isOn() then
inventoryWindow:close()
inventoryButton:setOn(false)
else
inventoryWindow:open()
inventoryButton:setOn(true)
end
end
function onMiniWindowClose()
2012-06-21 21:31:22 +02:00
inventoryButton:setOn(false)
2011-11-10 06:29:25 +01:00
end
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
2012-07-26 08:10:28 +02:00
if slot >= InventorySlotPurse then return end
2012-03-28 13:46:15 +02:00
local itemWidget = inventoryPanel:getChildById('slot' .. slot)
2012-07-26 08:10:28 +02:00
if item then
itemWidget:setStyle('Item')
itemWidget:setItem(item)
else
itemWidget:setStyle(InventorySlotStyles[slot])
itemWidget:setItem(nil)
end
2011-11-10 06:29:25 +01:00
end