Skip to content

Commit

Permalink
Totem timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviana committed Sep 13, 2022
1 parent a5d55c5 commit 8dc6ae6
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 18 deletions.
4 changes: 3 additions & 1 deletion LunaUnitFrames.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Luna Unit Frames 4.0 by Aviana

LUF = select(2, ...)
LUF.version = 4334
LUF.version = 4335

local L = LUF.L
local ACR = LibStub("AceConfigRegistry-3.0", true)
Expand Down Expand Up @@ -661,6 +661,7 @@ local moduleSettings = {
[3] = {0,0,1},
[4] = {0.41,0.8,0.94},
}
mod.Totems.disableTimer = not config.timer
for i=1, 4 do
local totem = mod.Totems[i]
totem:SetStatusBarTexture(texture)
Expand All @@ -673,6 +674,7 @@ local moduleSettings = {
else
totem.bg:Hide()
end
totem.timer:SetFont(LUF:LoadMedia(SML.MediaType.FONT, config.font), config.fontsize)
end
mod.autoHide = config.autoHide
mod:Update()
Expand Down
3 changes: 1 addition & 2 deletions LunaUnitFrames.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: Luna Unit Frames
## Notes:
## Author: Aviana
## Version: 4334
## Version: 4335
## SavedVariables: LunaUFDB
## OptionalDeps: Ace3, LibSharedMedia-3.0, AceGUI-3.0-SharedMediaWidgets, Clique
## X-License: WTFPL (http://www.wtfpl.net/about/)
Expand Down Expand Up @@ -44,7 +44,6 @@ libs\oUF\elements\raidtargetindicator.lua
libs\oUF\elements\range.lua
libs\oUF\elements\readycheckindicator.lua
libs\oUF\elements\resurrectindicator.lua
libs\oUF\elements\totems.lua

libs\oUF_Plugins\oUF_Plugins.xml

Expand Down
1 change: 1 addition & 0 deletions libs/oUF_Plugins/oUF_Plugins.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="oUF_Power\oUF_Power.lua"/>
<Script file="oUF_Totems\oUF_Totems.lua"/>
<Script file="oUF_Runes\oUF_Runes.lua"/>
<Script file="oUF_ClassIndicator\oUF_ClassIndicator.lua"/>
<Script file="oUF_EliteIndicator\oUF_EliteIndicator.lua"/>
Expand Down
227 changes: 227 additions & 0 deletions libs/oUF_Plugins/oUF_Totems/oUF_Totems.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
--[[
# Element: Totem Indicator
Handles the updating and visibility of totems.
## Widget
Totems - A `table` to hold sub-widgets.
## Sub-Widgets
Totem - Any UI widget.
## Sub-Widget Options
.Icon - A `Texture` representing the totem icon.
.Cooldown - A `Cooldown` representing the duration of the totem.
## Notes
OnEnter and OnLeave script handlers will be set to display a Tooltip if the `Totem` widget is mouse enabled.
## Examples
local Totems = {}
for index = 1, 5 do
-- Position and size of the totem indicator
local Totem = CreateFrame('Button', nil, self)
Totem:SetSize(40, 40)
Totem:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * Totem:GetWidth(), 0)
local Icon = Totem:CreateTexture(nil, 'OVERLAY')
Icon:SetAllPoints()
local Cooldown = CreateFrame('Cooldown', nil, Totem, 'CooldownFrameTemplate')
Cooldown:SetAllPoints()
Totem.Icon = Icon
Totem.Cooldown = Cooldown
Totems[index] = Totem
end
-- Register with oUF
self.Totems = Totems
--]]

if(select(2, UnitClass('player')) ~= 'SHAMAN') then return end

local _, ns = ...
local oUF = ns.oUF

local function UpdateTooltip(self)
GameTooltip:SetTotem(self:GetID())
end

local function OnEnter(self)
if(not self:IsVisible()) then return end

GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
self:UpdateTooltip()
end

local function OnLeave()
GameTooltip:Hide()
end

