Skip to content

Commit 6aadd31

Browse files
author
michaelspain
committed
Text Indicator: Now elapsed time can be displayed for afk and offline statuses (Ticket #835)
1 parent e6a9ede commit 6aadd31

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

Diff for: GridStatus.lua

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ status.GetText = Grid2.Dummy
4747
status.GetExpirationTime = Grid2.Dummy
4848
-- duration in seconds: bar, icon, text indicators
4949
status.GetDuration = Grid2.Dummy
50+
-- start time: text indicators
51+
status.GetStartTime = Grid2.Dummy
5052
-- percent value: alpha, bar indicators
5153
status.GetPercent = Grid2.Dummy
5254
-- texture: icon indicator

Diff for: Options/modules/general/GridGeneral.lua

+40-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Grid2Options:AddGeneralOptions( "General", "Themes", {
4343
longDurationStackFormat = "%.1f:%d",
4444
shortDurationStackFormat = "%.0f:%d",
4545
invertDurationStack = false,
46+
secondsElapsedFormat = "%ds",
47+
minutesElapsedFormat = "%dm",
4648
}
4749
shortFormat = used when duration >= 1 sec
4850
longFormat = used when duration < 1 sec
@@ -53,6 +55,13 @@ Grid2Options:AddGeneralOptions( "General", "Themes", {
5355
"%s" = represents stacks, becomes translated to/from: "%d" (integer number)
5456
--]]
5557

58+
-- Update text indicators database
59+
local function UpdateTextIndicators()
60+
for _, indicator in Grid2:IterateIndicators("text") do
61+
indicator:UpdateDB()
62+
end
63+
end
64+
5665
-- Posible values for "Display tenths of a second" options
5766
local tenthsValues = { L["Never"], L["Always"] , L["When duration<1sec"] }
5867

@@ -106,9 +115,7 @@ do
106115
dbx["short"..formatType] = short
107116
dbx["long" ..formatType] = long
108117
if inverted ~= nil then dbx.invertDurationStack = inverted end
109-
for _, indicator in Grid2:IterateIndicators("text") do
110-
indicator:UpdateDB()
111-
end
118+
UpdateTextIndicators()
112119
end
113120
end
114121
end
@@ -131,7 +138,7 @@ Grid2Options:AddGeneralOptions( "General", "Text Formatting", {
131138
set = function (_, v) SetFormat("DecimalFormat", nil, v) end,
132139
values = tenthsValues,
133140
},
134-
separator = { type = "description", name = "", order = 3 },
141+
separator1 = { type = "description", name = "", order = 3 },
135142
dsFormat = {
136143
type = "input",
137144
order = 4,
@@ -149,6 +156,35 @@ Grid2Options:AddGeneralOptions( "General", "Text Formatting", {
149156
set = function (_, v) SetFormat("DurationStackFormat", nil, v) end,
150157
values = tenthsValues
151158
},
159+
separator2 = { type = "description", name = "", order = 6 },
160+
secFormat = {
161+
type = "input",
162+
order = 7,
163+
name = L["Seconds Format"],
164+
desc = L["Examples:\n%ds\n%d seconds"],
165+
get = function()
166+
return Grid2.db.profile.formatting.secondsElapsedFormat
167+
end,
168+
set = function(_,v)
169+
string.format(v, 1) -- sanity check, crash if v is not a correct format mask
170+
Grid2.db.profile.formatting.secondsElapsedFormat = v
171+
UpdateTextIndicators()
172+
end,
173+
},
174+
minFormat = {
175+
type = "input",
176+
order = 8,
177+
name = L["Minutes Format"],
178+
desc = L["Examples:\n%dm\n%d minutes"],
179+
get = function()
180+
return Grid2.db.profile.formatting.minutesElapsedFormat
181+
end,
182+
set = function(_,v)
183+
string.format(v, 1) -- sanity check, crash if v is not a correct format mask
184+
Grid2.db.profile.formatting.minutesElapsedFormat = v
185+
UpdateTextIndicators()
186+
end,
187+
},
152188
})
153189

154190
--==========================================================================

Diff for: modules/IndicatorText.lua

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Grid2.defaults.profile.formatting = {
1515
longDurationStackFormat = "%.1f:%d",
1616
shortDurationStackFormat = "%.0f:%d",
1717
invertDurationStack = false,
18+
secondsElapsedFormat = "%ds",
19+
minutesElapsedFormat = "%dm",
1820
}
1921

2022
local timers = {}
@@ -77,8 +79,14 @@ local function _UpdateSD(text)
7779
end
7880
end
7981
-- elapsed
82+
local FmtEM, FmtES
8083
local function UpdateE(text)
81-
text:SetFormattedText( "%.0f", curTime - expirations[text] )
84+
local t = curTime - expirations[text]
85+
if t>=60 then
86+
text:SetFormattedText( FmtEM, t/60 )
87+
else
88+
text:SetFormattedText( FmtES, t )
89+
end
8290
end
8391
-- duration
8492
local function UpdateD(text)
@@ -150,6 +158,14 @@ local function Text_OnUpdateDE(self, parent, unit, status)
150158
self.updateFunc(Text)
151159
return
152160
end
161+
elseif self.elapsed then
162+
curTime = GetTime() -- not local because is used later by self.updateFunc
163+
expirations[Text] = status:GetStartTime(unit) or curTime
164+
if not timers[Text] then
165+
TimerStart(Text, self.updateFunc)
166+
end
167+
self.updateFunc(Text)
168+
return
153169
else
154170
Text:SetText( string_cut(status:GetText(unit) or "", self.textlength) )
155171
if timers[Text] then TimerStop(Text) end
@@ -221,6 +237,8 @@ local function Text_UpdateDB(self)
221237
FmtDE[false] = fmt.shortDecimalFormat
222238
FmtDES[true] = fmt.longDurationStackFormat
223239
FmtDES[false] = fmt.shortDurationStackFormat
240+
FmtES = fmt.secondsElapsedFormat
241+
FmtEM = fmt.minutesElapsedFormat
224242
UpdateES = fmt.invertDurationStack and _UpdateSE or _UpdateES
225243
UpdateDS = fmt.invertDurationStack and _UpdateSD or _UpdateDS
226244
-- indicator dbx

Diff for: modules/StatusAFK.lua

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ local L = LibStub("AceLocale-3.0"):GetLocale("Grid2")
55
local AFK = Grid2.statusPrototype:new("afk")
66

77
local Grid2 = Grid2
8+
local GetTime = GetTime
89
local UnitIsAFK = UnitIsAFK
910

11+
local afk_cache = setmetatable({}, {__index = function(t,k) local v=GetTime(); t[k]=v; return v end})
12+
1013
AFK.GetColor = Grid2.statusLibrary.GetColor
1114

1215
function AFK:UpdateUnit(_, unit)
1316
if unit then
17+
afk_cache[unit] = nil
1418
self:UpdateIndicators(unit)
1519
end
1620
end
@@ -27,14 +31,20 @@ function AFK:OnDisable()
2731
self:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
2832
self:UnregisterEvent("READY_CHECK")
2933
self:UnregisterEvent("READY_CHECK_FINISHED")
34+
wipe(afk_cache)
3035
end
3136

3237
function AFK:IsActive(unit)
3338
return UnitIsAFK(unit)
3439
end
3540

41+
function AFK:GetStartTime(unit)
42+
return afk_cache[unit]
43+
end
44+
45+
local text = L["AFK"]
3646
function AFK:GetText(unit)
37-
return L["AFK"]
47+
return text
3848
end
3949

4050
local function CreateStatusAFK(baseKey, dbx)

Diff for: modules/StatusOffline.lua

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ function Offline:IsActive(unit)
8787
return offline[unit]
8888
end
8989

90+
function Offline:GetStartTime(unit)
91+
return offline[unit]
92+
end
93+
9094
local text = L["Offline"]
9195
function Offline:GetText(unit)
9296
return text

0 commit comments

Comments
 (0)