Ui enhancements 2.0 #29

Merged
kepler155c merged 13 commits from ui-enhancements-2.0 into develop-1.8 2020-04-22 00:40:48 -04:00
39 changed files with 258 additions and 122 deletions
Showing only changes of commit 949c485539 - Show all commits

View File

@@ -724,8 +724,7 @@ function startPage:eventHandler(event)
Builder:begin()
elseif event.type == 'quit' then
UI.term:reset()
Event.exitPullEvents()
UI:quit()
end
return UI.Page.eventHandler(self, event)
@@ -769,5 +768,4 @@ UI:setPages({
})
UI:setPage('start')
UI:pullEvents()
UI:start()

View File

@@ -354,7 +354,7 @@ function categoryPage:eventHandler(event)
self:draw()
elseif event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
else
return UI.Page.eventHandler(self, event)
@@ -366,4 +366,4 @@ print("Retrieving catalog list")
categoryPage:setCategory(source.name, source.index)
UI:setPage(categoryPage)
UI:pullEvents()
UI:start()

View File

@@ -49,7 +49,7 @@ end
function peripheralsPage:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:quit()
elseif event.type == 'grid_select' then
UI:setPage('methods', event.selected)
@@ -198,4 +198,4 @@ UI:setPages({
methods = methodsPage,
})
UI:pullEvents()
UI:start()

View File

@@ -269,4 +269,4 @@ Event.onTimeout(.2, function()
end)
UI:setPage(page)
UI:pullEvents()
UI:start()

View File

