milo better notifications
This commit is contained in:
@@ -95,6 +95,9 @@ local page = UI.Page {
|
|||||||
help = displayModes[context.state.displayMode].help,
|
help = displayModes[context.state.displayMode].help,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
notification = UI.Notification {
|
||||||
|
anchor = 'top',
|
||||||
|
},
|
||||||
accelerators = {
|
accelerators = {
|
||||||
r = 'refresh',
|
r = 'refresh',
|
||||||
[ 'control-r' ] = 'refresh',
|
[ 'control-r' ] = 'refresh',
|
||||||
@@ -176,6 +179,7 @@ function page:eventHandler(event)
|
|||||||
Util.merge(self.statusBar.depositToggle, depositMode[context.state.deposit])
|
Util.merge(self.statusBar.depositToggle, depositMode[context.state.deposit])
|
||||||
self.statusBar:draw()
|
self.statusBar:draw()
|
||||||
context:setStatus(depositMode[context.state.deposit].help)
|
context:setStatus(depositMode[context.state.deposit].help)
|
||||||
|
context:notifyInfo(depositMode[context.state.deposit].help)
|
||||||
Config.update('miloRemote', context.state)
|
Config.update('miloRemote', context.state)
|
||||||
|
|
||||||
elseif event.type == 'focus_change' then
|
elseif event.type == 'focus_change' then
|
||||||
@@ -208,7 +212,7 @@ function page:eventHandler(event)
|
|||||||
self:transfer(item, count, 'requesting ' .. count .. ' ...')
|
self:transfer(item, count, 'requesting ' .. count .. ' ...')
|
||||||
else
|
else
|
||||||
Sound.play('entity.villager.no')
|
Sound.play('entity.villager.no')
|
||||||
context:setStatus('nope ...')
|
context:notify('nope ...')
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'plugin' then
|
elseif event.type == 'plugin' then
|
||||||
@@ -236,6 +240,7 @@ function page:eventHandler(event)
|
|||||||
event.button:draw()
|
event.button:draw()
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
context:setStatus(event.button.help)
|
context:setStatus(event.button.help)
|
||||||
|
context:notifyInfo(event.button.help)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
Config.update('miloRemote', context.state)
|
Config.update('miloRemote', context.state)
|
||||||
|
|
||||||
@@ -340,10 +345,23 @@ context.page = page
|
|||||||
|
|
||||||
function context:setStatus(status)
|
function context:setStatus(status)
|
||||||
page.menuBar.infoBar.values = status
|
page.menuBar.infoBar.values = status
|
||||||
--if page.menuBar.infoBar.enabled then
|
page.menuBar.infoBar:draw()
|
||||||
page.menuBar.infoBar:draw()
|
page:sync()
|
||||||
page:sync()
|
end
|
||||||
--end
|
|
||||||
|
function context:notifySuccess(status)
|
||||||
|
page.notification:success(status)
|
||||||
|
page:sync()
|
||||||
|
end
|
||||||
|
|
||||||
|
function context:notifyInfo(status)
|
||||||
|
page.notification:info(status)
|
||||||
|
page:sync()
|
||||||
|
end
|
||||||
|
|
||||||
|
function context:notifyError(status)
|
||||||
|
page.notification:error(status)
|
||||||
|
page:sync()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function processMessages(s)
|
local function processMessages(s)
|
||||||
@@ -359,26 +377,26 @@ local function processMessages(s)
|
|||||||
h(response)
|
h(response)
|
||||||
end
|
end
|
||||||
if response.msg then
|
if response.msg then
|
||||||
context:setStatus(response.msg)
|
context:notifyInfo(response.msg)
|
||||||
end
|
end
|
||||||
until not s.connected
|
until not s.connected
|
||||||
|
|
||||||
s:close()
|
s:close()
|
||||||
s = nil
|
s = nil
|
||||||
context:setStatus('disconnected ...')
|
context:notifyError('disconnected ...')
|
||||||
Sound.play('entity.villager.no')
|
Sound.play('entity.villager.no')
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function context:sendRequest(data, statusMsg)
|
function context:sendRequest(data, statusMsg)
|
||||||
if not context.state.server then
|
if not context.state.server then
|
||||||
self:setStatus('Invalid configuration')
|
self:notifyError('Invalid configuration')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = getPlayerName()
|
local player = getPlayerName()
|
||||||
if not player then
|
if not player then
|
||||||
self:setStatus('Missing neural or introspection')
|
self:notifyError('Missing neural or introspection')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -387,13 +405,13 @@ function context:sendRequest(data, statusMsg)
|
|||||||
local msg
|
local msg
|
||||||
for _ = 1, 2 do
|
for _ = 1, 2 do
|
||||||
if not context.socket or not context.socket.connected then
|
if not context.socket or not context.socket.connected then
|
||||||
self:setStatus('connecting ...')
|
self:notifyInfo('connecting ...')
|
||||||
context.socket, msg = Socket.connect(context.state.server, 4242)
|
context.socket, msg = Socket.connect(context.state.server, 4242)
|
||||||
if context.socket then
|
if context.socket then
|
||||||
context.socket:write(player)
|
context.socket:write(player)
|
||||||
local r = context.socket:read(2)
|
local r = context.socket:read(2)
|
||||||
if r and not r.msg then
|
if r and not r.msg then
|
||||||
self:setStatus('connected ...')
|
self:notifySuccess('connected ...')
|
||||||
processMessages(context.socket)
|
processMessages(context.socket)
|
||||||
else
|
else
|
||||||
msg = r and r.msg or 'Timed out'
|
msg = r and r.msg or 'Timed out'
|
||||||
@@ -404,10 +422,7 @@ function context:sendRequest(data, statusMsg)
|
|||||||
end
|
end
|
||||||
if context.socket then
|
if context.socket then
|
||||||
if statusMsg then
|
if statusMsg then
|
||||||
self:setStatus(statusMsg)
|
self:notifyInfo(statusMsg)
|
||||||
Event.onTimeout(2, function()
|
|
||||||
self:setStatus('')
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
if context.socket:write(data) then
|
if context.socket:write(data) then
|
||||||
success = true
|
success = true
|
||||||
@@ -417,7 +432,7 @@ function context:sendRequest(data, statusMsg)
|
|||||||
context.socket = nil
|
context.socket = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:setStatus(msg or 'Failed to connect')
|
self:notifyError(msg or 'Failed to connect')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return success
|
return success
|
||||||
@@ -467,12 +482,12 @@ context.responseHandlers['transfer'] = function(response)
|
|||||||
end
|
end
|
||||||
if response.craft then
|
if response.craft then
|
||||||
if response.craft > 0 then
|
if response.craft > 0 then
|
||||||
context:setStatus(response.craft .. ' crafting ...')
|
context:notifyInfo(response.craft .. ' crafting ...')
|
||||||
elseif response.craft + response.count < response.requested then
|
elseif response.craft + response.count < response.requested then
|
||||||
if response.craft + response.count == 0 then
|
if response.craft + response.count == 0 then
|
||||||
Sound.play('entity.villager.no')
|
Sound.play('entity.villager.no')
|
||||||
end
|
end
|
||||||
context:setStatus((response.craft + response.count) .. ' available ...')
|
context:notifyInfo((response.craft + response.count) .. ' available ...')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ local page = UI.Page {
|
|||||||
help = displayModes[displayMode].help,
|
help = displayModes[displayMode].help,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
notification = UI.Notification(),
|
notification = UI.Notification {
|
||||||
|
anchor = 'top',
|
||||||
|
},
|
||||||
throttle = UI.Throttle {
|
throttle = UI.Throttle {
|
||||||
textColor = colors.yellow,
|
textColor = colors.yellow,
|
||||||
borderColor = colors.gray,
|
borderColor = colors.gray,
|
||||||
@@ -180,6 +182,18 @@ function page:eject(amount)
|
|||||||
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
||||||
local request = Milo:craftAndEject(item, amount)
|
local request = Milo:craftAndEject(item, amount)
|
||||||
item.count = request.current - request.count
|
item.count = request.current - request.count
|
||||||
|
|
||||||
|
if request.craft then
|
||||||
|
if request.craft > 0 then
|
||||||
|
self:notifyInfo(request.craft .. ' crafting ...')
|
||||||
|
elseif request.craft + request.count < request.requested then
|
||||||
|
if request.craft + request.count == 0 then
|
||||||
|
Sound.play('entity.villager.no')
|
||||||
|
end
|
||||||
|
self:notifyInfo((request.craft + request.count) .. ' available ...')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if request.count + request.craft > 0 then
|
if request.count + request.craft > 0 then
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
return true
|
return true
|
||||||
@@ -271,6 +285,18 @@ function page:eventHandler(event)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function page:notifySuccess(status)
|
||||||
|
self.notification:success(status)
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:notifyInfo(status)
|
||||||
|
self.notification:info(status)
|
||||||
|
end
|
||||||
|
|
||||||
|
function page:notifyError(status)
|
||||||
|
self.notification:error(status)
|
||||||
|
end
|
||||||
|
|
||||||
function page:enable(args)
|
function page:enable(args)
|
||||||
local function updateStatus()
|
local function updateStatus()
|
||||||
self.statusBar.storageStatus.value =
|
self.statusBar.storageStatus.value =
|
||||||
|
|||||||
Reference in New Issue
Block a user