Advertisement
Guest User

pvp.lua

a guest
Feb 3rd, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.20 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. end
  94.  
  95. --------------------------------------------------------------------------------------------------------
  96. --                                             PvP Stuff                                              --
  97. --------------------------------------------------------------------------------------------------------
  98.  
  99. -- Load Honor Normal
  100. function mod:LoadHonorNormal()
  101.     self:HasData(true);
  102.     -- Query -- Az: Even if inspecting ourself, use inspect data as GetPVPYesterdayStats() is bugged as of (4.0.1 - 4.0.3a)
  103.     if (not ex.isSelf) or (HasInspectHonorData()) then
  104.         hd.todayHK, hd.todayHonor, hd.yesterdayHK, hd.yesterdayHonor, hd.lifetimeHK, hd.lifetimeRank = GetInspectHonorData();
  105.     else
  106.         hd.todayHK, hd.todayHonor = GetPVPSessionStats();
  107.         hd.yesterdayHK, hd.yesterdayHonor = GetPVPYesterdayStats();
  108.         hd.lifetimeHK, hd.lifetimeRank = GetPVPLifetimeStats();
  109.     end
  110.     -- Update
  111.     self:UpdateHonor();
  112. end
  113.  
  114. -- Honor Update
  115. function mod:UpdateHonor()
  116.     -- Show Rank
  117.     if (hd.lifetimeRank ~= 0) then
  118.         self.rankIcon.texture:SetTexture("Interface\\PvPRankBadges\\PvPRank"..format("%.2d",hd.lifetimeRank - 4));
  119.         self.rankIcon.texture:SetTexCoord(0,1,0,1);
  120.         --self.rankIcon.tip = format("%s (Rank %d)",GetPVPRankInfo(hd.lifetimeRank,ex.unit),(hd.lifetimeRank - 4));
  121.         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?
  122.         self.rankIcon:Show();
  123.     end
  124.     -- Show Kills/Honor
  125.     labels[4]:SetText(hd.todayHK);
  126.     labels[5]:SetText(hd.yesterdayHK);
  127.     labels[6]:SetText(hd.lifetimeHK);
  128.     labels[7]:SetText(hd.todayHonor);
  129.     labels[8]:SetText(hd.yesterdayHonor);
  130.     labels[9]:SetText("---");
  131.     labels[9]:SetTextColor(1,1,0);
  132. end
  133.  
  134. -- Load Arena Teams Normal
  135. function mod:LoadArenaTeamsNormal()
  136.     for i = 1, MAX_ARENA_TEAMS+1 do
  137.         local arenaRating, seasonPlayed, seasonWon, weeklyPlayed, weeklyWon = GetInspectArenaData(i);
  138.         ad[i] = { arenaRating, seasonWon, seasonPlayed };
  139.     end
  140.     self:ArenaTeamUpdate();
  141. end
  142.  
  143. -- Arena Team Update
  144. function mod:ArenaTeamUpdate()
  145.     for i = 1, MAX_ARENA_TEAMS+1 do
  146.         local at = ad[i];
  147.         labels[13+((i-1)*3)]:SetText(at[1]);
  148.         labels[14+((i-1)*3)]:SetText(at[2]);
  149.         labels[15+((i-1)*3)]:SetText(at[3]);
  150.     end
  151. end
  152.  
  153. --------------------------------------------------------------------------------------------------------
  154. --                                           Widget Creation                                          --
  155. --------------------------------------------------------------------------------------------------------
  156.  
  157. -- Rank Icon
  158. mod.rankIcon = CreateFrame("Frame",nil,mod.page);
  159. mod.rankIcon:SetPoint("TOPLEFT",12,-12);
  160. mod.rankIcon:SetWidth(18);
  161. mod.rankIcon:SetHeight(18);
  162. mod.rankIcon:EnableMouse(1);
  163. mod.rankIcon:SetScript("OnEnter",function(self) GameTooltip:SetOwner(self,"ANCHOR_BOTTOMRIGHT"); GameTooltip:SetText(self.tip) end)
  164. mod.rankIcon:SetScript("OnLeave",ex.HideGTT);
  165. mod.rankIcon.texture = mod.rankIcon:CreateTexture(nil,"ARTWORK");
  166. mod.rankIcon.texture:SetAllPoints();
  167.  
  168. -- Honor Labels
  169. for i = 1, 9 do
  170.     local l = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  171.     l:SetWidth(70);
  172.  
  173.     if (i <= 3) then
  174.         l:SetText(i == 1 and "Today" or i == 2 and "Yesterday" or "Lifetime");
  175.         l:SetTextColor(0.5,0.75,1);
  176.     else
  177.         l:SetTextColor(1,1,0);
  178.     end
  179.  
  180.     if ((i - 1) % 3 == 0) then
  181.         l:SetPoint("TOP",-28,-36 - (i - 1) / 3 * 12);
  182.     else
  183.         l:SetPoint("LEFT",labels[i - 1],"RIGHT");
  184.     end
  185.  
  186.     labels[i] = l;
  187. end
  188.  
  189. -- Honor Label Side Headers
  190. local t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  191. t:SetPoint("RIGHT",labels[4],"LEFT");
  192. t:SetWidth(70);
  193. t:SetJustifyH("LEFT");
  194. t:SetText("Honor Kills");
  195. t:SetTextColor(0.5,0.75,1);
  196.  
  197. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  198. t:SetPoint("RIGHT",labels[7],"LEFT");
  199. t:SetWidth(70);
  200. t:SetJustifyH("LEFT");
  201. t:SetText("Honor Points");
  202. t:SetTextColor(0.5,0.75,1);
  203.  
  204. -- Arena Labels
  205. for i = 1, 15 do
  206.     local l = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  207.     l:SetWidth(70);
  208.  
  209.     if (i <= 3) then
  210.         l:SetText(i == 1 and "Rating" or i == 2 and "Won" or "Played");
  211.         l:SetTextColor(0.5,0.75,1);
  212.     else
  213.         l:SetTextColor(1,1,0);
  214.     end
  215.  
  216.     if ((i - 1) % 3 == 0) then
  217.         l:SetPoint("TOP",-28,-36 - (i - 1) / 3 * 12 - 42);
  218.     else
  219.         l:SetPoint("LEFT",labels[i + 9 - 1],"RIGHT");
  220.     end
  221.  
  222.     labels[i+9] = l;
  223. end
  224.  
  225. -- Arena Label Side Headers
  226. local t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  227. t:SetPoint("RIGHT",labels[13],"LEFT");
  228. t:SetWidth(70);
  229. t:SetJustifyH("LEFT");
  230. t:SetText("2v2");
  231. t:SetTextColor(0.5,0.75,1);
  232.  
  233. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  234. t:SetPoint("RIGHT",labels[16],"LEFT");
  235. t:SetWidth(70);
  236. t:SetJustifyH("LEFT");
  237. t:SetText("3v3");
  238. t:SetTextColor(0.5,0.75,1);
  239.  
  240. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  241. t:SetPoint("RIGHT",labels[19],"LEFT");
  242. t:SetWidth(70);
  243. t:SetJustifyH("LEFT");
  244. t:SetText("5v5");
  245. t:SetTextColor(0.5,0.75,1);
  246.  
  247. t = mod.page:CreateFontString(nil,"ARTWORK","GameFontHighlightSmall");
  248. t:SetPoint("RIGHT",labels[22],"LEFT");
  249. t:SetWidth(70);
  250. t:SetJustifyH("LEFT");
  251. t:SetText("RBGs");
  252. t:SetTextColor(0.5,0.75,1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement