diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/FlashTaskBar.lua b/FlashTaskBar.lua new file mode 100644 index 0000000..e6a5337 --- /dev/null +++ b/FlashTaskBar.lua @@ -0,0 +1,1299 @@ + +local DF = _G ["DetailsFramework"] +if (not DF) then + print ("|cFFFFAA00FlashTaskBar: framework not found, if you just installed or updated the addon, please restart your client.|r") + return +end + +local _ + +local L = LibStub ("AceLocale-3.0"):GetLocale ("FlashTaskbarLocales", true) +if (not L) then + DF:ShowPanicWarning ("FlashTaskbar Locale failed to load, restart your game client to finish addon updates.") + return +end + +--> when true it will print what triggered the flash +local FlashDebug = false + +do + local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") + SharedMedia:Register ("sound", "d_whip1", [[Interface\Addons\FlashTaskBar\sounds\sound_whip1.ogg]]) +end + +local default_config = { + profile = { + readycheck = true, + arena_queue = true, + group_queue = true, + petbattle_queue = true, + brawlers_queue = true, + pull_timers = true, + enter_combat = false, + end_taxi = false, + chat_scan = false, + chat_scan_keywords = {}, + combat_log = false, + combat_log_keywords = {}, + rare_scan = true, + any_rare = true, + rare_names = {}, + disconnect_logout = false, + invite = true, + invite_ignore_on_autoaccept = false, + trade = true, + bags_full = false, + worldpvp = true, + duel_request = true, + summon = true, + fatigue = true, + on_chat_player_name = false, + whisper_blink = true, + battleground_end = false, + timer_start = false, + low_health = false, + lost_health = false, + player_died = true, + + sound_enabled = { + readycheck = {enabled = false, sound = "d_whip1"}, + arena_queue = {enabled = false, sound = "d_whip1"}, + group_queue = {enabled = false, sound = "d_whip1"}, + petbattle_queue = {enabled = false, sound = "d_whip1"}, + brawlers_queue = {enabled = false, sound = "d_whip1"}, + pull_timers = {enabled = false, sound = "d_whip1"}, + enter_combat = {enabled = false, sound = "d_whip1"}, + end_taxi = {enabled = false, sound = "d_whip1"}, + chat_scan = {enabled = false, sound = "d_whip1"}, + combat_log = {enabled = false, sound = "d_whip1"}, + rare_scan = {enabled = false, sound = "d_whip1"}, + disconnect_logout = {enabled = false, sound = "d_whip1"}, + invite = {enabled = false, sound = "d_whip1"}, + trade = {enabled = false, sound = "d_whip1"}, + bags_full = {enabled = false, sound = "d_whip1"}, + worldpvp = {enabled = false, sound = "d_whip1"}, + duel_request = {enabled = false, sound = "d_whip1"}, + summon = {enabled = false, sound = "d_whip1"}, + fatigue = {enabled = false, sound = "d_whip1"}, + on_chat_player_name = {enabled = false, sound = "d_whip1"}, + whisper_blink = {enabled = false, sound = "d_whip1"}, + battleground_end = {enabled = false, sound = "d_whip1"}, + timer_start = {enabled = false, sound = "d_whip1"}, + low_health = {enabled = false, sound = "d_whip1"}, + lost_health = {enabled = false, sound = "d_whip1"}, + player_died = {enabled = false, sound = "d_whip1"}, + }, + } +} + +local options_table = { + name = "FlashTaskBar", + type = "group", + args = { + + } +} +local FlashTaskBar = DF:CreateAddOn ("FlashTaskBar", "FlashTaskbarDB", default_config, options_table) +local lower = string.lower + +--store the address of the original chat func +local ChatFrame_MessageEventHandler_Original = ChatFrame_MessageEventHandler + +FlashTaskBar.last_flash = 0 + +function FlashTaskBar:DoFlash (config_key) + + if (FlashTaskBar.last_flash + 5 < GetTime()) then + if (FlashDebug) then + FlashTaskBar:Msg ("Flash Reason: " .. (config_key or "unknown")) + end + + FlashClientIcon() + local has_sound = FlashTaskBar.db.profile.sound_enabled + if (has_sound and has_sound [config_key] and has_sound [config_key].enabled) then + local file = LibStub:GetLibrary("LibSharedMedia-3.0"):Fetch ("sound", has_sound [config_key].sound) + PlaySoundFile (file, "Master") + end + FlashTaskBar.last_flash = GetTime() + end +end + +function FlashTaskBar.OnInit (self) + + --register slash + SLASH_FLASHTASKBAR1 = "/flashtaskbar" + function SlashCmdList.FLASHTASKBAR (msg, editbox) + + if (msg == "reason") then + FlashDebug = not FlashDebug + FlashTaskBar:Msg ("Flash Reason " .. (FlashDebug and "Enabled" or "Disabled")) + return + end + + InterfaceOptionsFrame_OpenToCategory ("FlashTaskBar") + InterfaceOptionsFrame_OpenToCategory ("FlashTaskBar") + end + + --invite + function FlashTaskBar:DelayInviteCheck() + --if already in a group, ignore the invite call + --but the player might have received a request to join the group + --may be in the future this might need a flash as well + if (IsInGroup() or IsInRaid()) then + return + else + FlashTaskBar:DoFlash("invite") + end + end + + --> wait 2 seconds before flash, other addons may auto answer the group invite + function FlashTaskBar:CheckForGroupInvite() + if (StaticPopup1 and StaticPopup1:IsShown()) then + FlashTaskBar:DoFlash("invite") + end + end + + function FlashTaskBar:PARTY_INVITE_REQUEST() + if (FlashTaskBar.db.profile.invite) then + if (FlashTaskBar.db.profile.invite_ignore_on_autoaccept) then + FlashTaskBar:ScheduleTimer ("DelayInviteCheck", 1.0) + else + FlashTaskBar:ScheduleTimer ("CheckForGroupInvite", 2.0) + end + end + end + FlashTaskBar:RegisterEvent ("PARTY_INVITE_REQUEST") + + --pet battle queue + function FlashTaskBar:CheckPetBattleQueue() + if (PetBattleQueueReadyFrame and PetBattleQueueReadyFrame:IsShown()) then + FlashTaskBar:DoFlash("petbattle_queue") + end + end + function FlashTaskBar:PET_BATTLE_QUEUE_STATUS (...) + if (FlashTaskBar.db.profile.petbattle_queue) then + FlashTaskBar:ScheduleTimer ("CheckPetBattleQueue", 1.5) + end + end + FlashTaskBar:RegisterEvent ("PET_BATTLE_QUEUE_STATUS") + + function FlashTaskBar:UPDATE_BATTLEFIELD_STATUS() + if (FlashTaskBar.db.profile.battleground_end) then + if (WorldStateScoreFrame and WorldStateScoreFrame:IsShown()) then + FlashTaskBar:DoFlash("battleground_end") + end + end + end + FlashTaskBar:RegisterEvent ("UPDATE_BATTLEFIELD_STATUS") + + --premade groups ready + hooksecurefunc ("LFGListInviteDialog_Show", function() + if (FlashTaskBar.db.profile.group_queue) then + FlashTaskBar:DoFlash("group_queue") + FlashTaskBar.last_flash = 0 + end + end) + + --lfg lfpvp windows + hooksecurefunc ("LFGDungeonReadyStatus_ResetReadyStates", function() + if (FlashTaskBar.db.profile.group_queue) then + FlashTaskBar:DoFlash("group_queue") + FlashTaskBar.last_flash = 0 + end + end) + hooksecurefunc ("PVPReadyDialog_Display", function() + if (FlashTaskBar.db.profile.arena_queue) then + FlashTaskBar:DoFlash("arena_queue") + FlashTaskBar.last_flash = 0 + end + end) + + --game master + hooksecurefunc ("HelpFrame_OnEvent", function (self, token) + if (token == "GMRESPONSE_RECEIVED") then + FlashTaskBar:DoFlash("gm_response") + end + end) + + --general alerts + hooksecurefunc ("StaticPopup_Show", function (token, text_arg1, text_arg2, data, insertedFrame) + if (token == "BFMGR_INVITED_TO_ENTER") then --> generic world pvp alert + if (FlashTaskBar.db.profile.worldpvp) then + FlashTaskBar:DoFlash("worldpvp") + end + + elseif (token == "DUEL_REQUESTED" or token == "PET_BATTLE_PVP_DUEL_REQUESTED") then + if (FlashTaskBar.db.profile.duel_request) then + FlashTaskBar:DoFlash("duel_request") + end + + elseif (token == "CONFIRM_SUMMON" or token == "CONFIRM_SUMMON_STARTING_AREA") then + if (FlashTaskBar.db.profile.summon) then + FlashTaskBar:DoFlash("summon") + end + + elseif (token == "CHANNEL_INVITE" or token == "CHAT_CHANNEL_INVITE") then + FlashTaskBar:DoFlash("chat_channel_invite") + + elseif (token == "PARTY_INVITE" or token == "PARTY_INVITE_XREALM") then + if (not FlashTaskBar.db.profile.invite) then + return + end + if (FlashTaskBar.db.profile.invite_ignore_on_autoaccept) then + FlashTaskBar:ScheduleTimer ("DelayInviteCheck", 1.5) + else + FlashTaskBar:DoFlash("invite") + end + + elseif (token == "TRADE_WITH_QUESTION") then + if (FlashTaskBar.db.profile.trade) then + FlashTaskBar:DoFlash("trade") + end + end + + end) + + --brawlers guild + function FlashTaskBar:CHAT_MSG_MONSTER_YELL (event, msg, source, _, _, player_name) + if (player_name == UnitName ("player")) then + if (FlashTaskBar.db.profile.brawlers_queue) then + FlashTaskBar:DoFlash("brawlers_queue") + end + end + end + function FlashTaskBar:CheckForBrawlersGuild() + local zoneName, zoneType, _, _, _, _, _, zoneMapID = GetInstanceInfo() + if (zoneMapID == 369 or zoneMapID == 1043) then + FlashTaskBar:RegisterEvent ("CHAT_MSG_MONSTER_YELL") + else + FlashTaskBar:UnregisterEvent ("CHAT_MSG_MONSTER_YELL") + end + end + function FlashTaskBar:PLAYER_ENTERING_WORLD() + FlashTaskBar:ScheduleTimer ("CheckForBrawlersGuild", 3) + end + function FlashTaskBar:ZONE_CHANGED_NEW_AREA() + FlashTaskBar:ScheduleTimer ("CheckForBrawlersGuild", 3) + end + FlashTaskBar:RegisterEvent ("PLAYER_ENTERING_WORLD") + FlashTaskBar:RegisterEvent ("ZONE_CHANGED_NEW_AREA") + + --pull timers + function FlashTaskBar:CommReceived (_, prefix) + if (not FlashTaskBar.db.profile.pull_timers) then + return + end + if (prefix:find ("PT")) then + FlashTaskBar:DoFlash("pull_timers") + elseif (prefix:find ("BWPull")) then + FlashTaskBar:DoFlash("pull_timers") + end + end + FlashTaskBar:RegisterComm ("D4", "CommReceived") + FlashTaskBar:RegisterComm ("BigWigs", "CommReceived") + + --readycheck + function FlashTaskBar:READY_CHECK() + if (FlashTaskBar.db.profile.readycheck) then + FlashTaskBar:DoFlash("readycheck") + end + end + FlashTaskBar:RegisterEvent ("READY_CHECK") + + --combat + function FlashTaskBar:PLAYER_REGEN_DISABLED() + if (FlashTaskBar.db.profile.enter_combat) then + FlashTaskBar:DoFlash("enter_combat") + end + end + FlashTaskBar:RegisterEvent ("PLAYER_REGEN_DISABLED") + + --taxi + --after a true for UnitOnTaxi, wait until it is false again + local CheckIfFlyingEnded = function (tickObject) + if (not UnitOnTaxi ("player")) then + tickObject:Cancel() + FlashTaskBar:DoFlash("end_taxi") + FlashTaskBar:Msg (L["STRING_CHAT_FLYPOINTENDED"]) + end + end + + --after closing, check if the player is on a taxi + local CheckIfIsFlying = function (tickObject) + if (UnitOnTaxi ("player")) then + if (FlashTaskBar.FlyingHasEndedCheck) then + FlashTaskBar.FlyingHasEndedCheck:Cancel() + end + FlashTaskBar.FlyingHasEndedCheck = C_Timer.NewTicker (1, CheckIfFlyingEnded) + tickObject:Cancel() + end + end + + --run when the player closes the taxi map + function FlashTaskBar:TAXIMAP_CLOSED() + if (FlashTaskBar.db.profile.end_taxi) then + if (FlashTaskBar.IsFlyingTaxiCheck) then + FlashTaskBar.IsFlyingTaxiCheck:Cancel() + end + FlashTaskBar.IsFlyingTaxiCheck = C_Timer.NewTicker (1, CheckIfIsFlying, 5) --only check for 5 seconds + end + end + FlashTaskBar:RegisterEvent ("TAXIMAP_CLOSED") + + --disconenct + GameMenuButtonLogout:HookScript ("OnClick", function() + FlashTaskBar.LogoutTolerance = GetTime()+30 + end) + function FlashTaskBar:PLAYER_LOGOUT() + if (FlashTaskBar.db.profile.disconnect_logout) then + if (FlashTaskBar.LogoutTolerance and FlashTaskBar.LogoutTolerance > GetTime()) then + return + end + FlashTaskBar:DoFlash("disconnect_logout") + end + end + FlashTaskBar:RegisterEvent ("PLAYER_LOGOUT") + + --trade + function FlashTaskBar:TRADE_SHOW() + if (FlashTaskBar.db.profile.trade) then + FlashTaskBar:Msg ("somebody opened a trade with you!") + FlashTaskBar:DoFlash("trade") + end + end + FlashTaskBar:RegisterEvent ("TRADE_SHOW") + + --bags full + function FlashTaskBar:BAG_UPDATE() + if (FlashTaskBar.db.profile.bags_full) then + for backpack = 0, 4 do + for slot = 1, GetContainerNumSlots (backpack) do + local itemId = GetContainerItemID (backpack, slot) + if (not itemId) then + return + end + end + end + FlashTaskBar:DoFlash("bags_full") + end + end + FlashTaskBar:RegisterEvent ("BAG_UPDATE") + + --fatigue + function FlashTaskBar:MIRROR_TIMER_START (event, name, value, maxvalue, step, pause, label) + if (FlashTaskBar.db.profile.fatigue) then + if (name == "EXHAUSTION" and step == -1) then + FlashTaskBar:DoFlash ("fatigue") + end + end + end + FlashTaskBar:RegisterEvent ("MIRROR_TIMER_START") + + --timer start + function FlashTaskBar:START_TIMER() + if (FlashTaskBar.db.profile.timer_start) then + FlashTaskBar:DoFlash ("timer_start") + end + end + FlashTaskBar:RegisterEvent ("START_TIMER") + + --low health + FlashTaskBar.LastHealthBlink = time() - 30 + function FlashTaskBar.CheckTargetHealth() + local targetHealth = UnitHealth ("target") + if (targetHealth > 1) then + local targetMaxHealth = UnitHealthMax ("target") + if (targetMaxHealth) then + if (FlashTaskBar.db.profile.low_health) then + local percent = targetHealth / targetMaxHealth + if (percent < 0.17) then + if (FlashTaskBar.LastHealthBlink + 30 < time()) then + FlashTaskBar:DoFlash ("low_health") + FlashTaskBar.LastHealthBlink = time() + end + end + end + if (FlashTaskBar.db.profile.lost_health) then + local percent = targetHealth / targetMaxHealth + if (percent < 0.95) then + if (FlashTaskBar.LastHealthBlink + 30 < time()) then + FlashTaskBar:DoFlash ("lost_health") + FlashTaskBar.LastHealthBlink = time() + end + end + end + end + end + end + function FlashTaskBar:EnableCheckHealth (state) + if (FlashTaskBar.HealthTicker) then + FlashTaskBar.HealthTicker:Cancel() + end + if (state) then + FlashTaskBar.HealthTicker = C_Timer.NewTicker (2, FlashTaskBar.CheckTargetHealth) + else + FlashTaskBar.HealthTicker = nil + end + end + if (FlashTaskBar.db.profile.low_health) then + FlashTaskBar:EnableCheckHealth (true) + end + if (FlashTaskBar.db.profile.lost_health) then + FlashTaskBar:EnableCheckHealth (true) + end + +--------> chat scan + + local player_name = lower (UnitName ("player")) + local do_chat_scan = function (_, message) + message = lower (message) + if (FlashTaskBar.db.profile.chat_scan) then + for _, keyword in ipairs (FlashTaskBar.db.profile.chat_scan_keywords) do + if (message:find (lower (keyword))) then + FlashTaskBar:DoFlash ("chat_scan") + FlashTaskBar:Msg ("work " .. keyword .. " found in chat!") + return + end + end + end + + if (FlashTaskBar.db.profile.on_chat_player_name) then + if (message:find (player_name)) then + FlashTaskBar:Msg ("somebody mentioned your name in the chat!") + FlashTaskBar:DoFlash("on_chat_player_name") + end + end + end + + function FlashTaskBar:EnableChatScan() + FlashTaskBar:RegisterEvent ("CHAT_MSG_EMOTE", do_chat_scan) + --FlashTaskBar:RegisterEvent ("CHAT_MSG_MONSTER_EMOTE", do_chat_scan) + --FlashTaskBar:RegisterEvent ("CHAT_MSG_MONSTER_SAY", do_chat_scan) + --FlashTaskBar:RegisterEvent ("CHAT_MSG_MONSTER_WHISPER", do_chat_scan) + --FlashTaskBar:RegisterEvent ("CHAT_MSG_MONSTER_YELL", do_chat_scan) + --FlashTaskBar:RegisterEvent ("CHAT_MSG_RAID_BOSS_EMOTE", do_chat_scan) + --FlashTaskBar:RegisterEvent ("CHAT_MSG_RAID_BOSS_WHISPER", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_SYSTEM", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_SAY", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_YELL", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_CHANNEL", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_PARTY", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_GUILD", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_INSTANCE_CHAT", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_OFFICER", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_PARTY_LEADER", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_RAID", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_RAID_LEADER", do_chat_scan) + FlashTaskBar:RegisterEvent ("CHAT_MSG_RAID_WARNING", do_chat_scan) + + player_name = lower (UnitName ("player")) + end + + function FlashTaskBar:DisableChatScan() + FlashTaskBar:UnregisterEvent ("CHAT_MSG_EMOTE") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_MONSTER_EMOTE") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_MONSTER_SAY") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_MONSTER_WHISPER") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_MONSTER_YELL") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_RAID_BOSS_EMOTE") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_RAID_BOSS_WHISPER") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_SYSTEM") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_SAY") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_YELL") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_CHANNEL") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_PARTY") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_GUILD") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_INSTANCE_CHAT") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_OFFICER") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_PARTY_LEADER") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_RAID") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_RAID_LEADER") + FlashTaskBar:UnregisterEvent ("CHAT_MSG_RAID_WARNING") + end + + --> player died + local healthFrame = CreateFrame ("frame", nil, UIParent) + healthFrame:SetScript ("OnEvent", function (self, unit) + local health = UnitHealth ("player") + if (health < 1) then + if (FlashTaskBar.db.profile.player_died) then + FlashTaskBar:DoFlash ("player_died") + end + end + end) + + function FlashTaskBar:EnablePlayerHealthMonitor() + healthFrame:RegisterUnitEvent ("UNIT_HEALTH", "player") + end + + function FlashTaskBar:DisablePlayerHealthMonitor() + healthFrame:UnregisterEvent ("UNIT_HEALTH", "player") + end + + if (FlashTaskBar.db.profile.player_died) then + FlashTaskBar:EnablePlayerHealthMonitor() + end + + --need a cleanup in the future + function FlashTaskBar:DoNotFlashOnWhisper() + --_G.ChatFrame_MessageEventHandler = ChatFrame_MessageEventHandler_WithNoFlash + end + + function FlashTaskBar:EnableFlashOnWhisper() + --_G.ChatFrame_MessageEventHandler = ChatFrame_MessageEventHandler_Original + end + + if (FlashTaskBar.db.profile.whisper_blink) then + --FlashTaskBar:EnableFlashOnWhisper() + else + --FlashTaskBar:DoNotFlashOnWhisper() + end + +--------> combat log scan + + local combat_log_keywords = {} + local do_combat_log_scan = function (self, event) + local time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2 = CombatLogGetCurrentEventInfo() + if (target_name and combat_log_keywords [lower (target_name)]) then + FlashTaskBar:DoFlash("combat_log") + end + end + + function FlashTaskBar:BuildCombatLogKeywordTable() + wipe (combat_log_keywords) + for _, keyword in ipairs (FlashTaskBar.db.profile.combat_log_keywords) do + combat_log_keywords [lower (keyword)] = true + end + end + + function FlashTaskBar:EnableCombatLogScan() + FlashTaskBar:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED", do_combat_log_scan) + FlashTaskBar:BuildCombatLogKeywordTable() + end + + function FlashTaskBar:DisableCombatLogScan() + FlashTaskBar:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") + end + +--------> rare mob scan + + --> store the timers for flash for each rare + FlashTaskBar.RareFlashCooldown = {} + + local do_rare_mob_scan = function() + + --/dump C_VignetteInfo.GetVignetteInfo (C_VignetteInfo.GetVignettes()[1]) + --/dump C_VignetteInfo.GetVignettes() + + for index, GUID in ipairs (C_VignetteInfo.GetVignettes()) do + local vignetteInfo = C_VignetteInfo.GetVignetteInfo (GUID) + if (vignetteInfo and vignetteInfo.onMinimap and not vignetteInfo.isDead and vignetteInfo.atlasName == "VignetteKill") then --vignetteID == 2004 + + local objectGUID = vignetteInfo.objectGUID + if (FlashTaskBar.db.profile.any_rare) then + if (not UnitOnTaxi ("player")) then + if (not FlashTaskBar.RareFlashCooldown [objectGUID] or FlashTaskBar.RareFlashCooldown [objectGUID] < time()) then + FlashTaskBar:DoFlash ("rare_scan") + FlashTaskBar.RareFlashCooldown [objectGUID] = time() + 180 + end + end + + elseif (vignetteInfo.name) then + for _, npc_name in ipairs (FlashTaskBar.db.profile.rare_names) do + npc_name = lower (npc_name) + name = lower (name) + if (npc_name == name) then + if (not FlashTaskBar.RareFlashCooldown [objectGUID] or FlashTaskBar.RareFlashCooldown [objectGUID] < time()) then + FlashTaskBar:DoFlash ("rare_scan") + FlashTaskBar.RareFlashCooldown [objectGUID] = time() + 180 + end + end + end + end + end + end + end + + function FlashTaskBar:EnableRareMobScan() + FlashTaskBar:RegisterEvent ("VIGNETTES_UPDATED", do_rare_mob_scan) + end + + function FlashTaskBar:DisableRareMobScan() + FlashTaskBar:UnregisterEvent ("VIGNETTES_UPDATED") + end + +--> overrides + --replace the built-in flash function from the game client to flash when the player enters in combat + if (LowHealthFrame) then + function LowHealthFrame:SetInCombat(inCombat) + if self.inCombat ~= inCombat then + self.inCombat = inCombat; + if ( self.inCombat ) then + --FlashClientIcon(); + end + self:EvaluateVisibleState(); + end + end + end + +--> build options panel + + local options = { + { + type = "toggle", + name = L["STRING_READYCHECK"], + desc = L["STRING_READYCHECK_DESC"], + order = 1, + get = function() return FlashTaskBar.db.profile.readycheck end, + set = function (self, val) + FlashTaskBar.db.profile.readycheck = not FlashTaskBar.db.profile.readycheck + end, + }, + { + type = "toggle", + name = L["STRING_PVPQUEUES"], + desc = L["STRING_PVPQUEUES_DESC"], + order = 2, + get = function() return FlashTaskBar.db.profile.arena_queue end, + set = function (self, val) + FlashTaskBar.db.profile.arena_queue = not FlashTaskBar.db.profile.arena_queue + end, + }, + { + type = "toggle", + name = L["STRING_FINDERQUEUES"], + desc = L["STRING_FINDERQUEUES_DESC"], + order = 3, + get = function() return FlashTaskBar.db.profile.group_queue end, + set = function (self, val) + FlashTaskBar.db.profile.group_queue = not FlashTaskBar.db.profile.group_queue + end, + }, + { + type = "toggle", + name = L["STRING_PETBATTLES"] , + desc = L["STRING_PETBATTLES_DESC"] , + order = 6, + get = function() return FlashTaskBar.db.profile.petbattle_queue end, + set = function (self, val) + FlashTaskBar.db.profile.petbattle_queue = not FlashTaskBar.db.profile.petbattle_queue + end, + }, + { + type = "toggle", + name = L["STRING_BRAWLERS"], + desc = L["STRING_BRAWLERS_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.brawlers_queue end, + set = function (self, val) + FlashTaskBar.db.profile.brawlers_queue = not FlashTaskBar.db.profile.brawlers_queue + end, + }, + { + type = "toggle", + name = L["STRING_PULL"], + desc = L["STRING_PULL_DESC"], + order = 4, + get = function() return FlashTaskBar.db.profile.pull_timers end, + set = function (self, val) + FlashTaskBar.db.profile.pull_timers = not FlashTaskBar.db.profile.pull_timers + end, + }, + { + type = "toggle", + name = L["STRING_ENTERCOMBAT"], + desc = L["STRING_ENTERCOMBAT_DESC"], + order = 5, + get = function() return FlashTaskBar.db.profile.enter_combat end, + set = function (self, val) + FlashTaskBar.db.profile.enter_combat = not FlashTaskBar.db.profile.enter_combat + end, + }, + { + type = "toggle", + name = L["STRING_FLYPOINT"], + desc = L["STRING_FLYPOINT_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.end_taxi end, + set = function (self, val) + FlashTaskBar.db.profile.end_taxi = not FlashTaskBar.db.profile.end_taxi + end, + }, + { + type = "toggle", + name = L["STRING_DISCONNECT"], + desc = L["STRING_DISCONNECT_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.disconnect_logout end, + set = function (self, val) + FlashTaskBar.db.profile.disconnect_logout = not FlashTaskBar.db.profile.disconnect_logout + end, + }, + + { + type = "toggle", + name = L["STRING_INVITES"], + desc = L["STRING_INVITES_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.invite end, + set = function (self, val) + FlashTaskBar.db.profile.invite = not FlashTaskBar.db.profile.invite + end, + }, + { + type = "toggle", + name = L["STRING_INVITEIGNORE"], + desc = L["STRING_INVITEIGNORE_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.invite_ignore_on_autoaccept end, + set = function (self, val) + FlashTaskBar.db.profile.invite_ignore_on_autoaccept = not FlashTaskBar.db.profile.invite_ignore_on_autoaccept + end, + }, + + { + type = "toggle", + name = L["STRING_TRADE"], + desc = L["STRING_TRADE_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.trade end, + set = function (self, val) + FlashTaskBar.db.profile.trade = not FlashTaskBar.db.profile.trade + end, + }, + { + type = "toggle", + name = L["STRING_BAGSFULL"], + desc = L["STRING_BAGSFULL_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.bags_full end, + set = function (self, val) + FlashTaskBar.db.profile.bags_full = not FlashTaskBar.db.profile.bags_full + end, + }, + { + type = "toggle", + name = L["STRING_WORLDPVP"], + desc = L["STRING_WORLDPVP_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.worldpvp end, + set = function (self, val) + FlashTaskBar.db.profile.worldpvp = not FlashTaskBar.db.profile.worldpvp + end, + }, + { + type = "toggle", + name = L["STRING_DUELREQUEST"] , + desc = L["STRING_DUELREQUEST_DESC"] , + order = 6, + get = function() return FlashTaskBar.db.profile.duel_request end, + set = function (self, val) + FlashTaskBar.db.profile.duel_request = not FlashTaskBar.db.profile.duel_request + end, + }, + { + type = "toggle", + name = L["STRING_SUMMON"], + desc = L["STRING_SUMMON_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.summon end, + set = function (self, val) + FlashTaskBar.db.profile.summon = not FlashTaskBar.db.profile.summon + end, + }, + { + type = "toggle", + name = L["STRING_FATIGUE"], + desc = L["STRING_FATIGUE_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.fatigue end, + set = function (self, val) + FlashTaskBar.db.profile.fatigue = not FlashTaskBar.db.profile.fatigue + end, + }, + { + type = "toggle", + name = L["STRING_PLAYERNAME"], + desc = L["STRING_PLAYERNAME_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.on_chat_player_name end, + set = function (self, val) + FlashTaskBar.db.profile.on_chat_player_name = not FlashTaskBar.db.profile.on_chat_player_name + if (FlashTaskBar.db.profile.on_chat_player_name) then + FlashTaskBar:EnableChatScan() + else + --ver se tem alguma outra funo usando o chat scan + if (not FlashTaskBar.db.profile.chat_scan) then + FlashTaskBar:DisableChatScan() + end + end + end, + }, + + --[=[ + { + type = "toggle", + name = L["STRING_ONWHISPER"], + desc = L["STRING_ONWHISPER_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.whisper_blink end, + set = function (self, val) + FlashTaskBar.db.profile.whisper_blink = not FlashTaskBar.db.profile.whisper_blink + if (FlashTaskBar.db.profile.whisper_blink) then + FlashTaskBar:EnableFlashOnWhisper() + else + FlashTaskBar:DoNotFlashOnWhisper() + end + end, + }, + --]=] + + { + type = "toggle", + name = L["STRING_BATTLEGROUND"], + desc = L["STRING_BATTLEGROUND_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.battleground_end end, + set = function (self, val) + FlashTaskBar.db.profile.battleground_end = not FlashTaskBar.db.profile.battleground_end + end, + }, + + { + type = "toggle", + name = L["STRING_ONCOUNTDOWN"], + desc = L["STRING_ONCOUNTDOWN_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.timer_start end, + set = function (self, val) + FlashTaskBar.db.profile.timer_start = not FlashTaskBar.db.profile.timer_start + end, + }, + + { + type = "toggle", + name = L["STRING_TARGETLOWHEALTH"], + desc = L["STRING_TARGETLOWHEALTH_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.low_health end, + set = function (self, val) + FlashTaskBar.db.profile.low_health = not FlashTaskBar.db.profile.low_health + if (FlashTaskBar.db.profile.low_health) then + FlashTaskBar:EnableCheckHealth (true) + else + FlashTaskBar:EnableCheckHealth (false) + end + end, + }, + + { + type = "toggle", + name = L["STRING_TARGETLOSTHEALTH"], + desc = L["STRING_TARGETLOSTHEALTH_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.lost_health end, + set = function (self, val) + FlashTaskBar.db.profile.lost_health = not FlashTaskBar.db.profile.lost_health + if (FlashTaskBar.db.profile.lost_health) then + FlashTaskBar:EnableCheckHealth (true) + else + FlashTaskBar:EnableCheckHealth (false) + end + end, + }, + + { + type = "toggle", + name = L["STRING_ONPLAYERDEATH"], + desc = L["STRING_ONPLAYERDEATH_DESC"], + order = 6, + get = function() return FlashTaskBar.db.profile.player_died end, + set = function (self, val) + FlashTaskBar.db.profile.player_died = not FlashTaskBar.db.profile.player_died + if (FlashTaskBar.db.profile.player_died) then + FlashTaskBar:EnablePlayerHealthMonitor() + else + FlashTaskBar:DisablePlayerHealthMonitor() + end + end, + }, + } + + local options_text_template = FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE") + local options_dropdown_template = FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE") + local options_switch_template = FlashTaskBar:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE") + local options_slider_template = FlashTaskBar:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE") + local options_button_template = FlashTaskBar:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE") + + local general_text1 = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_GENERALSETTINGS"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + general_text1:SetPoint ("topleft", main_frame, "topleft", 10, -50) + FlashTaskBar:SetFontSize (general_text1, 16) + + local general_settings_frame = CreateFrame ("frame", "FlashTaskBarGeneralOptionsFrame", FlashTaskBar.OptionsFrame1) + general_settings_frame:SetPoint ("topleft", 0, 0) + general_settings_frame:SetSize (1, 1) + + FlashTaskBar:BuildMenu (general_settings_frame, options, 15, -77, 280, true, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template) + + local y_chat_scan = -250 + + local camping_text1 = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_CAMPINGSETTINGS"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + camping_text1:SetPoint ("topleft", main_frame, "topleft", 10, y_chat_scan) + local sound_button_y = y_chat_scan + FlashTaskBar:SetFontSize (camping_text1, 16) + y_chat_scan = y_chat_scan - 30 + + --> chat scan settings + + --> title label + local blink_on_chat = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_CHATSCAN"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + blink_on_chat:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan) + + --> enabled + local enable_chat_filter = function (_, _, value) + FlashTaskBar.db.profile.chat_scan = value + if (value) then + FlashTaskBar:EnableChatScan() + else + --ver se tem alguma outra funo usando o chat scan + if (not FlashTaskBar.db.profile.on_chat_player_name) then + FlashTaskBar:DisableChatScan() + end + end + end + local chat_scan_switch, chat_scan_label = FlashTaskBar:CreateSwitch (FlashTaskBar.OptionsFrame1, enable_chat_filter, FlashTaskBar.db.profile.chat_scan, _, _, _, _, "switch_enable_chat_scan", _, _, _, _, L["STRING_CHATSCAN_ENABLED"] .. ":", FlashTaskBar:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + chat_scan_switch:SetAsCheckBox() + chat_scan_switch.tooltip = L["STRING_CHATSCAN_ENABLED_DESC"] + chat_scan_label:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-20) + + --> key words + --add + local chat_scan_keyword, label_chat_scan_keyword = FlashTaskBar:CreateTextEntry (FlashTaskBar.OptionsFrame1, function()end, 120, 20, "entry_add_keyword", _, L["STRING_ADDKEYWORD"] .. ":", FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + label_chat_scan_keyword:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-40) + + local add_key_word_func = function() + local keyword = chat_scan_keyword.text + if (keyword ~= "") then + tinsert (FlashTaskBar.db.profile.chat_scan_keywords, keyword) + end + chat_scan_keyword.text = "" + chat_scan_keyword:ClearFocus() + FlashTaskBar.OptionsFrame1.dropdown_keyword_remove:Refresh() + FlashTaskBar.OptionsFrame1.dropdown_keyword_remove:Select (1, true) + end + local button_add_keyword = FlashTaskBar:CreateButton (FlashTaskBar.OptionsFrame1, add_key_word_func, 60, 18, L["STRING_ADD"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + button_add_keyword:SetPoint ("left", chat_scan_keyword, "right", 2, 0) + + --remove + local dropdown_keyword_erase_fill = function() + local t = {} + for i, keyword in ipairs (FlashTaskBar.db.profile.chat_scan_keywords) do + t [#t+1] = {value = i, label = keyword, onclick = empty_func} + end + return t + end + local label_keyword_remove = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_ERASEKEYWORD"] .. ": ", FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + local dropdown_keyword_remove = FlashTaskBar:CreateDropDown (FlashTaskBar.OptionsFrame1, dropdown_keyword_erase_fill, _, 160, 20, "dropdown_keyword_remove", _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + dropdown_keyword_remove:SetPoint ("left", label_keyword_remove, "right", 2, 0) + + local keyword_remove = function() + local value = dropdown_keyword_remove.value + tremove (FlashTaskBar.db.profile.chat_scan_keywords, value) + dropdown_keyword_remove:Refresh() + dropdown_keyword_remove:Select (1, true) + end + local button_keyword_remove = FlashTaskBar:CreateButton (FlashTaskBar.OptionsFrame1, keyword_remove, 60, 18, L["STRING_REMOVE"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + button_keyword_remove:SetPoint ("left", dropdown_keyword_remove, "right", 2, 0) + label_keyword_remove:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-60) + + --ativar o chat scan se necessrio + if (FlashTaskBar.db.profile.chat_scan or FlashTaskBar.db.profile.on_chat_player_name) then + FlashTaskBar:EnableChatScan() + end + + --> combat log scan settings + --> title label + local blink_on_combatlog = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_COMBATLOGSCAN"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + blink_on_combatlog:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-90) + + --> enabled + local enable_combatlog_filter = function (_, _, value) + FlashTaskBar.db.profile.combat_log = value + if (value) then + FlashTaskBar:EnableCombatLogScan() + else + FlashTaskBar:DisableCombatLogScan() + end + end + local combatlog_scan_switch, combatlog_scan_label = FlashTaskBar:CreateSwitch (FlashTaskBar.OptionsFrame1, enable_combatlog_filter, FlashTaskBar.db.profile.combat_log, _, _, _, _, "switch_enable_combatlog_scan", _, _, _, _, L["STRING_COMBATLOGSCAN_ENABLED"] .. ":", FlashTaskBar:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + combatlog_scan_switch.tooltip = L["STRING_COMBATLOGSCAN_ENABLED_DESC"] + combatlog_scan_switch:SetAsCheckBox() + combatlog_scan_label:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-110) + + --> key words + --add + local combatlog_scan_keyword, label_combatlog_scan_keyword = FlashTaskBar:CreateTextEntry (FlashTaskBar.OptionsFrame1, function()end, 120, 20, "entry_add_keyword", _, L["STRING_RARENPCSCAN_NPCNAME"] .. ":", FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + label_combatlog_scan_keyword:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-130) + + local add_key_word_func = function() + local keyword = combatlog_scan_keyword.text + if (keyword ~= "") then + tinsert (FlashTaskBar.db.profile.combat_log_keywords, keyword) + end + combatlog_scan_keyword.text = "" + combatlog_scan_keyword:ClearFocus() + FlashTaskBar.OptionsFrame1.dropdown_combatlog_keyword_remove:Refresh() + FlashTaskBar.OptionsFrame1.dropdown_combatlog_keyword_remove:Select (1, true) + FlashTaskBar:BuildCombatLogKeywordTable() + end + local button_add_keyword = FlashTaskBar:CreateButton (FlashTaskBar.OptionsFrame1, add_key_word_func, 60, 18, L["STRING_ADD"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + button_add_keyword:SetPoint ("left", combatlog_scan_keyword, "right", 2, 0) + + --remove + local dropdown_keyword_erase_fill = function() + local t = {} + for i, keyword in ipairs (FlashTaskBar.db.profile.combat_log_keywords) do + t [#t+1] = {value = i, label = keyword, onclick = empty_func} + end + return t + end + local label_keyword_remove = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_REMOVE_TITLE"] .. ": ", FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + local dropdown_keyword_remove = FlashTaskBar:CreateDropDown (FlashTaskBar.OptionsFrame1, dropdown_keyword_erase_fill, _, 160, 20, "dropdown_combatlog_keyword_remove", _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + dropdown_keyword_remove:SetPoint ("left", label_keyword_remove, "right", 2, 0) + + local keyword_remove = function() + local value = dropdown_keyword_remove.value + tremove (FlashTaskBar.db.profile.combat_log_keywords, value) + dropdown_keyword_remove:Refresh() + dropdown_keyword_remove:Select (1, true) + FlashTaskBar:BuildCombatLogKeywordTable() + end + local button_keyword_remove = FlashTaskBar:CreateButton (FlashTaskBar.OptionsFrame1, keyword_remove, 60, 18, L["STRING_REMOVE"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + button_keyword_remove:SetPoint ("left", dropdown_keyword_remove, "right", 2, 0) + label_keyword_remove:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-150) + + if (FlashTaskBar.db.profile.combat_log) then + FlashTaskBar:EnableCombatLogScan() + end + + --> rare mob scan settings + --> title label + local blink_on_raremob = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_RARENPCSCAN"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + blink_on_raremob:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-180) + + --> enabled + local enable_raremob_filter = function (_, _, value) + FlashTaskBar.db.profile.rare_scan = value + if (value) then + FlashTaskBar:EnableRareMobScan() + else + FlashTaskBar:DisableRareMobScan() + end + end + local raremob_scan_switch, raremob_scan_label = FlashTaskBar:CreateSwitch (FlashTaskBar.OptionsFrame1, enable_raremob_filter, FlashTaskBar.db.profile.rare_scan, _, _, _, _, "switch_enable_raremob_scan", _, _, _, _, L["STRING_RARENPCSCAN_ENABLED"] .. ":", FlashTaskBar:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + raremob_scan_switch:SetAsCheckBox() + raremob_scan_switch.tooltip = L["STRING_RARENPCSCAN_DESC"] + raremob_scan_label:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-200) + + --> all rares + local enable_raremob_all_filter = function (_, _, value) + FlashTaskBar.db.profile.any_rare = value + end + local raremob_all_scan_switch, raremob_all_scan_label = FlashTaskBar:CreateSwitch (FlashTaskBar.OptionsFrame1, enable_raremob_all_filter, FlashTaskBar.db.profile.any_rare, _, _, _, _, "switch_enable_raremob_all_scan", _, _, _, _, L["STRING_RARENPCSCAN_ANYNPC"] .. ":", FlashTaskBar:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + raremob_all_scan_switch:SetAsCheckBox() + raremob_all_scan_label:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-220) + + --> key words + --add + local raremob_scan_keyword, label_raremob_scan_keyword = FlashTaskBar:CreateTextEntry (FlashTaskBar.OptionsFrame1, function()end, 120, 20, "raremob_add_keyword", _, L["STRING_RARENPCSCAN_NPCNAME"] .. ":", FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + label_raremob_scan_keyword:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-240) + + local add_key_word_func = function() + local keyword = raremob_scan_keyword.text + if (keyword ~= "") then + tinsert (FlashTaskBar.db.profile.rare_names, keyword) + end + raremob_scan_keyword.text = "" + raremob_scan_keyword:ClearFocus() + FlashTaskBar.OptionsFrame1.dropdown_rare_keyword_remove:Refresh() + FlashTaskBar.OptionsFrame1.dropdown_rare_keyword_remove:Select (1, true) + end + local button_add_keyword = FlashTaskBar:CreateButton (FlashTaskBar.OptionsFrame1, add_key_word_func, 60, 18, L["STRING_ADD"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + button_add_keyword:SetPoint ("left", raremob_scan_keyword, "right", 2, 0) + + --remove + local dropdown_keyword_erase_fill = function() + local t = {} + for i, keyword in ipairs (FlashTaskBar.db.profile.rare_names) do + t [#t+1] = {value = i, label = keyword, onclick = empty_func} + end + return t + end + local label_keyword_remove = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_REMOVE_TITLE"] .. ": ", FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + local dropdown_keyword_remove = FlashTaskBar:CreateDropDown (FlashTaskBar.OptionsFrame1, dropdown_keyword_erase_fill, _, 160, 20, "dropdown_rare_keyword_remove", _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + dropdown_keyword_remove:SetPoint ("left", label_keyword_remove, "right", 2, 0) + + local keyword_remove = function() + local value = dropdown_keyword_remove.value + tremove (FlashTaskBar.db.profile.rare_names, value) + dropdown_keyword_remove:Refresh() + dropdown_keyword_remove:Select (1, true) + end + local button_keyword_remove = FlashTaskBar:CreateButton (FlashTaskBar.OptionsFrame1, keyword_remove, 60, 20, L["STRING_REMOVE"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + button_keyword_remove:SetPoint ("left", dropdown_keyword_remove, "right", 2, 0) + label_keyword_remove:SetPoint ("topleft", FlashTaskBar.OptionsFrame1, "topleft", 10, y_chat_scan-260) + + if (FlashTaskBar.db.profile.rare_scan) then + FlashTaskBar:EnableRareMobScan() + end + + --> sound options + local sound_x = 380 + local sound_text1 = FlashTaskBar:CreateLabel (FlashTaskBar.OptionsFrame1, L["STRING_SOUNDSETTINGS"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + sound_text1:SetPoint ("topleft", main_frame, "topleft", sound_x, sound_button_y) + FlashTaskBar:SetFontSize (sound_text1, 16) + + local open_sound_panel = function() + if (_G.FlashTaskbarSoundSettings) then + _G.FlashTaskbarSoundSettings:Show() + return + end + + local f = DF:Create1PxPanel (FlashTaskBar.OptionsFrame1, 450, 300, "", "FlashTaskbarSoundSettings", nil, nil, nil) + f:SetPoint ("center", FlashTaskBar.OptionsFrame1, "center") + f:SetSize (FlashTaskBar.OptionsFrame1:GetSize()) + f:SetFrameLevel (FlashTaskBar.OptionsFrame1:GetFrameLevel()+5) + f:SetLocked (true) + + f:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], tile = true, tileSize = 64}) + f:SetBackdropColor (0, 0, 0, 1) + + local close_sound_settings = FlashTaskBar:CreateButton (f, function() f:Hide() end, 160, 20, L["STRING_CLOSESOUNDPANEL"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + close_sound_settings:SetPoint ("topleft", f, "topleft", 10, -520) + close_sound_settings:SetIcon ([[Interface\Scenarios\ScenarioIcon-Check]], 16, 16, "overlay", {0, 1, 0, 1}, nil, 6, nil, 1) + + local sound_title = FlashTaskBar:CreateLabel (f, L["STRING_SOUNDSETTINGS"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + sound_title:SetPoint ("topleft", f, "topleft", 10, -50) + FlashTaskBar:SetFontSize (sound_title, 16) + local sound_title_desc = FlashTaskBar:CreateLabel (f, L["STRING_SOUNDSETTINGS_DESC"] .. ":", FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + sound_title_desc:SetPoint ("topleft", f, "topleft", 10, -70) + + local localize_key = { + readycheck = "READYCHECK", + arena_queue = "PVPQUEUES", + group_queue = "FINDERQUEUES", + petbattle_queue = "PETBATTLES", + brawlers_queue = "BRAWLERS", + pull_timers = "PULL", + enter_combat = "ENTERCOMBAT", + end_taxi = "FLYPOINT", + chat_scan = "CHATSCAN", + combat_log = "COMBATLOGSCAN", + rare_scan = "RARENPCSCAN", + disconnect_logout = "DISCONNECT", + invite = "INVITES", + trade = "TRADE", + bags_full = "BAGSFULL", + worldpvp = "WORLDPVP", + duel_request = "DUELREQUEST", + summon = "SUMMON", + fatigue = "FATIGUE", + battleground_end = "BATTLEGROUND", + on_chat_player_name = "PLAYERNAME", + player_died = "ONPLAYERDEATH", + } + + --the game cannot play sounds when logging off + local settings = { + "rare_scan", + "arena_queue", + "group_queue", + "readycheck", + "petbattle_queue", + "brawlers_queue", + "pull_timers", + "enter_combat", + "end_taxi", + "chat_scan", + "combat_log", + "invite", + "trade", + "bags_full", + "worldpvp", + "duel_request", + "summon", + "fatigue", + "on_chat_player_name", + "battleground_end", + "player_died" + } + + local sound_options = {} + local y = -95 + local x = 10 + + local checkbox_ontoggle = function (self, _, value) + self.MyConfigTable.enabled = not self.MyConfigTable.enabled + end + local sound_dropdown_selected = function (self, _, value) + self.MyConfigTable.sound = value + PlaySoundFile (LibStub:GetLibrary("LibSharedMedia-3.0"):Fetch ("sound", value), "Master") + end + local SoundTable + local sound_dropdown_fill = function (capsule) + if (not SoundTable) then + SoundTable = {} + local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") + for name, _ in pairs (SharedMedia:HashTable ("sound")) do + tinsert (SoundTable, {value = name, label = name, onclick = sound_dropdown_selected}) + end + end + return SoundTable + end + + local switch_name = 999 + for index, config_key in ipairs (settings) do + local name_locale = L["STRING_" .. localize_key [config_key]] .. ":" + local desc_locale = L["STRING_" .. localize_key [config_key] .. "_DESC"] + local config_table = FlashTaskBar.db.profile.sound_enabled [config_key] + + local label = FlashTaskBar:CreateLabel (f, name_locale, FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + label.color = "yellow" + label:SetPoint (x, y) + + local checkbox = FlashTaskBar:CreateSwitch (f, checkbox_ontoggle, config_table.enabled, _, _, _, _, _, nil, _, _, _, _, FlashTaskBar:GetTemplate ("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE")) + checkbox:SetAsCheckBox() + checkbox.tooltip = desc_locale + checkbox.MyConfigTable = config_table + checkbox:SetPoint (x + 120, y) + + local dropdown = FlashTaskBar:CreateDropDown (f, sound_dropdown_fill, config_table.sound, 160, 20, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")) + dropdown.MyConfigTable = config_table + dropdown:SetPoint (x + 180, y) + + y = y - 20 + + switch_name = switch_name + 1 + end + + FlashTaskBar.NoBGSound = FlashTaskBar:CreateLabel (f, L["STRING_BACKGROUND_SOUND"], FlashTaskBar:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")) + FlashTaskBar.NoBGSound.color = "red" + FlashTaskBar.NoBGSound.fontsize = 12 + FlashTaskBar.NoBGSound.align = "center" + FlashTaskBar.NoBGSound:SetPoint (415, -150) + + f:SetScript ("OnShow", function() + local isBGSoundDisabled = GetCVar ("Sound_EnableSoundWhenGameIsInBG") + if (isBGSoundDisabled == "0") then + FlashTaskBar.NoBGSound:Show() + else + FlashTaskBar.NoBGSound:Hide() + end + end) + end + + local open_sound_settings = FlashTaskBar:CreateButton (FlashTaskBar.OptionsFrame1, open_sound_panel, 160, 18, L["STRING_OPENSOUNDPANEL"], _, _, _, _, _, _, FlashTaskBar:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"), FlashTaskBar:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")) + open_sound_settings:SetPoint ("topleft", main_frame, "topleft", sound_x-1, sound_button_y-30) + open_sound_settings:SetIcon ([[Interface\Buttons\UI-GuildButton-MOTD-Up]], 16, 15, "overlay", {1, 0, 0, 1}, nil, 6, nil, 1) +end + diff --git a/FlashTaskBar.toc b/FlashTaskBar.toc new file mode 100644 index 0000000..e42414f --- /dev/null +++ b/FlashTaskBar.toc @@ -0,0 +1,22 @@ +## Interface: 80200 +## Title: Flash Task Bar +## Notes: Flashes the taskbar when you are alt-tabbed and queue for raid finder, battleground pops up. +## SavedVariables: FlashTaskbarDB + +#@no-lib-strip@ +libs\libs.xml +#@end-no-lib-strip@ + +locales\enUS.lua +locales\deDE.lua +locales\esES.lua +locales\esMX.lua +locales\frFR.lua +locales\itIT.lua +locales\koKR.lua +locales\ptBR.lua +locales\ruRU.lua +locales\zhCN.lua +locales\zhTW.lua + +FlashTaskBar.lua \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e62ec04 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/libs/AceAddon-3.0/AceAddon-3.0.lua b/libs/AceAddon-3.0/AceAddon-3.0.lua new file mode 100644 index 0000000..a7f7279 --- /dev/null +++ b/libs/AceAddon-3.0/AceAddon-3.0.lua @@ -0,0 +1,674 @@ +--- **AceAddon-3.0** provides a template for creating addon objects. +-- It'll provide you with a set of callback functions that allow you to simplify the loading +-- process of your addon.\\ +-- Callbacks provided are:\\ +-- * **OnInitialize**, which is called directly after the addon is fully loaded. +-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present. +-- * **OnDisable**, which is only called when your addon is manually being disabled. +-- @usage +-- -- A small (but complete) addon, that doesn't do anything, +-- -- but shows usage of the callbacks. +-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- +-- function MyAddon:OnInitialize() +-- -- do init tasks here, like loading the Saved Variables, +-- -- or setting up slash commands. +-- end +-- +-- function MyAddon:OnEnable() +-- -- Do more initialization here, that really enables the use of your addon. +-- -- Register Events, Hook functions, Create Frames, Get information from +-- -- the game that wasn't available in OnInitialize +-- end +-- +-- function MyAddon:OnDisable() +-- -- Unhook, Unregister Events, Hide frames that you created. +-- -- You would probably only use an OnDisable if you want to +-- -- build a "standby" mode, or be able to toggle modules on/off. +-- end +-- @class file +-- @name AceAddon-3.0.lua +-- @release $Id: AceAddon-3.0.lua 1084 2013-04-27 20:14:11Z nevcairiel $ + +local MAJOR, MINOR = "AceAddon-3.0", 12 +local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR) + +if not AceAddon then return end -- No Upgrade needed. + +AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame +AceAddon.addons = AceAddon.addons or {} -- addons in general +AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon. +AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized +AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled +AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon + +-- Lua APIs +local tinsert, tconcat, tremove = table.insert, table.concat, table.remove +local fmt, tostring = string.format, tostring +local select, pairs, next, type, unpack = select, pairs, next, type, unpack +local loadstring, assert, error = loadstring, assert, error +local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget + +-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded +-- List them here for Mikk's FindGlobals script +-- GLOBALS: LibStub, IsLoggedIn, geterrorhandler + +--[[ + xpcall safecall implementation +]] +local xpcall = xpcall + +local function errorhandler(err) + return geterrorhandler()(err) +end + +local function CreateDispatcher(argCount) + local code = [[ + local xpcall, eh = ... + local method, ARGS + local function call() return method(ARGS) end + + local function dispatch(func, ...) + method = func + if not method then return end + ARGS = ... + return xpcall(call, eh) + end + + return dispatch + ]] + + local ARGS = {} + for i = 1, argCount do ARGS[i] = "arg"..i end + code = code:gsub("ARGS", tconcat(ARGS, ", ")) + return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) +end + +local Dispatchers = setmetatable({}, {__index=function(self, argCount) + local dispatcher = CreateDispatcher(argCount) + rawset(self, argCount, dispatcher) + return dispatcher +end}) +Dispatchers[0] = function(func) + return xpcall(func, errorhandler) +end + +local function safecall(func, ...) + -- we check to see if the func is passed is actually a function here and don't error when it isn't + -- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not + -- present execution should continue without hinderance + if type(func) == "function" then + return Dispatchers[select('#', ...)](func, ...) + end +end + +-- local functions that will be implemented further down +local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype + +-- used in the addon metatable +local function addontostring( self ) return self.name end + +-- Check if the addon is queued for initialization +local function queuedForInitialization(addon) + for i = 1, #AceAddon.initializequeue do + if AceAddon.initializequeue[i] == addon then + return true + end + end + return false +end + +--- Create a new AceAddon-3.0 addon. +-- Any libraries you specified will be embeded, and the addon will be scheduled for +-- its OnInitialize and OnEnable callbacks. +-- The final addon object, with all libraries embeded, will be returned. +-- @paramsig [object ,]name[, lib, ...] +-- @param object Table to use as a base for the addon (optional) +-- @param name Name of the addon object to create +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a simple addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0") +-- +-- -- Create a Addon object based on the table of a frame +-- local MyFrame = CreateFrame("Frame") +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0") +function AceAddon:NewAddon(objectorname, ...) + local object,name + local i=1 + if type(objectorname)=="table" then + object=objectorname + name=... + i=2 + else + name=objectorname + end + if type(name)~="string" then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) + end + if self.addons[name] then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2) + end + + object = object or {} + object.name = name + + local addonmeta = {} + local oldmeta = getmetatable(object) + if oldmeta then + for k, v in pairs(oldmeta) do addonmeta[k] = v end + end + addonmeta.__tostring = addontostring + + setmetatable( object, addonmeta ) + self.addons[name] = object + object.modules = {} + object.orderedModules = {} + object.defaultModuleLibraries = {} + Embed( object ) -- embed NewModule, GetModule methods + self:EmbedLibraries(object, select(i,...)) + + -- add to queue of addons to be initialized upon ADDON_LOADED + tinsert(self.initializequeue, object) + return object +end + + +--- Get the addon object by its name from the internal AceAddon registry. +-- Throws an error if the addon object cannot be found (except if silent is set). +-- @param name unique name of the addon object +-- @param silent if true, the addon is optional, silently return nil if its not found +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +function AceAddon:GetAddon(name, silent) + if not silent and not self.addons[name] then + error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2) + end + return self.addons[name] +end + +-- - Embed a list of libraries into the specified addon. +-- This function will try to embed all of the listed libraries into the addon +-- and error if a single one fails. +-- +-- **Note:** This function is for internal use by :NewAddon/:NewModule +-- @paramsig addon, [lib, ...] +-- @param addon addon object to embed the libs in +-- @param lib List of libraries to embed into the addon +function AceAddon:EmbedLibraries(addon, ...) + for i=1,select("#", ... ) do + local libname = select(i, ...) + self:EmbedLibrary(addon, libname, false, 4) + end +end + +-- - Embed a library into the addon object. +-- This function will check if the specified library is registered with LibStub +-- and if it has a :Embed function to call. It'll error if any of those conditions +-- fails. +-- +-- **Note:** This function is for internal use by :EmbedLibraries +-- @paramsig addon, libname[, silent[, offset]] +-- @param addon addon object to embed the library in +-- @param libname name of the library to embed +-- @param silent marks an embed to fail silently if the library doesn't exist (optional) +-- @param offset will push the error messages back to said offset, defaults to 2 (optional) +function AceAddon:EmbedLibrary(addon, libname, silent, offset) + local lib = LibStub:GetLibrary(libname, true) + if not lib and not silent then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2) + elseif lib and type(lib.Embed) == "function" then + lib:Embed(addon) + tinsert(self.embeds[addon], libname) + return true + elseif lib then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2) + end +end + +--- Return the specified module from an addon object. +-- Throws an error if the addon object cannot be found (except if silent is set) +-- @name //addon//:GetModule +-- @paramsig name[, silent] +-- @param name unique name of the module +-- @param silent if true, the module is optional, silently return nil if its not found (optional) +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- -- Get the Module +-- MyModule = MyAddon:GetModule("MyModule") +function GetModule(self, name, silent) + if not self.modules[name] and not silent then + error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2) + end + return self.modules[name] +end + +local function IsModuleTrue(self) return true end + +--- Create a new module for the addon. +-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\ +-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as +-- an addon object. +-- @name //addon//:NewModule +-- @paramsig name[, prototype|lib[, lib, ...]] +-- @param name unique name of the module +-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional) +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a module with some embeded libraries +-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0") +-- +-- -- Create a module with a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0") +function NewModule(self, name, prototype, ...) + if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end + if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end + + if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end + + -- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well. + -- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is. + local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name)) + + module.IsModule = IsModuleTrue + module:SetEnabledState(self.defaultModuleState) + module.moduleName = name + + if type(prototype) == "string" then + AceAddon:EmbedLibraries(module, prototype, ...) + else + AceAddon:EmbedLibraries(module, ...) + end + AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries)) + + if not prototype or type(prototype) == "string" then + prototype = self.defaultModulePrototype or nil + end + + if type(prototype) == "table" then + local mt = getmetatable(module) + mt.__index = prototype + setmetatable(module, mt) -- More of a Base class type feel. + end + + safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy. + self.modules[name] = module + tinsert(self.orderedModules, module) + + return module +end + +--- Returns the real name of the addon or module, without any prefix. +-- @name //addon//:GetName +-- @paramsig +-- @usage +-- print(MyAddon:GetName()) +-- -- prints "MyAddon" +function GetName(self) + return self.moduleName or self.name +end + +--- Enables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback +-- and enabling all modules of the addon (unless explicitly disabled).\\ +-- :Enable() also sets the internal `enableState` variable to true +-- @name //addon//:Enable +-- @paramsig +-- @usage +-- -- Enable MyModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +function Enable(self) + self:SetEnabledState(true) + + -- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still + -- it'll be enabled after the init process + if not queuedForInitialization(self) then + return AceAddon:EnableAddon(self) + end +end + +--- Disables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback +-- and disabling all modules of the addon.\\ +-- :Disable() also sets the internal `enableState` variable to false +-- @name //addon//:Disable +-- @paramsig +-- @usage +-- -- Disable MyAddon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:Disable() +function Disable(self) + self:SetEnabledState(false) + return AceAddon:DisableAddon(self) +end + +--- Enables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object. +-- @name //addon//:EnableModule +-- @paramsig name +-- @usage +-- -- Enable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +-- +-- -- Enable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:EnableModule("MyModule") +function EnableModule(self, name) + local module = self:GetModule( name ) + return module:Enable() +end + +--- Disables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object. +-- @name //addon//:DisableModule +-- @paramsig name +-- @usage +-- -- Disable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Disable() +-- +-- -- Disable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:DisableModule("MyModule") +function DisableModule(self, name) + local module = self:GetModule( name ) + return module:Disable() +end + +--- Set the default libraries to be mixed into all modules created by this object. +-- Note that you can only change the default module libraries before any module is created. +-- @name //addon//:SetDefaultModuleLibraries +-- @paramsig lib[, lib, ...] +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Configure default libraries for modules (all modules need AceEvent-3.0) +-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0") +-- -- Create a module +-- MyModule = MyAddon:NewModule("MyModule") +function SetDefaultModuleLibraries(self, ...) + if next(self.modules) then + error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleLibraries = {...} +end + +--- Set the default state in which new modules are being created. +-- Note that you can only change the default state before any module is created. +-- @name //addon//:SetDefaultModuleState +-- @paramsig state +-- @param state Default state for new modules, true for enabled, false for disabled +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Set the default state to "disabled" +-- MyAddon:SetDefaultModuleState(false) +-- -- Create a module and explicilty enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +function SetDefaultModuleState(self, state) + if next(self.modules) then + error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleState = state +end + +--- Set the default prototype to use for new modules on creation. +-- Note that you can only change the default prototype before any module is created. +-- @name //addon//:SetDefaultModulePrototype +-- @paramsig prototype +-- @param prototype Default prototype for the new modules (table) +-- @usage +-- -- Define a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- -- Set the default prototype +-- MyAddon:SetDefaultModulePrototype(prototype) +-- -- Create a module and explicitly Enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +-- -- should print "OnEnable called!" now +-- @see NewModule +function SetDefaultModulePrototype(self, prototype) + if next(self.modules) then + error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2) + end + if type(prototype) ~= "table" then + error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2) + end + self.defaultModulePrototype = prototype +end + +--- Set the state of an addon or module +-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize. +-- @name //addon//:SetEnabledState +-- @paramsig state +-- @param state the state of an addon or module (enabled=true, disabled=false) +function SetEnabledState(self, state) + self.enabledState = state +end + + +--- Return an iterator of all modules associated to the addon. +-- @name //addon//:IterateModules +-- @paramsig +-- @usage +-- -- Enable all modules +-- for name, module in MyAddon:IterateModules() do +-- module:Enable() +-- end +local function IterateModules(self) return pairs(self.modules) end + +-- Returns an iterator of all embeds in the addon +-- @name //addon//:IterateEmbeds +-- @paramsig +local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end + +--- Query the enabledState of an addon. +-- @name //addon//:IsEnabled +-- @paramsig +-- @usage +-- if MyAddon:IsEnabled() then +-- MyAddon:Disable() +-- end +local function IsEnabled(self) return self.enabledState end +local mixins = { + NewModule = NewModule, + GetModule = GetModule, + Enable = Enable, + Disable = Disable, + EnableModule = EnableModule, + DisableModule = DisableModule, + IsEnabled = IsEnabled, + SetDefaultModuleLibraries = SetDefaultModuleLibraries, + SetDefaultModuleState = SetDefaultModuleState, + SetDefaultModulePrototype = SetDefaultModulePrototype, + SetEnabledState = SetEnabledState, + IterateModules = IterateModules, + IterateEmbeds = IterateEmbeds, + GetName = GetName, +} +local function IsModule(self) return false end +local pmixins = { + defaultModuleState = true, + enabledState = true, + IsModule = IsModule, +} +-- Embed( target ) +-- target (object) - target object to embed aceaddon in +-- +-- this is a local function specifically since it's meant to be only called internally +function Embed(target, skipPMixins) + for k, v in pairs(mixins) do + target[k] = v + end + if not skipPMixins then + for k, v in pairs(pmixins) do + target[k] = target[k] or v + end + end +end + + +-- - Initialize the addon after creation. +-- This function is only used internally during the ADDON_LOADED event +-- It will call the **OnInitialize** function on the addon object (if present), +-- and the **OnEmbedInitialize** function on all embeded libraries. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- @param addon addon object to intialize +function AceAddon:InitializeAddon(addon) + safecall(addon.OnInitialize, addon) + + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedInitialize, lib, addon) end + end + + -- we don't call InitializeAddon on modules specifically, this is handled + -- from the event handler and only done _once_ +end + +-- - Enable the addon after creation. +-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED, +-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons. +-- It will call the **OnEnable** function on the addon object (if present), +-- and the **OnEmbedEnable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Enable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:EnableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if self.statuses[addon.name] or not addon.enabledState then return false end + + -- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable. + self.statuses[addon.name] = true + + safecall(addon.OnEnable, addon) + + -- make sure we're still enabled before continueing + if self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedEnable, lib, addon) end + end + + -- enable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:EnableAddon(modules[i]) + end + end + return self.statuses[addon.name] -- return true if we're disabled +end + +-- - Disable the addon +-- Note: This function is only used internally. +-- It will call the **OnDisable** function on the addon object (if present), +-- and the **OnEmbedDisable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Disable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:DisableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if not self.statuses[addon.name] then return false end + + -- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable. + self.statuses[addon.name] = false + + safecall( addon.OnDisable, addon ) + + -- make sure we're still disabling... + if not self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedDisable, lib, addon) end + end + -- disable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:DisableAddon(modules[i]) + end + end + + return not self.statuses[addon.name] -- return true if we're disabled +end + +--- Get an iterator over all registered addons. +-- @usage +-- -- Print a list of all installed AceAddon's +-- for name, addon in AceAddon:IterateAddons() do +-- print("Addon: " .. name) +-- end +function AceAddon:IterateAddons() return pairs(self.addons) end + +--- Get an iterator over the internal status registry. +-- @usage +-- -- Print a list of all enabled addons +-- for name, status in AceAddon:IterateAddonStatus() do +-- if status then +-- print("EnabledAddon: " .. name) +-- end +-- end +function AceAddon:IterateAddonStatus() return pairs(self.statuses) end + +-- Following Iterators are deprecated, and their addon specific versions should be used +-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon) +function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end +function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end + +-- Event Handling +local function onEvent(this, event, arg1) + -- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up + if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_DebugTools") or event == "PLAYER_LOGIN" then + -- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration + while(#AceAddon.initializequeue > 0) do + local addon = tremove(AceAddon.initializequeue, 1) + -- this might be an issue with recursion - TODO: validate + if event == "ADDON_LOADED" then addon.baseName = arg1 end + AceAddon:InitializeAddon(addon) + tinsert(AceAddon.enablequeue, addon) + end + + if IsLoggedIn() then + while(#AceAddon.enablequeue > 0) do + local addon = tremove(AceAddon.enablequeue, 1) + AceAddon:EnableAddon(addon) + end + end + end +end + +AceAddon.frame:RegisterEvent("ADDON_LOADED") +AceAddon.frame:RegisterEvent("PLAYER_LOGIN") +AceAddon.frame:SetScript("OnEvent", onEvent) + +-- upgrade embeded +for name, addon in pairs(AceAddon.addons) do + Embed(addon, true) +end + +-- 2010-10-27 nevcairiel - add new "orderedModules" table +if oldminor and oldminor < 10 then + for name, addon in pairs(AceAddon.addons) do + addon.orderedModules = {} + for module_name, module in pairs(addon.modules) do + tinsert(addon.orderedModules, module) + end + end +end diff --git a/libs/AceAddon-3.0/AceAddon-3.0.xml b/libs/AceAddon-3.0/AceAddon-3.0.xml new file mode 100644 index 0000000..dcf24c7 --- /dev/null +++ b/libs/AceAddon-3.0/AceAddon-3.0.xml @@ -0,0 +1,4 @@ + +