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:
if select(2, UnitClass("player")) ~= "ROGUE" then
return;
end
local RtheDsList = {
199603, -- Jolly Roger
193358, -- Grand Melee
193357, -- Shark Infested Waters
193359, -- True Bearing
199600, -- Buried Treasure
193356, -- Broadsides
};
local LSM = LibStub("LibSharedMedia-3.0");
local font = LSM:Fetch("font", "koverwatch");
local OutlawFrame = CreateFrame("Frame", "CA_Outlaw", UIParent);
OutlawFrame:RegisterEvent("PLAYER_LOGIN");
OutlawFrame:RegisterEvent("PLAYER_ENTERING_WORLD");
OutlawFrame:RegisterEvent("UNIT_AURA");
OutlawFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED");
OutlawFrame:SetSize(200, 200);
OutlawFrame:SetPoint("CENTER", 0, 250);
function OutlawFrame:CreateRtheDs()
local RtheDs = CreateFrame("Frame", "$parentRollTheDice", self);
RtheDs:SetAllPoints(true);
for i = 1, #RtheDsList do
local RtheD = CreateFrame("Frame", "$parentBuff" .. i, RtheDs);
RtheD:SetSize(32, 32);
RtheD:SetPoint("CENTER", math.cos(math.pi / 3 * (i - 1)) * 64, math.sin(math.pi / 3 * (i - 1)) * 64);
RtheD.sID = RtheDsList[i];
local cd = CreateFrame("Cooldown", "$parentCooldown", RtheD, "CooldownFrameTemplate");
cd:SetPoint("CENTER");
cd:GetRegions():SetSize(RtheD:GetWidth() + 2, 15);
cd:GetRegions():SetFont(font, 15, "OUTLINE");
cd:GetRegions():SetJustifyV("TOP");
cd:GetRegions():SetJustifyH("CENTER");
local name, _, icon = GetSpellInfo(RtheD.sID);
local texture = RtheD:CreateTexture("$parentIcon", "Overlay");
texture:SetTexture(icon);
texture:SetAllPoints(true);
RtheD.UpdateTooltip = function(self)
GameTooltip:SetSpellByID(self.sID);
end;
RtheD:SetScript("OnEnter", function(self)
if not self:IsVisible() then
return;
end
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");
self:UpdateTooltip();
end);
RtheD:SetScript("OnLeave", function()
GameTooltip:Hide();
end);
RtheD.cd = cd;
RtheD.texture = texture;
RtheDs[i] = RtheD;
end
self.RtheDs = RtheDs;
end
function OutlawFrame:OnEvent(event, ...)
if event == "PLAYER_LOGIN" then
self:CreateRtheDs();
if select(1, GetSpecializationInfo(GetSpecialization())) ~= 260 then
self:Hide();
else
for i = 1, #(self.RtheDs) do
self.RtheDs[i]:SetAlpha(0.4);
end
end
elseif event == "PLAYER_ENTERING_WORLD" or event == "UNIT_AURA" then
for i = 1, #(self.RtheDs) do
local name = GetSpellInfo(self.RtheDs[i].sID);
local _, _, _, _, _, duration, expirationTime = UnitAura("player", name);
if duration and duration > 0 then
self.RtheDs[i]:SetAlpha(1);
self.RtheDs[i].cd:SetCooldown(expirationTime - duration, duration);
self.RtheDs[i].cd:Show();
else
self.RtheDs[i]:SetAlpha(0.4);
self.RtheDs[i].cd:Hide();
end
end
elseif event == "PLAYER_SPECIALIZATION_CHANGED" then
if select(1, GetSpecializationInfo(GetSpecialization())) == 260 then
self:Show();
else
self:Hide();
end
end
end
OutlawFrame:SetScript("OnEvent", OutlawFrame.OnEvent);
I would appreciate any feedback, advice as well as criticism
Thank you!