QuestSounds.lua 9.05 KB
Newer Older
Azilroka's avatar
Azilroka committed
1 2 3 4
local PA = _G.ProjectAzilroka
local QS = PA:NewModule('QuestSounds', 'AceEvent-3.0', 'AceTimer-3.0')
PA.QS = QS

Azilroka's avatar
Azilroka committed
5
QS.Title = PA.ACL['|cFF16C3F2Quest|r|cFFFFFFFFSounds|r']
6
QS.Description = PA.ACL['Audio for Quest Progress & Completions.']
Azilroka's avatar
Azilroka committed
7 8
QS.Authors = 'Azilroka'
QS.Credits = 'Yoco'
Azilroka's avatar
Azilroka committed
9
QS.isEnabled = false
Azilroka's avatar
Azilroka committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

local GetNumQuestLeaderBoards, GetQuestLogLeaderBoard, PlaySoundFile = GetNumQuestLeaderBoards, GetQuestLogLeaderBoard, PlaySoundFile

function QS:CountCompletedObjectives(index)
	local Completed, Total = 0, GetNumQuestLeaderBoards(index)
	for i = 1, Total do
		local _, _, Finished = GetQuestLogLeaderBoard(i, index)
		if Finished then
			Completed = Completed + 1
		end
	end

	return Completed, Total
end

function QS:SetQuest(index)
	QS.QuestIndex = index

	QS:ScheduleTimer(function() QS:CheckQuest() end, .5)
end

function QS:ResetSoundPlayback()
	QS.IsPlaying = false
end

function QS:PlaySoundFile(file)
	QS.QuestIndex = 0

	if QS.IsPlaying or file == nil or file == '' then
		return
	end

	QS.IsPlaying = true

	if QS.db.UseSoundID then
		PlaySoundFile(file)
	else
		PlaySoundFile(PA.LSM:Fetch('sound', file))
	end

	QS:ScheduleTimer('ResetSoundPlayback', 3)
end

function QS:CheckQuest()
	if QS.QuestIndex == 0 then
		return
	end

Azilroka's avatar
Azilroka committed
58 59
	--local _, _, _, _, _, complete, daily, id = GetQuestLogTitle(index)

Azilroka's avatar
Azilroka committed
60
	QS.ObjectivesCompleted, QS.ObjectivesTotal = QS:CountCompletedObjectives(QS.QuestIndex)
Azilroka's avatar
Azilroka committed
61

Azilroka's avatar
Azilroka committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
	if QS.ObjectivesCompleted == QS.ObjectivesTotal then
		QS:ResetSoundPlayback()
		if QS.db.UseSoundID then
			QS:PlaySoundFile(QS.db.QuestCompleteID)
		else
			QS:PlaySoundFile(QS.db.QuestComplete)
		end
	elseif QS.ObjectivesCompleted > QS.ObjectivesTotal then
		if QS.db.UseSoundID then
			QS:PlaySoundFile(QS.db.ObjectiveCompleteID)
		else
			QS:PlaySoundFile(QS.db.ObjectiveComplete)
		end
	else
		if QS.db.UseSoundID then
			QS:PlaySoundFile(QS.db.ObjectiveProgressID)
		else
			QS:PlaySoundFile(QS.db.ObjectiveProgress)
		end
	end
end

function QS:UNIT_QUEST_LOG_CHANGED(_, unit)
	if unit ~= 'player' then
		return
	end

Azilroka's avatar
Azilroka committed
89
	QS:ScheduleTimer('CheckQuest', 1)
Azilroka's avatar
Azilroka committed
90 91 92 93 94 95
end

function QS:QUEST_WATCH_UPDATE(_, index)
	QS:SetQuest(index)
end

