--[[ FuBar_LuckyCharms2Fu - FuBar support for LuckyCharms2 ]]--

local VERSION = tonumber(("$Revision: 2000 $"):match("%d+"))

LuckyCharms2Fu = AceLibrary("AceAddon-2.0"):new("AceDB-2.0", "AceEvent-2.0", "AceConsole-2.0", "FuBarPlugin-2.0")
local LuckyCharms2Fu, self = LuckyCharms2Fu, LuckyCharms2Fu
LuckyCharms2Fu.version = "r" .. VERSION;
LuckyCharms2Fu.revision = VERSION
LuckyCharms2Fu.date = ("$Date: 2007-08-11 00:00:00 -0600 (Sat, 11 Aug 2007) $"):match("%d%d%d%d%-%d%d%-%d%d")
LuckyCharms2Fu.hasIcon = "Interface\\AddOns\\LuckyCharms2\\images\\charm8.tga"
LuckyCharms2Fu.hasNoText = true
LuckyCharms2Fu.hasNoColor = true
LuckyCharms2Fu.hideWithoutStandby = true
LuckyCharms2Fu.cannotDetachTooltip = true
LuckyCharms2Fu.independentProfile = false
LuckyCharms2Fu.blizzardTooltip = true

LuckyCharms2Fu:RegisterDB("LuckyCharms2FuDB")

local L = AceLibrary("AceLocale-2.2"):new("FuBar_LuckyCharms2Fu")

function LuckyCharms2Fu:OnEnable()
   self.LuckyCharms2Enabled = select(4, GetAddOnInfo('LuckyCharms2'))
   self.wereButtonTooltipsShown = false
   self.wasUnlocked = false
   self.globalScale = 1
   self.globalAlpha = 1
end

function LuckyCharms2Fu:OnClick()
   local shift, ctrl, alt = IsShiftKeyDown(), IsControlKeyDown(), IsAltKeyDown()
   if not shift and not ctrl and not alt then
   		if not self.LuckyCharms2Enabled then
         return
      end
      LuckyCharms:ToggleCharmBar()
   elseif shift and not ctrl and not alt then
   		LuckyCharms.ToggleLock()
   elseif not shift and ctrl and not alt then
  LuckyCharms:ToggleToolTips()
   elseif not shift and not ctrl and alt then
   		LuckyCharms:ToggleConfig()
   elseif shift and ctrl and not alt then
   		LuckyCharms:ToggleAncCharmBar()
   end
   self:UpdateTooltip()
end

function LuckyCharms2Fu:OnTooltipUpdate()
   GameTooltip:AddLine("LuckyCharms2Fu")
   GameTooltip:AddLine(" ")
   if (LuckyCharms:BarStatus() == "hide") then
	   GameTooltip:AddDoubleLine(L["CharmBar Status:"], L["Hidden"] , 1, 1, 0, 1, 1, 1)
	 elseif (LuckyCharms:BarStatus() == "show") then
	 		GameTooltip:AddDoubleLine(L["CharmBar Status:"], L["Shown"] , 1, 1, 0, 1, 1, 1)
	 else
	 		GameTooltip:AddDoubleLine(L["CharmBar Status:"], L["Auto"] , 1, 1, 0, 1, 1, 1)
	 end
   if (LuckyCharms:AnchorBarStatus() == "hide") then
	   GameTooltip:AddDoubleLine(L["Anchor Status:"], L["Hidden"] , 1, 1, 0, 1, 1, 1)
	 elseif (LuckyCharms:AnchorBarStatus() == "show") then
	 		GameTooltip:AddDoubleLine(L["Anchor Status:"], L["Shown"] , 1, 1, 0, 1, 1, 1)
	 else
	 		GameTooltip:AddDoubleLine(L["Anchor Status:"], L["Auto"] , 1, 1, 0, 1, 1, 1)
	 end
   if (LuckyCharms.IsLocked() == 1) then
   		GameTooltip:AddDoubleLine(L["Locked:"], L["Yes"], 1, 1, 0, 1, 1, 1)
   else
   		GameTooltip:AddDoubleLine(L["Locked:"], L["No"], 1, 1, 0, 1, 1, 1)
   end
   if (LuckyCharms:ShowingToolTips() == 1) then
   		GameTooltip:AddDoubleLine(L["Tooltips Shown:"], L["Yes"], 1, 1, 0, 1, 1, 1)
   else
   		GameTooltip:AddDoubleLine(L["Tooltips Shown:"], L["No"], 1, 1, 0, 1, 1, 1)
   end
   GameTooltip:AddLine(" ")
   GameTooltip:AddLine(L["Click: |cFFFFFFFFToggle CharmBar|r"], 0.2, 1, 0.2)
   GameTooltip:AddLine(L["Ctl + Shift + Click: |cFFFFFFFFToggle Anchor|r"], 0.2, 1, 0.2)
   if (LuckyCharms:ShowingToolTips() == 1) then
   		GameTooltip:AddLine(L["Ctl + Click: |cFFFFFFFFHide Tooltips|r"], 0.2, 1, 0.2)
   else
   		GameTooltip:AddLine(L["Ctl + Click: |cFFFFFFFFShow Tooltips|r"], 0.2, 1, 0.2)
   end
   if (LuckyCharms.IsLocked() == 1) then
      GameTooltip:AddLine(L["Shift + Click: |cFFFFFFFFUnlock CharmBar|r"], 0.2, 1, 0.2)
   else
      GameTooltip:AddLine(L["Shift + Click: |cFFFFFFFFLock CharmBar|r"], 0.2, 1, 0.2)
   end
   GameTooltip:AddLine(L["Alt + Click: |cFFFFFFFFOpen Configuration|r"], 0.2, 1, 0.2)
