Skip to content

Commit

Permalink
Fixed an issue with time types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Aug 13, 2023
1 parent 592b9a3 commit 4ae7c24
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 97 deletions.
7 changes: 4 additions & 3 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,20 @@ end
---return the role of the unit, this is safe to use for all versions of wow
---@param unitId string
---@param specId number
---@param bUseSupport boolean
---@return string
function DF.UnitGroupRolesAssigned(unitId, specId)
function DF.UnitGroupRolesAssigned(unitId, bUseSupport, specId)
if (not DF.IsTimewalkWoW()) then --Was function exist check. TBC has function, returns NONE. -Flamanis 5/16/2022
local role = UnitGroupRolesAssigned(unitId)

if (specId == 1473) then
if (specId == 1473 and bUseSupport) then
return "SUPPORT"
end

if (role == "NONE" and UnitIsUnit(unitId, "player")) then
local specializationIndex = GetSpecialization() or 0
local id, name, description, icon, role, primaryStat = GetSpecializationInfo(specializationIndex)
if (id == 1473) then
if (id == 1473 and bUseSupport) then
return "SUPPORT"
end
return id and role or "NONE"
Expand Down
215 changes: 132 additions & 83 deletions Libs/DF/unitframe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ local cleanfunction = function() end
self.currentHealthMax = UnitHealthMax(unit) or 0

for _, eventTable in ipairs(self.HealthBarEvents) do
local event = eventTable [1]
local isUnitEvent = eventTable [2]
local event = eventTable[1]
local isUnitEvent = eventTable[2]
if event then
if (isUnitEvent) then
self:RegisterUnitEvent (event, self.displayedUnit, self.unit)
self:RegisterUnitEvent(event, self.displayedUnit, self.unit)
else
self:RegisterEvent(event)
end
Expand All @@ -188,16 +188,16 @@ local cleanfunction = function() end

--check for settings and update some events
if (not self.Settings.ShowHealingPrediction) then
self:UnregisterEvent ("UNIT_HEAL_PREDICTION")
self:UnregisterEvent("UNIT_HEAL_PREDICTION")
if IS_WOW_PROJECT_MAINLINE then
self:UnregisterEvent ("UNIT_HEAL_ABSORB_AMOUNT_CHANGED")
self:UnregisterEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED")
end
self.incomingHealIndicator:Hide()
self.healAbsorbIndicator:Hide()
end
if (not self.Settings.ShowShields) then
if IS_WOW_PROJECT_MAINLINE then
self:UnregisterEvent ("UNIT_ABSORB_AMOUNT_CHANGED")
self:UnregisterEvent("UNIT_ABSORB_AMOUNT_CHANGED")
end
self.shieldAbsorbIndicator:Hide()
self.shieldAbsorbGlow:Hide()
Expand All @@ -210,7 +210,7 @@ local cleanfunction = function() end
self:SetScript("OnUpdate", self.OnTick)
end

self:PLAYER_ENTERING_WORLD (self.unit, self.displayedUnit)
self:PLAYER_ENTERING_WORLD(self.unit, self.displayedUnit)
else
--remove all registered events
for _, eventTable in ipairs(self.HealthBarEvents) do
Expand All @@ -229,7 +229,7 @@ local cleanfunction = function() end
end

healthBarMetaFunctions.Initialize = function(self)
PixelUtil.SetWidth (self, self.Settings.Width, 1)
PixelUtil.SetWidth(self, self.Settings.Width, 1)
PixelUtil.SetHeight(self, self.Settings.Height, 1)

self:SetTexture(self.Settings.Texture)
Expand Down Expand Up @@ -400,6 +400,12 @@ local cleanfunction = function() end
end

-- ~healthbar

---comment
---@param parent frame
---@param name string?
---@param settingsOverride table? a table with key/value pairs to override the default settings
---@return df_healthbar
function detailsFramework:CreateHealthBar(parent, name, settingsOverride)
assert(name or parent:GetName(), "DetailsFramework:CreateHealthBar parameter 'name' omitted and parent has no name.")

Expand Down Expand Up @@ -461,6 +467,28 @@ end
@settingsOverride = table with keys and values to replace the defaults from the framework
--]=]

---@class df_powerbarsettings : table
---@field ShowAlternatePower boolean
---@field ShowPercentText boolean
---@field HideIfNoPower boolean
---@field CanTick boolean
---@field BackgroundColor table
---@field Texture texturepath|textureid|atlasname
---@field Width number
---@field Height number

---@class df_powerbar : statusbar, df_scripthookmixin, df_statusbarmixin
---@field unit string
---@field displayedUnit string
---@field WidgetType string
---@field currentPower number
---@field currentPowerMax number
---@field powerType number
---@field minPower number
---@field Settings df_powerbarsettings
---@field background texture
---@field percentText fontstring