Azilroka's avatar
Azilroka committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
function QS:RegisterSounds()
	if PA.Classic then
		PA.LSM:Register('sound', 'You Will Die!', 'Sound/Creature/CThun/CThunYouWillDIe.ogg')
		PA.LSM:Register('sound', 'Gong Quest Complete', 'Sound/Doodad/G_GongTroll01.ogg')
		PA.LSM:Register('sound', 'Creature Quest Complete', 'Sound/Creature/Chicken/ChickenDeathA.ogg')
		PA.LSM:Register('sound', 'Creature Objective Complete', 'Sound/Creature/Frog/FrogFootstep2.ogg')
		PA.LSM:Register('sound', 'Creature Objective Progress', 'Sound/Creature/Crab/CrabWoundC.ogg')
		PA.LSM:Register('sound', 'Peon Quest Complete', 'Sound/Creature/Peon/PeonBuildingComplete1.ogg')
		PA.LSM:Register('sound', 'Peon Objective Complete', 'Sound/Creature/Peon/PeonReady1.ogg')
		PA.LSM:Register('sound', 'Peon Objective Progress', 'Sound/Creature/Peasant/PeasantWhat3.ogg')
		PA.LSM:Register('sound', 'QuestGuru Quest Complete', 'Sound/Interface/levelup2.ogg')
		PA.LSM:Register('sound', 'QuestGuru Objective Complete', 'Sound/Interface/AuctionWindowClose.ogg')
		PA.LSM:Register('sound', 'QuestGuru Objective Progress', 'Sound/Interface/AuctionWindowOpen.ogg')
	else
		PA.LSM:Register('sound', 'Rubber Ducky', 566121)
		PA.LSM:Register('sound', 'Cartoon FX', 566543)
		PA.LSM:Register('sound', 'Explosion', 566982)
		PA.LSM:Register('sound', 'Shing!', 566240)
		PA.LSM:Register('sound', 'Wham!', 566946)
		PA.LSM:Register('sound', 'Simon Chime', 566076)
		PA.LSM:Register('sound', 'War Drums', 567275)
		PA.LSM:Register('sound', 'Cheer', 567283)
		PA.LSM:Register('sound', 'Humm', 569518)
		PA.LSM:Register('sound', 'Short Circuit', 568975)
		PA.LSM:Register('sound', 'Fel Portal', 569215)
		PA.LSM:Register('sound', 'Fel Nova', 568582)
		PA.LSM:Register('sound', 'You Will Die!', 546633)
		PA.LSM:Register('sound', 'Gong Quest Complete', 565564)
		PA.LSM:Register('sound', 'Gong Objective Complete', 565515)
		PA.LSM:Register('sound', 'Gong Objective Progress', 569179)
		PA.LSM:Register('sound', 'Wacky Quest Complete', 566877)
		PA.LSM:Register('sound', 'Wacky Objectives Complete', 567381)
		PA.LSM:Register('sound', 'Wacky Objective Progress', 566877)
		PA.LSM:Register('sound', 'Creature Quest Complete', 546068)
		PA.LSM:Register('sound', 'Creature Objective Complete', 549326)
		PA.LSM:Register('sound', 'Creature Objective Progress', 546421)
		PA.LSM:Register('sound', 'Peon Quest Complete', 558132)
		PA.LSM:Register('sound', 'Peon Objective Complete', 558137)
		PA.LSM:Register('sound', 'Peon Objective Progress', 558127)
		PA.LSM:Register('sound', 'QuestGuru Quest Complete', 567478)
		PA.LSM:Register('sound', 'QuestGuru Objective Complete', 567499)
		PA.LSM:Register('sound', 'QuestGuru Objective Progress', 567482)
	end
end

