milo: categories, better listing page separation

This commit is contained in:
kepler155c@gmail.com
2018-12-01 00:52:39 -05:00
parent c5d209161e
commit e1084422e5
17 changed files with 146 additions and 96 deletions

View File

@@ -31,6 +31,7 @@ function activityWizardPage:isValidType(node)
return m and m.type == 'monitor' and {
name = 'Activity Monitor',
value = 'activity',
category = 'display',
help = 'Display storage activity'
}
end

View File

@@ -30,6 +30,7 @@ function brewingStandView:isValidType(node)
return m and m.type == 'minecraft:brewing_stand'and {
name = 'Brewing Stand',
value = 'brewingStand',
category = 'custom',
help = 'Auto-learning brewing stand',
}
end

View File

@@ -46,6 +46,7 @@ function exportView:isValidType(node)
return m and m.pullItems and {
name = 'Generic Inventory',
value = 'machine',
category = 'machine',
help = 'Chest, furnace... (has an inventory)'
}
end

View File

@@ -46,6 +46,7 @@ function importView:isValidType(node)
return m and m.pullItems and {
name = 'Generic Inventory',
value = 'machine',
category = 'machine',
help = 'Chest, furnace... (has an inventory)',
}
end

View File

@@ -26,6 +26,7 @@ function inputChestWizardPage:isValidType(node)
return m and m.pullItems and {
name = 'Input Chest',
value = 'input',
category = 'custom',
help = 'Sends all items to storage',
}
end

View File

