Skip to content

Commit

Permalink
nrg 1.1.0: updated the event selection, small UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sentilix committed Jun 27, 2022
1 parent ed35bfe commit cd2e76f
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 44 deletions.
Binary file added Releases/nrg-1.1.0.zip
Binary file not shown.
179 changes: 144 additions & 35 deletions nrg/Battery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;


--
Expand All @@ -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
Expand Down Expand Up @@ -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 <size 1-15>
-- Alternative: /nrg size <size 1-15>
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
Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -196,35 +233,43 @@ 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

return 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();
Expand All @@ -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)
Expand All @@ -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 = ...;
Expand All @@ -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
Expand All @@ -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


Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions nrg/Battery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer>
<FontString name="$parentValue" justifyH="CENTER" font="Fonts\FRIZQT__.TTF" inherits="GameFontNormal" text="999">
<Size>
<AbsDimension x="64" y="32"/>
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<Color r="1.0" g="1.0" b="1.0" a="0.0" />
<FontHeight val="32" />
</FontString>
</Layer>
</Layers>
<Scripts>
<OnLoad>
self:EnableMouse(true);
Expand Down
1 change: 1 addition & 0 deletions nrg/DigamAddonLib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
14 changes: 12 additions & 2 deletions nrg/ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <N> 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.

4 changes: 2 additions & 2 deletions nrg/nrg-Classic.toc
Original file line number Diff line number Diff line change
@@ -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 @ <EU-Pyrewood Village>
## Interface: 11403
## SavedVariables: NRG_Options
Expand Down
4 changes: 2 additions & 2 deletions nrg/nrg-TBC.toc
Original file line number Diff line number Diff line change
@@ -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 @ <EU-Pyrewood Village>
## Interface: 20504
## SavedVariables: NRG_Options
Expand Down
Loading

0 comments on commit cd2e76f

Please sign in to comment.