diff --git a/IceHUD.toc b/IceHUD.toc index 40256a8..84954e7 100644 --- a/IceHUD.toc +++ b/IceHUD.toc @@ -100,6 +100,7 @@ modules\PlayerAltMana.lua modules\ArcaneCharges.lua modules\RollTheBones.lua modules\EssencePower.lua +modules\DruidEnergy.lua #@do-not-package@ IceHUD_Options\Json.lua diff --git a/changelog.md b/changelog.md index 07e57cc..741c72f 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ v1.14.6: - Add ability for buff/debuff watchers to only display when the specified buff/debuff is missing. This also adds the ability to require that the given unit exists. So if you had Unit set to Target, Display mode set to Missing, and Only if unit exists checked, you'd show the bar if you have a target and they don't have the given buff/debuff. - Don't flash the castbar for instant-cast spells that the player didn't cast (such as internal quest spells). +- Add DruidEnergy module (disabled by default). This module will show the player's Energy level if they're a Druid and currently shapeshifted to a non-energy-using form (eligible forms are configurable by the user). v1.14.5: diff --git a/modules/DruidEnergy.lua b/modules/DruidEnergy.lua new file mode 100644 index 0000000..d23f65d --- /dev/null +++ b/modules/DruidEnergy.lua @@ -0,0 +1,123 @@ +local L = LibStub("AceLocale-3.0"):GetLocale("IceHUD", false) +local DruidEnergy = IceCore_CreateClass(IceUnitBar) + +DruidEnergy.prototype.DruidEnergy = nil +DruidEnergy.prototype.DruidEnergyMax = nil + +local _, unitClass = UnitClass("player") + +local FORM_NONE = 0 +local FORM_BEAR = 1 +local FORM_TRAVEL = 3 + +local SPELL_POWER_ENERGY = SPELL_POWER_ENERGY +if Enum and Enum.PowerType then + SPELL_POWER_ENERGY = Enum.PowerType.Energy +end + +local shapeshiftFormValues = {NONE = L["No form"], BEAR = L["Bear"], TRAVEL = L["Travel"], OTHER = L["Other"]} +local shapeshiftFormIds = {NONE = FORM_NONE, BEAR = FORM_BEAR, TRAVEL = FORM_TRAVEL} + +function DruidEnergy.prototype:init() + DruidEnergy.super.prototype.init(self, "DruidEnergy", "player") + + self.side = IceCore.Side.Left + self.offset = 5 + + self:SetDefaultColor("DruidEnergy", 218, 231, 31) +end + +function DruidEnergy.prototype:GetDefaultSettings() + local settings = DruidEnergy.super.prototype.GetDefaultSettings(self) + + settings["side"] = IceCore.Side.Left + settings["offset"] = 5 + settings["textVisible"] = {upper = true, lower = false} + settings["upperText"] = "[PercentMP(type='Energy'):Round]" + settings["lowerText"] = "[FractionalMP(type='Energy'):Color('dae71f'):Bracket]" + settings.enabled = false + settings.whileInForm = {["BEAR"] = true} + + return settings +end + +function DruidEnergy.prototype:GetOptions() + local opts = DruidEnergy.super.prototype.GetOptions(self) + + opts["whileInForm"] = { + type = 'multiselect', + values = shapeshiftFormValues, + name = L["Show in form"], + desc = L["When the player is in one of the chosen shapeshift forms the bar will be shown, otherwise it will be hidden."], + get = function(info, v) + for key, value in pairs(self.moduleSettings.whileInForm) do + if key == v then + return value + end + end + + return false + end, + set = function(info, v, state) + self.moduleSettings.whileInForm[v] = state + self:Update() + end, + disabled = function() + return not self.moduleSettings.enabled + end, + } + + return opts +end + +function DruidEnergy.prototype:Enable(core) + DruidEnergy.super.prototype.Enable(self, core) + + self:RegisterEvent("UPDATE_SHAPESHIFT_FORM", "Update") + self:RegisterEvent("UNIT_POWER_FREQUENT", "Update") + self:RegisterEvent("UNIT_MAXPOWER", "Update") +end + +function DruidEnergy.prototype:GetElementDescription() + return L["Always shows the Druid's Energy level while in non-energy-using forms."] +end + + +function DruidEnergy.prototype:ShouldShow(unit) + local currentForm = GetShapeshiftForm() + for k, v in pairs(self.moduleSettings.whileInForm) do + if currentForm > FORM_TRAVEL and k == "OTHER" then + return v + elseif currentForm == shapeshiftFormIds[k] then + return v + end + end + + return false +end + +function DruidEnergy.prototype:Update() + DruidEnergy.super.prototype.Update(self) + + self.DruidEnergy = UnitPower(self.unit, SPELL_POWER_ENERGY) + self.DruidEnergyMax = UnitPowerMax(self.unit, SPELL_POWER_ENERGY) + self.DruidEnergyPercentage = self.DruidEnergyMax ~= 0 and (self.DruidEnergy/self.DruidEnergyMax) or 0 + + if (not self.alive or not self:ShouldShow(self.unit) or not self.DruidEnergy or not self.DruidEnergyMax or self.DruidEnergyMax == 0) then + self:Show(false) + return + else + self:Show(true) + end + + if not IceHUD.IceCore:ShouldUseDogTags() and self.frame:IsVisible() then + self:SetBottomText1(math.floor(self.DruidEnergyPercentage * 100)) + self:SetBottomText2(self:GetFormattedText(self:Round(self.DruidEnergy), self:Round(self.DruidEnergyMax)), "DruidEnergy") + end + + self:UpdateBar(self.DruidEnergyMax ~= 0 and self.DruidEnergy / self.DruidEnergyMax or 0, "DruidEnergy") +end + +if unitClass == "DRUID" then + IceHUD.DruidEnergy = DruidEnergy:new() +end diff --git a/this_version.md b/this_version.md index 54fdd8a..314a925 100644 --- a/this_version.md +++ b/this_version.md @@ -4,6 +4,7 @@ v1.14.6: - Add ability for buff/debuff watchers to only display when the specified buff/debuff is missing. This also adds the ability to require that the given unit exists. So if you had Unit set to Target, Display mode set to Missing, and Only if unit exists checked, you'd show the bar if you have a target and they don't have the given buff/debuff. - Don't flash the castbar for instant-cast spells that the player didn't cast (such as internal quest spells). +- Add DruidEnergy module (disabled by default). This module will show the player's Energy level if they're a Druid and currently shapeshifted to a non-energy-using form (eligible forms are configurable by the user). v1.14.5: