-
-
Save anonymous/d6c44f8127f860333c3ca4a252851460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local name = ... | |
LeecherDB = {} | |
local GetTalentInfo = GetTalentInfo | |
local _uPower = UnitPower | |
local _uBuff = UnitBuff | |
local _sml = LibStub:GetLibrary("LibSharedMedia-3.0") | |
local _frame = CreateFrame("Frame", "LeecherFrame", UIParent) | |
local fullcost = 45 | |
local redcost = 40 | |
local ossuary = false | |
function _frame:initCreate() | |
_frame.tex = _frame:CreateTexture("ARTWORK") | |
_frame.text = _frame:CreateFontString() | |
end | |
function _frame:init() | |
_frame:SetPoint("TOPLEFT", self.db.x, -self.db.y); | |
_frame:SetAlpha(1) | |
_frame:SetWidth(self.db.size) | |
_frame:SetHeight(self.db.size) | |
_frame.tex:SetAllPoints() | |
--_frame.tex:SetTexture([[Interface\Icons\spell_deathknight_butcher2]]) | |
_frame.tex:SetTexture([[Interface\Icons\ability_deathknight_sanguinfortitude]]) | |
_frame.tex:SetAlpha(self.db.a) | |
_frame.tex:SetTexCoord(.08, .92, .08, .92) | |
--print(self.db.font) | |
--print(_sml:Fetch("font", self.db.font)) | |
_frame.text:SetFont(_sml:Fetch("font", self.db.font), self.db.fontsize, self.db.flags) | |
_frame.text:SetAlpha(self.db.fonta) | |
_frame.text:SetPoint("CENTER", _frame, "CENTER", self.db.offx, self.db.offy) | |
if (not UnitAffectingCombat("player") and not self.configmode) then | |
_frame:Hide() | |
end | |
end | |
function _frame:registerEvents() | |
self:SetScript("OnUpdate", self.OnUpdate) | |
self:RegisterEvent("PLAYER_REGEN_DISABLED") | |
self:RegisterEvent("PLAYER_REGEN_ENABLED") | |
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") | |
self:RegisterEvent("PLAYER_TALENT_UPDATE") | |
end | |
local function hasOssuary() | |
return select(4, GetTalentInfo(3, 1, 1, nil, nil)) | |
end | |
local e = 0 | |
local updateRate = 0.15 | |
function _frame:OnUpdate(elapsed) | |
e = e + elapsed | |
if (e > updateRate) then | |
e = 0 | |
self:update() | |
end | |
end | |
function _frame:toggleVisibility() | |
if (_frame.text:GetText() == "0") then | |
_frame:SetAlpha(0) | |
else | |
_frame:SetAlpha(1) | |
end | |
end | |
function _frame:update() | |
if (not UnitAffectingCombat("player")) then | |
return | |
end | |
if (ossuary == true) then | |
local boneshield = _uBuff("player", "Ossuary") | |
if (not boneshield) then | |
_frame.text:SetText(math.floor(_uPower("player") / fullcost)) | |
else | |
_frame.text:SetText(math.floor(_uPower("player") / redcost)) | |
end | |
else | |
_frame.text:SetText(math.floor(_uPower("player") / fullcost)) | |
end | |
if (not self.db.showzero) then | |
self:toggleVisibility() | |
end | |
end | |
function _frame:OnEvent(e, arg1, arg2) | |
if (e == "ADDON_LOADED" and name == arg1) then | |
self:loadVariables() | |
self:initOptionsPanel() | |
_frame:UnregisterEvent(e) | |
elseif (e == "PLAYER_LOGIN") then | |
ossuary = hasOssuary() | |
self:initCreate() | |
self:init() | |
self:registerEvents() | |
_frame:UnregisterEvent(e) | |
elseif (e == "PLAYER_TALENT_UPDATE") then | |
ossuary = hasOssuary() | |
elseif (e == "ACTIVE_TALENT_GROUP_CHANGED") then | |
local _, name = GetSpecializationInfo(GetSpecialization()) | |
if(name == "Blood") then | |
_frame:Show() | |
else | |
_frame:Hide() | |
end | |
elseif (e == "PLAYER_REGEN_DISABLED") then | |
_frame:SetAlpha(0) | |
_frame:Show() | |
elseif (e == "PLAYER_REGEN_ENABLED") then | |
_frame:Hide() | |
end | |
end | |
local function doDefaults(playerName) | |
LeecherDB[playerName] = {} | |
LeecherDB[playerName].font = "Morpheus" | |
LeecherDB[playerName].size = 44 | |
LeecherDB[playerName].fontsize = 24 | |
LeecherDB[playerName].flags = "OUTLINE" | |
LeecherDB[playerName].fonta = 0.8 | |
LeecherDB[playerName].a = 0.6 | |
LeecherDB[playerName].x = 938 | |
LeecherDB[playerName].y = 720 | |
LeecherDB[playerName].offx = 0 | |
LeecherDB[playerName].offy = 0 | |
LeecherDB[playerName].showzero = false | |
end | |
function _frame:loadVariables() | |
local playerName = format("%s - %s", UnitName("player"), GetRealmName()) | |
--defaults-- | |
if not LeecherDB[playerName] then | |
doDefaults(playerName) | |
end | |
self.db = LeecherDB[playerName] | |
end | |
--OPTIONS PANEL-- | |
local _optionsPanel = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer) | |
function _frame:createCheckBox(parent, label, desc, state, lambda) | |
local checkbox = CreateFrame("CheckButton", "LeecherCBox" .. label, parent, "InterfaceOptionsCheckButtonTemplate") | |
checkbox:SetChecked(state or false) | |
checkbox.tooltipText = desc | |
checkbox.SetValue = lambda | |
checkbox.title = string.sub(label, 2) | |
checkbox:SetScript("OnClick", | |
function(self, event, arg1) | |
self.SetValue(self:GetChecked()) | |
end) | |
_G[checkbox:GetName() .. "Text"]:SetText(format("%s", checkbox.title)) | |
return checkbox | |
end | |
function _frame:createSlider(parent, label, desc, state, lambda, min, max, step) | |
local slider = CreateFrame("Slider", "LeecherSlider" .. label, parent, "OptionsSliderTemplate") | |
slider.tooltipText = desc | |
slider.callback = lambda | |
slider:SetObeyStepOnDrag(true) | |
slider:SetValueStep(step) | |
slider:SetMinMaxValues(min, max) | |
slider.minText = _G[slider:GetName() .. "Low"] | |
slider.maxText = _G[slider:GetName() .. "High"] | |
slider.minText:SetText(min) | |
slider.maxText:SetText(max) | |
slider:SetValue(state) | |
slider.title = string.sub(label, 2) | |
slider:SetScript("OnValueChanged", function(self, value) | |
self.callback(value) | |
_G[slider:GetName() .. "Text"]:SetText(format("%s (%d)", self.title, self:GetValue())) | |
end) | |
slider:SetScript("OnMouseWheel", function(self, value) | |
local newvalue = self:GetValue() + (value * self:GetValueStep()) | |
self:SetValue(newvalue) | |
_G[slider:GetName() .. "Text"]:SetText(format("%s (%d)", self.title, self:GetValue())) | |
end) | |
_G[slider:GetName() .. "Text"]:SetText(format("%s (%d)", slider.title, slider:GetValue())) | |
return slider | |
end | |
function _frame:createDropDown(parent, label, desc, state, items, lambda) | |
local dropdown = CreateFrame("Frame", label, parent, "UIDropDownMenuTemplate") | |
_G[dropdown:GetName() .. "Text"]:SetText(label) | |
dropdown.info = {} | |
UIDropDownMenu_SetText(dropdown, state) | |
dropdown.items = items | |
UIDropDownMenu_Initialize(dropdown, | |
function(self, level, items) | |
local info = UIDropDownMenu_CreateInfo() | |
for k, v in pairs(self.items) do | |
info.text = v | |
info.notCheckable = true | |
info.arg1 = v | |
info.func = lambda | |
UIDropDownMenu_AddButton(info) | |
end | |
end) | |
return dropdown | |
end | |
_frame.configmode = false | |
function _frame:initOptionsPanel() | |
_optionsPanel.name = "Leecher" | |
InterfaceOptions_AddCategory(_optionsPanel) | |
--title-- | |
local leecherFrameOptions=CreateFrame("Frame", "LeecherOptionsTitle", _optionsPanel) | |
leecherFrameOptions:SetPoint("TOPLEFT", 10, -55) | |
leecherFrameOptions:SetWidth(150) | |
leecherFrameOptions:SetHeight(50) | |
local addonOptionsTitle = leecherFrameOptions:CreateFontString(nil, "OVERLAY", "GameFontNormal") | |
addonOptionsTitle:SetText("Leecher") | |
addonOptionsTitle:SetPoint("TOPLEFT", 0, 40) | |
addonOptionsTitle:SetFont("Fonts\\FRIZQT__.TTF", 24) | |
--configmode | |
local checkboxCfg = self:createCheckBox(leecherFrameOptions, "LConfig mode", "Show the icon to configurate", self.configmode, | |
function(val) | |
if (val == true) then | |
self.configmode = true | |
_frame:SetAlpha(1) | |
_frame.text:SetText("3") | |
_frame:Show() | |
else | |
self.configmode = false | |
_frame.text:SetText("") | |
_frame:Hide() | |
end | |
end) | |
checkboxCfg:SetScale(1.5) | |
checkboxCfg:SetPoint("TOPLEFT", 264, -12) | |
--show zero -- | |
local checkboxZero = self:createCheckBox(leecherFrameOptions, "LShow when zero", "Show icon when count is zero", self.db.showzero, | |
function(val) | |
self.db.showzero = val | |
end) | |
checkboxZero:SetScale(1.5) | |
checkboxZero:SetPoint("TOPLEFT", 4, -12) | |
--iconsize | |
local sliderIconSize = self:createSlider(leecherFrameOptions, "LIcon size", "Size for icon", self.db.size, | |
function(val) | |
self.db.size = val | |
self:init() | |
end, 32, 128, 2) | |
sliderIconSize:SetPoint("TOPLEFT", 16, -88) | |
--fontsize-- | |
local sliderFontSize = self:createSlider(leecherFrameOptions, "LFont size", "Text size for count", self.db.fontsize, | |
function(val) | |
self.db.fontsize = val | |
self:init() | |
end, 8, 60, 2) | |
sliderFontSize:SetPoint("TOPLEFT", 16, -120) | |
--icon alpha | |
local sliderIconAlpha = self:createSlider(leecherFrameOptions, "LIcon alpha", "Transparency for icon", self.db.a * 100, | |
function(val) | |
self.db.a = val / 100 | |
self:init() | |
end, 0, 100, 5) | |
sliderIconAlpha:SetPoint("TOPLEFT", 264, -88) | |
--font alpha-- | |
local sliderFontAlpha = self:createSlider(leecherFrameOptions, "LFont alpha", "Transparency for count", self.db.fonta * 100, | |
function(val) | |
self.db.fonta = val / 100 | |
self:init() | |
end, 0, 100, 5) | |
sliderFontAlpha:SetPoint("TOPLEFT", 264, -120) | |
--x position-- | |
local editLeecherX = self:createSlider(leecherFrameOptions, "LX pos", "Horizontal position", self.db.x, | |
function(val) | |
self.db.x = val | |
self:init() | |
end, 0, floor(GetScreenWidth()), 2) | |
editLeecherX:SetPoint("TOPLEFT", 16, -152) | |
--y position-- | |
local editLeecherY = self:createSlider(leecherFrameOptions, "LY pos", "Vertical position", self.db.y, | |
function(val) | |
self.db.y = val | |
self:init() | |
end, 0, floor(GetScreenHeight()), 2) | |
editLeecherY:SetPoint("TOPLEFT", 16, -184) | |
--outline | |
local leecherOutline = {"MONOCHROME", "OUTLINE", "THICKOUTLINE"} | |
local leecherDropOutline = self:createDropDown(leecherFrameOptions, "LeecherOutlineDrop", "Outline of counter", self.db.flags, leecherOutline, | |
function(key) | |
self.db.flags = key.value | |
self:init() | |
UIDropDownMenu_SetSelectedName(LeecherOutlineDrop, key.text, key.value) | |
UIDropDownMenu_SetText(LeecherOutlineDrop, key.value) | |
CloseDropDownMenus() | |
end) | |
leecherDropOutline:SetPoint("TOPLEFT", 0, -240) | |
--font-- | |
local leecherfonts = _sml:List("font") | |
local leecherFontOption = self:createDropDown(leecherFrameOptions, "LeecherFontsDrop", "Font of counter", self.db.font, leecherfonts, | |
function(key) | |
--print(key.value) | |
self.db.font = key.value | |
self:init() | |
UIDropDownMenu_SetSelectedName(LeecherFontsDrop, key.text, key.value) | |
UIDropDownMenu_SetText(LeecherFontsDrop, key.value) | |
CloseDropDownMenus() | |
end) | |
leecherFontOption:SetPoint("TOPLEFT", 0, -280) | |
--x text offset-- | |
local editLeecherOffX = self:createSlider(leecherFrameOptions, "LX offset", "Horizontal text offset", self.db.offy, | |
function(val) | |
self.db.offx = val | |
self:init() | |
end, -60, 60, 1) | |
editLeecherOffX:SetPoint("TOPLEFT", 16, -320) | |
--y text offset-- | |
local editLeecherOffY = self:createSlider(leecherFrameOptions, "LY offset", "Vertical text offset", self.db.offy, | |
function(val) | |
self.db.offy = val | |
self:init() | |
end, -60, 60, 1) | |
editLeecherOffY:SetPoint("TOPLEFT", 16, -352) | |
end | |
--SLASH COMMANDS -- | |
SlashCmdList["LEECHER_SLASHCMD"] = function(msg) | |
InterfaceOptionsFrame_OpenToCategory("Leecher") | |
end | |
SLASH_LEECHER_SLASHCMD1 = "/leecher" | |
_frame:RegisterEvent("PLAYER_LOGIN") | |
_frame:RegisterEvent("ADDON_LOADED") | |
_frame:SetScript("OnEvent", _frame.OnEvent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment