Implement purse slot (closes #208), add version 10.37 (could not find protocol changes)

This commit is contained in:
Sam
2014-03-12 15:46:35 +01:00
parent 8d8f32b081
commit a58a3e90c8
5 changed files with 40 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ InventorySlotStyles = {
inventoryWindow = nil
inventoryPanel = nil
inventoryButton = nil
purseButton = nil
function init()
connect(LocalPlayer, { onInventoryChange = onInventoryChange })
@@ -28,6 +29,16 @@ function init()
inventoryWindow:disableResize()
inventoryPanel = inventoryWindow:getChildById('contentsPanel')
purseButton = inventoryPanel:getChildById('purseButton')
local function purseFunction()
local purse = g_game.getLocalPlayer():getInventoryItem(InventorySlotPurse)
if purse then
print(purse:getId())
g_game.use(purse)
end
end
purseButton.onClick = purseFunction
refresh()
inventoryWindow:setup()
end
@@ -44,13 +55,15 @@ end
function refresh()
local player = g_game.getLocalPlayer()
for i=InventorySlotFirst,InventorySlotLast do
for i = InventorySlotFirst, InventorySlotPurse do
if g_game.isOnline() then
onInventoryChange(player, i, player:getInventoryItem(i))
else
onInventoryChange(player, i, nil)
end
end
purseButton:setVisible(g_game.getFeature(GamePurseSlot))
end
function toggle()
@@ -69,7 +82,15 @@ end
-- hooked events
function onInventoryChange(player, slot, item, oldItem)
if slot >= InventorySlotPurse then return end
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
local itemWidget = inventoryPanel:getChildById('slot' .. slot)
if item then
itemWidget:setStyle('Item')