UIPanelTemplates.lua

UIPanelTemplates.lua (8.3.7.35284; unchanged since 8.3.0.33062)
  1. ITEM_SEARCHBAR_LIST = {
  2. "BagItemSearchBox",
  3. "GuildItemSearchBox",
  4. "VoidItemSearchBox",
  5. "BankItemSearchBox",
  6. };
  7. function BagSearch_OnHide(self)
  8. local allClosed = true;
  9. for _,barName in pairs(ITEM_SEARCHBAR_LIST) do
  10. local bar = _G[barName];
  11. if bar and bar ~= self and bar:IsVisible() then
  12. allClosed = false;
  13. end
  14. end
  15. if ( allClosed ) then
  16. self.clearButton:Click();
  17. BagSearch_OnTextChanged(self);
  18. end
  19. end
  20. function BagSearch_OnTextChanged(self, userChanged)
  21. SearchBoxTemplate_OnTextChanged(self);
  22. for _, barName in pairs(ITEM_SEARCHBAR_LIST) do
  23. local bar = _G[barName];
  24. if ( bar and bar:GetText() ~= self:GetText() ) then
  25. bar:SetText(self:GetText());
  26. end
  27. end
  28. SetItemSearch(self:GetText());
  29. end
  30. function BagSearch_OnChar(self, text)
  31. -- clear focus if the player is repeating keys (ie - trying to move)
  32. -- TODO: move into base editbox code?
  33. local MIN_REPEAT_CHARACTERS = 4;
  34. local searchString = self:GetText();
  35. if (string.len(searchString) >= MIN_REPEAT_CHARACTERS) then
  36. local repeatChar = true;
  37. for i=1, MIN_REPEAT_CHARACTERS - 1, 1 do
  38. if ( string.sub(searchString,(0-i), (0-i)) ~= string.sub(searchString,(-1-i),(-1-i)) ) then
  39. repeatChar = false;
  40. break;
  41. end
  42. end
  43. if ( repeatChar ) then
  44. self:ClearFocus();
  45. end
  46. end
  47. end
  48. local ROLE_COUNT_EVENTS = {
  49. "GROUP_ROSTER_UPDATE",
  50. "PLAYER_ROLES_ASSIGNED",
  51. };
  52. RoleCountMixin = {};
  53. function RoleCountMixin:OnShow()
  54. self:Refresh();
  55. FrameUtil.RegisterFrameForEvents(self, ROLE_COUNT_EVENTS);
  56. end
  57. function RoleCountMixin:OnHide()
  58. FrameUtil.UnregisterFrameForEvents(self, ROLE_COUNT_EVENTS);
  59. end
  60. function RoleCountMixin:OnEvent()
  61. self:Refresh();
  62. end
  63. function RoleCountMixin:Refresh()
  64. local counts = GetGroupMemberCountsForDisplay();
  65. self.DamagerCount:SetText(counts.DAMAGER);
  66. self.HealerCount:SetText(counts.HEALER);
  67. self.TankCount:SetText(counts.TANK);
  68. end
  69. UIFrameCache = CreateFrame("FRAME");
  70. local caches = {};
  71. function UIFrameCache:New (frameType, baseName, parent, template)
  72. if ( self ~= UIFrameCache ) then
  73. error("Attempt to run factory method on class member");
  74. end
  75. local frameCache = {};
  76. setmetatable(frameCache, self);
  77. self.__index = self;
  78. frameCache.frameType = frameType;
  79. frameCache.baseName = baseName;
  80. frameCache.parent = parent;
  81. frameCache.template = template;
  82. frameCache.frames = {};
  83. frameCache.usedFrames = {};
  84. frameCache.numFrames = 0;
  85. tinsert(caches, frameCache);
  86. return frameCache;
  87. end
  88. function UIFrameCache:GetFrame ()
  89. local frame = self.frames[1];
  90. if ( frame ) then
  91. tremove(self.frames, 1);
  92. tinsert(self.usedFrames, frame);
  93. return frame;
  94. end
  95. frame = CreateFrame(self.frameType, self.baseName .. self.numFrames + 1, self.parent, self.template);
  96. frame.frameCache = self;
  97. self.numFrames = self.numFrames + 1;
  98. tinsert(self.usedFrames, frame);
  99. return frame;
  100. end
  101. function UIFrameCache:ReleaseFrame (frame)
  102. for k, v in next, self.frames do
  103. if ( v == frame ) then
  104. return;
  105. end
  106. end
  107. for k, v in next, self.usedFrames do
  108. if ( v == frame ) then
  109. tinsert(self.frames, frame);
  110. tremove(self.usedFrames, k);
  111. break;
  112. end
  113. end
  114. end
  115. -- SquareButton template code
  116. SQUARE_BUTTON_TEXCOORDS = {
  117. ["UP"] = { 0.45312500, 0.64062500, 0.01562500, 0.20312500};
  118. ["DOWN"] = { 0.45312500, 0.64062500, 0.20312500, 0.01562500};
  119. ["LEFT"] = { 0.23437500, 0.42187500, 0.01562500, 0.20312500};
  120. ["RIGHT"] = { 0.42187500, 0.23437500, 0.01562500, 0.20312500};
  121. ["DELETE"] = { 0.01562500, 0.20312500, 0.01562500, 0.20312500};
  122. };
  123. function SquareButton_SetIcon(self, name)
  124. local coords = SQUARE_BUTTON_TEXCOORDS[strupper(name)];
  125. if (coords) then
  126. self.icon:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  127. end
  128. end
  129. -- Cap progress bar
  130. function CapProgressBar_SetNotches(capBar, count)
  131. local barWidth = capBar:GetWidth();
  132. local barName = capBar:GetName();
  133. if ( capBar.notchCount and capBar.notchCount > count ) then
  134. for i = count + 1, capBar.notchCount do
  135. _G[barName.."Divider"..i]:Hide();
  136. end
  137. end
  138. local notchWidth = barWidth / count;
  139. for i=1, count - 1 do
  140. local notch = _G[barName.."Divider"..i];
  141. if ( not notch ) then
  142. notch = capBar:CreateTexture(barName.."Divider"..i, "BORDER", "CapProgressBarDividerTemplate", -1);
  143. end
  144. notch:ClearAllPoints();
  145. notch:SetPoint("LEFT", capBar, "LEFT", notchWidth * i - 2, 0);
  146. end
  147. capBar.notchCount = count;
  148. end
  149. function CapProgressBar_Update(capBar, cap1Quantity, cap1Limit, cap2Quantity, cap2Limit, totalQuantity, totalLimit, hasNoSharedStats)
  150. if ( totalLimit == 0) then
  151. return;
  152. end
  153. local barWidth = capBar:GetWidth() - 4;
  154. local sizePerPoint = barWidth / totalLimit;
  155. local progressWidth = totalQuantity * sizePerPoint;
  156. local cap1Width, cap2Width;
  157. if ( cap2Quantity and cap2Limit ) then
  158. cap1Width = min(cap1Limit - cap1Quantity, cap2Limit - cap2Quantity) * sizePerPoint; --cap1 can't go past the cap2 LFG limit either.
  159. cap2Width = (cap2Limit - cap2Quantity) * sizePerPoint - cap1Width;
  160. else
  161. cap1Width = (cap1Limit - cap1Quantity) * sizePerPoint;
  162. cap2Width = 0;
  163. end
  164. --Don't let it go past the end.
  165. progressWidth = min(progressWidth, barWidth);
  166. cap1Width = min(cap1Width, barWidth - progressWidth);
  167. cap2Width = min(cap2Width, barWidth - progressWidth - cap1Width);
  168. capBar.progress:SetWidth(progressWidth);
  169. capBar.cap1:SetWidth(cap1Width);
  170. capBar.cap2:SetWidth(cap2Width);
  171. local lastFrame, lastRelativePoint = capBar, "LEFT";
  172. if ( progressWidth > 0 ) then
  173. capBar.progress:Show();
  174. capBar.progress:SetPoint("LEFT", lastFrame, lastRelativePoint, 2, 0);
  175. lastFrame, lastRelativePoint = capBar.progress, "RIGHT";
  176. else
  177. capBar.progress:Hide();
  178. end
  179. if ( cap1Width > 0 and not hasNoSharedStats) then
  180. capBar.cap1:Show();
  181. capBar.cap1Marker:Show();
  182. capBar.cap1:SetPoint("LEFT", lastFrame, lastRelativePoint, 0, 0);
  183. lastFrame, lastRelativePoint = capBar.cap1, "RIGHT";
  184. else
  185. capBar.cap1:Hide();
  186. capBar.cap1Marker:Hide();
  187. end
  188. if ( cap2Width > 0 and not hasNoSharedStats) then
  189. capBar.cap2:Show();
  190. capBar.cap2Marker:Show();
  191. capBar.cap2:SetPoint("LEFT", lastFrame, lastRelativePoint, 0, 0);
  192. lastFrame, lastRelativePoint = capBar.cap2, "RIGHT";
  193. else
  194. capBar.cap2:Hide();
  195. capBar.cap2Marker:Hide();
  196. end
  197. end
  198. --Radio button functions
  199. function SetCheckButtonIsRadio(button, isRadio)
  200. if ( isRadio ) then
  201. button:SetNormalTexture("Interface\\Buttons\\UI-RadioButton");
  202. button:GetNormalTexture():SetTexCoord(0, 0.25, 0, 1);
  203. button:SetHighlightTexture("Interface\\Buttons\\UI-RadioButton");
  204. button:GetHighlightTexture():SetTexCoord(0.5, 0.75, 0, 1);
  205. button:SetCheckedTexture("Interface\\Buttons\\UI-RadioButton");
  206. button:GetCheckedTexture():SetTexCoord(0.25, 0.5, 0, 1);
  207. button:SetPushedTexture("Interface\\Buttons\\UI-RadioButton");
  208. button:GetPushedTexture():SetTexCoord(0, 0.25, 0, 1);
  209. button:SetDisabledCheckedTexture("Interface\\Buttons\\UI-RadioButton");
  210. button:GetDisabledCheckedTexture():SetTexCoord(0.75, 1, 0, 1);
  211. else
  212. button:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up");
  213. button:GetNormalTexture():SetTexCoord(0, 1, 0, 1);
  214. button:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight");
  215. button:GetHighlightTexture():SetTexCoord(0, 1, 0, 1);
  216. button:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check");
  217. button:GetCheckedTexture():SetTexCoord(0, 1, 0, 1);
  218. button:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down");
  219. button:GetPushedTexture():SetTexCoord(0, 1, 0, 1);
  220. button:SetDisabledCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled");
  221. button:GetDisabledCheckedTexture():SetTexCoord(0, 1, 0, 1);
  222. end
  223. end
  224. --Inline hyperlinks
  225. function InlineHyperlinkFrame_OnEnter(self, link, text, fontString, left, bottom, width, height)
  226. self.tooltipFrame:SetOwner(self, "ANCHOR_PRESERVE");
  227. self.tooltipFrame:ClearAllPoints();
  228. self.tooltipFrame:SetPoint("BOTTOMLEFT", fontString, "TOPLEFT", left + width, bottom);
  229. self.tooltipFrame:SetHyperlink(link);
  230. end
  231. function InlineHyperlinkFrame_OnLeave(self)
  232. self.tooltipFrame:Hide();
  233. end
  234. function InlineHyperlinkFrame_OnClick(self, link, text, button)
  235. if ( self.hasIconHyperlinks ) then
  236. local fixedLink;
  237. local _, _, linkType, linkID = string.find(link, "([%a]+):([%d]+)");
  238. if ( linkType == "currency" ) then
  239. fixedLink = GetCurrencyLink(linkID);
  240. end
  241. if ( fixedLink ) then
  242. HandleModifiedItemClick(fixedLink);
  243. return;
  244. end
  245. end
  246. SetItemRef(link, text, button);
  247. end
  248. CurrencyTemplateMixin = {};
  249. function CurrencyTemplateMixin:SetCurrencyFromID(currencyID, amount, formatString, colorCode)
  250. local _, _, currencyTexture = GetCurrencyInfo(currencyID);
  251. local markup = CreateTextureMarkup(currencyTexture, 64, 64, 16, 16, 0, 1, 0, 1);
  252. colorCode = colorCode or HIGHLIGHT_FONT_COLOR_CODE;
  253. local currencyString = ("%s%s %s|r"):format(colorCode, BreakUpLargeNumbers(amount), markup);
  254. if formatString then
  255. self:SetText(formatString:format(currencyString));
  256. else
  257. self:SetText(currencyString);
  258. end
  259. end
  260. UIExpandingButtonMixin = {};
  261. function UIExpandingButtonMixin:SetUp(expanded, expansionDirection)
  262. self.expansionDirection = expansionDirection;
  263. self.currentlyExpanded = expanded;
  264. self:Update();
  265. end
  266. function UIExpandingButtonMixin:SetLabel(label)
  267. self.Label:SetText(label);
  268. end
  269. local function GetOppositeDirection(direction)
  270. if (direction == "RIGHT") then
  271. return "LEFT";
  272. else
  273. return "RIGHT";
  274. end
  275. end
  276. function UIExpandingButtonMixin:SetExpanded(expanded)
  277. self.currentlyExpanded = expanded;
  278. self:Update();
  279. end
  280. function UIExpandingButtonMixin:IsCurrentlyExpanded()
  281. return self.currentlyExpanded;
  282. end
  283. function UIExpandingButtonMixin:Update(override)
  284. if (self.currentlyExpanded == nil or not self.expansionDirection) then
  285. error("The button must be set up before update.");
  286. return;
  287. end
  288. if (override ~= nil) then
  289. self.currentlyExpanded = override;
  290. end
  291. local direction = self.currentlyExpanded and GetOppositeDirection(self.expansionDirection) or self.expansionDirection;
  292. SquareButton_SetIcon(self, direction);
  293. if (self.callback) then
  294. self.callback(self, self.currentlyExpanded);
  295. end
  296. end
  297. function UIExpandingButtonMixin:RegisterCallback(callback)
  298. self.callback = callback;
  299. end
  300. function UIExpandingButtonMixin:OnClick(button, down)
  301. self.currentlyExpanded = not self.currentlyExpanded;
  302. self:Update();
  303. end
  304. TalentRankDisplayMixin = { };
  305. function TalentRankDisplayMixin:SetValues(currentRank, maxRank, isDisabled, isAvailable)
  306. self.Text:SetFormattedText(GENERIC_FRACTION_STRING, currentRank, maxRank);
  307. local atlas, textColor;
  308. if isDisabled then
  309. atlas = "orderhalltalents-rankborder";
  310. textColor = DISABLED_FONT_COLOR;
  311. elseif isAvailable and currentRank < maxRank then
  312. atlas = "orderhalltalents-rankborder-green";
  313. textColor = GREEN_FONT_COLOR;
  314. else
  315. atlas = "orderhalltalents-rankborder-yellow";
  316. textColor = YELLOW_FONT_COLOR;
  317. end
  318. local useAtlasSize = true;
  319. self.Background:SetAtlas(atlas, true);
  320. self.Text:SetTextColor(textColor:GetRGB());
  321. end
  322. ButtonWithDisableMixin = {};
  323. function ButtonWithDisableMixin:SetDisableTooltip(tooltipTitle, tooltipText)
  324. self.disableTooltipTitle = tooltipTitle;
  325. self.disableTooltipText = tooltipText;
  326. self:SetEnabled(tooltipTitle == nil);
  327. end
  328. function ButtonWithDisableMixin:OnEnter()
  329. if self.disableTooltipTitle and not self:IsEnabled() then
  330. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  331. local wrap = true;
  332. GameTooltip_SetTitle(GameTooltip, self.disableTooltipTitle, RED_FONT_COLOR, wrap);
  333. if self.disableTooltipText then
  334. GameTooltip_AddNormalLine(GameTooltip, self.disableTooltipText, wrap);
  335. end
  336. GameTooltip:Show();
  337. end
  338. end