mirror of
https://github.com/Bluewhale1337/ElvUIModernized.git
synced 2026-07-27 16:34:45 +00:00
add AFK module
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
<Include file="DataTexts\Load_DataTexts.xml"/>
|
||||
<Include file="ActionBars\Load_ActionBars.xml"/>
|
||||
<Include file="Maps\Load_Maps.xml"/>
|
||||
<Include file="Misc\Load_Misc.xml"/>
|
||||
<Include file="Chat\Load_Chat.xml"/>
|
||||
<Include file="Skins\Load_Skins.xml"/>
|
||||
<Include file="DataBars\Load_DataBars.xml"/>
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
local E, L, V, P, G = unpack(ElvUI)
|
||||
local AFK = E:NewModule("AFK", "AceEvent-3.0", "AceTimer-3.0")
|
||||
-- local CH = E:GetModule("Chat")
|
||||
|
||||
local _G = getfenv()
|
||||
local GetTime = GetTime
|
||||
local floor = math.floor
|
||||
|
||||
local CinematicFrame = CinematicFrame
|
||||
local CreateFrame = CreateFrame
|
||||
local GetBattlefieldStatus = GetBattlefieldStatus
|
||||
local GetGuildInfo = GetGuildInfo
|
||||
local GetScreenHeight = GetScreenHeight
|
||||
local GetScreenWidth = GetScreenWidth
|
||||
local UnitAffectingCombat = UnitAffectingCombat
|
||||
local IsInGuild = IsInGuild
|
||||
local IsShiftKeyDown = IsShiftKeyDown
|
||||
local Screenshot = Screenshot
|
||||
local SetCVar = SetCVar
|
||||
local UnitFactionGroup = UnitFactionGroup
|
||||
|
||||
local CUSTOM_CLASS_COLORS = CUSTOM_CLASS_COLORS
|
||||
local MAX_BATTLEFIELD_QUEUES = MAX_BATTLEFIELD_QUEUES
|
||||
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
|
||||
|
||||
local AFK_SPEED = 7.35
|
||||
|
||||
local ignoreKeys = {
|
||||
LALT = true,
|
||||
LSHIFT = true,
|
||||
RSHIFT = true
|
||||
}
|
||||
|
||||
local printKeys = {
|
||||
["PRINTSCREEN"] = true,
|
||||
}
|
||||
|
||||
if IsMacClient() then
|
||||
printKeys[_G["KEY_PRINTSCREEN_MAC"]] = true
|
||||
end
|
||||
|
||||
function AFK:UpdateTimer()
|
||||
local time = GetTime() - self.startTime
|
||||
self.AFKMode.bottom.time:SetText(format("%02d:%02d", floor(time / 60), math.floor(time / 60) * 60))
|
||||
end
|
||||
|
||||
local function StopAnimation(self)
|
||||
self:SetSequenceTime(0, 0)
|
||||
self:SetScript("OnUpdate", nil)
|
||||
self:SetScript("OnAnimFinished", nil)
|
||||
end
|
||||
|
||||
local function UpdateAnimation(...)
|
||||
this.animTime = this.animTime + (arg1 * 1000)
|
||||
this:SetSequenceTime(67, this.animTime)
|
||||
|
||||
if this.animTime >= 3000 then
|
||||
StopAnimation(this)
|
||||
end
|
||||
end
|
||||
|
||||
local function OnAnimFinished(self)
|
||||
if self.animTime > 500 then
|
||||
StopAnimation(self)
|
||||
end
|
||||
end
|
||||
|
||||
local recountVis
|
||||
local function RecountVisability(save)
|
||||
if Recount and Recount.db and Recount.db.profile then
|
||||
if save then
|
||||
recountVis = Recount.db.profile.MainWindowVis
|
||||
else
|
||||
Recount.db.profile.MainWindowVis = recountVis
|
||||
RecountDB.profiles[Recount.db.keys.profile].MainWindowVis = recountVis
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local LRC
|
||||
local function RockConfigFix()
|
||||
if not LRC then
|
||||
LRC = LibStub("LibRockConfig-1.0", true)
|
||||
end
|
||||
if LRC then
|
||||
if LRC.base and LRC.base:IsShown() then
|
||||
LRC.base.addonChooser:Select(LRC.base.addonChooser.value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AFK:SetAFK(status)
|
||||
if status and not self.isAFK then
|
||||
if InspectFrame then
|
||||
InspectPaperDollFrame:Hide()
|
||||
end
|
||||
|
||||
RecountVisability(true)
|
||||
UIParent:Hide()
|
||||
self.AFKMode:Show()
|
||||
RecountVisability()
|
||||
|
||||
E.global.afkEnabled = true
|
||||
E.global.afkCameraSpeedYaw = GetCVar("cameraYawMoveSpeed")
|
||||
E.global.afkCameraSpeedPitch = GetCVar("cameraPitchMoveSpeed")
|
||||
MoveViewLeftStart()
|
||||
|
||||
SetCVar("cameraYawMoveSpeed", AFK_SPEED)
|
||||
SetCVar("cameraPitchMoveSpeed", E.global.afkCameraSpeedPitch)
|
||||
|
||||
if IsInGuild() then
|
||||
local guildName, guildRankName = GetGuildInfo("player")
|
||||
self.AFKMode.bottom.guild:SetText(format("%s - %s", guildName, guildRankName))
|
||||
else
|
||||
self.AFKMode.bottom.guild:SetText(L["No Guild"])
|
||||
end
|
||||
|
||||
self.startTime = GetTime()
|
||||
self.timer = self:ScheduleRepeatingTimer("UpdateTimer", 1)
|
||||
|
||||
self.AFKMode.chat:RegisterEvent("CHAT_MSG_WHISPER")
|
||||
self.AFKMode.chat:RegisterEvent("CHAT_MSG_GUILD")
|
||||
|
||||
self.AFKMode.bottom.model:SetModelScale(1)
|
||||
self.AFKMode.bottom.model:RefreshUnit()
|
||||
self.AFKMode.bottom.model:SetModelScale(0.8)
|
||||
|
||||
self.AFKMode.bottom.model.animTime = 0
|
||||
self.AFKMode.bottom.model:SetScript("OnUpdate", UpdateAnimation)
|
||||
self.AFKMode.bottom.model:SetScript("OnAnimFinished", OnAnimFinished)
|
||||
|
||||
self.isAFK = true
|
||||
elseif not status and self.isAFK then
|
||||
self.AFKMode:Hide()
|
||||
UIParent:Show()
|
||||
|
||||
E.global.afkEnabled = nil
|
||||
SetCVar("cameraYawMoveSpeed", E.global.afkCameraSpeedYaw)
|
||||
SetCVar("cameraPitchMoveSpeed", E.global.afkCameraSpeedPitch)
|
||||
|
||||
MoveViewLeftStop()
|
||||
|
||||
self:CancelTimer(self.timer)
|
||||
self.AFKMode.bottom.time:SetText("00:00")
|
||||
|
||||
self.AFKMode.chat:UnregisterAllEvents()
|
||||
self.AFKMode.chat:Clear()
|
||||
|
||||
self.isAFK = false
|
||||
|
||||
RockConfigFix()
|
||||
end
|
||||
end
|
||||
|
||||
function AFK:OnEvent(event, ...)
|
||||
if event == "PLAYER_REGEN_DISABLED" or event == "UPDATE_BATTLEFIELD_STATUS" then
|
||||
if event == "UPDATE_BATTLEFIELD_STATUS" then
|
||||
local status, _, instanceID
|
||||
for i = 1, MAX_BATTLEFIELD_QUEUES do
|
||||
status, _, instanceID = GetBattlefieldStatus(i)
|
||||
if instanceID ~= 0 then
|
||||
status = status
|
||||
end
|
||||
end
|
||||
local status = status
|
||||
if status == "confirm" then
|
||||
self:SetAFK(false)
|
||||
end
|
||||
else
|
||||
self:SetAFK(false)
|
||||
end
|
||||
|
||||
if event == "PLAYER_REGEN_DISABLED" then
|
||||
self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEvent")
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if event == "PLAYER_REGEN_ENABLED" then
|
||||
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
|
||||
end
|
||||
|
||||
if not E.db.general.afk then return end
|
||||
if UnitAffectingCombat("player") or CinematicFrame:IsShown() then return end
|
||||
if event == "CURRENT_SPELL_CAST_CHANGED" then
|
||||
--Don't activate afk if player is crafting stuff, check back in 30 seconds
|
||||
self:ScheduleTimer("OnEvent", 30)
|
||||
return
|
||||
end
|
||||
print(unpack(arg1))
|
||||
-- if event == "PLAYER_FLAGS_CHANGED" and self
|
||||
-- self:SetAFK(true)
|
||||
end
|
||||
|
||||
function AFK:Toggle()
|
||||
if E.db.general.afk then
|
||||
self:RegisterEvent("PLAYER_FLAGS_CHANGED", "OnEvent")
|
||||
self:RegisterEvent("PLAYER_REGEN_DISABLED", "OnEvent")
|
||||
self:RegisterEvent("UPDATE_BATTLEFIELD_STATUS", "OnEvent")
|
||||
|
||||
SetCVar("autoClearAFK", "1")
|
||||
else
|
||||
self:UnregisterEvent("PLAYER_FLAGS_CHANGED")
|
||||
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
|
||||
self:UnregisterEvent("UPDATE_BATTLEFIELD_STATUS")
|
||||
|
||||
self:CancelAllTimers()
|
||||
end
|
||||
end
|
||||
|
||||
local function OnKeyDown(_, key)
|
||||
if ignoreKeys[key] then return end
|
||||
if printKeys[key] then
|
||||
Screenshot()
|
||||
else
|
||||
AFK:SetAFK(false)
|
||||
AFK:ScheduleTimer("OnEvent", 60)
|
||||
end
|
||||
end
|
||||
|
||||
local function Chat_OnMouseWheel(self, delta)
|
||||
if delta == 1 and IsShiftKeyDown() then
|
||||
self:ScrollToTop()
|
||||
elseif delta == -1 and IsShiftKeyDown() then
|
||||
self:ScrollToBottom()
|
||||
elseif delta == -1 then
|
||||
self:ScrollDown()
|
||||
else
|
||||
self:ScrollUp()
|
||||
end
|
||||
end
|
||||
|
||||
function AFK:Initialize()
|
||||
if E.global.afkEnabled then
|
||||
SetCVar("cameraYawMoveSpeed", E.global.afkCameraSpeedYaw)
|
||||
SetCVar("cameraPitchMoveSpeed", E.global.afkCameraSpeedPitch)
|
||||
E.global.afkEnabled = nil
|
||||
end
|
||||
|
||||
local classColor = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[E.myclass] or RAID_CLASS_COLORS[E.myclass]
|
||||
|
||||
self.AFKMode = CreateFrame("Frame", "ElvUIAFKFrame")
|
||||
self.AFKMode:SetFrameLevel(1)
|
||||
self.AFKMode:SetScale(UIParent:GetScale())
|
||||
self.AFKMode:SetAllPoints(UIParent)
|
||||
self.AFKMode:Hide()
|
||||
self.AFKMode:EnableKeyboard(true)
|
||||
self.AFKMode:SetScript("OnKeyDown", OnKeyDown)
|
||||
|
||||
self.AFKMode.chat = CreateFrame("ScrollingMessageFrame", "AFKChat", self.AFKMode)
|
||||
self.AFKMode.chat:SetWidth(500)
|
||||
self.AFKMode.chat:SetHeight(200)
|
||||
self.AFKMode.chat:SetPoint("TOPLEFT", self.AFKMode, "TOPLEFT", 4, -3)
|
||||
E:FontTemplate(self.AFKMode.chat)
|
||||
self.AFKMode.chat:SetJustifyH("LEFT")
|
||||
self.AFKMode.chat:SetMaxLines(500)
|
||||
self.AFKMode.chat:EnableMouseWheel(true)
|
||||
self.AFKMode.chat:SetFading(false)
|
||||
self.AFKMode.chat:SetMovable(true)
|
||||
self.AFKMode.chat:EnableMouse(true)
|
||||
self.AFKMode.chat:SetClampedToScreen(true)
|
||||
-- self.AFKMode.chat:SetClampRectInsets(-4, 3, 3, -4)
|
||||
self.AFKMode.chat:RegisterForDrag("LeftButton")
|
||||
self.AFKMode.chat:SetScript("OnDragStart", self.AFKMode.chat.StartMoving)
|
||||
self.AFKMode.chat:SetScript("OnDragStop", self.AFKMode.chat.StopMovingOrSizing)
|
||||
self.AFKMode.chat:SetScript("OnMouseWheel", Chat_OnMouseWheel)
|
||||
-- self.AFKMode.chat:SetScript("OnEvent", CH.ChatFrame_OnEvent)
|
||||
|
||||
self.AFKMode.bottom = CreateFrame("Frame", nil, self.AFKMode)
|
||||
self.AFKMode.bottom:SetFrameLevel(0)
|
||||
E:SetTemplate(self.AFKMode.bottom, "Transparent")
|
||||
self.AFKMode.bottom:SetPoint("BOTTOM", self.AFKMode, "BOTTOM", 0, -E.Border)
|
||||
self.AFKMode.bottom:SetWidth(GetScreenWidth() + (E.Border*2))
|
||||
self.AFKMode.bottom:SetHeight(GetScreenHeight() * 0.1)
|
||||
|
||||
self.AFKMode.bottom.logo = self.AFKMode:CreateTexture(nil, "OVERLAY")
|
||||
self.AFKMode.bottom.logo:SetWidth(320)
|
||||
self.AFKMode.bottom.logo:SetHeight(150)
|
||||
self.AFKMode.bottom.logo:SetPoint("CENTER", self.AFKMode.bottom, "CENTER", 0, 50)
|
||||
self.AFKMode.bottom.logo:SetTexture("Interface\\AddOns\\ElvUI\\media\\textures\\logo")
|
||||
|
||||
local factionGroup = UnitFactionGroup("player")
|
||||
self.AFKMode.bottom.faction = self.AFKMode.bottom:CreateTexture(nil, "OVERLAY")
|
||||
self.AFKMode.bottom.faction:SetPoint("BOTTOMLEFT", self.AFKMode.bottom, "BOTTOMLEFT", -20, -16)
|
||||
self.AFKMode.bottom.faction:SetTexture("Interface\\AddOns\\ElvUI\\media\\textures\\"..factionGroup.."-Logo")
|
||||
self.AFKMode.bottom.faction:SetWidth(140)
|
||||
self.AFKMode.bottom.faction:SetHeight(140)
|
||||
|
||||
self.AFKMode.bottom.name = self.AFKMode.bottom:CreateFontString(nil, "OVERLAY")
|
||||
E:FontTemplate(self.AFKMode.bottom.name, nil, 20)
|
||||
self.AFKMode.bottom.name:SetText(format("%s - %s", E.myname, E.myrealm))
|
||||
self.AFKMode.bottom.name:SetPoint("TOPLEFT", self.AFKMode.bottom.faction, "TOPRIGHT", -10, -28)
|
||||
-- self.AFKMode.bottom.name:SetTextColor(classColor.r, classColor.g, classColor.b)
|
||||
|
||||
self.AFKMode.bottom.guild = self.AFKMode.bottom:CreateFontString(nil, "OVERLAY")
|
||||
E:FontTemplate(self.AFKMode.bottom.guild, nil, 20)
|
||||
self.AFKMode.bottom.guild:SetText(L["No Guild"])
|
||||
self.AFKMode.bottom.guild:SetPoint("TOPLEFT", self.AFKMode.bottom.name, "BOTTOMLEFT", 0, -6)
|
||||
self.AFKMode.bottom.guild:SetTextColor(0.7, 0.7, 0.7)
|
||||
|
||||
self.AFKMode.bottom.time = self.AFKMode.bottom:CreateFontString(nil, "OVERLAY")
|
||||
E:FontTemplate(self.AFKMode.bottom.time, nil, 20)
|
||||
self.AFKMode.bottom.time:SetText("00:00")
|
||||
self.AFKMode.bottom.time:SetPoint("TOPLEFT", self.AFKMode.bottom.guild, "BOTTOMLEFT", 0, -6)
|
||||
self.AFKMode.bottom.time:SetTextColor(0.7, 0.7, 0.7)
|
||||
|
||||
self.AFKMode.bottom.model = CreateFrame("PlayerModel", "ElvUIAFKPlayerModel", self.AFKMode.bottom)
|
||||
self.AFKMode.bottom.model:SetPoint("BOTTOMRIGHT", self.AFKMode.bottom, "BOTTOMRIGHT", 120, -100)
|
||||
self.AFKMode.bottom.model:SetWidth(800)
|
||||
self.AFKMode.bottom.model:SetHeight(800)
|
||||
self.AFKMode.bottom.model:SetFacing(6)
|
||||
self.AFKMode.bottom.model:SetUnit("player")
|
||||
|
||||
self:Toggle()
|
||||
end
|
||||
|
||||
local function InitializeCallback()
|
||||
AFK:Initialize()
|
||||
end
|
||||
|
||||
E:RegisterModule(AFK:GetName(), InitializeCallback)
|
||||
@@ -0,0 +1,3 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/">
|
||||
<Script file="AFK.lua"/>
|
||||
</Ui>
|
||||
Reference in New Issue
Block a user