PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/blizzard/watchframe.lua

http://github.com/Asphyxia/Tukui
Lua | 108 lines | 90 code | 11 blank | 7 comment | 11 complexity | 529c5bc697ff0ab2733b8ed130fc6549 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2
  3local TukuiWatchFrame = CreateFrame("Frame", "TukuiWatchFrame", UIParent)
  4TukuiWatchFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  5
  6-- to be compatible with blizzard option
  7local wideFrame = GetCVar("watchFrameWidth")
  8
  9-- create our moving area
 10local TukuiWatchFrameAnchor = CreateFrame("Button", "TukuiWatchFrameAnchor", UIParent)
 11TukuiWatchFrameAnchor:SetFrameStrata("HIGH")
 12TukuiWatchFrameAnchor:SetFrameLevel(20)
 13TukuiWatchFrameAnchor:SetHeight(20)
 14TukuiWatchFrameAnchor:SetClampedToScreen(true)
 15TukuiWatchFrameAnchor:SetMovable(true)
 16TukuiWatchFrameAnchor:EnableMouse(false)
 17TukuiWatchFrameAnchor:SetTemplate("Default")
 18TukuiWatchFrameAnchor:SetBackdropBorderColor(0,0,0,0)
 19TukuiWatchFrameAnchor:SetBackdropColor(0,0,0,0)
 20TukuiWatchFrameAnchor.text = T.SetFontString(TukuiWatchFrameAnchor, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 21TukuiWatchFrameAnchor.text:SetPoint("CENTER")
 22TukuiWatchFrameAnchor.text:SetText(L.move_watchframe)
 23TukuiWatchFrameAnchor.text:Hide()
 24
 25-- set default position according to how many right bars we have
 26TukuiWatchFrameAnchor:Point("TOPLEFT", UIParent, 4, -110)
 27
 28-- width of the watchframe according to our Blizzard cVar.
 29if wideFrame == "1" then
 30	TukuiWatchFrame:SetWidth(350)
 31	TukuiWatchFrameAnchor:SetWidth(350)
 32else
 33	TukuiWatchFrame:SetWidth(250)
 34	TukuiWatchFrameAnchor:SetWidth(250)
 35end
 36
 37local screenheight = T.getscreenheight
 38TukuiWatchFrame:SetParent(TukuiWatchFrameAnchor)
 39TukuiWatchFrame:SetHeight(screenheight / 1.6)
 40TukuiWatchFrame:ClearAllPoints()
 41TukuiWatchFrame:SetPoint("TOP")
 42
 43local function init()
 44	TukuiWatchFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
 45	TukuiWatchFrame:RegisterEvent("CVAR_UPDATE")
 46	TukuiWatchFrame:SetScript("OnEvent", function(_,_,cvar,value)
 47		if cvar == "WATCH_FRAME_WIDTH_TEXT" then
 48			if not WatchFrame.userCollapsed then
 49				if value == "1" then
 50					TukuiWatchFrame:SetWidth(350)
 51					TukuiWatchFrameAnchor:SetWidth(350)
 52				else
 53					TukuiWatchFrame:SetWidth(250)
 54					TukuiWatchFrameAnchor:SetWidth(250)
 55				end
 56			end
 57			wideFrame = value
 58		end
 59	end)
 60end
 61
 62local function setup()	
 63	WatchFrame:SetParent(TukuiWatchFrame)
 64	WatchFrame:SetFrameStrata("MEDIUM")
 65	WatchFrame:SetFrameLevel(3)
 66	WatchFrame:SetClampedToScreen(false)
 67	WatchFrame:ClearAllPoints()
 68	WatchFrame.ClearAllPoints = function() end
 69	WatchFrame:SetPoint("TOPLEFT", 32,-2.5)
 70	WatchFrame:SetPoint("BOTTOMRIGHT", 4,0)
 71	WatchFrame.SetPoint = T.dummy
 72
 73	WatchFrameTitle:SetParent(TukuiWatchFrame)
 74	WatchFrameCollapseExpandButton:SetParent(TukuiWatchFrame)
 75	WatchFrameCollapseExpandButton:SetFrameStrata(WatchFrameHeader:GetFrameStrata())
 76	WatchFrameCollapseExpandButton:SetFrameLevel(WatchFrameHeader:GetFrameLevel() + 1)
 77	WatchFrameCollapseExpandButton:SetNormalTexture("")
 78	WatchFrameCollapseExpandButton:SetPushedTexture("")
 79	WatchFrameCollapseExpandButton:SetHighlightTexture("")
 80	WatchFrameCollapseExpandButton:SetTemplate("Default")
 81	WatchFrameCollapseExpandButton:FontString("text", C.media.font, 12)
 82	WatchFrameCollapseExpandButton.text:SetText("X")
 83	WatchFrameCollapseExpandButton.text:Point("CENTER", 1, 0)
 84	WatchFrameCollapseExpandButton:HookScript("OnClick", function(self) 
 85		if WatchFrame.collapsed then 
 86			self.text:SetText("V") 
 87		else 
 88			self.text:SetText("X")
 89		end 
 90	end)
 91	WatchFrameTitle:Kill()
 92end
 93
 94------------------------------------------------------------------------
 95-- Execute setup after we enter world
 96------------------------------------------------------------------------
 97
 98local f = CreateFrame("Frame")
 99f:Hide()
100f.elapsed = 0
101f:SetScript("OnUpdate", function(self, elapsed)
102	f.elapsed = f.elapsed + elapsed
103	if f.elapsed > .5 then
104		setup()
105		f:Hide()
106	end
107end)
108TukuiWatchFrame:SetScript("OnEvent", function() if not IsAddOnLoaded("Who Framed Watcher Wabbit") or not IsAddOnLoaded("Fux") then init() f:Show() end end)