Mercurial > wow > inventory
comparison Modules/Queue.lua @ 145:6a52272a0e5a
Added a craft button to the queue window. This is still very experimental.
| author | Zerotorescue |
|---|---|
| date | Thu, 20 Jan 2011 00:07:47 +0100 |
| parents | 12a8ea5af671 |
| children | ebe6f90c4bb9 |
comparison
equal
deleted
inserted
replaced
| 144:12a8ea5af671 | 145:6a52272a0e5a |
|---|---|
| 43 "Just finished restocking this item.", | 43 "Just finished restocking this item.", |
| 44 50, | 44 50, |
| 45 }, | 45 }, |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 local function Compare(a, b, this, aRow, bRow, columnNo) | |
| 49 if a == b then | |
| 50 local column = this.cols[columnNo]; | |
| 51 if column.sortnext then | |
| 52 local nextcol = this.cols[column.sortnext]; | |
| 53 if not(nextcol.sort) then | |
| 54 if nextcol.comparesort then | |
| 55 return nextcol.comparesort(this, aRow, bRow, column.sortnext); | |
| 56 else | |
| 57 return this:CompareSort(this, bRow, column.sortnext); | |
| 58 end | |
| 59 else | |
| 60 return false; | |
| 61 end | |
| 62 else | |
| 63 return false; | |
| 64 end | |
| 65 elseif (this.cols[columnNo].sort or this.cols[columnNo].defaultsort or "asc") == "dsc" then | |
| 66 return a > b; | |
| 67 else | |
| 68 return a < b; | |
| 69 end | |
| 70 end | |
| 71 | |
| 48 local function MakeQueueWindow() | 72 local function MakeQueueWindow() |
| 49 if not InventoriumQueuer then | 73 if not InventoriumQueuer then |
| 50 addon:CreateQueueFrame(); | 74 addon:CreateQueueFrame(); |
| 51 | 75 |
| 52 local frame = InventoriumQueuer; -- both for speed as code-consistency | 76 local frame = InventoriumQueuer; -- both for speed as code-consistency |
| 56 local headers = { | 80 local headers = { |
| 57 { | 81 { |
| 58 ["name"] = "Item", | 82 ["name"] = "Item", |
| 59 ["width"] = (scrollTableWidth * .65), | 83 ["width"] = (scrollTableWidth * .65), |
| 60 ["defaultsort"] = "asc", | 84 ["defaultsort"] = "asc", |
| 61 ["comparesort"] = function(this, aRow, bRow, column) | 85 ["comparesort"] = function(this, aRow, bRow, columnNo) |
| 62 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); | 86 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); |
| 63 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId); | 87 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId); |
| 64 local template = "%d%s"; | 88 aName = sformat("%d%s", (10 - (aRarity or 10)), slower(aName or "")); |
| 65 aName = sformat(template, (10 - (aRarity or 10)), slower(aName or "")); | 89 bName = sformat("%d%s", (10 - (bRarity or 10)), slower(bName or "")); |
| 66 bName = sformat(template, (10 - (bRarity or 10)), slower(bName or "")); | 90 |
| 67 | 91 return Compare(aName, bName, this, aRow, bRow, columnNo); |
| 68 if this.cols[column].sort == "dsc" then | |
| 69 return aName > bName; | |
| 70 else | |
| 71 return aName < bName; | |
| 72 end | |
| 73 end, | 92 end, |
| 74 ["sort"] = "asc", -- when the data is set, use this column so sort the default data | 93 ["sort"] = "asc", -- when the data is set, use this column so sort the default data |
| 75 ["tooltipTitle"] = "Item", | 94 ["tooltipTitle"] = "Item", |
| 76 ["tooltip"] = "Click to sort the list by item quality then item name.", | 95 ["tooltip"] = "Click to sort the list by item quality then item name.", |
| 77 }, | 96 }, |
| 78 { | 97 { |
| 79 ["name"] = "Amount", | 98 ["name"] = "Amount", |
| 80 ["width"] = (scrollTableWidth * .15), | 99 ["width"] = (scrollTableWidth * .15), |
| 81 ["align"] = "RIGHT", | 100 ["align"] = "RIGHT", |
| 82 ["defaultsort"] = "dsc", | 101 ["defaultsort"] = "dsc", |
| 83 ["comparesort"] = function(this, aRow, bRow, column) | 102 ["comparesort"] = function(this, aRow, bRow, columnNo) |
| 84 if this.cols[column].sort == "dsc" then | 103 local a = this:GetRow(aRow).rowData.amount; |
| 85 return (this:GetRow(aRow).rowData.amount > this:GetRow(bRow).rowData.amount); | 104 local b = this:GetRow(bRow).rowData.amount; |
| 86 else | 105 |
| 87 return (this:GetRow(aRow).rowData.amount < this:GetRow(bRow).rowData.amount); | 106 return Compare(a, b, this, aRow, bRow, columnNo); |
| 88 end | |
| 89 end, | 107 end, |
| 90 ["sortnext"] = 1, | 108 ["sortnext"] = 1, |
| 91 ["tooltipTitle"] = "Amount needed", | 109 ["tooltipTitle"] = "Amount needed", |
| 92 ["tooltip"] = "Click to sort the list by the amount of items needed to reach the restock target.", | 110 ["tooltip"] = "Click to sort the list by the amount of items needed to reach the restock target.", |
| 93 }, | 111 }, |
| 94 { | 112 { |
| 95 ["name"] = "Extra", | 113 ["name"] = "Extra", |
| 96 ["width"] = (scrollTableWidth * .15), | 114 ["width"] = (scrollTableWidth * .15), |
| 97 ["align"] = "RIGHT", | 115 ["align"] = "RIGHT", |
| 98 ["defaultsort"] = "dsc", | 116 ["defaultsort"] = "dsc", |
| 99 ["comparesort"] = function(this, aRow, bRow, column) | 117 ["comparesort"] = function(this, aRow, bRow, columnNo) |
| 100 if this.cols[column].sort == "dsc" then | 118 local a = this:GetRow(aRow).rowData.bonus; |
| 101 return (this:GetRow(aRow).rowData.bonus > this:GetRow(bRow).rowData.bonus); | 119 local b = this:GetRow(bRow).rowData.bonus; |
| 102 else | 120 |
| 103 return (this:GetRow(aRow).rowData.bonus < this:GetRow(bRow).rowData.bonus); | 121 return Compare(a, b, this, aRow, bRow, columnNo); |
| 104 end | |
| 105 end, | 122 end, |
| 106 ["sortnext"] = 1, | 123 ["sortnext"] = 1, |
| 107 ["tooltipTitle"] = "Extra items", | 124 ["tooltipTitle"] = "Extra items", |
| 108 ["tooltip"] = "Click to sort the list by the amount of bonus items.", | 125 ["tooltip"] = "Click to sort the list by the amount of bonus items.", |
| 109 }, | 126 }, |
| 135 local unqueueablesHeaders = { | 152 local unqueueablesHeaders = { |
| 136 { | 153 { |
| 137 ["name"] = "Item", | 154 ["name"] = "Item", |
| 138 ["width"] = (scrollTableWidth * .6), | 155 ["width"] = (scrollTableWidth * .6), |
| 139 ["defaultsort"] = "asc", | 156 ["defaultsort"] = "asc", |
| 140 ["comparesort"] = function(this, aRow, bRow, column) | 157 ["comparesort"] = function(this, aRow, bRow, columnNo) |
| 141 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); | 158 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId); |
| 142 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId); | 159 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId); |
| 143 local template = "%d%s"; | 160 aName = sformat("%d%s", (10 - (aRarity or 10)), slower(aName or "")); |
| 144 aName = sformat(template, (10 - (aRarity or 10)), slower(aName or "")); | 161 bName = sformat("%d%s", (10 - (bRarity or 10)), slower(bName or "")); |
| 145 bName = sformat(template, (10 - (bRarity or 10)), slower(bName or "")); | 162 |
| 146 | 163 return Compare(aName, bName, this, aRow, bRow, columnNo); |
| 147 if this.cols[column].sort == "dsc" then | |
| 148 return aName > bName; | |
| 149 else | |
| 150 return aName < bName; | |
| 151 end | |
| 152 end, | 164 end, |
| 153 ["tooltipTitle"] = "Item", | 165 ["tooltipTitle"] = "Item", |
| 154 ["tooltip"] = "Click to sort the list by item quality then item name.", | 166 ["tooltip"] = "Click to sort the list by item quality then item name.", |
| 155 }, | 167 }, |
| 156 { | 168 { |
| 157 ["name"] = "Reason", | 169 ["name"] = "Reason", |
| 158 ["width"] = (scrollTableWidth * .4), | 170 ["width"] = (scrollTableWidth * .4), |
| 159 ["defaultsort"] = "dsc", | 171 ["defaultsort"] = "dsc", |
| 160 ["comparesort"] = function(this, aRow, bRow, column) | 172 ["comparesort"] = function(this, aRow, bRow, columnNo) |
| 161 if this.cols[column].sort == "dsc" then | 173 local a = this:GetRow(aRow).rowData.reason[3]; |
| 162 return this:GetRow(aRow).rowData.reason[3] > this:GetRow(bRow).rowData.reason[3]; | 174 local b = this:GetRow(bRow).rowData.reason[3]; |
| 163 else | 175 |
| 164 return this:GetRow(aRow).rowData.reason[3] < this:GetRow(bRow).rowData.reason[3]; | 176 return Compare(a, b, this, aRow, bRow, columnNo); |
| 165 end | |
| 166 end, | 177 end, |
| 167 ["sort"] = "dsc", -- when the data is set, use this column to sort the default data | 178 ["sort"] = "dsc", -- when the data is set, use this column to sort the default data |
| 168 ["sortnext"] = 1, | 179 ["sortnext"] = 1, |
| 169 ["tooltipTitle"] = "Reason", | 180 ["tooltipTitle"] = "Reason", |
| 170 ["tooltip"] = "Click to sort the list by the reason the items couldn't be queued.", | 181 ["tooltip"] = "Click to sort the list by the reason the items couldn't be queued.", |
| 181 text = "Cancel", | 192 text = "Cancel", |
| 182 tooltipTitle = "Cancel", | 193 tooltipTitle = "Cancel", |
| 183 tooltip = "Do not queue anything and close the window.", | 194 tooltip = "Do not queue anything and close the window.", |
| 184 onClick = function() mod:QueueAbort(); end, | 195 onClick = function() mod:QueueAbort(); end, |
| 185 }; | 196 }; |
| 186 | 197 local craftButton = { |
| 187 addon:SetQueueFrameSettings("Inventorium Queue", "The following items can be added to the queue of your crafting addon. Do you wish to proceed?", proceedButton, cancelButton, headers, unqueueablesHeaders); | 198 text = "Craft", |
| 199 tooltipTitle = "Craft", | |
| 200 tooltip = "Start crafting the first item.", | |
| 201 onClick = function() mod:StartCrafting(); end, | |
| 202 }; | |
| 203 | |
| 204 addon:SetQueueFrameSettings("Inventorium Queue", "The following items can be added to the queue of your crafting addon. Do you wish to proceed?", proceedButton, cancelButton, craftButton, headers, unqueueablesHeaders); | |
| 188 end | 205 end |
| 189 end | 206 end |
| 190 | 207 |
| 191 function mod:BuildQueue() | 208 function mod:BuildQueue() |
| 192 MakeQueueWindow(); | 209 MakeQueueWindow(); |
| 266 function mod:StartCrafting(test) | 283 function mod:StartCrafting(test) |
| 267 local frame = InventoriumQueuer; -- both for speed as code-consistency | 284 local frame = InventoriumQueuer; -- both for speed as code-consistency |
| 268 | 285 |
| 269 local selectedIndex = frame.scrollTable:GetSelection(); -- gets realrow index | 286 local selectedIndex = frame.scrollTable:GetSelection(); -- gets realrow index |
| 270 | 287 |
| 271 addon:Debug("%d was selected.", tostring(selectedIndex)); | 288 addon:Debug("%s was selected.", tostring(selectedIndex)); |
| 272 | 289 |
| 273 if not selectedIndex then | 290 if not selectedIndex then |
| 274 -- Select the top most element (scrolltable with index of 1 will contain a index of the related realrow of the data table) | 291 -- Select the top most element (scrolltable with index of 1 will contain a index of the related realrow of the data table) |
| 275 selectedIndex = ((frame.scrollTable.sorttable and frame.scrollTable.sorttable[1]) or 1); | 292 selectedIndex = ((frame.scrollTable.sorttable and frame.scrollTable.sorttable[1]) or 1); |
| 276 | 293 |
| 277 addon:Debug("%d should be the top record.", tostring(selectedIndex)); | 294 addon:Debug("%s should be the top record.", tostring(selectedIndex)); |
| 278 end | 295 end |
| 279 | 296 |
| 280 local nextQueue = frame.scrollTable.data[selectedIndex] or frame.scrollTable.data[1]; -- if the selected index still fails, try to get the first record | 297 local nextQueue = frame.scrollTable.data[selectedIndex].rowData or frame.scrollTable.data[1].rowData; -- if the selected index still fails, try to get the first record |
| 281 | 298 |
| 282 if nextQueue then | 299 if nextQueue then |
| 283 if not test then | 300 if not test then |
| 301 self:ResetTradeSkillFilters(); | |
| 302 | |
| 284 -- Initiate spell (test will be used while debugging to fake crafts) | 303 -- Initiate spell (test will be used while debugging to fake crafts) |
| 285 DoTradeSkill(nextQueue.craft.no, ceil(nextQueue.amount / nextQueue.craft.quantity)); | 304 DoTradeSkill(nextQueue.craft.no, ceil(nextQueue.amount / nextQueue.craft.quantity)); |
| 286 end | 305 end |
| 287 | 306 |
| 288 -- Remember what we're crafting (saves many loops and/or table storing) | 307 -- Remember what we're crafting (saves many loops and/or table storing) |
| 583 self:QueueGroup(groupName); | 602 self:QueueGroup(groupName); |
| 584 end | 603 end |
| 585 end | 604 end |
| 586 | 605 |
| 587 do -- Trade skill recipes region | 606 do -- Trade skill recipes region |
| 588 -- Expand all categories so no crafts are hidden | |
| 589 local function ExpandSubClasses() | |
| 590 for i = GetNumTradeSkills(), 1, -1 do | |
| 591 local _, skillType, _, isExpanded = GetTradeSkillInfo(i); | |
| 592 | |
| 593 if skillType == "header" and not isExpanded then | |
| 594 ExpandTradeSkillSubClass(i); | |
| 595 end | |
| 596 end | |
| 597 end | |
| 598 | |
| 599 -- Reset all filters so no crafts are hidden | 607 -- Reset all filters so no crafts are hidden |
| 600 local function ResetFilters() | 608 function mod:ResetTradeSkillFilters() |
| 601 SetTradeSkillSubClassFilter(0, 1, 1); | 609 SetTradeSkillSubClassFilter(0, 1, 1); |
| 602 SetTradeSkillItemNameFilter(""); | 610 SetTradeSkillItemNameFilter(""); |
| 603 SetTradeSkillItemLevelFilter(0, 0); | 611 SetTradeSkillItemLevelFilter(0, 0); |
| 604 TradeSkillOnlyShowSkillUps(false); | 612 TradeSkillOnlyShowSkillUps(false); |
| 605 TradeSkillOnlyShowMakeable(false); | 613 TradeSkillOnlyShowMakeable(false); |
| 614 | |
| 615 -- Expand all categories so no crafts are hidden | |
| 616 for i = GetNumTradeSkills(), 1, -1 do | |
| 617 local _, skillType, _, isExpanded = GetTradeSkillInfo(i); | |
| 618 | |
| 619 if skillType == "header" and not isExpanded then | |
| 620 ExpandTradeSkillSubClass(i); | |
| 621 end | |
| 622 end | |
| 606 end | 623 end |
| 607 | 624 |
| 608 -- Get all craftable items into a table. Each record contains "no", "spellId" and "quantity". The last is the average amount made per craft. | 625 -- Get all craftable items into a table. Each record contains "no", "spellId" and "quantity". The last is the average amount made per craft. |
| 609 function mod:GetTradeskillCraftables() | 626 function mod:GetTradeskillCraftables() |
| 610 local craftables = {}; | 627 local craftables = {}; |
| 611 | 628 |
| 612 if GetTradeSkillLine() ~= "UNKNOWN" then | 629 if GetTradeSkillLine() ~= "UNKNOWN" then |
| 613 ExpandSubClasses(); | 630 self:ResetTradeSkillFilters(); |
| 614 ResetFilters(); | |
| 615 | 631 |
| 616 -- Cache all craftable items | 632 -- Cache all craftable items |
| 617 for i = 1, GetNumTradeSkills() do | 633 for i = 1, GetNumTradeSkills() do |
| 618 local itemLink = GetTradeSkillItemLink(i); | 634 local itemLink = GetTradeSkillItemLink(i); |
| 619 | 635 |
