milo shop updates

This commit is contained in:
kepler155c@gmail.com
2019-01-12 10:06:48 -05:00
parent 9921ede8fa
commit 91d434f93d
7 changed files with 69 additions and 29 deletions

View File

@@ -53,14 +53,14 @@ function storeTab:eventHandler(event)
self.form:setValues({ })
config[self.item.key] = nil
Config.update('shop', config)
os.queueEvent('store_refresh')
os.queueEvent('shop_refresh')
self.form:draw()
elseif event.type == 'update' then
if self.form:save() then
config[self.item.key] = self.form.values
Config.update('shop', config)
os.queueEvent('store_refresh')
os.queueEvent('shop_refresh')
self:emit({ type = 'success_message', message = 'Updated' })
end

View File

@@ -2,6 +2,7 @@ local UI = require('ui')
local colors = _G.colors
local device = _G.device
local os = _G.os
--[[ Configuration Page ]]--
local wizardPage = UI.Window {
@@ -9,7 +10,7 @@ local wizardPage = UI.Window {
index = 2,
backgroundColor = colors.cyan,
form = UI.Form {
x = 2, ex = -2, y = 2, ey = -4,
x = 2, ex = -2, y = 2, ey = -2,
manualControls = true,
[1] = UI.TextEntry {
formLabel = 'Domain', formKey = 'domain',
@@ -32,6 +33,11 @@ local wizardPage = UI.Window {
shadowText = "xxxx's shop",
required = false,
},
warning = UI.Text {
x = 2, y = -1,
textColor = colors.yellow,
value = 'swshop Package must be installed',
},
[4] = UI.Chooser {
width = 9,
formLabel = 'Font Size', formKey = 'textScale',
@@ -54,7 +60,7 @@ function wizardPage:validate()
end
function wizardPage:saveNode(node)
-- queue event ??
os.queueEvent('shop_restart', node)
end
function wizardPage:isValidType(node)

View File

@@ -7,9 +7,32 @@ local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local multishell = _ENV.multishell
local os = _G.os
local shell = _ENV.shell
local config = Config.load('shop')
local shopTab
local function startShop(node)
if shopTab then
multishell.terminate(shopTab)
end
shopTab = shell.openTab('/packages/swshop/swshop.lua', node.domain, node.password)
end
-- node has been reconfigured
Event.on('shop_restart', function(_, node)
startShop(node)
end)
-- milo is being terminated
Event.on('terminate', function()
if shopTab then
multishell.terminate(shopTab)
shopTab = nil
end
end)
--[[ Display ]]--
local function createPage(node)
@@ -163,14 +186,15 @@ end
local pages = { }
-- called when an item to sell has been changed
Event.on('store_refresh', function()
Event.on('shop_refresh', function()
config = Config.load('shop')
end)
Event.on('store_provide', function(_, item, quantity, uid)
-- called from the shop when an item has been purchased
Event.on('shop_provide', function(_, item, quantity, uid)
Milo:queueRequest({ }, function()
local count = Milo:eject(itemDB:splitKey(item), quantity)
os.queueEvent('store_provided', uid, count)
os.queueEvent('shop_provided', uid, count)
Sound.play('entity.villager.yes')
end)
end)
@@ -184,8 +208,8 @@ local StoreTask = {
function StoreTask:cycle(context)
for node in context.storage:filterActive('shop') do
if not pages[node.name] then
startShop(node)
pages[node.name] = createPage(node)
os.queueEvent('open_store', node.domain, node.password)
end
-- update the display
pages[node.name]:update()