From a8047cf0476825f2ece2005f8a33c5480b26fefd Mon Sep 17 00:00:00 2001 From: pepopo978 Date: Fri, 3 Jan 2025 13:17:31 -0800 Subject: [PATCH] add ability to choose curse ordering --- Localization.lua | 14 +++++++++++--- settings.lua | 14 ++++++++++++++ ui.lua | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/Localization.lua b/Localization.lua index 5b3a4fa..1835dfc 100644 --- a/Localization.lua +++ b/Localization.lua @@ -73,6 +73,10 @@ L:RegisterTranslations("enUS", function() ["Max Curses"] = true, ["Max Rows"] = true, ["Max Columns"] = true, + ["Curse Ordering"] = true, + ["Order applied"] = true, + ["Expiring soonest -> latest"] = true, + ["Expiring latest -> soonest"] = true, -- spells @@ -141,7 +145,7 @@ L:RegisterTranslations("enUS", function() ["Deadly Poison V"] = true, -- shaman - ["Flame Shock"] = true, + ["Flame Shock"] = true, -- warlock ["Conflagrate"] = true, @@ -234,6 +238,10 @@ L:RegisterTranslations("zhCN", function() ["Max Curses"] = "最大诅咒数", ["Max Rows"] = "最大行数", ["Max Columns"] = "最大列数", + ["Curse Ordering"] = "诅咒排序", + ["Order applied"] = "应用顺序", + ["Expiring soonest -> latest"] = "即将到期->最新", + ["Expiring latest -> soonest"] = "最新->即将到期", -- spells ["Rank 1"] = "等级 1", @@ -292,7 +300,7 @@ L:RegisterTranslations("zhCN", function() ["Blind"] = "致盲", ["Sap"] = "闷棍", ["Gouge"] = "凿击", - ["Expose Armor"] = "破甲", -- no idea if right + ["Expose Armor"] = "破甲", -- no idea if right ["Garrote"] = "锁喉", -- no idea if right ["Deadly Poison"] = "致命毒药", -- no idea if right ["Deadly Poison II"] = "致命毒药 II", @@ -301,7 +309,7 @@ L:RegisterTranslations("zhCN", function() ["Deadly Poison V"] = "致命毒药 V", -- shaman - ["Flame Shock"] = "烈焰震击", -- no idea if right + ["Flame Shock"] = "烈焰震击", -- no idea if right -- warlock ["Conflagrate"] = "引燃", -- no idea if right diff --git a/settings.lua b/settings.lua index 93c8c7c..567c67f 100644 --- a/settings.lua +++ b/settings.lua @@ -31,6 +31,8 @@ Cursive:RegisterDefaults("profile", { maxcol = 1, textsize = 9, + curseordering = L["Order applied"], + filterincombat = true, filterhostile = true, filterattackable = true, @@ -164,6 +166,18 @@ local barOptions = { end end, }, + ["curseordering"] = { + type = "text", + name = L["Curse Ordering"], + desc = L["Curse Ordering"], + get = function() + return Cursive.db.profile.curseordering + end, + validate = { L["Order applied"], L["Expiring soonest -> latest"], L["Expiring latest -> soonest"] }, + set = function(v) + Cursive.db.profile.curseordering = v + end, + }, ["spacing"] = { type = "range", name = L["Spacing"], diff --git a/ui.lua b/ui.lua index 2fff016..e255ca3 100644 --- a/ui.lua +++ b/ui.lua @@ -2,6 +2,8 @@ if not Cursive.superwow then return end +local L = AceLibrary("AceLocale-2.2"):new("Cursive") + local utils = Cursive.utils local filter = Cursive.filter @@ -401,6 +403,38 @@ local function GetBarCords(row, col) return x, y end +local function GetSortedCurses(guidCurses) + -- Collect keys + local curseNames = {} + for key in pairs(guidCurses) do + table.insert(curseNames, key) + end + + if Cursive.db.profile.curseordering == L["Order applied"] then + table.sort(curseNames, function(a, b) + return guidCurses[a].start < guidCurses[b].start + end) + elseif Cursive.db.profile.curseordering == L["Expiring soonest -> latest"] then + table.sort(curseNames, function(a, b) + return Cursive.curses:TimeRemaining(guidCurses[a]) < Cursive.curses:TimeRemaining(guidCurses[b]) + end) + elseif Cursive.db.profile.curseordering == L["Expiring latest -> soonest"] then + table.sort(curseNames, function(a, b) + return Cursive.curses:TimeRemaining(guidCurses[a]) > Cursive.curses:TimeRemaining(guidCurses[b]) + end) + end + + -- Iterator function + local i = 0 + return function() + i = i + 1 + local key = curseNames[i] + if key then + return key, guidCurses[key] + end + end +end + local function DisplayGuid(guid, row, col) local unitFrame = ui.unitFrames[guid] or CreateBar(guid) @@ -425,7 +459,7 @@ local function DisplayGuid(guid, row, col) local guidCurses = Cursive.curses.guids[guid] if guidCurses then - for curseName, curseData in pairs(guidCurses) do + for curseName, curseData in GetSortedCurses(guidCurses) do if curseNumber > Cursive.db.profile.maxcurses then break end