From 512048ac117ca227db7ede8842bab1742220af51 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Fri, 28 Feb 2025 02:10:20 +0000 Subject: [PATCH 1/2] Plugins/Bars: Add option for sorting bars: `Ascending` or `Descending`. --- Plugins/Bars.lua | 64 +++++++++++++++++++++++++++++++--------- Plugins/Locales/deDE.lua | 3 ++ Plugins/Locales/enUS.lua | 3 ++ Plugins/Locales/esES.lua | 3 ++ Plugins/Locales/esMX.lua | 3 ++ Plugins/Locales/frFR.lua | 3 ++ Plugins/Locales/itIT.lua | 3 ++ Plugins/Locales/koKR.lua | 3 ++ Plugins/Locales/ptBR.lua | 3 ++ Plugins/Locales/ruRU.lua | 3 ++ Plugins/Locales/zhCN.lua | 3 ++ Plugins/Locales/zhTW.lua | 3 ++ 12 files changed, 83 insertions(+), 14 deletions(-) diff --git a/Plugins/Bars.lua b/Plugins/Bars.lua index ba160db61..7c28fd4d8 100644 --- a/Plugins/Bars.lua +++ b/Plugins/Bars.lua @@ -47,6 +47,7 @@ plugin.defaultDB = { growup = false, text = true, time = true, + sorting = "ASCENDING", alignText = "LEFT", alignTime = "RIGHT", icon = true, @@ -435,21 +436,30 @@ do updateProfile() end, }, + sorting = { + type = "select", + name = "Sorting", + order = 9, + values = { + ASCENDING = L.ascending, + DESCENDING = L.descending, + }, + }, header2 = { type = "header", name = "", - order = 9, + order = 10, }, text = { type = "toggle", name = L.text, desc = L.textDesc, - order = 10, + order = 11, }, alignText = { type = "select", name = L.alignText, - order = 11, + order = 12, values = { LEFT = L.left, CENTER = L.center, @@ -459,18 +469,18 @@ do textSpacer = { type = "description", name = " ", - order = 12, + order = 13, }, time = { type = "toggle", name = L.time, desc = L.timeDesc, - order = 13, + order = 14, }, alignTime = { type = "select", name = L.alignTime, - order = 14, + order = 15, values = { LEFT = L.left, CENTER = L.center, @@ -480,19 +490,19 @@ do timeSpacer = { type = "description", name = " ", - order = 15, + order = 16, }, icon = { type = "toggle", name = L.icon, desc = L.iconDesc, - order = 16, + order = 17, }, iconPosition = { type = "select", name = L.iconPosition, desc = L.iconPositionDesc, - order = 17, + order = 18, values = { LEFT = L.left, RIGHT = L.right, @@ -502,14 +512,14 @@ do header3 = { type = "header", name = "", - order = 18, + order = 19, }, reset = { type = "execute", name = L.resetAll, desc = L.resetBarsDesc, func = function() plugin.db:ResetProfile() updateProfile() end, - order = 19, + order = 20, }, }, }, @@ -863,9 +873,13 @@ end -- do - local function barSorter(a, b) - return a.remaining < b.remaining and true or false - end + local function ascendSorter(a, b) + return a.remaining < b.remaining and true or false + end + + local function descendSorter(a, b) + return a.remaining > b.remaining and true or false + end rearrangeBars = function(anchor) if not anchor or not next(anchor.bars) then return end @@ -873,6 +887,9 @@ do for bar in next, anchor.bars do tmp[#tmp + 1] = bar end + + local ascending = db.sorting == "ASCENDING" + local barSorter = ascending and ascendSorter or descendSorter table.sort(tmp, barSorter) local lastBar = nil local up, barLimit @@ -883,6 +900,25 @@ do up = db.emphasizeGrowup barLimit = db.visibleBarLimitEmph end + + -- This is a workaround when descending to not get the bars to + -- keep getting shoved upwards by the hidden new bars. Ideally it + -- would be a good idea to separate `timers` and `bars`, and only + -- create bars when something should be visible. Then lots of logic + -- for sorting bars and this rule when descending could be avoided. + if #tmp > barLimit and not ascending then + local shift = (#tmp - barLimit) % #tmp + local rotated = {} + for i = 1, #tmp do + local fromIndex = ((i - 1) + shift) % #tmp + 1 + rotated[i] = tmp[fromIndex] + end + + for i = 1, #tmp do + tmp[i] = rotated[i] + end + end + for i = 1, #tmp do local bar = tmp[i] if i > barLimit then diff --git a/Plugins/Locales/deDE.lua b/Plugins/Locales/deDE.lua index 768e13211..17660992f 100644 --- a/Plugins/Locales/deDE.lua +++ b/Plugins/Locales/deDE.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "Hervorheben bei... (Sekunden)" L.growingUpwards = "Nach oben erweitern" L.growingUpwardsDesc = "Legt fest, ob die Leisten aufwärts oder abwärts vom Ankerpunkt angezeigt werden." L.texture = "Textur" +L.sorting = "Sortierung" +L.ascending = "Aufsteigend" +L.descending = "Absteigend" L.emphasize = "Hervorheben" L.emphasizeMultiplier = "Größenmultiplikator" L.emphasizeMultiplierDesc = "Wenn das Bewegen der Leisten zu den hervorgehobenen Leisten deaktiviert ist, entscheidet diese Option welche Größe die hervorgehobenen Leisten multipliziert mit den normalen Leisten haben." diff --git a/Plugins/Locales/enUS.lua b/Plugins/Locales/enUS.lua index 9ef4c35b3..2c8b259d5 100644 --- a/Plugins/Locales/enUS.lua +++ b/Plugins/Locales/enUS.lua @@ -95,6 +95,9 @@ L.emphasizeAt = "Emphasize at... (seconds)" L.growingUpwards = "Grow upwards" L.growingUpwardsDesc = "Toggle growing upwards or downwards from the anchor." L.texture = "Texture" +L.sorting = "Sorting" +L.ascending = "Ascending" +L.descending = "Descending" L.emphasize = "Emphasize" L.emphasizeMultiplier = "Size Multiplier" L.emphasizeMultiplierDesc = "If you disable the bars moving to the emphasize anchor, this option will decide what size the emphasized bars will be by multiplying the size of the normal bars." diff --git a/Plugins/Locales/esES.lua b/Plugins/Locales/esES.lua index a4c32dfd2..bea9c3e4a 100644 --- a/Plugins/Locales/esES.lua +++ b/Plugins/Locales/esES.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "Enfatizar en... (segundos)" L.growingUpwards = "Crecer ascendente" L.growingUpwardsDesc = "Cambia el crecimiento hacia arriba o hacia abajo desde el punto de anclaje." L.texture = "Textura" +L.sorting = "Clasificación" +L.ascending = "Ascendente" +L.descending = "Descendente" L.emphasize = "Enfatizar" L.emphasizeMultiplier = "Multiplicador de tamaño" L.emphasizeMultiplierDesc = "Si desactivas que las barras se muevan al ancla de Enfatizar, esta opción decidirá qué tamaño tendrán las barras enfatizadas multiplicando el tamaño de las barras normales." diff --git a/Plugins/Locales/esMX.lua b/Plugins/Locales/esMX.lua index 6abfc53bd..f30ab5989 100644 --- a/Plugins/Locales/esMX.lua +++ b/Plugins/Locales/esMX.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "Enfatiza en... (segundos)" L.growingUpwards = "Crecer hacia arriba" L.growingUpwardsDesc = "Alterna el crecimiento hacia arriba o abajo desde el punto de anclaje." L.texture = "Textura" +L.sorting = "Clasificación" +L.ascending = "Ascendente" +L.descending = "Descendente" L.emphasize = "Enfatizar" L.emphasizeMultiplier = "Multiplicador de tamaño" L.emphasizeMultiplierDesc = "Si desactiva las barras moviéndose el anclaje enfatizado, esta opción decidirá el tamaño de las barras enfatizadas multiplicando el tamaño de las barras normales." diff --git a/Plugins/Locales/frFR.lua b/Plugins/Locales/frFR.lua index 3813e82af..5cebdd434 100644 --- a/Plugins/Locales/frFR.lua +++ b/Plugins/Locales/frFR.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "Mettre en évidence à... (secondes)" L.growingUpwards = "Ajouter vers le haut" L.growingUpwardsDesc = "Permute le sens d'ajout des éléments par rapport à l'ancre entre vers le haut et vers le bas." L.texture = "Texture" +L.sorting = "Tri" +L.ascending = "Croissant" +L.descending = "Décroissant" L.emphasize = "Mise en évidence" L.emphasizeMultiplier = "Multiplicateur de taille" L.emphasizeMultiplierDesc = "Si vous désactivez le déplacement des barres vers l'ancre de mise en évidence, cette option décidera la taille des barres mises en évidence en multipliant la taille des barres normales." diff --git a/Plugins/Locales/itIT.lua b/Plugins/Locales/itIT.lua index 8162fe2cd..141224908 100644 --- a/Plugins/Locales/itIT.lua +++ b/Plugins/Locales/itIT.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "Enfatizza a... (secondi)" L.growingUpwards = "Cresci verso l'altro" L.growingUpwardsDesc = "Attiva o disattiva il riempimento crescente o decrescente rispetto al punto di ancoraggio." L.texture = "Texture" +L.sorting = "Ordinamento" +L.ascending = "Ascendente" +L.descending = "Discendente" L.emphasize = "Enfatizza" L.emphasizeMultiplier = "Moltiplicatore di dimensioni" L.emphasizeMultiplierDesc = "Se disabiliti le barre muovendole dall'ancora di enfatizzazione, questa opzione deciderà la dimensione delle barre enfatizzate moltiplicando la dimensione delle barre normali." diff --git a/Plugins/Locales/koKR.lua b/Plugins/Locales/koKR.lua index eb1e14ff6..5ff01f5ee 100644 --- a/Plugins/Locales/koKR.lua +++ b/Plugins/Locales/koKR.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "다음에 강조... (초)" L.growingUpwards = "위로 확장" L.growingUpwardsDesc = "고정기로부터 위 또는 아래로 확장하도록 전환합니다." L.texture = "텍스쳐" +L.sorting = "정렬" +L.ascending = "오름차순" +L.descending = "내림차순" L.emphasize = "강조" L.emphasizeMultiplier = "배율" L.emphasizeMultiplierDesc = "강조 고정기로 이동하는 바가 활성화되지 않았을때, 이 옵션은 해당 바를 강조 바로 이동하지 않고 바의 크기를 주어진 배율만큼 확대시킵니다." diff --git a/Plugins/Locales/ptBR.lua b/Plugins/Locales/ptBR.lua index cfcc5294c..bd9031b89 100644 --- a/Plugins/Locales/ptBR.lua +++ b/Plugins/Locales/ptBR.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "Enfatizar em... (segundos)" L.growingUpwards = "Crescimento para cima" L.growingUpwardsDesc = "Alterna crescimento para cima ou para baixo a partir da âncora." L.texture = "Textura" +L.sorting = "Classificação" +L.ascending = "Crescente" +L.descending = "Decrescente" L.emphasize = "Enfatizar" L.emphasizeMultiplier = "Multiplicador de Tamanho" L.emphasizeMultiplierDesc = "Se você desabilitar as barras movendo-as para a âncora em destaque, esta opção irá decidir qual tamanho as barras em destaque terão, ao se multiplicar o tamanho das barras normais." diff --git a/Plugins/Locales/ruRU.lua b/Plugins/Locales/ruRU.lua index ce060a37b..9aef083bf 100644 --- a/Plugins/Locales/ruRU.lua +++ b/Plugins/Locales/ruRU.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "Увеличение на... (секунды)" L.growingUpwards = "Рост вверх" L.growingUpwardsDesc = "Переключение направления роста вверх или вниз от якоря." L.texture = "Текстура" +L.sorting = "Сортировка" +L.ascending = "По возрастанию" +L.descending = "По убыванию" L.emphasize = "Увеличение" L.emphasizeMultiplier = "Множитель Размера" L.emphasizeMultiplierDesc = "Если Вы отмените перемещение увеличенных полос к своему якорю, эта опция будет просто определять, насколько будут увеличиваться полосы по отношению к нормальным." diff --git a/Plugins/Locales/zhCN.lua b/Plugins/Locales/zhCN.lua index 2ff0db9f6..c37dd6280 100644 --- a/Plugins/Locales/zhCN.lua +++ b/Plugins/Locales/zhCN.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "…(秒)后醒目" L.growingUpwards = "向上成长" L.growingUpwardsDesc = "切换在锚点向上或向下成长。" L.texture = "材质" +L.sorting = "排序" +L.ascending = "升序" +L.descending = "降序" L.emphasize = "醒目" L.emphasizeMultiplier = "尺寸倍数" L.emphasizeMultiplierDesc = "如禁用计时条移向醒目锚点,此选项将决定以一般计时条乘以尺寸倍数作为醒目计时条的尺寸。" diff --git a/Plugins/Locales/zhTW.lua b/Plugins/Locales/zhTW.lua index 01c5b4a45..a17ed7cdb 100644 --- a/Plugins/Locales/zhTW.lua +++ b/Plugins/Locales/zhTW.lua @@ -96,6 +96,9 @@ L.emphasizeAt = "…(秒)後強調" L.growingUpwards = "向上成長" L.growingUpwardsDesc = "切換在錨點向上或向下成長。" L.texture = "材質" +L.sorting = "排序" +L.ascending = "升序" +L.descending = "降序" L.emphasize = "強調" L.emphasizeMultiplier = "尺寸倍數" L.emphasizeMultiplierDesc = "如果你禁止計時條移動到強調計時條錨點,此選項可以調整一般計時條進入強調倒數後的放大倍率。" From e8b4dbe40bcd02f39647f35f0368e8dd76cb2409 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Fri, 28 Feb 2025 02:16:47 +0000 Subject: [PATCH 2/2] Plugins/Bars: Add missing localisation for name of `sorting` option. --- Plugins/Bars.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Bars.lua b/Plugins/Bars.lua index 7c28fd4d8..b414402c5 100644 --- a/Plugins/Bars.lua +++ b/Plugins/Bars.lua @@ -438,7 +438,7 @@ do }, sorting = { type = "select", - name = "Sorting", + name = L.sorting, order = 9, values = { ASCENDING = L.ascending,