Skip to content

Commit

Permalink
Beta - Rework button & SpellButton frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Neogeekmo committed Jul 15, 2024
1 parent 4f2302e commit eb04ced
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 89 deletions.
4 changes: 2 additions & 2 deletions APR-Recorder.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 17 additions & 3 deletions Commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
97 changes: 67 additions & 30 deletions frames/fillersSelection.lua → frames/QuestObjectiveSelector.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -66,36 +60,79 @@ 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
local info = C_QuestLog.GetInfo(i)
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
22 changes: 16 additions & 6 deletions frames/autocompleteLocales.lua → frames/autocomplete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion frames/exportRoute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 35 additions & 45 deletions frames/selectButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions helper/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 .. "] = "
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit eb04ced

Please sign in to comment.