-
Notifications
You must be signed in to change notification settings - Fork 2
/
ammo_ammopicker.lua
65 lines (56 loc) · 2.09 KB
/
ammo_ammopicker.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--
-- Please see the LICENSE.md file included with this distribution for
-- attribution and copyright information.
--
-- luacheck: globals itemsheetname defaultvalue findItems
function findItems()
local aAutoFill = {}
table.insert(aAutoFill, Interface.getString(defaultvalue[1]))
local nodeInventory = DB.getChild(getDatabaseNode(), '.....inventorylist')
if nodeInventory then
for _, nodeItem in ipairs(DB.getChildList(nodeInventory)) do
if DB.getValue(nodeItem, 'carried', 0) ~= 0 and itemsheetname and type(itemsheetname[1]) == 'table' then
local sName = ItemManager.getDisplayName(nodeItem, true)
local nodeWeapon = DB.getChild(getDatabaseNode(), '...')
for _, v in ipairs(itemsheetname) do
if v.field and type(v.field) == 'table' and v.string and AmmunitionManager.isAmmo(nodeItem, nodeWeapon, v.field[1]) then
table.insert(aAutoFill, sName)
end
end
end
end
end
super.addItems(aAutoFill)
end
-- luacheck: globals setValue setTooltipText
function onInit()
if super then
if super.onInit then
super.onInit()
end
local function setListValue_new(sValue)
setValue(sValue)
setTooltipText(sValue)
super.refreshSelectionDisplay()
-- save node to weapon node when choosing ammo
local nodeWeapon = DB.getChild(getDatabaseNode(), '...')
local nodeInventory = DB.getChild(nodeWeapon, '...inventorylist')
local nodeAmmoManager = DB.getChild(nodeWeapon, 'ammunitionmanager')
if not nodeAmmoManager or not nodeInventory then
return
end
local sDefaultValue = Interface.getString(defaultvalue[1])
for _, nodeItem in ipairs(DB.getChildList(nodeInventory)) do
local sName = ItemManager.getDisplayName(nodeItem, true)
local sShortcutNodeName = DB.getName(getDatabaseNode()) .. 'shortcut'
if sValue == sDefaultValue then
DB.setValue(nodeAmmoManager, sShortcutNodeName, 'windowreference', 'item', '')
elseif sValue == sName then
DB.setValue(nodeAmmoManager, sShortcutNodeName, 'windowreference', 'item', '.....inventorylist.' .. DB.getName(nodeItem))
end
end
end
super.setListValue = setListValue_new
end
findItems()
end