Hotkeys for Fluid Containers

Hotkeys now save subType for fluid containers instead of always trying
to use item with subType 0.
master
Sam 11 years ago
parent e6977b1b43
commit 1b27a095a9

@ -216,6 +216,7 @@ function save()
hotkeys[child.keyCombo] = { hotkeys[child.keyCombo] = {
autoSend = child.autoSend, autoSend = child.autoSend,
itemId = child.itemId, itemId = child.itemId,
subType = child.subType,
useType = child.useType, useType = child.useType,
value = child.value value = child.value
} }
@ -266,6 +267,9 @@ function onChooseItemMouseRelease(self, mousePosition, mouseButton)
if item and currentHotkeyLabel then if item and currentHotkeyLabel then
currentHotkeyLabel.itemId = item:getId() currentHotkeyLabel.itemId = item:getId()
if item:isFluidContainer() then
currentHotkeyLabel.subType = item:getSubType()
end
if item:isMultiUse() then if item:isMultiUse() then
currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH currentHotkeyLabel.useType = HOTKEY_MANAGER_USEWITH
else else
@ -293,6 +297,7 @@ end
function clearObject() function clearObject()
currentHotkeyLabel.itemId = nil currentHotkeyLabel.itemId = nil
currentHotkeyLabel.subType = nil
currentHotkeyLabel.useType = nil currentHotkeyLabel.useType = nil
currentHotkeyLabel.autoSend = nil currentHotkeyLabel.autoSend = nil
currentHotkeyLabel.value = nil currentHotkeyLabel.value = nil
@ -340,12 +345,14 @@ function addKeyCombo(keyCombo, keySettings, focus)
hotkeyLabel.keyCombo = keyCombo hotkeyLabel.keyCombo = keyCombo
hotkeyLabel.autoSend = toboolean(keySettings.autoSend) hotkeyLabel.autoSend = toboolean(keySettings.autoSend)
hotkeyLabel.itemId = tonumber(keySettings.itemId) hotkeyLabel.itemId = tonumber(keySettings.itemId)
hotkeyLabel.subType = tonumber(keySettings.subType)
hotkeyLabel.useType = tonumber(keySettings.useType) hotkeyLabel.useType = tonumber(keySettings.useType)
if keySettings.value then hotkeyLabel.value = tostring(keySettings.value) end if keySettings.value then hotkeyLabel.value = tostring(keySettings.value) end
else else
hotkeyLabel.keyCombo = keyCombo hotkeyLabel.keyCombo = keyCombo
hotkeyLabel.autoSend = false hotkeyLabel.autoSend = false
hotkeyLabel.itemId = nil hotkeyLabel.itemId = nil
hotkeyLabel.subType = nil
hotkeyLabel.useType = nil hotkeyLabel.useType = nil
hotkeyLabel.value = '' hotkeyLabel.value = ''
end end
@ -375,8 +382,8 @@ function doKeyCombo(keyCombo)
modules.game_console.setTextEditText(hotKey.value) modules.game_console.setTextEditText(hotKey.value)
end end
elseif hotKey.useType == HOTKEY_MANAGER_USE then elseif hotKey.useType == HOTKEY_MANAGER_USE then
if g_game.getProtocolVersion() < 780 then if g_game.getProtocolVersion() < 780 or hotKey.subType then
local item = g_game.findPlayerItem(hotKey.itemId, -1) local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if item then if item then
g_game.use(item) g_game.use(item)
end end
@ -384,8 +391,8 @@ function doKeyCombo(keyCombo)
g_game.useInventoryItem(hotKey.itemId) g_game.useInventoryItem(hotKey.itemId)
end end
elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
if g_game.getProtocolVersion() < 780 then if g_game.getProtocolVersion() < 780 or hotKey.subType then
local item = g_game.findPlayerItem(hotKey.itemId, -1) local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if item then if item then
g_game.useWith(item, g_game.getLocalPlayer()) g_game.useWith(item, g_game.getLocalPlayer())
end end
@ -396,8 +403,8 @@ function doKeyCombo(keyCombo)
local attackingCreature = g_game.getAttackingCreature() local attackingCreature = g_game.getAttackingCreature()
if not attackingCreature then return end if not attackingCreature then return end
if not attackingCreature:getTile() then return end if not attackingCreature:getTile() then return end
if g_game.getProtocolVersion() < 780 then if g_game.getProtocolVersion() < 780 or hotKey.subType then
local item = g_game.findPlayerItem(hotKey.itemId, -1) local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if item then if item then
g_game.useWith(item, attackingCreature) g_game.useWith(item, attackingCreature)
end end
@ -406,8 +413,8 @@ function doKeyCombo(keyCombo)
end end
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
local item = Item.create(hotKey.itemId) local item = Item.create(hotKey.itemId)
if g_game.getProtocolVersion() < 780 then if g_game.getProtocolVersion() < 780 or hotKey.subType then
local tmpItem = g_game.findPlayerItem(hotKey.itemId, -1) local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if not tmpItem then return true end if not tmpItem then return true end
item = tmpItem item = tmpItem
end end
@ -455,6 +462,9 @@ function updateHotkeyForm(reset)
selectObjectButton:disable() selectObjectButton:disable()
clearObjectButton:enable() clearObjectButton:enable()
currentItemPreview:setItemId(currentHotkeyLabel.itemId) currentItemPreview:setItemId(currentHotkeyLabel.itemId)
if currentHotkeyLabel.subType then
currentItemPreview:setItemSubType(currentHotkeyLabel.subType)
end
if currentItemPreview:getItem():isMultiUse() then if currentItemPreview:getItem():isMultiUse() then
useOnSelf:enable() useOnSelf:enable()
useOnTarget:enable() useOnTarget:enable()

@ -450,10 +450,12 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Item>("clone", &Item::clone); g_lua.bindClassMemberFunction<Item>("clone", &Item::clone);
g_lua.bindClassMemberFunction<Item>("setCount", &Item::setCount); g_lua.bindClassMemberFunction<Item>("setCount", &Item::setCount);
g_lua.bindClassMemberFunction<Item>("getCount", &Item::getCount); g_lua.bindClassMemberFunction<Item>("getCount", &Item::getCount);
g_lua.bindClassMemberFunction<Item>("getSubType", &Item::getSubType);
g_lua.bindClassMemberFunction<Item>("getId", &Item::getId); g_lua.bindClassMemberFunction<Item>("getId", &Item::getId);
g_lua.bindClassMemberFunction<Item>("getName", &Item::getName); g_lua.bindClassMemberFunction<Item>("getName", &Item::getName);
g_lua.bindClassMemberFunction<Item>("isStackable", &Item::isStackable); g_lua.bindClassMemberFunction<Item>("isStackable", &Item::isStackable);
g_lua.bindClassMemberFunction<Item>("isMarketable", &Item::isMarketable); g_lua.bindClassMemberFunction<Item>("isMarketable", &Item::isMarketable);
g_lua.bindClassMemberFunction<Item>("isFluidContainer", &Item::isFluidContainer);
g_lua.bindClassMemberFunction<Item>("getMarketData", &Item::getMarketData); g_lua.bindClassMemberFunction<Item>("getMarketData", &Item::getMarketData);
g_lua.bindClassMemberFunction<Item>("getClothSlot", &Item::getClothSlot); g_lua.bindClassMemberFunction<Item>("getClothSlot", &Item::getClothSlot);

Loading…
Cancel
Save