TotemFrame.lua

TotemFrame.lua (9.0.2.36294; unchanged since 7.1.0.22908)
  1. function TotemFrame_OnLoad(self)
  2. self:RegisterEvent("PLAYER_TOTEM_UPDATE");
  3. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  4. self:RegisterEvent("UPDATE_SHAPESHIFT_FORM");
  5. self:RegisterEvent("PLAYER_TALENT_UPDATE");
  6. local _, class = UnitClass("player");
  7. if ( class == "DEATHKNIGHT" ) then
  8. self:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 65, -55);
  9. elseif ( class == "WARLOCK" ) then
  10. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 28, -85);
  11. end
  12. end
  13. function TotemFrame_Update()
  14. local _, class = UnitClass("player");
  15. local priorities = STANDARD_TOTEM_PRIORITIES;
  16. if (class == "SHAMAN") then
  17. priorities = SHAMAN_TOTEM_PRIORITIES;
  18. end
  19. local hasPet = PetFrame and PetFrame:IsShown();
  20. if ( class == "PALADIN" or class == "DEATHKNIGHT" ) then
  21. if ( hasPet ) then
  22. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 28, -75);
  23. else
  24. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 67, -63);
  25. end
  26. elseif ( class == "DRUID" ) then
  27. local form = GetShapeshiftFormID();
  28. if ( form == MOONKIN_FORM or not form ) then
  29. if ( GetSpecialization() == 1 ) then
  30. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 115, -88);
  31. else
  32. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "BOTTOMLEFT", 99, 38);
  33. end
  34. elseif ( form == BEAR_FORM or form == CAT_FORM ) then
  35. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 99, -78);
  36. else
  37. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "BOTTOMLEFT", 99, 38);
  38. end
  39. elseif ( class == "MONK" ) then
  40. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 28, -75);
  41. elseif ( class == "MAGE" ) then
  42. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 50, -75);
  43. elseif ( class == "SHAMAN" ) then
  44. if ( GetSpecialization() == 3) then
  45. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "BOTTOMLEFT", 99, 38);
  46. else
  47. TotemFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 99, -78);
  48. end
  49. elseif ( hasPet and class ~= "SHAMAN" and class ~= "WARLOCK" ) then
  50. TotemFrame:Hide();
  51. return;
  52. end
  53. local haveTotem, name, startTime, duration, icon;
  54. local slot;
  55. local button;
  56. local buttonIndex = 1;
  57. TotemFrame.activeTotems = 0;
  58. for i=1, MAX_TOTEMS do
  59. slot = priorities[i];
  60. haveTotem, name, startTime, duration, icon = GetTotemInfo(slot);
  61. if ( haveTotem ) then
  62. button = _G["TotemFrameTotem"..buttonIndex];
  63. button.slot = slot;
  64. TotemButton_Update(button, startTime, duration, icon);
  65. if ( button:IsShown() ) then
  66. TotemFrame.activeTotems = TotemFrame.activeTotems + 1;
  67. end
  68. buttonIndex = buttonIndex + 1;
  69. else
  70. button = _G["TotemFrameTotem"..MAX_TOTEMS - i + buttonIndex];
  71. button.slot = 0;
  72. button:Hide();
  73. end
  74. end
  75. if ( TotemFrame.activeTotems > 0 ) then
  76. TotemFrame:Show();
  77. else
  78. TotemFrame:Hide();
  79. end
  80. TotemFrame_AdjustPetFrame();
  81. PlayerFrame_AdjustAttachments();
  82. end
  83. function TotemFrame_OnEvent(self, event, ...)
  84. if ( event == "PLAYER_TOTEM_UPDATE" ) then
  85. local slot = ...;
  86. if ( slot <= MAX_TOTEMS ) then
  87. local haveTotem, name, startTime, duration, icon = GetTotemInfo(slot);
  88. local button;
  89. for i=1, MAX_TOTEMS do
  90. button = _G["TotemFrameTotem"..i];
  91. if ( button.slot == slot ) then
  92. local previouslyShown = button:IsShown();
  93. TotemButton_Update(button, startTime, duration, icon);
  94. -- if we have no active totems then we need to hide the whole frame, otherwise show it
  95. if ( previouslyShown ) then
  96. if ( not button:IsShown() ) then
  97. self.activeTotems = self.activeTotems - 1;
  98. end
  99. else
  100. if ( button:IsShown() ) then
  101. self.activeTotems = self.activeTotems + 1;
  102. end
  103. end
  104. if ( self.activeTotems > 0 ) then
  105. self:Show();
  106. else
  107. self:Hide();
  108. end
  109. TotemFrame_AdjustPetFrame();
  110. return;
  111. end
  112. end
  113. end
  114. end
  115. TotemFrame_Update();
  116. end
  117. function TotemButton_OnClick(self, mouseButton)
  118. local cannotDismiss = GetTotemCannotDismiss(self.slot)
  119. if ( not cannotDismiss ) then
  120. if ( mouseButton == "RightButton" and self.slot > 0 ) then
  121. DestroyTotem(self.slot);
  122. end
  123. end
  124. end
  125. function TotemButton_OnLoad(self)
  126. self:RegisterForClicks("RightButtonUp");
  127. end
  128. function TotemButton_OnUpdate(button, elapsed)
  129. AuraButton_UpdateDuration(button, GetTotemTimeLeft(button.slot));
  130. if ( GameTooltip:IsOwned(button) ) then
  131. GameTooltip:SetTotem(button.slot);
  132. end
  133. end
  134. function TotemButton_Update(button, startTime, duration, icon)
  135. local buttonName = button:GetName();
  136. local buttonIcon = _G[buttonName.."IconTexture"];
  137. local buttonDuration = _G[buttonName.."Duration"];
  138. local buttonCooldown = _G[buttonName.."IconCooldown"];
  139. if ( duration > 0 ) then
  140. buttonIcon:SetTexture(icon);
  141. buttonIcon:Show();
  142. CooldownFrame_Set(buttonCooldown, startTime, duration, true);
  143. buttonCooldown:Show();
  144. button:SetScript("OnUpdate", TotemButton_OnUpdate);
  145. button:Show();
  146. else
  147. buttonIcon:Hide();
  148. buttonDuration:Hide();
  149. buttonCooldown:Hide();
  150. button:SetScript("OnUpdate", nil);
  151. button:Hide();
  152. end
  153. end
  154. function TotemFrame_AdjustPetFrame()
  155. local _, class = UnitClass("player");
  156. if ( class == "WARLOCK" ) then
  157. if ( PetFrame:IsShown() and TotemFrameTotem4:IsShown() ) then
  158. PetFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 156, -90);
  159. elseif ( PetFrame:IsShown() and TotemFrameTotem3:IsShown() ) then
  160. PetFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 126, -90);
  161. elseif ( PetFrame:IsShown() and TotemFrameTotem2:IsShown() ) then
  162. PetFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 93, -90);
  163. else
  164. PetFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPLEFT", 60, -90);
  165. end
  166. end
  167. end