milo: refactor eject
This commit is contained in:
@@ -175,8 +175,7 @@ function Milo:craftAndEject(item, count)
|
|||||||
return self:eject(item, request.requested)
|
return self:eject(item, request.requested)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- predict that we will eject that amount
|
return request
|
||||||
return request.current - request.count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:makeRequest(item, count, callback)
|
function Milo:makeRequest(item, count, callback)
|
||||||
|
|||||||
@@ -155,52 +155,51 @@ function listingPage.grid:getDisplayValues(row)
|
|||||||
return row
|
return row
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function listingPage:eject(amount)
|
||||||
|
local item = self.grid:getSelected()
|
||||||
|
if item and amount then
|
||||||
|
-- get most up-to-date item
|
||||||
|
if item then
|
||||||
|
if amount == 'stack' then
|
||||||
|
amount = item.maxCount or 64
|
||||||
|
elseif amount == 'all' then
|
||||||
|
item = Milo:getItem(Milo:listItems(), item)
|
||||||
|
amount = item.count
|
||||||
|
end
|
||||||
|
|
||||||
|
if amount > 0 then
|
||||||
|
item = Util.shallowCopy(item)
|
||||||
|
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
||||||
|
local request = Milo:craftAndEject(item, amount)
|
||||||
|
item.count = request.current - request.count
|
||||||
|
if request.count + request.craft > 0 then
|
||||||
|
self.grid:draw()
|
||||||
|
Sound.play('ui.button.click', .3)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Sound.play('entity.villager.no')
|
||||||
|
end
|
||||||
|
|
||||||
function listingPage:eventHandler(event)
|
function listingPage:eventHandler(event)
|
||||||
if event.type == 'quit' then
|
if event.type == 'quit' then
|
||||||
UI:exitPullEvents()
|
UI:exitPullEvents()
|
||||||
|
|
||||||
elseif event.type == 'eject' or event.type == 'grid_select' then
|
elseif event.type == 'eject' or event.type == 'grid_select' then
|
||||||
local item = self.grid:getSelected()
|
self:eject(1)
|
||||||
if item then
|
|
||||||
Sound.play('ui.button.click', .3)
|
|
||||||
item = Util.shallowCopy(item)
|
|
||||||
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
|
||||||
item.count = Milo:craftAndEject(item, 1)
|
|
||||||
self.grid:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'eject_stack' then
|
elseif event.type == 'eject_stack' then
|
||||||
local item = self.grid:getSelected()
|
self:eject('stack')
|
||||||
if item then
|
|
||||||
Sound.play('ui.button.click', .3)
|
|
||||||
item = Util.shallowCopy(item)
|
|
||||||
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
|
||||||
item.count = Milo:craftAndEject(item, itemDB:getMaxCount(item))
|
|
||||||
self.grid:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'eject_all' then
|
elseif event.type == 'eject_all' then
|
||||||
local item = self.grid:getSelected()
|
self:eject('all')
|
||||||
if item then
|
|
||||||
Sound.play('ui.button.click', .3)
|
|
||||||
local updated = Milo:getItem(Milo:listItems(), item)
|
|
||||||
if updated then
|
|
||||||
item = Util.shallowCopy(item)
|
|
||||||
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
|
||||||
item.count = Milo:craftAndEject(item, updated.count)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif event.type == 'eject_specified' then
|
elseif event.type == 'eject_specified' then
|
||||||
local item = self.grid:getSelected()
|
if self:eject(tonumber(self.statusBar.amount.value)) then
|
||||||
local count = tonumber(self.statusBar.amount.value)
|
|
||||||
if item and count then
|
|
||||||
Sound.play('ui.button.click', .3)
|
|
||||||
self.statusBar.amount:reset()
|
self.statusBar.amount:reset()
|
||||||
self:setFocus(self.statusBar.filter)
|
self:setFocus(self.statusBar.filter)
|
||||||
item = Util.shallowCopy(item)
|
|
||||||
self.grid.values[self.grid.sorted[self.grid.index]] = item
|
|
||||||
item.count = Milo:craftAndEject(item, count)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'network' then
|
elseif event.type == 'network' then
|
||||||
|
|||||||
Reference in New Issue
Block a user