Quantcast

Some sorting forcurrency dt. This closes #293

Darthpred [08-22-16 - 12:15]
Some sorting forcurrency dt. This closes #293
Filename
ElvUI_SLE/defaults/profile.lua
ElvUI_SLE/locales/english.lua
ElvUI_SLE/locales/russian.lua
ElvUI_SLE/modules/sledatatexts/currency.lua
ElvUI_SLE/options/datatexts/currency_c.lua
diff --git a/ElvUI_SLE/defaults/profile.lua b/ElvUI_SLE/defaults/profile.lua
index b4924b1..e615f20 100644
--- a/ElvUI_SLE/defaults/profile.lua
+++ b/ElvUI_SLE/defaults/profile.lua
@@ -285,6 +285,14 @@ P["sle"] = {
 			["Icons"] = true,
 			["Faction"] = true,
 			["Unused"] = true,
+			["gold"] = {
+				["direction"] = "normal",
+				["method"] = "name",
+			},
+			["cur"] = {
+				["direction"] = "normal",
+				["method"] = "name",
+			},
 		},
 		["regen"] = {
 			["short"] = false,
diff --git a/ElvUI_SLE/locales/english.lua b/ElvUI_SLE/locales/english.lua
index ca88634..1cd83e9 100644
--- a/ElvUI_SLE/locales/english.lua
+++ b/ElvUI_SLE/locales/english.lua
@@ -403,6 +403,10 @@ L["Are you sure you want to remove |cff1784d1%s|r from currency datatexts?"] = t
 L["Hide panel background"] = true
 L["Don't show this panel, only datatexts assinged to it"] = true
 L["SLE_DT_CURRENCY_WARNING_GOLD"] = [[Your datapanel %s has ElvUI's "Gold" datatext active while "S&L Currency" datatext is selected elsewhere. To ensure the correct functioning of "S&L Currency" datatext we are disabling some functions of "Gold" datatext. To avoid this conflict you need to replace one of conflicting datatexts.]]
+L["Gold Sorting"] = true
+L["Normal"] = true
+L["Reverced"] = true
+L["Amount"] = true

 --Enhnced Shadows
 L["Enhanced Shadows"] = true
diff --git a/ElvUI_SLE/locales/russian.lua b/ElvUI_SLE/locales/russian.lua
index 050dcd1..bf642e5 100644
--- a/ElvUI_SLE/locales/russian.lua
+++ b/ElvUI_SLE/locales/russian.lua
@@ -400,6 +400,10 @@ L["Account Time Played"] = "Время в игре на аккаунте"
 L["Hide panel background"] = "Скрыть фон"
 L["Don't show this panel, only datatexts assinged to it"] = "Не показывать фон панели, а только назначенные инфо-тексты."
 L["SLE_DT_CURRENCY_WARNING_GOLD"] = [[На вашей панели %s включен инфо-текст "Gold" при активном инфо-тексте "S&L Currency". Для корректной работы "S&L Currency" мы отключаем некоторые функции инфо-текста "Gold". Для избежания данного конфликта вам необходимо заменить один из конфликтующих инфо-текстов.]]
+L["Gold Sorting"] = "Сортировка золота"
+L["Normal"] = "Нормальная"
+L["Reverced"] = "Обратная"
+L["Amount"] = "Количество"

 --Enhnced Shadows
 L["Enhanced Shadows"] = "Улучшенные тени"
diff --git a/ElvUI_SLE/modules/sledatatexts/currency.lua b/ElvUI_SLE/modules/sledatatexts/currency.lua
index 632aa33..c2221b5 100644
--- a/ElvUI_SLE/modules/sledatatexts/currency.lua
+++ b/ElvUI_SLE/modules/sledatatexts/currency.lua
@@ -3,11 +3,12 @@ local DT = E:GetModule('DataTexts')
 local DTP = SLE:GetModule('Datatexts')
 --GLOBALS: ElvDB
 local abs, mod = abs, mod
+local sort = sort
 local GetMoney, GetCurrencyInfo, GetNumWatchedTokens, GetBackpackCurrencyInfo, GetCurrencyListInfo = GetMoney, GetCurrencyInfo, GetNumWatchedTokens, GetBackpackCurrencyInfo, GetCurrencyListInfo

 local defaultColor = { 1, 1, 1 }
 local Profit = 0
-local Spent	= 0
+local Spent = 0
 local copperFormatter = T.join("", "%d", L.copperabbrev)
 local silverFormatter = T.join("", "%d", L.silverabbrev, " %.2d", L.copperabbrev)
 local goldFormatter =  T.join("", "%s", L.goldabbrev, " %.2d", L.silverabbrev, " %.2d", L.copperabbrev)
@@ -100,22 +101,6 @@ local MiscellaneousCurrency = {
 local HordeColor = RAID_CLASS_COLORS["DEATHKNIGHT"]
 local AllianceColor = RAID_CLASS_COLORS["SHAMAN"]

-local function OrderedPairs(t, f)
-	local function orderednext(t, n)
-		local key = t[t.__next]
-		if not key then return end
-		t.__next = t.__next + 1
-		return key, t.__source[key]
-	end
-
-	local keys, kn = {__source = t, __next = 1}, 1
-	for k in T.pairs(t) do
-		keys[kn], kn = k, kn + 1
-	end
-	T.sort(keys, f)
-	return orderednext, keys
-end
-
 local function ToggleOption(name)
 	if E.db.sle.dt.currency[name] then
 		E.db.sle.dt.currency[name] = false
@@ -146,9 +131,28 @@ local function UnusedCheck()
 	end
 end

+local function SortCurrency(a,b)
+	local method = E.db.sle.dt.currency.cur.method
+	if E.db.sle.dt.currency.cur.direction == "normal" then
+		return a[method] < b[method]
+	else
+		return a[method] > b[method]
+	end
+end
+
+local function SortGold(a,b)
+	local method = E.db.sle.dt.currency.gold.method
+	if E.db.sle.dt.currency.gold.direction == "normal" then
+		return a[method] < b[method]
+	else
+		return a[method] > b[method]
+	end
+end
+
 local function GetCurrency(CurrencyTable, Text)
 	local Seperator = false
 	UnusedCheck()
+	local ShownTable = {}
 	for key, id in T.pairs(CurrencyTable) do
 		local name, amount, texture, week, weekmax, maxed, discovered = GetCurrencyInfo(id)
 		local LeftString = GetOption('Icons') and T.format('%s %s', T.format('|T%s:14:14:0:0:64:64:4:60:4:60|t', texture), name) or name
@@ -174,9 +178,23 @@ local function GetCurrency(CurrencyTable, Text)
 				DT.tooltip:AddLine(Text)
 				Seperator = true
 			end
-			DT.tooltip:AddDoubleLine(LeftString, RightString, r1, g1, b1, r2, g2, b2)
+			T.tinsert(ShownTable,
+				{
+					name = name,
+					left = LeftString,
+					right = RightString,
+					r1 = r1, g1 = g1, b1 = b1,
+					r2 = r2, g2 = g2, b2 = b2,
+					amount = amount
+				}
+			)
 		end
 	end
+	sort(ShownTable, SortCurrency)
+	for i = 1, #ShownTable do
+		local t = ShownTable[i]
+		DT.tooltip:AddDoubleLine(t.left, t.right, t.r1, t.g1, t.b1, t.r2, t.g2, t.b2)
+	end
 end

 local function OnEvent(self, event, ...)
@@ -273,11 +291,19 @@ local function OnEnter(self)

 	local totalGold, AllianceGold, HordeGold = 0, 0, 0
 	DT.tooltip:AddLine(L["Character: "])
-	for k,_ in OrderedPairs(ElvDB["gold"][E.myrealm]) do
+	local ShownGold = {}
+	for k,_ in T.pairs(ElvDB["gold"][E.myrealm]) do
 		if ElvDB["gold"][E.myrealm][k] then
 			local class = ElvDB["class"][E.myrealm][k]
 			local color = RAID_CLASS_COLORS[class or "PRIEST"]
-			DT.tooltip:AddDoubleLine(k, E:FormatMoney(ElvDB["gold"][E.myrealm][k], E.db.datatexts.goldFormat or "BLIZZARD", not E.db.datatexts.goldCoins), color.r, color.g, color.b, 1, 1, 1)
+			T.tinsert(ShownGold,
+				{
+					name = k,
+					amount = ElvDB["gold"][E.myrealm][k],
+					amountText = E:FormatMoney(ElvDB["gold"][E.myrealm][k], E.db.datatexts.goldFormat or "BLIZZARD", not E.db.datatexts.goldCoins),
+					r = color.r, g = color.g, b =color.b,
+				}
+			)
 			if ElvDB["faction"][E.myrealm]["Alliance"][k] then
 				AllianceGold = AllianceGold + ElvDB["gold"][E.myrealm][k]
 			end
@@ -287,6 +313,11 @@ local function OnEnter(self)
 			totalGold = totalGold + ElvDB["gold"][E.myrealm][k]
 		end
 	end
+	sort(ShownGold, SortGold)
+	for i = 1, #ShownGold do
+		local t = ShownGold[i]
+		DT.tooltip:AddDoubleLine(t.name, t.amountText, t.r, t.g, t.b, 1, 1, 1)
+	end

 	DT.tooltip:AddLine' '
 	DT.tooltip:AddLine(L["Server: "])
diff --git a/ElvUI_SLE/options/datatexts/currency_c.lua b/ElvUI_SLE/options/datatexts/currency_c.lua
index e761753..e0d3ae8 100644
--- a/ElvUI_SLE/options/datatexts/currency_c.lua
+++ b/ElvUI_SLE/options/datatexts/currency_c.lua
@@ -70,6 +70,63 @@ local function configTable()
 					E:StaticPopup_Show('SLE_CONFIRM_DELETE_CURRENCY_CHARACTER', nil, nil, { ["name"] = name, ["realm"] = realm });
 				end,
 			},
+			sortGold = {
+				order = 30,
+				name = L["Gold Sorting"],
+				type = "group",
+				guiInline = true,
+				get = function(info) return E.db.sle.dt.currency.gold[ info[#info] ] end,
+				set = function(info, value) E.db.sle.dt.currency.gold[ info[#info] ] = value; end,
+				args = {
+					direction = {
+						order = 1,
+						type = "select",
+						name = L["Sort Direction"],
+						values = {
+							["normal"] = L["Normal"],
+							["reverced"] = L["Reverced"],
+						},
+					},
+					method = {
+						order = 2,
+						type = "select",
+						name = L["Sort Method"],
+						values = {
+							["name"] = NAME,
+							["amount"] = L["Amount"],
+						},
+					},
+				},
+			},
+			sortCurrency = {
+				order = 31,
+				name = L["Currency Sorting"],
+				type = "group",
+				guiInline = true,
+				get = function(info) return E.db.sle.dt.currency.cur[ info[#info] ] end,
+				set = function(info, value) E.db.sle.dt.currency.cur[ info[#info] ] = value; end,
+				args = {
+					direction = {
+						order = 1,
+						type = "select",
+						name = L["Direction"],
+						values = {
+							["normal"] = L["Normal"],
+							["reverced"] = L["Reverced"],
+						},
+					},
+					method = {
+						order = 2,
+						type = "select",
+						name = L["Sort Method"],
+						values = {
+							["name"] = NAME,
+							["amount"] = L["Amount"],
+							["r1"] = L["Tracked"],
+						},
+					},
+				},
+			},
 		},
 	}
 end