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

View File

@@ -13,9 +13,9 @@ local wizardPage = UI.Window {
manualControls = true,
[1] = UI.TextEntry {
formLabel = 'Domain', formKey = 'domain',
help = 'Krist wallet address',
help = 'Krist wallet domain (minus .kst)',
limit = 64,
shadowText = 'example.kst',
shadowText = 'example',
required = true,
},
[2] = UI.TextEntry {
@@ -25,7 +25,14 @@ local wizardPage = UI.Window {
required = true,
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,
formLabel = 'Font Size', formKey = 'textScale',
nochoice = 'Small',
@@ -54,14 +61,14 @@ function wizardPage:isValidType(node)
local m = device[node.name]
return m and m.type == 'monitor' and {
name = 'Store Front',
value = 'store',
value = 'shop',
category = 'display',
help = 'Add a store front display'
}
end
function wizardPage:isValidFor(node)
return node.mtype == 'store'
return node.mtype == 'shop'
end
UI:getPage('nodeWizard').wizard:add({ storeFront = wizardPage })

View File

@@ -24,55 +24,92 @@ local function createPage(node)
local page = UI.Page {
parent = monitor,
header = UI.Window {
backgroundColor = colors.blue,
ey = 3,
},
grid = UI.Grid {
ey = -6,
y = 4, ey = -7,
headerHeight = 3,
headerBackgroundColor = colors.gray,
backgroundSelectedColor = colors.black,
unfocusedBackgroundSelectedColor = colors.gray,
columns = {
{ heading = 'Qty', key = 'count', width = 5 },
{ heading = 'Price', key = 'price', width = 5 },
{ heading = 'Stock', key = 'count', width = 6, justify = 'right' },
{ heading = ' Price', key = 'price', width = 9, justify = 'right' },
{ heading = 'Name', key = 'displayName' },
{ heading = 'Address', key = 'address', width = 20 },
{ heading = 'Address', key = 'address', width = 16 },
},
sortColumn = 'displayName',
},
buttons = UI.Window {
y = -5, height = 5,
footer = UI.Window {
y = -6,
backgroundColor = colors.gray,
prevButton = UI.Button {
x = 2, y = 2, height = 3, width = 5,
x = 2, y = 3, height = 3, width = 5,
event = 'previous',
backgroundColor = colors.lightGray,
text = ' < '
text = ' \017 ',
},
nextButton = UI.Button {
x = -6, y = 2, height = 3, width = 5,
x = -6, y = 3, height = 3, width = 5,
event = 'next',
backgroundColor = colors.lightGray,
text = ' > '
text = ' \016 ',
},
info = UI.Window {
x = 9, ex = -9,
textColor = colors.white,
}
},
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)
if row.count == 0 then
return colors.gray
return colors.lightGray
end
return UI.Grid:getRowTextColor(row, selected)
end
function page.grid:getDisplayValues(row)
row = Util.shallowCopy(row)
row.count = Util.toBytes(row.count)
row.address = row.name .. '@' .. node.domain
row.count = Util.toBytes(row.count) .. ' x'
row.price = row.price .. ' kst '
row.address = row.name
return row
end
function page:eventHandler(event)
if event.type == 'next' then
self.grid:nextPage()
self.grid:emit({ type = 'scroll_down' })
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
return UI.Page.eventHandler(self, event)
@@ -90,19 +127,13 @@ local function createPage(node)
self.grid.values = { }
for k,v in pairs(config) do
local item = list[k]
if item then
if item and item.count > 0 then
table.insert(self.grid.values, {
displayName = item.displayName,
count = item.count,
name = v.name,
price = v.price,
})
else
table.insert(self.grid.values, {
displayName = itemDB:getName(k),
count = 0,
name = v.name,
price = v.price,
info = v.info,
})
end
end
@@ -128,7 +159,7 @@ end)
Event.on('store_provide', function(_, item, quantity, uid)
Milo:queueRequest({ }, function()
local count = Milo:eject(item, quantity)
local count = Milo:eject(itemDB:splitKey(item), quantity)
os.queueEvent('store_provided', uid, count)
end)
end)
@@ -140,7 +171,7 @@ local StoreTask = {
}
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
pages[node.name] = createPage(node)
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())
os.loadAPI(programDir .. '/'.. 'json')
local w = require("w")
local r = require("r")
local k = require("k")
local w = require("w")
local r = require("r")
local k = require("k")
local jua = require("jua")
local await = jua.await
local fs = _G.fs
local json = _G.json
local os = _G.os
local await = jua.await
local fs = _G.fs
local json = _G.json
local os = _G.os
local rs = _G.rs
local textutils = _G.textutils
rs.setOutput('top', false)
r.init(jua)
w.init(jua)
k.init(jua, json, w, r)
@@ -22,6 +25,7 @@ local privatekey
local address
jua.on("terminate", function()
rs.setOutput('top', false)
jua.stop()
_G.printError("Terminated")
end)
@@ -32,9 +36,9 @@ local function getItemDetails(item)
local t = f.readAll()
f.close()
t = textutils.unserialize(t)
for k, v in pairs(t) do
for key, v in pairs(t) do
if v.name == item then
return k, v.price
return key, v.price
end
end
end
@@ -73,6 +77,7 @@ local function handleTransaction(transaction)
local count = math.floor(value / price)
local uid = math.random()
print('requesting %d of %s', count, itemId)
os.queueEvent('store_provide', itemId, count, uid)
local timerId = os.startTimer(5)
while true do
@@ -97,7 +102,8 @@ jua.on('open_store', function(_, _domain, _password)
domain = _domain
password = _password
print('opening store for: ' .. domain)
rs.setOutput('top', true)
print('opening store for: ' .. domain)
privatekey = k.toKristWalletFormat(password)
address = k.makev2address(privatekey)