Advertisement
Guest User

pvp.lua

a guest
Feb 3rd, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.25 KB | None | 0 0
  1. local ex = Examiner;
  2.  
  3. -- Module
  4. local mod = ex:CreateModule(PVP,PLAYER_V_PLAYER);
  5. mod.help = "Honor & Arena Details";
  6. mod:CreatePage(true,PLAYER_V_PLAYER);
  7. mod:HasButton(true);
  8. mod.canCache = true;
  9.  
  10. -- Variables
  11. local labels = {};
  12.  
  13. -- Data Variables -- Honor & Arena Data
  14. local hd, ad = {}, {};
  15.  
  16. --------------------------------------------------------------------------------------------------------
  17. --                                           Module Scripts                                           --
  18. --------------------------------------------------------------------------------------------------------
  19.  
  20. -- OnInitialize
  21. function mod:OnInitialize()
  22.     for i = 1, MAX_ARENA_TEAMS+1 do
  23.         ad[i] = {};
  24.     end
  25. end
  26.  
  27. -- OnInspect
  28. function mod:OnInspect(unit)
  29.     if (ex.isSelf) then
  30.         self:LoadHonorNormal();
  31.         self:LoadArenaTeamsNormal();
  32.     end
  33.     if (ex.canInspect) then
  34.         ex:RequestHonorData();
  35.     end
  36. end
  37.  
  38. -- OnHonorReady
  39. function mod:OnHonorReady()
  40.     self:LoadHonorNormal();
  41.     self:LoadArenaTeamsNormal();
  42. end
  43.  
  44. -- OnCacheLoaded
  45. function mod:OnCacheLoaded(entry,unit)
  46.     if (entry.Honor) then
  47.         self:HasData(true);
  48.         -- Honor
  49.         for name, value in next, entry.Honor do
  50.             hd[name] = value;
  51.         end
  52.         self:UpdateHonor();
  53.         -- Arena
  54.         for i = 1, MAX_ARENA_TEAMS+1 do
  55.             if (entry["Arena"..i]) then
  56.                 local at = ad[i];
  57.                 for name, value in next, entry["Arena"..i] do
  58.                     at[name] = value;
  59.                 end
  60.             end
  61.         end
  62.         self:ArenaTeamUpdate();
  63.     end
  64. end
  65.  
  66. -- OnCache
  67. function mod:OnCache(entry)
  68.     if (self:CanCache()) and (next(hd)) then
  69.         entry.Honor = CopyTable(hd);
  70.         for i = 1, MAX_ARENA_TEAMS+1 do
  71.             if (ad[i]) then
  72.                 entry["Arena"..i] = CopyTable(ad[i]);
  73.             end
  74.         end
  75.     end
  76. end
  77.  
  78. -- OnClearInspect
  79. function mod:OnClearInspect()
  80.     self:HasData(nil);
  81.     -- Header
  82.     self.rankIcon:Hide();
  83.     -- Clear Honor
  84.     wipe(hd);
  85.     for i = 4, 9 do
  86.         labels[i]:SetText("---");
  87.     end
  88.     labels[9]:SetTextColor(1,1,0);
  89.     -- Hide Arena Teams
  90.     for i = 1, MAX_ARENA_TEAMS+1 do
  91.         wipe(ad[i]);
  92.     end
  93.     for i = 13, 24 do
  94.         labels[i]:SetText("---");
  95.     end
  96. end
  97.  
  98. --------------------------------------------------------------------------------------------------------
  99. --                                             PvP Stuff                                              --
  100. --------------------------------------------------------------------------------------------------------
  101.  
  102. -- Load Honor Normal
  103. function mod:LoadHonorNormal()
  104.     self:HasData(true);
  105.     -- Query -- Az: Even if inspecting ourself, use inspect data as GetPVPYesterdayStats() is bugged as of (4.0.1 - 4.0.3a)
  106.     if (not ex.isSelf) or (HasInspectHonorData()) then
  107.         hd.todayHK, hd.todayHonor, hd.yesterdayHK, hd.yesterdayHonor, hd.lifetimeHK, hd.lifetimeRank = GetInspectHonorData();
  108.     else
  109.         hd.todayHK, hd.todayHonor = GetPVPSessionStats();
  110.         hd.yesterdayHK, hd.yesterdayHonor = GetPVPYesterdayStats();
  111.         hd.lifetimeHK, hd.lifetimeRank = GetPVPLifetimeStats();
  112.     end
  113.     -- Update
  114.     self:UpdateHonor();
  115. end
  116.  
  117. -- Honor Update
  118. function mod:UpdateHonor()
  119.     -- Show Rank
  120.     if (hd.lifetimeRank ~= 0) then
  121.         self.rankIcon.texture:SetTexture("Interface\\PvPRankBadges\\PvPRank"..format("%.2d",hd.lifetimeRank - 4));
  122.         self.rankIcon.texture:SetTexCoord(0,1,0,1);
  123.         --self.rankIcon.tip = format("%s (Rank %d)",GetPVPRankInfo(hd.lifetimeRank,ex.unit),(hd.lifetimeRank - 4));
  124.         self.rankIcon.tip = format("Rank %d",hd.lifetimeRank - 4);  -- 5.4: GetPVPRankInfo() func removed, can no longer get the rank name, not sure if lifetimeRank still returns valid?
  125.         self.rankIcon:Show();
  126.     end
  127.     -- Show Kills/Honor
  128.     labels[4]:SetText(hd.todayHK);
  129.     labels[5]:SetText(hd.yesterdayHK);
  130.     labels[6]:SetText(hd.lifetimeHK);
  131.     labels[7]:SetText(hd.todayHonor);
  132.     labels[8]:SetText(hd.yesterdayHonor);
  133.     labels[9]:SetText("---");
  134.     labels[9]:SetTextColor(1,1,0);
  135. end
  136.  
  137. -- Load Arena Teams Normal
  138. function mod:LoadArenaTeamsNormal()
  139.     for i = 1, MAX_ARENA_TEAMS+1 do
  140.         local arenaRating, seasonPlayed, seasonWon, weeklyPlayed, weeklyWon = GetInspectArenaData(i);
  141.         ad[i] = { arenaRating, seasonWon, seasonPlayed };
  142.     end
  143.     self:ArenaTeamUpdate();
  144. end
  145.  
  146. -- Arena Team Update
  147. function mod:ArenaTeamUpdate()
  148.     for i = 1, MAX_ARENA_TEAMS+1 do
  149.         local at = ad[i];
  150.         labels[13+((i-1)*3)]:SetText(at[1]);
  151.         labels[14+((i-1)*3)]:SetText(at[2]);
  152.         labels[15+((i-1)*3)]:SetText(at[3]);
  153.     end
  154. end
  155.  
  156. --------------------------------------------------------------------------------------------------------
  157. --                                           Widget Creation                                          --
  158. --------------------------------------------------------------------------------------------------------
  159.  
  160. -- Rank Icon
  161. mod.rankIcon = CreateFrame("Frame",nil,mod.page);
  162. mod.rankIcon:SetPoint("TOPLEFT",12,-12);
  163. mod.rankIcon:SetWidth(18);
  164. mod.rankIcon:SetHeight(18);
  165. mod.rankIcon:EnableMouse(1);
  166. mod.rankIcon:SetScript("OnEnter",function(self) GameTooltip:SetOwner(self,"ANCHOR_BOTTOMRIGHT"); GameTooltip:SetText(self.tip) end)
  167. mod.rankIcon:SetScript("OnLeave",ex.HideGTT);
  168. mod.rankIcon.texture = mod.rankIcon:CreateTexture(nil,"ARTWORK");
  169. mod.rankIcon.texture:SetAllPoints();
  170.  
  171. -- Honor Labels
  172. for i = 1, 9 do
  173.     local l = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  174.     l:SetWidth(70);
  175.  
  176.     if (i <= 3) then
  177.         l:SetText(i == 1 and "Today" or i == 2 and "Yesterday" or "Lifetime");
  178.         l:SetTextColor(0.5,0.75,1);
  179.     else
  180.         l:SetTextColor(1,1,0);
  181.     end
  182.  
  183.     if ((i - 1) % 3 == 0) then
  184.         l:SetPoint("TOP",-28,-36 - (i - 1) / 3 * 12);
  185.     else
  186.         l:SetPoint("LEFT",labels[i - 1],"RIGHT");
  187.     end
  188.  
  189.     labels[i] = l;
  190. end
  191.  
  192. -- Honor Label Side Headers
  193. local t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  194. t:SetPoint("RIGHT",labels[4],"LEFT");
  195. t:SetWidth(70);
  196. t:SetJustifyH("LEFT");
  197. t:SetText("Honor Kills");
  198. t:SetTextColor(0.5,0.75,1);
  199.  
  200. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  201. t:SetPoint("RIGHT",labels[7],"LEFT");
  202. t:SetWidth(70);
  203. t:SetJustifyH("LEFT");
  204. t:SetText("Honor Points");
  205. t:SetTextColor(0.5,0.75,1);
  206.  
  207. -- Arena Labels
  208. for i = 1, 15 do
  209.     local l = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  210.     l:SetWidth(70);
  211.  
  212.     if (i <= 3) then
  213.         l:SetText(i == 1 and "Rating" or i == 2 and "Won" or "Played");
  214.         l:SetTextColor(0.5,0.75,1);
  215.     else
  216.         l:SetTextColor(1,1,0);
  217.     end
  218.  
  219.     if ((i - 1) % 3 == 0) then
  220.         l:SetPoint("TOP",-28,-36 - (i - 1) / 3 * 12 - 42);
  221.     else
  222.         l:SetPoint("LEFT",labels[i + 9 - 1],"RIGHT");
  223.     end
  224.  
  225.     labels[i+9] = l;
  226. end
  227.  
  228. -- Arena Label Side Headers
  229. local t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  230. t:SetPoint("RIGHT",labels[13],"LEFT");
  231. t:SetWidth(70);
  232. t:SetJustifyH("LEFT");
  233. t:SetText("2v2");
  234. t:SetTextColor(0.5,0.75,1);
  235.  
  236. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  237. t:SetPoint("RIGHT",labels[16],"LEFT");
  238. t:SetWidth(70);
  239. t:SetJustifyH("LEFT");
  240. t:SetText("3v3");
  241. t:SetTextColor(0.5,0.75,1);
  242.  
  243. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  244. t:SetPoint("RIGHT",labels[19],"LEFT");
  245. t:SetWidth(70);
  246. t:SetJustifyH("LEFT");
  247. t:SetText("5v5");
  248. t:SetTextColor(0.5,0.75,1);
  249.  
  250. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  251. t:SetPoint("RIGHT",labels[22],"LEFT");
  252. t:SetWidth(70);
  253. t:SetJustifyH("LEFT");
  254. t:SetText("RBGs");
  255. t:SetTextColor(0.5,0.75,1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement