milo: better monitor handling + assigning machines to items
This commit is contained in:
@@ -23,7 +23,7 @@ local gzipMagic = 0x1f8b
|
|||||||
local Spinner = class()
|
local Spinner = class()
|
||||||
function Spinner:init(args)
|
function Spinner:init(args)
|
||||||
local defaults = {
|
local defaults = {
|
||||||
timeout = .095,
|
timeout = .075,
|
||||||
c = os.clock(),
|
c = os.clock(),
|
||||||
spinIndex = 0,
|
spinIndex = 0,
|
||||||
spinSymbols = { '-', '/', '|', '\\' }
|
spinSymbols = { '-', '/', '|', '\\' }
|
||||||
|
|||||||
10
core/t.lua
10
core/t.lua
@@ -1,4 +1,6 @@
|
|||||||
function doCommand(command, moves)
|
local turtle = _G.turtle
|
||||||
|
|
||||||
|
local function doCommand(command, moves)
|
||||||
|
|
||||||
local function format(value)
|
local function format(value)
|
||||||
if type(value) == 'boolean' then
|
if type(value) == 'boolean' then
|
||||||
@@ -49,6 +51,8 @@ function doCommand(command, moves)
|
|||||||
[ 'r' ] = turtle.turnRight,
|
[ 'r' ] = turtle.turnRight,
|
||||||
[ 'l' ] = turtle.turnLeft,
|
[ 'l' ] = turtle.turnLeft,
|
||||||
[ 'ta' ] = turtle.turnAround,
|
[ 'ta' ] = turtle.turnAround,
|
||||||
|
[ 'el' ] = turtle.equipLeft,
|
||||||
|
[ 'er' ] = turtle.equipRight,
|
||||||
[ 'DD' ] = turtle.digDown,
|
[ 'DD' ] = turtle.digDown,
|
||||||
[ 'DU' ] = turtle.digUp,
|
[ 'DU' ] = turtle.digUp,
|
||||||
[ 'D' ] = turtle.dig,
|
[ 'D' ] = turtle.dig,
|
||||||
@@ -64,7 +68,7 @@ function doCommand(command, moves)
|
|||||||
if cmds[command] then
|
if cmds[command] then
|
||||||
runCommand(cmds[command], moves)
|
runCommand(cmds[command], moves)
|
||||||
elseif repCmds[command] then
|
elseif repCmds[command] then
|
||||||
for i = 1, moves do
|
for _ = 1, moves do
|
||||||
if not runCommand(repCmds[command]) then
|
if not runCommand(repCmds[command]) then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -79,7 +83,7 @@ if #args > 0 then
|
|||||||
else
|
else
|
||||||
print('Enter command (q to quit):')
|
print('Enter command (q to quit):')
|
||||||
while true do
|
while true do
|
||||||
local cmd = read()
|
local cmd = _G.read()
|
||||||
if cmd == 'q' then break
|
if cmd == 'q' then break
|
||||||
end
|
end
|
||||||
args = { }
|
args = { }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ local depositMode = {
|
|||||||
[ false ] = { text = '\215', textColor = colors.red, help = 'Deposit disabled' },
|
[ false ] = { text = '\215', textColor = colors.red, help = 'Deposit disabled' },
|
||||||
}
|
}
|
||||||
|
|
||||||
local displayMode = {
|
local displayModes = {
|
||||||
[0] = { text = 'A', help = 'Showing all items' },
|
[0] = { text = 'A', help = 'Showing all items' },
|
||||||
[1] = { text = 'I', help = 'Showing inventory items' },
|
[1] = { text = 'I', help = 'Showing inventory items' },
|
||||||
[2] = { text = 'C', help = 'Showing craftable items' },
|
[2] = { text = 'C', help = 'Showing craftable items' },
|
||||||
@@ -98,8 +98,8 @@ local page = UI.Page {
|
|||||||
display = UI.Button {
|
display = UI.Button {
|
||||||
x = -3,
|
x = -3,
|
||||||
event = 'toggle_display',
|
event = 'toggle_display',
|
||||||
text = displayMode[config.displayMode].text,
|
text = displayModes[config.displayMode].text,
|
||||||
help = displayMode[config.displayMode].help,
|
help = displayModes[config.displayMode].help,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
accelerators = {
|
accelerators = {
|
||||||
@@ -357,7 +357,7 @@ function page:eventHandler(event)
|
|||||||
|
|
||||||
elseif event.type == 'toggle_display' then
|
elseif event.type == 'toggle_display' then
|
||||||
config.displayMode = (config.displayMode + 1) % 3
|
config.displayMode = (config.displayMode + 1) % 3
|
||||||
Util.merge(event.button, displayMode[config.displayMode])
|
Util.merge(event.button, displayModes[config.displayMode])
|
||||||
event.button:draw()
|
event.button:draw()
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
self:setStatus(event.button.help)
|
self:setStatus(event.button.help)
|
||||||
|
|||||||
@@ -164,7 +164,6 @@ function Storage:listItems(throttle)
|
|||||||
return self.cache
|
return self.cache
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: is there any reason now to maintain 2 lists
|
|
||||||
local cache = { }
|
local cache = { }
|
||||||
throttle = throttle or Util.throttle()
|
throttle = throttle or Util.throttle()
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ local function turtleCraft(recipe, storage, request, count)
|
|||||||
for k,v in pairs(recipe.ingredients) do
|
for k,v in pairs(recipe.ingredients) do
|
||||||
local item = splitKey(v)
|
local item = splitKey(v)
|
||||||
if storage:export(storage.localName, k, count, item) ~= count then
|
if storage:export(storage.localName, k, count, item) ~= count then
|
||||||
-- TODO: FIX: ingredients cannot be stacked
|
|
||||||
request.status = 'unknown error'
|
request.status = 'unknown error'
|
||||||
request.statusCode = Craft.STATUS_ERROR
|
request.statusCode = Craft.STATUS_ERROR
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -438,14 +438,13 @@ function nodeWizard:enable(node)
|
|||||||
self.node.adapter = adapter
|
self.node.adapter = adapter
|
||||||
node.adapter = adapter
|
node.adapter = adapter
|
||||||
|
|
||||||
_G._p2 = self.node
|
_G._p3 = self.node
|
||||||
|
|
||||||
local choices = {
|
local choices = {
|
||||||
{ name = 'Ignore', value = 'ignore' },
|
{ name = 'Ignore', value = 'ignore' },
|
||||||
}
|
}
|
||||||
for _, page in pairs(self.wizard.pages) do
|
for _, page in pairs(self.wizard.pages) do
|
||||||
if page.isValidType then
|
if page.isValidType then
|
||||||
-- TODO: dedupe list
|
|
||||||
local choice = page:isValidType(self.node)
|
local choice = page:isValidType(self.node)
|
||||||
if choice and not Util.find(choices, 'value', choice.value) then
|
if choice and not Util.find(choices, 'value', choice.value) then
|
||||||
table.insert(choices, choice)
|
table.insert(choices, choice)
|
||||||
@@ -474,6 +473,10 @@ function nodeWizard:eventHandler(event)
|
|||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
elseif event.type == 'accept' then
|
elseif event.type == 'accept' then
|
||||||
|
|
||||||
|
local adapter = self.node.adapter
|
||||||
|
self.node.adapter = nil
|
||||||
|
|
||||||
Util.prune(self.node, function(v)
|
Util.prune(self.node, function(v)
|
||||||
if type(v) == 'boolean' then
|
if type(v) == 'boolean' then
|
||||||
return v
|
return v
|
||||||
@@ -487,13 +490,15 @@ function nodeWizard:eventHandler(event)
|
|||||||
|
|
||||||
Util.clear(context.config.nodes[self.node.name])
|
Util.clear(context.config.nodes[self.node.name])
|
||||||
Util.merge(context.config.nodes[self.node.name], self.node)
|
Util.merge(context.config.nodes[self.node.name], self.node)
|
||||||
|
context.config.nodes[self.node.name].adapter = adapter
|
||||||
|
|
||||||
saveConfig()
|
saveConfig()
|
||||||
|
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
elseif event.type == 'choice_change' then
|
elseif event.type == 'choice_change' then
|
||||||
local help
|
local help
|
||||||
if event.choice and event.choice.help then -- TODO: new param sent by UI api
|
if event.choice and event.choice.help then
|
||||||
help = event.choice.help
|
help = event.choice.help
|
||||||
else
|
else
|
||||||
help = ''
|
help = ''
|
||||||
|
|||||||
@@ -7,15 +7,12 @@ local Util = require('util')
|
|||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local monitor = context.storage:getSingleNode('activity')
|
|
||||||
|
|
||||||
--[[ Configuration Page ]]--
|
--[[ Configuration Page ]]--
|
||||||
local template =
|
local template =
|
||||||
[[%sDisplays the amount of items entering or leaving storage.%s
|
[[%sDisplays the amount of items entering or leaving storage.%s
|
||||||
|
|
||||||
Right-clicking on the activity monitor will reset the totals.
|
Right-clicking on the activity monitor will reset the totals.]]
|
||||||
|
|
||||||
%sMilo must be restarted to activate diplay.]]
|
|
||||||
|
|
||||||
local activityWizardPage = UI.Window {
|
local activityWizardPage = UI.Window {
|
||||||
title = 'Activity Monitor',
|
title = 'Activity Monitor',
|
||||||
@@ -24,7 +21,7 @@ local activityWizardPage = UI.Window {
|
|||||||
[1] = UI.TextArea {
|
[1] = UI.TextArea {
|
||||||
x = 2, ex = -2, y = 2, ey = -2,
|
x = 2, ex = -2, y = 2, ey = -2,
|
||||||
marginRight = 0,
|
marginRight = 0,
|
||||||
value = string.format(template, Ansi.yellow, Ansi.reset, Ansi.orange),
|
value = string.format(template, Ansi.yellow, Ansi.reset),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,13 +40,11 @@ end
|
|||||||
|
|
||||||
UI:getPage('nodeWizard').wizard:add({ activity = activityWizardPage })
|
UI:getPage('nodeWizard').wizard:add({ activity = activityWizardPage })
|
||||||
|
|
||||||
if not monitor then
|
--[[ Display ]]--
|
||||||
return
|
local function createPage(node)
|
||||||
end
|
local page = UI.Window {
|
||||||
|
|
||||||
local page = UI.Window {
|
|
||||||
parent = UI.Device {
|
parent = UI.Device {
|
||||||
device = monitor.adapter,
|
device = node.adapter,
|
||||||
textScale = .5,
|
textScale = .5,
|
||||||
},
|
},
|
||||||
grid = UI.Grid {
|
grid = UI.Grid {
|
||||||
@@ -61,16 +56,16 @@ local page = UI.Window {
|
|||||||
},
|
},
|
||||||
sortColumn = 'displayName',
|
sortColumn = 'displayName',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function page.grid:getRowTextColor(row, selected)
|
function page.grid:getRowTextColor(row, selected)
|
||||||
if row.lastCount and row.lastCount ~= row.count then
|
if row.lastCount and row.lastCount ~= row.count then
|
||||||
return row.count > row.lastCount and colors.yellow or colors.lightGray
|
return row.count > row.lastCount and colors.yellow or colors.lightGray
|
||||||
end
|
end
|
||||||
return UI.Grid:getRowTextColor(row, selected)
|
return UI.Grid:getRowTextColor(row, selected)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.grid:getDisplayValues(row)
|
function page.grid:getDisplayValues(row)
|
||||||
row = Util.shallowCopy(row)
|
row = Util.shallowCopy(row)
|
||||||
|
|
||||||
local ind = '+'
|
local ind = '+'
|
||||||
@@ -83,16 +78,16 @@ function page.grid:getDisplayValues(row)
|
|||||||
row.rate = Util.toBytes(row.rate)
|
row.rate = Util.toBytes(row.rate)
|
||||||
|
|
||||||
return row
|
return row
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:reset()
|
function page:reset()
|
||||||
self.lastItems = nil
|
self.lastItems = nil
|
||||||
self.grid:setValues({ })
|
self.grid:setValues({ })
|
||||||
self.grid:clear()
|
self.grid:clear()
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:refresh()
|
function page:refresh()
|
||||||
local t = context.storage.cache
|
local t = context.storage.cache
|
||||||
|
|
||||||
if not self.lastItems then
|
if not self.lastItems then
|
||||||
@@ -142,24 +137,32 @@ function page:refresh()
|
|||||||
self.grid:setValues(changedItems)
|
self.grid:setValues(changedItems)
|
||||||
end
|
end
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:update()
|
function page:update()
|
||||||
page:refresh()
|
page:refresh()
|
||||||
page:sync()
|
page:sync()
|
||||||
|
end
|
||||||
|
|
||||||
|
page:enable()
|
||||||
|
page:draw()
|
||||||
|
page:sync()
|
||||||
|
|
||||||
|
return page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local pages = { }
|
||||||
|
|
||||||
Event.on('monitor_touch', function(_, side)
|
Event.on('monitor_touch', function(_, side)
|
||||||
if side == monitor.adapter.side then
|
local function filter(node)
|
||||||
page:reset()
|
return node.adapter.name == side and pages[node.name]
|
||||||
page:sync()
|
end
|
||||||
|
for node in context.storage:filterActive('activity', filter) do
|
||||||
|
pages[node.name]:reset()
|
||||||
|
pages[node.name]:sync()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
page:enable()
|
|
||||||
page:draw()
|
|
||||||
page:sync()
|
|
||||||
|
|
||||||
--[[ Task ]]--
|
--[[ Task ]]--
|
||||||
local ActivityTask = {
|
local ActivityTask = {
|
||||||
name = 'activity',
|
name = 'activity',
|
||||||
@@ -167,7 +170,12 @@ local ActivityTask = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ActivityTask:cycle()
|
function ActivityTask:cycle()
|
||||||
page:update()
|
for node in context.storage:filterActive('activity') do
|
||||||
|
if not pages[node.name] then
|
||||||
|
pages[node.name] = createPage(node)
|
||||||
|
end
|
||||||
|
pages[node.name]:update()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Milo:registerTask(ActivityTask)
|
Milo:registerTask(ActivityTask)
|
||||||
|
|||||||
@@ -110,10 +110,10 @@ local itemPage = UI.Page {
|
|||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
titleBar = UI.TitleBar {
|
titleBar = UI.TitleBar {
|
||||||
title = 'Select Machine',
|
title = 'Select Machine',
|
||||||
previousPage = true,
|
event = 'cancel_machine',
|
||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 2, ey = -4,
|
y = 2, ey = -5,
|
||||||
disableHeader = true,
|
disableHeader = true,
|
||||||
values = context.config.nodes,
|
values = context.config.nodes,
|
||||||
columns = {
|
columns = {
|
||||||
@@ -122,13 +122,14 @@ local itemPage = UI.Page {
|
|||||||
sortColumn = 'displayName',
|
sortColumn = 'displayName',
|
||||||
},
|
},
|
||||||
button1 = UI.Button {
|
button1 = UI.Button {
|
||||||
x = -14, y = -2,
|
x = -14, y = -3,
|
||||||
text = 'Ok', event = 'set_machine',
|
text = 'Ok', event = 'set_machine',
|
||||||
},
|
},
|
||||||
button2 = UI.Button {
|
button2 = UI.Button {
|
||||||
x = -9, y = -2,
|
x = -9, y = -3,
|
||||||
text = 'Cancel', event = 'cancel_machine',
|
text = 'Cancel', event = 'cancel_machine',
|
||||||
},
|
},
|
||||||
|
statusBar = UI.StatusBar { values = 'Enter or double click to select' },
|
||||||
},
|
},
|
||||||
info = UI.SlideOut {
|
info = UI.SlideOut {
|
||||||
titleBar = UI.TitleBar {
|
titleBar = UI.TitleBar {
|
||||||
@@ -155,6 +156,8 @@ function itemPage:enable(item)
|
|||||||
self.form:setValues(self.res)
|
self.form:setValues(self.res)
|
||||||
self.titleBar.title = item.displayName or item.name
|
self.titleBar.title = item.displayName or item.name
|
||||||
|
|
||||||
|
self.form[6].inactive = not Craft.machineLookup[self.item.key]
|
||||||
|
|
||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
self:focusFirst()
|
self:focusFirst()
|
||||||
end
|
end
|
||||||
@@ -169,6 +172,13 @@ function itemPage.machines.grid:getDisplayValues(row)
|
|||||||
return row
|
return row
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function itemPage.machines.grid:getRowTextColor(row, selected)
|
||||||
|
if row.name == Craft.machineLookup[itemPage.item.key] then
|
||||||
|
return colors.yellow
|
||||||
|
end
|
||||||
|
return UI.Grid:getRowTextColor(row, selected)
|
||||||
|
end
|
||||||
|
|
||||||
function itemPage.rsControl:enable()
|
function itemPage.rsControl:enable()
|
||||||
local devices = self.form[1].choices
|
local devices = self.form[1].choices
|
||||||
Util.clear(devices)
|
Util.clear(devices)
|
||||||
@@ -227,8 +237,15 @@ function itemPage:eventHandler(event)
|
|||||||
|
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
|
elseif event.type == 'grid_select' then
|
||||||
|
Craft.machineLookup[self.item.key] = event.selected.name
|
||||||
|
self.machines.grid:draw()
|
||||||
|
|
||||||
elseif event.type == 'set_machine' then
|
elseif event.type == 'set_machine' then
|
||||||
--TODO save machine
|
local machine = self.machines.grid:getSelected()
|
||||||
|
if machine then
|
||||||
|
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
||||||
|
end
|
||||||
self.machines:hide()
|
self.machines:hide()
|
||||||
|
|
||||||
elseif event.type == 'cancel_machine' then
|
elseif event.type == 'cancel_machine' then
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
local Ansi = require('ansi')
|
|
||||||
local Craft = require('turtle.craft')
|
local Craft = require('turtle.craft')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
@@ -9,14 +8,8 @@ local Util = require('util')
|
|||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local monitor = context.storage:getSingleNode('jobs')
|
|
||||||
|
|
||||||
--[[ Configuration Screen ]]
|
--[[ Configuration Screen ]]
|
||||||
local template =
|
|
||||||
[[%sDisplays the crafting progress%s
|
|
||||||
|
|
||||||
%sMilo must be restarted to activate diplay.]]
|
|
||||||
|
|
||||||
local wizardPage = UI.Window {
|
local wizardPage = UI.Window {
|
||||||
title = 'Crafting Monitor',
|
title = 'Crafting Monitor',
|
||||||
index = 2,
|
index = 2,
|
||||||
@@ -24,7 +17,8 @@ local wizardPage = UI.Window {
|
|||||||
[1] = UI.TextArea {
|
[1] = UI.TextArea {
|
||||||
x = 2, ex = -2, y = 2, ey = -2,
|
x = 2, ex = -2, y = 2, ey = -2,
|
||||||
marginRight = 0,
|
marginRight = 0,
|
||||||
value = string.format(template, Ansi.yellow, Ansi.reset, Ansi.orange),
|
textColor = colors.yellow,
|
||||||
|
value = 'Displays the crafting progress.'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,15 +38,11 @@ end
|
|||||||
UI:getPage('nodeWizard').wizard:add({ jobs = wizardPage })
|
UI:getPage('nodeWizard').wizard:add({ jobs = wizardPage })
|
||||||
|
|
||||||
--[[ Display ]]
|
--[[ Display ]]
|
||||||
if not monitor then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TODO: some way to cancel a job
|
-- TODO: some way to cancel a job
|
||||||
|
local function createPage(node)
|
||||||
local jobMonitor = UI.Page {
|
local page = UI.Page {
|
||||||
parent = UI.Device {
|
parent = UI.Device {
|
||||||
device = monitor.adapter,
|
device = node.adapter,
|
||||||
textScale = .5,
|
textScale = .5,
|
||||||
},
|
},
|
||||||
grid = UI.Grid {
|
grid = UI.Grid {
|
||||||
@@ -63,16 +53,16 @@ local jobMonitor = UI.Page {
|
|||||||
{ heading = 'Crafting', key = 'displayName', },
|
{ heading = 'Crafting', key = 'displayName', },
|
||||||
{ heading = 'Status', key = 'status', },
|
{ heading = 'Status', key = 'status', },
|
||||||
{ heading = 'need', key = 'need', width = 4 },
|
{ heading = 'need', key = 'need', width = 4 },
|
||||||
-- { heading = 'total', key = 'total', width = 4 },
|
-- { heading = 'total', key = 'total', width = 4 },
|
||||||
-- { heading = 'used', key = 'used', width = 4 },
|
-- { heading = 'used', key = 'used', width = 4 },
|
||||||
-- { heading = 'count', key = 'count', width = 4 },
|
-- { heading = 'count', key = 'count', width = 4 },
|
||||||
{ heading = 'crafted', key = 'crafted', width = 5 },
|
{ heading = 'crafted', key = 'crafted', width = 5 },
|
||||||
-- { heading = 'Progress', key = 'progress', width = 8 },
|
-- { heading = 'Progress', key = 'progress', width = 8 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function jobMonitor:updateList(craftList)
|
function page:updateList(craftList)
|
||||||
if not Milo:isCraftingPaused() then
|
if not Milo:isCraftingPaused() then
|
||||||
local t = { }
|
local t = { }
|
||||||
for _,v in pairs(craftList) do
|
for _,v in pairs(craftList) do
|
||||||
@@ -93,9 +83,9 @@ function jobMonitor:updateList(craftList)
|
|||||||
self:draw()
|
self:draw()
|
||||||
self:sync()
|
self:sync()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function jobMonitor.grid:getDisplayValues(row)
|
function page.grid:getDisplayValues(row)
|
||||||
row = Util.shallowCopy(row)
|
row = Util.shallowCopy(row)
|
||||||
if not row.displayName then
|
if not row.displayName then
|
||||||
row.displayName = itemDB:getName(row)
|
row.displayName = itemDB:getName(row)
|
||||||
@@ -107,9 +97,9 @@ function jobMonitor.grid:getDisplayValues(row)
|
|||||||
end
|
end
|
||||||
--row.progress = string.format('%d/%d', row.crafted, row.count)
|
--row.progress = string.format('%d/%d', row.crafted, row.count)
|
||||||
return row
|
return row
|
||||||
end
|
end
|
||||||
|
|
||||||
function jobMonitor.grid:getRowTextColor(row, selected)
|
function page.grid:getRowTextColor(row, selected)
|
||||||
local statusColor = {
|
local statusColor = {
|
||||||
[ Craft.STATUS_ERROR ] = colors.red,
|
[ Craft.STATUS_ERROR ] = colors.red,
|
||||||
[ Craft.STATUS_WARNING ] = colors.orange,
|
[ Craft.STATUS_WARNING ] = colors.orange,
|
||||||
@@ -118,31 +108,45 @@ function jobMonitor.grid:getRowTextColor(row, selected)
|
|||||||
}
|
}
|
||||||
return row.statusCode and statusColor[row.statusCode] or
|
return row.statusCode and statusColor[row.statusCode] or
|
||||||
UI.Grid:getRowTextColor(row, selected)
|
UI.Grid:getRowTextColor(row, selected)
|
||||||
|
end
|
||||||
|
|
||||||
|
page:enable()
|
||||||
|
page:draw()
|
||||||
|
page:sync()
|
||||||
|
|
||||||
|
return page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local pages = { }
|
||||||
|
|
||||||
Event.on({ 'milo_resume', 'milo_pause' }, function(_, reason)
|
Event.on({ 'milo_resume', 'milo_pause' }, function(_, reason)
|
||||||
|
for node in context.storage:filterActive('jobs') do
|
||||||
|
local page = pages[node.name]
|
||||||
|
if page then
|
||||||
if reason then
|
if reason then
|
||||||
jobMonitor.grid:clear()
|
page.grid:clear()
|
||||||
jobMonitor.grid:centeredWrite(math.ceil(jobMonitor.grid.height / 2), reason.msg)
|
page.grid:centeredWrite(math.ceil(page.grid.height / 2), reason.msg)
|
||||||
else
|
else
|
||||||
jobMonitor.grid:draw()
|
page.grid:draw()
|
||||||
|
end
|
||||||
|
page:sync()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
jobMonitor:sync()
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
jobMonitor:enable()
|
|
||||||
jobMonitor:draw()
|
|
||||||
jobMonitor:sync()
|
|
||||||
|
|
||||||
--[[ Task ]]
|
--[[ Task ]]
|
||||||
local jobMonitorTask = {
|
local task = {
|
||||||
name = 'job status',
|
name = 'job status',
|
||||||
priority = 80,
|
priority = 80,
|
||||||
}
|
}
|
||||||
|
|
||||||
function jobMonitorTask:cycle()
|
function task:cycle()
|
||||||
jobMonitor:updateList(context.craftingQueue)
|
for node in context.storage:filterActive('jobs') do
|
||||||
|
if not pages[node.name] then
|
||||||
|
pages[node.name] = createPage(node)
|
||||||
|
end
|
||||||
|
pages[node.name]:updateList(context.craftingQueue)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Milo:registerTask(jobMonitorTask)
|
Milo:registerTask(task)
|
||||||
context.jobMonitor = jobMonitor
|
|
||||||
|
|||||||
@@ -7,8 +7,15 @@ local Util = require('util')
|
|||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
local displayMode = Milo:getState('displayMode') or 0
|
||||||
|
|
||||||
local function filterItems(t, filter, displayMode)
|
local displayModes = {
|
||||||
|
[0] = { text = 'A', help = 'Showing all items' },
|
||||||
|
[1] = { text = 'I', help = 'Showing inventory items' },
|
||||||
|
[2] = { text = 'C', help = 'Showing craftable items' },
|
||||||
|
}
|
||||||
|
|
||||||
|
local function filterItems(t, filter)
|
||||||
if filter or displayMode > 0 then
|
if filter or displayMode > 0 then
|
||||||
local r = { }
|
local r = { }
|
||||||
if filter then
|
if filter then
|
||||||
@@ -96,7 +103,8 @@ local listingPage = UI.Page {
|
|||||||
x = -3,
|
x = -3,
|
||||||
event = 'toggle_display',
|
event = 'toggle_display',
|
||||||
value = 0,
|
value = 0,
|
||||||
text = 'A',
|
text = displayModes[displayMode].text,
|
||||||
|
help = displayModes[displayMode].help,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
notification = UI.Notification(),
|
notification = UI.Notification(),
|
||||||
@@ -112,7 +120,6 @@ local listingPage = UI.Page {
|
|||||||
|
|
||||||
q = 'quit',
|
q = 'quit',
|
||||||
},
|
},
|
||||||
displayMode = 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function listingPage.statusBar:draw()
|
function listingPage.statusBar:draw()
|
||||||
@@ -197,18 +204,12 @@ function listingPage:eventHandler(event)
|
|||||||
self:setFocus(self.statusBar.filter)
|
self:setFocus(self.statusBar.filter)
|
||||||
|
|
||||||
elseif event.type == 'toggle_display' then
|
elseif event.type == 'toggle_display' then
|
||||||
local values = {
|
displayMode = (displayMode + 1) % 3
|
||||||
[0] = 'A',
|
Util.merge(event.button, displayModes[displayMode])
|
||||||
[1] = 'I',
|
|
||||||
[2] = 'C',
|
|
||||||
}
|
|
||||||
|
|
||||||
event.button.value = (event.button.value + 1) % 3
|
|
||||||
self.displayMode = event.button.value
|
|
||||||
event.button.text = values[event.button.value]
|
|
||||||
event.button:draw()
|
event.button:draw()
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
Milo:setState('displayMode', displayMode)
|
||||||
|
|
||||||
elseif event.type == 'learn' then
|
elseif event.type == 'learn' then
|
||||||
UI:setPage('learn')
|
UI:setPage('learn')
|
||||||
@@ -275,7 +276,7 @@ function listingPage:refresh(force)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function listingPage:applyFilter()
|
function listingPage:applyFilter()
|
||||||
local t = filterItems(self.allItems, self.filter, self.displayMode)
|
local t = filterItems(self.allItems, self.filter)
|
||||||
self.grid:setValues(t)
|
self.grid:setValues(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user