/Tukui/modules/blizzard/watchframe.lua

http://github.com/Asphyxia/Tukui · Lua · 108 lines · 90 code · 11 blank · 7 comment · 12 complexity · 529c5bc697ff0ab2733b8ed130fc6549 MD5 · raw file

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