2018-12-23 03:11:16 +00:00
|
|
|
local UI = require('ui')
|
|
|
|
|
|
|
|
local settings = _G.settings
|
|
|
|
|
|
|
|
if settings then
|
|
|
|
local values = { }
|
|
|
|
for _,v in pairs(settings.getNames()) do
|
|
|
|
local value = settings.get(v)
|
|
|
|
if not value then
|
|
|
|
value = false
|
|
|
|
end
|
|
|
|
table.insert(values, {
|
|
|
|
name = v,
|
|
|
|
value = value,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-01-30 20:11:41 +00:00
|
|
|
local settingsTab = UI.Tab {
|
2018-12-23 03:11:16 +00:00
|
|
|
tabTitle = 'Settings',
|
|
|
|
description = 'Computercraft configurable settings',
|
|
|
|
grid = UI.Grid {
|
2019-01-30 20:11:41 +00:00
|
|
|
y = 2,
|
2018-12-23 03:11:16 +00:00
|
|
|
values = values,
|
|
|
|
autospace = true,
|
|
|
|
sortColumn = 'name',
|
|
|
|
columns = {
|
|
|
|
{ heading = 'Setting', key = 'name' },
|
|
|
|
{ heading = 'Value', key = 'value' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
function settingsTab:eventHandler(event)
|
|
|
|
if event.type == 'grid_select' then
|
|
|
|
if not event.selected.value or type(event.selected.value) == 'boolean' then
|
|
|
|
event.selected.value = not event.selected.value
|
|
|
|
end
|
|
|
|
settings.set(event.selected.name, event.selected.value)
|
|
|
|
settings.save('.settings')
|
|
|
|
self.grid:draw()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return settingsTab
|
|
|
|
end
|