look on items

This commit is contained in:
Henrique Santiago
2012-01-02 22:10:39 -02:00
parent 7c28297397
commit 9fbdf3f5cb
12 changed files with 58 additions and 72 deletions

View File

@@ -3,17 +3,6 @@ Inventory = {}
-- private variables
local window = nil
local InventorySlotHead = 1
local InventorySlotNecklace = 2
local InventorySlotBackpack = 3
local InventorySlotArmor = 4
local InventorySlotRight = 5
local InventorySlotLeft = 6
local InventorySlotLegs = 7
local InventorySlotFeet = 8
local InventorySlotRing = 9
local InventorySlotAmmo = 10
-- public functions
function Inventory.create()
window = UI.display('inventory.otui', { parent = Game.gameRightPanel })
@@ -26,30 +15,7 @@ end
-- hooked events
function Inventory.onInventoryChange(slot, item)
local slotId
if slot == InventorySlotHead then
slotId = 'head'
elseif slot == InventorySlotNecklace then
slotId = 'necklace'
elseif slot == InventorySlotBackpack then
slotId = 'backpack'
elseif slot == InventorySlotArmor then
slotId = 'armor'
elseif slot == InventorySlotRight then
slotId = 'right'
elseif slot == InventorySlotLeft then
slotId = 'left'
elseif slot == InventorySlotLegs then
slotId = 'legs'
elseif slot == InventorySlotFeet then
slotId = 'feet'
elseif slot == InventorySlotRing then
slotId = 'ring'
elseif slot == InventorySlotAmmo then
slotId = 'ammo'
end
local itemWidget = window:getChildById(slotId)
local itemWidget = window:getChildById('slot' .. slot)
itemWidget:setItem(item)
end
@@ -64,18 +30,19 @@ function Inventory.onSoulChange(soul)
end
function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
if mouseButton ~= MouseRightButton then
return
end
if mouseButton ~= MouseRightButton then return end
local item = itemWidget:getItem()
if not item then
return
end
if not item then return end
local menu = UIPopupMenu.create()
menu:addOption('Look', function() print('look') end)
-- Look
local itemId = item:getId()
local slotId = tonumber(itemWidget:getId():sub(5))
menu:addOption('Look', function() Game.lookAtInventory(itemId, slotId) end)
-- Open or Use, depending if thing is a container
if item:isContainer() then
menu:addOption('Open', function() print('open') end)
else

View File

@@ -10,72 +10,82 @@ UIWindow
move-policy: free updated
InvetoryItem
id: head
// head
id: slot1
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
InvetoryItem
id: armor
// armor
id: slot4
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5
InvetoryItem
id: legs
// legs
id: slot7
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5
InvetoryItem
id: feet
// feet
id: slot8
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5
InvetoryItem
id: necklace
// necklace
id: slot2
anchors.top: parent.top
anchors.right: head.left
anchors.right: slot1.left
margin-top: 10
margin-right: 5
InvetoryItem
id: left
// left
id: slot6
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5
InvetoryItem
id: ring
// ring
id: slot9
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5
InvetoryItem
id: backpack
// backpack
id: slot3
anchors.top: parent.top
anchors.left: head.right
anchors.left: slot1.right
margin-top: 10
margin-left: 5
InvetoryItem
id: right
// right
id: slot5
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5
InvetoryItem
id: ammo
// ammo
id: slot10
anchors.top: prev.bottom
anchors.horizontalCenter: prev.horizontalCenter
margin-top: 5
Label
id: soul
anchors.top: ring.bottom
anchors.bottom: feet.bottom
anchors.left: ring.left
anchors.right: ring.right
anchors.top: slot9.bottom
anchors.bottom: slot8.bottom
anchors.left: slot9.left
anchors.right: slot9.right
margin-top: 5
text-align: center
@@ -86,10 +96,10 @@ UIWindow
Label
id: capacity
anchors.top: ammo.bottom
anchors.bottom: feet.bottom
anchors.left: ammo.left
anchors.right: ammo.right
anchors.top: slot10.bottom
anchors.bottom: slot8.bottom
anchors.left: slot10.left
anchors.right: slot10.right
margin-top: 5
text-align: center