milo shop updates

This commit is contained in:
kepler155c@gmail.com
2019-01-11 14:59:33 -05:00
parent bfa528756e
commit 17912f6054
5 changed files with 91 additions and 40 deletions

View File

@@ -25,6 +25,11 @@ local storeTab = UI.Window {
required = true, required = true,
validate = 'numeric', validate = 'numeric',
}, },
[3] = UI.TextEntry {
limit = 64,
formLabel = 'Extra Info', formKey = 'info',
help = 'Additional info to display for item',
},
clearButton = UI.Button { clearButton = UI.Button {
x = 2, y = -2, x = 2, y = -2,
event = 'clear', event = 'clear',
@@ -58,6 +63,7 @@ function storeTab:eventHandler(event)
os.queueEvent('store_refresh') os.queueEvent('store_refresh')
self:emit({ type = 'success_message', message = 'Updated' }) self:emit({ type = 'success_message', message = 'Updated' })
end end
else else
return return
end end

View File

@@ -13,9 +13,9 @@ local wizardPage = UI.Window {
manualControls = true, manualControls = true,
[1] = UI.TextEntry { [1] = UI.TextEntry {
formLabel = 'Domain', formKey = 'domain', formLabel = 'Domain', formKey = 'domain',
help = 'Krist wallet address', help = 'Krist wallet domain (minus .kst)',
limit = 64, limit = 64,
shadowText = 'example.kst', shadowText = 'example',
required = true, required = true,
}, },
[2] = UI.TextEntry { [2] = UI.TextEntry {
@@ -25,7 +25,14 @@ local wizardPage = UI.Window {
required = true, required = true,
help = 'Krist wallet password', help = 'Krist wallet password',
}, },
[3] = UI.Chooser { [3] = UI.TextEntry {
formLabel = 'Header', formKey = 'header',
help = 'Text to show in header',
limit = 64,
shadowText = "xxxx's shop",
required = false,
},
[4] = UI.Chooser {
width = 9, width = 9,
formLabel = 'Font Size', formKey = 'textScale', formLabel = 'Font Size', formKey = 'textScale',
nochoice = 'Small', nochoice = 'Small',
@@ -54,14 +61,14 @@ function wizardPage:isValidType(node)
local m = device[node.name] local m = device[node.name]
return m and m.type == 'monitor' and { return m and m.type == 'monitor' and {
name = 'Store Front', name = 'Store Front',
value = 'store', value = 'shop',
category = 'display', category = 'display',
help = 'Add a store front display' help = 'Add a store front display'
} }
end end
function wizardPage:isValidFor(node) function wizardPage:isValidFor(node)
return node.mtype == 'store' return node.mtype == 'shop'
end end
UI:getPage('nodeWizard').wizard:add({ storeFront = wizardPage }) UI:getPage('nodeWizard').wizard:add({ storeFront = wizardPage })

View File

@@ -24,55 +24,92 @@ local function createPage(node)
local page = UI.Page { local page = UI.Page {
parent = monitor, parent = monitor,
header = UI.Window {
backgroundColor = colors.blue,
ey = 3,
},
grid = UI.Grid { grid = UI.Grid {
ey = -6, y = 4, ey = -7,
headerHeight = 3,
headerBackgroundColor = colors.gray,
backgroundSelectedColor = colors.black,
unfocusedBackgroundSelectedColor = colors.gray,
columns = { columns = {
{ heading = 'Qty', key = 'count', width = 5 }, { heading = 'Stock', key = 'count', width = 6, justify = 'right' },
{ heading = 'Price', key = 'price', width = 5 }, { heading = ' Price', key = 'price', width = 9, justify = 'right' },
{ heading = 'Name', key = 'displayName' }, { heading = 'Name', key = 'displayName' },
{ heading = 'Address', key = 'address', width = 20 }, { heading = 'Address', key = 'address', width = 16 },
}, },
sortColumn = 'displayName', sortColumn = 'displayName',
}, },
buttons = UI.Window { footer = UI.Window {
y = -5, height = 5, y = -6,
backgroundColor = colors.gray, backgroundColor = colors.gray,
prevButton = UI.Button { prevButton = UI.Button {
x = 2, y = 2, height = 3, width = 5, x = 2, y = 3, height = 3, width = 5,
event = 'previous', event = 'previous',
backgroundColor = colors.lightGray, backgroundColor = colors.lightGray,
text = ' < ' text = ' \017 ',
}, },
nextButton = UI.Button { nextButton = UI.Button {
x = -6, y = 2, height = 3, width = 5, x = -6, y = 3, height = 3, width = 5,
event = 'next', event = 'next',
backgroundColor = colors.lightGray, backgroundColor = colors.lightGray,
text = ' > ' text = ' \016 ',
}, },
info = UI.Window {
x = 9, ex = -9,
textColor = colors.white,
}
}, },
timestamp = os.clock(), timestamp = os.clock(),
} }
function page.header:draw()
self:clear()
if node.header then
self:centeredWrite(2, node.header, nil, colors.white)
end
end
function page.footer.info:draw()
self:clear()
local selected = page.grid:getSelected()
if selected then
if selected.info then
self:centeredWrite(2, selected.info)
end
self:centeredWrite(4, 'To purchase:')
self:centeredWrite(5, string.format('/pay %s@%s.kst <amount>', selected.name, node.domain))
end
end
function page.grid:getRowTextColor(row, selected) function page.grid:getRowTextColor(row, selected)
if row.count == 0 then if row.count == 0 then
return colors.gray return colors.lightGray
end end
return UI.Grid:getRowTextColor(row, selected) return UI.Grid:getRowTextColor(row, selected)
end end
function page.grid:getDisplayValues(row) function page.grid:getDisplayValues(row)
row = Util.shallowCopy(row) row = Util.shallowCopy(row)
row.count = Util.toBytes(row.count) row.count = Util.toBytes(row.count) .. ' x'
row.address = row.name .. '@' .. node.domain row.price = row.price .. ' kst '
row.address = row.name
return row return row
end end
function page:eventHandler(event) function page:eventHandler(event)
if event.type == 'next' then if event.type == 'next' then
self.grid:nextPage() self.grid:emit({ type = 'scroll_down' })
elseif event.type == 'previous' then elseif event.type == 'previous' then
self.grid:previousPage() self.grid:emit({ type = 'scroll_up' })
elseif event.type == 'grid_focus_row' then
self.footer:draw()
else else
return UI.Page.eventHandler(self, event) return UI.Page.eventHandler(self, event)
@@ -90,19 +127,13 @@ local function createPage(node)
self.grid.values = { } self.grid.values = { }
for k,v in pairs(config) do for k,v in pairs(config) do
local item = list[k] local item = list[k]
if item then if item and item.count > 0 then
table.insert(self.grid.values, { table.insert(self.grid.values, {
displayName = item.displayName, displayName = item.displayName,
count = item.count, count = item.count,
name = v.name, name = v.name,
price = v.price, price = v.price,
}) info = v.info,
else
table.insert(self.grid.values, {
displayName = itemDB:getName(k),
count = 0,
name = v.name,
price = v.price,
}) })
end end
end end
@@ -128,7 +159,7 @@ end)
Event.on('store_provide', function(_, item, quantity, uid) Event.on('store_provide', function(_, item, quantity, uid)
Milo:queueRequest({ }, function() Milo:queueRequest({ }, function()
local count = Milo:eject(item, quantity) local count = Milo:eject(itemDB:splitKey(item), quantity)
os.queueEvent('store_provided', uid, count) os.queueEvent('store_provided', uid, count)
end) end)
end) end)
@@ -140,7 +171,7 @@ local StoreTask = {
} }
function StoreTask:cycle(context) function StoreTask:cycle(context)
for node in context.storage:filterActive('store') do for node in context.storage:filterActive('shop') do
if not pages[node.name] then if not pages[node.name] then
pages[node.name] = createPage(node) pages[node.name] = createPage(node)
os.queueEvent('open_store', node.domain, node.password) os.queueEvent('open_store', node.domain, node.password)

View File

@@ -0,0 +1 @@
shell.openTab('swshop')

View File

@@ -1,17 +1,20 @@
local programDir = fs.getDir(shell.getRunningProgram()) local programDir = fs.getDir(shell.getRunningProgram())
os.loadAPI(programDir .. '/'.. 'json') os.loadAPI(programDir .. '/'.. 'json')
local w = require("w") local w = require("w")
local r = require("r") local r = require("r")
local k = require("k") local k = require("k")
local jua = require("jua") local jua = require("jua")
local await = jua.await
local fs = _G.fs local await = jua.await
local json = _G.json local fs = _G.fs
local os = _G.os local json = _G.json
local os = _G.os
local rs = _G.rs
local textutils = _G.textutils local textutils = _G.textutils
rs.setOutput('top', false)
r.init(jua) r.init(jua)
w.init(jua) w.init(jua)
k.init(jua, json, w, r) k.init(jua, json, w, r)
@@ -22,6 +25,7 @@ local privatekey
local address local address
jua.on("terminate", function() jua.on("terminate", function()
rs.setOutput('top', false)
jua.stop() jua.stop()
_G.printError("Terminated") _G.printError("Terminated")
end) end)
@@ -32,9 +36,9 @@ local function getItemDetails(item)
local t = f.readAll() local t = f.readAll()
f.close() f.close()
t = textutils.unserialize(t) t = textutils.unserialize(t)
for k, v in pairs(t) do for key, v in pairs(t) do
if v.name == item then if v.name == item then
return k, v.price return key, v.price
end end
end end
end end
@@ -73,6 +77,7 @@ local function handleTransaction(transaction)
local count = math.floor(value / price) local count = math.floor(value / price)
local uid = math.random() local uid = math.random()
print('requesting %d of %s', count, itemId)
os.queueEvent('store_provide', itemId, count, uid) os.queueEvent('store_provide', itemId, count, uid)
local timerId = os.startTimer(5) local timerId = os.startTimer(5)
while true do while true do
@@ -97,7 +102,8 @@ jua.on('open_store', function(_, _domain, _password)
domain = _domain domain = _domain
password = _password password = _password
print('opening store for: ' .. domain) rs.setOutput('top', true)
print('opening store for: ' .. domain)
privatekey = k.toKristWalletFormat(password) privatekey = k.toKristWalletFormat(password)
address = k.makev2address(privatekey) address = k.makev2address(privatekey)