Azilroka's avatar
Azilroka committed
141
function QS:GetOptions()
Azilroka's avatar
Azilroka committed
142
	PA.Options.args.QuestSounds = PA.ACH:Group(QS.Title, QS.Description, nil, nil, function(info) return QS.db[info[#info]] end, function(info, value) QS.db[info[#info]] = value end)
Azilroka's avatar
Azilroka committed
143
	PA.Options.args.QuestSounds.args.Description = PA.ACH:Description(QS.Description, 0)
Azilroka's avatar
Azilroka committed
144 145 146
	PA.Options.args.QuestSounds.args.Enable = PA.ACH:Toggle(PA.ACL['Enable'], nil, 1, nil, nil, nil, nil, function(info, value) QS.db[info[#info]] = value if (not QS.isEnabled) then QS:Initialize() else _G.StaticPopup_Show('PROJECTAZILROKA_RL') end end)

	PA.Options.args.QuestSounds.args.General = PA.ACH:Group(PA.ACL['General'], nil, 2)
Azilroka's avatar
Azilroka committed
147
	PA.Options.args.QuestSounds.args.General.inline = true
Azilroka's avatar
Azilroka committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

	PA.Options.args.QuestSounds.args.General.args.LSM = PA.ACH:Group(PA.ACL['Sound by LSM'], nil, 1, nil, nil, nil, function() return QS.db.UseSoundID end)
	PA.Options.args.QuestSounds.args.General.args.LSM.args.QuestComplete = PA.ACH:SharedMediaSound('Quest Complete', nil, 1)
	PA.Options.args.QuestSounds.args.General.args.LSM.args.ObjectiveComplete = PA.ACH:SharedMediaSound('Objective Complete', nil, 2)
	PA.Options.args.QuestSounds.args.General.args.LSM.args.ObjectiveProgress = PA.ACH:SharedMediaSound('Objective Progress', nil, 3)

	PA.Options.args.QuestSounds.args.General.args.ID = PA.ACH:Group(PA.ACL['Sound by SoundID'], nil, 2, nil, function(info) return tostring(QS.db[info[#info]]) end, function(info, value) QS.db[info[#info]] = tonumber(value) end, function() return (not QS.db.UseSoundID) end)
	PA.Options.args.QuestSounds.args.General.args.ID.args.UseSoundID = PA.ACH:Toggle(PA.ACL['Use Sound ID'], nil, 1, nil, nil, nil, function(info) return QS.db[info[#info]] end, function(info, value) QS.db[info[#info]] = value end, false)
	PA.Options.args.QuestSounds.args.General.args.ID.args.QuestCompleteID = PA.ACH:Input('Quest Complete Sound ID', nil, 1)
	PA.Options.args.QuestSounds.args.General.args.ID.args.ObjectiveCompleteID = PA.ACH:Input('Objective Complete Sound ID', nil, 2)
	PA.Options.args.QuestSounds.args.General.args.ID.args.ObjectiveProgressID = PA.ACH:Input('Objective Progress Sound ID', nil, 3)

	PA.Options.args.QuestSounds.args.AuthorHeader = PA.ACH:Header(PA.ACL['Authors:'], -4)
	PA.Options.args.QuestSounds.args.Authors = PA.ACH:Description(QS.Authors, -3, 'large')
	PA.Options.args.QuestSounds.args.CreditsHeader = PA.ACH:Header(PA.ACL['Image Credits:'], -2)
	PA.Options.args.QuestSounds.args.Credits = PA.ACH:Description(QS.Credits, -1, 'large')
Azilroka's avatar
Azilroka committed
164 165 166
end

function QS:BuildProfile()
Azilroka's avatar
Azilroka committed
167
	QS:RegisterSounds()
Azilroka's avatar
Azilroka committed
168

Azilroka's avatar
Azilroka committed
169
	PA.Defaults.profile.QuestSounds = {
Azilroka's avatar
1.61  
Azilroka committed
170
		Enable = true,
Azilroka's avatar
Azilroka committed
171 172 173 174 175 176 177
		QuestComplete = 'Peon Quest Complete',
		ObjectiveComplete = 'Peon Objective Complete',
		ObjectiveProgress = 'Peon Objective Progress',
		UseSoundID = false,
		QuestCompleteID = PA.MyFaction == 'Alliance' and 61525 or 95834,
		ObjectiveCompleteID = 6573,
		ObjectiveProgressID = 9873,
Azilroka's avatar
Azilroka committed
178 179 180 181
	}
end

function QS:Initialize()
Azilroka's avatar
Azilroka committed
182
	QS.db = PA.db.QuestSounds
Azilroka's avatar
Azilroka committed
183 184 185 186 187

	if QS.db.Enable ~= true then
		return
	end

Azilroka's avatar
Azilroka committed
188
	local KT = _G.LibStub('AceAddon-3.0'):GetAddon('!KalielsTracker', true)
Azilroka's avatar
Azilroka committed
189 190

	if KT and KT.db.profile.soundQuest then
Azilroka's avatar
Azilroka committed
191
		_G.StaticPopupDialogs.PROJECTAZILROKA.text = 'Kaliels Tracker Quest Sound and QuestSounds will make double sounds. Which one do you want to disable?|n|n(This does not disable Kaliels Tracker)'
Azilroka's avatar
Azilroka committed
192 193 194
		_G.StaticPopupDialogs.PROJECTAZILROKA.button1 = 'KT Quest Sound'
		_G.StaticPopupDialogs.PROJECTAZILROKA.button2 = 'Quest Sounds'
		_G.StaticPopupDialogs.PROJECTAZILROKA.OnAccept = function()
Azilroka's avatar
Azilroka committed
195
			KT.db.profile.soundQuest = false
Azilroka's avatar
Azilroka committed
196
			_G.ReloadUI()
Azilroka's avatar
Azilroka committed
197
		end
Azilroka's avatar
Azilroka committed
198
		_G.StaticPopupDialogs.PROJECTAZILROKA.OnCancel = function() QS.db.Enable = false end
Azilroka's avatar
Azilroka committed
199
		_G.StaticPopup_Show('PROJECTAZILROKA')
Azilroka's avatar
Azilroka committed
200 201 202 203
		return
	end

	if PA:IsAddOnEnabled('QuestGuruSounds', PA.MyName) then
Azilroka's avatar
Azilroka committed
204 205 206 207
		_G.StaticPopupDialogs.PROJECTAZILROKA.text = 'QuestGuru Sounds and QuestSounds will make double sounds. Which one do you want to disable?'
		_G.StaticPopupDialogs.PROJECTAZILROKA.button1 = 'KT Quest Sound'
		_G.StaticPopupDialogs.PROJECTAZILROKA.button2 = 'Quest Sounds'
		_G.StaticPopupDialogs.PROJECTAZILROKA.OnAccept = function() _G.DisableAddOn('QuestGuruSounds') _G.ReloadUI() end
Azilroka's avatar
Azilroka committed
208
		_G.StaticPopupDialogs.PROJECTAZILROKA.OnCancel = function() QS.db.Enable = false end
Azilroka's avatar
Azilroka committed
209
		_G.StaticPopup_Show('PROJECTAZILROKA')
Azilroka's avatar
Azilroka committed
210
		return
Azilroka's avatar
Azilroka committed
211
	end
Azilroka's avatar
Azilroka committed
212 213 214 215 216 217 218 219 220 221

	QS.isEnabled = true

	QS.QuestIndex = 0
	QS.ObjectivesComplete = 0
	QS.ObjectivesTotal = 0
	QS.IsPlaying = false

	QS:RegisterEvent('UNIT_QUEST_LOG_CHANGED')
	QS:RegisterEvent('QUEST_WATCH_UPDATE')
222
end