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