/Tukui/core/movers.lua

http://github.com/Asphyxia/Tukui · Lua · 172 lines · 152 code · 15 blank · 5 comment · 70 complexity · 33898ec0cbf0ea0ae22168979eefc092 MD5 · raw file

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