AddonList.lua

AddonList.lua (9.0.2.37176; unchanged since 9.0.1.36247)
  1. ADDON_BUTTON_HEIGHT = 16;
  2. MAX_ADDONS_DISPLAYED = 19;
  3. if ( not InGlue() ) then
  4. UIPanelWindows["AddonList"] = { area = "center", pushable = 0, whileDead = 1 };
  5. end
  6. -- We use this in the shared XML file
  7. AddonTooltip = nil;
  8. local UIDropDownMenu_Initialize = UIDropDownMenu_Initialize
  9. local UIDropDownMenu_AddButton = UIDropDownMenu_AddButton
  10. local UIDropDownMenu_CreateInfo = UIDropDownMenu_CreateInfo
  11. local UIDropDownMenu_GetSelectedValue = UIDropDownMenu_GetSelectedValue
  12. local UIDropDownMenu_SetSelectedValue = UIDropDownMenu_SetSelectedValue
  13. if ( InGlue() ) then
  14. AddonDialogTypes = { };
  15. HasShownAddonOutOfDateDialog = false;
  16. AddonDialogTypes["ADDONS_OUT_OF_DATE"] = {
  17. text = ADDONS_OUT_OF_DATE,
  18. button1 = DISABLE_ADDONS,
  19. button2 = LOAD_ADDONS,
  20. OnAccept = function()
  21. AddonDialog_Show("CONFIRM_DISABLE_ADDONS");
  22. end,
  23. OnCancel = function()
  24. AddonDialog_Show("CONFIRM_LOAD_ADDONS");
  25. end,
  26. }
  27. AddonDialogTypes["CONFIRM_LOAD_ADDONS"] = {
  28. text = CONFIRM_LOAD_ADDONS,
  29. button1 = OKAY,
  30. button2 = CANCEL,
  31. OnAccept = function()
  32. SetAddonVersionCheck(false);
  33. CharacterSelect_CheckDialogStates();
  34. end,
  35. OnCancel = function()
  36. AddonDialog_Show("ADDONS_OUT_OF_DATE");
  37. end,
  38. }
  39. AddonDialogTypes["CONFIRM_DISABLE_ADDONS"] = {
  40. text = CONFIRM_DISABLE_ADDONS,
  41. button1 = OKAY,
  42. button2 = CANCEL,
  43. OnAccept = function()
  44. AddonList_DisableOutOfDate();
  45. CharacterSelect_CheckDialogStates();
  46. end,
  47. OnCancel = function()
  48. AddonDialog_Show("ADDONS_OUT_OF_DATE");
  49. end,
  50. }
  51. function AddonDialog_Show(which)
  52. -- Set the text of the dialog
  53. AddonDialogText:SetText(AddonDialogTypes[which].text);
  54. -- Set the buttons of the dialog
  55. if ( AddonDialogTypes[which].button2 ) then
  56. AddonDialogButton1:ClearAllPoints();
  57. AddonDialogButton1:SetPoint("BOTTOMRIGHT", "AddonDialogBackground", "BOTTOM", -6, 16);
  58. AddonDialogButton2:ClearAllPoints();
  59. AddonDialogButton2:SetPoint("LEFT", "AddonDialogButton1", "RIGHT", 13, 0);
  60. AddonDialogButton2:SetText(AddonDialogTypes[which].button2);
  61. AddonDialogButton2:Show();
  62. else
  63. AddonDialogButton1:ClearAllPoints();
  64. AddonDialogButton1:SetPoint("BOTTOM", "AddonDialogBackground", "BOTTOM", 0, 16);
  65. AddonDialogButton2:Hide();
  66. end
  67. AddonDialogButton1:SetText(AddonDialogTypes[which].button1);
  68. -- Set the miscellaneous variables for the dialog
  69. AddonDialog.which = which;
  70. -- Finally size and show the dialog
  71. AddonDialogBackground:SetHeight(16 + AddonDialogText:GetHeight() + 8 + AddonDialogButton1:GetHeight() + 16);
  72. AddonDialog:Show();
  73. end
  74. function AddonDialog_OnClick(self, button, down)
  75. local index = self:GetID();
  76. AddonDialog:Hide();
  77. if ( index == 1 ) then
  78. local OnAccept = AddonDialogTypes[AddonDialog.which].OnAccept;
  79. if ( OnAccept ) then
  80. OnAccept();
  81. end
  82. else
  83. local OnCancel = AddonDialogTypes[AddonDialog.which].OnCancel;
  84. if ( OnCancel ) then
  85. OnCancel();
  86. end
  87. end
  88. end
  89. function AddonDialog_OnKeyDown(key)
  90. if ( key == "PRINTSCREEN" ) then
  91. Screenshot();
  92. return;
  93. end
  94. if ( key == "ESCAPE" ) then
  95. if ( AddonDialogButton2:IsShown() ) then
  96. AddonDialogButton2:Click();
  97. else
  98. AddonDialogButton1:Click();
  99. end
  100. elseif (key == "ENTER" ) then
  101. AddonDialogButton1:Click();
  102. end
  103. end
  104. AddonTooltip = GlueTooltip
  105. function TryShowAddonDialog()
  106. -- Check to see if any of them are out of date and not disabled
  107. if not GlueAnnouncementDialog:IsShown() and IsAddonVersionCheckEnabled() and AddonList_HasOutOfDate() and not HasShownAddonOutOfDateDialog then
  108. AddonDialog_Show("ADDONS_OUT_OF_DATE");
  109. HasShownAddonOutOfDateDialog = true;
  110. return true;
  111. end
  112. return false;
  113. end
  114. function UpdateAddonButton()
  115. if ( GetNumAddOns() > 0 ) then
  116. CharacterSelectAddonsButton:Show();
  117. else
  118. CharacterSelectAddonsButton:Hide();
  119. end
  120. end
  121. else
  122. AddonTooltip = GameTooltip
  123. end
  124. function AddonList_HasAnyChanged()
  125. if (AddonList.outOfDate and not IsAddonVersionCheckEnabled() or (not AddonList.outOfDate and IsAddonVersionCheckEnabled() and AddonList_HasOutOfDate())) then
  126. return true;
  127. end
  128. for i=1,GetNumAddOns() do
  129. local character = nil;
  130. if (not InGlue()) then
  131. character = UnitName("player");
  132. end
  133. local enabled = (GetAddOnEnableState(character, i) > 0);
  134. local reason = select(5,GetAddOnInfo(i))
  135. if ( enabled ~= AddonList.startStatus[i] and reason ~= "DEP_DISABLED" ) then
  136. return true
  137. end
  138. end
  139. return false
  140. end
  141. function AddonList_HasNewVersion()
  142. local hasNewVersion = false;
  143. for i=1, GetNumAddOns() do
  144. local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i);
  145. if ( newVersion ) then
  146. hasNewVersion = true;
  147. break;
  148. end
  149. end
  150. return hasNewVersion;
  151. end
  152. function AddonList_Show()
  153. if ( InGlue() ) then
  154. AddonList:Show();
  155. else
  156. ShowUIPanel(AddonList);
  157. end
  158. end
  159. function AddonList_Hide(save)
  160. AddonList.save = save
  161. if ( InGlue() ) then
  162. AddonList:Hide()
  163. else
  164. HideUIPanel(AddonList);
  165. end
  166. end
  167. function AddonList_OnLoad(self)
  168. self.TitleText:SetText(ADDON_LIST)
  169. ButtonFrameTemplate_HidePortrait(self)
  170. self.offset = 0;
  171. if ( InGlue() ) then
  172. self:SetParent(GlueParent)
  173. AddonDialog:SetParent(GlueParent)
  174. AddonDialog:SetFrameStrata("DIALOG")
  175. AddonDialogButton1:SetScript("OnClick", AddonDialog_OnClick);
  176. AddonDialogButton2:SetScript("OnClick", AddonDialog_OnClick);
  177. local bg = CreateFrame("Frame", "AddonListBackground", GlueParent)
  178. bg:SetFrameStrata("HIGH")
  179. bg:EnableMouse(true)
  180. bg:SetAllPoints()
  181. bg:Hide()
  182. local tex = bg:CreateTexture()
  183. tex:SetColorTexture(0, 0, 0, 0.6)
  184. tex:SetDrawLayer("BACKGROUND")
  185. tex:SetPoint("TOPLEFT")
  186. tex:SetPoint("BOTTOMRIGHT")
  187. self:EnableKeyboard(true)
  188. self:SetScript("OnKeyDown", AddonList_OnKeyDown)
  189. self:SetFrameStrata("DIALOG")
  190. else
  191. AddonDialog = nil;
  192. self:SetParent(UIParent);
  193. self:SetFrameStrata("HIGH");
  194. self.startStatus = {};
  195. self.shouldReload = false;
  196. self.outOfDate = IsAddonVersionCheckEnabled() and AddonList_HasOutOfDate();
  197. self.outOfDateIndexes = {};
  198. for i=1,GetNumAddOns() do
  199. self.startStatus[i] = (GetAddOnEnableState(UnitName("player"), i) > 0);
  200. if (select(5, GetAddOnInfo(i)) == "INTERFACE_VERSION") then
  201. tinsert(self.outOfDateIndexes, i);
  202. end
  203. end
  204. end
  205. local drop = CreateFrame("Frame", "AddonCharacterDropDown", self, "UIDropDownMenuTemplate")
  206. drop:SetPoint("TOPLEFT", 0, -30)
  207. UIDropDownMenu_Initialize(drop, AddonListCharacterDropDown_Initialize);
  208. UIDropDownMenu_SetSelectedValue(drop, true);
  209. AddonListScrollFrameScrollChildFrame:SetParent(AddonListScrollFrame);
  210. end
  211. function AddonList_SetStatus(self,lod,status,reload)
  212. local button = self.LoadAddonButton
  213. local string = self.Status
  214. local relstr = self.Reload
  215. if ( lod ) then
  216. button:Show()
  217. else
  218. button:Hide()
  219. end
  220. if ( status ) then
  221. string:Show()
  222. else
  223. string:Hide()
  224. end
  225. if ( reload ) then
  226. relstr:Show()
  227. else
  228. relstr:Hide()
  229. end
  230. end
  231. local function TriStateCheckbox_SetState(checked, checkButton)
  232. local checkedTexture = _G[checkButton:GetName().."CheckedTexture"];
  233. if ( not checkedTexture ) then
  234. message("Can't find checked texture");
  235. end
  236. if ( not checked or checked == 0 ) then
  237. -- nil or 0 means not checked
  238. checkButton:SetChecked(false);
  239. checkButton.state = 0;
  240. elseif ( checked == 2 ) then
  241. -- 2 is a normal
  242. checkButton:SetChecked(true);
  243. checkedTexture:SetVertexColor(1, 1, 1);
  244. checkedTexture:SetDesaturated(false);
  245. checkButton.state = 2;
  246. else
  247. -- 1 is a gray check
  248. checkButton:SetChecked(true);
  249. checkedTexture:SetDesaturated(true);
  250. checkButton.state = 1;
  251. end
  252. end
  253. function AddonList_Update()
  254. local numEntrys = GetNumAddOns();
  255. local name, title, notes, enabled, loadable, reason, security;
  256. local addonIndex;
  257. local entry, checkbox, string, status, urlButton, securityIcon, versionButton;
  258. for i=1, MAX_ADDONS_DISPLAYED do
  259. addonIndex = AddonList.offset + i;
  260. entry = _G["AddonListEntry"..i];
  261. if ( addonIndex > numEntrys ) then
  262. entry:Hide();
  263. else
  264. name, title, notes, loadable, reason, security = GetAddOnInfo(addonIndex);
  265. -- Get the character from the current list (nil is all characters)
  266. local character = UIDropDownMenu_GetSelectedValue(AddonCharacterDropDown);
  267. if ( character == true ) then
  268. character = nil;
  269. end
  270. checkbox = _G["AddonListEntry"..i.."Enabled"];
  271. local checkboxState = GetAddOnEnableState(character, addonIndex);
  272. if ( not InGlue() ) then
  273. enabled = (GetAddOnEnableState(UnitName("player"), addonIndex) > 0);
  274. else
  275. enabled = (checkboxState > 0);
  276. end
  277. TriStateCheckbox_SetState(checkboxState, checkbox);
  278. if (checkboxState == 1 ) then
  279. checkbox.AddonTooltip = ENABLED_FOR_SOME;
  280. else
  281. checkbox.AddonTooltip = nil;
  282. end
  283. string = _G["AddonListEntry"..i.."Title"];
  284. if ( loadable or ( enabled and (reason == "DEP_DEMAND_LOADED" or reason == "DEMAND_LOADED") ) ) then
  285. string:SetTextColor(1.0, 0.78, 0.0);
  286. elseif ( enabled and reason ~= "DEP_DISABLED" ) then
  287. string:SetTextColor(1.0, 0.1, 0.1);
  288. else
  289. string:SetTextColor(0.5, 0.5, 0.5);
  290. end
  291. if ( title ) then
  292. string:SetText(title);
  293. else
  294. string:SetText(name);
  295. end
  296. securityIcon = _G["AddonListEntry"..i.."SecurityIcon"];
  297. if ( security == "SECURE" ) then
  298. AddonList_SetSecurityIcon(securityIcon, 1);
  299. elseif ( security == "INSECURE" ) then
  300. AddonList_SetSecurityIcon(securityIcon, 2);
  301. elseif ( security == "BANNED" ) then
  302. AddonList_SetSecurityIcon(securityIcon, 3);
  303. end
  304. _G["AddonListEntry"..i.."Security"].tooltip = _G["ADDON_"..security];
  305. string = _G["AddonListEntry"..i.."Status"];
  306. if ( not loadable and reason ) then
  307. string:SetText(_G["ADDON_"..reason]);
  308. else
  309. string:SetText("");
  310. end
  311. if ( not InGlue() ) then
  312. if ( enabled ~= AddonList.startStatus[addonIndex] and reason ~= "DEP_DISABLED" or
  313. (reason ~= "INTERFACE_VERSION" and tContains(AddonList.outOfDateIndexes, addonIndex)) or
  314. (reason == "INTERFACE_VERSION" and not tContains(AddonList.outOfDateIndexes, addonIndex))) then
  315. if ( enabled ) then
  316. -- special case for loadable on demand addons
  317. if ( AddonList_IsAddOnLoadOnDemand(addonIndex) ) then
  318. AddonList_SetStatus(entry, true, false, false)
  319. else
  320. AddonList_SetStatus(entry, false, false, true)
  321. end
  322. else
  323. AddonList_SetStatus(entry, false, false, true)
  324. end
  325. else
  326. AddonList_SetStatus(entry, false, true, false)
  327. end
  328. else
  329. AddonList_SetStatus(entry, false, true, false)
  330. end
  331. entry:SetID(addonIndex);
  332. entry:Show();
  333. end
  334. end
  335. -- ScrollFrame stuff
  336. FauxScrollFrame_Update(AddonListScrollFrame, numEntrys, MAX_ADDONS_DISPLAYED, ADDON_BUTTON_HEIGHT);
  337. if ( not InGlue() ) then
  338. if ( AddonList_HasAnyChanged() ) then
  339. AddonListOkayButton:SetText(RELOADUI)
  340. AddonList.shouldReload = true
  341. else
  342. AddonListOkayButton:SetText(OKAY)
  343. AddonList.shouldReload = false
  344. end
  345. end
  346. end
  347. function AddonList_OnKeyDown(key)
  348. if ( key == "ESCAPE" ) then
  349. AddonList_OnCancel();
  350. elseif ( key == "ENTER" ) then
  351. AddonList_OnOkay();
  352. elseif ( key == "PRINTSCREEN" ) then
  353. Screenshot();
  354. end
  355. end
  356. function AddonList_IsAddOnLoadOnDemand(index)
  357. local lod = false
  358. if ( IsAddOnLoadOnDemand(index) ) then
  359. local deps = GetAddOnDependencies(index)
  360. local okay = true;
  361. for i = 1, select('#', deps) do
  362. local dep = select(i, deps)
  363. if ( dep and not IsAddOnLoaded(select(i, deps)) ) then
  364. okay = false;
  365. break;
  366. end
  367. end
  368. lod = okay;
  369. end
  370. return lod;
  371. end
  372. function AddonList_Enable(index, enabled)
  373. local character = UIDropDownMenu_GetSelectedValue(AddonCharacterDropDown);
  374. if ( enabled ) then
  375. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  376. EnableAddOn(index,character);
  377. else
  378. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF);
  379. DisableAddOn(index,character);
  380. end
  381. AddonList_Update();
  382. end
  383. function AddonList_EnableAll(self, button, down)
  384. EnableAllAddOns(UIDropDownMenu_GetSelectedValue(AddonCharacterDropDown));
  385. AddonList_Update();
  386. end
  387. function AddonList_DisableAll(self, button, down)
  388. DisableAllAddOns(UIDropDownMenu_GetSelectedValue(AddonCharacterDropDown));
  389. AddonList_Update();
  390. end
  391. function AddonList_LoadAddOn(index)
  392. if ( not AddonList_IsAddOnLoadOnDemand(index) ) then return end
  393. LoadAddOn(index)
  394. if ( IsAddOnLoaded(index) ) then
  395. AddonList.startStatus[index] = true
  396. end
  397. AddonList_Update()
  398. end
  399. function AddonList_OnOkay()
  400. PlaySound(SOUNDKIT.GS_LOGIN_CHANGE_REALM_OK);
  401. AddonList_Hide(true);
  402. if ( not InGlue() ) then
  403. if ( AddonList.shouldReload ) then
  404. ReloadUI();
  405. end
  406. end
  407. end
  408. function AddonList_OnCancel()
  409. PlaySound(SOUNDKIT.GS_LOGIN_CHANGE_REALM_CANCEL);
  410. AddonList_Hide(false);
  411. end
  412. function AddonListScrollFrame_OnVerticalScroll(self, offset)
  413. local scrollbar = _G[self:GetName().."ScrollBar"];
  414. scrollbar:SetValue(offset);
  415. AddonList.offset = floor((offset / ADDON_BUTTON_HEIGHT) + 0.5);
  416. AddonList_Update();
  417. if ( AddonTooltip:IsShown() ) then
  418. AddonTooltip_Update(AddonTooltip:GetOwner());
  419. AddonTooltip:Show()
  420. end
  421. end
  422. function AddonList_OnShow()
  423. if ( InGlue() ) then
  424. AddonListBackground:Show()
  425. end
  426. UIDropDownMenu_Initialize(AddonCharacterDropDown, AddonListCharacterDropDown_Initialize);
  427. UIDropDownMenu_SetSelectedValue( AddonCharacterDropDown, UIDropDownMenu_GetSelectedValue(AddonCharacterDropDown) );
  428. AddonList_Update();
  429. end
  430. function AddonList_OnHide(self)
  431. if ( InGlue() ) then
  432. AddonListBackground:Hide()
  433. end
  434. if ( self.save ) then
  435. SaveAddOns();
  436. else
  437. ResetAddOns();
  438. end
  439. self.save = false;
  440. end
  441. function AddonList_HasOutOfDate()
  442. local hasOutOfDate = false;
  443. for i=1, GetNumAddOns() do
  444. local name, title, notes, loadable, reason = GetAddOnInfo(i);
  445. local character = nil;
  446. if (not InGlue()) then
  447. character = UnitName("player");
  448. end
  449. local enabled = (GetAddOnEnableState(character, i) > 0);
  450. if ( enabled and not loadable and reason == "INTERFACE_VERSION" ) then
  451. hasOutOfDate = true;
  452. break;
  453. end
  454. end
  455. return hasOutOfDate;
  456. end
  457. function AddonList_SetSecurityIcon(texture, index)
  458. local width = 64;
  459. local height = 16;
  460. local iconWidth = 16;
  461. local increment = iconWidth/width;
  462. local left = (index - 1) * increment;
  463. local right = index * increment;
  464. texture:SetTexCoord( left, right, 0, 1.0);
  465. end
  466. function AddonList_DisableOutOfDate()
  467. for i=1, GetNumAddOns() do
  468. local name, title, notes, loadable, reason = GetAddOnInfo(i);
  469. local character = nil;
  470. if (not InGlue()) then
  471. character = UnitName("player");
  472. end
  473. local enabled = (GetAddOnEnableState(character , i) > 0);
  474. if ( enabled and not loadable and reason == "INTERFACE_VERSION" ) then
  475. DisableAddOn(i, true);
  476. end
  477. end
  478. SaveAddOns();
  479. end
  480. function AddonListCharacterDropDown_OnClick(self)
  481. UIDropDownMenu_SetSelectedValue(AddonCharacterDropDown, self.value);
  482. AddonList_Update();
  483. end
  484. function AddonListCharacterDropDown_Initialize()
  485. local selectedValue = UIDropDownMenu_GetSelectedValue(AddonCharacterDropDown);
  486. local info = UIDropDownMenu_CreateInfo();
  487. info.text = ALL;
  488. info.value = true;
  489. info.func = AddonListCharacterDropDown_OnClick;
  490. if ( not selectedValue ) then
  491. info.checked = 1;
  492. end
  493. UIDropDownMenu_AddButton(info);
  494. if ( InGlue() ) then
  495. for i=1, GetNumCharacters() do
  496. info.text = GetCharacterInfo(i);
  497. info.value = GetCharacterInfo(i);
  498. info.func = AddonListCharacterDropDown_OnClick;
  499. if ( selectedValue == info.value ) then
  500. info.checked = 1;
  501. else
  502. info.checked = nil;
  503. end
  504. UIDropDownMenu_AddButton(info);
  505. end
  506. else
  507. info.text = UnitName("player")
  508. info.value = UnitName("player");
  509. if ( selectedValue == info.value ) then
  510. info.checked = 1;
  511. else
  512. info.checked = nil;
  513. end
  514. UIDropDownMenu_AddButton(info);
  515. end
  516. end
  517. function AddonTooltip_BuildDeps(...)
  518. local deps = "";
  519. for i=1, select("#", ...) do
  520. if ( i == 1 ) then
  521. deps = ADDON_DEPENDENCIES .. select(i, ...);
  522. else
  523. deps = deps..", "..select(i, ...);
  524. end
  525. end
  526. return deps;
  527. end
  528. function AddonTooltip_Update(owner)
  529. local name, title, notes, _, _, security = GetAddOnInfo(owner:GetID());
  530. AddonTooltip:ClearLines();
  531. if ( security == "BANNED" ) then
  532. AddonTooltip:SetText(ADDON_BANNED_TOOLTIP);
  533. else
  534. if ( title ) then
  535. AddonTooltip:AddLine(title);
  536. else
  537. AddonTooltip:AddLine(name);
  538. end
  539. AddonTooltip:AddLine(notes, 1.0, 1.0, 1.0);
  540. AddonTooltip:AddLine(AddonTooltip_BuildDeps(GetAddOnDependencies(owner:GetID())));
  541. end
  542. AddonTooltip:Show()
  543. end