Blizzard_OrderHallUI/Blizzard_OrderHallCommandBar.lua

Blizzard_OrderHallUI/Blizzard_OrderHallCommandBar.lua (9.0.2.36294; unchanged since 9.0.1.36230)
  1. ---------------------------------------------------------------------------------
  2. --- OrderHallCommandBarMixin ---
  3. ---------------------------------------------------------------------------------
  4. OrderHallCommandBarMixin = { }
  5. function OrderHallCommandBarMixin:OnLoad()
  6. self.categoryPool = CreateFramePool("FRAME", self, "OrderHallClassSpecCategoryTemplate");
  7. local primaryCurrency, _ = C_Garrison.GetCurrencyTypes(Enum.GarrisonType.Type_7_0);
  8. self.currency = primaryCurrency;
  9. -- setup portrait texture
  10. local _, class = UnitClass("player");
  11. self.ClassIcon:SetTexture("Interface\\TargetingFrame\\UI-Classes-Circles");
  12. local x1, x2, y1, y2 = unpack(CLASS_ICON_TCOORDS[strupper(class)]);
  13. local height = y2 - y1;
  14. y1 = y1 + 0.25 * height;
  15. y2 = y2 - 0.25 * height;
  16. self.ClassIcon:SetTexCoord(x1, x2, y1, y2);
  17. -- don't wnat to get mouse events on anything under the command bar
  18. self:EnableMouse(true);
  19. self.AreaName:SetText(_G["ORDER_HALL_"..class]);
  20. end
  21. function OrderHallCommandBarMixin:OnShow()
  22. UIParent_UpdateTopFramePositions();
  23. self:RegisterUnitEvent("UNIT_AURA", "player");
  24. self:RegisterUnitEvent("UNIT_PHASE", "player");
  25. self:RegisterEvent("CURRENCY_DISPLAY_UPDATE");
  26. self:RegisterEvent("DISPLAY_SIZE_CHANGED");
  27. self:RegisterEvent("UI_SCALE_CHANGED");
  28. self:RegisterEvent("GARRISON_TALENT_COMPLETE");
  29. self:RegisterEvent("GARRISON_TALENT_UPDATE");
  30. self:RegisterEvent("GARRISON_FOLLOWER_CATEGORIES_UPDATED");
  31. self:RegisterEvent("GARRISON_FOLLOWER_ADDED");
  32. self:RegisterEvent("GARRISON_FOLLOWER_REMOVED");
  33. self:RegisterEvent("UPDATE_BINDINGS");
  34. self:RequestCategoryInfo();
  35. self:RefreshAll();
  36. self.WorldMapButton.tooltipText = MicroButtonTooltipText(WORLDMAP_BUTTON, "TOGGLEWORLDMAP");
  37. self.WorldMapButton.newbieText = NEWBIE_TOOLTIP_WORLDMAP;
  38. end
  39. function OrderHallCommandBarMixin:OnHide()
  40. self:UnregisterEvent("UNIT_AURA");
  41. self:UnregisterEvent("UNIT_PHASE");
  42. self:UnregisterEvent("CURRENCY_DISPLAY_UPDATE");
  43. self:UnregisterEvent("DISPLAY_SIZE_CHANGED");
  44. self:UnregisterEvent("UI_SCALE_CHANGED");
  45. self:UnregisterEvent("GARRISON_TALENT_COMPLETE");
  46. self:UnregisterEvent("GARRISON_TALENT_UPDATE");
  47. self:UnregisterEvent("GARRISON_FOLLOWER_CATEGORIES_UPDATED");
  48. self:UnregisterEvent("GARRISON_FOLLOWER_ADDED");
  49. self:UnregisterEvent("GARRISON_FOLLOWER_REMOVED");
  50. self:UnregisterEvent("UPDATE_BINDINGS");
  51. self.categoryPool:ReleaseAll();
  52. UIParent_UpdateTopFramePositions();
  53. end
  54. function OrderHallCommandBarMixin:OnEvent(event)
  55. if (event == "CURRENCY_DISPLAY_UPDATE") then
  56. self:RefreshCurrency();
  57. elseif (event == "DISPLAY_SIZE_CHANGED"
  58. or event == "UI_SCALE_CHANGED"
  59. or event == "GARRISON_FOLLOWER_CATEGORIES_UPDATED"
  60. or event == "GARRISON_FOLLOWER_ADDED"
  61. or event == "GARRISON_FOLLOWER_REMOVED") then
  62. self:RefreshCategories();
  63. elseif (event == "UNIT_AURA") then
  64. local inOrderHall = C_Garrison.IsPlayerInGarrison(Enum.GarrisonType.Type_7_0);
  65. self:SetShown(inOrderHall);
  66. elseif (event == "GARRISON_TALENT_COMPLETE"
  67. or event == "GARRISON_TALENT_UPDATE"
  68. or event == "UNIT_PHASE") then
  69. self:RequestCategoryInfo();
  70. elseif (event == "UPDATE_BINDINGS") then
  71. self.WorldMapButton.tooltipText = MicroButtonTooltipText(WORLDMAP_BUTTON, "TOGGLEWORLDMAP");
  72. self.WorldMapButton.newbieText = NEWBIE_TOOLTIP_WORLDMAP;
  73. end
  74. end
  75. function OrderHallCommandBarMixin:RequestCategoryInfo()
  76. C_Garrison.RequestClassSpecCategoryInfo(Enum.GarrisonFollowerType.FollowerType_7_0);
  77. end
  78. function OrderHallCommandBarMixin:RefreshAll()
  79. self:RefreshCurrency();
  80. self:RefreshCategories();
  81. end
  82. function OrderHallCommandBarMixin:RefreshCategories()
  83. self.categoryPool:ReleaseAll();
  84. local categoryInfo = C_Garrison.GetClassSpecCategoryInfo(Enum.GarrisonFollowerType.FollowerType_7_0);
  85. local numCategories = #categoryInfo;
  86. local prevCategory, firstCategory;
  87. local xSpacing = 20; -- space between categories
  88. for index, category in ipairs(categoryInfo) do
  89. local categoryInfoFrame = self.categoryPool:Acquire();
  90. categoryInfoFrame.Icon:SetTexture(category.icon);
  91. categoryInfoFrame.Icon:SetTexCoord(0, 1, 0.25, 0.75);
  92. categoryInfoFrame.name = category.name;
  93. categoryInfoFrame.description = category.description;
  94. categoryInfoFrame.Count:SetFormattedText(ORDER_HALL_COMMANDBAR_CATEGORY_COUNT, category.count, category.limit);
  95. categoryInfoFrame:ClearAllPoints();
  96. if (not firstCategory) then
  97. -- calculate positioning so that the set of categories ends up being centered
  98. categoryInfoFrame:SetPoint("LEFT", self, "RIGHT", (0 - (numCategories * (categoryInfoFrame:GetWidth() + xSpacing))) - 30, 0);
  99. firstCategory = categoryInfoFrame;
  100. else
  101. categoryInfoFrame:SetPoint("LEFT", prevCategory, "RIGHT", xSpacing, 0);
  102. end
  103. categoryInfoFrame:Show();
  104. prevCategory = categoryInfoFrame;
  105. end
  106. end
  107. function OrderHallCommandBarMixin:RefreshCurrency()
  108. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(self.currency);
  109. local amount = currencyInfo and currencyInfo.quantity or 0;
  110. amount = BreakUpLargeNumbers(amount);
  111. self.Currency:SetText(amount);
  112. -- self.CurrencyIcon:SetTexture(currencyTexture);
  113. end
  114. ---------------------------------------------------------------------------------
  115. --- OrderHallClassSpecCategory ---
  116. ---------------------------------------------------------------------------------
  117. OrderHallClassSpecCategory = { }
  118. function OrderHallClassSpecCategory:OnEnter()
  119. if (self.name) then
  120. GameTooltip:SetOwner(self, "ANCHOR_PRESERVE");
  121. GameTooltip:ClearAllPoints();
  122. GameTooltip:SetPoint("TOPLEFT", self.Count, "BOTTOMRIGHT", -20, -20);
  123. GameTooltip:AddLine(self.name);
  124. if (self.description) then
  125. GameTooltip:AddLine(self.description, 1, 1, 1, true);
  126. end
  127. GameTooltip:Show();
  128. end
  129. end
  130. function OrderHallClassSpecCategory:OnLeave()
  131. GameTooltip:Hide();
  132. end