PlayerFrame.lua

PlayerFrame.lua (8.3.7.35284; unchanged since 8.2.5.31960)
  1. REQUIRED_REST_HOURS = 5;
  2. function PlayerFrame_OnLoad(self)
  3. PlayerFrameHealthBar.LeftText = PlayerFrameHealthBarTextLeft;
  4. PlayerFrameHealthBar.RightText = PlayerFrameHealthBarTextRight;
  5. PlayerFrameManaBar.LeftText = PlayerFrameManaBarTextLeft;
  6. PlayerFrameManaBar.RightText = PlayerFrameManaBarTextRight;
  7. UnitFrame_Initialize(self, "player", PlayerName, PlayerPortrait,
  8. PlayerFrameHealthBar, PlayerFrameHealthBarText,
  9. PlayerFrameManaBar, PlayerFrameManaBarText,
  10. PlayerFrameFlash, nil, nil,
  11. PlayerFrameMyHealPredictionBar, PlayerFrameOtherHealPredictionBar,
  12. PlayerFrameTotalAbsorbBar, PlayerFrameTotalAbsorbBarOverlay, PlayerFrameOverAbsorbGlow,
  13. PlayerFrameOverHealAbsorbGlow, PlayerFrameHealAbsorbBar, PlayerFrameHealAbsorbBarLeftShadow,
  14. PlayerFrameHealAbsorbBarRightShadow, PlayerFrameManaCostPredictionBar);
  15. self.statusCounter = 0;
  16. self.statusSign = -1;
  17. CombatFeedback_Initialize(self, PlayerHitIndicator, 30);
  18. PlayerFrame_Update();
  19. self:RegisterEvent("PLAYER_LEVEL_CHANGED");
  20. self:RegisterEvent("UNIT_FACTION");
  21. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  22. self:RegisterEvent("PLAYER_ENTER_COMBAT");
  23. self:RegisterEvent("PLAYER_LEAVE_COMBAT");
  24. self:RegisterEvent("PLAYER_REGEN_DISABLED");
  25. self:RegisterEvent("PLAYER_REGEN_ENABLED");
  26. self:RegisterEvent("PLAYER_UPDATE_RESTING");
  27. self:RegisterEvent("PARTY_LEADER_CHANGED");
  28. self:RegisterEvent("GROUP_ROSTER_UPDATE");
  29. self:RegisterEvent("READY_CHECK");
  30. self:RegisterEvent("READY_CHECK_CONFIRM");
  31. self:RegisterEvent("READY_CHECK_FINISHED");
  32. self:RegisterEvent("UNIT_ENTERED_VEHICLE");
  33. self:RegisterEvent("UNIT_ENTERING_VEHICLE");
  34. self:RegisterEvent("UNIT_EXITING_VEHICLE");
  35. self:RegisterEvent("UNIT_EXITED_VEHICLE");
  36. self:RegisterEvent("PVP_TIMER_UPDATE");
  37. self:RegisterEvent("PLAYER_ROLES_ASSIGNED");
  38. self:RegisterEvent("VARIABLES_LOADED");
  39. self:RegisterEvent("HONOR_LEVEL_UPDATE");
  40. self:RegisterEvent("QUEST_SESSION_JOINED");
  41. self:RegisterEvent("QUEST_SESSION_LEFT");
  42. self:RegisterUnitEvent("UNIT_COMBAT", "player", "vehicle");
  43. self:RegisterUnitEvent("UNIT_MAXPOWER", "player", "vehicle");
  44. -- Chinese playtime stuff
  45. self:RegisterEvent("PLAYTIME_CHANGED");
  46. PlayerAttackBackground:SetVertexColor(0.8, 0.1, 0.1);
  47. PlayerAttackBackground:SetAlpha(0.4);
  48. self:SetClampRectInsets(20, 0, 0, 0);
  49. local showmenu = function()
  50. ToggleDropDownMenu(1, nil, PlayerFrameDropDown, "PlayerFrame", 106, 27);
  51. end
  52. UIParent_UpdateTopFramePositions();
  53. SecureUnitButton_OnLoad(self, "player", showmenu);
  54. end
  55. --This is overwritten in LocalizationPost for different languages.
  56. function PlayerFrame_UpdateLevelTextAnchor(level)
  57. if ( level >= 100 ) then
  58. PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -62, -17);
  59. else
  60. PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -61, -17);
  61. end
  62. end
  63. function PlayerFrame_Update ()
  64. if ( UnitExists("player") ) then
  65. PlayerFrame_UpdateLevel();
  66. PlayerFrame_UpdatePartyLeader();
  67. PlayerFrame_UpdatePvPStatus();
  68. PlayerFrame_UpdateStatus();
  69. PlayerFrame_UpdatePlaytime();
  70. PlayerFrame_UpdateLayout();
  71. end
  72. end
  73. function PlayerFrame_UpdateLevel()
  74. if ( UnitExists("player") ) then
  75. local level = UnitLevel(PlayerFrame.unit);
  76. local effectiveLevel = UnitEffectiveLevel(PlayerFrame.unit);
  77. if ( effectiveLevel ~= level ) then
  78. PlayerLevelText:SetVertexColor(0.1, 1.0, 0.1, 1.0);
  79. else
  80. PlayerLevelText:SetVertexColor(1.0, 0.82, 0.0, 1.0);
  81. end
  82. PlayerFrame_UpdateLevelTextAnchor(effectiveLevel);
  83. PlayerLevelText:SetText(effectiveLevel);
  84. end
  85. end
  86. function PlayerFrame_UpdatePartyLeader()
  87. if ( UnitIsGroupLeader("player") ) then
  88. if ( HasLFGRestrictions() ) then
  89. PlayerGuideIcon:Show();
  90. PlayerLeaderIcon:Hide();
  91. else
  92. PlayerLeaderIcon:Show()
  93. PlayerGuideIcon:Hide();
  94. end
  95. else
  96. PlayerLeaderIcon:Hide();
  97. PlayerGuideIcon:Hide();
  98. end
  99. end
  100. function PlayerFrame_UpdatePvPStatus()
  101. local factionGroup, factionName = UnitFactionGroup("player");
  102. if ( UnitIsPVPFreeForAll("player") ) then
  103. if ( not PlayerPVPIcon:IsShown() ) then
  104. PlaySound(SOUNDKIT.IG_PVP_UPDATE);
  105. end
  106. local honorLevel = UnitHonorLevel("player");
  107. local honorRewardInfo = C_PvP.GetHonorRewardInfo(honorLevel);
  108. if (honorRewardInfo) then
  109. PlayerPrestigePortrait:SetAtlas("honorsystem-portrait-neutral", false);
  110. PlayerPrestigeBadge:SetTexture(honorRewardInfo.badgeFileDataID);
  111. PlayerPrestigePortrait:Show();
  112. PlayerPrestigeBadge:Show();
  113. PlayerPVPIcon:Hide();
  114. else
  115. PlayerPrestigePortrait:Hide();
  116. PlayerPrestigeBadge:Hide();
  117. PlayerPVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-FFA");
  118. PlayerPVPIcon:Show();
  119. end
  120. -- Setup newbie tooltip
  121. PlayerPVPIconHitArea.tooltipTitle = PVPFFA;
  122. PlayerPVPIconHitArea.tooltipText = NEWBIE_TOOLTIP_PVPFFA;
  123. PlayerPVPIconHitArea:Show();
  124. PlayerPVPTimerText:Hide();
  125. PlayerPVPTimerText.timeLeft = nil;
  126. elseif ( factionGroup and factionGroup ~= "Neutral" and UnitIsPVP("player") ) then
  127. if ( not PlayerPVPIcon:IsShown() ) then
  128. PlaySound(SOUNDKIT.IG_PVP_UPDATE);
  129. end
  130. local honorLevel = UnitHonorLevel("player");
  131. local honorRewardInfo = C_PvP.GetHonorRewardInfo(honorLevel);
  132. if (honorRewardInfo) then
  133. -- ugly special case handling for mercenary mode
  134. if ( UnitIsMercenary("player") ) then
  135. if ( factionGroup == "Horde" ) then
  136. factionGroup = "Alliance";
  137. elseif ( factionGroup == "Alliance" ) then
  138. factionGroup = "Horde";
  139. end
  140. end
  141. PlayerPrestigePortrait:SetAtlas("honorsystem-portrait-"..factionGroup, false);
  142. PlayerPrestigeBadge:SetTexture(honorRewardInfo.badgeFileDataID);
  143. PlayerPrestigePortrait:Show();
  144. PlayerPrestigeBadge:Show();
  145. PlayerPVPIcon:Hide();
  146. else
  147. PlayerPrestigePortrait:Hide();
  148. PlayerPrestigeBadge:Hide();
  149. PlayerPVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-"..factionGroup);
  150. -- ugly special case handling for mercenary mode
  151. if ( UnitIsMercenary("player") ) then
  152. if ( factionGroup == "Horde" ) then
  153. PlayerPVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-Alliance");
  154. elseif ( factionGroup == "Alliance" ) then
  155. PlayerPVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-Horde");
  156. end
  157. end
  158. end
  159. PlayerPVPIcon:Show();
  160. -- Setup newbie tooltip
  161. PlayerPVPIconHitArea.tooltipTitle = factionName;
  162. PlayerPVPIconHitArea.tooltipText = _G["NEWBIE_TOOLTIP_"..strupper(factionGroup)];
  163. PlayerPVPIconHitArea:Show();
  164. else
  165. PlayerPrestigePortrait:Hide();
  166. PlayerPrestigeBadge:Hide();
  167. PlayerPVPIcon:Hide();
  168. PlayerPVPIconHitArea:Hide();
  169. PlayerPVPTimerText:Hide();
  170. PlayerPVPTimerText.timeLeft = nil;
  171. end
  172. end
  173. function PlayerFrame_OnEvent(self, event, ...)
  174. UnitFrame_OnEvent(self, event, ...);
  175. local arg1, arg2, arg3, arg4, arg5 = ...;
  176. if ( event == "PLAYER_LEVEL_CHANGED" ) then
  177. PlayerFrame_Update();
  178. elseif ( event == "UNIT_COMBAT" ) then
  179. if ( arg1 == self.unit ) then
  180. CombatFeedback_OnCombatEvent(self, arg2, arg3, arg4, arg5);
  181. end
  182. elseif ( event == "UNIT_FACTION" ) then
  183. if ( arg1 == "player" ) then
  184. PlayerFrame_UpdatePvPStatus();
  185. end
  186. elseif ( event == "PLAYER_ENTERING_WORLD" ) then
  187. PlayerFrame_ResetPosition(self);
  188. PlayerFrame_ToPlayerArt(self);
  189. -- if ( UnitHasVehicleUI("player") ) then
  190. -- UnitFrame_SetUnit(self, "vehicle", PlayerFrameHealthBar, PlayerFrameManaBar);
  191. -- else
  192. -- UnitFrame_SetUnit(self, "player", PlayerFrameHealthBar, PlayerFrameManaBar);
  193. -- end
  194. self.inCombat = nil;
  195. self.onHateList = nil;
  196. PlayerFrame_Update();
  197. PlayerFrame_UpdateStatus();
  198. PlayerFrame_UpdateRolesAssigned();
  199. if ( IsPVPTimerRunning() ) then
  200. PlayerPVPTimerText:Show();
  201. PlayerPVPTimerText.timeLeft = GetPVPTimer();
  202. else
  203. PlayerPVPTimerText:Hide();
  204. PlayerPVPTimerText.timeLeft = nil;
  205. end
  206. QuestSessionSync.Icon:SetShown(C_QuestSession.HasJoined());
  207. elseif ( event == "PLAYER_ENTER_COMBAT" ) then
  208. self.inCombat = 1;
  209. PlayerFrame_UpdateStatus();
  210. elseif ( event == "PLAYER_LEAVE_COMBAT" ) then
  211. self.inCombat = nil;
  212. PlayerFrame_UpdateStatus();
  213. elseif ( event == "PLAYER_REGEN_DISABLED" ) then
  214. self.onHateList = 1;
  215. PlayerFrame_UpdateStatus();
  216. elseif ( event == "PLAYER_REGEN_ENABLED" ) then
  217. self.onHateList = nil;
  218. PlayerFrame_UpdateStatus();
  219. elseif ( event == "PLAYER_UPDATE_RESTING" ) then
  220. PlayerFrame_UpdateStatus();
  221. elseif ( event == "PARTY_LEADER_CHANGED" or event == "GROUP_ROSTER_UPDATE" ) then
  222. PlayerFrame_UpdateGroupIndicator();
  223. PlayerFrame_UpdatePartyLeader();
  224. PlayerFrame_UpdateReadyCheck();
  225. elseif ( event == "PLAYTIME_CHANGED" ) then
  226. PlayerFrame_UpdatePlaytime();
  227. elseif ( event == "READY_CHECK" or event == "READY_CHECK_CONFIRM" ) then
  228. PlayerFrame_UpdateReadyCheck();
  229. elseif ( event == "READY_CHECK_FINISHED" ) then
  230. ReadyCheck_Finish(PlayerFrameReadyCheck, DEFAULT_READY_CHECK_STAY_TIME);
  231. elseif ( event == "UNIT_ENTERING_VEHICLE" ) then
  232. if ( arg1 == "player" ) then
  233. if ( arg2 ) then
  234. PlayerFrame_AnimateOut(self);
  235. else
  236. if ( PlayerFrame.state == "vehicle" ) then
  237. PlayerFrame_AnimateOut(self);
  238. end
  239. end
  240. end
  241. elseif ( event == "UNIT_ENTERED_VEHICLE" ) then
  242. if ( arg1 == "player" ) then
  243. self.inSeat = true;
  244. if (UnitInVehicleHidesPetFrame("player")) then
  245. self.vehicleHidesPet = true;
  246. end
  247. PlayerFrame_UpdateArt(self);
  248. end
  249. elseif ( event == "UNIT_EXITING_VEHICLE" ) then
  250. if ( arg1 == "player" ) then
  251. if ( self.state == "vehicle" ) then
  252. PlayerFrame_AnimateOut(self);
  253. else
  254. self.updatePetFrame = true;
  255. end
  256. self.vehicleHidesPet = false;
  257. end
  258. elseif ( event == "UNIT_EXITED_VEHICLE" ) then
  259. if ( arg1 == "player" ) then
  260. self.inSeat = true;
  261. PlayerFrame_UpdateArt(self);
  262. end
  263. elseif ( event == "PVP_TIMER_UPDATE" ) then
  264. if ( IsPVPTimerRunning() ) then
  265. PlayerPVPTimerText:Show();
  266. PlayerPVPTimerText.timeLeft = GetPVPTimer();
  267. else
  268. PlayerPVPTimerText:Hide();
  269. PlayerPVPTimerText.timeLeft = nil;
  270. end
  271. elseif ( event == "PLAYER_ROLES_ASSIGNED" ) then
  272. PlayerFrame_UpdateRolesAssigned();
  273. elseif ( event == "VARIABLES_LOADED" ) then
  274. PlayerFrame_SetLocked(not PLAYER_FRAME_UNLOCKED);
  275. if ( PLAYER_FRAME_CASTBARS_SHOWN ) then
  276. PlayerFrame_AttachCastBar();
  277. end
  278. elseif ( event == "HONOR_LEVEL_UPDATE" ) then
  279. PlayerFrame_UpdatePvPStatus();
  280. elseif ( event == "QUEST_SESSION_JOINED" ) then
  281. QuestSessionSync.Icon:Show();
  282. elseif ( event == "QUEST_SESSION_LEFT" ) then
  283. QuestSessionSync.Icon:Hide();
  284. end
  285. end
  286. function PlayerFrame_UpdateRolesAssigned()
  287. local frame = PlayerFrame;
  288. local icon = _G[frame:GetName().."RoleIcon"];
  289. local role = UnitGroupRolesAssigned("player");
  290. if ( role == "TANK" or role == "HEALER" or role == "DAMAGER") then
  291. icon:SetTexCoord(GetTexCoordsForRoleSmallCircle(role));
  292. icon:Show();
  293. else
  294. icon:Hide();
  295. end
  296. end
  297. local function PlayerFrame_AnimPos(self, fraction)
  298. return "TOPLEFT", UIParent, "TOPLEFT", -19, fraction*140-4;
  299. end
  300. function PlayerFrame_ResetPosition(self)
  301. CancelAnimations(PlayerFrame);
  302. self.isAnimatedOut = false;
  303. UIParent_UpdateTopFramePositions();
  304. self.inSequence = false;
  305. PetFrame_Update(PetFrame);
  306. end
  307. local PlayerFrameAnimTable = {
  308. totalTime = 0.3,
  309. updateFunc = "SetPoint",
  310. getPosFunc = PlayerFrame_AnimPos,
  311. }
  312. function PlayerFrame_AnimateOut(self)
  313. self.inSeat = false;
  314. self.animFinished = false;
  315. self.inSequence = true;
  316. self.isAnimatedOut = true;
  317. if ( self:IsUserPlaced() ) then
  318. PlayerFrame_AnimFinished(PlayerFrame);
  319. else
  320. SetUpAnimation(PlayerFrame, PlayerFrameAnimTable, PlayerFrame_AnimFinished, false)
  321. end
  322. end
  323. function PlayerFrame_AnimFinished(self)
  324. self.animFinished = true;
  325. PlayerFrame_UpdateArt(self);
  326. end
  327. function PlayerFrame_IsAnimatedOut(self)
  328. return self.isAnimatedOut;
  329. end
  330. function PlayerFrame_UpdateArt(self)
  331. if ( self.animFinished and self.inSeat and self.inSequence) then
  332. if ( self:IsUserPlaced() ) then
  333. PlayerFrame_SequenceFinished(PlayerFrame);
  334. else
  335. SetUpAnimation(PlayerFrame, PlayerFrameAnimTable, PlayerFrame_SequenceFinished, true)
  336. end
  337. if ( UnitHasVehiclePlayerFrameUI("player") ) then
  338. PlayerFrame_ToVehicleArt(self, UnitVehicleSkin("player"));
  339. else
  340. PlayerFrame_ToPlayerArt(self);
  341. end
  342. elseif ( self.updatePetFrame ) then
  343. -- leaving a vehicle that didn't change player art
  344. self.updatePetFrame = false;
  345. PetFrame_Update(PetFrame);
  346. end
  347. end
  348. function PlayerFrame_SequenceFinished(self)
  349. self.inSequence = false;
  350. PetFrame_Update(PetFrame);
  351. end
  352. function PlayerFrame_ToVehicleArt(self, vehicleType)
  353. --Swap frame
  354. PlayerFrame.state = "vehicle";
  355. UnitFrame_SetUnit(self, "vehicle", PlayerFrameHealthBar, PlayerFrameManaBar);
  356. UnitFrame_SetUnit(PetFrame, "player", PetFrameHealthBar, PetFrameManaBar);
  357. PetFrame_Update(PetFrame);
  358. PlayerFrame_Update();
  359. BuffFrame_Update();
  360. ComboFrame_Update(ComboFrame);
  361. PlayerFrameTexture:Hide();
  362. if ( vehicleType == "Natural" ) then
  363. PlayerFrameVehicleTexture:SetTexture("Interface\\Vehicles\\UI-Vehicle-Frame-Organic");
  364. PlayerFrameFlash:SetTexture("Interface\\Vehicles\\UI-Vehicle-Frame-Organic-Flash");
  365. PlayerFrameFlash:SetTexCoord(-0.02, 1, 0.07, 0.86);
  366. PlayerFrameHealthBar:SetWidth(103);
  367. PlayerFrameHealthBar:SetPoint("TOPLEFT",116,-41);
  368. PlayerFrameManaBar:SetWidth(103);
  369. PlayerFrameManaBar:SetPoint("TOPLEFT",116,-52);
  370. else
  371. PlayerFrameVehicleTexture:SetTexture("Interface\\Vehicles\\UI-Vehicle-Frame");
  372. PlayerFrameFlash:SetTexture("Interface\\Vehicles\\UI-Vehicle-Frame-Flash");
  373. PlayerFrameFlash:SetTexCoord(-0.02, 1, 0.07, 0.86);
  374. PlayerFrameHealthBar:SetWidth(100);
  375. PlayerFrameHealthBar:SetPoint("TOPLEFT",119,-41);
  376. PlayerFrameManaBar:SetWidth(100);
  377. PlayerFrameManaBar:SetPoint("TOPLEFT",119,-52);
  378. end
  379. PlayerFrame_ShowVehicleTexture();
  380. PlayerName:SetPoint("CENTER",50,23);
  381. PlayerLeaderIcon:SetPoint("TOPLEFT",40,-12);
  382. PlayerFrameGroupIndicator:SetPoint("BOTTOMLEFT", PlayerFrame, "TOPLEFT", 97, -13);
  383. PlayerFrameBackground:SetWidth(114);
  384. PlayerLevelText:Hide();
  385. end
  386. function PlayerFrame_ToPlayerArt(self)
  387. --Unswap frame
  388. PlayerFrame.state = "player";
  389. UnitFrame_SetUnit(self, "player", PlayerFrameHealthBar, PlayerFrameManaBar);
  390. UnitFrame_SetUnit(PetFrame, "pet", PetFrameHealthBar, PetFrameManaBar);
  391. PetFrame_Update(PetFrame);
  392. PlayerFrame_Update();
  393. BuffFrame_Update();
  394. ComboFrame_Update(ComboFrame);
  395. PlayerFrameTexture:Show();
  396. PlayerFrame_HideVehicleTexture();
  397. PlayerName:SetPoint("CENTER",50,19);
  398. PlayerLeaderIcon:SetPoint("TOPLEFT",40,-12);
  399. PlayerFrameGroupIndicator:SetPoint("BOTTOMLEFT", PlayerFrame, "TOPLEFT", 97, -20);
  400. PlayerFrameHealthBar:SetWidth(119);
  401. PlayerFrameHealthBar:SetPoint("TOPLEFT",106,-41);
  402. PlayerFrameManaBar:SetWidth(119);
  403. PlayerFrameManaBar:SetPoint("TOPLEFT",106,-52);
  404. PlayerFrameBackground:SetWidth(119);
  405. PlayerLevelText:Show();
  406. PlayerFrameFlash:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Flash");
  407. PlayerFrameFlash:SetTexCoord(0.9453125, 0, 0, 0.181640625);
  408. end
  409. function PlayerFrame_UpdateVoiceStatus (status)
  410. PlayerSpeakerFrame:Hide();
  411. end
  412. function PlayerFrame_UpdateReadyCheck ()
  413. local readyCheckStatus = GetReadyCheckStatus("player");
  414. if ( readyCheckStatus ) then
  415. if ( readyCheckStatus == "ready" ) then
  416. ReadyCheck_Confirm(PlayerFrameReadyCheck, 1);
  417. elseif ( readyCheckStatus == "notready" ) then
  418. ReadyCheck_Confirm(PlayerFrameReadyCheck, 0);
  419. else -- "waiting"
  420. ReadyCheck_Start(PlayerFrameReadyCheck);
  421. end
  422. else
  423. PlayerFrameReadyCheck:Hide();
  424. end
  425. end
  426. function PlayerFrame_OnUpdate (self, elapsed)
  427. if ( PlayerStatusTexture:IsShown() ) then
  428. local alpha = 255;
  429. local counter = self.statusCounter + elapsed;
  430. local sign = self.statusSign;
  431. if ( counter > 0.5 ) then
  432. sign = -sign;
  433. self.statusSign = sign;
  434. end
  435. counter = mod(counter, 0.5);
  436. self.statusCounter = counter;
  437. if ( sign == 1 ) then
  438. alpha = (55 + (counter * 400)) / 255;
  439. else
  440. alpha = (255 - (counter * 400)) / 255;
  441. end
  442. PlayerStatusTexture:SetAlpha(alpha);
  443. PlayerStatusGlow:SetAlpha(alpha);
  444. end
  445. if ( PlayerPVPTimerText.timeLeft ) then
  446. PlayerPVPTimerText.timeLeft = PlayerPVPTimerText.timeLeft - elapsed*1000;
  447. local timeLeft = PlayerPVPTimerText.timeLeft;
  448. if ( timeLeft < 0 ) then
  449. PlayerPVPTimerText:Hide()
  450. end
  451. PlayerPVPTimerText:SetFormattedText(SecondsToTimeAbbrev(floor(timeLeft/1000)));
  452. else
  453. PlayerPVPTimerText:Hide();
  454. end
  455. CombatFeedback_OnUpdate(self, elapsed);
  456. end
  457. function PlayerFrame_OnReceiveDrag ()
  458. if ( CursorHasItem() ) then
  459. AutoEquipCursorItem();
  460. end
  461. end
  462. function PlayerFrame_UpdateStatus()
  463. if ( UnitHasVehiclePlayerFrameUI("player") ) then
  464. PlayerStatusTexture:Hide()
  465. PlayerRestIcon:Hide()
  466. PlayerAttackIcon:Hide()
  467. PlayerRestGlow:Hide()
  468. PlayerAttackGlow:Hide()
  469. PlayerStatusGlow:Hide()
  470. PlayerAttackBackground:Hide()
  471. elseif ( IsResting() ) then
  472. PlayerStatusTexture:SetVertexColor(1.0, 0.88, 0.25, 1.0);
  473. PlayerStatusTexture:Show();
  474. PlayerRestIcon:Show();
  475. PlayerAttackIcon:Hide();
  476. PlayerRestGlow:Show();
  477. PlayerAttackGlow:Hide();
  478. PlayerStatusGlow:Show();
  479. PlayerAttackBackground:Hide();
  480. elseif ( PlayerFrame.inCombat ) then
  481. PlayerStatusTexture:SetVertexColor(1.0, 0.0, 0.0, 1.0);
  482. PlayerStatusTexture:Show();
  483. PlayerAttackIcon:Show();
  484. PlayerRestIcon:Hide();
  485. PlayerAttackGlow:Show();
  486. PlayerRestGlow:Hide();
  487. PlayerStatusGlow:Show();
  488. PlayerAttackBackground:Show();
  489. elseif ( PlayerFrame.onHateList ) then
  490. PlayerAttackIcon:Show();
  491. PlayerRestIcon:Hide();
  492. PlayerStatusGlow:Hide();
  493. PlayerAttackBackground:Hide();
  494. else
  495. PlayerStatusTexture:Hide();
  496. PlayerRestIcon:Hide();
  497. PlayerAttackIcon:Hide();
  498. PlayerStatusGlow:Hide();
  499. PlayerAttackBackground:Hide();
  500. end
  501. end
  502. function PlayerFrame_UpdateGroupIndicator()
  503. PlayerFrameGroupIndicator:Hide();
  504. local name, rank, subgroup;
  505. if ( not IsInRaid() ) then
  506. PlayerFrameGroupIndicator:Hide();
  507. return;
  508. end
  509. local numGroupMembers = GetNumGroupMembers();
  510. for i=1, MAX_RAID_MEMBERS do
  511. if ( i <= numGroupMembers ) then
  512. name, rank, subgroup = GetRaidRosterInfo(i);
  513. -- Set the player's group number indicator
  514. if ( name == UnitName("player") ) then
  515. PlayerFrameGroupIndicatorText:SetText(GROUP.." "..subgroup);
  516. PlayerFrameGroupIndicator:SetWidth(PlayerFrameGroupIndicatorText:GetWidth()+40);
  517. PlayerFrameGroupIndicator:Show();
  518. end
  519. end
  520. end
  521. end
  522. function PlayerFrameDropDown_OnLoad (self)
  523. UIDropDownMenu_SetInitializeFunction(self, PlayerFrameDropDown_Initialize);
  524. UIDropDownMenu_SetDisplayMode(self, "MENU");
  525. end
  526. function PlayerFrameDropDown_Initialize ()
  527. if ( PlayerFrame.unit == "vehicle" ) then
  528. UnitPopup_ShowMenu(PlayerFrameDropDown, "VEHICLE", "vehicle");
  529. else
  530. UnitPopup_ShowMenu(PlayerFrameDropDown, "SELF", "player");
  531. end
  532. end
  533. function PlayerFrame_UpdatePlaytime()
  534. if ( PartialPlayTime() ) then
  535. PlayerPlayTimeIcon:SetTexture("Interface\\CharacterFrame\\UI-Player-PlayTimeTired");
  536. PlayerPlayTime.tooltip = format(PLAYTIME_TIRED, REQUIRED_REST_HOURS - floor(GetBillingTimeRested()/60));
  537. PlayerPlayTime:Show();
  538. elseif ( NoPlayTime() ) then
  539. PlayerPlayTimeIcon:SetTexture("Interface\\CharacterFrame\\UI-Player-PlayTimeUnhealthy");
  540. PlayerPlayTime.tooltip = format(PLAYTIME_UNHEALTHY, REQUIRED_REST_HOURS - floor(GetBillingTimeRested()/60));
  541. PlayerPlayTime:Show();
  542. else
  543. PlayerPlayTime:Hide();
  544. end
  545. end
  546. function PlayerFrame_SetupDeathKnightLayout ()
  547. PlayerFrame:SetHitRectInsets(0,0,0,33);
  548. end
  549. function PlayerFrameMultiGroupFrame_OnLoad(self)
  550. self:RegisterEvent("GROUP_ROSTER_UPDATE");
  551. self:RegisterEvent("UPDATE_CHAT_COLOR");
  552. self:RegisterForClicks("LeftButtonUp", "RightButtonUp");
  553. end
  554. function PlayerFrameMultiGroupFrame_OnEvent(self, event, ...)
  555. if ( event == "GROUP_ROSTER_UPDATE" ) then
  556. if ( IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE) ) then
  557. self:Show();
  558. else
  559. self:Hide();
  560. end
  561. elseif ( event == "UPDATE_CHAT_COLOR" ) then
  562. local public = ChatTypeInfo["INSTANCE_CHAT"];
  563. local private = ChatTypeInfo["PARTY"];
  564. self.HomePartyIcon:SetVertexColor(private.r, private.g, private.b);
  565. self.InstancePartyIcon:SetVertexColor(public.r, public.g, public.b);
  566. end
  567. end
  568. function PlayerFrameMultiGroupframe_OnEnter(self)
  569. GameTooltip_SetDefaultAnchor(GameTooltip, self);
  570. self.homePlayers = GetHomePartyInfo(self.homePlayers);
  571. if ( IsInRaid(LE_PARTY_CATEGORY_HOME) ) then
  572. GameTooltip:SetText(PLAYER_IN_MULTI_GROUP_RAID_MESSAGE, nil, nil, nil, nil, true);
  573. GameTooltip:AddLine(format(MEMBER_COUNT_IN_RAID_LIST, #self.homePlayers + 1), 1, 1, 1, true);
  574. else
  575. GameTooltip:AddLine(PLAYER_IN_MULTI_GROUP_PARTY_MESSAGE, 1, 1, 1, true);
  576. local playerList = self.homePlayers[1] or "";
  577. for i=2, #self.homePlayers do
  578. playerList = playerList..PLAYER_LIST_DELIMITER..self.homePlayers[i];
  579. end
  580. GameTooltip:AddLine(format(MEMBERS_IN_PARTY_LIST, playerList));
  581. end
  582. GameTooltip:Show();
  583. end
  584. CustomClassLayouts = {
  585. ["DEATHKNIGHT"] = PlayerFrame_SetupDeathKnightLayout,
  586. }
  587. local layoutUpdated = false;
  588. function PlayerFrame_UpdateLayout ()
  589. if ( layoutUpdated ) then
  590. return;
  591. end
  592. layoutUpdated = true;
  593. local _, class = UnitClass("player");
  594. if ( CustomClassLayouts[class] ) then
  595. CustomClassLayouts[class]();
  596. end
  597. end
  598. local RUNICPOWERBARHEIGHT = 63;
  599. local RUNICPOWERBARWIDTH = 64;
  600. local RUNICGLOW_FADEALPHA = .050
  601. local RUNICGLOW_MINALPHA = .40
  602. local RUNICGLOW_MAXALPHA = .80
  603. local RUNICGLOW_THROBINTERVAL = .8;
  604. RUNICGLOW_FINISHTHROBANDHIDE = false;
  605. local RUNICGLOW_THROBSTART = 0;
  606. function PlayerFrame_SetRunicPower (runicPower)
  607. PlayerFrameRunicPowerBar:SetHeight(RUNICPOWERBARHEIGHT * (runicPower / 100));
  608. PlayerFrameRunicPowerBar:SetTexCoord(0, 1, (1 - (runicPower / 100)), 1);
  609. if ( runicPower >= 90 ) then
  610. -- Oh, God help us for these function and variable names.
  611. RUNICGLOW_FINISHTHROBANDHIDE = false;
  612. if ( not PlayerFrameRunicPowerGlow:IsShown() ) then
  613. PlayerFrameRunicPowerGlow:Show();
  614. end
  615. PlayerFrameRunicPowerGlow:GetParent():SetScript("OnUpdate", DeathKnniggetThrobFunction);
  616. elseif ( PlayerFrameRunicPowerGlow:GetParent():GetScript("OnUpdate") ) then
  617. RUNICGLOW_FINISHTHROBANDHIDE = true;
  618. else
  619. PlayerFrameRunicPowerGlow:Hide();
  620. end
  621. end
  622. local firstFadeIn = true;
  623. function DeathKnniggetThrobFunction (self, elapsed)
  624. if ( RUNICGLOW_THROBSTART == 0 ) then
  625. RUNICGLOW_THROBSTART = GetTime();
  626. elseif ( not RUNICGLOW_FINISHTHROBANDHIDE ) then
  627. local interval = RUNICGLOW_THROBINTERVAL - math.abs( .9 - (UnitPower("player") / 100));
  628. local animTime = GetTime() - RUNICGLOW_THROBSTART;
  629. if ( animTime >= interval ) then
  630. -- Fading out
  631. PlayerFrameRunicPowerGlow:SetAlpha(math.max(RUNICGLOW_MINALPHA, math.min(RUNICGLOW_MAXALPHA, RUNICGLOW_MAXALPHA * interval/animTime)));
  632. if ( animTime >= interval * 2 ) then
  633. self.timeSinceThrob = 0;
  634. RUNICGLOW_THROBSTART = GetTime();
  635. end
  636. firstFadeIn = false;
  637. else
  638. -- Fading in
  639. if ( firstFadeIn ) then
  640. PlayerFrameRunicPowerGlow:SetAlpha(math.max(RUNICGLOW_FADEALPHA, math.min(RUNICGLOW_MAXALPHA, RUNICGLOW_MAXALPHA * animTime/interval)));
  641. else
  642. PlayerFrameRunicPowerGlow:SetAlpha(math.max(RUNICGLOW_MINALPHA, math.min(RUNICGLOW_MAXALPHA, RUNICGLOW_MAXALPHA * animTime/interval)));
  643. end
  644. end
  645. elseif ( RUNICGLOW_FINISHTHROBANDHIDE ) then
  646. local currentAlpha = PlayerFrameRunicPowerGlow:GetAlpha();
  647. local animTime = GetTime() - RUNICGLOW_THROBSTART;
  648. local interval = RUNICGLOW_THROBINTERVAL;
  649. firstFadeIn = true;
  650. if ( animTime >= interval ) then
  651. -- Already fading out, just keep fading out.
  652. local alpha = math.min(PlayerFrameRunicPowerGlow:GetAlpha(), RUNICGLOW_MAXALPHA * (interval/(animTime*(animTime/2))));
  653. PlayerFrameRunicPowerGlow:SetAlpha(alpha);
  654. if ( alpha <= RUNICGLOW_FADEALPHA ) then
  655. self.timeSinceThrob = 0;
  656. RUNICGLOW_THROBSTART = 0;
  657. PlayerFrameRunicPowerGlow:Hide();
  658. self:SetScript("OnUpdate", nil);
  659. RUNICGLOW_FINISHTHROBANDHIDE = false;
  660. return;
  661. end
  662. else
  663. -- Was fading in, start fading out
  664. animTime = interval;
  665. end
  666. end
  667. end
  668. function PlayerFrame_ShowVehicleTexture()
  669. PlayerFrameVehicleTexture:Show();
  670. local _, class = UnitClass("player");
  671. if ( PlayerFrame.classPowerBar ) then
  672. PlayerFrame.classPowerBar:Hide();
  673. elseif ( class == "SHAMAN" ) then
  674. TotemFrame:Hide();
  675. elseif ( class == "DEATHKNIGHT" ) then
  676. RuneFrame:Hide();
  677. elseif ( class == "PRIEST" ) then
  678. PriestBarFrame:Hide();
  679. end
  680. ComboPointPlayerFrame:Setup();
  681. end
  682. function PlayerFrame_HideVehicleTexture()
  683. PlayerFrameVehicleTexture:Hide();
  684. local _, class = UnitClass("player");
  685. if ( PlayerFrame.classPowerBar ) then
  686. PlayerFrame.classPowerBar:Setup();
  687. elseif ( class == "SHAMAN" ) then
  688. TotemFrame_Update();
  689. elseif ( class == "DEATHKNIGHT" ) then
  690. RuneFrame:Show();
  691. elseif ( class == "PRIEST" ) then
  692. PriestBarFrame_CheckAndShow();
  693. end
  694. ComboPointPlayerFrame:Setup();
  695. end
  696. function PlayerFrame_OnDragStart(self)
  697. self:StartMoving();
  698. self:SetUserPlaced(true);
  699. self:SetClampedToScreen(true);
  700. end
  701. function PlayerFrame_OnDragStop(self)
  702. self:StopMovingOrSizing();
  703. end
  704. function PlayerFrame_SetLocked(locked)
  705. PLAYER_FRAME_UNLOCKED = not locked;
  706. if ( locked ) then
  707. PlayerFrame:RegisterForDrag(); --Unregister all buttons.
  708. else
  709. PlayerFrame:RegisterForDrag("LeftButton");
  710. end
  711. end
  712. function PlayerFrame_ResetUserPlacedPosition()
  713. PlayerFrame:ClearAllPoints();
  714. PlayerFrame:SetUserPlaced(false);
  715. PlayerFrame:SetClampedToScreen(false);
  716. PlayerFrame_SetLocked(true);
  717. UIParent_UpdateTopFramePositions();
  718. end
  719. --
  720. -- Functions for having the cast bar underneath the player frame
  721. --
  722. function PlayerFrame_AttachCastBar()
  723. local castBar = CastingBarFrame;
  724. local petCastBar = PetCastingBarFrame;
  725. -- player
  726. castBar.ignoreFramePositionManager = true;
  727. castBar:SetAttribute("ignoreFramePositionManager", true);
  728. CastingBarFrame_SetLook(castBar, "UNITFRAME");
  729. castBar:ClearAllPoints();
  730. castBar:SetPoint("LEFT", PlayerFrame, 78, 0);
  731. -- pet
  732. CastingBarFrame_SetLook(petCastBar, "UNITFRAME");
  733. petCastBar:SetWidth(150);
  734. petCastBar:SetHeight(10);
  735. petCastBar:ClearAllPoints();
  736. petCastBar:SetPoint("TOP", castBar, "TOP", 0, 0);
  737. PlayerFrame_AdjustAttachments();
  738. UIParent_ManageFramePositions();
  739. end
  740. function PlayerFrame_DetachCastBar()
  741. local castBar = CastingBarFrame;
  742. local petCastBar = PetCastingBarFrame;
  743. -- player
  744. castBar.ignoreFramePositionManager = nil;
  745. castBar:SetAttribute("ignoreFramePositionManager", false);
  746. CastingBarFrame_SetLook(castBar, "CLASSIC");
  747. castBar:ClearAllPoints();
  748. -- pet
  749. CastingBarFrame_SetLook(petCastBar, "CLASSIC");
  750. petCastBar:SetWidth(195);
  751. petCastBar:SetHeight(13);
  752. petCastBar:ClearAllPoints();
  753. petCastBar:SetPoint("BOTTOM", castBar, "TOP", 0, 12);
  754. UIParent_ManageFramePositions();
  755. end
  756. function PlayerFrame_AdjustAttachments()
  757. if ( not PLAYER_FRAME_CASTBARS_SHOWN ) then
  758. return;
  759. end
  760. if ( PetFrame and PetFrame:IsShown() ) then
  761. CastingBarFrame:SetPoint("TOP", PetFrame, "BOTTOM", 0, -4);
  762. elseif ( TotemFrame and TotemFrame:IsShown() ) then
  763. CastingBarFrame:SetPoint("TOP", TotemFrame, "BOTTOM", 0, 2);
  764. else
  765. local _, class = UnitClass("player");
  766. if ( class == "PALADIN" ) then
  767. CastingBarFrame:SetPoint("TOP", PlayerFrame, "BOTTOM", 0, -6);
  768. elseif ( class == "DRUID" ) then
  769. CastingBarFrame:SetPoint("TOP", PlayerFrame, "BOTTOM", 0, 10);
  770. elseif ( class == "PRIEST" and PriestBarFrame:IsShown() ) then
  771. CastingBarFrame:SetPoint("TOP", PlayerFrame, "BOTTOM", 0, -2);
  772. elseif ( class == "DEATHKNIGHT" or class == "WARLOCK" ) then
  773. CastingBarFrame:SetPoint("TOP", PlayerFrame, "BOTTOM", 0, 4);
  774. elseif ( class == "MONK" ) then
  775. CastingBarFrame:SetPoint("TOP", PlayerFrame, "BOTTOM", 0, -1);
  776. else
  777. CastingBarFrame:SetPoint("TOP", PlayerFrame, "BOTTOM", 0, 10);
  778. end
  779. end
  780. end