diff --git a/builder/builder.lua b/builder/builder.lua index f966ec9..1ad66f7 100644 --- a/builder/builder.lua +++ b/builder/builder.lua @@ -529,6 +529,72 @@ local startPage = UI.Page { { prompt = 'Quit', event = 'quit' } } }, + startLevel = UI.Dialog { + title = 'Enter Starting Level', + height = 7, + form = UI.Form { + y = 3, x = 2, height = 4, + event = 'setStartLevel', + cancelEvent = 'slide_hide', + text = UI.Text { + x = 5, y = 1, width = 20, + textColor = colors.gray, + }, + textEntry = UI.TextEntry { + formKey = 'level', + x = 15, y = 1, width = 7, + }, + }, + statusBar = UI.StatusBar(), + }, + startBlock = UI.Dialog { + title = 'Enter Block Number', + height = 7, + form = UI.Form { + y = 3, x = 2, height = 4, + event = 'setStartBlock', + cancelEvent = 'slide_hide', + text = UI.Text { + x = 2, y = 1, width = 20, + textColor = colors.gray, + }, + textEntry = UI.TextEntry { + x = 16, y = 1, + width = 10, limit = 8, + }, + }, + statusBar = UI.StatusBar(), + }, + startPoint = UI.Dialog { + title = 'Set starting point', + height = 11, + form = UI.Form { + y = 2, x = 2, ey = -2, + cancelEvent = 'slide_hide', + text1 = UI.Text { + x = 1, y = 2, value = 'Turtle location' }, + xLoc = UI.TextEntry { + x = 1, y = 3, formKey = 'x', width = 7, limit = 16, shadowText = 'x', required = true }, + yLoc = UI.TextEntry { + x = 9, y = 3, formKey = 'y', width = 7, limit = 16, shadowText = 'y', required = true }, + zLoc = UI.TextEntry { + x = 17, y = 3, formKey = 'z', width = 7, limit = 16, shadowText = 'z', required = true }, + text2 = UI.Text { + x = 1, y = 5, value = 'Starting Point' }, + xrLoc = UI.TextEntry { + x = 1, y = 6, formKey = 'rx', width = 7, limit = 16, shadowText = 'x', required = true }, + yrLoc = UI.TextEntry { + x = 9, y = 6, formKey = 'ry', width = 7, limit = 16, shadowText = 'y', required = true }, + zrLoc = UI.TextEntry { + x = 17, y = 6, formKey = 'rz', width = 7, limit = 16, shadowText = 'z', required = true }, + revert = UI.Button { + x = 1, y = -2, text = 'Revert', event = 'revert' }, + accelerators = { + form_cancel = 'slide_hide', + }, + }, + statusBar = UI.StatusBar({ values = 'Optional start point'}), + }, throttle = UI.Throttle { }, accelerators = { x = 'test', @@ -555,81 +621,64 @@ function startPage:enable() UI.Page.enable(self) end +function startPage.startPoint:eventHandler(event) + if event.type == 'form_complete' then + for k,v in pairs(event.values) do + Builder.loc[k] = tonumber(v) + end + Builder:saveProgress(Builder.index) + self:hide() + elseif event.type == 'revert' then + Builder.loc = { } + Builder:saveProgress(Builder.index) + self:hide() + elseif event.type == 'form_invalid' then + self.statusBar:setStatus(event.message) + elseif event.type == 'form_cancel' or event.type == 'cancel' then + self:hide() + else + return UI.Dialog.eventHandler(self, event) + end + return true +end + function startPage:eventHandler(event) if event.type == 'startLevel' then - local dialog = UI.Dialog({ - title = 'Enter Starting Level', - height = 7, - form = UI.Form { - y = 3, x = 2, height = 4, - text = UI.Text({ x = 5, y = 1, textColor = colors.gray, - value = '0 - ' .. Builder.schematic.height }), - textEntry = UI.TextEntry({ x = 15, y = 1, '0 - 11', width = 7 }), - }, - statusBar = UI.StatusBar(), - }) + self.startLevel.form.text.value = '0 - ' .. Builder.schematic.height + self.startLevel:show() - function dialog:eventHandler(event) - if event.type == 'form_complete' then - local l = tonumber(self.form.textEntry.value) - if l and l < Builder.schematic.height and l >= 0 then - for k,v in pairs(Builder.schematic.blocks) do - if v.y >= l then - Builder.index = k - Builder:saveProgress(Builder.index) - UI:setPreviousPage() - break - end - end - else - self.statusBar:timedStatus('Invalid Level', 3) + elseif event.type == 'setStartLevel' then + local l = tonumber(self.startLevel.form.textEntry.value) + if l and l < Builder.schematic.height and l >= 0 then + for k,v in pairs(Builder.schematic.blocks) do + if v.y >= l then + Builder.index = k + Builder:saveProgress(Builder.index) + break end - elseif event.type == 'form_cancel' or event.type == 'cancel' then - UI:setPreviousPage() - else - return UI.Dialog.eventHandler(self, event) end - return true + self.startLevel:hide() + self:draw() + else + self.startLevel.statusBar:setStatus('Invalid start level') end - dialog:setFocus(dialog.form.textEntry) - UI:setPage(dialog) - elseif event.type == 'startBlock' then - local dialog = UI.Dialog { - title = 'Enter Block Number', - height = 7, - form = UI.Form { - y = 3, x = 2, height = 4, - text = UI.Text { x = 2, y = 1, - value = '1 - ' .. #Builder.schematic.blocks, textColor = colors.gray }, - textEntry = UI.TextEntry { x = 16, y = 1, - value = tostring(Builder.index), width = 10, limit = 8 } - }, - statusBar = UI.StatusBar(), - } + self.startBlock.form.text.value = '1 - ' .. #Builder.schematic.blocks + self.startBlock.form.textEntry.value = tostring(Builder.index) + self.startBlock:show() - function dialog:eventHandler(event) - if event.type == 'form_complete' then - local bn = tonumber(self.form.textEntry.value) - if bn and bn < #Builder.schematic.blocks and bn >= 0 then - Builder.index = bn - Builder:saveProgress(Builder.index) - UI:setPreviousPage() - else - self.statusBar:timedStatus('Invalid Block', 3) - end - elseif event.type == 'form_cancel' or event.type == 'cancel' then - UI:setPreviousPage() - else - return UI.Dialog.eventHandler(self, event) - end - return true + elseif event.type == 'setStartBlock' then + local bn = tonumber(self.startBlock.form.textEntry.value) + if bn and bn < #Builder.schematic.blocks and bn >= 0 then + Builder.index = bn + Builder:saveProgress(Builder.index) + self.startBlock:hide() + self:draw() + else + self.startLevel.statusBar:setStatus('Invalid start block') end - dialog:setFocus(dialog.form.textEntry) - UI:setPage(dialog) - elseif event.type == 'startPoint' then local loc = Util.shallowCopy(Builder.loc) if not loc.x then @@ -645,57 +694,8 @@ function startPage:eventHandler(event) end end - local dialog = UI.Dialog { - title = 'Set starting point', - height = 11, - width = 30, - form = UI.Form { - y = 2, x = 2, ey = -2, - values = loc, - text1 = UI.Text { - x = 1, y = 2, value = 'Turtle location' }, - xLoc = UI.TextEntry { - x = 1, y = 3, formKey = 'x', width = 7, limit = 16, shadowText = 'x', required = true }, - yLoc = UI.TextEntry { - x = 9, y = 3, formKey = 'y', width = 7, limit = 16, shadowText = 'y', required = true }, - zLoc = UI.TextEntry { - x = 17, y = 3, formKey = 'z', width = 7, limit = 16, shadowText = 'z', required = true }, - text2 = UI.Text { - x = 1, y = 5, value = 'Starting Point' }, - xrLoc = UI.TextEntry { - x = 1, y = 6, formKey = 'rx', width = 7, limit = 16, shadowText = 'x', required = true }, - yrLoc = UI.TextEntry { - x = 9, y = 6, formKey = 'ry', width = 7, limit = 16, shadowText = 'y', required = true }, - zrLoc = UI.TextEntry { - x = 17, y = 6, formKey = 'rz', width = 7, limit = 16, shadowText = 'z', required = true }, - revert = UI.Button { - x = 1, y = -2, text = 'Revert', event = 'revert' }, - }, - statusBar = UI.StatusBar({ values = 'Optional start point'}), - } - - function dialog:eventHandler(event) - if event.type == 'form_complete' then - for k,v in pairs(loc) do - Builder.loc[k] = tonumber(v) - end - Builder:saveProgress(Builder.index) - UI:setPreviousPage() - elseif event.type == 'revert' then - Builder.loc = { } - Builder:saveProgress(Builder.index) - UI:setPreviousPage() - elseif event.type == 'form_invalid' then - self.statusBar:setStatus(event.message) - elseif event.type == 'form_cancel' or event.type == 'cancel' then - UI:setPreviousPage() - else - return UI.Dialog.eventHandler(self, event) - end - return true - end - - UI:setPage(dialog) + self.startPoint.form:setValues(loc) + self.startPoint:show() elseif event.type == 'assignBlocks' then -- this might be an approximation of the blocks needed diff --git a/core/apis/meAdapter18.lua b/core/apis/meAdapter18.lua index f19e3db..cbc3f44 100644 --- a/core/apis/meAdapter18.lua +++ b/core/apis/meAdapter18.lua @@ -1,5 +1,5 @@ local class = require('class') -local RSAdapter = require('refinedAdapter') +local RSAdapter = require('core.refinedAdapter') local Peripheral = require('peripheral') local Util = require('util') diff --git a/core/Script.lua b/ignore/Script.lua similarity index 100% rename from core/Script.lua rename to ignore/Script.lua diff --git a/milo/plugins/item/infoTab.lua b/milo/plugins/item/infoTab.lua index ce31d32..5fd3900 100644 --- a/milo/plugins/item/infoTab.lua +++ b/milo/plugins/item/infoTab.lua @@ -3,7 +3,7 @@ local UI = require('ui') local colors = _G.colors -local infoTab = UI.Window { +local infoTab = UI.Tab { tabTitle = 'Info', index = 4, backgroundColor = colors.cyan, @@ -40,7 +40,7 @@ function infoTab:draw() end self.textArea.value = value - UI.Window.draw(self) + UI.Tab.draw(self) end return { itemTab = infoTab } diff --git a/milo/plugins/item/machinesTab.lua b/milo/plugins/item/machinesTab.lua index 72b4780..ce61d13 100644 --- a/milo/plugins/item/machinesTab.lua +++ b/milo/plugins/item/machinesTab.lua @@ -6,7 +6,7 @@ local Util = require('util') local colors = _G.colors local context = Milo:getContext() -local machinesTab = UI.Window { +local machinesTab = UI.Tab { tabTitle = 'Machine', index = 3, backgroundColor = colors.cyan, diff --git a/milo/plugins/item/manageTab.lua b/milo/plugins/item/manageTab.lua index 1a252a7..999c0b3 100644 --- a/milo/plugins/item/manageTab.lua +++ b/milo/plugins/item/manageTab.lua @@ -5,7 +5,7 @@ local Util = require('util') local context = Milo:getContext() -local manageTab = UI.Window { +local manageTab = UI.Tab { tabTitle = 'Manage', index = 1, form = UI.Form { diff --git a/milo/plugins/item/recipeTab.lua b/milo/plugins/item/recipeTab.lua index f87a2aa..d2a6260 100644 --- a/milo/plugins/item/recipeTab.lua +++ b/milo/plugins/item/recipeTab.lua @@ -5,7 +5,7 @@ local UI = require('ui') local colors = _G.colors -local recipeTab = UI.Window { +local recipeTab = UI.Tab { tabTitle = 'Recipe', index = 2, backgroundColor = colors.cyan, diff --git a/milo/plugins/item/resetTab.lua b/milo/plugins/item/resetTab.lua index 034ea6f..da7c8eb 100644 --- a/milo/plugins/item/resetTab.lua +++ b/milo/plugins/item/resetTab.lua @@ -6,7 +6,7 @@ local Util = require('util') local colors = _G.colors local context = Milo:getContext() -local resetTab = UI.Window { +local resetTab = UI.Tab { tabTitle = 'Reset', index = 5, backgroundColor = colors.cyan, diff --git a/miners/multiMiner.lua b/miners/multiMiner.lua index b94d6ff..8c451be 100644 --- a/miners/multiMiner.lua +++ b/miners/multiMiner.lua @@ -216,7 +216,7 @@ local function run(member, point) end) end -local blocksTab = UI.Window { +local blocksTab = UI.Tab { tabTitle = 'Blocks', grid = UI.ScrollingGrid { y = 1, @@ -228,7 +228,7 @@ local blocksTab = UI.Window { }, } -local turtlesTab = UI.Window { +local turtlesTab = UI.Tab { tabTitle = 'Turtles', grid = UI.ScrollingGrid { y = 1,