annotate Devent.lua @ 111:5c591d9b4029 tip

Added tag v8.0.1-20181807-1 for changeset 930922e1ec5b
author Nenue
date Wed, 18 Jul 2018 15:02:50 -0400
parents 7a36f5a92f0a
children
rev   line source
Nenue@108 1 --- Devian - Devent.lua
Nenue@108 2 -- @file-author@
Nenue@108 3 -- @project-revision@ @project-hash@
Nenue@108 4 -- @file-revision@ @file-hash@
Nenue@108 5 -- Created: 4/12/2017 5:07 PM
Nenue@108 6 -- Event tracer
Nenue@107 7 --
Nenue@107 8 local tooltip = GameTooltip
Nenue@107 9 local traces = {} -- frames
Nenue@107 10 local eventLog = {} -- events received
Nenue@107 11 local selectedEvents = {} -- events selected
Nenue@107 12 local print = function(...) print('Devent', ...) end
Nenue@107 13
Nenue@107 14 --print('Devent script')
Nenue@107 15 --print('Devent:OnLoad()')
Nenue@107 16 SLASH_DTRACE1 = "/dtrace"
Nenue@107 17
Nenue@107 18 SlashCmdList.DTRACE = function(args)
Nenue@107 19 if #traces == 0 then
Nenue@107 20 local trace = CreateFrame('Frame', 'DevianTraceLog'.. (#traces+1), UIParent, 'DevianEventTraceTemplate')
Nenue@107 21 tinsert(traces, trace)
Nenue@107 22 trace:Setup()
Nenue@107 23 end
Nenue@107 24
Nenue@107 25 traces[1]:Show()
Nenue@107 26 end
Nenue@107 27 DevianEventTraceMixin = {
Nenue@107 28 events = {},
Nenue@107 29 selected = {},
Nenue@107 30 }
Nenue@107 31 local tracer = DevianEventTraceMixin
Nenue@107 32
Nenue@107 33 function tracer:OnLoad()
Nenue@107 34 self:SetMaxResize(GetScreenWidth(), GetScreenHeight())
Nenue@107 35 self:SetMinResize(100, 24)
Nenue@107 36 self:EnableMouse(true)
Nenue@107 37 self:RegisterForDrag('LeftButton')
Nenue@107 38 self:SetMovable(true)
Nenue@107 39 self:SetResizable(true)
Nenue@107 40 self:SetClampedToScreen(true)
Nenue@107 41 self:SetFont("Interface\\Addons\\Devian\\font\\SourceCodePro-Regular.ttf", 13, 'NORMAL')
Nenue@107 42 self:SetJustifyH('LEFT')
Nenue@107 43 self:SetHyperlinksEnabled(true)
Nenue@107 44 self:SetPoint('CENTER')
Nenue@107 45 self:SetSize(400,400)
Nenue@107 46 end
Nenue@107 47
Nenue@107 48 function tracer:Setup(info)
Nenue@107 49 if not info then
Nenue@107 50 self:RegisterAllEvents()
Nenue@107 51 return
Nenue@107 52 end
Nenue@107 53
Nenue@107 54 for _, event in ipairs(self.events) do
Nenue@107 55 self:UnregisterEvent(event)
Nenue@107 56 end
Nenue@107 57
Nenue@107 58 for _, event in ipairs(info.events) do
Nenue@107 59 self:RegisterEvent(event)
Nenue@107 60 end
Nenue@107 61 end
Nenue@107 62
Nenue@107 63 function tracer:OnHyperlinkEnter(linkdata, link)
Nenue@107 64 local messageID = tonumber(linkdata:match('%d+'))
Nenue@107 65 if messageID and self.events[messageID] then
Nenue@107 66 local data = self.events[messageID]
Nenue@107 67 tooltip:SetOwner(self, 'ANCHOR_RIGHT')
Nenue@107 68 tooltip:AddLine(data.event)
Nenue@107 69 for i, arg in ipairs(data.args) do
Nenue@107 70 local argtype = data.argtypes[i]
Nenue@107 71 tooltip:AddLine('|cFFAAAAAA'..tostring(argtype)..'|r ' .. tostring(arg))
Nenue@107 72 end
Nenue@107 73 tooltip:Show()
Nenue@107 74 end
Nenue@107 75
Nenue@107 76 end
Nenue@107 77
Nenue@107 78 function tracer:OnHyperlinkLeave(linkdata, link)
Nenue@107 79 end
Nenue@107 80
Nenue@107 81 function tracer:OnHyperlinkClick(linkdata, link)
Nenue@107 82
Nenue@107 83 local messageID = tonumber(linkdata:match('%d+'))
Nenue@107 84 if messageID and self.events[messageID] then
Nenue@107 85 local data = self.events[messageID]
Nenue@107 86
Nenue@107 87 if self.selected[data.event] then
Nenue@107 88 self.selected[data.event] = nil
Nenue@107 89 else
Nenue@107 90 self.selected[data.event] = true
Nenue@107 91 end
Nenue@107 92 end
Nenue@107 93 self:Update()
Nenue@107 94 end
Nenue@107 95
Nenue@107 96 function tracer:OnLeave()
Nenue@107 97 if tooltip:IsOwned(self) then
Nenue@107 98 tooltip:Hide()
Nenue@107 99 end
Nenue@107 100 end
Nenue@107 101
Nenue@107 102 function tracer:OnEvent(event, ...)
Nenue@107 103 local entry = {
Nenue@107 104 index = #self.events + 1,
Nenue@107 105 ts = time(),
Nenue@107 106 event = event,
Nenue@107 107 args = {},
Nenue@107 108 argtypes = {}
Nenue@107 109 }
Nenue@107 110 for i = 1, select('#', ...) do
Nenue@107 111 local arg = select(i,...)
Nenue@107 112 entry.argtypes[i] = type(arg)
Nenue@107 113 entry.args[i] = tostring(arg)
Nenue@107 114 end
Nenue@107 115 self.events[entry.index] = entry
Nenue@107 116 self:Update()
Nenue@107 117 end
Nenue@107 118
Nenue@107 119 function tracer:Update()
Nenue@107 120 local startingLine = self.CurrentLine or #self.events
Nenue@107 121 local prevLine
Nenue@107 122 for i = 0, 20 do
Nenue@107 123 local index = startingLine - i
Nenue@107 124 local line = self.lines[i]
Nenue@107 125 if not line then
Nenue@107 126 line = self:CreateFontString('EventLine'..i)
Nenue@107 127 line:SetFont([[Fonts\ARIALN__.TTF]], 14, 'THIN')
Nenue@107 128 line:SetTextColor(1,1,1)
Nenue@107 129 self.lines[i] = line
Nenue@107 130 end
Nenue@107 131 local entry = self.events[index]
Nenue@107 132
Nenue@107 133 if entry then
Nenue@107 134 line:SetText('|Hdevent:'..entry.index..'|h'..entry.event..'|h')
Nenue@107 135 line:ClearAllPoints()
Nenue@107 136 if prevLine then
Nenue@107 137 line:SetPoint('BOTTOMLEFT', prevLine, 'TOPLEFT', 0, 0)
Nenue@107 138 else
Nenue@107 139 line:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT')
Nenue@107 140 end
Nenue@107 141 line:Show()
Nenue@107 142 prevLine = line
Nenue@107 143 else
Nenue@107 144 line:Hide()
Nenue@107 145 end
Nenue@107 146 end
Nenue@107 147
Nenue@107 148 end