Advertisement
Yulai

Interface AddOns SMT core cd_icons.lua

May 17th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.02 KB | None | 0 0
  1. local T, C, L, G = unpack(select(2, ...))
  2.  
  3. local addon_name = G.addon_name
  4. local font = G.Font
  5.  
  6. --[[------------------------
  7. -- Group Inspect --
  8. ------------------------]]--
  9.  
  10. party_cd = LibStub("AceAddon-3.0"):NewAddon("party_cd")
  11.  
  12. if not party_cd then return end
  13.  
  14. party_cd.Roster = {}
  15. party_cd.Frames = {}
  16.  
  17. if not party_cd.events then
  18. party_cd.events = LibStub("CallbackHandler-1.0"):New(party_cd)
  19. end
  20.  
  21. --[[
  22. GetSpecializationInfoForClassID(classID, specNum)
  23.  
  24. 1战士 狂暴72 武器71 防御73
  25. 2骑士 惩戒70 神圣65 防护66
  26. 3猎人 射击254 野兽253 生存255
  27. 4盗贼 刺杀259 战斗260 敏锐261
  28. 5牧师 戒律256 暗影258 神圣257
  29. 6死骑 鲜血250 冰霜251 邪恶252
  30. 7萨满 元素262 增强263 恢复264
  31. 8法师 奥术62 火焰63 冰霜64
  32. 9术士 痛苦265 恶魔266 毁灭267
  33. 10武僧 酒仙268 织雾270 踏风269
  34. 11XD 平衡102 野性103 守护104 恢复105
  35. 12DH 浩劫577 复仇581
  36. ]]--
  37.  
  38. local DefensiveSpells = {
  39. ["PALADIN"] = {
  40. ["642_11"] = {spellID = 642, cd = 240, spec =70, talent = 22485}, -- 圣盾术 惩戒
  41. ["642_12"] = {spellID = 642, cd = 300, spec =70, talent = 22483}, -- 圣盾术 惩戒
  42. ["642_13"] = {spellID = 642, cd = 300, spec =70, talent = 22484}, -- 圣盾术 惩戒
  43. ["642_21"] = {spellID = 642, cd = 210, spec =65, talent = 17575}, -- 圣盾术 神圣
  44. ["642_22"] = {spellID = 642, cd = 300, spec =65, talent = 22176}, -- 圣盾术 神圣
  45. ["642_23"] = {spellID = 642, cd = 300, spec =65, talent = 17577}, -- 圣盾术 神圣
  46. ["642_31"] = {spellID = 642, cd = 300, spec =66, talent = "all"}, -- 圣盾术 防护
  47. ["1022_1"] = {spellID = 1022, cd = 240, spec =70, talent = "all"}, -- 保护之手 惩戒
  48. ["1022_2"] = {spellID = 1022, cd = 240, spec =65, talent = "all"}, -- 保护之手 神圣
  49. ["1022_3"] = {spellID = 1022, cd = 300, spec =66, talent = "all"}, -- 保护之手 防护
  50. ["31850"] = {spellID = 31850, cd = 80, spec =66, talent = "all"}, -- 炽热防御者
  51. ["86659"] = {spellID = 86659, cd = 300, spec =66, talent = "all"}, -- 远古列王守卫
  52. },
  53.  
  54. ["MAGE"] = {
  55. ["45438"] = {spellID = 45438, cd = 240, spec ="all", talent = "all"}, -- 寒冰屏障
  56. ["235219"] = {spellID = 235219, cd = 300, spec =64, talent = "all"}, -- 急速冷却
  57. },
  58.  
  59. ["DEMONHUNTER"] = {
  60. ["196555"] = {spellID = 196555, cd = 120, spec = 577, talent = 21863}, -- 虚空行走 浩劫
  61. ["198589"] = {spellID = 198589, cd = 60, spec = 577, talent = "all"}, -- 疾影 浩劫
  62. },
  63.  
  64. ["HUNTER"] = {
  65. ["186265"] = {spellID = 186265, cd = 180, spec = "all", talent = "all"}, -- 灵龟守护
  66. },
  67.  
  68. ["ROGUE"] = {
  69. ["31224"] = {spellID = 31224, cd = 90, spec = "all", talent = "all"}, -- 暗影斗篷
  70. },
  71.  
  72. ["SHAMAN"] = {
  73. ["108271"] = {spellID = 108271, cd = 90, spec = "all", talent = "all"}, -- 星界转移
  74. },
  75.  
  76. ["DRUID"] = {
  77. ["22812_1"] = {spellID = 22812, cd = 60, spec = 102, talent = "all"}, -- 树皮术 鹌鹑
  78. ["22812_2"] = {spellID = 22812, cd = 60, spec = 105, talent = "all"}, -- 树皮术 树
  79. ["22812_3"] = {spellID = 22812, cd = 90, spec = 104, talent = "all"}, -- 树皮术 熊
  80. ["61336_1"] = {spellID = 61336, cd = 120, spec = 103, charge = 2, talent = "all"}, -- 生存本能
  81. ["61336_2"] = {spellID = 61336, cd = 240, spec = 104, charge = 2, talent = "all"}, -- 生存本能
  82.  
  83. },
  84.  
  85. ["PRIEST"] = {
  86. ["47585"] = {spellID = 47585, cd = 80, spec = 258, talent = "all"}, -- 消散
  87. },
  88.  
  89. ["MONK"] = {
  90. ["115203"] = {spellID = 115203, cd = 420, spec = 268, talent = "all"}, -- 壮胆酒
  91. ["122470"] = {spellID = 122470, cd = 90, spec = 269, talent = "all"}, -- 业报之触
  92. ["122783"] = {spellID = 122783, cd = 90, spec = 269, talent = 20173}, -- 散魔功
  93. },
  94.  
  95. ["DEATHKNIGHT"] = {
  96. ["48707"] = {spellID = 48707, cd = 60, spec = "all", talent = "all"}, -- 反魔法护罩
  97. ["48792_1"] = {spellID = 48792, cd = 180, spec = 251, talent = "all"}, -- 冰封之韧
  98. ["48792_2"] = {spellID = 48792, cd = 180, spec = 252, talent = "all"}, -- 冰封之韧
  99. ["55233"] = {spellID = 55233, cd = 90, spec = 250, talent = "all"}, -- 吸血鬼之血
  100. ["49028"] = {spellID = 49028, cd = 180, spec = 250, talent = "all"}, -- 符文刃舞
  101.  
  102. },
  103.  
  104. ["WARRIOR"] = {
  105. ["871"] = {spellID = 871, cd = 240, spec = 73, talent = "all"}, -- 盾墙
  106. ["12975"] = {spellID = 12975, cd = 180, spec = 73, talent = "all"}, -- 破釜沉舟
  107. ["118038"] = {spellID = 118038, cd = 180, spec = 71, talent = "all"}, -- 剑在人在
  108. ["184364"] = {spellID = 184364, cd = 120, spec = 72, talent = "all"}, -- 狂怒回复
  109. },
  110.  
  111. ["WARLOCK"] = {
  112. ["104773_1"] = {spellID = 104773, cd = 60, spec = 267, talent = "all"}, -- 不灭决心
  113. ["104773_2"] = {spellID = 104773, cd = 200, spec = 266, talent = "all"}, -- 不灭决心
  114. ["104773_3"] = {spellID = 104773, cd = 240, spec = 265, talent = "all"}, -- 不灭决心
  115. }
  116.  
  117. }
  118.  
  119. local function CreateIcon(f)
  120. local icon = CreateFrame("Frame", nil, f)
  121. icon:SetSize(SMT_CDB["CD_Icons"]["icon_size"], SMT_CDB["CD_Icons"]["icon_size"])
  122. T.createborder(icon)
  123.  
  124. icon.spellID = 0
  125.  
  126. icon.cd = CreateFrame("Cooldown", nil, icon, "CooldownFrameTemplate")
  127. icon.cd:SetAllPoints(icon)
  128. icon.cd:SetAlpha(.5)
  129. icon.cd:SetScript("OnShow", function()
  130. if not party_cd['Roster'][icon.player_name] or not party_cd['Roster'][icon.player_name][icon.spellID] then return end
  131. if party_cd['Roster'][icon.player_name][icon.spellID]["charge"] then
  132. icon:SetAlpha(1)
  133. else
  134. icon:SetAlpha(SMT_CDB["CD_Icons"]["alpha"]/100)
  135. end
  136. end)
  137. icon.cd:SetScript("OnHide", function()
  138. if party_cd['Roster'][icon.player_name] and party_cd['Roster'][icon.player_name][icon.spellID] and party_cd['Roster'][icon.player_name][icon.spellID]["charge"] then
  139. if party_cd['Roster'][icon.player_name][icon.spellID]["charge"] == party_cd['Roster'][icon.player_name][icon.spellID]["max_charge"] then return end
  140. party_cd['Roster'][icon.player_name][icon.spellID]["charge"] = party_cd['Roster'][icon.player_name][icon.spellID]["charge"] + 1
  141. icon.count:SetText(party_cd['Roster'][icon.player_name][icon.spellID]["charge"])
  142. if party_cd['Roster'][icon.player_name][icon.spellID]["charge"] ~= party_cd['Roster'][icon.player_name][icon.spellID]["max_charge"] then
  143. icon.cd:SetCooldown(GetTime(), party_cd['Roster'][icon.player_name][icon.spellID]["dur"])
  144. end
  145. else
  146. icon:SetAlpha(1)
  147. f.lineup()
  148. end
  149. end)
  150.  
  151. icon.tex = icon:CreateTexture(nil, "OVERLAY")
  152. icon.tex:SetAllPoints(icon)
  153. icon.tex:SetTexCoord( .1, .9, .1, .9)
  154.  
  155. icon.count = T.createtext(icon, "OVERLAY", 16, "OUTLINE", "RIGHT")
  156. icon.count:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", 0, 0)
  157.  
  158. table.insert(f.icons, icon)
  159. end
  160.  
  161. local function GetRemain(Cooldown)
  162. local startTime, duration = Cooldown:GetCooldownTimes()
  163. local remain
  164. if duration == 0 then
  165. remain = 0
  166. else
  167. remain = duration - (GetTime() - startTime)
  168. end
  169. return remain
  170. end
  171.  
  172. local function CreateCDBar(unit)
  173. local f = CreateFrame("Frame", nil, UIParent)
  174. f:SetSize(SMT_CDB["CD_Icons"]["icon_size"], SMT_CDB["CD_Icons"]["icon_size"])
  175. f.icons = {}
  176.  
  177. for i = 1, 6 do
  178. CreateIcon(f)
  179. end
  180.  
  181. f.point = function()
  182. if f.pointlock then return end
  183.  
  184. f.pointlock = true
  185. C_Timer.After(.2, function()
  186.  
  187. f:ClearAllPoints()
  188. local hasGrid = IsAddOnLoaded("Grid")
  189. local hasGrid2 = IsAddOnLoaded("Grid2")
  190. local hasCompactRaid = IsAddOnLoaded("CompactRaid")
  191. local hasVuhDo = IsAddOnLoaded("VuhDo")
  192. local hasElvUI = _G["ElvUF_Raid"] and _G["ElvUF_Raid"]:IsVisible()
  193. local hasElvUI2 = _G["ElvUF_Party"] and _G["ElvUF_Party"]:IsVisible()
  194. local hasAltzUI = _G["Altz_HealerRaid"] and _G["Altz_HealerRaid"]:IsVisible()
  195. local hasNDui = IsAddOnLoaded("NDui")
  196.  
  197. if hasElvUI then
  198. for i=1, 8 do
  199. for j=1, 5 do
  200. local uf = _G["ElvUF_RaidGroup"..i.."UnitButton"..j]
  201. if uf and uf.unit and UnitIsUnit(uf.unit, unit) then
  202. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  203. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  204. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  205. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  206. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  207. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  208. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  209. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  210. end
  211. break
  212. end
  213. end
  214. end
  215. elseif hasElvUI2 then
  216. for i=1, 8 do
  217. for j=1, 5 do
  218. local uf = _G["ElvUF_PartyGroup"..i.."UnitButton"..j]
  219. if uf and uf.unit and UnitIsUnit(uf.unit, unit) then
  220. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  221. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  222. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  223. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  224. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  225. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  226. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  227. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  228. end
  229. break
  230. end
  231. end
  232. end
  233. elseif hasGrid then
  234. local layout = GridLayoutFrame
  235.  
  236. if layout then
  237. local children = {layout:GetChildren()}
  238. for _, child in ipairs(children) do
  239. if child:IsVisible() then
  240. local frames = {child:GetChildren()}
  241. for _, uf in ipairs(frames) do
  242. if uf.unit and UnitIsUnit(uf.unit, unit) then
  243. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  244. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  245. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  246. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  247. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  248. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  249. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  250. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  251. end
  252. break
  253. end
  254. end
  255. end
  256. end
  257. end
  258. elseif hasGrid2 then
  259. local layout = Grid2LayoutFrame
  260.  
  261. if layout then
  262. local children = {layout:GetChildren()}
  263. for _, child in ipairs(children) do
  264. if child:IsVisible() then
  265. local frames = {child:GetChildren()}
  266. for _, uf in ipairs(frames) do
  267. if uf.unit and UnitIsUnit(uf.unit, unit) then
  268. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  269. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  270. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  271. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  272. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  273. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  274. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  275. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  276. end
  277. break
  278. end
  279. end
  280. end
  281. end
  282. end
  283. elseif hasVuhDo then
  284. for i = 1, 40 do
  285. local uf = _G["Vd1H"..i]
  286. if uf and uf.raidid and UnitIsUnit(uf.raidid, unit) then
  287. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  288. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  289. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  290. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  291. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  292. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  293. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  294. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  295. end
  296. break
  297. end
  298. end
  299. elseif hasAltzUI then
  300. for i = 1, 40 do
  301. local uf = _G["Altz_HealerRaidUnitButton"..i]
  302. if uf and uf.unit and UnitIsUnit(uf.unit, unit) then
  303. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  304. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  305. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  306. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  307. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  308. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  309. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  310. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  311. end
  312. break
  313. end
  314. end
  315. elseif hasNDui then
  316. for i =1, 8 do
  317. for j = 1, 5 do
  318. local uf = _G["oUF_Raid"..i.."UnitButton"..j]
  319. if uf and uf.unit and UnitIsUnit(uf.unit, unit) then
  320. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  321. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  322. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  323. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  324. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  325. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  326. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  327. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  328. end
  329. break
  330. end
  331. end
  332. end
  333. elseif hasCompactRaid then
  334. for i =1, 8 do
  335. for j = 1, 5 do
  336. local uf = _G["CompactRaidGroupHeaderSubGroup"..i.."UnitButton"..j]
  337. if uf and uf.unit and UnitIsUnit(uf.unit, unit) then
  338. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  339. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  340. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  341. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  342. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  343. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  344. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  345. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  346. end
  347. break
  348. end
  349. end
  350. end
  351. else
  352. for i=1, 40 do
  353. local uf = _G["CompactRaidFrame"..i]
  354. if uf and uf.unitExists and uf.unit and UnitIsUnit(uf.unit, unit) then
  355. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  356. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  357. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  358. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  359. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  360. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  361. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  362. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  363. end
  364. break
  365. end
  366. end
  367. for i=1, 4 do
  368. for j=1, 5 do
  369. local uf = _G["CompactRaidGroup"..i.."Member"..j]
  370. if uf and uf.unitExists and uf.unit and UnitIsUnit(uf.unit, unit) then
  371. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  372. f:SetPoint("RIGHT", uf, "LEFT", -SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  373. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  374. f:SetPoint("LEFT", uf, "RIGHT", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  375. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  376. f:SetPoint("BOTTOM", uf, "TOP", SMT_CDB["CD_Icons"]["x"], SMT_CDB["CD_Icons"]["y"])
  377. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  378. f:SetPoint("TOP", uf, "BOTTOM", SMT_CDB["CD_Icons"]["x"], -SMT_CDB["CD_Icons"]["y"])
  379. end
  380. break
  381. end
  382. end
  383. end
  384. end
  385.  
  386. f.pointlock = nil
  387.  
  388. end)
  389. end
  390.  
  391. f.reset = function()
  392. for i = 1,6 do
  393. f.icons[i]:Hide()
  394. f.icons[i]["spellID"] = 0
  395. f.icons[i]["tex"]:SetTexture(nil)
  396. f.icons[i]["cd"]:SetCooldown(0,0)
  397. end
  398. end
  399.  
  400. f.update_size = function()
  401. for i = 1,6 do
  402. f.icons[i]:SetSize(SMT_CDB["CD_Icons"]["icon_size"], SMT_CDB["CD_Icons"]["icon_size"])
  403. end
  404. end
  405.  
  406. f.update_unit = function()
  407. f.reset()
  408.  
  409. f.name = UnitName(unit)
  410.  
  411. if f.name then
  412. local spell_num = 0
  413. if party_cd['Roster'][f.name] then
  414. for spellid, info in pairs(party_cd['Roster'][f.name]) do
  415. if spellid ~= "spec" then
  416. spell_num = spell_num + 1
  417. f.icons[spell_num]["spellID"] = spellid
  418. f.icons[spell_num]["player_name"] = f.name
  419. f.icons[spell_num]["tex"]:SetTexture(select(3, GetSpellInfo(spellid)))
  420. if info["charge"] then
  421. f.icons[spell_num]["count"]:SetText(info["charge"])
  422. else
  423. f.icons[spell_num]["count"]:SetText("")
  424. end
  425. f.icons[spell_num]:Show()
  426. end
  427. end
  428. end
  429. end
  430.  
  431. end
  432.  
  433. f.update_cd = function(spellid)
  434. if f.name then
  435. if spellid then
  436. for i = 1, 6 do
  437. if f.icons[i]["spellID"] == spellid and party_cd['Roster'][f.name][spellid] then
  438. local info = party_cd['Roster'][f.name][spellid]
  439. if info["start"] and info["start"] + info["dur"] > GetTime() then
  440. if party_cd['Roster'][f.name][spellid]["charge"] then
  441. if party_cd['Roster'][f.name][spellid]["charge"] == party_cd['Roster'][f.name][spellid]["max_charge"] then
  442. f.icons[i]["cd"]:SetCooldown(info["start"], info["dur"])
  443. end
  444. party_cd['Roster'][f.name][spellid]["charge"] = party_cd['Roster'][f.name][spellid]["charge"] - 1
  445. f.icons[i]["count"]:SetText(party_cd['Roster'][f.name][spellid]["charge"])
  446. if party_cd['Roster'][f.name][spellid]["charge"] == 0 then
  447. f.icons[i]:SetAlpha(SMT_CDB["CD_Icons"]["alpha"]/100)
  448. end
  449. else
  450. f.icons[i]["cd"]:SetCooldown(info["start"], info["dur"])
  451. f.icons[i]["count"]:SetText("")
  452. end
  453. else
  454. f.icons[i]["cd"]:SetCooldown(0,0)
  455. end
  456. break
  457. end
  458.  
  459. end
  460. else
  461. for i = 1, 6 do
  462. local icon_spellid = f.icons[i]["spellID"]
  463. if icon_spellid ~= 0 and party_cd['Roster'][f.name][icon_spellid] then
  464. local info = party_cd['Roster'][f.name][icon_spellid]
  465. if info["start"] and info["start"] + info["dur"] > GetTime() then
  466. f.icons[i]["cd"]:SetCooldown(info["start"], info["dur"])
  467. end
  468. end
  469. end
  470. end
  471. end
  472. end
  473.  
  474. f.lineup = function()
  475. if not IsInGroup() then return end
  476.  
  477. table.sort(f.icons, function(a,b)
  478. --if not a.cd or b.cd then return end
  479. if a.spellID ~= 0 and b.spellID ~= 0 then
  480. if GetRemain(a.cd) < GetRemain(b.cd) then
  481. return true
  482. elseif GetRemain(a.cd) == GetRemain(b.cd) and a.spellID < b.spellID then
  483. return true
  484. end
  485. elseif a.spellID ~= 0 and b.spellID == 0 then
  486. return true
  487. end
  488. end)
  489.  
  490. for i = 1,6 do
  491. f.icons[i]:ClearAllPoints()
  492.  
  493. if SMT_CDB["CD_Icons"]["grow_dir"] == "RIGHT" then
  494. f.icons[i]:SetPoint("RIGHT", f, "RIGHT", -(i-1)*(SMT_CDB["CD_Icons"]["icon_size"]+SMT_CDB["CD_Icons"]["icon_space"]), 0)
  495. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "LEFT" then
  496. f.icons[i]:SetPoint("LEFT", f, "LEFT", (i-1)*(SMT_CDB["CD_Icons"]["icon_size"]+SMT_CDB["CD_Icons"]["icon_space"]), 0)
  497. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "TOP" then
  498. f.icons[i]:SetPoint("TOP", f, "TOP", 0, (i-1)*(SMT_CDB["CD_Icons"]["icon_size"]+SMT_CDB["CD_Icons"]["icon_space"]))
  499. elseif SMT_CDB["CD_Icons"]["grow_dir"] == "BOTTOM" then
  500. f.icons[i]:SetPoint("BOTTOM", f, "BOTTOM", 0, -(i-1)*(SMT_CDB["CD_Icons"]["icon_size"]+SMT_CDB["CD_Icons"]["icon_space"]))
  501. end
  502.  
  503.  
  504. if f.icons[i].spellID ~= 0 and i<= SMT_CDB["CD_Icons"]["icon_num"] then
  505. f.icons[i]:Show()
  506. else
  507. f.icons[i]:Hide()
  508. end
  509. end
  510. end
  511.  
  512. table.insert(party_cd.Frames, f)
  513. end
  514.  
  515. local function UpdateCDBar(tag)
  516. for i = 1, #party_cd.Frames do
  517. local f = party_cd.Frames[i]
  518. if tag == "all" or tag == "unit" then
  519. f.update_unit()
  520. f.point()
  521. end
  522.  
  523. if tag == "all" or tag == "cd" then
  524. f.update_cd()
  525. f.lineup()
  526. end
  527. end
  528. end
  529.  
  530. local function UpdateCD(name, spellID)
  531. for i = 1, #party_cd.Frames do
  532. local f = party_cd.Frames[i]
  533. if f.name and f.name == name then
  534. f.update_cd(spellID)
  535. f.lineup()
  536. end
  537. end
  538. end
  539.  
  540. T.EditCDBar = function(tag)
  541. for i = 1, #party_cd.Frames do
  542. local f = party_cd.Frames[i]
  543.  
  544. if tag == "show" then
  545. if not SMT_CDB["General"]["disable_all"] and SMT_CDB["CD_Icons"]["enable"] and not (IsInRaid() and SMT_CDB["CD_Icons"]["hide_in_raid"]) then
  546. f:Show()
  547. else
  548. f:Hide()
  549. end
  550. elseif tag == "size" then
  551. f.update_size()
  552. f.lineup()
  553. elseif tag == "pos" then
  554. f.point()
  555. f.lineup()
  556. elseif tag == "alpha" then
  557. for i = 1,6 do
  558. if f.icons[i].cd:GetCooldownDuration() > 0 then
  559. f.icons[i]:SetAlpha(SMT_CDB["CD_Icons"]["alpha"]/100)
  560. end
  561. end
  562. end
  563. end
  564. end
  565.  
  566. function party_cd:OnUpdate(unit, info)
  567. if not info.name or not info.class or not info.global_spec_id or not info.talents then return end
  568.  
  569. if DefensiveSpells[info.class] then
  570. if UnitInParty(info.name) then
  571. if not party_cd['Roster'][info.name] or party_cd['Roster'][info.name]["spec"] ~= info.global_spec_id then
  572. party_cd['Roster'][info.name] = {}
  573. party_cd['Roster'][info.name]["spec"] = info.global_spec_id
  574.  
  575. for tag, spell_info in pairs (DefensiveSpells[info.class]) do
  576. if (spell_info.spec == "all" or spell_info.spec == info.global_spec_id) and (spell_info.talent == "all" or info.talents[spell_info.talent]) then
  577. party_cd['Roster'][info.name][spell_info.spellID] = {}
  578. party_cd['Roster'][info.name][spell_info.spellID]["dur"] = spell_info.cd
  579. party_cd['Roster'][info.name][spell_info.spellID]["tag"] = tag
  580. party_cd['Roster'][info.name][spell_info.spellID]["max_charge"] = spell_info.charge
  581. party_cd['Roster'][info.name][spell_info.spellID]["charge"] = spell_info.charge
  582. end
  583. end
  584. end
  585. UpdateCDBar("all")
  586. elseif party_cd['Roster'][info.name] then
  587.  
  588. party_cd['Roster'][info.name] = nil
  589. UpdateCDBar("all")
  590.  
  591. end
  592. end
  593. end
  594.  
  595. function party_cd:OnRemove(guid)
  596. if (guid) then
  597. local name = select(6, GetPlayerInfoByGUID(guid))
  598. if party_cd['Roster'][name] then
  599. party_cd['Roster'][name] = nil
  600. UpdateCDBar("all")
  601. end
  602. else
  603. party_cd['Roster'] = {}
  604. UpdateCDBar("all")
  605. end
  606. end
  607.  
  608. local LGIST = LibStub:GetLibrary("LibGroupInSpecT-1.1")
  609.  
  610. function party_cd:OnInitialize()
  611. LGIST.RegisterCallback (party_cd, "GroupInSpecT_Update", function(event, ...)
  612. party_cd.OnUpdate(...)
  613. end)
  614. LGIST.RegisterCallback (party_cd, "GroupInSpecT_Remove", function(...)
  615. party_cd.OnRemove(...)
  616. end)
  617. end
  618.  
  619. local Group_Update = CreateFrame("Frame")
  620. Group_Update:RegisterEvent("PLAYER_ENTERING_WORLD")
  621.  
  622. local function ResetCD()
  623. for player, spells in pairs(party_cd['Roster']) do
  624. for spellid, info in pairs(party_cd['Roster'][player]) do
  625. if spellid ~= "spec" then
  626. party_cd['Roster'][player][spellid]["start"] = 0
  627. end
  628. end
  629. end
  630. end
  631.  
  632. Group_Update:SetScript("OnEvent", function(self, event, ...)
  633. if event == "PLAYER_ENTERING_WORLD" then
  634.  
  635. CreateCDBar("party1")
  636. CreateCDBar("party2")
  637. CreateCDBar("party3")
  638. CreateCDBar("party4")
  639. CreateCDBar("player")
  640. --ResetCD()
  641. T.EditCDBar("show")
  642. UpdateCDBar("all")
  643.  
  644. Group_Update:UnregisterEvent("PLAYER_ENTERING_WORLD")
  645. Group_Update:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  646. Group_Update:RegisterEvent("ENCOUNTER_END")
  647. Group_Update:RegisterEvent("GROUP_ROSTER_UPDATE")
  648.  
  649. elseif event == "ENCOUNTER_END" then
  650.  
  651. --ResetCD()
  652. UpdateCDBar("cd")
  653.  
  654. elseif event == "GROUP_ROSTER_UPDATE" then
  655. T.EditCDBar("show")
  656. UpdateCDBar("all")
  657.  
  658. elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
  659.  
  660. local _, event_type, _, sourceGUID, sourceName, _, _, _, _, _, _, spellID = ...
  661.  
  662. if not sourceName or not spellID then return end
  663. local name = string.split("-", sourceName)
  664. if event_type == "SPELL_CAST_SUCCESS" and party_cd['Roster'][name] then
  665. if party_cd['Roster'][name][spellID] then
  666. party_cd['Roster'][name][spellID]["start"] = GetTime()
  667. UpdateCD(name, spellID)
  668. end
  669. if spellID == 235219 then -- 急速冷却
  670. party_cd['Roster'][name][45438]["start"] = 0 -- 寒冰屏障
  671. UpdateCD(name, 45438)
  672. elseif spellID == 191427 then -- 恶魔变形
  673. local info = LGIST:GetCachedInfo (sourceGUID)
  674. if info.talents[22767] then -- 恶魔重生
  675. party_cd['Roster'][name][198589]["start"] = 0 -- 疾影
  676. UpdateCD(name, 198589)
  677. end
  678. end
  679. end
  680.  
  681. end
  682. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement