From 6f70741c40b9f8bbc7cd6bd37ebf00d093dd08f7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 6 May 2016 15:29:04 +0200 Subject: [PATCH] Implemented the gui settings for target and focus, implemented growOrder, added in skeleton for sorting, added debug options. --- Vect.lua | 310 ++++++++++++++++++++++++++++++++++++++++++----- Vect.toc | 5 +- data/global.lua | 1 + data/options.lua | 197 ++++++++++++++++++++++++++++++ 4 files changed, 484 insertions(+), 29 deletions(-) create mode 100644 data/options.lua diff --git a/Vect.lua b/Vect.lua index 1bf6a23..cbcab9c 100644 --- a/Vect.lua +++ b/Vect.lua @@ -1,4 +1,9 @@ +--TODOS: +--Enable/disable on frames +--Player Entering World -> cleanup the db +--CD Sort Order + --"Globals" local ALLOCATE_FRAME_NUM = 5; @@ -7,6 +12,8 @@ local aceCDialog = LibStub("AceConfigDialog-3.0") local aceConfig = LibStub("AceConfig-3.0") local libSharedMedia = LibStub("LibSharedMedia-3.0") +Vect.MovableFrames = nil + Vect.targets = { ["target"] = nil, ["focus"] = nil @@ -23,41 +30,51 @@ Vect.defaults = { profile = { enabled = true, locked = true, - spellDebug = false; + debugLevel = 0, + spellCastDebug = false, + spellAuraDebug = false, + allCDebug = false, target = { enabled = true, - size = 23, - xPos = -150, - yPos = -125 + size = 27, + xPos = 350, + yPos = 350, + growOrder = 2, + sortOrder = 5 }, focus = { enabled = true, - size = 23, - xPos = 200, - yPos = -28 + size = 27, + xPos = 380, + yPos = 380, + growOrder = 2, + sortOrder = 5 } } } function Vect:Reset() - self.cds = {} - self.target = {unitGUID = -1, timers = {}} - self.focus = {unitGUID = -1, timers = {}} + Vect.cds = {} + Vect.target = {unitGUID = -1, timers = {}} + Vect.focus = {unitGUID = -1, timers = {}} end function Vect:OnInitialize() self.db = aceDB:New("VectDB", self.defaults); - self.db.RegisterCallback(self, "OnProfileChanged", function() self:ApplySettings() end) - self.db.RegisterCallback(self, "OnProfileCopied", function() self:ApplySettings() end) - self.db.RegisterCallback(self, "OnProfileReset", function() self:ApplySettings() end) + self.db.RegisterCallback(self, "OnProfileChanged", function() self:ApplySettings() end); + self.db.RegisterCallback(self, "OnProfileCopied", function() self:ApplySettings() end); + self.db.RegisterCallback(self, "OnProfileReset", function() self:ApplySettings() end); self:Print(self.appName .. " v. " .. Vect.version .. ". Chat command is /vect"); - --AceConfig:RegisterOptionsTable(self.appName, self:getOptions()) - self:RegisterChatCommand("vect", "ChatCommand") + aceConfig:RegisterOptionsTable("Vect", self:GetVectOptions()); + aceCDialog:AddToBlizOptions("Vect"); + + self:RegisterChatCommand("vect", "ChatCommand"); end function Vect:OnEnable() - --local db = self.db.profile self:Reset() + self:RegisterEvent("PLAYER_ENTERING_WORLD") + self:RegisterEvent("ZONE_CHANGED_NEW_AREA") self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") self:RegisterEvent("PLAYER_TARGET_CHANGED") self:RegisterEvent("PLAYER_FOCUS_CHANGED") @@ -68,7 +85,7 @@ end function Vect:OnDisable() - --TODO: cleanup + self.Reset(); end @@ -80,12 +97,26 @@ function Vect:COMBAT_LOG_EVENT_UNFILTERED(_, timestamp, eventType, srcGUID, srcN dstGUID, dstName, dstFlags, spellID, spellName, spellSchool, detail1, detail2, detail3) local db = Vect.db.profile; - if db["spellDebug"] then + + --debugAll + if db["allCDebug"] then self:Print("eventType: " .. eventType .. " id: " .. spellID .. " spellName: " .. spellName); end + --debugAura + if db["spellAuraDebug"] then + if eventType == "SPELL_AURA_APPLIED" or eventType == "SPELL_AURA_REMOVED" or eventType == "SPELL_AURA_APPLIED_DOSE" or + eventType == "SPELL_AURA_REMOVED_DOSE" or eventType == "SPELL_AURA_REFRESH" or eventType == "SPELL_AURA_BROKEN" or + eventType == "SPELL_AURA_BROKEN_SPELL" then + self:Print("eventType: " .. eventType .. " id: " .. spellID .. " spellName: " .. spellName); + end + end + if eventType == "SPELL_CAST_SUCCESS" or eventType == "SPELL_AURA_APPLIED" then - --self:Print("id: " .. spellID .. " spellName: " .. spellName); + --debug spell + if db["spellCastDebug"] and eventType == "SPELL_CAST_SUCCESS" then + self:Print("id: " .. spellID .. " spellName: " .. spellName); + end if Vect.spells[spellID] then Vect:AddCd(srcGUID, spellID); @@ -106,7 +137,15 @@ function Vect:PLAYER_FOCUS_CHANGED() end function Vect:PLAYER_ENTERING_WORLD() + --TODO clean up the db +end +function Vect:ZONE_CHANGED_NEW_AREA() + local type = select(2, IsInInstance()) + -- If we are entering an arena + if (type == "arena") then + self:Reset(); + end end --gets called when a cd is finished, reassigns the cds to frames. @@ -116,8 +155,12 @@ function Vect:ReassignCds(which) local frame = Vect.frames[which][i]["frame"]; frame:Hide(); end + --check if frames are unlocked + if not Vect.db.profile["locked"] then return end; --check if we have cooldown for that unit - if not self.cds[self.targets[which]] then return end + if not self.cds[self.targets[which]] then return end; + --sort them + Vect:SortCDs(which); --let's fill them up local i = 1; for k, v in pairs(self.cds[self.targets[which]]) do @@ -178,10 +221,14 @@ function Vect:CdRemoval(srcGUID, resetArray) end end +function Vect:SortCDs(which) + --TODO +end + function Vect:CreateFrames(which) for i = 1, 23 do local frame = CreateFrame("Frame", nil, UIParent, nil); - frame:SetFrameStrata("BACKGROUND"); + frame:SetFrameStrata("MEDIUM"); frame:SetWidth(150); frame:SetHeight(150); if i == 1 then @@ -202,17 +249,32 @@ function Vect:CreateFrames(which) end end -function Vect:MoveTimersStop(which, x, y, size) +function Vect:MoveTimersStop(which) + local db = Vect.db.profile; + local x = db[which]["xPos"]; + local y = db[which]["yPos"]; + local size = db[which]["size"]; + local growOrder = db[which]["growOrder"]; + for i = 1, 23 do local frame = Vect.frames[which][i]["frame"]; frame:ClearAllPoints(); - frame:SetFrameStrata("BACKGROUND"); + frame:SetFrameStrata("MEDIUM"); frame:SetWidth(size); frame:SetHeight(size); local text = Vect.frames[which][i]["texture"]; text:SetAllPoints(frame); frame.texture = text; - frame:SetPoint("CENTER", x + ((i - 1) * size), y); + --set them based on the grow type + if growOrder == "1" then --Up + frame:SetPoint("BOTTOMLEFT", x, y + ((i - 1) * size)); + elseif growOrder == "2" then --Right + frame:SetPoint("BOTTOMLEFT", x + ((i - 1) * size), y); + elseif growOrder == "3" then --Down + frame:SetPoint("BOTTOMLEFT", x, y - ((i - 1) * size)); + else --Left + frame:SetPoint("BOTTOMLEFT", x - ((i - 1) * size), y); + end local CoolDown = Vect.frames[which][i]["cooldown"]; CoolDown:SetAllPoints(); --frame:Show(); @@ -221,11 +283,11 @@ end function Vect:ApplySettings() local db = Vect.db.profile; - --self:Print(db["target"]["yPos"]); - Vect:MoveTimersStop("target", db["target"]["xPos"], db["target"]["yPos"], db["target"]["size"]); - Vect:MoveTimersStop("focus", db["focus"]["xPos"], db["focus"]["yPos"], db["focus"]["size"]); + Vect:MoveTimersStop("target"); + Vect:MoveTimersStop("focus"); Vect:ReassignCds("target"); Vect:ReassignCds("focus"); + if not db["locked"] then self:ShowMovableFrames() end; end function Vect:VOnTimerUpdate(which) @@ -238,4 +300,198 @@ function Vect:VOnTimerUpdate(which) self:ReassignCds(which); end end +end + +--Utility Functions for the options + +--enable +function Vect:isEnabled() + local db = Vect.db.profile; + return db["enabled"]; +end + +function Vect:setEnabledOrDisabled(enable) + if enable then + Vect:Enable() + else + Vect:Disable() + end +end + +function Vect:isPartEnabled(which) + local db = Vect.db.profile; + return db[which]["enabled"]; +end + +function Vect:SetPartEnabledOrDisabled(which, enable) + local db = Vect.db.profile; + db[which]["enabled"] = enable; + +end + +--lock +function Vect:isLocked() + return Vect.db.profile["locked"]; +end + +function Vect:LockFrames() + self:MoveTimersStop("target"); + self:MoveTimersStop("focus"); + self:HideMovableFrames() + self:ReassignCds("target"); + self:ReassignCds("focus"); +end + +function Vect:UnlockFrames() + --this will hide the frames + self:ReassignCds("target"); + self:ReassignCds("focus"); + Vect:ShowMovableFrames(); +end + +function Vect:HideMovableFrames() + if not Vect.MovableFrames then return end; + --Hide them + for k, v in pairs(Vect.MovableFrames) do + v["frame"]:EnableMouse(false); + v["frame"]:SetMovable(false); + v["frame"]:Hide(); + end +end + +function Vect:ShowMovableFrames() + local db = Vect.db.profile; + --Create them if they doesn't exists + if not Vect.MovableFrames then + Vect.MovableFrames = {} + for i = 1, 2 do + local frame = CreateFrame("Frame", nil, UIParent, nil); + frame:SetFrameStrata("BACKGROUND"); + frame:SetScript("OnDragStart", function() self:MovableFrameDragStart() end) + frame:SetScript("OnDragStop", function() self:MovableFrameDragStop() end) + local text = frame:CreateTexture(); + text:SetTexture("Interface\\Icons\\Spell_Arcane_Blink") + text:SetAllPoints(frame); + frame.texture = text; + + local which = ""; + if i == 1 then + which = "target"; + elseif i == 2 then + which = "focus"; + end + + frame.DragID = which; + + Vect.MovableFrames[i] = {} + Vect.MovableFrames[i]["frame"] = frame; + Vect.MovableFrames[i]["texture"] = text; + end + end + + --Show, resize them + for k, v in pairs(Vect.MovableFrames) do + v["frame"]:EnableMouse(true) + v["frame"]:SetMovable(true) + v["frame"]:RegisterForDrag("LeftButton") + v["frame"]:SetPoint("BOTTOMLEFT", db[v["frame"].DragID]["xPos"], db[v["frame"].DragID]["yPos"]); + v["frame"]:SetWidth(db[v["frame"].DragID]["size"]); + v["frame"]:SetHeight(db[v["frame"].DragID]["size"]); + v["frame"]:Show(); + end +end + +function Vect:MovableFrameDragStart() + this:StartMoving(); +end + +function Vect:MovableFrameDragStop() + local db = Vect.db.profile; + db[this.DragID]["xPos"] = this:GetLeft(); + db[this.DragID]["yPos"] = this:GetBottom(); + --Vect:Print(this:GetLeft() .. " " .. this:GetBottom()); + this:StopMovingOrSizing(); +end + +--size Functions + +function Vect:getFrameSize(which) + local db = Vect.db.profile; + return db[which]["size"]; +end + +function Vect:setFrameSize(which, size) + local db = Vect.db.profile; + db[which]["size"] = size; + + Vect:MoveTimersStop(which) + + if not db["locked"] then + Vect:ShowMovableFrames(); + end +end + +--Grow Order +function Vect:getGrowOrder(which) + local db = Vect.db.profile; + return db[which]["growOrder"]; +end + +function Vect:setGrowOrder(which, v) + local db = Vect.db.profile; + db[which]["growOrder"] = v; + Vect:MoveTimersStop(which) +end + +--Sort Order +function Vect:getSortOrder(which) + local db = Vect.db.profile; + return db[which]["sortOrder"]; +end + +function Vect:setSortOrder(which, v) + local db = Vect.db.profile; + db[which]["sortOrder"] = v; + Vect:ReassignCds(which); +end + +--Debug settings +function Vect:getDebugLevel() + local db = Vect.db.profile; + return db["debugLevel"]; +end + +function Vect:setDebugLevel(v) + local db = Vect.db.profile; + db["debugLevel"] = v; +end + +function Vect:getSpellCastDebug() + local db = Vect.db.profile; + return db["spellCastDebug"]; +end + +function Vect:setSpellCastDebug(v) + local db = Vect.db.profile; + db["spellCastDebug"] = v; +end + +function Vect:getSpellAuraDebug() + local db = Vect.db.profile; + return db["spellAuraDebug"]; +end + +function Vect:setSpellAuraDebug(v) + local db = Vect.db.profile; + db["spellAuraDebug"] = v; +end + +function Vect:getAllCDebug() + local db = Vect.db.profile; + return db["allCDebug"]; +end + +function Vect:setAllCDebug(v) + local db = Vect.db.profile; + db["allCDebug"] = v; end \ No newline at end of file diff --git a/Vect.toc b/Vect.toc index c670405..9196a8b 100644 --- a/Vect.toc +++ b/Vect.toc @@ -4,11 +4,12 @@ ## Title: Vect ## Notes: Verot's Enemy Cooldown Tracker. ## DefaultState: Enabled -## OptionalDeps: Ace3, LibSharedMedia-3.0 +## OptionalDeps: Ace3 ## SavedVariables: VectDB -## Version: 0.1 +## Version: 0.75 embeds.xml data\global.lua data\spells.lua +data\options.lua Vect.lua diff --git a/data/global.lua b/data/global.lua index 1347800..06e3238 100644 --- a/data/global.lua +++ b/data/global.lua @@ -1,3 +1,4 @@ + Vect = LibStub("AceAddon-3.0"):NewAddon("Vect", "AceConsole-3.0", "AceEvent-3.0") Vect.appName = "Vect" Vect.dbName = "VectDB" diff --git a/data/options.lua b/data/options.lua new file mode 100644 index 0000000..4f872f7 --- /dev/null +++ b/data/options.lua @@ -0,0 +1,197 @@ + +local adbo = LibStub("AceDBOptions-3.0") + +function Vect:GetVectOptions() + local db = self.db.profile; + local options = { + type = "group", name = "Vect", childGroups = "tab", + args = { + enabled = { + type = "toggle", name = "Enabled", desc = "Enable/Disable the addon", order = 0, + get = function() return Vect:IsEnabled() end, + set = function(_, v) + Vect:setEnabledOrDisabled(v); + end + }, + lock = { + type = "toggle", name = "Lock", desc = "Uncheck to move the frames", order = 1, + get = function() return Vect:isLocked() end, + set = function(_, v) + db.locked = v; + if v then Vect:LockFrames() else Vect:UnlockFrames() end; + end + }, + targetandfocus = { + type = "group", name = "T. and F. CDs", desc = "Cooldown frame's settings.", childGroups = "tab", order = 3, + args = Vect:getTargetandFocusOptions(); + }, + droptions = { + type = "group", name = "T. and F. DRs", desc = "DR frame's settings.", childGroups = "tab",order = 4, + args = Vect:getDROptions(); + }, + selfdr = { + type = "group", name = "Self DRs", desc = "Self DR frame's settings.", childGroups = "tab",order = 5, + args = Vect:getSelfDROptions() + }, + debugoptions = { + type = "group", name = "Debug", desc = "Debug settings.", childGroups = "tab",order = 6, + args = Vect:getDebugOptions(); + } + } + } + return options; +end + +function Vect:getTargetandFocusOptions() + local args = { + targetHeader = { + type = "header", name = "Target's settings", order = 10 + }, + targettoggle = { + type = "toggle", name = "Target", desc = "Enable/Disable showing the target's cooldowns", order = 3, + get = function() return Vect:isPartEnabled("target") end, + set = function(_, v) + Vect:SetPartEnabledOrDisabled("target", v); + end + }, + targetrange = { + type = "range", name = "Target's size", order = 11, min = 10, max = 150, step = 1, + get = function() return Vect:getFrameSize("target") end, + set = function(_, v) + Vect:setFrameSize("target", v); + end + + }, + targetGrowSelect = { + type = "select", style = "dropdown", name = "targetGrow", + desc = "Change which way the target's cooldowns will grow", order = 12, + values = { + ["1"] = "Up", + ["2"] = "Right", + ["3"] = "Down", + ["4"] = "Left" + }, + get = function() return Vect:getGrowOrder("target") end, + set = function(_, v) + Vect:setGrowOrder("target", v); + end + }, + targetSortSelect = { + type = "select", style = "dropdown", name = "targetSortOrder", + desc = "Change the target's cooldowns's sort order", order = 13, + values = { + ["1"] = "Ascending", + ["2"] = "Descending", + ["3"] = "Recent first", + ["4"] = "Recent Last", + ["5"] = "Random" + }, + get = function() return Vect:getSortOrder("target") end, + set = function(_, v) + Vect:setSortOrder("target", v); + end + }, + focusHeader = { + type = "header", name = "Focus's settings", order = 14 + }, + focustoggle = { + type = "toggle", name = "Focus", desc = "Enable/Disable showing the focus's cooldowns", order = 8, + get = function() return Vect:isPartEnabled("focus") end, + set = function(_, v) + Vect:SetPartEnabledOrDisabled("focus", v); + end + }, + focusRange = { + type = "range", name = "Focus's size", order = 15, min = 10, max = 150, step = 1, + get = function() return Vect:getFrameSize("focus") end, + set = function(_, v) + Vect:setFrameSize("focus", v); + end + }, + focusGrowSelect = { + type = "select", style = "dropdown", name = "focusGrow", + desc = "Change which way the focus's cooldowns will grow", order = 16, + values = { + ["1"] = "Up", + ["2"] = "Right", + ["3"] = "Down", + ["4"] = "Left" + }, + get = function() return Vect:getGrowOrder("focus") end, + set = function(_, v) + Vect:setGrowOrder("focus", v); + end + }, + focusSortSelect = { + type = "select", style = "dropdown", name = "focusSortOrder", + desc = "Change the focus's cooldowns's sort order", order = 17, + values = { + ["1"] = "Ascending", + ["2"] = "Descending", + ["3"] = "Recent first", + ["4"] = "Recent Last", + ["5"] = "Random" + }, + get = function() return Vect:getSortOrder("focus") end, + set = function(_, v) + Vect:setSortOrder("focus", v); + end + } + } + return args; +end + +--order 20-40 +function Vect:getDROptions() + local args = { + + } + return args; +end + +--order 40-50 +function Vect:getSelfDROptions() + local args = { + + } + return args; +end + +--order 50+ +function Vect:getDebugOptions() + local args = { + spellcast = { + type = "toggle", name = "SpellCast", desc = "Enable/Disable writing out SPELL_CAST_SUCCESS events.", order = 50, + get = function() return Vect:getSpellCastDebug() end, + set = function(_, v) + Vect:setSpellCastDebug(v); + end + }, + spellAura = { + type = "toggle", name = "SpellAura", desc = "Enable/Disablewriting out SPLL_AURA_* events", order = 51, + get = function() return Vect:getSpellAuraDebug() end, + set = function(_, v) + Vect:setSpellAuraDebug(v); + end + }, + allLog = { + type = "toggle", name = "Uber debug", desc = "Enable/Disable writing out all combatlog events", order = 52, + get = function() return Vect:getAllCDebug() end, + set = function(_, v) + Vect:setAllCDebug(v); + end + }, + debugselect = { + type = "select", style = "dropdown", name = "debuglevel", + desc = "Change the debuglevel", order = 53, + values = { + ["0"] = "No Messages", + }, + get = function() return Vect:getDebugLevel() end, + set = function(_, v) + Vect:setDebugLevel(v); + end + }, + } + return args; +end