This commit is contained in:
kepler155c
2018-11-15 12:17:50 -05:00
parent 560b9e42c9
commit 3e756abe42
10 changed files with 118 additions and 95 deletions

View File

@@ -145,20 +145,10 @@ function page:refresh()
end
function page:update()
if context.storage:isOnline() then
page:refresh()
page:sync()
else
page.grid:clear()
page.grid:centeredWrite(math.ceil(page.height / 2), 'Storage Offline')
page:sync()
end
page:refresh()
page:sync()
end
Event.on({ 'storage_offline', 'storage_online' }, function()
page:update()
end)
Event.on('monitor_touch', function(_, side)
if side == monitor.adapter.side then
page:reset()
@@ -166,6 +156,7 @@ Event.on('monitor_touch', function(_, side)
end
end)
page:enable()
page:draw()
page:sync()

View File

@@ -1,14 +1,15 @@
local Ansi = require('ansi')
local Craft = require('turtle.craft')
local itemDB = require('itemDB')
local Milo = require('milo')
local UI = require('ui')
local Util = require('util')
local Ansi = require('ansi')
local Craft = require('turtle.craft')
local Event = require('event')
local itemDB = require('itemDB')
local Milo = require('milo')
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local context = Milo:getContext()
local device = _G.device
local monitor = context.storage:getSingleNode('jobs')
local colors = _G.colors
local context = Milo:getContext()
local device = _G.device
local monitor = context.storage:getSingleNode('jobs')
--[[ Configuration Screen ]]
local template =
@@ -16,7 +17,7 @@ local template =
%sMilo must be restarted to activate diplay.]]
local jobsWizardPage = UI.Window {
local wizardPage = UI.Window {
title = 'Crafting Monitor',
index = 2,
backgroundColor = colors.cyan,
@@ -27,7 +28,7 @@ local jobsWizardPage = UI.Window {
},
}
function jobsWizardPage:isValidType(node)
function wizardPage:isValidType(node)
local m = device[node.name]
return m and m.type == 'monitor' and {
name = 'Crafting Monitor',
@@ -36,11 +37,11 @@ function jobsWizardPage:isValidType(node)
}
end
function jobsWizardPage:isValidFor(node)
function wizardPage:isValidFor(node)
return node.mtype == 'jobs'
end
UI:getPage('nodeWizard').wizard:add({ jobs = jobsWizardPage })
UI:getPage('nodeWizard').wizard:add({ jobs = wizardPage })
--[[ Display ]]
if not monitor then
@@ -61,22 +62,16 @@ local jobMonitor = UI.Page {
{ heading = 'Qty', key = 'remaining', width = 4 },
{ heading = 'Crafting', key = 'displayName', },
{ heading = 'Status', key = 'status', },
{ heading = 'need', key = 'need', width = 4 },
{ heading = 'total', key = 'total', width = 4 },
{ heading = 'used', key = 'used', width = 4 },
{ heading = 'count', key = 'count', width = 4 },
-- { heading = 'need', key = 'need', width = 4 },
-- { heading = 'total', key = 'total', width = 4 },
-- { heading = 'used', key = 'used', width = 4 },
-- { heading = 'count', key = 'count', width = 4 },
{ heading = 'crafted', key = 'crafted', width = 4 },
-- { heading = 'Progress', key = 'progress', width = 8 },
},
},
}
function jobMonitor:showError(msg)
self.grid:clear()
self.grid:centeredWrite(math.ceil(self.grid.height / 2), msg)
self:sync()
end
function jobMonitor:updateList(craftList)
if not Milo:isCraftingPaused() then
local t = { }
@@ -125,6 +120,16 @@ function jobMonitor.grid:getRowTextColor(row, selected)
UI.Grid:getRowTextColor(row, selected)
end
Event.on({ 'milo_resume', 'milo_pause' }, function(_, reason)
if reason then
jobMonitor.grid:clear()
jobMonitor.grid:centeredWrite(math.ceil(jobMonitor.grid.height / 2), reason.msg)
else
jobMonitor.grid:draw()
end
jobMonitor:sync()
end)
jobMonitor:enable()
jobMonitor:draw()
jobMonitor:sync()

View File

@@ -36,7 +36,7 @@ function learnPage:enable()
Milo:getState('learnType') or
self.chooser.choices[1].value
Milo:pauseCrafting()
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
sync.lock(turtle)
self:focusFirst()
@@ -50,7 +50,7 @@ end
function learnPage:eventHandler(event)
if event.type == 'cancel' then
sync.release(turtle)
Milo:resumeCrafting()
Milo:resumeCrafting({ key = 'gridInUse' })
UI:setPreviousPage()
elseif event.type == 'accept' then

View File

@@ -224,6 +224,7 @@ end
function listingPage:enable()
self:refresh()
self:setFocus(self.statusBar.filter)
self.timer = Event.onInterval(3, function()
for _,v in pairs(self.allItems) do
local c = context.storage.cache[v.key]
@@ -232,11 +233,22 @@ function listingPage:enable()
self.grid:draw()
self:sync()
end)
self.handler = Event.on({ 'storage_offline', 'storage_online' }, function(_, isOnline)
self.statusBar.storageStatus.value =
isOnline and '' or 'offline'
self.statusBar.storageStatus.textColor =
isOnline and colors.lime or colors.red
self.statusBar.storageStatus:draw()
self:sync()
end)
UI.Page.enable(self)
end
function listingPage:disable()
Event.off(self.timer)
Event.off(self.handler)
UI.Page.disable(self)
end
@@ -250,14 +262,4 @@ function listingPage:applyFilter()
self.grid:setValues(t)
end
Event.on({ 'storage_offline', 'storage_online' }, function(e, isOnline)
-- TODO: Fix button
listingPage.statusBar.storageStatus.value =
isOnline and '' or 'offline'
listingPage.statusBar.storageStatus.textColor =
isOnline and colors.lime or colors.red
listingPage.statusBar.storageStatus:draw()
listingPage:sync()
end)
UI:addPage('listing', listingPage)

View File

@@ -135,7 +135,7 @@ function pages.confirmation:validate()
end
function machineLearnWizard:disable()
Milo:resumeCrafting()
Milo:resumeCrafting({ key = 'gridInUse' })
sync.release(turtle)
UI.Page.disable(self)
end

View File

@@ -124,7 +124,7 @@ local turtleLearnWizard = UI.Page {
}
function turtleLearnWizard:disable()
Milo:resumeCrafting()
Milo:resumeCrafting({ key = 'gridInUse' })
sync.release(turtle)
UI.Page.disable(self)
end