milo: cleanup
This commit is contained in:
@@ -46,6 +46,7 @@ Needs work
|
|||||||
\030 \031 \030f\0317\130\030 \031 \030f\0317\130",
|
\030 \031 \030f\0317\130\030 \031 \030f\0317\130",
|
||||||
run = "Appstore.lua",
|
run = "Appstore.lua",
|
||||||
},
|
},
|
||||||
|
--[[
|
||||||
[ "131260cbfbb0c821f8eae5e7c3c296c7aa4d50b9" ] = {
|
[ "131260cbfbb0c821f8eae5e7c3c296c7aa4d50b9" ] = {
|
||||||
title = "Music",
|
title = "Music",
|
||||||
category = "Apps",
|
category = "Apps",
|
||||||
@@ -56,7 +57,6 @@ Needs work
|
|||||||
run = "usr/apps/Music.lua",
|
run = "usr/apps/Music.lua",
|
||||||
requires = 'turtle',
|
requires = 'turtle',
|
||||||
},
|
},
|
||||||
--[[
|
|
||||||
[ "89307d419a2fe4fbb69af92b3d3af27b6ec14d3e" ] = {
|
[ "89307d419a2fe4fbb69af92b3d3af27b6ec14d3e" ] = {
|
||||||
title = "Telnet",
|
title = "Telnet",
|
||||||
category = "Apps",
|
category = "Apps",
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
|||||||
|
|
||||||
_G._debug({'eval', recipe.result, count })
|
_G._debug({'eval', recipe.result, count })
|
||||||
|
|
||||||
local maxCount = recipe.maxCount or math.floor(64 / recipe.count)
|
local maxCount = math.floor((recipe.maxCount or 64) / recipe.count)
|
||||||
|
|
||||||
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
||||||
local itemCount = Craft.getItemCount(origItem.ingredients, key)
|
local itemCount = Craft.getItemCount(origItem.ingredients, key)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local Craft = require('turtle.craft')
|
local Craft = require('craft2')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
|
|||||||
@@ -287,20 +287,6 @@ function Storage:export(target, slot, count, item)
|
|||||||
-- If no slot and full amount is not exported, then no need to check rest of adapters
|
-- If no slot and full amount is not exported, then no need to check rest of adapters
|
||||||
-- ... so should not reach here
|
-- ... so should not reach here
|
||||||
|
|
||||||
|
|
||||||
--[[
|
|
||||||
-- not found - scan all others
|
|
||||||
for _, adapter in self:onlineAdapters() do
|
|
||||||
if not adapter.cache or not adapter.cache[key] then
|
|
||||||
provide(adapter)
|
|
||||||
if count <= 0 then
|
|
||||||
_G._debug('STORAGE: FOUND: %s - %d', key, count)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--]]
|
|
||||||
|
|
||||||
return total
|
return total
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -368,7 +354,7 @@ function Storage:import(source, slot, count, item)
|
|||||||
if count <= 0 then
|
if count <= 0 then
|
||||||
return total
|
return total
|
||||||
end
|
end
|
||||||
if adapter.cache and adapter.cache[key] and not node.lock then
|
if not node.lock and adapter.cache and adapter.cache[key] then
|
||||||
insert(adapter)
|
insert(adapter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
301
milo/core/listing.lua
Normal file
301
milo/core/listing.lua
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
local Craft = require('craft2')
|
||||||
|
local itemDB = require('itemDB')
|
||||||
|
local Event = require('event')
|
||||||
|
local Milo = require('milo')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local context = Milo:getContext()
|
||||||
|
local displayMode = Milo:getState('displayMode') or 0
|
||||||
|
local string = _G.string
|
||||||
|
|
||||||
|
local displayModes = {
|
||||||
|
[0] = { text = 'A', help = 'Showing all items' },
|
||||||
|
[1] = { text = 'I', help = 'Showing inventory items' },
|
||||||
|
[2] = { text = 'C', help = 'Showing craftable items' },
|
||||||
|
}
|
||||||
|
|
||||||
|
local function filterItems(t, filter)
|
||||||
|
if filter or displayMode > 0 then
|
||||||
|
local r = { }
|
||||||
|
if filter then
|
||||||
|
filter = filter:lower()
|
||||||
|
end
|
||||||
|
for _,v in pairs(t) do
|
||||||
|
if not filter or string.find(v.lname, filter, 1, true) then
|
||||||
|
if not displayMode or
|
||||||
|
displayMode == 0 or
|
||||||
|
displayMode == 1 and v.count > 0 or
|
||||||
|
displayMode == 2 and v.has_recipe then
|
||||||
|
table.insert(r, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local listingPage = UI.Page {
|
||||||
|
menuBar = UI.MenuBar {
|
||||||
|
buttons = {
|
||||||
|
{ text = 'Learn', event = 'learn' },
|
||||||
|
--{ text = 'Forget', event = 'forget' },
|
||||||
|
{ text = 'Craft', event = 'craft' },
|
||||||
|
{ text = 'Edit', event = 'details' },
|
||||||
|
{ text = 'Refresh', event = 'refresh', x = -12 },
|
||||||
|
{
|
||||||
|
text = '\206',
|
||||||
|
x = -3,
|
||||||
|
dropdown = {
|
||||||
|
{ text = 'Setup', event = 'network' },
|
||||||
|
UI.MenuBar.spacer,
|
||||||
|
{
|
||||||
|
text = 'Rescan storage',
|
||||||
|
event = 'rescan',
|
||||||
|
help = 'Rescan all inventories'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grid = UI.Grid {
|
||||||
|
y = 2, ey = -2,
|
||||||
|
columns = {
|
||||||
|
{ heading = ' Qty', key = 'count' , width = 4, justify = 'right' },
|
||||||
|
{ heading = 'Name', key = 'displayName' },
|
||||||
|
{ heading = 'Min', key = 'low' , width = 4 },
|
||||||
|
{ heading = 'Max', key = 'limit' , width = 4 },
|
||||||
|
},
|
||||||
|
sortColumn = 'displayName',
|
||||||
|
},
|
||||||
|
statusBar = UI.StatusBar {
|
||||||
|
filter = UI.TextEntry {
|
||||||
|
x = 1, ex = -17,
|
||||||
|
limit = 50,
|
||||||
|
shadowText = 'filter',
|
||||||
|
shadowTextColor = colors.gray,
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
backgroundFocusColor = colors.cyan,
|
||||||
|
accelerators = {
|
||||||
|
[ 'enter' ] = 'eject',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
storageStatus = UI.Text {
|
||||||
|
x = -16, ex = -9,
|
||||||
|
textColor = colors.lime,
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
value = '',
|
||||||
|
},
|
||||||
|
amount = UI.TextEntry {
|
||||||
|
x = -8, ex = -4,
|
||||||
|
limit = 3,
|
||||||
|
shadowText = '1',
|
||||||
|
shadowTextColor = colors.gray,
|
||||||
|
backgroundColor = colors.black,
|
||||||
|
backgroundFocusColor = colors.black,
|
||||||
|
accelerators = {
|
||||||
|
[ 'enter' ] = 'eject_specified',
|
||||||
|
},
|
||||||
|
help = 'Specify an amount to send',
|
||||||
|
},
|
||||||
|
display = UI.Button {
|
||||||
|
x = -3,
|
||||||
|
event = 'toggle_display',
|
||||||
|
value = 0,
|
||||||
|
text = displayModes[displayMode].text,
|
||||||
|
help = displayModes[displayMode].help,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
notification = UI.Notification(),
|
||||||
|
throttle = UI.Throttle {
|
||||||
|
textColor = colors.yellow,
|
||||||
|
borderColor = colors.gray,
|
||||||
|
},
|
||||||
|
accelerators = {
|
||||||
|
r = 'refresh',
|
||||||
|
[ 'control-r' ] = 'refresh',
|
||||||
|
|
||||||
|
[ 'control-e' ] = 'eject',
|
||||||
|
[ 'control-s' ] = 'eject_stack',
|
||||||
|
[ 'control-a' ] = 'eject_all',
|
||||||
|
|
||||||
|
[ 'control-m' ] = 'network',
|
||||||
|
|
||||||
|
q = 'quit',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function listingPage.statusBar:draw()
|
||||||
|
return UI.Window.draw(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function listingPage.grid:getRowTextColor(row, selected)
|
||||||
|
if row.is_craftable then
|
||||||
|
return colors.yellow
|
||||||
|
end
|
||||||
|
if row.has_recipe then
|
||||||
|
return colors.cyan
|
||||||
|
end
|
||||||
|
return UI.Grid:getRowTextColor(row, selected)
|
||||||
|
end
|
||||||
|
|
||||||
|
function listingPage.grid:getDisplayValues(row)
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
row.count = row.count > 0 and Util.toBytes(row.count)
|
||||||
|
if row.low then
|
||||||
|
row.low = Util.toBytes(row.low)
|
||||||
|
end
|
||||||
|
if row.limit then
|
||||||
|
row.limit = Util.toBytes(row.limit)
|
||||||
|
end
|
||||||
|
return row
|
||||||
|
end
|
||||||
|
|
||||||
|
function listingPage:eventHandler(event)
|
||||||
|
if event.type == 'quit' then
|
||||||
|
UI:exitPullEvents()
|
||||||
|
|
||||||
|
elseif event.type == 'eject' or event.type == 'grid_select' then
|
||||||
|
local item = self.grid:getSelected()
|
||||||
|
if item then
|
||||||
|
item.count = Milo:craftAndEject(item, 1)
|
||||||
|
self.grid:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'eject_stack' then
|
||||||
|
local item = self.grid:getSelected()
|
||||||
|
if item then
|
||||||
|
item.count = Milo:craftAndEject(item, itemDB:getMaxCount(item))
|
||||||
|
self.grid:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'eject_all' then
|
||||||
|
local item = self.grid:getSelected()
|
||||||
|
if item then
|
||||||
|
local updated = Milo:getItem(Milo:listItems(), item)
|
||||||
|
if updated then
|
||||||
|
Milo:craftAndEject(item, updated.count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'eject_specified' then
|
||||||
|
local item = self.grid:getSelected()
|
||||||
|
local count = tonumber(self.statusBar.amount.value)
|
||||||
|
if item and count then
|
||||||
|
self.statusBar.amount:reset()
|
||||||
|
self:setFocus(self.statusBar.filter)
|
||||||
|
Milo:craftAndEject(item, count)
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'network' then
|
||||||
|
UI:setPage('network')
|
||||||
|
|
||||||
|
elseif event.type == 'details' or event.type == 'grid_select_right' then
|
||||||
|
local item = self.grid:getSelected()
|
||||||
|
if item then
|
||||||
|
UI:setPage('item', item)
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'refresh' then
|
||||||
|
self:refresh()
|
||||||
|
self.grid:draw()
|
||||||
|
self:setFocus(self.statusBar.filter)
|
||||||
|
|
||||||
|
elseif event.type == 'rescan' then
|
||||||
|
self:refresh(true)
|
||||||
|
self.grid:draw()
|
||||||
|
self:setFocus(self.statusBar.filter)
|
||||||
|
|
||||||
|
elseif event.type == 'toggle_display' then
|
||||||
|
displayMode = (displayMode + 1) % 3
|
||||||
|
Util.merge(event.button, displayModes[displayMode])
|
||||||
|
event.button:draw()
|
||||||
|
self:applyFilter()
|
||||||
|
self.grid:draw()
|
||||||
|
Milo:setState('displayMode', displayMode)
|
||||||
|
|
||||||
|
elseif event.type == 'learn' then
|
||||||
|
UI:setPage('learn')
|
||||||
|
|
||||||
|
elseif event.type == 'craft' then
|
||||||
|
local item = self.grid:getSelected()
|
||||||
|
if item then
|
||||||
|
if Craft.findRecipe(item) then -- or item.is_craftable then
|
||||||
|
UI:setPage('craft', self.grid:getSelected())
|
||||||
|
else
|
||||||
|
self.notification:error('No recipe defined')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
||||||
|
self.filter = event.text
|
||||||
|
if #self.filter == 0 then
|
||||||
|
self.filter = nil
|
||||||
|
end
|
||||||
|
self:applyFilter()
|
||||||
|
self.grid:draw()
|
||||||
|
self.statusBar.filter:focus()
|
||||||
|
|
||||||
|
else
|
||||||
|
UI.Page.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function listingPage:enable()
|
||||||
|
Event.onTimeout(0, function()
|
||||||
|
self:refresh()
|
||||||
|
self:draw()
|
||||||
|
self:sync()
|
||||||
|
|
||||||
|
self.timer = Event.onInterval(3, function()
|
||||||
|
for _,v in pairs(self.allItems) do
|
||||||
|
local c = context.storage.cache[v.key]
|
||||||
|
v.count = c and c.count or 0
|
||||||
|
end
|
||||||
|
self.grid:draw()
|
||||||
|
self:sync()
|
||||||
|
end)
|
||||||
|
|
||||||
|
local function updateStatus()
|
||||||
|
self.statusBar.storageStatus.value =
|
||||||
|
context.storage:isOnline() and '' or 'offline'
|
||||||
|
self.statusBar.storageStatus.textColor =
|
||||||
|
context.storage:isOnline() and colors.lime or colors.red
|
||||||
|
end
|
||||||
|
updateStatus()
|
||||||
|
|
||||||
|
self.handler = Event.on({ 'storage_offline', 'storage_online' }, function()
|
||||||
|
updateStatus()
|
||||||
|
self.statusBar.storageStatus:draw()
|
||||||
|
self:sync()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
self:setFocus(self.statusBar.filter)
|
||||||
|
UI.Page.enable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function listingPage:disable()
|
||||||
|
Event.off(self.timer)
|
||||||
|
Event.off(self.handler)
|
||||||
|
UI.Page.disable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function listingPage:refresh(force)
|
||||||
|
local throttle = function() self.throttle:update() end
|
||||||
|
|
||||||
|
self.throttle:enable()
|
||||||
|
self.allItems = Milo:mergeResources(Milo:listItems(force, throttle))
|
||||||
|
self:applyFilter()
|
||||||
|
self.throttle:disable()
|
||||||
|
end
|
||||||
|
|
||||||
|
function listingPage:applyFilter()
|
||||||
|
local t = filterItems(self.allItems, self.filter)
|
||||||
|
self.grid:setValues(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
UI:addPage('listing', listingPage)
|
||||||
@@ -442,8 +442,6 @@ function nodeWizard:enable(node)
|
|||||||
self.node.adapter = adapter
|
self.node.adapter = adapter
|
||||||
node.adapter = adapter
|
node.adapter = adapter
|
||||||
|
|
||||||
_G._p3 = self.node -- TODO: remove - debugging
|
|
||||||
|
|
||||||
local choices = {
|
local choices = {
|
||||||
{ name = 'Ignore', value = 'ignore', '' },
|
{ name = 'Ignore', value = 'ignore', '' },
|
||||||
{ name = 'Hidden', value = 'hidden', help = 'Do not show in list' },
|
{ name = 'Hidden', value = 'hidden', help = 'Do not show in list' },
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('craft2')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local sync = require('sync').sync
|
local sync = require('sync').sync
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
@@ -36,6 +36,7 @@ function craftTask:craft(recipe, item)
|
|||||||
item.ingredients[recipe.result].total = item.count
|
item.ingredients[recipe.result].total = item.count
|
||||||
item.ingredients[recipe.result].crafted = item.crafted
|
item.ingredients[recipe.result].crafted = item.crafted
|
||||||
|
|
||||||
|
--[[
|
||||||
_G._p2 = item
|
_G._p2 = item
|
||||||
if not item.history then
|
if not item.history then
|
||||||
item.history = { }
|
item.history = { }
|
||||||
@@ -46,13 +47,14 @@ for k,v in pairs(item.ingredients) do
|
|||||||
t.history.input[k] = Util.shallowCopy(v)
|
t.history.input[k] = Util.shallowCopy(v)
|
||||||
end
|
end
|
||||||
table.insert(item.history, t)
|
table.insert(item.history, t)
|
||||||
|
]]
|
||||||
Craft.craftRecipe(recipe, item.requested - item.crafted, context.storage, item)
|
Craft.craftRecipe(recipe, item.requested - item.crafted, context.storage, item)
|
||||||
|
|
||||||
|
--[[
|
||||||
for k,v in pairs(item.ingredients) do
|
for k,v in pairs(item.ingredients) do
|
||||||
t.history.output[k] = Util.shallowCopy(v)
|
t.history.output[k] = Util.shallowCopy(v)
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
function craftTask:cycle()
|
function craftTask:cycle()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('craft2')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local Ansi = require('ansi')
|
local Ansi = require('ansi')
|
||||||
local Craft = require('turtle.craft')
|
local Craft = require('craft2')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
@@ -9,8 +9,6 @@ local device = _G.device
|
|||||||
|
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
-- TODO: allow change of machine
|
|
||||||
|
|
||||||
local itemPage = UI.Page {
|
local itemPage = UI.Page {
|
||||||
titleBar = UI.TitleBar {
|
titleBar = UI.TitleBar {
|
||||||
title = 'Limit Resource',
|
title = 'Limit Resource',
|
||||||
@@ -29,18 +27,6 @@ local itemPage = UI.Page {
|
|||||||
formLabel = 'Max', formKey = 'limit', help = 'Send to trash if above max',
|
formLabel = 'Max', formKey = 'limit', help = 'Send to trash if above max',
|
||||||
validate = 'numeric',
|
validate = 'numeric',
|
||||||
},
|
},
|
||||||
--[[
|
|
||||||
[3] = UI.Chooser {
|
|
||||||
width = 7,
|
|
||||||
formLabel = 'Autocraft', formKey = 'auto',
|
|
||||||
nochoice = 'No',
|
|
||||||
choices = {
|
|
||||||
{ name = 'Yes', value = true },
|
|
||||||
{ name = 'No', value = false },
|
|
||||||
},
|
|
||||||
help = 'Craft until out of ingredients'
|
|
||||||
},
|
|
||||||
]]
|
|
||||||
[4] = UI.Checkbox {
|
[4] = UI.Checkbox {
|
||||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||||
help = 'Ignore damage of item',
|
help = 'Ignore damage of item',
|
||||||
@@ -163,7 +149,12 @@ function itemPage:enable(item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function itemPage.machines.grid:isRowValid(_, value)
|
function itemPage.machines.grid:isRowValid(_, value)
|
||||||
return value.mtype == 'machine'
|
local ignores = Util.transpose({ 'storage', 'ignore', 'hidden' })
|
||||||
|
if not ignores[value.mtype] then
|
||||||
|
local node = context.storage.nodes[value.name]
|
||||||
|
_debug(node)
|
||||||
|
return node and node.adapter and node.adapter.online and node.adapter.pushItems
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function itemPage.machines.grid:getDisplayValues(row)
|
function itemPage.machines.grid:getDisplayValues(row)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('craft2')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
|
|||||||
@@ -1,300 +1 @@
|
|||||||
local Craft = require('turtle.craft')
|
--moved file
|
||||||
local itemDB = require('itemDB')
|
|
||||||
local Event = require('event')
|
|
||||||
local Milo = require('milo')
|
|
||||||
local UI = require('ui')
|
|
||||||
local Util = require('util')
|
|
||||||
|
|
||||||
local colors = _G.colors
|
|
||||||
local context = Milo:getContext()
|
|
||||||
local displayMode = Milo:getState('displayMode') or 0
|
|
||||||
|
|
||||||
local displayModes = {
|
|
||||||
[0] = { text = 'A', help = 'Showing all items' },
|
|
||||||
[1] = { text = 'I', help = 'Showing inventory items' },
|
|
||||||
[2] = { text = 'C', help = 'Showing craftable items' },
|
|
||||||
}
|
|
||||||
|
|
||||||
local function filterItems(t, filter)
|
|
||||||
if filter or displayMode > 0 then
|
|
||||||
local r = { }
|
|
||||||
if filter then
|
|
||||||
filter = filter:lower()
|
|
||||||
end
|
|
||||||
for _,v in pairs(t) do
|
|
||||||
if not filter or string.find(v.lname, filter, 1, true) then
|
|
||||||
if not displayMode or
|
|
||||||
displayMode == 0 or
|
|
||||||
displayMode == 1 and v.count > 0 or
|
|
||||||
displayMode == 2 and v.has_recipe then
|
|
||||||
table.insert(r, v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return r
|
|
||||||
end
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
local listingPage = UI.Page {
|
|
||||||
menuBar = UI.MenuBar {
|
|
||||||
buttons = {
|
|
||||||
{ text = 'Learn', event = 'learn' },
|
|
||||||
--{ text = 'Forget', event = 'forget' },
|
|
||||||
{ text = 'Craft', event = 'craft' },
|
|
||||||
{ text = 'Edit', event = 'details' },
|
|
||||||
{ text = 'Refresh', event = 'refresh', x = -12 },
|
|
||||||
{
|
|
||||||
text = '\206',
|
|
||||||
x = -3,
|
|
||||||
dropdown = {
|
|
||||||
{ text = 'Setup', event = 'network' },
|
|
||||||
UI.MenuBar.spacer,
|
|
||||||
{
|
|
||||||
text = 'Rescan storage',
|
|
||||||
event = 'rescan',
|
|
||||||
help = 'Rescan all inventories'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
grid = UI.Grid {
|
|
||||||
y = 2, ey = -2,
|
|
||||||
columns = {
|
|
||||||
{ heading = ' Qty', key = 'count' , width = 4, justify = 'right' },
|
|
||||||
{ heading = 'Name', key = 'displayName' },
|
|
||||||
{ heading = 'Min', key = 'low' , width = 4 },
|
|
||||||
{ heading = 'Max', key = 'limit' , width = 4 },
|
|
||||||
},
|
|
||||||
sortColumn = 'displayName',
|
|
||||||
},
|
|
||||||
statusBar = UI.StatusBar {
|
|
||||||
filter = UI.TextEntry {
|
|
||||||
x = 1, ex = -17,
|
|
||||||
limit = 50,
|
|
||||||
shadowText = 'filter',
|
|
||||||
shadowTextColor = colors.gray,
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
backgroundFocusColor = colors.cyan,
|
|
||||||
accelerators = {
|
|
||||||
[ 'enter' ] = 'eject',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
storageStatus = UI.Text {
|
|
||||||
x = -16, ex = -9,
|
|
||||||
textColor = colors.lime,
|
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
value = '',
|
|
||||||
},
|
|
||||||
amount = UI.TextEntry {
|
|
||||||
x = -8, ex = -4,
|
|
||||||
limit = 3,
|
|
||||||
shadowText = '1',
|
|
||||||
shadowTextColor = colors.gray,
|
|
||||||
backgroundColor = colors.black,
|
|
||||||
backgroundFocusColor = colors.black,
|
|
||||||
accelerators = {
|
|
||||||
[ 'enter' ] = 'eject_specified',
|
|
||||||
},
|
|
||||||
help = 'Specify an amount to send',
|
|
||||||
},
|
|
||||||
display = UI.Button {
|
|
||||||
x = -3,
|
|
||||||
event = 'toggle_display',
|
|
||||||
value = 0,
|
|
||||||
text = displayModes[displayMode].text,
|
|
||||||
help = displayModes[displayMode].help,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
notification = UI.Notification(),
|
|
||||||
throttle = UI.Throttle {
|
|
||||||
textColor = colors.yellow,
|
|
||||||
borderColor = colors.gray,
|
|
||||||
},
|
|
||||||
accelerators = {
|
|
||||||
r = 'refresh',
|
|
||||||
[ 'control-r' ] = 'refresh',
|
|
||||||
|
|
||||||
[ 'control-e' ] = 'eject',
|
|
||||||
[ 'control-s' ] = 'eject_stack',
|
|
||||||
[ 'control-a' ] = 'eject_all',
|
|
||||||
|
|
||||||
[ 'control-m' ] = 'network',
|
|
||||||
|
|
||||||
q = 'quit',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
function listingPage.statusBar:draw()
|
|
||||||
return UI.Window.draw(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function listingPage.grid:getRowTextColor(row, selected)
|
|
||||||
if row.is_craftable then
|
|
||||||
return colors.yellow
|
|
||||||
end
|
|
||||||
if row.has_recipe then
|
|
||||||
return colors.cyan
|
|
||||||
end
|
|
||||||
return UI.Grid:getRowTextColor(row, selected)
|
|
||||||
end
|
|
||||||
|
|
||||||
function listingPage.grid:getDisplayValues(row)
|
|
||||||
row = Util.shallowCopy(row)
|
|
||||||
row.count = row.count > 0 and Util.toBytes(row.count)
|
|
||||||
if row.low then
|
|
||||||
row.low = Util.toBytes(row.low)
|
|
||||||
end
|
|
||||||
if row.limit then
|
|
||||||
row.limit = Util.toBytes(row.limit)
|
|
||||||
end
|
|
||||||
return row
|
|
||||||
end
|
|
||||||
|
|
||||||
function listingPage:eventHandler(event)
|
|
||||||
if event.type == 'quit' then
|
|
||||||
UI:exitPullEvents()
|
|
||||||
|
|
||||||
elseif event.type == 'eject' or event.type == 'grid_select' then
|
|
||||||
local item = self.grid:getSelected()
|
|
||||||
if item then
|
|
||||||
item.count = Milo:craftAndEject(item, 1)
|
|
||||||
self.grid:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'eject_stack' then
|
|
||||||
local item = self.grid:getSelected()
|
|
||||||
if item then
|
|
||||||
item.count = Milo:craftAndEject(item, itemDB:getMaxCount(item))
|
|
||||||
self.grid:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'eject_all' then
|
|
||||||
local item = self.grid:getSelected()
|
|
||||||
if item then
|
|
||||||
local updated = Milo:getItem(Milo:listItems(), item)
|
|
||||||
if updated then
|
|
||||||
Milo:craftAndEject(item, updated.count)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'eject_specified' then
|
|
||||||
local item = self.grid:getSelected()
|
|
||||||
local count = tonumber(self.statusBar.amount.value)
|
|
||||||
if item and count then
|
|
||||||
self.statusBar.amount:reset()
|
|
||||||
self:setFocus(self.statusBar.filter)
|
|
||||||
Milo:craftAndEject(item, count)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'network' then
|
|
||||||
UI:setPage('network')
|
|
||||||
|
|
||||||
elseif event.type == 'details' or event.type == 'grid_select_right' then
|
|
||||||
local item = self.grid:getSelected()
|
|
||||||
if item then
|
|
||||||
UI:setPage('item', item)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'refresh' then
|
|
||||||
self:refresh()
|
|
||||||
self.grid:draw()
|
|
||||||
self:setFocus(self.statusBar.filter)
|
|
||||||
|
|
||||||
elseif event.type == 'rescan' then
|
|
||||||
self:refresh(true)
|
|
||||||
self.grid:draw()
|
|
||||||
self:setFocus(self.statusBar.filter)
|
|
||||||
|
|
||||||
elseif event.type == 'toggle_display' then
|
|
||||||
displayMode = (displayMode + 1) % 3
|
|
||||||
Util.merge(event.button, displayModes[displayMode])
|
|
||||||
event.button:draw()
|
|
||||||
self:applyFilter()
|
|
||||||
self.grid:draw()
|
|
||||||
Milo:setState('displayMode', displayMode)
|
|
||||||
|
|
||||||
elseif event.type == 'learn' then
|
|
||||||
UI:setPage('learn')
|
|
||||||
|
|
||||||
elseif event.type == 'craft' then
|
|
||||||
local item = self.grid:getSelected()
|
|
||||||
if item then
|
|
||||||
if Craft.findRecipe(item) then -- or item.is_craftable then
|
|
||||||
UI:setPage('craft', self.grid:getSelected())
|
|
||||||
else
|
|
||||||
self.notification:error('No recipe defined')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
|
||||||
self.filter = event.text
|
|
||||||
if #self.filter == 0 then
|
|
||||||
self.filter = nil
|
|
||||||
end
|
|
||||||
self:applyFilter()
|
|
||||||
self.grid:draw()
|
|
||||||
self.statusBar.filter:focus()
|
|
||||||
|
|
||||||
else
|
|
||||||
UI.Page.eventHandler(self, event)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function listingPage:enable()
|
|
||||||
Event.onTimeout(0, function()
|
|
||||||
self:refresh()
|
|
||||||
self:draw()
|
|
||||||
self:sync()
|
|
||||||
|
|
||||||
self.timer = Event.onInterval(3, function()
|
|
||||||
for _,v in pairs(self.allItems) do
|
|
||||||
local c = context.storage.cache[v.key]
|
|
||||||
v.count = c and c.count or 0
|
|
||||||
end
|
|
||||||
self.grid:draw()
|
|
||||||
self:sync()
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function updateStatus()
|
|
||||||
self.statusBar.storageStatus.value =
|
|
||||||
context.storage:isOnline() and '' or 'offline'
|
|
||||||
self.statusBar.storageStatus.textColor =
|
|
||||||
context.storage:isOnline() and colors.lime or colors.red
|
|
||||||
end
|
|
||||||
updateStatus()
|
|
||||||
|
|
||||||
self.handler = Event.on({ 'storage_offline', 'storage_online' }, function()
|
|
||||||
updateStatus()
|
|
||||||
self.statusBar.storageStatus:draw()
|
|
||||||
self:sync()
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
self:setFocus(self.statusBar.filter)
|
|
||||||
UI.Page.enable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function listingPage:disable()
|
|
||||||
Event.off(self.timer)
|
|
||||||
Event.off(self.handler)
|
|
||||||
UI.Page.disable(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function listingPage:refresh(force)
|
|
||||||
local throttle = function() self.throttle:update() end
|
|
||||||
|
|
||||||
self.throttle:enable()
|
|
||||||
self.allItems = Milo:mergeResources(Milo:listItems(force, throttle))
|
|
||||||
self:applyFilter()
|
|
||||||
self.throttle:disable()
|
|
||||||
end
|
|
||||||
|
|
||||||
function listingPage:applyFilter()
|
|
||||||
local t = filterItems(self.allItems, self.filter)
|
|
||||||
self.grid:setValues(t)
|
|
||||||
end
|
|
||||||
|
|
||||||
UI:addPage('listing', listingPage)
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('craft2')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
local Craft = require('turtle.craft')
|
local Craft = require('craft2')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local sync = require('sync')
|
local sync = require('sync')
|
||||||
|
|||||||
Reference in New Issue
Block a user