@@ -10,7 +10,7 @@ local device = _G.device
local context = Milo:getContext()
local itemPage = UI.Page {
local page = UI.Page {
titleBar = UI.TitleBar {
title = 'Limit Resource',
previousPage = true,
@@ -46,7 +46,7 @@ local itemPage = UI.Page {
x = 2, y = -2, width = 10,
formLabel = 'Machine',
event = 'select_machine',
text = 'Configure',
text = 'Assign',
},
infoButton = UI.Button {
x = 2, y = -2,
@@ -108,7 +108,6 @@ local itemPage = UI.Page {
grid = UI.ScrollingGrid {
y = 2, ey = -5,
disableHeader = true,
values = context.config.nodes,
columns = {
{ heading = 'Name', key = 'displayName'},
},
@@ -142,42 +141,48 @@ local itemPage = UI.Page {
notification = UI.Notification { },
}
function itemPage:enable(item)
function page:enable(item)
self.origItem = item
self.item = Util.shallowCopy(item)
self.res = item.resource or { }
self.res.displayName = self.item.displayName
self.form:setValues(self.res)
self.titleBar.title = item.displayName or item.name
self.form.machineButton.inactive = not Craft.machineLookup[self.item.key]
local machine = Craft.machineLookup[self.item.key]
self.form.machineButton.inactive = not machine
if machine then
self:filterMachines(machine)
end
UI.Page.enable(self)
self:focusFirst()
end
function itemPage.machines.grid:isRowValid(_, value)
local ignores = Util.transpose({ 'storage', 'ignore', 'hidden' })
if not ignores[value.mtype] then
local node = context.storage.nodes[value.name]
return node and node.adapter and node.adapter.online and node.adapter.pushItems
end
function page:filterMachines(machine)
local t = Util.filter(context.storage.nodes, function(node)
if node.category == 'machine' then
return node.adapter and node.adapter.online and node.adapter.pushItems
end
end)
self.machines.grid:setValues(t)
self.machines.grid:setSelected('name', machine)
end
function itemPage.machines.grid:getDisplayValues(row)
function page.machines.grid:getDisplayValues(row)
row = Util.shallowCopy(row)
row.displayName = row.displayName or row.name
return row
end
function itemPage.machines.grid:getRowTextColor(row, selected)
if row.name == Craft.machineLookup[itemPage.item.key] then
return colors.yellow
end
return UI.Grid:getRowTextColor(row, selected)
function page.machines.grid:getRowTextColor(row, selected)
if row.name == Craft.machineLookup[page.item.key] then
return colors.yellow
end
return UI.Grid:getRowTextColor(row, selected)
end
function itemPage.rsControl:enable()
function page.rsControl:enable()
local devices = self.form[2].choices
Util.clear(devices)
for _,dev in pairs(device) do
@@ -193,7 +198,7 @@ function itemPage.rsControl:enable()
UI.SlideOut.enable(self)
end
function itemPage.rsControl:eventHandler(event)
function page.rsControl:eventHandler(event)
if event.type == 'form_cancel' then
self:hide()
elseif event.type == 'form_complete' then
@@ -204,7 +209,7 @@ function itemPage.rsControl:eventHandler(event)
return true
end
function itemPage:eventHandler(event)
function page:eventHandler(event)
if event.type == 'form_cancel' then
UI:setPreviousPage()
@@ -212,8 +217,6 @@ function itemPage:eventHandler(event)
self.rsControl:show()
elseif event.type == 'select_machine' then
self.machines.grid:update()
self.machines.grid:setIndex(1)
self.machines:show()
elseif event.type == 'reset' then
@@ -334,4 +337,4 @@ function itemPage:eventHandler(event)
return true
end
UI:addPage('item', itemPage)
UI:addPage('item', page)

View File

@@ -27,6 +27,7 @@ function wizardPage:isValidType(node)
return m and m.type == 'monitor' and {
name = 'Crafting Monitor',
value = 'jobs',
category = 'display',
help = 'Display crafting progress / jobs'
}
end

View File

@@ -6,11 +6,15 @@ local context = Milo:getContext()
local turtle = _G.turtle
local learnPage = UI.Dialog {
height = 6, width = UI.term.width - 6,
height = 9, width = UI.term.width - 6,
title = 'Learn Recipe',
chooser = UI.Chooser {
x = 8, y = 3,
width = 20,
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,
@@ -24,17 +28,15 @@ local learnPage = UI.Dialog {
}
function learnPage:enable()
self.chooser.choices = { }
local t = { }
for k in pairs(context.learnTypes) do
table.insert(self.chooser.choices, {
table.insert(t, {
name = k,
value = k,
})
end
self.chooser.value =
Milo:getState('learnType') or
self.chooser.choices[1].value
self.grid:setValues(t)
self.grid:setSelected('name', Milo:getState('learnType') or '')
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
sync.lock(turtle)
@@ -53,12 +55,11 @@ function learnPage:eventHandler(event)
Milo:resumeCrafting({ key = 'gridInUse' })
UI:setPreviousPage()
elseif event.type == 'accept' then
local choice = self.chooser.value
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

View File

@@ -11,7 +11,7 @@ local turtle = _G.turtle
local context = Milo:getContext()
local machineLearnWizard = UI.Page {
titleBar = UI.TitleBar { title = 'Learn a crafting recipe' },
titleBar = UI.TitleBar { title = 'Select machine' },
wizard = UI.Wizard {
y = 2, ey = -2,
pages = {
@@ -19,7 +19,6 @@ local machineLearnWizard = UI.Page {
index = 1,
grid = UI.ScrollingGrid {
y = 2, ey = -2,
values = context.config.nodes,
columns = {
{ heading = 'Name', key = 'displayName' },
},
@@ -47,10 +46,6 @@ Example: Slot 1 is the top slot in a furnace.]],
local pages = machineLearnWizard.wizard.pages
local machine
function pages.machines.grid:isRowValid(_, value)
return value.mtype == 'machine' and value.adapter and value.adapter.online
end
function pages.machines.grid:getDisplayValues(row)
row = Util.shallowCopy(row)
row.displayName = row.displayName or row.name
@@ -58,7 +53,12 @@ function pages.machines.grid:getDisplayValues(row)
end
function pages.machines:enable()
self.grid:update()
local t = Util.filter(context.storage.nodes, function(node)
if node.category == 'machine' then
return node.adapter and node.adapter.online and node.adapter.pushItems
end
end)
self.grid:setValues(t)
UI.Window.enable(self)
end
@@ -122,15 +122,12 @@ function pages.confirmation:validate()
Milo:saveMachineRecipe(recipe, result, machine.name)
local listingPage = UI:getPage('listing')
local displayName = itemDB:getName(result)
listingPage.statusBar.filter:setValue(displayName)
listingPage.notification:success('Learned: ' .. displayName)
listingPage.filter = displayName
listingPage:refresh()
listingPage.grid:draw()
UI:setPage('listing', {
filter = displayName,
message = 'Learned: ' .. displayName,
})
return true
end
@@ -141,7 +138,7 @@ function machineLearnWizard:disable()
end
function machineLearnWizard:eventHandler(event)
if event.type == 'cancel' or event.type == 'accept' then
if event.type == 'cancel' then
turtle.emptyInventory()
UI:setPage('listing')
else

View File

@@ -38,6 +38,7 @@ function wizardPage:isValidType(node)
{
name = 'Manipulator',
value = 'manipulator',
category = 'custom',
help = 'Manipulator w/bound introspection mod'
}
end

View File

@@ -48,6 +48,7 @@ function storageView:isValidType(node)
return m and m.pullItems and {
name = 'Storage',
value = 'storage',
category = 'storage',
help = 'Use for item storage',
}
end
@@ -117,6 +118,7 @@ function lockView:isValidType(node)
return m and m.pullItems and {
name = 'Storage',
value = 'storage',
category = 'storage',
help = 'Use for item storage',
}
end

View File

@@ -58,6 +58,7 @@ function wizardPage:isValidType(node)
return m and m.pullItems and {
name = 'Trashcan',
value = 'trashcan',
category = 'custom',
help = 'An inventory to send unwanted items',
}
end

View File

@@ -133,15 +133,12 @@ function turtleLearnWizard.wizard.pages.confirmation:validate()
local recipe, msg = learnRecipe(self)
if recipe then
local listingPage = UI:getPage('listing')
local displayName = itemDB:getName(recipe)
listingPage.statusBar.filter:setValue(displayName)
listingPage.notification:success('Learned: ' .. displayName)
listingPage.filter = displayName
listingPage:refresh()
listingPage.grid:draw()
UI:setPage('listing', {
filter = displayName,
message = 'Learned: ' .. displayName,
})
return true
else
turtleLearnWizard.notification:error(msg)
@@ -149,7 +146,8 @@ function turtleLearnWizard.wizard.pages.confirmation:validate()
end
function turtleLearnWizard:eventHandler(event)
if event.type == 'cancel' or event.type == 'accept' then
if event.type == 'cancel' then
turtle.emptyInventory()
UI:setPage('listing')
else
return UI.Page.eventHandler(self, event)