diff --git a/builder/builder.lua b/builder/builder.lua index 0c39cb8..7e7638f 100644 --- a/builder/builder.lua +++ b/builder/builder.lua @@ -236,10 +236,7 @@ function substitutionPage.info:draw() end self:clear() - self:setCursorPos(1, 1) - self:print(' Replace ' .. inName .. '\n') - --self:print(' ' .. sub.id .. ':' .. sub.dmg .. '\n', nil, colors.yellow) - self:print(' With ' .. outName) + self:print(' Replace ' .. inName .. '\n' .. ' With ' .. outName) end function substitutionPage:enable() @@ -536,7 +533,7 @@ local startPage = UI.Page { event = 'setStartLevel', cancelEvent = 'slide_hide', text = UI.Text { - x = 5, y = 1, width = 20, + x = 5, y = 1, width = 10, textColor = colors.gray, }, textEntry = UI.TextEntry { @@ -554,7 +551,7 @@ local startPage = UI.Page { event = 'setStartBlock', cancelEvent = 'slide_hide', text = UI.Text { - x = 2, y = 1, width = 20, + x = 2, y = 1, width = 13, textColor = colors.gray, }, textEntry = UI.TextEntry { diff --git a/common/Appstore.lua b/common/Appstore.lua index 7a5856f..2bbb521 100644 --- a/common/Appstore.lua +++ b/common/Appstore.lua @@ -211,9 +211,7 @@ function appPage.container.viewport:draw() Ansi.yellow .. app.description .. Ansi.reset) self:clear() - self:setCursorPos(1, 1) self:print(str) - self.ymax = self.cursorY if appPage.notification.enabled then appPage.notification:draw() @@ -369,4 +367,3 @@ categoryPage:setCategory(source.name, source.index) UI:setPage(categoryPage) UI:pullEvents() -UI.term:reset() diff --git a/common/Devices.lua b/common/Devices.lua index 6ad2f08..0415291 100644 --- a/common/Devices.lua +++ b/common/Devices.lua @@ -68,7 +68,7 @@ local methodsPage = UI.Page { grid = UI.ScrollingGrid { y = -6, ey = -2, columns = { - { heading = 'Name', key = 'name', width = UI.term.width } + { heading = 'Name', key = 'name' } }, sortColumn = 'name', }, diff --git a/common/DiskCopy.lua b/common/DiskCopy.lua index 849dbe3..a0d41ef 100644 --- a/common/DiskCopy.lua +++ b/common/DiskCopy.lua @@ -122,7 +122,6 @@ function page:drawInfo(drive, textArea) return isValid(drive) and fs.getFreeSpace(drive.getMountPath()) or 0 end - textArea:setCursorPos(1, 1) textArea:print(string.format('Drive: %s%s%s\nLabel: %s%s%s\nUsed: %s%s%s\nFree: %s%s%s', Ansi.yellow, drive.name, Ansi.reset, isValid(drive) and Ansi.yellow or Ansi.orange, getLabel():sub(1, 10), Ansi.reset, diff --git a/common/Turtles.lua b/common/Turtles.lua index f27a004..947ec62 100644 --- a/common/Turtles.lua +++ b/common/Turtles.lua @@ -2,7 +2,6 @@ local Config = require('opus.config') local Event = require('opus.event') local itemDB = require('core.itemDB') local Socket = require('opus.socket') -local Terminal = require('opus.terminal') local UI = require('opus.ui') local Util = require('opus.util') @@ -11,10 +10,7 @@ local fs = _G.fs local multishell = _ENV.multishell local network = _G.network local os = _G.os -local shell = _ENV.shell -local term = _G.term ---UI.Button.defaults.focusIndicator = ' ' UI:configure('Turtles', ...) local config = { } @@ -31,13 +27,26 @@ local options = { local SCRIPTS_PATH = 'packages/common/etc/scripts' -local nullTerm = Terminal.getNullTerm(term.current()) -local socket +local socket, turtle, page -local page = UI.Page { +page = UI.Page { coords = UI.Window { backgroundColor = colors.black, height = 3, + marginTop = 1, marginLeft = 1, + draw = function(self) + local t = turtle + self:clear() + if t then + self:setCursorPos(2, 2) + local ind = 'GPS' + if not t.point.gps then + ind = 'REL' + end + self:print(string.format('%s : %d,%d,%d', + ind, t.point.x, t.point.y, t.point.z)) + end + end, }, tabs = UI.Tabs { x = 1, y = 4, ey = -2, @@ -50,6 +59,23 @@ local page = UI.Page { disableHeader = true, sortColumn = 'label', autospace = true, + draw = function(self) + Util.clear(self.values) + local files = fs.list(SCRIPTS_PATH) + for _,path in pairs(files) do + table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) }) + end + self:update() + UI.ScrollingGrid.draw(self) + end, + eventHandler = function(self, event) + if event.type == 'grid_select' then + page:runScript(event.selected.label) + else + return UI.ScrollingGrid.eventHandler(self, event) + end + return true + end, }, turtles = UI.ScrollingGrid { tabTitle = 'Select', @@ -63,6 +89,41 @@ local page = UI.Page { disableHeader = true, sortColumn = 'label', autospace = true, + getDisplayValues = function(_, row) + row = Util.shallowCopy(row) + if row.fuel then + row.fuel = Util.toBytes(row.fuel) + end + if row.distance then + row.distance = Util.round(row.distance, 1) + end + return row + end, + draw = function(self) + Util.clear(self.values) + for _,v in pairs(network) do + if v.fuel then + table.insert(self.values, v) + end + end + self:update() + UI.ScrollingGrid.draw(self) + end, + eventHandler = function(self, event) + if event.type == 'grid_select' then + turtle = event.selected + config.id = event.selected.id + Config.update('Turtles', config) + multishell.setTitle(multishell.getCurrent(), turtle.label) + if socket then + socket:close() + socket = nil + end + else + return UI.ScrollingGrid.eventHandler(self, event) + end + return true + end, }, inventory = UI.ScrollingGrid { backgroundColor = colors.cyan, @@ -74,6 +135,54 @@ local page = UI.Page { }, disableHeader = true, sortColumn = 'index', + getRowTextColor = function(self, row, selected) + if turtle and row.selected then + return colors.yellow + end + return UI.ScrollingGrid.getRowTextColor(self, row, selected) + end, + draw = function(self) + local t = turtle + Util.clear(self.values) + if t then + for k,v in pairs(t.inv or { }) do -- new method (less data) + local index, count = k:match('(%d+),(%d+)') + v = { + index = tonumber(index), + key = v, + count = tonumber(count), + } + table.insert(self.values, v) + end + + for _,v in pairs(t.inventory or { }) do + if v.count > 0 then + table.insert(self.values, v) + end + end + + for _,v in pairs(self.values) do + if v.index == t.slotIndex then + v.selected = true + end + if v.key then + v.key = itemDB:getName(v.key) + end + end + end + self:adjustWidth() + self:update() + UI.ScrollingGrid.draw(self) + end, + eventHandler = function(self, event) + if event.type == 'grid_select' then + local fn = string.format('turtle.select(%d)', event.selected.index) + page:runFunction(fn) + else + return UI.ScrollingGrid.eventHandler(self, event) + end + return true + end, }, --[[ policy = UI.ScrollingGrid { @@ -134,6 +243,15 @@ local page = UI.Page { { key = 'distance', width = 6 }, { key = 'fuel', width = 6 }, }, + draw = function(self) + local t = turtle + if t then + self.values.status = t.status + self.values.distance = t.distance and Util.round(t.distance, 2) + self.values.fuel = Util.toBytes(t.fuel) + end + UI.StatusBar.draw(self) + end, }, notification = UI.Notification(), accelerators = { @@ -141,15 +259,10 @@ local page = UI.Page { }, } -function page:enable(turtle) - self.turtle = turtle - UI.Page.enable(self) -end - function page:runFunction(script, nowrap) for _ = 1, 2 do if not socket then - socket = Socket.connect(self.turtle.id, 161) + socket = Socket.connect(turtle.id, 161) end if socket then @@ -170,151 +283,42 @@ function page:runFunction(script, nowrap) end function page:runScript(scriptName) - if self.turtle then + if turtle then self.notification:info('Connecting') self:sync() - local cmd = string.format('Script %d %s', self.turtle.id, scriptName) - local ot = term.redirect(nullTerm) - pcall(function() shell.run(cmd) end) - term.redirect(ot) + local script = Util.readFile(fs.combine(SCRIPTS_PATH, scriptName)) + if not script then + print('Unable to read script file') + end + + local socket = Socket.connect(turtle.id, 161) + if not socket then + print('Unable to connect to ' .. turtle.id) + return + end + + local function processVariables(script) + local variables = { + COMPUTER_ID = os.getComputerID(), + } + for k,v in pairs(variables) do + local token = string.format('{%s}', k) + script = script:gsub(token, v) + end + + return script + end + + script = processVariables(script) + + socket:write({ type = 'script', args = script }) + socket:close() + self.notification:success('Sent') end end -function page.coords:draw() - local t = self.parent.turtle - self:clear() - if t then - self:setCursorPos(2, 2) - local ind = 'GPS' - if not t.point.gps then - ind = 'REL' - end - self:print(string.format('%s : %d,%d,%d', - ind, t.point.x, t.point.y, t.point.z)) - end -end - ---[[ Inventory Tab ]]-- -function page.tabs.inventory:getRowTextColor(row, selected) - if page.turtle and row.selected then - return colors.yellow - end - return UI.ScrollingGrid.getRowTextColor(self, row, selected) -end - -function page.tabs.inventory:draw() - local t = page.turtle - Util.clear(self.values) - if t then - for k,v in pairs(t.inv or { }) do -- new method (less data) - local index, count = k:match('(%d+),(%d+)') - v = { - index = tonumber(index), - key = v, - count = tonumber(count), - } - table.insert(self.values, v) - end - - for _,v in pairs(t.inventory or { }) do - if v.count > 0 then - table.insert(self.values, v) - end - end - - for _,v in pairs(self.values) do - if v.index == t.slotIndex then - v.selected = true - end - if v.key then - v.key = itemDB:getName(v.key) - end - end - end - self:adjustWidth() - self:update() - UI.ScrollingGrid.draw(self) -end - -function page.tabs.inventory:eventHandler(event) - if event.type == 'grid_select' then - local fn = string.format('turtle.select(%d)', event.selected.index) - page:runFunction(fn) - else - return UI.ScrollingGrid.eventHandler(self, event) - end - return true -end - -function page.tabs.scripts:draw() - Util.clear(self.values) - local files = fs.list(SCRIPTS_PATH) - for _,path in pairs(files) do - table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) }) - end - self:update() - UI.ScrollingGrid.draw(self) -end - -function page.tabs.scripts:eventHandler(event) - if event.type == 'grid_select' then - page:runScript(event.selected.label) - else - return UI.ScrollingGrid.eventHandler(self, event) - end - return true -end - -function page.tabs.turtles:getDisplayValues(row) - row = Util.shallowCopy(row) - if row.fuel then - row.fuel = Util.toBytes(row.fuel) - end - if row.distance then - row.distance = Util.round(row.distance, 1) - end - return row -end - -function page.tabs.turtles:draw() - Util.clear(self.values) - for _,v in pairs(network) do - if v.fuel then - table.insert(self.values, v) - end - end - self:update() - UI.ScrollingGrid.draw(self) -end - -function page.tabs.turtles:eventHandler(event) - if event.type == 'grid_select' then - page.turtle = event.selected - config.id = event.selected.id - Config.update('Turtles', config) - multishell.setTitle(multishell.getCurrent(), page.turtle.label) - if socket then - socket:close() - socket = nil - end - else - return UI.ScrollingGrid.eventHandler(self, event) - end - return true -end - -function page.statusBar:draw() - local t = self.parent.turtle - if t then - self.values.status = t.status - self.values.distance = t.distance and Util.round(t.distance, 2) - self.values.fuel = Util.toBytes(t.fuel) - end - UI.StatusBar.draw(self) -end - function page:showBlocks() local script = [[ local function inspect(direction) @@ -354,19 +358,14 @@ function page:eventHandler(event) return true end -function page:enable() - UI.Page.enable(self) --- self.tabs:activateTab(page.tabs.turtles) -end - if not Util.getOptions(options, { ... }, true) then return end if options.turtle.value >= 0 then for _ = 1, 10 do - page.turtle = _G.network[options.turtle.value] - if page.turtle then + turtle = _G.network[options.turtle.value] + if turtle then break end os.sleep(1) @@ -374,9 +373,9 @@ if options.turtle.value >= 0 then end Event.onInterval(1, function() - if page.turtle then - local t = _G.network[page.turtle.id] - page.turtle = t + if turtle then + --local t = _G.network[turtle.id] + --turtle = t page:draw() page:sync() end @@ -387,5 +386,4 @@ if config.tab then end UI:setPage(page) - -UI:pullEvents() +UI:start() diff --git a/common/etc/scripts/goHome b/common/etc/scripts/goHome index 2749820..94fd138 100644 --- a/common/etc/scripts/goHome +++ b/common/etc/scripts/goHome @@ -1,5 +1,5 @@ _G.requireInjector(_ENV) -local config = require('config').load('gps') +local config = require('opus.config').load('gps') if config.home then if turtle.enableGPS() then return turtle.pathfind(config.home) diff --git a/common/etc/scripts/moveTo b/common/etc/scripts/moveTo index c68e1db..11be075 100644 --- a/common/etc/scripts/moveTo +++ b/common/etc/scripts/moveTo @@ -2,8 +2,8 @@ turtle.run(function() _G.requireInjector(_ENV) - local GPS = require('gps') - local Socket = require('socket') + local GPS = require('opus.gps') + local Socket = require('opus.socket') local id = {COMPUTER_ID} diff --git a/common/etc/scripts/setHome b/common/etc/scripts/setHome index 9f88beb..be69170 100644 --- a/common/etc/scripts/setHome +++ b/common/etc/scripts/setHome @@ -1,5 +1,5 @@ _G.requireInjector(_ENV) -local Config = require('config') +local Config = require('opus.config') local pt = turtle.enableGPS() if pt then local config = Config.load('gps', { }) diff --git a/common/etc/scripts/summon b/common/etc/scripts/summon index 45e0c9e..66dcded 100644 --- a/common/etc/scripts/summon +++ b/common/etc/scripts/summon @@ -2,9 +2,9 @@ local function summon(id) _G.requireInjector(_ENV) - local GPS = require('gps') - local Point = require('point') - local Socket = require('socket') + local GPS = require('opus.gps') + local Point = require('opus.point') + local Socket = require('opus.socket') turtle.setStatus('GPSing') turtle.setPoint({ x = 0, y = 0, z = 0, heading = 0 }) diff --git a/ignore/Music.lua b/ignore/Music.lua index 2af2b86..7ff44c2 100644 --- a/ignore/Music.lua +++ b/ignore/Music.lua @@ -250,5 +250,3 @@ turtle.setStatus('Jamming') UI:pullEvents() turtle.setStatus('idle') page:play(false) - -UI.term:reset() diff --git a/milo/plugins/item/resetTab.lua b/milo/plugins/item/resetTab.lua index a0a12ae..0d9d34d 100644 --- a/milo/plugins/item/resetTab.lua +++ b/milo/plugins/item/resetTab.lua @@ -9,7 +9,7 @@ local context = Milo:getContext() local resetTab = UI.Tab { tabTitle = 'Reset', index = 5, - backgroundColor = colors.cyan, + noFill = true, textArea = UI.TextArea { y = 2, ey = 6, textColor = colors.yellow, diff --git a/miners/scanningMiner.lua b/miners/scanningMiner.lua index 1d5e361..588259b 100644 --- a/miners/scanningMiner.lua +++ b/miners/scanningMiner.lua @@ -637,8 +637,7 @@ Event.addRoutine(function() end) UI:setPage(page) -UI:pullEvents() -UI.term:reset() +UI:start() turtle.reset() diff --git a/recipeBook/recipeBook.lua b/recipeBook/recipeBook.lua index 4922929..4df6acb 100644 --- a/recipeBook/recipeBook.lua +++ b/recipeBook/recipeBook.lua @@ -100,11 +100,10 @@ function page.info:draw() self:clear() if book then - self:setCursorPos(1, 1) self:print( - string.format('Name: %s%s%s\n', Ansi.yellow, book.name, Ansi.reset)) - self:print( - string.format('Version: %s%s%s\n', Ansi.yellow, book.version, Ansi.reset)) + string.format('Name: %s%s%s\nVersion: %s%s%s\n', + Ansi.yellow, book.name, Ansi.reset, + Ansi.yellow, book.version, Ansi.reset)) self.button.text = book.enabled and 'Disable' or 'Enable' self.button:draw() diff --git a/turtle/autorun/6.tl3.lua b/turtle/init/6.tl3.lua similarity index 100% rename from turtle/autorun/6.tl3.lua rename to turtle/init/6.tl3.lua