Mercurial > wow > inventory
changeset 101:6ae44d372360
The confirmation window when refilling from the (guild) bank is enabled can now be skipped at the general config. It defaults to false.
Added a window displaying a list of movable items when at least one is available at the (guild) bank.
Resetting the queue when closing the storage.
author | Zerotorescue |
---|---|
date | Tue, 11 Jan 2011 19:48:35 +0100 |
parents | dbb239fcc91b |
children | bca5a75bf022 |
files | .pkgmeta Core.lua Frames.lua Inventorium.toc Libraries.xml Modules/Config.lua Modules/Mover.lua Modules/Scanner.lua |
diffstat | 8 files changed, 371 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/.pkgmeta Sun Jan 09 17:52:02 2011 +0100 +++ b/.pkgmeta Tue Jan 11 19:48:35 2011 +0100 @@ -8,24 +8,12 @@ Libs/AceDB-3.0: url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDB-3.0 tag: latest -# Libs/AceDBOptions-3.0: -# url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDBOptions-3.0 -# tag: latest Libs/AceEvent-3.0: url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceEvent-3.0 tag: latest Libs/AceGUI-3.0: url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0 tag: latest -# Libs/AceGUI-3.0-SharedMediaWidgets: -# url: svn://svn.wowace.com/wow/ace-gui-3-0-shared-media-widgets/mainline/trunk/AceGUI-3.0-SharedMediaWidgets -# tag: latest -# Libs/AceHook-3.0: -# url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceHook-3.0 -# tag: latest -# Libs/AceLocale-3.0: -# url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceLocale-3.0 -# tag: latest Libs/AceSerializer-3.0: url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceSerializer-3.0 tag: latest @@ -35,15 +23,15 @@ Libs/CallbackHandler-1.0: url: svn://svn.wowace.com/wow/callbackhandler/mainline/trunk/CallbackHandler-1.0 tag: latest -# Libs/LibSharedMedia-3.0: -# url: svn://svn.wowace.com/wow/libsharedmedia-3-0/mainline/trunk/LibSharedMedia-3.0 -# tag: latest Libs/LibStub: url: svn://svn.wowace.com/wow/libstub/mainline/trunk tag: latest Libs/ChatHyperlinks: url: http://hg.curseforge.net/wow/chathyperlinks/mainline tag: latest + Libs/lib-st: + url: svn://svn.wowace.com/wow/lib-st/mainline/trunk + tag: latest #enable-nolib-creation: no
--- a/Core.lua Sun Jan 09 17:52:02 2011 +0100 +++ b/Core.lua Tue Jan 11 19:48:35 2011 +0100 @@ -33,6 +33,7 @@ minLocalStock = 20, alertBelowLocalMinimum = true, autoRefill = true, + autoRefillSkipConfirm = false, minGlobalStock = 60, alertBelowGlobalMinimum = true, summaryThresholdShow = 10,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Frames.lua Tue Jan 11 19:48:35 2011 +0100 @@ -0,0 +1,242 @@ +local addon = select(2, ...); + +local function ShowTooltip(self) + -- If this function is called from a widget, self is the widget and self.frame the actual frame + local this = self.frame or self; + + GameTooltip:SetOwner(this, "ANCHOR_NONE"); + if this.tooltipLocation and this.tooltipLocation == "TOP" then + GameTooltip:SetPoint("TOP", this, "TOP"); + else + GameTooltip:SetPoint("BOTTOM", this, "TOP"); + end + GameTooltip:SetText(this.tooltipTitle, 1, .82, 0, 1); + + if type(this.tooltip) == "string" then + GameTooltip:AddLine(this.tooltip, 1, 1, 1, 1); + end + + GameTooltip:Show(); +end + +local function HideTooltip() + GameTooltip:Hide(); +end + +function addon:CreateMoverFrame(onAccept, onCancel) + local frameWidth = 400; + + -- Main window + local frame = CreateFrame("Frame", "InventoriumItemMover", UIParent); + -- Hide by default + frame:Hide(); + -- Center the frame (will be adjusted later) + frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0); + -- Put in front of other windows + frame:SetFrameStrata("FULLSCREEN_DIALOG"); + frame:SetToplevel(true); + -- Give it a size + frame:SetWidth(frameWidth); + frame:SetHeight(175); + -- Background + frame:SetBackdrop({ + bgFile = "Interface\\ChatFrame\\ChatFrameBackground", + edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", + edgeSize = 13, + insets = { + left = 5, + right = 5, + top = 5, + bottom = 5, + }, + }); + frame:SetBackdropColor(0, 0, 0, .8); + -- Mouse functions + frame:EnableMouse(); + frame:SetMovable(true); + frame:SetResizable(true); + frame:SetMinResize(300, 175); + -- Set event handlers + frame:SetScript("OnMouseUp", function(this) this:StopMovingOrSizing(); end); + frame:SetScript("OnShow", function(this) + -- We wish to display our box at a similar position as the default interface's static popups, so we literally copied the code for these popups + local lastFrame = StaticPopup_DisplayedFrames[#StaticPopup_DisplayedFrames]; + if lastFrame then + this:SetPoint("TOP", lastFrame, "BOTTOM", 0, 0); + else + this:SetPoint("TOP", UIParent, "TOP", 0, -135); + end + + -- Position other static popups below this + tinsert(StaticPopup_DisplayedFrames, this); + + this:AdjustScrollTableRows(); + + PlaySound("OrcExploration"); + end); + + -- Title (AceGUI frame-widget-title used as example) + local titleBackground = frame:CreateTexture(nil, "OVERLAY"); + titleBackground:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); + titleBackground:SetTexCoord(0.31, 0.67, 0, 0.63); + titleBackground:SetPoint("TOP", 0, 12); + titleBackground:SetWidth(150); + titleBackground:SetHeight(40); + + local titleBackgroundLeft = frame:CreateTexture(nil, "OVERLAY"); + titleBackgroundLeft:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); + titleBackgroundLeft:SetTexCoord(0.21, 0.31, 0, 0.63); + titleBackgroundLeft:SetPoint("RIGHT", titleBackground, "LEFT"); + titleBackgroundLeft:SetWidth(30); + titleBackgroundLeft:SetHeight(40); + + local titleBackgroundRight = frame:CreateTexture(nil, "OVERLAY"); + titleBackgroundRight:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header"); + titleBackgroundRight:SetTexCoord(0.67, 0.77, 0, 0.63); + titleBackgroundRight:SetPoint("LEFT", titleBackground, "RIGHT"); + titleBackgroundRight:SetWidth(30); + titleBackgroundRight:SetHeight(40); + + local frmTitle = CreateFrame("Frame", nil, frame); + frmTitle:EnableMouse(true); + frmTitle:SetScript("OnMouseDown", function(this) this:GetParent():StartMoving(); end); + frmTitle:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); + frmTitle:SetAllPoints(titleBackground); + + local lblTitle = frmTitle:CreateFontString(nil, "OVERLAY", "GameFontNormal"); + lblTitle:SetPoint("TOP", titleBackground, "TOP", 0, -14); + lblTitle:SetText("Inventorium Bank Refill"); + + -- Resizer (vertical only) + local frmResizer = CreateFrame("Frame", nil, frame); + frmResizer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, -10); + frmResizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, -10); + frmResizer:SetHeight(20); + frmResizer:EnableMouse(); + frmResizer:SetScript("OnMouseDown", function(this) this:GetParent():StartSizing("BOTTOM"); end); + frmResizer:SetScript("OnMouseUp", function(this) this:GetParent():StopMovingOrSizing(); end); + + -- Description + local lblDescription = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal"); + lblDescription:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -23); + lblDescription:SetWidth(frameWidth - 10 - 10); -- 10 margin left & 10 margin right + lblDescription:SetJustifyH("LEFT"); + lblDescription:SetJustifyV("TOP"); + lblDescription:SetText("The items listed below can be refilled from this location, do you wish to move them to your bags?"); + + frame.lblDescription = lblDescription; + + -- Buttons + -- Move (proceed) + local btnMove = CreateFrame("Button", "$parentProceed", frame, "UIPanelButtonTemplate"); + btnMove:SetHeight(21); + btnMove:SetWidth(125); + btnMove:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 15, 10); + btnMove:SetText("Move Items"); + btnMove:SetScript("OnClick", onAccept); + btnMove:SetScript("OnEnter", ShowTooltip); + btnMove:SetScript("OnLeave", HideTooltip); + btnMove.tooltipTitle = "Move Items"; + btnMove.tooltip = "Start moving these items from the bank."; + + frame.btnMove = btnMove; + + -- Cancel + local btnCancel = CreateFrame("Button", "$parentCancel", frame, "UIPanelButtonTemplate"); + btnCancel:SetHeight(21); + btnCancel:SetWidth(125); + btnCancel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -15, 10); + btnCancel:SetText("Cancel"); + btnCancel:SetScript("OnClick", onCancel); + btnCancel:SetScript("OnEnter", ShowTooltip); + btnCancel:SetScript("OnLeave", HideTooltip); + btnCancel.tooltipTitle = "Cancel"; + btnCancel.tooltip = "Do not move anything and close the window."; + + frame.btnCancel = btnCancel; + + -- Because the scrolling table code-behind will change this element's height, we can't rely on that. Make a dummy frame which we can measure + local frmMeasureDummy = CreateFrame("Frame", nil, frame); + frmMeasureDummy:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20); + frmMeasureDummy:SetPoint("LEFT", frame.lblDescription, "LEFT", 10, 0); + frmMeasureDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 35); + + frame.frmMeasureDummy = frmMeasureDummy; + + -- Scrolling table with a list of items to be moved + local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 20 ); -- adjust width by the scrollbar size + local headers = { + { + ["name"] = "Item", + ["width"] = (scrollTableWidth * .5), + ["defaultsort"] = "asc", + ["comparesort"] = function(this, aRow, bRow, column) + local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).colorargs[2]); + local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).colorargs[2]); + local template = "%d%s"; + aName = template:format((10 - (aRarity or 10)), (aName or ""):lower()); + bName = template:format((10 - (bRarity or 10)), (bName or ""):lower()); + + if this.cols[column].sort == "dsc" then + return aName > bName; + else + return aName < bName; + end + end, + ["sort"] = "asc", -- when the data is set, use this column so sort the default data + }, + { + ["name"] = "Moving", + ["width"] = (scrollTableWidth * .15), + ["defaultsort"] = "dsc", + }, + { + ["name"] = "Missing", + ["width"] = (scrollTableWidth * .15), + ["defaultsort"] = "dsc", + }, + { + ["name"] = "Available", + ["width"] = (scrollTableWidth * .2), + ["defaultsort"] = "dsc", + }, + }; + + local ScrollingTable = LibStub("ScrollingTable"); + local table = ScrollingTable:CreateST(headers, 3, 15, nil, frame); + table:RegisterEvents({ + ["OnEnter"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) + if row and realrow and data[realrow] and data[realrow].colorargs and data[realrow].colorargs[2] then + GameTooltip:SetOwner(rowFrame, "ANCHOR_NONE"); + GameTooltip:SetPoint("TOPLEFT", rowFrame, "BOTTOMLEFT"); + GameTooltip:SetHyperlink(("item:%d"):format(data[realrow].colorargs[2])); + GameTooltip:Show(); + end + end, + ["OnLeave"] = function(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) + if row and realrow then + HideTooltip(); + end + end, + }); + + frame.scrollTable = table; + table.frame:SetPoint("TOP", frame.lblDescription, "BOTTOM", 0, -20); + table.frame:SetPoint("LEFT", frame.lblDescription, "LEFT", 10, 0); + table.frame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 35); + + -- Change the amount of displayed rows based on the size of the frame + frame.AdjustScrollTableRows = function(this) + local newRows = math.floor(( this.frmMeasureDummy:GetHeight() - 5 ) / 15); + newRows = (newRows < 3 and 3) or newRows; + + this.scrollTable:SetDisplayRows(newRows, 15); + end; + frame:SetScript("OnSizeChanged", frame.AdjustScrollTableRows); +end + +function addon:SetMoverFrameData(data) + InventoriumItemMover.scrollTable:SetData(data); + + InventoriumItemMover:Show(); +end
--- a/Inventorium.toc Sun Jan 09 17:52:02 2011 +0100 +++ b/Inventorium.toc Tue Jan 11 19:48:35 2011 +0100 @@ -13,6 +13,7 @@ # Main Core.lua +Frames.lua # Classes Classes\ItemData.class.lua
--- a/Libraries.xml Sun Jan 09 17:52:02 2011 +0100 +++ b/Libraries.xml Tue Jan 11 19:48:35 2011 +0100 @@ -13,4 +13,5 @@ <Include file="Libs\AceTimer-3.0\AceTimer-3.0.xml"/> <!-- end Ace 3 --> <Script file="Libs\ChatHyperlinks\ChatHyperlinks.lua"/> + <Include file="Libs\lib-st\lib-st.xml"/> </Ui>
--- a/Modules/Config.lua Sun Jan 09 17:52:02 2011 +0100 +++ b/Modules/Config.lua Tue Jan 11 19:48:35 2011 +0100 @@ -1486,6 +1486,14 @@ get = function() return addon.db.profile.defaults.autoRefill; end, set = function(i, v) addon.db.profile.defaults.autoRefill = v; end, }, + autoRefillSkipConfirm = { + order = 13, + type = "toggle", + name = "Skip confirmation", + desc = "Automatically start moving items from the (guild) bank without showing the confirmation window.\n\n|cfffed000This option can not be overridden.|r", + get = function() return addon.db.profile.defaults.autoRefillSkipConfirm; end, + set = function(i, v) addon.db.profile.defaults.autoRefillSkipConfirm = v; end, + }, minGlobalStock = { order = 20, type = "range", @@ -1510,12 +1518,12 @@ order = 30, type = "range", min = 0, - max = 10, + max = 100, softMax = 100, step = 0.05, isPercent = true, name = "Show in summary when below", - desc = "Show items in the summary when below this percentage of the minimum stock. This can be either below the minimum or the global stock.\n\nYou can manually enter a value between 1.000% and 10.000% in the edit box if the provided range is insufficient.", + desc = "Show items in the summary when below this percentage of the minimum stock. This can be either below the minimum or the global stock.", get = function() return addon.db.profile.defaults.summaryThresholdShow; end, set = function(i, v) addon.db.profile.defaults.summaryThresholdShow = v; end, }, @@ -1651,7 +1659,7 @@ step = 0.01, isPercent = true, name = "|cff00ff00Green|r", - desc = "Show quantity in green when at least this much of the minimum stock is available.", + desc = "Show quantity in green when at least this much of the minimum stock is available.\n\n|cfffed000This option can not be overridden.|r", get = function() return addon.db.profile.defaults.colors.green; end, set = function(i, v) addon.db.profile.defaults.colors.green = v; end, }, @@ -1663,7 +1671,7 @@ step = 0.01, isPercent = true, name = "|cffffff00Yellow|r", - desc = "Show quantity in yellow when at least this much of the minimum stock is available.", + desc = "Show quantity in yellow when at least this much of the minimum stock is available.\n\n|cfffed000This option can not be overridden.|r", get = function() return addon.db.profile.defaults.colors.yellow; end, set = function(i, v) addon.db.profile.defaults.colors.yellow = v; end, }, @@ -1675,7 +1683,7 @@ step = 0.01, isPercent = true, name = "|cffff9933Orange|r", - desc = "Show quantity in orange when at least this much of the minimum stock is available.", + desc = "Show quantity in orange when at least this much of the minimum stock is available.\n\n|cfffed000This option can not be overridden.|r", get = function() return addon.db.profile.defaults.colors.orange; end, set = function(i, v) addon.db.profile.defaults.colors.orange = v; end, }, @@ -1687,7 +1695,7 @@ step = 0.01, isPercent = true, name = "|cffff0000Red|r", - desc = "Show quantity in red when at least this much of the minimum stock is available.", + desc = "Show quantity in red when at least this much of the minimum stock is available.\n\n|cfffed000This option can not be overridden.|r", get = function() return addon.db.profile.defaults.colors.red; end, set = function(i, v) addon.db.profile.defaults.colors.red = v; end, },
--- a/Modules/Mover.lua Sun Jan 09 17:52:02 2011 +0100 +++ b/Modules/Mover.lua Tue Jan 11 19:48:35 2011 +0100 @@ -6,10 +6,12 @@ local combinedMoves = {}; -- table storing all combined moves (with source and target) that is to be processed by the actual mover in the order of the index (1 to #) local movesSource; -function mod:AddMove(itemId, amount) +function mod:AddMove(itemId, amount, numMissing, numAvailable) table.insert(queuedMoves, { id = itemId, num = amount, + missing = numMissing, + available = numAvailable, }); end @@ -17,6 +19,14 @@ return (#queuedMoves ~= 0); end +function mod:GetMoves() + return queuedMoves; +end + +function mod:ResetQueue() + table.wipe(queuedMoves); +end + if not table.reverse then table.reverse = function(orig) local temp = {}; @@ -49,7 +59,7 @@ for _, singleMove in pairs(queuedMoves) do local sourceItem = sourceContents[singleMove.id]; if not sourceItem then - addon:Print("Can't move " .. IdToItemLink(singleMove.id) .. ", this doesn't exist in the source.", addon.Colors.Red); + addon:Print(("Can't move %s, this doesn't exist in the source."):format(IdToItemLink(singleMove.id)), addon.Colors.Red); else -- 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) table.sort(sourceItem.locations, function(a, b)
--- a/Modules/Scanner.lua Sun Jan 09 17:52:02 2011 +0100 +++ b/Modules/Scanner.lua Tue Jan 11 19:48:35 2011 +0100 @@ -7,9 +7,23 @@ Guild = 2, }; -local Mover, paused; +local Mover, paused, currentLocation; local itemCache = {}; +local function OnMoveAccept(this) + mod:Pause(); + Mover:BeginMove(currentLocation, mod.Unpause); + + InventoriumItemMover:Hide(); +end + +local function OnMoveCancel(this) + Mover:ResetQueue(); + currentLocation = nil; + + InventoriumItemMover:Hide(); +end + function mod:ClearCache() table.wipe(itemCache); end @@ -115,6 +129,7 @@ local playerName = UnitName("player"); + currentLocation = location; self:CacheLocation(location, true); -- Go through all groups @@ -136,13 +151,15 @@ if itemCache[itemId] and missingItems > 0 then -- Check how many are available local availableItems = ((itemCache[itemId] and itemCache[itemId].totalCount) or 0); + -- Calculate how many we'll be moving (less missing than available? use missing, otherwise use available) + local moving = (((missingItems <= availableItems) and missingItems) or availableItems); if availableItems > 0 then - addon:Print("Insufficient " .. select(2, GetItemInfo(itemId)) .. " but this location has " .. availableItems .. " (moving " .. missingItems .. ")"); + --addon:Print("Insufficient " .. IdToItemLink(itemId) .. " but this location has " .. availableItems .. " (moving " .. moving .. ")"); - Mover:AddMove(itemId, missingItems); + Mover:AddMove(itemId, moving, missingItems, availableItems); else - addon:Print("Insufficient " .. IdToItemLink(itemId)); + --addon:Print("Insufficient " .. IdToItemLink(itemId)); end end end @@ -152,20 +169,70 @@ self:ClearCache(); if Mover:HasMoves() then - StaticPopupDialogs["InventoriumRefill"] = { - text = "There are items that can be refilled from this location, do you wish to proceed?", - button1 = YES, - button2 = NO, - OnAccept = function() - mod:Pause(); - Mover:BeginMove(location, self.Unpause); - end, - timeout = 0, - whileDead = 1, - hideOnEscape = 1, - exclusive = 1, - }; - StaticPopup_Show("InventoriumRefill"); + if addon.db.profile.defaults.autoRefillSkipConfirm then + OnMoveAccept(true); + else + local data = {}; + + local columns = { + { + value = function(d, cols, realrow, column, table) + return IdToItemLink(d[realrow].colorargs[2]); + end, + }, -- item + { + value = function(d, cols, realrow, column, table) + local queue = Mover:GetMoves(); + return queue[d[realrow].colorargs[1]].num; + end, + }, -- moving + { + value = function(d, cols, realrow, column, table) + local queue = Mover:GetMoves(); + return queue[d[realrow].colorargs[1]].missing; + end, + }, -- missing + { + value = function(d, cols, realrow, column, table) + local queue = Mover:GetMoves(); + return queue[d[realrow].colorargs[1]].available; + end, + color = function(d, cols, realrow, column, table) + local queue = Mover:GetMoves(); + return ((queue[d[realrow].colorargs[1]].available < queue[d[realrow].colorargs[1]].missing) and { r = 1, g = 0, b = 0, a = 1 }) or { r = 1, g = 1, b = 1, a = 1 }; + end, + }, -- available + }; + + local queue = Mover:GetMoves(); + + for i, move in pairs(Mover:GetMoves()) do + local row = { + ["colorargs"] = { i, queue[i].id }, + ["cols"] = columns, + }; + + table.insert(data, row); + end + + addon:SetMoverFrameData(data); + + --[[ + StaticPopupDialogs["InventoriumRefill"] = { + text = "There are items that can be refilled from this location, do you wish to proceed?", + button1 = YES, + button2 = NO, + OnAccept = function() + mod:Pause(); + Mover:BeginMove(location, self.Unpause); + end, + timeout = 0, + whileDead = 1, + hideOnEscape = 1, + exclusive = 1, + }; + StaticPopup_Show("InventoriumRefill");]] + end end end @@ -191,7 +258,9 @@ mod:UnregisterEvent("BANKFRAME_CLOSED"); - StaticPopup_Hide("InventoriumRefill"); + --StaticPopup_Hide("InventoriumRefill"); + InventoriumItemMover:Hide(); + Mover:ResetQueue(); end -- Guild bank @@ -226,7 +295,9 @@ self:CancelTimer(tmrScanGuild, true); -- silent - StaticPopup_Hide("InventoriumRefill"); + --StaticPopup_Hide("InventoriumRefill"); + InventoriumItemMover:Hide(); + Mover:ResetQueue(); end function mod:GUILDBANKFRAME_OPENED() @@ -252,10 +323,16 @@ self:RegisterEvent("GUILDBANKFRAME_OPENED"); Mover = addon:GetModule("Mover"); + + if not InventoriumItemMover then + addon:CreateMoverFrame(OnMoveAccept, OnMoveCancel); + end end function mod:OnDisable() Mover = nil; + currentLocation = nil; + paused = nil; -- Bank self:UnregisterEvent("BANKFRAME_OPENED");