annotate ui/CombatLogTab.lua @ 56:75431c084aa0

Added tag v20 for changeset 826f8e68e045
author yellowfive
date Tue, 24 Feb 2015 21:50:13 -0800
parents be5dc6c02f77
children
rev   line source
adam@0 1 local _, AskMrRobot = ...
yellowfive@11 2 local L = AskMrRobot.L;
adam@0 3
adam@17 4 -- initialize the CombatLogTab class
adam@0 5 AskMrRobot.CombatLogTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame)
adam@0 6
adam@17 7 -- these are valid keys in AmrDb.LogData, all others will be deleted
yellowfive@11 8 local _logDataKeys = {
yellowfive@11 9 ["_logging"] = true,
yellowfive@11 10 ["_autoLog"] = true,
yellowfive@11 11 ["_lastZone"] = true,
yellowfive@11 12 ["_lastDiff"] = true,
yellowfive@11 13 ["_current2"] = true,
yellowfive@11 14 ["_history2"] = true,
yellowfive@11 15 ["_wipes"] = true,
yellowfive@11 16 ["_lastWipe"] = true,
yellowfive@11 17 ["_currentExtra"] = true,
yellowfive@11 18 ["_historyExtra"] = true
yellowfive@11 19 };
yellowfive@11 20
yellowfive@11 21 local _undoButton = false
yellowfive@11 22
adam@0 23 -- helper to create text for this tab
adam@0 24 local function CreateText(tab, font, relativeTo, xOffset, yOffset, text)
adam@0 25 local t = tab:CreateFontString(nil, "ARTWORK", font)
adam@0 26 t:SetPoint("TOPLEFT", relativeTo, "BOTTOMLEFT", xOffset, yOffset)
yellowfive@11 27 t:SetPoint("RIGHT", tab, "RIGHT", -5, 0)
adam@0 28 t:SetWidth(t:GetWidth())
adam@0 29 t:SetJustifyH("LEFT")
adam@0 30 t:SetText(text)
adam@0 31
adam@0 32 return t
adam@0 33 end
adam@0 34
adam@0 35 local function newCheckbox(tab, label, tooltipTitle, description, onClick)
adam@0 36 local check = CreateFrame("CheckButton", "AmrCheck" .. label, tab, "InterfaceOptionsCheckButtonTemplate")
adam@0 37 check:SetScript("OnClick", function(self)
adam@0 38 PlaySound(self:GetChecked() and "igMainMenuOptionCheckBoxOn" or "igMainMenuOptionCheckBoxOff")
adam@0 39 onClick(self, self:GetChecked() and true or false)
adam@0 40 end)
adam@0 41 check.label = _G[check:GetName() .. "Text"]
adam@0 42 check.label:SetText(label)
adam@0 43 check.tooltipText = tooltipTitle
adam@0 44 check.tooltipRequirement = description
adam@0 45 return check
adam@0 46 end
adam@0 47
adam@0 48 function AskMrRobot.CombatLogTab:new(parent)
adam@0 49
yellowfive@11 50 local tab = AskMrRobot.Frame:new(nil, parent)
adam@0 51 setmetatable(tab, { __index = AskMrRobot.CombatLogTab })
adam@0 52 tab:SetPoint("TOPLEFT")
adam@0 53 tab:SetPoint("BOTTOMRIGHT")
adam@0 54 tab:Hide()
adam@0 55
yellowfive@11 56 -- tab header
adam@0 57 local text = tab:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
adam@0 58 text:SetPoint("TOPLEFT", 0, -5)
yellowfive@49 59 text:SetText(L.AMR_COMBATLOGTAB_COMBAT_LOGGING)
yellowfive@11 60
yellowfive@11 61 --scrollframe
yellowfive@11 62 tab.scrollframe = AskMrRobot.ScrollFrame:new(nil, tab)
yellowfive@11 63 tab.scrollframe:SetPoint("TOPLEFT", tab, "TOPLEFT", 0, -30)
yellowfive@11 64 tab.scrollframe:SetPoint("BOTTOMRIGHT", tab, "BOTTOMRIGHT", -30, 10)
yellowfive@11 65
yellowfive@11 66 local content = tab.scrollframe.content
yellowfive@11 67 content:SetHeight(730)
adam@0 68
yellowfive@11 69 local btn = CreateFrame("Button", "AmrCombatLogStart", content, "UIPanelButtonTemplate")
yellowfive@11 70 btn:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0)
adam@0 71 btn:SetText("Start Logging")
adam@0 72 btn:SetWidth(120)
adam@0 73 btn:SetHeight(30)
adam@0 74 tab.btnStart = btn
adam@0 75
adam@0 76 btn:SetScript("OnClick", function()
yellowfive@11 77 tab:ToggleLogging()
adam@0 78 end)
adam@0 79
adam@0 80
yellowfive@11 81 text = content:CreateFontString(nil, "ARTWORK", "GameFontWhite")
yellowfive@11 82 text:SetPoint("LEFT", btn, "RIGHT", 10, 0)
yellowfive@11 83 tab.loggingStatus = text;
adam@0 84
TuhMuffinMan>@51 85 local hmAutoChk = newCheckbox(content,
TuhMuffinMan>@51 86 L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_HM_LABEL,
TuhMuffinMan>@51 87 L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_HM_TOOLTIP_TITLE,
TuhMuffinMan>@51 88 L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_HM_DESCRIPTION,
adam@0 89 function(self, value)
adam@0 90 if value then
TuhMuffinMan>@51 91 AmrDb.LogData._autoLog[AskMrRobot.instanceIds.Highmaul] = "enabled"
adam@0 92 else
TuhMuffinMan>@51 93 AmrDb.LogData._autoLog[AskMrRobot.instanceIds.Highmaul] = "disabled"
adam@0 94 end
adam@0 95
adam@17 96 AmrDb.LogData._lastZone = nil
adam@17 97 AmrDb.LogData._lastDiff = nil
adam@0 98 tab:UpdateAutoLogging()
adam@0 99 end
adam@0 100 )
TuhMuffinMan>@51 101 hmAutoChk:SetChecked(AmrDb.LogData._autoLog[AskMrRobot.instanceIds.Highmaul] == "enabled")
TuhMuffinMan>@51 102 hmAutoChk:SetPoint("TOPLEFT", btn, "BOTTOMLEFT", 0, -10)
TuhMuffinMan>@51 103 hmAutoChk:SetHeight(30)
TuhMuffinMan>@51 104
TuhMuffinMan>@51 105 local brfAutoChk = newCheckbox(content,
TuhMuffinMan>@51 106 L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_BRF_LABEL,
TuhMuffinMan>@51 107 L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_BRF_TOOLTIP_TITLE,
TuhMuffinMan>@51 108 L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_BRF_DESCRIPTION,
TuhMuffinMan>@51 109 function(self, value)
TuhMuffinMan>@51 110 if value then
TuhMuffinMan>@51 111 AmrDb.LogData._autoLog[AskMrRobot.instanceIds.BlackrockFoundry] = "enabled"
TuhMuffinMan>@51 112 else
TuhMuffinMan>@51 113 AmrDb.LogData._autoLog[AskMrRobot.instanceIds.BlackrockFoundry] = "disabled"
TuhMuffinMan>@51 114 end
adam@0 115
TuhMuffinMan>@51 116 AmrDb.LogData._lastZone = nil
TuhMuffinMan>@51 117 AmrDb.LogData._lastDiff = nil
TuhMuffinMan>@51 118 tab:UpdateAutoLogging()
TuhMuffinMan>@51 119 end
TuhMuffinMan>@51 120 )
TuhMuffinMan>@51 121 brfAutoChk:SetChecked(AmrDb.LogData._autoLog[AskMrRobot.instanceIds.BlackrockFoundry] == "enabled")
TuhMuffinMan>@51 122 brfAutoChk:SetPoint("TOPLEFT", hmAutoChk, "BOTTOMLEFT", 0, -10)
TuhMuffinMan>@51 123 brfAutoChk:SetHeight(30)
adam@0 124
TuhMuffinMan>@51 125 local text = CreateText(content, "GameFontNormalLarge", brfAutoChk, 0, -20, L.AMR_COMBATLOGTAB_INFIGHT)
yellowfive@11 126
TuhMuffinMan>@51 127 btn = CreateFrame("Button", "AmrCombatLogWipe", brfAutoChk, "UIPanelButtonTemplate")
yellowfive@11 128 btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -10)
yellowfive@11 129 btn:SetText("Wipe")
yellowfive@11 130 btn:SetWidth(70)
yellowfive@11 131 btn:SetHeight(30)
yellowfive@11 132 btn:SetScript("OnClick", function()
yellowfive@11 133 tab:LogWipe()
yellowfive@11 134 end)
yellowfive@11 135
yellowfive@11 136 tab.btnWipe = btn
yellowfive@11 137
yellowfive@11 138 local text2 = CreateText(content, "GameFontWhite", text, 80, -12, L.AMR_COMBATLOGTAB_WIPE_1)
yellowfive@11 139 text2 = CreateText(content, "GameFontWhite", text2, 0, -2, L.AMR_COMBATLOGTAB_WIPE_2)
yellowfive@11 140 text2 = CreateText(content, "GameFontWhite", text2, 0, -2, L.AMR_COMBATLOGTAB_WIPE_3)
yellowfive@11 141
yellowfive@11 142 btn = CreateFrame("Button", "AmrCombatLogUnWipe", content, "UIPanelButtonTemplate")
yellowfive@11 143 btn:SetPoint("LEFT", text, "LEFT", 0, 0)
yellowfive@11 144 btn:SetPoint("TOP", text2, "BOTTOM", 0, -10)
yellowfive@11 145 btn:SetText("Undo")
yellowfive@11 146 btn:SetWidth(70)
yellowfive@11 147 btn:SetHeight(30)
yellowfive@11 148 btn:Hide() -- initially hidden
yellowfive@11 149 btn:SetScript("OnClick", function()
yellowfive@11 150 tab:LogUnwipe()
yellowfive@11 151 end)
yellowfive@11 152 tab.btnUnwipe = btn
yellowfive@11 153
yellowfive@11 154 text = content:CreateFontString(nil, "ARTWORK", "GameFontWhite")
yellowfive@11 155 text:SetPoint("LEFT", btn, "LEFT", 80, 0)
yellowfive@11 156 tab.lastWipeLabel = text
yellowfive@11 157
yellowfive@11 158 text = CreateText(tab, "GameFontNormalLarge", btn, 0, -20, L.AMR_COMBATLOGTAB_HEADLINE_OVER_BUTTON)
yellowfive@11 159
yellowfive@11 160 btn = CreateFrame("Button", "AmrCombatLogSaveCharData", content, "UIPanelButtonTemplate")
adam@0 161 btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -5)
yellowfive@11 162 btn:SetText(L.AMR_COMBATLOGTAB_SAVE_CHARACTER)
adam@0 163 btn:SetWidth(150)
adam@0 164 btn:SetHeight(30)
adam@0 165
yellowfive@11 166 -- reload the UI will save character data to disk
yellowfive@11 167 btn:SetScript("OnClick", ReloadUI)
adam@0 168
yellowfive@11 169 text = CreateText(content, "GameFontWhite", btn, 0, -15, L.AMR_COMBATLOGTAB_SAVE_CHARACTER_INFO)
adam@0 170
yellowfive@11 171 text = CreateText(content, "GameFontNormalLarge", text, 0, -30, L.AMR_COMBATLOGTAB_INSTRUCTIONS)
yellowfive@11 172 text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_1)
yellowfive@11 173 text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_2)
yellowfive@11 174 text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_3)
yellowfive@11 175 text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_4)
yellowfive@11 176
yellowfive@11 177 text = CreateText(content, "GameFontNormalSmall", text, 0, -30, L.AMR_COMBATLOGTAB_INSTRUCTIONS_5)
yellowfive@11 178 text = CreateText(content, "GameFontNormalSmall", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_6)
yellowfive@11 179 text = CreateText(content, "GameFontNormalSmall", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_7)
adam@0 180
yellowfive@15 181 --[[
adam@0 182 btn = CreateFrame("Button", "AmrCombatLogTest", tab, "UIPanelButtonTemplate")
adam@0 183 btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -15)
adam@0 184 btn:SetText("Test")
adam@0 185 btn:SetWidth(120)
adam@0 186 btn:SetHeight(30)
adam@0 187
adam@0 188 btn:SetScript("OnClick", function()
yellowfive@11 189
yellowfive@11 190 local t = time()
yellowfive@11 191 AskMrRobot.SaveAll()
yellowfive@11 192 AskMrRobot.ExportToAddonChat(t)
adam@17 193 AskMrRobot.CombatLogTab.SaveExtras(t)
adam@0 194 end)
yellowfive@15 195 ]]
adam@0 196
adam@0 197 -- when we start up, ensure that logging is still enabled if it was enabled when they last used the addon
adam@17 198 if (AskMrRobot.CombatLogTab.IsLogging()) then
adam@0 199 SetCVar("advancedCombatLogging", 1)
adam@0 200 LoggingCombat(true)
adam@0 201 end
adam@0 202
adam@0 203 -- if auto-logging is enabled, do a check when the addon is loaded to make sure that state is set correctly
yellowfive@53 204 if tab:IsAutoLoggingEnabled() then
adam@0 205 tab:UpdateAutoLogging()
adam@0 206 end
adam@0 207
adam@0 208 tab:SetScript("OnShow", function()
adam@0 209 tab:Update()
adam@0 210 end)
adam@0 211
adam@0 212 return tab
adam@0 213 end
adam@0 214
adam@17 215 function AskMrRobot.CombatLogTab.IsLogging()
adam@17 216 return AmrDb.LogData._logging == true
adam@0 217 end
adam@0 218
adam@0 219 function AskMrRobot.CombatLogTab:StartLogging()
adam@0 220
yellowfive@11 221 local now = time()
yellowfive@11 222 local oldDuration = 60 * 60 * 24 * 10
yellowfive@11 223
adam@0 224 -- archive the current logging session so that users don't accidentally blow away data before uploading it
adam@17 225 if AmrDb.LogData._current2 ~= nil then
adam@17 226 if not AmrDb.LogData._history2 then AmrDb.LogData._history2 = {} end
adam@0 227
adam@0 228 -- add new entries
adam@17 229 for name, timeList in AskMrRobot.spairs(AmrDb.LogData._current2) do
adam@17 230 if not AmrDb.LogData._history2[name] then AmrDb.LogData._history2[name] = {} end
adam@0 231 for timestamp, dataString in AskMrRobot.spairs(timeList) do
adam@17 232 AmrDb.LogData._history2[name][timestamp] = dataString
adam@0 233 end
adam@0 234 end
adam@0 235
adam@0 236 -- delete entries that are more than 10 days old
adam@17 237 for name, timeList in AskMrRobot.spairs(AmrDb.LogData._history2) do
adam@0 238 for timestamp, dataString in AskMrRobot.spairs(timeList) do
yellowfive@11 239 if difftime(now, tonumber(timestamp)) > oldDuration then
adam@0 240 timeList[timestamp] = nil
adam@0 241 end
adam@0 242 end
adam@0 243
adam@0 244 local count = 0
adam@0 245 for timestamp, dataString in pairs(timeList) do
adam@0 246 count = count + 1
adam@0 247 end
adam@0 248 if count == 0 then
adam@17 249 AmrDb.LogData._history2[name] = nil
adam@0 250 end
adam@0 251 end
adam@0 252 end
adam@0 253
yellowfive@11 254 -- same idea with extra info (auras, pets, whatever we end up adding to it)
adam@17 255 if AmrDb.LogData._currentExtra ~= nil then
adam@17 256 if not AmrDb.LogData._historyExtra then AmrDb.LogData._historyExtra = {} end
yellowfive@11 257
yellowfive@11 258 -- add new entries
adam@17 259 for name, timeList in AskMrRobot.spairs(AmrDb.LogData._currentExtra) do
adam@17 260 if not AmrDb.LogData._historyExtra[name] then AmrDb.LogData._historyExtra[name] = {} end
yellowfive@11 261 for timestamp, dataString in AskMrRobot.spairs(timeList) do
adam@17 262 AmrDb.LogData._historyExtra[name][timestamp] = dataString
yellowfive@11 263 end
yellowfive@11 264 end
yellowfive@11 265
yellowfive@11 266 -- delete entries that are more than 10 days old
adam@17 267 for name, timeList in AskMrRobot.spairs(AmrDb.LogData._historyExtra) do
yellowfive@11 268 for timestamp, dataString in AskMrRobot.spairs(timeList) do
yellowfive@11 269 if difftime(now, tonumber(timestamp)) > oldDuration then
yellowfive@11 270 timeList[timestamp] = nil
yellowfive@11 271 end
yellowfive@11 272 end
yellowfive@11 273
yellowfive@11 274 local count = 0
yellowfive@11 275 for timestamp, dataString in pairs(timeList) do
yellowfive@11 276 count = count + 1
yellowfive@11 277 end
yellowfive@11 278 if count == 0 then
adam@17 279 AmrDb.LogData._historyExtra[name] = nil
yellowfive@11 280 end
yellowfive@11 281 end
yellowfive@11 282 end
yellowfive@11 283
yellowfive@11 284
yellowfive@11 285 -- delete _wipes entries that are more than 10 days old
adam@17 286 if AmrDb.LogData._wipes then
yellowfive@11 287 local i = 1
adam@17 288 while i <= #AmrDb.LogData._wipes do
adam@17 289 local t = AmrDb.LogData._wipes[i]
yellowfive@11 290 if difftime(now, t) > oldDuration then
adam@17 291 tremove(AmrDb.LogData._wipes, i)
yellowfive@11 292 else
yellowfive@11 293 i = i + 1
yellowfive@11 294 end
yellowfive@11 295 end
yellowfive@11 296 end
yellowfive@11 297
yellowfive@11 298 -- delete the _lastWipe if it is more than 10 days old
adam@17 299 if AmrDb.LogData._lastWipe and difftime(now, AmrDb.LogData._lastWipe) > oldDuration then
adam@17 300 AmrDb.LogData_lastWipe = nil
yellowfive@11 301 end
yellowfive@11 302
adam@0 303 -- clean up old-style logging data from previous versions of the addon
adam@17 304 for k, v in AskMrRobot.spairs(AmrDb.LogData) do
yellowfive@11 305 if not _logDataKeys[k] then
adam@17 306 AmrDb.LogData[k] = nil
adam@0 307 end
adam@0 308 end
adam@0 309
adam@0 310 -- start a new logging session
adam@17 311 AmrDb.LogData._current2 = {}
adam@17 312 AmrDb.LogData._currentExtra = {}
adam@17 313 AmrDb.LogData._logging = true
adam@0 314
adam@0 315 -- always enable advanced combat logging via our addon, gathers more detailed data for better analysis
adam@0 316 SetCVar("advancedCombatLogging", 1)
adam@0 317
adam@0 318 LoggingCombat(true)
adam@0 319 self:Update()
yellowfive@11 320
yellowfive@11 321 AskMrRobot.AmrUpdateMinimap()
adam@0 322
yellowfive@11 323 print(L.AMR_COMBATLOGTAB_IS_LOGGING)
adam@0 324 end
adam@0 325
adam@0 326 function AskMrRobot.CombatLogTab:StopLogging()
adam@0 327 LoggingCombat(false)
adam@17 328 AmrDb.LogData._logging = false
adam@0 329 self:Update()
adam@0 330
yellowfive@11 331 AskMrRobot.AmrUpdateMinimap()
yellowfive@11 332
yellowfive@11 333 print(L.AMR_COMBATLOGTAB_STOPPED_LOGGING)
yellowfive@11 334 end
yellowfive@11 335
yellowfive@11 336 function AskMrRobot.CombatLogTab:ToggleLogging()
adam@17 337 if AskMrRobot.CombatLogTab.IsLogging() then
yellowfive@11 338 self:StopLogging()
yellowfive@11 339 else
yellowfive@11 340 self:StartLogging()
yellowfive@11 341 end
adam@0 342 end
adam@0 343
adam@0 344 -- update the panel and state
adam@0 345 function AskMrRobot.CombatLogTab:Update()
adam@17 346 local isLogging = AskMrRobot.CombatLogTab.IsLogging()
adam@0 347
adam@0 348 if isLogging then
yellowfive@11 349 self.btnStart:SetText(L.AMR_COMBATLOGTAB_STOP_LOGGING)
yellowfive@11 350 self.loggingStatus:SetText(L.AMR_COMBATLOGTAB_CURRENTLY_LOGGING)
adam@0 351 else
yellowfive@11 352 self.btnStart:SetText(L.AMR_COMBATLOGTAB_START_LOGGING)
yellowfive@11 353 self.loggingStatus:SetText("")
adam@0 354 end
yellowfive@11 355
adam@17 356 if AmrDb.LogData._lastWipe then
adam@17 357 self.lastWipeLabel:SetText(L.AMR_COMBATLOGTAB_LASTWIPE:format(date('%B %d', AmrDb.LogData._lastWipe), date('%I:%M %p', AmrDb.LogData._lastWipe)))
yellowfive@11 358 self.btnUnwipe:Show()
yellowfive@11 359 else
yellowfive@11 360 self.lastWipeLabel:SetText("")
yellowfive@11 361 self.btnUnwipe:Hide()
yellowfive@11 362 end
yellowfive@11 363
adam@0 364 end
adam@0 365
yellowfive@53 366 -- returns true if any auto-logging options are enabled
yellowfive@53 367 function AskMrRobot.CombatLogTab:IsAutoLoggingEnabled()
yellowfive@53 368 -- see if any auto-logging is enabled
yellowfive@53 369 for k,v in pairs(AmrDb.LogData._autoLog) do
yellowfive@53 370 if v == "enabled" then
yellowfive@53 371 return true
yellowfive@53 372 end
yellowfive@53 373 end
yellowfive@53 374 return false
yellowfive@53 375 end
yellowfive@53 376
adam@0 377 -- called to update logging state when auto-logging is enabled
adam@0 378 function AskMrRobot.CombatLogTab:UpdateAutoLogging()
adam@0 379
adam@0 380 -- get the info about the instance
adam@0 381 --local zone, zonetype, difficultyIndex, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID = GetInstanceInfo()
adam@0 382 local zone, _, difficultyIndex, _, _, _, _, instanceMapID = GetInstanceInfo()
adam@0 383 --local difficulty = difficultyIndex
adam@0 384 -- Unless Blizzard fixes scenarios to not return nil, let's hardcode this into returning "scenario" -Znuff
adam@0 385 --if zonetype == nil and difficultyIndex == 1 then
adam@0 386 --zonetype = "scenario"
adam@0 387 --end
adam@0 388
adam@17 389 if zone == AmrDb.LogData._lastZone and difficultyIndex == AmrDb.LogData._lastDiff then
adam@0 390 -- do nothing if the zone hasn't actually changed, otherwise we may override the user's manual enable/disable
adam@0 391 return
adam@0 392 end
adam@0 393
adam@17 394 AmrDb.LogData._lastZone = zone
adam@17 395 AmrDb.LogData._lastDiff = difficultyIndex
adam@0 396
yellowfive@53 397 if self:IsAutoLoggingEnabled() then
yellowfive@53 398 if AskMrRobot.IsSupportedInstanceId(instanceMapID) and AmrDb.LogData._autoLog[tonumber(instanceMapID)] == "enabled" then
yellowfive@53 399 -- we are in a supported zone that we want to auto-log, turn logging on
yellowfive@53 400 -- (supported check is probably redundant, but just in case someone has old settings lying around)
adam@17 401 if not AskMrRobot.CombatLogTab.IsLogging() then
adam@0 402 self:StartLogging()
adam@0 403 end
adam@0 404 else
yellowfive@53 405 -- not in a zone that we want to auto-log, turn logging off
adam@17 406 if AskMrRobot.CombatLogTab.IsLogging() then
adam@0 407 self:StopLogging()
adam@0 408 end
adam@0 409 end
adam@0 410 end
adam@0 411
adam@0 412 end
adam@0 413
yellowfive@11 414 local function RaidChatType()
yellowfive@11 415 if UnitIsGroupAssistant("player") or UnitIsGroupLeader("player") then
yellowfive@11 416 return "RAID_WARNING"
yellowfive@11 417 else
yellowfive@11 418 return "RAID"
yellowfive@11 419 end
yellowfive@11 420 end
yellowfive@11 421
adam@17 422 -- used to store wipes to AmrDb.LogData so that we trim data after the wipe
yellowfive@11 423 function AskMrRobot.CombatLogTab:LogWipe()
yellowfive@11 424 local t = time()
adam@17 425 tinsert(AmrDb.LogData._wipes, t)
adam@17 426 AmrDb.LogData._lastWipe = t
yellowfive@11 427
adam@17 428 --if GetNumGroupMembers() > 0 then
adam@17 429 -- SendChatMessage(L.AMR_COMBATLOGTAB_WIPE_CHAT, RaidChatType())
adam@17 430 --end
yellowfive@11 431 print(string.format(L.AMR_COMBATLOGTAB_WIPE_MSG, date('%I:%M %p', t)))
yellowfive@11 432
yellowfive@11 433 self:Update()
yellowfive@11 434 end
yellowfive@11 435
yellowfive@11 436 -- used to undo the wipe command
yellowfive@11 437 function AskMrRobot.CombatLogTab:LogUnwipe()
adam@17 438 local t = AmrDb.LogData._lastWipe
yellowfive@11 439 if not t then
yellowfive@11 440 print(L.AMR_COMBATLOGTAB_NOWIPES)
yellowfive@11 441 else
adam@17 442 tremove(AmrDb.LogData._wipes)
adam@17 443 AmrDb.LogData._lastWipe = nil
yellowfive@11 444 print(string.format(L.AMR_COMBATLOGTAB_UNWIPE_MSG, date('%I:%M %p', t)))
yellowfive@11 445 end
yellowfive@11 446 self:Update()
yellowfive@11 447 end
yellowfive@11 448
adam@17 449 -- initialize the AmrDb.LogData variable
yellowfive@11 450 function AskMrRobot.CombatLogTab.InitializeVariable()
adam@17 451 if not AmrDb.LogData then AmrDb.LogData = {} end
adam@17 452 if not AmrDb.LogData._autoLog then AmrDb.LogData._autoLog = {} end
yellowfive@53 453
yellowfive@53 454 for k,v in pairs(AskMrRobot.supportedInstanceIds) do
yellowfive@53 455 if not AmrDb.LogData._autoLog[k] then
yellowfive@53 456 AmrDb.LogData._autoLog[k] = "disabled"
yellowfive@53 457 end
yellowfive@11 458 end
yellowfive@53 459
adam@17 460 AmrDb.LogData._wipes = AmrDb.LogData._wipes or {}
yellowfive@11 461 end
yellowfive@11 462
yellowfive@41 463 local function GetPlayerExtraData(data, unitId, petId)
adam@17 464
adam@17 465 local guid = UnitGUID(unitId)
adam@17 466 if guid == nil then
yellowfive@41 467 return
adam@17 468 end
adam@17 469
adam@17 470 local fields = {}
adam@17 471
adam@17 472 local buffs = {}
adam@17 473 for i=1,40 do
adam@17 474 local _,_,_,count,_,_,_,_,_,_,spellId = UnitAura(unitId, i, "HELPFUL")
adam@17 475 table.insert(buffs, spellId)
adam@17 476 end
adam@17 477 if #buffs == 0 then
adam@17 478 table.insert(fields, "_")
adam@17 479 else
adam@17 480 table.insert(fields, AskMrRobot.toCompressedNumberList(buffs))
adam@17 481 end
adam@17 482
yellowfive@41 483 local petGuid = UnitGUID(petId)
adam@17 484 if petGuid then
adam@17 485 table.insert(fields, guid .. "," .. petGuid)
adam@17 486 else
adam@17 487 table.insert(fields, '_')
adam@17 488 end
adam@17 489
yellowfive@41 490 local name = GetUnitName(unitId, true) -- GetRaidRosterInfo(rosterIndex)
adam@17 491 local realm = GetRealmName()
yellowfive@41 492 local region = AskMrRobot.regionNames[GetCurrentRegion()]
adam@17 493 local splitPos = string.find(name, "-")
adam@17 494 if splitPos ~= nil then
adam@17 495 realm = string.sub(name, splitPos + 1)
adam@17 496 name = string.sub(name, 1, splitPos - 1)
adam@17 497 end
adam@17 498
yellowfive@41 499 data[region .. ":" .. realm .. ":" .. name] = table.concat(fields, ";")
adam@17 500 end
adam@17 501
adam@17 502 function AskMrRobot.CombatLogTab.SaveExtras(timestamp)
adam@17 503
adam@17 504 if not AskMrRobot.CombatLogTab.IsLogging() then
adam@17 505 return
adam@17 506 end
adam@17 507
yellowfive@41 508 local units = {}
yellowfive@41 509 local petUnits = {}
yellowfive@41 510
yellowfive@41 511 if IsInRaid() then
yellowfive@41 512 for i = 1,40 do
yellowfive@41 513 table.insert(units, "raid" .. i)
yellowfive@41 514 table.insert(petUnits, "raidpet" .. i)
yellowfive@41 515 end
yellowfive@41 516 elseif IsInGroup() then
yellowfive@41 517 table.insert(units, "player")
yellowfive@41 518 table.insert(petUnits, "pet")
yellowfive@41 519 for i = 1,4 do
yellowfive@41 520 table.insert(units, "party" .. i)
yellowfive@41 521 table.insert(petUnits, "partypet" .. i)
yellowfive@41 522 end
yellowfive@41 523 else
yellowfive@41 524 return
yellowfive@41 525 end
adam@17 526
adam@17 527 local data = {}
yellowfive@41 528 for i = 1,#units do
yellowfive@41 529 GetPlayerExtraData(data, units[i], petUnits[i])
yellowfive@41 530 end
adam@17 531
yellowfive@11 532 for name,val in pairs(data) do
yellowfive@11 533 -- record aura stuff, we never check for duplicates, need to know it at each point in time
adam@17 534 if AmrDb.LogData._currentExtra[name] == nil then
adam@17 535 AmrDb.LogData._currentExtra[name] = {}
yellowfive@11 536 end
adam@17 537 AmrDb.LogData._currentExtra[name][timestamp] = val
yellowfive@11 538 end
yellowfive@11 539 end
yellowfive@11 540
adam@0 541 -- read a message sent to the addon channel with a player's info at the time an encounter started
adam@0 542 function AskMrRobot.CombatLogTab:ReadAddonMessage(message)
adam@0 543
yellowfive@41 544 -- message will be of format: timestamp\nregion\nrealm\nname\n[stuff]
adam@0 545 local parts = {}
adam@0 546 for part in string.gmatch(message, "([^\n]+)") do
adam@0 547 tinsert(parts, part)
adam@0 548 end
adam@0 549
adam@0 550 local timestamp = parts[1]
yellowfive@41 551 local name = parts[2] .. ":" .. parts[3] .. ":" .. parts[4]
yellowfive@41 552 local data = parts[5]
adam@0 553
adam@0 554 if (data == "done") then
adam@0 555 -- we have finished receiving this message; now process it to reduce the amount of duplicate data
adam@17 556 local setup = AmrDb.LogData._current2[name][timestamp]
yellowfive@11 557
adam@17 558 if (AmrDb.LogData._previousSetup == nil) then
adam@17 559 AmrDb.LogData._previousSetup = {}
adam@0 560 end
adam@0 561
adam@17 562 local previousSetup = AmrDb.LogData._previousSetup[name]
adam@0 563
adam@0 564 if (previousSetup == setup) then
adam@0 565 -- if the last-seen setup for this player is the same as the current one, we don't need this entry
adam@17 566 AmrDb.LogData._current2[name][timestamp] = nil
adam@0 567 else
adam@0 568 -- record the last-seen setup
adam@17 569 AmrDb.LogData._previousSetup[name] = setup
adam@0 570 end
yellowfive@11 571
adam@0 572 else
adam@0 573 -- concatenate messages with the same timestamp+name
adam@17 574 if (AmrDb.LogData._current2[name] == nil) then
adam@17 575 AmrDb.LogData._current2[name] = {}
adam@0 576 end
adam@0 577
adam@17 578 if (AmrDb.LogData._current2[name][timestamp] == nil) then
adam@17 579 AmrDb.LogData._current2[name][timestamp] = data
adam@0 580 else
adam@17 581 AmrDb.LogData._current2[name][timestamp] = AmrDb.LogData._current2[name][timestamp] .. data
adam@0 582 end
adam@0 583 end
adam@0 584 end