deposit toggle

This commit is contained in:
kepler155c
2018-11-17 17:34:26 -05:00
parent b73775ad93
commit 72f23d4814

View File

@@ -16,10 +16,21 @@ local SHIELD_SLOT = 2
local config = Config.load('miloRemote', { }) local config = Config.load('miloRemote', { })
local depositMode = {
[ true ] = { text = '\25', textColor = colors.black, help = 'Deposit enabled' },
[ false ] = { text = '\215', textColor = colors.red, help = 'Deposit disabled' },
}
local page = UI.Page { local page = UI.Page {
menuBar = UI.MenuBar { menuBar = UI.MenuBar {
y = 1, height = 1, y = 1, height = 1,
buttons = { buttons = {
{
name = 'depositToggle',
text = '\215',
x = -15,
event = 'toggle_deposit'
},
{ {
text = 'Refresh', text = 'Refresh',
x = -12, x = -12,
@@ -40,7 +51,7 @@ local page = UI.Page {
}, },
}, },
infoBar = UI.StatusBar { infoBar = UI.StatusBar {
x = 1, ex = -13, x = 1, ex = -16,
backgroundColor = colors.lightGray, backgroundColor = colors.lightGray,
}, },
}, },
@@ -274,6 +285,13 @@ function page:eventHandler(event)
self.setup.form:setValues(config) self.setup.form:setValues(config)
self.setup:show() self.setup:show()
elseif event.type == 'toggle_deposit' then
config.deposit = not config.deposit
Util.merge(self.menuBar.depositToggle, depositMode[config.deposit])
self.menuBar:draw()
self:setStatus(depositMode[config.deposit].help)
Config.update('miloRemote', config)
elseif event.type == 'form_complete' then elseif event.type == 'form_complete' then
Config.update('miloRemote', config) Config.update('miloRemote', config)
self.setup:hide() self.setup:hide()
@@ -362,6 +380,7 @@ end
function page:enable() function page:enable()
self:setFocus(self.statusBar.filter) self:setFocus(self.statusBar.filter)
Util.merge(self.menuBar.depositToggle, depositMode[config.deposit])
UI.Page.enable(self) UI.Page.enable(self)
if not config.server then if not config.server then
self.setup:show() self.setup:show()
@@ -390,28 +409,30 @@ end
Event.addRoutine(function() Event.addRoutine(function()
while true do while true do
os.sleep(1.5) os.sleep(1.5)
local neural = device.neuralInterface if config.deposit then
local inv = config.useShield and 'getEquipment' or 'getInventory' local neural = device.neuralInterface
if not neural or not neural[inv] then local inv = config.useShield and 'getEquipment' or 'getInventory'
_G._debug('missing Introspection module') if not neural or not neural[inv] then
elseif config.server and (config.useShield or config.slot) then _G._debug('missing Introspection module')
local method = neural[inv] elseif config.server and (config.useShield or config.slot) then
local item = method and method().getItemMeta(config.useShield and SHIELD_SLOT or config.slot) local method = neural[inv]
if item then local item = method and method().getItemMeta(config.useShield and SHIELD_SLOT or config.slot)
local slotNo = config.useShield and 'shield' or config.slot if item then
local response = page:sendRequest({ local slotNo = config.useShield and 'shield' or config.slot
request = 'deposit', local response = page:sendRequest({
slot = slotNo, request = 'deposit',
count = item.count, slot = slotNo,
key = table.concat({ item.name, item.damage, item.nbtHash }, ':') count = item.count,
}) key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
if response then })
local ritem = page.items[response.key] if response then
if ritem then local ritem = page.items[response.key]
ritem.count = response.current + item.count if ritem then
ritem.count = response.current + item.count
end
page.grid:draw()
page:sync()
end end
page.grid:draw()
page:sync()
end end
end end
end end