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
15 changed files with 209 additions and 32 deletions
Showing only changes of commit e2aac13e8f - Show all commits

View File

@@ -38,7 +38,7 @@ local APP_DIR = 'usr/apps'
local source = {
text = "STD Default",
event = 'source',
url = "http://pastebin.com/raw/zVws7eLq",
url = "https://github.com/LDDestroier/STD-GUI/raw/master/list.lua",
}
shell.setDir(APP_DIR)
@@ -325,7 +325,7 @@ function categoryPage:setCategory(name, index)
table.insert(self.grid.values, v)
end
end
self.statusBar:setStatus(string.format('%s: %s', self.source.text, name))
self.statusBar:setStatus(string.format('%s: %s', self.source.text or '', name))
self.grid:update()
self.grid:setIndex(1)
end
@@ -346,7 +346,7 @@ function categoryPage:eventHandler(event)
UI:setPage(appPage, self.grid:getSelected())
elseif event.type == 'category' then
self:setCategory(self.source, event.button.text, event.button.index)
self:setCategory(event.button.text, event.button.index)
self:setFocus(self.grid)
self:draw()

View File

@@ -6,7 +6,6 @@ local Event = require('opus.event')
local colors = _G.colors
local fs = _G.fs
local gps = _G.gps
local os = _G.os
local peripheral = _G.peripheral
local read = _G.read
@@ -200,7 +199,7 @@ local function server(mode)
error('Modem is not activated or connected: ' .. k)
end
if mode == 'gps' then
modem.open(gps.CHANNEL_GPS)
modem.open(GPS.CHANNEL_GPS)
elseif mode == 'snmp' then
modem.open(999)
end
@@ -254,9 +253,9 @@ local function server(mode)
Event.on('modem_message', function(_, side, channel, computerId, message, distance)
if distance and modems[side] then
if mode == 'gps' and channel == gps.CHANNEL_GPS and message == "PING" then
if mode == 'gps' and channel == GPS.CHANNEL_GPS and message == "PING" then
for _, modem in pairs(modems) do
modem.transmit(computerId, gps.CHANNEL_GPS, { modem.x, modem.y, modem.z })
modem.transmit(computerId, GPS.CHANNEL_GPS, { modem.x, modem.y, modem.z })
end
getPosition(computerId, modems[side], distance)
end

View File

@@ -60,7 +60,7 @@ local page = UI.Page {
statusBar = UI.Window {
y = -1,
filter = UI.TextEntry {
x = 1, ex = -12,
x = 1, ex = -13,
limit = 50,
shadowText = 'filter',
backgroundColor = colors.cyan,
@@ -73,8 +73,8 @@ local page = UI.Page {
},
},
amount = UI.TextEntry {
x = -11, ex = -7,
limit = 3,
x = -12, ex = -7,
limit = 4,
shadowText = '1',
shadowTextColor = colors.gray,
backgroundColor = colors.black,

View File

@@ -50,7 +50,7 @@ local page = UI.Page {
},
statusBar = UI.StatusBar {
filter = UI.TextEntry {
x = 1, ex = -17,
x = 1, ex = -18,
limit = 50,
shadowText = 'filter',
shadowTextColor = colors.gray,
@@ -64,14 +64,14 @@ local page = UI.Page {
},
},
storageStatus = UI.Text {
x = -16, ex = -9,
x = -17, ex = -10,
textColor = colors.lime,
backgroundColor = colors.cyan,
value = '',
},
amount = UI.TextEntry {
x = -8, ex = -4,
limit = 3,
x = -9, ex = -4,
limit = 4,
shadowText = '1',
shadowTextColor = colors.gray,
backgroundColor = colors.black,

View File

@@ -0,0 +1,29 @@
local itemDB = require('core.itemDB')
local Milo = require('milo')
local device = _G.device
local EmitterTask = {
name = 'emitter',
priority = 5,
}
local function filter(a)
return a.emitter
end
function EmitterTask:cycle(context)
for node in context.storage:filterActive('emitter', filter) do
local config = node.emitter
local item = Milo:getItem(itemDB:splitKey(config.item))
config.signal = not not config.signal
if item and item.count >= config.amount then
device[node.name].setOutput(config.side, config.signal)
else
device[node.name].setOutput(config.side, not config.signal)
end
end
end
Milo:registerTask(EmitterTask)

View File

@@ -0,0 +1,109 @@
local Milo = require('milo')
local UI = require('opus.ui')
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,
textColor = colors.yellow,
value = 'Emit a redstone signal if an\nitem amount if over a threshold',
},
form = UI.Form {
x = 1, ex = -1, y = 3, ey = -1,
manualControls = true,
itemName = UI.TextEntry {
formLabel = 'Item', formKey = 'item', formIndex = 1,
help = 'Item to monitor',
required = true,
},
side = UI.Chooser {
formLabel = 'Side', formKey = 'side', formIndex = 2,
width = 10,
choices = {
{name = 'Down', value = 'down'},
{name = 'Up', value = 'up'},
{name = 'North', value = 'north'},
{name = 'South', value = 'south'},
{name = 'West', value = 'west'},
{name = 'East', value = 'east'},
},
required = true,
},
amount = UI.TextEntry {
formLabel = 'Amount', formKey = 'amount', formIndex = 3,
width = 7,
transform = 'number',
help = 'Threshold value',
required = true,
},
signal = UI.Checkbox {
formLabel = 'Signal', formKey = 'signal', formIndex = 4,
help = 'Enable redstone signal when over threshold',
},
scanItem = UI.Button {
x = 15, y = 6,
text = 'Scan item', event = 'scan_turtle',
help = 'Scan an item from the turtle inventory',
},
},
}
function wizardPage:setNode(node)
self.node = node
if not self.node.emitter then
self.node.emitter = {
signal = { value = true }
}
end
self.form:setValues(self.node.emitter)
end
function wizardPage:validate()
return self.form:save()
end
function wizardPage:isValidType(node)
local m = device[node.name]
return m and m.type == 'redstone_integrator' and {
name = 'Level Emitter',
value = 'emitter',
category = 'custom',
help = 'Emit redstone signals',
}
end
function wizardPage:isValidFor(node)
return node.mtype == 'emitter'
end
function wizardPage:enable()
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
UI.WizardPage.enable(self)
end
function wizardPage:disable()
Milo:resumeCrafting({ key = 'gridInUse' })
UI.WizardPage.disable(self)
end
function wizardPage:eventHandler(event)
if event.type == 'scan_turtle' then
local inventory = Milo:getTurtleInventory()
for _,item in pairs(inventory) do
self.form.itemName.value = itemDB:makeKey(item)
break
end
self:draw()
Milo:emptyInventory()
end
end
UI:getPage('nodeWizard').wizard:add({ emiter = wizardPage })

View File

@@ -27,6 +27,9 @@ function infoTab:draw()
value = value .. item.nbtHash .. '\n'
end
value = value .. string.format('\n%sCount:%s %s',
Ansi.yellow, Ansi.reset, item.count)
value = value .. string.format('\n%sDamage:%s %s',
Ansi.yellow, Ansi.reset, item.damage)

View File

@@ -6,8 +6,8 @@
-- Updated to use new(ish) canvas3d
local Config = require('opus.config')
local GPS = require("opus.gps")
local gps = _G.gps
local keys = _G.keys
local os = _G.os
local parallel = _G.parallel
@@ -35,14 +35,7 @@ end
local BLOCK_SIZE = .5
local function getPoint()
local pt = { gps.locate() }
if pt[1] then
return {
x = pt[1],
y = pt[2],
z = pt[3],
}
end
return GPS.locate()
end
local targets = Config.load('ores', {

View File

@@ -1,4 +1,7 @@
{
required = {
'milo',
},
title = 'Switchcraft basic shop',
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/swshop',
description = 'Modification of the k store by Lemmmy\nRun installPlugin.lua after install',

View File

@@ -141,7 +141,7 @@ end
function page.grid:getDisplayValues(row)
row = Util.shallowCopy(row)
local x = row.recipient
row.from = x and x:match('(%w+)@') or row.from
row.from = x and x:match('(.+)@') or row.from
return row
end

25
swshop/help/swshop Normal file
View File

@@ -0,0 +1,25 @@
An item shop software using Krist as its currency.
Requirements
============
* Advanced Turtle
* Chests (any type)
* Milo system
Installation
============
> pastebin run uzghlbnc
> package install swshop
> reboot
Setup
=====
From the shell, run the 'installPlugin.lua' once to install the shop component into your Milo installation.
From Milo, open the setup page and find the monitor you wish to use in the list.
Choose the monitor's type to be 'Store Front', and configure your domain and your wallet's key.
Usage
=====
Setup prices by right-clicking on the desired item and going on the 'Shops' tab.

View File

@@ -33,8 +33,22 @@ local wizardPage = UI.WizardPage {
limit = 64,
},
[4] = UI.Chooser {
formLabel = 'RS Signal', formKey = 'rsSide', formIndex = 5,
width = 10,
nochoice = 'Top',
choices = {
{name = 'Bottom', value = 'bottom'},
{name = 'Top', value = 'top'},
{name = 'Back', value = 'back'},
{name = 'Front', value = 'front'},
{name = 'Right', value = 'right'},
{name = 'Left', value = 'left'},
},
required = true,
},
[5] = UI.Chooser {
width = 9,
formIndex = 5,
formIndex = 6,
formLabel = 'Font Size', formKey = 'textScale',
nochoice = 'Small',
choices = {

View File

@@ -25,7 +25,7 @@ local shopTab = UI.Tab {
formLabel = 'Price', formKey = 'price',
help = 'Per item cost',
required = true,
transform = 'number',
validate = 'numeric',
},
[3] = UI.TextEntry {
limit = 64,

View File

@@ -19,7 +19,7 @@ local textutils = _G.textutils
local chat = device['plethora:chat']
local storage = Config.load('storage')
rs.setOutput('top', false)
Util.each(rs.getSides(), function(side) rs.setOutput(side, false) end)
r.init(jua)
w.init(jua)
@@ -29,9 +29,10 @@ local node = ({ ... })[1] or error('Node name is required')
local config = storage[node]
local privatekey = config.isPrivateKey and config.password or Krist.toKristWalletFormat(config.password)
local address = Krist.makev2address(privatekey)
local rsSide = config.rsSide or 'top'
jua.on("terminate", function()
rs.setOutput('top', false)
rs.setOutput(rsSide, false)
jua.stop()
_G.printError("Terminated")
end)
@@ -44,7 +45,7 @@ local function getItemDetails(item)
t = textutils.unserialize(t)
for key, v in pairs(t) do
if v.name == item then
return key, v.price
return key, tonumber(v.price)
end
end
end
@@ -144,7 +145,7 @@ local function connect()
assert(success, "Failed to get websocket URL")
print("Connected to websocket.")
rs.setOutput('top', true)
rs.setOutput(rsSide, true)
success = await(ws.subscribe, "ownTransactions", function(data)
local transaction = data.transaction
@@ -160,7 +161,7 @@ local s, m = pcall(function()
end)
end)
rs.setOutput('top', false)
rs.setOutput(rsSide, false)
if not s then
error(m, 2)
end

View File

@@ -391,8 +391,9 @@ end
if type(turtle.getFuelLevel()) ~= 'number' then
-- Support unlimited fuel
function turtle.getFuelLevel()
return 100000
return math.huge
end
turtle.getFuelLimit = turtle.getFuelLevel
end
-- override to optionally specify a fuel