local function UpdateTotem(self, event, slot)
local element = self.Totems
if(slot > #element) then return end

--[[ Callback: Totems:PreTotemUpdate(slot)
Called before the element has been updated.
* self - the Totems element
* slot - the slot of the totem to be updated (number)
--]]
if(element.PreTotemUpdate) then element:PreTotemUpdate(slot) end

local totem = element[slot]
local haveTotem, name, start, duration, icon = GetTotemInfo(slot)
if(haveTotem and duration > 0) then
if(totem.Icon) then
totem.Icon:SetTexture(icon)
end

if(totem.Cooldown) then
totem.Cooldown:SetCooldown(start, duration)
end

if totem:IsObjectType("Statusbar") then
totem:SetValue(0)
if totem.timer then
totem.timer:SetText("")
end
totem:SetScript("OnUpdate",function(self,elapsed)
self.total = (self.total or 0) + elapsed
if (self.total >= .01) then
self.total = 0
local _, _, startTime, duration = GetTotemInfo(slot)
if (startTime == 0) then
self:SetValue(0)
self.timer:SetText("")
self:SetScript("OnUpdate", nil)
elseif duration and duration > 0 then
self:SetValue(1 - ((GetTime() - startTime) / duration))
if totem.timer and not element.disableTimer then
self.timer:SetText(max(0,ceil(duration + startTime - GetTime())))
end
end
end
end)
end
end

--[[ Callback: Totems:PostTotemUpdate(slot, haveTotem, name, start, duration, icon)
Called after the element has been updated.
* self - the Totems element
* slot - the slot of the updated totem (number)
* haveTotem - indicates if a totem is present in the given slot (boolean)
* name - the name of the totem (string)
* start - the value of `GetTime()` when the totem was created (number)
* duration - the total duration for which the totem should last (number)
* icon - the totem's icon (Texture)
--]]
if(element.PostTotemUpdate) then
return element:PostTotemUpdate(slot, haveTotem, name, start, duration, icon)
end
end

local function Update(self, event)
local element = self.Totems

--[[ Callback: Totems:PreUpdate(slot)
Called before the element has been updated.
* self - the Totems element
* slot - the slot of the totem to be updated (number)
--]]
if(element.PreUpdate) then element:PreUpdate(slot) end

for i=1, 4 do
UpdateTotem(self, event, i)
end

--[[ Callback: Totems:PostUpdate(slot, haveTotem, name, start, duration, icon)
Called after the element has been updated.
* self - the Totems element
* slot - the slot of the updated totem (number)
* haveTotem - indicates if a totem is present in the given slot (boolean)
* name - the name of the totem (string)
* start - the value of `GetTime()` when the totem was created (number)
* duration - the total duration for which the totem should last (number)
* icon - the totem's icon (Texture)
--]]
if(element.PostUpdate) then
return element:PostUpdate(slot, haveTotem, name, start, duration, icon)
end
end

local function Path(self, ...)
--[[ Override: Totem.Override(self, event, ...)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* ... - the arguments accompanying the event
--]]
return (self.Totems.Override or Update) (self, ...)
end

local function Update(self, event)
for i = 1, #self.Totems do
Path(self, event, i)
end
end

local function ForceUpdate(element)
return Update(element.__owner, 'ForceUpdate')
end

local function Enable(self)
local element = self.Totems
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate

for i = 1, #element do
local totem = element[i]

totem:SetID(i)

if(totem:IsMouseEnabled()) then
totem:SetScript('OnEnter', OnEnter)
totem:SetScript('OnLeave', OnLeave)

--[[ Override: Totems[slot]:UpdateTooltip()
Used to populate the tooltip when the totem is hovered.
* self - the widget at the given slot index
--]]
if(not totem.UpdateTooltip) then
totem.UpdateTooltip = UpdateTooltip
end
end
end

self:RegisterEvent('PLAYER_TOTEM_UPDATE', UpdateTotem, true)

return true
end
end

local function Disable(self)
local element = self.Totems
if(element) then
for i = 1, #element do
element[i]:Hide()
end

self:UnregisterEvent('PLAYER_TOTEM_UPDATE', UpdateTotem)
end
end

oUF:AddElement('Totems', Update, Enable, Disable)
47 changes: 35 additions & 12 deletions modules/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4032,17 +4032,40 @@ function LUF:CreateConfig()
type = "toggle",
order = 2,
},
timer = {
name = L["Timer"],
desc = string.format(L["Enable or disable the %s."],L["Timer"]),
type = "toggle",
order = 3,
},
font = {
order = 4,
type = "select",
name = L["Font"],
dialogControl = "LSM30_Font",
values = getMediaData,
get = function(info) return get(info) or LUF.db.profile.font or SML.DefaultMedia.font end,
},
fontsize = {
name = FONT_SIZE,
desc = L["Set the font size."],
type = "range",
order = 5,
min = 5,
max = 24,
step = 1,
},
background = {
name = BACKGROUND,
desc = string.format(L["Enable or disable the %s."], BACKGROUND),
type = "toggle",
order = 3,
order = 6,
},
backgroundAlpha = {
name = L["Background alpha"],
desc = L["Set the background alpha."],
type = "range",
order = 4,
order = 7,
min = 0,
max = 1,
step = 0.01,
Expand All @@ -4051,7 +4074,7 @@ function LUF:CreateConfig()
name = L["Height"],
desc = L["Set the height."],
type = "range",
order = 5,
order = 8,
min = 1,
max = 10,
step = 0.1,
Expand All @@ -4060,13 +4083,13 @@ function LUF:CreateConfig()
name = L["Order"],
desc = L["Set the order priority."],
type = "range",
order = 6,
order = 9,
min = 0,
max = 100,
step = 5,
},
statusbar = {
order = 7,
order = 10,
type = "select",
name = L["Bar texture"],
dialogControl = "LSM30_Statusbar",
Expand All @@ -4077,7 +4100,7 @@ function LUF:CreateConfig()
name = L["Bar Group"],
desc = L["Select the bar stack"],
type = "select",
order = 8,
order = 11,
values = {["LEFT"] = L["Left Group"], ["RIGHT"] = L["Right Group"], ["CENTER"] = L["Center Group"]},
},
},
Expand Down Expand Up @@ -4170,16 +4193,16 @@ function LUF:CreateConfig()
type = "toggle",
order = 2,
},
timer = {
name = L["Timer"],
desc = string.format(L["Enable or disable the %s."],L["Timer"]),
type = "toggle",
order = 3,
},
grace = {
name = L["Rune Grace"],
desc = L["Highlights a rune while it does not have to be used yet to maximize efficiency"],
type = "toggle",
order = 3,
},
timer = {
name = L["Timer"],
desc = string.format(L["Enable or disable the %s."],L["Timer"]),
type = "toggle",
order = 4,
},
font = {
Expand Down
2 changes: 1 addition & 1 deletion modules/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function LUF:LoadDefaults()
xpBar = { enabled = false, height = 2, order = 90, background = false, backgroundAlpha = 0.2, alpha = 1, autoHide = true, posSlot = "CENTER" },
emptyBar = { enabled = false, height = 3, order = 50, reactionType="npc", class = true, alpha = 0.2, posSlot = "CENTER"},
druidBar = {enabled = false, autoHide = true, order = 70, height = 3, background = true, backgroundAlpha = 0.2, posSlot = "CENTER" },
totemBar = {enabled = false, order = 70, height = 2, background = true, backgroundAlpha = 0.2, autoHide = true, posSlot = "CENTER"},
totemBar = {enabled = false, order = 70, height = 2, background = true, backgroundAlpha = 0.2, fontsize = 8, autoHide = true, posSlot = "CENTER"},
comboPoints = {enabled = false, background = true, backgroundAlpha = 0.2, autoHide = true, order = 70, growth = "RIGHT", height = 2, posSlot = "CENTER"},
ghoul = { enabled = false, background = true, backgroundAlpha = 0.2, height = 2, autoHide = true, order = 70, posSlot = "CENTER"},
runes = {enabled = true, background = true, backgroundAlpha = 0.2, fontsize = 8, order = 80, height = 2, posSlot = "CENTER"},
Expand Down
4 changes: 3 additions & 1 deletion modules/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ local UnitSpecific = {
frame.Totems[i] = CreateFrame("StatusBar", nil, totemBar)
frame.Totems[i]:SetMinMaxValues(0,1)
frame.Totems[i]:SetValue(0)
frame.Totems[i].timer = frame.Totems[i]:CreateFontString("LUFTotemCooldown"..i, "OVERLAY")
frame.Totems[i].timer:SetPoint("CENTER", frame.Totems[i], "CENTER")
frame.Totems[i].bg = frame.Totems[i]:CreateTexture(nil, "BACKGROUND")
frame.Totems[i].bg:SetAllPoints(frame.Totems[i])
end
frame.Totems.PostUpdate = LUF.overrides["Totems"].PostUpdate
frame.Totems.PostTotemUpdate = LUF.overrides["Totems"].PostTotemUpdate
totemBar.Totems = frame.Totems
totemBar.Update = LUF.overrides["Totems"].Update
frame.modules.totemBar = totemBar
Expand Down
Loading

0 comments on commit 8dc6ae6

Please sign in to comment.