multi-device input support in UI
This commit is contained in:
@@ -96,7 +96,7 @@ context.storage.turtleInventory = context.turtleInventory
|
||||
local function loadDirectory(dir)
|
||||
for _, file in pairs(fs.list(dir)) do
|
||||
if not fs.isDir(fs.combine(dir, file)) then
|
||||
local s, m = Util.run(_ENV, fs.combine(dir, file))
|
||||
local s, m = Util.run(_ENV, fs.combine(dir, file), context)
|
||||
if not s and m then
|
||||
_G.printError('Error loading: ' .. file)
|
||||
error(m or 'Unknown error')
|
||||
|
||||
@@ -131,7 +131,7 @@ local function turtleCraft(recipe, storage, request, count)
|
||||
if storage:export(storage.turtleInventory, k, count, item) ~= count then
|
||||
request.status = 'unknown error'
|
||||
request.statusCode = Craft.STATUS_ERROR
|
||||
_debug(item)
|
||||
_debug('failed to export: ' .. item.name)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,12 +69,13 @@ UI:getPage('nodeWizard').wizard:add({ activity = wizardPage })
|
||||
|
||||
--[[ Display ]]--
|
||||
local function createPage(node)
|
||||
local page = UI.Window {
|
||||
local page = UI.Page {
|
||||
parent = UI.Device {
|
||||
device = node.adapter,
|
||||
textScale = node.textScale or .5,
|
||||
},
|
||||
grid = UI.Grid {
|
||||
ey = -6,
|
||||
columns = {
|
||||
{ heading = 'Qty', key = 'count', width = 5 },
|
||||
{ heading = 'Change', key = 'change', width = 5 },
|
||||
@@ -83,6 +84,28 @@ local function createPage(node)
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
},
|
||||
buttons = UI.Window {
|
||||
y = -5, height = 5,
|
||||
backgroundColor = colors.gray,
|
||||
prevButton = UI.Button {
|
||||
x = 2, y = 2, height = 3, width = 5,
|
||||
event = 'previous',
|
||||
backgroundColor = colors.lightGray,
|
||||
text = ' < '
|
||||
},
|
||||
resetButton = UI.Button {
|
||||
x = 8, y = 2, height = 3, ex = -8,
|
||||
event = 'reset',
|
||||
backgroundColor = colors.lightGray,
|
||||
text = 'Reset'
|
||||
},
|
||||
nextButton = UI.Button {
|
||||
x = -6, y = 2, height = 3, width = 5,
|
||||
event = 'next',
|
||||
backgroundColor = colors.lightGray,
|
||||
text = ' > '
|
||||
},
|
||||
},
|
||||
timestamp = os.clock(),
|
||||
}
|
||||
|
||||
@@ -108,6 +131,27 @@ local function createPage(node)
|
||||
return row
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'reset' then
|
||||
self:reset()
|
||||
|
||||
elseif event.type == 'next' then
|
||||
self.grid:nextPage()
|
||||
|
||||
elseif event.type == 'previous' then
|
||||
self.grid:previousPage()
|
||||
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
|
||||
Event.onTimeout(.1, function()
|
||||
self:setFocus(self.grid)
|
||||
self:sync()
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
function page:reset()
|
||||
self.lastItems = nil
|
||||
self.grid:setValues({ })
|
||||
@@ -171,39 +215,12 @@ local function createPage(node)
|
||||
page:sync()
|
||||
end
|
||||
|
||||
page:enable()
|
||||
page:draw()
|
||||
page:sync()
|
||||
|
||||
UI:setPage(page)
|
||||
return page
|
||||
end
|
||||
|
||||
local pages = { }
|
||||
|
||||
Event.on('monitor_resize', function(_, side)
|
||||
for node in context.storage:filterActive('activity') do
|
||||
if node.name == side and pages[node.name] then
|
||||
local p = pages[node.name]
|
||||
p.parent:setTextScale(node.textScale or .5)
|
||||
p.parent:resize()
|
||||
p:resize()
|
||||
p:draw()
|
||||
p:sync()
|
||||
break
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on('monitor_touch', function(_, side)
|
||||
local function filter(node)
|
||||
return node.adapter.side == side and pages[node.name]
|
||||
end
|
||||
for node in context.storage:filterActive('activity', filter) do
|
||||
pages[node.name]:reset()
|
||||
pages[node.name]:sync()
|
||||
end
|
||||
end)
|
||||
|
||||
--[[ Task ]]--
|
||||
local ActivityTask = {
|
||||
name = 'activity',
|
||||
|
||||
@@ -2,6 +2,7 @@ local Craft = require('craft2')
|
||||
local Event = require('event')
|
||||
local itemDB = require('itemDB')
|
||||
local Milo = require('milo')
|
||||
local Sound = require('sound')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
@@ -74,6 +75,7 @@ local function createPage(node)
|
||||
textScale = node.textScale or .5,
|
||||
},
|
||||
grid = UI.Grid {
|
||||
ey = -6,
|
||||
sortColumn = 'index',
|
||||
columns = {
|
||||
{ heading = 'Qty', key = 'remaining', width = 4 },
|
||||
@@ -87,6 +89,28 @@ local function createPage(node)
|
||||
-- { heading = 'Progress', key = 'progress', width = 8 },
|
||||
},
|
||||
},
|
||||
buttons = UI.Window {
|
||||
y = -5, height = 5,
|
||||
backgroundColor = colors.gray,
|
||||
prevButton = UI.Button {
|
||||
x = 2, y = 2, height = 3, width = 5,
|
||||
event = 'previous',
|
||||
backgroundColor = colors.lightGray,
|
||||
text = ' < '
|
||||
},
|
||||
cancelButton = UI.Button {
|
||||
x = 8, y = 2, height = 3, ex = -8,
|
||||
event = 'cancel_job',
|
||||
backgroundColor = colors.lightGray,
|
||||
text = 'Cancel Job'
|
||||
},
|
||||
nextButton = UI.Button {
|
||||
x = -6, y = 2, height = 3, width = 5,
|
||||
event = 'next',
|
||||
backgroundColor = colors.lightGray,
|
||||
text = ' > '
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
function page:updateList(craftList)
|
||||
@@ -137,29 +161,37 @@ local function createPage(node)
|
||||
UI.Grid:getRowTextColor(row, selected)
|
||||
end
|
||||
|
||||
page:enable()
|
||||
page:draw()
|
||||
page:sync()
|
||||
-- no sorting allowed
|
||||
function page:setInverseSort() end
|
||||
function page:setSortColumn() end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'cancel_job' then
|
||||
Sound.play('entity.villager.no', .5)
|
||||
|
||||
elseif event.type == 'next' then
|
||||
self.grid:nextPage()
|
||||
|
||||
elseif event.type == 'previous' then
|
||||
self.grid:previousPage()
|
||||
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
|
||||
Event.onTimeout(.1, function()
|
||||
self:setFocus(self.grid)
|
||||
self:sync()
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
return page
|
||||
end
|
||||
|
||||
local pages = { }
|
||||
|
||||
Event.on('monitor_resize', function(_, side)
|
||||
for node in context.storage:filterActive('jobs') do
|
||||
if node.name == side and pages[node.name] then
|
||||
local p = pages[node.name]
|
||||
p.parent:setTextScale(node.textScale or .5)
|
||||
p.parent:resize()
|
||||
p:resize()
|
||||
p:draw()
|
||||
p:sync()
|
||||
break
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on({ 'milo_resume', 'milo_pause' }, function(_, reason)
|
||||
for node in context.storage:filterActive('jobs') do
|
||||
local page = pages[node.name]
|
||||
|
||||
@@ -17,7 +17,7 @@ end
|
||||
local page = UI.Page {
|
||||
titleBar = UI.TitleBar {
|
||||
backgroundColor = colors.gray,
|
||||
title = 'Auto send items to storage',
|
||||
title = 'Auto deposit items',
|
||||
previousPage = true,
|
||||
},
|
||||
tabs = UI.Tabs {
|
||||
@@ -33,7 +33,7 @@ local page = UI.Page {
|
||||
},
|
||||
},
|
||||
autostore = UI.Window {
|
||||
tabTitle = 'Sending',
|
||||
tabTitle = 'Deposit',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
@@ -154,7 +154,7 @@ Event.onInterval(5, function()
|
||||
end)
|
||||
|
||||
return {
|
||||
menuItem = 'Autostore',
|
||||
menuItem = 'Auto-deposit',
|
||||
callback = function()
|
||||
UI:setPage(page)
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user