Skip to content

Instantly share code, notes, and snippets.

@Marabon
Created February 4, 2024 03:56
Show Gist options
  • Save Marabon/6acd07c132bc047a1b3a1e8b362a2f7b to your computer and use it in GitHub Desktop.
Save Marabon/6acd07c132bc047a1b3a1e8b362a2f7b to your computer and use it in GitHub Desktop.
--[[
Copyright 2012-2023 João Cardoso
All Rights Reserved
--]]
local MODULE = ...
local ADDON, Addon = MODULE:match('[^_]+'), _G[MODULE:match('[^_]+')]
local Alerts = Addon:NewModule('Alerts', LibStub('Sushi-3.2').Glowbox(PetBattleFrame))
local L = LibStub('AceLocale-3.0'):GetLocale(ADDON)
local instancename, instancetype, instancedifficultyIndex, instancedifficultyName, instancemaxPlayers, instancedynamicDifficulty, instanceisDynamic, instanceMapId, instancelfgID = GetInstanceInfo()
local isPetDungeon = false
local petDungeons = { 1161, 1687, 1688, 1694, 2179, 2282 }
local function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
if has_value(petDungeons, instanceMapId) then
isPetDungeon = true
else
isPetDungeon = false
end
function Alerts:OnEnable()
self:RegisterEvent('PET_BATTLE_CLOSE', 'Reset')
self:RegisterSignal('BATTLE_STARTED', 'Verify')
self:RegisterSignal('COLLECTION_CHANGED', 'Verify')
self:SetPoint('TOP', PetBattleFrame.ActiveEnemy.Icon, 'BOTTOM', 0, -20)
self:SetCall('OnClose', function() self.shown = true end)
self:SetText(L.UpgradeAlert)
self:SetFrameStrata('HIGH')
self:SetDirection('TOP')
end
function Alerts:Verify()
local upgrades = Addon.Battle:AnyUpgrade()
if not upgrades and Addon.Battle:IsWildBattle() and not isPetDungeon and not self.popped and Addon.sets.forfeit then
self.popped = true
LibStub('Sushi-3.2').Popup {
id = ADDON .. 'Alerts',
text = L.AskForfeit, button1 = QUIT, button2 = NO,
OnAccept = C_PetBattles.ForfeitGame,
hideOnEscape = 1,
}
end
self:SetShown(upgrades and not self.shown and Addon.sets.alertUpgrades)
end
function Alerts:Reset()
self.shown, self.popped = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment