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