diff --git a/ElvUI/Core/Config.lua b/ElvUI/Core/Config.lua index 10bcde1..f80c8b9 100644 --- a/ElvUI/Core/Config.lua +++ b/ElvUI/Core/Config.lua @@ -68,7 +68,7 @@ function E:ToggleConfigMode(override, configType) end ElvUIMoverPopupWindow:Show() - if(IsAddOnLoaded("ElvUI_Config")) then + if IsAddOnLoaded("ElvUI_Config") then LibStub("AceConfigDialog-3.0"):Close("ElvUI") GameTooltip:Hide() end @@ -162,18 +162,18 @@ end function E:NudgeMover(nudgeX, nudgeY) local mover = ElvUIMoverNudgeWindow.child - local x, y, point = E:CalculateMoverPoints(mover, nudgeX, nudgeY) mover:ClearAllPoints() E:Point(mover, mover.positionOverride or point, E.UIParent, mover.positionOverride and "BOTTOMLEFT" or point, x, y) E:SaveMoverPosition(mover.name) + --Update coordinates in Nudge Window E:UpdateNudgeFrame(mover, x, y) end function E:UpdateNudgeFrame(mover, x, y) - if not(x and y) then + if not (x and y) then x, y = E:CalculateMoverPoints(mover) end @@ -200,7 +200,8 @@ function E:CreateMoverPopup() f:SetMovable(true) f:SetFrameLevel(99) f:SetClampedToScreen(true) - E:Size(f, 360, 170) + E:Width(f, 360) + E:Height(f, 185) E:SetTemplate(f, "Transparent") E:Point(f, "BOTTOM", UIParent, "CENTER", 0, 100) f:SetScript("OnHide", function() @@ -214,8 +215,9 @@ function E:CreateMoverPopup() local header = CreateFrame("Button", nil, f) E:SetTemplate(header, "Default", true) - E:Size(header, 100, 25) - header:SetPoint("CENTER", f, "TOP") + E:Width(header, 100) + E:Height(header, 25) + E:Point(header, "CENTER", f, "TOP") header:SetFrameLevel(header:GetFrameLevel() + 2) header:EnableMouse(true) header:RegisterForClicks("AnyUp", "AnyDown") @@ -224,7 +226,7 @@ function E:CreateMoverPopup() local title = header:CreateFontString("OVERLAY") E:FontTemplate(title) - title:SetPoint("CENTER", header, "CENTER") + E:Point(title, "CENTER", header, "CENTER") title:SetText("ElvUI") local desc = f:CreateFontString("ARTWORK") @@ -252,7 +254,7 @@ function E:CreateMoverPopup() lock:SetScript("OnClick", function() E:ToggleConfigMode(true) - if(IsAddOnLoaded("ElvUI_Config")) then + if IsAddOnLoaded("ElvUI_Config") then LibStub("AceConfigDialog-3.0"):Open("ElvUI") end @@ -261,7 +263,8 @@ function E:CreateMoverPopup() end) local align = CreateFrame("EditBox", f:GetName().."EditBox", f, "InputBoxTemplate") - E:Size(align, 32, 17) + E:Width(align, 24) + E:Height(align, 17) align:SetAutoFocus(false) align:SetScript("OnEscapePressed", function() this:SetText(E.db.gridSize) @@ -284,6 +287,7 @@ function E:CreateMoverPopup() align:SetScript("OnEditFocusLost", function() this:SetText(E.db.gridSize) end) + align:SetScript("OnEditFocusGained", align.HighlightText) align:SetScript("OnShow", function() this:ClearFocus() this:SetText(E.db.gridSize) @@ -322,7 +326,8 @@ function E:CreateMoverPopup() local nudgeFrame = CreateFrame("Frame", "ElvUIMoverNudgeWindow", E.UIParent) nudgeFrame:SetFrameStrata("DIALOG") - E:Size(nudgeFrame, 200, 110) + E:Width(nudgeFrame, 200) + E:Height(nudgeFrame, 110) E:SetTemplate(nudgeFrame, "Transparent") E:Point(nudgeFrame, "TOP", ElvUIMoverPopupWindow, "BOTTOM", 0, -15) nudgeFrame:SetFrameLevel(100) @@ -333,18 +338,20 @@ function E:CreateMoverPopup() header = CreateFrame("Button", "ElvUIMoverNudgeWindowHeader", nudgeFrame) E:SetTemplate(header, "Default", true) - E:Size(header, 100, 25) - header:SetPoint("CENTER", nudgeFrame, "TOP") + E:Width(header, 100) + E:Height(header, 25) + E:Point(header, "CENTER", nudgeFrame, "TOP") header:SetFrameLevel(header:GetFrameLevel() + 2) title = header:CreateFontString("OVERLAY") E:FontTemplate(title) - title:SetPoint("CENTER", header, "CENTER") + E:Point(title, "CENTER", header, "CENTER") title:SetText(L["Nudge"]) header.title = title local xOffset = CreateFrame("EditBox", nudgeFrame:GetName().."XEditBox", nudgeFrame, "InputBoxTemplate") - E:Size(xOffset, 50, 17) + E:Width(xOffset, 50) + E:Height(xOffset, 17) xOffset:SetAutoFocus(false) xOffset.currentValue = 0 xOffset:SetScript("OnEscapePressed", function() @@ -353,7 +360,7 @@ function E:CreateMoverPopup() end) xOffset:SetScript("OnEnterPressed", function() local num = this:GetText() - if(tonumber(num)) then + if tonumber(num) then local diff = num - xOffset.currentValue xOffset.currentValue = num E:NudgeMover(diff) @@ -364,6 +371,7 @@ function E:CreateMoverPopup() xOffset:SetScript("OnEditFocusLost", function() this:SetText(E:Round(xOffset.currentValue)) end) + xOffset:SetScript("OnEditFocusGained", xOffset.HighlightText) xOffset:SetScript("OnShow", function() this:ClearFocus() this:SetText(E:Round(xOffset.currentValue)) @@ -377,7 +385,8 @@ function E:CreateMoverPopup() S:HandleEditBox(xOffset) local yOffset = CreateFrame("EditBox", nudgeFrame:GetName().."YEditBox", nudgeFrame, "InputBoxTemplate") - E:Size(yOffset, 50, 17) + E:Width(yOffset, 50) + E:Height(yOffset, 17) yOffset:SetAutoFocus(false) yOffset.currentValue = 0 yOffset:SetScript("OnEscapePressed", function() @@ -386,7 +395,7 @@ function E:CreateMoverPopup() end) yOffset:SetScript("OnEnterPressed", function() local num = this:GetText() - if(tonumber(num)) then + if tonumber(num) then local diff = num - yOffset.currentValue yOffset.currentValue = num E:NudgeMover(nil, diff) @@ -397,6 +406,7 @@ function E:CreateMoverPopup() yOffset:SetScript("OnEditFocusLost", function() this:SetText(E:Round(yOffset.currentValue)) end) + yOffset:SetScript("OnEditFocusGained", yOffset.HighlightText) yOffset:SetScript("OnShow", function() this:ClearFocus() this:SetText(E:Round(yOffset.currentValue)) @@ -429,7 +439,7 @@ function E:CreateMoverPopup() end) upButton.icon = upButton:CreateTexture(nil, "ARTWORK") E:Size(upButton.icon, 13) - upButton.icon:SetPoint("CENTER", 0, 0) + E:Point(upButton.icon, "CENTER", 0) upButton.icon:SetTexture([[Interface\AddOns\ElvUI\Media\Textures\SquareButtonTextures.blp]]) upButton.icon:SetTexCoord(0.01562500, 0.20312500, 0.01562500, 0.20312500) @@ -444,7 +454,7 @@ function E:CreateMoverPopup() end) downButton.icon = downButton:CreateTexture(nil, "ARTWORK") E:Size(downButton.icon, 13) - downButton.icon:SetPoint("CENTER", 0, 0) + E:Point(downButton.icon, "CENTER", 0) downButton.icon:SetTexture([[Interface\AddOns\ElvUI\Media\Textures\SquareButtonTextures.blp]]) downButton.icon:SetTexCoord(0.01562500, 0.20312500, 0.01562500, 0.20312500) @@ -459,7 +469,7 @@ function E:CreateMoverPopup() end) leftButton.icon = leftButton:CreateTexture(nil, "ARTWORK") E:Size(leftButton.icon, 13) - leftButton.icon:SetPoint("CENTER", 0, 0) + E:Point(leftButton.icon, "CENTER", 0) leftButton.icon:SetTexture([[Interface\AddOns\ElvUI\Media\Textures\SquareButtonTextures.blp]]) leftButton.icon:SetTexCoord(0.01562500, 0.20312500, 0.01562500, 0.20312500) @@ -474,10 +484,10 @@ function E:CreateMoverPopup() end) rightButton.icon = rightButton:CreateTexture(nil, "ARTWORK") E:Size(rightButton.icon, 13) - rightButton.icon:SetPoint("CENTER", 0, 0) + E:Point(rightButton.icon, "CENTER", 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 +end diff --git a/ElvUI/Core/Math.lua b/ElvUI/Core/Math.lua index 0300e5e..74d9f88 100644 --- a/ElvUI/Core/Math.lua +++ b/ElvUI/Core/Math.lua @@ -11,56 +11,63 @@ local GetScreenWidth, GetScreenHeight = GetScreenWidth, GetScreenHeight local CreateFrame = CreateFrame --Return short value of a number -local shortValueDec +local shortValueDec, value function E:ShortValue(v) shortValueDec = format("%%.%df", E.db.general.decimalLength or 1) + value = abs(v) if E.db.general.numberPrefixStyle == "METRIC" then - if abs(v) >= 1e9 then + if value >= 1e12 then + return format(shortValueDec.."T", v / 1e12) + elseif value >= 1e9 then return format(shortValueDec.."G", v / 1e9) - elseif abs(v) >= 1e6 then + elseif value >= 1e6 then return format(shortValueDec.."M", v / 1e6) - elseif abs(v) >= 1e3 then + elseif value >= 1e3 then return format(shortValueDec.."k", v / 1e3) else - return format("%s", v) + return format("%.0f", v) end elseif E.db.general.numberPrefixStyle == "CHINESE" then - if abs(v) >= 1e8 then + if value >= 1e8 then return format(shortValueDec.."Y", v / 1e8) - elseif abs(v) >= 1e4 then + elseif value >= 1e4 then return format(shortValueDec.."W", v / 1e4) else - return format("%s", v) + return format("%.0f", v) end elseif E.db.general.numberPrefixStyle == "KOREAN" then - if abs(v) >= 1e8 then + if value >= 1e8 then return format(shortValueDec.."억", v / 1e8) - elseif abs(v) >= 1e4 then + elseif value >= 1e4 then return format(shortValueDec.."만", v / 1e4) - elseif abs(v) >= 1e3 then + elseif value >= 1e3 then return format(shortValueDec.."천", v / 1e3) else - return format("%s", v) + return format("%.0f", v) end elseif E.db.general.numberPrefixStyle == "GERMAN" then - if abs(v) >= 1e9 then + if value >= 1e12 then + return format(shortValueDec.."Bio", v / 1e12) + elseif value >= 1e9 then return format(shortValueDec.."Mrd", v / 1e9) - elseif abs(v) >= 1e6 then + elseif value >= 1e6 then return format(shortValueDec.."Mio", v / 1e6) - elseif abs(v) >= 1e3 then + elseif value >= 1e3 then return format(shortValueDec.."Tsd", v / 1e3) else - return format("%s", v) + return format("%.0f", v) end else - if abs(v) >= 1e9 then + if value >= 1e12 then + return format(shortValueDec.."T", v / 1e12) + elseif value >= 1e9 then return format(shortValueDec.."B", v / 1e9) - elseif abs(v) >= 1e6 then + elseif value >= 1e6 then return format(shortValueDec.."M", v / 1e6) - elseif abs(v) >= 1e3 then + elseif value >= 1e3 then return format(shortValueDec.."K", v / 1e3) else - return format("%s", v) + return format("%.0f", v) end end end @@ -97,9 +104,9 @@ function E:Truncate(v, decimals) end function E:RGBToHex(r, g, b) - r = r <= 1 and r >= 0 and r or 0 - g = g <= 1 and g >= 0 and g or 0 - b = b <= 1 and b >= 0 and b or 0 + r = r <= 1 and r >= 0 and r or 1 + g = g <= 1 and g >= 0 and g or 1 + b = b <= 1 and b >= 0 and b or 1 return format("|cff%02x%02x%02x", r*255, g*255, b*255) end @@ -162,6 +169,7 @@ function E:GetScreenQuadrant(frame) else point = "CENTER" end + return point end @@ -177,7 +185,7 @@ function E:GetXYOffset(position, override) return -x, y elseif position == "BOTTOM" then return 0, -y - elseif(position == "BOTTOMLEFT") then + elseif position == "BOTTOMLEFT" then return x, -y elseif position == "BOTTOMRIGHT" then return -x, -y @@ -201,6 +209,7 @@ local styles = { ["DEFICIT"] = "-%s" } +local gftDec, gftUseStyle, gftDeficit function E:GetFormattedText(style, min, max) assert(styles[style], "Invalid format style: "..style) assert(min, "You need to provide a current value. Usage: E:GetFormattedText(style, min, max)") @@ -208,16 +217,15 @@ function E:GetFormattedText(style, min, max) if max == 0 then max = 1 end - local gftUseStyle - local gftDec = E.db.general.decimalLength or 1 - if gftDec ~= 1 and find(style, "PERCENT") then + gftDec = (E.db.general.decimalLength or 1) + if (gftDec ~= 1) and find(style, "PERCENT") then gftUseStyle = gsub(styles[style], "%%%.1f%%%%", "%%."..gftDec.."f%%%%") else gftUseStyle = styles[style] end if style == "DEFICIT" then - local gftDeficit = max - min + gftDeficit = max - min return ((gftDeficit > 0) and format(gftUseStyle, E:ShortValue(gftDeficit))) or "" elseif style == "PERCENT" then return format(gftUseStyle, min / max * 100) @@ -237,7 +245,7 @@ function E:AbbreviateString(string, allUpper) local words = {split(" ", string)} for _, word in pairs(words) do word = utf8sub(word, 1, 1) - if(allUpper) then + if allUpper then word = upper(word) end newString = newString..word @@ -309,12 +317,16 @@ function E:StringTitle(str) return gsub(str, "(.)", upper, 1) end +E.TimeThreshold = 3 + E.TimeColors = { [0] = "|cffeeeeee", [1] = "|cffeeeeee", [2] = "|cffeeeeee", [3] = "|cffeeeeee", - [4] = "|cfffe0000" + [4] = "|cfffe0000", + [5] = "|cff909090", --mmss + [6] = "|cff707070", --hhmm } E.TimeFormats = { @@ -322,14 +334,16 @@ E.TimeFormats = { [1] = {"%dh", "%dh"}, [2] = {"%dm", "%dm"}, [3] = {"%ds", "%d"}, - [4] = {"%.1fs", "%.1f"} + [4] = {"%.1fs", "%.1f"}, + [5] = {"%d:%02d", "%d:%02d"}, --mmss + [6] = {"%d:%02d", "%d:%02d"}, --hhmm } local DAY, HOUR, MINUTE = 86400, 3600, 60 local DAYISH, HOURISH, MINUTEISH = HOUR * 23.5, MINUTE * 59.5, 59.5 local HALFDAYISH, HALFHOURISH, HALFMINUTEISH = DAY/2 + 0.5, HOUR/2 + 0.5, MINUTE/2 + 0.5 -function E:GetTimeInfo(s, threshhold) +function E:GetTimeInfo(s, threshhold, hhmm, mmss) if s < MINUTE then if s >= threshhold then return floor(s), 3, 0.51 @@ -337,11 +351,26 @@ function E:GetTimeInfo(s, threshhold) return s, 4, 0.051 end elseif s < HOUR then - local minutes = floor((s/MINUTE)+.5) - return ceil(s / MINUTE), 2, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH) + if mmss and s < mmss then + return s/MINUTE, 5, 0.51, mod(s, MINUTE) + else + local minutes = floor((s/MINUTE)+.5) + if hhmm and s < (hhmm * MINUTE) then + return s/HOUR, 6, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH), mod(minutes, MINUTE) + else + return ceil(s / MINUTE), 2, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH) + end + end elseif s < DAY then - local hours = floor((s/HOUR)+.5) - return ceil(s / HOUR), 1, hours > 1 and (s - (hours*HOUR - HALFHOURISH)) or (s - HOURISH) + if mmss and s < mmss then + return s/MINUTE, 5, 0.51, mod(s, MINUTE) + elseif hhmm and s < (hhmm * MINUTE) then + local minutes = floor((s/MINUTE)+.5) + return s/HOUR, 6, minutes > 1 and (s - (minutes*MINUTE - HALFMINUTEISH)) or (s - MINUTEISH), mod(minutes, MINUTE) + else + local hours = floor((s/HOUR)+.5) + return ceil(s / HOUR), 1, hours > 1 and (s - (hours*HOUR - HALFHOURISH)) or (s - HOURISH) + end else local days = floor((s/DAY)+.5) return ceil(s / DAY), 0, days > 1 and (s - (days*DAY - HALFDAYISH)) or (s - DAYISH) @@ -419,4 +448,4 @@ function E:FormatMoney(amount, style) end return self:FormatMoney(amount, "SMART") -end \ No newline at end of file +end