@@ -90,7 +90,7 @@ local page = UI.Page {
self.grid:draw()
elseif event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
else
return UI.Page.eventHandler(self, event)

View File

@@ -238,6 +238,6 @@ Event.addRoutine(function()
end)
UI:setPage(page)
UI:pullEvents()
UI:start()
swarm:stop()

View File

@@ -60,4 +60,4 @@ function page:eventHandler(event)
end
UI:setPage(page)
UI:pullEvents()
UI:start()

View File

@@ -292,30 +292,42 @@ function page:runScript(scriptName)
print('Unable to read script file')
end
local socket = Socket.connect(turtle.id, 161)
if not socket then
print('Unable to connect to ' .. turtle.id)
return
end
local function processVariables(script)
local function processVariables()
local variables = {
COMPUTER_ID = os.getComputerID(),
COMPUTER_ID = os.getComputerID,
GPS = function()
local pt = require('opus.gps').getPoint()
if not pt then
error('Unable to determine location')
end
return _G.textutils.serialize(pt)
end,
}
for k,v in pairs(variables) do
local token = string.format('{%s}', k)
script = script:gsub(token, v)
if script:find(token, 1, true) then
local s, m = pcall(v)
if not s then
self.notification:error(m)
return
end
script = script:gsub(token, m)
end
end
return script
return true
end
script = processVariables(script)
if processVariables(script) then
local socket = Socket.connect(turtle.id, 161)
if not socket then
self.notification:error('Unable to connect')
return
end
socket:write({ type = 'script', args = script })
socket:close()
socket:write({ type = 'script', args = script })
socket:close()
self.notification:success('Sent')
self.notification:success('Sent')
end
end
end
@@ -339,7 +351,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
elseif event.type == 'tab_select' then
config.tab = event.button.text

View File

@@ -1,29 +0,0 @@
turtle.run(function()
_G.requireInjector(_ENV)
local GPS = require('opus.gps')
local Socket = require('opus.socket')
local id = {COMPUTER_ID}
if not turtle.enableGPS() then
error('turtle: No GPS found')
end
local socket = Socket.connect(id, 161)
if not socket then
error('turtle: Unable to connect to ' .. id)
end
socket:write({ type = 'gps' })
local pt = socket:read(3)
if not pt then
error('turtle: No GPS response')
end
if not turtle.pathfind(pt) then
error('Unable to go to location')
end
end)

View File

@@ -0,0 +1,17 @@
local turtle = _G.turtle
turtle.run(function()
_G.requireInjector(_ENV)
local GPS = require('opus.gps')
if not turtle.enableGPS() then
error('turtle: No GPS found')
end
local pt = {GPS}
if not turtle.pathfind(pt) then
error('Unable to go to location')
end
end)

View File

@@ -313,4 +313,4 @@ else
end
UI:setPage(page)
UI:pullEvents()
UI:start()

View File

@@ -216,7 +216,7 @@ _G._syslog = function(...)
end
local s, m = pcall(function()
UI:pullEvents()
UI:start()
end)
turtle.setStatus('idle')

View File

@@ -63,8 +63,8 @@ local page = UI.Page {
x = 1, ex = -13,
limit = 50,
shadowText = 'filter',
backgroundColor = colors.cyan,
backgroundFocusColor = colors.cyan,
backgroundColor = UI.colors.primary,
backgroundFocusColor = UI.colors.primary,
accelerators = {
[ 'enter' ] = 'eject',
[ 'up' ] = 'grid_up',
@@ -169,7 +169,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
elseif event.type == 'setup' then
self.setup.form:setValues(context.state)
@@ -524,7 +524,7 @@ local programDir = fs.getDir(shell.getRunningProgram())
loadDirectory(fs.combine(programDir, 'plugins/remote'))
UI:setPage(page)
UI:pullEvents()
UI:start()
if context.socket then
context.socket:close()

View File

@@ -54,8 +54,8 @@ local page = UI.Page {
limit = 50,
shadowText = 'filter',
shadowTextColor = colors.gray,
backgroundColor = colors.cyan,
backgroundFocusColor = colors.cyan,
backgroundColor = UI.colors.primary,
backgroundFocusColor = UI.colors.primary,
accelerators = {
[ 'enter' ] = 'eject',
[ 'up' ] = 'grid_up',
@@ -66,7 +66,7 @@ local page = UI.Page {
storageStatus = UI.Text {
x = -17, ex = -10,
textColor = colors.lime,
backgroundColor = colors.cyan,
backgroundColor = UI.colors.primary,
value = '',
},
amount = UI.TextEntry {
@@ -208,7 +208,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
elseif event.type == 'eject' or event.type == 'grid_select' then
self:eject(1)

View File

@@ -7,7 +7,6 @@ local Util = require('opus.util')
local colors = _G.colors
local device = _G.device
local turtle = _G.turtle
local context = Milo:getContext()
@@ -22,8 +21,8 @@ local networkPage = UI.Page {
y = -2, x = 1, ex = -9,
limit = 50,
shadowText = 'filter',
backgroundColor = colors.cyan,
backgroundFocusColor = colors.cyan,
backgroundColor = UI.colors.primary,
backgroundFocusColor = UI.colors.primary,
},
grid = UI.ScrollingGrid {
y = 2, ey = -3,
@@ -195,7 +194,6 @@ nodeWizard = UI.Page {
pages = {
general = UI.WizardPage {
index = 1,
backgroundColor = colors.cyan,
form = UI.Form {
x = 2, ex = -2, y = 1, ey = 3,
manualControls = true,
@@ -236,11 +234,10 @@ The settings will take effect immediately!]],
},
},
statusBar = UI.StatusBar {
backgroundColor = colors.cyan,
backgroundColor = UI.colors.primary,
},
notification = UI.Notification { },
filter = UI.SlideOut {
backgroundColor = colors.cyan,
noFill = true,
menuBar = UI.MenuBar {
buttons = {
@@ -292,7 +289,7 @@ The settings will take effect immediately!]],
},
},
statusBar = UI.StatusBar {
backgroundColor = colors.cyan,
backgroundColor = UI.colors.primary,
},
},
}

View File

@@ -17,7 +17,6 @@ Right-clicking on the activity monitor will reset the totals.]]
local wizardPage = UI.WizardPage {
title = 'Activity Monitor',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = 6,
marginRight = 0,

View File

@@ -3,7 +3,6 @@ local Event = require('opus.event')
local Milo = require('milo')
local UI = require('opus.ui')
local colors = _G.colors
local device = _G.device
local fs = _G.fs
local os = _G.os
@@ -23,7 +22,6 @@ Backup configuration files each minecraft day.
local wizardPage = UI.WizardPage {
title = 'Backup Drive',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = -2,
value = string.format(template, Ansi.yellow, Ansi.reset),

View File

@@ -18,7 +18,6 @@ Note that you do not need to import items from the brewing stand or export blaze
local wizardPage = UI.WizardPage {
title = 'Brewing Stand',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = -2,
value = string.format(template, Ansi.yellow, Ansi.reset),

View File

@@ -4,12 +4,10 @@ local itemDB = require('core.itemDB')
local colors = _G.colors
local device = _G.device
local context = Milo:getContext()
local wizardPage = UI.WizardPage {
title = 'Level Emitter',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, y = 1,
height = 2,

View File

@@ -1,7 +1,6 @@
local Ansi = require('opus.ansi')
local UI = require('opus.ui')
local colors = _G.colors
local device = _G.device
--[[ Configuration Screen ]]
@@ -14,7 +13,6 @@ Any items placed in this chest will be imported into storage.
local inputChestWizardPage = UI.WizardPage {
title = 'Input Chest',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = -2,
value = string.format(template, Ansi.yellow, Ansi.reset),

View File

@@ -1,12 +1,9 @@
local Ansi = require('opus.ansi')
local UI = require('opus.ui')
local colors = _G.colors
local infoTab = UI.Tab {
tabTitle = 'Info',
index = 4,
backgroundColor = colors.cyan,
textArea = UI.TextArea {
x = 2, ex = -2, y = 2, ey = -2,
},

View File

@@ -9,7 +9,6 @@ local context = Milo:getContext()
local machinesTab = UI.Tab {
tabTitle = 'Machine',
index = 3,
backgroundColor = colors.cyan,
grid = UI.ScrollingGrid {
x = 2, ex = -2, y = 2, ey = -2,
disableHeader = true,

View File

@@ -3,12 +3,9 @@ local itemDB = require('core.itemDB')
local Milo = require('milo')
local UI = require('opus.ui')
local colors = _G.colors
local recipeTab = UI.Tab {
tabTitle = 'Recipe',
index = 2,
backgroundColor = colors.cyan,
grid = UI.ScrollingGrid {
x = 2, ex = -2, y = 2, ey = -4,
disableHeader = true,

View File

@@ -15,7 +15,6 @@ local os = _G.os
local wizardPage = UI.WizardPage {
title = 'Crafting Monitor',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = 3,
marginRight = 0,

View File

@@ -10,7 +10,6 @@ local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
local context = ({ ... })[1]
local setup = UI.SlideOut {
backgroundColor = colors.cyan,
titleBar = UI.TitleBar {
title = 'Remote Setup',
},
@@ -51,7 +50,7 @@ local setup = UI.SlideOut {
[[also have an introspection module.]],
},
statusBar = UI.StatusBar {
backgroundColor = colors.cyan,
backgroundColor = UI.colors.primary,
},
}

View File

@@ -14,7 +14,6 @@ end
local wizardPage = UI.WizardPage {
title = 'Speaker',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.Text {
x = 2, y = 2,
textColor = colors.yellow,

View File

@@ -18,7 +18,6 @@ Right-clicking on the activity monitor will reset the totals.]]
local wizardPage = UI.WizardPage {
title = 'Status Monitor',
index = 2,
backgroundColor = colors.cyan,
[1] = UI.TextArea {
x = 2, ex = -2, y = 2, ey = 6,
marginRight = 0,
@@ -137,12 +136,14 @@ local function createPage(node)
},
[2] = UI.Tab {
tabTitle = 'Stats',
noFill = true,
textArea = UI.TextArea {
y = 3,
},
},
[3] = UI.Tab {
tabTitle = 'Storage',
noFill = true,
grid = UI.ScrollingGrid {
y = 2,
columns = {
@@ -157,6 +158,7 @@ local function createPage(node)
},
[4] = UI.Tab {
tabTitle = 'Offline',
noFill = true,
grid = UI.ScrollingGrid {
y = 2,
columns = {
@@ -167,12 +169,14 @@ local function createPage(node)
},
[5] = UI.Tab {
tabTitle = 'Activity',
noFill = true,
term = UI.Embedded {
--visible = true,
},
},
[6] = UI.Tab {
tabTitle = 'Tasks',
noFill = true,
grid = UI.ScrollingGrid {
y = 2,
values = context.tasks,

View File

@@ -7,7 +7,6 @@ local device = _G.device
local storageView = UI.WizardPage {
title = 'Storage Options - General',
index = 2,
backgroundColor = colors.cyan,
form = UI.Form {
x = 2, ex = -2, y = 1, ey = -2,
manualControls = true,
@@ -62,7 +61,6 @@ UI:getPage('nodeWizard').wizard:add({ storageGeneral = storageView })
local lockView = UI.WizardPage {
title = 'Storage Options - Locking',
index = 3,
backgroundColor = colors.cyan,
form = UI.Form {
x = 2, ex = -2, y = 1, ey = 3,
manualControls = true,

View File

@@ -12,7 +12,6 @@ local context = Milo:getContext()
local wizardPage = UI.WizardPage {
title = 'Transfer Inventory',
index = 2,
backgroundColor = colors.cyan,
grid = UI.ScrollingGrid {
y = 2, ey = -2,
values = context.storage.nodes,

View File

@@ -9,7 +9,6 @@ local device = _G.device
local wizardPage = UI.WizardPage {
title = 'Trashcan',
index = 2,
backgroundColor = colors.cyan,
info = UI.TextArea {
x = 1, ex = -1, y = 2, ey = 4,
textColor = colors.yellow,

142
neural/Equipment.lua Normal file
View File

@@ -0,0 +1,142 @@
local Event = require('opus.event')
local itemDB = require('core.itemDB')
local neural = require('neural.interface')
local UI = require('opus.ui')
local Util = require('opus.util')
local device = _G.device
neural.assertModules({
'plethora:sensor',
'plethora:kinetic',
'plethora:introspection',
})
UI:configure('Equipment', ...)
local equipment = device.neuralInterface.getEquipment()
local slots = {
'primary',
'offhand',
'boots',
'leggings',
'chest',
'helmet',
}
local page = UI.Page {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Drop', event = 'drop' },
{ text = 'Suck', event = 'suck' },
},
},
grid = UI.Grid {
y = 2,
columns = {
{ heading = 'Slot', key = 'index', width = 7 },
{ heading = 'Name', key = 'displayName' },
{ heading = 'Count', key = 'count', width = 5, align = 'right' },
},
sortColumn = 'index',
accelerators = {
grid_select = 'show_detail',
},
getDisplayValues = function(_, row)
row = Util.shallowCopy(row)
if row.name then
local item = itemDB:get(
table.concat({ row.name, row.damage, row.nbtHash }, ':'),
function()
return equipment.getItemMeta(row.index)
end)
row.displayName = item.displayName
else
row.displayName = 'empty'
end
row.index = slots[row.index]
return row
end,
},
accelerators = {
[ 'control-q' ] = 'quit',
},
detail = UI.SlideOut {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Back', event = 'slide_hide' },
},
},
grid = UI.ScrollingGrid {
y = 2,
columns = {
{ heading = 'Name', key = 'name' },
{ heading = 'Value', key = 'value' },
},
sortColumn = 'name',
accelerators = {
grid_select = 'inspect',
},
},
show = function(self, slot)
local detail = equipment.getItemMeta(slot.index)
local t = { }
for k,v in pairs(detail) do
table.insert(t, {
name = k,
value = v,
})
end
self.grid:setValues(t)
self.grid:setIndex(1)
UI.SlideOut.show(self)
end,
},
enable = function(self)
self:refresh()
UI.Page.enable(self)
end,
refresh = function(self)
local t = { }
local list = equipment.list()
for i = 1, equipment.size() do
local v = list[i] or { }
v.index = i
table.insert(t, v)
end
self.grid:setValues(t)
self.grid:draw()
end,
eventHandler = function(self, event)
if event.type == 'quit' then
UI:quit()
elseif event.type == 'show_detail' then
if event.selected.name then
self.detail:show(event.selected)
end
elseif event.type == 'drop' then
local selected = self.grid:getSelected()
equipment.drop(selected.index)
self:refresh()
elseif event.type == 'suck' then
local selected = self.grid:getSelected()
equipment.suck(selected.index)
self:refresh()
end
UI.Page.eventHandler(self, event)
end,
}
Event.onInterval(1, function()
page:refresh()
page:sync()
end)
UI:setPage(page)
UI:start()
itemDB:flush()

View File

@@ -182,7 +182,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:quit()
elseif event.type == 'scan' then
self:scan()
@@ -211,7 +211,7 @@ Event.onTimeout(0, function()
page:sync()
end)
UI:pullEvents()
UI:start()
if canvas then
canvas:clear()

View File

@@ -253,7 +253,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:quit()
elseif event.type == 'tab_activate' then
config.activeTab = event.activated.tabTitle
@@ -268,7 +268,7 @@ if config.activeTab then
end
UI:setPage(page)
UI:pullEvents()
UI:start()
if canvas then
canvas:clear()

View File

@@ -29,4 +29,10 @@
run = "ores.lua",
requires = "neuralInterface",
},
[ "7f2465ac7cefab2766e6ee0714647089df9364b0ff09858c84b21b8a436a845d" ] = {
title = "Equipment",
category = "Neural",
run = "Equipment",
requires = "neuralInterface",
}
}

View File

@@ -1,6 +1,15 @@
--[[
Breed either cows or sheep.
Must be run on a mob with the same height.
Changed to use a 2-high mob (smaller mobs may work ?)
Updated due to entity.look working correctly now.
The mob looks head-on to the lever. Make sure the
lever is accessible by the mob.
Laser is now optional - if no laser, the mobs will be
punched (or provide a stick). Best mob may be a
skeleton (unlimited ammo).
Feeding hand has been changed to off-hand.
]]
local Array = require('opus.array')
@@ -21,7 +30,7 @@ local WALK_SPEED = 1.5
neural.assertModules({
'plethora:sensor',
'plethora:scanner',
'plethora:laser',
--'plethora:laser',
'plethora:kinetic',
'plethora:introspection',
})
@@ -29,27 +38,27 @@ neural.assertModules({
local fed = { }
local function resupply()
local slot = neural.getEquipment().list()[1]
local slot = neural.getEquipment().list()[2]
if slot and slot.count > 32 then
return
end
print('resupplying')
for _ = 1, 2 do
local dispenser = Map.find(neural.scan(), 'name', 'minecraft:dispenser')
local dispenser = Map.find(neural.scan(), 'name', 'minecraft:lever')
if not dispenser then
print('dispenser not found')
break
end
if math.abs(dispenser.x) <= 1 and math.abs(dispenser.z) <= 1 then
neural.lookAt(dispenser)
neural.lookAt({ x = dispenser.x, y = dispenser.y, z = dispenser.z })
for _ = 1, 8 do
neural.use(0, 'off')
os.sleep(.2)
neural.getEquipment().suck(1, 64)
neural.getEquipment().suck(2, 64)
end
break
else
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED, .5)
end
end
end
@@ -63,18 +72,22 @@ local function breed(entity)
entity = neural.getMetaByID(entity.id)
if entity then
neural.lookAt(entity)
neural.use(1)
neural.use(1, 'off')
os.sleep(.1)
end
end
local function kill(entity)
print('killing')
neural.walkTo(entity, WALK_SPEED, 2.5)
neural.walkTo(entity, WALK_SPEED, (neural.fire or neural.shoot) and 2.5 or .5)
entity = neural.getMetaByID(entity.id)
if entity then
neural.lookAt(entity)
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
if neural.fire or neural.shoot then
neural.shootAt(entity)
else
neural.swing()
end
Sound.play('entity.firework.launch')
os.sleep(.2)
end

View File

@@ -172,11 +172,11 @@ function page:eventHandler(event)
self.info:draw()
elseif event.type == 'quit' then
UI:exitPullEvents()
UI:quit()
end
UI.Page.eventHandler(self, event)
end
UI:setPage(page)
UI:pullEvents()
UI:start()

View File

@@ -49,7 +49,7 @@ local function buildLockScreen()
#self.pass.value > 0 and
Security.verifyPassword(SHA.compute(self.pass.value)) then
UI:exitPullEvents() -- valid
UI:quit() -- valid
else
self.notification:error('Invalid password', math.max(counter, 2))
self:sync()
@@ -66,7 +66,7 @@ local function buildLockScreen()
Event.onTerminate(function() return false end)
UI:setPage(page)
UI:pullEvents()
UI:start()
-- restart lock timer
timer = os.startTimer(config.timeout)

View File

@@ -189,4 +189,4 @@ end)
page.grid:loadTransactions()
UI:setPage(page)
UI:pullEvents()
UI:start()

View File

@@ -9,7 +9,6 @@ local os = _G.os
local wizardPage = UI.WizardPage {
title = 'Store Front',
index = 2,
backgroundColor = colors.cyan,
form = UI.Form {
x = 2, ex = -2, y = 1, ey = -2,
manualControls = true,
@@ -90,7 +89,6 @@ end
local passwordPage = UI.WizardPage {
title = 'Krist Settings',
index = 3,
backgroundColor = colors.cyan,
form = UI.Form {
x = 2, ex = -2, y = 1, ey = -2,
manualControls = true,
@@ -112,7 +110,7 @@ local passwordPage = UI.WizardPage {
preview = UI.TextEntry {
formIndex = 4,
formLabel = 'Using address', formKey = 'address',
backgroundColor = colors.cyan,
backgroundColor = UI.colors.primary,
textColor = colors.yellow,
inactive = true,
},