From a49c1dbf3e22625acda86f4c349c2a4c34f6bdf3 Mon Sep 17 00:00:00 2001 From: pschifferer Date: Fri, 16 Oct 2009 05:33:55 +0000 Subject: [PATCH] Added some new logic to queue processing, where if the first item in the queue can be made, it will be processed immediately, instead of handling intermediate items (if any). Added the quantity that can be made (now) next to the name of items in the main and intermediate queues. --- Cauldron.toc | 2 +- CauldronMain.lua | 71 +++++++++++++++++++++++++++++++++++++++++----------- CauldronMain.xml | 2 ++ CauldronMainUI.lua | 44 ++++++++++++++++++++++++++++++-- 4 files changed, 102 insertions(+), 17 deletions(-) diff --git a/Cauldron.toc b/Cauldron.toc index 9363138..e56449e 100755 --- a/Cauldron.toc +++ b/Cauldron.toc @@ -1,6 +1,6 @@ ## Interface: 30100 ## Title: Cauldron |cff7fff7f -Ace3-|r -## Version: 0.9.13.@project-revision@ +## Version: 0.9.14.@project-revision@ ## Author: Caendra of Silver Hand ## Notes: An improved interface for your trade skills ## RequiredDeps: diff --git a/CauldronMain.lua b/CauldronMain.lua index 1c1db22..9260f58 100644 --- a/CauldronMain.lua +++ b/CauldronMain.lua @@ -4,7 +4,7 @@ Cauldron = LibStub("AceAddon-3.0"):NewAddon("Cauldron", "AceEvent-3.0", "AceTimer-3.0", "AceConsole-3.0", "AceHook-3.0", "LibLogger-1.0"); local L = LibStub("AceLocale-3.0"):GetLocale("Cauldron"); -Cauldron.version = "0.9.13.@project-revision@"; +Cauldron.version = "0.9.14.@project-revision@"; Cauldron.date = string.sub("$Date$", 8, 17); -- key binding names @@ -23,6 +23,7 @@ Cauldron.vars = { Cauldron.libs = {}; -- Cauldron.libs.Abacus = LibStub("LibAbacus-3.0"); -- Cauldron.libs.PT = LibStub("LibPeriodicTable-3.1"); +Cauldron.libs.GUI = LibStub("AceGUI-3.0"); -- logging Cauldron:SetLogLevel(Cauldron.logLevels.INFO); @@ -656,19 +657,57 @@ function Cauldron:ProcessQueue() -- if items other than first can be made and first can't, ask user if they want to make that instead --]] - -- see if first item can be made - -- TODO + local queue = CauldronQueue:GetItems(self.db.realm.userdata[self.vars.playername].queue); + self:debug("ProcessQueue: queue="..#queue); - -- see if queue contains other items that can be made if the first can't be - -- TODO + local queueInfo = nil; + local skillInfo = nil; + + if #queue > 0 then + self:debug("ProcessQueue: checking first main queue item to see if it can be made now"); + -- see if first item can be made + queueInfo = queue[1]; + self:debug("ProcessQueue: queueInfo="..queueInfo.name); + skillInfo = Cauldron:GetSkillInfo(queueInfo.tradeskill, queueInfo.name); + self:debug("ProcessQueue: skillInfo="..tostring(skillInfo)); + + if skillInfo.available > 0 then + self:debug("First item in main queue can be made "..skillInfo.available.." times"); + self:SubmitItemToProcess(queueInfo, skillInfo, skillInfo.available); + return; +--[[ else + -- see if queue contains other items that can be made if the first can't be + if #queue > 1 then + for i=2,#queue do + queueInfo = queue[i]; + skillInfo = Cauldron:GetSkillInfo(queueInfo.tradeskill, queueInfo.name); + self:debug("ProcessQueue: skillInfo="..tostring(skillInfo)); + + if skillInfo.available > 0 then + -- present dialog to user to move item to top of queue + Cauldron:ConfirmDialog(L["Confirm"], L["message"], + L["Okay"], + function() + Cauldron:info("Okay"); + -- TODO + end, + L["Cancel"], + function() + Cauldron:info("Cancel"); + -- TODO + end); + return; + end + end + end --]] + end + end + -- find intermediate items that need to be crafted local intQueue = CauldronQueue:GetIntermediates(self.db.realm.userdata[self.vars.playername].queue); self:debug("ProcessQueue: intQueue="..#intQueue); - local queueInfo = nil; - local skillInfo = nil; - if #intQueue > 0 then self:debug("ProcessQueue: processing intermediate queue items"); @@ -677,9 +716,6 @@ function Cauldron:ProcessQueue() skillInfo = Cauldron:GetSkillInfo(queueInfo.tradeskill, queueInfo.name); self:debug("ProcessQueue: skillInfo="..tostring(skillInfo)); else - local queue = CauldronQueue:GetItems(self.db.realm.userdata[self.vars.playername].queue); - self:debug("ProcessQueue: queue="..#queue); - if #queue > 0 then self:debug("ProcessQueue: processing main queue items"); @@ -689,6 +725,14 @@ function Cauldron:ProcessQueue() self:debug("ProcessQueue: skillInfo="..tostring(skillInfo)); end end + + self:SubmitItemToProcess(queueInfo, skillInfo); + + self:debug("ProcessQueue exit"); +end + +function Cauldron:SubmitItemToProcess(queueInfo, skillInfo, amount) + self:debug("SubmitItemToProcess enter"); if queueInfo and skillInfo then self:debug("ProcessQueue: queueInfo="..queueInfo.name); @@ -700,7 +744,7 @@ function Cauldron:ProcessQueue() end self:debug("ProcessQueue: process item: "..queueInfo.name); - Cauldron:ProcessItem(skillInfo, queueInfo, queueInfo.amount); + Cauldron:ProcessItem(skillInfo, queueInfo, amount or queueInfo.amount); else if not queueInfo then self:error("Missing queue info!"); @@ -710,10 +754,9 @@ function Cauldron:ProcessQueue() end end - self:debug("ProcessQueue exit"); + self:debug("SubmitItemToProcess exit"); end - function Cauldron:ProcessItem(skillInfo, queueInfo, amount) self:debug("ProcessItem enter"); diff --git a/CauldronMain.xml b/CauldronMain.xml index 934ebc1..e5cad25 100644 --- a/CauldronMain.xml +++ b/CauldronMain.xml @@ -491,6 +491,7 @@ Cauldron:IncreaseItemPriority(self:GetParent().itemName, IsShiftKeyDown()); + CauldronQueue:CalculateAllRequiredItems(Cauldron:GetQueue()); Cauldron:UpdateQueue(); @@ -528,6 +529,7 @@ Cauldron:DecreaseItemPriority(self:GetParent().itemName, IsShiftKeyDown()); + CauldronQueue:CalculateAllRequiredItems(Cauldron:GetQueue()); Cauldron:UpdateQueue(); diff --git a/CauldronMainUI.lua b/CauldronMainUI.lua index 2d17fd5..817f345 100644 --- a/CauldronMainUI.lua +++ b/CauldronMainUI.lua @@ -694,7 +694,11 @@ function Cauldron:UpdateQueue() --@alpha@ self:debug("frame: "..tostring(frame).." ("..frame:GetName()..")"); --@end-alpha@ - frame:SetText(queueInfo.name); + local nameText = queueInfo.name; + if skillInfo and (skillInfo.available > 0) then + nameText = nameText.." ["..skillInfo.available.."]"; + end + frame:SetText(nameText); if skillInfo then local color = TradeSkillTypeColor[skillInfo.difficulty]; if color then @@ -853,7 +857,11 @@ function Cauldron:UpdateQueue() -- set name and difficulty color frame = _G["CauldronQueueIntItem"..i.."ItemName"]; - frame:SetText(queueInfo.name); + local nameText = queueInfo.name; + if skillInfo and (skillInfo.available > 0) then + nameText = nameText.." ["..skillInfo.available.."]"; + end + frame:SetText(nameText); if skillInfo then local color = TradeSkillTypeColor[skillInfo.difficulty]; if color then @@ -2093,3 +2101,35 @@ function Cauldron:FavoriteItemButton_OnClick(button) self:debug("FavoriteItemButton_OnClick exit"); --@end-alpha@ end + +function Cauldron:ConfirmDialog(title, message, okayBtn, okayBtnCB, cancelBtn, cancelBtnCB) + + local gui = Cauldron.libs.GUI; + + -- Create a container frame + local f = gui:Create("Frame"); + f:SetCallback("OnClose", function(widget) gui:Release(widget) end); + f:SetTitle(title); + f:SetStatusText(""); + f:SetLayout("Flow"); + f:SetWidth(200); + f:SetHeight(100); + + -- Create okay button + local btn = gui:Create("Button") + btn:SetWidth(170); + btn:SetText(okayBtn); + btn:SetCallback("OnClick", okayBtnCB); -- TODO wrap this callback in another that will close the window + -- Add the button to the container + f:AddChild(btn); + + -- Create cancel button + local btn = gui:Create("Button") + btn:SetWidth(170); + btn:SetText(cancelBtn); + btn:SetCallback("OnClick", cancelBtnCB); -- TODO wrap this callback in another that will close the window + -- Add the button to the container + f:AddChild(btn); + + f:Show(); +end -- 1.7.9.5