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 LSM = LibStub("LibSharedMedia-3.0") local Boss = RW.BossPrototype local warningProt = {} local mt = {__index = warningProt} local Party = RW.Party local Utils = RW.Utils -- If text is a number this warning is considered not a custom one -- If text is not a number then it is custom and it can be possibly sent as a table, -- then the first value in the table will be the actual text, and the second oen will be the option text as its show in the GUI -- 3rd value in the table will be the tooltip text local spell function Boss:_Warning(wType, text, icon, optionName, default, color, sound) if type(text) == "number" then spell = text return self:_Warning(wType, GetSpellInfo(text), icon or text, optionName or text, default, color, sound) end if type(icon) == "number" then spell = icon return self:_Warning(wType, text, select(3, GetSpellInfo(icon)), optionName or icon, default, color, sound) 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) default = Utils:BuildRoleDefaults(default) local defaults = self:AddDefaults(optionName, "WARNING", wType ~= "CUSTOM" and wType or text[2], default) defaults.flash = true defaults.color = color if wType == "RUNAWAY" and not sound then defaults.sound = "RW: RunAwayLittleGirl" else defaults.sound = sound end 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 = "WARNING", type = wType, text = type(text) == "table" and text[1] or text, optText = type(text) == "table" and text[2] or nil, base = base, }, mt) self.AlertObjects.WARNING = self.AlertObjects.WARNING or {} tinsert(self.AlertObjects.WARNING, obj) spell = nil return obj end function Boss:Warning(...) return self:_Warning("NORMAL", ...) end function Boss:InformWarning(text, icon, optionName, default, color, sound) return self:_Warning("NORMAL", text, icon, optionName, default, color, sound or "Bell") end function Boss:RunawayWarning(...) return self:_Warning("RUNAWAY", ...) end function Boss:CastWarning(...) return self:_Warning("CAST", ...) end function Boss:OnYouWarning(text, icon, optionName, default, color, sound) return self:_Warning("ONYOU", text, icon, optionName, default, color, sound or "Bell") end function Boss:CustomWarning(text, optText, ...) --@debug assert(type(text) == "string", self:GetName()..": CustomWarning, variable \"text\" is not of type text") assert(type(optText) == "string", self:GetName()..": CustomWarning, variable \"optText\" is not of type text") --@end-debug return self:_Warning("CUSTOM", {text, optText}, ...) end function warningProt:Show(...) if not self.base.mod.DB[self.base.id].enabled then return end if not Utils:EvaluateRoleOption(self.base.mod.DB[self.base.id].WARNING[self.optText or self.type].enabled) then return end local text if self.optText then text = Utils:Format(self.text, ...) else text = Utils:Format(L["FORMAT_WARNING_"..self.type], self.text or ..., ...) end text = Utils:ColorNames(text) local db = self.base.mod.DB local color = db[self.base.id].WARNING[self.optText or self.type].color local sound = db[self.base.id].WARNING[self.optText or self.type].sound local flash = db[self.base.id].WARNING[self.optText or self.type].flash if type(color) == "string" then -- Add color plugin stuff here color = nil end RW.Callbacks:Fire("WarningShow", text, self.base.icon, color, sound, flash) end local function showMessage(message, ...) message:Show(...) end function warningProt:Schedule(stime, info, ...) self.base.mod:Schedule("WARNING"..self.base.id..(info or ""), stime, showMessage, self, info, ...) tinsert(self.base.scheduled, "WARNING"..self.base.id..(info or "")) end function warningProt:ScheduleRepeating(stime, now, info, ...) self.base.mod:ScheduleRepeating("WARNING"..self.base.id..(info or ""), stime, showMessage, now, self, info, ...) tinsert(self.base.scheduled, "WARNING"..self.base.id..(info or "")) end function warningProt:Unschedule(extraID) self.base.mod:Unschedule("WARNING"..self.base.id..(extraID or "")) Utils:TRemove(self.base.scheduled, "WARNING"..self.base.id..(extraID or "")) end -- Options function warningProt: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("") -- Workaround for old non-default values if type(boss.DB[self.base.id].WARNING[self.optText or self.type].enabled) ~= "table" then boss.DB[self.base.id].WARNING[self.optText or self.type].enabled = boss.defaults[self.base.id].WARNING[self.optText or self.type].enabled end -- End workaroudn local enabledDrop = UIF:MultiSelectDropdown(L.ENABLED, boss.DB[self.base.id].WARNING[self.optText or self.type].enabled, nil, Utils.Constants.EnableList, 0.5) if self.type == "CUSTOM" then subGroup:SetTitle(self.optText) else subGroup:SetTitle(L["WARNING_"..self.type]) end local color = UIF:ColorSelect(L.COLOR, boss.DB[self.base.id].WARNING[self.optText or self.type], "color", nil, nil, 0.3) local drop = UIF:LSMDropdown("sound", L.SOUND, boss.DB[self.base.id].WARNING[self.optText or self.type], "sound", nil, 0.5) local flash = UIF:CheckBox(L.FLASH, boss.DB[self.base.id].WARNING[self.optText or self.type], "flash", nil, nil, 0.3) local reset = UIF:Button(L.RESET, function() boss.DB[self.base.id].WARNING[self.optText or self.type].color = boss.defaults[self.base.id].WARNING[self.optText or self.type].color boss.DB[self.base.id].WARNING[self.optText or self.type].sound = boss.defaults[self.base.id].WARNING[self.optText or self.type].sound boss.DB[self.base.id].WARNING[self.optText or self.type].enabled = boss.defaults[self.base.id].WARNING[self.optText or self.type].enabled boss.DB[self.base.id].WARNING[self.optText or self.type].flash = boss.defaults[self.base.id].WARNING[self.optText or self.type].flash if type(boss.defaults[self.base.id].WARNING[self.optText or self.type].enabled) == "table" then for i, v in pairs(boss.defaults[self.base.id].WARNING[self.optText or self.type].enabled) do boss.DB[self.base.id].WARNING[self.optText or self.type].enabled[i] = v enabledDrop:SetItemValue(i, v) end else boss.DB[self.base.id].WARNING[self.optText or self.type].enabled = boss.defaults[self.base.id].WARNING[self.optText or self.type].enabled end drop:SetValue(boss.DB[self.base.id].WARNING[self.optText or self.type].sound) local colorvalue = boss.DB[self.base.id].WARNING[self.optText or self.type].color or nil if colorvalue then if type(colorvalue) == "table" then color:SetColor(unpack(colorvalue)) else -- Add color plugins stuff here color:SetColor("") end else color:SetColor("") end drop:SetValue(boss.DB[self.base.id].WARNING[self.optText or self.type].sound) flash:SetValue(boss.DB[self.base.id].WARNING[self.optText or self.type].flash) end) subGroup:AddChild(enabledDrop) subGroup:AddChild(drop) subGroup:AddChild(color) subGroup:AddChild(flash) subGroup:AddChild(reset) return subGroup end