PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Tukui/modules/datatext/guild.lua

http://github.com/Asphyxia/Tukui
Lua | 310 lines | 247 code | 59 blank | 4 comment | 44 complexity | bde700df17aa5fbb12f2fe0771409889 MD5 | raw file
  1. --------------------------------------------------------------------
  2. -- GUILD ROSTER
  3. --------------------------------------------------------------------
  4. local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants, Config, Locales
  5. local USE_EPGP = true
  6. if C["datatext"].guild and C["datatext"].guild > 0 then
  7. function sortGuildByRank(a,b)
  8. texta = string.format("%02d",a.rankIndex)..a.name
  9. textb = string.format("%02d",b.rankIndex)..b.name
  10. return texta<textb
  11. end
  12. function sortGuildByName(a,b)
  13. texta = a.name
  14. textb = b.name
  15. return texta<textb
  16. end
  17. function sortGuildByZone(a,b)
  18. texta = a.zone..a.name
  19. textb = b.zone..b.name
  20. return texta<textb
  21. end
  22. sortGuildFunc = sortGuildByName
  23. local Stat = CreateFrame("Frame")
  24. Stat:EnableMouse(true)
  25. Stat:SetFrameStrata("MEDIUM")
  26. Stat:SetFrameLevel(3)
  27. local tthead = {r=0.4,g=0.78,b=1}
  28. local ttsubh = {r=0.75,g=0.9,b=1}
  29. local Text = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
  30. Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  31. T.PP(C["datatext"].guild, Text)
  32. local BASE_GP = 1
  33. local function ParseGuildInfo(info)
  34. BASE_GP = 1
  35. local v
  36. local lines = {string.split("\n", info)}
  37. for _,line in pairs(lines) do
  38. v = string.match(line,"@BASE_GP:(%d+)")
  39. if(v) then
  40. BASE_GP = v
  41. break
  42. end
  43. end
  44. end
  45. local displayString = string.join("", GUILD, ": ",T.datacolor, "%d|r")
  46. local function Update(self, event, ...)
  47. if (event=="ADDON_LOADED") then
  48. if USE_EPGP then
  49. ParseGuildInfo(GetGuildInfoText())
  50. end
  51. else
  52. if IsInGuild() then
  53. GuildRoster()
  54. local numOnline = (GetNumGuildMembers())
  55. local total = (GetNumGuildMembers())
  56. local numOnline = 0
  57. for i = 1, total do
  58. local _, _, _, _, _, _, _, _, online, _, _ = GetGuildRosterInfo(i)
  59. if online then
  60. numOnline = numOnline + 1
  61. end
  62. end
  63. Text:SetFormattedText(displayString, numOnline)
  64. self:SetAllPoints(Text)
  65. else
  66. Text:SetText(T.datacolor..L.datatext_noguild)
  67. end
  68. end
  69. end
  70. local guildMenuFrame = nil
  71. function setGuildSort(self,fun)
  72. guildMenuFrame:Hide()
  73. sortGuildFunc = fun
  74. end
  75. local guildMenuList = {
  76. { text = "Select an Option", isTitle = true,notCheckable=true},
  77. { text = "Invite", hasArrow = true,notCheckable=true,
  78. menuList = {
  79. { text = "Option 3", func = function() print("You've chosen option 3"); end }
  80. }
  81. },
  82. { text = "Whisper", hasArrow = true,notCheckable=true,
  83. menuList = {
  84. { text = "Option 4", func = function() print("You've chosen option 4"); end }
  85. }
  86. },
  87. { text = "Sort", hasArrow = true,notCheckable=true,
  88. menuList = {
  89. { notCheckable=true,text = "Name", func = setGuildSort, arg1=sortGuildByName},
  90. { notCheckable=true,text = "Zone", func = setGuildSort, arg1=sortGuildByZone},
  91. { notCheckable=true,text = "Rank", func = setGuildSort, arg1=sortGuildByRank},
  92. }
  93. }
  94. }
  95. if USE_EPGP then
  96. function sortEPGP(a,b)
  97. if a.PR == b.PR then
  98. return a.name < b.name
  99. else
  100. return a.PR>b.PR
  101. end
  102. end
  103. guildMenuList[4].menuList[4] = { notCheckable=true,text = "EPGP (PR)", func = setGuildSort, arg1=sortEPGP}
  104. end
  105. function inviteFriendClick(self, arg1, arg2, checked)
  106. guildMenuFrame:Hide()
  107. InviteUnit(arg1)
  108. end
  109. function whisperFriendClick(self,arg1,arg2,checked)
  110. guildMenuFrame:Hide()
  111. SetItemRef( "player:"..arg1, ("|Hplayer:%1$s|h[%1$s]|h"):format(arg1), "LeftButton" )
  112. end
  113. local menuCountWhispers = 0
  114. local menuCountInvites = 0
  115. Stat:SetScript("OnMouseUp", function(self, btn)
  116. if btn == "RightButton" then
  117. GameTooltip:Hide()
  118. if(guildMenuFrame==nil) then
  119. guildMenuFrame = CreateFrame("Frame", "guildMenuFrame", nil, "UIDropDownMenuTemplate")
  120. guildMenuFrame.relativeTo = self
  121. else
  122. guildMenuFrame:Show()
  123. end
  124. EasyMenu(guildMenuList, guildMenuFrame, "cursor", 0, 0, "MENU")
  125. end
  126. end)
  127. local function EPGPDecodeNote(note)
  128. if note then
  129. if note == "" then
  130. return 0, 0
  131. else
  132. local ep, gp = string.match(note, "^(%d+),(%d+)$")
  133. if ep then
  134. return tonumber(ep), tonumber(gp)
  135. end
  136. end
  137. end
  138. end
  139. Stat:RegisterEvent("ADDON_LOADED")
  140. Stat:RegisterEvent("GUILD_ROSTER_UPDATE")
  141. Stat:RegisterEvent("PLAYER_GUILD_UPDATE")
  142. Stat:RegisterEvent("GUILD_PERK_UPDATE")
  143. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  144. Stat:RegisterEvent("CHAT_MSG_SYSTEM")
  145. Stat:SetScript("OnEnter", function(self)
  146. if not InCombatLockdown() or self.altdow then
  147. if IsInGuild() then
  148. menuCountWhispers = 0
  149. menuCountInvites = 0
  150. guildMenuList[2].menuList = {}
  151. guildMenuList[3].menuList = {}
  152. colors = {
  153. note = { .14, .76, .15 },
  154. officerNote = { 1, .56, .25 }
  155. }
  156. local r,g,b = unpack(colors.officerNote)
  157. local officerColor = ("\124cff%.2x%.2x%.2x"):format( r*255, g*255, b*255 )
  158. r,g,b = unpack(colors.note)
  159. local noteColor = ("\124cff%.2x%.2x%.2x"):format( r*255, g*255, b*255 )
  160. self.hovered = true
  161. GuildRoster()
  162. local name, rank,rankIndex, level, zone, note, officernote, EP,GP,PR, connected, status, class, zone_r, zone_g, zone_b, classc, levelc,grouped
  163. local online, total, gmotd = 0, GetNumGuildMembers(true), GetGuildRosterMOTD()
  164. for i = 0, total do if select(9, GetGuildRosterInfo(i)) then online = online + 1 end end
  165. GameTooltip:SetOwner(self, "ANCHOR_TOP", 0,T.Scale(6));
  166. GameTooltip:ClearAllPoints()
  167. --GameTooltip:SetPoint("BOTTOM", self, "TOP", 0,T.mult)
  168. GameTooltip:ClearLines()
  169. GameTooltip:AddDoubleLine(GetGuildInfo'player',format("%s: %d/%d",GUILD,online,total),tthead.r,tthead.g,tthead.b,tthead.r,tthead.g,tthead.b)
  170. GameTooltip:AddLine' '
  171. if gmotd ~= "" then GameTooltip:AddLine(format(" %s |cffaaaaaa- |cffffffff%s",GUILD_MOTD,gmotd),ttsubh.r,ttsubh.g,ttsubh.b,1) end
  172. if online > 1 then
  173. GameTooltip:AddLine' '
  174. sortable = {}
  175. for i = 1, total do
  176. tabletemp = {}
  177. tabletemp.index=i
  178. tabletemp.name, tabletemp.rank, tabletemp.rankIndex , tabletemp.level, _, tabletemp.zone, tabletemp.note, tabletemp.officernote, tabletemp.connected, tabletemp.status, tabletemp.class = GetGuildRosterInfo(i)
  179. if tabletemp.zone==nil then
  180. tabletemp.zone = "Unknow Zone"
  181. end
  182. if USE_EPGP then
  183. if tabletemp.officernote then
  184. tabletemp.EP,tabletemp.GP = EPGPDecodeNote(tabletemp.officernote)
  185. if(tabletemp.EP) then
  186. tabletemp.GP = tabletemp.GP + BASE_GP
  187. tabletemp.PR = tabletemp.EP / tabletemp.GP
  188. tabletemp.officernote = format("EP: %d GP: %d PR:%.2f",tabletemp.EP,tabletemp.GP,tabletemp.PR)
  189. else
  190. tabletemp.EP = 0
  191. tabletemp.GP = 0
  192. tabletemp.PR = -1
  193. end
  194. end
  195. end
  196. if tabletemp.connected~=nil and tabletemp.connected==1 then
  197. table.insert(sortable,tabletemp)
  198. end
  199. end
  200. table.sort(sortable,sortGuildFunc)
  201. for i,v in ipairs(sortable) do
  202. if online <= 1 then
  203. if online > 1 then GameTooltip:AddLine(format("+ %d More...", online - modules.Guild.maxguild),ttsubh.r,ttsubh.g,ttsubh.b) end
  204. break
  205. end
  206. name = v.name
  207. rank = v.rank
  208. rankIndex = v.rankIndex
  209. level = v.level
  210. zone = v.zone
  211. note = v.note
  212. officernote = v.officernote
  213. connected = v.connected
  214. status = v.status
  215. class = v.class
  216. if connected then
  217. if GetRealZoneText() == zone then zone_r, zone_g, zone_b = 0.3, 1.0, 0.3 else zone_r, zone_g, zone_b = 0.65, 0.65, 0.65 end
  218. classc, levelc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class], GetQuestDifficultyColor(level)
  219. notes = format(" %s%s",noteColor,note)
  220. if officernote ~= "" then
  221. notes = notes .. format(" %s%s",officerColor,officernote)
  222. end
  223. rank = noteColor..rank
  224. if (UnitInParty(name) or UnitInRaid(name)) and (name ~= UnitName'player') then
  225. grouped = "|cffaaaaaa*|r"
  226. else
  227. grouped = ""
  228. if name ~= UnitName'player' then
  229. menuCountInvites = menuCountInvites +1
  230. guildMenuList[2].menuList[menuCountInvites] = {text = format("|cff%02x%02x%02x%d|r |cff%02x%02x%02x%s|r",levelc.r*255,levelc.g*255,levelc.b*255,level,classc.r*255,classc.g*255,classc.b*255,name), arg1 = name,notCheckable=true, func = inviteFriendClick}
  231. end
  232. end
  233. GameTooltip:AddDoubleLine(format("|cff%02x%02x%02x%d|r %s%s%s%s",levelc.r*255,levelc.g*255,levelc.b*255,level,name,grouped,notes,' '..status),zone.." "..rank,classc.r,classc.g,classc.b,zone_r,zone_g,zone_b)
  234. if name ~= UnitName'player' then
  235. menuCountWhispers = menuCountWhispers + 1
  236. guildMenuList[3].menuList[menuCountWhispers] = {text = format("|cff%02x%02x%02x%d|r |cff%02x%02x%02x%s|r",levelc.r*255,levelc.g*255,levelc.b*255,level,classc.r*255,classc.g*255,classc.b*255,name), arg1 = name,notCheckable=true, func = whisperFriendClick}
  237. end
  238. end
  239. end
  240. end
  241. GameTooltip:Show()
  242. end
  243. end
  244. end)
  245. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  246. Stat:SetScript("OnMouseDown", function(self, btn)
  247. if btn == "LeftButton" then
  248. if not GuildFrame and IsInGuild() then LoadAddOn("Blizzard_GuildUI") end GuildFrame_Toggle() end
  249. end)
  250. Stat:SetScript("OnEvent", Update)
  251. end