From fb5658ee2b7d7da83f5133b64f19482c21bc2c86 Mon Sep 17 00:00:00 2001 From: Jan Galek Date: Fri, 30 Oct 2020 12:16:06 +0100 Subject: [PATCH 1/2] [Added] Sort by tracked achievements Short-cut getTrackedAchievements --- HandyNotes_Achievements.lua | 69 +++++++++++++++++++++++++++++++++++-- Locale/deDE.lua | 2 ++ Locale/enUS.lua | 2 ++ Locale/esES.lua | 2 ++ Locale/esMX.lua | 2 ++ Locale/frFR.lua | 2 ++ Locale/itIT.lua | 2 ++ Locale/koKR.lua | 2 ++ Locale/ptBR.lua | 2 ++ Locale/ruRU.lua | 2 ++ Locale/zhCN.lua | 2 ++ Locale/zhTW.lua | 2 ++ 12 files changed, 89 insertions(+), 2 deletions(-) diff --git a/HandyNotes_Achievements.lua b/HandyNotes_Achievements.lua index decd9fa..81b5e0c 100644 --- a/HandyNotes_Achievements.lua +++ b/HandyNotes_Achievements.lua @@ -65,14 +65,70 @@ function HNA:HandyNotesCoordsNear(c, coord) end +function SortByTrackedAchievement(nodes, enabled) + if enabled == false then + return nodes + end + + function getTrackedAchievements() + id1, id2, id3, id4, id5, id6, id7, id8, id9, id10 = GetTrackedAchievements() + + local result = {} + + function add(id, result) + if id ~= nil then + result[tonumber(id)] = tonumber(id) + end + end + + add(id1, result) + add(id2, result) + add(id3, result) + add(id4, result) + add(id5, result) + add(id6, result) + add(id7, result) + add(id8, result) + add(id9, result) + add(id10, result) + + return result + end + local trackedAchievements = getTrackedAchievements() + local sortedNodes = {} + local notTrackedNodes = {} + + for nodeIndex = 1, #nodes, 2 do + local row = nodes[nodeIndex + 1] + local achievementID = row[2] + + if trackedAchievements[achievementID] then + table.insert(sortedNodes, nodes[nodeIndex]) + table.insert(sortedNodes, nodes[nodeIndex + 1]) + else + table.insert(notTrackedNodes, nodes[nodeIndex]) + table.insert(notTrackedNodes, nodes[nodeIndex + 1]) + end + end + + for nodeIndex = 1, #notTrackedNodes, 2 do + table.insert(sortedNodes, notTrackedNodes[nodeIndex]) + table.insert(sortedNodes, notTrackedNodes[nodeIndex + 1]) + end + + return sortedNodes +end + function HNA:OnEnter(mapFile, nearCoord) tooltip = QTip:Acquire(ADDON_NAME, 2, "LEFT", "RIGHT") local firstRow = true local previousAchievementID local nodes = activeNodes[mapFile] - for nodeIndex = 1, #nodes, 2 do - local coord, row = nodes[nodeIndex], nodes[nodeIndex + 1] + local sortedNodes = SortByTrackedAchievement(nodes, HNA.db.profile.sort_by_tracked) + + for nodeIndex = 1, #sortedNodes, 2 do + local coord, row = sortedNodes[nodeIndex], sortedNodes[nodeIndex + 1] if HNA:HandyNotesCoordsNear(coord, nearCoord) and HNA:Valid(row) then local achievementID = row[2] local criterion = row.criterion @@ -173,6 +229,7 @@ function HNA:OnInitialize() season_warning = 14, clean_continents = true, completed = false, + sort_by_tracked = false, } } @@ -257,6 +314,14 @@ function HNA:PLAYER_ENTERING_WORLD(event) arg = "season_warning", order = 6, }, + sort_by_tracked = { + type = "toggle", + name = L["Sort by tracked"], + desc = L["Sort achievements by tracked"], + width = "full", + arg = "sort_by_tracked", + order = 7 + } }, } HandyNotes:RegisterPluginDB(ADDON_NAME, self, options) diff --git a/Locale/deDE.lua b/Locale/deDE.lua index 87bc8cb..a4c2e2c 100644 --- a/Locale/deDE.lua +++ b/Locale/deDE.lua @@ -25,3 +25,5 @@ L["Just Mine"] = "Nur für diesen Charakter" L["Show more map pins by including achievements completed only by other characters."] = "Auch Kartemsymbole von bereits anderen Charakteren abgeschlossene Errungenschaften anzeigen." L["Season Warning"] = "Sesonale Errungenschafts Erinnerung" L["Days in advance to show pins for seasonal holiday achievements."] = "Wie viele Tage im Vorraus sollen mögliche Sesonale Errungenschaften angezeigt werden?" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/enUS.lua b/Locale/enUS.lua index 32a07ea..37af6d9 100644 --- a/Locale/enUS.lua +++ b/Locale/enUS.lua @@ -25,3 +25,5 @@ L["Just Mine"] = true L["Show more map pins by including achievements completed only by other characters."] = true L["Season Warning"] = true L["Days in advance to show pins for seasonal holiday achievements."] = true +L["Sort by tracked"] = true +L["Sort achievements by tracked"] = true diff --git a/Locale/esES.lua b/Locale/esES.lua index 9cef1ab..b9e2b39 100644 --- a/Locale/esES.lua +++ b/Locale/esES.lua @@ -25,3 +25,5 @@ L["Icon Alpha"] = "Opacidad de iconos" -- L["Show more map pins by including achievements completed only by other characters."] = "" -- L["Season Warning"] = "" -- L["Days in advance to show pins for seasonal holiday achievements."] = "" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/esMX.lua b/Locale/esMX.lua index 0cb0e3f..8d636af 100644 --- a/Locale/esMX.lua +++ b/Locale/esMX.lua @@ -25,3 +25,5 @@ L["Icon Alpha"] = "Opacidad de iconos" -- L["Show more map pins by including achievements completed only by other characters."] = "" -- L["Season Warning"] = "" -- L["Days in advance to show pins for seasonal holiday achievements."] = "" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/frFR.lua b/Locale/frFR.lua index 09cbdd5..fbe4a02 100644 --- a/Locale/frFR.lua +++ b/Locale/frFR.lua @@ -25,3 +25,5 @@ L["Icon Alpha"] = "Transparence des icônes" -- L["Show more map pins by including achievements completed only by other characters."] = "" -- L["Season Warning"] = "" -- L["Days in advance to show pins for seasonal holiday achievements."] = "" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/itIT.lua b/Locale/itIT.lua index ef35c75..7d7b0f2 100644 --- a/Locale/itIT.lua +++ b/Locale/itIT.lua @@ -25,3 +25,5 @@ if not L then return end -- L["Show more map pins by including achievements completed only by other characters."] = "" -- L["Season Warning"] = "" -- L["Days in advance to show pins for seasonal holiday achievements."] = "" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/koKR.lua b/Locale/koKR.lua index dc1a93a..d158f53 100644 --- a/Locale/koKR.lua +++ b/Locale/koKR.lua @@ -25,3 +25,5 @@ L["Icon Alpha"] = "아이콘 투명도" -- L["Show more map pins by including achievements completed only by other characters."] = "" -- L["Season Warning"] = "" -- L["Days in advance to show pins for seasonal holiday achievements."] = "" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/ptBR.lua b/Locale/ptBR.lua index a056dc5..1bf23d7 100644 --- a/Locale/ptBR.lua +++ b/Locale/ptBR.lua @@ -25,3 +25,5 @@ if not L then return end -- L["Show more map pins by including achievements completed only by other characters."] = "" -- L["Season Warning"] = "" -- L["Days in advance to show pins for seasonal holiday achievements."] = "" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/ruRU.lua b/Locale/ruRU.lua index 73d0700..835501a 100644 --- a/Locale/ruRU.lua +++ b/Locale/ruRU.lua @@ -25,3 +25,5 @@ L["Icon Alpha"] = "Прозрачность значка" -- L["Show more map pins by including achievements completed only by other characters."] = "Показать больше меток на карте, включая достижения, выполненные только другими персонажами." -- L["Season Warning"] = "Сезонное Предупреждение" -- L["Days in advance to show pins for seasonal holiday achievements."] = "За сколько дней заранее показывать метки достижений сезонных праздников." +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/zhCN.lua b/Locale/zhCN.lua index 113445c..7398764 100644 --- a/Locale/zhCN.lua +++ b/Locale/zhCN.lua @@ -25,3 +25,5 @@ L["Icon Alpha"] = "图标透明度" -- L["Show more map pins by including achievements completed only by other characters."] = "" -- L["Season Warning"] = "" -- L["Days in advance to show pins for seasonal holiday achievements."] = "" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" diff --git a/Locale/zhTW.lua b/Locale/zhTW.lua index a324627..1209c0e 100644 --- a/Locale/zhTW.lua +++ b/Locale/zhTW.lua @@ -25,3 +25,5 @@ L["Just Mine"] = "只有這個角色的成就" L["Show more map pins by including achievements completed only by other characters."] = "顯示較多的成就內容,包含其他角色已經完成的共通成就。" L["Season Warning"] = "節慶通知天數" L["Days in advance to show pins for seasonal holiday achievements."] = "要顯示未來多少天內的季節性節慶成就。" +-- L["Sort by tracked"] = "" +-- L["Sort achievements by tracked"] = "" From c9978ee255820f910928d4adc106bdc48aa3b36e Mon Sep 17 00:00:00 2001 From: Jan Galek Date: Thu, 5 Nov 2020 20:05:53 +0100 Subject: [PATCH 2/2] Resolved CR --- HandyNotes_Achievements.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/HandyNotes_Achievements.lua b/HandyNotes_Achievements.lua index 81b5e0c..b628d06 100644 --- a/HandyNotes_Achievements.lua +++ b/HandyNotes_Achievements.lua @@ -65,11 +65,7 @@ function HNA:HandyNotesCoordsNear(c, coord) end -function SortByTrackedAchievement(nodes, enabled) - if enabled == false then - return nodes - end - +function SortByTrackedAchievement(nodes) function getTrackedAchievements() id1, id2, id3, id4, id5, id6, id7, id8, id9, id10 = GetTrackedAchievements() @@ -125,10 +121,13 @@ function HNA:OnEnter(mapFile, nearCoord) local previousAchievementID local nodes = activeNodes[mapFile] - local sortedNodes = SortByTrackedAchievement(nodes, HNA.db.profile.sort_by_tracked) - for nodeIndex = 1, #sortedNodes, 2 do - local coord, row = sortedNodes[nodeIndex], sortedNodes[nodeIndex + 1] + if HNA.db.profile.sort_by_tracked == true then + nodes = SortByTrackedAchievement(nodes) + end + + for nodeIndex = 1, #nodes, 2 do + local coord, row = nodes[nodeIndex], nodes[nodeIndex + 1] if HNA:HandyNotesCoordsNear(coord, nearCoord) and HNA:Valid(row) then local achievementID = row[2] local criterion = row.criterion