canvas use in UI overhaul
This commit is contained in:
@@ -529,6 +529,72 @@ local startPage = UI.Page {
|
|||||||
{ prompt = 'Quit', event = 'quit' }
|
{ 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 { },
|
throttle = UI.Throttle { },
|
||||||
accelerators = {
|
accelerators = {
|
||||||
x = 'test',
|
x = 'test',
|
||||||
@@ -555,81 +621,64 @@ function startPage:enable()
|
|||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
end
|
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)
|
function startPage:eventHandler(event)
|
||||||
if event.type == 'startLevel' then
|
if event.type == 'startLevel' then
|
||||||
local dialog = UI.Dialog({
|
self.startLevel.form.text.value = '0 - ' .. Builder.schematic.height
|
||||||
title = 'Enter Starting Level',
|
self.startLevel:show()
|
||||||
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(),
|
|
||||||
})
|
|
||||||
|
|
||||||
function dialog:eventHandler(event)
|
elseif event.type == 'setStartLevel' then
|
||||||
if event.type == 'form_complete' then
|
local l = tonumber(self.startLevel.form.textEntry.value)
|
||||||
local l = tonumber(self.form.textEntry.value)
|
if l and l < Builder.schematic.height and l >= 0 then
|
||||||
if l and l < Builder.schematic.height and l >= 0 then
|
for k,v in pairs(Builder.schematic.blocks) do
|
||||||
for k,v in pairs(Builder.schematic.blocks) do
|
if v.y >= l then
|
||||||
if v.y >= l then
|
Builder.index = k
|
||||||
Builder.index = k
|
Builder:saveProgress(Builder.index)
|
||||||
Builder:saveProgress(Builder.index)
|
break
|
||||||
UI:setPreviousPage()
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.statusBar:timedStatus('Invalid Level', 3)
|
|
||||||
end
|
end
|
||||||
elseif event.type == 'form_cancel' or event.type == 'cancel' then
|
|
||||||
UI:setPreviousPage()
|
|
||||||
else
|
|
||||||
return UI.Dialog.eventHandler(self, event)
|
|
||||||
end
|
end
|
||||||
return true
|
self.startLevel:hide()
|
||||||
|
self:draw()
|
||||||
|
else
|
||||||
|
self.startLevel.statusBar:setStatus('Invalid start level')
|
||||||
end
|
end
|
||||||
|
|
||||||
dialog:setFocus(dialog.form.textEntry)
|
|
||||||
UI:setPage(dialog)
|
|
||||||
|
|
||||||
elseif event.type == 'startBlock' then
|
elseif event.type == 'startBlock' then
|
||||||
local dialog = UI.Dialog {
|
self.startBlock.form.text.value = '1 - ' .. #Builder.schematic.blocks
|
||||||
title = 'Enter Block Number',
|
self.startBlock.form.textEntry.value = tostring(Builder.index)
|
||||||
height = 7,
|
self.startBlock:show()
|
||||||
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(),
|
|
||||||
}
|
|
||||||
|
|
||||||
function dialog:eventHandler(event)
|
elseif event.type == 'setStartBlock' then
|
||||||
if event.type == 'form_complete' then
|
local bn = tonumber(self.startBlock.form.textEntry.value)
|
||||||
local bn = tonumber(self.form.textEntry.value)
|
if bn and bn < #Builder.schematic.blocks and bn >= 0 then
|
||||||
if bn and bn < #Builder.schematic.blocks and bn >= 0 then
|
Builder.index = bn
|
||||||
Builder.index = bn
|
Builder:saveProgress(Builder.index)
|
||||||
Builder:saveProgress(Builder.index)
|
self.startBlock:hide()
|
||||||
UI:setPreviousPage()
|
self:draw()
|
||||||
else
|
else
|
||||||
self.statusBar:timedStatus('Invalid Block', 3)
|
self.startLevel.statusBar:setStatus('Invalid start block')
|
||||||
end
|
|
||||||
elseif event.type == 'form_cancel' or event.type == 'cancel' then
|
|
||||||
UI:setPreviousPage()
|
|
||||||
else
|
|
||||||
return UI.Dialog.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
dialog:setFocus(dialog.form.textEntry)
|
|
||||||
UI:setPage(dialog)
|
|
||||||
|
|
||||||
elseif event.type == 'startPoint' then
|
elseif event.type == 'startPoint' then
|
||||||
local loc = Util.shallowCopy(Builder.loc)
|
local loc = Util.shallowCopy(Builder.loc)
|
||||||
if not loc.x then
|
if not loc.x then
|
||||||
@@ -645,57 +694,8 @@ function startPage:eventHandler(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local dialog = UI.Dialog {
|
self.startPoint.form:setValues(loc)
|
||||||
title = 'Set starting point',
|
self.startPoint:show()
|
||||||
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)
|
|
||||||
|
|
||||||
elseif event.type == 'assignBlocks' then
|
elseif event.type == 'assignBlocks' then
|
||||||
-- this might be an approximation of the blocks needed
|
-- this might be an approximation of the blocks needed
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local class = require('class')
|
local class = require('class')
|
||||||
local RSAdapter = require('refinedAdapter')
|
local RSAdapter = require('core.refinedAdapter')
|
||||||
local Peripheral = require('peripheral')
|
local Peripheral = require('peripheral')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local UI = require('ui')
|
|||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
|
|
||||||
local infoTab = UI.Window {
|
local infoTab = UI.Tab {
|
||||||
tabTitle = 'Info',
|
tabTitle = 'Info',
|
||||||
index = 4,
|
index = 4,
|
||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
@@ -40,7 +40,7 @@ function infoTab:draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.textArea.value = value
|
self.textArea.value = value
|
||||||
UI.Window.draw(self)
|
UI.Tab.draw(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
return { itemTab = infoTab }
|
return { itemTab = infoTab }
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local Util = require('util')
|
|||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local machinesTab = UI.Window {
|
local machinesTab = UI.Tab {
|
||||||
tabTitle = 'Machine',
|
tabTitle = 'Machine',
|
||||||
index = 3,
|
index = 3,
|
||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ local Util = require('util')
|
|||||||
|
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local manageTab = UI.Window {
|
local manageTab = UI.Tab {
|
||||||
tabTitle = 'Manage',
|
tabTitle = 'Manage',
|
||||||
index = 1,
|
index = 1,
|
||||||
form = UI.Form {
|
form = UI.Form {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ local UI = require('ui')
|
|||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
|
|
||||||
local recipeTab = UI.Window {
|
local recipeTab = UI.Tab {
|
||||||
tabTitle = 'Recipe',
|
tabTitle = 'Recipe',
|
||||||
index = 2,
|
index = 2,
|
||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local Util = require('util')
|
|||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local resetTab = UI.Window {
|
local resetTab = UI.Tab {
|
||||||
tabTitle = 'Reset',
|
tabTitle = 'Reset',
|
||||||
index = 5,
|
index = 5,
|
||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ local function run(member, point)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local blocksTab = UI.Window {
|
local blocksTab = UI.Tab {
|
||||||
tabTitle = 'Blocks',
|
tabTitle = 'Blocks',
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 1,
|
y = 1,
|
||||||
@@ -228,7 +228,7 @@ local blocksTab = UI.Window {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local turtlesTab = UI.Window {
|
local turtlesTab = UI.Tab {
|
||||||
tabTitle = 'Turtles',
|
tabTitle = 'Turtles',
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
y = 1,
|
y = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user