wizard and tab rework
This commit is contained in:
@@ -5,7 +5,6 @@ local Socket = require('opus.socket')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
local multishell = _ENV.multishell
|
||||
local network = _G.network
|
||||
@@ -31,7 +30,7 @@ local socket, turtle, page
|
||||
|
||||
page = UI.Page {
|
||||
coords = UI.Window {
|
||||
backgroundColor = colors.black,
|
||||
backgroundColor = 'black',
|
||||
height = 3,
|
||||
marginTop = 1, marginLeft = 1,
|
||||
draw = function(self)
|
||||
@@ -50,156 +49,149 @@ page = UI.Page {
|
||||
},
|
||||
tabs = UI.Tabs {
|
||||
x = 1, y = 4, ey = -2,
|
||||
scripts = UI.ScrollingGrid {
|
||||
tabTitle = 'Run',
|
||||
backgroundColor = colors.cyan,
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
UI.Tab {
|
||||
title = 'Run',
|
||||
scripts = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
local files = fs.list(SCRIPTS_PATH)
|
||||
for _,path in pairs(files) do
|
||||
table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) })
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
page:runScript(event.selected.label)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
local files = fs.list(SCRIPTS_PATH)
|
||||
for _,path in pairs(files) do
|
||||
table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) })
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
page:runScript(event.selected.label)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
turtles = UI.ScrollingGrid {
|
||||
tabTitle = 'Select',
|
||||
backgroundColor = colors.cyan,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.fuel then
|
||||
row.fuel = Util.toBytes(row.fuel)
|
||||
end
|
||||
if row.distance then
|
||||
row.distance = Util.round(row.distance, 1)
|
||||
end
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
for _,v in pairs(network) do
|
||||
if v.fuel then
|
||||
table.insert(self.values, v)
|
||||
UI.Tab {
|
||||
title = 'Select',
|
||||
turtles = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.fuel then
|
||||
row.fuel = Util.toBytes(row.fuel)
|
||||
end
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
turtle = event.selected
|
||||
config.id = event.selected.id
|
||||
Config.update('Turtles', config)
|
||||
multishell.setTitle(multishell.getCurrent(), turtle.label)
|
||||
if socket then
|
||||
socket:close()
|
||||
socket = nil
|
||||
if row.distance then
|
||||
row.distance = Util.round(row.distance, 1)
|
||||
end
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
inventory = UI.ScrollingGrid {
|
||||
backgroundColor = colors.cyan,
|
||||
tabTitle = 'Inv',
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = '', key = 'count', width = 2 },
|
||||
{ heading = 'Inventory', key = 'key' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if turtle and row.selected then
|
||||
return colors.yellow
|
||||
end
|
||||
return UI.ScrollingGrid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
draw = function(self)
|
||||
local t = turtle
|
||||
Util.clear(self.values)
|
||||
if t then
|
||||
for k,v in pairs(t.inv or { }) do -- new method (less data)
|
||||
local index, count = k:match('(%d+),(%d+)')
|
||||
v = {
|
||||
index = tonumber(index),
|
||||
key = v,
|
||||
count = tonumber(count),
|
||||
}
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
|
||||
for _,v in pairs(t.inventory or { }) do
|
||||
if v.count > 0 then
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
for _,v in pairs(network) do
|
||||
if v.fuel then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
end
|
||||
|
||||
for _,v in pairs(self.values) do
|
||||
if v.index == t.slotIndex then
|
||||
v.selected = true
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
turtle = event.selected
|
||||
config.id = event.selected.id
|
||||
Config.update('Turtles', config)
|
||||
multishell.setTitle(multishell.getCurrent(), turtle.label)
|
||||
if socket then
|
||||
socket:close()
|
||||
socket = nil
|
||||
end
|
||||
if v.key then
|
||||
v.key = itemDB:getName(v.key)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
},
|
||||
UI.Tab {
|
||||
title = 'Inv',
|
||||
inventory = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = '', key = 'count', width = 2 },
|
||||
{ heading = 'Inventory', key = 'key' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if turtle and row.selected then
|
||||
return 'yellow'
|
||||
end
|
||||
return UI.ScrollingGrid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
draw = function(self)
|
||||
local t = turtle
|
||||
Util.clear(self.values)
|
||||
if t then
|
||||
for k,v in pairs(t.inv or { }) do -- new method (less data)
|
||||
local index, count = k:match('(%d+),(%d+)')
|
||||
v = {
|
||||
index = tonumber(index),
|
||||
key = v,
|
||||
count = tonumber(count),
|
||||
}
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
|
||||
for _,v in pairs(t.inventory or { }) do
|
||||
if v.count > 0 then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
end
|
||||
|
||||
for _,v in pairs(self.values) do
|
||||
if v.index == t.slotIndex then
|
||||
v.selected = true
|
||||
end
|
||||
if v.key then
|
||||
v.key = itemDB:getName(v.key)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self:adjustWidth()
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
local fn = string.format('turtle.select(%d)', event.selected.index)
|
||||
page:runFunction(fn)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
--[[
|
||||
policy = UI.ScrollingGrid {
|
||||
tabTitle = 'Mod',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
self:adjustWidth()
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
local fn = string.format('turtle.select(%d)', event.selected.index)
|
||||
page:runFunction(fn)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
values = policies,
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
]]
|
||||
action = UI.Window {
|
||||
tabTitle = 'Action',
|
||||
backgroundColor = colors.cyan,
|
||||
UI.Tab {
|
||||
title = 'Action',
|
||||
backgroundColor = 'primary',
|
||||
moveUp = UI.Button {
|
||||
x = 5, y = 2,
|
||||
text = 'up',
|
||||
@@ -233,8 +225,41 @@ page = UI.Page {
|
||||
info = UI.TextArea {
|
||||
x = 15, y = 2,
|
||||
inactive = true,
|
||||
}
|
||||
},
|
||||
showBlocks = function(self)
|
||||
local script = [[
|
||||
local function inspect(direction)
|
||||
local s,b = turtle['inspect' .. (direction or '')]()
|
||||
if not s then
|
||||
return 'minecraft:air:0'
|
||||
end
|
||||
return string.format('%s:%d', b.name, b.metadata)
|
||||
end
|
||||
|
||||
local bu, bf, bd = inspect('Up'), inspect(), inspect('Down')
|
||||
return string.format('%s\n%s\n%s', bu, bf, bd)
|
||||
]]
|
||||
|
||||
local s, m = self:runFunction(script, true)
|
||||
self.info:setText(s or m)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'button_press' then
|
||||
if event.button.fn then
|
||||
self:runFunction(event.button.fn, event.button.nowrap)
|
||||
self:showBlocks()
|
||||
end
|
||||
return true
|
||||
end
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
enable = function(self)
|
||||
if config.tab then
|
||||
self:selectTab(Util.find(self, 'title', config.tab))
|
||||
end
|
||||
UI.Tabs.enable(self)
|
||||
end
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
values = { },
|
||||
@@ -331,24 +356,6 @@ function page:runScript(scriptName)
|
||||
end
|
||||
end
|
||||
|
||||
function page:showBlocks()
|
||||
local script = [[
|
||||
local function inspect(direction)
|
||||
local s,b = turtle['inspect' .. (direction or '')]()
|
||||
if not s then
|
||||
return 'minecraft:air:0'
|
||||
end
|
||||
return string.format('%s:%d', b.name, b.metadata)
|
||||
end
|
||||
|
||||
local bu, bf, bd = inspect('Up'), inspect(), inspect('Down')
|
||||
return string.format('%s\n%s\n%s', bu, bf, bd)
|
||||
]]
|
||||
|
||||
local s, m = self:runFunction(script, true)
|
||||
self.tabs.action.info:setText(s or m)
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'quit' then
|
||||
UI:quit()
|
||||
@@ -357,13 +364,6 @@ function page:eventHandler(event)
|
||||
config.tab = event.button.text
|
||||
Config.update('Turtles', config)
|
||||
|
||||
elseif event.type == 'button_press' then
|
||||
if event.button.fn then
|
||||
self:runFunction(event.button.fn, event.button.nowrap)
|
||||
self:showBlocks()
|
||||
elseif event.button.script then
|
||||
self:runScript(event.button.script)
|
||||
end
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
@@ -393,9 +393,5 @@ Event.onInterval(1, function()
|
||||
end
|
||||
end)
|
||||
|
||||
if config.tab then
|
||||
page.tabs.tabBar:selectTab(config.tab)
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
UI:start()
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
category = "Apps",
|
||||
requires = "advancedComputer",
|
||||
iconExt = "\030 \031 \128\030d\159\030 \031d\140\030d\031 \155\030 \0315\140\0305\031 \155\030 \128\010\030 \031d\136\145\0315\136\145\031d\153\031 \128\0315\153\010\030 \031 \128\031d\130\140\134\0315\140\134\031 \128",
|
||||
run = "fileui --exec=hexedit.lua",
|
||||
run = "fileui --exec=hexedit.lua --title=hexedit",
|
||||
},
|
||||
[ "fb1c39e9f4f3c2628ad173ab401a6e4e4baf783d" ] = {
|
||||
title = "Sounds",
|
||||
|
||||
@@ -308,7 +308,7 @@ local containerText = {
|
||||
}
|
||||
|
||||
local containTab = UI.Tab {
|
||||
tabTitle = 'Contain',
|
||||
title = 'Contain',
|
||||
button = UI.Button {
|
||||
x = 2, y = 2,
|
||||
text = 'Set corner',
|
||||
@@ -321,7 +321,7 @@ local containTab = UI.Tab {
|
||||
}
|
||||
|
||||
local blocksTab = UI.Tab {
|
||||
tabTitle = 'Blocks',
|
||||
title = 'Blocks',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 1,
|
||||
columns = {
|
||||
@@ -333,7 +333,7 @@ local blocksTab = UI.Tab {
|
||||
}
|
||||
|
||||
local turtlesTab = UI.Tab {
|
||||
tabTitle = 'Turtles',
|
||||
title = 'Turtles',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 1,
|
||||
values = pool,
|
||||
|
||||
Reference in New Issue
Block a user