Thread Tools Display Modes
Prev Previous Post   Next Post Next
08-28-16, 08:28 PM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Would like to get some general advice

Hi all,

For this time, I am here to ask some general advice or feedback regarding my Outlaw Rogue's Roll the Dice assist addon.

Until now, I have been playing around with those awesome libraries or modules like oUF, LibSharedMedia, LibStub, CallbackHandler and so on, and I know that there are already couple of fancy Roll the Dice assist addons exist. However, creating one by myself would be a good practice to test my skills, revise the things that I am misunderstanding and even learn new features.

SO, here's a super simple addon that just displays duration, icon and tooltip for each Roll the Dice buffs that the player currently got.
(Pretty sure even a person who just started learning lua can make this and that's how simple this addon is haha...)

Lua Code:
  1. if select(2, UnitClass("player")) ~= "ROGUE" then
  2.     return;
  3. end
  4.  
  5. local RtheDsList = {
  6.     199603, -- Jolly Roger
  7.     193358, -- Grand Melee
  8.     193357, -- Shark Infested Waters
  9.     193359, -- True Bearing
  10.     199600, -- Buried Treasure
  11.     193356, -- Broadsides
  12. };
  13.  
  14. local LSM = LibStub("LibSharedMedia-3.0");
  15. local font = LSM:Fetch("font", "koverwatch");
  16.  
  17. local OutlawFrame = CreateFrame("Frame", "CA_Outlaw", UIParent);
  18. OutlawFrame:RegisterEvent("PLAYER_LOGIN");
  19. OutlawFrame:RegisterEvent("PLAYER_ENTERING_WORLD");
  20. OutlawFrame:RegisterEvent("UNIT_AURA");
  21. OutlawFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED");
  22. OutlawFrame:SetSize(200, 200);
  23. OutlawFrame:SetPoint("CENTER", 0, 250);
  24.  
  25. function OutlawFrame:CreateRtheDs()
  26.     local RtheDs = CreateFrame("Frame", "$parentRollTheDice", self);
  27.     RtheDs:SetAllPoints(true);
  28.  
  29.     for i = 1, #RtheDsList do
  30.         local RtheD = CreateFrame("Frame", "$parentBuff" .. i, RtheDs);
  31.         RtheD:SetSize(32, 32);
  32.         RtheD:SetPoint("CENTER", math.cos(math.pi / 3 * (i - 1)) * 64, math.sin(math.pi / 3 * (i - 1)) * 64);
  33.  
  34.         RtheD.sID = RtheDsList[i];
  35.  
  36.         local cd = CreateFrame("Cooldown", "$parentCooldown", RtheD, "CooldownFrameTemplate");
  37.         cd:SetPoint("CENTER");
  38.         cd:GetRegions():SetSize(RtheD:GetWidth() + 2, 15);
  39.         cd:GetRegions():SetFont(font, 15, "OUTLINE");
  40.         cd:GetRegions():SetJustifyV("TOP");
  41.         cd:GetRegions():SetJustifyH("CENTER");
  42.  
  43.         local name, _, icon = GetSpellInfo(RtheD.sID);
  44.  
  45.         local texture = RtheD:CreateTexture("$parentIcon", "Overlay");
  46.         texture:SetTexture(icon);
  47.         texture:SetAllPoints(true);
  48.  
  49.         RtheD.UpdateTooltip = function(self)
  50.             GameTooltip:SetSpellByID(self.sID);
  51.         end;
  52.         RtheD:SetScript("OnEnter", function(self)
  53.             if not self:IsVisible() then
  54.                 return;
  55.             end
  56.  
  57.             GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
  58.  
  59.             self:UpdateTooltip();
  60.         end);
  61.         RtheD:SetScript("OnLeave", function()
  62.             GameTooltip:Hide();
  63.         end);
  64.  
  65.         RtheD.cd = cd;
  66.         RtheD.texture = texture;
  67.  
  68.         RtheDs[i] = RtheD;
  69.     end
  70.  
  71.     self.RtheDs = RtheDs;
  72. end
  73.  
  74. function OutlawFrame:OnEvent(event, ...)
  75.     if event == "PLAYER_LOGIN" then
  76.         self:CreateRtheDs();
  77.  
  78.         if select(1, GetSpecializationInfo(GetSpecialization())) ~= 260 then
  79.             self:Hide();
  80.         else
  81.             for i = 1, #(self.RtheDs) do
  82.                 self.RtheDs[i]:SetAlpha(0.4);
  83.             end
  84.         end
  85.     elseif event == "PLAYER_ENTERING_WORLD" or event == "UNIT_AURA" then
  86.         for i = 1, #(self.RtheDs) do
  87.             local name = GetSpellInfo(self.RtheDs[i].sID);
  88.  
  89.             local _, _, _, _, _, duration, expirationTime = UnitAura("player", name);
  90.  
  91.             if duration and duration > 0 then
  92.                 self.RtheDs[i]:SetAlpha(1);
  93.                 self.RtheDs[i].cd:SetCooldown(expirationTime - duration, duration);
  94.                 self.RtheDs[i].cd:Show();
  95.             else
  96.                 self.RtheDs[i]:SetAlpha(0.4);
  97.                 self.RtheDs[i].cd:Hide();
  98.             end
  99.         end
  100.     elseif event == "PLAYER_SPECIALIZATION_CHANGED" then
  101.         if select(1, GetSpecializationInfo(GetSpecialization())) == 260 then
  102.             self:Show();
  103.         else
  104.             self:Hide();
  105.         end
  106.     end
  107. end
  108.  
  109. OutlawFrame:SetScript("OnEvent", OutlawFrame.OnEvent);

I would appreciate any feedback, advice as well as criticism

Thank you!

Last edited by Layback_ : 08-29-16 at 02:53 AM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Would like to get some general advice


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off