diff --git a/Releases/nrg-1.1.0.zip b/Releases/nrg-1.1.0.zip new file mode 100644 index 0000000..2345505 Binary files /dev/null and b/Releases/nrg-1.1.0.zip differ diff --git a/nrg/Battery.lua b/nrg/Battery.lua index 28f5dba..d93e512 100644 --- a/nrg/Battery.lua +++ b/nrg/Battery.lua @@ -11,9 +11,13 @@ Please see the ReadMe.txt for addon details. ]] +-- Persisted options, needs to be global. +NRG_Options = { }; + + local addonMetadata = { ["ADDONNAME"] = "NRG", - ["SHORTNAME"] = "NRG", + ["SHORTNAME"] = "nrg", ["PREFIX"] = "NRGv1", ["NORMALCHATCOLOR"] = "2060FF", ["HOTCHATCOLOR"] = "F0F0F0", @@ -79,19 +83,22 @@ local NRG_ENABLED_FOR_CLASSES = { local CONFIG_KEY_PowerButtonPosX = "PowerButton.X"; local CONFIG_KEY_PowerButtonPosY = "PowerButton.Y"; +local CONFIG_KEY_PowerButtonSize = "PowerButton.Size"; local CONFIG_KEY_PowerButtonVisible = "PowerButton.Visible"; +local CONFIG_DEFAULT_PowerButtonSize = 3; local CONFIG_DEFAULT_PowerButtonVisible = true; -A.options = { }; A.currentVersion = 0; A.currentPowerLevel = 0; +A.enabledForPlayer = false; -- Timer settings: A.timerTick = 0; A.nextPowerStep = 0; A.powerFrequency = 1.00; +A.disableUpdates = true; -- @@ -113,6 +120,8 @@ SlashCmdList["NRG_NRG"] = function(msg) SlashCmdList["NRG_SHOW"](); elseif option == "HIDE" then SlashCmdList["NRG_HIDE"](); + elseif option == "SIZE" then + SlashCmdList["NRG_SIZE"](msg); elseif option == "VERSION" then SlashCmdList["NRG_VERSION"](); else @@ -140,6 +149,19 @@ SlashCmdList["NRG_HIDE"] = function(msg) A:SetOption(CONFIG_KEY_PowerButtonVisible, A.configPowerButtonVisible); end +-- Set the size of the power button +-- Syntax: /nrgsize +-- Alternative: /nrg size +SLASH_NRG_SIZE1 = "/nrgsize" +SlashCmdList["NRG_SIZE"] = function(msg) + local _, _, sizeStr = string.find(msg, "size (%d*)"); + local size = tonumber(sizeStr); + if size and size >= 1 and size <= 15 then + A:UpdatePowerButtonSize(size + 1); + A:SetOption(CONFIG_KEY_PowerButtonSize, size); + end; +end + -- Request client version information -- Syntax: /nrgversion -- Alternative: /nrg version @@ -153,18 +175,27 @@ SlashCmdList["NRG_VERSION"] = function(msg) end -function A:MainInitialization() +function A:PreInitialization() self.currentPowerLevel = 0; + self.disableUpdates = true; + NRGPowerButton:Hide(); +end; + +function A:PostInitialization() self:InitializeConfigSettings(); self:RepositionateButton(NRGPowerButton); - if NRG_ENABLED_FOR_CLASSES[self.localPlayerClass] and A.configPowerButtonVisible then + self.enabledForPlayer = NRG_ENABLED_FOR_CLASSES[self.localPlayerClass]; + if self.enabledForPlayer and self.configPowerButtonVisible then NRGPowerButton:Show(); else NRGPowerButton:Hide(); end; + + self.disableUpdates = false; end; + function A:RepositionateButton(sender) local x, y = sender:GetLeft(), sender:GetTop() - UIParent:GetHeight(); @@ -179,6 +210,12 @@ function A:UpdatePower() NRGPowerButton:SetPushedTexture(NRG_POWERLEVELS[self.currentPowerLevel]["icon"]); end; +function A:UpdatePowerButtonSize(size) + NRGPowerButton:SetWidth(size * 16); + NRGPowerButton:SetHeight(size * 8); + NRGPowerButtonValue:SetFont("Fonts\\FRIZQT__.TTF", 10 + size * 3); +end; + function A:ResetPower() self.currentPowerLevel = 0; self:UpdatePower(); @@ -196,14 +233,18 @@ end; -- Configuration functions -- function A:GetOption(parameter, defaultValue) - if self.options[self.localPlayerRealm] then - if self.options[self.localPlayerRealm][self.localPlayerName] then - if self.options[self.localPlayerRealm][self.localPlayerName][parameter] then - local value = self.options[self.localPlayerRealm][self.localPlayerName][parameter]; + local realmname = self.localPlayerRealm; + local playername = UnitName("player"); + + -- Character level + if NRG_Options[realmname] then + if NRG_Options[realmname][playername] then + if NRG_Options[realmname][playername][parameter] then + local value = NRG_Options[realmname][playername][parameter]; if (type(value) == "table") or not(value == "") then return value; end - end + end end end @@ -211,20 +252,24 @@ function A:GetOption(parameter, defaultValue) end function A:SetOption(parameter, value) - if not self.options[self.localPlayerRealm] then - self.options[self.localPlayerRealm] = { }; + local realmname = self.localPlayerRealm; + local playername = UnitName("player"); + + -- Character level: + if not NRG_Options[realmname] then + NRG_Options[realmname] = { }; end - if not self.options[self.localPlayerRealm][self.localPlayerName] then - self.options[self.localPlayerRealm][self.localPlayerName] = { }; + if not NRG_Options[realmname][playername] then + NRG_Options[realmname][playername] = { }; end - self.options[self.localPlayerRealm][self.localPlayerName][parameter] = value; + NRG_Options[realmname][playername][parameter] = value; end function A:InitializeConfigSettings() - if not self.options then - self.options = { }; + if not NRG_Options then + NRG_Options = { }; end local x,y = NRGPowerButton:GetPoint(); @@ -233,11 +278,19 @@ function A:InitializeConfigSettings() local value = self:GetOption(CONFIG_KEY_PowerButtonVisible, CONFIG_DEFAULT_PowerButtonVisible); if type(value) == "boolean" then - A.configPowerButtonVisible = value; + self.configPowerButtonVisible = value; else - A.configPowerButtonVisible = CONFIG_DEFAULT_PowerButtonVisible; + self.configPowerButtonVisible = CONFIG_DEFAULT_PowerButtonVisible; + end; + self:SetOption(CONFIG_KEY_PowerButtonVisible, self.configPowerButtonVisible); + + local value = self:GetOption(CONFIG_KEY_PowerButtonSize, CONFIG_DEFAULT_PowerButtonSize); + local powerButtonSize = tonumber(value); + if not powerButtonSize or powerButtonSize < 1 or powerButtonSize > 15 then + powerButtonSize = CONFIG_DEFAULT_PowerButtonSize; end; - self:SetOption(CONFIG_KEY_PowerButtonVisible, A.configPowerButtonVisible); + self:UpdatePowerButtonSize(powerButtonSize + 1); + self:SetOption(CONFIG_KEY_PowerButtonSize, powerButtonSize); end; function A:HandleTXVersion(message, sender) @@ -248,24 +301,82 @@ function A:HandleRXVersion(message, sender) self:echo(string.format("[%s] is using NRG version %s", sender, message)) end; - function A:OnTimer(elapsed) self.timerTick = self.timerTick + elapsed + if A.enabledForPlayer then + A:CheckManaUpdates(); + end; + if self.timerTick > (self.nextPowerStep + self.powerFrequency) then self:AdvancePower(); self.nextPowerStep = self.timerTick; end; end; +function A:IsEligibleForReset(unitid, spellID) + if unitid ~= "player" then return false; end; + + return true; +end; + +A.lastManaValue = -1; +A.lastManaAlphaValue = 0.00; +A.manaAlphaValueDecay = 0.5 / GetFramerate(); +function A:CheckManaUpdates() + if disableUpdates then + return; + end; + + local mana = UnitPower("player", 0); + + if mana > self.lastManaValue and self.lastManaValue >= 0 then + NRGPowerButtonValue:SetText(mana - self.lastManaValue); + self.lastManaAlphaValue = 1.00; + NRGPowerButtonValue:SetAlpha(self.lastManaAlphaValue); + else + if self.lastManaAlphaValue > 0 then + self.lastManaAlphaValue = self.lastManaAlphaValue - self.manaAlphaValueDecay; + if self.lastManaAlphaValue < 0 then + self.lastManaAlphaValue = 0; + end; + NRGPowerButtonValue:SetAlpha(self.lastManaAlphaValue); + end; + end; + + self.lastManaValue = mana; +end; + + +local NRG_ValidSubEvents = { + ["SPELL_AURA_APPLIED"] = true, + ["SPELL_HEAL"] = true, + ["SPELL_DAMAGE"] = true, +} + function A:OnEvent(object, event, ...) - if event == "UNIT_SPELLCAST_SUCCEEDED" then - self:ResetPower(); - --elseif event == "UNIT_SPELLCAST_SENT" then - --elseif event == "UNIT_SPELLCAST_START" then - --elseif event == "UNIT_SPELLCAST_STOP" then - --elseif event == "UNIT_SPELLCAST_FAILED" then + if event == "ADDON_LOADED" then + local addonname = ...; + if addonname == self.addonShortName then + self:PostInitialization(); + end + + elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then + local _, subevent, _, sourceGUID, sourceName = CombatLogGetCurrentEventInfo(); + + -- Only spells I did please + if sourceGUID == self.localPlayerGUID then + -- Filter out unwanted heal/damage sub events. + -- TODO: Do we need Dispell actions too? + if NRG_ValidSubEvents[subevent] then + -- Only react on magic stuff: + local spellId, _, spellSchool = select(12, CombatLogGetCurrentEventInfo()); + if spellSchool and bit.band(spellSchool, 0x07e) > 0 then + self:ResetPower(); + end; + end; + end; elseif event == "CHAT_MSG_ADDON" then local prefix, msg, channel, sender = ...; @@ -274,7 +385,6 @@ function A:OnEvent(object, event, ...) return; end; - -- Note: sender+recipient contains both name+realm of who sended message. local _, _, cmd, message, recipient = string.find(msg, "([^#]*)#([^#]*)#([^#]*)"); if not (recipient == "") then @@ -295,16 +405,15 @@ function A:OnLoad() self.currentVersion = self:calculateVersion(A.addonVersion); self:echo(string.format("Type %s/nrg%s to configure the addon, or right-click the NRG power button.", self.chatColorHot, self.chatColorNormal)); + CombatTextSetActiveUnit("player"); + + NRGEventFrame:RegisterEvent("ADDON_LOADED"); NRGEventFrame:RegisterEvent("CHAT_MSG_ADDON"); - --NRGEventFrame:RegisterEvent("UNIT_SPELLCAST_SENT"); - --NRGEventFrame:RegisterEvent("UNIT_SPELLCAST_START"); - --NRGEventFrame:RegisterEvent("UNIT_SPELLCAST_STOP"); - --NRGEventFrame:RegisterEvent("UNIT_SPELLCAST_FAILED"); - NRGEventFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED"); + NRGEventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED"); C_ChatInfo.RegisterAddonMessagePrefix(self.addonPrefix); - self:MainInitialization(); + self:PreInitialization(); end @@ -316,8 +425,8 @@ function NRG_OnTimer(elapsed) A:OnTimer(elapsed); end; -function NRG_OnEvent(self, event, ...) - A:OnEvent(self, event, ...); +function NRG_OnEvent(object, event, ...) + A:OnEvent(object, event, ...); end; function NRG_RepositionateButton(sender) diff --git a/nrg/Battery.xml b/nrg/Battery.xml index 1cf1f6c..3614848 100644 --- a/nrg/Battery.xml +++ b/nrg/Battery.xml @@ -12,6 +12,24 @@ + + + + + + + + + + + + + + + + + + self:EnableMouse(true); diff --git a/nrg/DigamAddonLib.lua b/nrg/DigamAddonLib.lua index 29e5db1..ed82fd3 100644 --- a/nrg/DigamAddonLib.lua +++ b/nrg/DigamAddonLib.lua @@ -69,6 +69,7 @@ function DigamAddonLib:new(addonSettings) localPlayerName = self:getPlayerAndRealm("player", true), localPlayerClass = self:getUnitClass("player"), localPlayerRealm = self:getPlayerRealm("player"), + localPlayerGUID = UnitGUID("player"), chatColorNormal = DIGAM_COLOR_BEGIN .. (addonSettings["NORMALCHATCOLOR"] or DIGAM_DEFAULT_ColorNormal), chatColorHot = DIGAM_COLOR_BEGIN..(addonSettings["HOTCHATCOLOR"] or DIGAM_DEFAULT_ColorHot), diff --git a/nrg/ReadMe.txt b/nrg/ReadMe.txt index c32a914..1ef51e1 100644 --- a/nrg/ReadMe.txt +++ b/nrg/ReadMe.txt @@ -3,10 +3,20 @@ NRG --- Very simple addon which displays a battery pack (the power button), which starts counting when mp5 is on cooldown. -No config, no switches, no nothing. Well almost: you can move the power button byt shift+drag. +No config, no switches, no nothing. Well almost: you can move the power button by shift+drag. Version history: ---------------- -1.0.0: Initial version. +NRG version 1.1.0 +* Filtering events, so only magic events are now considered. + Still not perfect but far better than before: dismounting does no longer trigger mp5 cooldown for example! +* Added a new switch: /nrg size where N can be in a range from 1 to 15. The power button will resize accordingly. + The default size is 3. +* Added a text on the power button when mana increases. + The tick show any increment in mana from mp5, spirit, innervate, potions ... + + +NRG version 1.0.0 +* Initial version. diff --git a/nrg/nrg-Classic.toc b/nrg/nrg-Classic.toc index a28d2dd..4cfec2e 100644 --- a/nrg/nrg-Classic.toc +++ b/nrg/nrg-Classic.toc @@ -1,6 +1,6 @@ -## Title: NRG - 5 second rule +## Title: NRG - mp5 Power Button ## Notes: Addon to check mp5 rule -## Version: 1.0.0 +## Version: 1.1.0 ## Author: Mimma @ ## Interface: 11403 ## SavedVariables: NRG_Options diff --git a/nrg/nrg-TBC.toc b/nrg/nrg-TBC.toc index 72509e3..0161321 100644 --- a/nrg/nrg-TBC.toc +++ b/nrg/nrg-TBC.toc @@ -1,6 +1,6 @@ -## Title: NRG - 5 second rule +## Title: NRG - mp5 Power Button ## Notes: Addon to check mp5 rule -## Version: 1.0.0 +## Version: 1.1.0 ## Author: Mimma @ ## Interface: 20504 ## SavedVariables: NRG_Options diff --git a/nrg/nrg.toc b/nrg/nrg.toc index 87321db..8492304 100644 --- a/nrg/nrg.toc +++ b/nrg/nrg.toc @@ -1,6 +1,6 @@ -## Title: NRG - 5 second rule -## Notes: Addon to check mp5 rule -## Version: 1.0.0 +## Title: NRG - mp5 Power Button +## Notes: Addon to check mp5 rule (yeah, I know .. irrelevant for retail, but anyway) +## Version: 1.1.0 ## Author: Mimma @ ## Interface: 90205 ## SavedVariables: NRG_Options