some finishing touches for the full new ui release

This commit is contained in:
Manuel Simon Hirsig
2015-11-01 18:29:47 +01:00
parent 34ebedaf1b
commit 6a8e224040
17 changed files with 841 additions and 671 deletions
+50 -66
View File
@@ -1,4 +1,5 @@
Aux.stack = {}
local private, public = {}, {}
Aux.stack = public
local controller = (function()
local controller
@@ -10,19 +11,18 @@ end)()
local state
local item_slots, find_empty_slot, locked, same_slot, move_item, item_name, stack_size, stop, process
function item_slots(name)
function private.item_slots(item_key)
local slots = Aux.util.inventory_iterator()
return function()
local slot
repeat
slot = slots()
until slot == nil or item_name(slot) == name
until slot == nil or private.item_key(slot) == item_key
return slot
end
end
function find_empty_slot()
function private.find_empty_slot()
for slot in Aux.util.inventory_iterator() do
if not GetContainerItemInfo(slot.bag, slot.bag_slot) then
return slot
@@ -30,106 +30,90 @@ function find_empty_slot()
end
end
function find_charges_item_slot(name, charges)
for slot in item_slots(name) do
if item_charges(slot) == charges then
function private.find_charges_item_slot(item_key, charges)
for slot in private.item_slots(item_key) do
if private.item_charges(slot) == charges then
return slot
end
end
end
function locked(slot)
local _, _, locked = GetContainerItemInfo(slog.bag, slot.bag_slot)
return locked
end
function same_slot(slot1, slot2)
return slot1.bag == slot2.bag and slot1.bag_slot == slot2.bag_slot
end
function move_item(from_slot, to_slot, amount, k)
local size_before = stack_size(to_slot)
function private.move_item(from_slot, to_slot, amount, k)
local size_before = private.stack_size(to_slot)
amount = min(max_stack(from_slot) - stack_size(to_slot), amount)
amount = min(private.max_stack(from_slot) - private.stack_size(to_slot), amount)
ClearCursor()
SplitContainerItem(from_slot.bag, from_slot.bag_slot, amount)
PickupContainerItem(to_slot.bag, to_slot.bag_slot)
return controller().wait(function() return stack_size(to_slot) == size_before + amount end, k)
return controller().wait(function() return private.stack_size(to_slot) == size_before + amount end, k)
end
function item_name(slot)
function private.item_key(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.name
return container_item_info and container_item_info.item_key
end
function item_id(slot)
local hyperlink = GetContainerItemLink(slot.bag, slot.bag_slot)
if hyperlink then
local _, _, id_string = strfind(hyperlink, "^.-:(%d*).*")
return tonumber(id_string)
end
function private.stack_size(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.count or 0
end
function stack_size(slot)
local _, item_count = GetContainerItemInfo(slot.bag, slot.bag_slot)
return item_count or 0
function private.item_charges(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.charges
end
function item_charges(slot)
return Aux.info.container_item(slot.bag, slot.bag_slot).charges
end
function private.process()
function process()
if stack_size(state.target_slot) > state.target_size then
local empty_slot = find_empty_slot()
if private.stack_size(state.target_slot) > state.target_size then
local empty_slot = private.find_empty_slot()
if empty_slot then
return move_item(
return private.move_item(
state.target_slot,
empty_slot,
stack_size(state.target_slot) - state.target_size,
private.stack_size(state.target_slot) - state.target_size,
function()
return process()
return private.process()
end)
else
local next_slot = state.other_slots()
if next_slot then
return move_item(
return private.move_item(
state.target_slot,
next_slot,
stack_size(state.target_slot) - state.target_size,
private.stack_size(state.target_slot) - state.target_size,
function()
return process()
return private.process()
end)
end
end
elseif stack_size(state.target_slot) < state.target_size then
elseif private.stack_size(state.target_slot) < state.target_size then
local next_slot = state.other_slots()
if next_slot then
return move_item(
return private.move_item(
next_slot,
state.target_slot,
state.target_size - stack_size(state.target_slot),
state.target_size - private.stack_size(state.target_slot),
function()
return process()
return private.process()
end)
end
end
return stop()
return private.stop()
end
function max_stack(slot)
local _, _, _, _, _, _, max_stack = GetItemInfo(item_id(slot))
return max_stack
function private.max_stack(slot)
local container_item_info = Aux.info.container_item(slot.bag, slot.bag_slot)
return container_item_info and container_item_info.max_stack
end
function Aux.stack.stop(k)
function public.stop(k)
Aux.control.on_next_update(function()
stop()
private.stop()
if k then
return k()
@@ -137,11 +121,11 @@ function Aux.stack.stop(k)
end)
end
function stop()
function private.stop()
controller().reset()
if state then
local slot
if state.target_slot and (stack_size(state.target_slot) == state.target_size or item_charges(state.target_slot) == state.target_size) then
if state.target_slot and (private.stack_size(state.target_slot) == state.target_size or private.item_charges(state.target_slot) == state.target_size) then
slot = state.target_slot
end
local callback = state.callback
@@ -154,11 +138,11 @@ function stop()
end
end
function Aux.stack.start(name, size, callback)
function public.start(item_key, size, callback)
Aux.control.on_next_update(function()
stop()
private.stop()
local slots = item_slots(name)
local slots = private.item_slots(item_key)
local target_slot = slots()
state = {
@@ -169,12 +153,12 @@ function Aux.stack.start(name, size, callback)
}
if not target_slot then
return stop()
elseif item_charges(target_slot) then
state.target_slot = find_charges_item_slot(name, size)
return stop()
return private.stop()
elseif private.item_charges(target_slot) then
state.target_slot = private.find_charges_item_slot(item_key, size)
return private.stop()
else
return process()
return private.process()
end
end)
end