2012-07-10 14:15:31 +02:00
|
|
|
InventorySlotStyles = {
|
|
|
|
[InventorySlotHead] = "HeadSlot",
|
|
|
|
[InventorySlotNeck] = "NeckSlot",
|
|
|
|
[InventorySlotBack] = "BackSlot",
|
|
|
|
[InventorySlotBody] = "BodySlot",
|
|
|
|
[InventorySlotRight] = "RightSlot",
|
|
|
|
[InventorySlotLeft] = "LeftSlot",
|
|
|
|
[InventorySlotLeg] = "LegSlot",
|
|
|
|
[InventorySlotFeet] = "FeetSlot",
|
|
|
|
[InventorySlotFinger] = "FingerSlot",
|
|
|
|
[InventorySlotAmmo] = "AmmoSlot"
|
|
|
|
}
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
inventoryWindow = nil
|
|
|
|
inventoryPanel = nil
|
|
|
|
inventoryButton = nil
|
2014-03-12 15:46:35 +01:00
|
|
|
purseButton = nil
|
2011-11-10 06:29:25 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function init()
|
2014-12-29 18:08:13 +01:00
|
|
|
connect(LocalPlayer, {
|
|
|
|
onInventoryChange = onInventoryChange,
|
|
|
|
onBlessingsChange = onBlessingsChange
|
|
|
|
})
|
2012-07-24 07:30:08 +02:00
|
|
|
connect(g_game, { onGameStart = refresh })
|
2012-03-23 14:48:05 +01:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+I', toggle)
|
2012-03-23 14:48:05 +01:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
inventoryButton = modules.client_topmenu.addRightGameToggleButton('inventoryButton', tr('Inventory') .. ' (Ctrl+I)', '/images/topbuttons/inventory', toggle)
|
2012-08-21 07:35:08 +02:00
|
|
|
inventoryButton:setOn(true)
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
inventoryWindow = g_ui.loadUI('inventory', modules.game_interface.getRightPanel())
|
2012-07-13 01:40:55 +02:00
|
|
|
inventoryWindow:disableResize()
|
2012-03-28 16:10:21 +02:00
|
|
|
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
|
2012-03-23 14:48:05 +01:00
|
|
|
|
2014-03-12 15:46:35 +01:00
|
|
|
purseButton = inventoryPanel:getChildById('purseButton')
|
|
|
|
local function purseFunction()
|
|
|
|
local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
|
|
|
|
if purse then
|
|
|
|
g_game.use(purse)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
purseButton.onClick = purseFunction
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
refresh()
|
2012-08-21 23:40:47 +02:00
|
|
|
inventoryWindow:setup()
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function terminate()
|
2014-12-29 18:08:13 +01:00
|
|
|
disconnect(LocalPlayer, {
|
|
|
|
onInventoryChange = onInventoryChange,
|
|
|
|
onBlessingsChange = onBlessingsChange
|
|
|
|
})
|
2012-07-24 07:30:08 +02:00
|
|
|
disconnect(g_game, { onGameStart = refresh })
|
2012-03-23 14:48:05 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.unbindKeyDown('Ctrl+I')
|
2012-03-23 14:48:05 +01:00
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
inventoryWindow:destroy()
|
2013-02-01 05:32:15 +01:00
|
|
|
inventoryButton:destroy()
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
|
|
|
|
2014-12-29 18:08:13 +01:00
|
|
|
function toggleAdventurerStyle(hasBlessing)
|
|
|
|
for slot = InventorySlotFirst, InventorySlotLast do
|
|
|
|
local itemWidget = inventoryPanel:getChildById('slot' .. slot)
|
|
|
|
if itemWidget then
|
2015-01-19 01:52:49 +01:00
|
|
|
itemWidget:setOn(hasBlessing)
|
2014-12-29 18:08:13 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function refresh()
|
2012-04-27 08:30:54 +02:00
|
|
|
local player = g_game.getLocalPlayer()
|
2014-03-12 15:46:35 +01:00
|
|
|
for i = InventorySlotFirst, InventorySlotPurse do
|
2012-07-26 08:10:28 +02:00
|
|
|
if g_game.isOnline() then
|
2012-07-24 07:30:08 +02:00
|
|
|
onInventoryChange(player, i, player:getInventoryItem(i))
|
2012-04-27 22:35:39 +02:00
|
|
|
else
|
2012-07-24 07:30:08 +02:00
|
|
|
onInventoryChange(player, i, nil)
|
2012-04-27 22:35:39 +02:00
|
|
|
end
|
2014-12-30 16:40:03 +01:00
|
|
|
toggleAdventurerStyle(player and Bit.hasBit(player:getBlessings(), Blessings.Adventurer) or false)
|
2012-04-27 08:30:54 +02:00
|
|
|
end
|
2014-03-12 15:46:35 +01:00
|
|
|
|
|
|
|
purseButton:setVisible(g_game.getFeature(GamePurseSlot))
|
2012-04-27 08:30:54 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
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
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onMiniWindowClose()
|
2012-06-21 21:31:22 +02:00
|
|
|
inventoryButton:setOn(false)
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- hooked events
|
2012-07-24 07:30:08 +02:00
|
|
|
function onInventoryChange(player, slot, item, oldItem)
|
2014-03-12 15:46:35 +01:00
|
|
|
if slot > InventorySlotPurse then return end
|
|
|
|
|
|
|
|
if slot == InventorySlotPurse then
|
|
|
|
if g_game.getFeature(GamePurseSlot) then
|
|
|
|
purseButton:setEnabled(item and true or false)
|
|
|
|
end
|
|
|
|
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
|
2015-01-19 01:52:49 +01:00
|
|
|
itemWidget:setStyle('InventoryItem')
|
2012-07-10 14:15:31 +02:00
|
|
|
itemWidget:setItem(item)
|
|
|
|
else
|
|
|
|
itemWidget:setStyle(InventorySlotStyles[slot])
|
|
|
|
itemWidget:setItem(nil)
|
|
|
|
end
|
2011-11-10 06:29:25 +01:00
|
|
|
end
|
2014-12-29 18:08:13 +01:00
|
|
|
|
|
|
|
function onBlessingsChange(player, blessings, oldBlessings)
|
|
|
|
local hasAdventurerBlessing = Bit.hasBit(blessings, Blessings.Adventurer)
|
|
|
|
if hasAdventurerBlessing ~= Bit.hasBit(oldBlessings, Blessings.Adventurer) then
|
|
|
|
toggleAdventurerStyle(hasAdventurerBlessing)
|
|
|
|
end
|
|
|
|
end
|