KillingBlowAnnouncer = LibStub("AceAddon-3.0"):NewAddon("KillingBlowAnnouncer", "AceConsole-3.0", "AceEvent-3.0")

local Media = LibStub("LibSharedMedia-3.0")
------------------------------------------------------------------ADD SOUND FILES HERE--------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--------HOW TO ADD SOUND FILES----------------------------------------------------------------------------------
---1. Make sure that the sound file is either a mp3 file or ogg file. This is important because WoW doesn't support any other soundfiles.
---2. Add the file to the Sounds map. Found at Interface\AddOns\Killing Blow Announcer\Sounds
---3. Add the following line to this lua file with your own soundname and the path to the sound file: 
---   Media:Register("sound", "HOW YOU WANT THE SOUND FILE TO BE NAMED", [[Interface\AddOns\Killing Blow Announcer\Sounds\FILENAME.mp3]]);
---4. Save changes to the Killing Blow Announcer file and  Restart WoW in case it was already open.
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
---Make sure to backup any changes to this file and of the files added to the sounds map when updating this addon. Any changes will be overwritten
---when updating so just a heads up.
----------------------------------------------------------------------------------------------------------------

--QUAKE FEMALE SOUNDS
Media:Register("sound", "Quake female: bottomfeeder", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\bottomfeeder.mp3]]);
Media:Register("sound", "Quake female: dominating", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\dominating.mp3]]);
Media:Register("sound", "Quake female: firstblood", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\firstblood.mp3]]);
Media:Register("sound", "Quake female: godlike", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\godlike.mp3]]);
Media:Register("sound", "Quake female: headshot", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\headshot.mp3]]);
Media:Register("sound", "Quake female: humiliation", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\humiliation.mp3]]);
Media:Register("sound", "Quake female: killingspree", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\killingspree.mp3]]);
Media:Register("sound", "Quake female: monsterkill", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\monsterkill.mp3]]);
Media:Register("sound", "Quake female: multikill", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\multikill.mp3]]);
Media:Register("sound", "Quake female: play", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\prepare.mp3]]);
Media:Register("sound", "Quake female: rampage", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\rampage.mp3]]);
Media:Register("sound", "Quake female: ultrakill", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\ultrakill.mp3]]);
Media:Register("sound", "Quake female: unstoppable", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\unstoppable.mp3]]);
Media:Register("sound", "Quake female: wickedsick", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\wickedsick.mp3]]);

--QUAKE MALE SOUNDS
Media:Register("sound", "Quake male: wickedsick", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\wickedsick.mp3]]);
Media:Register("sound", "Quake male: unstoppable", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\unstoppable.mp3]])
Media:Register("sound", "Quake male: ultrakill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\ultrakill.mp3]]);
Media:Register("sound", "Quake male: triplekill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\triplekill.mp3]]);
Media:Register("sound", "Quake male: teamkiller", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\teamkiller.mp3]]);
Media:Register("sound", "Quake male: rampage", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\rampage.mp3]]);
Media:Register("sound", "Quake male: prepare", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\prepare.mp3]]);
Media:Register("sound", "Quake male: perfect", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\perfect.mp3]]);
Media:Register("sound", "Quake male: multikill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\multikill.mp3]]);
Media:Register("sound", "Quake male: monsterkill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\monsterkill.mp3]]);
Media:Register("sound", "Quake male: megakill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\megakill.mp3]]);
Media:Register("sound", "Quake male: ludicrouskill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\ludicrouskill.mp3]]);
Media:Register("sound", "Quake male: killingspree", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\killingspree.mp3]]);
Media:Register("sound", "Quake male: impressive", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\impressive.mp3]]);
Media:Register("sound", "Quake male: humiliation", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\humiliation.mp3]]);
Media:Register("sound", "Quake male: holyshit", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\holyshit.mp3]]);
Media:Register("sound", "Quake male: headshot", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\headshot.mp3]]);
Media:Register("sound", "Quake male: godlike", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\godlike.mp3]]);
Media:Register("sound", "Quake male: firstblood", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\firstblood.mp3]]);
Media:Register("sound", "Quake male: doublekill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\doublekill.mp3]]);
Media:Register("sound", "Quake male: dominating", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\dominating.mp3]]);
Media:Register("sound", "Quake male: combowhore", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\combowhore.mp3]]);

----------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------END OF SOUND FILE LIST------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------


------------------------------------------------------------------ADD IMAGE FILES HERE--------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--------HOW TO ADD IMAGE FILES----------------------------------------------------------------------------------
---1. Make sure that the image file is either a  BLP image or TGA  image. This is important because WoW doesn't support any other image types.
---2. Make sure that the image contains a power of two dimension. Basically this means that both the width and height of an image needs to be one of the following dimensions
--    "8", "16", "32", "64", "128", "256", "512", "1024", "2048". http://wowpedia.org/API_Texture_SetTexture
---3. Add the file to the Images map. Found at Interface\AddOns\Killing Blow Announcer\Images
---4. Add the following line exactly as the example below with FILENAME being the image name:
---   Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\FILENAME", [[Interface\AddOns\Killing Blow Announcer\Images\FILENAME.tga]]);
---5. Save changes to the Killing Blow Announcer file and  Restart WoW in case it was already open.
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
---Make sure to backup any changes to this file and of the files added to the images map when updating this addon. Any changes will be overwritten
---when updating so just a heads up.
----------------------------------------------------------------------------------------------------------------

Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\imageBlue", [[Interface\AddOns\Killing Blow Announcer\Images\imageBlue.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\imageFrost", [[Interface\AddOns\Killing Blow Announcer\Images\imageFrost.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\imageYellow", [[Interface\AddOns\Killing Blow Announcer\Images\imageYellow.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\alliance1", [[Interface\AddOns\Killing Blow Announcer\Images\alliance1.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\horde1", [[Interface\AddOns\Killing Blow Announcer\Images\horde1.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\alliance2", [[Interface\AddOns\Killing Blow Announcer\Images\alliance2.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\horde2", [[Interface\AddOns\Killing Blow Announcer\Images\horde2.tga]]);

----------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------END OF IMAGE FILES LIST-----------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------


local options = {
	name = "Killing Blow Announcer",
	handler = KillingBlowAnnouncer,
	type = 'group',
	childGroups = "tab",
	args = {
				enablePVP		=	{
									type		=	"toggle",
									name		=	"Enable pvp only",
									desc		=	"Enables the addon to only work for player kills. If left unchecked it will announce and track every kill regardless if it's a player or not.",	
									order 		= 	 1,
									get			=	"EnablePVP",
									set			=	"ToggleEnablePVP",
									},
				enableMinimapIcon		=	{
									type		=	"toggle",
									name		=	"Enable minimap icon",
									desc		=	"Enables the minimap icon.",	
									order 		= 	 1,
									get			=	"GetEnableMinimapIcon",
									set			=	"ToggleEnableMinimapIcon",
									},
				Options= {
					name		=	"Chat options",
					desc 		= 	"Options related to the chat message",
					type		=	"group",					
					order		=	1,
					args		=	{		
								enableMSG		=	{
									type		=	"toggle",
									name		=	"Enable chat message",
									desc		=	"Enables the Killing blow chat message ",	
									order 		= 	 1,
									width 		= 	"full",
									get			=	"EnableMSG",
									set			=	"ToggleEnableMSG",
									},
								
							    msg = {
									type = "input",
									name = "Chat message",
									desc = "The chat message displayed when you get a KB",
									order = 2,
									width = "full",
									usage = "<Your message here>",
									get = "GetMessage",
									set = "SetMessage",
								},
								editChannel = {
									name 		= "Channel",
									desc 		= "Adjust to which channel the message gets printed.",
									order 		= 3, width = "full",
									type 		= "select",
									values 		= {["say"] = "say",["yell"] = "yell",["raid"] = "raid",["party"] = "party",["guild"] = "guild"},
									get		    = function(info) return KillingBlowAnnouncer:GetChatChannel(info) end,
									set 		= function(info,key) KillingBlowAnnouncer:SetChatChannel(info,key) end,
									},
								header1		=	{
									type		=	"header",
									name		= 	 "",
									order 		= 	 4,
									width 		= 	"full",
									},
								toggleMessage		=	{
									type		=	"toggle",
									name		=	"Enable chat announcer message",
									desc		=	"Enables announcing who you killed to the chat",	
									order 		= 	 5,
									width 		= 	"full",
									get			=	"EnableMSGAnnounce",
									set			=	"ToggleEnableMSGAnnounce",
									},
								chatMessage = {
									type = "input",
									name = "Chat announce message",
									desc = "The chat message displayed which will announce who you killed to the chat when you get a killing blow. Only works for player kils.",
									order = 6,
									width = "full",
									usage = "<Your message here>",
									get = "GetAnnounceMessage",
									set = "SetAnnounceMessage",
								},
								chatMessagePreview = {
									type = "description",
									name = "The chat message above will display your name,who you've killed,which class the person was that you killed and in which zone this was. The default message will be displayed like this 'Eucalyptisch killed Eucal of class druid in Shadowmoon valley'. \n\nWhen changing the message make sure to write the ${} variables exactly as written below else it will just display ${playerr} instead of the actual player name. If you only want to display something like 'I killed Eucalyptisch in Shadowmoon valley' simply remove the unneeded ${} and it will work. For example the previous sentence would be 'I killed ${enemy} in ${zone}'.\n\nVariables:\n|cff3498db${player} = your playername.\n${enemy} = the killed player's name.\n${class} = the killed player's class.\n${zone} = the zone that the player was killed in.",
									fontSize  = "medium",
									order = 7,
									width = "full",
								},
								editChatChannel = {
									name 		= "Channel",
									desc 		= "Adjust to which channel the announce chat message gets printed.",
									order 		= 8, width = "full",
									type 		= "select",
									values 		= {["say"] = "say",["yell"] = "yell",["raid"] = "raid",["party"] = "party",["guild"] = "guild"},
									get		    = function(info) return KillingBlowAnnouncer:GetChatAnnounceChannel(info) end,
									set 		= function(info,key) KillingBlowAnnouncer:SetChatAnnounceChannel(info,key) end,
									},
								},
						},
			Options2= {
					name		=	"Tracker options",
					desc 		= 	"Options related to the tracker frame",
					type		=	"group",	
					order		=	2,
					args		=	{		
								enableTracker		=	{
									type		=	"toggle",
									name		=	"Enable tracker",
									order		=  	1,
									desc		=	"Enables the Killing blow tracker frame.",						
									get			=	"EnableKBT",
									set			=	"ToggleEnableKBT",
									},
								enableLock		=	{
									type		=	"toggle",
									name		=	"Enable drag",
									order		=  	2,
									desc		=	"Enables the user to drag the frame around.",						
									get			=	"EnableKBTDrag",
									set			=	"ToggleEnableKBTDrag",
								},
								editBackground = {
									name 		= "Background file",
									desc 		= "Adjust background file of the tracker.",
									order 		= 6, width = "double",
									type 		= "select",
									values 		= Media:HashTable("background"),
									dialogControl = "LSM30_Background",
									get		    = function(info) return KillingBlowAnnouncer:GetTrackerBackground(info) end,
									set 		= function(info,key) KillingBlowAnnouncer:SetTrackerBackground(info,key) end,
								},
								editBorder = {
									name 		= "Border file",
									desc 		= "Adjust border file of the tracker.",
									order 		= 6, width = "double",
									type 		= "select",
									values 		= Media:HashTable("border"),
									dialogControl = "LSM30_Border",
									get		    = function(info) return KillingBlowAnnouncer:GetTrackerBorder(info) end,
									set 		= function(info,key) KillingBlowAnnouncer:SetTrackerBorder(info,key) end,
								},
								editFont = {
									name 		= "Font",
									desc 		= "Adjust the font settings.",
									order 		= 6, width = "double",
									type 		= "select",
									values 		= Media:HashTable("font"),
									dialogControl = "LSM30_Font",
									get		    = function(info) return KillingBlowAnnouncer:GetTrackerFont(info) end,
									set 		= function(info,key) KillingBlowAnnouncer:SetTrackerFont(info,key) end,
								},
							},
						},
			Options3= {
					name		=	"Killing blow announcer options",
					desc 		= 	"Options related to the killing blow message",
					type		=	"group",
					order		=	3,
					args		=	{		
								Options4= {
								name		=	"Killing blow message",
								desc 		= 	"Options related to the killing blow message",
								type		=	"group",
								order		=	3,
								args		=	{	
										enablingEdit		=	{
											type		=	"toggle",
											name		=	"Snap message frame",
											desc		=	"Snaps the killing blow message to the window for editing purposes. Disable this option when done editing.",						
											get			=	"EnableSnap",
											width		= 	"full",
											order		=	2,
											set			=	"ToggleEnableSnap",
										},
										editMsg = {
											type 		= "input",
											name 		= "Killing blow message",
											order 		= 3,
											width		= "double",
											desc 		= "The message that gets displayed when you make a killing blow",
											usage 		= "<Your message here>",
											get 		= "GetKillingMessage",
											set		    = "SetKillingMessage",
													},										
										editFont = {
											name 		= "Font",
											desc 		= "Adjust the font settings.",
											order 		= 6, width = "double",
											type 		= "select",
											values 		= Media:HashTable("font"),
											dialogControl = "LSM30_Font",
											get		    = function(info) return KillingBlowAnnouncer:GetFont(info) end,
											set 		= function(info,key) KillingBlowAnnouncer:SetFont(info,key) end,
													},									
										editFontOutline = {
											name 		= "Font Outline",
											desc 		= "Adjust the font outline.",
											order 		= 5, width = "double",
											type 	    = "select",
											get         = function(info) return KillingBlowAnnouncer:GetOutline(info) end,
											set         = function(info,key) KillingBlowAnnouncer:SetOutline(info,key)end,
											values      = {
															NONE = "None",
															OUTLINE = "Thin",
															THICKOUTLINE = "Thick",
														},
													},
										editColor		=	{
											name		=	"Color",
											desc		=	"Adjust the color of the message.",	
											order	    = 4,
											width       = "double",
											type        = "color", hasAlpha = false,
											get         = function(info) return KillingBlowAnnouncer:GetRed(info),KillingBlowAnnouncer:GetGreen(info),KillingBlowAnnouncer:GetBlue(info) end,
											set         = function(info, r, g, b) KillingBlowAnnouncer:SetRed(info,r) KillingBlowAnnouncer:SetGreen(info,g) KillingBlowAnnouncer:SetBlue(info,b) setColors() end,
													},
			
										editFontSize		=	{
											type		=	"range",
											name		=	"FontSize" ,
											min 		= 	0,
											max    		=   30,
											width    	=   "double",
											desc		=	"Adjust the font size. Default is 30.",	
											order		=	7,		
											get			=	"GetFontSize",
											set			=	"SetFontSize",												
													
														},
										editVisibleTime		=	{
											type		=	"range",
											name		=	"VisibleTime" ,
											min 		= 	0,
											max    		=   60,
											width    	=   "double",
											desc		=	"Adjust the time that the message is visible in seconds. Default is 3.",	
											order		=	8,		
											get			=	"GetVisibleTime",
											set			=	"SetVisibleTime",												
													
														},
										editFadeTime		=	{
											type		=	"range",
											name		=	"FadeTime" ,
											min 		= 	0,
											max    		=   20,
											width    	=   "double",
											desc		=	"Adjust the time that it takes for the message to fade from start to end in seconds. Default is 1.",	
											order		=	9,		
											get			=	"GetFadeTime",
											set			=	"SetFadeTime",												
													
														},								
											},
								},
								Options5= {
								name		=	"Killing blow image",
								desc 		= 	"Options related to the killing blow image",
								type		=	"group",
								order		=	4,
								args		=	{
									enableKBIDebug		=	{
											type		=	"toggle",
											name		=	"Start image loop",
											desc		=	"Loops the killing blow image to the window for editing purposes. Disable this option when done editing.",						
											get			=	"GetKBIDebug",
											width		= 	"full",
											order		=	2,
											set			=	"ToggleKBIDebug",
										},
									chooseImage = {
											name 		=	 "Image file",
											desc 		=	 "Pick which image you want announced on a killing blow. See addon description on curse for a guide on how to add custom images.",
											order 		=	 3, width = "double",
											type 		= 	"select",
											values 		= 	Media:HashTable("images"),
											dialogControl = "LSM30_Font",
											get		    =   function(info) return KillingBlowAnnouncer:GetKBIImage(info) end,
											set 		=   function(info,key) KillingBlowAnnouncer:SetKBIImage(info,key) end,
										},	
									editHeight		=	{
											type		=	"range",
											name		=	"Image height" ,
											min 		= 	0,
											max    		=   1000,
											width    	=   "double",
											desc		=	"Adjust the image height.",	
											order		=	5,		
											get			=	"GetKBIHeight",
											set			=	"SetKBIHeight",			
											
											},
									editWidth		=	{
											type		=	"range",
											name		=	"Image width" ,
											min 		= 	0,
											max    		=   1000,
											width    	=   "double",
											desc		=	"Adjust the image width.",	
											order		=	5,		
											get			=	"GetKBIWidth",
											set			=	"SetKBIWidth",			
											
											},		
									editFadeInTime		=	{
											type		=	"range",
											name		=	"FadeIn time" ,
											min 		= 	0,
											max    		=   2,
											width    	=   "double",
											desc		=	"Adjust the time it takes for the image to fade in. Default is 0,5.",	
											order		=	7,		
											get			=	"GetFadeInTime",
											set			=	"SetFadeInTime",			
											
											},
									editFadeOutTime		=	{
											type		=	"range",
											name		=	"FadeOut time" ,
											min 		= 	0,
											max    		=   2,
											width    	=   "double",
											desc		=	"Adjust the time it takes for the image to fade out. Default is 0,5.",	
											order		=	8,		
											get			=	"GetFadeOutTime",
											set			=	"SetFadeOutTime",			
											
											},		
									editEndDelay		=	{
											type		=	"range",
											name		=	"Image duration" ,
											min 		= 	0,
											max    		=   10,
											width    	=   "double",
											desc		=	"Adjust the time that the image is displayed after fadeIn ends. Default is 1.",	
											order		=	9,		
											get			=	"GetEndDelay",
											set			=	"SetEndDelay",			
											
											},												
									},
								},																
								enableKillingBlow		=	{
									type		=	"toggle",
									name		=	"Enable killing blow announcer",
									order		=  	1,
									desc		=	"Enables the Killing blow announcer frame.",	
									width		= 	"full",
									get			=	"EnableKB",
									set			=	"ToggleEnableKB",									
								},
								enableKillingBlowSound		=	{
									type		=	"toggle",
									name		=	"Enable sound file",
									order		=  	2,
									desc		=	"Enables playing of a sound file.",	
									get			=	"EnableKBSound",
									set			=	"ToggleEnableKBSound",									
								},
								editSound = {
											name 		= "Sound",
											desc 		= "Adjust the sound that gets played.",
											order 		= 2, width = "double",							
											type 		= "select",
											values 		= Media:HashTable("sound"),
											dialogControl = "LSM30_Sound",
											get		    = function(info) return KillingBlowAnnouncer:GetSound(info) end,
											set 		= function(info,key) KillingBlowAnnouncer:SetSound(info,key) end,
								},
								enableModus = {
									name 		= "Killing blow modus",
									desc 		= "Enable either message mode or image mode. Message mode will display a message in the middle of the screen. Image mode will display an image in the middle of the screen",
									order 		= 6, 
									type 		= "select",
									values 		=	{"Message mode",'Image mode'},
									style 		= "radio",
									get		    = function(info) return KillingBlowAnnouncer:GetModus(info) end,
									set 		= function(info,key) KillingBlowAnnouncer:SetModus(info,key) end,
								},


								
							},
						},
				
			},			
	
}


--create default db settings
--enableMSG = sets the printing of the chat message to true meaning when a player first logs in the option will be enabled
--enableKBT = sets "killing blow!" to true meaning when a player first logs in the option will be enabled
--message = sets the message that will be printed to chat using enableMSG to "default"
local defaults = {
    profile = {
	    --enable pvp only mode 
		enablePVP= true,
		--enable chat message
		enableMSG= true,
		--enable announce chat message
		enableMSGAnnounce= true,
		--enable killing blow tracker
		enableKBT= true,
		--enable killing blow announcer
		enableKB= true,
		--enable killing blow sound
		enableKBSound= true,
		--enable edit snap
		enableSnap = false,
		--enable killing blow tracker drag
		enableKBTDrag= false,
		
		prevSession = 0;
		chatChannel = "say",
		message = "And stay down!",
		messageAnnounce = "${player} killed ${enemy} of class ${class} in ${zone}",
		chatAnnounceChannel = "say",
		sound = "DF UI_GuildLevelUp",
		killingMessage = "KILLING BLOW!",
		trackerBackground = "Blizzard Dialog Background",
		trackerBorder	= "Blizzard Tooltip",
		fontSize = 30,
		visibleTime = 3,
		fadeTime = 1,
		trackerFont = "Friz Quadrata TT",
		font = "Friz Quadrata TT",
		outline = "OUTLINE",
		
		--0 = message mode
		--1 = image mode
		KB_modus = 1,
		
		KBI_fadeInTime = 0.5,
		KBI_fadeOutTime = 0.5,
		KBI_duration = 1,
		KBI_debug = false,
		KBI_image = "Interface\\AddOns\\Killing Blow Announcer\\Images\\imageYellow",
		KBI_height = 300,
		KBI_width = 300,
		
		red = 1,
		green = 1,
		blue = 0,
		minimap = {
				hide = false,	
				enableMinimapIcon = true,				
			}
			
    },
};
--create minimap icon data
local kbaLDB = LibStub("LibDataBroker-1.1"):NewDataObject("Killing blow announcer", {
	type = "data source",
	text = "Killing Blow Announcer",
	icon = "Interface\\Icons\\Trade_Archaeology_Orc_BloodText",
	OnClick = function() KillingBlowAnnouncer:KillingBlowAnnouncerSlash() end,
	OnTooltipShow = function(tooltip)
		tooltip:AddLine("|cffecf0f1Killing Blow Announcer|r\nClick to open");
	end
})

--create Libstub variable for minimap icon
local icon = LibStub("LibDBIcon-1.0")


--intitialize chatcommand(/kba) and dependencies
function KillingBlowAnnouncer:OnInitialize()
	KillingBlowAnnouncer:RegisterChatCommand("kba", "KillingBlowAnnouncerSlash")
	
	self.db = LibStub("AceDB-3.0"):New("kbaDB", defaults, "Default")	
	LibStub("AceConfig-3.0"):RegisterOptionsTable("KillingBlowAnnouncer", options)		
	self.KillingBlowAnnouncerOptions = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("KillingBlowAnnouncer", "KillingBlowAnnouncer")
	icon:Register("Killing blow announcer", kbaLDB, self.db.profile.minimap)
end;

--getters and setters for database values
function KillingBlowAnnouncer:GetEnableMinimapIcon(info)
	s = self.db.profile.minimap.enableMinimapIcon
	if(s == true) then
		icon:Show("Killing blow announcer")
	else 
		icon:Hide("Killing blow announcer")
	end

    return s;
end;

function KillingBlowAnnouncer:ToggleEnableMinimapIcon(info, value)
    self.db.profile.minimap.enableMinimapIcon = value;	
end;

function KillingBlowAnnouncer:EnableMSGAnnounce(info)
    return self.db.profile.enableMSGAnnounce;
end;

function KillingBlowAnnouncer:ToggleEnableMSGAnnounce(info, value)
    self.db.profile.enableMSGAnnounce = value;	
end;


function KillingBlowAnnouncer:GetAnnounceMessage(info)
    return self.db.profile.messageAnnounce;
end;

function KillingBlowAnnouncer:SetAnnounceMessage(info, value)
    self.db.profile.messageAnnounce = value;
end;

function KillingBlowAnnouncer:GetChatAnnounceChannel(info)
    return self.db.profile.chatAnnounceChannel;
end;

function KillingBlowAnnouncer:SetChatAnnounceChannel(info, value)
    self.db.profile.chatAnnounceChannel = value;
end;


function KillingBlowAnnouncer:GetMinimapStatus(info)
    return self.db.profile.minimap.hide;
end;

function KillingBlowAnnouncer:SetKBIImage(info, value)
    self.db.profile.KBI_image = value;	
	imageObj:SetTexture(value)
end;

function KillingBlowAnnouncer:GetKBIImage(info)
    return self.db.profile.KBI_image;
end;



function KillingBlowAnnouncer:SetKBIWidth(info, value)
    self.db.profile.KBI_width = value;	
	resizeKBIImage(value,KillingBlowAnnouncer:GetKBIHeight(info))
end;

function KillingBlowAnnouncer:GetKBIWidth(info)
    return self.db.profile.KBI_width;
end;

function KillingBlowAnnouncer:SetKBIHeight(info, value)
    self.db.profile.KBI_height = value;	
	resizeKBIImage(KillingBlowAnnouncer:GetKBIWidth(info),value)
end;

function KillingBlowAnnouncer:GetKBIHeight(info)
    return self.db.profile.KBI_height;
end;



function KillingBlowAnnouncer:ToggleKBIDebug(info, value)
	if(value == true) then
		imageAnimationIn:Stop();
		imageAnimationOut:Stop();
		fade()
	end
	
    self.db.profile.KBI_debug = value;	
end;

function KillingBlowAnnouncer:GetKBIDebug(info)
    return self.db.profile.KBI_debug;
end;


function KillingBlowAnnouncer:SetFadeInTime(info, value)
    self.db.profile.KBI_fadeInTime = value;	
end;

function KillingBlowAnnouncer:GetFadeInTime(info)
    return self.db.profile.KBI_fadeInTime;
end;

function KillingBlowAnnouncer:SetFadeOutTime(info, value)
    self.db.profile.KBI_fadeOutTime = value;	
end;

function KillingBlowAnnouncer:GetFadeOutTime(info)
    return self.db.profile.KBI_fadeOutTime;
end;

function KillingBlowAnnouncer:SetEndDelay(info, value)
    self.db.profile.KBI_duration = value;	
end;

function KillingBlowAnnouncer:GetEndDelay(info)
    return self.db.profile.KBI_duration;
end;


function KillingBlowAnnouncer:SetModus(info, value)
    self.db.profile.KB_modus = value;	
end;

function KillingBlowAnnouncer:GetModus(info)
    return self.db.profile.KB_modus;
end;

function KillingBlowAnnouncer:SetMinimapStatus(info, value)
    self.db.profile.minimap.hide = value;	
end;

function KillingBlowAnnouncer:EnablePVP(info)
    return self.db.profile.enablePVP;
end;

function KillingBlowAnnouncer:ToggleEnablePVP(info, value)
    self.db.profile.enablePVP = value;	
end;

function KillingBlowAnnouncer:EnableMSG(info)
    return self.db.profile.enableMSG;
end;

function KillingBlowAnnouncer:ToggleEnableMSG(info, value)
    self.db.profile.enableMSG = value;	
end;

function KillingBlowAnnouncer:GetChatChannel(info)
    return self.db.profile.chatChannel;
end;

function KillingBlowAnnouncer:SetChatChannel(info, value)
    self.db.profile.chatChannel = value;	
end;

function KillingBlowAnnouncer:EnableKBSound(info)
    return self.db.profile.enableKBSound;
end;

function KillingBlowAnnouncer:ToggleEnableKBSound(info, value)
    self.db.profile.enableKBSound = value;	
end;

function KillingBlowAnnouncer:EnableKB(info)
    return self.db.profile.enableKB;
end;

function KillingBlowAnnouncer:ToggleEnableKB(info, value)
    self.db.profile.enableKB = value;	
end;

function KillingBlowAnnouncer:GetVisibleTime(info)
    return self.db.profile.visibleTime;
end;

function KillingBlowAnnouncer:SetVisibleTime(info, value)	
    self.db.profile.visibleTime = value;	
	setTime()	
end;

function KillingBlowAnnouncer:GetFadeTime(info)
    return self.db.profile.fadeTime;
end;

function KillingBlowAnnouncer:SetFadeTime(info, value)	
    self.db.profile.fadeTime = value;	
	setTime();	
end;

function KillingBlowAnnouncer:GetTrackerBackground(info)
    return self.db.profile.trackerBackground;
end;

function KillingBlowAnnouncer:SetTrackerBackground(info, value)	
    self.db.profile.trackerBackground = value;	
	setBackdrop();
end;

function KillingBlowAnnouncer:GetTrackerBorder(info)
    return self.db.profile.trackerBorder;
end;

function KillingBlowAnnouncer:SetTrackerBorder(info, value)	
    self.db.profile.trackerBorder = value;	
	setBackdrop();
end;

function KillingBlowAnnouncer:GetFontSize(info)
    return self.db.profile.fontSize;
end;

function KillingBlowAnnouncer:SetFontSize(info, value)	
    self.db.profile.fontSize = value;	
	setFont();	
end;

function KillingBlowAnnouncer:GetFont(info)
    return self.db.profile.font;
end;

function KillingBlowAnnouncer:SetFont(info, value)	
    self.db.profile.font = value;	
	setFont();	
end;

function KillingBlowAnnouncer:GetTrackerFont(info)
    return self.db.profile.trackerFont;
end;

function KillingBlowAnnouncer:SetTrackerFont(info, value)	
    self.db.profile.trackerFont = value;	
	setTrackerFont();	
end;

function KillingBlowAnnouncer:GetSound(info)
    return self.db.profile.sound;
end;

function KillingBlowAnnouncer:SetSound(info, value)	
    self.db.profile.sound = value;	
end;

function KillingBlowAnnouncer:GetOutline(info)
    return self.db.profile.outline;
end;

function KillingBlowAnnouncer:SetOutline(info, value)	
    self.db.profile.outline = value;	
	setFont();	
end;

function KillingBlowAnnouncer:EnableSnap(info)
    return self.db.profile.enableSnap;
end;

function KillingBlowAnnouncer:ToggleEnableSnap(info, value)
    self.db.profile.enableSnap = value;	
	snapMessage();
end;

function KillingBlowAnnouncer:EnableKBTDrag(info)
    return self.db.profile.EnableKBTDrag;
end;

function KillingBlowAnnouncer:ToggleEnableKBTDrag(info, value)
    self.db.profile.EnableKBTDrag = value;
	lockKbtracker();
end;

function KillingBlowAnnouncer:EnableKBT(info)
    return self.db.profile.EnableKBT;
end;

function KillingBlowAnnouncer:ToggleEnableKBT(info, value)
    self.db.profile.EnableKBT = value;
	hideKbtracker();
end;

function KillingBlowAnnouncer:GetKillingMessage(info)
    return self.db.profile.killingMessage;
end;

function KillingBlowAnnouncer:SetKillingMessage(info, newValue)
    self.db.profile.killingMessage = newValue;
	setKillingMsg();
end;

function KillingBlowAnnouncer:GetMessage(info)
    return self.db.profile.message;
end;

function KillingBlowAnnouncer:SetMessage(info, newValue)
    self.db.profile.message = newValue;
end;

function KillingBlowAnnouncer:GetRed(info)
    return self.db.profile.red;
end;

function KillingBlowAnnouncer:SetRed(info, newValue)
    self.db.profile.red = newValue;
end;

function KillingBlowAnnouncer:GetGreen(info)
    return self.db.profile.green;
end;

function KillingBlowAnnouncer:SetGreen(info, newValue)
    self.db.profile.green = newValue;
end;

function KillingBlowAnnouncer:GetBlue(info)
    return self.db.profile.blue;
end;

function KillingBlowAnnouncer:SetBlue(info, newValue)
    self.db.profile.blue = newValue;
end;

function KillingBlowAnnouncer:GetPrevSession(info)
    return self.db.profile.prevSession;
end;

function KillingBlowAnnouncer:SetPrevSession(info, newValue)
    self.db.profile.prevSession = newValue;
end;


-- open ingame options menu when /kba gets called
function KillingBlowAnnouncer:KillingBlowAnnouncerSlash(input)

	InterfaceOptionsFrame_OpenToCategory("KillingBlowAnnouncer");
	InterfaceOptionsFrame_OpenToCategory("KillingBlowAnnouncer");
end;

-- create startup event when player logs in
local startUp = CreateFrame("Frame")
startUp:RegisterEvent("PLAYER_LOGIN");

--set kbs_tracker variables to zero
local kbs_session = 0;
local kbs_cZone = 0;
local kbs_pZone = 0;


--function that gets called when an event within startUp triggers.
startUp:SetScript("OnEvent", function(self, event, ...)
    --print startup message for addon
	print("|cffffff00Killing Blow Announcer|cff3498db v1.08|cffecf0f1 - type in '/kba' to open the options panel");
	
	--hide or show minimap icon
	KillingBlowAnnouncer:GetEnableMinimapIcon(info)
	
	--create message and image frames
	createFrames();
	
	--snap edit killing blow message to screen if enabled
	snapMessage();
		
	--display or hide the kbtracker
	hideKbtracker();
	
    --enable or disable drag on startup
	lockKbtracker();
	
	--set tracker backdrop
	setBackdrop();
	
	
	if(KillingBlowAnnouncer:GetPrevSession(info) == 0) then
		new = kbs_session + 1;
		old = KillingBlowAnnouncer:GetPrevSession(info) + 1;
		p = format("%.2f",(new- old)/ old  * 100)
	else
		p = format("%.2f",(kbs_session- KillingBlowAnnouncer:GetPrevSession(info))/ KillingBlowAnnouncer:GetPrevSession(info)  * 100)
	end
	
	p = tonumber(p)
	
	if(p < 0) then 
		zone = "|cffE2252D" .. p;
	elseif(p > 0)then
		zone = "|cff2ed689" .. p;
	else
		zone = "|cFFFFFFFF" .. p;
	end
	
	kbtrackerText:SetText("|cFFFFFFFF          Killing blow tracker\n"
							 .. "|cffffcc00Current zone:\n"
						     .. "Previous zone:\n\n" 
							 .. "Current session:\n"
							 .. "Previous session:" )
	kbtrackerTextVars:SetText("|cFFFFFFFF"..kbs_cZone .."\n"
						     .. kbs_pZone .."\n\n" 
							 .. kbs_session.."\n"
							 .. KillingBlowAnnouncer:GetPrevSession(info))	  					 
	kbtrackerTextProc:SetText("|cFFFFFFFF0%\n\n\n"..zone.."%\n")

	
	setTrackerFont();
end);

local checkKill = CreateFrame("Frame")
checkKill:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");

-- function for checking if a player gets a killing blow 
checkKill:SetScript("OnEvent", function(self, event, timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, ...)
	local spellID, spellName, spellSchool, amount, overkill
	local playerName = UnitName("player");
	local petName = UnitName("pet");
	
            --IF event = a kill that happens within party(yours or anyone else in your raid/party)
			if (subevent == "PARTY_KILL") 
			--AND if the source of the event is the player(meaning you) or your pet 
			and (sourceName == playerName or sourceName == petName)  
			--AND if the killed enemy is a player instead of an npc/monster etc
			and (destFlags == 66888  or KillingBlowAnnouncer:EnablePVP(info) == false) 
			--THEN add the message KILLING BLOW! to the messageframe, and update the kbs_tracker
			then	

				if(destFlags == 66888 and KillingBlowAnnouncer:EnableMSGAnnounce(info) == true)then
					
					local className, classId, raceName, raceId, gender, name, realm = GetPlayerInfoByGUID(destGUID)
					local mapID = GetCurrentMapAreaID()
						  SetMapToCurrentZone()
					local mapName = GetMapNameByID(GetCurrentMapAreaID())
					local className = className:lower();
					
					SendChatMessage((interp(KillingBlowAnnouncer:GetAnnounceMessage(info),{player = playerName,enemy = name,class = className,zone = mapName})),KillingBlowAnnouncer:GetChatAnnounceChannel(info)) 	
				end	
			
				--IF enableKB = true			
				if (KillingBlowAnnouncer:EnableKB(info) == true) 
				--THEN addMessage
				then
					if(KillingBlowAnnouncer:GetModus(info) == 1) then
						message:AddMessage(KillingBlowAnnouncer:GetKillingMessage(info),KillingBlowAnnouncer:GetRed(info),KillingBlowAnnouncer:GetGreen(info),KillingBlowAnnouncer:GetBlue(info))	
					elseif(KillingBlowAnnouncer:GetModus(info) == 2) then
						imageAnimationIn:Stop();
						imageAnimationOut:Stop();
						fade();
					end
				end
				
				--IF enableKBSound = true			
				if (KillingBlowAnnouncer:EnableKBSound(info) == true) 
				--THEN playsoundfile
				then
					PlaySoundFile(Media:Fetch("sound", KillingBlowAnnouncer:GetSound(info)), "Master");
				end
				
				--IF enableKBT = true
				if (KillingBlowAnnouncer:EnableKBT(info) == true) 
				--THEN update kbtracker
				then
					updateKbtracker();
				end
				
				--IF chat message is enabled(variable enableMSG needs to be true for this)
				if (KillingBlowAnnouncer:EnableMSG(info) == true) 
				--THEN get message from variable message and send it to the chat chat
				then
					SendChatMessage(KillingBlowAnnouncer:GetMessage(info),KillingBlowAnnouncer:GetChatChannel(info));
				end			
		end		
end);


	  -- Creating kbtracker frame	
	  local kbtracker = CreateFrame("Frame", "DragFrame2", UIParent)

	  --set frame to move on left mouse button
	  kbtracker:SetMovable(true)
	  kbtracker:EnableMouse(true)
	  kbtracker:RegisterForDrag("LeftButton")

	  --set default place for frame
      kbtracker:SetPoint("CENTER")
	  --95
	  kbtracker:SetSize(200,90)	

	  --create textframe within kbtracker
	  kbtrackerText =  kbtracker:CreateFontString("frametext" ,"ARTWORK","GameFontNormal");
	  kbtrackerTextVars =  kbtracker:CreateFontString("frametext" ,"ARTWORK","GameFontNormal");
	  kbtrackerTextProc =  kbtracker:CreateFontString("frametext" ,"ARTWORK","GameFontNormal");
							
	  --set position of text in frame
      kbtrackerText:SetPoint("TopLeft", kbtracker, "TopLeft", 5, -8)
	  kbtrackerTextVars:SetPoint("TopLeft", kbtracker, "TopLeft", 130, -22)
	  kbtrackerTextProc:SetPoint("TopLeft", kbtracker, "TopLeft", 160, -16)
							 
	  
	  --align text 
	  kbtrackerText:SetJustifyH("left")
	  kbtrackerTextVars:SetJustifyH("right")
	  kbtrackerTextProc:SetJustifyH("right")
 
 --lock or unlock kbtracker based on options
function lockKbtracker() 
	if (KillingBlowAnnouncer:EnableKBTDrag(info) == true) then
	  kbtracker:SetScript("OnDragStart", kbtracker.StartMoving)
	  kbtracker:SetScript("OnDragStop", kbtracker.StopMovingOrSizing)
	else
	  kbtracker:SetScript("OnDragStart", nil)
	  kbtracker:SetScript("OnDragStop", nil)
	end
end
 
-- function for updating the frame
function updateKbtracker()
	--get zone information
	local pvpType, isFFA, faction = GetZonePVPInfo();

	--increase kbs_cZone
	kbs_cZone = kbs_cZone + 1;
	
	--increase kbs_session
	kbs_session = kbs_session + 1;

	
	if(kbs_pZone == 0) then
		new = kbs_cZone + 1;
		old = kbs_pZone + 1;
		p = format("%.2f",(new- old)/ old  * 100)
	else
		p = format("%.2f",(kbs_cZone- kbs_pZone)/ kbs_pZone  * 100)
	end
	
	p = tonumber(p)
	
	if(p < 0) then 
		zone = "|cffE2252D" .. p;
	elseif(p > 0)then
		zone = "|cff2ed689" .. p;
	else
		zone = "|cFFFFFFFF" .. p;
	end

	
	if(KillingBlowAnnouncer:GetPrevSession(info) == 0) then
		new = kbs_session + 1;
		old = KillingBlowAnnouncer:GetPrevSession(info) + 1;
		s = format("%.2f",(new- old)/ old  * 100)
	else
		s = format("%.2f",(kbs_session- KillingBlowAnnouncer:GetPrevSession(info))/ KillingBlowAnnouncer:GetPrevSession(info)  * 100)
	end
	
	s = tonumber(s)
	
	if(s < 0) then 
		s = "|cffE2252D" .. s;
	elseif(s > 0)then
		s = "|cff2ed689" .. s;
	else
		s = "|cFFFFFFFF" .. s;
	end
	
	--update text on tracker
	  kbtrackerText:SetText("|cFFFFFFFF          Killing blow tracker\n"
							 .. "|cffffcc00Current zone:\n"
						     .. "Previous zone:\n\n" 
							 .. "Current session:\n"
							 .. "Previous session:" )
	  kbtrackerTextVars:SetText("|cFFFFFFFF"..kbs_cZone .."\n"
						     .. kbs_pZone .."\n\n" 
							 .. kbs_session.."\n"
							 .. KillingBlowAnnouncer:GetPrevSession(info))	  					 
	  kbtrackerTextProc:SetText(zone.."%\n\n\n"..s.."%\n")
	
end


--function for hiding kbtracker frame
function hideKbtracker()	
	--IF enableKBT = false then hide otherwise show kbtracker
	if (KillingBlowAnnouncer:EnableKBT(info) == false) then
			kbtracker:Hide();
	else 
			kbtracker:Show();
	end	
end;


--create a frame and register when player changes zones
--EXAMPLE from jade forest -> Kun lai = event occured
--EXAMPLE from out of bg -> in to bg = event occured
--EXAMPLE from in of bg -> out of bg = event occured
local resetTrackerVariable = CreateFrame("Frame") 
resetTrackerVariable:RegisterEvent("ZONE_CHANGED_NEW_AREA")


--on end of bg set kbs_bg variable to zero and update kbtracker text.
resetTrackerVariable:SetScript("OnEvent",function(self, event, addon)
	kbs_pZone = kbs_cZone;
	kbs_cZone = 0;
	 
	if(kbs_pZone == 0) then
		old = kbs_pZone + 1;
		new = kbs_cZone + 1;
		p = format("%.2f",(new- old)/ old  * 100)
	else
		p = format("%.2f",(kbs_cZone- kbs_pZone)/ kbs_pZone  * 100)
	end
	
	p = tonumber(p)
	
	if(p < 0) then 
		zone = "|cffE2252D" .. p;
	elseif(p > 0)then
		zone = "|cff2ed689" .. p;
	else
		zone = "|cFFFFFFFF" .. p;
	end
	 
	 if(KillingBlowAnnouncer:GetPrevSession(info) == 0) then
		new = kbs_session + 1;
		old = KillingBlowAnnouncer:GetPrevSession(info) + 1;
		s = format("%.2f",(new- old)/ old  * 100)
	else
		s = format("%.2f",(kbs_session- KillingBlowAnnouncer:GetPrevSession(info))/ KillingBlowAnnouncer:GetPrevSession(info)  * 100)
	end
	
	s = tonumber(s)
	
	if(s < 0) then 
		s = "|cffE2252D" .. s;
	elseif(s > 0)then
		s = "|cff2ed689" .. s;
	else
		s = "|cFFFFFFFF" .. s;
	end

	
	  --update text on tracker
	  kbtrackerText:SetText("|cFFFFFFFF          Killing blow tracker\n"
							 .. "|cffffcc00Current zone:\n"
						     .. "Previous zone:\n\n" 
							 .. "Current session:\n"
							 .. "Previous session:" )
	  kbtrackerTextVars:SetText("|cFFFFFFFF"..kbs_cZone .."\n"
						     .. kbs_pZone .."\n\n" 
							 .. kbs_session.."\n"
							 .. KillingBlowAnnouncer:GetPrevSession(info))	  					 
	  kbtrackerTextProc:SetText(zone.."%\n\n\n"..s.."%\n")
	  
end)

local playerLeave = CreateFrame("Frame") 
playerLeave:RegisterEvent("PLAYER_LOGOUT")

playerLeave:SetScript("OnEvent",function(self, event, addon)
	  KillingBlowAnnouncer:SetPrevSession(info, kbs_session)
end)


--Snap killing blow message frame to window when enabled and when disabled clear and set timevisible back to normal
function snapMessage()
	--EnableSnap is false then set back to database value else if edit mode is true then set time to 10000
	if (KillingBlowAnnouncer:EnableSnap(info) == false) then
			message:SetTimeVisible(KillingBlowAnnouncer:GetVisibleTime(info))
			message:Clear()				
	else 
			message:SetTimeVisible(10000)
			message:AddMessage(KillingBlowAnnouncer:GetKillingMessage(info),KillingBlowAnnouncer:GetRed(info),KillingBlowAnnouncer:GetGreen(info),KillingBlowAnnouncer:GetBlue(info))
	end	

end

--setters for changing the snap message to the changed values
--setFont when changed in options menu
function setFont()
	message:SetFont(Media:Fetch("font", KillingBlowAnnouncer:GetFont(info)), KillingBlowAnnouncer:GetFontSize(info), KillingBlowAnnouncer:GetOutline(info))
end

function setTrackerFont()
	kbtrackerText:SetFont(Media:Fetch("font", KillingBlowAnnouncer:GetTrackerFont(info)), 12, "OUTLINE")
	kbtrackerTextVars:SetFont(Media:Fetch("font", KillingBlowAnnouncer:GetTrackerFont(info)), 12, "OUTLINE")
	kbtrackerTextProc:SetFont(Media:Fetch("font", KillingBlowAnnouncer:GetTrackerFont(info)), 12, "OUTLINE")
	width = kbtrackerText:GetWidth() + kbtrackerTextVars:GetWidth() + kbtrackerTextProc:GetWidth()
	kbtracker:SetWidth(math.floor(width))
end

--setColors when changed in options menu
function setColors()
	if (KillingBlowAnnouncer:EnableSnap(info) == true) then
		message:Clear()		
		message:AddMessage(KillingBlowAnnouncer:GetKillingMessage(info),KillingBlowAnnouncer:GetRed(info),KillingBlowAnnouncer:GetGreen(info),KillingBlowAnnouncer:GetBlue(info))
	end
end

--setTime when changed in options menu
function setTime()
	if (KillingBlowAnnouncer:EnableSnap(info) == false) then
		message:SetTimeVisible(KillingBlowAnnouncer:GetVisibleTime(info))
		message:SetFadeDuration(KillingBlowAnnouncer:GetFadeTime(info))
	end
end

--setKillingMsg when changed in options menu
function setKillingMsg()
	if (KillingBlowAnnouncer:EnableSnap(info) == true) then
		message:Clear()		
		message:AddMessage(KillingBlowAnnouncer:GetKillingMessage(info),KillingBlowAnnouncer:GetRed(info),KillingBlowAnnouncer:GetGreen(info),KillingBlowAnnouncer:GetBlue(info))
	end
end

function setBackdrop()
	--setbackground and border for tracker
	backdrop = {
			bgFile = Media:Fetch("background", KillingBlowAnnouncer:GetTrackerBackground(info)), 
			edgeFile= Media:Fetch("border", KillingBlowAnnouncer:GetTrackerBorder(info)),
			tile = false,   
			tileSize = 32,  
			edgeSize = 10, 
			insets = {   
				left = 0,
				right = 0,
				top = 0,
				bottom = 0
			}
	}   
	kbtracker:SetBackdrop(backdrop);
end

function createFrames()
	--create killing blow message frame.
	message = CreateFrame("MessageFrame", "KBFrameM", UIParent)
	
	--set place to display message in the center
	message:SetPoint("LEFT")
	message:SetPoint("RIGHT")
	message:SetPoint("CENTER")	
	
	--set height of message
	message:SetHeight(30)	
	
	--set where message gets inserted into the frame
	message:SetInsertMode("TOP")

	--set layer at high(ATTENTION CHILD FRAMES ALWAYS GET INSERTED ABOVE THEIR PARENT)
	message:SetFrameStrata("HIGH")
	
	--set amount of seconds before message fades(3 seconds)
	message:SetTimeVisible(KillingBlowAnnouncer:GetVisibleTime(info))
	
	--set amount of seconds it takes for message to fade(1 second)
	message:SetFadeDuration(KillingBlowAnnouncer:GetFadeTime(info))
	
	--set message font,font-size,and flags
	--max font size 30
	--flags: 
	--MONOCHROME - Font is rendered without antialiasing
	--OUTLINE - Font is displayed with a black outline
	--THICKOUTLINE - Font is displayed with a thick black outline
	message:SetFont(Media:Fetch("font", KillingBlowAnnouncer:GetFont(info)), KillingBlowAnnouncer:GetFontSize(info), KillingBlowAnnouncer:GetOutline(info))

	image = CreateFrame("Frame", "KBFrameI", UIParent)

	--set image at the center
	image:SetPoint("CENTER",0,5)

	--set frame on high level	
	image:SetFrameStrata("HIGH")
	image:SetSize(KillingBlowAnnouncer:GetKBIWidth(info),KillingBlowAnnouncer:GetKBIHeight(info))

	--create image texture
	imageObj = image:CreateTexture()
	imageObj:SetAllPoints()
	imageObj:SetAlpha(-1)
	imageObj:SetTexture(KillingBlowAnnouncer:GetKBIImage(info))

	--hide image intially
	image:Hide()

	--create animation groups
	imageAnimationIn = imageObj:CreateAnimationGroup()
	imageAnimationOut = imageObj:CreateAnimationGroup()

	--crette alphaIn and Out 
	alphaIn = imageAnimationIn:CreateAnimation("Alpha")
	alphaOut = imageAnimationOut:CreateAnimation("Alpha")
	
end

--Method for fading the killing blow message in and out 
function fade()
	--set duration it takes to finish the fade in and fade out
	i = KillingBlowAnnouncer:GetFadeInTime(info)
	if(i == 0) then
		i = 0.1
	end
	
	o = KillingBlowAnnouncer:GetFadeOutTime(info)
	if(o == 0) then
		o = 0.1
	end
	
	alphaIn:SetDuration(i)
	alphaOut:SetDuration(o)

	--set delay for waiting when fadein ends
	alphaIn:SetEndDelay(KillingBlowAnnouncer:GetEndDelay(info))
	
	imageAnimationIn:SetScript("OnPlay", function(self)
		image:Show();
	end)

	alphaIn:SetScript("OnPlay", function(self)
		alphaIn:SetChange(1)
	end)
	
	alphaOut:SetScript("OnPlay", function(self)
		alphaOut:SetChange(-1)
	end)

	imageAnimationIn:SetScript("OnFinished", function(self)
		imageObj:SetAlpha(1)
		imageAnimationOut:Play();
	end)
	
	imageAnimationOut:SetScript("OnFinished", function(self)
		imageObj:SetAlpha(-1)
		image:Hide();
		
		if(KillingBlowAnnouncer:GetKBIDebug(info) == true) then
			fade();
		end
	end)
	
	imageAnimationIn:Play();
end

function resizeKBIImage(w,h)
	image:SetSize(w,h)
end

function interp(s, tab)
	return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
end

