Major rework on the M+ end of run panel

This commit is contained in:
Tercio Jose
2024-08-09 20:55:16 -03:00
committed by andrew6180
parent c6fbc67442
commit 065c61c8ff
12 changed files with 816 additions and 289 deletions
+115 -29
View File
@@ -1,6 +1,7 @@
local DF = _G["DetailsFramework"]
if (not DF or not DetailsFrameworkCanLoad) then
---@type detailsframework
local detailsFramework = _G["DetailsFramework"]
if (not detailsFramework or not DetailsFrameworkCanLoad) then
return
end
@@ -9,20 +10,69 @@ local type = type
local floor = math.floor
local GetTime = GetTime
---@class df_timebar : statusbar, df_scripthookmixin, df_widgets
---@field type string
---@field dframework boolean
---@field statusBar df_timebar_statusbar
---@field widget statusbar
---@field direction string
---@field HookList table
---@field tooltip string
---@field locked boolean
---@field HasTimer fun(self:df_timebar):boolean return if the timer bar is active showing a timer
---@field SetTimer fun(self:df_timebar, currentTime:number, startTime:number|boolean|nil, endTime:number|nil)
---@field StartTimer fun(self:df_timebar, currentTime:number, startTime:number, endTime:number)
---@field StopTimer fun(self:df_timebar)
---@field ShowSpark fun(self:df_timebar, state:boolean, alpha:number|nil, color:string|nil)
---@field ShowTimer fun(self:df_timebar, bShowTimer:boolean)
---@field SetIcon fun(self:df_timebar, texture:string, L:number|nil, R:number|nil, T:number|nil, B:number|nil)
---@field SetIconSize fun(self:df_timebar, width:number, height:number)
---@field SetTexture fun(self:df_timebar, texture:texturepath|textureid)
---@field SetColor fun(self:df_timebar, color:any, green:number|nil, blue:number|nil, alpha:number|nil)
---@field SetLeftText fun(self:df_timebar, text:string)
---@field SetRightText fun(self:df_timebar, text:string)
---@field SetFont fun(self:df_timebar, font:string|nil, size:number|nil, color:any, shadow:boolean|nil)
---@field SetThrottle fun(self:df_timebar, seconds:number)
---@field SetDirection fun(self:df_timebar, direction:string)
---@class df_timebar_statusbar : statusbar
---@field MyObject df_timebar
---@field hasTimer boolean
---@field startTime number
---@field endTime number
---@field timeLeft1 number
---@field timeLeft2 number
---@field throttle number
---@field isUsingThrottle boolean
---@field showTimer boolean
---@field amountThrottle number
---@field sparkAlpha number
---@field sparkColorR number
---@field sparkColorG number
---@field sparkColorB number
---@field dontShowSpark boolean
---@field direction string
---@field spark texture
---@field icon texture
---@field leftText fontstring
---@field rightText fontstring
---@field backgroundTexture texture
---@field barTexture texture
local APITimeBarFunctions
do
local metaPrototype = {
WidgetType = "timebar",
dversion = DF.dversion,
dversion = detailsFramework.dversion,
}
--check if there's a metaPrototype already existing
if (_G[DF.GlobalWidgetControlNames["timebar"]]) then
if (_G[detailsFramework.GlobalWidgetControlNames["timebar"]]) then
--get the already existing metaPrototype
local oldMetaPrototype = _G[DF.GlobalWidgetControlNames["timebar"]]
local oldMetaPrototype = _G[detailsFramework.GlobalWidgetControlNames["timebar"]]
--check if is older
if ( (not oldMetaPrototype.dversion) or (oldMetaPrototype.dversion < DF.dversion) ) then
if ( (not oldMetaPrototype.dversion) or (oldMetaPrototype.dversion < detailsFramework.dversion) ) then
--the version is older them the currently loading one
--copy the new values into the old metatable
for funcName, _ in pairs(metaPrototype) do
@@ -31,12 +81,12 @@ do
end
else
--first time loading the framework
_G[DF.GlobalWidgetControlNames["timebar"]] = metaPrototype
_G[detailsFramework.GlobalWidgetControlNames["timebar"]] = metaPrototype
end
end
local TimeBarMetaFunctions = _G[DF.GlobalWidgetControlNames["timebar"]]
DF:Mixin(TimeBarMetaFunctions, DF.ScriptHookMixin)
local TimeBarMetaFunctions = _G[detailsFramework.GlobalWidgetControlNames["timebar"]]
detailsFramework:Mixin(TimeBarMetaFunctions, detailsFramework.ScriptHookMixin)
--methods
TimeBarMetaFunctions.SetMembers = TimeBarMetaFunctions.SetMembers or {}
@@ -159,7 +209,7 @@ function TimeBarMetaFunctions:SetTexture(texture)
end
function TimeBarMetaFunctions:SetColor(color, green, blue, alpha)
local r, g, b, a = DF:ParseColors(color, green, blue, alpha)
local r, g, b, a = detailsFramework:ParseColors(color, green, blue, alpha)
self.statusBar.barTexture:SetVertexColor(r, g, b, a)
end
@@ -172,22 +222,25 @@ end
function TimeBarMetaFunctions:SetFont(font, size, color, shadow)
if (font) then
DF:SetFontFace(self.statusBar.leftText, font)
detailsFramework:SetFontFace(self.statusBar.leftText, font)
end
if (size) then
DF:SetFontSize(self.statusBar.leftText, size)
detailsFramework:SetFontSize(self.statusBar.leftText, size)
end
if (color) then
DF:SetFontColor(self.statusBar.leftText, color)
detailsFramework:SetFontColor(self.statusBar.leftText, color)
end
if (shadow) then
DF:SetFontOutline(self.statusBar.leftText, shadow)
detailsFramework:SetFontOutline(self.statusBar.leftText, shadow)
end
end
---set a throttle for the timer bar, the timer will only update every X seconds
---calling without parameters will disable the throttle
---@param seconds number|nil the amount of seconds to throttle the timer
function TimeBarMetaFunctions:SetThrottle(seconds)
if (seconds and seconds > 0) then
self.statusBar.isUsingThrottle = true
@@ -197,6 +250,8 @@ function TimeBarMetaFunctions:SetThrottle(seconds)
end
end
---accept 'left' 'right' or nil, if ommited will default to right
---@param direction "left"|"right"|nil the direction of the timer bar
function TimeBarMetaFunctions:SetDirection(direction)
direction = direction or "right"
self.direction = direction
@@ -225,6 +280,14 @@ function TimeBarMetaFunctions:StopTimer()
statusBar.spark:Hide()
end
function TimeBarMetaFunctions:ShowTimer(bShowTimer)
if (bShowTimer) then
self.statusBar.showTimer = true
else
self.statusBar.showTimer = nil
end
end
function TimeBarMetaFunctions:ShowSpark(state, alpha, color)
if (type(state) == "boolean" and state == false) then
self.statusBar.dontShowSpark = true
@@ -239,7 +302,7 @@ function TimeBarMetaFunctions:ShowSpark(state, alpha, color)
end
if (color) then
local r, g, b = DF:ParseColors(color)
local r, g, b = detailsFramework:ParseColors(color)
if (r and g and b) then
self.statusBar.sparkColorR = r
self.statusBar.sparkColorG = g
@@ -252,6 +315,8 @@ function TimeBarMetaFunctions:ShowSpark(state, alpha, color)
end
end
---@param self df_timebar_statusbar
---@param deltaTime number
local OnUpdateFunc = function(self, deltaTime)
if (self.isUsingThrottle) then
self.throttle = self.throttle + deltaTime
@@ -283,9 +348,11 @@ local OnUpdateFunc = function(self, deltaTime)
end
end
local timeLeft = floor(endTime - timeNow)
local formatedTimeLeft = DF:IntegerToTimer(timeLeft)
self.rightText:SetText(formatedTimeLeft)
if (self.showTimer) then
local timeLeft = floor(endTime - timeNow)
local formatedTimeLeft = detailsFramework:IntegerToTimer(timeLeft)
self.rightText:SetText(formatedTimeLeft)
end
--check if finished
if (timeNow >= self.endTime) then
@@ -293,6 +360,12 @@ local OnUpdateFunc = function(self, deltaTime)
end
end
---start a timer on the timebar
---calling without parameters will stop the timer
---@param self df_timebar
---@param currentTime number the time in seconds if startTime is a boolean true. GetTime() when start and end time are passed
---@param startTime number|boolean|nil GetTime() when the timer started. if passed true: startTime and endTime are GetTime() and GetTime() + currentTime, currenTime is the time in seconds
---@param endTime number|nil GetTime() when the timer will end. ignored if startTime is a boolean true
function TimeBarMetaFunctions:SetTimer(currentTime, startTime, endTime)
self.statusBar:Show()
@@ -306,7 +379,7 @@ function TimeBarMetaFunctions:SetTimer(currentTime, startTime, endTime)
--it is the same timer called again
return
end
self.statusBar.startTime = startTime
self.statusBar.startTime = tonumber(startTime) or 0 --fit the number type
self.statusBar.endTime = endTime
else
local bForceNewTimer = type(startTime) == "boolean" and startTime
@@ -352,18 +425,26 @@ function TimeBarMetaFunctions:SetTimer(currentTime, startTime, endTime)
end
end
function DF:CreateTimeBar(parent, texture, width, height, value, member, name)
---create a time bar widget, a timebar is a statubar that can have a timer and a spark
---@param parent frame the parent frame
---@param texture texturepath|textureid the texture of the bar
---@param width number? the width of the bar, default is 150
---@param height number? the height of the bar, default is 20
---@param value number? the initial value of the bar, default is 0
---@param member string? the name of the member in the parent frame
---@param name string? the name of the widget
---@return df_timebar
function detailsFramework:CreateTimeBar(parent, texture, width, height, value, member, name)
if (not name) then
name = "DetailsFrameworkBarNumber" .. DF.BarNameCounter
DF.BarNameCounter = DF.BarNameCounter + 1
name = "DetailsFrameworkBarNumber" .. detailsFramework.BarNameCounter
detailsFramework.BarNameCounter = detailsFramework.BarNameCounter + 1
elseif (not parent) then
return error("Details! FrameWork: parent not found.", 2)
error("Details! FrameWork: parent not found.", 2)
end
if (name:find("$parent")) then
local parentName = DF:GetParentName(parent)
local parentName = detailsFramework:GetParentName(parent)
name = name:gsub("$parent", parentName)
end
@@ -375,18 +456,21 @@ function DF:CreateTimeBar(parent, texture, width, height, value, member, name)
if (member) then
parent[member] = timeBar
end
---@diagnostic disable-next-line: undefined-field
if (parent.dframework) then
---@diagnostic disable-next-line: undefined-field
parent = parent.widget
end
value = value or 0
width = width or 150
height = height or 14
height = height or 20
timeBar.locked = false
timeBar.statusBar = CreateFrame("statusbar", name, parent, "BackdropTemplate")
timeBar.widget = timeBar.statusBar
DF:Mixin(timeBar.statusBar, DF.WidgetFunctions)
detailsFramework:Mixin(timeBar.statusBar, detailsFramework.WidgetFunctions)
timeBar.statusBar.MyObject = timeBar
timeBar.direction = "right"
@@ -397,7 +481,9 @@ function DF:CreateTimeBar(parent, texture, width, height, value, member, name)
if (not TimeBarMetaFunctions[funcName]) then
TimeBarMetaFunctions[funcName] = function(object, ...)
local x = loadstring("return _G['"..object.statusBar:GetName().."']:"..funcName.."(...)")
return x(...)
if (x) then
return x(...)
end
end
end
end
@@ -433,7 +519,7 @@ function DF:CreateTimeBar(parent, texture, width, height, value, member, name)
timeBar.statusBar.rightText = timeBar.statusBar:CreateFontString(nil, "overlay", "GameFontNormal", 4)
timeBar.statusBar.rightText:SetPoint("right", timeBar.statusBar, "right", -2, 0)
timeBar.statusBar.rightText:SetJustifyH("left")
--hooks
timeBar.HookList = {
OnEnter = {},