diff --git a/APR-Recorder.toc b/APR-Recorder.toc index b53bf11..1da0b2c 100644 --- a/APR-Recorder.toc +++ b/APR-Recorder.toc @@ -29,12 +29,12 @@ helper/RouteManagement.lua Commands.lua Event.lua -frames/autocompleteLocales.lua +frames/autocomplete.lua frames/CommandsBar.lua frames/exportExtraLineText.lua frames/exportRoute.lua -frames/fillersSelection.lua frames/QuestionPopUp.lua +frames/QuestObjectiveSelector.lua frames/RecorderBar.lua frames/routeSelector.lua frames/selectButton.lua diff --git a/Commands.lua b/Commands.lua index c3a01fc..a5f0e52 100644 --- a/Commands.lua +++ b/Commands.lua @@ -129,11 +129,25 @@ function AprRC.command:SlashCmd(input) return elseif inputText == "button" or inputText == "btn" then AprRC.SelectButton:Show() - -- AprRC.autocomplete:ShowItemAutoComplete() - -- AprRC.autocomplete:ShowSpellAutoComplete() return elseif inputText == "fillers" or inputText == "filler" then - AprRC.fillers:Show() + AprRC.QuestObjectiveSelector:Show({ + title = "Fillers quest list", + statusText = "Click on an objective to add it as a filler", + questList = AprRC.QuestObjectiveSelector:GetQuestList(), + onClick = function(questID, objectiveID) + local currentStep = AprRC:GetLastStep() + if not currentStep.Fillers then + currentStep.Fillers = {} + end + if not currentStep.Fillers[questID] then + currentStep.Fillers[questID] = {} + end + table.insert(currentStep.Fillers[questID], objectiveID) + print("|cff00bfffFillers - [" .. + C_QuestLog.GetTitleForQuestID(questID) .. "] - " .. objectiveID .. "|r Added") + end + }) return elseif inputText == "spelltrigger" then AprRC.questionDialog:CreateEditBoxPopupWithCallback("SpellTrigger (Spell ID)", function(text) diff --git a/frames/fillersSelection.lua b/frames/QuestObjectiveSelector.lua similarity index 50% rename from frames/fillersSelection.lua rename to frames/QuestObjectiveSelector.lua index 26619a3..5b04252 100644 --- a/frames/fillersSelection.lua +++ b/frames/QuestObjectiveSelector.lua @@ -1,12 +1,13 @@ local _G = _G local AceGUI = LibStub("AceGUI-3.0") -AprRC.fillers = AprRC:NewModule('Fillers') +AprRC.QuestObjectiveSelector = AprRC:NewModule('QuestObjectiveSelector') -function AprRC.fillers:Show() + +function AprRC.QuestObjectiveSelector:Show(config) local frame = AceGUI:Create("Frame") - frame:SetTitle("Fillers quest list") - frame:SetStatusText("Click on an objective to add it as a filler") + frame:SetTitle(config.title or "Quest Objective Selector") + frame:SetStatusText(config.statusText or "Select a quest objective") frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end) frame:SetWidth(800) frame:SetHeight(600) @@ -18,9 +19,8 @@ function AprRC.fillers:Show() scrollFrame:SetFullHeight(true) scrollFrame:SetLayout("Flow") - local questList = AprRC.fillers:GetQuestList() - for _, quest in ipairs(questList) do + for _, quest in ipairs(config.questList) do if #quest.objectives > 0 then local questGroup = AceGUI:Create("InlineGroup") questGroup:SetFullWidth(true) @@ -32,15 +32,9 @@ function AprRC.fillers:Show() objectiveLabel:SetText("[" .. objective.objectiveID .. "]" .. " - " .. objective.text) objectiveLabel:SetFullWidth(true) objectiveLabel:SetCallback("OnClick", function() - local currentStep = AprRC:GetLastStep() - if not currentStep.Fillers then - currentStep.Fillers = {} - end - if not currentStep.Fillers[quest.questID] then - currentStep.Fillers[quest.questID] = {} + if config.onClick then + config.onClick(quest.questID, objective.objectiveID) end - tinsert(currentStep.Fillers[quest.questID], objective.objectiveID) - print("|cff00bfffFillers - [" .. quest.title .. "] - " .. objective.objectiveID .. "|r Added") AceGUI:Release(frame) end) objectiveLabel:SetCallback("OnEnter", function(widget) @@ -66,7 +60,40 @@ function AprRC.fillers:Show() frame:AddChild(scrollFrame) end -function AprRC.fillers:GetQuestList() +local function GetFormattedQuestObjectives(questID, objectiveIDs) + local formattedObjectives = {} + local objectivesInfo = C_QuestLog.GetQuestObjectives(questID) + + if objectivesInfo then + for _, objectiveID in ipairs(objectiveIDs) do + local objective = objectivesInfo[objectiveID] + if objective then + table.insert(formattedObjectives, { + objectiveID = objectiveID, + text = objective.text + }) + end + end + end + + return formattedObjectives +end + +local function AddQuestsToList(questList, questsTable) + for questID, objectives in pairs(questsTable) do + local title = C_QuestLog.GetTitleForQuestID(questID) + if title then + local formattedObjectives = GetFormattedQuestObjectives(questID, objectives) + table.insert(questList, { + title = questID .. " - " .. title, + questID = questID, + objectives = formattedObjectives + }) + end + end +end + +function AprRC.QuestObjectiveSelector:GetQuestList() local questList = {} for i = 1, C_QuestLog.GetNumQuestLogEntries() do @@ -74,28 +101,38 @@ function AprRC.fillers:GetQuestList() if info and not info.isHeader then local questID = info.questID local title = C_QuestLog.GetTitleForQuestID(questID) - local isComplete = C_QuestLog.IsComplete(questID) - if not isComplete then - local objectives = C_QuestLog.GetQuestObjectives(questID) - - local formattedObjectives = {} - for j, objective in ipairs(objectives) do - local formattedObjective = { - objectiveID = j, - text = objective.text - } - table.insert(formattedObjectives, formattedObjective) + if title and not C_QuestLog.IsComplete(questID) then + local objectives = {} + local objectivesInfo = C_QuestLog.GetQuestObjectives(questID) + for j, objective in ipairs(objectivesInfo) do + table.insert(objectives, j) end - - local questData = { + local formattedObjectives = GetFormattedQuestObjectives(questID, objectives) + table.insert(questList, { title = questID .. " - " .. title, questID = questID, objectives = formattedObjectives - } - table.insert(questList, questData) + }) end end end return questList end + +function AprRC.QuestObjectiveSelector:GetQuestListFromLastStep() + local questList = {} + local lastStep = AprRC:GetLastStep() + + if lastStep then + if lastStep.Qpart then + AddQuestsToList(questList, lastStep.Qpart) + end + + if lastStep.Fillers then + AddQuestsToList(questList, lastStep.Fillers) + end + end + + return questList +end diff --git a/frames/autocompleteLocales.lua b/frames/autocomplete.lua similarity index 89% rename from frames/autocompleteLocales.lua rename to frames/autocomplete.lua index 0e7a412..a3abc18 100644 --- a/frames/autocompleteLocales.lua +++ b/frames/autocomplete.lua @@ -138,7 +138,7 @@ function AprRC.autocomplete:ShowLocaleAutoComplete() ) end -function AprRC.autocomplete:ShowItemAutoComplete() +function AprRC.autocomplete:ShowItemAutoComplete(questID, objectiveID) local itemList = {} for bag = 0, 4 do for slot = 1, C_Container.GetContainerNumSlots(bag) do @@ -155,8 +155,13 @@ function AprRC.autocomplete:ShowItemAutoComplete() self:ShowAutoComplete( "Select Item", itemList, - function(text, key, frame) - print(text, key) + function(_, itemID, frame) + local currentStep = AprRC:GetLastStep() + if not currentStep.Button then + currentStep.Button = {} + end + currentStep.Button[questID .. "-" .. objectiveID] = tonumber(itemID, 10) + print("|cff00bfff Button |r Added") AceGUI:Release(frame) end, function(match) @@ -169,7 +174,7 @@ function AprRC.autocomplete:ShowItemAutoComplete() ) end -function AprRC.autocomplete:ShowSpellAutoComplete() +function AprRC.autocomplete:ShowSpellAutoComplete(questID, objectiveID) local spellList = {} for i = 1, C_SpellBook.GetNumSpellBookSkillLines() do local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(i) @@ -184,8 +189,13 @@ function AprRC.autocomplete:ShowSpellAutoComplete() self:ShowAutoComplete( "Select Spell", spellList, - function(text, key, frame) - print(text, key) + function(_, spellID, frame) + local currentStep = AprRC:GetLastStep() + if not currentStep.SpellButton then + currentStep.SpellButton = {} + end + currentStep.SpellButton[questID .. "-" .. objectiveID] = tonumber(spellID, 10) + print("|cff00bfff SpellButton |r Added") AceGUI:Release(frame) end, function(match) diff --git a/frames/exportRoute.lua b/frames/exportRoute.lua index e637c68..db5bb57 100644 --- a/frames/exportRoute.lua +++ b/frames/exportRoute.lua @@ -95,7 +95,6 @@ function AprRC.export:Show() local routeText = editbox:GetText() local newStepRouteTable = AprRC:stringToTable(routeText) if not newStepRouteTable then - UIErrorsFrame:AddMessage("Route not saved, incorrect format", 1, 0, 0, 1, 5) AprRC:Error("Route not saved, incorrect format") return end diff --git a/frames/selectButton.lua b/frames/selectButton.lua index 857e006..4a6bc35 100644 --- a/frames/selectButton.lua +++ b/frames/selectButton.lua @@ -17,51 +17,41 @@ function AprRC.SelectButton:Show() buttonGroup:SetLayout("Flow") frame:AddChild(buttonGroup) - local btnItem = AceGUI:Create("Button") - btnItem:SetText("Item") - btnItem:SetFullWidth(true) - btnItem:SetCallback("OnClick", function() - AceGUI:Release(frame) - AprRC.questionDialog:CreateEditBoxPopupWithCallback("QuestID for the button (ID)", function(questID) - C_Timer.After(0.2, function() - AprRC.questionDialog:CreateEditBoxPopupWithCallback("Objective index of the quest", function(index) - C_Timer.After(0.2, function() - AprRC.questionDialog:CreateEditBoxPopupWithCallback("Item Button (ID)", function(itemID) - local currentStep = AprRC:GetLastStep() - if not currentStep.Button then - currentStep.Button = {} - end - currentStep.Button[questID .. "-" .. index] = tonumber(itemID, 10) - print("|cff00bfff Button |r Added") - end) - end) - end) - end) + local function AddButton(text, callback) + local button = AceGUI:Create("Button") + button:SetText(text) + button:SetFullWidth(true) + button:SetCallback("OnClick", function() + AceGUI:Release(frame) + callback() end) - end) - buttonGroup:AddChild(btnItem) + buttonGroup:AddChild(button) + end - local btnSpell = AceGUI:Create("Button") - btnSpell:SetText("Spell") - btnSpell:SetFullWidth(true) - btnSpell:SetCallback("OnClick", function() - AceGUI:Release(frame) - AprRC.questionDialog:CreateEditBoxPopupWithCallback("QuestID for the button (ID)", function(questID) - C_Timer.After(0.2, function() - AprRC.questionDialog:CreateEditBoxPopupWithCallback("Objective index of the quest", function(index) - C_Timer.After(0.2, function() - AprRC.questionDialog:CreateEditBoxPopupWithCallback("Spell Button (ID)", function(spellID) - local currentStep = AprRC:GetLastStep() - if not currentStep.SpellButton then - currentStep.SpellButton = {} - end - currentStep.SpellButton[questID .. "-" .. index] = tonumber(spellID, 10) - print("|cff00bfff SpellButton |r Added") - end) - end) - end) - end) - end) - end) - buttonGroup:AddChild(btnSpell) + AddButton("Item", function() self:ShowQuestSelector("Item") end) + AddButton("Spell", function() self:ShowQuestSelector("Spell") end) +end + +function AprRC.SelectButton:ShowQuestSelector(type) + local questList = AprRC.QuestObjectiveSelector:GetQuestListFromLastStep() + if #questList == 0 then + AprRC:Error("No Qpart or Filler quests available on your last step") + return + end + + local callback + if type == "Item" then + callback = function(questID, objectiveID) + AprRC.autocomplete:ShowItemAutoComplete(questID, objectiveID) + end + elseif type == "Spell" then + callback = function(questID, objectiveID) + AprRC.autocomplete:ShowSpellAutoComplete(questID, objectiveID) + end + end + + AprRC.QuestObjectiveSelector:Show({ + questList = questList, + onClick = callback + }) end diff --git a/helper/Utils.lua b/helper/Utils.lua index ceba924..b045fc6 100644 --- a/helper/Utils.lua +++ b/helper/Utils.lua @@ -21,6 +21,7 @@ function AprRC:Error(errorMessage, data) else DEFAULT_CHAT_FRAME:AddMessage(redColorCode .. L["ERROR"] .. ": " .. errorMessage .. "|r") end + UIErrorsFrame:AddMessage(errorMessage, 1, 0, 0, 1, 5) end end @@ -124,7 +125,7 @@ local function qpartTableToString(tbl, level, parrentKey) for _, k in ipairs(keys) do local v = tbl[k] local keyStr = '' - if parrentKey == "Button" then + if parrentKey == "Button" or parrentKey == "SpellButton" then keyStr = '["' .. tostring(k) .. '"] = ' else keyStr = "[" .. k .. "] = " @@ -162,7 +163,7 @@ function AprRC:RouteToString(tbl, level) str = str .. itemIndent .. keyStr .. "{}" .. ",\n" else local valueStr - if k == "Qpart" or k == "Fillers" or k == "Button" then + if k == "Qpart" or k == "Fillers" or k == "Button" or k == "SpellButton" then valueStr = qpartTableToString(v, level + 1, k) else valueStr = self:RouteToString(v, level + 1)