EllieRThorpe

Untitled

Jan 16th, 2025 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 86.28 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. -- Kui Nameplates
  3. -- By Kesava at curse.com
  4. -- All rights reserved
  5. --------------------------------------------------------------------------------
  6. -- layout's create/update/callback functions
  7. --------------------------------------------------------------------------------
  8. local addon = KuiNameplates
  9. local kui = LibStub('Kui-1.0')
  10. local LSM = LibStub('LibSharedMedia-3.0')
  11. local KSL = LibStub('KuiSpellList-2.0')
  12. local core = KuiNameplatesCore --luacheck:globals KuiNameplatesCore
  13.  
  14. -- associative tables used by config
  15. core.POINT_ASSOC = {
  16. 'TOPLEFT','LEFT','BOTTOMLEFT',
  17. 'TOP','CENTER','BOTTOM',
  18. 'TOPRIGHT','RIGHT','BOTTOMRIGHT'
  19. }
  20. core.JUSTIFY_ASSOC = { 'LEFT','CENTER','RIGHT' }
  21. local POINT_ASSOC = core.POINT_ASSOC
  22. local JUSTIFY_ASSOC = core.JUSTIFY_ASSOC
  23.  
  24. -- frame fading plugin - called by some update functions
  25. local plugin_fading
  26. -- class powers plugin - called by NameOnlyUpdateFunctions
  27. local plugin_classpowers
  28.  
  29. -- common globals
  30. local UnitIsPlayer,UnitShouldDisplayName,
  31. strlen,format,pairs,ipairs,floor,ceil,unpack =
  32. UnitIsPlayer,UnitShouldDisplayName,
  33. strlen,format,pairs,ipairs,floor,ceil,unpack
  34.  
  35. local KUI_MEDIA = 'interface/addons/kui_media/'
  36. local MEDIA = 'interface/addons/kui_nameplates_core/media/'
  37.  
  38. local FRAME_WIDTH,FRAME_HEIGHT,FRAME_WIDTH_MINUS,FRAME_HEIGHT_MINUS,
  39. FRAME_WIDTH_PERSONAL,FRAME_HEIGHT_PERSONAL,FRAME_WIDTH_TARGET,
  40. FRAME_HEIGHT_TARGET,POWER_BAR_HEIGHT,FONT,FONT_STYLE,FONT_SHADOW,
  41. FONT_SIZE_NORMAL,FONT_SIZE_SMALL,NAME_VERTICAL_OFFSET,
  42. BOT_VERTICAL_OFFSET,BAR_TEXTURE,BAR_ANIMATION,
  43. SHOW_HEALTH_TEXT,SHOW_NAME_TEXT,SHOW_ARENA_ID,GUILD_TEXT_NPCS,
  44. GUILD_TEXT_PLAYERS,TITLE_TEXT_PLAYERS,HEALTH_TEXT_FRIEND_MAX,
  45. HEALTH_TEXT_FRIEND_DMG,HEALTH_TEXT_HOSTILE_MAX,HEALTH_TEXT_HOSTILE_DMG,
  46. HIDE_NAMES,FRAME_VERTICAL_OFFSET,
  47. MOUSEOVER_HIGHLIGHT,HIGHLIGHT_OPACITY,LEVEL_TEXT,LEVEL_NAMEONLY,
  48. HEALTH_TEXT_PERCENT_SYMBOL,FRAME_TARGET_SIZE,
  49. FRAME_MINUS_SIZE,BAR_SPARK
  50. local FADE_UNTRACKED,FADE_AVOID_NAMEONLY,FADE_AVOID_MOUSEOVER,
  51. FADE_AVOID_TRACKED,FADE_AVOID_COMBAT,FADE_AVOID_CASTING
  52. local TARGET_ARROWS,TARGET_ARROWS_SIZE,TARGET_ARROWS_INSET,TARGET_ARROWS_TEXTURE
  53. local TARGET_GLOW,TARGET_GLOW_COLOUR,FRAME_GLOW_THREAT,FRAME_GLOW_SIZE,
  54. GLOW_AS_SHADOW,MOUSEOVER_GLOW,MOUSEOVER_GLOW_COLOUR,
  55. FRAME_GLOW_SIZE_TARGET,FRAME_GLOW_SIZE_THREAT
  56. local THREAT_BRACKETS,THREAT_BRACKETS_SIZE
  57. local CASTBAR_DETACH,CASTBAR_MATCH_FRAME_WIDTH
  58. local CLASSPOWERS_ON_FRIENDS,CLASSPOWERS_ON_ENEMIES,CLASSPOWERS_Y
  59.  
  60. -- helper functions ############################################################
  61. local CreateStatusBar
  62. do
  63. local function FadeSpark(bar)
  64. local val,max = bar:GetValue(),select(2,bar:GetMinMaxValues())
  65. local show_val = (max / 100) * 80
  66.  
  67. if val <= 0 or val >= max then
  68. bar.spark:Hide()
  69. elseif val < show_val then
  70. bar.spark:SetAlpha(1)
  71. bar.spark:Show()
  72. else
  73. bar.spark:SetAlpha(1 - ((val - show_val) / (max - show_val)))
  74. bar.spark:Show()
  75. end
  76. end
  77.  
  78. local function FilledBar_SetStatusBarColor(self,r,g,b,a)
  79. self:orig_SetStatusBarColor(r,g,b,a)
  80.  
  81. if self.fill then
  82. self.fill:SetVertexColor(r,g,b)
  83. end
  84.  
  85. if self.spark then
  86. self.spark:SetVertexColor(kui.Brighten(.3,r,g,b,a))
  87. end
  88. end
  89. local function FilledBar_Show(self)
  90. self:orig_Show()
  91. self.fill:Show()
  92. end
  93. local function FilledBar_Hide(self)
  94. self:orig_Hide()
  95. self.fill:Hide()
  96. end
  97.  
  98. function CreateStatusBar(parent,spark,no_fill,no_fade_spark,spark_level)
  99. local bar = CreateFrame('StatusBar',nil,parent)
  100. bar:SetStatusBarTexture(BAR_TEXTURE)
  101. bar:SetFrameLevel(0)
  102.  
  103. if not no_fill then
  104. local fill = bar:CreateTexture(nil,'BACKGROUND',nil,2)
  105. fill:SetTexture(BAR_TEXTURE)
  106. fill:SetAllPoints(bar)
  107. fill:SetAlpha(.2)
  108.  
  109. bar.fill = fill
  110.  
  111. bar.orig_Show = bar.Show
  112. bar.Show = FilledBar_Show
  113.  
  114. bar.orig_Hide = bar.Hide
  115. bar.Hide = FilledBar_Hide
  116. end
  117.  
  118. if spark then
  119. local texture = bar:GetStatusBarTexture()
  120. spark = bar:CreateTexture(nil,'ARTWORK',nil,spark_level or 3)
  121. spark:SetTexture(KUI_MEDIA..'t/spark')
  122. spark:SetWidth(12)
  123.  
  124. spark:SetPoint('TOP',texture,'TOPRIGHT',-1,4)
  125. spark:SetPoint('BOTTOM',texture,'BOTTOMRIGHT',-1,-4)
  126.  
  127. bar.spark = spark
  128.  
  129. if not no_fade_spark then
  130. bar:HookScript('OnValueChanged',FadeSpark)
  131. bar:HookScript('OnMinMaxChanged',FadeSpark)
  132. end
  133. end
  134.  
  135. if not no_fill or spark then
  136. bar.orig_SetStatusBarColor = bar.SetStatusBarColor
  137. bar.SetStatusBarColor = FilledBar_SetStatusBarColor
  138. end
  139.  
  140. return bar
  141. end
  142. end
  143. local function UpdateFontObject(object)
  144. if not object then return end
  145. object:SetFont(
  146. FONT,
  147. object.fontobject_size or (object.fontobject_small and
  148. FONT_SIZE_SMALL or FONT_SIZE_NORMAL),
  149. not object.fontobject_no_style and FONT_STYLE or nil
  150. )
  151.  
  152. if object.fontobject_shadow or FONT_SHADOW then
  153. object:SetShadowColor(0,0,0,1)
  154. object:SetShadowOffset(1,-1)
  155. else
  156. object:SetShadowColor(0,0,0,0)
  157. end
  158. end
  159. local function CreateFontString(parent,small)
  160. local f = parent:CreateFontString(nil,'OVERLAY')
  161. f.fontobject_small = small
  162. f:SetWordWrap(false)
  163.  
  164. UpdateFontObject(f)
  165.  
  166. return f
  167. end
  168. local function ScaleTextOffset(v)
  169. return floor(core:Scale(v)) - .5
  170. end
  171. -- config functions ############################################################
  172. do
  173. local FONT_STYLE_ASSOC = {
  174. '',
  175. 'THINOUTLINE',
  176. '',
  177. 'THINOUTLINE',
  178. 'THINOUTLINE MONOCHROME'
  179. }
  180. local ANIM_ASSOC = {
  181. nil,'smooth','cutaway'
  182. }
  183. local function UpdateMediaLocals()
  184. core.BAR_TEXTURE = LSM:Fetch(LSM.MediaType.STATUSBAR,core.profile.bar_texture) or kui.m.t.bar
  185. core.FONT = LSM:Fetch(LSM.MediaType.FONT,core.profile.font_face) or kui.m.f.roboto
  186. BAR_TEXTURE = core.BAR_TEXTURE
  187. FONT = core.FONT
  188. end
  189. local function p1()
  190. BAR_ANIMATION = ANIM_ASSOC[core.profile.bar_animation]
  191.  
  192. TARGET_ARROWS = core.profile.target_arrows
  193. TARGET_ARROWS_SIZE = core:Scale(core.profile.target_arrows_size)
  194. TARGET_ARROWS_INSET = core:Scale(core.profile.target_arrows_inset)
  195. TARGET_ARROWS_TEXTURE = core.profile.target_arrows_texture
  196.  
  197. TARGET_GLOW = core.profile.target_glow
  198. TARGET_GLOW_COLOUR = core.profile.target_glow_colour
  199. MOUSEOVER_GLOW = core.profile.mouseover_glow
  200. MOUSEOVER_GLOW_COLOUR = core.profile.mouseover_glow_colour
  201. MOUSEOVER_HIGHLIGHT = core.profile.mouseover_highlight
  202. HIGHLIGHT_OPACITY = core.profile.mouseover_highlight_opacity
  203. GLOW_AS_SHADOW = core.profile.glow_as_shadow
  204.  
  205. THREAT_BRACKETS = core.profile.threat_brackets
  206. THREAT_BRACKETS_SIZE = core:Scale(core.profile.threat_brackets_size)
  207.  
  208. FRAME_WIDTH = core:Scale(core.profile.frame_width)
  209. FRAME_HEIGHT = core:Scale(core.profile.frame_height)
  210. FRAME_WIDTH_MINUS = core:Scale(core.profile.frame_width_minus)
  211. FRAME_HEIGHT_MINUS = core:Scale(core.profile.frame_height_minus)
  212. FRAME_WIDTH_PERSONAL = core:Scale(core.profile.frame_width_personal)
  213. FRAME_HEIGHT_PERSONAL = core:Scale(core.profile.frame_height_personal)
  214. FRAME_WIDTH_TARGET = core:Scale(core.profile.frame_width_target)
  215. FRAME_HEIGHT_TARGET = core:Scale(core.profile.frame_height_target)
  216. POWER_BAR_HEIGHT = core:Scale(core.profile.powerbar_height)
  217. FRAME_VERTICAL_OFFSET = core.profile.frame_vertical_offset
  218. FRAME_TARGET_SIZE = core.profile.frame_target_size
  219. FRAME_MINUS_SIZE = core.profile.frame_minus_size
  220.  
  221. LEVEL_TEXT = core.profile.level_text
  222. LEVEL_NAMEONLY = core.profile.level_nameonly
  223.  
  224. FRAME_GLOW_SIZE = core:Scale(core.profile.frame_glow_size_shadow)
  225. FRAME_GLOW_THREAT = core.profile.frame_glow_threat
  226. FRAME_GLOW_SIZE_TARGET = core:Scale(core.profile.frame_glow_size_target)
  227. FRAME_GLOW_SIZE_THREAT = core:Scale(core.profile.frame_glow_size_threat)
  228.  
  229. NAME_VERTICAL_OFFSET = ScaleTextOffset(core.profile.name_vertical_offset)
  230. BOT_VERTICAL_OFFSET = ScaleTextOffset(core.profile.bot_vertical_offset)
  231.  
  232. FONT_STYLE = FONT_STYLE_ASSOC[core.profile.font_style]
  233. FONT_SHADOW = core.profile.font_style == 3 or core.profile.font_style == 4
  234. FONT_SIZE_NORMAL = core:Scale(core.profile.font_size_normal)
  235. FONT_SIZE_SMALL = core:Scale(core.profile.font_size_small)
  236.  
  237. BAR_SPARK = core.profile.bar_spark
  238. end
  239. local function p2()
  240. FADE_UNTRACKED = core.profile.fade_untracked
  241. FADE_AVOID_NAMEONLY = core.profile.fade_avoid_nameonly
  242. FADE_AVOID_MOUSEOVER = core.profile.fade_avoid_mouseover
  243. FADE_AVOID_TRACKED = core.profile.fade_avoid_tracked
  244. FADE_AVOID_COMBAT = core.profile.fade_avoid_combat
  245. FADE_AVOID_CASTING =
  246. (core.profile.fade_avoid_casting_friendly
  247. or core.profile.fade_avoid_casting_hostile) and
  248. (core.profile.fade_avoid_casting_interruptible or
  249. core.profile.fade_avoid_casting_uninterruptible)
  250.  
  251. SHOW_HEALTH_TEXT = core.profile.health_text
  252. SHOW_NAME_TEXT = core.profile.name_text
  253. SHOW_ARENA_ID = core.profile.show_arena_id
  254. HIDE_NAMES = core.profile.hide_names
  255.  
  256. HEALTH_TEXT_FRIEND_MAX = core.profile.health_text_friend_max
  257. HEALTH_TEXT_FRIEND_DMG = core.profile.health_text_friend_dmg
  258. HEALTH_TEXT_HOSTILE_MAX = core.profile.health_text_hostile_max
  259. HEALTH_TEXT_HOSTILE_DMG = core.profile.health_text_hostile_dmg
  260. HEALTH_TEXT_PERCENT_SYMBOL = core.profile.health_text_percent_symbol and '%' or ''
  261.  
  262. GUILD_TEXT_NPCS = core.profile.guild_text_npcs
  263. GUILD_TEXT_PLAYERS = core.profile.guild_text_players
  264. TITLE_TEXT_PLAYERS = core.profile.title_text_players
  265.  
  266. CASTBAR_DETACH = core.profile.castbar_detach
  267. CASTBAR_MATCH_FRAME_WIDTH = core.profile.castbar_detach_match_frame_width
  268.  
  269. CLASSPOWERS_ON_FRIENDS = core.profile.classpowers_on_friends
  270. CLASSPOWERS_ON_ENEMIES = core.profile.classpowers_on_enemies
  271. CLASSPOWERS_Y = core:Scale(core.profile.classpowers_y)
  272. end
  273. function core:SetLocals()
  274. -- set config locals to reduce table lookup
  275. -- yes this is a bit extreme isn't it
  276. UpdateMediaLocals()
  277. p1()
  278. p2()
  279. end
  280. function core:LSMMediaRegistered(_,mediatype,key)
  281. -- callback registered in config.lua:InitialiseConfig
  282. if mediatype == LSM.MediaType.STATUSBAR and key == self.profile.bar_texture or
  283. mediatype == LSM.MediaType.FONT and key == self.profile.font_face
  284. then
  285. UpdateMediaLocals()
  286. end
  287. end
  288. end
  289. function core:configChangedTargetArrows()
  290. if not TARGET_ARROWS then return end
  291. for _,f in addon:Frames() do
  292. self:CreateTargetArrows(f)
  293. end
  294. end
  295. function core:configChangedFrameSize()
  296. for _,f in addon:Frames() do
  297. if f.Auras and f.Auras.frames then
  298. -- force auras frame size + position update
  299. if f.Auras.frames.core_dynamic then
  300. f.Auras.frames.core_dynamic.__width = nil
  301. end
  302. if f.Auras.frames.core_purge then
  303. f.Auras.frames.core_purge.__width = nil
  304. end
  305. end
  306. end
  307. end
  308. function core:configChangedTextOffset()
  309. for _,f in addon:Frames() do
  310. f:UpdateSpellNamePosition()
  311.  
  312. if f.Auras and f.Auras.frames then
  313. -- update aura text
  314. for _,frame in pairs(f.Auras.frames) do
  315. for _,button in ipairs(frame.buttons) do
  316. self.Auras_PostCreateAuraButton(frame,button)
  317. end
  318. end
  319. end
  320. end
  321. end
  322. function core:configChangedFontOption()
  323. -- update font objects
  324. for _,f in addon:Frames() do
  325. UpdateFontObject(f.NameText)
  326. UpdateFontObject(f.GuildText)
  327. UpdateFontObject(f.SpellName)
  328. UpdateFontObject(f.HealthText)
  329. UpdateFontObject(f.LevelText)
  330.  
  331. if f.Auras and f.Auras.frames then
  332. for _,frame in pairs(f.Auras.frames) do
  333. for _,button in ipairs(frame.buttons) do
  334. self.AurasButton_SetFont(button)
  335. end
  336. end
  337. end
  338. end
  339. end
  340. do
  341. local function UpdateStatusBar(object)
  342. if not object then return end
  343. if object.SetStatusBarTexture then
  344. object:SetStatusBarTexture(BAR_TEXTURE)
  345. UpdateStatusBar(object.fill)
  346. elseif object.SetTexture then
  347. object:SetTexture(BAR_TEXTURE)
  348. end
  349. end
  350. function core:configChangedBarTexture()
  351. for _,f in addon:Frames() do
  352. UpdateStatusBar(f.CastBar)
  353. UpdateStatusBar(f.Highlight)
  354. UpdateStatusBar(f.HealthBar)
  355. UpdateStatusBar(f.PowerBar)
  356.  
  357. if f.UpdateAbsorbBar then
  358. f:UpdateAbsorbBar()
  359. end
  360. end
  361.  
  362. if addon.ClassPowersFrame then
  363. UpdateStatusBar(addon.ClassPowersFrame.bar)
  364. self.ClassPowers.bar_texture = BAR_TEXTURE
  365. end
  366. end
  367. end
  368. function core:SetBarAnimation()
  369. for _,f in addon:Frames() do
  370. f.handler:SetBarAnimation(f.HealthBar,BAR_ANIMATION)
  371. f.handler:SetBarAnimation(f.PowerBar,BAR_ANIMATION)
  372.  
  373. if BAR_ANIMATION == 'smooth' then
  374. f.handler:SetBarAnimation(f.AbsorbBar,BAR_ANIMATION)
  375. else
  376. f.handler:SetBarAnimation(f.AbsorbBar,nil)
  377. end
  378. end
  379. end
  380. -- #############################################################################
  381. -- create/update functions #####################################################
  382. -- frame background ############################################################
  383. local function UpdateFrameSize(f)
  384. -- set frame size and position
  385. if f.state.personal then
  386. f:SetSize(FRAME_WIDTH_PERSONAL,FRAME_HEIGHT_PERSONAL)
  387. elseif FRAME_TARGET_SIZE and f.state.target then
  388. f:SetSize(FRAME_WIDTH_TARGET,FRAME_HEIGHT_TARGET)
  389. elseif FRAME_MINUS_SIZE and f.state.minus then
  390. f:SetSize(FRAME_WIDTH_MINUS,FRAME_HEIGHT_MINUS)
  391. else
  392. f:SetSize(FRAME_WIDTH,FRAME_HEIGHT)
  393. end
  394.  
  395. f:SetPoint('CENTER',0,FRAME_VERTICAL_OFFSET)
  396.  
  397. f:UpdateMainBars()
  398. f:SpellIconSetWidth()
  399. f:UpdateAuras()
  400.  
  401. if CASTBAR_MATCH_FRAME_WIDTH then
  402. f:UpdateCastbarSize()
  403. end
  404. end
  405. function core:CreateBackground(f)
  406. local bg = f:CreateTexture(nil,'BACKGROUND',nil,1)
  407. bg:SetTexture(kui.m.t.solid)
  408. bg:SetVertexColor(0,0,0,.9)
  409. bg:SetAllPoints(f)
  410.  
  411. -- in UpdateFrameSize,
  412. -- we override the frame position + size to use it as the background
  413. f:ClearAllPoints()
  414.  
  415. f.bg = bg
  416. f.UpdateFrameSize = UpdateFrameSize
  417. end
  418. -- highlight ###################################################################
  419. do
  420. local function UpdateHighlight(f)
  421. if MOUSEOVER_HIGHLIGHT then
  422. if not f.Highlight then
  423. core:CreateHighlight(f)
  424. end
  425.  
  426. f.Highlight:SetVertexColor(1,1,1,HIGHLIGHT_OPACITY)
  427. f.handler:EnableElement('Highlight')
  428. elseif f.Highlight and f.elements.Highlight then
  429. f.handler:DisableElement('Highlight')
  430. end
  431.  
  432. -- functions which depend on f.state.glow from Highlight
  433. -- (which is set regardless of the element being enabled)
  434. if MOUSEOVER_GLOW then
  435. f:UpdateFrameGlow()
  436. end
  437. if FADE_AVOID_MOUSEOVER then
  438. plugin_fading:UpdateFrame(f)
  439. end
  440. end
  441. function core:CreateHighlight(f)
  442. f.UpdateHighlight = UpdateHighlight
  443.  
  444. if not MOUSEOVER_HIGHLIGHT then return end
  445.  
  446. local highlight = f.HealthBar:CreateTexture(nil,'ARTWORK',nil,2)
  447. highlight:SetTexture(BAR_TEXTURE)
  448. highlight:SetAllPoints(f.HealthBar)
  449. highlight:SetBlendMode('ADD')
  450. highlight:Hide()
  451.  
  452. f.handler:RegisterElement('Highlight',highlight)
  453. end
  454. end
  455. -- health bar ##################################################################
  456. do
  457. local function UpdateMainBars(f)
  458. -- update health/power bar size
  459. local hb_height = f.bg:GetHeight()-2
  460.  
  461. if f.PowerBar:IsShown() then
  462. local pb_height = POWER_BAR_HEIGHT
  463.  
  464. if pb_height >= (hb_height-1) then
  465. -- reduce height so that healthbar is at least 1 pixel
  466. pb_height = hb_height - 2
  467. end
  468.  
  469. hb_height = (hb_height-pb_height)-1
  470. f.PowerBar:SetHeight(pb_height)
  471. end
  472.  
  473. f.HealthBar:SetHeight(hb_height)
  474. end
  475. function core:CreateHealthBar(f)
  476. local healthbar = CreateStatusBar(f,BAR_SPARK)
  477.  
  478. healthbar:SetPoint('TOPLEFT',f.bg,1,-1)
  479. healthbar:SetPoint('RIGHT',f.bg,-1,0)
  480.  
  481. f.handler:SetBarAnimation(healthbar,BAR_ANIMATION)
  482. f.handler:RegisterElement('HealthBar',healthbar)
  483.  
  484. f.UpdateMainBars = UpdateMainBars
  485. end
  486. end
  487. -- power bar ###################################################################
  488. do
  489. local function UpdatePowerBar(f,on_show)
  490. if f.state.personal and
  491. f.state.power_type
  492. and UnitPowerMax(f.unit,f.state.power_type) > 0
  493. then
  494. f.handler:EnableElement('PowerBar')
  495. else
  496. f.handler:DisableElement('PowerBar')
  497. end
  498.  
  499. if not on_show then
  500. -- update health bar height
  501. f:UpdateMainBars()
  502. end
  503. end
  504. function core:CreatePowerBar(f)
  505. local powerbar = CreateStatusBar(f.HealthBar,BAR_SPARK)
  506. powerbar:SetPoint('TOPLEFT',f.HealthBar,'BOTTOMLEFT',0,-1)
  507. powerbar:SetPoint('RIGHT',f.bg,-1,0)
  508.  
  509. f.handler:SetBarAnimation(powerbar,BAR_ANIMATION)
  510. f.handler:RegisterElement('PowerBar',powerbar)
  511.  
  512. f.UpdatePowerBar = UpdatePowerBar
  513. end
  514. end
  515. -- absorb bar ##################################################################
  516. do
  517. local ABSORB_ENABLE,ABSORB_STRIPED,ABSORB_COLOUR
  518.  
  519. function core:configChangedAbsorb()
  520. ABSORB_ENABLE = not kui.CLASSIC and self.profile.absorb_enable
  521. ABSORB_STRIPED = self.profile.absorb_striped
  522. ABSORB_COLOUR = self.profile.colour_absorb
  523.  
  524. if ABSORB_ENABLE then
  525. for _,f in addon:Frames() do
  526. if not f.AbsorbBar then
  527. self:CreateAbsorbBar(f)
  528. else
  529. f:UpdateAbsorbBar()
  530. end
  531. end
  532. end
  533. end
  534.  
  535. local function UpdateAbsorbBar(f)
  536. if not ABSORB_ENABLE then return end
  537. if ABSORB_STRIPED then
  538. f.AbsorbBar.t:SetTexture(kui.m.t.stripebar,true,true)
  539. f.AbsorbBar.t:SetHorizTile(true)
  540. f.AbsorbBar.t:SetVertTile(true)
  541. else
  542. f.AbsorbBar.t:SetTexture(BAR_TEXTURE,false,false)
  543. f.AbsorbBar.t:SetHorizTile(false)
  544. f.AbsorbBar.t:SetVertTile(false)
  545. end
  546.  
  547. f.AbsorbBar.t:SetDrawLayer('ARTWORK',1)
  548. f.AbsorbBar:SetStatusBarColor(unpack(ABSORB_COLOUR))
  549. f.AbsorbBar.spark:SetVertexColor(unpack(ABSORB_COLOUR))
  550. f.AbsorbBar.spark:SetAlpha(1)
  551. end
  552. function core:CreateAbsorbBar(f)
  553. if not ABSORB_ENABLE then return end
  554.  
  555. local bar = CreateStatusBar(f.HealthBar,nil,true)
  556. bar:SetAllPoints(f.HealthBar)
  557.  
  558. bar.t = bar:CreateTexture(nil,'ARTWORK')
  559. bar:SetStatusBarTexture(bar.t)
  560.  
  561. -- spark for over-absorb highlighting
  562. local spark = bar:CreateTexture(nil,'ARTWORK',nil,7)
  563. spark:SetTexture(KUI_MEDIA..'t/spark')
  564. spark:SetWidth(12)
  565. spark:SetPoint('TOP',bar,'TOPRIGHT',-1,4)
  566. spark:SetPoint('BOTTOM',bar,'BOTTOMRIGHT',-1,-4)
  567. bar.spark = spark
  568.  
  569. if BAR_ANIMATION == 'smooth' then
  570. -- updated by core.SetBarAnimation (XXX twice?)
  571. f.handler:SetBarAnimation(bar,BAR_ANIMATION)
  572. end
  573.  
  574. f.handler:RegisterElement('AbsorbBar',bar)
  575. f.UpdateAbsorbBar = UpdateAbsorbBar
  576. f:UpdateAbsorbBar()
  577. end
  578. end
  579. -- name text ###################################################################
  580. do
  581. local NAME_COLOUR_WHITE_IN_BAR_MODE,CLASS_COLOUR_FRIENDLY_NAMES,
  582. CLASS_COLOUR_ENEMY_NAMES,NAME_COLOUR_BRIGHTEN_CLASS,
  583. NAME_COLOUR_PLAYER_FRIENDLY,NAME_COLOUR_PLAYER_HOSTILE,
  584. NAME_COLOUR_NPC_FRIENDLY,NAME_COLOUR_NPC_NEUTRAL,
  585. NAME_COLOUR_NPC_HOSTILE,CONSTRAIN_OFFSET,CONSTRAIN_JUSTIFY
  586.  
  587. -- adjusted class colours, built as needed
  588. local CLASS_COLOURS
  589.  
  590. function core:configChangedName()
  591. CLASS_COLOURS = nil
  592. NAME_COLOUR_WHITE_IN_BAR_MODE = self.profile.name_colour_white_in_bar_mode
  593. CLASS_COLOUR_FRIENDLY_NAMES = self.profile.class_colour_friendly_names
  594. CLASS_COLOUR_ENEMY_NAMES = self.profile.class_colour_enemy_names
  595. NAME_COLOUR_BRIGHTEN_CLASS = self.profile.name_colour_brighten_class
  596. NAME_COLOUR_PLAYER_FRIENDLY = self.profile.name_colour_player_friendly
  597. NAME_COLOUR_PLAYER_HOSTILE = self.profile.name_colour_player_hostile
  598. NAME_COLOUR_NPC_FRIENDLY = self.profile.name_colour_npc_friendly
  599. NAME_COLOUR_NPC_NEUTRAL = self.profile.name_colour_npc_neutral
  600. NAME_COLOUR_NPC_HOSTILE = self.profile.name_colour_npc_hostile
  601.  
  602. CONSTRAIN_OFFSET = ScaleTextOffset(self.profile.name_constrain_offset)
  603. CONSTRAIN_JUSTIFY = self.profile.name_constrain_justify
  604. end
  605.  
  606. local function GetClassColour(f)
  607. -- return adjusted class colour
  608. if not f.state.class then return end
  609. if not CLASS_COLOURS then CLASS_COLOURS = {} end
  610. if not CLASS_COLOURS[f.state.class] then
  611. if NAME_COLOUR_BRIGHTEN_CLASS then
  612. CLASS_COLOURS[f.state.class] = { kui.Brighten(NAME_COLOUR_BRIGHTEN_CLASS,kui.GetClassColour(f.state.class,2)) }
  613. else
  614. CLASS_COLOURS[f.state.class] = { kui.GetClassColour(f.state.class,2) }
  615. end
  616. end
  617. return unpack(CLASS_COLOURS[f.state.class])
  618. end
  619. local function SetNameTextColour(f)
  620. -- override colour based on config
  621. -- white by default
  622. f.NameText:SetTextColor(1,1,1,1)
  623. f.GuildText:SetTextColor(1,1,1,.8)
  624.  
  625. if f.state.personal then
  626. -- self (name & guild text always hidden)
  627. return
  628. elseif UnitIsPlayer(f.unit) then
  629. -- other players
  630. if f.state.friend then
  631. if CLASS_COLOUR_FRIENDLY_NAMES then
  632. -- use adjusted class colour
  633. f.NameText:SetTextColor(GetClassColour(f))
  634. elseif NAME_COLOUR_WHITE_IN_BAR_MODE and not f.IN_NAMEONLY then
  635. -- white in bar mode
  636. return
  637. else
  638. -- use configured friendly player colour
  639. f.NameText:SetTextColor(unpack(NAME_COLOUR_PLAYER_FRIENDLY))
  640. end
  641. elseif CLASS_COLOUR_ENEMY_NAMES then
  642. f.NameText:SetTextColor(GetClassColour(f))
  643. elseif NAME_COLOUR_WHITE_IN_BAR_MODE and not f.IN_NAMEONLY then
  644. return
  645. else
  646. f.NameText:SetTextColor(unpack(NAME_COLOUR_PLAYER_HOSTILE))
  647. end
  648. elseif NAME_COLOUR_WHITE_IN_BAR_MODE and not f.IN_NAMEONLY then
  649. return
  650. else
  651. -- NPCs; reaction colour
  652. if f.state.reaction > 4 then
  653. -- friendly
  654. f.NameText:SetTextColor(unpack(NAME_COLOUR_NPC_FRIENDLY))
  655. elseif f.state.reaction == 4 then
  656. -- neutral
  657. f.NameText:SetTextColor(unpack(NAME_COLOUR_NPC_NEUTRAL))
  658. else
  659. -- hostile
  660. f.NameText:SetTextColor(unpack(NAME_COLOUR_NPC_HOSTILE))
  661. end
  662. end
  663.  
  664. f.GuildText:SetTextColor(kui.Brighten(.8,f.NameText:GetTextColor()))
  665. f.GuildText:SetAlpha(.8)
  666. end
  667.  
  668. local function UpdateNameText(f)
  669. if f.IN_NAMEONLY then
  670. if TITLE_TEXT_PLAYERS then
  671. -- override name with title
  672. f.state.name = UnitPVPName(f.unit) or UnitName(f.unit)
  673. f.NameText:SetText(f.state.name)
  674. end
  675.  
  676. f.NameText:Show()
  677. SetNameTextColour(f)
  678.  
  679. -- update name text colour to with health percent
  680. core:NameOnlyUpdateNameText(f)
  681. elseif SHOW_NAME_TEXT or SHOW_ARENA_ID then
  682. if SHOW_NAME_TEXT and TITLE_TEXT_PLAYERS then
  683. -- reset name to title-less
  684. f.handler:UpdateName()
  685. end
  686. if f.state.no_name then
  687. f.NameText:Hide()
  688. else
  689. if SHOW_ARENA_ID and f.state.arenaid then
  690. if SHOW_NAME_TEXT then
  691. f.NameText:SetText('|cffffffff'..f.state.arenaid..'|r '..f.state.name)
  692. else
  693. f.NameText:SetText('|cffffffff'..f.state.arenaid..'|r')
  694. end
  695. end
  696. f.NameText:Show()
  697. SetNameTextColour(f)
  698. end
  699. else
  700. f.NameText:Hide()
  701. end
  702. end
  703. local function UpdateNameTextPosition(f)
  704. if f.IN_NAMEONLY then
  705. -- position in nameonly is set by NameOnlyEnable
  706. return
  707. end
  708. f.NameText:SetPoint('BOTTOMLEFT',f.HealthBar,'TOPLEFT',CONSTRAIN_OFFSET,NAME_VERTICAL_OFFSET)
  709. f.NameText:SetPoint('RIGHT',f.HealthBar,-CONSTRAIN_OFFSET,0)
  710. f.NameText:SetJustifyH(JUSTIFY_ASSOC[CONSTRAIN_JUSTIFY])
  711. end
  712. function core:CreateNameText(f)
  713. local nametext = CreateFontString(f)
  714. f.handler:RegisterElement('NameText',nametext)
  715.  
  716. f.UpdateNameTextPosition = UpdateNameTextPosition
  717. f.UpdateNameText = UpdateNameText
  718. end
  719. end
  720. -- level text ##################################################################
  721. do
  722. local function UpdateLevelText(f)
  723. if LEVEL_TEXT and not f.IN_NAMEONLY and
  724. not f.state.minus and
  725. not f.state.personal
  726. then
  727. f.LevelText:ClearAllPoints()
  728.  
  729. if f.state.no_name then
  730. f.LevelText:SetPoint('LEFT',2,0)
  731. else
  732. f.LevelText:SetPoint('BOTTOMLEFT',2,BOT_VERTICAL_OFFSET)
  733. end
  734.  
  735. f.LevelText:Show()
  736. else
  737. f.LevelText:Hide()
  738. end
  739. end
  740. function core:CreateLevelText(f)
  741. local leveltext = CreateFontString(f.HealthBar)
  742.  
  743. f.handler:RegisterElement('LevelText',leveltext)
  744.  
  745. f.UpdateLevelText = UpdateLevelText
  746. end
  747. end
  748. -- health text #################################################################
  749. do
  750. local function HealthDisplay_Percent(s)
  751. if s.health_per < 1 then
  752. return format('%.1f',s.health_per)..HEALTH_TEXT_PERCENT_SYMBOL
  753. else
  754. return ceil(s.health_per)..HEALTH_TEXT_PERCENT_SYMBOL
  755. end
  756. end
  757. local health_display_funcs = {
  758. function() return '' end,
  759. function(s) return kui.num(s.health_cur) end,
  760. function(s) return kui.num(s.health_max) end,
  761. HealthDisplay_Percent,
  762. function(s) return '-'..kui.num(s.health_deficit) end,
  763. function(s) return kui.num(s.health_cur)..' '..HealthDisplay_Percent(s) end,
  764. function(s) return kui.num(s.health_cur)..' -'..kui.num(s.health_deficit) end,
  765. }
  766. local function GetHealthDisplay(f,key)
  767. return type(key) == 'number' and
  768. health_display_funcs[key] and
  769. health_display_funcs[key](f.state) or
  770. ''
  771. end
  772.  
  773. local function UpdateHealthText(f)
  774. if f.IN_NAMEONLY then return end
  775. if not SHOW_HEALTH_TEXT or f.state.minus or f.state.personal then
  776. f.HealthText:Hide()
  777. else
  778. local disp
  779.  
  780. if f.state.friend then
  781. if f.state.health_cur ~= f.state.health_max then
  782. disp = GetHealthDisplay(f,HEALTH_TEXT_FRIEND_DMG)
  783. else
  784. disp = GetHealthDisplay(f,HEALTH_TEXT_FRIEND_MAX)
  785. end
  786. else
  787. if f.state.health_cur ~= f.state.health_max then
  788. disp = GetHealthDisplay(f,HEALTH_TEXT_HOSTILE_DMG)
  789. else
  790. disp = GetHealthDisplay(f,HEALTH_TEXT_HOSTILE_MAX)
  791. end
  792. end
  793.  
  794. f.HealthText:SetText(disp)
  795. f.HealthText:ClearAllPoints()
  796.  
  797. if f.state.no_name then
  798. f.HealthText:SetPoint('RIGHT',-2,0)
  799. else
  800. f.HealthText:SetPoint('BOTTOMRIGHT',-2,BOT_VERTICAL_OFFSET)
  801. end
  802.  
  803. f.HealthText:Show()
  804. end
  805. end
  806. function core:CreateHealthText(f)
  807. local healthtext = CreateFontString(f.HealthBar)
  808.  
  809. f.HealthText = healthtext
  810. f.UpdateHealthText = UpdateHealthText
  811. end
  812. end
  813. -- npc guild text ##############################################################
  814. do
  815. local function UpdateGuildText(f)
  816. if not f.IN_NAMEONLY or not f.state.guild_text or
  817. (not GUILD_TEXT_PLAYERS and UnitIsPlayer(f.unit)) or
  818. (not GUILD_TEXT_NPCS and not UnitIsPlayer(f.unit))
  819. then
  820. f.GuildText:Hide()
  821. else
  822. f.GuildText:SetText(f.state.guild_text)
  823. f.GuildText:Show()
  824.  
  825. -- shift name text up in nameonly mode
  826. f.NameText:SetPoint('CENTER',.5,6)
  827. end
  828. end
  829. function core:CreateGuildText(f)
  830. local guildtext = CreateFontString(f,FONT_SIZE_SMALL)
  831. guildtext:SetPoint('TOP',f.NameText,'BOTTOM', 0, -2)
  832. guildtext:SetShadowOffset(1,-1)
  833. guildtext:SetShadowColor(0,0,0,1)
  834. guildtext:Hide()
  835.  
  836. f.GuildText = guildtext
  837. f.UpdateGuildText = UpdateGuildText
  838. end
  839. end
  840. -- frame glow ##################################################################
  841. do
  842. local function UpdateFrameGlow(f)
  843. -- update colour of ThreatGlow or NameOnlyGlow
  844. if f.IN_NAMEONLY then
  845. f.ThreatGlow:Hide()
  846. f.TargetGlow:Hide()
  847.  
  848. if f.NameOnlyGlow then
  849. if TARGET_GLOW and f.state.target then
  850. f.NameOnlyGlow:SetSize(FRAME_GLOW_SIZE_TARGET)
  851. f.NameOnlyGlow:SetVertexColor(unpack(TARGET_GLOW_COLOUR))
  852. f.NameOnlyGlow:Show()
  853. elseif MOUSEOVER_GLOW and f.state.highlight then
  854. f.NameOnlyGlow:SetSize(FRAME_GLOW_SIZE_TARGET)
  855. f.NameOnlyGlow:SetVertexColor(unpack(MOUSEOVER_GLOW_COLOUR))
  856. f.NameOnlyGlow:Show()
  857. elseif FRAME_GLOW_THREAT and f.state.glowing then
  858. f.NameOnlyGlow:SetSize(FRAME_GLOW_SIZE_THREAT)
  859. f.NameOnlyGlow:SetVertexColor(unpack(f.state.glow_colour))
  860. f.NameOnlyGlow:SetAlpha(.6)
  861. f.NameOnlyGlow:Show()
  862. else
  863. f.NameOnlyGlow:Hide()
  864. end
  865. end
  866. else
  867. f.ThreatGlow:Show()
  868. f.TargetGlow:SetHeight(FRAME_GLOW_SIZE_TARGET)
  869.  
  870. if f.NameOnlyGlow then
  871. f.NameOnlyGlow:Hide()
  872. end
  873.  
  874. if TARGET_GLOW and f.state.target then
  875. -- target glow colour
  876. f.ThreatGlow:SetSize(FRAME_GLOW_SIZE_TARGET)
  877. f.ThreatGlow:SetVertexColor(unpack(TARGET_GLOW_COLOUR))
  878. f.TargetGlow:SetVertexColor(unpack(TARGET_GLOW_COLOUR))
  879. f.TargetGlow:SetAlpha(1)
  880. f.TargetGlow:Show()
  881. elseif MOUSEOVER_GLOW and f.state.highlight and not f.state.target then
  882. -- mouseover glow
  883. f.ThreatGlow:SetSize(FRAME_GLOW_SIZE_TARGET)
  884. f.ThreatGlow:SetVertexColor(unpack(MOUSEOVER_GLOW_COLOUR))
  885. f.TargetGlow:SetVertexColor(unpack(MOUSEOVER_GLOW_COLOUR))
  886. f.TargetGlow:SetAlpha(1)
  887. f.TargetGlow:Show()
  888. else
  889. f.TargetGlow:Hide()
  890.  
  891. if FRAME_GLOW_THREAT and f.state.glowing then
  892. -- threat glow colour
  893. f.ThreatGlow:SetSize(FRAME_GLOW_SIZE_THREAT)
  894. f.ThreatGlow:SetVertexColor(unpack(f.state.glow_colour))
  895. else
  896. f.ThreatGlow:SetSize(FRAME_GLOW_SIZE)
  897. if GLOW_AS_SHADOW then
  898. -- shadow
  899. f.ThreatGlow:SetVertexColor(0,0,0,.2)
  900. else
  901. f.ThreatGlow:SetVertexColor(0,0,0,0)
  902. end
  903. end
  904. end
  905. end
  906. end
  907. function core:CreateFrameGlow(f)
  908. local glow = kui.CreateEightSlice(f,KUI_MEDIA..'t/shadowBorder','BACKGROUND',-5)
  909. glow:SetAllPoints(f.bg)
  910. f.handler:RegisterElement('ThreatGlow',glow)
  911.  
  912. local target_glow = f:CreateTexture(nil,'BACKGROUND',nil,-5)
  913. target_glow:SetTexture(MEDIA..'target-glow')
  914. target_glow:SetPoint('TOPLEFT',f.bg,'BOTTOMLEFT')
  915. target_glow:SetPoint('TOPRIGHT',f.bg,'BOTTOMRIGHT')
  916. f.TargetGlow = target_glow
  917.  
  918. f.UpdateFrameGlow = UpdateFrameGlow
  919. end
  920. end
  921. -- target arrows ###############################################################
  922. do
  923. local function Arrows_Hide(self)
  924. self.l:Hide()
  925. self.r:Hide()
  926. end
  927. local function Arrows_Show(self)
  928. self.l:Show()
  929. self.r:Show()
  930. end
  931. local function Arrows_SetVertexColor(self,...)
  932. self.l:SetVertexColor(...)
  933. self.l:SetAlpha(1)
  934. self.r:SetVertexColor(...)
  935. self.r:SetAlpha(1)
  936. end
  937. local function Arrows_UpdatePosition(self)
  938. self.l:SetPoint('RIGHT',self.parent.bg,'LEFT',TARGET_ARROWS_INSET,0)
  939. self.r:SetPoint('LEFT',self.parent.bg,'RIGHT',-TARGET_ARROWS_INSET,0)
  940. end
  941. local function Arrows_SetSize(self,size)
  942. self.l:SetSize(size,size)
  943. self.r:SetSize(size,size)
  944. self:UpdatePosition()
  945. end
  946.  
  947. local function UpdateTargetArrows(f)
  948. if not TARGET_ARROWS or f.IN_NAMEONLY then
  949. f.TargetArrows:Hide()
  950. return
  951. end
  952.  
  953. if f.state.target then
  954. f.TargetArrows.l:SetTexture(TARGET_ARROWS_TEXTURE)
  955. f.TargetArrows.r:SetTexture(TARGET_ARROWS_TEXTURE)
  956. f.TargetArrows:SetVertexColor(unpack(TARGET_GLOW_COLOUR))
  957. f.TargetArrows:SetSize(TARGET_ARROWS_SIZE)
  958. f.TargetArrows:Show()
  959. else
  960. f.TargetArrows:Hide()
  961. end
  962. end
  963. function core:CreateTargetArrows(f)
  964. if not TARGET_ARROWS or f.TargetArrows then return end
  965.  
  966. local left = f.HealthBar:CreateTexture(nil,'ARTWORK',nil,4)
  967. left:SetBlendMode('BLEND')
  968.  
  969. local right = f.HealthBar:CreateTexture(nil,'ARTWORK',nil,4)
  970. right:SetBlendMode('BLEND')
  971. right:SetTexCoord(1,0,0,1)
  972.  
  973. local arrows = {
  974. Hide = Arrows_Hide,
  975. Show = Arrows_Show,
  976. SetVertexColor = Arrows_SetVertexColor,
  977. UpdatePosition = Arrows_UpdatePosition,
  978. SetSize = Arrows_SetSize,
  979. parent = f,
  980. l = left,
  981. r = right,
  982. }
  983.  
  984. f.TargetArrows = arrows
  985. f.UpdateTargetArrows = UpdateTargetArrows
  986. end
  987. end
  988. -- castbar #####################################################################
  989. do
  990. local CASTBAR_ENABLED,CASTBAR_HEIGHT,CASTBAR_COLOUR,CASTBAR_UNIN_COLOUR,
  991. CASTBAR_SHOW_ICON,CASTBAR_SHOW_NAME,CASTBAR_SHOW_SHIELD,
  992. CASTBAR_NAME_VERTICAL_OFFSET,CASTBAR_ANIMATE,
  993. CASTBAR_ANIMATE_CHANGE_COLOUR,CASTBAR_SPACING,SHIELD_SIZE,
  994. CASTBAR_DETACH_HEIGHT,CASTBAR_DETACH_WIDTH,
  995. CASTBAR_DETACH_OFFSET,CASTBAR_DETACH_COMBINE,CASTBAR_DETACH_NAMEONLY,
  996. CASTBAR_RATIO,CASTBAR_ICON_SIDE
  997.  
  998. local function AnimGroup_Stop(self)
  999. self.frame:HideCastBar(nil,true)
  1000. self.frame.CastBar.highlight:Hide()
  1001. end
  1002. local function SpellIconSetWidth(f)
  1003. -- set spell icon width (as it's based on height)
  1004. if CASTBAR_DETACH or not f.SpellIcon or not f.SpellIcon.bg then return end
  1005. f.SpellIcon.bg:SetWidth(ceil(f.CastBar.bg:GetHeight() + f.bg:GetHeight() + CASTBAR_SPACING))
  1006. end
  1007. local function CastBarSetColour(castbar,colour)
  1008. -- set colour, assuming colour is a 3/4-length table,
  1009. -- and set alpha depending on detach-combine/spell icon settings
  1010. castbar:SetStatusBarColor(unpack(colour))
  1011.  
  1012. if CASTBAR_DETACH_COMBINE and CASTBAR_SHOW_ICON then
  1013. -- reduced alpha for spell icon
  1014. castbar:GetStatusBarTexture():SetAlpha(.7)
  1015. else
  1016. castbar:GetStatusBarTexture():SetAlpha(1)
  1017. end
  1018. end
  1019.  
  1020. local function ShowCastBar(f)
  1021. if not f.elements.CastBar then
  1022. -- ignore cast messsages if we've disabled the cast bar
  1023. return
  1024. end
  1025.  
  1026. if CASTBAR_ANIMATE then
  1027. f.CastBar.AnimGroup:Stop()
  1028. end
  1029.  
  1030. if f.cast_state.interruptible then
  1031. CastBarSetColour(f.CastBar,CASTBAR_COLOUR)
  1032.  
  1033. if f.elements.SpellShield then
  1034. f.SpellShield:Hide()
  1035. end
  1036. else
  1037. CastBarSetColour(f.CastBar,CASTBAR_UNIN_COLOUR)
  1038.  
  1039. if f.elements.SpellShield then
  1040. f.SpellShield:Show()
  1041. end
  1042. end
  1043.  
  1044. f.CastBar:Show()
  1045. f.CastBar.bg:Show()
  1046.  
  1047. if f.CastBar.spark then
  1048. f.CastBar.spark:Show()
  1049. end
  1050.  
  1051. if CASTBAR_SHOW_ICON and f.SpellIcon then
  1052. f.SpellIcon:Show()
  1053.  
  1054. if CASTBAR_DETACH then
  1055. f.SpellIcon.bg:Hide()
  1056. else
  1057. f.SpellIcon.bg:Show()
  1058. end
  1059. end
  1060.  
  1061. if CASTBAR_SHOW_NAME and f.SpellName then
  1062. f.SpellName:Show()
  1063. end
  1064.  
  1065. if FADE_AVOID_CASTING then
  1066. plugin_fading:UpdateFrame(f)
  1067. end
  1068. end
  1069. local function HideCastBar(f,hide_cause,force)
  1070. if f.CastBar.spark then
  1071. -- always hide spark instantly
  1072. f.CastBar.spark:Hide()
  1073. end
  1074.  
  1075. if force or not CASTBAR_ANIMATE then
  1076. -- hide instantly
  1077. if CASTBAR_ANIMATE and f.CastBar.AnimGroup:IsPlaying() then
  1078. -- this fires another force hide, so use that;
  1079. f.CastBar.AnimGroup:Stop()
  1080. return
  1081. end
  1082.  
  1083. f.CastBar:Hide()
  1084. f.CastBar.bg:Hide()
  1085.  
  1086. if f.SpellName then
  1087. f.SpellName:Hide()
  1088. end
  1089. if f.SpellIcon then
  1090. f.SpellIcon:Hide()
  1091. f.SpellIcon.bg:Hide()
  1092. end
  1093. if f.SpellShield then
  1094. f.SpellShield:Hide()
  1095. end
  1096. else
  1097. -- soft hide; set state colours, text, start animation
  1098. if hide_cause == 2 then
  1099. -- stopped
  1100. f.CastBar:SetMinMaxValues(0,1)
  1101. f.CastBar:SetValue(0)
  1102. else
  1103. if hide_cause == 1 then
  1104. -- interrupted
  1105. if f.SpellName then
  1106. f.SpellName:SetText(INTERRUPTED)
  1107. end
  1108.  
  1109. if CASTBAR_ANIMATE_CHANGE_COLOUR then
  1110. CastBarSetColour(f.CastBar,CASTBAR_UNIN_COLOUR)
  1111. end
  1112. else
  1113. -- successful
  1114. if CASTBAR_ANIMATE_CHANGE_COLOUR then
  1115. CastBarSetColour(f.CastBar,CASTBAR_COLOUR)
  1116. end
  1117. end
  1118.  
  1119. f.CastBar:SetMinMaxValues(0,1)
  1120. f.CastBar:SetValue(1)
  1121. f.CastBar.highlight:Show()
  1122. end
  1123.  
  1124. f.CastBar.AnimGroup:Play()
  1125. end
  1126.  
  1127. if FADE_AVOID_CASTING then
  1128. plugin_fading:UpdateFrame(f)
  1129. end
  1130. end
  1131. local function UpdateCastBar(f)
  1132. if not CASTBAR_ENABLED then return end
  1133. if f.IN_NAMEONLY and (not CASTBAR_DETACH or not CASTBAR_DETACH_NAMEONLY) then
  1134. f.handler:DisableElement('CastBar')
  1135.  
  1136. if CASTBAR_ANIMATE and f.CastBar.AnimGroup:IsPlaying() then
  1137. -- disabling the element only fires a force hide if the unit
  1138. -- is currently casting; the animation can be left playing
  1139. f.CastBar.AnimGroup:Stop()
  1140. end
  1141. else
  1142. if f.state.personal then
  1143. if core.profile.castbar_showpersonal then
  1144. f.handler:EnableElement('CastBar')
  1145. else
  1146. f.handler:DisableElement('CastBar')
  1147. end
  1148. else
  1149. if not core.profile.castbar_showall and
  1150. not f.state.target
  1151. then
  1152. f.handler:DisableElement('CastBar')
  1153. elseif f.state.friend then
  1154. if core.profile.castbar_showfriend then
  1155. f.handler:EnableElement('CastBar')
  1156. else
  1157. f.handler:DisableElement('CastBar')
  1158. end
  1159. else
  1160. if core.profile.castbar_showenemy then
  1161. f.handler:EnableElement('CastBar')
  1162. else
  1163. f.handler:DisableElement('CastBar')
  1164. end
  1165. end
  1166. end
  1167. end
  1168. end
  1169. local function UpdateSpellNamePosition(f)
  1170. if not f.SpellName then return end
  1171. f.SpellName:SetPoint('TOP',f.CastBar.bg,'BOTTOM',0,CASTBAR_NAME_VERTICAL_OFFSET)
  1172. end
  1173. local function UpdateCastbarSize(f)
  1174. -- update castbar position and size to match config
  1175. f.CastBar.bg:ClearAllPoints()
  1176. f.CastBar:SetPoint('TOPLEFT',f.CastBar.bg,1,-1)
  1177. f.CastBar:SetPoint('BOTTOMRIGHT',f.CastBar.bg,-1,1)
  1178.  
  1179. if CASTBAR_DETACH then
  1180. -- castbar detached from main frame
  1181. if CASTBAR_MATCH_FRAME_WIDTH then
  1182. f.CastBar.bg:SetHeight(CASTBAR_DETACH_HEIGHT)
  1183. f.CastBar.bg:SetPoint('TOPLEFT',f.bg,'BOTTOMLEFT',0,-CASTBAR_DETACH_OFFSET)
  1184. f.CastBar.bg:SetPoint('TOPRIGHT',f.bg,'BOTTOMRIGHT',0,0)
  1185. else
  1186. f.CastBar.bg:SetSize(CASTBAR_DETACH_WIDTH,CASTBAR_DETACH_HEIGHT)
  1187. f.CastBar.bg:SetPoint('TOP',f.bg,'BOTTOM',0,-CASTBAR_DETACH_OFFSET)
  1188. end
  1189.  
  1190. if CASTBAR_SHOW_SHIELD and f.SpellShield then
  1191. f.SpellShield:ClearAllPoints()
  1192. f.SpellShield:SetPoint('CENTER',f.CastBar.bg,'LEFT',1,0)
  1193. end
  1194.  
  1195. if CASTBAR_SHOW_ICON and f.SpellIcon then
  1196. if CASTBAR_DETACH_COMBINE then
  1197. -- overlay spell icon on bar
  1198. f.SpellIcon:SetAllPoints()
  1199. f.SpellIcon:SetTexCoord(.1,.9,.1+CASTBAR_RATIO,.9-CASTBAR_RATIO)
  1200. f.SpellIcon:SetAlpha(.6)
  1201. else
  1202. -- spell icon next to bar
  1203. f.SpellIcon:ClearAllPoints()
  1204. f.SpellIcon:SetSize(CASTBAR_DETACH_HEIGHT-2,CASTBAR_DETACH_HEIGHT-2)
  1205. f.SpellIcon:SetTexCoord(.1,.9,.1,.9)
  1206. f.SpellIcon:SetAlpha(1)
  1207.  
  1208. if CASTBAR_ICON_SIDE == 1 then
  1209. f.SpellIcon:SetPoint('TOPLEFT',f.CastBar.bg,1,-1)
  1210. f.CastBar:SetPoint('TOPLEFT',f.SpellIcon,'TOPRIGHT',1,0)
  1211. else
  1212. f.SpellIcon:SetPoint('TOPRIGHT',f.CastBar.bg,-1,-1)
  1213. f.CastBar:SetPoint('BOTTOMRIGHT',f.SpellIcon,'BOTTOMLEFT',-1,0)
  1214. end
  1215. end
  1216. end
  1217. else
  1218. -- move spell icon to left side of health bar,
  1219. -- attach castbar to bottom of health bar background
  1220. f.CastBar.bg:SetPoint('TOPLEFT',f.bg,'BOTTOMLEFT',0,-CASTBAR_SPACING)
  1221. f.CastBar.bg:SetPoint('TOPRIGHT',f.bg,'BOTTOMRIGHT')
  1222. f.CastBar.bg:SetHeight(CASTBAR_HEIGHT)
  1223.  
  1224. f.CastBar:SetPoint('TOPLEFT',f.CastBar.bg,1,-1)
  1225. f.CastBar:SetPoint('BOTTOMRIGHT',f.CastBar.bg,-1,1)
  1226.  
  1227. if CASTBAR_SHOW_SHIELD and f.SpellShield then
  1228. f.SpellShield:ClearAllPoints()
  1229.  
  1230. if CASTBAR_SHOW_ICON and f.SpellIcon and CASTBAR_ICON_SIDE == 2 then
  1231. f.SpellShield:SetPoint('CENTER',f.CastBar.bg,'RIGHT',1,0)
  1232. else
  1233. f.SpellShield:SetPoint('CENTER',f.CastBar.bg,'LEFT',1,0)
  1234. end
  1235. end
  1236.  
  1237. if CASTBAR_SHOW_ICON and f.SpellIcon then
  1238. f.SpellIcon:ClearAllPoints()
  1239. f.SpellIcon.bg:ClearAllPoints()
  1240.  
  1241. f.SpellIcon:SetPoint('TOPLEFT',f.SpellIcon.bg,1,-1)
  1242. f.SpellIcon:SetPoint('BOTTOMRIGHT',f.SpellIcon.bg,-1,1)
  1243. f.SpellIcon:SetTexCoord(.1,.9,.1,.9)
  1244. f.SpellIcon:SetAlpha(1)
  1245.  
  1246. if CASTBAR_ICON_SIDE == 1 then
  1247. f.SpellIcon.bg:SetPoint('TOPRIGHT',f.bg,'TOPLEFT',-CASTBAR_SPACING,0)
  1248. f.SpellIcon.bg:SetPoint('BOTTOMRIGHT',f.CastBar.bg,'BOTTOMLEFT')
  1249. else
  1250. f.SpellIcon.bg:SetPoint('TOPLEFT',f.bg,'TOPRIGHT',CASTBAR_SPACING,0)
  1251. f.SpellIcon.bg:SetPoint('BOTTOMLEFT',f.CastBar.bg,'BOTTOMRIGHT')
  1252. end
  1253.  
  1254. f:SpellIconSetWidth()
  1255. end
  1256. end
  1257. end
  1258.  
  1259. local function CreateSpellIcon(f)
  1260. local icon = f.CastBar:CreateTexture(nil, 'BACKGROUND', nil, 2)
  1261. f.handler:RegisterElement('SpellIcon', icon)
  1262.  
  1263. local bg = f.CastBar:CreateTexture(nil,'BACKGROUND',nil,1)
  1264. bg:SetTexture(kui.m.t.solid)
  1265. bg:SetVertexColor(0,0,0,.9)
  1266. icon.bg = bg
  1267. end
  1268. local function CreateSpellShield(f)
  1269. -- cast shield
  1270. local shield = f.CastBar:CreateTexture(nil, 'ARTWORK', nil, 3)
  1271. shield:SetTexture(MEDIA..'shield3')
  1272. shield:SetSize(SHIELD_SIZE,SHIELD_SIZE)
  1273. shield:SetVertexColor(.8, .8, 1)
  1274. shield:Hide()
  1275.  
  1276. f.handler:RegisterElement('SpellShield', shield)
  1277. end
  1278. local function CreateSpellName(f)
  1279. local spellname = CreateFontString(f.CastBar,FONT_SIZE_SMALL)
  1280. spellname:SetWordWrap(false)
  1281. spellname:Hide()
  1282.  
  1283. f.handler:RegisterElement('SpellName', spellname)
  1284. end
  1285. local function CreateAnimGroup(f)
  1286. -- bar highlight texture
  1287. local hl = f.CastBar:CreateTexture(nil,'ARTWORK',nil,1)
  1288. hl:SetTexture(BAR_TEXTURE)
  1289. hl:SetAllPoints(f.CastBar)
  1290. hl:SetVertexColor(1,1,1,.4)
  1291. hl:SetBlendMode('ADD')
  1292. hl:Hide()
  1293. f.CastBar.highlight = hl
  1294.  
  1295. local grp = f.CastBar:CreateAnimationGroup()
  1296. -- bar fade
  1297. local bar = grp:CreateAnimation("Alpha")
  1298. bar:SetStartDelay(.5)
  1299. bar:SetDuration(.5)
  1300. bar:SetFromAlpha(1)
  1301. bar:SetToAlpha(0)
  1302. grp.bar = bar
  1303.  
  1304. -- highlight flash
  1305. local highlight = grp:CreateAnimation("Alpha")
  1306. highlight:SetChildKey('highlight')
  1307. highlight:SetStartDelay(.05)
  1308. highlight:SetDuration(.25)
  1309. highlight:SetSmoothing('IN')
  1310. highlight:SetFromAlpha(.4)
  1311. highlight:SetToAlpha(0)
  1312. grp.highlight = highlight
  1313.  
  1314. grp.frame = f
  1315. f.CastBar.AnimGroup = grp
  1316. grp:SetScript('OnFinished',AnimGroup_Stop)
  1317. grp:SetScript('OnStop',AnimGroup_Stop)
  1318. end
  1319. local function CreateOptionalElementsMaybe(f)
  1320. -- check if we need to create extra elements to support configuration
  1321. if CASTBAR_SHOW_NAME and not f.SpellName then
  1322. CreateSpellName(f)
  1323. end
  1324. if CASTBAR_SHOW_ICON and not f.SpellIcon then
  1325. CreateSpellIcon(f)
  1326. end
  1327. if CASTBAR_SHOW_SHIELD and not f.SpellShield then
  1328. CreateSpellShield(f)
  1329. end
  1330. if CASTBAR_ANIMATE and not f.CastBar.AnimGroup then
  1331. CreateAnimGroup(f)
  1332. elseif not CASTBAR_ANIMATE and f.CastBar.AnimGroup then
  1333. -- make sure frames which might have been animating when the
  1334. -- option was changed are stopped;
  1335. f.CastBar.AnimGroup:Stop()
  1336. end
  1337. end
  1338.  
  1339. function core:CreateCastBar(f)
  1340. local castbar = CreateStatusBar(f,BAR_SPARK,nil,true,1)
  1341. castbar:Hide()
  1342.  
  1343. local bg = castbar:CreateTexture(nil,'BACKGROUND',nil,1)
  1344. bg:SetTexture(kui.m.t.solid)
  1345. bg:SetVertexColor(0,0,0,.9)
  1346. bg:Hide()
  1347.  
  1348. castbar.bg = bg
  1349.  
  1350. f.handler:RegisterElement('CastBar', castbar)
  1351.  
  1352. CreateOptionalElementsMaybe(f)
  1353.  
  1354. f.ShowCastBar = ShowCastBar
  1355. f.HideCastBar = HideCastBar
  1356. f.UpdateCastBar = UpdateCastBar
  1357. f.UpdateSpellNamePosition = UpdateSpellNamePosition
  1358. f.UpdateCastbarSize = UpdateCastbarSize
  1359. f.SpellIconSetWidth = SpellIconSetWidth
  1360.  
  1361. f:UpdateSpellNamePosition()
  1362. f:UpdateCastbarSize()
  1363. end
  1364.  
  1365. function core:SetCastBarConfig()
  1366. CASTBAR_ENABLED = self.profile.castbar_enable
  1367. CASTBAR_HEIGHT = self:Scale(self.profile.castbar_height)
  1368. CASTBAR_COLOUR = self.profile.castbar_colour
  1369. CASTBAR_UNIN_COLOUR = self.profile.castbar_unin_colour
  1370. CASTBAR_SHOW_ICON = self.profile.castbar_icon
  1371. CASTBAR_SHOW_NAME = self.profile.castbar_name
  1372. CASTBAR_SHOW_SHIELD = self.profile.castbar_shield
  1373. CASTBAR_NAME_VERTICAL_OFFSET = ScaleTextOffset(self.profile.castbar_name_vertical_offset)
  1374. CASTBAR_ANIMATE = self.profile.castbar_animate
  1375. CASTBAR_ANIMATE_CHANGE_COLOUR = self.profile.castbar_animate_change_colour
  1376. CASTBAR_SPACING = self.profile.castbar_spacing
  1377. SHIELD_SIZE = self:Scale(self.profile.castbar_shield_size)
  1378.  
  1379. CASTBAR_DETACH = self.profile.castbar_detach
  1380. CASTBAR_DETACH_HEIGHT = self:Scale(self.profile.castbar_detach_height)
  1381. CASTBAR_DETACH_WIDTH = self:Scale(self.profile.castbar_detach_width)
  1382. CASTBAR_DETACH_OFFSET = self:Scale(self.profile.castbar_detach_offset)
  1383. CASTBAR_DETACH_COMBINE = CASTBAR_DETACH and self.profile.castbar_detach_combine
  1384. CASTBAR_DETACH_NAMEONLY = self.profile.castbar_detach_nameonly
  1385. CASTBAR_RATIO = (1-(CASTBAR_DETACH_HEIGHT/CASTBAR_DETACH_WIDTH))/2.5
  1386. CASTBAR_ICON_SIDE = self.profile.castbar_icon_side
  1387.  
  1388. for _,f in addon:Frames() do
  1389. CreateOptionalElementsMaybe(f)
  1390.  
  1391. if f.SpellShield then
  1392. if CASTBAR_SHOW_SHIELD then
  1393. f.handler:EnableElement('SpellShield')
  1394. f.SpellShield:SetSize(SHIELD_SIZE,SHIELD_SIZE)
  1395. else
  1396. f.handler:DisableElement('SpellShield')
  1397. end
  1398. end
  1399.  
  1400. f:UpdateCastbarSize()
  1401. f:UpdateSpellNamePosition()
  1402. end
  1403. end
  1404. end
  1405. -- state icons #################################################################
  1406. do
  1407. local SHOW_STATE_ICONS,ICON_SIZE
  1408. local BOSS = {0,.5,0,.5}
  1409. local RARE = {.5,1,.5,1}
  1410.  
  1411. function core:configChangedStateIcons()
  1412. SHOW_STATE_ICONS = self.profile.state_icons
  1413. ICON_SIZE = self:Scale(20)
  1414.  
  1415. for _,f in addon:Frames() do
  1416. f:UpdateStateIconSize()
  1417. end
  1418. end
  1419.  
  1420. local function UpdateStateIcon(f)
  1421. if not SHOW_STATE_ICONS or
  1422. f.IN_NAMEONLY or
  1423. (f.elements.LevelText and f.LevelText:IsShown())
  1424. then
  1425. f.StateIcon:Hide()
  1426. return
  1427. end
  1428.  
  1429. if f.state.classification == 'worldboss' then
  1430. f.StateIcon:SetTexCoord(unpack(BOSS))
  1431. f.StateIcon:SetVertexColor(1,1,1)
  1432. f.StateIcon:Show()
  1433. elseif f.state.classification == 'rare' or f.state.classification == 'rareelite' then
  1434. f.StateIcon:SetTexCoord(unpack(RARE))
  1435. f.StateIcon:SetVertexColor(1,.8,.2)
  1436. f.StateIcon:Show()
  1437. else
  1438. f.StateIcon:Hide()
  1439. end
  1440. end
  1441. local function UpdateStateIconSize(f)
  1442. f.StateIcon:SetSize(ICON_SIZE,ICON_SIZE)
  1443. end
  1444. function core:CreateStateIcon(f)
  1445. local stateicon = f:CreateTexture(nil,'ARTWORK',nil,4)
  1446. stateicon:SetTexture(MEDIA..'state-icons')
  1447. stateicon:SetPoint('LEFT',f.HealthBar,'BOTTOMLEFT',0,1)
  1448.  
  1449. f.StateIcon = stateicon
  1450. f.UpdateStateIcon = UpdateStateIcon
  1451. f.UpdateStateIconSize = UpdateStateIconSize
  1452.  
  1453. f:UpdateStateIconSize()
  1454. end
  1455. end
  1456. -- raid icons ##################################################################
  1457. do
  1458. local SHOW_RAID_ICON,RAID_ICON_SIZE,RAID_ICON_POINT,RAID_ICON_X,RAID_ICON_Y
  1459. local function Init(icon)
  1460. icon:ClearAllPoints()
  1461. icon:SetSize(RAID_ICON_SIZE,RAID_ICON_SIZE)
  1462. icon:SetPoint(POINT_ASSOC[RAID_ICON_POINT],
  1463. RAID_ICON_X,RAID_ICON_Y)
  1464. end
  1465. function core:CreateRaidIcon(f)
  1466. local raidicon = f:CreateTexture(nil,'ARTWORK',nil,6)
  1467. raidicon:SetTexture('interface/targetingframe/ui-raidtargetingicons')
  1468. raidicon:Hide()
  1469. Init(raidicon)
  1470. f.handler:RegisterElement('RaidIcon',raidicon)
  1471. end
  1472. function core:configChangedRaidIcon()
  1473. SHOW_RAID_ICON = self.profile.show_raid_icon
  1474. RAID_ICON_SIZE = self:Scale(self.profile.raid_icon_size)
  1475. RAID_ICON_POINT = self.profile.raid_icon_point
  1476. RAID_ICON_X = self:Scale(self.profile.raid_icon_x)
  1477. RAID_ICON_Y = self:Scale(self.profile.raid_icon_y)
  1478.  
  1479. if SHOW_RAID_ICON then
  1480. addon:GetPlugin('RaidIcon'):Enable()
  1481. else
  1482. addon:GetPlugin('RaidIcon'):Disable()
  1483. end
  1484.  
  1485. -- update existing icons...
  1486. for _,f in addon:Frames() do
  1487. if f.RaidIcon then
  1488. if SHOW_RAID_ICON then
  1489. Init(f.RaidIcon)
  1490. else
  1491. f.RaidIcon:Hide()
  1492. end
  1493. end
  1494. end
  1495. end
  1496. end
  1497. -- auras #######################################################################
  1498. do
  1499. local AURAS_NORMAL_SIZE,AURAS_MINUS_SIZE,AURAS_CENTRE,
  1500. AURAS_ON_PERSONAL,AURAS_ON_FRIENDS,AURAS_ON_ENEMIES,AURAS_ON_MINUS,
  1501. AURAS_ENABLED,AURAS_SHOW_ALL_SELF,AURAS_HIDE_ALL_OTHER,
  1502. AURAS_PURGE_SIZE,AURAS_SHOW_PURGE,AURAS_SIDE,AURAS_OFFSET,
  1503. AURAS_POINT_S,AURAS_POINT_R,PURGE_POINT_S,PURGE_POINT_R,
  1504. PURGE_OFFSET,AURAS_TIMER_THRESHOLD,
  1505. AURAS_PURGE_OPPOSITE,AURAS_HIGHLIGHT_OTHER,
  1506. AURAS_CD_SIZE,AURAS_COUNT_SIZE,AURAS_PER_ROW,
  1507. AURAS_PULSATE,AURAS_ICON_SQUARENESS,AURAS_SORT
  1508.  
  1509. local AURAS_CD_POINT,AURAS_CD_OFFSET_X,AURAS_CD_OFFSET_Y,
  1510. AURAS_COUNT_POINT,AURAS_COUNT_OFFSET_X,AURAS_COUNT_OFFSET_Y
  1511.  
  1512. local function AuraFrame_UpdateFrameSize(self,to_size)
  1513. -- frame width changes depending on icon size, needs to be correct if
  1514. -- auras are centred, and we want to make sure the frame isn't aligned
  1515. -- to subpixels;
  1516. if not self.__width or to_size then
  1517. self.__width = ((to_size or self.size) * self.num_per_row) +
  1518. (self.num_per_row - 1)
  1519. self:SetWidth(self.__width)
  1520.  
  1521. if to_size or AURAS_CENTRE then
  1522. -- resize & re-arrange buttons
  1523. -- (arrange is always needed after a width change if centred)
  1524. self:SetIconSize(to_size)
  1525. end
  1526.  
  1527. -- update frame height
  1528. core.Auras_PostUpdateAuraFrame(self)
  1529. end
  1530.  
  1531. -- update position
  1532. self:ClearAllPoints()
  1533. self.__h_offset = AURAS_CENTRE and
  1534. floor((self.parent.bg:GetWidth() - self.__width) / 2) or 0
  1535.  
  1536. if self.id == 'core_dynamic' or
  1537. (not AURAS_PURGE_OPPOSITE and not self.sibling:IsShown())
  1538. then
  1539. -- attach to top/bottom of frame bg
  1540. self:SetPoint(AURAS_POINT_S,self.parent.bg,AURAS_POINT_R,
  1541. self.__h_offset,AURAS_OFFSET)
  1542. else
  1543. -- core_purge;
  1544. if AURAS_PURGE_OPPOSITE then
  1545. -- attach to the opposite side of frame bg
  1546. self:SetPoint(PURGE_POINT_S,self.parent.bg,PURGE_POINT_R,
  1547. self.__h_offset,PURGE_OFFSET)
  1548. else
  1549. -- attach to top/bottom of core_dynamic
  1550. self:SetPoint(PURGE_POINT_S,self.sibling,PURGE_POINT_R,
  1551. 0,PURGE_OFFSET)
  1552. self:SetPoint('LEFT',self.parent.bg,
  1553. self.__h_offset,0)
  1554. end
  1555. end
  1556. end
  1557. local function AuraFrame_UpdateIconSize(self,state)
  1558. -- determine current icon size
  1559. local size
  1560. if self.id == 'core_purge' then
  1561. size = AURAS_PURGE_SIZE
  1562. elseif (FRAME_MINUS_SIZE and state.minus) and (not FRAME_TARGET_SIZE or not state.target) then
  1563. size = AURAS_MINUS_SIZE
  1564. else
  1565. size = AURAS_NORMAL_SIZE
  1566. end
  1567. if self.id ~= 'core_purge' and self.size == size then
  1568. -- no size update necessary
  1569. size = nil
  1570. end
  1571. -- update frame point + size
  1572. AuraFrame_UpdateFrameSize(self,size)
  1573. end
  1574. local function AuraFrame_CoreDynamic_OnVisibilityChange(self)
  1575. if self.parent.IGNORE_VISIBILITY_BUBBLE then return end
  1576. if not AURAS_PURGE_OPPOSITE and self.sibling.__width then
  1577. -- update sibling point if it's attached and initialised
  1578. AuraFrame_UpdateFrameSize(self.sibling)
  1579. end
  1580. end
  1581.  
  1582. local function UpdateAuras(f)
  1583. -- enable/disable aura frames on frame update
  1584. if not f.Auras or not f.Auras.frames then return end
  1585. if f.Auras.frames.core_dynamic then
  1586. if not AURAS_ENABLED or
  1587. (not AURAS_ON_PERSONAL and f.state.personal) or
  1588. (not AURAS_ON_FRIENDS and f.state.friend and not f.state.personal) or
  1589. (not AURAS_ON_ENEMIES and not f.state.friend) or
  1590. (not AURAS_ON_MINUS and f.state.minus)
  1591. then
  1592. f.Auras.frames.core_dynamic:Disable()
  1593. else
  1594. f.Auras.frames.core_dynamic:Enable(true)
  1595. AuraFrame_UpdateIconSize(f.Auras.frames.core_dynamic,f.state)
  1596. end
  1597. end
  1598. if f.Auras.frames.core_purge then
  1599. if not AURAS_SHOW_PURGE or f.state.friend then
  1600. f.Auras.frames.core_purge:Disable()
  1601. else
  1602. -- only show purge on enemies
  1603. f.Auras.frames.core_purge:Enable(true)
  1604. AuraFrame_UpdateIconSize(f.Auras.frames.core_purge)
  1605. end
  1606. end
  1607. end
  1608. function core:CreateAuras(f)
  1609. -- for both frames:
  1610. -- initial icon size set by AuraFrame_UpdateIconSize < UpdateAuras
  1611. -- frame width & point set by AuraFrame_UpdateFrameSize < _UpdateIconSize
  1612. f.UpdateAuras = UpdateAuras
  1613.  
  1614. local auras = f.handler:CreateAuraFrame({
  1615. id = 'core_dynamic',
  1616. max = 10,
  1617. point = {'BOTTOMLEFT','LEFT','RIGHT'},
  1618. x_spacing = 1,
  1619. y_spacing = 1,
  1620.  
  1621. num_per_row = AURAS_PER_ROW,
  1622. pulsate = AURAS_PULSATE,
  1623. timer_threshold = AURAS_TIMER_THRESHOLD,
  1624. squareness = AURAS_ICON_SQUARENESS,
  1625. sort = AURAS_SORT,
  1626. centred = AURAS_CENTRE,
  1627. })
  1628. auras.__core = true
  1629. auras:SetFrameLevel(0)
  1630. auras:HookScript('OnShow',AuraFrame_CoreDynamic_OnVisibilityChange)
  1631. auras:HookScript('OnHide',AuraFrame_CoreDynamic_OnVisibilityChange)
  1632.  
  1633. local purge = f.handler:CreateAuraFrame({
  1634. id = 'core_purge',
  1635. purge = true,
  1636. max = 4,
  1637. point = {'BOTTOMLEFT','LEFT','RIGHT'},
  1638. x_spacing = 1,
  1639. y_spacing = 1,
  1640. rows = 1,
  1641.  
  1642. pulsate = false,
  1643. timer_threshold = AURAS_TIMER_THRESHOLD,
  1644. squareness = AURAS_ICON_SQUARENESS,
  1645. sort = AURAS_SORT,
  1646. centred = AURAS_CENTRE,
  1647. })
  1648. purge.__core = true
  1649. purge:SetFrameLevel(0)
  1650.  
  1651. auras.sibling = purge
  1652. purge.sibling = auras
  1653. end
  1654.  
  1655. -- callbacks
  1656. function core.Auras_PostCreateAuraButton(frame,button)
  1657. -- move text to obey our settings
  1658. button.cd.fontobject_shadow = true
  1659. button.cd:ClearAllPoints()
  1660. button.cd:SetPoint(POINT_ASSOC[AURAS_CD_POINT],
  1661. AURAS_CD_OFFSET_X,AURAS_CD_OFFSET_Y)
  1662.  
  1663. button.count.fontobject_shadow = true
  1664. button.count.fontobject_small = true
  1665. button.count:ClearAllPoints()
  1666. button.count:SetPoint(POINT_ASSOC[AURAS_COUNT_POINT],
  1667. AURAS_COUNT_OFFSET_X,AURAS_COUNT_OFFSET_Y)
  1668.  
  1669. if frame.__core and not button.hl then
  1670. -- create owner highlight
  1671. local hl = button:CreateTexture(nil,'ARTWORK',nil,2)
  1672. hl:SetTexture(KUI_MEDIA..'t/button-highlight')
  1673. hl:SetAllPoints(button.icon)
  1674. hl:Hide()
  1675.  
  1676. button.hl = hl
  1677. end
  1678.  
  1679. core.AurasButton_SetFont(button)
  1680. end
  1681. function core.Auras_PostDisplayAuraButton(frame,button)
  1682. if not frame.__core then return end
  1683. if not button.hl then return end
  1684.  
  1685. if frame.purge or button.can_purge then
  1686. button.hl:SetVertexColor(1,.2,.2,.8)
  1687. button.hl:Show()
  1688. elseif AURAS_HIGHLIGHT_OTHER and not button.own then
  1689. button.hl:SetVertexColor(.4,1,.2,.8)
  1690. button.hl:Show()
  1691. else
  1692. button.hl:Hide()
  1693. end
  1694. end
  1695. function core.Auras_PostUpdateAuraFrame(frame)
  1696. -- maintain auraframe height corresponding to #visible buttons
  1697. if not frame.__core then return end
  1698. if frame.visible and frame.visible > 0 then
  1699. frame:SetHeight(
  1700. ceil(frame.size*frame.squareness) *
  1701. ceil(frame.visible / (frame.max / frame.rows))
  1702. )
  1703. end
  1704. end
  1705. function core.Auras_DisplayAura(frame,spellid,name,duration,_,own,_,nps_own,nps_all)
  1706. if not frame.__core then return end
  1707. if frame.purge then
  1708. -- force hide if excluded by spell list
  1709. if KSL:SpellExcluded(spellid) or KSL:SpellExcluded(name) then
  1710. return 1
  1711. end
  1712. else
  1713. -- force show if included by spell list
  1714. if (KSL:SpellIncludedAll(spellid) or
  1715. KSL:SpellIncludedAll(name)) or
  1716. (own and (KSL:SpellIncludedOwn(spellid) or
  1717. KSL:SpellIncludedOwn(name)))
  1718. then
  1719. return 2
  1720. end
  1721.  
  1722. -- force hide infinite duration unless whitelisted
  1723. if duration == 0 and not nps_all and not nps_own then
  1724. return 1
  1725. end
  1726.  
  1727. -- force hide if excluded by spell list, as above
  1728. if KSL:SpellExcluded(spellid) or KSL:SpellExcluded(name) then
  1729. return 1
  1730. end
  1731.  
  1732. if AURAS_SHOW_ALL_SELF or AURAS_HIDE_ALL_OTHER then
  1733. if own then
  1734. if AURAS_SHOW_ALL_SELF then
  1735. -- show all casts from the player
  1736. return 2
  1737. end
  1738. else
  1739. if AURAS_HIDE_ALL_OTHER then
  1740. -- hide all other players' casts (CC, etc.)
  1741. return 1
  1742. end
  1743. end
  1744. end
  1745. end
  1746.  
  1747. -- process as normal
  1748. return
  1749. end
  1750. function core.AurasButton_SetFont(button)
  1751. button.cd.fontobject_size = AURAS_CD_SIZE > 0 and AURAS_CD_SIZE
  1752. UpdateFontObject(button.cd)
  1753.  
  1754. button.count.fontobject_size = AURAS_COUNT_SIZE > 0 and AURAS_COUNT_SIZE
  1755. UpdateFontObject(button.count)
  1756. end
  1757.  
  1758. -- config changed
  1759. function core:SetAurasConfig()
  1760. AURAS_ENABLED = self.profile.auras_enabled
  1761. AURAS_PULSATE = self.profile.auras_pulsate
  1762. AURAS_CENTRE = self.profile.auras_centre
  1763. AURAS_SORT = self.profile.auras_sort
  1764. AURAS_TIMER_THRESHOLD = self.profile.auras_time_threshold
  1765. AURAS_NORMAL_SIZE = self:Scale(self.profile.auras_icon_normal_size)
  1766. AURAS_MINUS_SIZE = self:Scale(self.profile.auras_icon_minus_size)
  1767. AURAS_ICON_SQUARENESS = self.profile.auras_icon_squareness
  1768. AURAS_ON_PERSONAL = self.profile.auras_on_personal
  1769. AURAS_ON_FRIENDS = self.profile.auras_on_friends
  1770. AURAS_ON_ENEMIES = self.profile.auras_on_enemies
  1771. AURAS_ON_MINUS = self.profile.auras_on_minus
  1772. AURAS_SHOW_ALL_SELF = self.profile.auras_show_all_self
  1773. AURAS_HIDE_ALL_OTHER = self.profile.auras_hide_all_other
  1774. AURAS_SHOW_PURGE = self.profile.auras_show_purge
  1775. AURAS_PURGE_SIZE = self:Scale(self.profile.auras_purge_size)
  1776. AURAS_PURGE_OPPOSITE = self.profile.auras_purge_opposite
  1777. AURAS_SIDE = self.profile.auras_side
  1778. AURAS_OFFSET = self:Scale(self.profile.auras_offset)
  1779. AURAS_HIGHLIGHT_OTHER = self.profile.auras_highlight_other
  1780. AURAS_PER_ROW = self.profile.auras_per_row
  1781. AURAS_CD_SIZE = self:Scale(self.profile.auras_cd_size)
  1782. AURAS_COUNT_SIZE = self:Scale(self.profile.auras_count_size)
  1783. AURAS_CD_POINT = self.profile.auras_cd_point
  1784. AURAS_CD_OFFSET_X = ScaleTextOffset(self.profile.auras_cd_x)
  1785. AURAS_CD_OFFSET_Y = ScaleTextOffset(self.profile.auras_cd_y)
  1786. AURAS_COUNT_POINT = self.profile.auras_count_point
  1787. AURAS_COUNT_OFFSET_X = ScaleTextOffset(self.profile.auras_count_x)
  1788. AURAS_COUNT_OFFSET_Y = ScaleTextOffset(self.profile.auras_count_y)
  1789.  
  1790. if AURAS_TIMER_THRESHOLD < 0 then
  1791. AURAS_TIMER_THRESHOLD = nil
  1792. end
  1793.  
  1794. -- resolve side to points
  1795. if not AURAS_SIDE or AURAS_SIDE == 1 then
  1796. -- top
  1797. AURAS_POINT_S = 'BOTTOMLEFT'
  1798. AURAS_POINT_R = 'TOPLEFT'
  1799.  
  1800. if AURAS_PURGE_OPPOSITE then
  1801. PURGE_POINT_S = 'TOPLEFT'
  1802. PURGE_POINT_R = 'BOTTOMLEFT'
  1803. PURGE_OFFSET = -AURAS_OFFSET
  1804. else
  1805. PURGE_POINT_S = 'BOTTOM'
  1806. PURGE_POINT_R = 'TOP'
  1807. PURGE_OFFSET = 3
  1808. end
  1809. else
  1810. -- bottom
  1811. AURAS_POINT_S = 'TOPLEFT'
  1812. AURAS_POINT_R = 'BOTTOMLEFT'
  1813.  
  1814. if AURAS_PURGE_OPPOSITE then
  1815. PURGE_POINT_S = 'BOTTOMLEFT'
  1816. PURGE_POINT_R = 'TOPLEFT'
  1817. PURGE_OFFSET = AURAS_OFFSET
  1818. else
  1819. PURGE_POINT_S = 'TOP'
  1820. PURGE_POINT_R = 'BOTTOM'
  1821. PURGE_OFFSET = -3
  1822. end
  1823.  
  1824. AURAS_OFFSET = -AURAS_OFFSET
  1825. end
  1826.  
  1827. -- update config values within aura frames;
  1828. for _,f in addon:Frames() do
  1829. if f.Auras and f.Auras.frames then
  1830. local cd = f.Auras.frames.core_dynamic
  1831. local cp = f.Auras.frames.core_purge
  1832. if cd then
  1833. cd.point[1] = AURAS_POINT_S
  1834. cd.pulsate = AURAS_PULSATE
  1835. cd.num_per_row = AURAS_PER_ROW
  1836. cd.timer_threshold = AURAS_TIMER_THRESHOLD
  1837. cd.squareness = AURAS_ICON_SQUARENESS
  1838. cd.centred = AURAS_CENTRE
  1839. cd.__width = nil -- force size & position update
  1840. cd:SetSort(AURAS_SORT)
  1841. end
  1842. if cp and AURAS_SHOW_PURGE then
  1843. cp.point[1] = AURAS_PURGE_OPPOSITE and
  1844. PURGE_POINT_S or AURAS_POINT_S
  1845. cp.timer_threshold = AURAS_TIMER_THRESHOLD
  1846. cp.squareness = AURAS_ICON_SQUARENESS
  1847. cp.centred = AURAS_CENTRE
  1848. cp.__width = nil
  1849. cp:SetSort(AURAS_SORT)
  1850. end
  1851.  
  1852. -- update all buttons
  1853. for _,auraframe in pairs(f.Auras.frames) do
  1854. for _,button in ipairs(auraframe.buttons) do
  1855. self.Auras_PostCreateAuraButton(auraframe,button)
  1856. end
  1857. end
  1858. end
  1859. end
  1860.  
  1861. -- update auras plugin config
  1862. -- (we override fonts with the PostCreateAuraButton callback)
  1863. self.Auras = self.Auras or {}
  1864. self.Auras.colour_short = self.profile.auras_colour_short
  1865. self.Auras.colour_medium = self.profile.auras_colour_medium
  1866. self.Auras.colour_long = self.profile.auras_colour_long
  1867. self.Auras.decimal_threshold = self.profile.auras_decimal_threshold
  1868.  
  1869. addon:GetPlugin('Auras'):UpdateConfig()
  1870.  
  1871. -- we don't want to actually disable the element as other plugins
  1872. -- (such as bossmods) rely on it
  1873. end
  1874. end
  1875. -- class powers ################################################################
  1876. do
  1877. local function ClassPowers_StateFilter(state)
  1878. if state.personal then
  1879. return true
  1880. elseif state.friend then
  1881. return CLASSPOWERS_ON_FRIENDS
  1882. else
  1883. return CLASSPOWERS_ON_ENEMIES
  1884. end
  1885. end
  1886. function core.ClassPowers_PostPositionFrame(cpf,parent)
  1887. if not parent or not cpf or not cpf:IsShown() then return end
  1888.  
  1889. if not ClassPowers_StateFilter(parent.state) then
  1890. -- hide on friends/enemies
  1891. return cpf:Hide()
  1892. end
  1893.  
  1894. -- override frame position
  1895. -- XXX we ~could~ use pixel-corrected positions but it doesn't matter
  1896. -- too much with textures; @classpowers2 fixes this anyway
  1897. cpf:ClearAllPoints()
  1898. if parent.IN_NAMEONLY then
  1899. -- (we add a -2 here as a margin between text
  1900. cpf:SetPoint('TOP',parent.GuildText and parent.GuildText:IsShown() and parent.GuildText or parent.NameText,'BOTTOM',0,CLASSPOWERS_Y-2)
  1901. else
  1902. cpf:SetPoint('CENTER',parent.bg,'BOTTOM',0,CLASSPOWERS_Y)
  1903. end
  1904. end
  1905. function core.ClassPowers_CreateBar()
  1906. local bar = CreateStatusBar(addon.ClassPowersFrame,BAR_SPARK)
  1907. bar:SetSize(
  1908. core.ClassPowers.bar_width,
  1909. core.ClassPowers.bar_height
  1910. )
  1911. bar:SetPoint('CENTER',0,-1)
  1912.  
  1913. bar.fill:SetParent(bar)
  1914. bar.fill:SetDrawLayer('BACKGROUND',2)
  1915.  
  1916. Mixin(bar,BackdropTemplateMixin)
  1917. bar:SetBackdrop({
  1918. bgFile=kui.m.t.solid,
  1919. insets={top=-1,right=-1,bottom=-1,left=-1}
  1920. })
  1921. bar:SetBackdropColor(0,0,0,.9)
  1922.  
  1923. return bar
  1924. end
  1925. end
  1926. -- threat brackets #############################################################
  1927. do
  1928. local TB_TEXTURE = MEDIA..'threat-bracket'
  1929. local TB_POINTS = {
  1930. { 'BOTTOMRIGHT', 'TOPLEFT', -1, 1 },
  1931. { 'BOTTOMLEFT','TOPRIGHT', 1, 1 },
  1932. { 'TOPRIGHT', 'BOTTOMLEFT', -1, -1 },
  1933. { 'TOPLEFT', 'BOTTOMRIGHT', 1, -1 },
  1934. }
  1935. -- threat bracket prototype
  1936. local tb_prototype = {}
  1937. tb_prototype.__index = tb_prototype
  1938. function tb_prototype:SetVertexColor(...)
  1939. for _,v in ipairs(self.textures) do
  1940. v:SetVertexColor(...)
  1941. v:SetAlpha(.8)
  1942. end
  1943. end
  1944. function tb_prototype:Show(...)
  1945. for _,v in ipairs(self.textures) do
  1946. v:Show(...)
  1947. end
  1948. end
  1949. function tb_prototype:Hide(...)
  1950. for _,v in ipairs(self.textures) do
  1951. v:Hide(...)
  1952. end
  1953. end
  1954. function tb_prototype:SetSize(size)
  1955. for _,v in ipairs(self.textures) do
  1956. v:SetSize(size,size)
  1957. end
  1958. end
  1959. -- update
  1960. local function UpdateThreatBrackets(f)
  1961. if not THREAT_BRACKETS or f.IN_NAMEONLY then
  1962. f.ThreatBrackets:Hide()
  1963. return
  1964. end
  1965.  
  1966. if f.state.glowing then
  1967. f.ThreatBrackets:SetVertexColor(unpack(f.state.glow_colour))
  1968. f.ThreatBrackets:SetSize(THREAT_BRACKETS_SIZE)
  1969. f.ThreatBrackets:Show()
  1970. else
  1971. f.ThreatBrackets:Hide()
  1972. end
  1973. end
  1974. -- create
  1975. function core:CreateThreatBrackets(f)
  1976. local tb = { textures = {} }
  1977. setmetatable(tb,tb_prototype)
  1978.  
  1979. for i,p in ipairs(TB_POINTS) do
  1980. local b = f:CreateTexture(nil,'BACKGROUND',nil,0)
  1981. b:SetTexture(TB_TEXTURE)
  1982. b:SetBlendMode('ADD')
  1983. b:SetPoint(p[1], f.bg, p[2], p[3], p[4])
  1984. b:Hide()
  1985.  
  1986. if i == 2 then
  1987. b:SetTexCoord(1,0,0,1)
  1988. elseif i == 3 then
  1989. b:SetTexCoord(0,1,1,0)
  1990. elseif i == 4 then
  1991. b:SetTexCoord(1,0,1,0)
  1992. end
  1993.  
  1994. tinsert(tb.textures,b)
  1995. end
  1996.  
  1997. f.ThreatBrackets = tb
  1998. f.UpdateThreatBrackets = UpdateThreatBrackets
  1999. end
  2000. end
  2001. -- quest icon ##################################################################
  2002. do
  2003. local SHOW_QUEST_ICON,QUEST_ICON_SIZE,QUEST_ICON_POINT,
  2004. QUEST_ICON_X,QUEST_ICON_Y
  2005. local function Init(icon)
  2006. icon:ClearAllPoints()
  2007. icon:SetSize(QUEST_ICON_SIZE,QUEST_ICON_SIZE)
  2008. icon:SetPoint(POINT_ASSOC[QUEST_ICON_POINT],
  2009. QUEST_ICON_X,QUEST_ICON_Y)
  2010. end
  2011. local function UpdateQuestIcon(frame)
  2012. if SHOW_QUEST_ICON and frame.state.quest then
  2013. frame.QuestIcon:Show()
  2014. else
  2015. frame.QuestIcon:Hide()
  2016. end
  2017. end
  2018. function core:CreateQuestIcon(frame)
  2019. local icon = frame:CreateTexture(nil,'ARTWORK',nil,6)
  2020. icon:SetAtlas('QuestNormal')
  2021. icon:Hide()
  2022. Init(icon)
  2023.  
  2024. frame.QuestIcon = icon
  2025. frame.UpdateQuestIcon = UpdateQuestIcon
  2026. end
  2027. function core:configChangedQuestIcon()
  2028. SHOW_QUEST_ICON = self.profile.show_quest_icon
  2029. QUEST_ICON_SIZE = self:Scale(self.profile.quest_icon_size)
  2030. QUEST_ICON_POINT = self.profile.quest_icon_point
  2031. QUEST_ICON_X = self:Scale(self.profile.quest_icon_x)
  2032. QUEST_ICON_Y = self:Scale(self.profile.quest_icon_y)
  2033.  
  2034. if SHOW_QUEST_ICON then
  2035. -- update existing icons...
  2036. for _,f in addon:Frames() do
  2037. if f.QuestIcon then
  2038. Init(f.QuestIcon)
  2039. end
  2040. end
  2041. end
  2042. end
  2043. end
  2044. -- name show/hide ##############################################################
  2045. function core:ShowNameUpdate(f)
  2046. if f.state.target or
  2047. f.state.threat or
  2048. UnitShouldDisplayName(f.unit)
  2049. then
  2050. f.state.tracked = true
  2051. f.state.no_name = nil
  2052. else
  2053. f.state.tracked = nil
  2054. f.state.no_name = HIDE_NAMES
  2055. end
  2056.  
  2057. if SHOW_ARENA_ID and f.state.arenaid then
  2058. f.state.no_name = nil
  2059. elseif f.state.personal or not SHOW_NAME_TEXT then
  2060. f.state.no_name = true
  2061. end
  2062.  
  2063. if FADE_UNTRACKED or FADE_AVOID_TRACKED or FADE_AVOID_COMBAT then
  2064. plugin_fading:UpdateFrame(f)
  2065. end
  2066. end
  2067. -- nameonly ####################################################################
  2068. do
  2069. local NAMEONLY_ENABLED,NAMEONLY_NO_FONT_STYLE,NAMEONLY_HEALTH_COLOUR
  2070. local NAMEONLY_TARGET,NAMEONLY_ALL_ENEMIES,NAMEONLY_ON_NEUTRAL,
  2071. NAMEONLY_HOSTILE_NPCS,NAMEONLY_DAMAGED_ENEMIES,NAMEONLY_FRIENDLY_NPCS,
  2072. NAMEONLY_DAMAGED_FRIENDS,NAMEONLY_COMBAT_HOSTILE,
  2073. NAMEONLY_COMBAT_FRIENDLY,NAMEONLY_HOSTILE_PLAYERS,
  2074. NAMEONLY_FRIENDLY_PLAYERS,NAMEONLY_COMBAT_HOSTILE_PLAYER
  2075.  
  2076. function core:configChangedNameOnly()
  2077. NAMEONLY_ENABLED = self.profile.nameonly
  2078. NAMEONLY_NO_FONT_STYLE = self.profile.nameonly_no_font_style
  2079. NAMEONLY_HEALTH_COLOUR = self.profile.nameonly_health_colour
  2080.  
  2081. NAMEONLY_TARGET = self.profile.nameonly_target
  2082. NAMEONLY_ALL_ENEMIES = self.profile.nameonly_all_enemies
  2083. NAMEONLY_ON_NEUTRAL = self.profile.nameonly_neutral
  2084. NAMEONLY_HOSTILE_NPCS = self.profile.nameonly_enemies
  2085. NAMEONLY_HOSTILE_PLAYERS = self.profile.nameonly_hostile_players
  2086. NAMEONLY_DAMAGED_ENEMIES = self.profile.nameonly_damaged_enemies
  2087. NAMEONLY_FRIENDLY_NPCS = self.profile.nameonly_friends
  2088. NAMEONLY_FRIENDLY_PLAYERS = self.profile.nameonly_friendly_players
  2089. NAMEONLY_DAMAGED_FRIENDS = self.profile.nameonly_damaged_friends
  2090. NAMEONLY_COMBAT_HOSTILE = self.profile.nameonly_combat_hostile
  2091. NAMEONLY_COMBAT_HOSTILE_PLAYER = self.profile.nameonly_combat_hostile_player
  2092. NAMEONLY_COMBAT_FRIENDLY = self.profile.nameonly_combat_friends
  2093.  
  2094. -- create target/threat glow
  2095. for _,f in addon:Frames() do
  2096. self:CreateNameOnlyGlow(f)
  2097. end
  2098. end
  2099.  
  2100. local function NameOnlyGlow_SetSize(self,size)
  2101. self:SetPoint('TOPLEFT',self:GetParent().NameText,-6-size,size)
  2102. self:SetPoint('BOTTOMRIGHT',self:GetParent().NameText,6+size,-size)
  2103. end
  2104. function core:CreateNameOnlyGlow(f)
  2105. if f.NameOnlyGlow then return end
  2106.  
  2107. local g = f:CreateTexture(nil,'BACKGROUND',nil,-5)
  2108. g:SetTexture(KUI_MEDIA..'t/spark-flat')
  2109. g:Hide()
  2110. -- initial size set in UpdateFrameGlow
  2111.  
  2112. g.SetSize = NameOnlyGlow_SetSize
  2113. f.NameOnlyGlow = g
  2114. end
  2115.  
  2116. function core:NameOnlyUpdateFunctions(f)
  2117. -- update elements affected by nameonly
  2118. f:UpdateNameText()
  2119. f:UpdateHealthText()
  2120. f:UpdateLevelText()
  2121. f:UpdateFrameGlow()
  2122. f:UpdateStateIcon()
  2123. f:UpdateCastBar()
  2124. f:UpdateGuildText()
  2125.  
  2126. if f.TargetArrows then
  2127. f:UpdateTargetArrows()
  2128. end
  2129. if f.ThreatBrackets then
  2130. f:UpdateThreatBrackets()
  2131. end
  2132.  
  2133. if f.NameOnlyGlow and addon.ClassPowersFrame and plugin_classpowers.enabled then
  2134. -- force-update classpowers position (to run our post)
  2135. plugin_classpowers:TargetUpdate()
  2136. end
  2137. end
  2138.  
  2139. local function NameOnlyEnable(f)
  2140. if f.IN_NAMEONLY then return end
  2141. f.IN_NAMEONLY = true
  2142.  
  2143. f.bg:Hide()
  2144. f.HealthBar:Hide()
  2145. f.HealthBar.fill:Hide()
  2146. f.ThreatGlow:Hide()
  2147. f.ThreatBrackets:Hide()
  2148.  
  2149. f.NameText:SetParent(f)
  2150. f.NameText:ClearAllPoints()
  2151. f.NameText:SetPoint('CENTER',.5,0+FRAME_VERTICAL_OFFSET)
  2152. f.NameText:Show()
  2153.  
  2154. f.NameText.fontobject_shadow = true
  2155. f.GuildText.fontobject_shadow = true
  2156. f.NameText.fontobject_no_style = NAMEONLY_NO_FONT_STYLE
  2157. f.GuildText.fontobject_no_style = NAMEONLY_NO_FONT_STYLE
  2158.  
  2159. UpdateFontObject(f.NameText)
  2160. UpdateFontObject(f.GuildText)
  2161.  
  2162. if FADE_AVOID_NAMEONLY then
  2163. plugin_fading:UpdateFrame(f)
  2164. end
  2165. end
  2166. local function NameOnlyDisable(f)
  2167. if not f.IN_NAMEONLY then return end
  2168. f.IN_NAMEONLY = nil
  2169.  
  2170. f.NameText:SetText(f.state.name)
  2171. f.NameText:SetTextColor(1,1,1,1)
  2172. f.NameText:ClearAllPoints()
  2173. f.NameText:SetParent(f.HealthBar)
  2174. f:UpdateNameTextPosition()
  2175.  
  2176. f.GuildText:SetTextColor(1,1,1,1)
  2177.  
  2178. f.bg:Show()
  2179. f.HealthBar:Show()
  2180. f.HealthBar.fill:Show()
  2181.  
  2182. -- nil fontobject overrides
  2183. f.NameText.fontobject_shadow = nil
  2184. f.NameText.fontobject_no_style = nil
  2185. f.GuildText.fontobject_shadow = nil
  2186. f.GuildText.fontobject_no_style = nil
  2187.  
  2188. UpdateFontObject(f.NameText)
  2189. UpdateFontObject(f.GuildText)
  2190.  
  2191. if FADE_AVOID_NAMEONLY then
  2192. plugin_fading:UpdateFrame(f)
  2193. end
  2194. end
  2195. function core:NameOnlyUpdateNameText(f)
  2196. if not f.IN_NAMEONLY then return end
  2197.  
  2198. local text
  2199. if NAMEONLY_HEALTH_COLOUR then
  2200. if f.state.health_cur and f.state.health_cur > 0 and
  2201. f.state.health_max and f.state.health_max > 0
  2202. then
  2203. local health_len =
  2204. strlen(f.state.name) *
  2205. (f.state.health_cur / f.state.health_max)
  2206. -- name w/grey health deficit
  2207. text = kui.utf8sub(f.state.name, 0, health_len)..
  2208. '|cff666666'..kui.utf8sub(f.state.name, health_len+1)
  2209. end
  2210. end
  2211.  
  2212. if LEVEL_NAMEONLY then
  2213. local r,g,b=f.LevelText:GetTextColor()
  2214. text = string.format('|cff%02x%02x%02x',r*255,g*255,b*255)..
  2215. f.LevelText:GetText()..'|r '..(text or f.state.name)
  2216. end
  2217.  
  2218. if text then
  2219. f.NameText:SetText(text)
  2220. end
  2221. end
  2222. function core:NameOnlyHealthUpdate(f)
  2223. if NAMEONLY_DAMAGED_FRIENDS or not f.state.friend then
  2224. self:NameOnlyUpdateNameText(f)
  2225. else
  2226. -- disable/enable based on health
  2227. self:NameOnlyUpdate(f)
  2228. self:NameOnlyUpdateFunctions(f)
  2229. end
  2230. end
  2231.  
  2232. local function NameOnlyFilterFrame(f)
  2233. if not NAMEONLY_ENABLED then return end
  2234. -- disable on personal frame
  2235. if f.state.personal then return end
  2236. -- disable on target
  2237. if not NAMEONLY_TARGET and f.state.target then return end
  2238.  
  2239. if not f.state.attackable and f.state.reaction >= 4 then
  2240. -- friendly;
  2241. -- disable on friends in combat
  2242. if not NAMEONLY_COMBAT_FRIENDLY and f.state.combat then
  2243. return
  2244. end
  2245. if f.state.player then
  2246. -- disable on friendly players
  2247. if not NAMEONLY_FRIENDLY_PLAYERS then
  2248. return
  2249. end
  2250. else
  2251. -- disable on friendly NPCs
  2252. if not NAMEONLY_FRIENDLY_NPCS then
  2253. return
  2254. end
  2255. end
  2256. -- disable on damaged friends
  2257. if not NAMEONLY_DAMAGED_FRIENDS and f.state.health_deficit > 0 then
  2258. return
  2259. end
  2260. else
  2261. if f.state.reaction == 4 then
  2262. -- neutral;
  2263. -- disable on neutral
  2264. if not NAMEONLY_ON_NEUTRAL then
  2265. return
  2266. end
  2267. else
  2268. -- hostile;
  2269. if f.state.player then
  2270. -- disable on hostile players
  2271. if not NAMEONLY_HOSTILE_PLAYERS then
  2272. return
  2273. end
  2274. else
  2275. -- disable on hostile NPCS
  2276. if not NAMEONLY_HOSTILE_NPCS then
  2277. return
  2278. end
  2279. end
  2280. -- disable on attackable units
  2281. if not NAMEONLY_ALL_ENEMIES and f.state.attackable then
  2282. return
  2283. end
  2284. end
  2285. -- neutral & hostile;
  2286. -- disable on damaged enemies
  2287. if not NAMEONLY_DAMAGED_ENEMIES and f.state.health_deficit > 0 then
  2288. return
  2289. end
  2290. if f.state.combat then
  2291. -- disable on enemies in combat
  2292. if not NAMEONLY_COMBAT_HOSTILE then
  2293. return
  2294. end
  2295. -- disable on enemies the player has threat with
  2296. -- (and hostile players in any combat, since we can't check
  2297. -- if they're in combat with the player)
  2298. if not NAMEONLY_COMBAT_HOSTILE_PLAYER and
  2299. (f.state.threat or f.state.player)
  2300. then
  2301. return
  2302. end
  2303. end
  2304. end
  2305. -- enable
  2306. return true
  2307. end
  2308.  
  2309. function core:NameOnlyCombatUpdate(f)
  2310. self:NameOnlyUpdate(f)
  2311. self:NameOnlyUpdateFunctions(f)
  2312. end
  2313. function core:NameOnlyUpdate(f,hide)
  2314. if not hide and NameOnlyFilterFrame(f) then
  2315. NameOnlyEnable(f)
  2316. else
  2317. NameOnlyDisable(f)
  2318. end
  2319. end
  2320. end
  2321. -- init elements ###############################################################
  2322. function core:InitialiseElements()
  2323. plugin_fading = addon:GetPlugin('Fading')
  2324. plugin_classpowers = addon:GetPlugin('ClassPowers')
  2325.  
  2326. -- initialise classpowers...
  2327. self.ClassPowers = {
  2328. on_target = self.profile.classpowers_on_target,
  2329. icon_size = self:Scale(self.profile.classpowers_size),
  2330. bar_width = self:Scale(self.profile.classpowers_bar_width),
  2331. bar_height = self:Scale(self.profile.classpowers_bar_height),
  2332. icon_texture = MEDIA..'combopoint-round',
  2333. icon_sprite = MEDIA..'combopoint',
  2334. icon_glow_texture = MEDIA..'combopoint-glow',
  2335. cd_texture = 'interface/playerframe/classoverlay-runecooldown',
  2336. bar_texture = BAR_TEXTURE,
  2337. point = { 'CENTER','bg','BOTTOM',0,1 },
  2338. colours = {
  2339. overflow = self.profile.classpowers_colour_overflow,
  2340. inactive = self.profile.classpowers_colour_inactive,
  2341. animacharged = self.profile.classpowers_colour_animacharged,
  2342. animacharged_active = self.profile.classpowers_colour_animacharged_active,
  2343. }
  2344. }
  2345.  
  2346. local class = select(2,UnitClass('player'))
  2347. if self.profile['classpowers_colour_'..strlower(class)] then
  2348. self.ClassPowers.colours[class] = self.profile['classpowers_colour_'..strlower(class)]
  2349. end
  2350.  
  2351. local plugin_pb = addon:GetPlugin('PowerBar')
  2352. if plugin_pb then
  2353. -- set custom power colours
  2354. plugin_pb.colours['MANA'] = { .30, .37, .74 }
  2355. end
  2356.  
  2357. -- initialise boss mods...
  2358. self.BossModIcon = {
  2359. icon_size = self:Scale(self.profile.bossmod_icon_size),
  2360. icon_x_offset = self.profile.bossmod_x_offset,
  2361. icon_y_offset = self.profile.bossmod_y_offset,
  2362. control_visibility = self.profile.bossmod_control_visibility,
  2363. clickthrough = self.profile.bossmod_clickthrough,
  2364. }
  2365. end
  2366.  
Advertisement
Add Comment
Please, Sign In to add comment