This commit is contained in:
kepler155c@gmail.com 2017-04-15 23:39:15 -04:00
parent a074213b7c
commit 4546b9c726
5 changed files with 59 additions and 113 deletions

View File

@ -8,6 +8,15 @@ multishell.setTitle(multishell.getCurrent(), 'Turtles')
UI.Button.defaults.focusIndicator = ' '
UI:configure('Turtles', ...)
local options = {
turtle = { arg = 'i', type = 'number', value = -1,
desc = 'Turtle ID' },
tab = { arg = 's', type = 'string', value = 'inventory',
desc = 'Selected tab to display' },
help = { arg = 'h', type = 'flag', value = false,
desc = 'Displays the options' },
}
local SCRIPTS_PATH = '/apps/scripts'
local ct = term.current()
@ -62,7 +71,7 @@ local page = UI.Page {
},
]]
coords = UI.Window {
x = 16, y = 2, height = 4, width = 9,
x = 14, y = 2, height = 5, rex = -2,
},
tabs = UI.Tabs {
x = 1, y = 8, rey = -2,
@ -146,7 +155,8 @@ function page.coords:draw()
if t then
self:clear()
self:setCursorPos(1, 1)
self:print(string.format('%s\nx: %d\ny: %d\nz: %d\n', t.coordSystem, t.point.x, t.point.y, t.point.z))
self:print(string.format('%s\nx: %d\ny: %d\nz: %d\nFuel: %s\n',
t.coordSystem, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel)))
end
end
@ -282,7 +292,17 @@ local function updateThread()
end
end
if not Util.getOptions(options, { ... }, true) then
return
end
if options.turtle.value then
page.turtle = _G.network[options.turtle.value]
end
UI:setPage(page)
page.tabs:activateTab(page.tabs[options.tab.value])
Event.pullEvents(updateThread)
UI.term:reset()

View File

@ -40,12 +40,14 @@ function getItemDetails(item)
detail = controller.findItem(item)
if detail then
Util.merge(detail, detail.getMetadata())
detail.displayName = safeString(detail.displayName)
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
detail.displayName = detail.displayName .. ' (damaged)'
if detail.displayName then
detail.displayName = safeString(detail.displayName)
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
detail.displayName = detail.displayName .. ' (damaged)'
end
detail.lname = detail.displayName:lower()
cache[key] = detail
end
detail.lname = detail.displayName:lower()
cache[key] = detail
end
end
return detail
@ -303,7 +305,6 @@ function itemPage.displayName:draw()
if item.nbtHash then
str = str .. string.format('\nNBT: %s\n', item.nbtHash)
end
debug(str)
self:setCursorPos(1, 1)
self:print(str)
end
@ -478,11 +479,7 @@ function listingPage:enable()
end
function listingPage:refresh()
local t = os.clock()
self.allItems = listItems()
debug('list items')
debug(os.clock() - t)
mergeResources(self.allItems)
self:applyFilter()
end
@ -492,43 +489,6 @@ function listingPage:applyFilter()
self.grid:setValues(t)
end
local nullDevice = {
setCursorPos = function(...) end,
write = function(...) end,
getSize = function() return 13, 20 end,
isColor = function() return false end,
setBackgroundColor = function(...) end,
setTextColor = function(...) end,
clear = function(...) end,
sync = function(...) end,
}
local function jobMonitor(jobList)
local mon = Peripheral.getByType('monitor')
if mon then
mon = UI.Device({
device = mon,
textScale = .5,
})
else
mon = UI.Device({
device = nullDevice
})
end
jobListGrid = UI.Grid {
parent = mon,
sortColumn = 'displayName',
columns = {
{ heading = 'Qty', key = 'count', width = 6 },
{ heading = 'Crafting', key = 'displayName', width = mon.width / 2 - 10 },
{ heading = 'Status', key = 'status', width = mon.width - 10 },
},
}
end
local function jobMonitor(jobList)
local mon = Peripheral.getByType('monitor')

View File

@ -1,13 +1,10 @@
require = requireInjector(getfenv(1))
local Util = require('util')
local Event = require('event')
local UI = require('ui')
local RefinedProvider = require('refinedProvider')
local MEProvider = require('meProvider')
if not device.monitor then
error('Monitor not found')
end
local storage = RefinedProvider()
if not storage:isValid() then
storage = MEProvider()
@ -17,45 +14,21 @@ if not storage:isValid() then
error('Not connected to a storage device')
end
local monitor = UI.Device({
deviceType = 'monitor',
textScale = .5
})
UI:setDefaultDevice(monitor)
multishell.setTitle(multishell.getCurrent(), 'Storage Activity')
UI:configure('StorageActivity', ...)
-- Strip off color prefix
local function safeString(text)
local val = text:byte(1)
if val < 32 or val > 128 then
local newText = {}
for i = 4, #text do
local val = text:byte(i)
newText[i - 3] = (val > 31 and val < 127) and val or 63
end
return string.char(unpack(newText))
end
return text
end
local changedPage = UI.Page({
grid = UI.Grid({
columns = {
{ heading = 'Qty', key = 'dispQty', width = 5 },
{ heading = 'Change', key = 'change', width = 6 },
{ heading = 'Name', key = 'name', width = monitor.width - 15 },
{ heading = 'Qty', key = 'qty', width = 5 },
{ heading = 'Change', key = 'change', width = 6 },
{ heading = 'Name', key = 'display_name', width = UI.term.width - 15 },
},
sortColumn = 'name',
height = monitor.height - 6,
sortColumn = 'display_name',
rey = -6,
}),
buttons = UI.Window({
y = monitor.height - 5,
ry = -4,
height = 5,
backgroundColor = colors.gray,
prevButton = UI.Button({
@ -73,31 +46,37 @@ local changedPage = UI.Page({
x = 8,
y = 2,
height = 3,
width = monitor.width - 14,
rex = -8,
text = 'Reset'
}),
nextButton = UI.Button({
event = 'next',
backgroundColor = colors.lightGray,
x = monitor.width - 5,
rx = -5,
y = 2,
height = 3,
width = 5,
text = ' > '
})
}),
statusBar = UI.StatusBar({
columns = {
{ '', 'slots', 18 },
{ '', 'spacer', monitor.width-36 },
{ '', 'space', 15 }
}
}),
accelerators = {
q = 'quit',
}
})
function changedPage.grid:getDisplayValues(row)
row = Util.shallowCopy(row)
local ind = '+'
if row.change < 0 then
ind = ''
end
row.change = ind .. Util.toBytes(row.change)
row.qty = Util.toBytes(row.qty)
return row
end
function changedPage:eventHandler(event)
if event.type == 'reset' then
@ -132,11 +111,7 @@ function changedPage:refresh()
end
for k,v in pairs(t) do
--v.id = v.id
--v.dmg = v.dmg
v.name = safeString(v.display_name)
t[k] = Util.shallowCopy(v)
--v.qty = v.qty
end
if not self.lastItems then
@ -172,22 +147,14 @@ function changedPage:refresh()
v.lastQty = 0
table.insert(changedItems, v)
end
for k,v in pairs(changedItems) do
local diff = v.qty - v.lastQty
local ind = '+'
if v.qty < v.lastQty then
ind = ''
end
v.change = ind .. diff
v.dispQty = v.qty
if v.dispQty > 10000 then
v.dispQty = math.floor(v.qty / 1000) .. 'k'
end
v.iddmg = tostring(v.id) .. ':' .. tostring(v.dmg)
v.change = v.qty - v.lastQty
end
self.grid:setValues(changedItems)
end
self:draw()
self.grid:draw()
end
Event.addTimer(5, true, function()
@ -196,5 +163,5 @@ Event.addTimer(5, true, function()
end)
UI:setPage(changedPage)
Event.pullEvents()
UI:pullEvents()
UI.term:reset()

View File

@ -1,5 +1,4 @@
local class = require('class')
local Logger = require('logger')
local ChestProvider = class()

View File

@ -357,9 +357,9 @@ end
--[[ String functions ]] --
function Util.toBytes(n)
if n >= 1000000 then
if n >= 1000000 or n <= -1000000 then
return string.format('%sM', Util.round(n/1000000, 1))
elseif n >= 1000 then
elseif n >= 1000 or n <= -1000 then
return string.format('%sK', Util.round(n/1000, 1))
end
return tostring(n)