Mercurial > wow > inventory
comparison Modules/Mover.lua @ 98:252292b703ce
All print(...) function calls are now handled by addon:Print(text, color).
The cursor will be cleared of any items/spells before moving as well as when aborting.
author | Zerotorescue |
---|---|
date | Sun, 09 Jan 2011 17:49:33 +0100 |
parents | 31493364b163 |
children | 6ae44d372360 |
comparison
equal
deleted
inserted
replaced
97:ae268e5c7825 | 98:252292b703ce |
---|---|
47 addon:Debug("%d moves were queued.", #queuedMoves); | 47 addon:Debug("%d moves were queued.", #queuedMoves); |
48 | 48 |
49 for _, singleMove in pairs(queuedMoves) do | 49 for _, singleMove in pairs(queuedMoves) do |
50 local sourceItem = sourceContents[singleMove.id]; | 50 local sourceItem = sourceContents[singleMove.id]; |
51 if not sourceItem then | 51 if not sourceItem then |
52 print("Can't move " .. IdToItemLink(singleMove.id) .. ", non-existant in source"); | 52 addon:Print("Can't move " .. IdToItemLink(singleMove.id) .. ", this doesn't exist in the source.", addon.Colors.Red); |
53 else | 53 else |
54 -- We want to move the smallest stacks first to keep stuff pretty (and minimize space usage, splitting a stack takes 2 slots, moving something only 1) | 54 -- We want to move the smallest stacks first to keep stuff pretty (and minimize space usage, splitting a stack takes 2 slots, moving something only 1) |
55 table.sort(sourceItem.locations, function(a, b) | 55 table.sort(sourceItem.locations, function(a, b) |
56 return a.count < b.count; | 56 return a.count < b.count; |
57 end); | 57 end); |
130 -- populate targetContents with it so future moves of this item can be put on top of it if this isn't a full stack | 130 -- populate targetContents with it so future moves of this item can be put on top of it if this isn't a full stack |
131 | 131 |
132 local firstAvailableSlot = emptySlots[1]; | 132 local firstAvailableSlot = emptySlots[1]; |
133 | 133 |
134 if not firstAvailableSlot then | 134 if not firstAvailableSlot then |
135 print("Bags are full. Skipping " .. IdToItemLink(outgoingMove.itemId) .. "."); | 135 addon:Print(("Bags are full. Skipping %s."):format(IdToItemLink(outgoingMove.itemId)), addon.Colors.Orange); |
136 | 136 |
137 outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table | 137 outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table |
138 else | 138 else |
139 table.insert(combinedMoves, { | 139 table.insert(combinedMoves, { |
140 itemId = outgoingMove.itemId, | 140 itemId = outgoingMove.itemId, |
258 | 258 |
259 function mod:ProcessMove() | 259 function mod:ProcessMove() |
260 addon:Debug("ProcessMove"); | 260 addon:Debug("ProcessMove"); |
261 | 261 |
262 if #combinedMoves == 0 then | 262 if #combinedMoves == 0 then |
263 print("Nothing to move."); | 263 addon:Print("Nothing to move."); |
264 | 264 |
265 self:Abort(); | 265 self:Abort(); |
266 | 266 |
267 return; | 267 return; |
268 end | 268 end |
269 | 269 |
270 --self:RegisterEvent("BAG_UPDATE"); | 270 -- Make sure nothing is at the mouse |
271 ClearCursor(); | |
272 | |
271 self:RegisterEvent("ITEM_LOCK_CHANGED"); | 273 self:RegisterEvent("ITEM_LOCK_CHANGED"); |
272 self:RegisterEvent("UI_ERROR_MESSAGE"); | 274 self:RegisterEvent("UI_ERROR_MESSAGE"); |
273 | 275 |
274 -- combinedMoves now has all moves in it (source -> target) | 276 -- combinedMoves now has all moves in it (source -> target) |
275 -- go through list, move everything inside it | 277 -- go through list, move everything inside it |
296 local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or select(3, _GetContainerItemInfo(move.sourceContainer, move.sourceSlot))); | 298 local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or select(3, _GetContainerItemInfo(move.sourceContainer, move.sourceSlot))); |
297 local isTargetLocked = ((targetLocationsLocked[move.targetContainer] and targetLocationsLocked[move.targetContainer][move.targetSlot]) or select(3, GetContainerItemInfo(move.targetContainer, move.targetSlot))); | 299 local isTargetLocked = ((targetLocationsLocked[move.targetContainer] and targetLocationsLocked[move.targetContainer][move.targetSlot]) or select(3, GetContainerItemInfo(move.targetContainer, move.targetSlot))); |
298 | 300 |
299 if move and not isSourceLocked and not isTargetLocked then | 301 if move and not isSourceLocked and not isTargetLocked then |
300 | 302 |
301 print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId))); | 303 addon:Print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId))); |
302 | 304 |
303 addon:Debug("Moving %dx%s from (%d,%d) to (%d,%d)", move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot); | 305 addon:Debug("Moving %dx%s from (%d,%d) to (%d,%d)", move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot); |
304 | 306 |
305 if _GetContainerItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then | 307 if _GetContainerItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then |
306 self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId)); | 308 self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId)); |
350 end | 352 end |
351 | 353 |
352 addon:Debug("%d moves processed. %d moves remaining.", (combinedMovesOriginalLength - #combinedMoves), #combinedMoves); | 354 addon:Debug("%d moves processed. %d moves remaining.", (combinedMovesOriginalLength - #combinedMoves), #combinedMoves); |
353 | 355 |
354 if #combinedMoves == 0 then | 356 if #combinedMoves == 0 then |
355 print("Finished."); | 357 addon:Print("Finished.", addon.Colors.Green); |
356 | 358 |
357 self:Abort(); | 359 self:Abort(); |
358 | 360 |
359 return; | 361 return; |
360 end | 362 end |
381 function mod:Abort(simple, debugMsg) | 383 function mod:Abort(simple, debugMsg) |
382 if debugMsg then | 384 if debugMsg then |
383 addon:Debug("Aborting:%s", debugMsg); | 385 addon:Debug("Aborting:%s", debugMsg); |
384 end | 386 end |
385 if simple then | 387 if simple then |
386 print("|cffff0000Aborting: " .. simple .. ".|r"); | 388 addon:Print(("Aborting: %s."):format(simple), addon.Colors.Red); |
387 end | 389 end |
388 table.wipe(combinedMoves); | 390 table.wipe(combinedMoves); |
389 movesSource = nil; | 391 movesSource = nil; |
392 | |
393 -- Make sure nothing is at the mouse | |
394 ClearCursor(); | |
390 | 395 |
391 -- Stop timer | 396 -- Stop timer |
392 self:UnregisterEvent("ITEM_LOCK_CHANGED"); | 397 self:UnregisterEvent("ITEM_LOCK_CHANGED"); |
393 self:CancelTimer(tmrProcessNext, true); -- silent | 398 self:CancelTimer(tmrProcessNext, true); -- silent |
394 | 399 |