Compare with Previous | Blame | View Log
local RW = LibStub("AceAddon-3.0"):GetAddon("Raid Watch") local L = LibStub("AceLocale-3.0"):GetLocale("RW2-Plugin-Base") local Boss = RW.BossPrototype local directionProt = {} local mt = {__index = directionProt} local Party = RW.Party local Utils = RW.Utils function Boss:HideAllDirections() if not self.AlertObjects.DIRECTION then return end for i, direction in pairs(self.AlertObjects.DIRECTION) do for j, runningID in pairs(direction.running) do RW.Callbacks:Fire("DirectionHide", runningID) direction.running[j] = nil end end end local spell function Boss:_Direction(dType, text, icon, optionName, default) if type(text) == "number" then spell = text return self:_Direction(dType, GetSpellInfo(text), icon or text, optionName or text, default) end if type(icon) == "number" then spell = icon return self:_Direction(dType, text, select(3, GetSpellInfo(icon)), optionName or icon, default) end optionName = type(optionName) == "number" and Utils.SpellName[optionName] or optionName -- If no option name is found by now we use the text as default if not optionName then optionName = type(text) == "table" and text[1] or text end self:AddToCategory(nil, optionName) local defaults = self:AddDefaults(optionName, "DIRECTION", dType ~= "CUSTOM" and dType or text[2], default) local base = self:GetBaseAlertObject(optionName) if not base then base = { icon = icon, id = optionName, spell = spell, mod = self, scheduled = {}, } tinsert(self.BaseAlertObjects, base) end local obj = setmetatable({ mainType = "DIRECTION", type = dType, text = type(text) == "table" and text[1] or text, optText = (dType == "CUSTOM" and type(text) == "table") and text[2] or nil, running = {}, base = base, }, mt) self.AlertObjects.DIRECTION = self.AlertObjects.DIRECTION or {} tinsert(self.AlertObjects.DIRECTION, obj) spell = nil return obj end function Boss:DirectionTo(...) return self:_Direction("TO", ...) end function Boss:DirectionFrom(...) return self:_Direction("FROM", ...) end local function HideArrow(id, self) RW.Callbacks:Fire("DirectionHide", id) Utils:TRemove(self.running, id) end function directionProt:Show(target, time, dist, ...) if not self.base.mod.DB[self.base.id].enabled then return end if not self.base.mod.DB[self.base.id].DIRECTION[self.optText or self.type].enabled then return end local tname, uID = nil, nil if self.base.mod:IsUID(target) then uID = target else tname = target end local away = self.type == "FROM" and dist or nil RW.Callbacks:Fire("DirectionToNameOrUnit", self.type..self.base.id..self.text..(target or ""), uID, tname, away, self.base.spell) tinsert(self.running, self.type..self.base.id..self.text..(target or "")) if time then self.base.mod:Schedule("HideArrow"..target, time, HideArrow, self.type..self.base.id..self.text..(target or ""), self) end end directionProt.Start = directionProt.Show function directionProt:ShowPos(x, y, time, dist, ...) if not self.base.mod.DB[self.base.id].enabled then return end if not self.base.mod.DB[self.base.id].DIRECTION[self.optText or self.type].enabled then return end local away = dist or nil RW.Callbacks:Fire("DirectionToPosition", self.type..self.base.id..self.text..(target or ""), x, y, away, self.base.spell) tinsert(self.running, self.type..self.base.id..self.text..(target or "")) if time then self.base.mod:Schedule("HideArrow"..target, time, HideArrow, self.type..self.base.id..self.text..(target or ""), self) end end function directionProt:Hide(extraID) if not extraID then for i, id in pairs(self.running) do RW.Callbacks:Fire("DirectionHide", id) end wipe(self.running) self:Unschedule() else RW.Callbacks:Fire("DirectionHide", self.type..self.base.id..self.text..(extraID or "")) Utils:TRemove(self.running, extraID) self:Unschedule(extraID) end end local function showArrow(self, target, info, ...) end function directionProt:Schedule(stime, target, info, ...) self.base.mod:Schedule("DIRECTION"..self.base.id..(info or ""), stime, showMessage, self, info, ...) tinsert(self.base.scheduled, "DIRECTION"..self.base.id..(info or "")) end function directionProt:ScheduleRepeating(stime, target, now, info, ...) self.base.mod:ScheduleRepeating("DIRECTION"..self.base.id..(target or ""), stime, showMessage, now, self, info, ...) tinsert(self.base.scheduled, "DIRECTION"..self.base.id..(target or "")) end function directionProt:Unschedule(extraID) self.base.mod:Unschedule("DIRECTION"..self.base.id..(extraID or "")) Utils:TRemove(self.base.scheduled, "DIRECTION"..self.base.id..(extraID or "")) end -- Options function directionProt:GetOption() local Options = RW:GetPlugin("Options") local boss = self.base.mod local AceGUI = LibStub("AceGUI-3.0") local UIF = LibStub("LibGUIFactory-1.0"):GetFactory("RW") local subGroup = UIF:InlineGroup("") local check = UIF:CheckBox(L.ENABLED, boss.DB[self.base.id].DIRECTION[self.optText or self.type], "enabled") subGroup:AddChild(check) return subGroup end