From 859977f75c0e9bb86768fab85133f919a0fd2a85 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 2 Jan 2019 10:34:31 -0500 Subject: [PATCH] multi-device input support in UI --- milo/Milo.lua | 2 +- milo/apis/craft2.lua | 2 +- milo/plugins/activityView.lua | 75 +++++++++++++++++++------------ milo/plugins/jobMonitor.lua | 66 ++++++++++++++++++++------- milo/plugins/remote/autostore.lua | 6 +-- 5 files changed, 100 insertions(+), 51 deletions(-) diff --git a/milo/Milo.lua b/milo/Milo.lua index 9bb37d9..c09cb7b 100644 --- a/milo/Milo.lua +++ b/milo/Milo.lua @@ -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') diff --git a/milo/apis/craft2.lua b/milo/apis/craft2.lua index 096616d..a9258e9 100644 --- a/milo/apis/craft2.lua +++ b/milo/apis/craft2.lua @@ -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 diff --git a/milo/plugins/activityView.lua b/milo/plugins/activityView.lua index 09263d2..4b0dbbe 100644 --- a/milo/plugins/activityView.lua +++ b/milo/plugins/activityView.lua @@ -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', diff --git a/milo/plugins/jobMonitor.lua b/milo/plugins/jobMonitor.lua index 0d34a47..95b2020 100644 --- a/milo/plugins/jobMonitor.lua +++ b/milo/plugins/jobMonitor.lua @@ -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] diff --git a/milo/plugins/remote/autostore.lua b/milo/plugins/remote/autostore.lua index 1c514fc..744ac5f 100644 --- a/milo/plugins/remote/autostore.lua +++ b/milo/plugins/remote/autostore.lua @@ -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,