# HG changeset patch # User Nenue # Date 1471357368 14400 # Node ID d5e6b2265d6f0b191066887e9c74b563b5038993 # Parent 34a2e8d93448bb76485471975eff87d8a68a5092 casdfasd diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonStats/DamageMeter.lua --- a/SkeletonStats/DamageMeter.lua Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,315 +0,0 @@ --------------------------------------------- --- KrakTool --- DamageMeter --- @project-revision@ @project-hash@ --- @file-revision@ @file-hash@ --- Created: 6/19/2016 10:43 AM --------------------------------------------- --- dm --- {...} = actor ( name, guid ) -- returns actor table --- .showbar (bar ) -- toggle row --- .hidebar ( bar ) -- --- .ui () -- update chart -local KT = LibKT.register(DamageMeter) -local dm = DamageMeter -local db - -local addon, core = ... -core.segments = {} -core.actors = {} -core.pets = {} -core.ordered = {} -core.actorsOrdered = {} -core.current = {} -core.prototypes = {} - -local GROUP_SIZE = 4 -local GROUP_TOKEN = 'party' -local myGUID -local segments, actors, pets, ordered = core.segments, core.actors, core.pets, core.ordered -local prototypes = core.prototypes -local segmentUID -local viewPos -local handler -local viewType = 'damageDone' -local meterWidth = 230 - -dm.init = function() - dm:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED') - dm:RegisterEvent('PLAYER_REGEN_DISABLED') - dm:RegisterEvent('ENCOUNTER_START') - dm.bars = dm.bars or {} - dm.headings = dm.headings or {} -end - -dm.ENCOUNTER_START = function() - dm.new() -end - -dm.variables = function() - SkeletonStatsDB = SkeletonStatsDB or {} - db = SkeletonStatsDB - db.segments = db.segments or {} - db.currentSegment = db.currentSegment or 0 - db.actors = db.actors or {} - db.viewType = db.viewType or 'damageDone' - - - - myGUID = UnitGUID('player') - core.actor(myGUID) - segments = db.segments - viewPos = db.currentSegment - viewType = prototypes[viewType] and viewType or 'damageDone' - - if not segments[#segments] then - dm.new() - end - - dm.handler(viewType) - dm.view(viewPos) - - dm.ui() -end - -dm.handler = function (viewType) - handler = prototypes[viewType] - dm.header:SetText(handler.header) -end - -dm.new = function() - if core.active then - core.active.finish = GetTime() - end - - segmentUID = (db.segUID or 0) + 1 - db.segUID = segmentUID - - local segPos = #segments+1 - core.segments[segPos] = { - view = {}, - start = GetTime(), - uid = segmentUID - } - core.active = core.segments[viewPos].view - print('Starting new segment #', segPos, 'UID', segmentUID, core.active, core.segments[viewPos]) - - dm.view(segPos) - - return viewPos -end - -dm.view = function(pos) - if not segments[pos] then - pos = 1 - end - core.current = segments[pos] - core.current.view = core.current.view or {} -end - -local dummyColor = { - r = 0, - g = 0.5, - b = 0 -} -local dummyActor = { - name = 'Unknown', - flags = 0, - class = 'NA', - classFilename = '', - race = 'Unknown', - raceFilename = '', - sex = 1, - realm = '' -} - -local UNKNOWN_ACTOR = { - name = 'Unknown', - flags = 0, - class = 'NADA' -} ---- Pull stored actor info if possible -core.actor = function (guid, name, flags) - local class, classFilename, race, raceFilename, sex, name, realm - local actor = UNKNOWN_ACTOR - if actors[guid] then - print('cached GUID', guid) - return actors[guid] - end - - if guid:match('^Player') then - if db.actors[guid] then - actor = db.actors[guid] - print('using saved player GUID') - else - - class, classFilename, race, raceFilename, sex, name, realm = GetPlayerInfoByGUID(guid) - actor = { - name = name, - flags = flags, - class = class, - classFilename = classFilename, - race = race, - raceFilename = raceFilename, - sex = sex, - realm = realm - } - print('saving player GUID') - db.actors[guid] = actor - - end - - actors[guid] = actor - elseif guid:match('^Pet') then - print('analyzing pet GUID') - actor = { - name = name, - class = 'PET', - } - if not pets[guid] then - if bit.band(flags, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0 then - pets[guid] = myGUID - actors[myGUID].pets = actors[myGUID].pets or {} - actors[myGUID].pets[guid] = actor - elseif bit.band(flags, COMBATLOG_OBJECT_AFFILIATION_PARTY+COMBATLOG_OBJECT_AFFILIATION_RAID > 0) then - -- todo: handle party/raid pets - end - end - actors[guid] = actor - end - return actor -end - -dm.PLAYER_REGEN_DISABLED = function() - dm.new() -end - -dm.COMBAT_LOG_EVENT_UNFILTERED = function(self, event, timeStemp, subEvent, u1, ...) - local sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags = ... - - local storeActor = false - local args = {...} - for key, prototype in pairs(prototypes) do - --print(subEvent) - if prototype[subEvent] then - local result = prototype[subEvent](subEvent, ...) - storeActor = (storeActor or result) - --print('|cFFFFFF00' .. key .. '|r.|cFF00FFFF'..subEvent, '|r', ...) - end - end - - if storeActor then - core.actor(sourceGUID, sourceName, sourceFlags) - core.actor(destGUID, destName, destFlags) - end - - dm.ui() - return true -end - ---- [name] --- .COMBAT_EVENT = function(event, ...) --- .init = function() --- .calculate = function(bar, data, actor) --- .refresh = function(bar, data, actor - -dm.showbar = function(bar) - bar:Show() - bar.icon:Show() - bar.header:Show() - bar.headerRight:Show() -end - -dm.hidebar = function(bar) - bar:Hide() - bar.icon:Hide() - bar.header:Hide() - bar.headerRight:Hide() -end - -dm.ui = function() - --table.sort(view, sortType) - local view = core.current.view - - table.wipe(ordered) - for k,v in pairs(view) do - if type(v) ~= 'table' then - view[k] = nil - else - tinsert(ordered, v) - end - end - table.sort(ordered, handler.sort) - - handler.init() - - for i = 1, 12 do - if ordered[i] then - if not dm.bars[i] then - dm.bars[i] = dm:CreateTexture('MeterBar'..i, 'BORDER') - dm.bars[i]:SetHeight(24) - dm.bars[i]:SetPoint('TOPLEFT', dm, 0, i * -24) - dm.bars[i].icon = dm:CreateTexture('MeterIcon' .. i, 'OVERLAY') - dm.bars[i].icon:SetSize(24,24) - dm.bars[i].icon:SetPoint('TOPLEFT', dm.bars[i], 'TOPLEFT', -12, 0) - - dm.bars[i].header = dm:CreateFontString('MeterHeader'..i, 'OVERLAY', 'MeterHeaderLeft') - dm.bars[i].header:SetPoint('LEFT', dm.bars[i], 'LEFT', 22, 0) - - dm.bars[i].headerRight = dm:CreateFontString('MeterHeaderRight'..i, 'OVERLAY', 'MeterHeaderRight') - dm.bars[i].headerRight:SetPoint('TOP', dm.bars[i], 'TOP', 0, -6) - end - - local actor = actors[ordered[i].guid] or UNKNOWN_ACTOR - handler.calculate(dm.bars[i], ordered[i], ordered[i], actor) - end - end - - for i, bar in ipairs(dm.bars) do - if ordered[i] then - - local actor = actors[ordered[i].guid] or UNKNOWN_ACTOR - local icon, textLeft, textRight, r, g, b, a, percent = handler.refresh(bar, ordered[i], actor) - - bar:SetColorTexture(r, g, b, a) - - if icon then - bar.icon:Show() - bar.icon:SetTexture(icon[1]) - if icon[2] then - bar.icon:SetTexCoord(unpack(icon[2])) - else - bar.icon:SetTexCoord(1,0,1,0) - end - else - bar.icon:Hide() - end - - if textLeft then - bar.header:Show() - bar.header:SetText(textLeft) - else - bar.header:Hide() - end - if textRight then - bar.headerRight:Show() - bar.headerRight:SetText(textRight) - else - bar.headerRight:Hide() - end - - bar:SetWidth(meterWidth*percent) - bar:Show() - else - dm.hidebar(bar) - end - end - dm:SetHeight((#ordered + 1) * 24) - dm:SetWidth(meterWidth) -end ---------------------------------------------------------- --- DAMAGE DONE - - ---------------------------------------------------------- --- HEALING DONE \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonStats/DamageMeter.xml --- a/SkeletonStats/DamageMeter.xml Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ - - - - - - - - - - - self:RegisterForDrag('LeftButton') - - - self:StartMoving() - - - self:StopMovingOrSizing() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonStats/SkeletonStats.iml --- a/SkeletonStats/SkeletonStats.iml Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonStats/SkeletonStats.toc --- a/SkeletonStats/SkeletonStats.toc Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -## Interface: 70000 -## Title: Skeleton Stats -## Notes: Combat statistics for dinosaurs -## Author: Krakyn -## Version: 1.0-@project-revision@ -## SavedVariables: SkeletonStatsDB -## X-Category: Interface Enhancements -## DefaultState: Enabled -## LoadOnDemand: 0 -## OptionalDeps: libKT - -libKT-1.0\libKT-1.0.xml - -DamageMeter.xml -DamageMeter.lua -Views\DamageDone.lua \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonStats/Views/DamageDone.lua --- a/SkeletonStats/Views/DamageDone.lua Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ - -local core = select(2, ...) -local prototypes = core.prototypes -local SOURCE_MASK = COMBATLOG_OBJECT_AFFILIATION_RAID+COMBATLOG_OBJECT_AFFILIATION_PARTY+COMBATLOG_OBJECT_AFFILIATION_MINE - -local dd = { - header = 'Damage Done', -} -dd.SPELL_DAMAGE = function(subEvent, ...) - local sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ... - - if not sourceName then - return false - end - - if bit.band(sourceFlags, SOURCE_MASK) == 0 then - --print('discarded non-raid damage event', sourceFlags, sourceName) - return false - end - - local view = core.current.view - view[sourceName] = view[sourceName] or {} - local p = view[sourceName] - - - p.guid = sourceGUID - p.last = amount - p.damage = (p.damage or 0) + amount - p.name = (sourceName or 'Unknown') - - p.child = p.child or {} - p.child[spellName] = p.child[spellName] or {} - p.child[spellName].hit = (p.child[spellName].hit or 0) + 1 - - -- true = store this event's actor - return true -end - -dd.SPELL_DAMAGE_PERIODIC = dd.SPELL_DAMAGE -dd.RANGE_DAMAGE = dd.SPELL_DAMAGE - -dd.SWING_DAMAGE = function(subEvent, ...) - local sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ... - local spellID, spellName, spellSchool = -1, 'Attack', 1 - dd.SPELL_DAMAGE(subEvent, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing) -end - -dd.init = function() - dd.maxDamage = 0 -end - -dd.sort = function(a, b) - return a.damage > b.damage -end - -dd.calculate = function(bar, data, actor) - if dd.maxDamage < data.damage then - dd.maxDamage = data.damage - end - -end - -dd.refresh = function(bar, data, actor) - local icon, textLeft, textRight - local r, g, b, a, percent = 1,1,1,1,1 - if actor.class and CLASS_ICON_TCOORDS[actor.classFilename] then - icon = { "Interface\\TargetingFrame\\UI-Classes-Circles" , CLASS_ICON_TCOORDS[actor.classFilename] } - end - textLeft = data.name - textRight = data.damage .. ' ('..data.last..')' - - - if actor.class and RAID_CLASS_COLORS[actor.classFilename] then - r = RAID_CLASS_COLORS[actor.classFilename].r - g = RAID_CLASS_COLORS[actor.classFilename].g - b = RAID_CLASS_COLORS[actor.classFilename].b - end - percent = (data.damage / dd.maxDamage) - - return icon, textLeft, textRight, r, g, b, a, percent -end - -prototypes.damageDone = dd \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonUnit/SkeletonUnit.iml --- a/SkeletonUnit/SkeletonUnit.iml Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonUnit/SkeletonUnit.toc --- a/SkeletonUnit/SkeletonUnit.toc Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -## Interface: 70000 -## Title: Skeleton Unit -## Notes: Unit Frames for dinosaurs -## Author: Krakyn -## SavedVariables: FossilDB -## Version: 1.0-@project-revision@ -## X-Category: Interface Enhancements -## DefaultState: Enabled -## LoadOnDemand: 0 -## OptionalDeps: libKT - -libKT-1.0\libKT-1.0.xml - -UnitFrame.xml -UnitFrame.lua \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonUnit/UnitFrame.lua --- a/SkeletonUnit/UnitFrame.lua Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,309 +0,0 @@ --------------------------------------------- --- KrakTool --- Nick --- @project - r e v i s i o n @ @project-hash@ --- @file - r e v i s i o n @ @file-hash@ --- Created: 6/16/2016 3:46 AM --------------------------------------------- - -local KT = LibKT.register(SkeletonUnits) -local db -local PLAYER_NAMEPLATE -local PLAYER_WIDTH = 220 -local BUFF_SIZE = 24 -local uf = SkeletonUnits -local prototypes = {} -local units = {} -local buttons = {} - -local params = setmetatable({}, { - __index = function(t, k) - print('get', k) - return t.player - end, - __newindex = function(t, k, v) - if type(v) == 'table' then - print('branch', k) - v = setmetatable(v, { - __index = function(tt, kk) - print('get', k, kk) - return rawget(t.player, kk) - end, - __newindex = function(tt, kk, vv) - if type(vv) == 'table' then - print('_branch', k, kk) - vv = setmetatable(vv, { - __index = function(_tt, _kk) - print('_get', k, kk, _kk) - return rawget(t.player[kk], _kk) - end - }) - end - rawset(tt, kk ,vv) - end - }) - end - rawset(t,k,v) - end -}) - -params.player = { - width = 220, - height = 30, - health = { height = 24 }, - power = { height = 6}, - position = {'CENTER', nil, 'CENTER',0,-120 } -} -params.pet = { - width = 180, - height = 25, - - position = {'TOPLEFT', 'player', 'BOTTOMLEFT',0,-4} -} -params.target = { - - position = {'TOPLEFT', 'player', 'TOPRIGHT',4,0} -} -params.focus = { - width = 180, - height = 25, - position = {'BOTTOMRIGHT', 'target', 'TOPRIGHT',0,4} -} - -uf.handler = uf -- so uf.event can work - - -local UpdateUnitAnchor = function(self) - self.nameplate = C_NamePlate.GetNamePlateForUnit(self.unit) - if self.nameplate and self.nameplate.namePlateUnitToken then - self:ClearAllPoints() - self:SetPoint('TOP', self.nameplate, 'BOTTOM', 0, 0) - print('snapping', self.unit, 'to', self.nameplate.namePlateUnitToken) - else - self:ClearAllPoints() - self:SetPoint(unpack(self.anchorPoint)) - end -end - -local SetupButton = function(self, unit, index) - if not buttons[unit][index] then - buttons[unit][index] = CreateFrame('Frame', 'KT'..unit..'Buff'..index, self, 'KTAuraButton') - buttons[unit][index]:SetSize(BUFF_SIZE, BUFF_SIZE) - buttons[unit][index].cooldown:SetHideCountdownNumbers(true) - end - return buttons[unit][index] -end - -uf.unit = function(unit) - if not prototypes[unit] then - return - end - print('|cFFFFFF00unit|r:', unit) - - local c = params[unit] - - if not _G['KT'..unit..'Frame'] then - local new = CreateFrame('Button', 'KT'.. unit .. 'Frame', uf, 'KTUnitFrameTemplate') - new.unit = unit - new.anchorPoint = {new:GetPoint(1)} - new.handler = prototypes[unit] - new.params = c - - --if not db.position[unit] then - db.position[unit] = c.position - --end - new.position = db.position[unit] - - - buttons[unit] = {} - new.buttons = buttons[unit] - new.refresh = prototypes[unit].refresh - new.init = prototypes[unit].init - - new:EnableMouse(true) - new:SetScript('OnMouseUp', prototypes[unit].OnMouseUp) - - new:SetAttribute("type", "target") - new:SetAttribute("unit", unit) - RegisterUnitWatch(new) - units[unit] = new - end - - return _G['KT'..unit..'Frame'] -end - -uf.ui = function () - for unit, frame in pairs(units) do - frame.handler.refresh(frame) - end -end - -uf.init = function() - uf:RegisterEvent('PLAYER_TARGET_CHANGED') - uf:RegisterEvent('PLAYER_FOCUS_CHANGED') - uf:RegisterUnitEvent("UNIT_AURA") -end - -uf.variables = function() - if not FossilDB then - FossilDB = { - units = {'player', 'target', 'focus', 'pet', 'targettarget' }, - position = {} - } - end - db = FossilDB - - for i, unit in pairs(db.units) do - print(unit) - local frame = uf.unit(unit) - if frame then - frame.handler.init(frame) - end - end - uf.ui() -end - -uf.event = function(self, event, ...) - if self.handler[event] then - self.handler[event](self, event, ...) - end - return true -end - -uf.PLAYER_TARGET_CHANGED = function() - print('caught target change') - units.target:refresh() -end - -uf.PLAYER_FOCUS_CHANGED = function() - units.focus:refresh() -end - -prototypes.player = {} -local player = prototypes.player -player.init = function(self) - self:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", self.unit) - self:RegisterUnitEvent("UNIT_POWER_FREQUENT", self.unit) - self:RegisterEvent("NAME_PLATE_UNIT_ADDED") - self:RegisterEvent("NAME_PLATE_UNIT_REMOVED") - self:RegisterEvent("UNIT_TARGET") - self:SetScript('OnEvent', uf.event) - - local anchor, parent, relative, x, y = unpack(self.position) - if parent and units[parent] then - parent = units[parent] - else - parent = UIParent - end - - self:SetPoint(anchor, parent, relative, x, y) - self:SetSize(self.params.width, self.params.height) - -end - - ---- Runs when event handler decides so -player.refresh = function(self) - print(self.unit, UnitExists(self.unit)) - if not UnitExists(self.unit) then - print('hiding unit') - self:Hide() - return - end - - self:Show() - if UnitIsPlayer(self.unit) then - local class, classFile = UnitClass(self.unit) - if classFile then - self.healthbar:SetColorTexture(RAID_CLASS_COLORS[classFile].r, RAID_CLASS_COLORS[classFile].g, RAID_CLASS_COLORS[classFile].b) - end - elseif UnitIsFriend('player', self.unit) then - self.healthbar:SetColorTexture(0,.75,0,1) - elseif UnitIsEnemy('player', self.unit) then - self.healthbar:SetColorTexture(1,0,0,1) - else - self.healthbar:SetColorTexture(1,1,0,1) - end - self.powertype = UnitPowerType(self.unit) - if self.powertype then - self.powerbar:SetColorTexture(0,.3,1, 1) - - self.handler.UNIT_POWER_FREQUENT(self) - else - self.healthbar:SetHeight(params[self.unit].health.height + params[self.unit].power.height) - end - uf.UNIT_AURA(self, 'UNIT_AURA', self.unit) - - self.handler.UNIT_HEALTH_FREQUENT(self) -end - - -uf.UNIT_AURA = function(self, event, unit) - if not units[unit] then return true end - - local buffOffset = 0 - local buttons = buttons[unit] - for i = 1, 16 do - - local aura, _, texture, count, dispelType, duration, expires, caster = UnitAura(unit, i, 'HARMFUL') - if aura then - local button = SetupButton(units[unit], unit, i) - - button.icon:SetTexture(texture) - button.cooldown:SetCooldown(expires - duration, duration) - button.cooldown:Show() - button.count:SetText(count > 0 and count or nil) - button:SetPoint('BOTTOMLEFT', units[unit], 'TOPLEFT', buffOffset* BUFF_SIZE, 2) - button:Show() - buffOffset = buffOffset + 1 - else - if buttons[i] then - buttons[i]:Hide() - end - end - end - return true -end - -player.NAME_PLATE_UNIT_ADDED = function(self, event, nameplate) - --UpdateUnitAnchor(self) -end -player.NAME_PLATE_UNIT_REMOVED = function(self, event, nameplate) - --UpdateUnitAnchor(self) -end - -player.UNIT_HEALTH_FREQUENT = function(self, ...) - if UnitHealthMax(self.unit) > 0 then - self.healthbar:SetWidth(self.params.width * UnitHealth(self.unit) / UnitHealthMax(self.unit)) - self.healthtext:SetText(UnitHealth(self.unit)) - else - self.healthbar:SetWidth(PLAYER_WIDTH) - self.healthtext:SetText(nil) - end - return true -end - -player.UNIT_POWER_FREQUENT = function(self) - if UnitPowerMax(self.unit) > 0 then - self.powerbar:SetWidth(self.params.width * UnitPower(self.unit) / UnitPowerMax(self.unit)) - self.powertext:SetText(UnitPower(self.unit)) - else - self.powerbar:Hide() - self.powertext:SetText(nil) - end - return true -end - - -player.UNIT_TARGET = function(self, ...) - if not UnitExists(self.unit) then - self:Hide() - else - self:Show() - self.handler.refresh(self) - end -end - -prototypes.pet = player -prototypes.target = player -prototypes.focus = player \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f SkeletonUnit/UnitFrame.xml --- a/SkeletonUnit/UnitFrame.xml Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ - - - - - - - - - \ No newline at end of file diff -r 34a2e8d93448 -r d5e6b2265d6f libKT/libKT-1.0.lua --- a/libKT/libKT-1.0.lua Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +0,0 @@ ---[[ Implements --- KT.register(frame) to hook the following (all optional): --- frame:init() run immediately after KT sets itself up --- frame:profile("Name-TruncatedRealm") called the first time SavedVars data becomes available --- frame:variables() called by PLAYER_ENTERING_WORLD --- frame:event(event, ...) replaces the event callback --- frame:ui() called by /ui when activating -]]-- - ---GLOBALS: LibKT, KrakTool, KTErrorFrame, LibKTError, SlashCmdList, SLASH_RL1, SLASH_UI1 -local CreateFrame, debugstack, tostring, select = CreateFrame, debugstack, tostring, select -local print, max, unpack, tinsert = print, max, unpack, tinsert -local ipairs, xpcall = ipairs, xpcall -local UI_TOGGLE = false - -KrakTool = CreateFrame('Frame', 'KrakTool', UIParent) -LibKT = select(2, ...) -local KT = LibKT -KT.handler = KrakTool -KT.frames = {} - -SLASH_RL1 = "/rl" -SlashCmdList.RL = function () - ReloadUI() -end - -SLASH_UI1 = "/ui" -SlashCmdList.UI = function () - if UI_TOGGLE then - UI_TOGGLE = false - else - UI_TOGGLE = true - end - for i, frame in pairs(KT.frames) do - if UI_TOGGLE then - if frame.close then - frame.close() - else - frame:Hide() - end - else - if frame.ui then - frame.ui() - end - frame:Show() - end - end -end - -LibKTError = function(msg) - local dstack = debugstack() - :gsub("Interface\\AddOns\\",'~\\') - :gsub("<(.-)>", function(a) return '|cFF00FFFF<'.. a ..'>|r' end) - KTErrorFrame.errmsg:SetText(msg) - KTErrorFrame.debugstack:SetText(dstack) - KTErrorFrame:SetHeight(KTErrorFrame.debugstack:GetStringHeight() + KTErrorFrame.errmsg:GetStringHeight() + 12) - KTErrorFrame:Show() -end - -local initStack = {} -local eventStub = function(self, event, ...) - local isHandled - local nodebug - - if self.event then - nodebug = self.event(self, event, ...) - end - - if self[event] then - nodebug = nodebug or self[event](self, event, ...) - self.missed = 0 - self.handled = self.handled + 1 - isHandled = true - else - self.firstEvent = false - self.unhandled = self.unhandled + 1 - self.missed = self.missed + 1 - end - - if nodebug then - return - end - - print(self:GetName(), event, ...) - - -- debug outputs - if self.status then - self.status:SetText(event .. '\n|cFF00FF00' .. self.handled .. '|r |cFFFF8800' .. self.missed .. '|r |cFFFF4400' .. self.unhandled .. '|r') - if isHandled then - self.status:SetTextColor(0,1,0) - if self.log then - local logtext = event - for i = 1, select('#',...) do - logtext = logtext .. '\n' .. i .. ':' .. tostring(select(i,...)) - end - self.log:SetText('|cFFFFFF00last|r\n' .. logtext) - local newWidth = self.log:GetStringWidth() - - if self.logfirst then - if not self.firstEvent then - self.firstEvent = event - self.logfirst:SetText('|cFF00FF88first|r\n' .. logtext) - end - - newWidth = newWidth + self.logfirst:GetStringWidth() - end - if self.logdiff then - if not event ~= self.firstEvent then - self.firstEvent = event - self.logdiff:SetText('|cFF0088FFdiff|r\n' .. logtext) - end - newWidth = newWidth + self.logdiff:GetStringWidth() - end - --self:SetWidth(newWidth) - end - else - self.status:SetTextColor(1,0,0) - end - end -end - -KT.register = function(frame, name, noGUI) - if not name then - name = frame:GetName() - end - - KT.frames[name] = frame - frame:SetScript('OnEvent', eventStub) - frame.unhandled = 0 - frame.missed = 0 - frame.handled = 0 - frame.firstEvent = false - tinsert(initStack, frame) - - if noGUI then - return - end - - frame.UIPanelAnchor = {'TOPLEFT', frame, 'TOPLEFT', 12, -12 } - frame.UIPanelGrowth = {'TOPLEFT', 'TOPRIGHT', 14, 0} - frame.button = KT.button - frame.uibutton = KT.uibutton - frame.tab = KT.tab - frame.print = KT.print - - return KT -end - -KT.handler:RegisterEvent('VARIABLES_LOADED') -KT.handler:SetScript('OnEvent', function(self, event, ...) - print('KrakTool', event, ...) - if not LibKTDB then - LibKTDB = {} - end - KT.db = LibKTDB - - KT.db.runcount = KT.db.runcount or 1 - KT.db.runcount = KT.db.runcount + 1 - print(KT.db.runcount) - - for i, frame in ipairs(initStack) do - print('|cFF00FF00', i, '|r', frame:GetName()) - if frame.init then - xpcall(frame.init, LibKTError) - end - end - - self:RegisterEvent('PLAYER_ENTERING_WORLD') - self:SetScript('OnEvent', function() - for i, frame in ipairs(initStack) do - print('|cFF00FFFF', i, '|r', frame:GetName()) - if frame.variables then - xpcall(frame.variables, LibKTError) - end - end - end) -end) - -KT.print = function(module, ...) - print('|cFF00FFFF'..module:GetName()..'|r:', ...) -end - ---- Button generators - -local GetButtonTemplate = function(name, parent, template, onClick) - if _G[name] then - return _G[name] - end - - local button = CreateFrame('Button', name, parent, template) - button:SetScript('OnMouseUp', onClick) - return button -end - -local SetButtonAnchor = function(self, collector, anchor, growth) - if self:GetID() == 0 then - self:SetID(#collector) - print('registered TabButton #', self:GetID()) - end - - if self:GetID() == 1 then - self:SetPoint(unpack(anchor)) - else - growth[2] = collector[self:GetID()-1] - self:SetPoint(unpack(growth)) - end -end - -KT.tab = function(self, name, tooltip, texture, coords) - local button = GetButtonTemplate(name, self, 'KTTabButton', self.SelectTab) - button.icon:SetTexture(texture) - button.tooltip = tooltip - button:SetSize(unpack(self.tabSize)) - if coords then - button.icon:SetTexCoord(unpack(coords)) - end - SetButtonAnchor(button, self.tabButtons, self.tabAnchor, self.tabGrowth) - return button -end - -KT.button = function(self, name, text, tooltip, onClick) - local button = GetButtonTemplate(name, self, 'KTButton', onClick) - - button.tooltip = tooltip - button:SetText(text) - button:SetWidth(max(button:GetWidth(), button:GetFontString():GetStringWidth() + 12)) - - SetButtonAnchor(button, self.controls, self.controlsAnchor, self.controlsGrowth) - return button -end - -KT.uibutton = function(self, name, text, tooltip, onClick, texture, coords) - local button = GetButtonTemplate(name, self, 'KTUIPanelButton', onClick) - - button.tooltip = tooltip - button:SetText(text) - button.icon:SetTexture(texture) - button:SetWidth(button:GetFontString():GetStringWidth() + button.icon:GetWidth()/1.5) - if coords then - button.icon:SetTexCoord(unpack(coords)) - end - SetButtonAnchor(button, self.UIPanels, self.UIPanelAnchor, self.UIPanelGrowth) - return button -end diff -r 34a2e8d93448 -r d5e6b2265d6f libKT/libKT-1.0.xml --- a/libKT/libKT-1.0.xml Fri Aug 05 19:50:52 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,249 +0,0 @@ - - -