PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 32ms app.codeStats 0ms

/Tukui/core/movers.lua

http://github.com/Asphyxia/Tukui
Lua | 172 lines | 152 code | 15 blank | 5 comment | 53 complexity | 33898ec0cbf0ea0ae22168979eefc092 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2
  3-- all the frame we want to move
  4-- all our frames that we want being movable.
  5-- Credits to Sapz for Filger movers
  6
  7T.MoverFrames = {
  8	TukuiMinimap,
  9	TukuiTooltipAnchor,
 10	TukuiPlayerBuffs,
 11	TukuiPlayerDebuffs,
 12	TukuiShiftBar,
 13	TukuiRollAnchor,
 14	TukuiAchievementHolder,
 15	TukuiWatchFrameAnchor,
 16	TukuiGMFrameAnchor,
 17	TukuiVehicleAnchor,
 18	FilgerPlayerBuffs,
 19	FilgerPlayerDebuffs,
 20	FilgerPlayerProccs,
 21	FilgerPlayerHealBuffs,
 22	FilgerTargetDebuffs,
 23	FilgerTargetHeals,
 24	FilgerPvPBuffs,
 25	FilgerWLBuffs,
 26	FilgerDebuffBars,
 27	FilgerCDBars,
 28}
 29
 30-- used to exec various code if we enable or disable moving
 31local function exec(self, enable)
 32
 33	if self == TukuiGMFrameAnchor or self == FilgerCDBars or self == FilgerDebuffBars or self == FilgerWLBuffs or self == FilgerPvPBuffs or self == FilgerTargetHeals or self == FilgerTargetDebuffs or self == FilgerPlayerBuffs or self == FilgerPlayerDebuffs or self == FilgerPlayerProccs or self == FilgerPlayerHealBuffs then
 34		if enable then
 35			self:Show()
 36		else
 37			self:Hide()
 38		end
 39	end
 40	
 41	if self == TukuiMinimap then
 42		if enable then 
 43			Minimap:Hide()
 44			self:SetBackdropBorderColor(1,0,0,1)
 45		else 
 46			Minimap:Show()
 47			self:SetBackdropBorderColor(unpack(C.media.bordercolor))
 48		end
 49	end
 50	
 51	if self == TukuiPlayerBuffs or self == TukuiPlayerDebuffs then
 52		if enable then
 53			self:SetBackdropColor(unpack(C.media.backdropcolor))
 54			self:SetBackdropBorderColor(1,0,0,1)	
 55		else
 56			local position = self:GetPoint()			
 57			if position:match("TOPLEFT") or position:match("BOTTOMLEFT") or position:match("BOTTOMRIGHT") or position:match("TOPRIGHT") then
 58				self:SetAttribute("point", position)
 59			end
 60			if position:match("LEFT") then
 61				self:SetAttribute("xOffset", 36)
 62			else
 63				self:SetAttribute("xOffset", -36)
 64			end
 65			if position:match("BOTTOM") then
 66				self:SetAttribute("wrapYOffset", 68)
 67			else
 68				self:SetAttribute("wrapYOffset", -68)
 69			end
 70			self:SetBackdropColor(0,0,0,0)
 71			self:SetBackdropBorderColor(0,0,0,0)
 72		end
 73	end
 74	
 75	if self == TukuiTooltipAnchor or self == TukuiRollAnchor or self == TukuiAchievementHolder or self == TukuiVehicleAnchor then
 76		if enable then
 77			self:SetAlpha(1)
 78		else
 79			self:SetAlpha(0)
 80			if self == TukuiTooltipAnchor then 
 81				local position = TukuiTooltipAnchor:GetPoint()
 82				local healthBar = GameTooltipStatusBar
 83				if position:match("TOP") then
 84					healthBar:ClearAllPoints()
 85					healthBar:Point("TOPLEFT", healthBar:GetParent(), "BOTTOMLEFT", 2, -5)
 86					healthBar:Point("TOPRIGHT", healthBar:GetParent(), "BOTTOMRIGHT", -2, -5)
 87					if healthBar.text then healthBar.text:Point("CENTER", healthBar, 0, -6) end
 88				else
 89					healthBar:ClearAllPoints()
 90					healthBar:Point("BOTTOMLEFT", healthBar:GetParent(), "TOPLEFT", 2, 5)
 91					healthBar:Point("BOTTOMRIGHT", healthBar:GetParent(), "TOPRIGHT", -2, 5)
 92					if healthBar.text then healthBar.text:Point("CENTER", healthBar, 0, 6) end			
 93				end
 94			end
 95		end		
 96	end
 97	
 98	if self == TukuiWatchFrameAnchor then
 99		if enable then
100			TukuiWatchFrameAnchor:SetBackdropBorderColor(1,0,0,1)
101			TukuiWatchFrameAnchor:SetBackdropColor(unpack(C.media.backdropcolor))		
102		else
103			TukuiWatchFrameAnchor:SetBackdropBorderColor(0,0,0,0)
104			TukuiWatchFrameAnchor:SetBackdropColor(0,0,0,0)		
105		end
106	end
107	
108	if self == TukuiShiftBar then
109		if enable then
110			TukuiShapeShiftHolder:SetAlpha(1)
111		else
112			TukuiShapeShiftHolder:SetAlpha(0)
113		end
114	end
115end
116
117local enable = true
118local origa1, origf, origa2, origx, origy
119
120local function moving()
121	-- don't allow moving while in combat
122	if InCombatLockdown() then print(ERR_NOT_IN_COMBAT) return end
123	
124	for i = 1, getn(T.MoverFrames) do
125		if T.MoverFrames[i] then		
126			if enable then			
127				T.MoverFrames[i]:EnableMouse(true)
128				T.MoverFrames[i]:RegisterForDrag("LeftButton", "RightButton")
129				T.MoverFrames[i]:SetScript("OnDragStart", function(self) 
130					origa1, origf, origa2, origx, origy = T.MoverFrames[i]:GetPoint() 
131					self.moving = true 
132					self:SetUserPlaced(true) 
133					self:StartMoving() 
134				end)			
135				T.MoverFrames[i]:SetScript("OnDragStop", function(self) 
136					self.moving = false 
137					self:StopMovingOrSizing() 
138				end)			
139				exec(T.MoverFrames[i], enable)			
140				if T.MoverFrames[i].text then 
141					T.MoverFrames[i].text:Show() 
142				end
143			else			
144				T.MoverFrames[i]:EnableMouse(false)
145				if T.MoverFrames[i].moving == true then
146					T.MoverFrames[i]:StopMovingOrSizing()
147					T.MoverFrames[i]:ClearAllPoints()
148					T.MoverFrames[i]:SetPoint(origa1, origf, origa2, origx, origy)
149				end
150				exec(T.MoverFrames[i], enable)
151				if T.MoverFrames[i].text then T.MoverFrames[i].text:Hide() end
152				T.MoverFrames[i].moving = false
153			end
154		end
155	end
156	
157	if T.MoveUnitFrames then T.MoveUnitFrames() end
158	
159	if enable then enable = false else enable = true end
160end
161SLASH_MOVING1 = "/mtukui"
162SLASH_MOVING2 = "/moveui"
163SlashCmdList["MOVING"] = moving
164
165local protection = CreateFrame("Frame")
166protection:RegisterEvent("PLAYER_REGEN_DISABLED")
167protection:SetScript("OnEvent", function(self, event)
168	if enable then return end
169	print(ERR_NOT_IN_COMBAT)
170	enable = false
171	moving()
172end)