Advertisement
Guest User

Unitframes.lua

a guest
Oct 26th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.87 KB | None | 0 0
  1. local MODULE_NAME = "Unitframes"
  2. local BasicUI = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
  3. local MODULE = BasicUI:NewModule(MODULE_NAME, "AceEvent-3.0")
  4. local L = BasicUI.L
  5.  
  6. local db
  7.  
  8. local defaults = {
  9. profile = {
  10. enable = true,
  11. --abbrevRealmNames = true,
  12. player = {
  13. enable = true, -- Enable Player Frame Adjustments
  14. scale = 1.15, -- Player Frame Scale
  15. },
  16. target = {
  17. enable = true, -- Enable Target Frame Adjustments
  18. scale = 1.15, -- Target Frame Scale
  19. },
  20. focus = {
  21. enable = true, -- Enable Focus Frame Adjustments
  22. scale = 1.15, -- Focus Frame Scale
  23. },
  24. party = {
  25. enable = true,
  26. scale = 1.15,
  27. position = {
  28. relAnchor = "TOPLEFT",
  29. offSetX = 10, -- Controls the X offset. (Left - Right)
  30. offSetY = -200, -- Controls the Y offset. (Up - Down)
  31. },
  32. },
  33. arena = {
  34. enable = true,
  35. scale = 1.15,
  36. },
  37. boss = {
  38. enable = true,
  39. scale = 1.15,
  40. position = {
  41. relAnchor = "RIGHT",
  42. offSetX = -50, -- Controls the X offset. (Left - Right)
  43. offSetY = -250, -- Controls the Y offset. (Up - Down)
  44. },
  45. },
  46. },
  47. }
  48.  
  49. local CUSTOM_FACTION_BAR_COLORS = {
  50. [1] = {r = 1, g = 0, b = 0},
  51. [2] = {r = 1, g = 0, b = 0},
  52. [3] = {r = 1, g = 1, b = 0},
  53. [4] = {r = 1, g = 1, b = 0},
  54. [5] = {r = 0, g = 1, b = 0},
  55. [6] = {r = 0, g = 1, b = 0},
  56. [7] = {r = 0, g = 1, b = 0},
  57. [8] = {r = 0, g = 1, b = 0},
  58. }
  59.  
  60. -- Font Style
  61. local shorts = {
  62. { 1e10, 1e9, "%.0fB" }, -- 10b+ as 12b
  63. { 1e9, 1e9, "%.1fB" }, -- 1b+ as 8.3b
  64. { 1e7, 1e6, "%.0fM" }, -- 10m+ as 14m
  65. { 1e6, 1e6, "%.1fM" }, -- 1m+ as 7.4m
  66. { 1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
  67. { 1e3, 1e3, "%.1fK" }, -- 1k+ as 2.5k
  68. { 0, 1, "%d" }, -- < 1k as 974
  69. }
  70. for i = 1, #shorts do
  71. shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  72. end
  73.  
  74. function MODULE:OnInitialize()
  75. self.db = BasicUI.db:RegisterNamespace(MODULE_NAME, defaults)
  76. db = self.db.profile
  77.  
  78. self:SetEnabledState(BasicUI:GetModuleEnabled(MODULE_NAME))
  79. end
  80.  
  81. function MODULE:OnEnable()
  82.  
  83. if InCombatLockdown() then
  84. return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
  85. end
  86. self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  87.  
  88. db = self.db.profile
  89.  
  90. if enabled or not db.enable then return end
  91. enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc)
  92.  
  93. -- Move Party Frames
  94. --local movingPartyFrame
  95. --hooksecurefunc(PartyMemberFrame1, "SetPoint", function(f, ...)
  96. --if movingPartyFrame or InCombatLockdown() then
  97. --return
  98. --end
  99. --movingPartyFrame = true
  100. --PartyMemberFrame1:ClearAllPoints()
  101. --PartyMemberFrame1:SetPoint(db.party.position.relAnchor, UIParent, db.party.position.offSetX, db.party.position.offSetY)
  102. --movingPartyFrame = nil
  103. --end)
  104.  
  105. --PartyMemberFrame1:SetPoint(db.party.position.relAnchor, UIParent, db.party.position.offSetX, db.party.position.offSetY);
  106.  
  107. -- Move Boss Frames
  108. --local movingBossFrame
  109. --hooksecurefunc(Boss1TargetFrame, "SetPoint", function(f, ...)
  110. --if movingBossFrame or InCombatLockdown() then
  111. --return
  112. --end
  113. --movingBossFrame = true
  114. --Boss1TargetFrame:ClearAllPoints()
  115. --Boss1TargetFrame:SetPoint(db.boss.position.relAnchor, UIParent, db.boss.position.offSetX, db.boss.position.offSetY)
  116. --movingBossFrame = nil
  117. --end)
  118.  
  119. -- Update Unit Frames
  120. self:ApplySettings()
  121.  
  122. -- Disable healing/damage spam over player/pet frame:
  123. PlayerHitIndicator:SetText(nil)
  124. PlayerHitIndicator.SetText = function() end
  125. PetHitIndicator:SetText(nil)
  126. PetHitIndicator.SetText = function() end
  127.  
  128. -- Change other frames' name backgrounds to match player frame
  129. for _, region in pairs({
  130. TargetFrameNameBackground,
  131. FocusFrameNameBackground,
  132. Boss1TargetFrameNameBackground,
  133. Boss2TargetFrameNameBackground,
  134. Boss3TargetFrameNameBackground,
  135. Boss4TargetFrameNameBackground,
  136. Boss5TargetFrameNameBackground,
  137.  
  138. }) do
  139. region:SetTexture(0, 0, 0, 0.5)
  140. end
  141.  
  142. -- Font Style / Color thanks to Phanx from WoWinterface.
  143. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, textString, value, valueMin, valueMax)
  144. if value == 0 then
  145. return textString:SetText("")
  146. end
  147.  
  148. local style = GetCVar("statusTextDisplay")
  149. if style == "PERCENT" then
  150. return textString:SetFormattedText("%.0f%%", value / valueMax * 100)
  151. end
  152. for i = 1, #shorts do
  153. local t = shorts[i]
  154. if value >= t[1] then
  155. if style == "BOTH" then
  156. return textString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  157. else
  158. if value < valueMax then
  159. for j = 1, #shorts do
  160. local v = shorts[j]
  161. if valueMax >= v[1] then
  162. return textString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2])
  163. end
  164. end
  165. end
  166. return textString:SetFormattedText(t[3], value / t[2])
  167. end
  168. end
  169. end
  170. end)
  171.  
  172. -- Font Color
  173. hooksecurefunc("UnitFrame_Update", function(self, isParty)
  174. if not self.name or not self:IsShown() then return end
  175.  
  176. local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
  177. local unit, color = self.unit
  178. if UnitPlayerControlled(unit) then
  179. if UnitIsPlayer(unit) then
  180. local _, class = UnitClass(unit)
  181. color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  182. else
  183. color = PET_COLOR
  184. end
  185. elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  186. color = GRAY_FONT_COLOR
  187. else
  188. color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
  189. end
  190.  
  191. if not color then
  192. color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
  193. end
  194.  
  195. self.name:SetTextColor(color.r, color.g, color.b)
  196. if isParty then
  197. self.name:SetText(GetUnitName(self.overrideName or unit))
  198. end
  199. end)
  200. end
  201.  
  202. function MODULE:ApplySettings(event)
  203.  
  204. db = self.db.profile
  205.  
  206. if event then
  207. self:UnregisterEvent(event)
  208. end
  209.  
  210. if InCombatLockdown() then
  211. return self:RegisterEvent("PLAYER_REGEN_ENABLED", "ApplySettings")
  212. end
  213.  
  214. local failure
  215. for unit, func in pairs(self.UnitFunctions) do
  216. if db[unit].enable then
  217. if func(self) then
  218. failure = true
  219. end
  220. end
  221. end
  222.  
  223. if failure then
  224. self:RegisterEvent("ADDON_LOADED", "ApplySettings")
  225. end
  226.  
  227. end
  228.  
  229. ------------------------------------------------------------------------
  230.  
  231.  
  232. MODULE.UnitFunctions = {
  233.  
  234.  
  235. player = function(self)
  236. PlayerFrame:SetScale(db.player.scale)
  237. end,
  238.  
  239. target = function(self)
  240. TargetFrame:SetScale(db.target.scale)
  241. end,
  242.  
  243. focus = function(self)
  244. FocusFrame:SetScale(db.focus.scale)
  245. end,
  246.  
  247. party = function(self)
  248. for i = 1, MAX_PARTY_MEMBERS do
  249. local partyFrame = "PartyMemberFrame"..i
  250. _G[partyFrame]:SetScale(db.party.scale)
  251. end
  252. end,
  253.  
  254. arena = function(self)
  255. if not ArenaEnemyFrame1 then
  256. return true
  257. end
  258.  
  259. for i = 1, MAX_ARENA_ENEMIES do
  260. local prepFrame = "ArenaPrepFrame"..i
  261. _G[prepFrame]:SetScale(db.arena.scale)
  262.  
  263. local arenaFrame = "ArenaEnemyFrame"..i
  264. _G[arenaFrame]:SetScale(db.arena.scale)
  265. end
  266. end,
  267.  
  268. boss = function(self)
  269. for i = 1, MAX_BOSS_FRAMES do
  270. local bossFrame = "Boss"..i.."TargetFrame"
  271. _G[bossFrame]:SetScale(db.boss.scale)
  272. end
  273. end,
  274.  
  275.  
  276. }
  277. ------------------------------------------------------------------------------
  278.  
  279. -- Leave this out if the module doesn't have any settings:
  280. function MODULE:Refresh()
  281. db = self.db.profile -- update the upvalue
  282.  
  283. -- change stuff here
  284. end
  285.  
  286. -- Leave this out if the module doesn't have any options:
  287. local options
  288. function MODULE:GetOptions()
  289.  
  290.  
  291. local regions = {
  292. ['BOTTOM'] = L['Bottom'],
  293. ['BOTTOMLEFT'] = L['Bottom Left'],
  294. ['BOTTOMRIGHT'] = L['Bottom Right'],
  295. ['CENTER'] = L['Center'],
  296. ['LEFT'] = L['Left'],
  297. ['RIGHT'] = L['Right'],
  298. ['TOP'] = L['Top'],
  299. ['TOPLEFT'] = L['Top Left'],
  300. ['TOPRIGHT'] = L['Top Right'],
  301. }
  302.  
  303. if options then
  304. return options
  305. end
  306.  
  307. local function isModuleDisabled()
  308. return not BasicUI:GetModuleEnabled(MODULE_NAME)
  309. end
  310.  
  311. options = {
  312. type = "group",
  313. name = L[MODULE_NAME],
  314. get = function(info) return db[ info[#info] ] end,
  315. set = function(info, value) db[ info[#info] ] = value; self:ApplySettings(event) end,
  316. disabled = isModuleDisabled(),
  317. args = {
  318. reloadUI = {
  319. type = "execute",
  320. name = "Reload UI",
  321. desc = " ",
  322. order = 0,
  323. func = function()
  324. ReloadUI()
  325. end,
  326. },
  327. Text = {
  328. type = "description",
  329. order = 0,
  330. name = "When you enable or disable a Unitframe a reload of the UI is needed.",
  331. width = "full",
  332. },
  333. Text1 = {
  334. type = "description",
  335. order = 1,
  336. name = " ",
  337. width = "full",
  338. },
  339. enable = {
  340. type = "toggle",
  341. order = 1,
  342. name = L["Enable Uniframes Module"],
  343. width = "full",
  344. disabled = false,
  345. },
  346. Text2 = {
  347. type = "description",
  348. order = 2,
  349. name = " ",
  350. width = "full",
  351. },
  352. player = {
  353. type = "group",
  354. order = 2,
  355. name = L["Player Frame Adjustments"],
  356. get = function(info) return db.player[ info[#info] ] end,
  357. set = function(info, value) db.player[ info[#info] ] = value; self:ApplySettings(event) end,
  358. disabled = function() return isModuleDisabled() or not db.enable end,
  359. guiInline = true,
  360. args = {
  361. enable = {
  362. type = "toggle",
  363. order = 0,
  364. name = L["Enable Player Frame"],
  365. width = "full",
  366. },
  367. Text1 = {
  368. type = "description",
  369. order = 1,
  370. name = " ",
  371. width = "full",
  372. },
  373. scale = {
  374. type = "range",
  375. order = 1,
  376. name = L["Frame Scale"],
  377. desc = L["Controls the scaling of Blizzard's Player Frame"],
  378. min = 0.5, max = 2, step = 0.05,
  379. disabled = function() return isModuleDisabled() or not db.enable or not db.player.enable end,
  380. },
  381. },
  382. },
  383. target = {
  384. type = "group",
  385. order = 4,
  386. name = L["Target Frame Adjustments"],
  387. get = function(info) return db.target[ info[#info] ] end,
  388. set = function(info, value) db.target[ info[#info] ] = value; self:ApplySettings(event) end,
  389. disabled = function() return isModuleDisabled() or not db.enable end,
  390. guiInline = true,
  391. args = {
  392. ---------------------------
  393. --Option Type Seperators
  394. sep1 = {
  395. type = "description",
  396. order = 1,
  397. name = " ",
  398. },
  399. sep2 = {
  400. type = "description",
  401. order = 2,
  402. name = " ",
  403. },
  404. sep3 = {
  405. type = "description",
  406. order = 3,
  407. name = " ",
  408. },
  409. sep4 = {
  410. type = "description",
  411. order = 4,
  412. name = " ",
  413. },
  414. ---------------------------
  415. enable = {
  416. type = "toggle",
  417. order = 0,
  418. name = L["Enable Target Frame"],
  419. width = "full",
  420. },
  421. scale = {
  422. type = "range",
  423. order = 1,
  424. name = L["Frame Scale"],
  425. desc = L["Controls the scaling of Blizzard's Target Frame"],
  426. min = 0.5, max = 2, step = 0.05,
  427. disabled = function() return isModuleDisabled() or not db.enable or not db.target.enable end,
  428. },
  429. },
  430. },
  431. focus = {
  432. type = "group",
  433. order = 5,
  434. name = L["Focus Frame Adjustments"],
  435. get = function(info) return db.focus[ info[#info] ] end,
  436. set = function(info, value) db.focus[ info[#info] ] = value; self:ApplySettings(event) end,
  437. disabled = function() return isModuleDisabled() or not db.enable end,
  438. guiInline = true,
  439. args = {
  440. ---------------------------
  441. --Option Type Seperators
  442. sep1 = {
  443. type = "description",
  444. order = 1,
  445. name = " ",
  446. },
  447. sep2 = {
  448. type = "description",
  449. order = 2,
  450. name = " ",
  451. },
  452. sep3 = {
  453. type = "description",
  454. order = 3,
  455. name = " ",
  456. },
  457. sep4 = {
  458. type = "description",
  459. order = 4,
  460. name = " ",
  461. },
  462. ---------------------------
  463. enable = {
  464. type = "toggle",
  465. order = 0,
  466. name = L["Enable Focus Frame"],
  467. width = "full",
  468. },
  469. scale = {
  470. type = "range",
  471. order = 1,
  472. name = L["Frame Scale"],
  473. desc = L["Controls the scaling of Blizzard's Focus Frame"],
  474. min = 0.5, max = 2, step = 0.05,
  475. disabled = function() return isModuleDisabled() or not db.enable or not db.focus.enable end,
  476. },
  477. },
  478. },
  479. party = {
  480. type = "group",
  481. order = 6,
  482. name = L["Party Frame Adjustments"],
  483. get = function(info) return db.party[ info[#info] ] end,
  484. set = function(info, value) db.party[ info[#info] ] = value; self:ApplySettings(event) end,
  485. disabled = function() return isModuleDisabled() or not db.enable end,
  486. guiInline = true,
  487. args = {
  488. ---------------------------
  489. sep1 = {
  490. type = "description",
  491. order = 1,
  492. name = " ",
  493. },
  494. sep2 = {
  495. type = "description",
  496. order = 2,
  497. name = " ",
  498. },
  499. sep3 = {
  500. type = "description",
  501. order = 3,
  502. name = " ",
  503. },
  504. sep4 = {
  505. type = "description",
  506. order = 4,
  507. name = " ",
  508. },
  509. sep5 = {
  510. type = "description",
  511. order = 5,
  512. name = " ",
  513. },
  514. ---------------------------
  515. enable = {
  516. type = "toggle",
  517. order = 0,
  518. name = L["Enable Party Frame"],
  519. width = "full",
  520. },
  521. scale = {
  522. type = "range",
  523. order = 1,
  524. name = L["Scale"],
  525. desc = L["Controls the scaling of Blizzard's Party Frame"],
  526. min = 0.5, max = 2, step = 0.05,
  527. disabled = function() return isModuleDisabled() or not db.enable or not db.party.enable end,
  528. },
  529. position = {
  530. type = "group",
  531. order = 2,
  532. childGroups = "tree",
  533. name = L["Party Frame Position"],
  534. disabled = function() return isModuleDisabled() or not db.enable or not db.party.enable end,
  535. get = function(info) return db.party.position[ info[#info] ] end,
  536. set = function(info, value) db.party.position[ info[#info] ] = value; self:ApplySettings(event) end,
  537.  
  538. args = {
  539. ---------------------------
  540. --Option Type Seperators
  541. sep1 = {
  542. type = "description",
  543. order = 1,
  544. name = " ",
  545. },
  546. sep2 = {
  547. type = "description",
  548. order = 2,
  549. name = " ",
  550. },
  551. sep3 = {
  552. type = "description",
  553. order = 3,
  554. name = " ",
  555. },
  556. sep4 = {
  557. type = "description",
  558. order = 4,
  559. name = " ",
  560. },
  561. ---------------------------
  562. relAnchor = {
  563. order = 1,
  564. name = L["Self Anchor"],
  565. type = "select",
  566. values = regions,
  567. disabled = function() return isModuleDisabled() or not db.enable or not db.party.enable end,
  568. },
  569. offSetX = {
  570. type = "range",
  571. order = 2,
  572. name = L["X Offset"],
  573. desc = L["Controls the X offset. (Left - Right)"],
  574. min = -250, max = 250, step = 5,
  575. disabled = function() return isModuleDisabled() or not db.enable or not db.party.enable end,
  576. },
  577. offSetY = {
  578. type = "range",
  579. order = 3,
  580. name = L["Y Offset"],
  581. desc = L["Controls the Y offset. (Up - Down)"],
  582. min = -250, max = 250, step = 5,
  583. disabled = function() return isModuleDisabled() or not db.enable or not db.party.enable end,
  584. },
  585. },
  586. },
  587. },
  588. },
  589. arena = {
  590. type = "group",
  591. order = 7,
  592. name = L["Arena Frame Adjustments"],
  593. get = function(info) return db.arena[ info[#info] ] end,
  594. set = function(info, value) db.arena[ info[#info] ] = value; self:ApplySettings(event) end,
  595. disabled = function() return isModuleDisabled() or not db.enable end,
  596. guiInline = true,
  597. args = {
  598. ---------------------------
  599. sep1 = {
  600. type = "description",
  601. order = 1,
  602. name = " ",
  603. },
  604. sep2 = {
  605. type = "description",
  606. order = 2,
  607. name = " ",
  608. },
  609. sep3 = {
  610. type = "description",
  611. order = 3,
  612. name = " ",
  613. },
  614. sep4 = {
  615. type = "description",
  616. order = 4,
  617. name = " ",
  618. },
  619. ---------------------------
  620. enable = {
  621. type = "toggle",
  622. order = 0,
  623. name = L["Enable Arena Frame"],
  624. },
  625. scale = {
  626. type = "range",
  627. order = 1,
  628. name = L["Scale"],
  629. desc = L["Controls the scaling of Blizzard's Arena Frames"],
  630. min = 0.5, max = 2, step = 0.05,
  631. disabled = function() return isModuleDisabled() or not db.enable or not db.arena.enable end,
  632. },
  633. },
  634. },
  635. boss = {
  636. type = "group",
  637. order = 6,
  638. name = L["Boss Frame Adjustments"],
  639. get = function(info) return db.boss[ info[#info] ] end,
  640. set = function(info, value) db.boss[ info[#info] ] = value; self:ApplySettings(event) end,
  641. disabled = function() return isModuleDisabled() or not db.enable end,
  642. guiInline = true,
  643. args = {
  644. ---------------------------
  645. sep1 = {
  646. type = "description",
  647. order = 1,
  648. name = " ",
  649. },
  650. sep2 = {
  651. type = "description",
  652. order = 2,
  653. name = " ",
  654. },
  655. sep3 = {
  656. type = "description",
  657. order = 3,
  658. name = " ",
  659. },
  660. sep4 = {
  661. type = "description",
  662. order = 4,
  663. name = " ",
  664. },
  665. sep5 = {
  666. type = "description",
  667. order = 5,
  668. name = " ",
  669. },
  670. ---------------------------
  671. enable = {
  672. type = "toggle",
  673. order = 0,
  674. name = L["Enable Boss Frame"],
  675. width = "full",
  676. },
  677. scale = {
  678. type = "range",
  679. order = 1,
  680. name = L["Scale"],
  681. desc = L["Controls the scaling of Blizzard's Boss Frame's"],
  682. min = 0.5, max = 2, step = 0.05,
  683. disabled = function() return isModuleDisabled() or not db.enable or not db.boss.enable end,
  684. },
  685. position = {
  686. type = "group",
  687. order = 2,
  688. childGroups = "tree",
  689. name = L["Boss Frame Position"],
  690. disabled = function() return isModuleDisabled() or not db.enable or not db.boss.enable end,
  691. get = function(info) return db.boss.position[ info[#info] ] end,
  692. set = function(info, value) db.boss.position[ info[#info] ] = value; self:ApplySettings(event) end,
  693.  
  694. args = {
  695. ---------------------------
  696. --Option Type Seperators
  697. sep1 = {
  698. type = "description",
  699. order = 1,
  700. name = " ",
  701. },
  702. sep2 = {
  703. type = "description",
  704. order = 2,
  705. name = " ",
  706. },
  707. sep3 = {
  708. type = "description",
  709. order = 3,
  710. name = " ",
  711. },
  712. sep4 = {
  713. type = "description",
  714. order = 4,
  715. name = " ",
  716. },
  717. ---------------------------
  718. relAnchor = {
  719. order = 1,
  720. name = L["Self Anchor"],
  721. type = "select",
  722. values = regions,
  723. disabled = function() return isModuleDisabled() or not db.enable or not db.boss.enable end,
  724. },
  725. offSetX = {
  726. type = "range",
  727. order = 2,
  728. name = L["X Offset"],
  729. desc = L["Controls the X offset. (Left - Right)"],
  730. min = -250, max = 250, step = 5,
  731. disabled = function() return isModuleDisabled() or not db.enable or not db.boss.enable end,
  732. },
  733. offSetY = {
  734. type = "range",
  735. order = 3,
  736. name = L["Y Offset"],
  737. desc = L["Controls the Y offset. (Up - Down)"],
  738. min = -250, max = 250, step = 5,
  739. disabled = function() return isModuleDisabled() or not db.enable or not db.boss.enable end,
  740. },
  741. },
  742. },
  743. },
  744. },
  745. },
  746. }
  747. return options
  748. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement