Quantcast
-- for the menu stuff
local menuLib
local curDewdropParent
local _wasMoving = nil
local _state = 0
local _menuTarget =nil

menuLib = DewdropLib:GetInstance('1.0')
function HealWatch.LabelOnClick(arg1)
	if (arg1 == 'RightButton') then
		_menuTarget = this
		if (not menuLib:IsRegistered(HealWatchCastFrame)) then
			menuLib:Register(HealWatchCastFrame,'children',HealWatch.PropagateMenus)
		else
			menuLib:Open(HealWatchCastFrame,curDewdropParent)
		end
		return
	end
end

function HealWatch.PropagateMenus(level,value)
	if (level == 1) then
		local text = 'HealWatch v'..HealWatch.version
		-- add the title line first
		menuLib:AddLine('text',text,'isTitle',true)
		text = HealWatch.localisation.menu.TARGETOPTIONS
		menuLib:AddLine('text',text,'isTitle',true)
		if (_menuTarget.locked) then
			text = HealWatch.localisation.menu.DETACH
			menuLib:AddLine('text',text,'checked',_menuTarget.detached,'func',HealWatch.DetachToggle,'arg1',_menuTarget)
		end
		menuLib:AddLine()
		text = HealWatch.localisation.menu.DISPLAYOPTIONS
		menuLib:AddLine('text',text,'isTitle',true)
		-- show health?
		text = HealWatch.localisation.menu.SHOWHEALTH
		menuLib:AddLine('text',text,'checked',HealWatch.Options.showHealth,'func',HealWatch.ToggleOption,'arg1','showHealth')
		-- hide the background?
		text = HealWatch.localisation.menu.SHOWBACKGROUND
		menuLib:AddLine('text',text,'checked',HealWatch.Options.showBackground,'func',HealWatch.ToggleBackground)
		-- change the width
		text = HealWatch.localisation.menu.WIDTH
		menuLib:AddLine('text',text,'hasArrow',true,'hasSlider',true,'sliderTop','300','sliderBottom','100',
				'sliderValue',(HealWatch.Options.labelWidth-100)/200,'sliderFunc',HealWatch.SetLabelWidth)
		-- change the scale
		text = HealWatch.localisation.menu.SCALE
		menuLib:AddLine('text',text,'hasArrow',true,'hasSlider',true,'sliderTop','3','sliderBottom','0',
				'sliderValue',HealWatch.Options.scale/3,'sliderFunc',HealWatch.SetWindowScale)
		-- label growth direction
		text = HealWatch.localisation.menu.LABELGROWDIRECTION
	--	menuLib:AddLine('text',text,'hasArrow',true,'value','labels')
		-- do the max cast bars
		text = HealWatch.localisation.menu.CASTBARS
		menuLib:AddLine('text',text,'hasArrow',true,'hasSlider',true,'sliderTop','40','sliderBottom','1',
				'sliderValue',HealWatch.Options.maxCastBars/40,'sliderFunc',HealWatch.SetMaxCastBars)
		-- grow up or down?
		text = HealWatch.localisation.menu.GROWUP
	--	menuLib:AddLine('text',text,'isRadio',true,'checked',(HealWatch.Options.FrameAttachPoint == 'BOTTOM'),'func',HealWatch.ToggleGrowDirection,'arg1','up')
		text = HealWatch.localisation.menu.GROWDOWN
	--	menuLib:AddLine('text',text,'isRadio',true,'checked',(HealWatch.Options.FrameAttachPoint == 'TOP'),'func',HealWatch.ToggleGrowDirection,'arg1','down')
		-- filtering options
		text = HealWatch.localisation.menu.FILTEROPTIONS
		menuLib:AddLine('text',text,'isTitle',true)
		-- show all heals
		text = HealWatch.localisation.menu.SHOWALLHEALS
		menuLib:AddLine('text',text,'checked',HealWatch.Options.showAllHeals,'func',HealWatch.ToggleOption,'arg1','showAllHeals')
		-- show my heals
		text = HealWatch.localisation.menu.SHOWMYHEALS
		menuLib:AddLine('text',text,'checked',HealWatch.Options.showMyHeals,'func',HealWatch.ToggleOption,'arg1','showMyHeals')
		text = HealWatch.localisation.menu.COLORMYHEALS
		menuLib:AddLine('text',text,'checked',HealWatch.Options.colorMyHeals,'func',HealWatch.ToggleOption,'arg1','colorMyHeals')
--		text = HealWatch.localisation.menu.STICKYLABEL
--		menuLib:AddLine('text',text,'checked',HealWatch.Options.stickTarget,'func',HealWatch.ToggleOption,'arg1','stickTarget')
		-- lock the location of HealWatch
		-- misc options
		text = HealWatch.localisation.menu.MISCOPTIONS
		menuLib:AddLine('text',text,'isTitle',true)
		-- coms enabled?
		text = HealWatch.localisation.menu.COMS
		menuLib:AddLine('text',text,'hasArrow',true,'value','coms')
		-- add the enable/disable check next
		text = HealWatch.localisation.menu.ENABLED
		menuLib:AddLine('text',text,'checked',HealWatch.Options.enabled,'func',HealWatch.ToggleOption,'arg1','enabled')
		text = HealWatch.localisation.menu.CLOSE
		menuLib:AddLine('text',text,'closeWhenClicked',true)
	elseif (level == 2) then
		if (value == 'coms') then
			menuLib:AddLine('text',HealWatch.localisation.menu.COMSENABLED,'isTitle',true,
			'checked',HealWatch.enableComs,'func',HealWatch.EnableComsModule)
			text = HealWatch.localisation.menu.COMSSEND
			menuLib:AddLine('text',text,'hasArrow',true,'value','Send')
			text = HealWatch.localisation.menu.COMSRECV
			menuLib:AddLine('text',text,'hasArrow',true,'value','receive')
		elseif (value == 'labels') then
			text = HealWatch.localisation.menu.LABELSGROWUP
	--		menuLib:AddLine('text',text,'isRadio',true,'func',HealWatch.ChangeLabelDirection,'arg1',1,'checked',(HealWatch.Options.LabelGrowDirection == 1))
			text = HealWatch.localisation.menu.LABELSGROWDOWN
	--		menuLib:AddLine('text',text,'isRadio',true,'func',HealWatch.ChangeLabelDirection,'arg1',2,'checked',(HealWatch.Options.LabelGrowDirection == 2))
			text = HealWatch.localisation.menu.LABELSGROWRIGHT
	--		menuLib:AddLine('text',text,'isRadio',true,'func',HealWatch.ChangeLabelDirection,'arg1',3,'checked',(HealWatch.Options.LabelGrowDirection == 3))
			text = HealWatch.localisation.menu.LABELSGROWLEFT
	--		menuLib:AddLine('text',text,'isRadio',true,'func',HealWatch.ChangeLabelDirection,'arg1',4,'checked',(HealWatch.Options.LabelGrowDirection == 4))
		end
	elseif (level == 3) then
		if (value == 'Send') then
			local comModule
			menuLib:AddLine('text',HealWatch.localisation.menu.COMSSEND,'isTitle',true)
			for i=1,table.getn(HealWatch.comModules) do
				comModule = HealWatch.comModules[i]
				menuLib:AddLine('text',comModule.menuLine,'isRadio',true,
				'checked',HealWatch.sendModule == comModule,
				'func',HealWatch.EnableComsModule,'arg1',comModule,'arg3',true)
			end
		elseif (value == 'receive') then
			local comModule
			menuLib:AddLine('text',HealWatch.localisation.menu.COMSLISTEN,'isTitle',true)
			for i=1,table.getn(HealWatch.comModules) do
				comModule = HealWatch.comModules[i]
				menuLib:AddLine('text',comModule.menuLine,
				'checked',comModule.enabled,
				'func',HealWatch.EnableComsModule,'arg1',comModule,'arg2',not comModule.enabled)
			end
		end
	end
end

function HealWatch.ToggleBackground()
	HealWatch.Options.showBackground = not HealWatch.Options.showBackground
	local c = {HealWatchCastFrame:GetBackdropColor()}
	local b = {HealWatchCastFrame:GetBackdropBorderColor()}
	local a = 0
	if (HealWatch.Options.showBackground) then a = 1 end
	HealWatchCastFrame:SetBackdropColor(c[1],c[2],c[3],a)
	HealWatchCastFrame:SetBackdropBorderColor(b[1],b[2],b[3],a)
end

function HealWatch.ToggleOption(option)
	HealWatch.Options[option] = not HealWatch.Options[option]
end

function HealWatch.ChangeLabelDirection(direction)
	HealWatch.Options.LabelGrowDirection = direction
	if (direction == 1) then
		HealWatch.ToggleGrowDirection('up')
	elseif (direction == 2) then
		HealWatch.ToggleGrowDirection('down')
	end
end

function HealWatch.ToggleGrowDirection(direction)
	if (direction == 'up') then
		HealWatch.Options.FrameAttachPoint = 'BOTTOM'
		HealWatch.Options.ParentAttachPoint = 'TOP'
		HealWatch.Options.FramePrefix = 1
	elseif (direction == 'down') then
		HealWatch.Options.FrameAttachPoint = 'TOP'
		HealWatch.Options.ParentAttachPoint = 'BOTTOM'
		HealWatch.Options.FramePrefix = -1
	end
	HealWatch.ResetBars()
end

function HealWatch.SetMaxCastBars(value)
	value = math.floor(40*value + 0.5)
	value = max(value,1)
	HealWatch.Options.maxCastBars = value
	return value
end

function HealWatch.SetLabelWidth(value)
	value = math.floor(200*value + 0.5)+100
	value = max(value,100)
	value = min(value,300)
	HealWatch.Options.labelWidth = value
	HealWatch.UpdateWidths()
	HealWatchLabelHeader:SetWidth(value)
	HealWatchCastFrame:SetWidth(value+6)
	HealWatch.UpdateBarWidths(value)
	return value
end

function HealWatch.SetWindowScale(value)
	value = math.floor(value*30+0.5)/10
	value = math.max(math.min(value,3),0.1)
	HealWatch.Options.scale = value
	HealWatchCastFrame:SetScale(value)
	return value
end

function HealWatch.DetachToggle(frame)
	if (frame.detached) then
		HealWatch.AttachFrame(frame)
	else
		HealWatch.DetachFrame(frame)
	end
end

function HealWatch.EnableComsModule(comMod,listen,send)
	if (not comMod) then
		HealWatch.enableComs = not HealWatch.enableComs
		if (HealWatch.enableComs and HealWatch.EnableComs) then
			HealWatch.EnableComs()
		elseif (HealWatch.DisableComs and not HealWatch.enableComs) then
			HealWatch.DisableComs()
		end
	else
		if (comMod ~= HealWatch.sendModule and send) then
			HealWatch.sendModule = comMod
			HealWatch.customSend = comMod.send
		else
			comMod.enabled = listen
		end
	end
end