PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/TellMeWhen/TellMeWhen/Components/IconTypes/IconType_losecontrol/Config.lua

https://bitbucket.org/cadcamzy/eui_otheraddons
Lua | 306 lines | 235 code | 50 blank | 21 comment | 31 complexity | 4fc9aef9e2d7afc6908bf7445540e138 MD5 | raw file
  1. -- --------------------
  2. -- TellMeWhen
  3. -- Originally by Nephthys of Hyjal <lieandswell@yahoo.com>
  4. -- Other contributions by:
  5. -- Sweetmms of Blackrock, Oozebull of Twisting Nether, Oodyboo of Mug'thol,
  6. -- Banjankri of Blackrock, Predeter of Proudmoore, Xenyr of Aszune
  7. -- Currently maintained by
  8. -- Cybeloras of Aerie Peak/Detheroc/Mal'Ganis
  9. -- --------------------
  10. if not TMW then return end
  11. local TMW = TMW
  12. local L = TMW.L
  13. local print = TMW.print
  14. local get = TMW.get
  15. local Type = rawget(TMW.Types, "losecontrol")
  16. if not Type then return end
  17. Type.CONFIG = {}
  18. local CONFIG = Type.CONFIG
  19. -- IMPORTANT NOTE: the setting used by this icon type (LoseContolTypes) is spelled wrong.
  20. -- I noticed too late to change it, so just make sure and continue to spell it wrong.
  21. CONFIG.Types = {
  22. -- Unconfirmed:
  23. [LOSS_OF_CONTROL_DISPLAY_BANISH] = { -- "Banished"
  24. value = "FEAR",
  25. },
  26. [LOSS_OF_CONTROL_DISPLAY_CHARM] = { -- "Charmed"
  27. value = "CHARM",
  28. },
  29. [LOSS_OF_CONTROL_DISPLAY_CYCLONE] = { -- "Cycloned"
  30. -- I don't know if this is used at all
  31. value = "CYCLONE",
  32. desc = L["LOSECONTROL_TYPE_DESC_USEUNKNOWN"],
  33. },
  34. --[[[LOSS_OF_CONTROL_DISPLAY_DAZE] = { -- "Dazed"
  35. -- I don't think this is used at all
  36. value = "DAZE",
  37. desc = L["LOSECONTROL_TYPE_DESC_USEUNKNOWN"],
  38. },]]
  39. [LOSS_OF_CONTROL_DISPLAY_DISARM] = { -- "Disarmed"
  40. value = "DISARM",
  41. },
  42. [LOSS_OF_CONTROL_DISPLAY_DISORIENT] = { -- "Disoriented"
  43. value = "DISORIENT",
  44. desc = L["LOSECONTROL_TYPE_DESC_USEUNKNOWN"],
  45. },
  46. [LOSS_OF_CONTROL_DISPLAY_DISTRACT] = { -- "Distracted"
  47. value = "DISTRACT",
  48. },
  49. [LOSS_OF_CONTROL_DISPLAY_FREEZE] = { -- "Frozen"
  50. value = "FREEZE",
  51. },
  52. [LOSS_OF_CONTROL_DISPLAY_HORROR] = { -- "Horrified"
  53. value = "HORROR",
  54. },
  55. [LOSS_OF_CONTROL_DISPLAY_INCAPACITATE] = { -- "Incapacitated"
  56. value = "INCAPACITATE",
  57. },
  58. [LOSS_OF_CONTROL_DISPLAY_INTERRUPT] = { -- "Interrupted"
  59. value = "INTERRUPT",
  60. },
  61. [LOSS_OF_CONTROL_DISPLAY_INVULNERABILITY] = { -- "Invulnerable"
  62. value = "INVULNERABILITY",
  63. },
  64. [LOSS_OF_CONTROL_DISPLAY_MAGICAL_IMMUNITY] = { -- "Pacified"
  65. -- text = L["LOSECONTROL_TYPE_MAGICAL_IMMUNITY"] , -- "Magical Immunity"
  66. desc = L["LOSECONTROL_TYPE_DESC_USEUNKNOWN"],
  67. value = "MAGICAL_IMMUNITY",
  68. },
  69. [LOSS_OF_CONTROL_DISPLAY_PACIFY] = { -- "Pacified"
  70. value = "PACIFY",
  71. },
  72. [LOSS_OF_CONTROL_DISPLAY_PACIFYSILENCE] = { -- "Disabled"
  73. value = "PACIFYSILENCE",
  74. desc = L["LOSECONTROL_TYPE_DESC_USEUNKNOWN"],
  75. },
  76. [LOSS_OF_CONTROL_DISPLAY_POLYMORPH] = { -- "Polymorphed"
  77. value = "POLYMORPH",
  78. },
  79. [LOSS_OF_CONTROL_DISPLAY_POSSESS] = { -- "Possessed"
  80. value = "POSSESS",
  81. },
  82. [LOSS_OF_CONTROL_DISPLAY_SAP] = { -- "Sapped"
  83. value = "SAP",
  84. desc = L["LOSECONTROL_TYPE_DESC_USEUNKNOWN"],
  85. },
  86. [LOSS_OF_CONTROL_DISPLAY_SHACKLE_UNDEAD] = { -- "Shackled"
  87. value = "SHACKLE_UNDEAD",
  88. },
  89. [LOSS_OF_CONTROL_DISPLAY_SLEEP] = { -- "Asleep"
  90. value = "SLEEP",
  91. },
  92. [LOSS_OF_CONTROL_DISPLAY_SNARE] = { -- "Snared"
  93. value = "SNARE",
  94. desc = L["LOSECONTROL_TYPE_DESC_USEUNKNOWN"],
  95. },
  96. [LOSS_OF_CONTROL_DISPLAY_TURN_UNDEAD] = { -- "Feared"
  97. value = "TURN_UNDEAD",
  98. },
  99. -- Confirmed:
  100. [L["LOSECONTROL_TYPE_SCHOOLLOCK"]] = {
  101. -- HAS SPECIAL HANDLING (per spell school)!
  102. value = "SCHOOL_INTERRUPT",
  103. },
  104. [LOSS_OF_CONTROL_DISPLAY_ROOT] = { -- "Rooted
  105. value = "ROOT",
  106. },
  107. [LOSS_OF_CONTROL_DISPLAY_CONFUSE] = { -- "Confused"
  108. value = "CONFUSE",
  109. },
  110. [LOSS_OF_CONTROL_DISPLAY_STUN] = { -- "Stunned"
  111. value = "STUN",
  112. },
  113. [LOSS_OF_CONTROL_DISPLAY_SILENCE] = { -- "Silenced"
  114. value = "SILENCE",
  115. },
  116. [LOSS_OF_CONTROL_DISPLAY_FEAR] = { -- "Feared"
  117. value = "FEAR",
  118. },
  119. }
  120. CONFIG.TypesByValue = {}
  121. for k, v in pairs(CONFIG.Types) do
  122. v.text = k
  123. CONFIG.TypesByValue[v.value] = v
  124. end
  125. CONFIG.schools = {
  126. [0x1 ] = "|cffFFFF00" .. SPELL_SCHOOL0_CAP,
  127. [0x2 ] = "|cffFFE680" .. SPELL_SCHOOL1_CAP,
  128. [0x4 ] = "|cffFF8000" .. SPELL_SCHOOL2_CAP,
  129. [0x8 ] = "|cff4DFF4D" .. SPELL_SCHOOL3_CAP,
  130. [0x10] = "|cff80FFFF" .. SPELL_SCHOOL4_CAP,
  131. [0x20] = "|cff8080FF" .. SPELL_SCHOOL5_CAP,
  132. [0x40] = "|cffFF80FF" .. SPELL_SCHOOL6_CAP,
  133. }
  134. function CONFIG:LoadConfig()
  135. if TellMeWhen_LoseControlTypes then
  136. CONFIG:DropdownMenu_SetText()
  137. end
  138. end
  139. TMW:RegisterCallback("TMW_CONFIG_ICON_LOADED", CONFIG, "LoadConfig")
  140. function CONFIG.DropdownMenu_OnClick_Normal(dropDownButton, LoseContolTypes)
  141. LoseContolTypes[dropDownButton.value] = not LoseContolTypes[dropDownButton.value]
  142. CONFIG:DropdownMenu_SetText()
  143. end
  144. function CONFIG.DropdownMenu_OnClick_All(dropDownButton, LoseContolTypes)
  145. if not LoseContolTypes[dropDownButton.value] then
  146. wipe(LoseContolTypes)
  147. LoseContolTypes = TMW:CopyTableInPlaceWithMeta(TMW.DEFAULT_ICON_SETTINGS.LoseContolTypes, LoseContolTypes)
  148. end
  149. LoseContolTypes[dropDownButton.value] = not LoseContolTypes[dropDownButton.value]
  150. CloseDropDownMenus()
  151. CONFIG:DropdownMenu_SetText()
  152. end
  153. function CONFIG.DropdownMenu_OnClick_SchoolInterrupt(dropDownButton, LoseContolTypes, schoolFlag)
  154. LoseContolTypes[dropDownButton.value] = bit.bxor(LoseContolTypes[dropDownButton.value], schoolFlag)
  155. CONFIG:DropdownMenu_SetText()
  156. end
  157. function CONFIG.DropdownMenu_SelectTypes()
  158. local LoseContolTypes = TMW.CI.ics.LoseContolTypes
  159. if UIDROPDOWNMENU_MENU_LEVEL == 1 then
  160. local info = UIDropDownMenu_CreateInfo()
  161. info.text = L["LOSECONTROL_TYPE_ALL"]
  162. info.tooltipTitle = L["LOSECONTROL_TYPE_ALL"]
  163. info.tooltipText = L["LOSECONTROL_TYPE_ALL_DESC"]
  164. info.tooltipOnButton = true
  165. info.value = ""
  166. info.arg1 = LoseContolTypes
  167. info.keepShownOnClick = true
  168. info.checked = LoseContolTypes[info.value]
  169. info.func = CONFIG.DropdownMenu_OnClick_All
  170. UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL)
  171. TMW.AddDropdownSpacer()
  172. for text, data in TMW:OrderedPairs(CONFIG.Types) do
  173. local info = UIDropDownMenu_CreateInfo()
  174. info.text = get(text)
  175. info.tooltipTitle = get(text)
  176. info.tooltipText = (TMW.debug and (data.value and data.value .. "\r\n") or "") .. (get(data.desc) or "")
  177. info.tooltipOnButton = true
  178. info.value = data.value
  179. info.arg1 = LoseContolTypes
  180. info.keepShownOnClick = true
  181. if data.value == "SCHOOL_INTERRUPT" then
  182. info.hasArrow = true
  183. info.notCheckable = true
  184. else
  185. info.checked = LoseContolTypes[""] or LoseContolTypes[data.value]
  186. info.disabled = LoseContolTypes[""]
  187. info.func = CONFIG.DropdownMenu_OnClick_Normal
  188. end
  189. UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL)
  190. end
  191. elseif UIDROPDOWNMENU_MENU_LEVEL == 2 then
  192. if UIDROPDOWNMENU_MENU_VALUE == "SCHOOL_INTERRUPT" then
  193. for bitFlag, name in TMW:OrderedPairs(CONFIG.schools) do
  194. local info = UIDropDownMenu_CreateInfo()
  195. info.text = LOSS_OF_CONTROL_DISPLAY_INTERRUPT_SCHOOL:format(name .. "|r")
  196. info.value = UIDROPDOWNMENU_MENU_VALUE
  197. info.keepShownOnClick = true
  198. info.arg1 = LoseContolTypes
  199. info.arg2 = bitFlag
  200. info.checked = LoseContolTypes[""] or bit.band(LoseContolTypes[UIDROPDOWNMENU_MENU_VALUE], bitFlag) == bitFlag
  201. info.disabled = LoseContolTypes[""]
  202. info.func = CONFIG.DropdownMenu_OnClick_SchoolInterrupt
  203. UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL)
  204. end
  205. end
  206. end
  207. end
  208. function CONFIG:DropdownMenu_SetText()
  209. local LoseContolTypes = TMW.CI.ics.LoseContolTypes
  210. local n = 0
  211. if LoseContolTypes[""] then
  212. n = L["LOSECONTROL_TYPE_ALL"]
  213. else
  214. for k, v in pairs(LoseContolTypes) do
  215. if k == "SCHOOL_INTERRUPT" then
  216. for bitFlag in TMW:OrderedPairs(CONFIG.schools) do
  217. if bit.band(LoseContolTypes[k], bitFlag) == bitFlag then
  218. n = n + 1
  219. end
  220. end
  221. elseif v then
  222. n = n + 1
  223. end
  224. end
  225. end
  226. if n == 0 then
  227. n = " |cFFFF5959(0)|r |TInterface\\AddOns\\TellMeWhen\\Textures\\Alert:0:2|t"
  228. else
  229. n = " (|cff59ff59" .. n .. "|r)"
  230. end
  231. UIDropDownMenu_SetText(TellMeWhen_LoseControlTypes.LocTypes, L["LOSECONTROL_DROPDOWNLABEL"] .. n)
  232. end
  233. function Type:GetIconMenuText(ics)
  234. local text = ""
  235. if not ics.LoseContolTypes then
  236. return "", ""
  237. end
  238. if ics.LoseContolTypes[""] then
  239. text = L["LOSECONTROL_TYPE_ALL"]
  240. else
  241. for locType, v in pairs(ics.LoseContolTypes) do
  242. local data = CONFIG.TypesByValue[locType]
  243. if locType == "SCHOOL_INTERRUPT" then
  244. if v ~= 0 then
  245. text = text .. ", " .. data.text
  246. end
  247. elseif v and data then
  248. text = text .. ", " .. data.text
  249. end
  250. end
  251. if text ~= "" then
  252. text = text:sub(3)
  253. end
  254. end
  255. return text, text and text ~= "" and text .. "\r\n" or ""
  256. end