detailsFramework.PowerFrameFunctions = {
WidgetType = "powerBar",

Expand Down Expand Up @@ -504,11 +532,11 @@ detailsFramework.PowerFrameFunctions = {
--register events
if (unit) then
for _, eventTable in ipairs(self.PowerBarEvents) do
local event = eventTable [1]
local isUnitEvent = eventTable [2]
local event = eventTable[1]
local isUnitEvent = eventTable[2]

if (isUnitEvent) then
self:RegisterUnitEvent (event, self.displayedUnit)
self:RegisterUnitEvent(event, self.displayedUnit)
else
self:RegisterEvent(event)
end
Expand All @@ -526,8 +554,8 @@ detailsFramework.PowerFrameFunctions = {
else
--remove all registered events
for _, eventTable in ipairs(self.PowerBarEvents) do
local event = eventTable [1]
self:UnregisterEvent (event)
local event = eventTable[1]
self:UnregisterEvent(event)
end

--remove scripts
Expand All @@ -553,7 +581,7 @@ detailsFramework.PowerFrameFunctions = {

detailsFramework:SetFontSize(self.percentText, 9)
detailsFramework:SetFontColor(self.percentText, "white")
detailsFramework:SetFontOutline (self.percentText, "OUTLINE")
detailsFramework:SetFontOutline(self.percentText, "OUTLINE")
else
self.percentText:Hide()
end
Expand All @@ -566,10 +594,10 @@ detailsFramework.PowerFrameFunctions = {

--when an event happen for this unit, send it to the apropriate function
OnEvent = function(self, event, ...)
local eventFunc = self [event]
local eventFunc = self[event]
if (eventFunc) then
--the function doesn't receive which event was, only 'self' and the parameters
eventFunc (self, ...)
eventFunc(self, ...)
end
end,

Expand Down Expand Up @@ -629,20 +657,20 @@ detailsFramework.PowerFrameFunctions = {
return
end

local powerColor = PowerBarColor [self.powerType] --don't appear to be, but PowerBarColor is a global table with all power colors /run Details:Dump (PowerBarColor)
local powerColor = PowerBarColor[self.powerType] --don't appear to be, but PowerBarColor is a global table with all power colors /run Details:Dump (PowerBarColor)
if (powerColor) then
self:SetStatusBarColor(powerColor.r, powerColor.g, powerColor.b)
return
end

local _, _, r, g, b = UnitPowerType (self.displayedUnit)
local _, _, r, g, b = UnitPowerType(self.displayedUnit)
if (r) then
self:SetStatusBarColor(r, g, b)
return
end

--if everything else fails, tint as rogue energy
powerColor = PowerBarColor ["ENERGY"]
powerColor = PowerBarColor["ENERGY"]
self:SetStatusBarColor(powerColor.r, powerColor.g, powerColor.b)
end,

Expand Down Expand Up @@ -675,6 +703,12 @@ detailsFramework.PowerFrameFunctions = {
detailsFramework:Mixin(detailsFramework.PowerFrameFunctions, detailsFramework.ScriptHookMixin)

-- ~powerbar

---create a power bar
---@param parent frame
---@param name string?
---@param settingsOverride table? a table with key/value pairs to override the default settings
---@return df_powerbar
function detailsFramework:CreatePowerBar(parent, name, settingsOverride)
assert(name or parent:GetName(), "DetailsFramework:CreatePowerBar parameter 'name' omitted and parent has no name.")

Expand Down Expand Up @@ -757,6 +791,65 @@ end
---@field SparkHeight number
---@field SparkOffset number

---@alias caststage_color
---| "Casting"
---| "Channeling"
---| "Interrupted"
---| "Failed"
---| "NotInterruptable"
---| "Finished"

---@class df_castcolors : table
---@field Casting table
---@field Channeling table
---@field Interrupted table
---@field Failed table
---@field NotInterruptable table
---@field Finished table

---@class df_castbar : statusbar, df_scripthookmixin, df_statusbarmixin
---@field unit string
---@field displayedUnit string
---@field WidgetType string
---@field value number
---@field maxValue number
---@field spellStartTime number
---@field spellEndTime number
---@field empowered boolean
---@field curStage number
---@field numStages number
---@field empStages {start:number, finish:number}[]
---@field stagePips texture[]
---@field holdAtMaxTime number
---@field casting boolean
---@field channeling boolean
---@field interrupted boolean
---@field failed boolean
---@field finished boolean
---@field canInterrupt boolean
---@field spellID spellid
---@field castID number
---@field spellName spellname
---@field spellTexture textureid
---@field Colors df_castcolors
---@field Settings df_castbarsettings
---@field background texture
---@field extraBackground texture
---@field Text fontstring
---@field BorderShield texture
---@field Icon texture
---@field Spark texture
---@field percentText fontstring
---@field barTexture texture
---@field flashTexture texture
---@field fadeOutAnimation animationgroup
---@field fadeInAnimation animationgroup
---@field flashAnimation animationgroup
---@field SetUnit fun(self:df_castbar, unit:string)
---@field SetDefaultColor fun(self:df_castbar, colorType: caststage_color, red:any, green:number?, blue:number?, alpha:number?)
---@field UpdateCastColor fun(self:df_castbar) after setting a new color, call this function to update the bar color (while casting or channeling)
---@field GetCastColor fun(self:df_castbar) return a table with the color values for the current state of the casting process

detailsFramework.CastFrameFunctions = {
WidgetType = "castBar",

Expand Down Expand Up @@ -1729,66 +1822,13 @@ detailsFramework.CastFrameFunctions = {

detailsFramework:Mixin(detailsFramework.CastFrameFunctions, detailsFramework.ScriptHookMixin)

---@alias caststage_color
---| "Casting"
---| "Channeling"
---| "Interrupted"
---| "Failed"
---| "NotInterruptable"
---| "Finished"

---@class df_castcolors : table
---@field Casting table
---@field Channeling table
---@field Interrupted table
---@field Failed table
---@field NotInterruptable table
---@field Finished table

---@class df_castbar : statusbar, df_scripthookmixin, df_statusbarmixin, df_castbarsettings
---@field unit string
---@field displayedUnit string
---@field WidgetType string
---@field value number
---@field maxValue number
---@field spellStartTime number
---@field spellEndTime number
---@field empowered boolean
---@field curStage number
---@field numStages number
---@field empStages {start:number, finish:number}[]
---@field stagePips texture[]
---@field holdAtMaxTime number
---@field casting boolean
---@field channeling boolean
---@field interrupted boolean
---@field failed boolean
---@field finished boolean
---@field canInterrupt boolean
---@field spellID spellid
---@field castID number
---@field spellName spellname
---@field spellTexture textureid
---@field Colors df_castcolors
---@field background texture
---@field extraBackground texture
---@field Text fontstring
---@field BorderShield texture
---@field Icon texture
---@field Spark texture
---@field percentText fontstring
---@field barTexture texture
---@field flashTexture texture
---@field fadeOutAnimation animationgroup
---@field fadeInAnimation animationgroup
---@field flashAnimation animationgroup
---@field SetUnit fun(self:df_castbar, unit:string)
---@field SetDefaultColor fun(self:df_castbar, colorType: caststage_color, red:any, green:number?, blue:number?, alpha:number?)
---@field UpdateCastColor fun(self:df_castbar) after setting a new color, call this function to update the bar color (while casting or channeling)
---@field GetCastColor fun(self:df_castbar) return a table with the color values for the current state of the casting process

-- ~castbar

---create a castbar widget
---@param parent frame
---@param name string?
---@param settingsOverride table? a table with key/value pairs to override the default settings
---@return df_castbar
function detailsFramework:CreateCastBar(parent, name, settingsOverride)
assert(name or parent:GetName(), "DetailsFramework:CreateCastBar parameter 'name' omitted and parent has no name.")

Expand Down Expand Up @@ -2365,10 +2405,19 @@ end
---@field castBar df_castbar
---@field powerBar df_powerbar
---@field targetOverlay texture
---@field Settings table
---@field Settings df_unitframesettings

-- ~unitframe
local globalBaseFrameLevel = 1 -- to be increased + used across each new plate

-- ~unitframe
---create a unit frame with a health bar, cast bar and power bar
---@param parent frame
---@param name string?
---@param unitFrameSettingsOverride table?
---@param healthBarSettingsOverride table?
---@param castBarSettingsOverride table?
---@param powerBarSettingsOverride table?
---@return df_unitframe
function detailsFramework:CreateUnitFrame(parent, name, unitFrameSettingsOverride, healthBarSettingsOverride, castBarSettingsOverride, powerBarSettingsOverride)
local parentName = name or ("DetailsFrameworkUnitFrame" .. tostring(math.random(1, 100000000)))

Expand All @@ -2378,22 +2427,22 @@ function detailsFramework:CreateUnitFrame(parent, name, unitFrameSettingsOverrid
--base level
--local baseFrameLevel = f:GetFrameLevel()
local baseFrameLevel = globalBaseFrameLevel
globalBaseFrameLevel = globalBaseFrameLevel + 50
globalBaseFrameLevel = globalBaseFrameLevel + 10

mewUnitFrame:SetFrameLevel(baseFrameLevel)

--create the healthBar
local healthBar = detailsFramework:CreateHealthBar(mewUnitFrame, false, healthBarSettingsOverride)
local healthBar = detailsFramework:CreateHealthBar(mewUnitFrame, nil, healthBarSettingsOverride)
healthBar:SetFrameLevel(baseFrameLevel + 1)
mewUnitFrame.healthBar = healthBar

--create the power bar
local powerBar = detailsFramework:CreatePowerBar(mewUnitFrame, false, powerBarSettingsOverride)
local powerBar = detailsFramework:CreatePowerBar(mewUnitFrame, nil, powerBarSettingsOverride)
powerBar:SetFrameLevel(baseFrameLevel + 2)
mewUnitFrame.powerBar = powerBar

--create the castBar
local castBar = detailsFramework:CreateCastBar(mewUnitFrame, false, castBarSettingsOverride)
local castBar = detailsFramework:CreateCastBar(mewUnitFrame, nil, castBarSettingsOverride)
castBar:SetFrameLevel(baseFrameLevel + 3)
mewUnitFrame.castBar = castBar

Expand Down
Loading

0 comments on commit 4ae7c24

Please sign in to comment.