milo: lock chest with multiple items

This commit is contained in:
kepler155c
2018-11-13 16:07:28 -05:00
parent 2af29c5d93
commit 6870378422
3 changed files with 62 additions and 23 deletions

View File

@@ -20,21 +20,25 @@ local storageView = UI.Window {
},
[2] = UI.Checkbox {
formLabel = 'Locked', formKey = 'lockWith',
help = 'Locks chest to a single item type',
help = 'Locks chest to current item types',
},
[3] = UI.Text {
x = 16, ex = -2, y = 3,
value = '',
},
[4] = UI.TextEntry {
[4] = UI.Checkbox {
formLabel = 'Void', formKey = 'void',
help = 'Void items if locked chest is full',
},
[5] = UI.TextEntry {
formLabel = 'Refresh', formKey = 'refreshInterval',
help = 'Refresh periodically',
shadowText = 'seconds between refresh',
limit = 4,
validate = 'numeric',
shadowText = 'seconds between refresh',
help = 'Refresh periodically',
},
[5] = UI.TextArea {
x = 12, ex = -2, y = 5,
[6] = UI.TextArea {
x = 12, ex = -2, y = 6,
textColor = colors.yellow,
value = 'Only specify if you are manually taking items out of this inventory. Value should be > 10',
},
@@ -53,9 +57,24 @@ local storageView = UI.Window {
},
}
function storageView:showLockTypes()
local types = { }
if self.node.lock then
if type(self.node.lock) == 'string' then
self.form[3].value = self.node.lock
return
end
for name in pairs(self.node.lock) do
table.insert(types, itemDB:getName(name))
end
end
self.form[3].value = table.concat(types, ', ')
end
function storageView:enable()
UI.Window.enable(self)
self:focusFirst()
self:showLockTypes()
end
function storageView:validate()
@@ -76,32 +95,34 @@ function storageView:isValidFor(node)
end
function storageView:setNode(node)
self.machine = node
self.node = node
self.form:setValues(node)
self.form[3].value = node.lock and itemDB:getName(node.lock) or ''
self:showLockTypes()
end
function storageView:eventHandler(event)
if event.type == 'checkbox_change' and event.element.formKey == 'lockWith' then
if event.checked then
if device[self.machine.name] and device[self.machine.name].list then
local _, slot = next(device[self.machine.name].list())
if slot then
self.machine.lock = itemDB:makeKey(slot)
self.form[3].value = itemDB:getName(slot)
else
if device[self.node.name] and device[self.node.name].list then
local lock = { }
for _, slot in pairs(device[self.node.name].list()) do
lock[itemDB:makeKey(slot)] = true
end
if not next(lock) then
self:emit({
type = 'general_error',
field = event.element,
message = 'The chest must contain the item to lock' })
message = 'The chest must contain the item(s) to lock' })
self.form[3].value = false
self.form[3]:draw()
else
self.node.lock = lock
end
end
else
self.machine.lock = nil
self.node.lock = nil
self.form[3].value = ''
end
self:showLockTypes()
self.form[3]:draw()
end
end