diff --git a/ElvUI/Bindings.xml b/ElvUI/Bindings.xml new file mode 100644 index 0000000..7fa753a --- /dev/null +++ b/ElvUI/Bindings.xml @@ -0,0 +1,17 @@ + + + RaidMark_HotkeyPressed(keystate); + + + FarmMode(); + + + HideLeftChat(); + + + HideRightChat(); + + + HideBothChat(); + + \ No newline at end of file diff --git a/ElvUI/Core/ClassCache.lua b/ElvUI/Core/ClassCache.lua new file mode 100644 index 0000000..c28d86e --- /dev/null +++ b/ElvUI/Core/ClassCache.lua @@ -0,0 +1,463 @@ +local E, L, V, P, G = unpack(ElvUI); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB +local CC = E:NewModule("ClassCache", "AceEvent-3.0"); +local LW = LibStub:GetLibrary("LibWho-2.0"); + +--Cache global variables +--Lua functions +local split, upper = string.split, string.upper +local wipe = table.wipe +local pairs = pairs +local select = select +--WoW API / Variables +local GetBattlefieldScore = GetBattlefieldScore +local GetFriendInfo = GetFriendInfo +local GetGuildRosterInfo = GetGuildRosterInfo +local GetNumBattlefieldScores = GetNumBattlefieldScores +local GetNumFriends = GetNumFriends +local GetNumGuildMembers = GetNumGuildMembers +local GetNumPartyMembers = GetNumPartyMembers +local GetNumRaidMembers = GetNumRaidMembers +local GetTime = GetTime +local IsInGuild = IsInGuild +local UnitClass = UnitClass +local UnitExists = UnitExists +local UnitIsPlayer = UnitIsPlayer +local UnitName = UnitName + +local UNKNOWN = UNKNOWN + +local GAME_LOCALE = GetLocale() +local ENGLISH_CLASS_NAMES + +local function GetEnglishClassName(class) + if class == UNKNOWN then + return class + elseif GAME_LOCALE == "enUS" then + return upper(class) + end + + if not ENGLISH_CLASS_NAMES then + ENGLISH_CLASS_NAMES = {} + + for english, localized in pairs(LOCALIZED_CLASS_NAMES_MALE) do + ENGLISH_CLASS_NAMES[localized] = english + end + for english, localized in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do + ENGLISH_CLASS_NAMES[localized] = english + end + end + + return ENGLISH_CLASS_NAMES[class] +end + +local function WhoCallback(result) + if result then + if result.NoLocaleClass then + CC:CachePlayer(result.Name, result.NoLocaleClass) + CC:SendMessage("ClassCacheQueryResult", result.Name, result.NoLocaleClass) + end + end +end + +function CC:GetClassByName(name, realm) + if not name or name == "" then return end + if realm and realm == "" then return end + + if E.db.general.classCacheStoreInDB then + if realm then + if self.cache[realm] and self.cache[realm][name] then + return self.cache[realm][name] + else + return + end + else + if self.cache[E.myrealm][name] then + return self.cache[E.myrealm][name] + end + end + else + if realm then + if self.tempCache[realm] and self.tempCache[realm][name] then + return self.tempCache[realm][name] + else + return + end + else + if self.tempCache[E.myrealm][name] then + return self.tempCache[E.myrealm][name] + end + end + end + + if E.db.general.classCacheRequestInfo then + local result = LW:UserInfo(name, { + queue = LW.WHOLIB_QUEUE_QUIET, + timeout = 0, + callback = function(result) + WhoCallback(result) + end + }) + + if result and result.NoLocaleClass then + self:CachePlayer(result.Name, result.NoLocaleClass) + return result.NoLocaleClass + end + end +end + +function CC:CachePlayer(name, class, realm) + if not (name and class and class ~= UNKNOWN) then return end + + if realm and realm == "" then return end + + if E.db.general.classCacheStoreInDB then + if realm and not self.cache[realm] then + self.cache[realm] = {} + end + + if realm then + self.cache[realm][name] = class + else + self.cache[E.myrealm][name] = class + end + else + if realm and not self.tempCache[realm] then + self.tempCache[realm] = {} + end + + if realm then + self.tempCache[realm][name] = class + else + self.tempCache[E.myrealm][name] = class + end + end +end + +function CC:SwitchCacheType(init) + if E.db.general.classCacheStoreInDB then + if not self.cache[E.myrealm] then + self.cache[E.myrealm] = {} + end + + if not self.cache[E.myrealm][E.myname] then + self.cache[E.myrealm][E.myname] = E.myclass + end + + if not init then + for realm in pairs(self.tempCache) do + if not self.cache[realm] then + self.cache[realm] = {} + end + + for name, class in pairs(self.tempCache[realm]) do + self.cache[realm][name] = class + end + end + end + else + if not self.tempCache[E.myrealm] then + self.tempCache[E.myrealm] = {} + end + + if not self.tempCache[E.myrealm][E.myname] then + self.tempCache[E.myrealm][E.myname] = E.myclass + end + + if not init then + for realm in pairs(self.cache) do + if not self.cache[realm] then + self.tempCache[realm] = {} + end + + for name, class in pairs(self.cache[realm]) do + self.tempCache[realm][name] = class + end + end + end + end +end + +function CC:GetCacheTable() + if E.db.general.classCacheStoreInDB then + return self.cache + else + return self.tempCache + end +end + +function CC:GetCacheSize(global) + if global and not (self.cacheDBCalculationTime + 30 < GetTime()) then + return self.cacheDBSize > 1, self.cacheDBSize + elseif not global and not (self.cacheLocalCalculationTime + 30 < GetTime()) then + return self.cacheLocalSize > 1, self.cacheLocalSize + end + + local size = 0 + + if global then + for realm in pairs(self.cache) do + for name in pairs(self.cache[realm]) do + size = size + 1 + end + end + + self.cacheDBSize = size + self.cacheDBCalculationTime = GetTime() + else + for realm in pairs(self.tempCache) do + for name in pairs(self.tempCache[realm]) do + size = size + 1 + end + end + + self.cacheLocalSize = size + self.cacheLocalCalculationTime = GetTime() + end + + return size > 1, size +end + +function CC:WipeCache(global) + if global then + for realm in pairs(self.cache) do + wipe(realm) + end + + wipe(self.cache) + self:SwitchCacheType(true) + self.cacheDBCalculationTime = 0 + + E:Print(L["Class DB cache wiped."]) + else + for realm in pairs(self.tempCache) do + wipe(realm) + end + + wipe(self.tempCache) + self:SwitchCacheType(true) + self.cacheLocalCalculationTime = 0 + + E:Print(L["Class session cache wiped."]) + end +end + +function CC:PLAYER_ENTERING_WORLD() + local inInstance, instanceType = IsInInstance() + self.inInstance = inInstance + + if instanceType == "arena" or instanceType == "pvp" then + self.inBattleground = true + else + self.inBattleground = false + end + + if self.inInstance or self.inBattleground then + self.lastNumPlayers = 0 + + self:UnregisterEvent("PLAYER_TARGET_CHANGED") + self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT") + + self:UnregisterEvent("PARTY_MEMBERS_CHANGED") + self:UnregisterEvent("RAID_ROSTER_UPDATE") + + + self:RegisterEvent("UPDATE_BATTLEFIELD_SCORE") + + if self.inBattleground then + self:UPDATE_BATTLEFIELD_SCORE() + end + else + self.lastNumPlayers = 0 + + self:RegisterEvent("PLAYER_TARGET_CHANGED") + self:RegisterEvent("UPDATE_MOUSEOVER_UNIT") + + self:RegisterEvent("PARTY_MEMBERS_CHANGED") + self:RegisterEvent("RAID_ROSTER_UPDATE") + + self:UnregisterEvent("UPDATE_BATTLEFIELD_SCORE") + end + + self:PLAYER_GUILD_UPDATE() + + if not self.initUpdate then + if GetNumRaidMembers() > 0 then + self:RAID_ROSTER_UPDATE() + elseif GetNumPartyMembers() > 0 then + self:PARTY_MEMBERS_CHANGED() + end + + self:GUILD_ROSTER_UPDATE(nil, true) + + self.initUpdate = true + end +end + +function CC:PLAYER_GUILD_UPDATE() + if IsInGuild() then + self:RegisterEvent("GUILD_ROSTER_UPDATE") + else + self:UnregisterEvent("RAID_ROSTER_UPDATE") + end +end + +function CC:FRIENDLIST_UPDATE() + local name, class, _ + + for i = 1, GetNumFriends() do + name, _, class = GetFriendInfo(i) + + if class then + self:CachePlayer(name, GetEnglishClassName(class)) + end + end +end + +function CC:GUILD_ROSTER_UPDATE(_, update) + if not update then return end + + local name, class, _ + + for i = 1, GetNumGuildMembers() do + name, _, _, _, _, _, _, _, _, _, class = GetGuildRosterInfo(i) + + if class then + self:CachePlayer(name, class) + end + end +end + +function CC:PARTY_MEMBERS_CHANGED() + local name, realm, class, _ + + for i = 1, GetNumPartyMembers() do + name, realm = UnitName("party"..i) + _, class = UnitClass("party"..i) + + if not class then return end + + if self.inBattleground then + self:CachePlayer(name, class, realm) + else + self:CachePlayer(name, class) + end + end +end + +function CC:RAID_ROSTER_UPDATE() + local name, realm, class, _ + + for i = 1, GetNumRaidMembers() do + name, realm = UnitName("raid"..i) + _, class = UnitClass("raid"..i) + + if not class then return end + + if self.inBattleground then + self:CachePlayer(name, class, realm) + else + self:CachePlayer(name, class) + end + end +end + +function CC:PLAYER_TARGET_CHANGED() + if not UnitExists("target") or not UnitIsPlayer("target") then return end + + local _, class = UnitClass("target") + if not class then return end + + local name, realm = UnitName("target") + + if self.inBattleground then + self:CachePlayer(name, class, realm) + else + self:CachePlayer(name, class) + end +end + +function CC:UPDATE_MOUSEOVER_UNIT() + if not UnitExists("mouseover") or not UnitIsPlayer("mouseover") then return end + + local _, class = UnitClass("mouseover") + if not class then return end + + local name, realm = UnitName("mouseover") + + if self.inBattleground then + self:CachePlayer(name, class, realm) + else + self:CachePlayer(name, class) + end +end + +function CC:UPDATE_BATTLEFIELD_SCORE() + local numPlayers = GetNumBattlefieldScores() or 0 + + if self.lastNumPlayers == numPlayers then + return + elseif self.lastNumPlayers > numPlayers then + self.lastNumPlayers = numPlayers + return + end + + local name, realm, class, _ + + for i = 1, numPlayers do + name, _, _, _, _, _, _, _, _, class = GetBattlefieldScore(i) + + if name and class then + name, realm = split("-", name) + self:CachePlayer(name, class, realm) + end + end +end + +function CC:WHOLIB_QUERY_RESULT(_, query, results, complete) + for _, result in pairs(results) do + if result and result.NoLocaleClass then + self:CachePlayer(result.Name, result.NoLocaleClass) + end + end +end + +function CC:ToggleModule() + if E.private.general.classCache then + if not self.initialized then + self:SwitchCacheType(true) + self.initialized = true + end + + self:RegisterEvent("PLAYER_ENTERING_WORLD") + self:RegisterEvent("PLAYER_GUILD_UPDATE") + + self:RegisterEvent("FRIENDLIST_UPDATE") + self:RegisterEvent("PARTY_MEMBERS_CHANGED") + self:RegisterEvent("RAID_ROSTER_UPDATE") + + LW.RegisterCallback(self, "WHOLIB_QUERY_RESULT", "WHOLIB_QUERY_RESULT") + else + self:UnregisterAllEvents() + LW.UnregisterAllCallbacks(self) + end +end + +function CC:Initialize() + self.cache = E.global.classCache + self.tempCache = {} + + self.cacheLocalCalculationTime = 0 + self.cacheDBCalculationTime = 0 + + LW:SetWhoLibDebug(false) + + if E.private.general.classCache then + self:ToggleModule() + end +end + +local function InitializeCallback() + CC:Initialize() +end + +E:RegisterModule(CC:GetName(), InitializeCallback) \ No newline at end of file diff --git a/ElvUI/Core/Commands.lua b/ElvUI/Core/Commands.lua new file mode 100644 index 0000000..c8b9078 --- /dev/null +++ b/ElvUI/Core/Commands.lua @@ -0,0 +1,130 @@ +local E, L, V, P, G = unpack(ElvUI); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB + +--Cache global variables +--Lua functions +local _G = _G +local tonumber, type = tonumber, type +local format, lower, match = string.format, string.lower, string.match +--WoW API / Variables +local UIFrameFadeOut, UIFrameFadeIn = UIFrameFadeOut, UIFrameFadeIn +local EnableAddOn, DisableAddOn, DisableAllAddOns = EnableAddOn, DisableAddOn, DisableAllAddOns +local SetCVar = SetCVar +local ReloadUI = ReloadUI +local GetAddOnInfo = GetAddOnInfo + +function E:EnableAddon(addon) + local _, _, _, _, _, reason, _ = GetAddOnInfo(addon) + if reason ~= "MISSING" then + EnableAddOn(addon) + ReloadUI() + else + E:Print(format("Addon '%s' not found.", addon)) + end +end + +function E:DisableAddon(addon) + local _, _, _, _, _, reason, _ = GetAddOnInfo(addon) + if reason ~= "MISSING" then + DisableAddOn(addon) + ReloadUI() + else + E:Print(format("Addon '%s' not found.", addon)) + end +end + +function FarmMode() + if E.private.general.minimap.enable ~= true then return end + + if Minimap:IsShown() then + UIFrameFadeOut(Minimap, 0.3) + UIFrameFadeIn(FarmModeMap, 0.3) + Minimap.fadeInfo.finishedFunc = function() Minimap:Hide() _G.MinimapZoomIn:Click() _G.MinimapZoomOut:Click() Minimap:SetAlpha(1) end + FarmModeMap.enabled = true + else + UIFrameFadeOut(FarmModeMap, 0.3) + UIFrameFadeIn(Minimap, 0.3) + FarmModeMap.fadeInfo.finishedFunc = function() FarmModeMap:Hide() _G.MinimapZoomIn:Click() _G.MinimapZoomOut:Click() Minimap:SetAlpha(1) end + FarmModeMap.enabled = false + end +end + +function E:FarmMode(msg) + if E.private.general.minimap.enable ~= true then return end + if msg and type(tonumber(msg)) == "number" and tonumber(msg) <= 500 and tonumber(msg) >= 20 then + E.db.farmSize = tonumber(msg) + FarmModeMap:SetWidth(tonumber(msg)) + FarmModeMap:SetHeight(tonumber(msg)) + end + + FarmMode() +end + +function E:Grid(msg) + if msg and type(tonumber(msg)) == "number" and tonumber(msg) <= 256 and tonumber(msg) >= 4 then + E.db.gridSize = msg + E:Grid_Show() + else + if EGrid then + E:Grid_Hide() + else + E:Grid_Show() + end + end +end + +function E:LuaError(msg) + msg = lower(msg) + if msg == "on" then + DisableAllAddOns() + EnableAddOn("ElvUI") + EnableAddOn("ElvUI_Config") + SetCVar("ShowErrors", "1") + ReloadUI() + elseif msg == "off" then + SetCVar("ShowErrors", "0") + E:Print("Lua errors off.") + else + E:Print("/luaerror on - /luaerror off") + end +end + +function E:BGStats() + local DT = E:GetModule("DataTexts") + DT.ForceHideBGStats = nil + DT:LoadDataTexts() + + E:Print(L["Battleground datatexts will now show again if you are inside a battleground."]) +end + +local function OnCallback(command) + MacroEditBox:GetScript("OnEvent")(MacroEditBox, "EXECUTE_CHAT_LINE", command) +end + +function E:DelayScriptCall(msg) + local secs, command = match(msg, "^([^%s]+)%s+(.*)$") + secs = tonumber(secs) + if (not secs) or (getn(command) == 0) then + self:Print("usage: /in ") + self:Print("example: /in 1.5 /say hi") + else + E:ScheduleTimer(OnCallback, secs, command) + end +end + +function E:LoadCommands() + self:RegisterChatCommand("in", "DelayScriptCall") + self:RegisterChatCommand("ec", "ToggleConfig") + self:RegisterChatCommand("elvui", "ToggleConfig") + self:RegisterChatCommand("bgstats", "BGStats") + self:RegisterChatCommand("luaerror", "LuaError") + self:RegisterChatCommand("egrid", "Grid") + self:RegisterChatCommand("moveui", "ToggleConfigMode") + self:RegisterChatCommand("resetui", "ResetUI") + self:RegisterChatCommand("enable", "EnableAddon") + self:RegisterChatCommand("disable", "DisableAddon") + self:RegisterChatCommand("farmmode", "FarmMode") + +-- if E:GetModule("ActionBars") and E.private.actionbar.enable then +-- self:RegisterChatCommand("kb", E:GetModule("ActionBars").ActivateBindMode) +-- end +end \ No newline at end of file diff --git a/ElvUI/Core/Config.lua b/ElvUI/Core/Config.lua new file mode 100644 index 0000000..8e1c7f3 --- /dev/null +++ b/ElvUI/Core/Config.lua @@ -0,0 +1,497 @@ +local E, L, V, P, G = unpack(ElvUI); -- Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB + +--Cache global variables +--Lua functions +local _G = _G +local type, ipairs, tonumber = type, ipairs, tonumber +local floor = math.floor +--WoW API / Variables +local CreateFrame = CreateFrame +local IsAddOnLoaded = IsAddOnLoaded +local GetScreenWidth = GetScreenWidth +local GetScreenHeight = GetScreenHeight +local RESET = RESET + +local grid +local selectedValue = "ALL" + +E.ConfigModeLayouts = { + "ALL", + "GENERAL", + "SOLO", + "PARTY", + "RAID", + "ACTIONBARS" +} + +E.ConfigModeLocalizedStrings = { + ALL = ALL, + GENERAL = GENERAL, + SOLO = SOLO, + PARTY = PARTY, + RAID = RAID, + ACTIONBARS = ACTIONBAR_LABEL +} + +function E:Grid_Show() + if not grid then + E:Grid_Create() + elseif grid.boxSize ~= E.db.gridSize then + grid:Hide() + E:Grid_Create() + else + grid:Show() + end +end + +function E:Grid_Hide() + if grid then + grid:Hide() + end +end + +function E:ToggleConfigMode(override, configType) + if override ~= nil and override ~= "" then E.ConfigurationMode = override end + + if E.ConfigurationMode ~= true then + if not grid then + E:Grid_Create() + elseif grid.boxSize ~= E.db.gridSize then + grid:Hide() + E:Grid_Create() + else + grid:Show() + end + + if not ElvUIMoverPopupWindow then + E:CreateMoverPopup() + end + + ElvUIMoverPopupWindow:Show() + if(IsAddOnLoaded("ElvUI_Config")) then + LibStub("AceConfigDialog-3.0"):Close("ElvUI") + GameTooltip:Hide() + end + + E.ConfigurationMode = true + else + if ElvUIMoverPopupWindow then + ElvUIMoverPopupWindow:Hide() + end + + if grid then + grid:Hide() + end + + E.ConfigurationMode = false + end + + if type(configType) ~= "string" then + configType = nil + end + + self:ToggleMovers(E.ConfigurationMode, configType or "ALL") +end + +function E:Grid_Create() + grid = CreateFrame("Frame", "EGrid", UIParent) + grid.boxSize = E.db.gridSize + grid:SetAllPoints(E.UIParent) + grid:Show() + + local size = 1 + local width = E.eyefinity or GetScreenWidth() + local ratio = width / GetScreenHeight() + local height = GetScreenHeight() * ratio + + local wStep = width / E.db.gridSize + local hStep = height / E.db.gridSize + + for i = 0, E.db.gridSize do + local tx = grid:CreateTexture(nil, "BACKGROUND") + if i == E.db.gridSize / 2 then + tx:SetTexture(1, 0, 0) + else + tx:SetTexture(0, 0, 0) + end + tx:SetPoint("TOPLEFT", grid, "TOPLEFT", i*wStep - (size/2), 0) + tx:SetPoint("BOTTOMRIGHT", grid, "BOTTOMLEFT", i*wStep + (size/2), 0) + end + height = GetScreenHeight() + + do + local tx = grid:CreateTexture(nil, "BACKGROUND") + tx:SetTexture(1, 0, 0) + tx:SetPoint("TOPLEFT", grid, "TOPLEFT", 0, -(height/2) + (size/2)) + tx:SetPoint("BOTTOMRIGHT", grid, "TOPRIGHT", 0, -(height/2 + size/2)) + end + + for i = 1, floor((height/2)/hStep) do + local tx = grid:CreateTexture(nil, "BACKGROUND") + tx:SetTexture(0, 0, 0) + + tx:SetPoint("TOPLEFT", grid, "TOPLEFT", 0, -(height/2+i*hStep) + (size/2)) + tx:SetPoint("BOTTOMRIGHT", grid, "TOPRIGHT", 0, -(height/2+i*hStep + size/2)) + + tx = grid:CreateTexture(nil, "BACKGROUND") + tx:SetTexture(0, 0, 0) + + tx:SetPoint("TOPLEFT", grid, "TOPLEFT", 0, -(height/2-i*hStep) + (size/2)) + tx:SetPoint("BOTTOMRIGHT", grid, "TOPRIGHT", 0, -(height/2-i*hStep + size/2)) + end +end + +local function ConfigMode_OnClick() + selectedValue = this.value + E:ToggleConfigMode(false, this.value) + UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, this.value) +end + +local function ConfigMode_Initialize() + local info = {} + info.func = ConfigMode_OnClick + + for _, configMode in ipairs(E.ConfigModeLayouts) do + info.text = E.ConfigModeLocalizedStrings[configMode] + info.value = configMode + UIDropDownMenu_AddButton(info) + end + + UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, selectedValue) +end + +function E:NudgeMover(nudgeX, nudgeY) + local mover = ElvUIMoverNudgeWindow.child + + local x, y, point = E:CalculateMoverPoints(mover, nudgeX, nudgeY) + + mover:ClearAllPoints() + mover:SetPoint(mover.positionOverride or point, E.UIParent, mover.positionOverride and "BOTTOMLEFT" or point, x, y) + E:SaveMoverPosition(mover.name) + + E:UpdateNudgeFrame(mover, x, y) +end + +function E:UpdateNudgeFrame(mover, x, y) + if not(x and y) then + x, y = E:CalculateMoverPoints(mover) + end + + x = E:Round(x, 0) + y = E:Round(y, 0) + + ElvUIMoverNudgeWindow.xOffset:SetText(x) + ElvUIMoverNudgeWindow.yOffset:SetText(y) + ElvUIMoverNudgeWindow.xOffset.currentValue = x + ElvUIMoverNudgeWindow.yOffset.currentValue = y + ElvUIMoverNudgeWindowHeader.title:SetText(mover.textString) +end + +function E:AssignFrameToNudge() + ElvUIMoverNudgeWindow.child = self + E:UpdateNudgeFrame(self) +end + +function E:CreateMoverPopup() + local f = CreateFrame("Frame", "ElvUIMoverPopupWindow", UIParent) + f:SetFrameStrata("DIALOG") + f:SetToplevel(true) + f:EnableMouse(true) + f:SetMovable(true) + f:SetFrameLevel(99) + f:SetClampedToScreen(true) + f:SetWidth(360) + f:SetHeight(170) + E:SetTemplate(f, "Transparent") + f:SetPoint("BOTTOM", UIParent, "CENTER", 0, 100) + f:SetScript("OnHide", function() + if ElvUIMoverPopupWindowDropDown then + UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, "ALL") + end + end) + f:Hide() + + local S = E:GetModule("Skins") + + local header = CreateFrame("Button", nil, f) + E:SetTemplate(header, "Default", true) + header:SetWidth(100) header:SetHeight(25) + header:SetPoint("CENTER", f, "TOP") + header:SetFrameLevel(header:GetFrameLevel() + 2) + header:EnableMouse(true) + header:RegisterForClicks("AnyUp", "AnyDown") + header:SetScript("OnMouseDown", function() f:StartMoving() end) + header:SetScript("OnMouseUp", function() f:StopMovingOrSizing() end) + + local title = header:CreateFontString("OVERLAY") + E:FontTemplate(title) + title:SetPoint("CENTER", header, "CENTER") + title:SetText("ElvUI") + + local desc = f:CreateFontString("ARTWORK") + desc:SetFontObject("GameFontHighlight") + desc:SetJustifyV("TOP") + desc:SetJustifyH("LEFT") + desc:SetPoint("TOPLEFT", 18, -32) + desc:SetPoint("BOTTOMRIGHT", -18, 48) + desc:SetText(L["DESC_MOVERCONFIG"]) + + local snapping = CreateFrame("CheckButton", f:GetName().."CheckButton", f, "OptionsCheckButtonTemplate") + _G[snapping:GetName().."Text"]:SetText(L["Sticky Frames"]) + + snapping:SetScript("OnShow", function() + this:SetChecked(E.db.general.stickyFrames) + end) + + snapping:SetScript("OnClick", function() + E.db.general.stickyFrames = this:GetChecked() + end) + + local lock = CreateFrame("Button", f:GetName().."CloseButton", f, "OptionsButtonTemplate") + _G[lock:GetName().."Text"]:SetText(L["Lock"]) + + lock:SetScript("OnClick", function() + E:ToggleConfigMode(true) + + if(IsAddOnLoaded("ElvUI_Config")) then + LibStub("AceConfigDialog-3.0"):Open("ElvUI") + end + + selectedValue = "ALL" + UIDropDownMenu_SetSelectedValue(ElvUIMoverPopupWindowDropDown, selectedValue) + end) + + local align = CreateFrame("EditBox", f:GetName().."EditBox", f, "InputBoxTemplate") + align:SetWidth(32) + align:SetHeight(17) + align:SetAutoFocus(false) + align:SetScript("OnEscapePressed", function() + this:SetText(E.db.gridSize) + this:ClearFocus() + end) + align:SetScript("OnEnterPressed", function() + local text = this:GetText() + if tonumber(text) then + if tonumber(text) <= 256 and tonumber(text) >= 4 then + E.db.gridSize = tonumber(text) + else + this:SetText(E.db.gridSize) + end + else + this:SetText(E.db.gridSize) + end + E:Grid_Show() + this:ClearFocus() + end) + align:SetScript("OnEditFocusLost", function() + this:SetText(E.db.gridSize) + end) + align:SetScript("OnShow", function() + this:ClearFocus() + this:SetText(E.db.gridSize) + end) + + align.text = align:CreateFontString(nil, "OVERLAY", "GameFontNormal") + align.text:SetPoint("RIGHT", align, "LEFT", -4, 0) + align.text:SetText(L["Grid Size:"]) + + --position buttons + snapping:SetPoint("BOTTOMLEFT", 14, 10) + lock:SetPoint("BOTTOMRIGHT", -14, 14) + align:SetPoint("TOPRIGHT", lock, "TOPLEFT", -4, -2) + + S:HandleCheckBox(snapping) + S:HandleButton(lock) + S:HandleEditBox(align) + + f:RegisterEvent("PLAYER_REGEN_DISABLED") + f:SetScript("OnEvent", function() + if this:IsShown() then + this:Hide() + E:Grid_Hide() + E:ToggleConfigMode(true) + end + end) + + local configMode = CreateFrame("Frame", f:GetName().."DropDown", f, "UIDropDownMenuTemplate") + configMode:SetPoint("BOTTOMRIGHT", lock, "TOPRIGHT", 8, -5) + S:HandleDropDownBox(configMode, 148) + configMode.text = configMode:CreateFontString(nil, "OVERLAY", "GameFontNormal") + configMode.text:SetPoint("RIGHT", configMode.backdrop, "LEFT", -2, 0) + configMode.text:SetText(L["Config Mode:"]) + + UIDropDownMenu_Initialize(configMode, ConfigMode_Initialize) + + local nudgeFrame = CreateFrame("Frame", "ElvUIMoverNudgeWindow", E.UIParent) + nudgeFrame:SetFrameStrata("DIALOG") + nudgeFrame:SetWidth(200) + nudgeFrame:SetHeight(110) + E:SetTemplate(nudgeFrame, "Transparent") + nudgeFrame:SetPoint("TOP", ElvUIMoverPopupWindow, "BOTTOM", 0, -15) + nudgeFrame:SetFrameLevel(100) + nudgeFrame:Hide() + nudgeFrame:EnableMouse(true) + nudgeFrame:SetClampedToScreen(true) + HookScript(ElvUIMoverPopupWindow, "OnHide", function() ElvUIMoverNudgeWindow:Hide() end) + + header = CreateFrame("Button", "ElvUIMoverNudgeWindowHeader", nudgeFrame) + E:SetTemplate(header, "Default", true) + header:SetWidth(100) header:SetHeight(25) + header:SetPoint("CENTER", nudgeFrame, "TOP") + header:SetFrameLevel(header:GetFrameLevel() + 2) + + title = header:CreateFontString("OVERLAY") + E:FontTemplate(title) + title:SetPoint("CENTER", header, "CENTER") + title:SetText(L["Nudge"]) + header.title = title + + local xOffset = CreateFrame("EditBox", nudgeFrame:GetName().."XEditBox", nudgeFrame, "InputBoxTemplate") + xOffset:SetWidth(50) + xOffset:SetHeight(17) + xOffset:SetAutoFocus(false) + xOffset.currentValue = 0 + xOffset:SetScript("OnEscapePressed", function() + this:SetText(E:Round(xOffset.currentValue)) + this:ClearFocus() + end) + xOffset:SetScript("OnEnterPressed", function() + local num = this:GetText() + if(tonumber(num)) then + local diff = num - xOffset.currentValue + xOffset.currentValue = num + E:NudgeMover(diff) + end + this:SetText(E:Round(xOffset.currentValue)) + this:ClearFocus() + end) + xOffset:SetScript("OnEditFocusLost", function() + this:SetText(E:Round(xOffset.currentValue)) + end) + xOffset:SetScript("OnShow", function() + this:ClearFocus() + this:SetText(E:Round(xOffset.currentValue)) + end) + + xOffset.text = xOffset:CreateFontString(nil, "OVERLAY", "GameFontNormal") + xOffset.text:SetPoint("RIGHT", xOffset, "LEFT", -4, 0) + xOffset.text:SetText("X:") + xOffset:SetPoint("BOTTOMRIGHT", nudgeFrame, "CENTER", -6, 8) + nudgeFrame.xOffset = xOffset + S:HandleEditBox(xOffset) + + local yOffset = CreateFrame("EditBox", nudgeFrame:GetName().."YEditBox", nudgeFrame, "InputBoxTemplate") + yOffset:SetWidth(50) + yOffset:SetHeight(17) + yOffset:SetAutoFocus(false) + yOffset.currentValue = 0 + yOffset:SetScript("OnEscapePressed", function() + this:SetText(E:Round(yOffset.currentValue)) + this:ClearFocus() + end) + yOffset:SetScript("OnEnterPressed", function() + local num = this:GetText() + if(tonumber(num)) then + local diff = num - yOffset.currentValue + yOffset.currentValue = num + E:NudgeMover(nil, diff) + end + this:SetText(E:Round(yOffset.currentValue)) + this:ClearFocus() + end) + yOffset:SetScript("OnEditFocusLost", function() + this:SetText(E:Round(yOffset.currentValue)) + end) + yOffset:SetScript("OnShow", function() + this:ClearFocus() + this:SetText(E:Round(yOffset.currentValue)) + end) + + yOffset.text = yOffset:CreateFontString(nil, "OVERLAY", "GameFontNormal") + yOffset.text:SetPoint("RIGHT", yOffset, "LEFT", -4, 0) + yOffset.text:SetText("Y:") + yOffset:SetPoint("BOTTOMLEFT", nudgeFrame, "CENTER", 16, 8) + nudgeFrame.yOffset = yOffset + S:HandleEditBox(yOffset) + + local resetButton = CreateFrame("Button", nudgeFrame:GetName().."ResetButton", nudgeFrame, "UIPanelButtonTemplate") + resetButton:SetText(RESET) + resetButton:SetPoint("TOP", nudgeFrame, "CENTER", 0, 2) + resetButton:SetWidth(100) + resetButton:SetHeight(25) + resetButton:SetScript("OnClick", function() + if(ElvUIMoverNudgeWindow.child.textString) then + E:ResetMovers(ElvUIMoverNudgeWindow.child.textString) + E:UpdateNudgeFrame(ElvUIMoverNudgeWindow.child) + end + end) + S:HandleButton(resetButton) + -- Up Button + local upButton = CreateFrame("Button", nudgeFrame:GetName().."PrevButton", nudgeFrame) + upButton:SetWidth(26) + upButton:SetHeight(26) + upButton:SetPoint("BOTTOMRIGHT", nudgeFrame, "BOTTOM", -6, 4) + upButton:SetScript("OnClick", function() + E:NudgeMover(nil, 1) + end) + upButton.icon = upButton:CreateTexture(nil, "ARTWORK") + upButton.icon:SetWidth(13) + upButton.icon:SetHeight(13) + upButton.icon:SetPoint("CENTER", 0, 0) + upButton.icon:SetTexture([[Interface\AddOns\ElvUI\Media\Textures\SquareButtonTextures.blp]]) + upButton.icon:SetTexCoord(0.01562500, 0.20312500, 0.01562500, 0.20312500) + + S:SquareButton_SetIcon(upButton, "UP") + S:HandleButton(upButton) + -- Down Button + local downButton = CreateFrame("Button", nudgeFrame:GetName().."DownButton", nudgeFrame) + downButton:SetWidth(26) + downButton:SetHeight(26) + downButton:SetPoint("BOTTOMLEFT", nudgeFrame, "BOTTOM", 6, 4) + downButton:SetScript("OnClick", function() + E:NudgeMover(nil, -1) + end) + downButton.icon = downButton:CreateTexture(nil, "ARTWORK") + downButton.icon:SetWidth(13) + downButton.icon:SetHeight(13) + downButton.icon:SetPoint("CENTER", 0, 0) + downButton.icon:SetTexture([[Interface\AddOns\ElvUI\Media\Textures\SquareButtonTextures.blp]]) + downButton.icon:SetTexCoord(0.01562500, 0.20312500, 0.01562500, 0.20312500) + + S:SquareButton_SetIcon(downButton, "DOWN") + S:HandleButton(downButton) + -- Left Button + local leftButton = CreateFrame("Button", nudgeFrame:GetName().."LeftButton", nudgeFrame) + leftButton:SetWidth(26) + leftButton:SetHeight(26) + leftButton:SetPoint("RIGHT", upButton, "LEFT", -6, 0) + leftButton:SetScript("OnClick", function() + E:NudgeMover(-1) + end) + leftButton.icon = leftButton:CreateTexture(nil, "ARTWORK") + leftButton.icon:SetWidth(13) + leftButton.icon:SetHeight(13) + leftButton.icon:SetPoint("CENTER", 0, 0) + leftButton.icon:SetTexture([[Interface\AddOns\ElvUI\Media\Textures\SquareButtonTextures.blp]]) + leftButton.icon:SetTexCoord(0.01562500, 0.20312500, 0.01562500, 0.20312500) + + S:SquareButton_SetIcon(leftButton, "LEFT") + S:HandleButton(leftButton) + -- Right Button + local rightButton = CreateFrame("Button", nudgeFrame:GetName().."RightButton", nudgeFrame) + rightButton:SetWidth(26) + rightButton:SetHeight(26) + rightButton:SetPoint("LEFT", downButton, "RIGHT", 6, 0) + rightButton:SetScript("OnClick", function() + E:NudgeMover(1) + end) + rightButton.icon = rightButton:CreateTexture(nil, "ARTWORK") + rightButton.icon:SetWidth(13) + rightButton.icon:SetHeight(13) + rightButton.icon:SetPoint("CENTER", 0, 0) + rightButton.icon:SetTexture([[Interface\AddOns\ElvUI\Media\Textures\SquareButtonTextures.blp]]) + rightButton.icon:SetTexCoord(0.01562500, 0.20312500, 0.01562500, 0.20312500) + + S:SquareButton_SetIcon(rightButton, "RIGHT") + S:HandleButton(rightButton) +end \ No newline at end of file diff --git a/ElvUI/Core/Cooldowns.lua b/ElvUI/Core/Cooldowns.lua new file mode 100644 index 0000000..5a59366 --- /dev/null +++ b/ElvUI/Core/Cooldowns.lua @@ -0,0 +1,140 @@ +local E, L, V, P, G = unpack(ElvUI); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB + +--Cache global variables +--Lua functions +local floor = math.floor +local format = string.format +local GetTime = GetTime +--WoW API / Variables +local CreateFrame = CreateFrame +local hooksecurefunc = hooksecurefunc + +local ICON_SIZE = 36 --the normal size for an icon (don't change this) +local FONT_SIZE = 20 --the base font size to use at a scale of 1 +local MIN_SCALE = 0.5 --the minimum scale we want to show cooldown counts at, anything below this will be hidden +local MIN_DURATION = 1.5 --the minimum duration to show cooldown text for + +local TimeColors = { + [0] = "|cfffefefe", + [1] = "|cfffefefe", + [2] = "|cfffefefe", + [3] = "|cfffefefe", + [4] = "|cfffe0000" +} + +local function Cooldown_OnUpdate(cd, elapsed) + if cd.nextUpdate > 0 then + cd.nextUpdate = cd.nextUpdate - elapsed + return + end + + local remain = cd.duration - (GetTime() - cd.start) + if remain > 0.05 then + if (cd.fontScale * cd:GetEffectiveScale() / UIParent:GetScale()) < MIN_SCALE then + cd.text:SetText("") + cd.nextUpdate = 500 + else + local timervalue, formatid + timervalue, formatid, cd.nextUpdate = E:GetTimeInfo(remain, E.db.cooldown.threshold) + cd.text:SetText(format("%s%s|r", TimeColors[formatid], format(E.TimeFormats[formatid][2], timervalue))) + end + else + E:Cooldown_StopTimer(cd) + end +end + +function E:Cooldown_OnSizeChanged(cd, width) + local fontScale = floor(width +.5) / ICON_SIZE + local override = cd:GetParent():GetParent().SizeOverride + if override then + fontScale = override / FONT_SIZE + end + + if fontScale == cd.fontScale then + return + end + + cd.fontScale = fontScale + if fontScale < MIN_SCALE and not override then + cd:Hide() + else + cd:Show() + E:FontTemplate(cd.text, nil, fontScale * FONT_SIZE, "OUTLINE") + if cd.enabled then + self:Cooldown_ForceUpdate(cd) + end + end +end + +function E:Cooldown_ForceUpdate(cd) + cd.nextUpdate = 0 + cd:Show() +end + +function E:Cooldown_StopTimer(cd) + cd.enabled = nil + cd:Hide() +end + +function E:CreateCooldownTimer(parent) + local scaler = CreateFrame("Frame", nil, parent) + scaler:SetAllPoints() + + local timer = CreateFrame("Frame", nil, scaler) + timer:Hide() + timer:SetAllPoints() + timer:SetScript("OnUpdate", function() Cooldown_OnUpdate(this, arg1) end) + + local text = timer:CreateFontString(nil, "OVERLAY") + text:SetPoint("CENTER", 1, 1) + text:SetJustifyH("CENTER") + timer.text = text + + self:Cooldown_OnSizeChanged(timer, parent:GetWidth(), parent:GetHeight()) + parent:SetScript("OnSizeChanged", function() self:Cooldown_OnSizeChanged(timer, parent:GetWidth(), parent:GetHeight()) end) + + parent.timer = timer + return timer +end + +function E:OnSetCooldown(start, duration, enable) + if self.noOCC then return end + + if start > 0 and duration > MIN_DURATION and enable > 0 then + local timer = self.timer or E:CreateCooldownTimer(self) + timer.start = start + timer.duration = duration + timer.enabled = true + timer.nextUpdate = 0 + if timer.fontScale >= MIN_SCALE then timer:Show() end + else + local timer = self.timer + if timer then + E:Cooldown_StopTimer(timer) + return + end + end +end + +function E:RegisterCooldown(cooldown) + if not E.private.cooldown.enable or cooldown.isHooked then return end + hooksecurefunc("CooldownFrame_SetTimer", E.OnSetCooldown) + cooldown.isHooked = true +end + +function E:UpdateCooldownSettings() + local color = self.db.cooldown.expiringColor + TimeColors[4] = E:RGBToHex(color.r, color.g, color.b) -- color for timers that are soon to expire + + color = self.db.cooldown.secondsColor + TimeColors[3] = E:RGBToHex(color.r, color.g, color.b) -- color for timers that have seconds remaining + + color = self.db.cooldown.minutesColor + TimeColors[2] = E:RGBToHex(color.r, color.g, color.b) -- color for timers that have minutes remaining + + color = self.db.cooldown.hoursColor + TimeColors[1] = E:RGBToHex(color.r, color.g, color.b) -- color for timers that have hours remaining + + color = self.db.cooldown.daysColor + TimeColors[0] = E:RGBToHex(color.r, color.g, color.b) -- color for timers that have days remaining +end \ No newline at end of file diff --git a/ElvUI/Core/Load_Core.xml b/ElvUI/Core/Load_Core.xml new file mode 100644 index 0000000..2a74520 --- /dev/null +++ b/ElvUI/Core/Load_Core.xml @@ -0,0 +1,18 @@ + +