end

function self:GlobalScale()
   return self.globalScale
end

function self:GlobalAlpha()
   return self.globalAlpha
end

function self:Noop(...)
   return 0
end

LuckyCharms2Fu.OnMenuRequest = {
   type = 'group',
   handler = LuckyCharms2Fu,
   args = {
      globalScale = {
         order = 33,
         name = L["Scale"],
         desc = L["Controls the scale of LuckyCharms2."],
         type = 'range',
         min = 0.5,
         max = 3.0,
         step = 0.1,
         isPercent = true,
         get = (function() return LuckyCharms:RetScale() end) or "Noop",
         set = (function(v) LuckyCharms:ModScale(v) end) or "Noop",
      },
      globalAlpha = {
         order = 37,
         name = L["Opacity"],
         desc = L["Controls the opacity of LuckyCharms2."],
         type = 'range',
         min = 0,
         max = 1,
         step = 0.1,
         isPercent = true,
         get = (function() return LuckyCharms:RetAlpha() end) or "Noop",
         set = (function(v) LuckyCharms:ModAlpha(v) end) or "Noop",
      },
      addConfig = {
      	order = 40,
      	name = L["Configure"],
      	desc = L["Additional Configuration of LuckyCharms2"],
      	type = 'group',
      	args = {
      		cbarPos = {
      			order = 10,
      			name = L["Position"],
      			desc = L["Position of the CharmBar related to the Anchor"],
      			type = 'group',
      			args = {
      				cbarTop = {
      					order = 10,
      					name = L["Top"],
      					desc = L["Makes the CharmBar Verticle and aligned at the Top of the Anchor."],
      					type = 'toggle',
      					get = (function(v) return LuckyCharms.RetBarPos("top") end) or "Noop",
                set = (function(v) LuckyCharms.BarAnchor("top") end) or "Noop",
      				},
      				cbarBottom = {
      					order = 20,
      					name = L["Bottom"],
      					desc = L["Makes the CharmBar Verticle and aligned at the Bottom of the Anchor."],
      					type = 'toggle',
      					get = (function(v) return LuckyCharms.RetBarPos("bottom") end) or "Noop",
                set = (function(v) LuckyCharms.BarAnchor("bottom") end) or "Noop",
      				},
      				cbarLeft = {
      					order = 30,
      					name = L["Left"],
      					desc = L["Makes the CharmBar Horizontal and aligned at the Left of the Anchor."],
      					type = 'toggle',
      					get = (function(v) return LuckyCharms.RetBarPos("left") end) or "Noop",
                set = (function(v) LuckyCharms.BarAnchor("left") end) or "Noop",
      				},
      				cbarRight = {
      					order = 40,
      					name = L["Right"],
      					desc = L["Makes the CharmBar Horizontal and aligned at the Right of the Anchor."],
      					type = 'toggle',
      					get = (function(v) return LuckyCharms.RetBarPos("right") end) or "Noop",
                set = (function(v) LuckyCharms.BarAnchor("right") end) or "Noop",
      				},
      			}
      		},
      	}
      },
   }
}
