Mercurial > wow > askmrrobot
comparison ui/CombatLogTab.lua @ 0:ec731d2fe6ba
Version 1.2.12.0
author | Adam tegen <adam.tegen@gmail.com> |
---|---|
date | Tue, 20 May 2014 21:43:23 -0500 |
parents | |
children | ece9167c0d1c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ec731d2fe6ba |
---|---|
1 local _, AskMrRobot = ... | |
2 | |
3 -- initialize the ExportTab class | |
4 AskMrRobot.CombatLogTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame) | |
5 | |
6 -- helper to create text for this tab | |
7 local function CreateText(tab, font, relativeTo, xOffset, yOffset, text) | |
8 local t = tab:CreateFontString(nil, "ARTWORK", font) | |
9 t:SetPoint("TOPLEFT", relativeTo, "BOTTOMLEFT", xOffset, yOffset) | |
10 t:SetPoint("RIGHT", tab, "RIGHT", -25, 0) | |
11 t:SetWidth(t:GetWidth()) | |
12 t:SetJustifyH("LEFT") | |
13 t:SetText(text) | |
14 | |
15 return t | |
16 end | |
17 | |
18 local function newCheckbox(tab, label, tooltipTitle, description, onClick) | |
19 local check = CreateFrame("CheckButton", "AmrCheck" .. label, tab, "InterfaceOptionsCheckButtonTemplate") | |
20 check:SetScript("OnClick", function(self) | |
21 PlaySound(self:GetChecked() and "igMainMenuOptionCheckBoxOn" or "igMainMenuOptionCheckBoxOff") | |
22 onClick(self, self:GetChecked() and true or false) | |
23 end) | |
24 check.label = _G[check:GetName() .. "Text"] | |
25 check.label:SetText(label) | |
26 check.tooltipText = tooltipTitle | |
27 check.tooltipRequirement = description | |
28 return check | |
29 end | |
30 | |
31 function AskMrRobot.CombatLogTab:new(parent) | |
32 | |
33 local tab = AskMrRobot.Frame:new(nil, parent) | |
34 setmetatable(tab, { __index = AskMrRobot.CombatLogTab }) | |
35 tab:SetPoint("TOPLEFT") | |
36 tab:SetPoint("BOTTOMRIGHT") | |
37 tab:Hide() | |
38 | |
39 local text = tab:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") | |
40 text:SetPoint("TOPLEFT", 0, -5) | |
41 text:SetText("Combat Logging") | |
42 | |
43 local manulText = CreateText(tab, "GameFontWhite", text, 0, -15, "Manual:") | |
44 manulText:SetJustifyV("MIDDLE") | |
45 manulText:SetHeight(30) | |
46 | |
47 local btn = CreateFrame("Button", "AmrCombatLogStart", tab, "UIPanelButtonTemplate") | |
48 btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 75, -15) | |
49 btn:SetText("Start Logging") | |
50 btn:SetWidth(120) | |
51 btn:SetHeight(30) | |
52 tab.btnStart = btn | |
53 | |
54 btn:SetScript("OnClick", function() | |
55 tab:StartLogging() | |
56 end) | |
57 | |
58 btn = CreateFrame("Button", "AmrCombatLogEnd", tab, "UIPanelButtonTemplate") | |
59 btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 225, -15) | |
60 btn:SetText("Stop Logging") | |
61 btn:SetWidth(120) | |
62 btn:SetHeight(30) | |
63 tab.btnEnd = btn | |
64 | |
65 btn:SetScript("OnClick", function() | |
66 tab:StopLogging() | |
67 end) | |
68 | |
69 local autoText = CreateText(tab, "GameFontWhite", text, 0, -50, "Automatic:") | |
70 autoText:SetJustifyV("MIDDLE") | |
71 autoText:SetHeight(28) | |
72 | |
73 local autoChk = newCheckbox(tab, | |
74 "Always log Siege of Orgrimmar", | |
75 "Auto-Log Siege of Orgrimmar", | |
76 "Automatically start logging when you enter SoO and stop when you leave SoO.\n\nNote that you should disable similar features in other addons to avoid conflicts.", | |
77 function(self, value) | |
78 if value then | |
79 AmrLogData._autoLog[AskMrRobot.instanceIds.SiegeOfOrgrimmar] = "enabled" | |
80 else | |
81 AmrLogData._autoLog[AskMrRobot.instanceIds.SiegeOfOrgrimmar] = "disabled" | |
82 end | |
83 | |
84 AmrLogData._lastZone = nil | |
85 AmrLogData._lastDiff = nil | |
86 tab:UpdateAutoLogging() | |
87 end | |
88 ) | |
89 autoChk:SetChecked(AmrLogData._autoLog[AskMrRobot.instanceIds.SiegeOfOrgrimmar] == "enabled") | |
90 autoChk:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 75, -50) | |
91 autoChk:SetHeight(30) | |
92 | |
93 text = CreateText(tab, "GameFontNormalLarge", text, 0, -100, "Character Data") | |
94 | |
95 btn = CreateFrame("Button", "AmrCombatLogSaveCharData", tab, "UIPanelButtonTemplate") | |
96 btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -5) | |
97 btn:SetText("Save Character Data") | |
98 btn:SetWidth(150) | |
99 btn:SetHeight(30) | |
100 | |
101 btn:SetScript("OnClick", function() | |
102 -- reload the UI will save character data to disk | |
103 ReloadUI() | |
104 end) | |
105 | |
106 text = CreateText(tab, "GameFontNormalLarge", btn, 0, -30, "INSTRUCTIONS") | |
107 text = CreateText(tab, "GameFontWhite", text, 0, -10, "1. Use the Start/Stop buttons or check 'Always log Siege of Orgrimmar'.") | |
108 text = CreateText(tab, "GameFontWhite", text, 0, -10, "2. When you are ready to upload, press 'Save Character Data'. *") | |
109 text = CreateText(tab, "GameFontWhite", text, 0, -10, "3. Exit World of Warcraft. **") | |
110 text = CreateText(tab, "GameFontWhite", text, 0, -10, "4. Launch the Ask Mr. Robot client and follow the instructions. ***") | |
111 | |
112 text = CreateText(tab, "GameFontNormalSmall", text, 0, -30, "|c00999999* This will reload your UI to ensure that all collected data is saved to disk. This step is not necessary if you log out of the game before uploading.|r") | |
113 text = CreateText(tab, "GameFontNormalSmall", text, 0, -10, "|c00999999** Exiting WoW before uploading your combat log is optional, but highly recommended. This prevents your log file from getting ridiculously large and slowing down your uploads.|r") | |
114 text = CreateText(tab, "GameFontNormalSmall", text, 0, -10, "|c00999999*** You can download the client program at|r |c003333ffhttp://www.askmrrobot.com/wow/combatlog/upload|r|c00999999.|r") | |
115 | |
116 --[[ | |
117 btn = CreateFrame("Button", "AmrCombatLogTest", tab, "UIPanelButtonTemplate") | |
118 btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -15) | |
119 btn:SetText("Test") | |
120 btn:SetWidth(120) | |
121 btn:SetHeight(30) | |
122 | |
123 btn:SetScript("OnClick", function() | |
124 AskMrRobot.ExportToAddonChat(time()) | |
125 end) | |
126 ]] | |
127 | |
128 -- when we start up, ensure that logging is still enabled if it was enabled when they last used the addon | |
129 if (tab:IsLogging()) then | |
130 SetCVar("advancedCombatLogging", 1) | |
131 LoggingCombat(true) | |
132 end | |
133 | |
134 -- if auto-logging is enabled, do a check when the addon is loaded to make sure that state is set correctly | |
135 if AmrLogData._autoLog[AskMrRobot.instanceIds.SiegeOfOrgrimmar] == "enabled" then | |
136 tab:UpdateAutoLogging() | |
137 end | |
138 | |
139 tab:SetScript("OnShow", function() | |
140 tab:Update() | |
141 end) | |
142 | |
143 return tab | |
144 end | |
145 | |
146 function AskMrRobot.CombatLogTab:IsLogging() | |
147 return AmrLogData._logging == true | |
148 end | |
149 | |
150 function AskMrRobot.CombatLogTab:StartLogging() | |
151 | |
152 -- archive the current logging session so that users don't accidentally blow away data before uploading it | |
153 if AmrLogData._current2 ~= nil then | |
154 if not AmrLogData._history2 then AmrLogData._history2 = {} end | |
155 | |
156 -- add new entries | |
157 for name, timeList in AskMrRobot.spairs(AmrLogData._current2) do | |
158 if not AmrLogData._history2[name] then AmrLogData._history2[name] = {} end | |
159 for timestamp, dataString in AskMrRobot.spairs(timeList) do | |
160 AmrLogData._history2[name][timestamp] = dataString | |
161 end | |
162 end | |
163 | |
164 -- delete entries that are more than 10 days old | |
165 local now = time() | |
166 local interval = 60 * 60 * 24 * 10 | |
167 for name, timeList in AskMrRobot.spairs(AmrLogData._history2) do | |
168 for timestamp, dataString in AskMrRobot.spairs(timeList) do | |
169 if difftime(now, tonumber(timestamp)) > interval then | |
170 timeList[timestamp] = nil | |
171 end | |
172 end | |
173 | |
174 local count = 0 | |
175 for timestamp, dataString in pairs(timeList) do | |
176 count = count + 1 | |
177 end | |
178 if count == 0 then | |
179 AmrLogData._history2[name] = nil | |
180 end | |
181 end | |
182 end | |
183 | |
184 -- clean up old-style logging data from previous versions of the addon | |
185 for k, v in AskMrRobot.spairs(AmrLogData) do | |
186 if k ~= "_logging" and k ~= "_autoLog" and k ~= "_lastZone" and k ~= "_lastDiff" and k ~= "_current2" and k ~= "_history2" then | |
187 AmrLogData[k] = nil | |
188 end | |
189 end | |
190 | |
191 -- start a new logging session | |
192 AmrLogData._current2 = {} | |
193 AmrLogData._logging = true | |
194 | |
195 -- always enable advanced combat logging via our addon, gathers more detailed data for better analysis | |
196 SetCVar("advancedCombatLogging", 1) | |
197 | |
198 LoggingCombat(true) | |
199 self:Update() | |
200 | |
201 print("You are now logging combat, and Mr. Robot is logging character data for your raid.") | |
202 end | |
203 | |
204 function AskMrRobot.CombatLogTab:StopLogging() | |
205 LoggingCombat(false) | |
206 AmrLogData._logging = false | |
207 self:Update() | |
208 | |
209 print("Combat logging has been stopped.") | |
210 end | |
211 | |
212 -- update the panel and state | |
213 function AskMrRobot.CombatLogTab:Update() | |
214 local isLogging = self:IsLogging() | |
215 | |
216 if isLogging then | |
217 self.btnStart:Disable() | |
218 self.btnEnd:Enable() | |
219 else | |
220 self.btnStart:Enable() | |
221 self.btnEnd:Disable() | |
222 end | |
223 end | |
224 | |
225 -- called to update logging state when auto-logging is enabled | |
226 function AskMrRobot.CombatLogTab:UpdateAutoLogging() | |
227 | |
228 -- get the info about the instance | |
229 --local zone, zonetype, difficultyIndex, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID = GetInstanceInfo() | |
230 local zone, _, difficultyIndex, _, _, _, _, instanceMapID = GetInstanceInfo() | |
231 --local difficulty = difficultyIndex | |
232 -- Unless Blizzard fixes scenarios to not return nil, let's hardcode this into returning "scenario" -Znuff | |
233 --if zonetype == nil and difficultyIndex == 1 then | |
234 --zonetype = "scenario" | |
235 --end | |
236 | |
237 if zone == AmrLogData._lastZone and difficultyIndex == AmrLogData._lastDiff then | |
238 -- do nothing if the zone hasn't actually changed, otherwise we may override the user's manual enable/disable | |
239 return | |
240 end | |
241 | |
242 AmrLogData._lastZone = zone | |
243 AmrLogData._lastDiff = difficultyIndex | |
244 | |
245 if AmrLogData._autoLog[AskMrRobot.instanceIds.SiegeOfOrgrimmar] == "enabled" then | |
246 if tonumber(instanceMapID) == AskMrRobot.instanceIds.SiegeOfOrgrimmar then | |
247 -- if in SoO, make sure logging is on | |
248 if not self:IsLogging() then | |
249 self:StartLogging() | |
250 end | |
251 else | |
252 -- not in SoO, turn logging off | |
253 if self:IsLogging() then | |
254 self:StopLogging() | |
255 end | |
256 end | |
257 end | |
258 | |
259 end | |
260 | |
261 -- read a message sent to the addon channel with a player's info at the time an encounter started | |
262 function AskMrRobot.CombatLogTab:ReadAddonMessage(message) | |
263 | |
264 -- message will be of format: timestamp\nrealm\nname\n[stuff] | |
265 local parts = {} | |
266 for part in string.gmatch(message, "([^\n]+)") do | |
267 tinsert(parts, part) | |
268 end | |
269 | |
270 local timestamp = parts[1] | |
271 local name = parts[2] .. ":" .. parts[3] | |
272 local data = parts[4] | |
273 | |
274 if (data == "done") then | |
275 -- we have finished receiving this message; now process it to reduce the amount of duplicate data | |
276 local setup = AmrLogData._current2[name][timestamp] | |
277 | |
278 if (AmrLogData._previousSetup == nil) then | |
279 AmrLogData._previousSetup = {} | |
280 end | |
281 | |
282 local previousSetup = AmrLogData._previousSetup[name] | |
283 | |
284 if (previousSetup == setup) then | |
285 -- if the last-seen setup for this player is the same as the current one, we don't need this entry | |
286 AmrLogData._current2[name][timestamp] = nil | |
287 else | |
288 -- record the last-seen setup | |
289 AmrLogData._previousSetup[name] = setup | |
290 end | |
291 else | |
292 -- concatenate messages with the same timestamp+name | |
293 if (AmrLogData._current2[name] == nil) then | |
294 AmrLogData._current2[name] = {} | |
295 end | |
296 | |
297 if (AmrLogData._current2[name][timestamp] == nil) then | |
298 AmrLogData._current2[name][timestamp] = data | |
299 else | |
300 AmrLogData._current2[name][timestamp] = AmrLogData._current2[name][timestamp] .. data | |
301 end | |
302 end | |
303 end |