From 081134979e844672615c2e246af8af30ec27669f Mon Sep 17 00:00:00 2001 From: shagu Date: Mon, 16 Mar 2020 17:02:26 +0100 Subject: [PATCH] energytick: add initial manatick support * add option to enable mana ticks * move into seperate module --- api/config.lua | 1 + init/modules.xml | 1 + modules/energytick.lua | 82 ++++++++++++++++++++++++++++++++++++++++++ modules/gui.lua | 1 + modules/player.lua | 59 ------------------------------ 5 files changed, 85 insertions(+), 59 deletions(-) create mode 100644 modules/energytick.lua diff --git a/api/config.lua b/api/config.lua index 41598b20..4f448e87 100644 --- a/api/config.lua +++ b/api/config.lua @@ -238,6 +238,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", "player", "showPVPMinimap", "0") pfUI:UpdateConfig("unitframes", "player", "showRest", "0") pfUI:UpdateConfig("unitframes", "player", "energy", "1") + pfUI:UpdateConfig("unitframes", "player", "manatick", "0") pfUI:UpdateConfig("unitframes", "focus", "width", "120") pfUI:UpdateConfig("unitframes", "focus", "height", "34") diff --git a/init/modules.xml b/init/modules.xml index 0be5b56b..b13cf49c 100644 --- a/init/modules.xml +++ b/init/modules.xml @@ -65,4 +65,5 @@ + diff --git a/modules/energytick.lua b/modules/energytick.lua new file mode 100644 index 00000000..8e966afc --- /dev/null +++ b/modules/energytick.lua @@ -0,0 +1,82 @@ +pfUI:RegisterModule("energytick", "vanilla:tbc", function () + if not pfUI.uf or not pfUI.uf.player then return end + + local energytick = CreateFrame("Frame", nil, pfUI.uf.player.power.bar) + energytick:SetAllPoints(pfUI.uf.player.power.bar) + energytick:RegisterEvent("PLAYER_ENTERING_WORLD") + energytick:RegisterEvent("UNIT_DISPLAYPOWER") + energytick:RegisterEvent("UNIT_ENERGY") + energytick:RegisterEvent("UNIT_MANA") + energytick:SetScript("OnEvent", function() + if UnitPowerType("player") == 0 and C.unitframes.player.manatick == "1" then + this.mode = "MANA" + this:Show() + elseif UnitPowerType("player") == 3 and C.unitframes.player.energy == "1" then + this.mode = "ENERGY" + this:Show() + else + this:Hide() + end + + if event == "PLAYER_ENTERING_WORLD" then + this.lastMana = UnitMana("player") + end + + if (event == "UNIT_MANA" or event == "UNIT_ENERGY") and arg1 == "player" then + this.currentMana = UnitMana("player") + local diff = 0 + if this.lastMana then + diff = this.currentMana - this.lastMana + end + + if this.mode == "MANA" and diff < 0 then + this.target = 5 + elseif this.mode == "MANA" and diff > 0 then + if this.max ~= 5 and diff > (this.badtick and this.badtick*1.2 or 5) then + this.target = 2 + else + this.badtick = diff + end + elseif this.mode == "ENERGY" and diff > 0 then + this.target = 2 + end + this.lastMana = this.currentMana + end + end) + + energytick:SetScript("OnUpdate", function() + if this.target then + this.start, this.max = GetTime(), this.target + this.target = nil + end + + if not this.start then return end + + this.current = GetTime() - this.start + + if this.current > this.max then + this.start, this.max, this.current = GetTime(), 2, 0 + end + + local pos = (C.unitframes.player.pwidth ~= "-1" and C.unitframes.player.pwidth or C.unitframes.player.width) * (this.current / this.max) + if not C.unitframes.player.pheight then return end + this.spark:SetPoint("LEFT", pos-((C.unitframes.player.pheight+5)/2), 0) + end) + + energytick.spark = energytick:CreateTexture(nil, 'OVERLAY') + energytick.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark") + energytick.spark:SetHeight(C.unitframes.player.pheight + 15) + energytick.spark:SetWidth(C.unitframes.player.pheight + 5) + energytick.spark:SetBlendMode('ADD') + + -- update spark size on player frame changes + local hookUpdateConfig = pfUI.uf.player.UpdateConfig + function pfUI.uf.player.UpdateConfig() + -- update spark sizes + energytick.spark:SetHeight(C.unitframes.player.pheight + 15) + energytick.spark:SetWidth(C.unitframes.player.pheight + 5) + + -- run default unitframe update function + hookUpdateConfig(pfUI.uf.player) + end +end) diff --git a/modules/gui.lua b/modules/gui.lua index 47615b73..340c1bf5 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -1528,6 +1528,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function () CreateConfig(nil, T["Abbreviate Numbers (4200 -> 4.2k)"], C.unitframes, "abbrevnum", "checkbox") CreateConfig(nil, T["Show Resting"], C.unitframes.player, "showRest", "checkbox") CreateConfig(nil, T["Enable Energy Ticks"], C.unitframes.player, "energy", "checkbox") + CreateConfig(nil, T["Enable Mana Ticks"], C.unitframes.player, "manatick", "checkbox") CreateConfig(U[c], T["Group Options"], nil, nil, "header") CreateConfig(nil, T["Enable 40y-Range Check"], C.unitframes, "rangecheck", "checkbox", nil, nil, nil, nil, "vanilla" ) diff --git a/modules/player.lua b/modules/player.lua index eaf42b88..18b7eae7 100644 --- a/modules/player.lua +++ b/modules/player.lua @@ -25,63 +25,4 @@ pfUI:RegisterModule("player", "vanilla:tbc", function () StaticPopup_Show("CONFIRM_RESET_INSTANCES") end end) - - if C.unitframes.player.energy == "1" then - pfUI.uf.player.power.tick = CreateFrame("Frame", nil, pfUI.uf.player.power.bar) - pfUI.uf.player.power.tick:RegisterEvent("PLAYER_ENTERING_WORLD") - pfUI.uf.player.power.tick:RegisterEvent("UNIT_DISPLAYPOWER") - - pfUI.uf.player.power.tick:SetScript("OnShow", function() - this.spark:Show() - end) - - pfUI.uf.player.power.tick:SetScript("OnHide", function() - this.spark:Hide() - end) - - pfUI.uf.player.power.tick:SetScript("OnEvent", function() - if event == "PLAYER_ENTERING_WORLD" then this.lastTick = GetTime() end - if event == "PLAYER_ENTERING_WORLD" or ( event == "UNIT_DISPLAYPOWER" and arg1 == "player" ) then - if UnitPowerType("player") ~= 3 then - this:Hide() - else - this:Show() - end - end - end) - - pfUI.uf.player.power.tick.spark = pfUI.uf.player.power.bar:CreateTexture(nil, 'OVERLAY') - pfUI.uf.player.power.tick.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark") - pfUI.uf.player.power.tick.spark:SetHeight(C.unitframes.player.pheight + 15) - pfUI.uf.player.power.tick.spark:SetWidth(C.unitframes.player.pheight + 5) - pfUI.uf.player.power.tick.spark:SetBlendMode('ADD') - - -- update spark size on player frame changes - local hookUpdateConfig = pfUI.uf.player.UpdateConfig - function pfUI.uf.player.UpdateConfig() - -- update spark sizes - local spark = pfUI.uf.player.power.tick.spark - spark:SetHeight(C.unitframes.player.pheight + 15) - spark:SetWidth(C.unitframes.player.pheight + 5) - - -- run default unitframe update function - hookUpdateConfig(pfUI.uf.player) - end - - pfUI.uf.player.power.tick:SetScript("OnUpdate", function() - if UnitPowerType("player") ~= 3 then this:Hide() end - if not this.energy then this.energy = UnitMana("player") end - - if(UnitMana("player") > this.energy or GetTime() >= this.lastTick + 2) then - this.lastTick = GetTime() - end - - this.energy = UnitMana("player") - - local value = round((GetTime() - this.lastTick) * 100) - local pos = (C.unitframes.player.pwidth ~= "-1" and C.unitframes.player.pwidth or C.unitframes.player.width) / 200 * value - if not C.unitframes.player.pheight then return end - this.spark:SetPoint("LEFT", pos-((C.unitframes.player.pheight+5)/2), 0) - end) - end end)