Advertisement
Guest User

BasicMinimap

a guest
Dec 17th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.40 KB | None | 0 0
  1.  
  2. local name, BM = ...
  3.  
  4. local buttonValues = {RightButton = KEY_BUTTON2, MiddleButton = KEY_BUTTON3,
  5. Button4 = KEY_BUTTON4, Button5 = KEY_BUTTON5, Button6 = KEY_BUTTON6,
  6. Button7 = KEY_BUTTON7, Button8 = KEY_BUTTON8, Button9 = KEY_BUTTON9,
  7. Button10 = KEY_BUTTON10, Button11 = KEY_BUTTON11, Button12 = KEY_BUTTON12,
  8. Button13 = KEY_BUTTON13, Button14 = KEY_BUTTON14, Button15 = KEY_BUTTON15,
  9. None = NONE
  10. }
  11.  
  12. BM.hide = function(frame) frame:Hide() end
  13.  
  14. BM.options = {
  15. type = "group",
  16. name = name,
  17. args = {
  18. btndesc = {
  19. name = BM.BUTTONDESC,
  20. order = 1, type = "description",
  21. },
  22. calendarbtn = {
  23. name = BM.CALENDAR,
  24. order = 2, type = "select",
  25. get = function() return BM.db.calendar or "RightButton" end,
  26. set = function(_, btn) BM.db.calendar = btn~="RightButton" and btn or nil end,
  27. values = buttonValues,
  28. },
  29. trackingbtn = {
  30. name = TRACKING,
  31. order = 3, type = "select",
  32. get = function() return BM.db.tracking or "MiddleButton" end,
  33. set = function(_, btn) BM.db.tracking = btn~="MiddleButton" and btn or nil end,
  34. values = buttonValues,
  35. },
  36. borderspacer = {
  37. name = "\n",
  38. order = 3.1, type = "description",
  39. },
  40. bordertitle = {
  41. name = EMBLEM_BORDER, --Border
  42. order = 4, type = "header",
  43. },
  44. bordercolor = {
  45. name = EMBLEM_BORDER_COLOR, --Border Color
  46. order = 5, type = "color",
  47. get = function() return BM.db.borderR, BM.db.borderG, BM.db.borderB end,
  48. set = function(_, r, g, b)
  49. BM.db.borderR = r BM.db.borderG = g BM.db.borderB = b
  50. BasicMinimapBorder:SetBackdropBorderColor(r, g, b)
  51. end,
  52. disabled = function() return BM.db.round or BM.db.ccolor end,
  53. },
  54. classcolor = {
  55. name = BM.CLASSCOLORED,
  56. order = 6, type = "toggle",
  57. get = function() return BM.db.ccolor end,
  58. set = function(_, state)
  59. if state then
  60. BM.db.ccolor = true
  61. local class = select(2, UnitClass("player"))
  62. local color = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]
  63. BasicMinimapBorder:SetBackdropBorderColor(color.r, color.g, color.b)
  64. else
  65. BM.db.ccolor = nil
  66. BasicMinimapBorder:SetBackdropBorderColor(BM.db.borderR, BM.db.borderG, BM.db.borderB)
  67. end
  68. end,
  69. disabled = function() return BM.db.round end,
  70. },
  71. bordersize = {
  72. name = BM.BORDERSIZE,
  73. order = 7, type = "range", width = "full",
  74. min = 0.5, max = 5, step = 0.5,
  75. get = function() return BM.db.borderSize or 3 end,
  76. set = function(_, s) BM.db.borderSize = s~=3 and s or nil
  77. BasicMinimapBorder:SetBackdrop(
  78. {edgeFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = false,
  79. tileSize = 0, edgeSize = s,}
  80. )
  81. BasicMinimapBorder:SetWidth(Minimap:GetWidth()+s)
  82. BasicMinimapBorder:SetHeight(Minimap:GetHeight()+s)
  83. if BM.db.ccolor then
  84. local class = select(2, UnitClass("player"))
  85. local color = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]
  86. BasicMinimapBorder:SetBackdropBorderColor(color.r, color.g, color.b)
  87. else
  88. BasicMinimapBorder:SetBackdropBorderColor(BM.db.borderR, BM.db.borderG, BM.db.borderB)
  89. end
  90. end,
  91. disabled = function() return BM.db.round end,
  92. },
  93. miscspacer = {
  94. name = "\n",
  95. order = 7.1, type = "description",
  96. },
  97. mischeader = {
  98. name = MISCELLANEOUS,
  99. order = 8, type = "header",
  100. },
  101. scale = {
  102. name = BM.SCALE,
  103. order = 9, type = "range",
  104. min = 0.5, max = 2, step = 0.01,
  105. get = function() return BM.db.scale or 1 end,
  106. set = function(_, scale)
  107. Minimap:SetScale(scale)
  108. Minimap:ClearAllPoints()
  109. local s = (BM.db.scale or 1)/scale
  110. BM.db.x, BM.db.y = BM.db.x*s, BM.db.y*s
  111. Minimap:SetPoint(BM.db.point, nil, BM.db.relpoint, BM.db.x, BM.db.y)
  112. BM.db.scale = scale~=1 and scale or nil
  113. end,
  114. },
  115. strata = {
  116. name = BM.STRATA,
  117. order = 10, type = "select",
  118. get = function() return BM.db.strata or "BACKGROUND" end,
  119. set = function(_, strata) BM.db.strata = strata~="BACKGROUND" and strata or nil
  120. Minimap:SetFrameStrata(strata)
  121. BasicMinimapBorder:SetFrameStrata(strata)
  122. end,
  123. values = {TOOLTIP = BM.TOOLTIP, HIGH = HIGH, MEDIUM = AUCTION_TIME_LEFT2,
  124. LOW = LOW, BACKGROUND = BACKGROUND
  125. },
  126. },
  127. shape = {
  128. name = BM.SHAPE,
  129. order = 11, type = "select",
  130. get = function() return BM.db.round and "circular" or "square" end,
  131. set = function(_, shape)
  132. if shape == "square" then
  133. BM.db.round = nil
  134. Minimap:SetMaskTexture("Interface\\BUTTONS\\WHITE8X8")
  135. BasicMinimapBorder:Show()
  136. function GetMinimapShape() return "SQUARE" end
  137. else
  138. BM.db.round = true
  139. Minimap:SetMaskTexture("Interface\\AddOns\\BasicMinimap\\circle")
  140. BasicMinimapBorder:Hide()
  141. function GetMinimapShape() return "ROUND" end
  142. end
  143. end,
  144. values = {square = RAID_TARGET_6, circular = RAID_TARGET_2}, --Square, Circle
  145. },
  146. zoom = {
  147. name = ZOOM_IN.."/"..ZOOM_OUT,
  148. order = 12, type = "toggle",
  149. get = function() return BM.db.zoomBtn end,
  150. set = function(_, state)
  151. BM.db.zoomBtn = state
  152. if state then
  153. MinimapZoomIn:ClearAllPoints()
  154. MinimapZoomIn:SetParent("Minimap")
  155. MinimapZoomIn:SetPoint("RIGHT", "Minimap", "RIGHT", BM.db.round and 10 or 20, BM.db.round and -40 or -50)
  156. MinimapZoomIn:Show()
  157. MinimapZoomOut:ClearAllPoints()
  158. MinimapZoomOut:SetParent("Minimap")
  159. MinimapZoomOut:SetPoint("BOTTOM", "Minimap", "BOTTOM", BM.db.round and 40 or 50, BM.db.round and -10 or -20)
  160. MinimapZoomOut:Show()
  161. else
  162. MinimapZoomIn:Hide()
  163. MinimapZoomOut:Hide()
  164. end
  165. end,
  166. },
  167. raiddiff = {
  168. name = RAID_DIFFICULTY,
  169. order = 13, type = "toggle",
  170. get = function() if BM.db.hideraid then return false else return true end end,
  171. set = function(_, state)
  172. if state then
  173. BM.db.hideraid = nil
  174. MiniMapInstanceDifficulty:SetScript("OnShow", nil)
  175. GuildInstanceDifficulty:SetScript("OnShow", nil)
  176. local z = select(2, IsInInstance())
  177. if z and (z == "party" or z == "raid") and (IsInRaid() or IsInGroup()) then
  178. MiniMapInstanceDifficulty:Show()
  179. GuildInstanceDifficulty:Show()
  180. end
  181. else
  182. BM.db.hideraid = true
  183. MiniMapInstanceDifficulty:SetScript("OnShow", BM.hide)
  184. MiniMapInstanceDifficulty:Hide()
  185. GuildInstanceDifficulty:SetScript("OnShow", BM.hide)
  186. GuildInstanceDifficulty:Hide()
  187. end
  188. end,
  189. },
  190. clock = {
  191. name = TIMEMANAGER_TITLE,
  192. order = 14, type = "toggle",
  193. get = function() return BM.db.clock or BM.db.clock == nil and true end,
  194. set = function(_, state)
  195. BM.db.clock = state
  196. if state then
  197. if TimeManagerClockButton.bmShow then
  198. TimeManagerClockButton.Show = TimeManagerClockButton.bmShow
  199. TimeManagerClockButton.bmShow = nil
  200. end
  201. TimeManagerClockButton:Show()
  202. else
  203. if not TimeManagerClockButton.bmShow then
  204. TimeManagerClockButton.bmShow = TimeManagerClockButton.Show
  205. TimeManagerClockButton.Show = function() end
  206. end
  207. TimeManagerClockButton:Hide()
  208. end
  209. end,
  210. },
  211. autozoom = {
  212. name = BM.AUTOZOOM,
  213. order = 15, type = "toggle",
  214. get = function() return BM.db.zoom end,
  215. set = function(_, state) BM.db.zoom = state and true or nil end,
  216. },
  217. lockspacer = {
  218. name = "\n",
  219. order = 15.1, type = "description",
  220. },
  221. lock = {
  222. name = LOCK,
  223. order = 16, type = "toggle",
  224. get = function() return BM.db.lock end,
  225. set = function(_, state) BM.db.lock = state and true or nil
  226. if not state then state = true else state = false end
  227. Minimap:SetMovable(state)
  228. end,
  229. },
  230. },
  231. }
  232.  
  233. BM.self = CreateFrame("Frame", "BasicMinimap", InterfaceOptionsFramePanelContainer)
  234. BM.self:RegisterEvent("PLAYER_LOGIN")
  235. BM.self:SetScript("OnEvent", function(f)
  236. if not BasicMinimapDB then
  237. BasicMinimapDB = {
  238. x = 0, y = 0,
  239. point = "CENTER", relpoint = "CENTER",
  240. borderR = 0.73, borderG = 0.75, borderB = 1
  241. }
  242. end
  243. BM.db = BasicMinimapDB
  244.  
  245. --Return minimap shape for other addons
  246. if not BM.db.round then function GetMinimapShape() return "SQUARE" end end
  247.  
  248. LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(name, BM.options, true)
  249. LibStub("AceConfigDialog-3.0"):AddToBlizOptions(name)
  250.  
  251. SlashCmdList.BASICMINIMAP = function() InterfaceOptionsFrame_OpenToCategory(name) InterfaceOptionsFrame_OpenToCategory(name) end
  252. SLASH_BASICMINIMAP1 = "/bm"
  253. SLASH_BASICMINIMAP2 = "/basicminimap"
  254.  
  255. local Minimap = Minimap
  256. Minimap:SetParent(UIParent)
  257. MinimapCluster:EnableMouse(false)
  258.  
  259. local border = CreateFrame("Frame", "BasicMinimapBorder", Minimap)
  260. border:SetBackdrop({edgeFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = false, tileSize = 0, edgeSize = BM.db.borderSize or 3})
  261. border:SetFrameStrata(BM.db.strata or "BACKGROUND")
  262. border:SetPoint("CENTER", Minimap, "CENTER")
  263. if BM.db.ccolor then
  264. local class = select(2, UnitClass("player"))
  265. local color = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[class] or RAID_CLASS_COLORS[class]
  266. BasicMinimapBorder:SetBackdropBorderColor(color.r, color.g, color.b)
  267. else
  268. border:SetBackdropBorderColor(BM.db.borderR, BM.db.borderG, BM.db.borderB)
  269. end
  270. border:SetWidth(Minimap:GetWidth()+(BM.db.borderSize or 3))
  271. border:SetHeight(Minimap:GetHeight()+(BM.db.borderSize or 3))
  272. border:Hide()
  273.  
  274. Minimap:ClearAllPoints()
  275. Minimap:SetPoint(BM.db.point, nil, BM.db.relpoint, BM.db.x, BM.db.y)
  276. Minimap:RegisterForDrag("LeftButton")
  277. Minimap:SetClampedToScreen(true)
  278.  
  279. Minimap:SetScript("OnDragStart", function(self) if self:IsMovable() then self:StartMoving() end end)
  280. Minimap:SetScript("OnDragStop", function(self)
  281. self:StopMovingOrSizing()
  282. local p, _, rp, x, y = self:GetPoint()
  283. BM.db.point, BM.db.relpoint, BM.db.x, BM.db.y = p, rp, x, y
  284. end)
  285.  
  286. if not BM.db.lock then Minimap:SetMovable(true) end
  287.  
  288. Minimap:SetScale(BM.db.scale or 1)
  289. Minimap:SetFrameStrata(BM.db.strata or "BACKGROUND")
  290. MinimapNorthTag.Show = MinimapNorthTag.Hide
  291. MinimapNorthTag:Hide()
  292.  
  293. MinimapBorder:Hide()
  294. MinimapBorderTop:Hide()
  295. if not BM.db.round then
  296. border:Show()
  297. Minimap:SetMaskTexture("Interface\\BUTTONS\\WHITE8X8")
  298. end
  299.  
  300. -- Removes the circular "waffle-like" texture that shows when using a non-circular minimap in the blue quest objective area.
  301. Minimap:SetArchBlobRingScalar(0)
  302. Minimap:SetArchBlobRingAlpha(0)
  303. Minimap:SetQuestBlobRingScalar(0)
  304. Minimap:SetQuestBlobRingAlpha(0)
  305.  
  306. if not BM.db.zoomBtn then
  307. MinimapZoomIn:Hide()
  308. MinimapZoomOut:Hide()
  309. else
  310. MinimapZoomIn:ClearAllPoints()
  311. MinimapZoomIn:SetParent("Minimap")
  312. MinimapZoomIn:SetPoint("RIGHT", "Minimap", "RIGHT", BM.db.round and 10 or 20, BM.db.round and -40 or -50)
  313. MinimapZoomIn:Show()
  314. MinimapZoomOut:ClearAllPoints()
  315. MinimapZoomOut:SetParent("Minimap")
  316. MinimapZoomOut:SetPoint("BOTTOM", "Minimap", "BOTTOM", BM.db.round and 40 or 50, BM.db.round and -10 or -20)
  317. MinimapZoomOut:Show()
  318. end
  319.  
  320. MiniMapVoiceChatFrame:SetScript("OnShow", BM.hide)
  321. MiniMapVoiceChatFrame:Hide()
  322. MiniMapVoiceChatFrame:UnregisterAllEvents()
  323.  
  324. if BM.db.clock == false then
  325. TimeManagerClockButton:Hide()
  326. TimeManagerClockButton.bmShow = TimeManagerClockButton.Show
  327. TimeManagerClockButton.Show = function() end
  328. end
  329.  
  330. border:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
  331. border:RegisterEvent("CALENDAR_ACTION_PENDING")
  332. border:SetScript("OnEvent", function()
  333. if CalendarGetNumPendingInvites() < 1 then
  334. GameTimeFrame:Hide()
  335. else
  336. GameTimeFrame:Show()
  337. end
  338. end)
  339. if CalendarGetNumPendingInvites() < 1 then
  340. GameTimeFrame:Hide()
  341. else
  342. GameTimeFrame:Show()
  343. end
  344.  
  345. MiniMapWorldMapButton:SetScript("OnShow", BM.hide)
  346. MiniMapWorldMapButton:Hide()
  347. MiniMapWorldMapButton:UnregisterAllEvents()
  348.  
  349. MinimapZoneTextButton:SetScript("OnShow", BM.hide)
  350. MinimapZoneTextButton:Hide()
  351. MinimapZoneTextButton:UnregisterAllEvents()
  352.  
  353. MiniMapTracking:SetScript("OnShow", BM.hide)
  354. MiniMapTracking:Hide()
  355. MiniMapTracking:UnregisterAllEvents()
  356.  
  357. MiniMapInstanceDifficulty:ClearAllPoints()
  358. MiniMapInstanceDifficulty:SetParent(Minimap)
  359. MiniMapInstanceDifficulty:SetPoint("TOPLEFT", Minimap, "TOPLEFT", -20, 0)
  360.  
  361. GuildInstanceDifficulty:ClearAllPoints()
  362. GuildInstanceDifficulty:SetParent(Minimap)
  363. GuildInstanceDifficulty:SetPoint("TOPLEFT", Minimap, "TOPLEFT", -20, 0)
  364.  
  365. GarrisonLandingPageMinimapButton:SetSize(38, 38)
  366. GarrisonLandingPageMinimapButton:ClearAllPoints()
  367. GarrisonLandingPageMinimapButton:SetParent(Minimap)
  368. GarrisonLandingPageMinimapButton:SetPoint("BOTTOMLEFT", Minimap, "BOTTOMLEFT", -23, 15)
  369.  
  370. if BM.db.hideraid then
  371. MiniMapInstanceDifficulty:SetScript("OnShow", BM.hide)
  372. MiniMapInstanceDifficulty:Hide()
  373. GuildInstanceDifficulty:SetScript("OnShow", BM.hide)
  374. GuildInstanceDifficulty:Hide()
  375. end
  376.  
  377. QueueStatusMinimapButton:ClearAllPoints()
  378. QueueStatusMinimapButton:SetParent(Minimap)
  379. QueueStatusMinimapButton:SetPoint("BOTTOMLEFT", Minimap, "BOTTOMLEFT", -10, -10)
  380.  
  381. -- This is our method of cancelling timers, we only let the very last scheduled timer actually run the code.
  382. -- We do this by using a simple counter, which saves us using the more expensive C_Timer.NewTimer API.
  383. local started, current = 0, 0
  384. --[[ Auto Zoom Out ]]--
  385. local zoomOut = function()
  386. current = current + 1
  387. if started == current then
  388. for i = 1, Minimap:GetZoom() or 0 do
  389. Minimap_ZoomOutClick() -- Call it directly so we don't run our own hook
  390. end
  391. started, current = 0, 0
  392. end
  393. end
  394.  
  395. local zoomBtnFunc = function()
  396. if BM.db.zoom then
  397. started = started + 1
  398. C_Timer.After(4, zoomOut)
  399. end
  400. end
  401. zoomBtnFunc()
  402. MinimapZoomIn:HookScript("OnClick", zoomBtnFunc)
  403. MinimapZoomOut:HookScript("OnClick", zoomBtnFunc)
  404.  
  405. Minimap:EnableMouseWheel(true)
  406. Minimap:SetScript("OnMouseWheel", function(self, d)
  407. if d > 0 then
  408. MinimapZoomIn:Click()
  409. elseif d < 0 then
  410. MinimapZoomOut:Click()
  411. end
  412. end)
  413.  
  414. Minimap:SetScript("OnMouseUp", function(self, btn)
  415. if btn == (BM.db.calendar or "RightButton") then
  416. GameTimeFrame:Click()
  417. elseif btn == (BM.db.tracking or "MiddleButton") then
  418. ToggleDropDownMenu(1, nil, MiniMapTrackingDropDown, self)
  419. elseif btn == "LeftButton" then
  420. Minimap_OnClick(self)
  421. end
  422. end)
  423.  
  424. f:UnregisterEvent("PLAYER_LOGIN")
  425.  
  426. -- Hide the Minimap during a pet battle
  427. f:SetScript("OnEvent", function(_, event)
  428. if event == "PET_BATTLE_CLOSE" then
  429. Minimap:Show()
  430. else
  431. Minimap:Hide()
  432. end
  433. end)
  434. f:RegisterEvent("PET_BATTLE_OPENING_START")
  435. f:RegisterEvent("PET_BATTLE_CLOSE")
  436. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement