milo: simplify learn types + monitor resize
This commit is contained in:
@@ -7,6 +7,7 @@ local Util = require('util')
|
||||
local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
|
||||
--[[ Configuration Page ]]--
|
||||
local template =
|
||||
@@ -30,10 +31,10 @@ local wizardPage = UI.Window {
|
||||
formLabel = 'Font Size', formKey = 'textScale',
|
||||
nochoice = 'Small',
|
||||
choices = {
|
||||
{ name = 'Small', value = .5, help = '(requires restart)', },
|
||||
{ name = 'Large', value = 1, help = '(requires restart)', },
|
||||
{ name = 'Small', value = .5 },
|
||||
{ name = 'Large', value = 1 },
|
||||
},
|
||||
help = 'Adjust text scaling (requires restart)',
|
||||
help = 'Adjust text scaling',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -46,6 +47,10 @@ function wizardPage:validate()
|
||||
return self.form:save()
|
||||
end
|
||||
|
||||
function wizardPage:saveNode(node)
|
||||
os.queueEvent('monitor_resize', node.name)
|
||||
end
|
||||
|
||||
function wizardPage:isValidType(node)
|
||||
local m = device[node.name]
|
||||
return m and m.type == 'monitor' and {
|
||||
@@ -71,8 +76,8 @@ local function createPage(node)
|
||||
},
|
||||
grid = UI.Grid {
|
||||
columns = {
|
||||
{ heading = 'Qty', key = 'count', width = 6 },
|
||||
{ heading = 'Change', key = 'change', width = 6 },
|
||||
{ heading = 'Qty', key = 'count', width = 5 },
|
||||
{ heading = 'Change', key = 'change', width = 5 },
|
||||
{ heading = 'Rate', key = 'rate', width = 6 },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
},
|
||||
@@ -106,7 +111,6 @@ local function createPage(node)
|
||||
function page:reset()
|
||||
self.lastItems = nil
|
||||
self.grid:setValues({ })
|
||||
self.grid:clear()
|
||||
self.grid:draw()
|
||||
end
|
||||
|
||||
@@ -176,6 +180,20 @@ 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.name == side and pages[node.name]
|
||||
|
||||
@@ -8,8 +8,8 @@ local template =
|
||||
[[%sBrewing stands have the ability to automatically learn recipes.%s
|
||||
|
||||
Simply craft potions in the brewing stand as normal except for these conditions.
|
||||
1. Place item in top slot first.
|
||||
2. At least 1 bottle must be placed in the first slot.
|
||||
1. Place item in top slot FIRST.
|
||||
2. Place all 3 bottles.
|
||||
|
||||
When finished brewing, the recipe will be available upon refreshing.
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ local Milo = require('milo')
|
||||
local Util = require('util')
|
||||
|
||||
local context = Milo:getContext()
|
||||
local turtle = _G.turtle
|
||||
|
||||
local craftTask = {
|
||||
name = 'crafting',
|
||||
|
||||
@@ -63,10 +63,7 @@ end
|
||||
|
||||
function craftPage.wizard.pages.resources.grid:getDisplayValues(row)
|
||||
local function dv(v)
|
||||
if v == 0 then
|
||||
return ''
|
||||
end
|
||||
return Util.toBytes(v)
|
||||
return v == 0 and '' or Util.toBytes(v)
|
||||
end
|
||||
row = Util.shallowCopy(row)
|
||||
row.total = Util.toBytes(row.total)
|
||||
|
||||
@@ -8,6 +8,7 @@ local Util = require('util')
|
||||
local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
|
||||
--[[ Configuration Screen ]]
|
||||
local wizardPage = UI.Window {
|
||||
@@ -28,10 +29,10 @@ local wizardPage = UI.Window {
|
||||
formLabel = 'Font Size', formKey = 'textScale',
|
||||
nochoice = 'Small',
|
||||
choices = {
|
||||
{ name = 'Small', value = .5, help = '(requires restart)', },
|
||||
{ name = 'Large', value = 1, help = '(requires restart)', },
|
||||
{ name = 'Small', value = .5 },
|
||||
{ name = 'Large', value = 1 },
|
||||
},
|
||||
help = 'Adjust text scaling (requires restart)',
|
||||
help = 'Adjust text scaling',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -40,6 +41,10 @@ function wizardPage:setNode(node)
|
||||
self.form:setValues(node)
|
||||
end
|
||||
|
||||
function wizardPage:saveNode(node)
|
||||
os.queueEvent('monitor_resize', node.name)
|
||||
end
|
||||
|
||||
function wizardPage:validate()
|
||||
return self.form:save()
|
||||
end
|
||||
@@ -70,7 +75,6 @@ local function createPage(node)
|
||||
},
|
||||
grid = UI.Grid {
|
||||
sortColumn = 'index',
|
||||
backgroundFocusColor = colors.black,
|
||||
columns = {
|
||||
{ heading = 'Qty', key = 'remaining', width = 4 },
|
||||
{ heading = 'Crafting', key = 'displayName', },
|
||||
@@ -142,6 +146,20 @@ 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]
|
||||
|
||||
@@ -1,67 +1 @@
|
||||
local Milo = require('milo')
|
||||
local UI = require('ui')
|
||||
|
||||
local context = Milo:getContext()
|
||||
local turtle = _G.turtle
|
||||
|
||||
local learnPage = UI.Dialog {
|
||||
height = 9, width = UI.term.width - 6,
|
||||
title = 'Learn Recipe',
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 3, height = 4,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'name'},
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
cancel = UI.Button {
|
||||
x = 3, y = -2,
|
||||
text = 'Cancel', event = 'cancel'
|
||||
},
|
||||
accept = UI.Button {
|
||||
ex = -3, y = -2,
|
||||
width = 8,
|
||||
text = 'Ok', event = 'accept',
|
||||
},
|
||||
}
|
||||
|
||||
function learnPage:enable()
|
||||
local t = { }
|
||||
for k in pairs(context.learnTypes) do
|
||||
table.insert(t, {
|
||||
name = k,
|
||||
value = k,
|
||||
})
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
self.grid:setSelected('name', Milo:getState('learnType') or '')
|
||||
|
||||
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
|
||||
|
||||
self:focusFirst()
|
||||
UI.Dialog.enable(self)
|
||||
end
|
||||
|
||||
function learnPage:disable()
|
||||
UI.Dialog.disable(self)
|
||||
end
|
||||
|
||||
function learnPage:eventHandler(event)
|
||||
if event.type == 'cancel' then
|
||||
Milo:resumeCrafting({ key = 'gridInUse' })
|
||||
turtle.emptyInventory()
|
||||
UI:setPreviousPage()
|
||||
|
||||
elseif event.type == 'accept' or event.type == 'grid_select' then
|
||||
local choice = self.grid:getSelected().value
|
||||
|
||||
Milo:setState('learnType', choice)
|
||||
UI:setPage(context.learnTypes[choice])
|
||||
else
|
||||
return UI.Dialog.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
UI:addPage('learn', learnPage)
|
||||
-- moved
|
||||
@@ -5,46 +5,38 @@ local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
local turtle = _G.turtle
|
||||
|
||||
local context = Milo:getContext()
|
||||
local machine
|
||||
|
||||
local machineLearnWizard = UI.Page {
|
||||
titleBar = UI.TitleBar { title = 'Select machine' },
|
||||
wizard = UI.Wizard {
|
||||
y = 2, ey = -2,
|
||||
pages = {
|
||||
machines = UI.Window {
|
||||
index = 1,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
},
|
||||
local pages = {
|
||||
machines = UI.Window {
|
||||
index = 2,
|
||||
validFor = 'Machine Processing',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
},
|
||||
confirmation = UI.Window {
|
||||
index = 2,
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
backgroundColor = colors.black,
|
||||
value =
|
||||
sortColumn = 'displayName',
|
||||
},
|
||||
},
|
||||
confirmation = UI.Window {
|
||||
index = 3,
|
||||
validFor = 'Machine Processing',
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
backgroundColor = colors.black,
|
||||
value =
|
||||
[[Place items in slots according to the machine's inventory.
|
||||
|
||||
Place the result in the last slot of the turtle.
|
||||
|
||||
Example: Slot 1 is the top slot in a furnace.]],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
notification = UI.Notification { },
|
||||
}
|
||||
|
||||
local pages = machineLearnWizard.wizard.pages
|
||||
local machine
|
||||
|
||||
function pages.machines.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = row.displayName or row.name
|
||||
@@ -64,18 +56,18 @@ end
|
||||
function pages.machines:validate()
|
||||
local selected = self.grid:getSelected()
|
||||
if not selected then
|
||||
machineLearnWizard.notification:error('No machines configured')
|
||||
self:emit({ type = 'general_error', message = 'No machines configured' })
|
||||
return
|
||||
end
|
||||
|
||||
machine = device[selected.name]
|
||||
if not machine then
|
||||
machineLearnWizard.notification:error('Machine not found')
|
||||
self:emit({type = 'general_error', message = 'Machine not found' })
|
||||
return
|
||||
end
|
||||
|
||||
if not machine.size then
|
||||
machineLearnWizard.notification:error('Invalid machine')
|
||||
self:emit({ type = 'general_error', message = 'Invalid machine' })
|
||||
return
|
||||
end
|
||||
|
||||
@@ -90,19 +82,21 @@ function pages.confirmation:validate()
|
||||
inventory[16] = nil
|
||||
|
||||
if not result then
|
||||
machineLearnWizard.notification:error('Result must be placed in last slot')
|
||||
self:emit({ type = 'general_error', message = 'Result must be placed in last slot' })
|
||||
return
|
||||
end
|
||||
|
||||
if Util.empty(inventory) then
|
||||
machineLearnWizard.notification:error('Ingredients not present')
|
||||
self:emit({ type = 'general_error', message = 'Ingredients not present' })
|
||||
return
|
||||
end
|
||||
|
||||
for k in pairs(inventory) do
|
||||
if k > slotCount then
|
||||
machineLearnWizard.notification:error(
|
||||
'Slot ' .. k .. ' is not valid\nThe valid slots are 1 - ' .. machine.size())
|
||||
self:emit({
|
||||
type = 'general_error',
|
||||
message = 'Slot ' .. k .. ' is not valid\nThe valid slots are 1 - ' .. machine.size()
|
||||
})
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -130,19 +124,4 @@ function pages.confirmation:validate()
|
||||
return true
|
||||
end
|
||||
|
||||
function machineLearnWizard:disable()
|
||||
Milo:resumeCrafting({ key = 'gridInUse' })
|
||||
UI.Page.disable(self)
|
||||
end
|
||||
|
||||
function machineLearnWizard:eventHandler(event)
|
||||
if event.type == 'cancel' then
|
||||
turtle.emptyInventory()
|
||||
UI:setPage('listing')
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
context.learnTypes['Machine processing'] = machineLearnWizard
|
||||
UI:getPage('learnWizard').wizard:add(pages)
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
local Event = require('event')
|
||||
local Milo = require('milo')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
local RedstoneTask = {
|
||||
name = 'redstone',
|
||||
priority = 40,
|
||||
}
|
||||
|
||||
function RedstoneTask:cycle(context)
|
||||
for v in context.storage:filterActive({ 'mtype', 'machine' }) do
|
||||
if v.redstone then
|
||||
local ri = device[v.redstone.integrator]
|
||||
if not ri or not v.adapter then
|
||||
_debug(v.redstone)
|
||||
else
|
||||
local function conditionsSatisfied()
|
||||
return not not next(v.adapter.list())
|
||||
end
|
||||
if conditionsSatisfied() then
|
||||
ri.setOutput(v.redstone.side, true)
|
||||
Event.onTimeout(.25, function()
|
||||
ri.setOutput(v.redstone.side, false)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Milo:registerTask(RedstoneTask)
|
||||
@@ -1,73 +0,0 @@
|
||||
local UI = require('ui')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
|
||||
local dispenserView = UI.Window {
|
||||
index = 10,
|
||||
title = 'Redstone Control',
|
||||
backgroundColor = colors.cyan,
|
||||
form = UI.Form {
|
||||
x = 1, y = 2, ex = -1, ey = -2,
|
||||
manualControls = true,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Interval', formKey = 'interval',
|
||||
help = 'Pulse redstone if items are present',
|
||||
limit = 6,
|
||||
validate = 'numeric',
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
formLabel = 'Integrator', formKey = 'integrator',
|
||||
nochoice = 'disable',
|
||||
help = 'Control via redstone',
|
||||
},
|
||||
[3] = UI.Chooser {
|
||||
width = 10,
|
||||
formLabel = 'Side', formKey = 'side',
|
||||
choices = {
|
||||
{ name = 'up', value = 'up' },
|
||||
{ name = 'down', value = 'down' },
|
||||
{ name = 'east', value = 'east' },
|
||||
{ name = 'north', value = 'north' },
|
||||
{ name = 'west', value = 'west' },
|
||||
{ name = 'south', value = 'south' },
|
||||
},
|
||||
help = 'Output side',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
function dispenserView:isValidFor(node)
|
||||
if node.mtype == 'machine' then
|
||||
local m = device[node.name]
|
||||
--return m and m.type == 'minecraft:dispenser'
|
||||
end
|
||||
end
|
||||
|
||||
function dispenserView:enable()
|
||||
UI.Window.enable(self)
|
||||
self:focusFirst()
|
||||
|
||||
self.form[2].choices = { }
|
||||
for _,m in pairs(device) do
|
||||
if m.type == 'redstone_integrator' then
|
||||
table.insert(self.form[2].choices, {
|
||||
name = m.name,
|
||||
value = m.name,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function dispenserView:validate()
|
||||
return self.form:save()
|
||||
end
|
||||
|
||||
function dispenserView:setNode(node)
|
||||
if not node.redstone then
|
||||
node.redstone = { }
|
||||
end
|
||||
self.form:setValues(node.redstone)
|
||||
end
|
||||
|
||||
--UI:getPage('nodeWizard').wizard:add({ dispenser = dispenserView })
|
||||
@@ -75,7 +75,7 @@ local function client(socket)
|
||||
if not data then
|
||||
break
|
||||
end
|
||||
_G._debug(data)
|
||||
--_G._debug(data)
|
||||
socket.co = coroutine.running()
|
||||
|
||||
if data.request == 'scan' then -- full scan of all inventories
|
||||
|
||||
@@ -38,15 +38,15 @@ local wizardPage = UI.Window {
|
||||
}
|
||||
|
||||
function wizardPage:setNode(node)
|
||||
self.node = node
|
||||
self.form:setValues(node)
|
||||
end
|
||||
|
||||
function wizardPage:saveNode(node)
|
||||
Sound.setVolume(node.volume)
|
||||
end
|
||||
|
||||
function wizardPage:validate()
|
||||
if self.form:save() then
|
||||
Sound.setVolume(self.node.volume)
|
||||
return true
|
||||
end
|
||||
return self.form:save()
|
||||
end
|
||||
|
||||
function wizardPage:isValidType(node)
|
||||
|
||||
@@ -104,30 +104,19 @@ local function learnRecipe()
|
||||
return recipe
|
||||
end
|
||||
|
||||
local turtleLearnWizard = UI.Page {
|
||||
titleBar = UI.TitleBar { title = 'Learn a crafting recipe' },
|
||||
wizard = UI.Wizard {
|
||||
y = 2, ey = -3,
|
||||
pages = {
|
||||
confirmation = UI.Window {
|
||||
index = 1,
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value =
|
||||
local pages = {
|
||||
turtleCraft = UI.Window {
|
||||
index = 2,
|
||||
validFor = 'Turtle Crafting',
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value =
|
||||
[[Place recipe in turtle!]],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
notification = UI.Notification { },
|
||||
}
|
||||
|
||||
function turtleLearnWizard:disable()
|
||||
Milo:resumeCrafting({ key = 'gridInUse' })
|
||||
UI.Page.disable(self)
|
||||
end
|
||||
|
||||
function turtleLearnWizard.wizard.pages.confirmation:validate()
|
||||
function pages.turtleCraft:validate()
|
||||
local recipe, msg = learnRecipe(self)
|
||||
|
||||
if recipe then
|
||||
@@ -139,18 +128,8 @@ function turtleLearnWizard.wizard.pages.confirmation:validate()
|
||||
})
|
||||
return true
|
||||
else
|
||||
turtleLearnWizard.notification:error(msg)
|
||||
self:emit({ type = 'general_error', message = msg })
|
||||
end
|
||||
end
|
||||
|
||||
function turtleLearnWizard:eventHandler(event)
|
||||
if event.type == 'cancel' then
|
||||
turtle.emptyInventory()
|
||||
UI:setPage('listing')
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
context.learnTypes['Turtle crafting'] = turtleLearnWizard
|
||||
UI:getPage('learnWizard').wizard:add(pages)
|
||||
|
||||
Reference in New Issue
Block a user